1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-09-09 23:42:20 +08:00

add filters from config to addr filter in swarm

License: MIT
Signed-off-by: Jeromy <jeromyj@gmail.com>
This commit is contained in:
Jeromy
2015-06-30 15:03:56 -07:00
parent 74a331db96
commit e7fd57f69a
2 changed files with 15 additions and 0 deletions

View File

@ -533,6 +533,10 @@ func constructPeerHost(ctx context.Context, id peer.ID, ps peer.Peerstore, bwr m
return nil, err
}
for _, f := range fs {
network.Swarm().Filters.AddDialFilter(f)
}
host := p2pbhost.New(network, p2pbhost.NATPortMap, bwr)
return host, nil

View File

@ -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"
)
@ -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 {