-
Notifications
You must be signed in to change notification settings - Fork 3
feat: support WebRTC transport for libp2p client and server #2
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
base: master
Are you sure you want to change the base?
Conversation
lexnv
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job here @timwu20! 🙏
Is the WebRTC working as expected for:
- litep2p <-> litep2p
- libp2p <-> litep2p?
Well since litep2p can't dial via WebRTC we won't be able to test that unless we decide to implement it. I'm getting decode errors on the litep2p/str0m side when running the libp2p client with the litep2p server. After making changes locally to str0m, I'm now getting a panic from the litep2p side after the ICE handshake. Still debugging and will likely make changes to litep2p and str0m after I get it working locally. |
|
That sounds like great progress! I'm expecting indeed some subtle incompatibility to surface after updating the str0m crate |
libp2p/Cargo.toml
Outdated
| libp2p-tls = "0.5.0" | ||
| libp2p-noise = "0.45.0" | ||
| libp2p-yamux = "0.46.0" | ||
| libp2p = { git = "https://github.com/timwu20/rust-libp2p", rev = "8bdee16f4dc345eb2a4d63246bb8739f16353cc3", features = ["dns", "identify", "kad", "macros", "mdns", "noise", "ping", "tcp", "tokio", "yamux", "websocket", "request-response"] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dq: Do we need to introduce any changes to the rust-libp2p crates? Is something not working there? 🤔
I would ask the maintainers for some help with releasing if that's the case 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need rust-libp2p to use webrtc.rs version 0.13.0 or later. Otherwise the libp2p dialer crashes during connection establishment with this error:
2025-11-12T04:52:01.683603Z INFO webrtc::peer_connection: ICE connection state changed: connected
thread 'tokio-runtime-worker' (2592172) panicked at /Users/haiko/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/generic-array-0.14.7/src/lib.rs:572:9:
assertion `left == right` failed
left: 32
right: 16
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Tim opened libp2p/rust-libp2p#6186 for this but then had to shift focus to something else and the PR wasn't merged due to CI failures. I've taken over all WebRTC related work from Tim and will try to move this forward (or more likely open a new PR since webrtc.rs 0.14.0 has been released in the meantime.)
I'm also currently working on adding WebRTC tests to run_bandwidth.sh.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like great progress! Thanks for tackling this 🙏
litep2p/Cargo.toml
Outdated
| futures = "0.3.28" | ||
|
|
||
| litep2p = { version = "0.10.0", features = ["websocket", "webrtc"] } | ||
| litep2p = { git = "https://github.com/timwu20/litep2p", rev = "9fb09abd77f88450f673c40e51b57aa0c7f4d358", features = ["websocket", "webrtc"] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need a new litep2p including the changes from:
Or is this more of a work-in-progress testing harness? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we need at least the str0m upgrade from that fork. I'm also trying to move paritytech/litep2p#441 forward but it seems a bit stuck atm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's get libp2p/rust-libp2p#6186 merged and released. The changes look good to me, and we can build upon them in multiple PRs.
Once we have rust-libp2p released and working without panics/issues with litep2p via:
We can bake a new litep2p release and focus on any surfacing issues/smoldot incompatibilities 🙏
|
@lexnv I've made the following changes to the PR: Switched to ChainSafe forks of libp2p & litep2p for WebRTC dependenciesThe litep2p one is temporary until paritytech/litep2p#465 is merged and a new release is cut. For the libp2p one we agreed to deprioritize getting a release with webrtc.rs 0.13 and that it is acceptable to point to a fork for now. Set the keep alive timeout in the litep2p WebRTC listener to 5 minutesI've seen logs saying that this timeout was hit and the connection downgraded. I think there is some interaction with this change I made in my litep2p PR causing the connection to be closed instead of just marked inactive, but I might be wrong. In any case, that change is a temporary one, before we tackle gracefully closing substreams with the flags in the protobuf frame. Updated
|
|
Oki doki that sounds about right! Could you open a few issues in litep2p around those occurrences 🤔 ? I think we'd need to take a closer look in the future as it might affect the connection stability. While at it, I remember you mentioning a few issues with the current webrtc:
Could you open up a few issues for those as well? So we can link to them in the Webrtc milestone in litep2p 🙏 Once we get the WebRTC fully compatible and stable with smoldot, we should pull the changes via a local |
|
@haikoschol I can see from the rust-libp2p branch that we are not running with the latest webrtc crate, is there something wrong there? In other words, the litep2p implementation should function only with 0.13 as opposed to 0.14? 🤔 |
Yes, I briefly tried 0.14, but with that I couldn't even connect a libp2p dialer to a libp2p listener. I didn't debug this further since I was focused on getting the script to run to completion. I did mean to mention it in my summary comment, but apparently forgot. I think it's some interaction with transitive dependencies, maybe related to DTLS. There's a lot of 0.x stuff being pulled in. :-/ Will look into it again. |
You mean related to the keep-alive timeout? I'm not sure yet what exactly needs to be done, if anything. It is probably covered by the performance related issue I've linked to below. If I get a better idea of it I'll create another issue if necessary.
I'm not sure what you are referring to. Maybe this change related to calling
opened paritytech/litep2p#477
opened paritytech/litep2p#476 |
TransportLayerenum inClientOptsandServerOptsin libp2p implementation utilizingrust-libp2pnative implementation of WebRTC transport.libp2p-webrtc.libp2p-webrtc.