Skip to main content

Crate rtc_shared

Crate rtc_shared 

Source
Expand description

Shared types and utilities for the Sans-I/O WebRTC stack.

This crate holds what every other crate in the rtc stack needs: the common Error type, the Marshal/Unmarshal traits that every protocol codec implements, and the transport plumbing that carries bytes between the network and a protocol state machine.

§Key types

  • TransportContext / TransportMessage — a datagram plus the 4-tuple and protocol it arrived on or should be sent on. Every layer in the stack passes these around instead of touching sockets.
  • marshalMarshal, Unmarshal and MarshalSize, the wire-format traits shared by STUN, RTP, RTCP, SDP, DTLS and SCTP.
  • error — the crate-wide Error enum and Result alias, re-exported by the higher-level crates so callers import from one place.
  • crypto, replay_detector — primitives shared by DTLS and SRTP.
  • tcp_framing — RFC 4571 length-prefixed framing, for ICE-TCP candidates.
  • ifaces — local interface enumeration used during ICE candidate gathering.

§Feature flags

crypto, ifaces, marshal and replay are all enabled by default; each gates the correspondingly named module so that dependents can compile only what they use.

§Example

Every protocol codec in the stack implements the same three traits, so encoding and decoding look the same whichever layer you are at:

use bytes::Bytes;
use rtc_shared::marshal::{Marshal, MarshalSize, Unmarshal};

// Size the buffer, encode into it, then decode the result back.
let n = value.marshal_size();
let encoded = value.marshal()?;
assert_eq!(encoded.len(), n);

let mut buf = Bytes::from(encoded.to_vec());
assert_eq!(T::unmarshal(&mut buf)?, value);

Most applications do not depend on this crate directly — the rtc crate re-exports what it needs as rtc::shared.

Modules§

crypto
Cryptographic primitives shared by DTLS and SRTP, including DTLS-SRTP keying-material export.
error
The crate-wide error type shared by every protocol in the stack. The error type shared across the stack.
ifaces
Local network interface enumeration, used to gather ICE host candidates.
marshal
The wire-format traits every protocol codec in the stack implements.
replay_detector
Replay protection for sequence-numbered packets, as DTLS and SRTP require.
serde
serde helpers for types that have no natural serialized form, such as std::time::Instant.
tcp_framing
TCP framing utilities for ICE over TCP (RFC 4571/RFC 6544).
time
Conversions between monotonic, Unix and NTP time. Monotonic, Unix and NTP time.
util
Small shared helpers: packet demultiplexing predicates and random-string generation. Shared helpers: packet demultiplexing and random strings.

Structs§

FiveTuple
Five Tuple consists of local address, peer address and protocol
FourTuple
Four Tuple consists of local address and peer address
TransportContext
Transport Context with local address, peer address, ECN, protocol, etc.
TransportMessage
A generic transmit with TransportContext

Enums§

EcnCodepoint
Explicit congestion notification codepoint
TransportProtocol
Type of transport protocol, either UDP or TCP

Type Aliases§

TaggedBytesMut
BytesMut type transmit with TransportContext