From 84d4e76e2faf2b09b916bdb889a93fee66aff3c0 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Sat, 14 May 2016 19:32:28 -0700 Subject: [PATCH] address CR feedback --- p2p/net/swarm/addr/addr.go | 4 ++-- p2p/net/swarm/addr/filter.go | 4 ++++ p2p/net/swarm/swarm_dial.go | 8 ++++---- package.json | 1 + 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/p2p/net/swarm/addr/addr.go b/p2p/net/swarm/addr/addr.go index 8c0c94b..d9ba872 100644 --- a/p2p/net/swarm/addr/addr.go +++ b/p2p/net/swarm/addr/addr.go @@ -40,8 +40,8 @@ func init() { SupportedTransportProtocols = transports } -// FilterAddrs is a filter that removes certain addresses, according to filter. -// if filter returns true, the address is kept. +// FilterAddrs is a filter that removes certain addresses, according the given filters. +// if all filters return true, the address is kept. func FilterAddrs(a []ma.Multiaddr, filters ...func(ma.Multiaddr) bool) []ma.Multiaddr { b := make([]ma.Multiaddr, 0, len(a)) for _, addr := range a { diff --git a/p2p/net/swarm/addr/filter.go b/p2p/net/swarm/addr/filter.go index c67e1c6..d87ba81 100644 --- a/p2p/net/swarm/addr/filter.go +++ b/p2p/net/swarm/addr/filter.go @@ -5,6 +5,7 @@ import ( mafmt "github.com/whyrusleeping/mafmt" ) +// SubtractFilter returns a filter func that filters all of the given addresses func SubtractFilter(addrs ...ma.Multiaddr) func(ma.Multiaddr) bool { addrmap := make(map[string]bool) for _, a := range addrs { @@ -16,10 +17,13 @@ func SubtractFilter(addrs ...ma.Multiaddr) func(ma.Multiaddr) bool { } } +// IsFDCostlyTransport returns true for transports that require a new file +// descriptor per connection created func IsFDCostlyTransport(a ma.Multiaddr) bool { return mafmt.TCP.Matches(a) } +// FilterNeg returns a negated version of the passed in filter func FilterNeg(f func(ma.Multiaddr) bool) func(ma.Multiaddr) bool { return func(a ma.Multiaddr) bool { return !f(a) diff --git a/p2p/net/swarm/swarm_dial.go b/p2p/net/swarm/swarm_dial.go index c1b3a73..33b087e 100644 --- a/p2p/net/swarm/swarm_dial.go +++ b/p2p/net/swarm/swarm_dial.go @@ -390,9 +390,6 @@ func (s *Swarm) dialAddrs(ctx context.Context, p peer.ID, remoteAddrs <-chan ma. continue } - // limitedDial will start a dial to the given peer when - // it is able, respecting the various different types of rate - // limiting that occur without using extra goroutines per addr s.limitedDial(ctx, p, addr, respch) active++ case <-ctx.Done(): @@ -403,7 +400,7 @@ func (s *Swarm) dialAddrs(ctx context.Context, p peer.ID, remoteAddrs <-chan ma. case resp := <-respch: active-- if resp.Err != nil { - log.Error("got error on dial: ", resp.Err) + log.Info("got error on dial: ", resp.Err) // Errors are normal, lots of dials will fail exitErr = resp.Err @@ -417,6 +414,9 @@ func (s *Swarm) dialAddrs(ctx context.Context, p peer.ID, remoteAddrs <-chan ma. } } +// limitedDial will start a dial to the given peer when +// it is able, respecting the various different types of rate +// limiting that occur without using extra goroutines per addr func (s *Swarm) limitedDial(ctx context.Context, p peer.ID, a ma.Multiaddr, resp chan dialResult) { s.limiter.AddDialJob(&dialJob{ addr: a, diff --git a/package.json b/package.json index 5af7297..70d1bf2 100644 --- a/package.json +++ b/package.json @@ -1,4 +1,5 @@ { + "name":"go-libp2p", "author": "whyrusleeping", "bugs": { "url": "https://github.com/ipfs/go-libp2p" -- GitLab