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
8ad672a7
Commit
8ad672a7
authored
Jul 02, 2015
by
Juan Batiz-Benet
Browse files
Merge pull request #1433 from ipfs/fix/addr-filter
add filters from config to addr filter in swarm
parents
bafe1b04
1c1e389d
Changes
2
Hide whitespace changes
Inline
Side-by-side
net/filter/filter.go
View file @
8ad672a7
...
...
@@ -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 @
8ad672a7
...
...
@@ -20,6 +20,7 @@ import (
pst
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-peerstream/transport"
psy
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-peerstream/transport/yamux"
prom
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/prometheus/client_golang/prometheus"
mafilter
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/whyrusleeping/multiaddr-filter"
context
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
)
...
...
@@ -83,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
...
...
@@ -101,6 +102,16 @@ func (s *Swarm) teardown() error {
return
s
.
swarm
.
Close
()
}
func
(
s
*
Swarm
)
AddAddrFilter
(
f
string
)
error
{
m
,
err
:=
mafilter
.
NewMask
(
f
)
if
err
!=
nil
{
return
err
}
s
.
Filters
.
AddDialFilter
(
m
)
return
nil
}
// CtxGroup returns the Context Group of the swarm
func
filterAddrs
(
listenAddrs
[]
ma
.
Multiaddr
)
([]
ma
.
Multiaddr
,
error
)
{
if
len
(
listenAddrs
)
>
0
{
...
...
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