@cryptotaxi247 / kubo / commits / 9b4d42f7b

p2p/net/swarm: dial - filter out own addrs

Juan Batiz-Benet committed Jan 12, 2015 at 20:51 UTC 9b4d42f7b065ad2a4a44867be3ab210159209bd9
1 file changed +10 -4
p2p/net/swarm/swarm_dial.go
+10 -4
@@ -39,16 +39,22 @@ func (s *Swarm) Dial(ctx context.Context, p peer.ID) (*Conn, error) {
39 log.Warning("Dial not given PrivateKey, so WILL NOT SECURE conn.")
40 }
41
42 + // get our own addrs
43 + localAddrs := s.peers.Addresses(s.local)
44 + if len(localAddrs) == 0 {
45 + log.Debug("Dialing out with no local addresses.")
46 + }
47 +
48 + // get remote peer addrs
49 remoteAddrs := s.peers.Addresses(p)
50 // make sure we can use the addresses.
51 remoteAddrs = addrutil.FilterUsableAddrs(remoteAddrs)
52 + // drop out any addrs that would just dial ourselves. use ListenAddresses
53 + // as that is a more authoritative view than localAddrs.
54 + remoteAddrs = addrutil.Subtract(remoteAddrs, s.ListenAddresses())
55 if len(remoteAddrs) == 0 {
56 return nil, errors.New("peer has no addresses")
57 }
48 - localAddrs := s.peers.Addresses(s.local)
49 - if len(localAddrs) == 0 {
50 - log.Debug("Dialing out with no local addresses.")
51 - }
58
59 // open connection to peer
60 d := &conn.Dialer{