Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove deprecated filter functions #157

Merged
merged 1 commit into from Jul 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 0 additions & 35 deletions filter.go
Expand Up @@ -50,18 +50,6 @@ func (fs *Filters) find(ipnet net.IPNet) (int, *filterEntry) {
return -1, nil
}

// AddDialFilter adds a deny rule to this Filters set. Hosts
// matching the given net.IPNet filter will be denied, unless
// another rule is added which states that they should be accepted.
//
// No effort is made to prevent duplication of filters, or to simplify
// the filters list.
//
// Deprecated: Use AddFilter().
func (fs *Filters) AddDialFilter(f *net.IPNet) {
fs.AddFilter(*f, ActionDeny)
}

// AddFilter adds a rule to the Filters set, enforcing the desired action for
// the provided IPNet mask.
func (fs *Filters) AddFilter(ipnet net.IPNet, action Action) {
Expand All @@ -75,15 +63,6 @@ func (fs *Filters) AddFilter(ipnet net.IPNet, action Action) {
}
}

// RemoveLiteral removes the first filter associated with the supplied IPNet,
// returning whether something was removed or not. It makes no distinction
// between whether the rule is an accept or a deny.
//
// Deprecated: use RemoveLiteral() instead.
func (fs *Filters) Remove(ipnet *net.IPNet) (removed bool) {
return fs.RemoveLiteral(*ipnet)
}

// RemoveLiteral removes the first filter associated with the supplied IPNet,
// returning whether something was removed or not. It makes no distinction
// between whether the rule is an accept or a deny.
Expand Down Expand Up @@ -144,20 +123,6 @@ func (fs *Filters) AddrBlocked(a Multiaddr) (deny bool) {
return action == ActionDeny
}

// Filters returns the list of DENY net.IPNet masks. For backwards compatibility.
//
// A copy of the filters is made prior to returning, so the inner state is not exposed.
//
// Deprecated: Use FiltersForAction().
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
}

func (fs *Filters) ActionForFilter(ipnet net.IPNet) (action Action, ok bool) {
if _, f := fs.find(ipnet); f != nil {
return f.action, true
Expand Down
14 changes: 7 additions & 7 deletions filter_test.go
Expand Up @@ -15,10 +15,10 @@ func TestFilterListing(t *testing.T) {
}
for cidr := range expected {
_, ipnet, _ := net.ParseCIDR(cidr)
f.AddDialFilter(ipnet)
f.AddFilter(*ipnet, ActionDeny)
}

for _, filter := range f.Filters() {
for _, filter := range f.FiltersForAction(ActionDeny) {
cidr := filter.String()
if expected[cidr] {
delete(expected, cidr)
Expand All @@ -35,8 +35,8 @@ func TestFilterBlocking(t *testing.T) {
f := NewFilters()

_, ipnet, _ := net.ParseCIDR("0.1.2.3/24")
f.AddDialFilter(ipnet)
filters := f.Filters()
f.AddFilter(*ipnet, ActionDeny)
filters := f.FiltersForAction(ActionDeny)
if len(filters) != 1 {
t.Fatal("Expected only 1 filter")
}
Expand All @@ -45,7 +45,7 @@ func TestFilterBlocking(t *testing.T) {
t.Fatal("Expected filter with DENY action")
}

if !f.RemoveLiteral(*filters[0]) {
if !f.RemoveLiteral(filters[0]) {
t.Error("expected true value from RemoveLiteral")
}

Expand All @@ -56,7 +56,7 @@ func TestFilterBlocking(t *testing.T) {
"fc00::1/128",
} {
_, ipnet, _ := net.ParseCIDR(cidr)
f.AddDialFilter(ipnet)
f.AddFilter(*ipnet, ActionDeny)
}

// These addresses should all be blocked
Expand Down Expand Up @@ -170,7 +170,7 @@ func TestFiltersRemoveRules(t *testing.T) {

// Test removing the filter. It'll remove multiple, so make a dupe &
// a complement
f.AddDialFilter(ipnet)
f.AddFilter(*ipnet, ActionDeny)

// Show that they all apply, these are now blacklisted & should fail
for _, addr := range ips {
Expand Down