Skip to content

Mismatch with the usage of fully and non-fully qualified multiaddr (/p2p suffix) #4573

Closed
@stormshield-frb

Description

Summary

There seems to be no uniformization with the use of fully-qualified multiaddr (ie. with p2p suffix). This leads to unfortunate side-effects.

For example, like it was mentionned in #2280, multiaddr are stored fully-qualified in kad behaviour, but they are stored not fully-qualified in identify behaviour.

The identify case

In identify, the cache is constructed with addresses received from the listen_addrs fields which do not contains the /p2p/ part (due to back and forth conversions between MultiAddr and SocketAddr).

However, removal of such addresses occurrs on DialError

FromSwarm::DialFailure(DialFailure { peer_id, error, .. }) => {
if let Some(entry) = peer_id.and_then(|id| self.discovered_peers.get_mut(&id)) {
if let DialError::Transport(errors) = error {
for (addr, _error) in errors {
entry.remove(addr);
}
}
}
}

and on ConnectionEstablished::failed_addresses

if let Some(entry) = self.discovered_peers.get_mut(&peer_id) {
for addr in failed_addresses {
entry.remove(addr);
}
}

with fully-qualified multiaddr. This result in addresses never being removed since /ip4/127.0.0.1/tcp/4001/p2p/Qm... does not match /ip4/127.0.0.1/tcp/4001.

The kad case

With the current implementation of the kademlia behaviour, events like ConnectionEstablished and DialError always contain fully-qualified multiaddr.

But the application can also manually add multiaddresses into the k-bucket (with the add_address method) : if we call add_address with a fully-qualified multiaddr it will successfully be removed when a DialError occurrs, but if we call add_address with a non-fully-qualified multiaddr it will never be removed (it might be an expected behaviour for a bootnode for example, we are not sure about it).

Also, non-fully-qualified addresses already present will be duplicated (with /p2p suffix) on a ConnectionEstablished event as a dialer.

Expected behaviour

We would expect to have a coherent behaviour when using multiaddr with or without /p2p/ suffix.

It would be nice if the documentation specify whether we should provide fully or non-fully qualified addresses (and the possible side effect if there is any).

Actual behaviour

Mixed of full and non-full qualified leads to addresses never being removed from the identify cache and the DHT.

Possible Solution

The identify case

We have two possible solutions to this problem :

  1. ensure that only fully-qualified multiaddr are inserted into the cache
  2. keep non-fully-qualified multiaddr in the cache but remove them accordingly

The kad case

Ensure that we always insert fully-qualified multiaddr when calling add_address.

Version

  • libp2p version : 0.52.3

Would you like to work on fixing this bug?

Yes. We already started to work to address this issue. You can find a proof of concept in the following commit : d63cd80

This was made as a starting point for a discussion.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions