add filters from config to addr filter in swarm
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
Jeromy committed
Jun 30, 2015 at 15:03 UTC
e7fd57f69a9079acd8fc722150e3f1d51df29972
2 files changed
+15
core/core.go
+4
@@ -533,6 +533,10 @@ func constructPeerHost(ctx context.Context, id peer.ID, ps peer.Peerstore, bwr m
533
return nil, err
534
}
535
536
+ for _, f := range fs {
537
+ network.Swarm().Filters.AddDialFilter(f)
538
+ }
539
+
540
host := p2pbhost.New(network, p2pbhost.NATPortMap, bwr)
541
542
return host, nil
p2p/net/swarm/swarm.go
+11
@@ -20,6 +20,7 @@ import (
20
pst "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-peerstream/transport"
21
psy "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-peerstream/transport/yamux"
22
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"
24
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
25
)
26
@@ -101,6 +102,16 @@ func (s *Swarm) teardown() error {
102
return s.swarm.Close()
103
}
104
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
+
115
// CtxGroup returns the Context Group of the swarm
116
func filterAddrs(listenAddrs []ma.Multiaddr) ([]ma.Multiaddr, error) {
117
if len(listenAddrs) > 0 {