Expand description
SRT (Secure Reliable Transport) as specified by the Internet-Draft
draft-sharabayko-srt-01: byte-exact codecs for every data and control
packet, and sans-IO engines for the HSv5 Caller/Listener and Rendezvous
handshakes, the ARQ reliability loop (loss detection, NAK, ACK/ACKACK,
RTT), TSBPD delivery with too-late drop, and LiveCC and FileCC congestion
control. Behind features it adds the §6 payload encryption (AES-CTR, RFC 3394
key wrap, PBKDF2 key derivation, KM refresh), the one-connection
Link engine, and a tokio UDP adapter that has been checked against
a real libsrt 1.5.5 peer.
The core is no_std + alloc and reads no clock: every engine takes the
caller’s time (tick, set_elapsed, a broadcast_core::stage::Instant), and
every bound, timeout and cadence (arq::ArqBounds, io::IoConfig,
link::LinkCadence) is the caller’s. Packets the delivery engine gives up
on are reported as damage, coalesced per sequence run (damage); a
handshake that is rejected or never completes stays an error. It builds on
broadcast-core, broadcast-common and broadcast-net; broadcast-client
(the SRT caller source) and multimux (SRT input and push) build on it.
§Choosing limits
No limit struct here has a Default. Each one offers
for_profile(broadcast_core::Profile), a complete preset whose every
number is a documented constant, and a typed with_* setter per field:
| Profile | Sized for |
|---|---|
Embedded | one program, a few hundred MB of memory, 32-bit or wasm32, few elementary streams (values checked against the 256 MiB budget where exercised, #4834) |
Device | single-service playback on a phone, tablet, TV or desktop, about 30 s of read-ahead |
Server | a live origin or HLS server carrying several programs |
Headend | a whole multiplex with full SI/EPG, up to 2048 PIDs |
The presets: arq::ArqBounds, arq::ReceiverBounds, arq::SenderBounds,
io::ListenerLimits, handshake_sm::HandshakeConfig. A preset delivers
a damaged unit flagged; dropping it is the caller’s opt-in.
§Quickstart
Run a Caller/Listener handshake in memory: the bytes one side emits are parsed and fed to the other, as a transport would.
use core::time::Duration;
use srt_runtime::HandshakeConfig;
use srt_runtime::caller::{CallerHandshake, CallerHandshakeState};
use srt_runtime::handshake_sm::HandshakeOutput;
use srt_runtime::listener::{ListenerHandshake, ListenerHandshakeState};
use srt_runtime::packet::ControlPacket;
fn first_send(outputs: Vec<HandshakeOutput>) -> Option<Vec<u8>> {
outputs.into_iter().find_map(|o| match o {
HandshakeOutput::Send(bytes) => Some(bytes),
_ => None,
})
}
let mut caller = CallerHandshake::new(
0x1111_1111,
HandshakeConfig::new(
Duration::from_millis(120),
1500,
8192,
Duration::from_millis(250),
12,
)
.with_latency(Duration::from_millis(180))
.with_stream_id(Some("live/camera-1".into())),
);
// A real listener derives the SYN cookie from the peer address and a secret.
let mut listener = ListenerHandshake::new(
0x2222_2222,
0xC0FF_EE42,
HandshakeConfig::new(
Duration::from_millis(120),
1500,
8192,
Duration::from_millis(250),
12,
).with_latency(Duration::from_millis(250)),
);
let mut to_listener = caller.start().unwrap();
for _ in 0..10 {
let pkt = ControlPacket::parse(&to_listener).unwrap();
let Some(reply) = first_send(listener.feed(&pkt).unwrap()) else { break };
let pkt = ControlPacket::parse(&reply).unwrap();
match first_send(caller.feed(&pkt).unwrap()) {
Some(next) => to_listener = next,
None => break,
}
}
assert_eq!(caller.state(), CallerHandshakeState::Connected);
assert_eq!(listener.state(), ListenerHandshakeState::Connected);
// Both sides agree on the greater of the two latencies.
assert_eq!(caller.negotiated().unwrap().latency, Duration::from_millis(250));§How do I…
- Parse and re-serialize an SRT packet:
SrtPacket,packet::ControlPacket,examples/packet_round_trip.rs. - Run a Caller/Listener handshake without sockets:
CallerHandshake,ListenerHandshake,HandshakeConfig,examples/handshake_loopback.rs. - Recover lost packets with NAK and retransmission:
arq::Sender,arq::Receiver,examples/arq_loss_recovery.rs. - Read an
srt://URL (stream id, latency, mode, passphrase):SrtUrl,examples/parse_url.rs. - Connect over UDP with tokio:
io::SrtListener,io::SrtSocket,io::SrtSocketConfig,examples/udp_loopback.rs. - Encrypt the payload with a passphrase:
handshake_sm::CryptoConfig,HandshakeConfig::with_crypto,examples/udp_loopback.rs. - Size the socket receive buffer:
broadcast_net::net::UdpOptions,io::SrtSocket::recv_buffer_size; no example yet (the README section “Sizing the receive buffer” gives the rule). - Connect two peers in Rendezvous mode:
RendezvousHandshake,RendezvousRole; no example yet. - Drive one connection from your own socket loop:
Link,CallerLink,Delivered; no example yet. - Release data on its delivery time:
tsbpd::TsbpdScheduler; no example yet. - Pace a sender:
livecc::LiveCC,filecc::FileCc; no example yet.
§Modules
Wire format: packet (every data and control packet and handshake
extension), url (feature std, the srt:// URL).
Handshakes: handshake_sm (the shared configuration, outputs and
negotiated parameters), caller, listener, rendezvous, cookie
(feature link, the Listener’s SYN cookie).
Reliability and timing: arq (sender, receiver, sequence arithmetic,
RTT), tsbpd (delivery scheduler), livecc and filecc
(congestion control), damage (drops as damage reports).
Encryption (feature crypto): crypto (AES-CTR, key wrap, key
derivation), km_refresh (SEK rotation).
Connections: link (feature link, one connection as a sans-IO engine),
io (feature tokio, the UDP adapter).
Errors: error.
§Feature flags
std(default): the standard library andSrtUrl; without it the crate isno_std+alloc.serde:Serializeon the public wire types.crypto: payload encryption, the handshake key exchange and KM refresh.link: theLinkandCallerLinkengines and the SYN cookie; impliescrypto.tokio: theioUDP adapter; impliesstdandlink.
§Spec citations
draft-sharabayko-srt-01 §3 (packet structure), §4.3.1 (Caller/Listener),
§4.3.2 (Rendezvous), §4.5 to §4.7 (TSBPD and too-late drop), §4.8 and §4.10
(ARQ and RTT), §5.1 (LiveCC), §5.2 (FileCC), §6 (encryption)
(private/specs-verified/ietf/specs/ietf_draft_sharabayko_srt_01.txt); RFC
3394 (private/specs-verified/ietf/srt-runtime/rfc3394-aes-key-wrap.md);
RFC 8018 PBKDF2 (private/specs-verified/ietf/srt-runtime/rfc8018-pbkdf2.md).
Re-exports§
pub use caller::CallerHandshake;pub use caller::CallerHandshakeState;pub use error::Error;pub use error::Result;pub use handshake_sm::HandshakeConfig;pub use handshake_sm::HandshakeOutput;pub use handshake_sm::NegotiatedParams;pub use handshake_sm::RejectionReason;pub use link::CallerLink;linkpub use link::CallerParams;linkpub use link::Delivered;linkpub use link::DeliveredItem;linkpub use link::Link;linkpub use link::LinkCounts;linkpub use link::LinkEnd;linkpub use link::LinkSetup;linkpub use link::Payload;linkpub use listener::ListenerHandshake;pub use listener::ListenerHandshakeState;pub use packet::SrtPacket;pub use rendezvous::RendezvousHandshake;pub use rendezvous::RendezvousHandshakeState;pub use rendezvous::RendezvousRole;pub use url::SrtUrl;std
Modules§
- arq
- SRT ARQ (Automatic Repeat reQuest) reliability engine —
draft-sharabayko-srt-01§4.8 (Acknowledgement and Lost Packet Handling), §4.8.1 (Packet Acknowledgement — ACKs, ACKACKs), §4.8.2 (Packet Retransmission — NAKs), §4.10 (Round-Trip Time Estimation). Curated behavioural rules:private/specs-verified/rules/srt-arq.md. The wire field layouts this module drives (ACK/NAK/ACKACK) are the existingcrate::packetcodecs — this module never re-encodes them, it only decides when to build one and what to do with one received. - caller
- Caller-side handshake engine —
draft-sharabayko-srt-01§4.3.1 (Caller-Listener Handshake), Caller role. - cookie
link - The SYN Cookie and the Listener’s stateless identifiers —
draft-sharabayko-srt-01§4.3.1.1 (“a cookie that is crafted based on host, port and current time with 1 minute accuracy”;private/specs-verified/rules/srt-rules.md). - crypto
crypto - SRT payload encryption —
draft-sharabayko-srt-01§6 (“Encryption”). - damage
- Turning the delivery engine’s drops into the workspace’s one damage report.
- error
- Error type for SRT packet parsing and serialization.
- filecc
- SRT File Transfer Congestion Control (FileCC) — window-based congestion
control,
draft-sharabayko-srt-01§5.2 (curated atprivate/specs-verified/rules/srt-congestion.md). - handshake_
sm - Shared types for the sans-IO HSv5 handshake state machine —
draft-sharabayko-srt-01§4.3 (Handshake Messages) / §4.3.1 (Caller-Listener Handshake). - io
tokio - Async real-socket UDP adapter over the sans-IO SRT engine.
- km_
refresh crypto - SEK-rotation (“KM Refresh”) driver —
draft-sharabayko-srt-01§6.1.6 (KM Refresh), curated atprivate/specs-verified/rules/srt-crypto.md(“KM Refresh — §6.1.6”). - link
link - One SRT connection as a sans-IO link: datagrams and the caller’s
nowin, datagrams to send and delivered payloads out. - listener
- Listener-side handshake engine —
draft-sharabayko-srt-01§4.3.1 (Caller-Listener Handshake), Listener role. - livecc
- SRT Live Congestion Control — packet pacing (
draft-sharabayko-srt-01§5.1, curated atprivate/specs-verified/rules/srt-livecc.md). - packet
- SRT packet structure —
draft-sharabayko-srt-01§3 (Packet Structure). - presets
- The
broadcast_core::Profilepresets of this crate’s bounds. Every number is a documented constant used only by afor_profilebody; the caller replaces any field through its typedwith_*setter. - rendezvous
- Rendezvous handshake engine —
draft-sharabayko-srt-01§4.3.2 (Rendezvous Handshake), curated atprivate/specs-verified/rules/srt-rendezvous.md. Line cites below (LNNNN) are the source draft’s line numbers, exactly as recorded in that curation. - tsbpd
- Instant-Based Packet Delivery (TSBPD) + Too-Late Packet Drop — SRT receiver-side delivery scheduling.
- url
std - The
srt://URL a caller dials (draft-sharabayko-srt-01 §3.2.1.3 Stream ID; the scheme itself is SRT’s registered URL form).
Constants§
- SPEC
- The Internet-Draft this crate implements packet structure from.