Skip to main content

Module relay

Module relay 

Source
Expand description

Thin WebSocket relay — the v1 browser↔mesh bridge.

A browser tab cannot open a raw socket or listen; its only outbound P2P primitive is a WebSocket. So a browser peer reaches the world through a relay: a plain WS server that a browser dials and that forwards its pub/sub traffic. This is deliberately thin — it carries no libp2p stack into the browser. The browser speaks the same RelayFrame wire protocol over web-sys/gloo-net WebSocket; this module is the native server + a native client (used for tests and native-to-native links).

“Native servers are their own relays”: any native node runs serve_bridged beside its mesh, which cross-forwards the relay’s topics with the libp2p gossipsub mesh — so a browser that dials a native node is injected straight into the real mesh, and mesh traffic flows back out to the browser. The pure hub (serve) is the browser↔browser path and is fully testable without a live mesh; the gossip bridge adds browser↔native.

Re-exports§

pub use crate::relay_proto::RelayFrame;

Structs§

RelayClient
A native relay client — and the reference for what the browser does over web-sys WebSocket with the same RelayFrame protocol.
RelayServer
A running relay server. Dropping the handle aborts the accept loop.

Functions§

serve
Start a relay (a pure WebSocket pub/sub hub) on addr (e.g. 127.0.0.1:0). This is the browser↔browser-via-relay path and needs no mesh.