Skip to main content

Crate rtci_host

Crate rtci_host 

Source
Expand description

The host around the sans-I/O rtci WebRTC engine: everything a WebRTC implementation needs besides the protocol state machines and the JavaScript bindings.

rtci runs ICE, DTLS, SCTP, the data channels, SRTP and RTP as state machines that never open a socket, arm a timer or read the clock. This crate gives each Peer (one RTCPeerConnection) its sockets, timers, STUN/TURN clients (UDP, TCP, TLS), ICE-TCP, mDNS, media packetizing and frame assembly, the fake capture devices, and the queue of events for the front end. It was extracted from the Denext-Deno fork’s ext/webrtc; the fork’s built-in extension and the rtci-ffi library are its two front ends.

Two traits stand between the engine and the network:

  • NetGate, the permission gate: every address the engine sends to, every IP it binds on and the machine’s interface list are asked of it first. There is no allowing default (DenyAllGate refuses all). A gate may answer later (AskGate): the engine holds back whatever needed the answer, and Peer::set_remote_description / Peer::add_ice_candidate finish through an opdone event (JsEvent::OpDone).
  • NetIo, the socket factory: the only place sockets are created and names resolved, each call carrying the GateToken of the allow it needs. PlainNetIo uses the operating system’s.

§Threading

The engine is single-threaded (Rc / RefCell). It spawns !Send tasks on the current thread: run it on a current-thread tokio runtime (as Deno does), or inside a tokio::task::LocalSet.

Modules§

media_types
The media types the front ends pass and receive (transceivers, tracks, codecs, capabilities, frames).

Structs§

AskGate
An asynchronous gate answered by ticket. Deny by default: until AskGate::attach every question is refused at once (NO_GATE_REGISTERED). Once attached, each question the engine asks queues a GateRequest (AskGate::take_requests) and runs the notifier (AskGate::set_notify); AskGate::answer delivers the verdict. An answer is remembered and reused for the same question from any connection on this gate (NetGate::decide).
CandidateArg
RTCIceCandidateInit.
CertificateInfo
An RTCCertificate for the front end’s JavaScript.
CertificateStore
The RTCCertificates of a realm, by id: each holds a key and an X.509 certificate for the DTLS handshakes of the connections given it. The front end removes an entry when its RTCCertificate is garbage collected; a connection keeps its own copy.
ConfigArg
RTCConfiguration, as the front end’s JavaScript passes it.
CreatedChannel
A created data channel: its engine handle and its stream id, when assigned.
DataChannelArg
createDataChannel(label, init).
DenyAllGate
Refuses everything.
Error
A failure of an rtci-host call: its kind and message.
FingerprintInfo
One RTCDtlsFingerprint.
GateRequest
One question for the front end: the gaterequest event.
GateToken
Proof that the gate allowed a Reach: every NetIo call that creates a socket or resolves a name takes one. Only the engine mints them (there is no public constructor), from an allow for the Reach the call is for, so a NetIo implementation may check GateToken::reach against its arguments.
IceServerArg
One RTCIceServer.
IceServerSpec
A STUN or TURN server URL from RTCConfiguration.iceServers, parsed and permission-checked by the constructor.
IceTimeoutsArg
IceTransport
KeygenArg
generateCertificate’s algorithm (WebCrypto’s dictionaries).
Network
NetworkArg
NetworkOptions
PairCandidate
One candidate of SelectedPair, with the fields JavaScript needs to build the RTCIceCandidate (a peer-reflexive remote candidate is exposed without its address, so it can’t be found among the signalled ones).
Payload
A received payload’s bytes (a data channel message, an RTP packet, a frame). Serializes as bytes.
Peer
PeerDescriptions
The four description slots of a connection, each (type, sdp).
PeerOptions
Options for Peer::new, from RTCConfiguration.
PlainNetIo
The operating system’s sockets and resolver, unrouted.
PortRangeArg
PublicAddress
A public address and the private one it maps to (None: every private address).
Reach
One thing the engine wants to reach.
SelectedPair
The ICE agent’s selected candidate pair.
SharedEndpoint
One of a shared port’s sockets.
TcpEndpoint
One of an ICE-TCP network’s listeners.
UdpOpts
How NetIo::bind_udp binds.

Enums§

Direction
Whether a Reach sends to an address or binds one.
ErrorKind
Which exception a failure is, as the W3C WebRTC specs name them.
Host
A host a Reach names: a name (an ICE server URL’s host, before DNS) or an IP address.
IceEvent
An event for JavaScript, delivered in batches by op_webrtc_ice_next_events.
JsEvent
An event for JavaScript, delivered in batches by Peer::next_events. Data channels are named by their engine handle (channel), which exists before the SCTP stream id does.
MdnsMode
What a connection does with mDNS .local host candidates.
Proto
The transport of a Reach.
ReachKind
Why the engine asks (for logs and prompts; a gate may also decide on it). The engine’s cache of asked answers ignores the kind: an answer for one kind is reused for another with the same direction, transport, host, port and resolved_from.
ServerTransport
How a STUN/TURN client reaches its server.
Verdict
A gate’s answer.

Constants§

DEFAULT_ASK_TIMEOUT
How long the engine waits for an asked answer by default (NetGate::ask_timeout).
NO_GATE_REGISTERED
The refusal for every question asked before AskGate::attach.

Traits§

NetGate
The net permission gate. There is no allowing default: every Peer, Network and IceTransport is given one, and DenyAllGate refuses everything.
NetIo
The socket factory.

Functions§

certificate_fingerprints
The certificate’s fingerprints, in each algorithm the engine computes.
certificate_from_pem
The inverse of certificate_to_pem; anything else is a SyntaxError.
certificate_to_pem
Deno.webrtc.exportCertificate: the key and certificate as PEM, with the expires time, to keep a server’s DTLS fingerprint across restarts.
check_ice_servers
Asks gate for each server’s host and port before DNS (ReachKind::IceServer); the first refusal is a ErrorKind::NotCapable error.
engine_log_level
The engine’s log level (off by default: its outcomes are RTCPeerConnection events). A host’s logger shows engine records at or above it, and no others.
epoch_fields_relative
One stats dictionary with its epoch fields made relative to wall_ms, the wall clock (milliseconds since the epoch) when the report was asked for: JavaScript adds the Performance time of that moment, so the timestamps are DOMHighResTimeStamps on performance.timeOrigin’s timeline (W3C webrtc-stats, hr-time) whatever the wall clock does.
expires_ms
The W3C expires, a DOMTimeStamp: whole milliseconds since the epoch.
fake_media_devices
Whether the fake capture devices are on (DENO_FAKE_MEDIA_DEVICES=1).
generate_certificate
The DTLS key: ECDSA P-256 (what browsers default to), or RSASSA-PKCS1-v1_5 with SHA-256 and the public exponent 65537 (WebCrypto’s algorithm dictionaries, as generateCertificate takes them). CPU-heavy for RSA: call it off the engine’s thread.
is_engine_log_target
Whether a log record comes from the WebRTC engine (the rtci and rtci_* crates), whose records set_engine_log_level governs. This crate’s own records (rtci_host::*) are not the engine’s: they follow the host’s log filter, as they did inside the Deno extension.
mdns_socket
Finishes an mDNS socket (IPv4, UDP): reuse options and the bind on 0.0.0.0:5353 unless bound (a socket handed out bound already, as a sandbox broker does), non-blocking, multicast TTL 255 with loopback, and the mDNS group joined on each non-loopback IPv4 address of hosts (on the default interface when none joins). For NetIo::bind_mdns implementations.
needs_tls
Whether any server needs TLS (turns: / stuns:): the front end then builds PeerOptions::tls.
parse_ice_servers
Parses every URL of RTCConfiguration.iceServers (the W3C SyntaxError / InvalidAccessError checks); no gate is asked.
set_engine_log_level
Sets the engine’s log level by name: off, error, warn, info, debug or trace (a ErrorKind::Type error for any other).

Type Aliases§

LocalBoxFuture
A boxed, !Send future (the engine is single-threaded).
Result
Result with this crate’s Error.