Skip to main content

libp2p_wasi_sockets/
lib.rs

1//! WASI 0.2 sockets transport for rust-libp2p.
2//!
3//! This crate implements [`libp2p_core::Transport`] over the `wasi:sockets/tcp` interface,
4//! enabling rust-libp2p applications to run as Wasm Components on any WASI 0.2 host
5//! (Wasmtime, Spin, jco, Wasmer) without modification to the rest of the libp2p stack.
6//!
7//! # Supported multiaddrs
8//!
9//! - `/ip4/<addr>/tcp/<port>`
10//! - `/ip4/<addr>/tcp/<port>/p2p/<peer-id>`
11//! - `/ip6/<addr>/tcp/<port>`
12//! - `/ip6/<addr>/tcp/<port>/p2p/<peer-id>`
13//!
14//! # Not supported
15//!
16//! - `/dns4`, `/dns6`, `/dnsaddr` — DNS resolution via `wasi:sockets/ip-name-lookup` is a
17//!   planned follow-up.
18//! - `/quic-v1`, `/ws`, `/wss`, `/webrtc`, `/p2p-circuit` — out of scope.
19//! - UDP — out of scope for v0.1.
20//!
21//! # Quick start
22//!
23//! ```no_run
24//! use libp2p_wasi_sockets::WasiTcpTransport;
25//!
26//! let transport = WasiTcpTransport::default();
27//! ```
28//!
29//! Build and run under Wasmtime:
30//!
31//! ```bash
32//! cargo build --release --target wasm32-wasip2
33//! wasmtime run -S inherit-network ./target/wasm32-wasip2/release/my_app.wasm
34//! ```
35//!
36//! If you omit `-S inherit-network`, all dials will fail with
37//! [`Error::AccessDenied`] — Wasmtime denies all outbound connections by default.
38
39#![cfg_attr(not(target_arch = "wasm32"), allow(dead_code, unused_imports))]
40
41mod error;
42mod multiaddr;
43mod stream;
44mod transport;
45
46pub use error::Error;
47pub use stream::WasiTcpStream;
48pub use transport::{Config, WasiTcpTransport};