node-device-session
Shared server for the /econ-v1/device-session/1 wire protocol (C-5 / ADR-100).
Carriers (node-app-iroh, node-app-p2p) implement [SessionStreams] and
[HostBus], then call [serve]. This crate has no iroh (or other carrier)
dependency.
Public API
ALPN—b"/econ-v1/device-session/1"SessionStreams/HostBus/WebRtcSignalingserve(conn, bus, ingress, path, webrtc)— passSome(hook)when the carrier answerswebrtc.signal/1;Nonerefuses withunsupported_transport.wire/1is refused (wire_unavailable) unless configured via optionsserve_with_registry(..., registry)— same asserve, plus live-session registration for periodic revalidationserve_with_options(..., ServeOptions { registry, wire, .. })— additive; configure [WireSocket] and/or registry without changing the classic signaturesSessionRegistry/revalidate— close revoked / expired / invalid sessionswebrtc::WebRtcAnswerer+webrtc::WebRtcCarrier— shared str0m answerer;WebRtcAnswerer::with_wire_socketenables DataChannelwire/1WireSocket/wire_socket_path/splice_to_wire_socket— node-wire (ADR-310) splice helpers for carriers
Wire methods: session.open/1, session.renew/1, device.call/1,
http.request/1, ws.stream/1, webrtc.signal/1, wire/1.
Live-session revalidation (once a minute)
A device that is revoked, unpaired or expired after it connected must lose its live session within a minute on every carrier. Wire it like this:
- Hold one shared [
SessionRegistry] in the carrier app. - Accept connections with [
serve_with_registry] (plain [serve] is unchanged and does not register). - In
WebRtcCarrier::bind_session, callregistry.bind_webrtc(&identity.device_id, handle.clone())so a later revoke also tears down the WebRTC path. - Expose a capability such as
<app>.device.revalidateand register a cron row whose trigger is that capability on schedule0 * * * * *(every minute). The handler callsregistry.revalidate(&bus).await.
Only definitive verify refusals (device_revoked, expired,
invalid_credential, endpoint_mismatch) close a session.
verifier_unavailable, timeouts and other errors leave it open.
Wiring the shared WebRTC answerer
The answerer owns signaling, ICE (str0m), DataChannel framing, and the
http.request/1 / ws.stream/1 / wire/1 tunnels over those channels. A
carrier only supplies what is carrier-specific via [WebRtcCarrier]:
| Carrier concern | Trait method |
|---|---|
| STUN server list (no TURN) | stun_servers() |
| Optional ICE UDP bind | bind_addr() |
| Router / UPnP / relay portmap | port_mapper() + mapping_description() |
| Clock for str0m / ICE | now() (default: Instant::now()) |
| Bind handle into session registry | bind_session(...) |
Iroh-only adapters (gossip discovery → STUN list, RelaySessionPortMapper)
stay in node-app-iroh and implement the trait. p2p does the same with its
own STUN / portmap sources. Neither carrier reimplements the answerer.
use ;
use Arc;
// Inside the carrier's ProtocolHandler / accept path:
let ingress = new;
let wire = new;
let carrier = StaticWebRtcCarrier ;
let webrtc = new;
let mut options = default;
options.wire = .clone;
serve_with_options
.await?;
Carriers that do not need wire/1 keep calling
serve / serve_with_registry and WebRtcAnswerer::new unchanged.
For revocation / replace, override WebRtcCarrier::bind_session to store the
[WebRtcHandle] in the carrier's session registry and return false when the
session cannot accept WebRTC. Call handle.close() on revoke.
wire/1 (node-wire)
After a full session.open/1, a bi-stream (QUIC) or DataChannel (WebRTC)
labelled wire/1 splices onto the configured [WireSocket] with the ADR-310
preamble (carrier = relay / webrtc, no peer). Renewal-only sessions
refuse with renewal_only and never touch the socket. Carriers that pass no
wire path (the default) keep prior HTTP/WS-only behaviour; wire/1 is refused
with wire_unavailable.
Wire protocol for webrtc.signal/1 is unchanged.