.getPeerId() returns the peer id from a multiaddr if one is present but it may not be the one we expect.
If the mulitaddr is a relay address but doesn't have the relay client's peer id in the address, the peer id returned is that of the relay.
I believe the intention of .getPeerId is to return the peer id of the remote peer that can be dialled using the peer id, not just any peer id that happens to be in the multiaddr.
We could fix this by treating p2p-circuit as a special case and returning the value part of the p2p-circuit tuple if found, or more generally by only returning a peer id if it's in the final tuple?
.getPeerId()
returns the peer id from a multiaddr if one is present but it may not be the one we expect.If the mulitaddr is a relay address but doesn't have the relay client's peer id in the address, the peer id returned is that of the relay.
I believe the intention of
.getPeerId
is to return the peer id of the remote peer that can be dialled using the peer id, not just any peer id that happens to be in the multiaddr.We could fix this by treating
p2p-circuit
as a special case and returning the value part of thep2p-circuit
tuple if found, or more generally by only returning a peer id if it's in the final tuple?Refs: https://github.com/libp2p/js-libp2p/pull/1680