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 (
...
@@ -9,11 +9,17 @@ import (
)
)
type
Filters
struct
{
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
)
{
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
{
func
(
f
*
Filters
)
AddrBlocked
(
a
ma
.
Multiaddr
)
bool
{
...
@@ -32,3 +38,15 @@ func (f *Filters) AddrBlocked(a ma.Multiaddr) bool {
...
@@ -32,3 +38,15 @@ func (f *Filters) AddrBlocked(a ma.Multiaddr) bool {
}
}
return
false
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 (
...
@@ -20,6 +20,7 @@ import (
pst
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-peerstream/transport"
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"
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"
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"
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,
...
@@ -83,7 +84,7 @@ func NewSwarm(ctx context.Context, listenAddrs []ma.Multiaddr,
dialT
:
DialTimeout
,
dialT
:
DialTimeout
,
notifs
:
make
(
map
[
inet
.
Notifiee
]
ps
.
Notifiee
),
notifs
:
make
(
map
[
inet
.
Notifiee
]
ps
.
Notifiee
),
bwc
:
bwc
,
bwc
:
bwc
,
Filters
:
new
(
filter
.
Filters
),
Filters
:
filter
.
New
Filters
(
),
}
}
// configure Swarm
// configure Swarm
...
@@ -101,6 +102,16 @@ func (s *Swarm) teardown() error {
...
@@ -101,6 +102,16 @@ func (s *Swarm) teardown() error {
return
s
.
swarm
.
Close
()
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
// CtxGroup returns the Context Group of the swarm
func
filterAddrs
(
listenAddrs
[]
ma
.
Multiaddr
)
([]
ma
.
Multiaddr
,
error
)
{
func
filterAddrs
(
listenAddrs
[]
ma
.
Multiaddr
)
([]
ma
.
Multiaddr
,
error
)
{
if
len
(
listenAddrs
)
>
0
{
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