enigma-transport-webrtc

Crates.ioenigma-transport-webrtc
lib.rsenigma-transport-webrtc
version0.1.1
created_at2025-12-15 11:47:57.654325+00
updated_at2025-12-15 13:51:15.892766+00
descriptionWebRTC transport bindings for Enigma secure messaging sessions
homepagehttps://github.com/Gladius33/enigma-transport-webrtc
repositoryhttps://github.com/Gladius33/enigma-transport-webrtc
max_upload_size
id1985886
size101,558
Sébastien TLX (Gladius33)

documentation

https://docs.rs/enigma-transport-webrtc

README

enigma-transport-webrtc

A byte-level transport crate that wraps a single WebRTC DataChannel and exposes a deterministic mock for testing. The scope is limited to creating offers/answers, sharing ICE candidates, and moving opaque bytes; signaling, encryption, and higher-level framing stay with the embedding application.

Scope & non-goals

  • Byte delivery only: transports raw &[u8] payloads over a single binary data channel.
  • No signaling or persistence: the crate consigns offer/answer/candidate exchange to the caller.
  • No ENP1/ENM1 or cryptography: those responsibilities live outside this transport.

ByteTransport handshake quickstart

  1. Instantiate a transport (real or mock) and call create_offer() on the initiator.
  2. Send the returned SDP through the caller’s signaling layer and feed the remote side with accept_offer().
  3. Apply the answer generated by the accepter via accept_answer() on the initiator.
  4. Relay any LocalIceCandidate events emitted through next_event() back to the peer via add_ice_candidate().
  5. Once the underlying DataChannel opens, next_event() also emits Connected, and the connected transports can start calling send()/recv().
use enigma_transport_webrtc::{MockTransport, ByteTransport};

#[tokio::main]
async fn main() {
    let (mut alice, mut bob) = MockTransport::pair(16);
    let offer = alice.create_offer().await.unwrap();
    let answer = bob.accept_offer(&offer).await.unwrap();
    alice.accept_answer(&answer).await.unwrap();
    alice.send(b"ping").await.unwrap();
    let pong = bob.recv().await.unwrap();
    assert_eq!(pong, b"ping");
}

ICE and state events

  • Poll next_event() for TransportEvent::LocalIceCandidate and send those JSON blobs over your signaling channel.
  • TransportEvent::StateChanged tracks the internal state machine (Idle, CreatingOffer, WaitingAnswer, IncomingOffer, Connecting, Connected, Closed).
  • Connected fires once the data channel is open, and Closed occurs when the transport shuts down.

Mock-driven testing

  • All tests in the crate rely solely on MockTransport, which mirrors the WebRTC state machine, emits the same events, and enforces the configured max_message_size.
  • This keeps cargo test fast, deterministic, and offline-friendly.

Documentation

  • docs/api.md: ByteTransport contract, builders, and error semantics.
  • docs/design.md: State machine and event rationale.
  • docs/testing.md: Why the mock transport is the only test dependency.

Run cargo test locally to validate the mock layer and abstraction.

Commit count: 0

cargo fmt