node-device-session 7.6.212

Shared server for /econ-v1/device-session/1 behind transport-neutral traits (C-5)
Documentation
//! Shared device-session server (C-5): transport-neutral `/econ-v1/device-session/1`.
//!
//! Carriers implement [`SessionStreams`] + [`HostBus`] and call [`serve`].
//! Pass [`WebRtcSignaling`] when the carrier can answer `webrtc.signal/1`
//! (iroh); otherwise that method is refused with `unsupported_transport`.
//! Iroh-specific pieces (QUIC `ProtocolHandler`, WebRTC media path, session
//! registry/push) stay in `node-app-iroh`.

#![deny(missing_docs)]

mod messages;
mod serve;
mod stream_wire;
mod traits;
mod tunnel;
mod types;
mod wire;

pub use messages::{OpenMode, OpenOk};
pub use serve::serve;
pub use traits::{BoxRecv, BoxSend, HostBus, SessionStreams, WebRtcSignaling};
pub use types::{
    IngressSocket, Refusal, Session, SessionEnd, SessionPath, SESSION_HEADER, PATH_HEADER,
};
pub use wire::{
    decode_request, decode_response, encode_request, encode_response, peek_method, FrameError,
    ResponseError, ALPN, DEVICE_CALL_METHOD, HTTP_REQUEST_METHOD, MAX_FRAME_BYTES,
    RESPONSE_STATUS_ERR, RESPONSE_STATUS_OK, SESSION_OPEN_METHOD, SESSION_RENEW_METHOD,
    WEBRTC_SIGNAL_METHOD, WS_STREAM_METHOD,
};

/// Capability names the host bus is expected to map.
pub mod caps {
    /// `core.device_session.verify`
    pub const VERIFY: &str = "core.device_session.verify";
    /// `core.device_session.renew`
    pub const RENEW: &str = "core.device_session.renew";
    /// `core.device_session.admit_renewal`
    pub const ADMIT_RENEWAL: &str = "core.device_session.admit_renewal";
}

/// Encode an `http.request/1` body for tests and carriers.
pub fn encode_http_tunnel_request(
    method: &str,
    path: &str,
    headers: std::collections::HashMap<String, String>,
    body: &[u8],
) -> Vec<u8> {
    use base64::{engine::general_purpose::STANDARD, Engine as _};
    let request = stream_wire::StreamRequest {
        method: method.into(),
        path: path.into(),
        headers,
        body_b64: STANDARD.encode(body),
    };
    stream_wire::encode_request(&request).expect("http tunnel request encodes")
}