Connectivity Tests
In libp2p.io, the current state of Transport implementations in each programming language is already written. But, I’ve seen there have been so many changes in rust-libp2p, as described in the rust-libp2p in 2022 blog post.
After reading the libp2p Connectivity document, I've tested if 'dialing' works for each of the following scenarios using rust-libp2p v0.51.3.
Scenario | Dialing | Transports tested |
---|---|---|
Standalone -> Standalone | Successful | TCP, WebSocket, WebRTC1 |
WASM browser -> Standalone | Successful | WebSocket2 |
WASM browser <- Standalone | Failed3 | WebSocket |
WASM browser -> WASM browser | Failed3 | WebSocket |
JS browser4 -> Standalone | Successful | WebRTC |
Private -> (Relay5) -> Private | Successful | TCP |
Private6 -> (Relay5) -> Private with Hole-punching | Failed7 | TCP |
WASM Limitations
I've found that the following features of rust-libp2p cannot be enabled for WASM.
gossipsub, mdns, dns, tokio
If WASM codes import those features, the following error occurs:
error[E0432]: unresolved import `libp2p::gossipsub`
--> core/src/p2p.rs:20:5
|
20 | gossipsub, identity,
| ^^^^^^^^^ no `gossipsub` in the root
In regard to gossipsub especially, the gossipsub has been disabled for the wasm32-unknown-unknown
target by rust-libp2p/pull/2506#issuecomment-1036448620
because of the following reasons:
- The custom
Interval
implementation in rust-libp2p wasn't performant: rust-libp2p/issues/2497. So, they decided to revert back to wasm-timer by rust-libp2p/pull/2506. -
However, the
rust-libp2p
withwasm-timer
cannot be compiled forwasm32-unknown-unknown
with the following error:
$ wasm-pack build [INFO]: 🎯 Checking for the Wasm target... [INFO]: 🌀 Compiling to Wasm... Compiling libp2p-gossipsub v0.45.0 (https://github.com/libp2p/rust-libp2p.git?branch=master#14938043) error[E0599]: no method named `checked_add` found for struct `wasm_timer::Instant` in the current scope --> /Users/yjlee/.cargo/git/checkouts/rust-libp2p-98135dbcf5b63918/1493804/protocols/gossipsub/src/peer_score.rs:872:34 | 871 | ... let window_time = validated_time | _________________________________________- 872 | | ... .checked_add(topic_params.mesh_message_deliveries_window) | | -^^^^^^^^^^^ method not found in `Instant` | |___________________________| |
rust Fortunately, it seems that we can use the instant crate instead of
wasm_timer::Instant
. This try had been done by rust-libp2p/pull/2320, but has been reverted by rust-libp2p/pull/2506 as above.But the one remaining problem was that the gossipsub needs the
Interval
struct which is also dependant on theInstant
. To resolve this, the libp2p team is thinking of contributing anInterval
implementation to thefutures-timer
crate: rust-libp2p/issues/2497#issuecomment-1038923700But, I think the easier solution would be just implementing the missing
wasm_imter::Instant.checked_add()
function above into thewasm_timer
because thewasm_timer
already provides theInterval
struct which is being used byrust-libp2p
in production. However, it seems that the libp2p the doesn't want to keep maintaining thewasm-timer
crate.
-
vincev/wasm-p2p-chat based on vincev/libp2p-websys-transport that will be included in the rust-libp2p offically ↩
-
It seems that the hole-punching is not always successful. Used AWS for relayer and listener (in private subnet with NAT), and my laptop for dialer. ↩
Top comments (0)