Skip to content

Commit e7fd57f

Browse files
committedJun 30, 2015
add filters from config to addr filter in swarm
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
1 parent 74a331d commit e7fd57f

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed
 

‎core/core.go

+4
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,10 @@ func constructPeerHost(ctx context.Context, id peer.ID, ps peer.Peerstore, bwr m
533533
return nil, err
534534
}
535535

536+
for _, f := range fs {
537+
network.Swarm().Filters.AddDialFilter(f)
538+
}
539+
536540
host := p2pbhost.New(network, p2pbhost.NATPortMap, bwr)
537541

538542
return host, nil

‎p2p/net/swarm/swarm.go

+11
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
pst "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-peerstream/transport"
2121
psy "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-peerstream/transport/yamux"
2222
prom "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/prometheus/client_golang/prometheus"
23+
mafilter "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/whyrusleeping/multiaddr-filter"
2324
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
2425
)
2526

@@ -101,6 +102,16 @@ func (s *Swarm) teardown() error {
101102
return s.swarm.Close()
102103
}
103104

105+
func (s *Swarm) AddAddrFilter(f string) error {
106+
m, err := mafilter.NewMask(f)
107+
if err != nil {
108+
return err
109+
}
110+
111+
s.Filters.AddDialFilter(m)
112+
return nil
113+
}
114+
104115
// CtxGroup returns the Context Group of the swarm
105116
func filterAddrs(listenAddrs []ma.Multiaddr) ([]ma.Multiaddr, error) {
106117
if len(listenAddrs) > 0 {

0 commit comments

Comments
 (0)
Please sign in to comment.