Roman Borschel 6ad05b0ff1
[libp2p-swarm] Ignore a node's own addresses on dialing. (#1646)
* Ignore a node's own addresses on dialing.

Dialing attempts of a local node to one of its own
addresses for what appears to be a different peer
ID are futile and bound to fail with an `InvalidPeerId`
error. To avoid such futile dialing attempts, filter
out the node's own addresses from the addresses
reported by the `NetworkBehaviour` for any peer.

There can be a few reasons why a `NetworkBehaviour` may
think an address belongs to a different peer, e.g.:

  1. In the context of e.g. `libp2p-kad`, the local node
     may have changed its network identity (e.g. key rotation)
     and "discovers" its former identity in the DHT, with the same
     address(es).
  2. Another peer may erroneously or intentionally, possibly even maliciously,
    report one of the local node's addresses as its own, making the node
    try to connect to itself.

Relates to https://github.com/paritytech/stakingops-issues/issues/18.

* Remove filtering of external addresses.

Since these are obtained from other peers, it would constitute
an attack vector. It is furthermore usually not possible for
a peer behind a NAT to dial its own external address so these
are unlikely to cause `InvalidPeerId` errors as a result of a
peer dialing itself under the expectation of one of its
former peer IDs.
2020-07-08 11:51:49 +02:00
..