Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions cmd/observation-encoder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/pelletier/go-toml/v2"

"github.com/dnstapir/tapir-analyse-lib/common"
"github.com/dnstapir/tapir-analyse-lib/libtapir"
"github.com/dnstapir/tapir-analyse-lib/logger"

"github.com/dnstapir/observation-encoder/internal/api"
Expand All @@ -27,10 +26,9 @@ var commit = "BAD-BUILD"

type conf struct {
app.Conf
Debug bool `toml:"debug"`
Api api.Conf `toml:"api"`
Nats nats.Conf `toml:"nats"`
Libtapir libtapir.Conf `toml:"libtapir"`
Debug bool `toml:"debug"`
Api api.Conf `toml:"api"`
Nats nats.Conf `toml:"nats"`
Comment thread
zluudg marked this conversation as resolved.
}

func main() {
Expand Down Expand Up @@ -116,13 +114,6 @@ func main() {
os.Exit(-1)
}

/*
******************************************************************
********************** SET UP LIBTAPIR ***************************
******************************************************************
*/
libtapirHandle := libtapir.New(mainConf.Libtapir)

/*
******************************************************************
********************** SET UP MAIN APP ***************************
Expand All @@ -135,7 +126,6 @@ func main() {

mainConf.Log = applog
mainConf.NatsHandle = natsHandle
mainConf.LibtapirHandle = libtapirHandle
appHandle, err := app.Create(mainConf.Conf)
if err != nil {
log.Error("Error creating application: '%s'", err)
Expand Down
18 changes: 9 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ module github.com/dnstapir/observation-encoder
go 1.26.1

require (
github.com/dnstapir/tapir-analyse-lib v0.0.0-20260319145549-171c55292770
github.com/nats-io/nats.go v1.49.0
github.com/dnstapir/tapir-analyse-lib v0.0.0-20260414104340-0e06dc6a4691
github.com/nats-io/nats.go v1.50.0
github.com/pelletier/go-toml/v2 v2.2.4
)

require (
github.com/dnstapir/edm v0.0.0-20260226140325-d0441597d9e7 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/klauspost/compress v1.18.4 // indirect
github.com/klauspost/compress v1.18.5 // indirect
github.com/miekg/dns v1.1.72 // indirect
github.com/nats-io/nkeys v0.4.15 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
golang.org/x/crypto v0.48.0 // indirect
golang.org/x/mod v0.33.0 // indirect
golang.org/x/net v0.50.0 // indirect
golang.org/x/sync v0.19.0 // indirect
golang.org/x/sys v0.41.0 // indirect
golang.org/x/tools v0.42.0 // indirect
golang.org/x/crypto v0.50.0 // indirect
golang.org/x/mod v0.34.0 // indirect
golang.org/x/net v0.53.0 // indirect
golang.org/x/sync v0.20.0 // indirect
golang.org/x/sys v0.43.0 // indirect
golang.org/x/tools v0.43.0 // indirect
)
18 changes: 18 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ github.com/dnstapir/edm v0.0.0-20260226140325-d0441597d9e7 h1:iu3dtBFVW58alLOy4A
github.com/dnstapir/edm v0.0.0-20260226140325-d0441597d9e7/go.mod h1:HZaurgLX4rzgRotcHywFO0epgeVMTs4hFUwnxMu76P0=
github.com/dnstapir/tapir-analyse-lib v0.0.0-20260319145549-171c55292770 h1:pwxsirkB01EOQqR+Jeiy7ZW6zeMPDeG1TGHFQgkDA0M=
github.com/dnstapir/tapir-analyse-lib v0.0.0-20260319145549-171c55292770/go.mod h1:0LY/5nSFMzA9GMp8lZqNDwcovdCNaFFDIwLqJLPbtpI=
github.com/dnstapir/tapir-analyse-lib v0.0.0-20260414104340-0e06dc6a4691 h1:nAh8TAnaoEG3dL/QNeogYSaSbznIV2lzf82F7MGzUTY=
github.com/dnstapir/tapir-analyse-lib v0.0.0-20260414104340-0e06dc6a4691/go.mod h1:40Qa1ffewXPK41MZgpTSTt7Yvu80wA7A9bfNyYpP6nc=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/klauspost/compress v1.18.4 h1:RPhnKRAQ4Fh8zU2FY/6ZFDwTVTxgJ/EMydqSTzE9a2c=
github.com/klauspost/compress v1.18.4/go.mod h1:R0h/fSBs8DE4ENlcrlib3PsXS61voFxhIs2DeRhCvJ4=
github.com/klauspost/compress v1.18.5 h1:/h1gH5Ce+VWNLSWqPzOVn6XBO+vJbCNGvjoaGBFW2IE=
github.com/klauspost/compress v1.18.5/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ=
github.com/miekg/dns v1.1.72 h1:vhmr+TF2A3tuoGNkLDFK9zi36F2LS+hKTRW0Uf8kbzI=
github.com/miekg/dns v1.1.72/go.mod h1:+EuEPhdHOsfk6Wk5TT2CzssZdqkmFhf8r+aVyDEToIs=
github.com/nats-io/nats.go v1.49.0 h1:yh/WvY59gXqYpgl33ZI+XoVPKyut/IcEaqtsiuTJpoE=
github.com/nats-io/nats.go v1.49.0/go.mod h1:fDCn3mN5cY8HooHwE2ukiLb4p4G4ImmzvXyJt+tGwdw=
github.com/nats-io/nats.go v1.50.0 h1:5zAeQrTvyrKrWLJ0fu02W3br8ym57qf7csDzgLOpcds=
github.com/nats-io/nats.go v1.50.0/go.mod h1:26HypzazeOkyO3/mqd1zZd53STJN0EjCYF9Uy2ZOBno=
github.com/nats-io/nkeys v0.4.15 h1:JACV5jRVO9V856KOapQ7x+EY8Jo3qw1vJt/9Jpwzkk4=
github.com/nats-io/nkeys v0.4.15/go.mod h1:CpMchTXC9fxA5zrMo4KpySxNjiDVvr8ANOSZdiNfUrs=
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
Expand All @@ -18,13 +24,25 @@ github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
golang.org/x/crypto v0.48.0 h1:/VRzVqiRSggnhY7gNRxPauEQ5Drw9haKdM0jqfcCFts=
golang.org/x/crypto v0.48.0/go.mod h1:r0kV5h3qnFPlQnBSrULhlsRfryS2pmewsg+XfMgkVos=
golang.org/x/crypto v0.50.0 h1:zO47/JPrL6vsNkINmLoo/PH1gcxpls50DNogFvB5ZGI=
golang.org/x/crypto v0.50.0/go.mod h1:3muZ7vA7PBCE6xgPX7nkzzjiUq87kRItoJQM1Yo8S+Q=
golang.org/x/mod v0.33.0 h1:tHFzIWbBifEmbwtGz65eaWyGiGZatSrT9prnU8DbVL8=
golang.org/x/mod v0.33.0/go.mod h1:swjeQEj+6r7fODbD2cqrnje9PnziFuw4bmLbBZFrQ5w=
golang.org/x/mod v0.34.0 h1:xIHgNUUnW6sYkcM5Jleh05DvLOtwc6RitGHbDk4akRI=
golang.org/x/mod v0.34.0/go.mod h1:ykgH52iCZe79kzLLMhyCUzhMci+nQj+0XkbXpNYtVjY=
golang.org/x/net v0.50.0 h1:ucWh9eiCGyDR3vtzso0WMQinm2Dnt8cFMuQa9K33J60=
golang.org/x/net v0.50.0/go.mod h1:UgoSli3F/pBgdJBHCTc+tp3gmrU4XswgGRgtnwWTfyM=
golang.org/x/net v0.53.0 h1:d+qAbo5L0orcWAr0a9JweQpjXF19LMXJE8Ey7hwOdUA=
golang.org/x/net v0.53.0/go.mod h1:JvMuJH7rrdiCfbeHoo3fCQU24Lf5JJwT9W3sJFulfgs=
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k=
golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/sys v0.43.0 h1:Rlag2XtaFTxp19wS8MXlJwTvoh8ArU6ezoyFsMyCTNI=
golang.org/x/sys v0.43.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/tools v0.42.0 h1:uNgphsn75Tdz5Ji2q36v/nsFSfR/9BRFvqhGBaJGd5k=
golang.org/x/tools v0.42.0/go.mod h1:Ma6lCIwGZvHK6XtgbswSoWroEkhugApmsXyrUmBhfr0=
golang.org/x/tools v0.43.0 h1:12BdW9CeB3Z+J/I/wj34VMl8X+fEXBxVR90JeMX5E7s=
golang.org/x/tools v0.43.0/go.mod h1:uHkMso649BX2cZK6+RpuIPXS3ho2hZo4FVwfoy1vIk0=
32 changes: 11 additions & 21 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,25 @@ import (
"sync/atomic"

"github.com/dnstapir/tapir-analyse-lib/common"
"github.com/dnstapir/tapir-analyse-lib/libtapir"
)

const c_N_HANDLERS = 3
const c_NATS_DELIM = common.NATS_DELIM

type Conf struct {
Debug bool `toml:"debug"`
TtlMargin int `toml:"ttl_margin"`
Log common.Logger
NatsHandle nats
LibtapirHandle libtapir
Debug bool `toml:"debug"`
TtlMargin int `toml:"ttl_margin"`
Log common.Logger
NatsHandle nats
}

type appHandle struct {
id string
ttlMargin int
log common.Logger
natsHandle nats
libtapirHandle libtapir
exitCh chan<- common.Exit
id string
ttlMargin int
log common.Logger
natsHandle nats
exitCh chan<- common.Exit
pm
}

Expand All @@ -47,10 +46,6 @@ type nats interface {
Shutdown() error
}

type libtapir interface {
GenerateObservationMsg(string, uint32, int) (string, error) // TODO set ttl?
}

func Create(conf Conf) (*appHandle, error) {
a := new(appHandle)

Expand All @@ -62,10 +57,6 @@ func Create(conf Conf) (*appHandle, error) {
return nil, common.ErrBadHandle
}

if conf.LibtapirHandle == nil {
return nil, common.ErrBadHandle
}

// TODO what is a reasonale safety margin (in seconds) for adding to outgoing TTL?
if conf.TtlMargin < 0 || conf.TtlMargin > 3600 {
return nil, common.ErrBadParam
Expand All @@ -75,7 +66,6 @@ func Create(conf Conf) (*appHandle, error) {
a.id = "main app"
a.ttlMargin = conf.TtlMargin
a.natsHandle = conf.NatsHandle
a.libtapirHandle = conf.LibtapirHandle

return a, nil
}
Expand Down Expand Up @@ -166,7 +156,7 @@ func (a *appHandle) handleJob(ctx context.Context, j job) {

a.log.Debug("%s has observation vector %d", domain, obs)

obsJSON, err := a.libtapirHandle.GenerateObservationMsg(domain, obs, int(ttl)+a.ttlMargin)
obsJSON, err := libtapir.GenerateObservationMsg(domain, obs, int(ttl)+a.ttlMargin)
if err != nil {
a.log.Error("Couldn't generate JSON observation: %s", err)
return
Expand Down
Loading