Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
mf
go-multiaddr
Commits
c693710d
Unverified
Commit
c693710d
authored
Jul 24, 2021
by
Marten Seemann
Committed by
GitHub
Jul 24, 2021
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #157 from multiformats/remove-deprecated-filters
remove deprecated filter functions
parents
87b29417
b26603fd
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
42 deletions
+7
-42
filter.go
filter.go
+0
-35
filter_test.go
filter_test.go
+7
-7
No files found.
filter.go
View file @
c693710d
...
@@ -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
...
...
filter_test.go
View file @
c693710d
...
@@ -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
.
Add
Dial
Filter
(
ipnet
)
f
.
AddFilter
(
*
ipnet
,
ActionDeny
)
}
}
for
_
,
filter
:=
range
f
.
Filters
(
)
{
for
_
,
filter
:=
range
f
.
Filters
ForAction
(
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
.
Add
Dial
Filter
(
ipnet
)
f
.
AddFilter
(
*
ipnet
,
ActionDeny
)
filters
:=
f
.
Filters
(
)
filters
:=
f
.
Filters
ForAction
(
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
.
Add
Dial
Filter
(
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
.
Add
Dial
Filter
(
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
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment