p2p/net/swarm: dial - filter out own addrs
This commit is contained in:
parent
5c3adb60cf
commit
23cf9d6fa5
|
@ -39,17 +39,23 @@ func (s *Swarm) Dial(ctx context.Context, p peer.ID) (*Conn, error) {
|
|||
log.Warning("Dial not given PrivateKey, so WILL NOT SECURE conn.")
|
||||
}
|
||||
|
||||
remoteAddrs := s.peers.Addresses(p)
|
||||
// make sure we can use the addresses.
|
||||
remoteAddrs = addrutil.FilterUsableAddrs(remoteAddrs)
|
||||
if len(remoteAddrs) == 0 {
|
||||
return nil, errors.New("peer has no addresses")
|
||||
}
|
||||
// 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")
|
||||
}
|
||||
|
||||
// open connection to peer
|
||||
d := &conn.Dialer{
|
||||
LocalPeer: s.local,
|
||||
|
|
Loading…
Reference in New Issue