Skip to content
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

webrtc: wrong peer id when connecting to peer via relay #5453

Open
dariusc93 opened this issue Jun 7, 2024 · 4 comments
Open

webrtc: wrong peer id when connecting to peer via relay #5453

dariusc93 opened this issue Jun 7, 2024 · 4 comments

Comments

@dariusc93
Copy link
Member

dariusc93 commented Jun 7, 2024

Summary

When attempting to connect to a peer (from the browser) through a relay with webrtc-direct transport, it gives a WrongPeerId. This seems to happen because it is reporting/expecting the relay peer id instead the actual peer id whom we are connecting to via relay, likely coming from the outbound upgrade in webrtc-websys.

Expected behavior

Connect to peer over relay

Actual behavior

Errors with wrong peer id when attempting to connect to remote peer via relay

Relevant log output

/home/darius/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libp2p-swarm-0.44.2/src/lib.rs:843 Connection attempt to peer failed with WrongPeerId { obtained: PeerId("12D3KooWSsn13GxHchpG6dtr7o6ARqSkcMtsBuojgL9XU9t1M1uE"), endpoint: Dialer { address: "/ip4/XXX.XXX.XXX.XXX/udp/XXXX/webrtc-direct/certhash/uEiAX9LacN1_nm3t-qLg7Ap7g3GMiAoJgWTPwfueva3xdlg/p2p/12D3KooWSsn13GxHchpG6dtr7o6ARqSkcMtsBuojgL9XU9t1M1uE/p2p-circuit/p2p/12D3KooWR8YyQ3TxpkdS6QYNDjC18XtyqBxwaPGVMGraDmpmchqQ", role_override: Dialer } }. peer = 12D3KooWR8YyQ3TxpkdS6QYNDjC18XtyqBxwaPGVMGraDmpmchqQ;

Possible Solution

If intended, might be worth to document this until browser-to-browser is implemented (which may be the best solution), otherwise, we might need to report the correct peer id when connecting over relay (would need to evaluate other libp2p impl in how they handle relay v2 with webrtc-direct)

Version

0.53

Would you like to work on fixing this bug ?

Maybe

@sqrtsanta
Copy link

I have a similar problem, with a setup like this:

node1 (in browser) based on rust-libp2p as wasm with websocket_sys & webrtc_sys
node2 as a relay with websocket transport + quic
node3 connecting to relay with quic transport and webrtc

I want node1 to connect to relay (websocket) which then will share information with node3 so that I end up with direct webrtc connection between node1 & node3.

From node1 I'm trying to connect to /ip4/IP/tcp/PORT/ws/p2p/RELAY_PEER_ID/p2p-circuit/webrtc-direct/certhash/HASH/p2p/NODE3_PEER_ID. I see that it's connected to relay (devtools > ws), but unable to connect to node3: error: WrongPeerId.

It this setup even feasible? And if not, what would be correct way, so that I end up with direct connection between node1 & node3 (given that both are behind NAT)?

I'm using master branch for rust-libp2p since currently it's 0.53.0 on Cargo, but 0.54.0 on github

@dariusc93
Copy link
Member Author

Hey @sqrtsanta. If youre using another transport like websocket, tcp, or quic, you do not need to include webrtc-direct/certhash/HASH/ in apart of the relay. Instead you would use (in your case) /ip4/IP/tcp/PORT/ws/p2p/RELAY_PEER_ID/p2p-circuit/p2p/NODE3_PEER_ID.

@sqrtsanta
Copy link

sqrtsanta commented Jul 30, 2024

@dariusc93 Thanks for answer, unfortunately it still doesn't work. Does node3 - relay connection have to be same transport as node1 - relay, e.g. webrtc or websocket? Or can it be arbitrary like quic?

@dariusc93
Copy link
Member Author

@dariusc93 Thanks for answer, unfortunately it still doesn't work. Does node3 - relay connection have to be same transport as node1 - relay, e.g. webrtc or websocket? Or can it be arbitrary like quic?

If youre doing it from the browser then unfortunately it would have to be websocket. In other words, your public relay would have to be listening on websocket (either ws or wss) with your browser connecting to that specific node at that address and establish a reservation.

For webrtc, I have already concluded that to use the relay it would require browser-to-browser (unless this was a bug in the design - hard to say for sure but based on js and go impl i assume its not a bug but could be wrong).

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

No branches or pull requests

2 participants