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_transportserve_with_registry(..., registry)— same asserve, plus live-session registration for periodic revalidationSessionRegistry/revalidate— close revoked / expired / invalid sessionswebrtc::WebRtcAnswerer+webrtc::WebRtcCarrier— shared str0m answerer
Wire methods: session.open/1, session.renew/1, device.call/1,
http.request/1, ws.stream/1, webrtc.signal/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 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 carrier = StaticWebRtcCarrier ;
let webrtc = new;
serve.await?;
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 protocol for webrtc.signal/1 is unchanged.