Skip to content

fix: encapsulate /p2p-circuit multiaddrs when dialing a known peerid #1680

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 14, 2023
Merged

fix: encapsulate /p2p-circuit multiaddrs when dialing a known peerid #1680

merged 6 commits into from
Apr 14, 2023

Conversation

joeltg
Copy link
Contributor

@joeltg joeltg commented Apr 12, 2023

The logic for creating a dial target tries to ensure multiaddrs are encapsulated with /p2p/${peerId} IF the dial target's peer id is known. It uses addr.getPeerId() != null to check if this is already the case.

> multiaddr("/ip4/127.0.0.1/tcp/4001/p2p/12Dfoo...").getPeerId()
'12Dfoo...'

However, circuit relay addresses return the relay server's peer id if they don't end in /p2p/${destinationPeerId}.

> multiaddr("/ip4/127.0.0.1/tcp/4001/p2p/12D3bar.../p2p-circuit").getPeerId()
'12D3bar...'

Since the dialer then thinks the multiaddr already has a peer id, it doesn't encapsulate with /p2p/${destinationPeerId}, which ultimately results in failed dials to circuit relay destinations (Circuit relay dial failed as addresses did not have peer id). If I understand things right, the desired behavior is for circuit relay addresses to get encapsulated with the destination peer id.

joeltg added 2 commits April 12, 2023 19:14
The logic for creating a dial target is intended to ensure multiaddrs are encapsulated with `/p2p/${peerId}` IF the dial target's peer id is known. It uses `addr.getPeerId()` to check if this is already the case.

```
> multiaddr("/ip4/127.0.0.1/tcp/4001/p2p/12D3...").getPeerId()
'12D3...'
```

However, circuit relay addresses return the **relay server's** peer id if they don't end in `/p2p/${destinationPeerId}`.

```
> multiaddr("/ip4/127.0.0.1/tcp/4001/p2p/12D3.../p2p-circuit").getPeerId()
'12D3...'
```

Since the dialer then thinks the multiaddr already has a peer id, it doesn't encapsulate with `/p2p/${destinationPeerId}`, which ultimately results in failed dials to circuit relay destinations with error `ERR_RELAYED_DIAL` (`Circuit relay dial failed as addresses did not have peer id`). If I understand things right, the desired behavior is for circuit relay addresses to get encapsulated with the destination peer id.
@joeltg
Copy link
Contributor Author

joeltg commented Apr 14, 2023

Just want to bump this since I'm now confident this is breaking all dials to circuit-relay addresses, at least on our network. @achingbrain if you could take a look at this, I'd be really grateful 💜

@achingbrain achingbrain merged commit 4078082 into libp2p:master Apr 14, 2023
@achingbrain
Copy link
Member

achingbrain commented Apr 14, 2023

Thanks! This fix is available via the next tag - could you try it out and let me know if it fixes the problem? I'll do a release if so.

There's a short upgrade guide to follow but it should be relatively painless unless you are doing a lot of custom stuff with the connection manager.

$ npm i libp2p@next

@joeltg
Copy link
Contributor Author

joeltg commented Apr 14, 2023

That works! Thank you so much!

@joeltg joeltg deleted the patch-1 branch April 14, 2023 14:30
@achingbrain
Copy link
Member

This has been released in [email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants