Transport Abstraction & Custom Transports
rings-core has zero hard-coded dependency on WebRTC, TURN, or OS sockets. Instead, peer
connectivity lives in crates/transport behind object-safe async traits, decoupled configuration
descriptors, and runtime contracts provided by crates/runtime.
Decoupled trait boundary (rings-transport)
rings-core interacts with network links solely through crates/transport/src/core/transport/interface.rs:
-
TransportInterface/DynTransportInterface/SharedTransport: creates outbound connections, accepts inbound handshake steps, and registers the swarm’sInnerTransportCallbackwithout exposing ICE, SDP, or WebRTC types to the DHT or replay state machines. -
ConnectionInterface/DynConnection: owns connection lifecycle,max_message_size()(must satisfyMIN_MAX_MESSAGE_SIZE = 6145bytes so widest unchunked control payloads fit whole), four ordered credit-boundedChannelLanechannels, and the multi-step handshake driver. -
NodeNetworkParameters&NetworkConfigDescriptor:crates/node/src/processor/config.rsbridges a tagged YAML/JSON descriptor:network: kind: webrtc params: ice_servers: "stun://stun.l.google.com:19302" external_ip: null udp_port_range: [40000, 40100]with
webrtcregistered by default (derived automatically from top-levelice_servers,external_ip, andudp_port_min/udp_port_maxwhennetworkis omitted). External embedders can register alternative transport implementations (for example QUIC, BLE, or packet radio) viaNetworkConfigDescriptorwithout patchingrings-core.
Generalized 0–8 step binary handshakes
ConnectionInterface::handshake_step replaces WebRTC-specific SDP strings inside rings-core with
opaque byte payloads (DEFAULT_MAX_HANDSHAKE_STEP_BYTES = 4096, MAX_HANDSHAKE_STEPS = 8) driven
by the three-variant HandshakeStep state machine:
| Pattern | Initiator emissions | Responder emissions | Example transport |
|---|---|---|---|
| 0-step (pre-provisioned) | Done | Done | Pre-shared / connectionless link |
| 1-step (unidirectional announce) | SendFinal(m1) | Done | Single-message announce |
| 2-step (offer / answer) | Send(offer) → Done | SendFinal(answer) | WebRTC SDP offer/answer |
| 3-step (mutual challenge) | Send(m1) → SendFinal(m3) | Send(m2) → Done | Noise XX or authenticated key exchange |
Each step carries (step_index, final_step, session_id) inside the overlay handshake frame so
concurrent crossing offers tie-break cleanly and session keys can rotate two-phase across transport
rebuilds.
Built-in transport backends
- Native WebRTC (
native-webrtc,webrtc = "0.17.3"):- Supports STUN and UDP/TCP TURN servers (
turn://,turns://,?transport=tcp). - Includes a built-in TURN-over-TCP/TLS bridge (
crates/transport/src/connections/native_webrtc/turn_tcp.rs) usingtokio-rustls+webpki-rootsto bridge WebRTC ICE over TCP and TLS (3478/5349) whenever OS UDP is blocked or?transport=tcpis requested. - Supports bounded
IceCandidateTiersettling and container-bridge filtering so candidate gathering does not stall on phantom virtual interfaces.
- Supports STUN and UDP/TCP TURN servers (
- Browser WebRTC (
web-sys-webrtc):- Drives browser
RTCPeerConnectionandRTCDataChannelwith quiet-window ICE settling so strict NAT/mobile hosts settle promptly without waiting for a full timeout.
- Drives browser
- In-memory test transport (
dummy):- Deterministic, socket-free simulation transport gated out of production
ringsbinaries via compile-time checks, used by multi-node convergence and sync-storm test suites.
- Deterministic, socket-free simulation transport gated out of production
Runtime isolation (rings-runtime)
crates/runtime isolates task spawning (Spawner), join handles (TaskSet), timers (sleep),
and MaybeSendSync bounds across Tokio multi-thread/current-thread executors on native hosts and
single-threaded WebAssembly (wasm-bindgen-futures) in browsers.
Related chapters
- Transport Flow Control — 4-lane credit windows,
NodeFramePool, and liveness probes - How handshake works — end-to-end handshake paths and glare tie-breaking
- TURN Server & Onion TURN — stateless UDP/TCP TURN and Onion TURN integration