Commit 9b4d42f7 authored by Juan Batiz-Benet's avatar Juan Batiz-Benet

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

parent 7aa4a83f
......@@ -39,16 +39,22 @@ func (s *Swarm) Dial(ctx context.Context, p peer.ID) (*Conn, error) {
log.Warning("Dial not given PrivateKey, so WILL NOT SECURE conn.")
}
// get our own addrs
localAddrs := s.peers.Addresses(s.local)
if len(localAddrs) == 0 {
log.Debug("Dialing out with no local addresses.")
}
// get remote peer addrs
remoteAddrs := s.peers.Addresses(p)
// make sure we can use the addresses.
remoteAddrs = addrutil.FilterUsableAddrs(remoteAddrs)
// drop out any addrs that would just dial ourselves. use ListenAddresses
// as that is a more authoritative view than localAddrs.
remoteAddrs = addrutil.Subtract(remoteAddrs, s.ListenAddresses())
if len(remoteAddrs) == 0 {
return nil, errors.New("peer has no addresses")
}
localAddrs := s.peers.Addresses(s.local)
if len(localAddrs) == 0 {
log.Debug("Dialing out with no local addresses.")
}
// open connection to peer
d := &conn.Dialer{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment