Skip to content

Commit

Permalink
Merge pull request #6 from teleconsys/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Giordyfish authored Mar 6, 2023
2 parents 7cbed60 + dc9155b commit dede113
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 374 deletions.
15 changes: 9 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
.idea
.DS_Store
collector.db
inx-collector
/database
/tools/datapayloads_tester/target

*.exe
*.exe~
*.dll
*.so
*.dylib
*.test
*.out
go.work
Binary file removed collector.exe
Binary file not shown.
10 changes: 2 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ require (
go.uber.org/dig v1.15.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

require (
filippo.io/edwards25519 v1.0.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
Expand Down Expand Up @@ -101,10 +95,10 @@ require (
github.com/iotaledger/inx-app v1.0.0-rc.1
github.com/iotaledger/inx/go v1.0.0-rc.1
github.com/labstack/echo/v4 v4.9.0
github.com/stretchr/testify v1.8.1
github.com/stretchr/testify v1.8.1 // indirect
golang.org/x/net v0.0.0-20220923203811-8be639271d50 // indirect
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/text v0.7.0 // indirect
google.golang.org/genproto v0.0.0-20220923205249-dd2d53f1fffc // indirect
google.golang.org/protobuf v1.28.1 // indirect
)
7 changes: 2 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,6 @@ github.com/iotaledger/inx/go v1.0.0-rc.1 h1:BCLPHP+GiC99tVKvaiw0BMn4+Tv6VBNSAusJ
github.com/iotaledger/inx/go v1.0.0-rc.1/go.mod h1:avAlMHmwcXsyOIIQ6sskA3b1K28Yew7O/iDmDcCQjCo=
github.com/iotaledger/iota.go v1.0.0 h1:tqm1FxJ/zOdzbrAaQ5BQpVF8dUy2eeGlSeWlNG8GoXY=
github.com/iotaledger/iota.go v1.0.0/go.mod h1:RiKYwDyY7aCD1L0YRzHSjOsJ5mUR9yvQpvhZncNcGQI=
github.com/iotaledger/iota.go/v3 v3.0.0-rc.1 h1:2WCARL7b+7kecVqAsoBXuSt7R5nTDUDXtRPf4GP9AVo=
github.com/iotaledger/iota.go/v3 v3.0.0-rc.1/go.mod h1:R3m6d5AFI0I++HOaYQR7QU8hY//vUSwbOyqQ7Bco2O4=
github.com/iotaledger/iota.go/v3 v3.0.0-rc.1.0.20230209162540-d0cd57775f0b h1:mKjq7/vaC4/nsgDD9EY4f5a/MRS462nLtDlq1bMOUI0=
github.com/iotaledger/iota.go/v3 v3.0.0-rc.1.0.20230209162540-d0cd57775f0b/go.mod h1:R3m6d5AFI0I++HOaYQR7QU8hY//vUSwbOyqQ7Bco2O4=
github.com/iris-contrib/blackfriday v2.0.0+incompatible/go.mod h1:UzZ2bDEoaSGPbkg6SAB4att1aAwTmVIx/5gCVqeyUdI=
Expand Down Expand Up @@ -582,7 +580,6 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0 h1:M2gUjqZET1qApGOWNSnZ49BAIMX4F/1plDv3+l31EJ4=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
Expand All @@ -592,7 +589,6 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
Expand Down Expand Up @@ -844,8 +840,9 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down
6 changes: 5 additions & 1 deletion pkg/api/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,11 @@ func (s *Server) subscribeToTag(c echo.Context) (string, string, error) {
bucketName = request.BucketName
}

filter := listener.NewFilter(request.Tag, request.PublicKey, bucketName, request.Duration, request.WithPOI)
filter, err := listener.NewFilter(request.Tag, request.PublicKey, bucketName, request.Duration, request.WithPOI)
if err != nil {
return "", "", err
}

filterId, err := s.Collector.Listener.AddFilter(filter)
if err != nil {
return "", "", err
Expand Down
55 changes: 45 additions & 10 deletions pkg/listener/filter.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package listener

import (
"crypto"
"crypto/ed25519"
"crypto/md5"
"encoding/hex"
"encoding/json"
"fmt"
"time"
Expand All @@ -10,33 +13,62 @@ import (
)

type Filter struct {
Tag string `json:"tag" validate:"required"`
PublicKey string `json:"publicKey,omitempty"`
Id string `json:"id,omitempty"`
BucketName string `json:"bucketName,omitempty"`
WithPOI bool `json:"withPOI,omitempty"`
Duration string `json:"duration,omitempty"`
Expiration time.Time `json:"expiration,omitempty"`
Tag string `json:"tag" validate:"required"`
PublicKey string `json:"publicKey,omitempty"`
Id string `json:"id,omitempty"`
BucketName string `json:"bucketName,omitempty"`
WithPOI bool `json:"withPOI,omitempty"`
Duration string `json:"duration,omitempty"`
Expiration time.Time
PublicKeyDecoded crypto.PublicKey
}

type StartupFilters struct {
Filters []Filter `json:"filters"`
}

func NewFilter(tag string, publicKey string, bucketName string, duration string, withPOI bool) Filter {
return Filter{
func NewFilter(tag string, publicKey string, bucketName string, duration string, withPOI bool) (Filter, error) {
filter := Filter{
Tag: tag,
PublicKey: publicKey,
BucketName: bucketName,
WithPOI: withPOI,
Duration: duration,
}

if filter.PublicKey != "" {
err := filter.setPublicKeyDecoded()
if err != nil {
return Filter{}, err
}
}

return filter, nil
}

func (f *Filter) setId() {
f.Id = fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("%v", f))))
}

func (f *Filter) setPublicKeyDecoded() error {
publicKeyBytes, err := hex.DecodeString(f.PublicKey)
if err != nil {
return err
}

pubKeyLen := len(publicKeyBytes)
if pubKeyLen != ed25519.PublicKeySize {
err = fmt.Errorf("invalid length for public key, got %d, wanted %d", pubKeyLen, ed25519.PublicKeySize)
return err
}

var publicKeyDecoded [ed25519.PublicKeySize]byte
copy(publicKeyDecoded[:], publicKeyBytes)

f.PublicKeyDecoded = publicKeyDecoded
return nil
}

func (f *Filter) setExpiration() error {
durationParsed, err := time.ParseDuration(f.Duration)
if err != nil {
Expand All @@ -61,12 +93,15 @@ func UnmarshalStartupFilters(filtersString string) ([]Filter, error) {
return filters.Filters, err
}

// validate filters
for _, filter := range filters.Filters {

// validate filters
err = validator.New().Struct(filter)
if err != nil {
return filters.Filters, err
}

}

return filters.Filters, nil
}
Loading

0 comments on commit dede113

Please sign in to comment.