Skip to content

Commit c693710

Browse files
Merge pull request #157 from multiformats/remove-deprecated-filters
remove deprecated filter functions
2 parents 87b2941 + b26603f commit c693710

File tree

2 files changed

+7
-42
lines changed

2 files changed

+7
-42
lines changed

filter.go

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,6 @@ func (fs *Filters) find(ipnet net.IPNet) (int, *filterEntry) {
5050
return -1, nil
5151
}
5252

53-
// AddDialFilter adds a deny rule to this Filters set. Hosts
54-
// matching the given net.IPNet filter will be denied, unless
55-
// another rule is added which states that they should be accepted.
56-
//
57-
// No effort is made to prevent duplication of filters, or to simplify
58-
// the filters list.
59-
//
60-
// Deprecated: Use AddFilter().
61-
func (fs *Filters) AddDialFilter(f *net.IPNet) {
62-
fs.AddFilter(*f, ActionDeny)
63-
}
64-
6553
// AddFilter adds a rule to the Filters set, enforcing the desired action for
6654
// the provided IPNet mask.
6755
func (fs *Filters) AddFilter(ipnet net.IPNet, action Action) {
@@ -75,15 +63,6 @@ func (fs *Filters) AddFilter(ipnet net.IPNet, action Action) {
7563
}
7664
}
7765

78-
// RemoveLiteral removes the first filter associated with the supplied IPNet,
79-
// returning whether something was removed or not. It makes no distinction
80-
// between whether the rule is an accept or a deny.
81-
//
82-
// Deprecated: use RemoveLiteral() instead.
83-
func (fs *Filters) Remove(ipnet *net.IPNet) (removed bool) {
84-
return fs.RemoveLiteral(*ipnet)
85-
}
86-
8766
// RemoveLiteral removes the first filter associated with the supplied IPNet,
8867
// returning whether something was removed or not. It makes no distinction
8968
// between whether the rule is an accept or a deny.
@@ -144,20 +123,6 @@ func (fs *Filters) AddrBlocked(a Multiaddr) (deny bool) {
144123
return action == ActionDeny
145124
}
146125

147-
// Filters returns the list of DENY net.IPNet masks. For backwards compatibility.
148-
//
149-
// A copy of the filters is made prior to returning, so the inner state is not exposed.
150-
//
151-
// Deprecated: Use FiltersForAction().
152-
func (fs *Filters) Filters() (result []*net.IPNet) {
153-
ffa := fs.FiltersForAction(ActionDeny)
154-
for _, res := range ffa {
155-
res := res // allocate a new copy
156-
result = append(result, &res)
157-
}
158-
return result
159-
}
160-
161126
func (fs *Filters) ActionForFilter(ipnet net.IPNet) (action Action, ok bool) {
162127
if _, f := fs.find(ipnet); f != nil {
163128
return f.action, true

filter_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ func TestFilterListing(t *testing.T) {
1515
}
1616
for cidr := range expected {
1717
_, ipnet, _ := net.ParseCIDR(cidr)
18-
f.AddDialFilter(ipnet)
18+
f.AddFilter(*ipnet, ActionDeny)
1919
}
2020

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

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

48-
if !f.RemoveLiteral(*filters[0]) {
48+
if !f.RemoveLiteral(filters[0]) {
4949
t.Error("expected true value from RemoveLiteral")
5050
}
5151

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

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

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

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

0 commit comments

Comments
 (0)