Skip to main content

moq_net/
lib.rs

1//! # moq-net: Media over QUIC networking layer
2//!
3//! `moq-net` is the networking layer for Media over QUIC: real-time pub/sub with built-in
4//! caching, fan-out, and prioritization, on top of QUIC. Sub-second latency at massive scale.
5//! At session setup it negotiates one of two wire protocols: the simplified `moq-lite`
6//! protocol (the default) or the full IETF `moq-transport` protocol.
7//!
8//! ## API
9//! The API is built around Producer/Consumer pairs, with the hierarchy:
10//! - [origin::Consumer]: A collection of [broadcast::Consumer]s, produced by one or more [Session]s.
11//! - [broadcast::Consumer]: A collection of [track::Consumer]s, produced by a single publisher.
12//! - [track::Consumer]: A collection of [group::Info]s, delivered out-of-order until expired.
13//! - [group::Info]: A collection of [frame::Info]s, delivered in order until cancelled.
14//! - [frame::Info]: Chunks of data with an upfront size.
15//!
16//! Each level lives in its own module (`broadcast`, `track`, `group`, `frame`, `origin`,
17//! `announce`) that owns the short `Producer` / `Consumer` / `Info` names.
18//!
19//! Traffic counters for the levels above live in [`stats`]: build a [`stats::Registry`]
20//! and hand each session a [`stats::Handle`] via [`Client::with_stats`] /
21//! [`Server::with_stats`]. Publishing the counters as MoQ broadcasts lives in the
22//! `moq-stats` crate.
23//!
24//! ## Compatibility
25//! The API exposes the intersection of features supported by both protocols, intentionally
26//! keeping it small rather than polluting it with half-baked features.
27//!
28//! The library is forwards-compatible with the full IETF specification and supports
29//! moq-transport drafts 14+ via version negotiation. Everything will work perfectly,
30//! so long as your application uses the API as defined above.
31//!
32//! For example, there's no concept of "sub-group". When connecting to a moq-transport
33//! implementation, we use `sub-group=0` for all frames and silently drop any received
34//! frames not in `sub-group=0`. If your application genuinely needs multiple sub-groups,
35//! tell me *why* and we can figure something out.
36//!
37//! ## Producers and Consumers
38//! Each level of the hierarchy is split into a Producer / Consumer pair:
39//! - The **Producer** is the writer: it appends new state (publishes a broadcast,
40//!   starts a group, writes frames, closes a track).
41//! - The **Consumer** is a reader: each consumer holds its own independent view
42//!   of the producer's state, with its own cursor through the stream.
43//!
44//! Both halves are cheaply clonable so you can hand out multiple handles. Cloning
45//! a consumer creates another reader (each at its own cursor); cloning a producer
46//! gives another writer that contributes to the same shared state. Closing the
47//! last producer signals consumers that no more updates are coming.
48//!
49//! ## Async
50//! This library is async-first. [`Client::connect`] and [`Server::accept`] return a
51//! `(Session, Driver)` pair: the [`Session`] is the handle, and the [`Driver`] is
52//! the future that runs all of its protocol work. Nothing is spawned behind your
53//! back: spawn the driver on your executor, await it in place, or step
54//! [`Driver::poll`] with a [`kio::Waiter`] from your own `poll_*` function. The
55//! driver holds no session handle, so the transport still closes when the last
56//! [`Session`] clone drops (or on [`Session::abort`]), which in turn finishes the
57//! driver.
58//!
59//! The crate has no direct tokio dependency: every future is built on [`kio`]
60//! (plain [`std::task::Waker`] plumbing) and `futures`, so any executor can poll
61//! them, and the `poll_xxx` counterparts can be stepped synchronously with a
62//! [`kio::Waiter`].
63//!
64//! The one remaining runtime tie is time. Timers go through `web_async::time`,
65//! which is backed by tokio's time driver on native (and `wasmtimer` in the
66//! browser), and those timers panic when polled outside a tokio runtime. So on
67//! native you still need a tokio runtime to poll a [`Driver`] (bandwidth sampling,
68//! the control stream timeout, and subscription linger all sleep); purely
69//! model-layer methods (tracks, groups, frames, origins) never touch a timer and
70//! run on any executor.
71
72#![warn(missing_docs)]
73
74mod client;
75mod coding;
76mod error;
77mod ietf;
78mod lite;
79mod model;
80mod path;
81mod server;
82mod session;
83mod setup;
84mod util;
85mod version;
86
87pub mod stats;
88
89pub use client::*;
90pub use coding::{BoundsExceeded, DecodeError, EncodeError, VarInt};
91pub use error::*;
92/// The session direction a client advertises in its SETUP (moq-lite-05+).
93pub use lite::Role;
94pub use model::*;
95pub use path::*;
96pub use server::*;
97pub use session::*;
98pub use version::*;
99
100// Re-export the bytes crate
101pub use bytes;
102
103// Re-export the transport trait, since it bounds the Client/Server entry points.
104pub use web_transport_trait;
105
106// Re-export the kio crate, since it appears in the public API (e.g. poll_* waiters).
107pub use kio;