Skip to content

Commit

Permalink
foo
Browse files Browse the repository at this point in the history
  • Loading branch information
johanix committed May 27, 2024
1 parent 9a5736b commit 2a1e4b9
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 14 deletions.
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ default: ${PROG}

${PROG}: build


version.go:
/bin/sh make-version.sh $(VERSION)-$(COMMIT) $(APPDATE) $(PROG)

build: version.go
build: version.go # ../tapir/tapir.pb.go
$(GO) build $(GOFLAGS) -o ${PROG}

# ../tapir/tapir.pb.go: ../tapir/tapir.proto
# make -C ../tapir tapir.pb.go

linux:
/bin/sh make-version.sh $(VERSION)-$(COMMIT) $(APPDATE) $(PROG)
GOOS=linux GOARCH=amd64 go build $(GOFLAGS) -o ${PROG}.linux
Expand Down
82 changes: 74 additions & 8 deletions apihandler.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Johan Stenstam, johani@johani.org
* Johan Stenstam, johan.stenstam@internetstiftelsen.se
*/
package main

Expand Down Expand Up @@ -233,17 +233,83 @@ func APIbootstrap(conf *Config) func(w http.ResponseWriter, r *http.Request) {
}
log.Printf("Found %s greylist containing %d names", bp.ListName, len(greylist.Names))

w.Header().Set("Content-Type", "application/octet-stream")
w.Header().Set("Content-Disposition", "attachment; filename=greylist-dns-tapir.gob")
switch bp.Encoding {
case "gob":
w.Header().Set("Content-Type", "application/octet-stream")
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=greylist-%s.gob", bp.ListName))

encoder := gob.NewEncoder(w)
err := encoder.Encode(greylist)
if err != nil {
log.Printf("Error encoding greylist: %v", err)
resp.Error = true
resp.ErrorMsg = err.Error()
return
}

encoder := gob.NewEncoder(w)
err := encoder.Encode(greylist)
if err != nil {
log.Printf("Error encoding greylist: %v", err)
// case "protobuf":
// w.Header().Set("Content-Type", "application/octet-stream")
// w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=greylist-%s.protobuf", bp.ListName))
//
// data, err := proto.Marshal(greylist)
// if err != nil {
// log.Printf("Error encoding greylist to protobuf: %v", err)
// resp.Error = true
// resp.ErrorMsg = err.Error()
// return
// }

// _, err = w.Write(data)
// if err != nil {
// log.Printf("Error writing protobuf data to response: %v", err)
// resp.Error = true
// resp.ErrorMsg = err.Error()
// return
// }

// case "flatbuffer":
// w.Header().Set("Content-Type", "application/octet-stream")
// w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=greylist-%s.flatbuffer", bp.ListName))

// builder := flatbuffers.NewBuilder(0)
// names := make([]flatbuffers.UOffsetT, len(greylist.Names))

// i := 0
// for name := range greylist.Names {
// nameOffset := builder.CreateString(name)
// tapir.NameStart(builder)
// tapir.NameAddName(builder, nameOffset)
// names[i] = tapir.NameEnd(builder)
// i++
// }

// tapir.GreylistStartNamesVector(builder, len(names))
// for j := len(names) - 1; j >= 0; j-- {
// builder.PrependUOffsetT(names[j])
// }
// namesVector := builder.EndVector(len(names))

// tapir.GreylistStart(builder)
// tapir.GreylistAddNames(builder, namesVector)
// greylistOffset := tapir.GreylistEnd(builder)

// builder.Finish(greylistOffset)
// buf := builder.FinishedBytes()

// _, err := w.Write(buf)
// if err != nil {
// log.Printf("Error writing flatbuffer data to response: %v", err)
// resp.Error = true
// resp.ErrorMsg = err.Error()
// return
// }

default:
resp.Error = true
resp.ErrorMsg = err.Error()
resp.ErrorMsg = fmt.Sprintf("Unknown encoding: %s", bp.Encoding)
return
}

default:
resp.ErrorMsg = fmt.Sprintf("Unknown command: %s", bp.Command)
resp.Error = true
Expand Down
3 changes: 1 addition & 2 deletions bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,15 @@ func (td *TemData) BootstrapMqttSource(s *tapir.WBGlist, src SourceConf) (*tapir
status, buf, err := api.RequestNG(http.MethodPost, "/bootstrap", tapir.BootstrapPost{
Command: "export-greylist",
ListName: src.Name,
Encoding: "gob", // XXX: This is our default, but we'll test other encodings later
}, true)
if err != nil {
fmt.Printf("Error from RequestNG: %v\n", err)
// return nil, fmt.Errorf("Error from RequestNG: %v", err)
continue
}

if status != http.StatusOK {
fmt.Printf("HTTP Error: %s\n", buf)
// return nil, fmt.Errorf("HTTP Error: %s", buf)
continue
}

Expand Down
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ replace github.com/dnstapir/tapir => ../tapir
require (
github.com/dnstapir/tapir v0.0.0-00010101000000-000000000000
github.com/go-playground/validator/v10 v10.20.0
github.com/golang/protobuf v1.5.3
github.com/gorilla/mux v1.8.1
github.com/mattn/go-sqlite3 v1.14.22
github.com/miekg/dns v1.1.59
github.com/ryanuber/columnize v2.1.2+incompatible
github.com/smhanov/dawg v0.0.0-20220118194912-66057bdbf2e3
github.com/spf13/viper v1.18.2
google.golang.org/protobuf v1.31.0
gopkg.in/natefinch/lumberjack.v2 v2.2.1
gopkg.in/yaml.v3 v3.0.1
)

Expand All @@ -35,7 +39,6 @@ require (
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/ryanuber/columnize v2.1.2+incompatible // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/segmentio/asm v1.2.0 // indirect
Expand All @@ -56,5 +59,4 @@ require (
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.19.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
)
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBEx
github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
Expand Down Expand Up @@ -163,6 +167,11 @@ golang.org/x/tools v0.19.0 h1:tfGCXNR1OsFG+sVdLAitlpjAvD/I6dHDKnYrpEZUHkw=
golang.org/x/tools v0.19.0/go.mod h1:qoJWxmGSIBmAeriMx19ogtrEPrGtDbPK634QFIcLAhc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down

0 comments on commit 2a1e4b9

Please sign in to comment.