Commit b26603fd authored by Marten Seemann's avatar Marten Seemann

remove deprecated filter functions

parent eef92462
......@@ -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) {
......@@ -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.
......@@ -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
......
......@@ -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)
......@@ -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")
}
......@@ -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")
}
......@@ -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
......@@ -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 {
......
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