Unverified Commit c693710d authored by Marten Seemann's avatar Marten Seemann Committed by GitHub

Merge pull request #157 from multiformats/remove-deprecated-filters

remove deprecated filter functions
parents 87b29417 b26603fd
...@@ -50,18 +50,6 @@ func (fs *Filters) find(ipnet net.IPNet) (int, *filterEntry) { ...@@ -50,18 +50,6 @@ func (fs *Filters) find(ipnet net.IPNet) (int, *filterEntry) {
return -1, nil 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 // AddFilter adds a rule to the Filters set, enforcing the desired action for
// the provided IPNet mask. // the provided IPNet mask.
func (fs *Filters) AddFilter(ipnet net.IPNet, action Action) { func (fs *Filters) AddFilter(ipnet net.IPNet, action Action) {
...@@ -75,15 +63,6 @@ func (fs *Filters) AddFilter(ipnet net.IPNet, action Action) { ...@@ -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, // RemoveLiteral removes the first filter associated with the supplied IPNet,
// returning whether something was removed or not. It makes no distinction // returning whether something was removed or not. It makes no distinction
// between whether the rule is an accept or a deny. // between whether the rule is an accept or a deny.
...@@ -144,20 +123,6 @@ func (fs *Filters) AddrBlocked(a Multiaddr) (deny bool) { ...@@ -144,20 +123,6 @@ func (fs *Filters) AddrBlocked(a Multiaddr) (deny bool) {
return action == ActionDeny 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) { func (fs *Filters) ActionForFilter(ipnet net.IPNet) (action Action, ok bool) {
if _, f := fs.find(ipnet); f != nil { if _, f := fs.find(ipnet); f != nil {
return f.action, true return f.action, true
......
...@@ -15,10 +15,10 @@ func TestFilterListing(t *testing.T) { ...@@ -15,10 +15,10 @@ func TestFilterListing(t *testing.T) {
} }
for cidr := range expected { for cidr := range expected {
_, ipnet, _ := net.ParseCIDR(cidr) _, 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() cidr := filter.String()
if expected[cidr] { if expected[cidr] {
delete(expected, cidr) delete(expected, cidr)
...@@ -35,8 +35,8 @@ func TestFilterBlocking(t *testing.T) { ...@@ -35,8 +35,8 @@ func TestFilterBlocking(t *testing.T) {
f := NewFilters() f := NewFilters()
_, ipnet, _ := net.ParseCIDR("0.1.2.3/24") _, ipnet, _ := net.ParseCIDR("0.1.2.3/24")
f.AddDialFilter(ipnet) f.AddFilter(*ipnet, ActionDeny)
filters := f.Filters() filters := f.FiltersForAction(ActionDeny)
if len(filters) != 1 { if len(filters) != 1 {
t.Fatal("Expected only 1 filter") t.Fatal("Expected only 1 filter")
} }
...@@ -45,7 +45,7 @@ func TestFilterBlocking(t *testing.T) { ...@@ -45,7 +45,7 @@ func TestFilterBlocking(t *testing.T) {
t.Fatal("Expected filter with DENY action") t.Fatal("Expected filter with DENY action")
} }
if !f.RemoveLiteral(*filters[0]) { if !f.RemoveLiteral(filters[0]) {
t.Error("expected true value from RemoveLiteral") t.Error("expected true value from RemoveLiteral")
} }
...@@ -56,7 +56,7 @@ func TestFilterBlocking(t *testing.T) { ...@@ -56,7 +56,7 @@ func TestFilterBlocking(t *testing.T) {
"fc00::1/128", "fc00::1/128",
} { } {
_, ipnet, _ := net.ParseCIDR(cidr) _, ipnet, _ := net.ParseCIDR(cidr)
f.AddDialFilter(ipnet) f.AddFilter(*ipnet, ActionDeny)
} }
// These addresses should all be blocked // These addresses should all be blocked
...@@ -170,7 +170,7 @@ func TestFiltersRemoveRules(t *testing.T) { ...@@ -170,7 +170,7 @@ func TestFiltersRemoveRules(t *testing.T) {
// Test removing the filter. It'll remove multiple, so make a dupe & // Test removing the filter. It'll remove multiple, so make a dupe &
// a complement // a complement
f.AddDialFilter(ipnet) f.AddFilter(*ipnet, ActionDeny)
// Show that they all apply, these are now blacklisted & should fail // Show that they all apply, these are now blacklisted & should fail
for _, addr := range ips { for _, addr := range ips {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment