Skip to content
This repository has been archived by the owner on May 14, 2020. It is now read-only.

Commit

Permalink
Merge pull request #13 from libp2p/fix/filter-listing
Browse files Browse the repository at this point in the history
fix filter listing
  • Loading branch information
Stebalien authored May 20, 2019
2 parents 05a9b9b + 505b670 commit e3cdd80
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ func (fs *Filters) AddrBlocked(a ma.Multiaddr) (deny bool) {
func (fs *Filters) Filters() (result []*net.IPNet) {
ffa := fs.FiltersForAction(ActionDeny)
for _, res := range ffa {
res := res // allocate a new copy
result = append(result, &res)
}
return result
Expand Down
26 changes: 26 additions & 0 deletions filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,32 @@ import (
ma "github.com/multiformats/go-multiaddr"
)

func TestFilterListing(t *testing.T) {
f := NewFilters()
expected := map[string]bool{
"1.2.3.0/24": true,
"4.3.2.1/32": true,
"fd00::/8": true,
"fc00::1/128": true,
}
for cidr := range expected {
_, ipnet, _ := net.ParseCIDR(cidr)
f.AddDialFilter(ipnet)
}

for _, filter := range f.Filters() {
cidr := filter.String()
if expected[cidr] {
delete(expected, cidr)
} else {
t.Errorf("unexected filter %s", cidr)
}
}
for cidr := range expected {
t.Errorf("expected filter %s", cidr)
}
}

func TestFilterBlocking(t *testing.T) {
f := NewFilters()

Expand Down

0 comments on commit e3cdd80

Please sign in to comment.