Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
go-libp2p
Commits
1c1e389d
Commit
1c1e389d
authored
Jun 30, 2015
by
Jeromy
Browse files
add command to manipulate address filters and a sharness test for them
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
parent
c5cdd981
Changes
2
Hide whitespace changes
Inline
Side-by-side
net/filter/filter.go
View file @
1c1e389d
...
...
@@ -9,11 +9,17 @@ import (
)
type
Filters
struct
{
filters
[]
*
net
.
IPNet
filters
map
[
string
]
*
net
.
IPNet
}
func
NewFilters
()
*
Filters
{
return
&
Filters
{
filters
:
make
(
map
[
string
]
*
net
.
IPNet
),
}
}
func
(
fs
*
Filters
)
AddDialFilter
(
f
*
net
.
IPNet
)
{
fs
.
filters
=
append
(
fs
.
filters
,
f
)
fs
.
filters
[
f
.
String
()]
=
f
}
func
(
f
*
Filters
)
AddrBlocked
(
a
ma
.
Multiaddr
)
bool
{
...
...
@@ -32,3 +38,15 @@ func (f *Filters) AddrBlocked(a ma.Multiaddr) bool {
}
return
false
}
func
(
f
*
Filters
)
Filters
()
[]
*
net
.
IPNet
{
var
out
[]
*
net
.
IPNet
for
_
,
ff
:=
range
f
.
filters
{
out
=
append
(
out
,
ff
)
}
return
out
}
func
(
f
*
Filters
)
Remove
(
ff
*
net
.
IPNet
)
{
delete
(
f
.
filters
,
ff
.
String
())
}
net/swarm/swarm.go
View file @
1c1e389d
...
...
@@ -84,7 +84,7 @@ func NewSwarm(ctx context.Context, listenAddrs []ma.Multiaddr,
dialT
:
DialTimeout
,
notifs
:
make
(
map
[
inet
.
Notifiee
]
ps
.
Notifiee
),
bwc
:
bwc
,
Filters
:
new
(
filter
.
Filters
),
Filters
:
filter
.
New
Filters
(
),
}
// configure Swarm
...
...
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