diff --git a/filter.go b/net/filter.go similarity index 93% rename from filter.go rename to net/filter.go index 6751202..f7076d0 100644 --- a/filter.go +++ b/net/filter.go @@ -1,8 +1,10 @@ -package multiaddr +package manet import ( "net" "sync" + + ma "github.com/multiformats/go-multiaddr" ) // Action is an enum modelling all possible filter actions. @@ -98,7 +100,7 @@ func (fs *Filters) RemoveLiteral(ipnet net.IPNet) (removed bool) { return false } -// AddrBlocked parses a ma.Multiaddr and, if a valid netip is found, it applies the +// AddrBlocked parses a ma.ma.Multiaddr and, if a valid netip is found, it applies the // Filter set rules, returning true if the given address should be denied, and false if // the given address is accepted. // @@ -108,17 +110,17 @@ func (fs *Filters) RemoveLiteral(ipnet net.IPNet) (removed bool) { // TODO: currently, the last filter to match wins always, but it shouldn't be that way. // Instead, the highest-specific last filter should win; that way more specific filters // override more general ones. -func (fs *Filters) AddrBlocked(a Multiaddr) (deny bool) { +func (fs *Filters) AddrBlocked(a ma.Multiaddr) (deny bool) { var ( netip net.IP found bool ) - ForEach(a, func(c Component) bool { + ma.ForEach(a, func(c ma.Component) bool { switch c.Protocol().Code { - case P_IP6ZONE: + case ma.P_IP6ZONE: return true - case P_IP6, P_IP4: + case ma.P_IP6, ma.P_IP4: found = true netip = net.IP(c.RawValue()) return false diff --git a/filter_test.go b/net/filter_test.go similarity index 92% rename from filter_test.go rename to net/filter_test.go index 741ee0a..c19579f 100644 --- a/filter_test.go +++ b/net/filter_test.go @@ -1,8 +1,10 @@ -package multiaddr +package manet import ( "net" "testing" + + ma "github.com/multiformats/go-multiaddr" ) func TestFilterListing(t *testing.T) { @@ -66,7 +68,7 @@ func TestFilterBlocking(t *testing.T) { "/ip6/fd00::2/tcp/321", "/ip6/fc00::1/udp/321", } { - maddr, err := NewMultiaddr(blocked) + maddr, err := ma.NewMultiaddr(blocked) if err != nil { t.Error(err) } @@ -82,7 +84,7 @@ func TestFilterBlocking(t *testing.T) { "/ip6/fe00::1/tcp/321", "/ip6/fc00::2/udp/321", } { - maddr, err := NewMultiaddr(addr) + maddr, err := ma.NewMultiaddr(addr) if err != nil { t.Error(err) } @@ -112,7 +114,7 @@ func TestFilterWhitelisting(t *testing.T) { "/ip4/1.2.3.254/tcp/123", "/ip4/1.2.3.254/udp/321", } { - maddr, err := NewMultiaddr(addr) + maddr, err := ma.NewMultiaddr(addr) if err != nil { t.Error(err) } @@ -128,7 +130,7 @@ func TestFilterWhitelisting(t *testing.T) { "/ip6/fd00::2/tcp/321", "/ip6/fc00::1/udp/321", } { - maddr, err := NewMultiaddr(blocked) + maddr, err := ma.NewMultiaddr(blocked) if err != nil { t.Error(err) } @@ -159,7 +161,7 @@ func TestFiltersRemoveRules(t *testing.T) { // these are all whitelisted, should be OK for _, addr := range ips { - maddr, err := NewMultiaddr(addr) + maddr, err := ma.NewMultiaddr(addr) if err != nil { t.Error(err) } @@ -174,7 +176,7 @@ func TestFiltersRemoveRules(t *testing.T) { // Show that they all apply, these are now blacklisted & should fail for _, addr := range ips { - maddr, err := NewMultiaddr(addr) + maddr, err := ma.NewMultiaddr(addr) if err != nil { t.Error(err) } @@ -191,7 +193,7 @@ func TestFiltersRemoveRules(t *testing.T) { // our default is reject, so the 1.2.3.0/24 should be rejected now, // along with everything else for _, addr := range ips { - maddr, err := NewMultiaddr(addr) + maddr, err := ma.NewMultiaddr(addr) if err != nil { t.Error(err) }