Skip to content

Commit

Permalink
feat: move filters into a sub-package
Browse files Browse the repository at this point in the history
These really don't belong in the root package.
  • Loading branch information
Stebalien committed May 20, 2020
1 parent 192ac0f commit 379d881
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
12 changes: 7 additions & 5 deletions filter.go → filter/filter.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package multiaddr
package filter

import (
"net"
"sync"

ma "github.com/multiformats/go-multiaddr"
)

// Action is an enum modelling all possible filter actions.
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions filter_test.go → filter/filter_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package multiaddr
package filter

import (
"net"
"testing"

ma "github.com/multiformats/go-multiaddr"
)

func TestFilterListing(t *testing.T) {
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 379d881

Please sign in to comment.