From 8afa21accf6699cbac73de3ba7859521da5c0955 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 7 Nov 2026 23:31:11 -0800 Subject: [PATCH 1/7] chore(quest): claim quest/m2/api-shape/net.md Quest-Claim: 97db455105bc7704 From 3f80ce736cc54881fb399713f18507d6e7461ed8 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 7 Nov 2026 23:53:48 -0800 Subject: [PATCH 2/7] refactor(net)!: one spelling for client origin, versions, admission, refusals, datagram priority, routes, and attempts Co-Authored-By: Claude Opus 5.5 --- doc/bin/relay/index.md | 4 +- doc/concept/stats.md | 2 +- doc/lib/rs/index.md | 2 +- js/net/src/origin.test.ts | 12 +++ js/net/src/origin.ts | 12 ++- rs/moq-auth/src/mesh/mod.rs | 18 ++-- rs/moq-boy/src/main.rs | 2 +- rs/moq-c/src/publish.rs | 9 +- rs/moq-c/src/test.rs | 16 +-- rs/moq-cli/src/args.rs | 6 +- rs/moq-cli/src/main.rs | 12 +-- rs/moq-crypto/src/e2ee/datagram.rs | 7 +- rs/moq-crypto/tests/transport.rs | 2 +- rs/moq-ffi/src/datagram.rs | 10 +- rs/moq-ffi/src/test.rs | 3 +- rs/moq-net/MIGRATE.md | 6 +- rs/moq-net/benches/admission.rs | 10 +- rs/moq-net/src/auth.rs | 2 +- rs/moq-net/src/auth/tokens.rs | 99 ++++++++--------- rs/moq-net/src/client.rs | 15 ++- rs/moq-net/src/model/datagram.rs | 36 ++++++- rs/moq-net/src/model/origin.rs | 41 ++++++- rs/moq-net/src/reconnect.rs | 76 +++++++------ rs/moq-net/src/reconnect/tests.rs | 4 +- rs/moq-net/src/server.rs | 40 +++---- rs/moq-net/src/stats/outcomes.rs | 24 ++--- rs/moq-net/src/version.rs | 18 +++- rs/moq-net/tests/integration/support/mod.rs | 15 +-- rs/moq-relay/benches/http_idle.rs | 10 +- rs/moq-relay/src/cluster.rs | 15 ++- rs/moq-relay/src/connection.rs | 6 +- rs/moq-relay/src/internal.rs | 4 +- rs/moq-relay/src/listener.rs | 18 ++-- rs/moq-relay/src/listener/idle.rs | 6 +- rs/moq-relay/src/relay.rs | 16 +-- rs/moq-relay/src/shutdown.rs | 32 +++--- rs/moq-relay/src/web.rs | 20 ++-- rs/moq-relay/src/websocket.rs | 14 +-- rs/moq-relay/tests/integration/refusals.rs | 2 +- rs/moq-tokio/src/client.rs | 25 +---- rs/moq-tokio/src/connection.rs | 5 +- rs/moq-tokio/src/server.rs | 102 +++++++++--------- rs/moq-tokio/src/tcp.rs | 2 +- rs/moq-tokio/src/websocket.rs | 20 ++-- rs/moq-tokio/tests/integration/broadcast.rs | 12 +-- .../tests/integration/datagram_tracks.rs | 5 +- rs/moq-tokio/tests/integration/migrate.rs | 3 +- rs/moq-uring/src/quic/driver/connection.rs | 2 +- rs/moq-uring/src/quic/driver/endpoint.rs | 6 +- rs/moq-uring/src/quic/endpoint.rs | 6 +- rs/moq-uring/tests/integration/endpoint.rs | 18 ++-- rs/moq-webrtc/src/p2p/mod.rs | 2 +- rs/moq-webrtc/src/p2p/tests.rs | 6 +- test/interop/clients/rust/tail.rs | 5 +- 54 files changed, 472 insertions(+), 393 deletions(-) diff --git a/doc/bin/relay/index.md b/doc/bin/relay/index.md index fe2ce4f07e1..d507bf3451c 100644 --- a/doc/bin/relay/index.md +++ b/doc/bin/relay/index.md @@ -96,8 +96,8 @@ relay.with_web(web).run().await?; example to leave DNS before draining, call `with_signals(false)` and fire `shutdown_trigger()` yourself. The drain reaches only MoQ sessions, so stop any extra listener (RTMP, SRT, ...) on your own deadline. -- To serve MoQ from your own `moq_tokio::server::Config`, set its `activity` - from `relay.shutdown().activity()` and pass `relay.shutdown().clone()` to +- To serve MoQ from your own `moq_tokio::server::Config`, set its `admission` + from `relay.shutdown().admission()` and pass `relay.shutdown().clone()` to `Connection::with_shutdown`, so the drain waits for its handshakes too. - To serve a session from any other moq-net transport, such as the in-memory one in tests, enable the `test-support` feature, read its SETUP with `moq_net::Server::accept_request` and pass diff --git a/doc/concept/stats.md b/doc/concept/stats.md index 3c54f1d5650..27594f763cd 100644 --- a/doc/concept/stats.md +++ b/doc/concept/stats.md @@ -402,7 +402,7 @@ should prefer the canonical name and fall back to the legacy one. "requests": 3, "sessions_started": 12, "sessions_ended": 10, "sessions": 12, "sessions_closed": 10, "sent_bytes": 1048576, "received_bytes": 524288, - "sessions_refused": { "refused": 0, "unavailable": 0, "request": 0, "forbidden": 0, "lan": 0, "expired": 0 }, + "sessions_refused": { "refused": 0, "unavailable": 0, "request": 0, "forbidden": 0, "membership": 0, "expired": 0 }, "sessions_failed": { "idle_timeout": 1, "transport": 0, "application": 0, "expired": 0 }, "announces_peak": 40, "subscriptions_peak": 900, "wire_tx": 2048, "wire_rx": 1024 diff --git a/doc/lib/rs/index.md b/doc/lib/rs/index.md index 86c2c9c425e..b370db1566c 100644 --- a/doc/lib/rs/index.md +++ b/doc/lib/rs/index.md @@ -61,7 +61,7 @@ let origin = moq_tokio::origin::spawn(); let client = moq_tokio::connect::Config::default().init(Default::default())?; let url = url::Url::parse("https://cdn.moq.dev/anon")?; // Reconnects on its own; `closed()` resolves when it gives up. -let session = client.with_origin(origin.clone()).connect(url); +let session = client.with_publisher(&origin).with_subscriber(origin.clone()).connect(url); // Subscribe: wait for a route, resolve the broadcast at its path, read the catalog. let consumer = origin.consume(); diff --git a/js/net/src/origin.test.ts b/js/net/src/origin.test.ts index 77833c9937b..044f75542b7 100644 --- a/js/net/src/origin.test.ts +++ b/js/net/src/origin.test.ts @@ -2493,6 +2493,18 @@ test("a higher epoch of a dynamic route supersedes a cheaper local broadcast of origin.close(); }); +test("a route refuses a minted instance", async () => { + const origin = new Producer(); + const minted = { instance: Instance.minted() }; + expect(() => origin.route(Path.from("camera"), minted)).toThrow(); + expect(() => origin.routePrefix(Path.from("room"), minted)).toThrow(); + const claim = origin.routePrefix(Path.from("lobby")); + const requests = claim.requested(); + origin.consume().request(Path.from("lobby/alice")); + const asked = await requests.next(); + expect(() => asked.value.route(minted)).toThrow(); +}); + test("a higher epoch that is not the best route still supersedes a local broadcast", async () => { const origin = new Producer(); const path = Path.from("camera"); diff --git a/js/net/src/origin.ts b/js/net/src/origin.ts index a54395e7076..95236ea5d3d 100644 --- a/js/net/src/origin.ts +++ b/js/net/src/origin.ts @@ -342,6 +342,13 @@ function received(entry: RouteEntry): boolean { return !entry.originated; } +/** Refuse a named instance a relay minted for one announcement: it names no stream. */ +function refuseMinted(options: RouteOptions): void { + if (options.instance !== undefined && Instance.isMinted(options.instance)) { + throw new Error("a minted instance names no stream to route"); + } +} + /** What a peer cannot be served through: a received route, or one of another instance than it pinned. */ function unservable(instance: Instance.Valid | undefined): (entry: RouteEntry) => boolean { if (instance === undefined) return received; @@ -1279,8 +1286,7 @@ export interface RouteOptions { * epoch wins over every older one of the instance, cheaper or not. Naming an instance grants * nothing: publishing still needs the path's grant. * - * Do not start a named instance with `~`: that marks one a relay minted (see - * {@link Instance.isMinted}), which signing refuses to bind and a catalog's instance check skips. + * A {@link Instance.isMinted | minted} instance names no stream, so routing under one throws. */ instance?: Instance.Valid; /** Which incarnation of {@link instance} this is; raise it on each restart. Ignored without an instance. */ @@ -1433,6 +1439,7 @@ export class Producer implements Table { publishPath(path); const created = this.#state.created; if (!created) throw new Error("origin is closed"); + refuseMinted(options); // Normalized first, so a bad cost throws before anything is created. let info = WireRoute.normalize({ instance: options.instance ?? Instance.random(), @@ -1559,6 +1566,7 @@ export class Producer implements Table { * {@link route} instead, so subscribers can enumerate them. */ routePrefix(prefix: Path.Valid, options: RouteOptions = {}): Route { + refuseMinted(options); const info = WireRoute.normalize({ instance: options.instance, epoch: options.epoch, diff --git a/rs/moq-auth/src/mesh/mod.rs b/rs/moq-auth/src/mesh/mod.rs index 6c155b8cd24..e313a1f80a4 100644 --- a/rs/moq-auth/src/mesh/mod.rs +++ b/rs/moq-auth/src/mesh/mod.rs @@ -39,10 +39,11 @@ pub use coordinator::*; /// The context string every [`Proof`] signature starts with, so a signature made for /// enrollment can never be replayed as anything else the endpoint key signs. -pub const PROOF_CONTEXT: &[u8] = b"moq-mesh-enroll-00"; +const PROOF_CONTEXT: &[u8] = b"moq-mesh-enroll-00"; /// The length of a challenge in bytes. -pub const CHALLENGE_LEN: usize = 32; +#[cfg_attr(not(feature = "serve"), allow(dead_code, reason = "only the coordinator issues challenges"))] +pub(crate) const CHALLENGE_LEN: usize = 32; const SIGNATURE_LEN: usize = 64; @@ -51,7 +52,7 @@ const SIGNATURE_LEN: usize = 64; /// /// The URL binds the proof to one coordinator, so a coordinator the device trusts cannot /// relay another's challenge and enroll the device's key there. -pub fn proof_message(base: &url::Url, challenge: &[u8]) -> Vec { +fn proof_message(base: &url::Url, challenge: &[u8]) -> Vec { let base = audience(base); let mut message = Vec::with_capacity(PROOF_CONTEXT.len() + base.len() + challenge.len() + 2); message.extend_from_slice(PROOF_CONTEXT); @@ -71,7 +72,7 @@ fn audience(base: &url::Url) -> &str { #[serde_as] #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct Challenge { - /// [`CHALLENGE_LEN`] bytes, opaque to the device, base64url without padding. + /// 32 bytes, opaque to the device, base64url without padding. #[serde_as(as = "serde_with::base64::Base64")] pub challenge: Vec, /// When the coordinator stops accepting a proof over it, unix seconds. @@ -79,8 +80,11 @@ pub struct Challenge { pub expires: kio::clock::Wall, } -/// Proof that the caller holds `endpoint`'s secret key: its signature over -/// [`proof_message`] for a challenge the coordinator issued and has not yet seen used. +/// Proof that the caller holds `endpoint`'s secret key: its signature over a challenge the +/// coordinator issued and has not yet seen used. +/// +/// The signed message is `moq-mesh-enroll-00`, a zero byte, the coordinator's base URL as +/// the device addressed it without a trailing slash, a zero byte, then the raw challenge. #[serde_as] #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct Proof { @@ -89,7 +93,7 @@ pub struct Proof { /// The challenge, as issued. #[serde_as(as = "serde_with::base64::Base64")] pub challenge: Vec, - /// The Ed25519 signature over [`proof_message`]. + /// The Ed25519 signature over the challenge, bound to the coordinator's base URL. #[serde_as(as = "serde_with::base64::Base64")] pub signature: Vec, } diff --git a/rs/moq-boy/src/main.rs b/rs/moq-boy/src/main.rs index 157553d1e91..d008533de14 100644 --- a/rs/moq-boy/src/main.rs +++ b/rs/moq-boy/src/main.rs @@ -293,7 +293,7 @@ async fn run(config: &Config) -> Result<()> { tracing::info!(url = %moq_tokio::RedactedUrl::new(&url), %name, broadcast = %broadcast_path, "connecting to relay"); - let reconnect = client.with_origin(origin).connect(url); + let reconnect = client.with_publisher(&origin).with_subscriber(origin).connect(url); // Set up catalog and encoders. let catalog = moq_mux::catalog::Producer::new(&mut route.broadcast().clone(), moq_mux::catalog::Config::default())?; diff --git a/rs/moq-c/src/publish.rs b/rs/moq-c/src/publish.rs index 1940ed24fff..2b076835319 100644 --- a/rs/moq-c/src/publish.rs +++ b/rs/moq-c/src/publish.rs @@ -1948,7 +1948,7 @@ impl Publish { pub fn datagrams_demand(&mut self, track: Id, callback: OnStatus) -> Result { let entry = self.datagrams.get(track).ok_or(Error::TrackNotFound)?; - let producer = entry.producer.clone(); + let mut producer = entry.producer.clone(); let alive = entry.alive.consume(); let (task, mut close) = Task::new(callback); let id = self.datagram_demand.insert(DatagramDemand { @@ -1967,7 +1967,12 @@ impl Publish { biased; _ = &mut close => return Ok(()), _ = alive.closed() => return Ok(()), - priority = kio::wait(|waiter| producer.poll_priority(waiter, priority)) => priority, + next = kio::wait(|waiter| loop { + let next = std::task::ready!(producer.poll_priority_changed(waiter)); + if next != priority { + return std::task::Poll::Ready(next); + } + }) => next, }; } }) diff --git a/rs/moq-c/src/test.rs b/rs/moq-c/src/test.rs index 13304162ecb..d199fb2ca9b 100644 --- a/rs/moq-c/src/test.rs +++ b/rs/moq-c/src/test.rs @@ -2358,13 +2358,14 @@ fn raw_track_publish_consume() { /// Wait until a datagram producer has a reader. fn wait_datagram_reader(track: u32) { - let datagrams = State::lock() + let mut datagrams = State::lock() .publish .datagram_producer(Id::try_from(track).unwrap()) .expect("a datagram track"); - let reader = kio::wait(|waiter| match datagrams.poll_priority(waiter, None) { - std::task::Poll::Ready(Some(_)) => std::task::Poll::Ready(()), - _ => std::task::Poll::Pending, + let reader = kio::wait(|waiter| loop { + if std::task::ready!(datagrams.poll_priority_changed(waiter)).is_some() { + return std::task::Poll::Ready(()); + } }); crate::ffi::RUNTIME .block_on(async { kio::clock::timeout(TIMEOUT, reader).await }) @@ -2483,9 +2484,10 @@ fn a_datagram_only_track_is_read() { dg_cb.ptr, ) }); - let reader = kio::wait(|waiter| match datagrams.poll_priority(waiter, None) { - std::task::Poll::Ready(Some(_)) => std::task::Poll::Ready(()), - _ => std::task::Poll::Pending, + let reader = kio::wait(|waiter| loop { + if std::task::ready!(datagrams.poll_priority_changed(waiter)).is_some() { + return std::task::Poll::Ready(()); + } }); crate::ffi::RUNTIME .block_on(async { kio::clock::timeout(TIMEOUT, reader).await }) diff --git a/rs/moq-cli/src/args.rs b/rs/moq-cli/src/args.rs index 3f79060000d..2214bcf25cd 100644 --- a/rs/moq-cli/src/args.rs +++ b/rs/moq-cli/src/args.rs @@ -3214,11 +3214,7 @@ mod tests { // As a set: a choice list reads ascending, and that ordering is a presentation call. // Every wire code moq-net parses, including the opt-in `-wip` drafts. - let codes = (0xff0dad00..=0xff0dadff).chain(0xff000000..=0xff0000ff); - let mut expected: Vec<&str> = codes - .filter_map(hang::moq_net::Version::from_code) - .map(|version| version.as_str()) - .collect(); + let mut expected: Vec<&str> = hang::moq_net::Version::ALL.iter().map(|version| version.as_str()).collect(); expected.sort_unstable(); let mut found = Vec::new(); walk(Cli::spec().root, &mut found); diff --git a/rs/moq-cli/src/main.rs b/rs/moq-cli/src/main.rs index 0a8a4d2590b..7b19d9db060 100644 --- a/rs/moq-cli/src/main.rs +++ b/rs/moq-cli/src/main.rs @@ -56,11 +56,11 @@ impl Net { fn server( &self, config: moq_tokio::listen::Config, - activity: moq_net::server::Activity, + admission: moq_net::server::Admission, ) -> anyhow::Result { let mut server = moq_tokio::server::Config::default(); server.listen = config; - server.activity = activity; + server.admission = admission; server.quic = self.quic.clone(); Ok(server.init()?) } @@ -86,7 +86,7 @@ async fn spawn_server( .map(Into::into) .unwrap_or(moq_relay::DEFAULT_DRAIN_TIMEOUT); let (trigger, shutdown) = moq_relay::shutdown::Observer::new(window); - let server = net.server(moq.server_config(), shutdown.activity().clone())?; + let server = net.server(moq.server_config(), shutdown.admission().clone())?; let certificates = server.certificates(); let cluster = attach_lan(cluster.clone(), moq, &server)?; // The auth server or public grant a `--listen` endpoint admits through. A @@ -1077,7 +1077,7 @@ mod tests { async fn drain_ends_when_the_last_admission_leaves() { let _signals = SIGNALS.lock().await; let (trigger, mut observer) = moq_relay::shutdown::Observer::new(std::time::Duration::from_secs(10)); - let active = observer.activity().enter().unwrap(); + let active = observer.admission().enter().unwrap(); let mut signals = Signals::new().unwrap(); let shutdown = Shutdown { trigger, @@ -1098,7 +1098,7 @@ mod tests { async fn a_signal_before_the_driver_polls_drains() { let _signals = SIGNALS.lock().await; let (trigger, mut observer) = moq_relay::shutdown::Observer::new(std::time::Duration::from_secs(10)); - let session = observer.activity().enter().unwrap(); + let session = observer.admission().enter().unwrap(); let signals = Signals::new().unwrap(); // SAFETY: raise has no memory-safety preconditions. assert_eq!(unsafe { libc::raise(libc::SIGTERM) }, 0); @@ -1179,7 +1179,7 @@ mod tests { let _signals = SIGNALS.lock().await; let window = std::time::Duration::from_secs(10); let (trigger, mut observer) = moq_relay::shutdown::Observer::new(window); - let _active = observer.activity().enter().unwrap(); + let _active = observer.admission().enter().unwrap(); let mut signals = Signals::new().unwrap(); let shutdown = Shutdown { trigger, diff --git a/rs/moq-crypto/src/e2ee/datagram.rs b/rs/moq-crypto/src/e2ee/datagram.rs index 2707149443a..0a9a5157701 100644 --- a/rs/moq-crypto/src/e2ee/datagram.rs +++ b/rs/moq-crypto/src/e2ee/datagram.rs @@ -129,9 +129,10 @@ impl Producer { self.inner.priority() } - /// Resolves to [`Self::priority`] once it differs from `last`. - pub fn poll_priority(&self, waiter: &kio::Waiter, last: Option) -> Poll> { - self.inner.poll_priority(waiter, last) + /// [`priority`](Self::priority) once it differs from what this handle last returned: + /// immediately on the first call, then on each change. + pub fn poll_priority_changed(&mut self, waiter: &kio::Waiter) -> Poll> { + self.inner.poll_priority_changed(waiter) } /// Finish the track. diff --git a/rs/moq-crypto/tests/transport.rs b/rs/moq-crypto/tests/transport.rs index 6d3c7a3dbd0..8683f5645f4 100644 --- a/rs/moq-crypto/tests/transport.rs +++ b/rs/moq-crypto/tests/transport.rs @@ -131,7 +131,7 @@ async fn datagram_roundtrip(version: &str, plaintext: &[u8]) { consumer.set_priority(1); let mut priority = producer.priority(); while priority != Some(1) { - priority = kio::wait(|waiter| producer.poll_priority(waiter, priority)).await; + priority = kio::wait(|waiter| producer.poll_priority_changed(waiter)).await; } let sequence = producer.append(Timestamp::from_millis(9).unwrap(), plaintext).unwrap(); diff --git a/rs/moq-ffi/src/datagram.rs b/rs/moq-ffi/src/datagram.rs index e4be80f3139..c429a15bdbe 100644 --- a/rs/moq-ffi/src/datagram.rs +++ b/rs/moq-ffi/src/datagram.rs @@ -158,7 +158,15 @@ impl MoqDatagramProducer { /// Wait until the aggregate subscriber priority differs from `last`. pub async fn priority_changed(&self, last: Option) -> Result, MoqError> { self.inner - .wait(|producer, waiter| Poll::Ready(Ok(ready!(producer.poll_priority(waiter, last))))) + .wait(|producer, waiter| loop { + let priority = match producer.priority() { + now if now != last => now, + _ => ready!(producer.poll_priority_changed(waiter)), + }; + if priority != last { + return Poll::Ready(Ok(priority)); + } + }) .await } diff --git a/rs/moq-ffi/src/test.rs b/rs/moq-ffi/src/test.rs index 269284b3613..168ad452b22 100644 --- a/rs/moq-ffi/src/test.rs +++ b/rs/moq-ffi/src/test.rs @@ -8194,7 +8194,8 @@ async fn memory_shutdown_pair() -> (Arc, Arc) { let (client, server) = moq_net::transport::memory::pair(transport); let connect = async { let (session, driver) = moq_net::Client::new() - .with_origin(a.inner.clone()) + .with_publisher(&a.inner) + .with_subscriber(a.inner.clone()) .with_versions(version.into()) .connect(kio::clock::Instant::now(), client) .await diff --git a/rs/moq-net/MIGRATE.md b/rs/moq-net/MIGRATE.md index ae43f831715..1355e33844c 100644 --- a/rs/moq-net/MIGRATE.md +++ b/rs/moq-net/MIGRATE.md @@ -70,10 +70,10 @@ Each wrapper is now generated from its `poll_*` method, which stays available wi ### Admission completion records its own time -`server::Activity::drain()` begins closing admission once its active set empties. -`Activity::close()` and the new poll-native `poll_close()` return that instant, +`server::Admission::drain()` begins closing admission once its active set empties. +`Admission::close()` and the new poll-native `poll_close()` return that instant, even for a late observer. Replace matches against `()` with a discarded result -or read the returned `kio::clock::Instant`. Once draining begins, the last `Active` +or read the returned `kio::clock::Instant`. Once draining begins, the last `Admitted` drop closes admission synchronously, including when a close wait was cancelled. This is native listener bookkeeping; the protocol wire is unchanged. diff --git a/rs/moq-net/benches/admission.rs b/rs/moq-net/benches/admission.rs index 41db17e7b52..dd2c0502c26 100644 --- a/rs/moq-net/benches/admission.rs +++ b/rs/moq-net/benches/admission.rs @@ -9,14 +9,14 @@ use std::{sync::Barrier, time::Instant}; use criterion::{BenchmarkId, Criterion, Throughput, criterion_group, criterion_main}; -use moq_net::server::Activity; +use moq_net::server::Admission; fn admission(c: &mut Criterion) { let mut group = c.benchmark_group("server_admission"); for workers in [1, 4, 16] { for held in [0, 64, 4096] { - let activity = Activity::default(); - let _held: Vec<_> = (0..held).map(|_| activity.enter()).collect(); + let admission = Admission::default(); + let _held: Vec<_> = (0..held).map(|_| admission.enter()).collect(); group.throughput(Throughput::Elements(workers as u64)); group.bench_function(BenchmarkId::new(format!("workers={workers}"), held), |b| { b.iter_custom(|iterations| { @@ -25,11 +25,11 @@ fn admission(c: &mut Criterion) { let barrier = &barrier; let handles: Vec<_> = (0..workers) .map(|_| { - let activity = &activity; + let admission = &admission; scope.spawn(move || { barrier.wait(); for _ in 0..iterations { - drop(std::hint::black_box(activity.enter())); + drop(std::hint::black_box(admission.enter())); } }) }) diff --git a/rs/moq-net/src/auth.rs b/rs/moq-net/src/auth.rs index d49a72a1d56..854480d449f 100644 --- a/rs/moq-net/src/auth.rs +++ b/rs/moq-net/src/auth.rs @@ -48,7 +48,7 @@ use crate::{Error, Patterns, Result, SessionError, time::Instant}; mod tokens; -pub(crate) use tokens::Dial; +pub(crate) use tokens::{Dial, locate}; pub use tokens::{EmptyToken, Token, Tokens}; /// Classify malformed AUTH messages separately from transport and local failures. diff --git a/rs/moq-net/src/auth/tokens.rs b/rs/moq-net/src/auth/tokens.rs index a62344de031..258d27eabeb 100644 --- a/rs/moq-net/src/auth/tokens.rs +++ b/rs/moq-net/src/auth/tokens.rs @@ -68,7 +68,8 @@ pub struct EmptyToken; /// one has its answer, so the grant never narrows in between. /// /// [`Reconnect::with_tokens`](crate::Reconnect::with_tokens) presents them on every dial, -/// whose sessions are built on [`handle`](Self::handle); aborting the handle ends the policy. +/// whose [`Attempt::client`](crate::reconnect::Attempt::client) builds each session on +/// [`handle`](Self::handle); aborting the handle ends the policy. /// /// Cheap to clone; every clone shares one set. #[derive(Clone)] @@ -78,12 +79,9 @@ pub struct Tokens { /// What one dial presents, from [`Tokens::dial`]. pub(crate) struct Dial { - /// The URL to dial, carrying the connection credential in its query when an offered - /// version has no SETUP token. - pub(crate) url: Url, - /// The connection credential for [`Client::with_token`](crate::Client::with_token), unless - /// the URL brought its own. - pub(crate) token: Option, + /// The connection credential to present in SETUP and, where an offered version cannot + /// carry it there, the URL's query ([`locate`]), unless the URL brought its own. + pub(crate) token: Option, generation: u64, } @@ -99,7 +97,7 @@ impl Tokens { Self { handle } } - /// The handle to build each session on, with [`Client::with_auth`](crate::Client::with_auth). + /// The handle each session is built on, with [`Client::with_auth`](crate::Client::with_auth). pub fn handle(&self) -> Handle { self.handle.clone() } @@ -158,23 +156,19 @@ impl Tokens { Poll::Ready(answer(&state).expect("checked answered")) } - /// Decide what a dial to `url` offering `versions` presents, and hold every other token in - /// band on the session it builds. Call it before each dial. - pub(crate) fn dial(&self, url: &Url, versions: &crate::Versions) -> Dial { + /// Decide what a dial to `url` presents, and hold every other token in band on the + /// session it builds. Call it before each dial. + pub(crate) fn dial(&self, url: &Url) -> Dial { let mut state = self.handle.state.lock(); state.record(); let configured = state.configured.as_mut().expect("built by Tokens::new"); - let (url, setup, connection) = credential(url, versions, &configured.tokens); - let token = setup.map(|token| crate::setup::Token { - kind: crate::setup::Token::OUT_OF_BAND, - value: token.into_bytes(), - }); + let (token, connection) = credential(url, &configured.tokens); configured.dialed = Some(connection); configured.session = None; configured.unsupported = false; let generation = configured.generation; state.hold(); - Dial { url, token, generation } + Dial { token, generation } } /// The session the latest [`dial`](Self::dial) built on [`handle`](Self::handle), once it @@ -447,22 +441,25 @@ fn dedup(tokens: &[Token]) -> Vec { /// What a dial to `url` presents: the URL to dial, the token SETUP carries, and the /// connection credential, which is never also held in band. -fn credential(url: &Url, versions: &crate::Versions, tokens: &[Token]) -> (Url, Option, Option) { +fn credential(url: &Url, tokens: &[Token]) -> (Option, Option) { if let Some(jwt) = jwt(url) { // The URL's own credential (a cluster's per-peer `?jwt=`) wins, so the tokens all // ride AUTH and no second credential reaches SETUP or the query. - return (url.clone(), None, Some(jwt)); + return (None, Some(jwt)); } - let Some(first) = tokens.first() else { - return (url.clone(), None, None); - }; - // The URL is fixed before the version is negotiated, so it carries the credential - // whenever a version that may be picked could not carry it in SETUP. - let url = match versions.iter().all(|version| version.has_setup_token()) { + let first = tokens.first().map(|first| first.as_str().to_string()); + (first.clone(), first) +} + +/// `url` for a dial offering `versions` that presents `credential`. The URL is fixed before +/// the version is negotiated, so it carries the credential whenever a version that may be +/// picked could not carry it in SETUP. +#[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] +pub(crate) fn locate(url: &Url, credential: &str, versions: &crate::Versions) -> Url { + match versions.iter().all(|version| version.has_setup_token()) { true => url.clone(), - false => with_jwt(url, first.as_str()), - }; - (url, Some(first.as_str().to_string()), Some(first.as_str().to_string())) + false => with_jwt(url, credential), + } } /// The request target's query: the URL's own, or for `unix:` the one inside `?path=`. @@ -485,6 +482,7 @@ fn jwt(url: &Url) -> Option { } /// `url` with `jwt` appended to its request target's query. +#[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] fn with_jwt(url: &Url, jwt: &str) -> Url { let mut url = url.clone(); if url.scheme() != "unix" { @@ -547,10 +545,7 @@ mod tests { } fn dial(set: &Tokens, supported: bool, requests: bool) -> Session { - set.dial( - &"moqt://relay.example.com/".parse().unwrap(), - &versions(&["moq-lite-07-wip"]), - ); + set.dial(&"moqt://relay.example.com/".parse().unwrap()); let link = Link::attach(&set.handle, supported, requests).unwrap(); let credential = supported.then(|| link.present(Bytes::new(), true).unwrap()); set.connect(credential.as_ref()); @@ -710,10 +705,7 @@ mod tests { /// A session without AUTH that awaits the server's SETUP, as a moq-lite-05/06 client does. fn dial_awaiting_setup(set: &Tokens) -> Link { - set.dial( - &"moqt://relay.example.com/".parse().unwrap(), - &versions(&["moq-lite-06"]), - ); + set.dial(&"moqt://relay.example.com/".parse().unwrap()); let link = Link::attach(&set.handle, false, false).unwrap(); link.await_setup(); set.connect(None); @@ -870,38 +862,36 @@ mod tests { #[test] fn only_a_change_outdates_a_dial() { let set = Tokens::new(tokens(&["a"])); - let dial = set.dial( - &"moqt://relay.example.com/".parse().unwrap(), - &versions(&["moq-lite-07-wip"]), - ); + let dial = set.dial(&"moqt://relay.example.com/".parse().unwrap()); set.set(tokens(&["a"])); assert!(!set.changed(&dial)); set.set(tokens(&["b"])); assert!(set.changed(&dial)); } + /// The first token is the connection credential, presented in SETUP. + #[test] + fn the_first_token_is_the_connection_credential() { + let url: Url = "https://relay.example.com/room".parse().unwrap(); + let (setup, connection) = credential(&url, &tokens(&["a", "b"])); + assert_eq!(setup.as_deref(), Some("a")); + assert_eq!(connection.as_deref(), Some("a")); + } + /// Only lite-07 and moq-transport carry the credential in SETUP, so the URL stays clean. #[test] fn setup_versions_keep_the_credential_out_of_the_url() { let url: Url = "https://relay.example.com/room".parse().unwrap(); - let (dialed, setup, connection) = credential( - &url, - &versions(&["moq-lite-07-wip", "moq-transport-18"]), - &tokens(&["a", "b"]), - ); + let dialed = locate(&url, "a", &versions(&["moq-lite-07-wip", "moq-transport-18"])); assert_eq!(dialed, url); - assert_eq!(setup.as_deref(), Some("a")); - assert_eq!(connection.as_deref(), Some("a")); } - /// An offered version without a SETUP token needs the credential in the query, and the - /// same value rides SETUP too. + /// An offered version without a SETUP token needs the credential in the query. #[test] fn an_older_version_puts_the_credential_in_the_url() { let url: Url = "https://relay.example.com/room?x=1".parse().unwrap(); - let (dialed, setup, _) = credential(&url, &crate::Versions::all(), &tokens(&["a b"])); + let dialed = locate(&url, "a b", &crate::Versions::all()); assert_eq!(dialed.as_str(), "https://relay.example.com/room?x=1&jwt=a+b"); - assert_eq!(setup.as_deref(), Some("a b")); } /// A URL credential stays the connection credential, so every token rides AUTH, except @@ -910,8 +900,7 @@ mod tests { fn a_url_credential_sends_every_token_on_auth() { let url: Url = "moqt://relay.example.com/room?jwt=peer".parse().unwrap(); let set = Tokens::new(tokens(&["a", "peer", "a"])); - let dial = set.dial(&url, &crate::Versions::all()); - assert_eq!(dial.url, url); + let dial = set.dial(&url); assert_eq!(dial.token, None); assert_eq!(held(&set), ["a"]); } @@ -919,7 +908,7 @@ mod tests { #[test] fn no_tokens_present_nothing() { let url: Url = "https://relay.example.com/room".parse().unwrap(); - assert_eq!(credential(&url, &crate::Versions::all(), &[]), (url, None, None)); + assert_eq!(credential(&url, &[]), (None, None)); } /// A unix socket's request target lives in `?path=`, so the credential goes inside it. @@ -931,7 +920,7 @@ mod tests { ("unix:///tmp/moq.sock", "?jwt=a"), ] { let url: Url = url.parse().unwrap(); - let (dialed, _, _) = credential(&url, &crate::Versions::all(), &tokens(&["a"])); + let dialed = locate(&url, "a", &crate::Versions::all()); let path = dialed .query_pairs() .find(|(k, _)| k == "path") diff --git a/rs/moq-net/src/client.rs b/rs/moq-net/src/client.rs index 1b2783a4106..cd5402e86d7 100644 --- a/rs/moq-net/src/client.rs +++ b/rs/moq-net/src/client.rs @@ -17,7 +17,7 @@ pub struct Client { publish: Option, subscribe: Option, stats: stats::Session, - versions: Versions, + pub(crate) versions: Versions, url: Option, setup_token: Option, cost: Option, @@ -61,14 +61,6 @@ impl Client { self } - /// Set both publish and subscribe from one shared [`origin::Producer`]. - /// - /// Equivalent to [`with_publisher`](Self::with_publisher) and - /// [`with_subscriber`](Self::with_subscriber) with the same origin. - pub fn with_origin(self, origin: origin::Producer) -> Self { - self.with_publisher(&origin).with_subscriber(origin) - } - /// Cap what the server can make this session hold. Defaults to [`session::Limits::default`](crate::session::Limits::default). pub fn with_limits(mut self, limits: crate::session::Limits) -> Self { self.limits = limits; @@ -127,6 +119,11 @@ impl Client { self } + /// The URL [`with_url`](Self::with_url) set, if any. + pub fn url(&self) -> Option<&url::Url> { + self.url.as_ref() + } + /// The request target our SETUP carries: the dialed URL's path, plus `?` and the /// query when there is one (draft-ietf-moq-transport-22, section 9.1.2). /// diff --git a/rs/moq-net/src/model/datagram.rs b/rs/moq-net/src/model/datagram.rs index 2f7525a8551..dbb89648f37 100644 --- a/rs/moq-net/src/model/datagram.rs +++ b/rs/moq-net/src/model/datagram.rs @@ -239,6 +239,8 @@ pub struct Producer { info: Info, state: kio::Shared, stats: stats::Scope, + // The value `poll_priority_changed` last returned, or `None` before it returned any. + prev: Option>, } impl Producer { @@ -254,6 +256,7 @@ impl Producer { info: info.unwrap_or_default(), state: kio::Shared::new(state), stats: stats::Scope::default(), + prev: None, } } @@ -344,8 +347,21 @@ impl Producer { self.state.read().priority() } + /// [`priority`](Self::priority) once it differs from what this handle last returned: + /// immediately on the first call, then on each change. + #[cfg_attr(feature = "async", kio::wrapper)] + pub fn poll_priority_changed(&mut self, waiter: &kio::Waiter) -> Poll> { + let priority = match self.prev { + None => self.priority(), + Some(last) => ready!(self.poll_priority(waiter, last)), + }; + self.prev = Some(priority); + Poll::Ready(priority) + } + /// Resolves to [`Self::priority`] once it differs from `last`. - pub fn poll_priority(&self, waiter: &kio::Waiter, last: Option) -> Poll> { + #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] + pub(crate) fn poll_priority(&self, waiter: &kio::Waiter, last: Option) -> Poll> { let state = ready!(self.state.poll(waiter, |state| match state.priority() == last { true => Poll::Pending, false => Poll::Ready(()), @@ -393,6 +409,7 @@ impl Clone for Producer { info: self.info, state: self.state.clone(), stats: self.stats.clone(), + prev: None, } } } @@ -856,6 +873,23 @@ mod tests { assert!(producer.close_unused()); } + #[test] + fn priority_changed_reports_the_current_value_then_each_change() { + let waiter = kio::Waiter::noop(); + let mut producer = Info::default().produce("dg"); + assert_eq!(producer.poll_priority_changed(&waiter), Poll::Ready(None)); + assert!(producer.poll_priority_changed(&waiter).is_pending()); + let mut consumer = producer.consume(); + consumer.set_priority(4); + assert_eq!(producer.poll_priority_changed(&waiter), Poll::Ready(Some(4))); + assert!(producer.poll_priority_changed(&waiter).is_pending()); + // A clone watches on its own, starting from the current value. + let mut clone = producer.clone(); + assert_eq!(clone.poll_priority_changed(&waiter), Poll::Ready(Some(4))); + drop(consumer); + assert_eq!(producer.poll_priority_changed(&waiter), Poll::Ready(None)); + } + #[test] fn a_request_resolves_its_consumers() { let request = Request::new("dg".into()); diff --git a/rs/moq-net/src/model/origin.rs b/rs/moq-net/src/model/origin.rs index 935cd396e03..56f765351f8 100644 --- a/rs/moq-net/src/model/origin.rs +++ b/rs/moq-net/src/model/origin.rs @@ -677,14 +677,21 @@ impl RouteOptions { /// The highest epoch wins over every older one of the instance, cheaper or not. /// Naming an instance grants nothing: publishing still needs the path's grant. /// - /// Do not start a named instance with `~`: that marks one a relay minted - /// ([`Instance::is_minted`]), which moq-crypto's signing refuses to bind and a catalog's instance - /// check skips. + /// A [minted](Instance::is_minted) instance names no stream, so routing under one fails + /// with [`Error::Unsupported`]. pub fn with_instance(mut self, instance: Instance, epoch: u64) -> Self { self.instance = Some((instance, epoch)); self } + /// Refuse a named instance a relay minted for one announcement: it names no stream. + fn refuse_minted(&self) -> Result<(), Error> { + match self.instance.as_ref().is_some_and(|(instance, _)| instance.is_minted()) { + true => Err(Error::Unsupported), + false => Ok(()), + } + } + /// The route metadata these options advertise, under `instance` at `epoch`. fn info(&self, instance: &Instance, epoch: u64) -> RouteInfo { RouteInfo { @@ -2498,6 +2505,7 @@ impl Producer { /// [`Error::BoundsExceeded`] if the full rooted path exceeds /// [`Path::MAX_PARTS`] or [`Path::MAX_BYTES`], [`Error::InvalidPath`] if it holds a segment no /// pattern can spell (`*` or `**`), [`Error::NavigationSegment`] for a literal `.` or `..`, + /// [`Error::Unsupported`] if `options` names a [minted](Instance::is_minted) instance, /// or [`Error::Closed`] once the origin's /// [`Driver`] has been dropped. pub fn route(&self, path: impl TryInto>, options: RouteOptions) -> Result { @@ -2517,6 +2525,7 @@ impl Producer { /// An exact route at the absolute `full` path, answering `request` on its first /// announce when it is a job's. fn exact(&self, full: Path, options: RouteOptions, request: Option) -> Result { + options.refuse_minted()?; publish_path(&full)?; if !self.scope.permits(&full) || !self.scope.publishes(&full) { return Err(Error::Unauthorized); @@ -2732,12 +2741,14 @@ impl Producer { /// for as long as the returned [`Route`] (and every clone) lives, unless withdrawn. /// /// The prefix must overlap this producer's pattern scope. Individual requests - /// remain authoritative and are refused when they do not match the scope. + /// remain authoritative and are refused when they do not match the scope. Fails with + /// [`Error::Unsupported`] if `options` names a [minted](Instance::is_minted) instance. pub fn route_prefix( &self, prefix: impl TryInto>, options: RouteOptions, ) -> Result { + options.refuse_minted()?; let (instance, epoch) = options.instance.clone().unwrap_or_else(|| (Instance::random(), 0)); let info = options.info(&instance, epoch); let advertised = !options.hidden; @@ -12475,6 +12486,28 @@ mod tests { pending.await.expect("resolves"); } + /// A minted instance names no stream, so no route takes one. + #[kio::test] + #[cfg(feature = "async")] + async fn a_route_refuses_a_minted_instance() { + let producer = origin(1).produce(); + let consumer = producer.consume(); + let minted = RouteOptions::default().with_instance(Instance::minted(), 0); + assert!(matches!( + producer.route("room/bob", minted.clone()), + Err(Error::Unsupported) + )); + assert!(matches!( + producer.route_prefix("lobby", minted.clone()), + Err(Error::Unsupported) + )); + + let claim = producer.route_prefix("room", RouteOptions::default()).unwrap(); + let mut pending = Box::pin(consumer.request("room/alice", None)); + assert!((&mut pending).now_or_never().is_none()); + assert!(matches!(queued(&claim).await.route(minted), Err(Error::Unsupported))); + } + #[kio::test] #[cfg(feature = "async")] async fn claim_answer_is_hidden_until_published_with_its_instance() { diff --git a/rs/moq-net/src/reconnect.rs b/rs/moq-net/src/reconnect.rs index 97fd40aeb37..fc7cf824b25 100644 --- a/rs/moq-net/src/reconnect.rs +++ b/rs/moq-net/src/reconnect.rs @@ -260,28 +260,47 @@ pub enum ConfigError { } /// One dial the caller runs for [`Reconnect`]. -#[derive(Clone, Debug)] +#[derive(Clone)] pub struct Attempt { target: A, - url: Url, - token: Option, + /// The connection credential, from [`Reconnect::with_tokens`]. + token: Option, + auth: Option, } -impl Attempt { +impl std::fmt::Debug for Attempt { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + // The credential stays out of logs. + f.debug_struct("Attempt") + .field("target", &self.target) + .field("token", &self.token.as_ref().map(|token| token.len())) + .finish_non_exhaustive() + } +} + +impl Attempt { /// The address to dial. pub fn target(&self) -> &A { &self.target } - /// The URL to dial, carrying the connection credential in its query when an offered - /// version has no SETUP token. - pub fn url(&self) -> &Url { - &self.url - } - - /// The connection credential for [`Client::with_token`](crate::Client::with_token), if any. - pub fn token(&self) -> Option<&crate::setup::Token> { - self.token.as_ref() + /// `client` set up for this dial: the target's URL, the connection credential in SETUP + /// and, when one of `client`'s versions cannot carry it there, the URL's query, and the + /// session built on the tokens' handle. + pub fn client(&self, client: &crate::Client) -> crate::Client { + let mut client = client.clone(); + let mut url = self.target.url().clone(); + if let Some(token) = &self.token { + url = auth::locate(&url, token, &client.versions); + client = client.with_token(crate::setup::Token { + kind: crate::setup::Token::OUT_OF_BAND, + value: token.clone().into_bytes(), + }); + } + if let Some(auth) = &self.auth { + client = client.with_auth(auth.clone()); + } + client.with_url(url) } } @@ -291,8 +310,8 @@ impl Attempt { #[derive(Debug)] pub enum Action { /// Dial this attempt and report it with [`Reconnect::connected`] or - /// [`Reconnect::failed`], polling meanwhile. Building each session on the tokens' - /// handle, from [`Reconnect::with_tokens`], is the caller's. + /// [`Reconnect::failed`], polling meanwhile. Build each session's client with + /// [`Attempt::client`]. Dial(Attempt), /// Drop the dial in flight: it ran out its deadline, which already counted as its failure. Abandon, @@ -319,7 +338,7 @@ pub enum Action { pub struct Reconnect { config: Config, targets: Vec, - tokens: Option<(auth::Tokens, crate::Versions)>, + tokens: Option, retry: Retry, redirects: Redirects, phase: Phase, @@ -408,12 +427,12 @@ impl + From> Reco }) } - /// Present `tokens` on every dial offering `versions`. + /// Present `tokens` on every dial, through [`Attempt::client`]. /// /// A refused credential then earns another dial once the tokens change, and an ended /// tokens handle ends the policy at its next walk. - pub fn with_tokens(mut self, tokens: auth::Tokens, versions: crate::Versions) -> Self { - self.tokens = Some((tokens, versions)); + pub fn with_tokens(mut self, tokens: auth::Tokens) -> Self { + self.tokens = Some(tokens); self } @@ -528,7 +547,7 @@ impl + From> Reco let Phase::Dialing(dialing) = std::mem::replace(&mut self.phase, Phase::Start) else { unreachable!("checked above"); }; - if let Some((tokens, _)) = &self.tokens { + if let Some(tokens) = &self.tokens { tokens.connected(&session); } // A predecessor that retired mid-dial queued an offline this session now contradicts. @@ -561,7 +580,7 @@ impl + From> Reco } // An ended auth handle refuses every later session, so no dial can recover. A fresh // watch only reports an error once its handle has ended. - if let Some((tokens, _)) = &self.tokens + if let Some(tokens) = &self.tokens && let Poll::Ready(Err(err)) = tokens.handle().grant().poll_changed(&kio::Waiter::noop()) { return self.done(Err(err.into())); @@ -576,14 +595,9 @@ impl + From> Reco // Read before the dial starts its session's driver, so a request the session sends // early waits on the held tokens' answers rather than being refused outside the // connection credential's grant. - let presented = self - .tokens - .as_ref() - .map(|(tokens, versions)| tokens.dial(target.url(), versions)); - let (url, token) = match &presented { - Some(presented) => (presented.url.clone(), presented.token.clone()), - None => (target.url().clone(), None), - }; + let presented = self.tokens.as_ref().map(|tokens| tokens.dial(target.url())); + let token = presented.as_ref().and_then(|presented| presented.token.clone()); + let auth = self.tokens.as_ref().map(auth::Tokens::handle); // The connect deadline covers the dial and the handshake, for every transport: it is // the only bound some of them have. The fixed bound applies only with a fallback. @@ -601,7 +615,7 @@ impl + From> Reco deadline, presented, }); - Action::Dial(Attempt { target, url, token }) + Action::Dial(Attempt { target, token, auth }) } /// The dial in flight failed: move on to the next target, or end the walk. @@ -814,7 +828,7 @@ impl + From> Reco /// Whether the tokens changed since `presented` read them, so a refusal earns another dial. fn changed(&self, presented: Option<&auth::Dial>) -> bool { match (&self.tokens, presented) { - (Some((tokens, _)), Some(presented)) => tokens.changed(presented), + (Some(tokens), Some(presented)) => tokens.changed(presented), _ => false, } } diff --git a/rs/moq-net/src/reconnect/tests.rs b/rs/moq-net/src/reconnect/tests.rs index 47f3b939477..ee227cac05e 100644 --- a/rs/moq-net/src/reconnect/tests.rs +++ b/rs/moq-net/src/reconnect/tests.rs @@ -422,7 +422,7 @@ async fn a_refusal_retries_only_new_tokens() { let tokens = auth::Tokens::new(vec!["old".parse().unwrap()]); let mut machine = Reconnect::new(config(INITIAL, Duration::ZERO), vec![peer.clone()], kio::clock::now()) .unwrap() - .with_tokens(tokens.clone(), version().into()); + .with_tokens(tokens.clone()); let Action::Dial(_) = next(&mut machine).await else { panic!("expected a dial") @@ -449,7 +449,7 @@ async fn an_ended_auth_handle_ends_the_policy() { let tokens = auth::Tokens::new(Vec::new()); let mut machine = Reconnect::new(config(INITIAL, Duration::ZERO), vec![peer.clone()], kio::clock::now()) .unwrap() - .with_tokens(tokens.clone(), version().into()); + .with_tokens(tokens.clone()); let mut run = Run::default(); drive(&mut machine, &[(peer.clone(), Peer::Serve)], &mut run, |run| { diff --git a/rs/moq-net/src/server.rs b/rs/moq-net/src/server.rs index 040d16c0c2c..5323d6de491 100644 --- a/rs/moq-net/src/server.rs +++ b/rs/moq-net/src/server.rs @@ -20,23 +20,23 @@ use crate::{ /// Tracks admitted connections until their handshake or session ends. #[derive(Clone, Debug, Default)] -pub struct Activity { - state: std::sync::Arc>, +pub struct Admission { + state: std::sync::Arc>, } #[derive(Debug, Default)] -struct ActivityState { +struct AdmissionState { active: usize, draining: bool, closed: Option, } -impl Activity { +impl Admission { /// Hold the server active until the returned guard is dropped, or `None` once closed. - pub fn enter(&self) -> Option { + pub fn enter(&self) -> Option { let mut state = self.state.write().ok()?; state.active += 1; - Some(Active { + Some(Admitted { state: std::sync::Arc::downgrade(&self.state), }) } @@ -66,12 +66,12 @@ impl Activity { /// Keeps an admitted connection in the server's active set. #[derive(Debug)] #[must_use] -pub struct Active { +pub struct Admitted { // A connection observes its source without keeping it open. - state: std::sync::Weak>, + state: std::sync::Weak>, } -impl Drop for Active { +impl Drop for Admitted { fn drop(&mut self) { let Some(source) = self.state.upgrade() else { return }; let Ok(mut state) = source.write() else { return }; @@ -1458,24 +1458,24 @@ mod tests { use futures::FutureExt; use std::time::Duration; - let activity = Activity::default(); - let first = activity.enter().unwrap(); - activity.drain(); - let last = activity.enter().expect("admission stays open while active"); + let admission = Admission::default(); + let first = admission.enter().unwrap(); + admission.drain(); + let last = admission.enter().expect("admission stays open while active"); kio::clock::sleep(Duration::from_secs(1)).await; drop(first); - assert!(activity.close().now_or_never().is_none()); + assert!(admission.close().now_or_never().is_none()); kio::clock::sleep(Duration::from_secs(1)).await; let ended = kio::clock::now(); drop(last); - assert!(activity.enter().is_none(), "last drop did not close admission"); + assert!(admission.enter().is_none(), "last drop did not close admission"); kio::clock::sleep(Duration::from_secs(100)).await; - assert_eq!(activity.close().await, ended, "the observer changed the close time"); + assert_eq!(admission.close().await, ended, "the observer changed the close time"); - let activity = Activity::default(); - let active = activity.enter().unwrap(); - let source = activity.state.weak(); - drop(activity); + let admission = Admission::default(); + let active = admission.enter().unwrap(); + let source = admission.state.weak(); + drop(admission); assert!(source.is_closed(), "an active connection kept its source open"); drop(active); } diff --git a/rs/moq-net/src/stats/outcomes.rs b/rs/moq-net/src/stats/outcomes.rs index ced706f33e0..0c8e240992b 100644 --- a/rs/moq-net/src/stats/outcomes.rs +++ b/rs/moq-net/src/stats/outcomes.rs @@ -15,8 +15,8 @@ pub enum RefusalKind { Request, /// The grant covers none of the requested operations. Forbidden, - /// The LAN membership proof was missing or invalid. - Lan, + /// A membership proof was missing or invalid. + Membership, /// The verified credential expired before admission. Expired, } @@ -28,7 +28,7 @@ impl RefusalKind { Self::Unavailable, Self::Request, Self::Forbidden, - Self::Lan, + Self::Membership, Self::Expired, ]; /// The stable stats and metrics name. @@ -38,7 +38,7 @@ impl RefusalKind { Self::Unavailable => "unavailable", Self::Request => "request", Self::Forbidden => "forbidden", - Self::Lan => "lan", + Self::Membership => "membership", Self::Expired => "expired", } } @@ -57,8 +57,8 @@ pub struct Refusals { pub request: u64, /// The grant covers none of the requested operations. pub forbidden: u64, - /// The LAN membership proof was missing or invalid. - pub lan: u64, + /// A membership proof was missing or invalid. + pub membership: u64, /// The verified credential expired before admission. pub expired: u64, } @@ -71,7 +71,7 @@ impl Refusals { RefusalKind::Unavailable => self.unavailable, RefusalKind::Request => self.request, RefusalKind::Forbidden => self.forbidden, - RefusalKind::Lan => self.lan, + RefusalKind::Membership => self.membership, RefusalKind::Expired => self.expired, } } @@ -81,7 +81,7 @@ impl Refusals { self.unavailable += other.unavailable; self.request += other.request; self.forbidden += other.forbidden; - self.lan += other.lan; + self.membership += other.membership; self.expired += other.expired; } /// Whether any cumulative count went backwards. @@ -90,7 +90,7 @@ impl Refusals { || self.unavailable < previous.unavailable || self.request < previous.request || self.forbidden < previous.forbidden - || self.lan < previous.lan + || self.membership < previous.membership || self.expired < previous.expired } } @@ -101,7 +101,7 @@ pub(super) struct RefusalCounters { unavailable: AtomicU64, request: AtomicU64, forbidden: AtomicU64, - lan: AtomicU64, + membership: AtomicU64, expired: AtomicU64, } @@ -112,7 +112,7 @@ impl RefusalCounters { RefusalKind::Unavailable => &self.unavailable, RefusalKind::Request => &self.request, RefusalKind::Forbidden => &self.forbidden, - RefusalKind::Lan => &self.lan, + RefusalKind::Membership => &self.membership, RefusalKind::Expired => &self.expired, } } @@ -122,7 +122,7 @@ impl RefusalCounters { unavailable: self.unavailable.load(Ordering::Relaxed), request: self.request.load(Ordering::Relaxed), forbidden: self.forbidden.load(Ordering::Relaxed), - lan: self.lan.load(Ordering::Relaxed), + membership: self.membership.load(Ordering::Relaxed), expired: self.expired.load(Ordering::Relaxed), } } diff --git a/rs/moq-net/src/version.rs b/rs/moq-net/src/version.rs index a4c9d96b6a8..ec59ed20794 100644 --- a/rs/moq-net/src/version.rs +++ b/rs/moq-net/src/version.rs @@ -72,6 +72,10 @@ pub enum Version { } impl Version { + /// Every version this crate speaks, newest first, including the opt-in `-wip` drafts + /// that [`Versions::all`] leaves out. + pub const ALL: &'static [Version] = &ALL; + #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] pub(crate) fn session_code(self, error: &crate::SessionError) -> u32 { match self { @@ -90,6 +94,16 @@ impl Version { } } + /// Whether SETUP carries the request path, so a transport with no request URI (native + /// QUIC, qmux over TCP) can still name its target: moq-lite-05 and newer, and every + /// moq-transport draft. + pub fn has_request_path(&self) -> bool { + match self { + Self::Lite(version) => version.has_setup_stream(), + Self::Ietf(_) => true, + } + } + /// Handshake / config name, e.g. `moq-lite-05` or `moq-transport-22`. pub fn as_str(&self) -> &'static str { match self { @@ -107,7 +121,7 @@ impl Version { } /// Parse from wire version code (used during SETUP negotiation). - pub fn from_code(code: u64) -> Option { + pub(crate) fn from_code(code: u64) -> Option { match code { 0xff0dad01 => Some(Self::Lite(lite::Version::Lite01)), 0xff0dad02 => Some(Self::Lite(lite::Version::Lite02)), @@ -124,7 +138,7 @@ impl Version { } /// Get the wire version code. - pub fn code(&self) -> u64 { + pub(crate) fn code(&self) -> u64 { match self { Self::Lite(lite::Version::Lite01) => 0xff0dad01, Self::Lite(lite::Version::Lite02) => 0xff0dad02, diff --git a/rs/moq-net/tests/integration/support/mod.rs b/rs/moq-net/tests/integration/support/mod.rs index f9d2a692771..356d5cdf8c9 100644 --- a/rs/moq-net/tests/integration/support/mod.rs +++ b/rs/moq-net/tests/integration/support/mod.rs @@ -27,10 +27,8 @@ pub async fn unwanted(mut demand: track::Demand) -> moq_net::Result<()> { /// nobody reads it. #[allow(dead_code, reason = "shared by several test binaries, each using only part of it")] pub async fn datagram_priority(producer: &datagram::Producer, want: Option) { - let mut priority = producer.priority(); - while priority != want { - priority = moq_net::kio::wait(|waiter| producer.poll_priority(waiter, priority)).await; - } + let mut watch = producer.clone(); + while watch.priority_changed().await != want {} } /// Wait until `consumer` sees a route announced at exactly `path`, and return it. @@ -119,12 +117,9 @@ impl Draining for goaway::Consumer { } } -/// Every version this crate speaks, found by wire code, including the opt-in `-wip` -/// drafts that [`moq_net::Versions::all`] leaves out. +/// Every version this crate speaks, including the opt-in `-wip` drafts that +/// [`moq_net::Versions::all`] leaves out. #[allow(dead_code, reason = "shared by several test binaries, each using only part of it")] pub fn every_version() -> Vec { - (0xff0dad00..=0xff0dadff) - .chain(0xff000000..=0xff0000ff) - .filter_map(moq_net::Version::from_code) - .collect() + moq_net::Version::ALL.to_vec() } diff --git a/rs/moq-relay/benches/http_idle.rs b/rs/moq-relay/benches/http_idle.rs index 37bec35052d..cf9c795b273 100644 --- a/rs/moq-relay/benches/http_idle.rs +++ b/rs/moq-relay/benches/http_idle.rs @@ -109,23 +109,23 @@ fn admission(c: &mut Criterion) { let mut group = c.benchmark_group("http_admission"); for connections in [1, 16, 256] { for pending in [0, 16, 256] { - let activity = moq_net::server::Activity::default(); + let admission = moq_net::server::Admission::default(); let _held = (0..connections + pending) - .map(|_| activity.enter().unwrap()) + .map(|_| admission.enter().unwrap()) .collect::>(); let shape = format!("connections={connections}/pending={pending}"); group.bench_function(BenchmarkId::new("handler", &shape), |b| { - b.iter(|| std::hint::black_box(activity.enter().unwrap())); + b.iter(|| std::hint::black_box(admission.enter().unwrap())); }); group.bench_function(BenchmarkId::new("plain", &shape), |b| { b.iter(|| { - let accepted = idle::Admission::new(activity.enter().unwrap()); + let accepted = idle::Admission::new(admission.enter().unwrap()); drop(std::hint::black_box(accepted.take().unwrap())); }); }); group.bench_function(BenchmarkId::new("upgrade", &shape), |b| { b.iter(|| { - let accepted = idle::Admission::new(activity.enter().unwrap()); + let accepted = idle::Admission::new(admission.enter().unwrap()); let request = idle::Admission::new(accepted.take().unwrap()); drop(std::hint::black_box(request.take().unwrap())); }); diff --git a/rs/moq-relay/src/cluster.rs b/rs/moq-relay/src/cluster.rs index 3ab74e0c993..87f6f873275 100644 --- a/rs/moq-relay/src/cluster.rs +++ b/rs/moq-relay/src/cluster.rs @@ -1731,11 +1731,6 @@ impl Cluster { grant } - /// Whether a protocol version carries the request path used to mark a mesh dial. - pub(crate) fn carries_request_path(version: &moq_net::Version) -> bool { - !version.is_lite() || version.code() >= 0xff0dad05 - } - /// Reject version restrictions that leave a LAN dial with no request path. pub fn validate_lan_versions( client: &moq_tokio::connect::Config, @@ -1746,7 +1741,7 @@ impl Cluster { anyhow::ensure!( client .iter() - .any(|version| Self::carries_request_path(version) && server.contains(version)), + .any(|version| version.has_request_path() && server.contains(version)), "--cluster-lan needs --connect-version and --listen-version to share a version that carries a request path (moq-lite-05 and newer, or any moq-transport version)" ); Ok(()) @@ -1791,7 +1786,7 @@ impl Cluster { ); if let Some(connect) = &self.connect { anyhow::ensure!( - connect.versions().iter().any(Self::carries_request_path), + connect.versions().iter().any(moq_net::Version::has_request_path), "--cluster-lan needs --connect-version to include a version that carries a request path (moq-lite-05 and newer, or any moq-transport version)" ); } else { @@ -2281,7 +2276,7 @@ impl Cluster { connect.version = connect .versions() .iter() - .filter(|version| Self::carries_request_path(version)) + .filter(|version| version.has_request_path()) .copied() .collect(); } @@ -2305,9 +2300,11 @@ impl Cluster { #[cfg(all(test, feature = "cluster-lan"))] fn dial_lan_target(&self, target: &DialTarget) -> anyhow::Result { let addrs = moq_tokio::Addrs::collect(target.addrs()).context("peer advertised no reachable address")?; + let origin = self.origin.clone().with_link(origin::Link::Peer); let mut client = self .peer_client(true, Some(target))? - .with_origin(self.origin.clone().with_link(origin::Link::Peer)); + .with_publisher(&origin) + .with_subscriber(origin); if let Some(cost) = target.cost { client = client.with_cost(cost); } diff --git a/rs/moq-relay/src/connection.rs b/rs/moq-relay/src/connection.rs index 4f0e1947c7c..2b6f2cec756 100644 --- a/rs/moq-relay/src/connection.rs +++ b/rs/moq-relay/src/connection.rs @@ -329,7 +329,7 @@ impl Lifecycle { let Some(presented) = cluster::Cluster::lan_credential(&request.path) else { return Err(Rejection { code: moq_net::SessionError::Unauthorized, - refusal: Some(RefusalKind::Lan), + refusal: Some(RefusalKind::Membership), source: anyhow::anyhow!("LAN peer did not present a membership proof"), }); }; @@ -342,14 +342,14 @@ impl Lifecycle { Some(false) => { return Err(Rejection { code: moq_net::SessionError::Unauthorized, - refusal: Some(RefusalKind::Lan), + refusal: Some(RefusalKind::Membership), source: anyhow::anyhow!("LAN peer did not present this listener's membership proof"), }); } None => { return Err(Rejection { code: moq_net::SessionError::Unauthorized, - refusal: Some(RefusalKind::Lan), + refusal: Some(RefusalKind::Membership), source: anyhow::anyhow!("/.cluster request refused: LAN discovery is not enabled"), }); } diff --git a/rs/moq-relay/src/internal.rs b/rs/moq-relay/src/internal.rs index fd4955a28eb..1932b01ebcf 100644 --- a/rs/moq-relay/src/internal.rs +++ b/rs/moq-relay/src/internal.rs @@ -328,7 +328,7 @@ impl Internal { crate::listener::Config { health, timeout, - activity: None, + admission: None, }, InternalAcceptor, )? @@ -2159,7 +2159,7 @@ counter moq_relay_sessions_failed_total{kind="transport",tier="edge"} 0 counter moq_relay_sessions_opened_total{tier="edge"} 1 counter moq_relay_sessions_refused_total{reason="expired"} 0 counter moq_relay_sessions_refused_total{reason="forbidden"} 0 -counter moq_relay_sessions_refused_total{reason="lan"} 0 +counter moq_relay_sessions_refused_total{reason="membership"} 0 counter moq_relay_sessions_refused_total{reason="refused"} 0 counter moq_relay_sessions_refused_total{reason="request"} 0 counter moq_relay_sessions_refused_total{reason="unavailable"} 1 diff --git a/rs/moq-relay/src/listener.rs b/rs/moq-relay/src/listener.rs index f88bfff2862..dac84f2a581 100644 --- a/rs/moq-relay/src/listener.rs +++ b/rs/moq-relay/src/listener.rs @@ -110,7 +110,7 @@ impl axum::extract::connect_info::Connected for SocketAddr { pub(crate) struct Listener { inner: TcpListener, health: Health, - activity: Option, + admission: Option, } impl Listener { @@ -119,12 +119,12 @@ impl Listener { pub(crate) fn new( listener: std::net::TcpListener, health: Health, - activity: Option, + admission: Option, ) -> io::Result { Ok(Self { inner: TcpListener::from_std(listener)?, health, - activity, + admission, }) } } @@ -133,7 +133,7 @@ impl Listener { pub(crate) struct Config { pub health: Health, /// Count public web sockets from TCP accept through their first request. - pub activity: Option, + pub admission: Option, pub timeout: Option, } @@ -154,10 +154,10 @@ pub(crate) fn server( let Config { health, timeout, - activity, + admission, } = config; let mut server = - axum_server::Server::from_listener(Listener::new(listener, health, activity)?).acceptor(idle::Acceptor { + axum_server::Server::from_listener(Listener::new(listener, health, admission)?).acceptor(idle::Acceptor { inner: acceptor, timeout, }); @@ -183,7 +183,7 @@ impl AddrListener for Listener { Ok(Self { inner: TcpListener::bind(addr.0).await?, health: Health::new("tcp"), - activity: None, + admission: None, }) } @@ -206,9 +206,9 @@ impl AddrListener for Listener { // Enter before returning the socket: axum_server spawns the TLS // acceptor, and waiting for that task would leave an uncounted gap. let admission = self - .activity + .admission .as_ref() - .and_then(|activity| activity.enter()) + .and_then(|admission| admission.enter()) .map(Admission::new); self.health.accepted(); return Ok((Accepted { stream, admission }, Peer(peer))); diff --git a/rs/moq-relay/src/listener/idle.rs b/rs/moq-relay/src/listener/idle.rs index f7ab00d5f00..786b91613c9 100644 --- a/rs/moq-relay/src/listener/idle.rs +++ b/rs/moq-relay/src/listener/idle.rs @@ -20,14 +20,14 @@ use tower_service::Service; /// A connection's accept guard, handed off once to a WebSocket upgrade. #[derive(Clone)] -pub(crate) struct Admission(Arc>>); +pub(crate) struct Admission(Arc>>); impl Admission { - pub(crate) fn new(active: moq_net::server::Active) -> Self { + pub(crate) fn new(active: moq_net::server::Admitted) -> Self { Self(Arc::new(Mutex::new(Some(active)))) } - pub(crate) fn take(&self) -> Option { + pub(crate) fn take(&self) -> Option { self.0.lock().unwrap_or_else(PoisonError::into_inner).take() } } diff --git a/rs/moq-relay/src/relay.rs b/rs/moq-relay/src/relay.rs index b5fe4b74765..3e79b654999 100644 --- a/rs/moq-relay/src/relay.rs +++ b/rs/moq-relay/src/relay.rs @@ -198,7 +198,7 @@ impl Relay { server.listen = listen.clone(); server.tls = served.clone(); server.quic = config.quic.clone(); - server.activity = shutdown.activity.clone(); + server.admission = shutdown.admission.clone(); server.demux = demux.clone(); Some(moq_tokio::worker::Workers::bind(server, worker).context("failed to start the QUIC workers")?) } @@ -237,7 +237,7 @@ impl Relay { server_config.listen = listen; server_config.tls = served; server_config.quic = config.quic.clone(); - server_config.activity = shutdown.activity.clone(); + server_config.admission = shutdown.admission.clone(); #[cfg(feature = "_quic")] { server_config.demux = demux.clone(); @@ -915,7 +915,7 @@ mod tests { use futures::FutureExt; let window = std::time::Duration::from_secs(10); let (trigger, shutdown) = crate::shutdown::Observer::new(window); - let _pending = shutdown.activity.enter(); + let _pending = shutdown.admission.enter(); trigger.start(); let draining = super::drain(trigger, shutdown, None); tokio::pin!(draining); @@ -936,7 +936,7 @@ mod tests { // Either arm is ready, so an unbiased wait would pass some runs. for _ in 0..32 { let (trigger, shutdown) = crate::shutdown::Observer::new(std::time::Duration::from_secs(10)); - let _active = shutdown.activity.enter(); + let _active = shutdown.admission.enter(); trigger.start(); let mut signals = crate::shutdown::Signals::new().unwrap(); crate::shutdown::raise(libc::SIGTERM).await; @@ -979,15 +979,15 @@ mod tests { async fn arrival_as_the_drain_empties_is_counted_or_refused() { use futures::FutureExt; let (trigger, shutdown) = crate::shutdown::Observer::new(std::time::Duration::from_secs(10)); - let activity = shutdown.activity.clone(); - let last = activity.enter().expect("admission open before the drain"); + let admission = shutdown.admission.clone(); + let last = admission.enter().expect("admission open before the drain"); trigger.start(); let draining = super::drain(trigger, shutdown, None); tokio::pin!(draining); assert!(draining.as_mut().now_or_never().is_none()); // Arrives before the last connection leaves: it is counted. - let arrival = activity.enter().expect("admitted before the drain committed"); + let arrival = admission.enter().expect("admitted before the drain committed"); drop(last); assert!( draining.as_mut().now_or_never().is_none(), @@ -998,7 +998,7 @@ mod tests { drop(arrival); assert!(draining.as_mut().now_or_never().is_some()); assert!( - activity.enter().is_none(), + admission.enter().is_none(), "admitted a connection after the drain committed to exit" ); } diff --git a/rs/moq-relay/src/shutdown.rs b/rs/moq-relay/src/shutdown.rs index ccd0f94017e..2b26cf4ca07 100644 --- a/rs/moq-relay/src/shutdown.rs +++ b/rs/moq-relay/src/shutdown.rs @@ -23,7 +23,7 @@ use tokio::sync::watch; pub struct Trigger { tx: watch::Sender>, drain_timeout: Duration, - activity: moq_net::server::Activity, + admission: moq_net::server::Admission, } impl Trigger { @@ -45,7 +45,7 @@ impl Trigger { } // Admission records its own completion, even if nobody polls `drained`. - self.activity.drain(); + self.admission.drain(); } } @@ -161,7 +161,7 @@ struct Window { /// and drains itself via [`drain_session`](Self::drain_session) when it fires. #[derive(Clone)] pub struct Observer { - pub(crate) activity: moq_net::server::Activity, + pub(crate) admission: moq_net::server::Admission, rx: watch::Receiver>, state: watch::Sender, changes: watch::Receiver, @@ -178,7 +178,7 @@ impl Observer { let trigger = Trigger { tx, drain_timeout, - activity: observer.activity.clone(), + admission: observer.admission.clone(), }; (trigger, observer) } @@ -200,7 +200,7 @@ impl Observer { state, changes, seen: Tally::default(), - activity: Default::default(), + admission: Default::default(), drain_timeout, } } @@ -250,9 +250,9 @@ impl Observer { } } - /// The admission tracker the drain waits on; give it to your own listener's `Config::activity`. - pub fn activity(&self) -> &moq_net::server::Activity { - &self.activity + /// The admission tracker the drain waits on; give it to your own listener's `Config::admission`. + pub fn admission(&self) -> &moq_net::server::Admission { + &self.admission } /// When the drain window ends, if [`Trigger::start`] has fired. @@ -277,7 +277,7 @@ impl Observer { self.state.send_modify(|state| state.tally.open += 1); } Serving { - _active: self.activity.enter(), + _active: self.admission.enter(), count: match counted { true => Count::Open, false => Count::Uncounted, @@ -319,7 +319,7 @@ impl Observer { let window = self.rx.borrow().expect("started"); let wait_ended = tokio::select! { biased; - closed = self.activity.close() => closed.min(window.deadline), + closed = self.admission.close() => closed.min(window.deadline), () = self.expired() => window.deadline, }; // Either way, wait for the counted sessions: past the deadline they are still @@ -418,7 +418,7 @@ impl Observer { pub struct Serving { // `None` only once the drain closed admission, which the connection's own // admission prevents while it is held before the SETUP reply. - _active: Option, + _active: Option, count: Count, pub(crate) shutdown: Observer, } @@ -575,7 +575,7 @@ mod tests { let relay = crate::Relay::load(config).await.unwrap().with_signals(false); let addr = relay.web_addrs().http.unwrap(); let trigger = relay.shutdown_trigger().clone(); - let activity = relay.shutdown().activity.clone(); + let admission = relay.shutdown().admission.clone(); let running = tokio::spawn(relay.run()); // Upgraded, then silent: no MoQ SETUP ever follows. @@ -589,21 +589,21 @@ mod tests { // Only timers decide what follows. tokio::time::pause(); trigger.start(); - kio::clock::timeout(window + Duration::from_secs(1), activity.close()) + kio::clock::timeout(window + Duration::from_secs(1), admission.close()) .await .expect("a withheld SETUP outlived the drain deadline"); running.await.unwrap().unwrap(); } /// An embedder's own listener shares the relay's admission tracking through - /// [`Observer::activity`], so a connection it holds keeps the drain open. + /// [`Observer::admission`], so a connection it holds keeps the drain open. #[tokio::test(start_paused = true)] async fn embedder_admission_holds_drain() { let mut config = crate::Config::default(); config.listen.tcp.bind = Some("127.0.0.1:0".parse().unwrap()); let mut relay = crate::Relay::load(config).await.unwrap().with_signals(false); let _admissions = relay.admissions().unwrap(); - let active = relay.shutdown().activity().enter().unwrap(); + let active = relay.shutdown().admission().enter().unwrap(); let trigger = relay.shutdown_trigger().clone(); let running = tokio::spawn(relay.run()); trigger.start(); @@ -789,7 +789,7 @@ mod tests { async fn an_emptied_drain_still_waits_for_counted_sessions() { let (trigger, shutdown) = Observer::new(Duration::from_secs(10)); trigger.start(); - shutdown.activity.close().await; + shutdown.admission.close().await; let serving = shutdown.serve(); let drained = tokio::spawn({ let shutdown = shutdown.clone(); diff --git a/rs/moq-relay/src/web.rs b/rs/moq-relay/src/web.rs index 88f3f576eca..3b04f288e48 100644 --- a/rs/moq-relay/src/web.rs +++ b/rs/moq-relay/src/web.rs @@ -466,7 +466,7 @@ impl Web { crate::listener::Config { health: health.clone(), timeout: state.timeout, - activity: Some(state.shutdown.activity.clone()), + admission: Some(state.shutdown.admission.clone()), }, WebAcceptor::plain(ws, rtmp.clone(), state.clone()), )?; @@ -483,7 +483,7 @@ impl Web { crate::listener::Config { health: health.clone(), timeout: state.timeout, - activity: Some(state.shutdown.activity.clone()), + admission: Some(state.shutdown.admission.clone()), }, WebAcceptor::tls( crate::listener::Tls { @@ -687,7 +687,7 @@ impl WebAcceptor { .admission .clone() .and_then(|admission| admission.take()) - .or_else(|| state.shutdown.activity.enter()) + .or_else(|| state.shutdown.admission.enter()) else { return; }; @@ -2834,7 +2834,7 @@ mod tests { fn holds_drain(&self) { use futures::FutureExt; assert!( - self.shutdown.activity().close().now_or_never().is_none(), + self.shutdown.admission().close().now_or_never().is_none(), "a TCP-accepted web connection was absent from the drain before its upgrade" ); } @@ -2954,17 +2954,17 @@ mod tests { .with_no_client_auth(); client.alpn_protocols = vec![b"h2".to_vec()]; let connector = tokio_rustls::TlsConnector::from(Arc::new(client)); - let activity = moq_net::server::Activity::default(); + let admission = moq_net::server::Admission::default(); let bound = moq_tokio::bind::tcp("127.0.0.1:0".parse().unwrap()).unwrap(); let addr = bound.local_addr().unwrap(); let listener = - crate::listener::Listener::new(bound, moq_tokio::accept::Health::new("h2"), Some(activity.clone())) + crate::listener::Listener::new(bound, moq_tokio::accept::Health::new("h2"), Some(admission.clone())) .unwrap(); let ((accepted, _), connected) = socket_step(async { tokio::try_join!(listener.accept_stream(), tokio::net::TcpStream::connect(addr)) }) .await .unwrap(); - assert!(activity.close().now_or_never().is_none(), "TLS was not counted"); + assert!(admission.close().now_or_never().is_none(), "TLS was not counted"); let tls = crate::listener::Tls { http: RustlsConfig::from_config(tls), serve, @@ -2981,7 +2981,7 @@ mod tests { .unwrap(); assert_eq!(stream.tls().unwrap().alpn_protocol(), Some(&b"h2"[..])); assert!( - activity.close().now_or_never().is_some(), + admission.close().now_or_never().is_some(), "h2 awaited request headers before releasing its admission" ); } @@ -3009,7 +3009,7 @@ mod tests { #[tokio::test(start_paused = true)] async fn later_keep_alive_upgrade_enters_from_the_handler() { let mut web = DrainingWeb::new(false, true).await; - let pending = web.shutdown.activity().enter().unwrap(); + let pending = web.shutdown.admission().enter().unwrap(); socket_step(plain_request(&mut web.stream)).await; web.trigger.start(); let session = socket_step(upgrade_while_draining(web.stream, false)).await; @@ -3043,7 +3043,7 @@ mod tests { socket_step(plain_request(&mut web.stream)).await; // Keep the listener running while admission is closed, exposing the // same boundary a connection can reach just before Relay::run stops it. - socket_step(web.shutdown.activity().close()).await; + socket_step(web.shutdown.admission().close()).await; socket_step(refused_upgrade(web.stream)).await; let mut fresh = socket_step(tokio::net::TcpStream::connect(addr)).await.unwrap(); socket_step(plain_request(&mut fresh)).await; diff --git a/rs/moq-relay/src/websocket.rs b/rs/moq-relay/src/websocket.rs index 593d5f32400..94d73dc4112 100644 --- a/rs/moq-relay/src/websocket.rs +++ b/rs/moq-relay/src/websocket.rs @@ -41,7 +41,7 @@ pub(crate) async fn serve_ws( // upgrade enters here; after the drain commits, it receives 503 instead. let active = admission .and_then(|Extension(admission)| admission.take()) - .or_else(|| state.shutdown.activity.enter()) + .or_else(|| state.shutdown.admission.enter()) .ok_or(StatusCode::SERVICE_UNAVAILABLE)?; let protocol = negotiate_subprotocol(request.headers(), &versions)?; @@ -286,9 +286,9 @@ mod tests { #[test] fn supported_subprotocols_lists_full_matrix() { - let drafts: Vec<_> = [0xff000012, 0xff000014, 0xff000016] + let drafts: Vec<_> = ["moq-transport-18", "moq-transport-20", "moq-transport-22"] .into_iter() - .map(|code| moq_net::Version::from_code(code).unwrap().alpn()) + .map(|name| name.parse::().unwrap().alpn()) .collect(); let list = supported_subprotocols(&moq_net::Versions::all()); @@ -692,13 +692,13 @@ mod tests { let (server_to_client, client_incoming) = mpsc::unbounded_channel(); let frozen = Arc::new(AtomicBool::new(false)); - let activity = moq_net::server::Activity::default(); + let admission = moq_net::server::Admission::default(); let mut options = moq_tokio::websocket::Options::new( "ws://localhost/".parse().unwrap(), moq_net::Server::new() .with_versions(moq_net::Versions::all()) .with_timeout(None), - activity.enter().unwrap(), + admission.enter().unwrap(), ); options.link.alpn = Some(alpn.clone()); let server = tokio::spawn(moq_tokio::websocket::accept( @@ -746,13 +746,13 @@ mod tests { let (server_to_client, client_incoming) = mpsc::unbounded_channel(); let timeout = Duration::from_secs(10); - let activity = moq_net::server::Activity::default(); + let admission = moq_net::server::Admission::default(); let mut options = moq_tokio::websocket::Options::new( "ws://localhost/".parse().unwrap(), moq_net::Server::new() .with_versions(moq_net::Versions::all()) .with_timeout(Some(timeout)), - activity.enter().unwrap(), + admission.enter().unwrap(), ); options.link.alpn = Some(alpn.clone()); let start = kio::clock::now(); diff --git a/rs/moq-relay/tests/integration/refusals.rs b/rs/moq-relay/tests/integration/refusals.rs index 6bb073888b0..9c5f6f23dee 100644 --- a/rs/moq-relay/tests/integration/refusals.rs +++ b/rs/moq-relay/tests/integration/refusals.rs @@ -198,7 +198,7 @@ async fn lan_refusals_are_counted() { false, ) .await; - assert_eq!(relay.refused("lan").await, 1); + assert_eq!(relay.refused("membership").await, 1); assert_eq!(relay.refused("refused").await, 0); relay.stop().await; } diff --git a/rs/moq-tokio/src/client.rs b/rs/moq-tokio/src/client.rs index ceee5ccb887..087c9ef9511 100644 --- a/rs/moq-tokio/src/client.rs +++ b/rs/moq-tokio/src/client.rs @@ -190,12 +190,6 @@ impl Client { self } - /// Publish and subscribe through one shared origin. - pub fn with_origin(mut self, origin: moq_net::origin::Producer) -> Self { - self.moq = self.moq.with_origin(origin); - self - } - /// Subscribe to the peer's broadcasts, ingesting them into the given origin. pub fn with_subscriber(mut self, subscribe: moq_net::origin::Producer) -> Self { self.moq = self.moq.with_subscriber(subscribe); @@ -380,15 +374,10 @@ impl Client { &self, attempt: moq_net::reconnect::Attempt, ) -> crate::Result { - let addr = attempt.target().with_url(attempt.url().clone()); - let client = match attempt.token() { - Some(token) => { - let mut client = self.clone(); - client.moq = client.moq.with_token(token.clone()); - std::borrow::Cow::Owned(client) - } - None => std::borrow::Cow::Borrowed(self), - }; + let mut client = self.clone(); + client.moq = attempt.client(&self.moq); + let url = client.moq.url().expect("an attempt sets the URL").clone(); + let addr = attempt.target().with_url(url); #[cfg(test)] if let Some(dialer) = &self.dialer { return dialer(addr, client.moq.clone()).await; @@ -914,11 +903,7 @@ mod tests { fn test_cli_version_help_lists_every_parseable_name() { let help = Cli::render_help(Cli::command(), true).expect("long help"); // Every wire code this crate parses, including the opt-in `-wip` drafts. - let codes = (0xff0dad00..=0xff0dadff).chain(0xff000000..=0xff0000ff); - for name in codes - .filter_map(moq_net::Version::from_code) - .map(|version| version.as_str()) - { + for name in moq_net::Version::ALL.iter().map(|version| version.as_str()) { assert!(help.contains(name), "missing {name} from --connect-version help"); } } diff --git a/rs/moq-tokio/src/connection.rs b/rs/moq-tokio/src/connection.rs index 1b432b2f93e..d2a8b3cf90e 100644 --- a/rs/moq-tokio/src/connection.rs +++ b/rs/moq-tokio/src/connection.rs @@ -887,12 +887,11 @@ struct Running { type CloseGuard = std::sync::Arc>>; impl Connection { - pub(crate) fn new(mut client: Client, addrs: Addrs) -> Self { + pub(crate) fn new(client: Client, addrs: Addrs) -> Self { let producer = kio::Producer::::default(); let state = producer.consume(); let tokens = moq_net::auth::Tokens::new(client.tokens.clone()); let auth = tokens.handle(); - client.moq = client.moq.with_auth(auth.clone()); // The loop feeds these across every reconnect, so a consumer's handle survives session churn // (unlike a session's own bandwidth consumer, which dies with the session). @@ -1034,7 +1033,7 @@ impl Connection { let mut client = client; let mut policy = moq_net::Reconnect::new(client.policy, addrs.as_slice().to_vec(), kio::clock::now()) .map_err(|_| Error::BackoffHealthy)? - .with_tokens(shared.tokens.clone(), client.versions.clone()); + .with_tokens(shared.tokens.clone()); // The dial in flight, and the address it was asked for. It owns its client, so a // fresh port can replace the loop's between walks. let mut dial: Option<(url::Url, std::pin::Pin>)> = None; diff --git a/rs/moq-tokio/src/server.rs b/rs/moq-tokio/src/server.rs index 914f0df6e8c..70f1ac571a4 100644 --- a/rs/moq-tokio/src/server.rs +++ b/rs/moq-tokio/src/server.rs @@ -177,7 +177,7 @@ pub struct Config { pub tls: Option, /// Tracks accepted transports through their handshake and session lifetime. - pub activity: moq_net::server::Activity, + pub admission: moq_net::server::Admission, /// The accept side of the endpoint: what to listen on and how to be trusted. pub listen: crate::listen::Config, @@ -227,7 +227,7 @@ impl Config { publisher: self.publisher.clone(), subscriber: self.subscriber.clone(), stats: self.stats.clone(), - activity: self.activity.clone(), + admission: self.admission.clone(), demux: self.demux.clone(), } } @@ -239,7 +239,7 @@ impl Config { /// (`--listen-tcp-bind`) and Unix sockets (`--listen-unix-bind`). Create via /// [`crate::listen::Config::init`] or [`Server::new`]. pub struct Server { - activity: moq_net::server::Activity, + admission: moq_net::server::Admission, moq: moq_net::Server, #[cfg(any(feature = "quic", feature = "websocket", feature = "tcp", all(feature = "uds", unix)))] versions: moq_net::Versions, @@ -271,7 +271,7 @@ impl Server { /// [`Self::new`], for a caller that opens only some of the config's listeners. pub(crate) fn build(config: Config, parts: Parts) -> crate::Result { let Config { - activity, + admission, listen: config, quic, #[cfg(feature = "_certs")] @@ -439,7 +439,7 @@ impl Server { } Ok(Server { - activity, + admission, #[cfg(any(feature = "quic", feature = "websocket", feature = "tcp", all(feature = "uds", unix)))] accept: Default::default(), moq, @@ -632,7 +632,7 @@ impl Server { .moq .clone() .with_versions(listener.server.streams.versions.clone()); - listener.server.streams.serve(&server, &listener.server.activity); + listener.server.streams.serve(&server, &listener.server.admission); Ok(listener) } } @@ -647,7 +647,7 @@ impl Server { #[cfg(any(feature = "tcp", all(feature = "uds", unix)))] { let server = self.moq.clone().with_versions(self.streams.versions.clone()); - self.streams.serve(&server, &self.activity); + self.streams.serve(&server, &self.admission); } loop { // The QUIC endpoint address, reported as a QUIC session's local side. @@ -684,7 +684,7 @@ impl Server { #[allow(unused_variables, reason = "a build without a transport feature never reads it")] let setup = Setup { - activity: self.activity.clone(), + admission: self.admission.clone(), server: self.moq.clone(), }; #[allow(unused_variables, reason = "a build without a transport feature never reads it")] @@ -730,7 +730,7 @@ impl Server { let tls = quic_tls.expect("an accepting QUIC endpoint has its TLS"); let deadline = setup.deadline(); // Closed for drain: refuse so the peer redials elsewhere at once. - let Some(active) = setup.activity.enter() else { + let Some(active) = setup.admission.enter() else { _conn.refuse(); continue; }; @@ -758,7 +758,7 @@ impl Server { let local = self.websocket_local_addr(); let deadline = setup.deadline(); // Dropping the pending upgrade closes its socket. - let Some(active) = setup.activity.enter() else { + let Some(active) = setup.admission.enter() else { continue; }; self.accept.push(crate::panic::isolate(async move { @@ -872,7 +872,7 @@ impl Listener { /// the listener is closing. /// /// To have a drain wait for a session still being established, hold a guard from - /// [`Self::activity`] until this call returns. + /// [`Self::admission`] until this call returns. #[cfg(feature = "qmux")] pub async fn accept_with( &self, @@ -881,7 +881,7 @@ impl Listener { link: Link, ) -> crate::Result { let server = &self.server; - let active = server.activity.enter().ok_or(Error::Stopped)?; + let active = server.admission.enter().ok_or(Error::Stopped)?; let mut incoming = Incoming::new(transport, server.moq.deadline(kio::clock::now()), active); incoming.link = link; crate::runtime::scope(Request::accept_qmux(&server.moq, session, incoming)).await @@ -890,8 +890,8 @@ impl Listener { /// The accepted connections a drain waits for, including any session a guard from it /// holds while it is established for [`Self::accept_with`]. #[cfg(feature = "qmux")] - pub fn activity(&self) -> &moq_net::server::Activity { - &self.server.activity + pub fn admission(&self) -> &moq_net::server::Admission { + &self.server.admission } /// Close every listener and connection, once each QUIC peer has been sent the @@ -956,7 +956,7 @@ async fn serve_session(request: Request) -> crate::Result<()> { #[cfg(any(feature = "quic", feature = "websocket", feature = "tcp", all(feature = "uds", unix)))] #[derive(Clone)] struct Setup { - activity: moq_net::server::Activity, + admission: moq_net::server::Admission, server: moq_net::Server, } @@ -1212,13 +1212,13 @@ impl StreamListeners { /// No-op when nothing is waiting: either nothing was configured, or the loops /// are already running. `server` is the configuration each accepted session /// handshakes against, fixed by the time this runs. - fn serve(&mut self, server: &moq_net::Server, activity: &moq_net::server::Activity) { + fn serve(&mut self, server: &moq_net::Server, admission: &moq_net::server::Admission) { if self.pending.is_empty() { return; } let setup = Setup { - activity: activity.clone(), + admission: admission.clone(), server: server.clone(), }; let (tx, rx) = tokio::sync::mpsc::channel(16); @@ -1299,7 +1299,7 @@ fn spawn_tcp_loop( Some(_) = handshakes.join_next() => continue, }; // Closed for drain: dropping the pending handshake closes its socket. - let Some(active) = setup.activity.enter() else { + let Some(active) = setup.admission.enter() else { continue; }; let deadline = setup.deadline(); @@ -1337,7 +1337,7 @@ fn spawn_unix_loop( Some(_) = handshakes.join_next() => continue, }; // Closed for drain: dropping the pending handshake closes its socket. - let Some(active) = setup.activity.enter() else { + let Some(active) = setup.admission.enter() else { continue; }; let deadline = setup.deadline(); @@ -1368,7 +1368,7 @@ pub(crate) struct Incoming { pub identity: Option, /// When the whole accept must finish; see [`moq_net::Server::deadline`]. pub deadline: Option, - pub active: moq_net::server::Active, + pub active: moq_net::server::Admitted, } #[cfg(any(test, feature = "qmux"))] @@ -1377,7 +1377,7 @@ impl Incoming { pub(crate) fn new( transport: Transport, deadline: Option, - active: moq_net::server::Active, + active: moq_net::server::Admitted, ) -> Self { Self { transport, @@ -1416,7 +1416,7 @@ impl Incoming { remote: Option, local: Option, deadline: Option, - active: moq_net::server::Active, + active: moq_net::server::Admitted, ) -> Self { let server_name = session.server_name().map(str::to_owned); let identity = tls @@ -1501,7 +1501,7 @@ pub struct Link { /// otherwise the Server's configuration is used by default. Call [Self::ok] to start the /// session, or [Self::reject] to reject it (which closes the just-established session). pub struct Request { - active: moq_net::server::Active, + active: moq_net::server::Admitted, transport: Transport, /// The request URL for WebTransport/WebSocket. `None` for bindings whose path rides SETUP. url: Option, @@ -1948,7 +1948,7 @@ mod tests { async fn tcp_stalled_handshake_does_not_block_accept() { use futures::FutureExt; use tokio::io::AsyncReadExt; - let activity = moq_net::server::Activity::default(); + let admission = moq_net::server::Admission::default(); let listener = crate::tcp::Listener::bind("127.0.0.1:0".parse().unwrap()) .await .unwrap() @@ -1958,7 +1958,7 @@ mod tests { let task = spawn_tcp_loop( listener, Setup { - activity: activity.clone(), + admission: admission.clone(), server: moq_net::Server::new().with_timeout(None), }, tx, @@ -1966,7 +1966,7 @@ mod tests { let mut stalled = tokio::net::TcpStream::connect(addr).await.unwrap(); stalled.read_u8().await.expect("first handshake started"); assert!( - activity.close().now_or_never().is_none(), + admission.close().now_or_never().is_none(), "transport handshake must hold admission" ); let mut remaining = Vec::new(); @@ -1979,7 +1979,7 @@ mod tests { } task.abort(); let _ = task.await; - activity.close().await; + admission.close().await; } /// A drain that closed admission refuses at accept instead of starting a @@ -1987,8 +1987,8 @@ mod tests { #[cfg(feature = "tcp")] #[tokio::test] async fn tcp_closed_activity_refuses_at_accept() { - let activity = moq_net::server::Activity::default(); - activity.close().await; + let admission = moq_net::server::Admission::default(); + admission.close().await; let listener = crate::tcp::Listener::bind("127.0.0.1:0".parse().unwrap()) .await .unwrap() @@ -1998,7 +1998,7 @@ mod tests { let task = spawn_tcp_loop( listener, Setup { - activity, + admission, server: moq_net::Server::new().with_timeout(None), }, tx, @@ -2033,7 +2033,7 @@ mod tests { let task = spawn_unix_loop( listener, Setup { - activity: Default::default(), + admission: Default::default(), server: moq_net::Server::new().with_timeout(None), }, Some(crate::unix::Allow { @@ -2078,7 +2078,7 @@ mod tests { async fn unix_stalled_handshake_does_not_block_accept() { use futures::FutureExt; use tokio::io::AsyncReadExt; - let activity = moq_net::server::Activity::default(); + let admission = moq_net::server::Admission::default(); let dir = tempfile::tempdir().unwrap(); let path = dir.path().join("listener.sock"); let listener = crate::unix::Listener::bind(&path) @@ -2089,7 +2089,7 @@ mod tests { let task = spawn_unix_loop( listener, Setup { - activity: activity.clone(), + admission: admission.clone(), server: moq_net::Server::new().with_timeout(None), }, None, @@ -2098,7 +2098,7 @@ mod tests { let mut stalled = tokio::net::UnixStream::connect(&path).await.unwrap(); stalled.read_u8().await.expect("first handshake started"); assert!( - activity.close().now_or_never().is_none(), + admission.close().now_or_never().is_none(), "transport handshake must hold admission" ); let mut remaining = Vec::new(); @@ -2111,7 +2111,7 @@ mod tests { } task.abort(); let _ = task.await; - activity.close().await; + admission.close().await; } /// Stopping the accept loop must drop a stalled handshake at once. Each @@ -2132,7 +2132,7 @@ mod tests { let task = spawn_tcp_loop( listener, Setup { - activity: Default::default(), + admission: Default::default(), server: moq_net::Server::new().with_timeout(None), }, tx, @@ -2160,7 +2160,7 @@ mod tests { let task = spawn_unix_loop( listener, Setup { - activity: Default::default(), + admission: Default::default(), server: moq_net::Server::new().with_timeout(None), }, None, @@ -2202,9 +2202,9 @@ mod tests { let (client, server) = tokio::io::duplex(64 * 1024); let client = WebSocketStream::from_raw_socket(client, Role::Client, None).await; let server = WebSocketStream::from_raw_socket(server, Role::Server, None).await; - let activity = moq_net::server::Activity::default(); + let admission = moq_net::server::Admission::default(); let url = "wss://example.com/room?jwt=token".parse().unwrap(); - let mut options = crate::websocket::Options::new(url, moq_net::Server::new(), activity.enter().unwrap()); + let mut options = crate::websocket::Options::new(url, moq_net::Server::new(), admission.enter().unwrap()); options.link = Link { remote: Some("127.0.0.1:1234".parse().unwrap()), local: Some("127.0.0.1:443".parse().unwrap()), @@ -2232,9 +2232,9 @@ mod tests { assert_eq!(request.server_name(), Some("example.com")); assert_eq!(request.alpn(), Some("qmux-01.moq-lite-06")); assert!(request.peer_identity().is_some()); - assert!(activity.close().now_or_never().is_none()); + assert!(admission.close().now_or_never().is_none()); drop(request); - assert!(activity.close().now_or_never().is_some()); + assert!(admission.close().now_or_never().is_some()); } #[cfg(feature = "websocket")] @@ -2248,11 +2248,11 @@ mod tests { let (client, server) = tokio::io::duplex(64 * 1024); let client = WebSocketStream::from_raw_socket(client, Role::Client, None).await; let server = WebSocketStream::from_raw_socket(server, Role::Server, None).await; - let activity = moq_net::server::Activity::default(); + let admission = moq_net::server::Admission::default(); let mut options = crate::websocket::Options::new( "wss://example.com/room?jwt=url-token".parse().unwrap(), moq_net::Server::new(), - activity.enter().unwrap(), + admission.enter().unwrap(), ); options.link.alpn = Some(protocol.into()); let accept = tokio::spawn(crate::websocket::accept(server, options)); @@ -2450,7 +2450,7 @@ mod tests { #[tokio::test] async fn unreachable_timeout_has_no_deadline() { let setup = Setup { - activity: Default::default(), + admission: Default::default(), server: moq_net::Server::new().with_timeout(Some(std::time::Duration::MAX)), }; assert_eq!(setup.deadline(), None); @@ -2463,7 +2463,7 @@ mod tests { let peer = Scripted::new("moq-lite-06"); let timeout = std::time::Duration::from_secs(10); let setup = Setup { - activity: Default::default(), + admission: Default::default(), server: moq_net::Server::new().with_timeout(Some(timeout)), }; let start = kio::clock::now(); @@ -2507,11 +2507,11 @@ mod tests { peer.setup = Some(bytes.into()); let timeout = std::time::Duration::from_secs(10); let setup = Setup { - activity: Default::default(), + admission: Default::default(), server: moq_net::Server::new().with_timeout(Some(timeout)), }; let start = kio::clock::now(); - let incoming = Incoming::new(Transport::WebSocket, setup.deadline(), setup.activity.enter().unwrap()); + let incoming = Incoming::new(Transport::WebSocket, setup.deadline(), setup.admission.enter().unwrap()); let Ok(request) = Request::accept(&setup.server, peer.clone(), Under::Opaque, incoming).await else { panic!("a readable SETUP was refused"); }; @@ -2546,7 +2546,7 @@ mod tests { let (client, server) = session_pair().await; let timeout = std::time::Duration::from_secs(10); let setup = Setup { - activity: Default::default(), + admission: Default::default(), server: moq_net::Server::new().with_timeout(Some(timeout)), }; let deadline = setup.deadline(); @@ -2626,11 +2626,7 @@ mod tests { let help = Cli::render_help(Cli::command(), true).unwrap(); // Every wire code this crate parses, including the opt-in `-wip` drafts. - let codes = (0xff0dad00..=0xff0dadff).chain(0xff000000..=0xff0000ff); - for name in codes - .filter_map(moq_net::Version::from_code) - .map(|version| version.as_str()) - { + for name in moq_net::Version::ALL.iter().map(|version| version.as_str()) { assert!(help.contains(name), "missing {name} from --server-version help"); } } diff --git a/rs/moq-tokio/src/tcp.rs b/rs/moq-tokio/src/tcp.rs index d5f634c14c1..a67a6c249ba 100644 --- a/rs/moq-tokio/src/tcp.rs +++ b/rs/moq-tokio/src/tcp.rs @@ -292,7 +292,7 @@ impl TlsAcceptor { pub async fn accept( &self, stream: tokio_rustls::server::TlsStream, - active: moq_net::server::Active, + active: moq_net::server::Admitted, ) -> crate::Result where T: tokio::io::AsyncRead + tokio::io::AsyncWrite + AsRef + Send + Unpin + 'static, diff --git a/rs/moq-tokio/src/websocket.rs b/rs/moq-tokio/src/websocket.rs index 1670aba1fb0..bba728ed7bf 100644 --- a/rs/moq-tokio/src/websocket.rs +++ b/rs/moq-tokio/src/websocket.rs @@ -114,7 +114,7 @@ type Result = std::result::Result; pub struct Options { pub(crate) url: Url, pub(crate) server: moq_net::Server, - pub(crate) active: moq_net::server::Active, + pub(crate) active: moq_net::server::Admitted, /// The addresses and negotiated subprotocol captured before the upgrade. pub link: crate::server::Link, /// The verified TLS peer, when the HTTP server requested a certificate. @@ -129,7 +129,7 @@ pub struct Options { impl Options { /// Carry an accepted connection's guard, URL, and MoQ policy through its upgrade. - pub fn new(url: Url, server: moq_net::Server, active: moq_net::server::Active) -> Self { + pub fn new(url: Url, server: moq_net::Server, active: moq_net::server::Admitted) -> Self { Self { url, server, @@ -1034,11 +1034,11 @@ mod tests { stream_receive_window: Some(256 * 1024), ..Default::default() }; - let activity = moq_net::server::Activity::default(); + let admission = moq_net::server::Admission::default(); let mut options = Options::new( "ws://localhost/".parse().unwrap(), moq_net::Server::new().with_versions(moq_net::Versions::all()), - activity.enter().unwrap(), + admission.enter().unwrap(), ); options.link.alpn = Some(alpn.clone()); options.quic = quic.resolve(); @@ -1069,9 +1069,9 @@ mod tests { fn moqt_18_and_newer_pin_to_qmux01() { // The literals in `qmux_versions_for` must stay the IETF draft ALPNs; // otherwise the pin silently stops matching. - let drafts: Vec<_> = [0xff000012, 0xff000014, 0xff000016] + let drafts: Vec<_> = ["moq-transport-18", "moq-transport-20", "moq-transport-22"] .into_iter() - .map(|code| moq_net::Version::from_code(code).unwrap().alpn()) + .map(|name| name.parse::().unwrap().alpn()) .collect(); assert_eq!(QMUX01_ONLY_ALPNS, drafts); for &alpn in QMUX01_ONLY_ALPNS { @@ -1158,12 +1158,12 @@ mod timeout_tests { #[tokio::test(start_paused = true)] async fn silent_qmux_peer_is_refused_at_the_deadline() { const ALPN: &str = "qmux-01.moq-lite-06"; - let activity = moq_net::server::Activity::default(); + let admission = moq_net::server::Admission::default(); let timeout = time::Duration::from_secs(1); let mut options = Options::new( "ws://localhost/".parse().unwrap(), moq_net::Server::new().with_timeout(Some(timeout)), - activity.enter().unwrap(), + admission.enter().unwrap(), ); options.link.alpn = Some(ALPN.into()); let (server, _peer) = tokio::io::duplex(4096); @@ -1185,11 +1185,11 @@ mod timeout_tests { const ALPN: &str = "qmux-01.moq-lite-06"; let short = time::Duration::from_secs(1); for (timeout, expires) in [(Some(short), true), (None, false)] { - let activity = moq_net::server::Activity::default(); + let admission = moq_net::server::Admission::default(); let mut options = Options::new( "ws://localhost/".parse().unwrap(), moq_net::Server::new().with_timeout(timeout), - activity.enter().unwrap(), + admission.enter().unwrap(), ); options.link.alpn = Some(ALPN.into()); // Complete QMux over an in-memory WebSocket, then withhold MoQ SETUP. diff --git a/rs/moq-tokio/tests/integration/broadcast.rs b/rs/moq-tokio/tests/integration/broadcast.rs index 5508bbfe111..b0e5655bc61 100644 --- a/rs/moq-tokio/tests/integration/broadcast.rs +++ b/rs/moq-tokio/tests/integration/broadcast.rs @@ -1155,10 +1155,8 @@ async fn broadcast_rejoin_skips_a_stale_warm_cache() { "moq-lite-04", "moq-lite-05", ]; - let every = (0xff0dad00..=0xff0dadff) - .chain(0xff000000..=0xff0000ff) - .filter_map(moq_net::Version::from_code); - for version in every + for version in moq_net::Version::ALL + .iter() .map(|version| version.as_str()) .filter(|version| !pre06.contains(version)) { @@ -1290,11 +1288,7 @@ async fn rejoin_skips_a_stale_warm_cache(version: &str) { /// open (a JSON log appending frames to group 0), on every version. #[tokio::test] async fn broadcast_rejoin_replays_a_current_warm_cache() { - for version in (0xff0dad00..=0xff0dadff) - .chain(0xff000000..=0xff0000ff) - .filter_map(moq_net::Version::from_code) - .map(|version| version.as_str()) - { + for version in moq_net::Version::ALL.iter().map(|version| version.as_str()) { for open in [false, true] { rejoin_replays_a_current_warm_cache(version, open).await; } diff --git a/rs/moq-tokio/tests/integration/datagram_tracks.rs b/rs/moq-tokio/tests/integration/datagram_tracks.rs index 5d23061814c..5d69efc9f2b 100644 --- a/rs/moq-tokio/tests/integration/datagram_tracks.rs +++ b/rs/moq-tokio/tests/integration/datagram_tracks.rs @@ -203,10 +203,7 @@ async fn run(relay: bool, js_publishes: bool) { let (mut child, mut lines) = spawn("subscribe"); expect_line(&mut lines, "subscribed").await; - let mut priority = None; - while priority != Some(PRIORITY) { - priority = kio::wait(|waiter| audio.poll_priority(waiter, priority)).await; - } + while audio.priority_changed().await != Some(PRIORITY) {} for (sequence, micros, payload) in AUDIO { audio .insert(datagram::Datagram { diff --git a/rs/moq-tokio/tests/integration/migrate.rs b/rs/moq-tokio/tests/integration/migrate.rs index aa53e31f36b..ceb889baf52 100644 --- a/rs/moq-tokio/tests/integration/migrate.rs +++ b/rs/moq-tokio/tests/integration/migrate.rs @@ -70,7 +70,8 @@ fn connect(origin: &moq_net::origin::Producer, port: u16, versions: Vec().unwrap()) } diff --git a/rs/moq-uring/src/quic/driver/connection.rs b/rs/moq-uring/src/quic/driver/connection.rs index 76785931860..328922494cc 100644 --- a/rs/moq-uring/src/quic/driver/connection.rs +++ b/rs/moq-uring/src/quic/driver/connection.rs @@ -53,7 +53,7 @@ pub(crate) struct Inner { } pub(crate) struct State { - pub(crate) active: Option, + pub(crate) active: Option, /// Wakes the driver when the endpoint fed the connection (a received /// datagram, an unreachable peer) so it answers and re-arms its timers, or /// failed it from outside. Handles need no wake of their own: whatever diff --git a/rs/moq-uring/src/quic/driver/endpoint.rs b/rs/moq-uring/src/quic/driver/endpoint.rs index 914d776b1af..2d7ddb65822 100644 --- a/rs/moq-uring/src/quic/driver/endpoint.rs +++ b/rs/moq-uring/src/quic/driver/endpoint.rs @@ -37,7 +37,7 @@ struct Accepting { /// State shared by the handles, the demux task, and the per-connection /// teardown tasks. pub(crate) struct Inner { - activity: moq_net::server::Activity, + admission: moq_net::server::Admission, /// The socket's worker, where every task of this endpoint runs. owner: Owner, socket: Rc, @@ -115,7 +115,7 @@ impl Endpoint { )?; let inner = Rc::new(Inner { - activity: config.activity, + admission: config.admission, owner, socket: Rc::new(socket), local, @@ -377,7 +377,7 @@ impl Inner { // Closed for drain: refuse so the peer redials elsewhere instead of // retransmitting into a server that is leaving. - let Some(active) = self.activity.enter() else { + let Some(active) = self.admission.enter() else { buf.clear(); let transmit = self.endpoint.borrow_mut().refuse(incoming, buf); self.respond(&transmit, buf); diff --git a/rs/moq-uring/src/quic/endpoint.rs b/rs/moq-uring/src/quic/endpoint.rs index b6a95752e5f..54f2a58a0eb 100644 --- a/rs/moq-uring/src/quic/endpoint.rs +++ b/rs/moq-uring/src/quic/endpoint.rs @@ -32,7 +32,7 @@ pub use super::driver::Endpoint; #[non_exhaustive] pub struct Config { /// Tracks accepted connections from admission until transport closure. - pub activity: moq_net::server::Activity, + pub admission: moq_net::server::Admission, /// Accept incoming connections with this configuration. Without it the /// endpoint only dials, and inbound handshakes are dropped. pub server: Option, @@ -62,7 +62,7 @@ pub struct Config { impl std::fmt::Debug for Config { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("Config") - .field("activity", &self.activity) + .field("admission", &self.admission) .field("server", &self.server) .field("backlog", &self.backlog) .field("handshake", &self.handshake) @@ -75,7 +75,7 @@ impl Default for Config { fn default() -> Self { Self { server: None, - activity: Default::default(), + admission: Default::default(), backlog: 1024, handshake: Default::default(), reset_secret: None, diff --git a/rs/moq-uring/tests/integration/endpoint.rs b/rs/moq-uring/tests/integration/endpoint.rs index 79bcee6f8cb..fc30a1b1edd 100644 --- a/rs/moq-uring/tests/integration/endpoint.rs +++ b/rs/moq-uring/tests/integration/endpoint.rs @@ -228,8 +228,8 @@ fn dropping_the_last_connection_handle_closes_it() { fn a_close_reaches_both_ends_with_its_code() { let Some(mut worker) = worker() else { return }; let handle = worker.handle(); - let activity = moq_net::server::Activity::default(); - let outgoing = moq_net::server::Activity::default(); + let admission = moq_net::server::Admission::default(); + let outgoing = moq_net::server::Admission::default(); let certs = support::certs().expect("certificates"); let socket = |handle: &moq_uring::Handle| { @@ -238,10 +238,10 @@ fn a_close_reaches_both_ends_with_its_code() { .expect("socket") }; let mut incoming_config = quic::endpoint::Config::default().with_server(server_config(&certs)); - incoming_config.activity = activity.clone(); + incoming_config.admission = admission.clone(); let server = quic::Endpoint::new(incoming_config, socket(&handle)).expect("server endpoint"); let mut outgoing_config = quic::endpoint::Config::default(); - outgoing_config.activity = outgoing.clone(); + outgoing_config.admission = outgoing.clone(); let client = quic::Endpoint::new(outgoing_config, socket(&handle)).expect("dial-only endpoint"); worker @@ -250,15 +250,15 @@ fn a_close_reaches_both_ends_with_its_code() { .connect(&dial_config(), server.local_addr(), "localhost") .await .expect("dial"); - let closes = |activity: &moq_net::server::Activity| { - let mut future = std::pin::pin!(activity.close()); + let closes = |admission: &moq_net::server::Admission| { + let mut future = std::pin::pin!(admission.close()); std::future::Future::poll( future.as_mut(), &mut std::task::Context::from_waker(std::task::Waker::noop()), ) .is_ready() }; - assert!(!closes(&activity), "unclaimed incoming connection holds admission"); + assert!(!closes(&admission), "unclaimed incoming connection holds admission"); assert!(closes(&outgoing), "outbound dials are not admissions"); let mut accepted = server.accept().await.expect("accept"); @@ -274,7 +274,7 @@ fn a_close_reaches_both_ends_with_its_code() { } } assert!( - closes(&activity), + closes(&admission), "closed transport releases admission even while handles survive" ); assert!( @@ -282,7 +282,7 @@ fn a_close_reaches_both_ends_with_its_code() { .connect(&dial_config(), server.local_addr(), "localhost") .await .is_err(), - "closed activity refuses a new connection at accept" + "closed admission refuses a new connection at accept" ); }) .expect("worker"); diff --git a/rs/moq-webrtc/src/p2p/mod.rs b/rs/moq-webrtc/src/p2p/mod.rs index 755aba406ad..35b8f9ff10e 100644 --- a/rs/moq-webrtc/src/p2p/mod.rs +++ b/rs/moq-webrtc/src/p2p/mod.rs @@ -468,7 +468,7 @@ impl Answerer { /// one session may take the channel. pub async fn accept(&self, listener: &moq_tokio::Listener) -> Result { // Held until `accept_with` takes its own, so a drain that starts meanwhile waits. - let _establishing = listener.activity().enter().ok_or(moq_tokio::Error::Stopped)?; + let _establishing = listener.admission().enter().ok_or(moq_tokio::Error::Stopped)?; let establish = async { let opened = self.peer.channel().await?; if opened.protocol != self.protocol { diff --git a/rs/moq-webrtc/src/p2p/tests.rs b/rs/moq-webrtc/src/p2p/tests.rs index f2146e3f2d5..6c41e1a45a1 100644 --- a/rs/moq-webrtc/src/p2p/tests.rs +++ b/rs/moq-webrtc/src/p2p/tests.rs @@ -427,14 +427,14 @@ async fn a_drain_waits_for_an_establishing_peer() { .await .unwrap(); - let activity = moq_net::server::Activity::default(); + let admission = moq_net::server::Admission::default(); let mut config = moq_tokio::server::Config::default(); - config.activity = activity.clone(); + config.admission = admission.clone(); let listener = config.init_streams().unwrap().listen().await.unwrap(); let mut accept = std::pin::pin!(answerer.accept(&listener)); // The answer is not applied yet, so the channel cannot open. assert!(futures::poll!(accept.as_mut()).is_pending()); - let mut closed = std::pin::pin!(activity.close()); + let mut closed = std::pin::pin!(admission.close()); assert!( futures::poll!(closed.as_mut()).is_pending(), "the drain skipped the establishing peer" diff --git a/test/interop/clients/rust/tail.rs b/test/interop/clients/rust/tail.rs index 199aefa9e61..bdef9f88f82 100644 --- a/test/interop/clients/rust/tail.rs +++ b/test/interop/clients/rust/tail.rs @@ -121,10 +121,7 @@ async fn main() -> anyhow::Result<()> { .connect(url) .established() .await?; - let mut priority = track.priority(); - while priority.is_none() { - priority = kio::wait(|waiter| track.poll_priority(waiter, priority)).await; - } + while kio::wait(|waiter| track.poll_priority_changed(waiter)).await.is_none() {} for sequence in 0..GROUPS { ensure!( commands.next_line().await?.as_deref() == Some(&format!("datagram {sequence}")), From 408f4648105faacdb8e3b1e300f3a6aa351ea81f Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sun, 8 Nov 2026 02:47:05 -0800 Subject: [PATCH 3/7] refactor(net)!: a Compression enum, stats argument structs, an explicit report time, and a narrower surface - track::Info::compression takes a Compression enum (None, Deflate) matching the wire values, mirrored in @moq/net ("none" | "deflate"), moq-ffi, moq-c, and every binding. - stats::Handle::{refuse, session} take #[non_exhaustive] Refusal and SessionInfo structs, and stats::Registry::report takes the drain's now. - auth::Grant is #[non_exhaustive]. - origin::Consumer::with_proxy is removed; set it on the origin::Producer. - group::MAX_CACHE_BYTES is pub(crate); moq-json, moq-mux, and moq-stats keep their own 32 MiB limits. - The route refusal of a minted instance is backed out and left for the maintainer in the quest. Co-Authored-By: Claude Opus 5.5 --- c/moq/MIGRATE.md | 4 +- dart/moq/MIGRATE.md | 2 +- dart/moq/lib/json.dart | 4 +- dart/moq/test/moq_test.dart | 10 +- dart/moq_ffi/lib/src/moq.dart | 101 +++++++- demo/carla/sim/moq_carla_sim/publish.py | 2 +- demo/carla/sim/tests/conftest.py | 1 + demo/carla/web/src/preview.ts | 2 +- demo/carla/web/src/truck.test.ts | 4 +- doc/concept/compression.md | 6 +- doc/lib/c/index.md | 2 +- doc/lib/cpp/index.md | 2 +- doc/lib/dart/index.md | 4 +- doc/lib/go/index.md | 2 +- doc/lib/js/json.md | 2 +- doc/lib/kt/index.md | 4 +- doc/lib/layers.md | 2 +- doc/lib/py/index.md | 4 +- doc/lib/rs/moq-json.md | 2 +- doc/lib/rs/moq-net.md | 2 +- doc/lib/swift/index.md | 4 +- go/wrapper/MIGRATE.md | 6 +- go/wrapper/README.md | 3 +- go/wrapper/json/json.go | 2 +- go/wrapper/json/json_test.go | 6 +- go/wrapper/records.go | 10 +- go/wrapper/types.go | 8 + js/hang/src/report.ts | 2 +- js/json/MIGRATE.md | 2 +- js/json/README.md | 2 +- js/json/bench/stream.ts | 2 +- js/json/src/snapshot/producer.ts | 2 +- js/json/src/snapshot/snapshot.test.ts | 4 +- js/json/src/stream/index.ts | 2 +- js/json/src/stream/stream.test.ts | 16 +- js/json/src/window/window.test.ts | 8 +- js/net/api/index.api.md | 3 +- js/net/bench/compression-fanout.ts | 8 +- js/net/src/flate/group.test.ts | 10 +- js/net/src/lite/compression.test.ts | 4 +- js/net/src/lite/datagram-tracks.test.ts | 2 +- js/net/src/lite/publisher.ts | 4 +- js/net/src/lite/subscriber.ts | 2 +- js/net/src/lite/tracks.test.ts | 4 +- js/net/src/origin.test.ts | 12 - js/net/src/origin.ts | 12 +- js/net/src/resume.test.ts | 2 +- js/net/src/resume.ts | 2 +- js/net/src/track.test.ts | 2 +- js/net/src/track.ts | 21 +- js/publish/src/broadcast.ts | 2 +- js/publish/src/catalog.ts | 2 +- js/watch/src/broadcast.test.ts | 2 +- kt/moq/MIGRATE.md | 2 +- .../kotlin/dev/moq/Aliases.kt | 5 + .../kotlin/dev/moq/json/Tracks.kt | 6 +- .../kotlin/dev/moq/SmokeTest.kt | 5 +- py/moq-rs/MIGRATE.md | 2 +- py/moq-rs/README.md | 2 +- py/moq-rs/moq/__init__.py | 2 + py/moq-rs/moq/_records.py | 11 +- py/moq-rs/moq/json.py | 2 +- py/moq-rs/moq/types.py | 4 + py/moq-rs/tests/test_local.py | 6 +- quest/m2/api-shape/README.md | 2 +- quest/m2/api-shape/net.md | 102 +++----- rs/hang/src/catalog/root.rs | 4 +- rs/moq-auth/src/mesh/mod.rs | 5 +- rs/moq-c/MIGRATE.md | 6 +- rs/moq-c/build.rs | 1 + rs/moq-c/src/api.rs | 24 +- rs/moq-c/src/publish.rs | 2 +- rs/moq-c/src/test.rs | 32 +-- rs/moq-cli/src/args.rs | 5 +- rs/moq-cli/src/report.rs | 2 +- rs/moq-ffi/MIGRATE.md | 6 +- rs/moq-ffi/src/bench.rs | 2 +- rs/moq-ffi/src/datagram.rs | 16 +- rs/moq-ffi/src/json.rs | 2 +- rs/moq-ffi/src/producer.rs | 30 ++- rs/moq-ffi/src/test.rs | 23 +- rs/moq-gst/tests/element.rs | 2 +- rs/moq-hls/src/export/mod.rs | 2 +- rs/moq-json/MIGRATE.md | 4 +- rs/moq-json/examples/telemetry.rs | 7 +- rs/moq-json/src/lib.rs | 4 + rs/moq-json/src/snapshot/consumer.rs | 13 +- rs/moq-json/src/snapshot/encoder.rs | 12 +- rs/moq-json/src/snapshot/mod.rs | 10 +- rs/moq-json/src/snapshot/producer.rs | 4 +- rs/moq-json/src/stream/consumer.rs | 6 +- rs/moq-json/src/stream/encoder.rs | 4 +- rs/moq-json/src/stream/mod.rs | 25 +- rs/moq-json/src/window/encoder.rs | 2 +- rs/moq-json/src/window/mod.rs | 4 +- rs/moq-mux/MIGRATE.md | 4 +- rs/moq-mux/src/catalog/producer.rs | 20 +- rs/moq-mux/src/catalog/tracks.rs | 2 +- rs/moq-mux/src/container/consumer.rs | 2 +- rs/moq-mux/src/container/fmp4/import.rs | 2 +- rs/moq-mux/src/container/fmp4/mod.rs | 10 +- rs/moq-mux/src/container/test_util.rs | 4 +- rs/moq-mux/src/fuzz.rs | 2 +- rs/moq-mux/src/jitter.rs | 2 +- rs/moq-mux/src/json.rs | 8 +- .../tests/integration/hop_limit.rs | 4 +- .../tests/integration/ietf_conformance.rs | 2 +- rs/moq-net-tests/tests/integration/refresh.rs | 2 +- rs/moq-net-tests/tests/integration/restart.rs | 2 +- rs/moq-net-tests/tests/integration/serve.rs | 2 +- rs/moq-net/benches/group.rs | 9 +- rs/moq-net/benches/origin.rs | 7 +- rs/moq-net/benches/session/mod.rs | 8 +- rs/moq-net/benches/stats.rs | 24 +- rs/moq-net/src/auth.rs | 4 +- rs/moq-net/src/client.rs | 12 +- rs/moq-net/src/coding/reader.rs | 4 +- rs/moq-net/src/coding/writer.rs | 2 +- rs/moq-net/src/error.rs | 2 +- rs/moq-net/src/fuzz.rs | 14 +- rs/moq-net/src/fuzz/ingest.rs | 12 +- rs/moq-net/src/ietf/object.rs | 5 +- rs/moq-net/src/ietf/properties.rs | 2 +- rs/moq-net/src/ietf/publisher.rs | 16 +- rs/moq-net/src/ietf/request_stream.rs | 4 +- rs/moq-net/src/ietf/subscriber.rs | 7 +- rs/moq-net/src/lite/ietf.rs | 4 +- rs/moq-net/src/lite/publisher.rs | 2 +- rs/moq-net/src/lite/subscriber.rs | 6 +- rs/moq-net/src/lite/track.rs | 63 +++-- rs/moq-net/src/lite/tracks.rs | 4 +- rs/moq-net/src/model/flate.rs | 2 +- rs/moq-net/src/model/front.rs | 2 +- rs/moq-net/src/model/group.rs | 32 +-- rs/moq-net/src/model/origin.rs | 83 ++----- rs/moq-net/src/model/resume.rs | 8 +- rs/moq-net/src/model/track.rs | 51 ++-- rs/moq-net/src/server.rs | 8 +- rs/moq-net/src/stats.rs | 229 ++++++++++++------ rs/moq-net/src/test_interop.rs | 7 +- .../integration/announce_covering_route.rs | 2 +- .../tests/integration/announce_takeover.rs | 2 +- .../tests/integration/announce_to_serve.rs | 2 +- .../tests/integration/answer_behind_cache.rs | 2 +- rs/moq-net/tests/integration/auth.rs | 34 +-- .../tests/integration/broadcast_close.rs | 2 +- .../tests/integration/catalog_acquisition.rs | 2 +- rs/moq-net/tests/integration/catalog_churn.rs | 2 +- .../tests/integration/catalog_handover.rs | 2 +- rs/moq-net/tests/integration/compress.rs | 17 +- rs/moq-net/tests/integration/control_stats.rs | 10 +- rs/moq-net/tests/integration/datagram.rs | 2 +- .../tests/integration/dial_split_horizon.rs | 2 +- rs/moq-net/tests/integration/drained_claim.rs | 2 +- rs/moq-net/tests/integration/empty_group.rs | 2 +- rs/moq-net/tests/integration/errored_end.rs | 2 +- rs/moq-net/tests/integration/extensions.rs | 2 +- .../tests/integration/fastest_reader.rs | 2 +- rs/moq-net/tests/integration/fetch_cancel.rs | 2 +- rs/moq-net/tests/integration/fetch_fanout.rs | 2 +- .../tests/integration/fetch_from_feed.rs | 2 +- rs/moq-net/tests/integration/fetch_only.rs | 2 +- .../tests/integration/fetch_pipeline.rs | 2 +- .../integration/finished_broadcast_mock.rs | 2 +- rs/moq-net/tests/integration/finite_relay.rs | 2 +- rs/moq-net/tests/integration/flights.rs | 2 +- rs/moq-net/tests/integration/goaway.rs | 2 +- rs/moq-net/tests/integration/group_order.rs | 2 +- .../tests/integration/history_groups.rs | 2 +- .../tests/integration/idle_cancel_refetch.rs | 2 +- rs/moq-net/tests/integration/idle_session.rs | 6 +- rs/moq-net/tests/integration/instance.rs | 2 +- .../tests/integration/late_lower_group.rs | 2 +- .../tests/integration/lazy_discovery.rs | 2 +- rs/moq-net/tests/integration/mesh_withdraw.rs | 7 +- rs/moq-net/tests/integration/mount.rs | 4 +- rs/moq-net/tests/integration/multi_cdn.rs | 2 +- rs/moq-net/tests/integration/partial_group.rs | 2 +- rs/moq-net/tests/integration/quiet_catalog.rs | 2 +- rs/moq-net/tests/integration/range_anchors.rs | 2 +- rs/moq-net/tests/integration/range_fill.rs | 2 +- rs/moq-net/tests/integration/range_read.rs | 2 +- .../tests/integration/received_rewind.rs | 2 +- rs/moq-net/tests/integration/rejoin.rs | 2 +- .../tests/integration/relay_upstream_close.rs | 2 +- rs/moq-net/tests/integration/replacement.rs | 2 +- rs/moq-net/tests/integration/request_caps.rs | 2 +- rs/moq-net/tests/integration/route_change.rs | 10 +- .../tests/integration/segmented_frame.rs | 2 +- rs/moq-net/tests/integration/session_close.rs | 4 +- .../integration/settled_end_survives_abort.rs | 2 +- rs/moq-net/tests/integration/slow_joiner.rs | 2 +- rs/moq-net/tests/integration/socket.rs | 2 +- rs/moq-net/tests/integration/source_errors.rs | 2 +- rs/moq-net/tests/integration/stream_credit.rs | 2 +- .../tests/integration/subscribe_priority.rs | 2 +- .../tests/integration/subscribe_ranges.rs | 2 +- .../tests/integration/subscribe_tracks.rs | 2 +- .../tests/integration/subscribe_with_track.rs | 2 +- .../tests/integration/subscriber_max_age.rs | 2 +- .../integration/subscription_end_integrity.rs | 2 +- .../tests/integration/support/harness.rs | 8 +- rs/moq-net/tests/integration/synced.rs | 2 +- .../integration/track_abort_over_session.rs | 2 +- .../tests/integration/track_info_cancel.rs | 2 +- .../tests/integration/track_stream_demand.rs | 2 +- rs/moq-net/tests/integration/track_tail.rs | 2 +- rs/moq-net/tests/integration/tracks.rs | 6 +- rs/moq-net/tests/integration/tracks_ietf.rs | 2 +- .../tests/integration/unannounce_release.rs | 2 +- rs/moq-net/tests/integration/untimed.rs | 2 +- rs/moq-net/tests/integration/warm_backfill.rs | 2 +- rs/moq-net/tests/integration/wide_hop.rs | 2 +- rs/moq-net/tests/integration/wide_sequence.rs | 2 +- .../tests/integration/widened_max_age.rs | 4 +- rs/moq-relay/src/auth.rs | 9 +- rs/moq-relay/src/auth/admission_tests.rs | 4 +- rs/moq-relay/src/auth/refresh.rs | 26 +- rs/moq-relay/src/cluster.rs | 10 +- rs/moq-relay/src/internal.rs | 24 +- rs/moq-relay/src/refusals.rs | 10 +- rs/moq-relay/src/uring.rs | 2 +- rs/moq-relay/src/web.rs | 4 +- .../tests/integration/auth_lifetime.rs | 2 +- rs/moq-relay/tests/integration/refusals.rs | 7 +- rs/moq-stats/benches/producer_tick.rs | 17 +- rs/moq-stats/src/aggregate.rs | 18 +- rs/moq-stats/src/consume.rs | 2 +- rs/moq-stats/src/produce.rs | 148 ++++++----- rs/moq-tokio/src/server.rs | 2 +- rs/moq-tokio/tests/integration/broadcast.rs | 2 +- swift/MIGRATE.md | 2 +- swift/README.md | 2 +- swift/Sources/Moq/Aliases.swift | 2 + swift/Sources/Moq/Json.swift | 2 +- swift/Tests/MoqTests/SmokeTests.swift | 6 +- test/interop/clients/js-native/catalog.ts | 6 +- test/interop/clients/js-native/hls.ts | 2 +- test/interop/clients/js-native/tail.ts | 9 +- test/interop/clients/rust/catalog.rs | 5 +- test/interop/clients/rust/tail.rs | 8 +- 241 files changed, 1178 insertions(+), 837 deletions(-) diff --git a/c/moq/MIGRATE.md b/c/moq/MIGRATE.md index 98cd2db4c41..2ad00f40654 100644 --- a/c/moq/MIGRATE.md +++ b/c/moq/MIGRATE.md @@ -145,9 +145,9 @@ Publish a replacement under a new name, and expect a finished track's demand ter To answer with a broadcast you already hold, `moq_broadcast_request_serve(request, consumer)` serves it under the prefix route without announcing an exact route; the consumer stays yours to free. `moq_broadcast_prepared_free` refuses an answer you will not publish. -### `moq_track_info` gains `compress` (#5928) +### `moq_track_info` gains `compression` (#5928) -The new trailing field changes its ABI. A zero-initialized struct leaves it false, as before. +The new trailing field changes its ABI. A zero-initialized struct leaves it `MOQ_COMPRESSION_NONE`, as before. ### Anchors can name a time (#6074) diff --git a/dart/moq/MIGRATE.md b/dart/moq/MIGRATE.md index 5d7dac2a1ac..67ec23a4d59 100644 --- a/dart/moq/MIGRATE.md +++ b/dart/moq/MIGRATE.md @@ -102,7 +102,7 @@ A fixed audio playout delay `d` is `delay: Delay(min: d, max: ...)` with `estima ### Compression moves to the track `package:moq/flate.dart` is removed: publish opaque bytes on a `TrackProducer`. -`SnapshotConfig` and `WindowConfig` lose `compression`, and `StreamConfig` is removed. Publish the track with `MoqTrackInfo(compress: true)` instead. +`SnapshotConfig` and `WindowConfig` lose `compression`, and `StreamConfig` is removed. Publish the track with `MoqTrackInfo(compression: MoqCompression.deflate)` instead. `StreamProducer` drops its `config`, and `StreamConsumer` and `WindowConsumer` take only the track. `SnapshotConsumer` takes the broadcast and track name; see the entry above. ### Paths with an empty segment are refused ([#6648](https://github.com/moq-dev/moq/pull/6648)) diff --git a/dart/moq/lib/json.dart b/dart/moq/lib/json.dart index cda9004ac77..a9c7da503f8 100644 --- a/dart/moq/lib/json.dart +++ b/dart/moq/lib/json.dart @@ -4,7 +4,7 @@ /// snapshot and stream producers also advertise it in the broadcast's catalog, /// which has no window mode), and a consumer takes over a `TrackConsumer` that /// has not read a group yet. Values cross as JSON strings. Compression is the -/// track's: publish JSON with `MoqTrackInfo(compress: true)`, and a consumer +/// track's: publish JSON with `MoqTrackInfo(compression: MoqCompression.deflate)`, and a consumer /// reads it with no option of its own. Every write (a snapshot update, a stream /// append, a window push or pop) takes a timestamp on the broadcast clock, the /// epoch every track in the broadcast shares, so the track needs a timescale; @@ -18,7 +18,7 @@ /// broadcast: broadcast, /// track: broadcast.publishTrack( /// name: 'status', -/// info: MoqTrackInfo(timescale: 1000, compress: true), +/// info: MoqTrackInfo(timescale: 1000, compression: MoqCompression.deflate), /// ), /// config: moq_json.SnapshotConfig(), /// ); diff --git a/dart/moq/test/moq_test.dart b/dart/moq/test/moq_test.dart index 0e6d525cf5b..9a2968df10a 100644 --- a/dart/moq/test/moq_test.dart +++ b/dart/moq/test/moq_test.dart @@ -715,7 +715,10 @@ void main() { broadcast: broadcast, track: broadcast.publishTrack( name: 'status', - info: MoqTrackInfo(timescale: 1000000, compress: true), + info: MoqTrackInfo( + timescale: 1000000, + compression: MoqCompression.deflate, + ), ), config: moq_json.SnapshotConfig(), ); @@ -751,7 +754,10 @@ void main() { final producer = moq_json.WindowProducer( track: broadcast.publishTrack( name: 'log', - info: MoqTrackInfo(timescale: 1000000, compress: true), + info: MoqTrackInfo( + timescale: 1000000, + compression: MoqCompression.deflate, + ), ), config: moq_json.WindowConfig(), ); diff --git a/dart/moq_ffi/lib/src/moq.dart b/dart/moq_ffi/lib/src/moq.dart index 290b21c71fd..3c2cc87c1d3 100644 --- a/dart/moq_ffi/lib/src/moq.dart +++ b/dart/moq_ffi/lib/src/moq.dart @@ -3259,14 +3259,14 @@ class MoqTrackInfo { final bool maxAgeUnlimited; final int? refresh; final int? timescale; - final bool compress; + final MoqCompression? compression; MoqTrackInfo({ this.priority = 0, this.maxAge = null, this.maxAgeUnlimited = false, this.refresh = null, this.timescale = null, - this.compress = false, + this.compression = null, }); } @@ -3302,11 +3302,11 @@ class FfiConverterMoqTrackInfo { ); final timescale = timescale_lifted.value; new_offset += timescale_lifted.bytesRead; - final compress_lifted = FfiConverterBool.read( + final compression_lifted = FfiConverterOptionalMoqCompression.read( Uint8List.view(buf.buffer, new_offset), ); - final compress = compress_lifted.value; - new_offset += compress_lifted.bytesRead; + final compression = compression_lifted.value; + new_offset += compression_lifted.bytesRead; return LiftRetVal( MoqTrackInfo( priority: priority, @@ -3314,7 +3314,7 @@ class FfiConverterMoqTrackInfo { maxAgeUnlimited: maxAgeUnlimited, refresh: refresh, timescale: timescale, - compress: compress, + compression: compression, ), new_offset - buf.offsetInBytes, ); @@ -3327,7 +3327,7 @@ class FfiConverterMoqTrackInfo { FfiConverterBool.allocationSize(value.maxAgeUnlimited) + FfiConverterOptionalUInt32.allocationSize(value.refresh) + FfiConverterOptionalUInt64.allocationSize(value.timescale) + - FfiConverterBool.allocationSize(value.compress) + + FfiConverterOptionalMoqCompression.allocationSize(value.compression) + 0; final buf = Uint8List(total_length); write(value, buf); @@ -3356,8 +3356,8 @@ class FfiConverterMoqTrackInfo { value.timescale, Uint8List.view(buf.buffer, new_offset), ); - new_offset += FfiConverterBool.write( - value.compress, + new_offset += FfiConverterOptionalMoqCompression.write( + value.compression, Uint8List.view(buf.buffer, new_offset), ); return new_offset - buf.offsetInBytes; @@ -3369,7 +3369,7 @@ class FfiConverterMoqTrackInfo { FfiConverterBool.allocationSize(value.maxAgeUnlimited) + FfiConverterOptionalUInt32.allocationSize(value.refresh) + FfiConverterOptionalUInt64.allocationSize(value.timescale) + - FfiConverterBool.allocationSize(value.compress) + + FfiConverterOptionalMoqCompression.allocationSize(value.compression) + 0; } } @@ -8578,6 +8578,40 @@ class AbsentMoqAnnounceEvent extends MoqAnnounceEvent { } } +enum MoqCompression { deflate } + +class FfiConverterMoqCompression { + static LiftRetVal read(Uint8List buf) { + final index = buf.buffer.asByteData(buf.offsetInBytes).getInt32(0); + switch (index) { + case 1: + return LiftRetVal(MoqCompression.deflate, 4); + default: + throw UniffiInternalError( + UniffiInternalError.unexpectedEnumCase, + "Unable to determine enum variant", + ); + } + } + + static MoqCompression lift(RustBuffer buffer) { + return FfiConverterMoqCompression.read(buffer.asUint8List()).value; + } + + static RustBuffer lower(MoqCompression input) { + return toRustBuffer(createUint8ListFromInt(input.index + 1)); + } + + static int allocationSize(MoqCompression _value) { + return 4; + } + + static int write(MoqCompression value, Uint8List buf) { + buf.buffer.asByteData(buf.offsetInBytes).setInt32(0, value.index + 1); + return 4; + } +} + enum MoqTransport { quic, webSocket, tcp, unix, webTransport } class FfiConverterMoqTransport { @@ -17574,6 +17608,53 @@ class FfiConverterOptionalMoqCatalog { } } +class FfiConverterOptionalMoqCompression { + static MoqCompression? lift(RustBuffer buf) { + return FfiConverterOptionalMoqCompression.read(buf.asUint8List()).value; + } + + static LiftRetVal read(Uint8List buf) { + if (ByteData.view(buf.buffer, buf.offsetInBytes).getInt8(0) == 0) { + return LiftRetVal(null, 1); + } + final result = FfiConverterMoqCompression.read( + Uint8List.view(buf.buffer, buf.offsetInBytes + 1), + ); + return LiftRetVal(result.value, result.bytesRead + 1); + } + + static int allocationSize([MoqCompression? value]) { + if (value == null) { + return 1; + } + return FfiConverterMoqCompression.allocationSize(value) + 1; + } + + static RustBuffer lower(MoqCompression? value) { + if (value == null) { + return toRustBuffer(Uint8List.fromList([0])); + } + final buf = Uint8List( + FfiConverterOptionalMoqCompression.allocationSize(value), + ); + FfiConverterOptionalMoqCompression.write(value, buf); + return toRustBuffer(buf); + } + + static int write(MoqCompression? value, Uint8List buf) { + if (value == null) { + buf[0] = 0; + return 1; + } + buf[0] = 1; + return FfiConverterMoqCompression.write( + value, + Uint8List.view(buf.buffer, buf.offsetInBytes + 1), + ) + + 1; + } +} + class FfiConverterOptionalMoqCongestionControl { static MoqCongestionControl? lift(RustBuffer buf) { return FfiConverterOptionalMoqCongestionControl.read( diff --git a/demo/carla/sim/moq_carla_sim/publish.py b/demo/carla/sim/moq_carla_sim/publish.py index 1e98f795493..862fc782498 100644 --- a/demo/carla/sim/moq_carla_sim/publish.py +++ b/demo/carla/sim/moq_carla_sim/publish.py @@ -185,7 +185,7 @@ class StatusPublisher: """ def __init__(self, broadcast: moq.BroadcastProducer) -> None: - track = broadcast.publish_track("status", moq.TrackInfo(timescale=1_000, compress=True)) + track = broadcast.publish_track("status", moq.TrackInfo(timescale=1_000, compression=moq.Compression.DEFLATE)) self._catalog = moq.media.CatalogProducer(broadcast) self._producer = moq.json.SnapshotProducer(broadcast, track) # Weak: watching demand neither keeps the track open nor locks it. diff --git a/demo/carla/sim/tests/conftest.py b/demo/carla/sim/tests/conftest.py index 1c9d18fa0b0..57ce385d4b1 100644 --- a/demo/carla/sim/tests/conftest.py +++ b/demo/carla/sim/tests/conftest.py @@ -29,6 +29,7 @@ def update(self, value: object, timestamp: object) -> None: moq.Subscription = lambda **kwargs: SimpleNamespace(**kwargs) moq.Delay = lambda **kwargs: SimpleNamespace(**kwargs) moq.Order = SimpleNamespace(ASCENDING="ascending") +moq.Compression = SimpleNamespace(DEFLATE="deflate") # Tests that run a truck's endpoint script it in place of this. moq.socket = ModuleType("moq.socket") moq.Timestamp = lambda value, scale: SimpleNamespace(value=value, scale=scale) diff --git a/demo/carla/web/src/preview.ts b/demo/carla/web/src/preview.ts index 7d7de0980d6..ce9ebce3202 100644 --- a/demo/carla/web/src/preview.ts +++ b/demo/carla/web/src/preview.ts @@ -14,7 +14,7 @@ export function populatePreview(add: (path: Moq.Path.Valid) => Truck) { const truck = add(Moq.Path.from(`carla/truck${index + 1}/front.hang`)); const origin = new Moq.Broadcast.Producer(); const producer = new Json.Snapshot.Producer({ - track: origin.createTrack("status", { compress: true }), + track: origin.createTrack("status", { compression: "deflate" }), }); (truck.broadcast.out.active as Moq.Signals.Signal).set(origin.consume()); producer.update({ diff --git a/demo/carla/web/src/truck.test.ts b/demo/carla/web/src/truck.test.ts index 3648f41c17d..4c0f275c92c 100644 --- a/demo/carla/web/src/truck.test.ts +++ b/demo/carla/web/src/truck.test.ts @@ -65,7 +65,7 @@ describe("Truck status", () => { function statusBroadcast() { const broadcast = new Moq.Broadcast.Producer(); - const track = broadcast.createTrack("status", { compress: true }); + const track = broadcast.createTrack("status", { compression: "deflate" }); const producer = new Json.Snapshot.Producer({ track }); return { broadcast, producer }; } @@ -525,7 +525,7 @@ describe("Truck sessions", () => { // The truck's status echoing the latch is what lets the session go. const broadcast = new Moq.Broadcast.Producer(); const producer = new Json.Snapshot.Producer({ - track: broadcast.createTrack("status", { compress: true }), + track: broadcast.createTrack("status", { compression: "deflate" }), }); try { (truck.broadcast.out.active as Moq.Signals.Signal).set( diff --git a/doc/concept/compression.md b/doc/concept/compression.md index 306e9e29c4c..9233639b3f2 100644 --- a/doc/concept/compression.md +++ b/doc/concept/compression.md @@ -12,11 +12,11 @@ Applications still write and read plain frames. A reader whose session cannot carry compression gets an inflated copy from the relay. ```rust -let info = moq_net::track::Info::default().with_compress(true); +let info = moq_net::track::Info::default().with_compression(moq_net::track::Compression::Deflate); ``` ```ts -const track = broadcast.createTrack("state.json", { compress: true }); +const track = broadcast.createTrack("state.json", { compression: "deflate" }); ``` ## When to set it @@ -42,7 +42,7 @@ moq-lite 07 is still opt-in, so compressed bytes cross a hop only where both ends list `moq-lite-07-wip`. Sessions on the default versions, and relay links among them, carry the inflated frames. Only Rust offers the moq-transport extension, so a JavaScript or third-party moq-transport peer reads the -inflated copy. A received track's `compress` flag says which form arrived. A +inflated copy. A received track's `compression` says which form arrived. A datagram track is never compressed. ## Cost on the relay diff --git a/doc/lib/c/index.md b/doc/lib/c/index.md index 6849b86d54f..c8ccb8876f6 100644 --- a/doc/lib/c/index.md +++ b/doc/lib/c/index.md @@ -109,7 +109,7 @@ inside. The header is the reference: each function carries a doc comment. - **Threading.** Call any function from any thread. Callbacks run on moq-c's runtime thread; the callback and its `user_data` must be safe to use there. Synchronize access to data shared with other threads, and dispatch UI work to your UI thread. Raw publish calls block until the codec takes the frame, which paces a publisher. - **Zeroed config is the default.** A zeroed `moq_client_config` means the default for every field, so new fields don't break callers. A field whose default isn't zero has a `has_*` flag: `backoff_timeout_us = 0` means "retry forever" only with `has_backoff_timeout = true`. - **Subscription defaults.** A zeroed `moq_subscription`, a NULL pointer, and `moq_subscription_defaults()` all mean moq-net's defaults, whose zero `delay` starts at the newest group and skips a superseded one at once. Set `delay.max_unlimited` for no subscriber limit, and `delay.min_unstated` to leave the target latency unstated. -- **Compressed tracks.** `moq_track_info.compress` on a raw track sends each group DEFLATE-compressed to opt-in `moq-lite-07-wip` peers; other peers, and every reader here, get the original frames. +- **Compressed tracks.** `moq_track_info.compression` set to `MOQ_COMPRESSION_DEFLATE` on a raw track sends each group DEFLATE-compressed to opt-in `moq-lite-07-wip` peers; other peers, and every reader here, get the original frames. - **fMP4 import.** `MOQ_CONTAINER_FORMAT_FMP4` splits each fragment into one frame per sample. - **Audio needs cuts.** Video groups at its keyframes, but audio forms a group only where you call `moq_publish_media_cut`: after every frame, or less often to batch frames into fewer groups. Pass that cadence as `moq_audio_init.hint.join_us`. - **Catalog hints.** Give the catalog what the encoder knows instead of having it estimated: `moq_video_init.hint` (coded size, bitrate, frame rate, join) and `moq_audio_init.hint` (bitrate, join). A supplied bitrate is never re-estimated. `join_us` is the time between join points, the longest span between two group starts: the GOP, or your cut cadence. Leave a field's `has_*` flag false to have it measured. A bitrate or `join_us` flag set with a 0 value returns `MOQ_ERROR_INVALID_CONFIG`. diff --git a/doc/lib/cpp/index.md b/doc/lib/cpp/index.md index f8fad94854b..ec99a95753c 100644 --- a/doc/lib/cpp/index.md +++ b/doc/lib/cpp/index.md @@ -233,7 +233,7 @@ screen.reset(); // stopped watching: its share returns to camera ## Compressed tracks -`moq::TrackInfo::compress` on a raw track sends each group DEFLATE-compressed to opt-in `moq-lite-07-wip` peers; other peers, and every reader here, get the original frames. +`moq::TrackInfo::compression` set to DEFLATE on a raw track sends each group DEFLATE-compressed to opt-in `moq-lite-07-wip` peers; other peers, and every reader here, get the original frames. ## Subscription defaults diff --git a/doc/lib/dart/index.md b/doc/lib/dart/index.md index abfc1fe159c..87e3e21e4f4 100644 --- a/doc/lib/dart/index.md +++ b/doc/lib/dart/index.md @@ -17,7 +17,7 @@ Import `package:moq/media.dart` with a prefix for catalogs, encoded-media import container consumers. `TrackProducer.audio` / `.video` take a broadcast, an init record, and a `Named` or `Requested` target. `CatalogProducer(broadcast: ...)` owns catalog properties and sections; it holds the broadcast weakly and fails after the broadcast closes. -Publish JSON tracks with `MoqTrackInfo(compress: true)`; a `package:moq/json.dart` consumer reads one with no option of its own. +Publish JSON tracks with `MoqTrackInfo(compression: MoqCompression.deflate)`; a `package:moq/json.dart` consumer reads one with no option of its own. A raw frame without a timestamp stays untimed, which only an untimed track accepts; JSON writes always take one. The library never substitutes zero or now. `SnapshotProducer.update`, `StreamProducer.append`, and `WindowProducer.push` and `pop` require a timestamp on the broadcast clock (`CatalogProducer.now()`), the epoch every track in the broadcast shares, so their track needs a timescale. `package:moq/json.dart` consumers return `Value` (`value`, `timestamp`) from `next()`; a snapshot consumer @@ -25,7 +25,7 @@ yields each state in order, and `latest()` skips to the newest. Media times are exact `Timestamp` records, `value` units at `scale` units per second, so a 90 kHz tick survives a read and republish. `Duration.toTimestamp()` converts exactly; `Timestamp.toDuration()` rounds down to a whole microsecond. Raw tracks with a `null` timescale are untimed on both publish and receive. -`MoqTrackInfo.compress` on a raw track sends each group DEFLATE-compressed to opt-in `moq-lite-07-wip` peers; other peers, and every reader here, get the original frames. +`MoqTrackInfo.compression` set to `MoqCompression.deflate` on a raw track sends each group DEFLATE-compressed to opt-in `moq-lite-07-wip` peers; other peers, and every reader here, get the original frames. Whole-frame media writes require caller time; container imports keep their own timeline handling. Timed raw/data tracks require caller-supplied timestamps. Use `CatalogProducer.now()` to stamp a locally created event on the broadcast clock; reading it fixes that clock for later media producers. diff --git a/doc/lib/go/index.md b/doc/lib/go/index.md index daaaeb292e1..44246875c99 100644 --- a/doc/lib/go/index.md +++ b/doc/lib/go/index.md @@ -21,7 +21,7 @@ catalog writes fail with `ErrClosed` after the broadcast closes. Media timestamp `TimestampFromDuration` converts exactly; `TimestampToDuration` rounds down to a whole nanosecond. A raw frame without a timestamp stays untimed, which only an untimed track accepts; JSON writes always take one. The library never substitutes zero or now. Raw tracks with a `nil` timescale are untimed on both publish and receive. -`TrackInfo.Compress` sends each group DEFLATE-compressed to opt-in `moq-lite-07-wip` peers; other peers, and every reader here, get the original frames. Set it on JSON tracks. +`TrackInfo.Compression` set to `CompressionDeflate` sends each group DEFLATE-compressed to opt-in `moq-lite-07-wip` peers; other peers, and every reader here, get the original frames. Set it on JSON tracks. The JSON producers' `Update`, `Append`, `Push`, and `Pop` take a final `moq.Timestamp` on the broadcast clock, the epoch every track in the broadcast shares, so their track needs a timescale. JSON consumers return a `*Timed` holding the value and that timestamp; `SnapshotConsumer.Latest` skips to the newest state where `Next` yields each one. A read timestamp is at the track's timescale. diff --git a/doc/lib/js/json.md b/doc/lib/js/json.md index 2c105c612f8..ad7d0e53ec8 100644 --- a/doc/lib/js/json.md +++ b/doc/lib/js/json.md @@ -17,7 +17,7 @@ reader will not pick it up. - **Stream**: lossless append-log in a single group. A reader that falls behind fails the read rather than resuming mid-log. - **Window**: a bounded run of records a reader can join at any point. A new group restates what it keeps explicitly, so a reader that was keeping up is not handed a record twice. Its ops roll on the track's `refresh` ratio the same way. -Compression is the track's: create it with `compress: true`, which JSON benefits +Compression is the track's: create it with `compression: "deflate"`, which JSON benefits from, and readers see plain frames either way. Producers take a `Timed` value, `{ value, at }`, where `at` is the capture time written as the frame timestamp, and the snapshot and stream consumers return the same diff --git a/doc/lib/kt/index.md b/doc/lib/kt/index.md index c67762b7fc9..c509aa5d7e2 100644 --- a/doc/lib/kt/index.md +++ b/doc/lib/kt/index.md @@ -16,7 +16,7 @@ x86\_64) and desktop JVM (Linux x86\_64/aarch64, macOS arm64, Windows x64). `dev.moq.media` owns catalogs, encoded imports, and container consumers. `TrackProducer.audio` / `.video` take a broadcast, a `Named` or `Requested` target, and an init record. `CatalogProducer(broadcast)` holds its broadcast weakly and fails with `Closed` after it closes. -Publish JSON tracks with `TrackInfo(compress = true)`; a `dev.moq.json` consumer reads one with no option of its own. +Publish JSON tracks with `TrackInfo(compression = Compression.DEFLATE)`; a `dev.moq.json` consumer reads one with no option of its own. A raw frame without a timestamp stays untimed, which only an untimed track accepts; JSON writes always take one. The library never substitutes zero or now. `SnapshotProducer.update`, `StreamProducer.append`, and `WindowProducer.push` and `pop` require a timestamp on the broadcast clock (`CatalogProducer.now()`), the epoch every track in the broadcast shares, so their track needs a timescale. `dev.moq.json` consumers' `values()` emits `Value` (`value`, `timestamp`) and `valuesAs()` emits `Timed`; @@ -24,7 +24,7 @@ a snapshot consumer yields each state in order, and `latest()` skips to the newe A `Timestamp(value, scale)` is exact and reads back at the track's timescale, so a 90 kHz tick republishes unchanged. `Duration.toTimestamp()` is exact at nanosecond scale; `Timestamp.toDuration()` rounds down to a whole nanosecond. Raw tracks with a `null` timescale are untimed on both publish and receive. -`MoqTrackInfo.compress` on a raw track sends each group DEFLATE-compressed to opt-in `moq-lite-07-wip` peers; other peers, and every reader here, get the original frames. +`MoqTrackInfo.compression` set to `DEFLATE` on a raw track sends each group DEFLATE-compressed to opt-in `moq-lite-07-wip` peers; other peers, and every reader here, get the original frames. Whole-frame media writes require caller time; container imports keep their own timeline handling. Timed raw/data tracks require caller-supplied timestamps. Use `CatalogProducer.now()` to stamp a locally created event on the broadcast clock; reading it fixes that clock for later media producers. diff --git a/doc/lib/layers.md b/doc/lib/layers.md index a9ec70893c3..edf32d75093 100644 --- a/doc/lib/layers.md +++ b/doc/lib/layers.md @@ -87,7 +87,7 @@ The catalog has no window mode, so a window track is not advertised there. Go code usually imports it under an alias, next to `encoding/json`. Compression is the track's, not this layer's: publish a JSON track with -`compress` set on its track info, and a consumer reads it like any other. +`compression` set on its track info, and a consumer reads it like any other. Opaque bytes go on a raw net track. ## audio diff --git a/doc/lib/py/index.md b/doc/lib/py/index.md index fb1b7356e18..50a3b436545 100644 --- a/doc/lib/py/index.md +++ b/doc/lib/py/index.md @@ -28,7 +28,7 @@ A raw frame without a timestamp stays untimed, which only an untimed track accep JSON consumers yield `moq.json.Timed(value, timestamp)`; a snapshot consumer yields each state in order, and `await consumer.latest()` skips to the newest. A window consumer's value is a `WindowEventPush`, `WindowEventPop`, or `WindowEventSkip`. Raw tracks with a `None` timescale are untimed on both publish and receive. -`TrackInfo(compress=True)` sends each group DEFLATE-compressed to opt-in `moq-lite-07-wip` peers; other peers, and every reader here, get the original frames. Set it on JSON tracks. +`TrackInfo(compression=moq.Compression.DEFLATE)` sends each group DEFLATE-compressed to opt-in `moq-lite-07-wip` peers; other peers, and every reader here, get the original frames. Set it on JSON tracks. The JSON producers' `update`, `append`, `push`, and `pop` require a `timestamp` on the broadcast clock, the epoch every track in the broadcast shares, so their track needs a timescale. Whole-frame media writes require caller time; container imports keep their own timeline handling. Timed raw/data tracks require caller-supplied timestamps. Use `CatalogProducer.now()` to stamp a locally @@ -96,7 +96,7 @@ async def main(): # Raw bytes and JSON events = broadcast.publish_track("events") events.write_frame(b'{"cmd": "ready"}') - status_track = broadcast.publish_track("status", moq.TrackInfo(timescale=1_000, compress=True)) + status_track = broadcast.publish_track("status", moq.TrackInfo(timescale=1_000, compression=moq.Compression.DEFLATE)) status = moq.json.SnapshotProducer(broadcast, status_track) status.update({"state": "live", "viewers": 42}, catalog_producer.now()) diff --git a/doc/lib/rs/moq-json.md b/doc/lib/rs/moq-json.md index f678c6fd095..e1ff5bee366 100644 --- a/doc/lib/rs/moq-json.md +++ b/doc/lib/rs/moq-json.md @@ -20,7 +20,7 @@ The `poll_*` methods work by default. Enable the `async` Cargo feature to await - **stream**: lossless append-log in a single group. A reader that falls behind fails the read rather than resuming mid-log. - **window**: a bounded run of records a reader can join at any point. A new group restates what it keeps explicitly, so a reader that was keeping up is not handed a record twice. Its ops roll on the track's `refresh` ratio the same way. -Compression is the track's: create it with `Info::default().with_compress(true)`, +Compression is the track's: create it with `Info::default().with_compression(Compression::Deflate)`, which JSON benefits from, and readers see plain frames either way. A bare value stays untimed; publish `moq_net::Timed::from(&value).at(captured)` to retain a capture timestamp. The timestamp must match the track: an untimed track has no timescale, and a diff --git a/doc/lib/rs/moq-net.md b/doc/lib/rs/moq-net.md index ed1976326d3..9ed3f4580f9 100644 --- a/doc/lib/rs/moq-net.md +++ b/doc/lib/rs/moq-net.md @@ -21,7 +21,7 @@ What you use it for, beyond what the concept page already describes: - **Rank several CDNs.** Dial each with its own subscribe handle, `origin.clone().with_preference(origin::Preference::new(rank))` (higher wins; 0 is neutral and a negative rank demotes), all on one origin. Requests use the preferred link that has a route and fail over to the next; see [multiple CDNs](/concept/moq-lite#multiple-cdns). - **Request one instance, or follow them all.** `consumer.request(path, None)` resolves the instance serving a path now, and fails `Unroutable` only once discovery has synced with no route for it. `consumer.follow(path, None)` hands out each publisher instance serving a path from `available()`: the first once announced, then each one that takes over, `None` once the path goes offline, and whatever serves it next, like JS `follow(path)`. `consumer.announced()` lists paths only as present or absent. A broadcast already resolved stays on the old instance until dropped or its route goes. See [identity and recovery](/concept/identity) to choose between following and holding one instance. - **Discovery follows what you watch.** A client session asks the relay for announcements only under the prefixes its subscribe origin's readers watch, with `announced()`, `request`, or `follow`, stops asking about a prefix 2s after nothing at or beneath it is watched, and asks again on reconnect. A broadcast resolved through a discovered route keeps its path watched until dropped. `request` owns discovery of its path, so no separate watch is needed. A server session, or a client fed into an origin handle marked `with_link(origin::Link::Peer)` or `Link::Upstream`, asks for everything it may, so a relay discovers everything. An HTTP gateway (the moq-hls `Server`, the moq-webrtc WHEP router) watches its whole scope while it lives, so the paths its callers name never open a request each. moq-lite-03/04 sessions, whose announcements mark no initial set, still ask for everything. -- **Relay by opting into proxying.** On moq-lite-07 (`moq-lite-07-wip`, opt-in) a session sends its peer only the routes to its origin's own claims, so an application never becomes transit for anyone else. A relay built on the library marks the handle it publishes with `origin.clone().with_proxy(true)`, or one consumer with `consumer.with_proxy(true)`, to carry what it learned from other peers too; `moq-relay` does so for every session. Older versions advertise everything either way. +- **Relay by opting into proxying.** On moq-lite-07 (`moq-lite-07-wip`, opt-in) a session sends its peer only the routes to its origin's own claims, so an application never becomes transit for anyone else. A relay built on the library marks the handle it publishes with `origin.clone().with_proxy(true)` to carry what it learned from other peers too; `moq-relay` does so for every session. Older versions advertise everything either way. - **Dial and accept sockets.** `socket::Endpoint::new(&origin, prefix, id)` is a server, a client, or both: its first dial announces a hidden client endpoint at `/.client/`, and its first accept a hidden server endpoint at `/.server/`, both used only to route sessions, so grants decide which roles it may take. A session speaks one of two protocols, each with its own dial and accept. `accept_tcp()` and `accept_track()` yield an `Incoming` dial to `accept` or `reject` (dropping it rejects). `dial_tcp(server)` and an accepted `tcp` dial yield a `socket::TcpStream`, a `group::Producer` and `group::Consumer` pair carrying one reliable, ordered byte pipe each way (finish is FIN, abort is RST, and `ready` paces the writer to the reader); `dial_track(server, info)` and an accepted `track` dial yield a `socket::TrackStream`, this side's `track::Producer` and a `track::Subscriber` of the peer's half, subscribed reliably and in order until the application updates it, one message per group. A dial resolves once the peer accepts, and an accept checks that the claimed dialer really dialed this endpoint, waiting for its endpoint while the dial stays open. Every hop needs moq-lite-07 or moq-transport: while the origin has an older moq-lite client session whose publish half doesn't opt into hidden broadcasts (`with_hidden(true)`), dials and accepts fail with `Unsupported`. A dial to a peer behind such a hop waits, as for a peer not online yet. Session tracks are never announced or listed. See [Sockets](/concept/socket). - **One track per name.** Concurrent subscriptions share one request and producer. The application owns sequence numbers: the broadcast keeps nothing of an ended track, so a producer that replaces it starts at 0. A name always means the same content, so the replacement continues past its predecessor's groups with `create_group` at an explicit sequence. Readers of an aborted track resume onto the replacement when they read through an origin request, whose route always names an instance; otherwise their subscription ends with the error. - **Authored tracks default to a zero `max_age`.** `track::Info::default()` sets `max_age` to `Some(Duration::ZERO)`, the live edge only; a publisher that wants readers to reach history sets a longer bound, or `with_max_age(None)` for no publisher limit. Media tracks from `hang::container::track_info` declare `hang::container::MAX_AGE` (30 seconds). `max_age` is how long a superseded group stays fresh, never the newest group; it frees no bytes, which the cache pool's expiry reclaims. Received metadata keeps absence as no limit, and an origin's `cache_duration` can only cap it lower. diff --git a/doc/lib/swift/index.md b/doc/lib/swift/index.md index 7889493d3f4..a04f7067294 100644 --- a/doc/lib/swift/index.md +++ b/doc/lib/swift/index.md @@ -20,13 +20,13 @@ Its writes fail after closing or releasing the broadcast. Media timestamps are exact `Timestamp` records, `value` units at `scale` units per second, carried at the track's timescale (a write at another scale rounds down to it). On macOS 13+ and iOS, `try Timestamp(duration)` converts a `Duration` exactly, and `try timestamp.duration` rounds down to a whole attosecond. -Publish JSON tracks with `TrackInfo(compress: true)`; a `Json` consumer reads one with no option of its own. +Publish JSON tracks with `TrackInfo(compression: .deflate)`; a `Json` consumer reads one with no option of its own. A raw frame without a timestamp stays untimed, which only an untimed track accepts; JSON writes always take one. The library never substitutes zero or now. `Json.SnapshotProducer.update`, `Json.StreamProducer.append`, and `Json.WindowProducer.push` and `pop` require a timestamp on the broadcast clock (`Media.CatalogProducer.now()`), the epoch every track in the broadcast shares, so their track needs a timescale. `Json` consumers yield `Json.Timed` (`value`, `timestamp`); a snapshot consumer yields each state in order, and `latest()` skips to the newest. Raw tracks with a `nil` timescale are untimed on both publish and receive. -`MoqTrackInfo.compress` on a raw track sends each group DEFLATE-compressed to opt-in `moq-lite-07-wip` peers; other peers, and every reader here, get the original frames. +`MoqTrackInfo.compression` set to `.deflate` on a raw track sends each group DEFLATE-compressed to opt-in `moq-lite-07-wip` peers; other peers, and every reader here, get the original frames. Whole-frame media writes require caller time; container imports keep their own timeline handling. Timed raw/data tracks require caller-supplied timestamps. Use `Media.CatalogProducer.now()` to stamp a locally created event on the broadcast clock; reading it fixes that clock for later media producers. diff --git a/go/wrapper/MIGRATE.md b/go/wrapper/MIGRATE.md index a1fd89df012..da573d46d55 100644 --- a/go/wrapper/MIGRATE.md +++ b/go/wrapper/MIGRATE.md @@ -118,7 +118,7 @@ A fixed audio playout delay `d` is `Delay: moq.Delay{Min: d, Max: max}` with `Es `moq.dev/moq/flate` is removed: publish opaque bytes on a `TrackProducer`. `SnapshotOptions` and `WindowOptions` lose `Compression`, and `StreamOptions` and `ConsumerOptions` are removed: `NewStreamProducer` and every JSON consumer constructor take only the track (and broadcast). -Publish the track with `&moq.TrackInfo{Compress: true}` instead; a consumer reads a compressed track with no option of its own. +Publish the track with `&moq.TrackInfo{Compression: &deflate}` (where `deflate := moq.CompressionDeflate`) instead; a consumer reads a compressed track with no option of its own. ### Paths with an empty segment are refused ([#6648](https://github.com/moq-dev/moq/pull/6648)) @@ -237,9 +237,9 @@ Replace `request.Accept(broadcast)` with `request.Prepare()`, which returns a `* To answer with a broadcast you already hold, `request.Serve(consumer)` serves it under the prefix route without announcing an exact route; the consumer stays yours to close. Where you rejected a request after a failed setup, `Close()` the prepared answer instead. -### `TrackInfo` gains `Compress` (#5928) +### `TrackInfo` gains `Compression` (#5928) -A positional `TrackInfo{...}` literal adds a trailing `false`; keyed literals need no change. +A positional `TrackInfo{...}` literal adds a trailing `nil`; keyed literals need no change. ### Anchors can name a time (#6074) diff --git a/go/wrapper/README.md b/go/wrapper/README.md index 16f98f5e61b..d39c2efced8 100644 --- a/go/wrapper/README.md +++ b/go/wrapper/README.md @@ -143,7 +143,8 @@ broadcast, _ := route.Broadcast() // Every JSON write is stamped, so the track is timed. JSON is small and repetitive, so // compress it on the wire. scale := uint64(1_000) -track, _ := broadcast.PublishTrack("status", &moq.TrackInfo{Timescale: &scale, Compress: true}) +deflate := moq.CompressionDeflate +track, _ := broadcast.PublishTrack("status", &moq.TrackInfo{Timescale: &scale, Compression: &deflate}) status, _ := moqjson.NewSnapshotProducer(broadcast, track, moqjson.SnapshotOptions{}) catalog, _ := moqmedia.NewCatalogProducer(broadcast) now, _ := catalog.Now() diff --git a/go/wrapper/json/json.go b/go/wrapper/json/json.go index e2715aaca21..18f0c1b8279 100644 --- a/go/wrapper/json/json.go +++ b/go/wrapper/json/json.go @@ -5,7 +5,7 @@ // their broadcast's catalog, which has no window mode), and a consumer takes // over a [moq.TrackConsumer] that has not read a group yet. The track can come // from a request as well as by name. Compression is the track's: publish JSON -// with [moq.TrackInfo] Compress set, and a consumer reads it with no option of +// with [moq.TrackInfo] Compression set, and a consumer reads it with no option of // its own. Every write (a snapshot update, a stream append, a window push or // pop) takes a timestamp on the broadcast clock, the epoch every track in the // broadcast shares (read it with media.CatalogProducer.Now), so the track needs diff --git a/go/wrapper/json/json_test.go b/go/wrapper/json/json_test.go index 42c077f0d40..312d7e7d730 100644 --- a/go/wrapper/json/json_test.go +++ b/go/wrapper/json/json_test.go @@ -57,7 +57,8 @@ func TestTracks(t *testing.T) { broadcast, consumer := newBroadcast(t) scale := uint64(1_000_000) - track, err := broadcast.PublishTrack("status", &moq.TrackInfo{Timescale: &scale, Compress: true}) + deflate := moq.CompressionDeflate + track, err := broadcast.PublishTrack("status", &moq.TrackInfo{Timescale: &scale, Compression: &deflate}) if err != nil { t.Fatal(err) } @@ -137,7 +138,8 @@ func TestWindow(t *testing.T) { broadcast, consumer := newBroadcast(t) scale := uint64(1_000_000) - track, err := broadcast.PublishTrack("log", &moq.TrackInfo{Timescale: &scale, Compress: true}) + deflate := moq.CompressionDeflate + track, err := broadcast.PublishTrack("log", &moq.TrackInfo{Timescale: &scale, Compression: &deflate}) if err != nil { t.Fatal(err) } diff --git a/go/wrapper/records.go b/go/wrapper/records.go index 30d7456af97..38fbe185ee4 100644 --- a/go/wrapper/records.go +++ b/go/wrapper/records.go @@ -149,8 +149,8 @@ func subscriptionFFI(s *Subscription) (*ffi.MoqSubscription, error) { // bytes may grow before a joining subscriber asks for a new group (nil never // asks), and the timescale in ticks per second (nil means untimed on both publish // and receive). Priority is higher first; the zero Priority is the midpoint a nil -// TrackInfo uses. Compress DEFLATEs each group on the wire to peers that support -// it; readers always see the original frames. +// TrackInfo uses. Compression compresses each group on the wire to peers that +// support it, nil sending frames as written; readers always see the original frames. type TrackInfo struct { Priority int8 // MaxAge is how long a superseded group stays fresh. Zero, the default, serves @@ -161,7 +161,7 @@ type TrackInfo struct { MaxAgeUnlimited bool Refresh *uint32 Timescale *uint64 - Compress bool + Compression *Compression } func trackInfoFFI(info *TrackInfo) (*ffi.MoqTrackInfo, error) { @@ -173,7 +173,7 @@ func trackInfoFFI(info *TrackInfo) (*ffi.MoqTrackInfo, error) { MaxAgeUnlimited: info.MaxAgeUnlimited, Refresh: info.Refresh, Timescale: info.Timescale, - Compress: info.Compress, + Compression: info.Compression, } if !info.MaxAgeUnlimited { out.MaxAge = &info.MaxAge @@ -187,7 +187,7 @@ func trackInfoFromFFI(info ffi.MoqTrackInfo) TrackInfo { MaxAgeUnlimited: info.MaxAgeUnlimited, Refresh: info.Refresh, Timescale: info.Timescale, - Compress: info.Compress, + Compression: info.Compression, } if info.MaxAge != nil && !info.MaxAgeUnlimited { out.MaxAge = *info.MaxAge diff --git a/go/wrapper/types.go b/go/wrapper/types.go index 9367d94be2e..1965975ef46 100644 --- a/go/wrapper/types.go +++ b/go/wrapper/types.go @@ -71,6 +71,8 @@ type ( AnchorTime = ffi.MoqAnchorTime // Order is which of a subscription's pending groups the publisher sends first. Order = ffi.MoqOrder + // Compression is how a track's frames are compressed on the wire: CompressionDeflate. + Compression = ffi.MoqCompression // Position is a location within a track: a group sequence and a frame index in it. Position = ffi.MoqPosition // VideoDecoderOutput configures what a video.Consumer delivers: an optional resize, a max delay, and whether frames keep the decoder's surface (macOS only; refused elsewhere). @@ -162,6 +164,12 @@ const ( OrderDescending = ffi.MoqOrderDescending ) +// Compression values: how a track's frames are compressed on the wire. +const ( + // CompressionDeflate makes each group one DEFLATE stream, which suits small, repetitive frames like JSON. + CompressionDeflate = ffi.MoqCompressionDeflate +) + // ConnectionPhase values: the lifecycle of a client session's connection. const ( // ConnectionPhaseConnecting means no session has connected yet. diff --git a/js/hang/src/report.ts b/js/hang/src/report.ts index d44cd11b199..65a87ea1fac 100644 --- a/js/hang/src/report.ts +++ b/js/hang/src/report.ts @@ -31,7 +31,7 @@ export class Writer { /** Create `name` on `broadcast`, validating each report against `schema` before it is written. */ constructor(broadcast: Moq.Broadcast.Producer, name: string, schema?: z.ZodMiniType) { - this.track = broadcast.createTrack(name, { priority: PRIORITY, compress: true, refresh: REFRESH }); + this.track = broadcast.createTrack(name, { priority: PRIORITY, compression: "deflate", refresh: REFRESH }); this.#producer = new Json.Snapshot.Producer({ track: this.track, schema }); } diff --git a/js/json/MIGRATE.md b/js/json/MIGRATE.md index c18dd854690..4963a99fb9c 100644 --- a/js/json/MIGRATE.md +++ b/js/json/MIGRATE.md @@ -16,7 +16,7 @@ A reader that set `delay.max` to replay a snapshot track's history or trail a pl ### Compression moves to the track The `Compression` type, every `compression` option, `Desync`, `Stream.Decoder.reset`, and `Window.DecoderConfig` are gone, along with the `@moq/flate` dependency. -Frames are plain JSON: create the track with `compress: true` instead, and `@moq/net` compresses each group on the wire and hands every reader plain frames. +Frames are plain JSON: create the track with `compression: "deflate"` instead, and `@moq/net` compresses each group on the wire and hands every reader plain frames. Drop `compression` from producer and consumer options, and construct `Window.Decoder` with no arguments. A consumer reads a compressed track with no option of its own. Every frame is charged its JSON size against `Group.MAX_GROUP_CACHE_BYTES`, as a compressed one already was. diff --git a/js/json/README.md b/js/json/README.md index b15aa79ac80..25f4b987d36 100644 --- a/js/json/README.md +++ b/js/json/README.md @@ -65,4 +65,4 @@ for await (const { value, at } of consumer) { Producers take `{ value, at }`, where `at` is the capture time written as the frame timestamp, and consumers return the same shape. Nothing fills in now: a timed track needs `at` on every write, and an untimed track takes none and reads back without one. -Compression is the track's: create it with `compress: true` (`new Track.Producer(name).accept({ compress: true })`) and `@moq/net` compresses each group on the wire, while every reader sees plain JSON. JSON is small and repetitive, so set it on JSON tracks. `Config` is the codec options; `Producer.Config` / `Consumer.Config` add the track. +Compression is the track's: create it with `compression: "deflate"` (`new Track.Producer(name).accept({ compression: "deflate" })`) and `@moq/net` compresses each group on the wire, while every reader sees plain JSON. JSON is small and repetitive, so set it on JSON tracks. `Config` is the codec options; `Producer.Config` / `Consumer.Config` add the track. diff --git a/js/json/bench/stream.ts b/js/json/bench/stream.ts index 0c5e940dd66..b1d6b9bb2a3 100644 --- a/js/json/bench/stream.ts +++ b/js/json/bench/stream.ts @@ -8,7 +8,7 @@ for (const records of [64, 1024]) { for (const compress of [false, true]) { const samples: number[] = []; for (let sample = 0; sample < 6; sample++) { - const track = new Track.Producer("stream-bench").accept({ compress }); + const track = new Track.Producer("stream-bench").accept({ compression: compress ? "deflate" : "none" }); const producer = new Producer<{ n: number; text: string }>({ track }); const text = "x".repeat(bytes); for (let n = 0; n < records; n++) producer.append({ value: { n, text } }); diff --git a/js/json/src/snapshot/producer.ts b/js/json/src/snapshot/producer.ts index 4d558297b43..671bbd09b49 100644 --- a/js/json/src/snapshot/producer.ts +++ b/js/json/src/snapshot/producer.ts @@ -16,7 +16,7 @@ import { type Config as CodecConfig, type Encoded, Encoder } from "./encoder.ts" * restates the value there at the newest timestamp written. Set the ratio when creating the * track, or joins never ask. * - * Set `compress` on that track's info too: JSON is small and repetitive, and moq-net compresses each + * Set `compression` on that track's info too: JSON is small and repetitive, and moq-net compresses each * delta against the snapshot earlier in its group. */ export class Producer { diff --git a/js/json/src/snapshot/snapshot.test.ts b/js/json/src/snapshot/snapshot.test.ts index 3b4b571d35c..5efd87ea9bb 100644 --- a/js/json/src/snapshot/snapshot.test.ts +++ b/js/json/src/snapshot/snapshot.test.ts @@ -527,7 +527,7 @@ test("no ratio never refreshes", async () => { }); test("a compressed refresh opens a fresh group", async () => { - const track = new Track.Producer("test").accept({ refresh: 0, compress: true, maxAge: null }); + const track = new Track.Producer("test").accept({ refresh: 0, compression: "deflate", maxAge: null }); const producer = new Producer({ track }); producer.update({ value: { a: 1, b: 1 } }); producer.update({ value: { a: 1, b: 2 } }); @@ -718,7 +718,7 @@ test("an untimed state reads back untimed", async () => { // Each state carries the timestamp of the frame that produced it, snapshot or delta, so a caller can // hold it back until a playhead reaches it. `latest()` reports the head's own frame. test("each state reads back with its frame's timestamp", async () => { - const track = new Track.Producer("test").accept({ timescale: Time.Timescale.MILLI, compress: true }); + const track = new Track.Producer("test").accept({ timescale: Time.Timescale.MILLI, compression: "deflate" }); const producer = new Producer({ track, deltas: true }); for (let n = 1; n <= 3; n++) { producer.update({ value: { n, b: "x".repeat(64) }, at: Time.Timestamp.fromMillis(n * 1_000) }); diff --git a/js/json/src/stream/index.ts b/js/json/src/stream/index.ts index 16dac10091c..4915c0bbb68 100644 --- a/js/json/src/stream/index.ts +++ b/js/json/src/stream/index.ts @@ -4,7 +4,7 @@ * records that preserves everything; every {@link Producer.append} writes one JSON object as one * frame, nothing is ever superseded, and a {@link Consumer} yields every record in order. * - * The whole log rides a **single group** that is never rolled: on a track created with `compress`, + * The whole log rides a **single group** that is never rolled: on a track created with `compression: "deflate"`, * that one group is one DEFLATE window, so every record compresses against the earlier ones. * There is deliberately no group rolling (and so no catch-up machinery); a caller that wants to * bound the record rate throttles at the source. Interoperable on the wire with the Rust diff --git a/js/json/src/stream/stream.test.ts b/js/json/src/stream/stream.test.ts index 7e2b6c860bb..e657afe6cd4 100644 --- a/js/json/src/stream/stream.test.ts +++ b/js/json/src/stream/stream.test.ts @@ -28,7 +28,7 @@ test("plaintext roundtrip in order", async () => { }); test("compressed roundtrip in order", async () => { - const track = new Track.Producer("test").accept({ compress: true }); + const track = new Track.Producer("test").accept({ compression: "deflate" }); const producer = new Producer({ track }); for (let n = 0; n < 20; n++) producer.append({ value: { n } }); producer.finish(); @@ -37,7 +37,7 @@ test("compressed roundtrip in order", async () => { }); test("a record whose worst-case slice outgrows the frame cap is refused, leaving the track open", async () => { - const track = new Track.Producer("test").accept({ compress: true }); + const track = new Track.Producer("test").accept({ compression: "deflate" }); const producer = new Producer({ track }); // 32 MiB of JSON fits the plain cap, but its DEFLATE bound does not. expect(() => producer.append({ value: "x".repeat(32 * 1024 * 1024 - 2) })).toThrow( @@ -51,7 +51,7 @@ test("a record whose worst-case slice outgrows the frame cap is refused, leaving }); test("the whole log rides one group, never rolled", async () => { - const track = new Track.Producer("test").accept({ compress: true }); + const track = new Track.Producer("test").accept({ compression: "deflate" }); const producer = new Producer({ track }); for (let n = 0; n < 50; n++) producer.append({ value: { n } }); producer.finish(); @@ -67,7 +67,7 @@ test("the whole log rides one group, never rolled", async () => { test("records with embedded newlines round-trip (JSON escapes the newline)", async () => { // Each record is its own frame (one JSON object), and JSON.stringify escapes control characters, // so a string value containing a newline round-trips cleanly. - const track = new Track.Producer("test").accept({ compress: true }); + const track = new Track.Producer("test").accept({ compression: "deflate" }); const producer = new Producer<{ s: string }>({ track }); const value = { s: "line1\nline2\ttab" }; for (let i = 0; i < 4; i++) producer.append({ value: value }); @@ -115,7 +115,7 @@ test("a second group is reported while the first is still open", async () => { for (const compress of [false, true]) { test(`schema validation stays inside the read (compress=${compress})`, async () => { - const track = new Track.Producer("test").accept({ compress }); + const track = new Track.Producer("test").accept({ compression: compress ? "deflate" : "none" }); const producer = new Producer({ track }); producer.append({ value: { n: 1 } }); producer.finish(); @@ -207,7 +207,7 @@ test("an untimed record reads back untimed", async () => { }); test("each record reads back with its capture timestamp", async () => { - const track = new Track.Producer("test").accept({ timescale: Time.Timescale.MILLI, compress: true }); + const track = new Track.Producer("test").accept({ timescale: Time.Timescale.MILLI, compression: "deflate" }); const producer = new Producer({ track }); producer.append({ value: 1, at: Time.Timestamp.fromMillis(1_000) }); producer.append({ value: 2, at: Time.Timestamp.fromMillis(2_000) }); @@ -224,7 +224,7 @@ test("each record reads back with its capture timestamp", async () => { for (const compress of [false, true]) { test(`a stream has no record ceiling (compress=${compress})`, async () => { - const track = new Track.Producer("test").accept({ compress }); + const track = new Track.Producer("test").accept({ compression: compress ? "deflate" : "none" }); const producer = new Producer({ track }); for (let n = 0; n < 9000; n++) producer.append({ value: { n } }); producer.finish(); @@ -234,7 +234,7 @@ for (const compress of [false, true]) { }); test(`a live stream passes several tails and refuses a truncated replay (compress=${compress})`, async () => { - const track = new Track.Producer("test").accept({ compress }); + const track = new Track.Producer("test").accept({ compression: compress ? "deflate" : "none" }); const producer = new Producer<{ n: number; pad: string }>({ track }); const fast = new Consumer<{ n: number; pad: string }>({ track: track.subscribe() }); const slow = new Consumer({ track: track.subscribe() }); diff --git a/js/json/src/window/window.test.ts b/js/json/src/window/window.test.ts index 39e7c5f5c11..902034a2433 100644 --- a/js/json/src/window/window.test.ts +++ b/js/json/src/window/window.test.ts @@ -19,9 +19,9 @@ class Live { events: Event[] = []; #next?: Promise> | undefined>; - constructor(config: { ops?: boolean; compress?: boolean; checkpointRecords?: number } = {}) { - const { compress, ...producer } = config; - const track = new Track.Producer("test").accept({ compress }); + constructor(config: { ops?: boolean; compression?: Track.Compression; checkpointRecords?: number } = {}) { + const { compression, ...producer } = config; + const track = new Track.Producer("test").accept({ compression }); this.producer = new Producer({ track, ...producer }); this.consumer = new Consumer({ track: track.subscribe() }); } @@ -199,7 +199,7 @@ test("rolling is invisible to the consumer", async () => { }); test("compressed round-trip across rolls", async () => { - const live = new Live({ compress: true }); + const live = new Live({ compression: "deflate" }); for (let n = 0; n < 40; n++) { await live.push(n); if (n >= 10) await live.pop(1); diff --git a/js/net/api/index.api.md b/js/net/api/index.api.md index 40d9626fd6a..2e07b01fc90 100644 --- a/js/net/api/index.api.md +++ b/js/net/api/index.api.md @@ -689,6 +689,7 @@ export namespace Track { excluded: bigint; included?: never; }; + export type Compression = "none" | "deflate"; export class Consumer { fetchGroup(sequence: bigint, options?: Track.FetchGroupOptions): Promise; info(options?: Track.InfoOptions): Promise; @@ -730,7 +731,7 @@ export namespace Track { start?: Track.Bound; } export interface Info { - compress?: boolean; + compression?: Track.Compression; maxAge?: Milli; priority: number; refresh?: number; diff --git a/js/net/bench/compression-fanout.ts b/js/net/bench/compression-fanout.ts index 768ef4aabdc..f25628e17de 100644 --- a/js/net/bench/compression-fanout.ts +++ b/js/net/bench/compression-fanout.ts @@ -15,7 +15,9 @@ export function fanout() { let stored = 0; let inflated = 0; for (let round = 0; round < rounds; round++) { - const tracks = Array.from({ length: publishers }, () => new Track("bench").accept({ compress: true })); + const tracks = Array.from({ length: publishers }, () => + new Track("bench").accept({ compression: "deflate" }), + ); const groups: Group[] = tracks.map((track) => track.appendGroup()); const consumers = groups.map((group) => Array.from({ length: readers }, () => group.consume())); let started = performance.now(); @@ -71,7 +73,9 @@ export function tails() { for (const compress of [false, true]) { const frames = frame_bytes === 256 ? 9000 : 96; const payload = new Uint8Array(frame_bytes).fill(42); - const tracks = Array.from({ length: publishers }, () => new Track("tail").accept({ compress })); + const tracks = Array.from({ length: publishers }, () => + new Track("tail").accept({ compression: compress ? "deflate" : "none" }), + ); const groups = tracks.map((track) => track.appendGroup()); const consumers = groups.map((group) => Array.from({ length: readers }, () => group.consume())); const started = performance.now(); diff --git a/js/net/src/flate/group.test.ts b/js/net/src/flate/group.test.ts index 281f48fd50d..58dee17d2f5 100644 --- a/js/net/src/flate/group.test.ts +++ b/js/net/src/flate/group.test.ts @@ -10,7 +10,7 @@ import { encodable } from "./group.ts"; const payload = new TextEncoder().encode("one shared compression window ".repeat(100)); test("synchronous writers store slices; plain readers share one charged inflated copy", async () => { - const track = new Track("compressed").accept({ compress: true }); + const track = new Track("compressed").accept({ compression: "deflate" }); const group = track.appendGroup(); const first = group.mirror(); const second = group.mirror(); @@ -95,7 +95,7 @@ for (const readPlain of [false, true]) { } test("empty frames preserve the window", async () => { - const track = new Track("compressed").accept({ compress: true }); + const track = new Track("compressed").accept({ compression: "deflate" }); const group = track.createGroup(0n); group.writeFrame({ payload }); group.writeFrame({ payload: new Uint8Array() }); @@ -109,7 +109,7 @@ test("empty frames preserve the window", async () => { }); test("a cut compressed group preserves its committed frames before returning its error", async () => { - const track = new Track("compressed").accept({ compress: true }); + const track = new Track("compressed").accept({ compression: "deflate" }); const group = track.appendGroup(); const reader = group.mirror(); group.writeFrame({ payload }); @@ -122,7 +122,7 @@ test("a cut compressed group preserves its committed frames before returning its }); test("a shared plain read cannot change a later synchronous write's admission", async () => { - const track = new Track("compressed").accept({ compress: true }); + const track = new Track("compressed").accept({ compression: "deflate" }); const group = track.appendGroup(); const reader = group.mirror(); // The largest local frame whose worst-case slice fits the frame cap. @@ -139,7 +139,7 @@ test("a shared plain read cannot change a later synchronous write's admission", }); test("refresh measures stored slices without inflating a compressed group", () => { - const track = new Track("compressed").accept({ compress: true }); + const track = new Track("compressed").accept({ compression: "deflate" }); const group = track.appendGroup(); const payload = Uint8Array.from({ length: 1024 }, (_, index) => index % 251); for (let index = 0; index < 3; index++) group.writeFrame({ payload }); diff --git a/js/net/src/lite/compression.test.ts b/js/net/src/lite/compression.test.ts index d6d32fb03f8..d1fda008f4f 100644 --- a/js/net/src/lite/compression.test.ts +++ b/js/net/src/lite/compression.test.ts @@ -16,7 +16,7 @@ for (const downstream of [ALPN_06, ALPN_07_WIP]) { const broadcastRoute = source.route(Path.from("compressed"), { hidden: true }); const broadcast = broadcastRoute.broadcast; const datagrams = broadcast.createDatagrams("data"); - const track = broadcast.createTrack("data", { compress: true }); + const track = broadcast.createTrack("data", { compression: "deflate" }); broadcastRoute.announce(); const peers: { abort(): void }[] = []; async function link(publish: Producer, consume: Producer, alpn: string) { @@ -42,7 +42,7 @@ for (const downstream of [ALPN_06, ALPN_07_WIP]) { const active = request.active.peek(); if (!active) throw new Error("broadcast did not resolve"); const remote = active.track("data"); - expect((await remote.info()).compress).toBe(downstream === ALPN_07_WIP); + expect((await remote.info()).compression).toBe(downstream === ALPN_07_WIP ? "deflate" : "none"); const reader = remote.subscribe({ delay: { max: Milli(1000) } }); const group = track.appendGroup(); const payloads = [new Uint8Array(4096).fill(7), new Uint8Array(), new Uint8Array(4096).fill(7)]; diff --git a/js/net/src/lite/datagram-tracks.test.ts b/js/net/src/lite/datagram-tracks.test.ts index e8c81d01445..028899282a6 100644 --- a/js/net/src/lite/datagram-tracks.test.ts +++ b/js/net/src/lite/datagram-tracks.test.ts @@ -115,7 +115,7 @@ test("lite-07 bounds and prioritizes independent createWritable datagram queues" const source = new Origin(); const publication = source.route(path, { hidden: true }); const datagrams = publication.broadcast.createDatagrams("audio"); - publication.broadcast.createTrack("audio", { compress: true }); + publication.broadcast.createTrack("audio", { compression: "deflate" }); publication.announce(); const other = publication.broadcast.createDatagrams("other", { priority: 7 }); const pair = createMockTransportPair(ALPN_07_WIP, { datagramWritable: "createWritable" }); diff --git a/js/net/src/lite/publisher.ts b/js/net/src/lite/publisher.ts index e76ae79f119..32b747f1fe4 100644 --- a/js/net/src/lite/publisher.ts +++ b/js/net/src/lite/publisher.ts @@ -166,7 +166,7 @@ function trackInfoMessage(info: track.Info, version: Version): TrackInfoMessage // `#serveGroup` emits each frame converted to it. timescale: info.timescale ?? undefined, // An older peer is served the frames inflated. - compress: hasCompression(version) && !!info.compress, + compress: hasCompression(version) && info.compression === "deflate", }); } @@ -1095,7 +1095,7 @@ export class Publisher { // what TRACK_INFO advertised. It comes from the producer's accept(), so // they always agree. stamp = stamping(this.version, info); - compress = hasCompression(this.version) && !!info.compress; + compress = hasCompression(this.version) && info.compression === "deflate"; } else { // Older drafts acknowledge with SUBSCRIBE_OK and stream frames verbatim. const ok = new SubscribeOk({ diff --git a/js/net/src/lite/subscriber.ts b/js/net/src/lite/subscriber.ts index 051672e0dee..8032d0ea6d1 100644 --- a/js/net/src/lite/subscriber.ts +++ b/js/net/src/lite/subscriber.ts @@ -1714,7 +1714,7 @@ export class Subscriber { maxAge: info.maxAge === undefined ? undefined : Milli(info.maxAge), priority: info.priority, refresh: info.refresh, - compress: info.compress, + compression: info.compress ? "deflate" : "none", // Lite-05/06 timestamps may be send times, so the copy's groups skip the rewind check. ...(hasMediaTime(this.version) ? {} : { unchecked: true }), }; diff --git a/js/net/src/lite/tracks.test.ts b/js/net/src/lite/tracks.test.ts index cd3beebc5ab..0812665698f 100644 --- a/js/net/src/lite/tracks.test.ts +++ b/js/net/src/lite/tracks.test.ts @@ -465,7 +465,7 @@ test("a listing over a session carries each track's info, end to end", async () maxAge: Milli(3000), priority: 9, refresh: 4, - compress: true, + compression: "deflate", }); const tracks = wireOf(client).consume(Path.from("room")).tracks(); @@ -473,7 +473,7 @@ test("a listing over a session carries each track's info, end to end", async () expect(await tracks.next()).toEqual({ kind: "added", name: "a", - info: { timescale: Timescale.MILLI, maxAge: Milli(3000), priority: 9, refresh: 4, compress: true }, + info: { timescale: Timescale.MILLI, maxAge: Milli(3000), priority: 9, refresh: 4, compression: "deflate" }, }); broadcast.createTrack("b"); expect(await next(tracks)).toBe("+b"); diff --git a/js/net/src/origin.test.ts b/js/net/src/origin.test.ts index 044f75542b7..77833c9937b 100644 --- a/js/net/src/origin.test.ts +++ b/js/net/src/origin.test.ts @@ -2493,18 +2493,6 @@ test("a higher epoch of a dynamic route supersedes a cheaper local broadcast of origin.close(); }); -test("a route refuses a minted instance", async () => { - const origin = new Producer(); - const minted = { instance: Instance.minted() }; - expect(() => origin.route(Path.from("camera"), minted)).toThrow(); - expect(() => origin.routePrefix(Path.from("room"), minted)).toThrow(); - const claim = origin.routePrefix(Path.from("lobby")); - const requests = claim.requested(); - origin.consume().request(Path.from("lobby/alice")); - const asked = await requests.next(); - expect(() => asked.value.route(minted)).toThrow(); -}); - test("a higher epoch that is not the best route still supersedes a local broadcast", async () => { const origin = new Producer(); const path = Path.from("camera"); diff --git a/js/net/src/origin.ts b/js/net/src/origin.ts index 95236ea5d3d..a54395e7076 100644 --- a/js/net/src/origin.ts +++ b/js/net/src/origin.ts @@ -342,13 +342,6 @@ function received(entry: RouteEntry): boolean { return !entry.originated; } -/** Refuse a named instance a relay minted for one announcement: it names no stream. */ -function refuseMinted(options: RouteOptions): void { - if (options.instance !== undefined && Instance.isMinted(options.instance)) { - throw new Error("a minted instance names no stream to route"); - } -} - /** What a peer cannot be served through: a received route, or one of another instance than it pinned. */ function unservable(instance: Instance.Valid | undefined): (entry: RouteEntry) => boolean { if (instance === undefined) return received; @@ -1286,7 +1279,8 @@ export interface RouteOptions { * epoch wins over every older one of the instance, cheaper or not. Naming an instance grants * nothing: publishing still needs the path's grant. * - * A {@link Instance.isMinted | minted} instance names no stream, so routing under one throws. + * Do not start a named instance with `~`: that marks one a relay minted (see + * {@link Instance.isMinted}), which signing refuses to bind and a catalog's instance check skips. */ instance?: Instance.Valid; /** Which incarnation of {@link instance} this is; raise it on each restart. Ignored without an instance. */ @@ -1439,7 +1433,6 @@ export class Producer implements Table { publishPath(path); const created = this.#state.created; if (!created) throw new Error("origin is closed"); - refuseMinted(options); // Normalized first, so a bad cost throws before anything is created. let info = WireRoute.normalize({ instance: options.instance ?? Instance.random(), @@ -1566,7 +1559,6 @@ export class Producer implements Table { * {@link route} instead, so subscribers can enumerate them. */ routePrefix(prefix: Path.Valid, options: RouteOptions = {}): Route { - refuseMinted(options); const info = WireRoute.normalize({ instance: options.instance, epoch: options.epoch, diff --git a/js/net/src/resume.test.ts b/js/net/src/resume.test.ts index f3b2b5e1b9b..6ab35770ece 100644 --- a/js/net/src/resume.test.ts +++ b/js/net/src/resume.test.ts @@ -1831,7 +1831,7 @@ test("a front serving another front reports the inner serving route's drop", asy for (const [field, first, second] of [ ["priority", { priority: 1 }, { priority: 2 }], - ["compression", { compress: true }, { compress: false }], + ["compression", { compression: "deflate" }, { compression: "none" }], ["refresh", { refresh: 4 }, {}], ] as const) { test(`track info keeps one ${field} answer across routes`, async () => { diff --git a/js/net/src/resume.ts b/js/net/src/resume.ts index 54dc9d9289d..d23d20cec97 100644 --- a/js/net/src/resume.ts +++ b/js/net/src/resume.ts @@ -129,7 +129,7 @@ function copyFailed(copy: Copy): boolean { // listed here. `unchecked` says how a copy arrived, not what it holds, so copies over different // lite versions still match. `ietf` is compared, like Rust's moq-transport `properties`. const INFO_FIELDS = Object.keys({ - compress: true, + compression: true, timescale: true, maxAge: true, priority: true, diff --git a/js/net/src/track.test.ts b/js/net/src/track.test.ts index abc467d4437..2e91462218e 100644 --- a/js/net/src/track.test.ts +++ b/js/net/src/track.test.ts @@ -563,7 +563,7 @@ test("an authored track defaults to a zero max age, null is unlimited, and decod // superseded group goes stale and the live edge is exempt from the payload cache window. test("a sole snapshot stays readable to a late joiner at the zero default max age", async () => { const clock = manualTime(10_000); - const producer = new TrackProducer("catalog").accept({ timescale: Timescale.MILLI, compress: true }); + const producer = new TrackProducer("catalog").accept({ timescale: Timescale.MILLI, compression: "deflate" }); try { expect((await producer.info()).maxAge).toBe(Milli.zero); const group = producer.appendGroup(); diff --git a/js/net/src/track.ts b/js/net/src/track.ts index 17f499ba0c2..c6fd0795d76 100644 --- a/js/net/src/track.ts +++ b/js/net/src/track.ts @@ -119,6 +119,13 @@ export interface Position { frame: number; } +/** + * How a track's frames are compressed, mirroring the Rust `track::Compression`: `"deflate"` makes + * each group one DEFLATE stream (draft-lcurley-moq-flate), which suits small, repetitive frames + * like JSON. + */ +export type Compression = "none" | "deflate"; + /** * A track's immutable publisher properties, fixed for the lifetime of the track. * @@ -127,8 +134,8 @@ export interface Position { * (resolved from the wire TRACK_INFO on lite-05+). They map 1:1 onto TRACK_INFO. */ export interface Info { - /** Compress frame payloads per group on lite-07; other sessions receive plain frames. Defaults to false. */ - compress?: boolean; + /** How frame payloads are compressed per group on lite-07; other sessions receive plain frames. Defaults to `"none"`. */ + compression?: Compression; /** * Units per second for this track's frame timestamps, or omitted (`undefined` or `null`, * which mean the same) for an untimed track, whose frames carry no timestamp. @@ -231,11 +238,11 @@ function priorityValue(value: number): number { * {@link InfoInit} at {@link Producer.accept} instead, where an omitted `maxAge` is zero. */ export function infoDefaults(info: Partial = {}): Info { - if (info.compress !== undefined && typeof info.compress !== "boolean") - throw new TypeError("compress must be a boolean"); + if (info.compression !== undefined && info.compression !== "none" && info.compression !== "deflate") + throw new TypeError(`unknown compression: ${info.compression}`); const timescale = info.timescale == null ? undefined : Timescale(info.timescale); return { - compress: info.compress ?? false, + compression: info.compression ?? "none", timescale, maxAge: info.maxAge === undefined ? undefined : wireMillis("maxAge", info.maxAge), priority: priorityValue(info.priority ?? DEFAULT_PRIORITY), @@ -1356,7 +1363,7 @@ export class Producer { try { for (const { group } of this.#cache) { hooks.bindGroupTimed(group, resolved); - hooks.bindGroupCompression(group, resolved.compress ?? false); + hooks.bindGroupCompression(group, resolved.compression === "deflate"); } } catch (err) { this.abort(err instanceof Error ? err : new Error(String(err))); @@ -1777,7 +1784,7 @@ export class Producer { const info = this.#state.info.peek(); if (info) { hooks.bindGroupTimed(group, info); - hooks.bindGroupCompression(group, info.compress ?? false); + hooks.bindGroupCompression(group, info.compression === "deflate"); } } diff --git a/js/publish/src/broadcast.ts b/js/publish/src/broadcast.ts index 0be9a147598..2b8d9a5b40e 100644 --- a/js/publish/src/broadcast.ts +++ b/js/publish/src/broadcast.ts @@ -501,7 +501,7 @@ export class Broadcast { timescale: Moq.Time.Timescale.MILLI, priority: Catalog.PRIORITY.catalog, // Catalog JSON is small and repetitive. - compress: true, + compression: "deflate", }); effect.cleanup(() => { track.finish(); diff --git a/js/publish/src/catalog.ts b/js/publish/src/catalog.ts index 5b07a9674c4..515553134f5 100644 --- a/js/publish/src/catalog.ts +++ b/js/publish/src/catalog.ts @@ -72,7 +72,7 @@ export class CatalogProducer { /** * Serve a track: seed it with the current catalog, then forward updates. * - * Create the track with `compress: true`: catalog JSON is small and repetitive. + * Create the track with `compression: "deflate"`: catalog JSON is small and repetitive. */ serve(track: Moq.Track.Producer, effect: Effect): void { const output = new Json.Snapshot.Producer({ track, deltas: false }); diff --git a/js/watch/src/broadcast.test.ts b/js/watch/src/broadcast.test.ts index 32e8ea4676a..31dc4775fac 100644 --- a/js/watch/src/broadcast.test.ts +++ b/js/watch/src/broadcast.test.ts @@ -108,7 +108,7 @@ describe("unsupported catalog", () => { const owner = new Origin.Producer(); const name = Path.from("room/live.hang"); const published = publish(owner, name); - const track = published.createTrack(Catalog.TRACK, { compress }); + const track = published.createTrack(Catalog.TRACK, { compression: compress ? "deflate" : "none" }); const producer = new Json.Snapshot.Producer({ track, deltas: false }); const enabled = new Signal(true); const source = new Broadcast({ origin: owner, name, catalogFormat: "hang", enabled }); diff --git a/kt/moq/MIGRATE.md b/kt/moq/MIGRATE.md index ba7286c5ffe..4a93f00eb17 100644 --- a/kt/moq/MIGRATE.md +++ b/kt/moq/MIGRATE.md @@ -102,7 +102,7 @@ A fixed audio playout delay `d` is `delay = Delay(min = d, max = ...)` with `est ### Compression moves to the track `dev.moq.flate` is removed: publish opaque bytes on a `TrackProducer`. -`SnapshotConfig` and `WindowConfig` lose `compression`, and `StreamConfig` is removed. Publish the track with `TrackInfo(compress = true)` instead. +`SnapshotConfig` and `WindowConfig` lose `compression`, and `StreamConfig` is removed. Publish the track with `TrackInfo(compression = Compression.DEFLATE)` instead. `StreamProducer` drops its config argument, and `StreamConsumer` and `WindowConsumer` take only the track. `SnapshotConsumer` takes the broadcast and track name; see the entry above. ### Paths with an empty segment are refused ([#6648](https://github.com/moq-dev/moq/pull/6648)) diff --git a/kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/Aliases.kt b/kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/Aliases.kt index 54149942435..2cd0bf297bc 100644 --- a/kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/Aliases.kt +++ b/kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/Aliases.kt @@ -216,6 +216,11 @@ typealias FetchGroupOptions = uniffi.moq.MoqFetchGroupOptions /** Delivery settings for a raw track: priority, ordering, latency budget, and timescale. */ typealias TrackInfo = uniffi.moq.MoqTrackInfo +/** + * How a track's frames are compressed on the wire: `DEFLATE`, or `null` in [TrackInfo] for none. + */ +typealias Compression = uniffi.moq.MoqCompression + /** One audio frame: PCM payload bytes plus a presentation timestamp. */ typealias AudioFrame = uniffi.moq.MoqAudioFrame diff --git a/kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/json/Tracks.kt b/kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/json/Tracks.kt index 8804be16c2c..6f73ff9242f 100644 --- a/kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/json/Tracks.kt +++ b/kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/json/Tracks.kt @@ -4,12 +4,14 @@ package dev.moq.json // producer takes over a `dev.moq.TrackProducer` (the snapshot and stream // producers also advertise it in the broadcast's catalog, which has no window // mode), and a consumer takes over a `dev.moq.TrackConsumer` that has not read -// a group yet. Compression is the track's, set through `TrackInfo(compress = true)`. +// a group yet. Compression is the track's, set through `TrackInfo(compression = +// Compression.DEFLATE)`. // Every write (a snapshot update, a stream append, a window push or pop) takes a // timestamp on the broadcast clock, the epoch every track in the broadcast // shares, so the track needs a timescale; one without is refused: // -// val track = broadcast.publishTrack("status", TrackInfo(timescale = 1_000uL, compress = true)) +// val track = broadcast.publishTrack("status", TrackInfo(timescale = 1_000uL, compression = +// Compression.DEFLATE)) // val status = SnapshotProducer(broadcast, track, SnapshotConfig()) // status.update(Status(state = "live"), CatalogProducer(broadcast).now()) // val reader = SnapshotConsumer(consumer, "status") diff --git a/kt/moq/src/jvmAndAndroidTest/kotlin/dev/moq/SmokeTest.kt b/kt/moq/src/jvmAndAndroidTest/kotlin/dev/moq/SmokeTest.kt index bdb48cef8c3..fbbd78fd9c0 100644 --- a/kt/moq/src/jvmAndAndroidTest/kotlin/dev/moq/SmokeTest.kt +++ b/kt/moq/src/jvmAndAndroidTest/kotlin/dev/moq/SmokeTest.kt @@ -588,7 +588,10 @@ class SmokeTest { BroadcastProducer().use { broadcast -> val config = WindowConfig() val track = - broadcast.publishTrack("log", TrackInfo(timescale = 1_000_000uL, compress = true)) + broadcast.publishTrack( + "log", + TrackInfo(timescale = 1_000_000uL, compression = Compression.DEFLATE), + ) val producer = WindowProducer(track, config) val consumer = WindowConsumer(broadcast.consume().subscribeTrack("log", null)) for (n in 1..3) producer.push( diff --git a/py/moq-rs/MIGRATE.md b/py/moq-rs/MIGRATE.md index e91e7200cb3..481234123aa 100644 --- a/py/moq-rs/MIGRATE.md +++ b/py/moq-rs/MIGRATE.md @@ -91,7 +91,7 @@ A fixed audio playout delay `d` is `delay=Delay(min=d, max=...)` with `estimate= ### Compression moves to the track `moq.flate` is removed: publish opaque bytes on a `TrackProducer`. -The `moq.json` producers and consumers drop their `compression` keyword. Publish the track with `TrackInfo(compress=True)` instead; a consumer reads a compressed track with no option of its own. +The `moq.json` producers and consumers drop their `compression` keyword. Publish the track with `TrackInfo(compression=moq.Compression.DEFLATE)` instead; a consumer reads a compressed track with no option of its own. ### Paths with an empty segment are refused ([#6648](https://github.com/moq-dev/moq/pull/6648)) diff --git a/py/moq-rs/README.md b/py/moq-rs/README.md index 14c62fbff2d..e7ca2b3d114 100644 --- a/py/moq-rs/README.md +++ b/py/moq-rs/README.md @@ -231,7 +231,7 @@ and `.cut()` ends its open group so the next edit opens one restating the window no window mode, so `WindowProducer` takes only the track. A raw frame may omit its timestamp on an untimed track, but every JSON write takes one on the broadcast clock. Publish JSON tracks with -`TrackInfo(compress=True)`: the track compresses each group on the wire, and consumers read it the +`TrackInfo(compression=moq.Compression.DEFLATE)`: the track compresses each group on the wire, and consumers read it the same either way. Opaque bytes go on a plain `TrackProducer`. ### Subscribing diff --git a/py/moq-rs/moq/__init__.py b/py/moq-rs/moq/__init__.py index 76c391c65e4..c7cd8c70d59 100644 --- a/py/moq-rs/moq/__init__.py +++ b/py/moq-rs/moq/__init__.py @@ -61,6 +61,7 @@ AudioSampleFormat, Backoff, ClientTls, + Compression, ConnectionPhase, ConnectionState, ConnectionStats, @@ -110,6 +111,7 @@ "BroadcastRequest", "Client", "ClientTls", + "Compression", "CongestionControl", "ConnectionStats", "ConnectionPhase", diff --git a/py/moq-rs/moq/_records.py b/py/moq-rs/moq/_records.py index b034d4d48e3..ef5e8882679 100644 --- a/py/moq-rs/moq/_records.py +++ b/py/moq-rs/moq/_records.py @@ -18,6 +18,7 @@ MoqAnchor, MoqBackoff, MoqClientTls, + MoqCompression, MoqCongestionControl, MoqConnectionStats, MoqDatagram, @@ -299,15 +300,15 @@ class TrackInfo: how many times its first frame a group's later bytes may grow before a joining subscriber asks for a new group, ``None`` to never ask. ``timescale`` is ticks per second: ``None`` means the track is untimed, on both publish and receive. - ``compress`` DEFLATEs each group on the wire to peers that support it; readers - always see the original frames. + ``compression`` compresses each group on the wire to peers that support it, ``None`` + sending frames as written; readers always see the original frames. """ priority: int = 0 max_age: timedelta | None = timedelta(0) refresh: int | None = None timescale: int | None = None - compress: bool = False + compression: MoqCompression | None = None def _ffi(self) -> MoqTrackInfo: return MoqTrackInfo( @@ -316,7 +317,7 @@ def _ffi(self) -> MoqTrackInfo: max_age_unlimited=self.max_age is None, refresh=self.refresh, timescale=self.timescale, - compress=self.compress, + compression=self.compression, ) @staticmethod @@ -326,7 +327,7 @@ def _from_ffi(info: MoqTrackInfo) -> TrackInfo: max_age=None if info.max_age_unlimited else (info.max_age or timedelta(0)), refresh=info.refresh, timescale=info.timescale, - compress=info.compress, + compression=info.compression, ) diff --git a/py/moq-rs/moq/json.py b/py/moq-rs/moq/json.py index 62a242db139..a3113eed85e 100644 --- a/py/moq-rs/moq/json.py +++ b/py/moq-rs/moq/json.py @@ -6,7 +6,7 @@ :class:`~moq.TrackConsumer` that has not read a group yet. Either track can come from a request as well as by name. Values are any JSON-serializable Python object. -Compression is the track's: publish it with ``TrackInfo(compress=True)``, which JSON benefits from, +Compression is the track's: publish it with ``TrackInfo(compression=Compression.DEFLATE)``, which JSON benefits from, and a consumer reads it with no option of its own. Every write (a snapshot update, a stream append, a window push or pop) takes a timestamp on the diff --git a/py/moq-rs/moq/types.py b/py/moq-rs/moq/types.py index 43ce8f7f7d2..cfb040de79b 100644 --- a/py/moq-rs/moq/types.py +++ b/py/moq-rs/moq/types.py @@ -13,6 +13,9 @@ from moq_ffi import ( MoqAudioSampleFormat as AudioSampleFormat, ) +from moq_ffi import ( + MoqCompression as Compression, +) from moq_ffi import ( MoqConnectionPhase as ConnectionPhase, ) @@ -85,6 +88,7 @@ "AudioSampleFormat", "Backoff", "ClientTls", + "Compression", "ConnectionStats", "ConnectionPhase", "ConnectionState", diff --git a/py/moq-rs/tests/test_local.py b/py/moq-rs/tests/test_local.py index fbe1b655e77..ca2120ae380 100644 --- a/py/moq-rs/tests/test_local.py +++ b/py/moq-rs/tests/test_local.py @@ -589,7 +589,7 @@ async def test_fetch_group_and_serve_dynamic_miss(): async def test_json_snapshot_roundtrip(): broadcast = moq.BroadcastProducer() - track = broadcast.publish_track("status", moq.TrackInfo(timescale=1_000_000, compress=True)) + track = broadcast.publish_track("status", moq.TrackInfo(timescale=1_000_000, compression=moq.Compression.DEFLATE)) producer = moq.json.SnapshotProducer(broadcast, track) consumer = moq.json.SnapshotConsumer(broadcast.consume(), "status") @@ -623,7 +623,7 @@ async def test_json_stream_roundtrip(): async def test_json_window_roundtrip(): broadcast = moq.BroadcastProducer() - track = broadcast.publish_track("log", moq.TrackInfo(timescale=1_000_000, compress=True)) + track = broadcast.publish_track("log", moq.TrackInfo(timescale=1_000_000, compression=moq.Compression.DEFLATE)) producer = moq.json.WindowProducer(track) consumer = moq.json.WindowConsumer(await broadcast.consume().subscribe_track("log")) demand = producer.demand() @@ -709,7 +709,7 @@ async def test_json_window_skips_records_outside_the_checkpoint(): async def test_json_producers_report_demand(): broadcast = moq.BroadcastProducer() - timed = moq.TrackInfo(timescale=1_000, compress=True) + timed = moq.TrackInfo(timescale=1_000, compression=moq.Compression.DEFLATE) snapshot = moq.json.SnapshotProducer(broadcast, broadcast.publish_track("status", timed)) stream = moq.json.StreamProducer(broadcast, broadcast.publish_track("events", timed)) snapshot_demand = snapshot.demand() diff --git a/quest/m2/api-shape/README.md b/quest/m2/api-shape/README.md index 1b78418aacc..39b30df6b5b 100644 --- a/quest/m2/api-shape/README.md +++ b/quest/m2/api-shape/README.md @@ -54,7 +54,7 @@ Rejected in planning: ## Required -- [moq-net's small surface fixes](/quest/m2/api-shape/net.md) - one spelling per session, admission, compression, proxy, and priority surface, and no public wire codes +- [moq-net's remaining surface fixes](/quest/m2/api-shape/net.md) - the route stream un-hide after #8063, whether `group::Demand` stays public, and whether a route refuses a minted instance - [Transports take shared types](/quest/m2/api-shape/transport.md) - moq-uring takes a congestion factory and rustls configs, and the tokio server request stops exposing its QUIC internals - [Crates re-export no whole crate](/quest/m2/api-shape/reexports.md) - no moq crate re-exports a whole crate, moq's own included, so a dependency bump is no moq break, and moq-mux's container `Guard` gets a name - [Media crates' small surface fixes](/quest/m2/api-shape/media.md) - exporters, the container consumer, catalog color range, rate grant, moq-stats, JSON, and MSF each have one path and one name diff --git a/quest/m2/api-shape/net.md b/quest/m2/api-shape/net.md index 093d8078e9e..f0bdd6382d1 100644 --- a/quest/m2/api-shape/net.md +++ b/quest/m2/api-shape/net.md @@ -1,41 +1,9 @@ -# [M] moq-net's small surface fixes +# [S] moq-net's remaining surface fixes ## Goal -Each item below lands in moq-net (and moq-auth for the mesh constants) with -its JS and binding mirrors: +The rest of moq-net's small surface fixes, with their JS mirrors: -- Remove `Client::with_origin` (`rs/moq-net/src/client.rs`). It is sugar - for `with_publisher(&o).with_subscriber(o)`, release's - `Server::with_origin` is already gone, and its six callers (moq-boy, - moq-stats, the relay's cluster and stats, a moq-ffi test, and moq-tokio's - forwarder) switch to the two calls. -- Make `Version::{code, from_code}` `pub(crate)`. The relay compares - `version.code() >= 0xff0dad05` (`rs/moq-relay/src/cluster.rs`) and moq-cli - scans `0xff0dad00..=0xff0dadff`; each asks a named question of `Version` - instead (add the predicate the relay needs, and let moq-cli list - `Version`'s supported set). -- Make `group::Producer::demand` and `group::Demand` `pub(crate)`. Nothing - outside moq-net calls them, and flights stop through - `Fill::poll_unwanted`. Update `rs/moq-net/MIGRATE.md`'s mention. -- Replace `compress: bool` on track info with a `Compression` enum that - matches the wire's values, in Rust, `@moq/net`, moq-ffi, and moq-c. -- Rename `server::{Activity, Active}` to `server::{Admission, Admitted}`. -- Rename `RefusalKind::Lan` and `Refusals.lan` to `Membership` and - `membership` ("a membership proof was missing or invalid"), so moq-net's - counters name no relay flag. No serde alias: the field is new since - release. moq-stats and stats dashboards follow. -- Add `reconnect::Attempt::client(&self, &Client) -> Client`, which sets the - URL, places the token where the client's own versions put it, and attaches - the token handle. It replaces `Attempt::token()`, `Reconnect::with_tokens`'s - `versions` argument, and the caller's separate `with_auth` call. -- Make `moq_auth::mesh::{PROOF_CONTEXT, CHALLENGE_LEN, proof_message}` - private. -- Rename the datagram `Producer::poll_priority(waiter, last)` to - `poll_priority_changed(&mut self, waiter)`, keeping its own last value like - `poll_wanted_changed`. -- `Producer::route` and `Request::route` refuse an instance that - `is_minted()`, so a caller cannot claim a random instance as stable. - After [moq-dev/moq#8063](https://github.com/moq-dev/moq/pull/8063) removes `RouteEvent::Takeover`, un-hide `origin::Consumer::routes`, `Routes`, and `RouteEvent`, documented as the relay-level stream that moq-relay and @@ -44,42 +12,42 @@ its JS and binding mirrors: announce: Announce }` with `pub enum RouteKind { Start, Update, Restart, End }`, mirroring JS's `{ kind } & Routed`, so callers need no or-pattern and no accessors. -- `stats::Registry::report` takes an explicit `now`, and - `stats::Handle::{refuse, session}` take `#[non_exhaustive]` argument - structs with a `new(label, ..)` constructor (named by role, not clashing - with `server::Admission`), so [lag-histogram](/quest/m3/qos/lag-histogram.md) - and [session-outcome-records](/quest/m3/session-outcome-records.md) add - fields instead of breaking moq-net again. -- `group::MAX_CACHE_BYTES` becomes `pub(crate)`: byte-holes turns it from a - size cap into a tail budget, and moq-json's `max_group_bytes` keeps its own - 32 MiB default. Each outside use takes a limit of its own: moq-json's - encoder defaults and clamp, moq-mux's jitter, container-consumer, and - fMP4 bounds, the moq-stats `producer_tick` benchmark, and the oversize - tests in moq-json, moq-mux, and moq-gst. -- Remove `origin::Consumer::with_proxy` (from - [moq-dev/moq#8023](https://github.com/moq-dev/moq/pull/8023)) in favor of - `origin::Producer::with_proxy`, which already reaches every consumer taken - from that producer. Only tests call the consumer override: the moq-net - integration harness (`rs/moq-net/tests/integration/support/harness.rs`, two - sites), `mount.rs`, and moq-mux's `container/test_util.rs` (two sites); - each sets proxy on the producer it consumes from instead. -- `auth::Grant` gets `#[non_exhaustive]`, since - [rate-grant](/quest/m5/rate-grant.md) adds rates to it; callers outside - moq-net build it from `Grant::default()`. +- Settle whether `group::Producer::demand` and `group::Demand` stay public (see + Waiting). +- Settle whether `Producer::route` and `Request::route` refuse an instance that + `is_minted()` (see Waiting). ## Plan Found by the 2026-11-07 API shape audit (net model and net session); see -the [epic](/quest/m2/api-shape/README.md). Each item is XS except -`Attempt::client`, `Compression`, and the `with_proxy` removal (S each). `RefusalKind` is a stats-wire -field, so say in the PR which deployed dashboards read it. If #8063 has not -merged when this starts, leave the un-hide for a follow-up and say so. +the [epic](/quest/m2/api-shape/README.md). The rest of the audit's items landed in +[moq-dev/moq#8266](https://github.com/moq-dev/moq/pull/8266). Start the un-hide +once #8063 merges. The `RouteEvent` reshape replaces +[moq-dev/moq#7862](https://github.com/moq-dev/moq/pull/7862)'s accessors, which +closed without taking it. -Added 2026-11-07 (maintainer, /quest-plan from the 2026-11-07 API sweep of open PRs and remaining quests): the `RouteEvent` -struct, the stats arguments, the cache cap, and `Grant`. The `RouteEvent` -reshape replaces [moq-dev/moq#7862](https://github.com/moq-dev/moq/pull/7862)'s -accessors. #7862 closed without taking it, so the reshape lands here. +## Waiting -Decided 2026-11-07 (maintainer, /quest-complete, from -[moq-dev/moq#8088](https://github.com/moq-dev/moq/pull/8088)'s follow-ups): -✅ remove `origin::Consumer::with_proxy` in favor of the producer's. +- Maintainer: decide whether `group::Demand` stays public. It cannot simply go + `pub(crate)`: a paced flight needs it. The audit assumed flights stop through + `Fill::poll_unwanted`, but that resolves as soon as readers take the group + (`fills.wants`), while a paced flight has to see its riders leave; + `rs/moq-net/tests/integration/flights.rs` and `rs/moq-net/benches/group.rs` + call `group::Producer::demand` for that. Options: (a) keep + `group::Producer::demand` and `group::Demand` public, documented as how a + paced flight sees its riders leave (recommended: the one spelling that works + today); (b) fold reader demand into `Fill::poll_unwanted` and + `Fill::is_wanted`, then make `group::Demand` `pub(crate)`, a behavior change + for every flight; (c) make it `pub(crate)` and move the flight test and the + group bench in-crate. +- Maintainer: decide whether a route refuses a minted instance. Refusing it in + `Producer::route`, `Request::route`, and `route_prefix` (Rust and JS) breaks + three tests outside moq-net that route `Instance::minted()` directly to stand in + for a route a pre-lite-07 session minted: moq-mux's + `follow::tests::a_named_instance_follows_a_minted_one` and @moq/watch's + `relativeBroadcast` and include tests. Options: (a) refuse, and rewrite those + tests to receive the route over a pre-lite-07 session, which needs a version + argument on moq-mux's `container/test_util.rs` `Link` and a session test helper + @moq/watch can import from @moq/net (recommended: the API then cannot claim a + minted instance as stable); (b) keep accepting it, documenting that a minted + instance proves nothing; (c) refuse it in Rust only, leaving JS as is. diff --git a/rs/hang/src/catalog/root.rs b/rs/hang/src/catalog/root.rs index a3328a79a6a..510d3e85685 100644 --- a/rs/hang/src/catalog/root.rs +++ b/rs/hang/src/catalog/root.rs @@ -256,12 +256,12 @@ impl Catalog<()> { /// Keeps moq-net's default zero max age rather than the media one: the catalog is /// snapshot mode, so a join reads the newest snapshot, which never goes stale. /// Timed in milliseconds, so snapshots share the broadcast clock with media, and - /// [`compress`](moq_net::track::Info::compress)ed, since catalog JSON is small and repetitive. + /// [compressed](moq_net::track::Info::compression), since catalog JSON is small and repetitive. pub fn default_track_info() -> moq_net::track::Info { moq_net::track::Info::default() .with_timescale(moq_net::Timescale::MILLI) .with_priority(PRIORITY.catalog) - .with_compress(true) + .with_compression(moq_net::track::Compression::Deflate) } /// The subscription preferences used for the catalog track (high priority so diff --git a/rs/moq-auth/src/mesh/mod.rs b/rs/moq-auth/src/mesh/mod.rs index e313a1f80a4..ae832bbb42f 100644 --- a/rs/moq-auth/src/mesh/mod.rs +++ b/rs/moq-auth/src/mesh/mod.rs @@ -42,7 +42,10 @@ pub use coordinator::*; const PROOF_CONTEXT: &[u8] = b"moq-mesh-enroll-00"; /// The length of a challenge in bytes. -#[cfg_attr(not(feature = "serve"), allow(dead_code, reason = "only the coordinator issues challenges"))] +#[cfg_attr( + not(feature = "serve"), + allow(dead_code, reason = "only the coordinator issues challenges") +)] pub(crate) const CHALLENGE_LEN: usize = 32; const SIGNATURE_LEN: usize = 64; diff --git a/rs/moq-c/MIGRATE.md b/rs/moq-c/MIGRATE.md index 2f11ec28ba1..cbc75582521 100644 --- a/rs/moq-c/MIGRATE.md +++ b/rs/moq-c/MIGRATE.md @@ -88,7 +88,7 @@ Set `delay.max_us` to the old `max_delay_us`, `delay.max_unlimited` for no limit `moq_json_snapshot_config.compression`, `moq_json_stream_config`, `moq_binary_config`, and the `moq_publish_binary_snapshot*` and `moq_publish_binary_stream*` functions are removed. `moq_publish_json_stream`, `moq_consume_json_snapshot`, and `moq_consume_json_stream` drop their `config` argument. -JSON tracks are created with `compress` set, and a consumer reads one like a plain track. Publish opaque bytes on a raw track with `moq_publish_track`. +JSON tracks are created with `compression` set to `MOQ_COMPRESSION_DEFLATE`, and a consumer reads one like a plain track. Publish opaque bytes on a raw track with `moq_publish_track`. ### Authored configs keep their identity ([#7110](https://github.com/moq-dev/moq/pull/7110)) @@ -194,9 +194,9 @@ Publish a replacement under a new name, and expect a finished track's demand ter To answer with a broadcast you already hold, `moq_broadcast_request_serve(request, consumer)` serves it under the prefix route without announcing an exact route; the consumer stays yours to free. `moq_broadcast_prepared_free` refuses an answer you will not publish. -### `moq_track_info` gains `compress` (#5928) +### `moq_track_info` gains `compression` (#5928) -The new trailing field changes its ABI. A zero-initialized struct leaves it false, as before. +The new trailing field changes its ABI. A zero-initialized struct leaves it `MOQ_COMPRESSION_NONE`, as before. ### Anchors can name a time (#6074) diff --git a/rs/moq-c/build.rs b/rs/moq-c/build.rs index 420816a9213..12d2ea7a960 100644 --- a/rs/moq-c/build.rs +++ b/rs/moq-c/build.rs @@ -19,6 +19,7 @@ const ENUMS: &[&str] = &[ "moq_demand", "moq_decode_start", "moq_anchor_kind", + "moq_compression", ]; fn main() { diff --git a/rs/moq-c/src/api.rs b/rs/moq-c/src/api.rs index 7bb563d9a4f..2ba8df4aefb 100644 --- a/rs/moq-c/src/api.rs +++ b/rs/moq-c/src/api.rs @@ -718,9 +718,20 @@ pub struct moq_track_info { /// Whether `refresh` is set. When false, a joining subscriber never asks for a new group. pub refresh_present: bool, - /// Whether each group is DEFLATE-compressed on the wire to peers that support it. - /// Readers always see the original frames. - pub compress: bool, + /// `moq_compression` discriminant: how each group is compressed on the wire to peers that + /// support it. Zero sends frames as written. Readers always see the original frames. + pub compression: u32, +} + +/// How a track's frames are compressed, with the values TRACK_INFO carries. +#[repr(C)] +#[expect(non_camel_case_types, reason = "C ABI type names match moq.h")] +#[derive(Clone, Copy, Debug)] +pub enum moq_compression { + /// Frames travel as written. + MOQ_COMPRESSION_NONE = 0, + /// Each group is one DEFLATE stream, which suits small, repetitive frames like JSON. + MOQ_COMPRESSION_DEFLATE = 1, } impl TryFrom<&moq_track_info> for moq_net::track::Info { @@ -738,7 +749,12 @@ impl TryFrom<&moq_track_info> for moq_net::track::Info { if info.refresh_present { out = out.with_refresh(info.refresh); } - Ok(out.with_compress(info.compress)) + let compression = match info.compression { + v if v == moq_compression::MOQ_COMPRESSION_NONE as u32 => moq_net::track::Compression::None, + v if v == moq_compression::MOQ_COMPRESSION_DEFLATE as u32 => moq_net::track::Compression::Deflate, + _ => return Err(Error::InvalidCode), + }; + Ok(out.with_compression(compression)) } } diff --git a/rs/moq-c/src/publish.rs b/rs/moq-c/src/publish.rs index 2b076835319..1eedd9350a2 100644 --- a/rs/moq-c/src/publish.rs +++ b/rs/moq-c/src/publish.rs @@ -1295,7 +1295,7 @@ impl Publish { // Compressed: JSON is small and repetitive. let mut info = moq_net::track::Info::default() .with_timescale(moq_net::Timescale::MILLI) - .with_compress(true); + .with_compression(moq_net::track::Compression::Deflate); info.refresh = refresh; let track = broadcast.producer.create_track(name, info)?; let producer = publish(&broadcast.catalog, track)?; diff --git a/rs/moq-c/src/test.rs b/rs/moq-c/src/test.rs index d199fb2ca9b..00cda3cb000 100644 --- a/rs/moq-c/src/test.rs +++ b/rs/moq-c/src/test.rs @@ -1986,7 +1986,7 @@ fn publish_track_invalid_broadcast() { timescale_present: false, refresh: 0, refresh_present: false, - compress: false, + compression: 0, }; assert!(unsafe { moq_publish_track(0, name.as_ptr() as *const c_char, name.len(), &info) } < 0); assert!(moq_publish_track_group(9999) < 0); @@ -2021,7 +2021,7 @@ fn publish_track_with_info_rejects_invalid_timescale() { timescale_present: true, refresh: 0, refresh_present: false, - compress: false, + compression: 0, }; assert!(unsafe { moq_publish_track(broadcast, name.as_ptr() as *const c_char, name.len(), &info) } < 0); @@ -2040,7 +2040,7 @@ fn track_info_max_age() { timescale_present: false, refresh: 0, refresh_present: false, - compress: false, + compression: 0, }; let max_age = |info: moq_track_info| moq_net::track::Info::try_from(&info).unwrap().max_age; @@ -2362,9 +2362,11 @@ fn wait_datagram_reader(track: u32) { .publish .datagram_producer(Id::try_from(track).unwrap()) .expect("a datagram track"); - let reader = kio::wait(|waiter| loop { - if std::task::ready!(datagrams.poll_priority_changed(waiter)).is_some() { - return std::task::Poll::Ready(()); + let reader = kio::wait(|waiter| { + loop { + if std::task::ready!(datagrams.poll_priority_changed(waiter)).is_some() { + return std::task::Poll::Ready(()); + } } }); crate::ffi::RUNTIME @@ -2484,9 +2486,11 @@ fn a_datagram_only_track_is_read() { dg_cb.ptr, ) }); - let reader = kio::wait(|waiter| loop { - if std::task::ready!(datagrams.poll_priority_changed(waiter)).is_some() { - return std::task::Poll::Ready(()); + let reader = kio::wait(|waiter| { + loop { + if std::task::ready!(datagrams.poll_priority_changed(waiter)).is_some() { + return std::task::Poll::Ready(()); + } } }); crate::ffi::RUNTIME @@ -2646,7 +2650,7 @@ fn raw_track_subscription_options_and_update() { timescale_present: true, refresh: 0, refresh_present: false, - compress: false, + compression: 0, }; let track = id(unsafe { moq_publish_track(broadcast, track_name.as_ptr() as *const c_char, track_name.len(), &info) }); @@ -2781,7 +2785,7 @@ fn raw_track_time_anchor() { timescale_present: true, refresh: 0, refresh_present: false, - compress: false, + compression: 0, }; let track = id(unsafe { moq_publish_track(broadcast, track_name.as_ptr() as *const c_char, track_name.len(), &info) }); @@ -3761,7 +3765,7 @@ fn publish_finish_serves_finished_tracks_until_closed() { timescale_present: false, refresh: 0, refresh_present: false, - compress: false, + compression: 0, }; let track = id(unsafe { moq_publish_track(broadcast, name.as_ptr() as *const c_char, name.len(), &info) }); let payload = b"tail"; @@ -4571,7 +4575,7 @@ fn track_demand_reports_the_wanted_group() { timescale_present: false, refresh: 0, refresh_present: true, - compress: false, + compression: 0, }; let track = id(unsafe { moq_publish_track(broadcast, name.as_ptr() as *const c_char, name.len(), &info) }); @@ -4981,7 +4985,7 @@ fn a_group_request_nobody_reads_is_withdrawn() { timescale_present: false, refresh: 0, refresh_present: false, - compress: false, + compression: 0, }; let track = id(unsafe { moq_publish_track(broadcast, name.as_ptr() as *const c_char, name.len(), &info) }); let group_cb = Callback::new(); diff --git a/rs/moq-cli/src/args.rs b/rs/moq-cli/src/args.rs index 2214bcf25cd..03ced99ebf6 100644 --- a/rs/moq-cli/src/args.rs +++ b/rs/moq-cli/src/args.rs @@ -3214,7 +3214,10 @@ mod tests { // As a set: a choice list reads ascending, and that ordering is a presentation call. // Every wire code moq-net parses, including the opt-in `-wip` drafts. - let mut expected: Vec<&str> = hang::moq_net::Version::ALL.iter().map(|version| version.as_str()).collect(); + let mut expected: Vec<&str> = hang::moq_net::Version::ALL + .iter() + .map(|version| version.as_str()) + .collect(); expected.sort_unstable(); let mut found = Vec::new(); walk(Cli::spec().root, &mut found); diff --git a/rs/moq-cli/src/report.rs b/rs/moq-cli/src/report.rs index 4617dc16ebd..6ff78b6d10a 100644 --- a/rs/moq-cli/src/report.rs +++ b/rs/moq-cli/src/report.rs @@ -49,7 +49,7 @@ impl ReportTrack { // once they outweigh eight snapshots. let info = moq_net::track::Info::default() .with_priority(PRIORITY) - .with_compress(true) + .with_compression(moq_net::track::Compression::Deflate) .with_refresh(8); let track = broadcast.create_track(name, info)?; Ok(Self { diff --git a/rs/moq-ffi/MIGRATE.md b/rs/moq-ffi/MIGRATE.md index 3f8e68f7198..48803f3a086 100644 --- a/rs/moq-ffi/MIGRATE.md +++ b/rs/moq-ffi/MIGRATE.md @@ -102,7 +102,7 @@ A fixed audio playout delay `d` is `delay: MoqDelay { min: d, max }` with `estim ### Compression moves to the track The `MoqFlate*` producers and `MoqFlateConfig` are deleted: publish opaque bytes on a `MoqTrackProducer`. -`MoqJsonSnapshotConfig` and `MoqJsonWindowConfig` lose `compression`, and `MoqJsonStreamConfig` is removed: set `compress` on the `MoqTrackInfo` you publish the track with instead. +`MoqJsonSnapshotConfig` and `MoqJsonWindowConfig` lose `compression`, and `MoqJsonStreamConfig` is removed: set `compression` on the `MoqTrackInfo` you publish the track with instead. `MoqJsonStreamProducer::new` drops its config argument, and `MoqJsonSnapshotConsumer::new`, `MoqJsonStreamConsumer::new`, and `MoqJsonWindowConsumer::new` take only the track, reading a compressed track like a plain one. ### Paths with an empty segment are refused ([#6648](https://github.com/moq-dev/moq/pull/6648)) @@ -239,9 +239,9 @@ Publish a replacement under a new name, and expect a finished track's demand wat `MoqBroadcastRequest::accept` is replaced by `prepare()`, which returns a `MoqBroadcastPrepared`: fill its `broadcast()`, then `publish()` announces it at the exact path under a fresh instance of its own and returns its producer. Dropping a prepared answer unpublished refuses the request. -### `MoqTrackInfo` gains `compress` (#5928) +### `MoqTrackInfo` gains `compression` (#5928) -It defaults to `false` in every generated binding; a Rust struct literal adds `compress: false`. +It defaults to none (`null`/`nil`/`None`) in every generated binding; a Rust struct literal adds `compression: None`. ### Anchors can name a time (#6074) diff --git a/rs/moq-ffi/src/bench.rs b/rs/moq-ffi/src/bench.rs index 8e7ae89e77d..d0c25354099 100644 --- a/rs/moq-ffi/src/bench.rs +++ b/rs/moq-ffi/src/bench.rs @@ -260,7 +260,7 @@ async fn rust_ffi() { max_age_unlimited: false, refresh: None, timescale: Some(1_000_000), - compress: false, + compression: None, }; let tracks: Vec<_> = (0..case.publishers) .map(|p| broadcast.publish_track(p.to_string(), Some(timed.clone())).unwrap()) diff --git a/rs/moq-ffi/src/datagram.rs b/rs/moq-ffi/src/datagram.rs index c429a15bdbe..506fedb17d7 100644 --- a/rs/moq-ffi/src/datagram.rs +++ b/rs/moq-ffi/src/datagram.rs @@ -158,13 +158,15 @@ impl MoqDatagramProducer { /// Wait until the aggregate subscriber priority differs from `last`. pub async fn priority_changed(&self, last: Option) -> Result, MoqError> { self.inner - .wait(|producer, waiter| loop { - let priority = match producer.priority() { - now if now != last => now, - _ => ready!(producer.poll_priority_changed(waiter)), - }; - if priority != last { - return Poll::Ready(Ok(priority)); + .wait(|producer, waiter| { + loop { + let priority = match producer.priority() { + now if now != last => now, + _ => ready!(producer.poll_priority_changed(waiter)), + }; + if priority != last { + return Poll::Ready(Ok(priority)); + } } }) .await diff --git a/rs/moq-ffi/src/json.rs b/rs/moq-ffi/src/json.rs index 9bbe24a2319..243a1160f88 100644 --- a/rs/moq-ffi/src/json.rs +++ b/rs/moq-ffi/src/json.rs @@ -21,7 +21,7 @@ use crate::producer::{Child, MoqBroadcastProducer, MoqTrackProducer}; /// Options for a JSON snapshot producer (lossy latest-value mode). /// -/// Compression is the track's: set `compress` on the [`MoqTrackInfo`](crate::producer::MoqTrackInfo) +/// Compression is the track's: set `compression` on the [`MoqTrackInfo`](crate::producer::MoqTrackInfo) /// the track is created with. A consumer reads either kind with no option of its own. #[derive(Clone, uniffi::Record)] pub struct MoqJsonSnapshotConfig { diff --git a/rs/moq-ffi/src/producer.rs b/rs/moq-ffi/src/producer.rs index 6aecedbf9d5..630f8cc2c19 100644 --- a/rs/moq-ffi/src/producer.rs +++ b/rs/moq-ffi/src/producer.rs @@ -57,10 +57,25 @@ pub struct MoqTrackInfo { /// Per-frame timescale in ticks per second, or null for an untimed track. #[uniffi(default = None)] pub timescale: Option, - /// Whether each group is DEFLATE-compressed on the wire to peers that support it. - /// Readers always see the original frames. - #[uniffi(default = false)] - pub compress: bool, + /// How each group is compressed on the wire to peers that support it, or null to send + /// frames as written. Readers always see the original frames. + #[uniffi(default = None)] + pub compression: Option, +} + +/// How a track's frames are compressed, mirroring [`moq_net::track::Compression`]; an +/// uncompressed track has none. +#[derive(Clone, Copy, Debug, PartialEq, Eq, uniffi::Enum)] +pub enum MoqCompression { + /// Each group is one DEFLATE stream, which suits small, repetitive frames like JSON. + Deflate, +} + +fn compression(compression: Option) -> moq_net::track::Compression { + match compression { + None => moq_net::track::Compression::None, + Some(MoqCompression::Deflate) => moq_net::track::Compression::Deflate, + } } impl TryFrom for moq_net::track::Info { @@ -81,7 +96,7 @@ impl TryFrom for moq_net::track::Info { })?; out = out.with_timescale(scale); } - Ok(out.with_compress(info.compress)) + Ok(out.with_compression(compression(info.compression))) } } @@ -99,7 +114,8 @@ impl From<&moq_net::track::Info> for MoqTrackInfo { max_age_unlimited: info.max_age.is_none(), refresh: info.refresh, timescale: info.timescale.map(|timescale| timescale.as_u64()), - compress: info.compress, + // A codec this binding cannot name yet reads as uncompressed, as its frames do. + compression: (info.compression == moq_net::track::Compression::Deflate).then_some(MoqCompression::Deflate), } } } @@ -1042,7 +1058,7 @@ mod metadata_tests { max_age_unlimited, refresh: None, timescale: None, - compress: false, + compression: None, }; let zero = Some(std::time::Duration::ZERO); let five = Some(std::time::Duration::from_secs(5)); diff --git a/rs/moq-ffi/src/test.rs b/rs/moq-ffi/src/test.rs index 168ad452b22..f7402b2d6e4 100644 --- a/rs/moq-ffi/src/test.rs +++ b/rs/moq-ffi/src/test.rs @@ -52,7 +52,7 @@ fn timed_info() -> MoqTrackInfo { max_age_unlimited: false, refresh: None, timescale: Some(1_000_000), - compress: false, + compression: None, } } @@ -1233,7 +1233,7 @@ async fn raw_track_info_reports_publisher_properties() { max_age_unlimited: false, refresh: Some(2), timescale: Some(90_000), - compress: true, + compression: Some(crate::producer::MoqCompression::Deflate), }; let track = broadcast.publish_track("status".into(), Some(info)).unwrap(); let consumer = track.consume(None).unwrap(); @@ -1244,7 +1244,7 @@ async fn raw_track_info_reports_publisher_properties() { assert!(!got.max_age_unlimited); assert_eq!(got.refresh, Some(2)); assert_eq!(got.timescale, Some(90_000)); - assert!(got.compress); + assert_eq!(got.compression, Some(crate::producer::MoqCompression::Deflate)); } #[tokio::test] @@ -1319,7 +1319,7 @@ async fn data_writes_preserve_the_callers_timestamp() { max_age_unlimited: false, refresh: None, timescale: Some(timestamp.scale), - compress: false, + compression: None, }), ) .unwrap(); @@ -1423,7 +1423,7 @@ async fn json_snapshot_roundtrip() { max_age_unlimited: false, timescale: Some(1_000_000), refresh: None, - compress: true, + compression: Some(crate::producer::MoqCompression::Deflate), }; let track = broadcast.publish_track("meta".into(), Some(info)).unwrap(); let producer = MoqJsonSnapshotProducer::new(&broadcast, &track, config.clone()).unwrap(); @@ -1497,7 +1497,7 @@ async fn json_snapshot_refreshes_for_a_joiner() { max_age_unlimited: false, refresh: Some(1), timescale: Some(1_000_000), - compress: false, + compression: None, }), ) .unwrap(); @@ -1725,7 +1725,7 @@ async fn json_window_refreshes_a_bounded_checkpoint_for_a_joiner() { max_age_unlimited: false, refresh: Some(1), timescale: Some(1_000_000), - compress: false, + compression: None, }), ) .unwrap(); @@ -8577,9 +8577,10 @@ async fn auth_tokens_join_and_leave_the_union() { let mut listener = config.init(Default::default()).unwrap().listen().await.unwrap(); let addr = listener.tcp_local_addr().unwrap(); - let publish = |pattern: &str| moq_net::auth::Grant { - publish: pattern.parse::().unwrap().into(), - ..Default::default() + let publish = |pattern: &str| { + let mut grant = moq_net::auth::Grant::default(); + grant.publish = pattern.parse::().unwrap().into(); + grant }; let serving = tokio::spawn(async move { let mut request = listener.accept().await.expect("accept"); @@ -9226,7 +9227,7 @@ async fn audio_subscribe_configuration_boundary() { max_age_unlimited: false, refresh: None, timescale: None, - compress: false, + compression: None, }), ) .unwrap(); diff --git a/rs/moq-gst/tests/element.rs b/rs/moq-gst/tests/element.rs index efdc1b7bccb..b8c1258c621 100644 --- a/rs/moq-gst/tests/element.rs +++ b/rs/moq-gst/tests/element.rs @@ -1093,7 +1093,7 @@ fn a_pad_requested_from_the_eos_notify_is_refused() { } // A write that the producer rejects is the failure the property exists for. A frame past -// MAX_CACHE_BYTES is the deterministic way to cause one: moq-net refuses it before reserving a group. +// moq-net's 32 MiB frame bound is the deterministic way to cause one: moq-net refuses it before reserving a group. #[test] fn a_rejected_write_moves_the_pad_to_error() { init(); diff --git a/rs/moq-hls/src/export/mod.rs b/rs/moq-hls/src/export/mod.rs index 143f1d1028a..5fffcb8bb71 100644 --- a/rs/moq-hls/src/export/mod.rs +++ b/rs/moq-hls/src/export/mod.rs @@ -2181,7 +2181,7 @@ mod tests { let consumer = origin.consume().with_stats( registry .tier(moq_net::stats::Tier::default()) - .session(moq_net::Path::from_static("viewer")), + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static("viewer"))), ); let bytes = || -> u64 { registry diff --git a/rs/moq-json/MIGRATE.md b/rs/moq-json/MIGRATE.md index 6e96c0c3eed..126c3ea39e9 100644 --- a/rs/moq-json/MIGRATE.md +++ b/rs/moq-json/MIGRATE.md @@ -26,10 +26,10 @@ A reader that set `delay.max` to replay a snapshot track's history or trail a pl ### Compression moves to the track `Compression`, every `Config::compression` field, the `with_compression` setters, `Error::Flate`, `Error::Desync`, and `stream::Decoder::reset` are gone, along with the moq-flate dependency. -Frames are plain JSON; set `compress: true` on the `moq_net::track::Info` you create the track with, and moq-net compresses each group on the wire and hands every reader plain frames. +Frames are plain JSON; set `compression: Compression::Deflate` on the `moq_net::track::Info` you create the track with, and moq-net compresses each group on the wire and hands every reader plain frames. Drop the `compression` field from your producer and consumer configs: a consumer reads a compressed track with no setting of its own. The stream and window consumer configs are now empty, kept for options to come. -Every frame is charged its JSON size against `moq_net::group::MAX_CACHE_BYTES`, as a compressed one already was. +Every frame is charged its JSON size against the 32 MiB group budget, as a compressed one already was. ### Groups roll on joiner demand diff --git a/rs/moq-json/examples/telemetry.rs b/rs/moq-json/examples/telemetry.rs index d319456742e..8047000f47a 100644 --- a/rs/moq-json/examples/telemetry.rs +++ b/rs/moq-json/examples/telemetry.rs @@ -4,7 +4,7 @@ //! Simulates a realistic device telemetry blob that ticks once per second: most of the document //! is static (identity, config, geo) while a handful of gauges and counters change each tick. This //! is exactly the shape `moq-json` targets. The bytes counted are the JSON frames a plain reader -//! sees; a [`compress`](moq_net::track::Info::compress)ed track shrinks them further on the wire. +//! sees; a [compressed](moq_net::track::Info::compression) track shrinks them further on the wire. //! //! Run with: `cargo run -p moq-json --example telemetry` @@ -79,7 +79,10 @@ fn telemetry(tick: u64) -> Value { fn track(compress: bool) -> moq_net::track::Producer { let info = moq_net::track::Info::default() .with_timescale(moq_net::Timescale::MILLI) - .with_compress(compress); + .with_compression(match compress { + true => moq_net::track::Compression::Deflate, + false => moq_net::track::Compression::None, + }); moq_net::broadcast::Info::new() .produce() .create_track("telemetry", info) diff --git a/rs/moq-json/src/lib.rs b/rs/moq-json/src/lib.rs index 77daab3fd41..c122f5be7ef 100644 --- a/rs/moq-json/src/lib.rs +++ b/rs/moq-json/src/lib.rs @@ -33,6 +33,10 @@ pub mod window; pub use crate::diff::{Diff, diff}; +/// The most a frame, or a group's frames together, may hold: 32 MiB, which moq-net's group cache +/// also holds, so a larger frame is refused before it is written. +pub(crate) const MAX_GROUP_BYTES: u64 = 32 * 1024 * 1024; + /// Errors produced while publishing or consuming JSON. #[derive(thiserror::Error, Debug, Clone)] #[non_exhaustive] diff --git a/rs/moq-json/src/snapshot/consumer.rs b/rs/moq-json/src/snapshot/consumer.rs index bcea338bfbf..777bdd83660 100644 --- a/rs/moq-json/src/snapshot/consumer.rs +++ b/rs/moq-json/src/snapshot/consumer.rs @@ -17,7 +17,7 @@ pub struct Config { /// Maximum bytes in a frame or the compact JSON of the reconstructed value. /// /// Unset, the group budget is the only bound: a group holds at most - /// [`MAX_CACHE_BYTES`](moq_net::group::MAX_CACHE_BYTES), compressed or not, so the + /// 32 MiB, compressed or not, so the /// reconstructed value costs no more than that. Set it to hold a smaller document, at the cost /// of re-measuring the value after every delta. pub max_size: Option, @@ -52,7 +52,7 @@ impl Consumer { /// Subscribes right away at [`Config::priority`] and a zero /// [`max`](moq_net::track::Delay::max) delay, with default preferences otherwise; no handle to that subscription leaves the /// consumer, so nothing can change its budget. A read waits until the subscription resolves, - /// and fails if it cannot. A [`compress`](moq_net::track::Info::compress)ed track reads the + /// and fails if it cannot. A [compressed](moq_net::track::Info::compression) track reads the /// same: moq-net inflates it. pub fn new(track: moq_net::track::Consumer, config: Config) -> Self { let subscription = moq_net::track::Subscription::default() @@ -224,12 +224,12 @@ mod timestamps { #[test] fn exact_timestamps_survive_reads() { - for compress in [false, true] { + for compression in [moq_net::track::Compression::None, moq_net::track::Compression::Deflate] { let scale = moq_net::Timescale::new(90_000).unwrap(); // Every state is read, superseded groups included, so they must stay fresh. let info = moq_net::track::Info::default() .with_timescale(scale) - .with_compress(compress) + .with_compression(compression) .with_max_age(None); let track = moq_net::broadcast::Info::new() .produce() @@ -276,7 +276,10 @@ mod timestamps { fn latest_advances_the_same_cursor_as_next() { let track = moq_net::broadcast::Info::new() .produce() - .create_track("data", moq_net::track::Info::default().with_compress(true)) + .create_track( + "data", + moq_net::track::Info::default().with_compression(moq_net::track::Compression::Deflate), + ) .unwrap(); let mut consumer = Consumer::::new(track.consume(), Default::default()); let mut producer = crate::snapshot::Producer::new(track, crate::snapshot::Config::default()); diff --git a/rs/moq-json/src/snapshot/encoder.rs b/rs/moq-json/src/snapshot/encoder.rs index 6c3a4112f02..8d5a7217b78 100644 --- a/rs/moq-json/src/snapshot/encoder.rs +++ b/rs/moq-json/src/snapshot/encoder.rs @@ -70,10 +70,10 @@ pub struct Config { /// /// A delta that would pass it rolls a fresh snapshot instead, and a snapshot past it is refused /// with [`FrameTooLarge`](moq_net::Error::FrameTooLarge). Lowering it lets a test reach the limit - /// without megabytes of JSON; a value above moq-net's cache limit is clamped to it, since moq-net - /// refuses a larger group anyway. + /// without megabytes of JSON; a value above 32 MiB, what moq-net's group cache holds, is clamped + /// to it. /// - /// Defaults to [`moq_net::group::MAX_CACHE_BYTES`]. + /// Defaults to 32 MiB. pub max_group_bytes: u64, } @@ -95,7 +95,7 @@ impl Default for Config { fn default() -> Self { Self { deltas: true, - max_group_bytes: moq_net::group::MAX_CACHE_BYTES, + max_group_bytes: crate::MAX_GROUP_BYTES, } } } @@ -241,7 +241,7 @@ impl Encoder { /// Create an encoder with a cold baseline, so the first [`update`](Self::update) is a snapshot. pub fn new(config: Config) -> Self { Self { - max_group_bytes: config.max_group_bytes.min(moq_net::group::MAX_CACHE_BYTES), + max_group_bytes: config.max_group_bytes.min(crate::MAX_GROUP_BYTES), config, last: None, scratch: RefCell::new(crate::diff::Scratch::memoized()), @@ -942,7 +942,7 @@ mod test { #[test] fn the_budget_is_clamped_to_the_cache_limit() { let encoder = Encoder::::new(Config::default().with_max_group_bytes(u64::MAX)); - assert_eq!(encoder.max_group_bytes, moq_net::group::MAX_CACHE_BYTES); + assert_eq!(encoder.max_group_bytes, crate::MAX_GROUP_BYTES); } /// A value whose serialization changes on every call, standing in for a `Serialize` impl backed by diff --git a/rs/moq-json/src/snapshot/mod.rs b/rs/moq-json/src/snapshot/mod.rs index df8d84266d4..306f13fb5fc 100644 --- a/rs/moq-json/src/snapshot/mod.rs +++ b/rs/moq-json/src/snapshot/mod.rs @@ -178,7 +178,7 @@ mod test { /// A compressed track. fn compressed() -> moq_net::track::Info { - moq_net::track::Info::default().with_compress(true) + moq_net::track::Info::default().with_compression(moq_net::track::Compression::Deflate) } fn producer(config: Config) -> (Producer, moq_net::track::Consumer) { @@ -437,7 +437,7 @@ mod test { producer.update(&json!({ "keep": true })).unwrap(); // Serializes past the group cache limit, so the frame cannot be published. - let oversized = json!({ "big": "x".repeat(moq_net::group::MAX_CACHE_BYTES as usize + 1) }); + let oversized = json!({ "big": "x".repeat(crate::MAX_GROUP_BYTES as usize + 1) }); assert!(producer.update(&oversized).is_err()); producer.finish().unwrap(); @@ -867,7 +867,7 @@ mod test { assert!(matches!( producer.mutate( |value| { - *value = json!({ "big": "x".repeat(moq_net::group::MAX_CACHE_BYTES as usize + 1) }); + *value = json!({ "big": "x".repeat(crate::MAX_GROUP_BYTES as usize + 1) }); }, None ), @@ -910,7 +910,7 @@ mod test { producer.update(&json!({ "keep": true })).unwrap(); let mut subscriber = track.subscribe(None).now_or_never().unwrap().unwrap().ordered(); - *producer.modify(None).unwrap() = json!({ "big": "x".repeat(moq_net::group::MAX_CACHE_BYTES as usize + 1) }); + *producer.modify(None).unwrap() = json!({ "big": "x".repeat(crate::MAX_GROUP_BYTES as usize + 1) }); // The publisher learns the cause at its next edit. The consumer drains the snapshot // that finished, then learns it from the aborted track. @@ -934,7 +934,7 @@ mod test { producer.update(&json!({ "keep": true })).unwrap(); let mut guard = producer.modify(None).unwrap(); - *guard = json!({ "big": "x".repeat(moq_net::group::MAX_CACHE_BYTES as usize + 1) }); + *guard = json!({ "big": "x".repeat(crate::MAX_GROUP_BYTES as usize + 1) }); assert!(matches!( guard.commit(), Err(crate::Error::Net(moq_net::Error::FrameTooLarge)) diff --git a/rs/moq-json/src/snapshot/producer.rs b/rs/moq-json/src/snapshot/producer.rs index 346a2103ca3..84fdb1a1b05 100644 --- a/rs/moq-json/src/snapshot/producer.rs +++ b/rs/moq-json/src/snapshot/producer.rs @@ -34,7 +34,7 @@ fn take(inner: &Mutex>) -> MutexGuard<'_, Inner> { /// it reaches the encoder's caps. Set the track's [`refresh`](moq_net::track::Info::refresh) ratio /// when creating it, or joins never ask. /// -/// Set [`compress`](moq_net::track::Info::compress) on that track's info too: JSON is small and +/// Set [`compression`](moq_net::track::Info::compression) on that track's info too: JSON is small and /// repetitive, and moq-net compresses each delta against the snapshot earlier in its group. /// /// Cheaply clonable: clones share one underlying track and publishing state, like other MoQ @@ -452,7 +452,7 @@ impl Track { // new one before the frame is written, so discovering the limit inside `write_frame` would // leave an empty newest group behind: a snapshot consumer jumps to the newest, so the previous // value would be lost even though this update reported an error. - if encoded.payload.len() as u64 > moq_net::group::MAX_CACHE_BYTES { + if encoded.payload.len() as u64 > crate::MAX_GROUP_BYTES { return Err(moq_net::Error::FrameTooLarge.into()); } diff --git a/rs/moq-json/src/stream/consumer.rs b/rs/moq-json/src/stream/consumer.rs index ec9976be16e..b1e7c5e6935 100644 --- a/rs/moq-json/src/stream/consumer.rs +++ b/rs/moq-json/src/stream/consumer.rs @@ -36,7 +36,7 @@ pub struct Consumer { impl Consumer { /// Create a consumer reading from the given track subscriber. /// - /// A [`compress`](moq_net::track::Info::compress)ed track reads the same: moq-net inflates it. + /// A [compressed](moq_net::track::Info::compression) track reads the same: moq-net inflates it. pub fn new(track: moq_net::track::Subscriber, config: Config) -> Self { Self { track, @@ -104,11 +104,11 @@ mod timestamps { #[test] fn exact_timestamps_survive_reads() { - for compress in [false, true] { + for compression in [moq_net::track::Compression::None, moq_net::track::Compression::Deflate] { let scale = moq_net::Timescale::new(90_000).unwrap(); let info = moq_net::track::Info::default() .with_timescale(scale) - .with_compress(compress); + .with_compression(compression); let track = moq_net::broadcast::Info::new() .produce() .create_track("data", info) diff --git a/rs/moq-json/src/stream/encoder.rs b/rs/moq-json/src/stream/encoder.rs index 8c9e1118c97..35970669463 100644 --- a/rs/moq-json/src/stream/encoder.rs +++ b/rs/moq-json/src/stream/encoder.rs @@ -59,7 +59,7 @@ impl Encoder { /// Create an encoder. pub fn new(_config: Config) -> Self { Self { - max_frame_bytes: moq_net::group::MAX_CACHE_BYTES, + max_frame_bytes: crate::MAX_GROUP_BYTES, _marker: PhantomData, } } @@ -72,7 +72,7 @@ impl Encoder { /// [`commit`](Pending::commit)s. /// /// Errors with [`moq_net::Error::FrameTooLarge`] if the record is larger than one frame may be - /// ([`moq_net::group::MAX_CACHE_BYTES`]). The refused record leaves the encoder untouched. + /// (32 MiB, what moq-net's group cache holds). The refused record leaves the encoder untouched. pub fn encode(&mut self, value: &T) -> Result> { let payload = Bytes::from(serde_json::to_vec(value)?); if payload.len() as u64 > self.max_frame_bytes { diff --git a/rs/moq-json/src/stream/mod.rs b/rs/moq-json/src/stream/mod.rs index ce6e399a493..afcc9602781 100644 --- a/rs/moq-json/src/stream/mod.rs +++ b/rs/moq-json/src/stream/mod.rs @@ -5,7 +5,7 @@ //! JSON object as one frame, and a [`Consumer`] yields every record in order. //! //! The whole log rides a **single group** that is never rolled: on a -//! [`compress`](moq_net::track::Info::compress)ed track, that one group is one DEFLATE window, so +//! [compressed](moq_net::track::Info::compression) track, that one group is one DEFLATE window, so //! every record compresses against all the earlier ones. There is deliberately no group rolling (and so no //! catch-up machinery): a moq-net group has no size cap. A caller that wants to bound the record rate throttles at //! the source (e.g. the timeline's segment cadence); a consumer that finds a gap can fetch or @@ -18,7 +18,7 @@ //! # Budget //! //! A log accepts appends for its track's life; only a record larger than one frame may be -//! ([`MAX_CACHE_BYTES`](moq_net::group::MAX_CACHE_BYTES), 32 MiB) is refused, with +//! (32 MiB) is refused, with //! [`moq_net::Error::FrameTooLarge`], before it is written. moq-net holds only the group's newest //! 32 MiB and sheds older records from its front, so a consumer that falls further behind, or //! joins after the front is shed, gets [`moq_net::Error::Evicted`]. @@ -147,7 +147,7 @@ mod test { /// A compressed track. fn compressed() -> moq_net::track::Info { - moq_net::track::Info::default().with_compress(true) + moq_net::track::Info::default().with_compression(moq_net::track::Compression::Deflate) } fn consume(track: moq_net::track::Subscriber) -> Consumer { @@ -179,7 +179,10 @@ mod test { /// Each record keeps its own capture time, and the returned size is the encoded frame. #[test] fn a_stamped_append_writes_its_capture_time() { - let (mut producer, _track) = producer_on(Config::default(), timed().with_compress(true)); + let (mut producer, _track) = producer_on( + Config::default(), + timed().with_compression(moq_net::track::Compression::Deflate), + ); let mut groups = producer.consume(); let captured = moq_net::Timestamp::from_millis(1_234).unwrap(); let record = json!({ "n": 1 }); @@ -412,8 +415,8 @@ mod test { )); } - fn info(compress: bool) -> moq_net::track::Info { - moq_net::track::Info::default().with_compress(compress) + fn info(compression: moq_net::track::Compression) -> moq_net::track::Info { + moq_net::track::Info::default().with_compression(compression) } fn refused(result: crate::Result) -> bool { @@ -427,13 +430,13 @@ mod test { /// the next record lands and decodes. #[test] fn an_oversized_record_is_refused_and_the_log_continues() { - for compression in [false, true] { + for compression in [moq_net::track::Compression::None, moq_net::track::Compression::Deflate] { let (mut producer, track) = producer_on(Config::default(), info(compression)); producer.set_max_frame_bytes(BUDGET); producer.append(&json!({ "n": 0 })).unwrap(); let oversized = Value::String("x".repeat(BUDGET as usize)); - assert!(refused(producer.append(&oversized)), "compression={compression}"); + assert!(refused(producer.append(&oversized)), "compression={compression:?}"); producer.append(&json!({ "n": 1 })).unwrap(); producer.finish().unwrap(); @@ -441,7 +444,7 @@ mod test { assert_eq!( drain(consume(track)), vec![json!({ "n": 0 }), json!({ "n": 1 })], - "compression={compression}" + "compression={compression:?}" ); } } @@ -449,7 +452,7 @@ mod test { /// A log has no budget: it carries more records than a group once could, and reads back whole. #[test] fn a_log_accepts_every_append() { - for compression in [false, true] { + for compression in [moq_net::track::Compression::None, moq_net::track::Compression::Deflate] { let (mut producer, track) = producer_on(Config::default(), info(compression)); for n in 0..10_000 { producer.append(&json!({ "n": n })).unwrap(); @@ -457,7 +460,7 @@ mod test { producer.finish().unwrap(); let records = drain(consume(track)); - assert_eq!(records.len(), 10_000, "compression={compression}"); + assert_eq!(records.len(), 10_000, "compression={compression:?}"); assert_eq!(records.last(), Some(&json!({ "n": 9_999 }))); } } diff --git a/rs/moq-json/src/window/encoder.rs b/rs/moq-json/src/window/encoder.rs index e43c113c7ca..a4e72318cc0 100644 --- a/rs/moq-json/src/window/encoder.rs +++ b/rs/moq-json/src/window/encoder.rs @@ -183,7 +183,7 @@ impl Encoder { start: 0, group_bytes: 0, group_frames: 0, - max_group_bytes: moq_net::group::MAX_CACHE_BYTES, + max_group_bytes: crate::MAX_GROUP_BYTES, resync: true, _marker: PhantomData, } diff --git a/rs/moq-json/src/window/mod.rs b/rs/moq-json/src/window/mod.rs index 27b572ac235..a58e16de5c4 100644 --- a/rs/moq-json/src/window/mod.rs +++ b/rs/moq-json/src/window/mod.rs @@ -21,7 +21,7 @@ //! //! Trimming is therefore an op, not a group boundary. Dropping a record costs one small frame //! instead of a roll that restates the whole window (and, on a -//! [`compress`](moq_net::track::Info::compress)ed track, throws away the group's DEFLATE window). +//! [compressed](moq_net::track::Info::compression) track, throws away the group's DEFLATE window). //! //! # Group boundaries are invisible //! @@ -806,7 +806,7 @@ mod test { fn compressed_round_trip_across_rolls() { let mut live = Live::on( ProducerConfig::default(), - moq_net::track::Info::default().with_compress(true), + moq_net::track::Info::default().with_compression(moq_net::track::Compression::Deflate), ); for n in 0..40 { live.push(n); diff --git a/rs/moq-mux/MIGRATE.md b/rs/moq-mux/MIGRATE.md index 3efaa0be233..9915ec0d513 100644 --- a/rs/moq-mux/MIGRATE.md +++ b/rs/moq-mux/MIGRATE.md @@ -114,9 +114,9 @@ Replace `consumer.set_max_delay(d)` with `consumer.set_delay(Delay::default().wi ### Compression moves to the track -`catalog.json.z` is gone: `catalog::Producer` publishes one `catalog.json` with `compress: true` (the MSF `catalog` stays uncompressed). +`catalog.json.z` is gone: `catalog::Producer` publishes one `catalog.json` with `Compression::Deflate` (the MSF `catalog` stays uncompressed). `CatalogFormat::HangZ` and `catalog::hang::Consumer::compressed` are removed; read `CatalogFormat::Hang` with `Consumer::new`, which reads a compressed track like a plain one. -`json::Config::compression` and `with_compression` are removed: create the track with `moq_net::track::Info::default().with_compress(true)` instead. `Error::UnsupportedCompression` and `Error::Flate` are gone with them. +`json::Config::compression` and `with_compression` are removed: create the track with `moq_net::track::Info::default().with_compression(moq_net::track::Compression::Deflate)` instead. `Error::UnsupportedCompression` and `Error::Flate` are gone with them. The `binary` module and `catalog::Producer::binary_snapshot` and `binary_stream` are deleted, along with the moq-flate dependency: publish opaque bytes on a plain track, or JSON through `json_snapshot` and `json_stream`. ### A decoder identity change publishes a new track ([#7110](https://github.com/moq-dev/moq/pull/7110)) diff --git a/rs/moq-mux/src/catalog/producer.rs b/rs/moq-mux/src/catalog/producer.rs index 7a0fa308224..63693a9a3fd 100644 --- a/rs/moq-mux/src/catalog/producer.rs +++ b/rs/moq-mux/src/catalog/producer.rs @@ -494,7 +494,7 @@ impl Producer { // priority. Leaving it at the default would rank a subscriber reading MSF // below every media track on a relay's upstream leg. It stays uncompressed: MSF is // read by other implementations, which hang's compression decisions don't cover. - let msf_info = hang::Catalog::default_track_info().with_compress(false); + let msf_info = hang::Catalog::default_track_info().with_compression(moq_net::track::Compression::None); let msf_track = broadcast.create_track(moq_msf::DEFAULT_NAME, msf_info)?; // Disable deltas for now to stay byte-compatible with consumers that only read snapshots. @@ -991,7 +991,7 @@ impl Producer { /// catalog entry and removes the entry when the returned handle drops. The catalog key is /// [`track.name()`](moq_net::track::Producer::name) verbatim. Create `track` with a /// [`timescale`](moq_net::track::Info::timescale), since every write is stamped on the - /// broadcast clock, and with [`compress`](moq_net::track::Info::compress) set: JSON is small and + /// broadcast clock, and with [`compression`](moq_net::track::Info::compression) set: JSON is small and /// repetitive. /// /// `config` is a [`json::Config`](crate::json::Config) for the `json` section, or an @@ -1823,8 +1823,16 @@ mod test { let mut catalog = Producer::new(&mut broadcast, Config::default()).unwrap(); let track = catalog.outputs.hang_track.consume(); - assert!(catalog.outputs.hang_track.info().compress, "catalog.json is compressed"); - assert!(!catalog.outputs.msf_track.info().compress, "the MSF catalog is not"); + assert_eq!( + catalog.outputs.hang_track.info().compression, + moq_net::track::Compression::Deflate, + "catalog.json is compressed" + ); + assert_eq!( + catalog.outputs.msf_track.info().compression, + moq_net::track::Compression::None, + "the MSF catalog is not" + ); let mut consumer = Consumer::new(track); { @@ -1912,7 +1920,7 @@ mod test { catalog .modify() .unwrap() - .set_section("big", "x".repeat(moq_net::group::MAX_CACHE_BYTES as usize + 1).into()) + .set_section("big", "x".repeat(crate::jitter::MAX_BYTES + 1).into()) .unwrap(); assert!(matches!( @@ -1941,7 +1949,7 @@ mod test { let mut guard = catalog.modify().unwrap(); guard - .set_section("big", "x".repeat(moq_net::group::MAX_CACHE_BYTES as usize + 1).into()) + .set_section("big", "x".repeat(crate::jitter::MAX_BYTES + 1).into()) .unwrap(); assert!(matches!( guard.commit(), diff --git a/rs/moq-mux/src/catalog/tracks.rs b/rs/moq-mux/src/catalog/tracks.rs index 08948b54c90..f81989d6bab 100644 --- a/rs/moq-mux/src/catalog/tracks.rs +++ b/rs/moq-mux/src/catalog/tracks.rs @@ -73,7 +73,7 @@ use super::hang::{Catalog, CatalogExt}; /// # ) -> moq_mux::Result<()> { /// let info = moq_net::track::Info::default() /// .with_timescale(moq_net::Timescale::MILLI) -/// .with_compress(true); +/// .with_compression(moq_net::track::Compression::Deflate); /// let track = broadcast.create_track("telemetry", info)?; /// // The producer fixes the mode, so the one passed here is only a placeholder. /// let entry = Mavlink { config: JsonConfig::new(Mode::Stream), sysid: 1 }; diff --git a/rs/moq-mux/src/container/consumer.rs b/rs/moq-mux/src/container/consumer.rs index fbfd63b514c..9ef9afaf467 100644 --- a/rs/moq-mux/src/container/consumer.rs +++ b/rs/moq-mux/src/container/consumer.rs @@ -219,7 +219,7 @@ pub struct Consumer { const CONTIGUITY_TOLERANCE: std::time::Duration = std::time::Duration::from_millis(1); /// The default decoded-byte cap: one group at the transport's size cap. -pub(crate) const DEFAULT_MAX_BUFFER: usize = moq_net::group::MAX_CACHE_BYTES as usize; +pub(crate) const DEFAULT_MAX_BUFFER: usize = 32 * 1024 * 1024; /// The decoded bytes a consumer's groups hold, shared with each group so one dropped by any path /// refunds what it held. diff --git a/rs/moq-mux/src/container/fmp4/import.rs b/rs/moq-mux/src/container/fmp4/import.rs index 415cb90b3bf..c4501c690c9 100644 --- a/rs/moq-mux/src/container/fmp4/import.rs +++ b/rs/moq-mux/src/container/fmp4/import.rs @@ -357,7 +357,7 @@ impl Import { /// /// Media samples stream into their frames as bytes arrive. What must be held whole is /// bounded: a `moov` or `moof` body larger than 2 MiB, or a text sample larger than the - /// transport's per-group bound ([`MAX_CACHE_BYTES`](moq_net::group::MAX_CACHE_BYTES)), is + /// transport's 32 MiB frame bound, is /// refused before it is held. A `moof` declaring more than 131,072 samples, or more than its /// size accepts, is refused before they are planned, and a `moov` declaring more than 256 /// tracks before any is created. diff --git a/rs/moq-mux/src/container/fmp4/mod.rs b/rs/moq-mux/src/container/fmp4/mod.rs index c545ea96e47..682c5a48651 100644 --- a/rs/moq-mux/src/container/fmp4/mod.rs +++ b/rs/moq-mux/src/container/fmp4/mod.rs @@ -28,10 +28,10 @@ pub use mp4_atom; /// The largest text sample [`Import`] holds whole. /// /// A text sample is rewritten only once its last byte arrives, so a larger one is refused before -/// any of it is staged. It matches the transport's per-group bound, -/// [`MAX_CACHE_BYTES`](moq_net::group::MAX_CACHE_BYTES), which the rewritten sample must fit. +/// any of it is staged. It matches moq-net's 32 MiB frame bound, +/// which the rewritten sample must fit. /// Media samples stream into their frames and have no such bound. -const MAX_HELD_BYTES: usize = moq_net::group::MAX_CACHE_BYTES as usize; +const MAX_HELD_BYTES: usize = 32 * 1024 * 1024; /// The largest metadata box body parsed on import or from received CMAF. /// @@ -240,8 +240,8 @@ pub enum Error { size: usize, }, - /// A text sample is rewritten whole, so one larger than the transport's per-group bound, - /// [`MAX_CACHE_BYTES`](moq_net::group::MAX_CACHE_BYTES), is refused before any of its bytes + /// A text sample is rewritten whole, so one larger than moq-net's 32 MiB frame bound + /// is refused before any of its bytes /// are staged. #[error("text sample of {0} bytes is more than the {MAX_HELD_BYTES} an importer holds")] TextSampleTooLarge(usize), diff --git a/rs/moq-mux/src/container/test_util.rs b/rs/moq-mux/src/container/test_util.rs index 2d217cc286e..999be4ae78e 100644 --- a/rs/moq-mux/src/container/test_util.rs +++ b/rs/moq-mux/src/container/test_util.rs @@ -357,7 +357,7 @@ impl Link { // `from` may be a middle hop, so it forwards what it learned as well as its own. let client = moq_net::Client::new() .with_versions(version.into()) - .with_publisher(from.consume().with_proxy(true)); + .with_publisher(from.clone().with_proxy(true).consume()); let server = moq_net::Server::new() .with_versions(version.into()) .with_subscriber(to.clone()); @@ -409,7 +409,7 @@ impl Link { .with_subscriber(to.clone()); let server = moq_net::Server::new() .with_versions(version.into()) - .with_publisher(from.consume().with_proxy(true)); + .with_publisher(from.clone().with_proxy(true).consume()); let sessions = tokio::join!( async { let (session, driver) = client diff --git a/rs/moq-mux/src/fuzz.rs b/rs/moq-mux/src/fuzz.rs index ad62ec7842c..cbec409c6c4 100644 --- a/rs/moq-mux/src/fuzz.rs +++ b/rs/moq-mux/src/fuzz.rs @@ -194,7 +194,7 @@ pub fn catalog(data: &[u8]) -> bool { moq_msf::DEFAULT_NAME }; // Uncompressed: inflating a compressed group is moq-net's, ahead of any catalog parser. - let info = hang::Catalog::default_track_info().with_compress(false); + let info = hang::Catalog::default_track_info().with_compression(moq_net::track::Compression::None); let track = broadcast .create_track(name, info) .expect("a fresh broadcast has no catalog"); diff --git a/rs/moq-mux/src/jitter.rs b/rs/moq-mux/src/jitter.rs index 00209a8c89d..fa4ab6547b1 100644 --- a/rs/moq-mux/src/jitter.rs +++ b/rs/moq-mux/src/jitter.rs @@ -12,7 +12,7 @@ use moq_net::Timestamp; /// What each track may hold before its reader is held back, as the container consumer's max /// buffer: the most one group may cache. -pub(crate) const MAX_BYTES: usize = moq_net::group::MAX_CACHE_BYTES as usize; +pub(crate) const MAX_BYTES: usize = 32 * 1024 * 1024; /// One active publisher and at most one independently acquiring replacement. /// Ordinary timeline jumps stay entirely inside each existing clock engine. diff --git a/rs/moq-mux/src/json.rs b/rs/moq-mux/src/json.rs index b32a1a34229..387f1d07e11 100644 --- a/rs/moq-mux/src/json.rs +++ b/rs/moq-mux/src/json.rs @@ -23,7 +23,7 @@ //! // A timed track, since every write is stamped. JSON is small and repetitive, so compress it. //! let info = moq_net::track::Info::default() //! .with_timescale(moq_net::Timescale::MILLI) -//! .with_compress(true); +//! .with_compression(moq_net::track::Compression::Deflate); //! let track = broadcast.create_track("chat", info)?; //! let mut chat = catalog.json_stream::(track, moq_mux::json::Config::default())?; //! chat.append(&Message { text: "hello".to_string() }, catalog.clock().now())?; @@ -520,7 +520,9 @@ mod test { /// Create the moq-net track a data producer publishes on, as a caller does for a media track. fn track(broadcast: &mut moq_net::broadcast::Producer, name: &str) -> moq_net::track::Producer { - broadcast.create_track(name, timed().with_compress(true)).unwrap() + broadcast + .create_track(name, timed().with_compression(moq_net::track::Compression::Deflate)) + .unwrap() } fn entry(catalog: &crate::catalog::Producer, name: &str) -> JsonConfig { @@ -917,7 +919,7 @@ mod test { let entry = entry(&catalog, "chat"); let consumer = read(broadcast.consume().track("chat").unwrap(), &entry).unwrap(); - let oversized = Value::String("x".repeat(moq_net::group::MAX_CACHE_BYTES as usize)); + let oversized = Value::String("x".repeat(crate::jitter::MAX_BYTES)); assert!(matches!( chat.append(&oversized, catalog.clock().now()), Err(crate::Error::Json(moq_json::Error::Net(moq_net::Error::FrameTooLarge))) diff --git a/rs/moq-net-tests/tests/integration/hop_limit.rs b/rs/moq-net-tests/tests/integration/hop_limit.rs index 8c36f23ec50..5c6b120d42e 100644 --- a/rs/moq-net-tests/tests/integration/hop_limit.rs +++ b/rs/moq-net-tests/tests/integration/hop_limit.rs @@ -18,7 +18,7 @@ fn produce_origin(hop: u64) -> origin::Producer { config.pool = cache::Pool::unbounded(); let (producer, driver) = origin::Producer::new(config); spawn(driver); - producer + producer.with_proxy(true) } /// Land a peer's route at `path` on `origin`, as its session does. @@ -46,6 +46,7 @@ async fn hop_limit_bounds_receive_and_send() { config.pool = cache::Pool::unbounded(); let (relay, driver) = origin::Producer::new(config); spawn(driver); + let relay = relay.with_proxy(true); let sink = produce_origin(3); let _upstream = peer(version, &source, &relay).await; let _downstream = peer(version, &relay, &sink).await; @@ -106,6 +107,7 @@ async fn hop_limit_falls_back_to_a_forwardable_route() { config.pool = cache::Pool::unbounded(); let (relay, driver) = origin::Producer::new(config); spawn(driver); + let relay = relay.with_proxy(true); let sink = produce_origin(3); let _near = peer(version, &near, &relay).await; let _far = peer(version, &far, &relay).await; diff --git a/rs/moq-net-tests/tests/integration/ietf_conformance.rs b/rs/moq-net-tests/tests/integration/ietf_conformance.rs index cd9cb6c9ac4..abe6d9100c3 100644 --- a/rs/moq-net-tests/tests/integration/ietf_conformance.rs +++ b/rs/moq-net-tests/tests/integration/ietf_conformance.rs @@ -14,7 +14,7 @@ const NAMESPACE: &str = "moq-test-00/0/0/0/1/2/2/1024/100/50/1/1/1/-1/-1/0"; fn origin(hop: u64) -> origin::Producer { let (producer, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); spawn(driver); - producer + producer.with_proxy(true) } async fn routing(version: &str, cluster: bool) { diff --git a/rs/moq-net-tests/tests/integration/refresh.rs b/rs/moq-net-tests/tests/integration/refresh.rs index c22b9b44794..58e4ae1e089 100644 --- a/rs/moq-net-tests/tests/integration/refresh.rs +++ b/rs/moq-net-tests/tests/integration/refresh.rs @@ -6,7 +6,7 @@ use std::time::Duration; fn origin(hop: u64) -> origin::Producer { let (origin, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); spawn(driver); - origin + origin.with_proxy(true) } /// The JSON owner answers demand across a publisher link, a cluster peer, and a reader link. diff --git a/rs/moq-net-tests/tests/integration/restart.rs b/rs/moq-net-tests/tests/integration/restart.rs index 3dcd2cfffd3..4f935b86e2b 100644 --- a/rs/moq-net-tests/tests/integration/restart.rs +++ b/rs/moq-net-tests/tests/integration/restart.rs @@ -26,7 +26,7 @@ const TEST_TIMEOUT: Duration = Duration::from_secs(60); fn produce_origin(hop: u64) -> origin::Producer { let (producer, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } /// Have `to` pull everything `from` publishes. diff --git a/rs/moq-net-tests/tests/integration/serve.rs b/rs/moq-net-tests/tests/integration/serve.rs index 053f91db9f2..2b80da415d7 100644 --- a/rs/moq-net-tests/tests/integration/serve.rs +++ b/rs/moq-net-tests/tests/integration/serve.rs @@ -9,7 +9,7 @@ use crate::support::harness::{MockConnectOptions, connect_mock, spawn}; fn origin(hop: u64) -> origin::Producer { let (origin, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); spawn(driver); - origin + origin.with_proxy(true) } async fn first_subscribe(version: &str, publish: bool) { diff --git a/rs/moq-net/benches/group.rs b/rs/moq-net/benches/group.rs index f5a69718588..f58f998fab3 100644 --- a/rs/moq-net/benches/group.rs +++ b/rs/moq-net/benches/group.rs @@ -489,7 +489,9 @@ fn bench_inflate(c: &mut Criterion) { b.iter_batched( || { let broadcast = broadcast::Producer::new(broadcast::Info::default()); - let track = broadcast.create_track("bench", timed().with_compress(true)).unwrap(); + let track = broadcast + .create_track("bench", timed().with_compression(moq_net::track::Compression::Deflate)) + .unwrap(); let consumers: Vec = (0..groups) .flat_map(|_| { let mut group = track.append_group().unwrap(); @@ -534,7 +536,10 @@ fn bench_compressed_updates(c: &mut Criterion) { let producers: Vec<_> = (0..tracks) .map(|i| { let track = broadcast - .create_track(format!("bench{i}"), track::Info::default().with_compress(true)) + .create_track( + format!("bench{i}"), + track::Info::default().with_compression(moq_net::track::Compression::Deflate), + ) .unwrap(); let mut group = track.append_group().unwrap(); group.write_frame(None, payload.clone()).unwrap(); diff --git a/rs/moq-net/benches/origin.rs b/rs/moq-net/benches/origin.rs index 3784a59ee51..f488eea1cf5 100644 --- a/rs/moq-net/benches/origin.rs +++ b/rs/moq-net/benches/origin.rs @@ -1259,10 +1259,9 @@ fn runtime() -> tokio::runtime::Runtime { /// Everything under `room/`, which leaves out only the `muted` subscription. fn room() -> auth::Grant { - auth::Grant { - subscribe: Pattern::subtree("room").unwrap().into(), - ..auth::Grant::all() - } + let mut grant = auth::Grant::all(); + grant.subscribe = Pattern::subtree("room").unwrap().into(); + grant } /// Steady-state delivery through a session's gates: one round across every diff --git a/rs/moq-net/benches/session/mod.rs b/rs/moq-net/benches/session/mod.rs index 37d276eed3e..d943ef5d156 100644 --- a/rs/moq-net/benches/session/mod.rs +++ b/rs/moq-net/benches/session/mod.rs @@ -661,7 +661,13 @@ impl Cluster { this.tracks.push( broadcast .broadcast() - .create_track(TRACK, timed().with_compress(shape.compress)) + .create_track( + TRACK, + timed().with_compression(match shape.compress { + true => moq_net::track::Compression::Deflate, + false => moq_net::track::Compression::None, + }), + ) .unwrap(), ); if shape.datagrams { diff --git a/rs/moq-net/benches/stats.rs b/rs/moq-net/benches/stats.rs index 1369af72ede..a1e3fc89c0d 100644 --- a/rs/moq-net/benches/stats.rs +++ b/rs/moq-net/benches/stats.rs @@ -34,7 +34,7 @@ fn registry(broadcasts: usize, tiers: usize) -> Registry { .map(|t| { let session = registry .tier(stats::Tier::new(moq_net::Path::new(&format!("tier{t}")).unwrap())) - .session(moq_net::Path::from_static("root")); + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static("root"))); let mut cursor = producer.consume().with_stats(session).routes(); // Each announce the cursor replays records under its tier. while cursor.next().now_or_never().flatten().is_some() {} @@ -54,7 +54,7 @@ fn report(c: &mut Criterion) { for (broadcasts, tiers) in SHAPES { let fixture = registry(broadcasts, tiers); let mut report = stats::Report::default(); - fixture.registry.report(&mut report); + fixture.registry.report(&mut report, moq_net::time::Instant::now()); assert_eq!( report.traffic.len(), broadcasts * tiers, @@ -64,7 +64,7 @@ fn report(c: &mut Criterion) { group.bench_with_input( BenchmarkId::from_parameter(format!("{broadcasts}x{tiers}")), &fixture, - |b, fixture| b.iter(|| fixture.registry.report(&mut report)), + |b, fixture| b.iter(|| fixture.registry.report(&mut report, moq_net::time::Instant::now())), ); } group.finish(); @@ -115,8 +115,11 @@ fn session_report(c: &mut Criterion) { let contexts: Vec<_> = (0..labels) .flat_map(|label| { let handle = handle.clone(); - (0..sessions) - .map(move |_| handle.session(moq_net::Path::new(&format!("project/key/{label}")).unwrap())) + (0..sessions).map(move |_| { + handle.session(moq_net::stats::SessionInfo::new( + moq_net::Path::new(&format!("project/key/{label}")).unwrap(), + )) + }) }) .collect(); let wires: Vec<_> = contexts @@ -131,7 +134,7 @@ fn session_report(c: &mut Criterion) { }) .collect(); let mut report = stats::Report::default(); - registry.report(&mut report); + registry.report(&mut report, moq_net::time::Instant::now()); assert_eq!(report.sessions.len(), labels); for row in &report.sessions { assert_eq!(row.presence.sessions_started, sessions as u64); @@ -141,7 +144,7 @@ fn session_report(c: &mut Criterion) { group.throughput(Throughput::Elements((labels * sessions) as u64)); group.bench_function( BenchmarkId::from_parameter(format!("{labels}x{sessions}/connections={connections}")), - |b| b.iter(|| registry.report(&mut report)), + |b| b.iter(|| registry.report(&mut report, moq_net::time::Instant::now())), ); std::hint::black_box((contexts, wires)); } @@ -162,8 +165,11 @@ fn retag(c: &mut Criterion) { let mut contexts: Vec<_> = (0..labels) .flat_map(|label| { let handle = handle.clone(); - (0..sessions) - .map(move |_| handle.session(moq_net::Path::new(&format!("project/key/{label}")).unwrap())) + (0..sessions).map(move |_| { + handle.session(moq_net::stats::SessionInfo::new( + moq_net::Path::new(&format!("project/key/{label}")).unwrap(), + )) + }) }) .collect(); let moving = contexts.split_off(contexts.len() - sessions); diff --git a/rs/moq-net/src/auth.rs b/rs/moq-net/src/auth.rs index 854480d449f..849eed6a5af 100644 --- a/rs/moq-net/src/auth.rs +++ b/rs/moq-net/src/auth.rs @@ -85,8 +85,10 @@ pub(crate) enum Answer { /// What a peer lets this side do, in this side's own paths. /// /// The paths are relative to the session's root, the same paths the session -/// announces and subscribes with. `Grant::default()` grants nothing. +/// announces and subscribes with. `Grant::default()` grants nothing; set the +/// fields on it to grant more. #[derive(Clone, Debug, Default, PartialEq, Eq)] +#[non_exhaustive] pub struct Grant { /// The broadcasts this side may publish to the peer. pub publish: Patterns, diff --git a/rs/moq-net/src/client.rs b/rs/moq-net/src/client.rs index cd5402e86d7..6f60cc4f4df 100644 --- a/rs/moq-net/src/client.rs +++ b/rs/moq-net/src/client.rs @@ -1211,7 +1211,11 @@ mod tests { let fake = FakeSession::new(Some(ALPN_LITE_04), Vec::new()); let client = Client::new() .with_versions(Version::Lite(lite::Version::Lite04).into()) - .with_stats(registry.tier(Tier::default()).session(crate::Path::from_static("root"))); + .with_stats( + registry + .tier(Tier::default()) + .session(crate::stats::SessionInfo::new(crate::Path::from_static("root"))), + ); let runtime = crate::time::Deadlines::new(crate::time::Instant::now()); let (session, mut driver) = futures::executor::block_on(client.connect(runtime.now(), fake)).unwrap(); session.abort(abort); @@ -1243,7 +1247,11 @@ mod tests { let registry = Registry::new(Default::default()); let client = Client::new() .with_versions(Version::Lite(lite::Version::Lite04).into()) - .with_stats(registry.tier(Tier::default()).session(crate::Path::from_static("root"))); + .with_stats( + registry + .tier(Tier::default()) + .session(crate::stats::SessionInfo::new(crate::Path::from_static("root"))), + ); let runtime = crate::time::Deadlines::new(crate::time::Instant::now()); let task = Transport::new(FakeSession::new(Some(ALPN_LITE_04), Vec::new())); let (session, mut driver) = diff --git a/rs/moq-net/src/coding/reader.rs b/rs/moq-net/src/coding/reader.rs index c4e343f17df..3c8526bbc53 100644 --- a/rs/moq-net/src/coding/reader.rs +++ b/rs/moq-net/src/coding/reader.rs @@ -603,7 +603,9 @@ mod tests { stats::{Message, Registry, Tier, Totals}, }; let registry = Registry::new(Default::default()); - let session = registry.tier(Tier::default()).session(crate::Path::from_static("")); + let session = registry + .tier(Tier::default()) + .session(crate::stats::SessionInfo::new(crate::Path::from_static(""))); let version = lite::Version::Lite07; let msg = lite::Probe { bitrate: Some(123), diff --git a/rs/moq-net/src/coding/writer.rs b/rs/moq-net/src/coding/writer.rs index 71591b52578..c6de21f4b79 100644 --- a/rs/moq-net/src/coding/writer.rs +++ b/rs/moq-net/src/coding/writer.rs @@ -483,7 +483,7 @@ mod tests { let stats = Registry::new(Default::default()); let session = stats .tier(Tier::new(crate::Path::from_static("internal"))) - .session(crate::Path::from_static("")); + .session(crate::stats::SessionInfo::new(crate::Path::from_static(""))); let gate = kio::Producer::new(false); let mut writer = Writer::new(SinkSend::gated(Log::default(), gate.consume()), lite::Version::Lite07).with_stats(&session); diff --git a/rs/moq-net/src/error.rs b/rs/moq-net/src/error.rs index beb30d536d8..6ccebe836df 100644 --- a/rs/moq-net/src/error.rs +++ b/rs/moq-net/src/error.rs @@ -485,7 +485,7 @@ pub enum Error { /// A write could not make room in the group even by shedding its front: what is left, /// such as the frame in flight, already fills the live tail - /// ([`MAX_CACHE_BYTES`](crate::group::MAX_CACHE_BYTES)). The write is refused and the + /// (32 MiB). The write is refused and the /// group is aborted. #[error("group too large")] GroupTooLarge, diff --git a/rs/moq-net/src/fuzz.rs b/rs/moq-net/src/fuzz.rs index 1dcd4ff6cae..09964b4de94 100644 --- a/rs/moq-net/src/fuzz.rs +++ b/rs/moq-net/src/fuzz.rs @@ -572,7 +572,9 @@ impl Meter { /// Build a session-local payload meter without exposing the model's private stats carriers. pub fn session_meter(registry: &crate::stats::Registry, tier: crate::stats::Tier, label: &str, path: &str) -> Meter { - let session = registry.tier(tier).session(Path::new(label).expect("label fits")); + let session = registry + .tier(tier) + .session(crate::stats::SessionInfo::new(Path::new(label).expect("label fits"))); Meter(session.egress(Path::new(path).expect("path fits")).meter()) } @@ -944,7 +946,7 @@ impl Default for Messages { priority: 1, max_age: Some(Duration::from_secs(10)), timescale: Some(crate::Timescale::MICRO), - compress: false, + compression: crate::track::Compression::None, }, lite_group: lite::Group { subscribe: 7, @@ -1963,15 +1965,17 @@ mod tests { let (origin, driver) = crate::origin::Producer::new(crate::origin::Config::default()); let _driver = driver; let tier = crate::stats::Tier::new(crate::Path::from_static("t")); - let session = registry.tier(tier.clone()).session(crate::Path::from_static("root")); + let session = registry + .tier(tier.clone()) + .session(crate::stats::SessionInfo::new(crate::Path::from_static("root"))); let _broadcast = origin.route("room/1", crate::origin::RouteOptions::default()).unwrap(); let mut cursor = origin.consume().with_stats(session).routes(); while cursor.next().now_or_never().flatten().is_some() {} bump_publisher_bytes(®istry, crate::Path::from_static("room/1"), &tier, 5); let mut report = crate::stats::Report::default(); - registry.report(&mut report); - registry.report(&mut report); + registry.report(&mut report, crate::time::Instant::now()); + registry.report(&mut report, crate::time::Instant::now()); let entry = report .traffic .iter() diff --git a/rs/moq-net/src/fuzz/ingest.rs b/rs/moq-net/src/fuzz/ingest.rs index f45a8d9ec04..95b3de2027a 100644 --- a/rs/moq-net/src/fuzz/ingest.rs +++ b/rs/moq-net/src/fuzz/ingest.rs @@ -60,7 +60,9 @@ fn track_info(timed: bool, compress: bool, draft: Option) -> trac if timed { info = info.with_timescale(Timescale::MILLI); } - info.compress = compress; + if compress { + info.compression = crate::track::Compression::Deflate; + } info.properties = draft.map(|version| { std::sync::Arc::new(TrackProperties { version, @@ -137,7 +139,7 @@ fn check(session: Session, info: &track::Info, body: &[u8], ingested: &Ingested) ); assert_eq!( frame.inflated.is_some(), - info.compress, + info.compressed(), "frame {index} lost its inflated size" ); let id = frame.fields.as_ref().map_or(index as u64, |(id, _)| *id); @@ -219,7 +221,7 @@ fn run(session: Session, info: &track::Info, body: &[u8], chunk: usize) -> Optio let mut reader = reader(Bytes::copy_from_slice(body), chunk, version); let producer = track.append_group().ok()?; let consumer = producer.consume(); - let mut viewer = stored(producer.consume(), info.compress); + let mut viewer = stored(producer.consume(), info.compressed()); let mut group = crate::recv::Group::new(producer); let framing = lite::Framing::new(info, version); let mut ingest = lite::FrameIngest::new(framing, records, frame_start); @@ -250,7 +252,7 @@ fn run(session: Session, info: &track::Info, body: &[u8], chunk: usize) -> Optio }) .ok()?; let consumer = producer.consume(); - let mut viewer = stored(producer.consume(), info.compress); + let mut viewer = stored(producer.consume(), info.compressed()); let mut group = crate::recv::Group::new(producer); let mut ingest = ietf::GroupIngest::new(version, &header, info.timescale); let end = drive(body.len(), |waiter| { @@ -274,7 +276,7 @@ fn run(session: Session, info: &track::Info, body: &[u8], chunk: usize) -> Optio } Some(Ingested { - frames: read(consumer, info.compress), + frames: read(consumer, info.compressed()), end: end.map_err(|err| err.to_string()), }) } diff --git a/rs/moq-net/src/ietf/object.rs b/rs/moq-net/src/ietf/object.rs index e16164882de..f88d6f3a015 100644 --- a/rs/moq-net/src/ietf/object.rs +++ b/rs/moq-net/src/ietf/object.rs @@ -794,7 +794,10 @@ mod compression_tests { fn inflated_size_is_admitted_before_any_inflate() { let broadcast = crate::broadcast::Info::default().produce(); let track = broadcast - .create_track("data", crate::track::Info::default().with_compress(true)) + .create_track( + "data", + crate::track::Info::default().with_compression(crate::track::Compression::Deflate), + ) .unwrap(); let group = track.append_group().unwrap(); let header = crate::frame::Header { diff --git a/rs/moq-net/src/ietf/properties.rs b/rs/moq-net/src/ietf/properties.rs index 838f6cc68c1..6a11f9f41a5 100644 --- a/rs/moq-net/src/ietf/properties.rs +++ b/rs/moq-net/src/ietf/properties.rs @@ -92,7 +92,7 @@ impl Properties { group_order: Some(GroupOrder::Descending), // A track opted in to refresh answers a NEW_GROUP_REQUEST as a join. dynamic_groups: info.refresh.is_some(), - compress: info.compress, + compress: info.compressed(), unknown: Vec::new(), } } diff --git a/rs/moq-net/src/ietf/publisher.rs b/rs/moq-net/src/ietf/publisher.rs index daab6e47e9d..c83c934ff01 100644 --- a/rs/moq-net/src/ietf/publisher.rs +++ b/rs/moq-net/src/ietf/publisher.rs @@ -89,10 +89,12 @@ fn track_properties( version: Version, negotiated: bool, ) -> Result { - let compressed = info.compress && negotiated; + let compressed = info.compressed() && negotiated; super::flate::egress(info, compressed)?; let mut plain = info.clone(); - plain.compress = compressed; + if !compressed { + plain.compression = crate::track::Compression::None; + } let info = &plain; if !wanted { return Ok(ietf::Properties::default()); @@ -6532,7 +6534,7 @@ impl TrackServe { } fn compression(mut self, negotiated: bool) -> Self { - self.compression = negotiated && self.track.info().compress; + self.compression = negotiated && self.track.info().compressed(); self } @@ -21451,7 +21453,7 @@ mod compression_tests { encoder.varint(super::super::flate::COMPRESSION).unwrap(); encoder.varint(1).unwrap(); let info = track::Info { - compress: true, + compression: crate::track::Compression::Deflate, properties: Some(Arc::new(crate::model::object::TrackProperties { version, values: vec![crate::model::object::Property { @@ -21472,7 +21474,7 @@ mod compression_tests { assert!(decoded.compress); assert_eq!(decoded.unknown, outgoing.unknown); let mut contradiction = info.clone(); - contradiction.compress = false; + contradiction.compression = crate::track::Compression::None; assert!( contradiction .properties @@ -21487,7 +21489,7 @@ mod compression_tests { Err(Error::Unsupported) )); } - let plain = track::Info::default().with_compress(true); + let plain = track::Info::default().with_compression(crate::track::Compression::Deflate); assert!(!track_properties(&plain, true, version, false).unwrap().compress); } } @@ -21509,7 +21511,7 @@ mod compression_tests { let track = track::Producer::new( Arc::new(crate::broadcast::Info::default()), "data", - track::Info::timed().with_compress(true), + track::Info::timed().with_compression(crate::track::Compression::Deflate), ); let subscriber = track.subscribe(None); let frames = [vec![b'a'; 1024], vec![b'b'; 1024], Vec::new()]; diff --git a/rs/moq-net/src/ietf/request_stream.rs b/rs/moq-net/src/ietf/request_stream.rs index a9c97865835..83f3083edd0 100644 --- a/rs/moq-net/src/ietf/request_stream.rs +++ b/rs/moq-net/src/ietf/request_stream.rs @@ -514,7 +514,9 @@ mod tests { use crate::lite::test_transport::ScriptedSession; use crate::stats::{Message, Registry, Tier}; let registry = Registry::new(Default::default()); - let stats = registry.tier(Tier::default()).session(crate::Path::from_static("")); + let stats = registry + .tier(Tier::default()) + .session(crate::stats::SessionInfo::new(crate::Path::from_static(""))); let version = Version::Draft22; let session = ScriptedSession::new(vec![0x10, 0, 2, 0, 0, 0x07, 0, 0]); let mut stream = Stream::open(&crate::driver::Transport::new(session.clone()), version) diff --git a/rs/moq-net/src/ietf/subscriber.rs b/rs/moq-net/src/ietf/subscriber.rs index 1da3ff9fa20..9591d5c95bb 100644 --- a/rs/moq-net/src/ietf/subscriber.rs +++ b/rs/moq-net/src/ietf/subscriber.rs @@ -774,7 +774,10 @@ impl Target { /// metadata differs. A sealed TIMESCALE travels downstream unchanged, so it must too. fn accepted_info(properties: &ietf::Properties, version: Version) -> track::Info { let mut info = track::Info::default() - .with_compress(properties.compress) + .with_compression(match properties.compress { + true => crate::track::Compression::Deflate, + false => crate::track::Compression::None, + }) .with_timescale(properties.timescale) .with_max_age(properties.max_cache_duration) // A track without the property gets the default. @@ -19671,7 +19674,7 @@ mod compression_negotiation_tests { assert!(refused(&properties, version, true).is_none(), "{version}"); } let info = accepted_info(&properties, Version::Draft22); - assert!(info.compress); + assert_eq!(info.compression, crate::track::Compression::Deflate); assert!(info.properties.unwrap().values.is_empty()); } } diff --git a/rs/moq-net/src/lite/ietf.rs b/rs/moq-net/src/lite/ietf.rs index b247d0e3559..6d18d27a276 100644 --- a/rs/moq-net/src/lite/ietf.rs +++ b/rs/moq-net/src/lite/ietf.rs @@ -1202,11 +1202,11 @@ mod hop_tests { let broadcast = upstream.route("room", crate::origin::RouteOptions::default()).unwrap(); let info = track::Info::timed() .with_timescale(Timescale::MILLI) - .with_compress(true); + .with_compression(crate::track::Compression::Deflate); let track = broadcast.broadcast().create_track("video", info).unwrap(); let (downstream, sessions) = test_hop(&upstream, "room", [true, true]).await; let (_copy, mut subscriber) = subscribe(&downstream).await; - assert!(subscriber.info().compress); + assert_eq!(subscriber.info().compression, crate::track::Compression::Deflate); let payload = |n: u8| vec![n; 300]; let mut group = track.append_group().unwrap(); diff --git a/rs/moq-net/src/lite/publisher.rs b/rs/moq-net/src/lite/publisher.rs index 271dc6d4e4d..65f3f29e1a2 100644 --- a/rs/moq-net/src/lite/publisher.rs +++ b/rs/moq-net/src/lite/publisher.rs @@ -2179,7 +2179,7 @@ impl Request for TrackInfoServe { priority: info.priority, max_age: None, timescale: info.timescale, - compress: false, + compression: crate::track::Compression::None, })?; // As a stream track's answer does, though only lite-05/06 get here, which // never negotiate the extension. diff --git a/rs/moq-net/src/lite/subscriber.rs b/rs/moq-net/src/lite/subscriber.rs index 846ed0dcb7d..41382ccd88b 100644 --- a/rs/moq-net/src/lite/subscriber.rs +++ b/rs/moq-net/src/lite/subscriber.rs @@ -6453,7 +6453,7 @@ mod tests { priority: 0, max_age: None, timescale: Some(Timescale::MILLI), - compress: false, + compression: crate::track::Compression::None, } .encode(&mut crate::coding::Encoder::new(&mut info, version.into()), version) .unwrap(); @@ -6479,7 +6479,7 @@ mod tests { priority: 0, max_age: Some(Duration::from_secs(1)), timescale: Some(Timescale::MILLI), - compress: false, + compression: crate::track::Compression::None, } .encode(&mut crate::coding::Encoder::new(&mut info, version.into()), version) .unwrap(); @@ -12538,7 +12538,7 @@ impl kio::Task for FetchServeRun { // fetch we can serve. // Until TRACK_INFO says, the group may be compressed, which only a whole // group decodes: ask for all of it. - let plain = matches!(self.info.peek(), Some(Ok(info)) if !info.compress); + let plain = matches!(self.info.peek(), Some(Ok(info)) if !info.compressed()); let frame_start = match self.serve.subscriber.version.has_frame_bounds() { true if plain => request.frame_start(), true => 0, diff --git a/rs/moq-net/src/lite/track.rs b/rs/moq-net/src/lite/track.rs index caf738956ed..acd00776a87 100644 --- a/rs/moq-net/src/lite/track.rs +++ b/rs/moq-net/src/lite/track.rs @@ -6,6 +6,7 @@ use crate::{ }; use super::{Message, Version}; +use crate::track::Compression; // Older JS readers use safe integer milliseconds; larger legacy ages mean no limit. const LEGACY_UNLIMITED: u64 = (1u64 << 53) - 1; @@ -89,10 +90,9 @@ pub struct TrackInfo { /// Lite07 encodes `None` as zero; Lite05/06 have no untimed encoding, so `None` /// goes out as milliseconds (see [`Version::wire_timescale`]). pub timescale: Option, - /// Whether FRAME payloads and datagrams are DEFLATE compressed per group, the only codec - /// the wire's `Compression` id names. Lite07+ only: an earlier peer is served the frames - /// inflated, so it is never set. - pub compress: bool, + /// How FRAME payloads and datagrams are compressed per group. Lite07+ only: an earlier + /// peer is served the frames inflated, so it is always [`Compression::None`] there. + pub compression: Compression, } impl TrackInfo { @@ -104,7 +104,10 @@ impl TrackInfo { max_age: info.max_age, timescale: info.timescale, // An older peer is served the frames inflated. - compress: info.compress && version.has_compression(), + compression: match version.has_compression() { + true => info.compression, + false => Compression::None, + }, } } } @@ -116,15 +119,10 @@ impl From for crate::track::Info { .with_max_age(info.max_age) .with_priority(info.priority) .with_refresh(info.refresh) - .with_compress(info.compress) + .with_compression(info.compression) } } -/// TRACK_INFO `Compression`: no codec. -const COMPRESSION_NONE: u64 = 0; -/// TRACK_INFO `Compression`: per-group DEFLATE (draft-lcurley-moq-flate). -const COMPRESSION_DEFLATE: u64 = 1; - /// What reading a track's groups and datagrams needs from its TRACK_INFO and, with the /// `ietf` extension, TRACK_PROPERTIES. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] @@ -145,7 +143,7 @@ impl Framing { Self { timescale: version.wire_timescale(info.timescale), ietf: info.ietf(), - compressed: info.compress, + compressed: info.compressed(), } } } @@ -179,13 +177,13 @@ impl<'a> Message<'a> for TrackInfo { .map_err(|_| DecodeError::InvalidValue)?, false => None, }; - let compress = match version.has_compression() { + let compression = match version.has_compression() { true => match r.varint()? { - COMPRESSION_NONE => false, - COMPRESSION_DEFLATE => true, + 0 => Compression::None, + 1 => Compression::Deflate, _ => return Err(DecodeError::InvalidValue), }, - false => false, + false => Compression::None, }; Ok(Self { @@ -193,7 +191,7 @@ impl<'a> Message<'a> for TrackInfo { refresh, max_age, timescale, - compress, + compression, }) } @@ -216,11 +214,8 @@ impl<'a> Message<'a> for TrackInfo { w.varint(self.refresh.map_or(0, |ratio| u64::from(ratio) + 1))?; } if version.has_compression() { - w.varint(match self.compress { - true => COMPRESSION_DEFLATE, - false => COMPRESSION_NONE, - })?; - } else if self.compress { + w.varint(self.compression as u64)?; + } else if self.compression != Compression::None { // The frames would arrive compressed with nothing saying so. return Err(EncodeError::Version); } @@ -238,7 +233,7 @@ mod test { priority: 7, max_age: Some(Duration::from_millis(2000)), timescale: Some(Timescale::MICRO), - compress: false, + compression: Compression::None, } } @@ -399,20 +394,20 @@ mod test { #[test] fn lite07_carries_the_compression_codec() { - for compress in [false, true] { + for compression in [Compression::None, Compression::Deflate] { let info = TrackInfo { - compress, + compression, ..info_sample() }; let buf = info.encode_bytes(Version::Lite07).unwrap(); - assert_eq!(buf.last(), Some(&u8::from(compress))); - assert_eq!(info_roundtrip(Version::Lite07, &info).compress, compress); + assert_eq!(buf.last(), Some(&(compression as u8))); + assert_eq!(info_roundtrip(Version::Lite07, &info).compression, compression); } // The message body, without its length prefix, ends in the codec id. let mut buf = Vec::new(); TrackInfo { - compress: true, + compression: Compression::Deflate, ..info_sample() } .encode_msg(&mut Encoder::new(&mut buf, Version::Lite07.into()), Version::Lite07) @@ -430,7 +425,7 @@ mod test { #[test] fn compression_needs_lite07() { let info = TrackInfo { - compress: true, + compression: Compression::Deflate, ..info_sample() }; for version in [Version::Lite05, Version::Lite06] { @@ -439,10 +434,10 @@ mod test { "{version}" ); let plain = TrackInfo { - compress: false, + compression: Compression::None, ..info_sample() }; - assert!(!info_roundtrip(version, &plain).compress); + assert_eq!(info_roundtrip(version, &plain).compression, Compression::None); } } @@ -463,7 +458,7 @@ mod test { priority: i8::MIN, max_age: None, timescale: Some(Timescale::new((1u64 << 62) - 1).unwrap()), - compress: false, + compression: Compression::None, }; let got = info_roundtrip(Version::Lite05, &info); assert_eq!(got.priority, i8::MIN); @@ -483,7 +478,7 @@ mod test { priority: 0, max_age: Some(Duration::from_nanos(999_999)), timescale: Some(Timescale::MILLI), - compress: false, + compression: Compression::None, }; let got = info_roundtrip(Version::Lite05, &info); assert_eq!(got.max_age, Some(Duration::ZERO)); @@ -497,7 +492,7 @@ mod test { priority: 7, max_age: Some(Duration::from_millis(u64::MAX)), timescale: Some(Timescale::MILLI), - compress: false, + compression: Compression::None, }; // The partial bytes are the Writer's to drop; see `a_failed_encode_leaves_no_partial_bytes`. assert!(matches!( diff --git a/rs/moq-net/src/lite/tracks.rs b/rs/moq-net/src/lite/tracks.rs index ad8e2e5a7bc..516951e2604 100644 --- a/rs/moq-net/src/lite/tracks.rs +++ b/rs/moq-net/src/lite/tracks.rs @@ -163,7 +163,7 @@ mod test { priority: 3, max_age: Some(Duration::from_secs(2)), timescale: Some(Timescale::MICRO), - compress: true, + compression: crate::track::Compression::Deflate, }; let TracksEvent::Added { name, info: got } = roundtrip(&TracksEvent::Added { name: "video".into(), @@ -176,7 +176,7 @@ mod test { assert_eq!(got.priority, 3); assert_eq!(got.max_age, Some(Duration::from_secs(2))); assert_eq!(got.timescale, Some(Timescale::MICRO)); - assert!(got.compress); + assert_eq!(got.compression, crate::track::Compression::Deflate); let TracksEvent::Finished { name } = roundtrip(&TracksEvent::Finished { name: "audio".into() }) else { panic!("expected TRACKS_FINISH"); diff --git a/rs/moq-net/src/model/flate.rs b/rs/moq-net/src/model/flate.rs index b178c142c77..89dc23d9bae 100644 --- a/rs/moq-net/src/model/flate.rs +++ b/rs/moq-net/src/model/flate.rs @@ -1,4 +1,4 @@ -//! The DEFLATE codec behind compressed tracks ([`crate::track::Info::compress`]). +//! The DEFLATE codec behind compressed tracks ([`crate::track::Info::compression`]). //! //! Each group is one raw DEFLATE stream ([RFC 1951]) with a sync flush after every frame, so //! each frame's slice is self-delimited while later frames compress against earlier ones. diff --git a/rs/moq-net/src/model/front.rs b/rs/moq-net/src/model/front.rs index 4a3ae1f9c4e..f5240930b0c 100644 --- a/rs/moq-net/src/model/front.rs +++ b/rs/moq-net/src/model/front.rs @@ -1268,7 +1268,7 @@ mod tests { ..info() }, track::Info { - compress: true, + compression: crate::track::Compression::Deflate, ..info() }, track::Info { diff --git a/rs/moq-net/src/model/group.rs b/rs/moq-net/src/model/group.rs index 8353dddecbc..01642d8324d 100644 --- a/rs/moq-net/src/model/group.rs +++ b/rs/moq-net/src/model/group.rs @@ -13,7 +13,7 @@ //! [Producer::finish] ends it wherever writing stopped. [Consumer::with_range] bounds a reader to a sub-range the same way [`track::Subscriber`] //! bounds group sequences. //! -//! A group has no size cap. Each copy holds at most its newest [`MAX_CACHE_BYTES`], less +//! A group has no size cap. Each copy holds at most its newest 32 MiB, less //! under the cache pool's memory pressure, and sheds whole frames from its front to stay //! there. A reader that reaches a shed frame rides a flight when the track has a //! [`track::Requests`] handler: a separate copy from that frame, paced by its fastest @@ -49,7 +49,7 @@ use crate::{Error, IntoBytes, Result, StreamError, Timestamp}; /// sheds the same way. A reader that reaches a shed frame rides a flight, or gets /// [`Error::Evicted`] when nothing serves one (see the module docs). A larger declared /// frame size is [`Error::FrameTooLarge`] before allocating. -pub const MAX_CACHE_BYTES: u64 = 32 * 1024 * 1024; // 32 MB +pub(crate) const MAX_CACHE_BYTES: u64 = 32 * 1024 * 1024; // 32 MB /// How far behind a copy's fastest reader a reader may board it: half the live tail, less /// the most one shed frees at once, since the other half may be all ahead of that reader. @@ -1611,7 +1611,7 @@ impl Producer { let access = charge.access(); let (log, pace) = { let mut state = state.write().ok().expect("a new group is open"); - if track.compress { + if track.compressed() { state.flate = Some(Box::new(Flate::new( Arc::new(Plain::new(charge.extra())), charge.extra(), @@ -1660,7 +1660,7 @@ impl Producer { /// with its inflated size ([`frame::Header::inflated`]). #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] pub(crate) fn compressed(&self) -> bool { - self.handle.track.compress + self.handle.track.compressed() } /// The track to check this group's start against, while frame 0 may still be unwritten. @@ -1942,7 +1942,7 @@ impl Producer { /// The `timestamp` is converted into the parent track's timescale, so the scale you /// build it with doesn't have to match the track. A frame the group cannot take /// aborts the group with the error: [`Error::FrameTooLarge`] if the declared size - /// exceeds [`MAX_CACHE_BYTES`] (refused before allocating), + /// exceeds 32 MiB, what a copy holds (refused before allocating), /// [`Error::TimestampMismatch`] if the timestamp can't be converted, or /// [`Error::Closed`] once the group finished. /// @@ -1971,7 +1971,7 @@ impl Producer { /// compresses on commit, which counts its stored slice then, as `bytes` counts payload /// as stored. fn chunk_meter(&self, inflated: Option) -> stats::Meter { - match self.handle.track.compress && inflated.is_none() { + match self.handle.track.compressed() && inflated.is_none() { true => stats::Meter::default(), false => self.stats.clone(), } @@ -1989,10 +1989,10 @@ impl Producer { } // Only a compressed group takes a stored slice, and every frame a local producer // streams into one is plain until it commits. - if header.inflated.is_some() && !self.handle.track.compress { + if header.inflated.is_some() && !self.handle.track.compressed() { return Err(Error::ProtocolViolation); } - let scratch = self.handle.track.compress && header.inflated.is_none(); + let scratch = self.handle.track.compressed() && header.inflated.is_none(); let producer = self.first_frame_track(); let track = producer.as_ref().map(|track| track.read()); @@ -2953,7 +2953,7 @@ impl Handle { end: None, prefetch: Prefetch::default(), raw: false, - compressed: self.track.compress, + compressed: self.track.compressed(), cache: self.cache.clone(), alive: self.alive.clone(), refreshed: self.cache.pool().now(), @@ -6481,7 +6481,11 @@ mod test { fn compressed_group(pool: &cache::Pool) -> Producer { let cache = cache::Track::new(pool.clone(), Default::default(), kio::Weak::new()); - Producer::new(Info::from(0u64), track::Info::default().with_compress(true), cache) + Producer::new( + Info::from(0u64), + track::Info::default().with_compression(crate::track::Compression::Deflate), + cache, + ) } fn read_plain(consumer: &mut Consumer) -> Result> { @@ -6573,7 +6577,7 @@ mod test { fn reused_encoders_start_independent_group_streams() { let pool = cache::Pool::unbounded(); let account = cache::Track::new(pool.clone(), Default::default(), kio::Weak::new()); - let info = track::Info::default().with_compress(true); + let info = track::Info::default().with_compression(crate::track::Compression::Deflate); let mut concurrent = Producer::new(0u64.into(), info.clone(), account.clone()); concurrent.write_frame(None, verbose(0)).unwrap(); for sequence in 1..5u64 { @@ -6793,7 +6797,7 @@ mod test { // A job belongs to its delivery even when another copy keeps the canonical // inflated cache alive. Releasing one must not make its pending read succeed. let cache = cache::Track::new(pool.clone(), Default::default(), kio::Weak::new()); - let info = track::Info::default().with_compress(true); + let info = track::Info::default().with_compression(crate::track::Compression::Deflate); let mut released = Producer::new(Info::from(0u64), info.clone(), cache.clone()); released.bound(Bounds { start: 0, end: Some(2) }).unwrap(); for index in 0..2 { @@ -6935,9 +6939,9 @@ mod test { /// prefix matched. A compressed copy cannot continue with its advanced encoder. #[test] fn a_refused_shared_write_fails_the_group() { - for compress in [false, true] { + for compression in [crate::track::Compression::None, crate::track::Compression::Deflate] { let cache = cache::Track::new(cache::Pool::unbounded(), Default::default(), kio::Weak::new()); - let info = track::Info::default().with_compress(compress); + let info = track::Info::default().with_compression(compression); let mut first = Producer::new(Info::from(0u64), info.clone(), cache.clone()); first.write_frame(None, verbose(0)).unwrap(); first.write_frame(None, verbose(1)).unwrap(); diff --git a/rs/moq-net/src/model/origin.rs b/rs/moq-net/src/model/origin.rs index 56f765351f8..d1f63ab8bc3 100644 --- a/rs/moq-net/src/model/origin.rs +++ b/rs/moq-net/src/model/origin.rs @@ -677,21 +677,14 @@ impl RouteOptions { /// The highest epoch wins over every older one of the instance, cheaper or not. /// Naming an instance grants nothing: publishing still needs the path's grant. /// - /// A [minted](Instance::is_minted) instance names no stream, so routing under one fails - /// with [`Error::Unsupported`]. + /// Do not start a named instance with `~`: that marks one a relay minted + /// ([`Instance::is_minted`]), which moq-crypto's signing refuses to bind and a catalog's instance + /// check skips. pub fn with_instance(mut self, instance: Instance, epoch: u64) -> Self { self.instance = Some((instance, epoch)); self } - /// Refuse a named instance a relay minted for one announcement: it names no stream. - fn refuse_minted(&self) -> Result<(), Error> { - match self.instance.as_ref().is_some_and(|(instance, _)| instance.is_minted()) { - true => Err(Error::Unsupported), - false => Ok(()), - } - } - /// The route metadata these options advertise, under `instance` at `epoch`. fn info(&self, instance: &Instance, epoch: u64) -> RouteInfo { RouteInfo { @@ -2383,8 +2376,14 @@ impl Producer { } /// Whether a moq-lite-07 session publishing through a consumer of this handle (and - /// of any handle derived from it) carries its peer's traffic to other origins; see - /// [`Consumer::with_proxy`], which overrides it for one consumer. + /// of any handle derived from it) carries its peer's traffic to other origins: off, + /// the peer is sent only the routes to this node's own claims; on, the routes it + /// learned from other peers too. + /// + /// A relay turns it on for every session. An application publishing its own + /// broadcasts leaves it off, so a peer never routes through it to reach anyone + /// else. Older versions advertise everything either way, since their hop chains + /// cannot tell this node's claims from what it forwards. pub fn with_proxy(mut self, proxy: bool) -> Self { self.proxy = proxy; self @@ -2505,7 +2504,6 @@ impl Producer { /// [`Error::BoundsExceeded`] if the full rooted path exceeds /// [`Path::MAX_PARTS`] or [`Path::MAX_BYTES`], [`Error::InvalidPath`] if it holds a segment no /// pattern can spell (`*` or `**`), [`Error::NavigationSegment`] for a literal `.` or `..`, - /// [`Error::Unsupported`] if `options` names a [minted](Instance::is_minted) instance, /// or [`Error::Closed`] once the origin's /// [`Driver`] has been dropped. pub fn route(&self, path: impl TryInto>, options: RouteOptions) -> Result { @@ -2525,7 +2523,6 @@ impl Producer { /// An exact route at the absolute `full` path, answering `request` on its first /// announce when it is a job's. fn exact(&self, full: Path, options: RouteOptions, request: Option) -> Result { - options.refuse_minted()?; publish_path(&full)?; if !self.scope.permits(&full) || !self.scope.publishes(&full) { return Err(Error::Unauthorized); @@ -2741,14 +2738,12 @@ impl Producer { /// for as long as the returned [`Route`] (and every clone) lives, unless withdrawn. /// /// The prefix must overlap this producer's pattern scope. Individual requests - /// remain authoritative and are refused when they do not match the scope. Fails with - /// [`Error::Unsupported`] if `options` names a [minted](Instance::is_minted) instance. + /// remain authoritative and are refused when they do not match the scope. pub fn route_prefix( &self, prefix: impl TryInto>, options: RouteOptions, ) -> Result { - options.refuse_minted()?; let (instance, epoch) = options.instance.clone().unwrap_or_else(|| (Instance::random(), 0)); let info = options.info(&instance, epoch); let advertised = !options.hidden; @@ -7290,22 +7285,8 @@ impl Consumer { node } - /// Whether a moq-lite-07 session publishing through this handle (and any handle - /// derived from it) carries its peer's traffic to other origins: off, the peer is - /// sent only the routes to this node's own claims; on, the routes it learned from - /// other peers too. - /// - /// A relay turns it on for every session. An application publishing its own - /// broadcasts leaves it off, so a peer never routes through it to reach anyone - /// else. Older versions advertise everything either way, since their hop chains - /// cannot tell this node's claims from what it forwards. - pub fn with_proxy(mut self, proxy: bool) -> Self { - self.proxy = proxy; - self - } - - /// Whether this handle carries its peer's traffic to other origins; see - /// [`Self::with_proxy`]. + /// Whether this handle carries its peer's traffic to other origins, taken from + /// the [`Producer::with_proxy`] it was consumed from. #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] pub(crate) fn proxy(&self) -> bool { self.proxy @@ -9417,7 +9398,7 @@ mod tests { .with_stats( registry .tier(stats::Tier::default()) - .session(crate::Path::from_static("p1")), + .session(crate::stats::SessionInfo::new(crate::Path::from_static("p1"))), ) .with_hidden(true); @@ -9426,7 +9407,7 @@ mod tests { project.request(".svc/foo", None).await.expect("resolves"); let mut report = stats::Report::default(); - registry.report(&mut report); + registry.report(&mut report, crate::time::Instant::now()); let paths: Vec<_> = report .traffic .iter() @@ -9450,7 +9431,7 @@ mod tests { let consumer = producer.consume().with_stats( registry .tier(stats::Tier::default()) - .session(crate::Path::from_static("viewer")), + .session(crate::stats::SessionInfo::new(crate::Path::from_static("viewer"))), ); let broadcast = consumer.request("room/alice", None).await.expect("resolves"); let bytes = || -> u64 { @@ -10639,7 +10620,7 @@ mod tests { let producer = origin(1).produce().with_stats( registry .tier(stats::Tier::default()) - .session(crate::Path::from_static("root")), + .session(crate::stats::SessionInfo::new(crate::Path::from_static("root"))), ); let announces = || { registry @@ -12486,28 +12467,6 @@ mod tests { pending.await.expect("resolves"); } - /// A minted instance names no stream, so no route takes one. - #[kio::test] - #[cfg(feature = "async")] - async fn a_route_refuses_a_minted_instance() { - let producer = origin(1).produce(); - let consumer = producer.consume(); - let minted = RouteOptions::default().with_instance(Instance::minted(), 0); - assert!(matches!( - producer.route("room/bob", minted.clone()), - Err(Error::Unsupported) - )); - assert!(matches!( - producer.route_prefix("lobby", minted.clone()), - Err(Error::Unsupported) - )); - - let claim = producer.route_prefix("room", RouteOptions::default()).unwrap(); - let mut pending = Box::pin(consumer.request("room/alice", None)); - assert!((&mut pending).now_or_never().is_none()); - assert!(matches!(queued(&claim).await.route(minted), Err(Error::Unsupported))); - } - #[kio::test] #[cfg(feature = "async")] async fn claim_answer_is_hidden_until_published_with_its_instance() { @@ -15935,7 +15894,7 @@ mod tests { .with_stats( registry .tier(stats::Tier::default()) - .session(Path::from_static("project")), + .session(crate::stats::SessionInfo::new(Path::from_static("project"))), ); let mut selected = consumer.routes(); selected.expect_next_active("cam.chat").await; @@ -15963,13 +15922,13 @@ mod tests { let mut group = reader.recv_group().await.unwrap().unwrap(); assert_eq!(group.read_frame().await.unwrap().unwrap().payload.as_ref(), b"frame"); let mut report = stats::Report::default(); - registry.report(&mut report); + registry.report(&mut report, crate::time::Instant::now()); assert_eq!(report.traffic.len(), 1); assert_eq!(report.traffic[0].path.as_str(), "project/cam.chat"); assert_eq!(report.traffic[0].publisher.announces_started, 1); assert_eq!(report.traffic[0].publisher.bytes, 5); drop(selected); - registry.report(&mut report); + registry.report(&mut report, crate::time::Instant::now()); assert_eq!(report.traffic[0].publisher.announces_ended, 1); // Discovery of a request still sees a covering route that enumeration omits. diff --git a/rs/moq-net/src/model/resume.rs b/rs/moq-net/src/model/resume.rs index 457df779de0..e7e8e542e64 100644 --- a/rs/moq-net/src/model/resume.rs +++ b/rs/moq-net/src/model/resume.rs @@ -3347,7 +3347,7 @@ mod test { #[test] #[cfg(feature = "async")] fn a_failed_compressed_group_continues_from_the_replacement() { - let info = crate::track::Info::timed().with_compress(true); + let info = crate::track::Info::timed().with_compression(crate::track::Compression::Deflate); let compressed = || track::Producer::new(Arc::new(broadcast::Info::default()), "video", info.clone()); let routes = Producer::new(); let logical = track::Request::new(Arc::new(broadcast::Info::default()), "video") @@ -3387,7 +3387,7 @@ mod test { #[test] #[cfg(feature = "async")] fn a_malformed_compressed_frame_fails_the_read() { - let info = crate::track::Info::timed().with_compress(true); + let info = crate::track::Info::timed().with_compression(crate::track::Compression::Deflate); let routes = Producer::new(); let logical = track::Request::new(Arc::new(broadcast::Info::default()), "video") .routes(routes.consume()) @@ -3429,7 +3429,7 @@ mod test { pool: pool.clone(), ..Default::default() }); - let info = crate::track::Info::timed().with_compress(true); + let info = crate::track::Info::timed().with_compression(crate::track::Compression::Deflate); let routes = Producer::new(); let logical = track::Request::new(broadcast.clone(), "video") .routes(routes.consume()) @@ -4222,7 +4222,7 @@ mod test { #[test] #[cfg(feature = "async")] fn a_fetched_plain_reader_past_a_shed_inflated_front_gets_evicted() { - let info = crate::track::Info::timed().with_compress(true); + let info = crate::track::Info::timed().with_compression(crate::track::Compression::Deflate); let routes = Producer::new(); let a = track::Producer::new(Arc::new(broadcast::Info::default()), "video", info.clone()); routes.serve(a.consume()); diff --git a/rs/moq-net/src/model/track.rs b/rs/moq-net/src/model/track.rs index 6d4536dfaeb..d908234ceeb 100644 --- a/rs/moq-net/src/model/track.rs +++ b/rs/moq-net/src/model/track.rs @@ -147,16 +147,16 @@ pub struct Info { /// It breaks ties between subscriptions of equal subscriber priority. Reported in /// TRACK_INFO (Lite05+). pub priority: i8, - /// Whether frames are DEFLATE compressed per group, so later frames compress against - /// earlier ones in the same group. Defaults to `false`. + /// How frames are compressed per group, so later frames compress against earlier ones in + /// the same group. Defaults to [`Compression::None`]. /// /// Writers and readers see plain frames either way: the producer compresses each /// frame as it is written and the cache stores the compressed form. A moq-lite-07 peer or a /// moq-transport peer negotiating the Flate extension receives the compressed - /// bytes and the flag. Other sessions receive one shared inflated copy per group, + /// bytes and the codec. Other sessions receive one shared inflated copy per group, /// unless a sealed compression declaration makes that fallback unsupported. /// Worth it for small, repetitive payloads like JSON; wasted on media. - pub compress: bool, + pub compression: Compression, /// The ratio of a group's bytes after its first frame to the first frame past which a /// joining subscriber asks for a new group, or `None` (the default) to never ask. /// @@ -192,7 +192,7 @@ impl PartialEq for Info { timescale, max_age, priority, - compress, + compression, refresh, properties, unchecked: _, @@ -200,7 +200,7 @@ impl PartialEq for Info { *timescale == other.timescale && *max_age == other.max_age && *priority == other.priority - && *compress == other.compress + && *compression == other.compression && *refresh == other.refresh && *properties == other.properties } @@ -208,6 +208,18 @@ impl PartialEq for Info { impl Eq for Info {} +/// How a track's frames are compressed, with the values TRACK_INFO's `Compression` field +/// carries. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] +#[non_exhaustive] +pub enum Compression { + /// Frames travel as written. + #[default] + None = 0, + /// Each group is one DEFLATE stream (draft-lcurley-moq-flate). + Deflate = 1, +} + /// An authored track's defaults: untimed, a zero [`max_age`](Info::max_age) (the live edge only), /// priority 0, uncompressed, never asking for a refresh. impl Default for Info { @@ -216,7 +228,7 @@ impl Default for Info { timescale: None, max_age: Some(Duration::ZERO), priority: DEFAULT_PRIORITY, - compress: false, + compression: Compression::None, refresh: None, properties: None, unchecked: false, @@ -248,12 +260,17 @@ impl Info { self } - /// Set whether frames are DEFLATE compressed per group, returning `self` for chaining. - pub fn with_compress(mut self, compress: bool) -> Self { - self.compress = compress; + /// Set how frames are compressed per group, returning `self` for chaining. + pub fn with_compression(mut self, compression: Compression) -> Self { + self.compression = compression; self } + /// Whether frames are compressed at all. + pub(crate) fn compressed(&self) -> bool { + self.compression != Compression::None + } + /// Set the [`refresh`](Self::refresh) ratio, returning `self` for chaining. pub fn with_refresh(mut self, refresh: impl Into>) -> Self { self.refresh = refresh.into(); @@ -3298,7 +3315,7 @@ impl TrackState { let mut group = group::Producer::new(group::Info { sequence }, info.clone(), self.cache.clone()); // A compressed flight inflates from frame 0 with a decoder of its own, so it keeps // its own content rather than the cached copy's, whose inflated copy is further on. - if !info.compress { + if !info.compressed() { if let Some(content) = self.content_for_copy(sequence)? { group.handle().share_content(content); } @@ -3362,7 +3379,7 @@ pub(super) enum Board { /// before it, and its riders skip to their frame. pub(super) fn board(track: &kio::Producer, reader: &group::Consumer) -> Option { let state = track.read(); - let compress = state.info.as_ref()?.compress; + let compress = state.info.as_ref()?.compressed(); if let Some((copy, flight)) = state.ride(reader, false) && let Some(copy) = copy.try_consume() { @@ -5598,13 +5615,13 @@ impl Consumer { { let state = state.read(); if state.lookup.get(&sequence).is_none_or(Slot::is_aborted) - || state.info.as_ref().is_none_or(|info| info.compress) + || state.info.as_ref().is_none_or(|info| info.compressed()) { request.options.frame_start = 0; } // A compressed stream needs the entire dictionary; an unknown track is conservative // until TRACK_INFO has told the relay which representation it will receive. - if state.info.as_ref().is_none_or(|info| info.compress) { + if state.info.as_ref().is_none_or(|info| info.compressed()) { request.end = None; } } @@ -19124,7 +19141,7 @@ mod test { pool: pool.clone(), ..Default::default() }); - let producer = Producer::new(broadcast, "test", Info::timed().with_compress(true)); + let producer = Producer::new(broadcast, "test", Info::timed().with_compression(Compression::Deflate)); let frame = bytes::Bytes::from(vec![0u8; 256 * 1024]); let groups = 16; for _ in 0..groups { @@ -24653,7 +24670,7 @@ mod test { } frame.finish().unwrap() } - let info = Info::timed().with_compress(true); + let info = Info::timed().with_compression(Compression::Deflate); let reference = track_producer("reference", info.clone()); let mut source = reference.create_group(group::Info { sequence: 0 }).unwrap(); let expected: Vec<_> = (0..9) @@ -25017,7 +25034,7 @@ mod test { #[test] #[cfg(feature = "async")] fn a_compressed_flight_starts_at_frame_0_and_its_rider_skips_ahead() { - let producer = track_producer("test", Info::default().with_compress(true)); + let producer = track_producer("test", Info::default().with_compression(Compression::Deflate)); let requests = producer.requests(); let mut live = producer.append_group().unwrap(); let mut reader = live.consume(); diff --git a/rs/moq-net/src/server.rs b/rs/moq-net/src/server.rs index 5323d6de491..e82f2746daa 100644 --- a/rs/moq-net/src/server.rs +++ b/rs/moq-net/src/server.rs @@ -1838,7 +1838,7 @@ mod tests { .with_stats( registry .tier(Default::default()) - .session(crate::Path::from_static("room")), + .session(crate::stats::SessionInfo::new(crate::Path::from_static("room"))), ); let Err(err) = request.ok().await else { panic!("a reply the peer never took completed"); @@ -1888,7 +1888,7 @@ mod tests { .with_stats( registry .tier(Default::default()) - .session(crate::Path::from_static("room")), + .session(crate::stats::SessionInfo::new(crate::Path::from_static("room"))), ); request.expired().await; assert_eq!(kio::clock::now(), start + std::time::Duration::from_secs(5)); @@ -1980,7 +1980,7 @@ mod tests { .with_stats( registry .tier(Default::default()) - .session(crate::Path::from_static("room")), + .session(crate::stats::SessionInfo::new(crate::Path::from_static("room"))), ); let abandoned = kio::clock::timeout(std::time::Duration::from_secs(1), request.ok()).await; assert!(abandoned.is_err(), "a reply the peer never took completed"); @@ -2028,7 +2028,7 @@ mod tests { .with_stats( registry .tier(Default::default()) - .session(crate::Path::from_static("room")), + .session(crate::stats::SessionInfo::new(crate::Path::from_static("room"))), ) .close(err.clone()); let failures = registry.snapshot().sessions()[0].1.sessions_failed; diff --git a/rs/moq-net/src/stats.rs b/rs/moq-net/src/stats.rs index 9d958334e07..544f115b4ae 100644 --- a/rs/moq-net/src/stats.rs +++ b/rs/moq-net/src/stats.rs @@ -1352,11 +1352,10 @@ impl Registry { /// an interval sees the closing readout exactly once. A pruned path that /// sees traffic again restarts from zero; see the module docs on counter /// resets. Leaves the report empty for a disabled registry. - pub fn report(&self, report: &mut Report) { - self.report_at(report, Instant::now()); - } - - fn report_at(&self, report: &mut Report, now: Instant) { + /// + /// `now` is the drain's time, usually [`Instant::now`], which dates each + /// session's activity window. + pub fn report(&self, report: &mut Report, now: Instant) { self.collect_wire(); report.traffic.clear(); report.sessions.clear(); @@ -1440,25 +1439,59 @@ pub struct Handle { tier: Tier, } +/// A refused session, as [`Handle::refuse`] counts it. +#[derive(Clone, Debug)] +#[non_exhaustive] +pub struct Refusal { + /// The session's resolved stats label. + pub label: Path, + /// Why it was refused. + pub reason: RefusalKind, +} + +impl Refusal { + /// A session under `label`, refused for `reason`. + pub fn new(label: impl Into, reason: RefusalKind) -> Self { + Self { + label: label.into(), + reason, + } + } +} + +/// A connected session, as [`Handle::session`] records it. +#[derive(Clone, Debug)] +#[non_exhaustive] +pub struct SessionInfo { + /// The session's resolved stats label. + pub label: Path, +} + +impl SessionInfo { + /// A session under `label`. + pub fn new(label: impl Into) -> Self { + Self { label: label.into() } + } +} + impl Handle { /// Count a session refused outside relay admission under its resolved label and tier. - pub fn refuse(&self, label: impl Into, reason: RefusalKind) { - if let Some(presence) = self.stats.session_counters(&self.tier, label) { + pub fn refuse(&self, refusal: Refusal) { + if let Some(presence) = self.stats.session_counters(&self.tier, refusal.label) { presence .sessions_refused - .counter(reason) + .counter(refusal.reason) .fetch_add(1, Ordering::Relaxed); } } - /// Record a connected session under `label` on this tier. Hold - /// the returned guard for the session's lifetime; dropping it bumps - /// `sessions_ended`. Counts presence regardless of any data flow, so a - /// session that merely connects is still billable. Surfaced on the session - /// track for this tier, keyed by `label`, in its totals, and in `label`'s - /// presence track. - pub fn session(&self, label: impl Into) -> Session { - self.context(label, Context::Session) + /// Record a connected session on this tier. Hold the returned guard for + /// the session's lifetime; dropping it bumps `sessions_ended`. Counts + /// presence regardless of any data flow, so a session that merely connects + /// is still billable. Surfaced on the session track for this tier, keyed by + /// its label, in its totals, and in that label's presence track. + pub fn session(&self, session: SessionInfo) -> Session { + self.context(session.label, Context::Session) } /// Count one admitted request under `label` and meter its traffic without session presence. @@ -2197,7 +2230,9 @@ mod tests { let registry = test_stats(); let old = Tier::new(crate::Path::from_static("old")); let new = Tier::new(crate::Path::from_static("new")); - let session = registry.tier(old.clone()).session(crate::Path::from_static("room")); + let session = registry + .tier(old.clone()) + .session(SessionInfo::new(crate::Path::from_static("room"))); let bytes = counters(10, 20); let _wire = session.wire(bytes.clone()); let report = drain(®istry); @@ -2227,7 +2262,9 @@ mod tests { #[test] fn a_wire_counter_reset_never_lowers_presence() { let registry = test_stats(); - let session = registry.tier(Tier::default()).session(crate::Path::from_static("room")); + let session = registry + .tier(Tier::default()) + .session(SessionInfo::new(crate::Path::from_static("room"))); let bytes = crate::transport::Wire::new(); let _wire = session.wire(bytes.clone()); for (reading, expected) in [((20, 30), (20, 30)), ((3, 4), (20, 30)), ((8, 10), (25, 36))] { @@ -2244,7 +2281,9 @@ mod tests { #[test] fn disabled_wire_collection_reports_nothing() { let registry = Registry::disabled(); - let session = registry.tier(Tier::default()).session(crate::Path::from_static("root")); + let session = registry + .tier(Tier::default()) + .session(SessionInfo::new(crate::Path::from_static("root"))); let wire = session.wire(counters(5, 7)); assert!(drain(®istry).sessions.is_empty()); drop(wire); @@ -2254,7 +2293,9 @@ mod tests { #[test] fn wire_guards_hold_the_session_until_the_final_reading() { let registry = test_stats(); - let session = registry.tier(Tier::default()).session(crate::Path::from_static("room")); + let session = registry + .tier(Tier::default()) + .session(SessionInfo::new(crate::Path::from_static("room"))); let wire = session.wire(counters(19, 23)); drop(session); assert_eq!(drain(®istry).sessions[0].presence.active(), 1); @@ -2280,8 +2321,8 @@ mod tests { fn outcomes_survive_clones_tier_changes_and_pruning() { let stats = test_stats(); let handle = stats.tier(Tier::new(crate::Path::from_static("gateway"))); - handle.refuse(crate::Path::from_static("root"), RefusalKind::Forbidden); - let session = handle.session(crate::Path::from_static("root")); + handle.refuse(Refusal::new(crate::Path::from_static("root"), RefusalKind::Forbidden)); + let session = handle.session(SessionInfo::new(crate::Path::from_static("root"))); let clone = session.clone(); session.retag( Tier::new(crate::Path::from_static("next")), @@ -2316,10 +2357,10 @@ mod tests { let disabled = Registry::disabled(); disabled .tier(Tier::default()) - .refuse(crate::Path::from_static("root"), RefusalKind::Refused); + .refuse(Refusal::new(crate::Path::from_static("root"), RefusalKind::Refused)); disabled .tier(Tier::default()) - .session(crate::Path::from_static("root")) + .session(SessionInfo::new(crate::Path::from_static("root"))) .end(&crate::Error::Expired); assert!(disabled.snapshot().sessions().is_empty()); } @@ -2377,10 +2418,12 @@ mod tests { #[test] fn default_and_named_tiers_are_independent() { let stats = test_stats(); - let default = stats.tier(Tier::default()).session(crate::Path::from_static("root")); + let default = stats + .tier(Tier::default()) + .session(SessionInfo::new(crate::Path::from_static("root"))); let regional = stats .tier(Tier::new(crate::Path::from_static("region/sjc"))) - .session(crate::Path::from_static("root")); + .session(SessionInfo::new(crate::Path::from_static("root"))); default.egress(crate::Path::from_static("demo/bbb")).meter().bytes(100); regional.ingress(crate::Path::from_static("demo/bbb")).meter().bytes(7); @@ -2403,8 +2446,8 @@ mod tests { let stats = test_stats(); let tier = stats.tier(Tier::default()); let (s1, s2) = ( - tier.session(crate::Path::from_static("acme")), - tier.session(crate::Path::from_static("acme")), + tier.session(SessionInfo::new(crate::Path::from_static("acme"))), + tier.session(SessionInfo::new(crate::Path::from_static("acme"))), ); let announces = Slots::new(10).with_stats(&s1, Cap::Announces); let subscriptions = Slots::new(10).with_stats(&s2, Cap::Subscriptions); @@ -2437,7 +2480,9 @@ mod tests { use crate::session::Slots; let stats = test_stats(); - let session = stats.tier(Tier::default()).session(crate::Path::from_static("acme")); + let session = stats + .tier(Tier::default()) + .session(SessionInfo::new(crate::Path::from_static("acme"))); let subscriptions = Slots::new(10).with_stats(&session, Cap::Subscriptions); let mut held: Vec<_> = (0..5).map(|_| subscriptions.acquire().unwrap()).collect(); held.truncate(3); @@ -2465,9 +2510,9 @@ mod tests { let regional = stats.tier(Tier::new(crate::Path::from_static("region/sjc"))); // Two default-tier sessions under one label, one regional; presence sums them. - let s1 = default.session(crate::Path::from_static("acme")); - let _s2 = default.session(crate::Path::from_static("acme")); - let s3 = regional.session(crate::Path::from_static("peer")); + let s1 = default.session(SessionInfo::new(crate::Path::from_static("acme"))); + let _s2 = default.session(SessionInfo::new(crate::Path::from_static("acme"))); + let s3 = regional.session(SessionInfo::new(crate::Path::from_static("peer"))); // Default-tier egress across two broadcasts; the snapshot sums them. { @@ -2527,7 +2572,7 @@ mod tests { fn drain(stats: &Registry) -> Report { let mut report = Report::default(); - stats.report(&mut report); + stats.report(&mut report, crate::time::Instant::now()); report } @@ -2535,18 +2580,20 @@ mod tests { fn report_reuses_capacity() { // A reused report is cleared, not appended to, and keeps its buffers. let stats = test_stats(); - let ctx = stats.tier(Tier::default()).session(crate::Path::from_static("root")); + let ctx = stats + .tier(Tier::default()) + .session(SessionInfo::new(crate::Path::from_static("root"))); let _scopes: Vec<_> = (0..8) .map(|i| ctx.egress(crate::Path::new(format!("b/{i}").as_str()).unwrap())) .collect(); let mut report = Report::default(); - stats.report(&mut report); + stats.report(&mut report, crate::time::Instant::now()); assert_eq!(report.traffic.len(), 8); assert_eq!(report.sessions.len(), 1); let (traffic, sessions) = (report.traffic.as_ptr(), report.sessions.as_ptr()); - stats.report(&mut report); + stats.report(&mut report, crate::time::Instant::now()); assert_eq!(report.traffic.len(), 8, "refilled, not appended"); assert_eq!(report.sessions.len(), 1); assert_eq!(report.traffic.as_ptr(), traffic, "traffic buffer reused"); @@ -2560,7 +2607,9 @@ mod tests { // after the last guard drops (returning the final values that once). let stats = test_stats(); let key = crate::Path::from_static("foo/bar"); - let ctx = stats.tier(Tier::default()).session(crate::Path::from_static("root")); + let ctx = stats + .tier(Tier::default()) + .session(SessionInfo::new(crate::Path::from_static("root"))); let scope = ctx.egress(crate::Path::from_static("foo/bar")); let sub = scope.subscribe(); scope.meter().bytes(42); @@ -2608,7 +2657,9 @@ mod tests { // subscription could still begin at any moment. let stats = test_stats(); let key = crate::Path::from_static("foo/bar"); - let ctx = stats.tier(Tier::default()).session(crate::Path::from_static("root")); + let ctx = stats + .tier(Tier::default()) + .session(SessionInfo::new(crate::Path::from_static("root"))); let scope = ctx.egress(crate::Path::from_static("foo/bar")); let guard = scope.announce(); @@ -2633,7 +2684,9 @@ mod tests { // Once the last session under a label disconnects, the label leaves the // registry on the drain that reports its final gauge. let stats = test_stats(); - let session = stats.tier(Tier::default()).session(crate::Path::from_static("acme")); + let session = stats + .tier(Tier::default()) + .session(SessionInfo::new(crate::Path::from_static("acme"))); let report = drain(&stats); let row = report @@ -2662,7 +2715,9 @@ mod tests { let registry = Registry::new(Default::default()); let first = Tier::new(crate::Path::from_static("internal")); let second = Tier::new(crate::Path::from_static("edge")); - let context = registry.tier(first.clone()).session(crate::Path::from_static("")); + let context = registry + .tier(first.clone()) + .session(SessionInfo::new(crate::Path::from_static(""))); context.control(Message::Announce, 17, false); context.retag(second.clone(), crate::Path::from_static("")); context.control(Message::TrackInfo, 23, true); @@ -2672,7 +2727,7 @@ mod tests { ]; assert_eq!(registry.snapshot().control(), expected); drop(context); - registry.report(&mut Report::default()); + registry.report(&mut Report::default(), crate::time::Instant::now()); assert_eq!(registry.snapshot().control(), expected); assert_eq!(registry.snapshot().control(), expected, "scrapes do not drain totals"); } @@ -2681,11 +2736,15 @@ mod tests { fn snapshot_preserves_retired_counters() { let stats = test_stats(); let tier = Tier::default(); - let live = stats.tier(tier.clone()).session(crate::Path::from_static("live")); + let live = stats + .tier(tier.clone()) + .session(SessionInfo::new(crate::Path::from_static("live"))); let scope = live.egress(crate::Path::from_static("live/video")); let _live_sub = scope.subscribe(); for _ in 0..2 { - let session = stats.tier(tier.clone()).session(crate::Path::from_static("retired")); + let session = stats + .tier(tier.clone()) + .session(SessionInfo::new(crate::Path::from_static("retired"))); let scope = session.egress(crate::Path::from_static("retired/video")); let sub = scope.subscribe(); scope.meter().bytes(100); @@ -2729,7 +2788,7 @@ mod tests { let path = format!("root/{i}"); let session = worker_stats .tier(Tier::default()) - .session(crate::Path::new(path.as_str()).unwrap()); + .session(SessionInfo::new(crate::Path::new(path.as_str()).unwrap())); session .ingress(crate::Path::new(path.as_str()).unwrap()) .meter() @@ -2778,7 +2837,9 @@ mod tests { // Our own stats broadcasts (and any sibling category under the same // prefix) must not feed back into the registry. let stats = test_stats(); - let ctx = stats.tier(Tier::default()).session(crate::Path::from_static("root")); + let ctx = stats + .tier(Tier::default()) + .session(SessionInfo::new(crate::Path::from_static("root"))); let scope = ctx.egress(crate::Path::from_static(".stats/node/sjc")); scope.meter().bytes(100); let _guard = scope.announce(); @@ -2792,7 +2853,9 @@ mod tests { // and bumps are dropped. let stats = Registry::default(); assert!(stats.shared.is_none()); - let ctx = stats.tier(Tier::default()).session(crate::Path::from_static("root")); + let ctx = stats + .tier(Tier::default()) + .session(SessionInfo::new(crate::Path::from_static("root"))); let scope = ctx.egress(crate::Path::from_static("demo/bbb")); scope.meter().bytes(100); let _guard = scope.announce(); @@ -2812,9 +2875,9 @@ mod tests { session_snapshot(&stats, &Tier::default(), label).map(|p| (p.sessions_started, p.sessions_ended)) }; - let a1 = ext.session(crate::Path::from_static("acme")); - let a2 = ext.session(crate::Path::from_static("acme")); - let b1 = ext.session(crate::Path::from_static("globex")); + let a1 = ext.session(SessionInfo::new(crate::Path::from_static("acme"))); + let a2 = ext.session(SessionInfo::new(crate::Path::from_static("acme"))); + let b1 = ext.session(SessionInfo::new(crate::Path::from_static("globex"))); assert_eq!(snap("acme"), Some((2, 0)), "two sessions under one label"); assert_eq!(snap("globex"), Some((1, 0)), "a distinct label is counted separately"); @@ -2889,7 +2952,9 @@ mod tests { session_snapshot(&stats, &Tier::default(), label).map(|p| (p.sessions_started, p.sessions_ended)) }; - let ctx = stats.tier(Tier::default()).session(crate::Path::from_static("acme")); + let ctx = stats + .tier(Tier::default()) + .session(SessionInfo::new(crate::Path::from_static("acme"))); assert_eq!(snap("acme"), Some((1, 0))); let clone = ctx.clone(); @@ -2907,7 +2972,9 @@ mod tests { let gold = Tier::new(crate::Path::from_static("gold")); let snap = |tier: &Tier| session_snapshot(&stats, tier, "acme").map(|p| (p.sessions_started, p.sessions_ended)); - let ctx = stats.tier(Tier::default()).session(crate::Path::from_static("acme")); + let ctx = stats + .tier(Tier::default()) + .session(SessionInfo::new(crate::Path::from_static("acme"))); ctx.retag(Tier::default(), crate::Path::from_static("acme")); assert_eq!(snap(&Tier::default()), Some((1, 0)), "the same tier is a no-op"); @@ -2923,7 +2990,9 @@ mod tests { fn retag_moves_subsequent_traffic() { let stats = test_stats(); let gold = Tier::new(crate::Path::from_static("gold")); - let ctx = stats.tier(Tier::default()).session(crate::Path::from_static("acme")); + let ctx = stats + .tier(Tier::default()) + .session(SessionInfo::new(crate::Path::from_static("acme"))); let scope = ctx.egress(crate::Path::from_static("demo/bbb")); let clone = scope.clone(); @@ -2971,7 +3040,7 @@ mod tests { let tier = Tier::default(); let session = stats .tier(tier.clone()) - .session(crate::Path::from_static("project/root")); + .session(SessionInfo::new(crate::Path::from_static("project/root"))); session .egress(crate::Path::from_static("project/live")) .meter() @@ -2993,7 +3062,9 @@ mod tests { fn retag_back_counts_bytes_once() { let stats = test_stats(); let tier = Tier::default(); - let session = stats.tier(tier.clone()).session(crate::Path::from_static("a")); + let session = stats + .tier(tier.clone()) + .session(SessionInfo::new(crate::Path::from_static("a"))); let meter = session.ingress(crate::Path::from_static("a/live")).meter(); meter.bytes(1); session.retag(tier.clone(), crate::Path::from_static("b")); @@ -3009,18 +3080,20 @@ mod tests { fn session_bytes_outlive_the_session() { let stats = test_stats(); let tier = Tier::default(); - let session = stats.tier(tier.clone()).session(crate::Path::from_static("acme")); + let session = stats + .tier(tier.clone()) + .session(SessionInfo::new(crate::Path::from_static("acme"))); let meter = session.egress(crate::Path::from_static("acme/live")).meter(); meter.bytes(3); drop(session); let mut report = Report::default(); - stats.report(&mut report); + stats.report(&mut report, crate::time::Instant::now()); assert!(!report.sessions[0].closed, "a live meter keeps its label's row open"); meter.datagram(4); drop(meter); - stats.report(&mut report); + stats.report(&mut report, crate::time::Instant::now()); assert_eq!(report.sessions[0].presence.sent_bytes, 7); assert!(report.sessions[0].closed); assert_eq!( @@ -3038,8 +3111,12 @@ mod tests { let activity = |secs| stats.snapshot_at(at(secs)).activity[&tier]; let both = |idle, active| Activity { idle, active }; - let quiet = stats.tier(tier.clone()).session(crate::Path::from_static("acme")); - let busy = stats.tier(tier.clone()).session(crate::Path::from_static("acme")); + let quiet = stats + .tier(tier.clone()) + .session(SessionInfo::new(crate::Path::from_static("acme"))); + let busy = stats + .tier(tier.clone()) + .session(SessionInfo::new(crate::Path::from_static("acme"))); let _request = stats.tier(tier.clone()).request(crate::Path::from_static("acme")); let meter = busy.egress(crate::Path::from_static("acme/live")).meter(); let _held = quiet.ingress(crate::Path::from_static("acme/other")).meter(); @@ -3073,7 +3150,7 @@ mod tests { ); drop((quiet, _held, _request, meter)); - stats.report_at(&mut Report::default(), at(15)); + stats.report(&mut Report::default(), at(15)); assert_eq!(activity(15), both(0, 0), "a pruned tier still reports zero"); } @@ -3081,7 +3158,9 @@ mod tests { fn excluded_paths_skip_session_bytes() { let stats = test_stats(); let tier = Tier::default(); - let session = stats.tier(tier.clone()).session(crate::Path::from_static("acme")); + let session = stats + .tier(tier.clone()) + .session(SessionInfo::new(crate::Path::from_static("acme"))); session.egress(crate::Path::from_static(".stats/node")).meter().bytes(9); assert_eq!(session_snapshot(&stats, &tier, "acme").unwrap().sent_bytes, 0); } @@ -3090,7 +3169,9 @@ mod tests { fn meter_bumps_the_right_side() { // A payload meter records on its own side only. let stats = test_stats(); - let ctx = stats.tier(Tier::default()).session(crate::Path::from_static("root")); + let ctx = stats + .tier(Tier::default()) + .session(SessionInfo::new(crate::Path::from_static("root"))); let egress = ctx.egress(crate::Path::from_static("demo/bbb")).meter(); egress.group(); @@ -3114,7 +3195,9 @@ mod tests { // An egress subscription bumps `subscriptions_started` and, being the context's first // for the broadcast, `broadcasts_started`. Dropping closes both. let stats = test_stats(); - let ctx = stats.tier(Tier::default()).session(crate::Path::from_static("root")); + let ctx = stats + .tier(Tier::default()) + .session(SessionInfo::new(crate::Path::from_static("root"))); let raw = || tier_counters(&stats, "demo/bbb", &Tier::default()).publisher.snapshot(); let scope = ctx.egress(crate::Path::from_static("demo/bbb")); @@ -3141,13 +3224,13 @@ mod tests { let v1 = stats .tier(Tier::default()) - .session(crate::Path::from_static("a")) + .session(SessionInfo::new(crate::Path::from_static("a"))) .egress(crate::Path::from_static("demo/bbb")) .subscribe(); assert_eq!(raw().broadcasts_started, 1); let v2 = stats .tier(Tier::default()) - .session(crate::Path::from_static("b")) + .session(SessionInfo::new(crate::Path::from_static("b"))) .egress(crate::Path::from_static("demo/bbb")) .subscribe(); assert_eq!(raw().broadcasts_started, 2, "two distinct contexts => two viewers"); @@ -3163,7 +3246,9 @@ mod tests { // An ingress (producer-lifetime) subscription bumps subscriptions but never // the viewer refcount, which is egress-only. let stats = test_stats(); - let ctx = stats.tier(Tier::default()).session(crate::Path::from_static("root")); + let ctx = stats + .tier(Tier::default()) + .session(SessionInfo::new(crate::Path::from_static("root"))); let guard = ctx.ingress(crate::Path::from_static("demo/bbb")).subscribe(); let sub = tier_counters(&stats, "demo/bbb", &Tier::default()) .subscriber @@ -3196,7 +3281,7 @@ mod tests { drop(request); drop(clone); let mut report = Report::default(); - stats.report(&mut report); + stats.report(&mut report, crate::time::Instant::now()); for (label, requests, bytes) in [("old", 1, 7), ("new", 0, 11)] { let tier = Tier::new(crate::Path::new(label).unwrap()); let presence = report.sessions.iter().find(|entry| entry.tier == tier).unwrap(); @@ -3218,7 +3303,7 @@ mod tests { bytes ); } - stats.report(&mut report); + stats.report(&mut report, crate::time::Instant::now()); assert!(report.sessions.is_empty()); let totals = stats.snapshot().sessions(); assert_eq!(totals.iter().map(|(_, p)| p.requests).sum::(), 1); @@ -3248,7 +3333,9 @@ mod tests { fn fetch_counts_separately_from_subscriptions() { // A fetch bumps `fetches`, not `subscriptions_started` or the viewer refcount. let stats = test_stats(); - let ctx = stats.tier(Tier::default()).session(crate::Path::from_static("root")); + let ctx = stats + .tier(Tier::default()) + .session(SessionInfo::new(crate::Path::from_static("root"))); let scope = ctx.egress(crate::Path::from_static("demo/bbb")); scope.fetch(); scope.fetch(); @@ -3263,7 +3350,9 @@ mod tests { // The announce guard bumps `announces_started` + the path length on open, and // `announces_ended` + the path length again on drop. let stats = test_stats(); - let ctx = stats.tier(Tier::default()).session(crate::Path::from_static("root")); + let ctx = stats + .tier(Tier::default()) + .session(SessionInfo::new(crate::Path::from_static("root"))); let path_len = "demo/bbb".len() as u64; let guard = ctx.egress(crate::Path::from_static("demo/bbb")).announce(); diff --git a/rs/moq-net/src/test_interop.rs b/rs/moq-net/src/test_interop.rs index 80446166634..63ad9475c2a 100644 --- a/rs/moq-net/src/test_interop.rs +++ b/rs/moq-net/src/test_interop.rs @@ -367,7 +367,10 @@ fn lite_varint_interop() { priority: 1, max_age: None, timescale: None, - compress: version.has_compression(), + compression: match version.has_compression() { + true => crate::track::Compression::Deflate, + false => crate::track::Compression::None, + }, } .encode_bytes(version) .unwrap(); @@ -594,7 +597,7 @@ fn lite_tracks_interop() { priority: 3, max_age: Some(std::time::Duration::from_secs(2)), timescale: Some(crate::Timescale::MICRO), - compress: true, + compression: crate::track::Compression::Deflate, }; let mut bytes = Vec::new(); let mut w = Encoder::new(&mut bytes, version.into()); diff --git a/rs/moq-net/tests/integration/announce_covering_route.rs b/rs/moq-net/tests/integration/announce_covering_route.rs index 40c9a34c183..4d992a76368 100644 --- a/rs/moq-net/tests/integration/announce_covering_route.rs +++ b/rs/moq-net/tests/integration/announce_covering_route.rs @@ -23,7 +23,7 @@ const REQUESTED: &str = ".dash/nobody"; fn produce_origin(hop: u64) -> origin::Producer { let (producer, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } /// Drain every event the cursor has pending, as `kind prefix` lines. diff --git a/rs/moq-net/tests/integration/announce_takeover.rs b/rs/moq-net/tests/integration/announce_takeover.rs index b9fc5e10802..eb4787df124 100644 --- a/rs/moq-net/tests/integration/announce_takeover.rs +++ b/rs/moq-net/tests/integration/announce_takeover.rs @@ -17,7 +17,7 @@ const TEST_TIMEOUT: Duration = Duration::from_secs(600); fn produce_origin(hop: u64) -> origin::Producer { let (producer, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } /// Have `to` pull everything `from` publishes, over a link priced at `cost`. diff --git a/rs/moq-net/tests/integration/announce_to_serve.rs b/rs/moq-net/tests/integration/announce_to_serve.rs index 3d4c9e7a6a5..5ab3b344c7a 100644 --- a/rs/moq-net/tests/integration/announce_to_serve.rs +++ b/rs/moq-net/tests/integration/announce_to_serve.rs @@ -31,7 +31,7 @@ const PATH: &str = "bcast"; fn produce_origin(hop: u64) -> origin::Producer { let (producer, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } /// Where the observing consumer sits relative to the publisher. diff --git a/rs/moq-net/tests/integration/answer_behind_cache.rs b/rs/moq-net/tests/integration/answer_behind_cache.rs index efd4596ad5d..a7050f9c860 100644 --- a/rs/moq-net/tests/integration/answer_behind_cache.rs +++ b/rs/moq-net/tests/integration/answer_behind_cache.rs @@ -16,7 +16,7 @@ const TIMEOUT: Duration = Duration::from_secs(5); fn produce_origin(hop: u64) -> origin::Producer { let (producer, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } fn write_group(track: &track::Producer, payload: &'static [u8]) { diff --git a/rs/moq-net/tests/integration/auth.rs b/rs/moq-net/tests/integration/auth.rs index f20b098213d..e8ce6cb5e83 100644 --- a/rs/moq-net/tests/integration/auth.rs +++ b/rs/moq-net/tests/integration/auth.rs @@ -365,7 +365,7 @@ async fn a_route_auth_renews_its_announce(version: &'static str) { fn produce_origin(hop: u64) -> origin::Producer { let (producer, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); spawn(driver); - producer + producer.with_proxy(true) } fn patterns(prefixes: &[&str]) -> Patterns { @@ -376,11 +376,15 @@ fn patterns(prefixes: &[&str]) -> Patterns { } fn grant(publish: &[&str], subscribe: &[&str]) -> Grant { - Grant { - publish: patterns(publish), - subscribe: patterns(subscribe), - expires: None, - } + grant_of(patterns(publish), patterns(subscribe)) +} + +/// A grant of exactly these paths that never expires. +fn grant_of(publish: Patterns, subscribe: Patterns) -> Grant { + let mut grant = Grant::default(); + grant.publish = publish; + grant.subscribe = subscribe; + grant } /// Wait for a watch to hold a grant satisfying `f`. @@ -1422,11 +1426,7 @@ async fn a_grant_too_large_for_one_message_is_unsupported(version: &'static str) .collect(); let mut issued = serve(pair.requests.take().unwrap(), move |token| match token { b"" => Some(grant(&["a"], &[])), - b"huge" => Some(Grant { - publish: huge.clone(), - subscribe: Patterns::new(), - expires: None, - }), + b"huge" => Some(grant_of(huge.clone(), Patterns::new())), _ => None, }); let (_, _setup) = issued.next().await.unwrap(); @@ -1462,11 +1462,7 @@ async fn a_grant_update_too_large_for_one_message_is_unsupported(version: &'stat let huge: Patterns = (0..20) .map(|i| Pattern::subtree(&format!("{i}{}", "x".repeat(4000))).unwrap()) .collect(); - updated.update(Grant { - publish: huge, - subscribe: Patterns::new(), - expires: None, - }); + updated.update(grant_of(huge, Patterns::new())); let err = token.closed().await; assert!(matches!(err, Error::Unsupported), "{err:?}"); assert_eq!(token.grant().peek(), None); @@ -1502,11 +1498,7 @@ async fn pattern_grants_arrive_exactly(version: &'static str) { b"root" => (pattern_set(&[""]), pattern_set(&["**"])), _ => return None, }; - Some(Grant { - publish, - subscribe, - expires: None, - }) + Some(grant_of(publish, subscribe)) }; let mut issued = serve(pair.requests.take().unwrap(), table); let (_, _setup) = issued.next().await.unwrap(); diff --git a/rs/moq-net/tests/integration/broadcast_close.rs b/rs/moq-net/tests/integration/broadcast_close.rs index f98e5a12988..3861375d8d3 100644 --- a/rs/moq-net/tests/integration/broadcast_close.rs +++ b/rs/moq-net/tests/integration/broadcast_close.rs @@ -18,7 +18,7 @@ fn produce_origin(hop: u64) -> moq_net::origin::Producer { let (producer, driver) = moq_net::origin::Producer::new(moq_net::origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } /// Close a published broadcast and check what `reader`'s origin answers afterwards. diff --git a/rs/moq-net/tests/integration/catalog_acquisition.rs b/rs/moq-net/tests/integration/catalog_acquisition.rs index 9019acb48cc..ba8eeb669d2 100644 --- a/rs/moq-net/tests/integration/catalog_acquisition.rs +++ b/rs/moq-net/tests/integration/catalog_acquisition.rs @@ -10,7 +10,7 @@ use support::harness::{MockConnectOptions, MockPair, connect_mock}; fn origin(hop: u64) -> origin::Producer { let (producer, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } async fn link(version: Version, from: &origin::Producer, to: &origin::Producer, cost: u64) -> MockPair { diff --git a/rs/moq-net/tests/integration/catalog_churn.rs b/rs/moq-net/tests/integration/catalog_churn.rs index 980ff19644f..3846b21d137 100644 --- a/rs/moq-net/tests/integration/catalog_churn.rs +++ b/rs/moq-net/tests/integration/catalog_churn.rs @@ -29,7 +29,7 @@ const STUCK_AFTER: Duration = Duration::from_secs(120); fn produce_origin(hop: u64) -> origin::Producer { let (producer, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } async fn link(version: Version, from: &origin::Producer, to: &origin::Producer) -> MockPair { diff --git a/rs/moq-net/tests/integration/catalog_handover.rs b/rs/moq-net/tests/integration/catalog_handover.rs index 91df5e6ae58..78d4c966c5b 100644 --- a/rs/moq-net/tests/integration/catalog_handover.rs +++ b/rs/moq-net/tests/integration/catalog_handover.rs @@ -37,7 +37,7 @@ fn timed() -> track::Info { fn produce_origin(hop: u64) -> origin::Producer { let (producer, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } async fn link(version: Version, from: &origin::Producer, to: &origin::Producer, cost: Option) -> MockPair { diff --git a/rs/moq-net/tests/integration/compress.rs b/rs/moq-net/tests/integration/compress.rs index c33ca84e0df..c34ebf281ba 100644 --- a/rs/moq-net/tests/integration/compress.rs +++ b/rs/moq-net/tests/integration/compress.rs @@ -26,14 +26,14 @@ const VERSIONS: &[&str] = &[ fn compressed() -> moq_net::track::Info { moq_net::track::Info::default() .with_timescale(moq_net::Timescale::MILLI) - .with_compress(true) + .with_compression(moq_net::track::Compression::Deflate) } fn produce_origin(hop: u64) -> moq_net::origin::Producer { let (producer, driver) = moq_net::origin::Producer::new(moq_net::origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } /// A repetitive payload, which DEFLATE shrinks, distinct per frame. @@ -195,7 +195,7 @@ async fn relay_serves_every_version() { kio::clock::timeout(TIMEOUT, async { let mut fixture = connect("moq-lite-07-wip", version).await; assert_eq!( - fixture.subscriber.info().compress, + fixture.subscriber.info().compression == moq_net::track::Compression::Deflate, !matches!(version, "moq-lite-06" | "moq-lite-03"), "{version}: compression declared" ); @@ -244,7 +244,10 @@ async fn ietf_ingress_stays_compressed_across_protocols() { for downstream in ["moq-lite-07-wip", "moq-transport-22"] { kio::clock::timeout(TIMEOUT, async { let mut fixture = connect(upstream, downstream).await; - assert!(fixture.subscriber.info().compress, "{upstream} -> {downstream}"); + assert!( + fixture.subscriber.info().compression == moq_net::track::Compression::Deflate, + "{upstream} -> {downstream}" + ); let mut group = fixture.track.append_group().unwrap(); for index in 0..3 { group @@ -300,7 +303,11 @@ async fn ietf_fetch_keeps_the_stored_form() { .unwrap() .unwrap(); let consumer = remote.track("data").unwrap(); - assert!(consumer.info().await.unwrap().compress, "{version}"); + assert_eq!( + consumer.info().await.unwrap().compression, + moq_net::track::Compression::Deflate, + "{version}" + ); let mut fetched = consumer.fetch_group(0, moq_net::group::Fetch::default()).await.unwrap(); for index in 0..3 { assert_eq!( diff --git a/rs/moq-net/tests/integration/control_stats.rs b/rs/moq-net/tests/integration/control_stats.rs index bf635fec0af..23588e9019f 100644 --- a/rs/moq-net/tests/integration/control_stats.rs +++ b/rs/moq-net/tests/integration/control_stats.rs @@ -14,7 +14,7 @@ use moq_net::{ fn origin() -> origin::Producer { let (origin, driver) = origin::Producer::new(Default::default()); spawn(driver); - origin + origin.with_proxy(true) } #[kio::test] @@ -25,7 +25,9 @@ async fn control_classes_cross_lite_and_ietf_sessions_without_counting_payload() let registry = Registry::new(Default::default()); let tier = Tier::new(moq_net::Path::from_static("internal")); let mut options = MockConnectOptions::new(version.parse().unwrap()); - options.server_stats = registry.tier(tier.clone()).session(moq_net::Path::from_static("")); + options.server_stats = registry + .tier(tier.clone()) + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static(""))); options.client_publish = Some(publisher.consume()); options.server_subscribe = Some(subscriber.clone()); let _pair = connect_mock(options).await; @@ -86,7 +88,9 @@ async fn setup_counts_under_the_admitted_stats() { let (client_transport, server_transport) = create_mock_session_pair(transport); let client = moq_net::Client::new().with_versions(version.into()); let server = moq_net::Server::new().with_versions(version.into()); - let stats = registry.tier(tier.clone()).session(moq_net::Path::from_static("")); + let stats = registry + .tier(tier.clone()) + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static(""))); let client = async { let (session, driver) = client.connect(now(), client_transport).await.unwrap(); spawn(driver); diff --git a/rs/moq-net/tests/integration/datagram.rs b/rs/moq-net/tests/integration/datagram.rs index a52c9b8edfa..5c257ce5ca3 100644 --- a/rs/moq-net/tests/integration/datagram.rs +++ b/rs/moq-net/tests/integration/datagram.rs @@ -25,7 +25,7 @@ const TRACK: &str = "audio"; fn produce_origin(hop: u64) -> origin::Producer { let (producer, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } fn millis(ms: u64) -> Timestamp { diff --git a/rs/moq-net/tests/integration/dial_split_horizon.rs b/rs/moq-net/tests/integration/dial_split_horizon.rs index ef02f794539..7ed10505225 100644 --- a/rs/moq-net/tests/integration/dial_split_horizon.rs +++ b/rs/moq-net/tests/integration/dial_split_horizon.rs @@ -40,7 +40,7 @@ async fn dial(version: Version, dialer: &origin::Producer, edge: &origin::Produc let registry = stats::Registry::new(stats::Config::new()); let session_stats = registry .tier(stats::Tier::default()) - .session(moq_net::Path::from_static("")); + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static(""))); let mut mock = moq_net::transport::memory::Config::default(); mock.protocol = Some(version.alpn().to_string()); let (client_transport, server_transport) = create_mock_session_pair(mock); diff --git a/rs/moq-net/tests/integration/drained_claim.rs b/rs/moq-net/tests/integration/drained_claim.rs index 226aefd0a41..36eaa8eddea 100644 --- a/rs/moq-net/tests/integration/drained_claim.rs +++ b/rs/moq-net/tests/integration/drained_claim.rs @@ -26,7 +26,7 @@ const TEST_TIMEOUT: Duration = Duration::from_secs(600); fn produce_origin(hop: u64) -> origin::Producer { let (producer, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } /// Have `to` pull everything `from` publishes, over a link priced at `cost`. diff --git a/rs/moq-net/tests/integration/empty_group.rs b/rs/moq-net/tests/integration/empty_group.rs index 0809356144d..bf97a3e15b0 100644 --- a/rs/moq-net/tests/integration/empty_group.rs +++ b/rs/moq-net/tests/integration/empty_group.rs @@ -21,7 +21,7 @@ const VERSIONS: &[&str] = &["moq-lite-06", "moq-transport-18", "moq-transport-22 fn produce_origin(hop: u64) -> origin::Producer { let (producer, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } #[kio::test] diff --git a/rs/moq-net/tests/integration/errored_end.rs b/rs/moq-net/tests/integration/errored_end.rs index 6954413ec10..c1315a61b17 100644 --- a/rs/moq-net/tests/integration/errored_end.rs +++ b/rs/moq-net/tests/integration/errored_end.rs @@ -21,7 +21,7 @@ fn produce_origin(hop: u64) -> moq_net::origin::Producer { let (producer, driver) = moq_net::origin::Producer::new(moq_net::origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } /// Read every group from the first, frame by frame, returning each group's sequence and diff --git a/rs/moq-net/tests/integration/extensions.rs b/rs/moq-net/tests/integration/extensions.rs index b798752d102..ad1b6f2d14b 100644 --- a/rs/moq-net/tests/integration/extensions.rs +++ b/rs/moq-net/tests/integration/extensions.rs @@ -24,7 +24,7 @@ const AUTH: [&str; 2] = ["moq-transport-18", "moq-transport-22"]; fn produce_origin(hop: u64) -> origin::Producer { let (producer, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } fn declined(f: impl FnOnce(&mut Extensions)) -> Extensions { diff --git a/rs/moq-net/tests/integration/fastest_reader.rs b/rs/moq-net/tests/integration/fastest_reader.rs index 249fdf2544b..764c6b93d2b 100644 --- a/rs/moq-net/tests/integration/fastest_reader.rs +++ b/rs/moq-net/tests/integration/fastest_reader.rs @@ -26,7 +26,7 @@ fn uncapped() -> ReceiveWindow { fn origin(hop: u64) -> origin::Producer { let (origin, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); spawn(driver); - origin + origin.with_proxy(true) } /// A publisher's track and a relay's subscription to it, over one peering. diff --git a/rs/moq-net/tests/integration/fetch_cancel.rs b/rs/moq-net/tests/integration/fetch_cancel.rs index 7e52db166da..adc81bcd4f7 100644 --- a/rs/moq-net/tests/integration/fetch_cancel.rs +++ b/rs/moq-net/tests/integration/fetch_cancel.rs @@ -23,7 +23,7 @@ fn timed() -> moq_net::track::Info { fn produce_origin(hop: u64) -> origin::Producer { let (producer, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } /// Where the reader gives up. diff --git a/rs/moq-net/tests/integration/fetch_fanout.rs b/rs/moq-net/tests/integration/fetch_fanout.rs index 8dfeebaf340..cfbf1833764 100644 --- a/rs/moq-net/tests/integration/fetch_fanout.rs +++ b/rs/moq-net/tests/integration/fetch_fanout.rs @@ -11,7 +11,7 @@ use support::harness::{MockConnectOptions, connect_mock}; fn origin(hop: u64) -> origin::Producer { let (origin, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - origin + origin.with_proxy(true) } #[kio::test] diff --git a/rs/moq-net/tests/integration/fetch_from_feed.rs b/rs/moq-net/tests/integration/fetch_from_feed.rs index e07fa0b2fe9..a28fee7a2e8 100644 --- a/rs/moq-net/tests/integration/fetch_from_feed.rs +++ b/rs/moq-net/tests/integration/fetch_from_feed.rs @@ -19,7 +19,7 @@ fn produce_origin(hop: u64) -> moq_net::origin::Producer { let (producer, driver) = moq_net::origin::Producer::new(moq_net::origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } struct Relay { diff --git a/rs/moq-net/tests/integration/fetch_only.rs b/rs/moq-net/tests/integration/fetch_only.rs index 82abda3e4d2..fa14fc57cf9 100644 --- a/rs/moq-net/tests/integration/fetch_only.rs +++ b/rs/moq-net/tests/integration/fetch_only.rs @@ -29,7 +29,7 @@ fn produce_origin(hop: u64) -> moq_net::origin::Producer { let (producer, driver) = moq_net::origin::Producer::new(moq_net::origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } async fn resolve(origin: &moq_net::origin::Producer) -> moq_net::broadcast::Consumer { diff --git a/rs/moq-net/tests/integration/fetch_pipeline.rs b/rs/moq-net/tests/integration/fetch_pipeline.rs index f4c70ad28e5..f3adc7b77bd 100644 --- a/rs/moq-net/tests/integration/fetch_pipeline.rs +++ b/rs/moq-net/tests/integration/fetch_pipeline.rs @@ -24,7 +24,7 @@ fn produce_origin(hop: u64) -> moq_net::origin::Producer { let (producer, driver) = moq_net::origin::Producer::new(moq_net::origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } async fn link(version: Version, from: &moq_net::origin::Producer, to: &moq_net::origin::Producer) -> MockPair { diff --git a/rs/moq-net/tests/integration/finished_broadcast_mock.rs b/rs/moq-net/tests/integration/finished_broadcast_mock.rs index e5b8f5c0483..975b956de5b 100644 --- a/rs/moq-net/tests/integration/finished_broadcast_mock.rs +++ b/rs/moq-net/tests/integration/finished_broadcast_mock.rs @@ -33,7 +33,7 @@ fn produce_origin(hop: u64) -> moq_net::origin::Producer { let (producer, driver) = moq_net::origin::Producer::new(moq_net::origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } /// Publish a one-frame track over one mock session, end it cleanly, and return what diff --git a/rs/moq-net/tests/integration/finite_relay.rs b/rs/moq-net/tests/integration/finite_relay.rs index efc76a9c313..724b060e8b0 100644 --- a/rs/moq-net/tests/integration/finite_relay.rs +++ b/rs/moq-net/tests/integration/finite_relay.rs @@ -45,7 +45,7 @@ fn produce_origin(hop: u64) -> moq_net::origin::Producer { let (producer, driver) = moq_net::origin::Producer::new(moq_net::origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } /// How the publisher's groups reach the relay. diff --git a/rs/moq-net/tests/integration/flights.rs b/rs/moq-net/tests/integration/flights.rs index 879907485ef..594f9545f19 100644 --- a/rs/moq-net/tests/integration/flights.rs +++ b/rs/moq-net/tests/integration/flights.rs @@ -45,7 +45,7 @@ fn origin(hop: u64, pool: &cache::Pool) -> origin::Producer { config.pool = pool.clone(); let (origin, driver) = origin::Producer::new(config); spawn(driver); - origin + origin.with_proxy(true) } /// Write `payload` once `group`'s fastest reader leaves room, or return `false` once no diff --git a/rs/moq-net/tests/integration/goaway.rs b/rs/moq-net/tests/integration/goaway.rs index 5ddaa428c03..6d158565022 100644 --- a/rs/moq-net/tests/integration/goaway.rs +++ b/rs/moq-net/tests/integration/goaway.rs @@ -24,7 +24,7 @@ fn timed() -> moq_net::track::Info { fn produce_origin() -> moq_net::origin::Producer { let (producer, driver) = moq_net::origin::Producer::new(moq_net::origin::Config::default()); support::harness::spawn(driver); - producer + producer.with_proxy(true) } /// Maximum time any single test may run before being treated as a deadlock. diff --git a/rs/moq-net/tests/integration/group_order.rs b/rs/moq-net/tests/integration/group_order.rs index 6771c2d77e4..7fdeddd9040 100644 --- a/rs/moq-net/tests/integration/group_order.rs +++ b/rs/moq-net/tests/integration/group_order.rs @@ -28,7 +28,7 @@ fn produce_origin(hop: u64) -> moq_net::origin::Producer { let (producer, driver) = moq_net::origin::Producer::new(moq_net::origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } /// Connect a session serving `publish` to a fresh subscribing origin. diff --git a/rs/moq-net/tests/integration/history_groups.rs b/rs/moq-net/tests/integration/history_groups.rs index 816f6d4e8b0..12e2f9a5e34 100644 --- a/rs/moq-net/tests/integration/history_groups.rs +++ b/rs/moq-net/tests/integration/history_groups.rs @@ -34,7 +34,7 @@ fn produce_origin(hop: u64) -> moq_net::origin::Producer { let (producer, driver) = moq_net::origin::Producer::new(moq_net::origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } /// Publish a finished group 5 (three frames) then an open group 6 (two frames), optionally diff --git a/rs/moq-net/tests/integration/idle_cancel_refetch.rs b/rs/moq-net/tests/integration/idle_cancel_refetch.rs index 5425cee0e5d..c1625b63d5e 100644 --- a/rs/moq-net/tests/integration/idle_cancel_refetch.rs +++ b/rs/moq-net/tests/integration/idle_cancel_refetch.rs @@ -16,7 +16,7 @@ fn produce_origin(hop: u64) -> moq_net::origin::Producer { let (producer, driver) = moq_net::origin::Producer::new(moq_net::origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } #[kio::test] diff --git a/rs/moq-net/tests/integration/idle_session.rs b/rs/moq-net/tests/integration/idle_session.rs index 701746fcd2b..477f5f08686 100644 --- a/rs/moq-net/tests/integration/idle_session.rs +++ b/rs/moq-net/tests/integration/idle_session.rs @@ -57,7 +57,7 @@ async fn viewer( fn origin() -> origin::Producer { let (origin, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(1).unwrap())); support::harness::spawn(driver); - origin + origin.with_proxy(true) } #[kio::test] @@ -181,7 +181,7 @@ async fn wire_collection_never_arms_the_idle_sampler() { let mut options = MockConnectOptions::new(version.parse().unwrap()); options.server_stats = registry .tier(Default::default()) - .session(moq_net::Path::from_static("room")); + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static("room"))); options.server_polls = Some(polls.clone()); let pair = connect_mock(options).await; kio::clock::sleep(Duration::from_secs(1)).await; @@ -191,7 +191,7 @@ async fn wire_collection_never_arms_the_idle_sampler() { pair.server_transport.wire().set_sent_bytes(tick); pair.server_transport.wire().set_received_bytes(tick * 2); let mut report = moq_net::stats::Report::default(); - registry.report(&mut report); + registry.report(&mut report, moq_net::time::Instant::now()); assert_eq!( (report.sessions[0].presence.wire_tx, report.sessions[0].presence.wire_rx), (tick, tick * 2) diff --git a/rs/moq-net/tests/integration/instance.rs b/rs/moq-net/tests/integration/instance.rs index c5103b3f857..ee64af26bd8 100644 --- a/rs/moq-net/tests/integration/instance.rs +++ b/rs/moq-net/tests/integration/instance.rs @@ -13,7 +13,7 @@ use support::harness::{MockConnectOptions, MockPair, connect_mock}; fn produce_origin(hop: u64) -> origin::Producer { let (producer, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } async fn link(version: Version, from: &origin::Producer, to: &origin::Producer) -> MockPair { diff --git a/rs/moq-net/tests/integration/late_lower_group.rs b/rs/moq-net/tests/integration/late_lower_group.rs index c78b779c143..d7b51aac9bc 100644 --- a/rs/moq-net/tests/integration/late_lower_group.rs +++ b/rs/moq-net/tests/integration/late_lower_group.rs @@ -40,7 +40,7 @@ fn produce_origin(hop: u64) -> moq_net::origin::Producer { let (producer, driver) = moq_net::origin::Producer::new(moq_net::origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } /// Four frames starting at `sequence` seconds, so a group created late still starts diff --git a/rs/moq-net/tests/integration/lazy_discovery.rs b/rs/moq-net/tests/integration/lazy_discovery.rs index 81022bdbd7e..00487b2ffde 100644 --- a/rs/moq-net/tests/integration/lazy_discovery.rs +++ b/rs/moq-net/tests/integration/lazy_discovery.rs @@ -26,7 +26,7 @@ const ANNOUNCE: u8 = 1; fn produce_origin(hop: u64) -> origin::Producer { let (producer, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } /// A server publishing `a/x` and `b/y`, and a client fed into `subscriber` asking diff --git a/rs/moq-net/tests/integration/mesh_withdraw.rs b/rs/moq-net/tests/integration/mesh_withdraw.rs index ffdbb0cb14b..60e5a9ae183 100644 --- a/rs/moq-net/tests/integration/mesh_withdraw.rs +++ b/rs/moq-net/tests/integration/mesh_withdraw.rs @@ -30,7 +30,7 @@ fn produce(hop: u64, hold: Duration) -> origin::Producer { config.update_hold = hold; let (producer, driver) = origin::Producer::new(config); support::harness::spawn(driver); - producer + producer.with_proxy(true) } /// `n` relays meshed over `edges`, watched from the last one. @@ -291,7 +291,7 @@ impl Cluster { config.hop = std::num::NonZeroU64::new(id).unwrap(); let (origin, driver) = origin::Producer::new(config); support::harness::spawn(driver); - origin + origin.with_proxy(true) }) .collect(); let mut pairs = Vec::new(); @@ -725,7 +725,7 @@ async fn a_node_that_does_not_proxy_keeps_what_it_learned_over_lite06() { let lite07: Version = "moq-lite-07-wip".parse().unwrap(); let lite06: Version = "moq-lite-06".parse().unwrap(); let first = produce_origin(1); - let app = produce_origin(2); + let app = produce_origin(2).with_proxy(false); let second = produce_origin(3); let mut pairs = Vec::new(); for (version, relay) in [(lite06, &first), (lite07, &second)] { @@ -734,7 +734,6 @@ async fn a_node_that_does_not_proxy_keeps_what_it_learned_over_lite06() { options.client_subscribe = Some(app.clone()); options.server_publish = Some(relay.consume().with_hidden(true)); options.server_subscribe = Some(relay.clone().with_link(origin::Link::Peer)); - options.proxy = false; pairs.push(connect_mock(options).await); } diff --git a/rs/moq-net/tests/integration/mount.rs b/rs/moq-net/tests/integration/mount.rs index 5e988744579..62f3d94e8dc 100644 --- a/rs/moq-net/tests/integration/mount.rs +++ b/rs/moq-net/tests/integration/mount.rs @@ -16,7 +16,7 @@ const TEST_TIMEOUT: Duration = Duration::from_secs(600); fn produce_origin(hop: u64) -> origin::Producer { let (producer, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } /// Publish a broadcast at `path` whose `video` track carries the path. @@ -50,8 +50,8 @@ fn tenant(origin: &origin::Producer, root: &str) -> origin::Consumer { .unwrap() .scope(root, &Patterns::from(Pattern::all())) .unwrap() - .consume() .with_proxy(true) + .consume() } /// Have `to` read `from` through a session. diff --git a/rs/moq-net/tests/integration/multi_cdn.rs b/rs/moq-net/tests/integration/multi_cdn.rs index 62338a6b746..9f6b86e4af0 100644 --- a/rs/moq-net/tests/integration/multi_cdn.rs +++ b/rs/moq-net/tests/integration/multi_cdn.rs @@ -37,7 +37,7 @@ const A_COST: u64 = 100; fn produce_origin(hop: u64) -> origin::Producer { let (producer, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } /// Let every task settle. Time is paused, so this returns once the runtime is idle. diff --git a/rs/moq-net/tests/integration/partial_group.rs b/rs/moq-net/tests/integration/partial_group.rs index 1f908a659c9..c7259e12496 100644 --- a/rs/moq-net/tests/integration/partial_group.rs +++ b/rs/moq-net/tests/integration/partial_group.rs @@ -24,7 +24,7 @@ fn produce_origin(hop: u64) -> moq_net::origin::Producer { let (producer, driver) = moq_net::origin::Producer::new(moq_net::origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } /// Publish an unfinished group 0 that stalls past the budget after its only frame, and diff --git a/rs/moq-net/tests/integration/quiet_catalog.rs b/rs/moq-net/tests/integration/quiet_catalog.rs index cc13fbebb2f..d2156d62f7c 100644 --- a/rs/moq-net/tests/integration/quiet_catalog.rs +++ b/rs/moq-net/tests/integration/quiet_catalog.rs @@ -27,7 +27,7 @@ const LITE: &[&str] = &["moq-lite-06", "moq-lite-07-wip"]; fn produce_origin(hop: u64) -> origin::Producer { let (producer, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } async fn link(version: Version, from: &origin::Producer, to: &origin::Producer) -> MockPair { diff --git a/rs/moq-net/tests/integration/range_anchors.rs b/rs/moq-net/tests/integration/range_anchors.rs index 2eab4eec7c0..f5418981587 100644 --- a/rs/moq-net/tests/integration/range_anchors.rs +++ b/rs/moq-net/tests/integration/range_anchors.rs @@ -34,7 +34,7 @@ fn produce_origin(hop: u64) -> moq_net::origin::Producer { let (producer, driver) = moq_net::origin::Producer::new(moq_net::origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } fn millis(ms: u64) -> Timestamp { diff --git a/rs/moq-net/tests/integration/range_fill.rs b/rs/moq-net/tests/integration/range_fill.rs index 3a035fcbb3d..d262661fa0f 100644 --- a/rs/moq-net/tests/integration/range_fill.rs +++ b/rs/moq-net/tests/integration/range_fill.rs @@ -26,7 +26,7 @@ fn origin(hop: u64, pool: Option) -> moq_net::origin::Producer { } let (producer, driver) = moq_net::origin::Producer::new(config); support::harness::spawn(driver); - producer + producer.with_proxy(true) } /// The publisher's groups, one per second, with no publisher max age. diff --git a/rs/moq-net/tests/integration/range_read.rs b/rs/moq-net/tests/integration/range_read.rs index 21e09b5e680..85aff5ffdd7 100644 --- a/rs/moq-net/tests/integration/range_read.rs +++ b/rs/moq-net/tests/integration/range_read.rs @@ -18,7 +18,7 @@ fn produce_origin(hop: u64) -> moq_net::origin::Producer { let (producer, driver) = moq_net::origin::Producer::new(moq_net::origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } fn write_group(track: &mut moq_net::track::Producer, sequence: u64) { diff --git a/rs/moq-net/tests/integration/received_rewind.rs b/rs/moq-net/tests/integration/received_rewind.rs index 8dc91f60caa..8c7d79c9bd2 100644 --- a/rs/moq-net/tests/integration/received_rewind.rs +++ b/rs/moq-net/tests/integration/received_rewind.rs @@ -33,7 +33,7 @@ fn produce_origin(hop: u64) -> moq_net::origin::Producer { let (producer, driver) = moq_net::origin::Producer::new(moq_net::origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } fn write_group(track: &moq_net::track::Producer, sequence: u64) { diff --git a/rs/moq-net/tests/integration/rejoin.rs b/rs/moq-net/tests/integration/rejoin.rs index 4f9954de887..5e12f0d5d66 100644 --- a/rs/moq-net/tests/integration/rejoin.rs +++ b/rs/moq-net/tests/integration/rejoin.rs @@ -25,7 +25,7 @@ fn produce_origin(hop: u64) -> moq_net::origin::Producer { let (producer, driver) = moq_net::origin::Producer::new(moq_net::origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } async fn read_all(group: &mut group::Consumer) -> moq_net::Result>> { diff --git a/rs/moq-net/tests/integration/relay_upstream_close.rs b/rs/moq-net/tests/integration/relay_upstream_close.rs index 93e8e1e7d3f..80c536ba01c 100644 --- a/rs/moq-net/tests/integration/relay_upstream_close.rs +++ b/rs/moq-net/tests/integration/relay_upstream_close.rs @@ -52,7 +52,7 @@ fn produce_origin(hop: u64) -> moq_net::origin::Producer { let (producer, driver) = moq_net::origin::Producer::new(moq_net::origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } /// How the publisher's session to the relay ends. diff --git a/rs/moq-net/tests/integration/replacement.rs b/rs/moq-net/tests/integration/replacement.rs index 08aa479860b..ff8d6de5d29 100644 --- a/rs/moq-net/tests/integration/replacement.rs +++ b/rs/moq-net/tests/integration/replacement.rs @@ -27,7 +27,7 @@ const TEST_TIMEOUT: Duration = Duration::from_secs(60); fn produce_origin(hop: u64) -> origin::Producer { let (producer, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } /// Have `to` pull everything `from` publishes, over a new session. diff --git a/rs/moq-net/tests/integration/request_caps.rs b/rs/moq-net/tests/integration/request_caps.rs index 46788353dda..9e90b233bf9 100644 --- a/rs/moq-net/tests/integration/request_caps.rs +++ b/rs/moq-net/tests/integration/request_caps.rs @@ -21,7 +21,7 @@ fn produce_origin(hop: u64) -> moq_net::origin::Producer { let (producer, driver) = moq_net::origin::Producer::new(moq_net::origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } /// A server publishing `bcast` with `tracks`, and a client subscribed to its origin. diff --git a/rs/moq-net/tests/integration/route_change.rs b/rs/moq-net/tests/integration/route_change.rs index 9b7a6013546..d2b492a9b75 100644 --- a/rs/moq-net/tests/integration/route_change.rs +++ b/rs/moq-net/tests/integration/route_change.rs @@ -41,7 +41,7 @@ const FRAMES: u64 = 4; pub(super) fn produce_origin(hop: u64) -> origin::Producer { let (producer, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } /// Have `to` pull everything `from` publishes. @@ -1161,7 +1161,13 @@ async fn compression_changes_behind_a_relay(compress: bool) { .unwrap(); let track = broadcast .broadcast() - .create_track("video", timed().with_compress(compress)) + .create_track( + "video", + timed().with_compression(match compress { + true => moq_net::track::Compression::Deflate, + false => moq_net::track::Compression::None, + }), + ) .unwrap(); broadcast.announce().unwrap(); let link = priced_link(version, &publisher, &relay, cost).await; diff --git a/rs/moq-net/tests/integration/segmented_frame.rs b/rs/moq-net/tests/integration/segmented_frame.rs index c40d0e70128..ff855daa112 100644 --- a/rs/moq-net/tests/integration/segmented_frame.rs +++ b/rs/moq-net/tests/integration/segmented_frame.rs @@ -20,7 +20,7 @@ const SIZE: usize = 5 * 1024 * 1024 / 2; fn origin(hop: u64) -> origin::Producer { let (origin, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); spawn(driver); - origin + origin.with_proxy(true) } #[kio::test] diff --git a/rs/moq-net/tests/integration/session_close.rs b/rs/moq-net/tests/integration/session_close.rs index d2c85b6d3ca..8991869dab5 100644 --- a/rs/moq-net/tests/integration/session_close.rs +++ b/rs/moq-net/tests/integration/session_close.rs @@ -23,7 +23,7 @@ fn produce_origin(hop: u64) -> moq_net::origin::Producer { let (producer, driver) = moq_net::origin::Producer::new(moq_net::origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } /// The payloads the server read, then how the track ended. @@ -462,7 +462,7 @@ async fn ended(version: &str, close: impl FnOnce(&MockPair)) -> (Error, moq_net: let mut options = MockConnectOptions::new(version.parse().unwrap()); options.server_stats = registry .tier(Default::default()) - .session(moq_net::Path::from_static("room")); + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static("room"))); let pair = connect_mock(options).await; close(&pair); let err = kio::clock::timeout(TIMEOUT, pair.server.closed()) diff --git a/rs/moq-net/tests/integration/settled_end_survives_abort.rs b/rs/moq-net/tests/integration/settled_end_survives_abort.rs index 28e1ebf1c41..4a53b6acb9b 100644 --- a/rs/moq-net/tests/integration/settled_end_survives_abort.rs +++ b/rs/moq-net/tests/integration/settled_end_survives_abort.rs @@ -21,7 +21,7 @@ fn produce_origin(hop: u64) -> moq_net::origin::Producer { let (producer, driver) = moq_net::origin::Producer::new(moq_net::origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } const GROUPS: u64 = 2; diff --git a/rs/moq-net/tests/integration/slow_joiner.rs b/rs/moq-net/tests/integration/slow_joiner.rs index 684702222c1..4d77fb72116 100644 --- a/rs/moq-net/tests/integration/slow_joiner.rs +++ b/rs/moq-net/tests/integration/slow_joiner.rs @@ -21,7 +21,7 @@ const GROUPS: u64 = 5; fn origin(hop: u64) -> origin::Producer { let (origin, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); spawn(driver); - origin + origin.with_proxy(true) } /// The groups a reader subscribed with `budget` receives once it resumes from a stall diff --git a/rs/moq-net/tests/integration/socket.rs b/rs/moq-net/tests/integration/socket.rs index 2bd90f5f6d1..f4de1ac8219 100644 --- a/rs/moq-net/tests/integration/socket.rs +++ b/rs/moq-net/tests/integration/socket.rs @@ -26,7 +26,7 @@ const IETF: &str = "moq-transport-18"; fn origin(hop: u64) -> origin::Producer { let (origin, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); spawn(driver); - origin + origin.with_proxy(true) } /// A relay and the clients connected to it. diff --git a/rs/moq-net/tests/integration/source_errors.rs b/rs/moq-net/tests/integration/source_errors.rs index d2bfdceb2f3..2734869f9b5 100644 --- a/rs/moq-net/tests/integration/source_errors.rs +++ b/rs/moq-net/tests/integration/source_errors.rs @@ -25,7 +25,7 @@ fn produce_origin(hop: u64) -> moq_net::origin::Producer { let (producer, driver) = moq_net::origin::Producer::new(moq_net::origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } /// A publisher announcing `bcast`, a relay subscribed to it, and a far origin subscribed diff --git a/rs/moq-net/tests/integration/stream_credit.rs b/rs/moq-net/tests/integration/stream_credit.rs index 8ade46e4814..e6ca9433073 100644 --- a/rs/moq-net/tests/integration/stream_credit.rs +++ b/rs/moq-net/tests/integration/stream_credit.rs @@ -12,7 +12,7 @@ use crate::support::harness::{MockConnectOptions, connect_mock, spawn}; fn origin(hop: u64) -> origin::Producer { let (origin, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); spawn(driver); - origin + origin.with_proxy(true) } #[kio::test] diff --git a/rs/moq-net/tests/integration/subscribe_priority.rs b/rs/moq-net/tests/integration/subscribe_priority.rs index 4abf1a02f9e..a3402d2a571 100644 --- a/rs/moq-net/tests/integration/subscribe_priority.rs +++ b/rs/moq-net/tests/integration/subscribe_priority.rs @@ -21,7 +21,7 @@ const HIGH: i8 = 100; fn produce_origin(hop: u64) -> origin::Producer { let (producer, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } /// Wait until the subscription `track` serves asks for `want`. diff --git a/rs/moq-net/tests/integration/subscribe_ranges.rs b/rs/moq-net/tests/integration/subscribe_ranges.rs index 9dc5994530f..ec53e7424e9 100644 --- a/rs/moq-net/tests/integration/subscribe_ranges.rs +++ b/rs/moq-net/tests/integration/subscribe_ranges.rs @@ -22,7 +22,7 @@ fn produce_origin(hop: u64) -> moq_net::origin::Producer { let (producer, driver) = moq_net::origin::Producer::new(moq_net::origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } /// A millisecond track with no publisher max age, so ranges reach its superseded groups. diff --git a/rs/moq-net/tests/integration/subscribe_tracks.rs b/rs/moq-net/tests/integration/subscribe_tracks.rs index 78a7b53e8c3..0f1d964679c 100644 --- a/rs/moq-net/tests/integration/subscribe_tracks.rs +++ b/rs/moq-net/tests/integration/subscribe_tracks.rs @@ -36,7 +36,7 @@ fn produce_origin(hop: u64) -> moq_net::origin::Producer { let (producer, driver) = moq_net::origin::Producer::new(moq_net::origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } /// A client publishing one track to a server subscribed to it, plus the payloads the diff --git a/rs/moq-net/tests/integration/subscribe_with_track.rs b/rs/moq-net/tests/integration/subscribe_with_track.rs index e75a7a8e8dd..4cb6c031f08 100644 --- a/rs/moq-net/tests/integration/subscribe_with_track.rs +++ b/rs/moq-net/tests/integration/subscribe_with_track.rs @@ -41,7 +41,7 @@ enum Arrival { fn produce_origin(hop: u64) -> origin::Producer { let (producer, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } /// `subscriber` reads what `publisher` serves, over a link with [`LATENCY`] each way. diff --git a/rs/moq-net/tests/integration/subscriber_max_age.rs b/rs/moq-net/tests/integration/subscriber_max_age.rs index ee006fdf82c..ef30fec46ad 100644 --- a/rs/moq-net/tests/integration/subscriber_max_age.rs +++ b/rs/moq-net/tests/integration/subscriber_max_age.rs @@ -11,7 +11,7 @@ use crate::support::harness::{peer, spawn}; fn origin(hop: u64) -> origin::Producer { let (origin, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); spawn(driver); - origin + origin.with_proxy(true) } async fn budget(track: &mut track::Producer, millis: u64, version: Version) { diff --git a/rs/moq-net/tests/integration/subscription_end_integrity.rs b/rs/moq-net/tests/integration/subscription_end_integrity.rs index ffb13a87f1f..ebf1268131c 100644 --- a/rs/moq-net/tests/integration/subscription_end_integrity.rs +++ b/rs/moq-net/tests/integration/subscription_end_integrity.rs @@ -39,7 +39,7 @@ fn produce_origin(hop: u64) -> moq_net::origin::Producer { let (producer, driver) = moq_net::origin::Producer::new(moq_net::origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } /// Let the drivers run until nothing is runnable: under paused time an idle runtime diff --git a/rs/moq-net/tests/integration/support/harness.rs b/rs/moq-net/tests/integration/support/harness.rs index 2fb68611a8d..9d1405cc114 100644 --- a/rs/moq-net/tests/integration/support/harness.rs +++ b/rs/moq-net/tests/integration/support/harness.rs @@ -109,9 +109,6 @@ pub struct MockConnectOptions { pub client_implementation: Option, /// What the server advertises as its implementation, when not the default. pub server_implementation: Option, - /// Whether both sides forward the routes they learned from other sessions - /// (moq-lite-07): on, since these tests build their relays from plain origins. - pub proxy: bool, } impl MockConnectOptions { @@ -136,7 +133,6 @@ impl MockConnectOptions { client_discovers_all: true, server_gate: None, client_implementation: None, - proxy: true, server_implementation: None, } } @@ -186,7 +182,7 @@ pub async fn connect_mock(opts: MockConnectOptions) -> MockPair { client = client.with_implementation(implementation); } if let Some(publish) = &opts.client_publish { - client = client.with_publisher(publish.clone().with_proxy(opts.proxy)); + client = client.with_publisher(publish.clone()); } let client_discovery = opts .client_subscribe @@ -202,7 +198,7 @@ pub async fn connect_mock(opts: MockConnectOptions) -> MockPair { .with_versions(opts.version.into()) .with_extensions(opts.server_extensions); if let Some(publish) = &opts.server_publish { - server = server.with_publisher(publish.clone().with_proxy(opts.proxy)); + server = server.with_publisher(publish.clone()); } if let Some(subscribe) = opts.server_subscribe { server = server.with_subscriber(subscribe); diff --git a/rs/moq-net/tests/integration/synced.rs b/rs/moq-net/tests/integration/synced.rs index 0d043420e80..149c57f499c 100644 --- a/rs/moq-net/tests/integration/synced.rs +++ b/rs/moq-net/tests/integration/synced.rs @@ -18,7 +18,7 @@ const SETTLE: Duration = Duration::from_secs(1); fn produce_origin(hop: u64) -> origin::Producer { let (producer, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } /// Read events until the consumer syncs, returning the prefixes then announced. diff --git a/rs/moq-net/tests/integration/track_abort_over_session.rs b/rs/moq-net/tests/integration/track_abort_over_session.rs index 90b3d561b33..3041443a262 100644 --- a/rs/moq-net/tests/integration/track_abort_over_session.rs +++ b/rs/moq-net/tests/integration/track_abort_over_session.rs @@ -19,7 +19,7 @@ fn produce_origin(hop: u64) -> moq_net::origin::Producer { let (producer, driver) = moq_net::origin::Producer::new(moq_net::origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } /// A group reader alone must see the abort, without polling the next group. diff --git a/rs/moq-net/tests/integration/track_info_cancel.rs b/rs/moq-net/tests/integration/track_info_cancel.rs index 3f7a405db97..ca5debfa3ba 100644 --- a/rs/moq-net/tests/integration/track_info_cancel.rs +++ b/rs/moq-net/tests/integration/track_info_cancel.rs @@ -18,7 +18,7 @@ use support::harness::{MockConnectOptions, connect_mock, peer}; fn produce_origin(hop: u64) -> origin::Producer { let (producer, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } /// `relays` relays between the publisher and the reader. diff --git a/rs/moq-net/tests/integration/track_stream_demand.rs b/rs/moq-net/tests/integration/track_stream_demand.rs index 9994bd8eb53..a40bfb75120 100644 --- a/rs/moq-net/tests/integration/track_stream_demand.rs +++ b/rs/moq-net/tests/integration/track_stream_demand.rs @@ -32,7 +32,7 @@ const STARTUP: Duration = Duration::from_millis(5); fn produce_origin(hop: u64) -> origin::Producer { let (producer, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } /// `subscriber` reads what `publisher` serves, over a link with [`LATENCY`] each way. diff --git a/rs/moq-net/tests/integration/track_tail.rs b/rs/moq-net/tests/integration/track_tail.rs index c40bf3916f7..205d875436f 100644 --- a/rs/moq-net/tests/integration/track_tail.rs +++ b/rs/moq-net/tests/integration/track_tail.rs @@ -60,7 +60,7 @@ fn produce_origin(hop: u64) -> moq_net::origin::Producer { let (producer, driver) = moq_net::origin::Producer::new(moq_net::origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } struct Outcome { diff --git a/rs/moq-net/tests/integration/tracks.rs b/rs/moq-net/tests/integration/tracks.rs index 41fc17741bb..9c1370fa8b6 100644 --- a/rs/moq-net/tests/integration/tracks.rs +++ b/rs/moq-net/tests/integration/tracks.rs @@ -17,7 +17,7 @@ fn produce_origin(hop: u64) -> moq_net::origin::Producer { let (producer, driver) = moq_net::origin::Producer::new(moq_net::origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } fn lite07() -> Version { @@ -106,7 +106,7 @@ async fn a_listing_carries_track_info() { .with_max_age(Duration::from_secs(3)) .with_priority(9) .with_refresh(4) - .with_compress(true); + .with_compression(moq_net::track::Compression::Deflate); let _a = broadcast.broadcast().create_track("a", info).unwrap(); broadcast.announce().unwrap(); @@ -125,7 +125,7 @@ async fn a_listing_carries_track_info() { assert_eq!(info.max_age, Some(Duration::from_secs(3))); assert_eq!(info.priority, 9); assert_eq!(info.refresh, Some(4)); - assert!(info.compress); + assert_eq!(info.compression, moq_net::track::Compression::Deflate); } /// A listed track is a track like any other: a SUBSCRIBE from the listing reads the diff --git a/rs/moq-net/tests/integration/tracks_ietf.rs b/rs/moq-net/tests/integration/tracks_ietf.rs index cc78320d4fe..a8c2040c506 100644 --- a/rs/moq-net/tests/integration/tracks_ietf.rs +++ b/rs/moq-net/tests/integration/tracks_ietf.rs @@ -30,7 +30,7 @@ fn produce_origin(hop: u64) -> moq_net::origin::Producer { let (producer, driver) = moq_net::origin::Producer::new(moq_net::origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } /// The next event as `+name`, `-name`, `synced`, `end`, or `error: ..`. diff --git a/rs/moq-net/tests/integration/unannounce_release.rs b/rs/moq-net/tests/integration/unannounce_release.rs index 0e6d6ba56ff..6d19bf330f2 100644 --- a/rs/moq-net/tests/integration/unannounce_release.rs +++ b/rs/moq-net/tests/integration/unannounce_release.rs @@ -14,7 +14,7 @@ fn produce_origin(hop: u64) -> moq_net::origin::Producer { let (producer, driver) = moq_net::origin::Producer::new(moq_net::origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } async fn release(version: Version) { diff --git a/rs/moq-net/tests/integration/untimed.rs b/rs/moq-net/tests/integration/untimed.rs index 2e2f8ae0543..1a862b836d6 100644 --- a/rs/moq-net/tests/integration/untimed.rs +++ b/rs/moq-net/tests/integration/untimed.rs @@ -55,7 +55,7 @@ const VERSIONS: &[&str] = &[ fn produce_origin(hop: u64) -> origin::Producer { let (producer, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } fn millis(ms: u64) -> Timestamp { diff --git a/rs/moq-net/tests/integration/warm_backfill.rs b/rs/moq-net/tests/integration/warm_backfill.rs index 78c06d0072f..2edf94242ed 100644 --- a/rs/moq-net/tests/integration/warm_backfill.rs +++ b/rs/moq-net/tests/integration/warm_backfill.rs @@ -31,7 +31,7 @@ const VERSIONS: &[&str] = &["moq-lite-05", "moq-lite-06", "moq-lite-07-wip"]; fn origin(hop: u64) -> origin::Producer { let (origin, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); spawn(driver); - origin + origin.with_proxy(true) } async fn subscribe(relay: &origin::Producer) -> track::Subscriber { diff --git a/rs/moq-net/tests/integration/wide_hop.rs b/rs/moq-net/tests/integration/wide_hop.rs index a42bd3b0c94..ba93323c66b 100644 --- a/rs/moq-net/tests/integration/wide_hop.rs +++ b/rs/moq-net/tests/integration/wide_hop.rs @@ -13,7 +13,7 @@ fn produce(hop: u64) -> origin::Producer { config.pool = cache::Pool::unbounded(); let (producer, driver) = origin::Producer::new(config); support::harness::spawn(driver); - producer + producer.with_proxy(true) } /// A draft-18 peer declaring `u64::MAX` keeps its session and its place in the path. diff --git a/rs/moq-net/tests/integration/wide_sequence.rs b/rs/moq-net/tests/integration/wide_sequence.rs index 36d486eb278..71e26d1f5f9 100644 --- a/rs/moq-net/tests/integration/wide_sequence.rs +++ b/rs/moq-net/tests/integration/wide_sequence.rs @@ -77,7 +77,7 @@ fn produce_origin(hop: u64) -> moq_net::origin::Producer { let (producer, driver) = moq_net::origin::Producer::new(moq_net::origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } /// The relay accepts the wide sequence from lite-07, refuses that subscription to the diff --git a/rs/moq-net/tests/integration/widened_max_age.rs b/rs/moq-net/tests/integration/widened_max_age.rs index f3b147f4d6e..4fddb8bb625 100644 --- a/rs/moq-net/tests/integration/widened_max_age.rs +++ b/rs/moq-net/tests/integration/widened_max_age.rs @@ -38,7 +38,7 @@ const VERSION: &str = "moq-lite-07-wip"; fn origin(hop: u64) -> origin::Producer { let (origin, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); spawn(driver); - origin + origin.with_proxy(true) } /// A millisecond track with no publisher max age, so only a reader's budget skips its groups. @@ -307,7 +307,7 @@ async fn wider_newcomers_after_the_first_pull_nothing_upstream() { options.server_subscribe = Some(publisher.clone()); options.server_stats = registry .tier(moq_net::stats::Tier::new(moq_net::Path::from_static("upstream"))) - .session(moq_net::Path::from_static("")); + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static(""))); let _upstream = connect_mock(options).await; let broadcast = publisher .route("live", moq_net::origin::RouteOptions::hidden()) diff --git a/rs/moq-relay/src/auth.rs b/rs/moq-relay/src/auth.rs index 65a213967b7..e264fd97260 100644 --- a/rs/moq-relay/src/auth.rs +++ b/rs/moq-relay/src/auth.rs @@ -707,11 +707,10 @@ impl Lease { subscribe = %join(&fresh.subscribe), "grant changed; re-authorizing the session", ); - session.authorize(&moq_net::auth::Grant { - publish: fresh.publish.clone(), - subscribe: fresh.subscribe.clone(), - expires: None, - }); + let mut grant = moq_net::auth::Grant::default(); + grant.publish = fresh.publish.clone(); + grant.subscribe = fresh.subscribe.clone(); + session.authorize(&grant); self.token.publish = fresh.publish; self.token.subscribe = fresh.subscribe; } diff --git a/rs/moq-relay/src/auth/admission_tests.rs b/rs/moq-relay/src/auth/admission_tests.rs index c010b7281b7..99f5129c182 100644 --- a/rs/moq-relay/src/auth/admission_tests.rs +++ b/rs/moq-relay/src/auth/admission_tests.rs @@ -174,7 +174,7 @@ async fn gateway_admission_refuses_once_in_the_shared_stats_registry() { assert_eq!(values[0].1.sessions_refused.refused, 1); assert_eq!(values[0].1.sessions_started, 0); let mut report = moq_net::stats::Report::default(); - registry.report(&mut report); + registry.report(&mut report, moq_net::time::Instant::now()); assert_eq!( report.sessions[0].label.as_str(), "", @@ -210,7 +210,7 @@ async fn embedded_expired_refusals_keep_verified_root_and_tier() { assert_eq!(actual, expected); } let mut report = moq_net::stats::Report::default(); - registry.report(&mut report); + registry.report(&mut report, moq_net::time::Instant::now()); assert_eq!(report.sessions.len(), 2); for entry in report.sessions { assert!(["", "edge"].contains(&entry.tier.as_str())); diff --git a/rs/moq-relay/src/auth/refresh.rs b/rs/moq-relay/src/auth/refresh.rs index 0876f37163f..7f6691c31fa 100644 --- a/rs/moq-relay/src/auth/refresh.rs +++ b/rs/moq-relay/src/auth/refresh.rs @@ -82,19 +82,15 @@ impl Credential { } fn wire(&self, role: Option) -> auth::Grant { - auth::Grant { - publish: if role == Some(Role::Subscriber) { - Default::default() - } else { - self.grant.publish.clone() - }, - subscribe: if role == Some(Role::Publisher) { - Default::default() - } else { - self.grant.subscribe.clone() - }, - expires: self.expires, + let mut grant = auth::Grant::default(); + if role != Some(Role::Subscriber) { + grant.publish = self.grant.publish.clone(); } + if role != Some(Role::Publisher) { + grant.subscribe = self.grant.subscribe.clone(); + } + grant.expires = self.expires; + grant } } @@ -688,7 +684,7 @@ mod tests { let registry = moq_net::stats::Registry::new(Default::default()); let stats = registry .tier(moq_net::stats::Tier::default()) - .session(moq_net::Path::from_static("room")); + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static("room"))); let lease = super::super::Lease::new("/room", consumer) .unwrap() .with_stats(stats.clone()); @@ -905,7 +901,7 @@ mod tests { let registry = moq_net::stats::Registry::new(Default::default()); let stats = registry .tier(moq_net::stats::Tier::default()) - .session(moq_net::Path::from_static("room")); + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static("room"))); let lease = super::super::Lease::new("/room", consumer).unwrap().with_stats(stats); let (client, supervising) = sessions(lease).await; producer.revoke(reason.clone()); @@ -1118,7 +1114,7 @@ mod tests { let registry = moq_net::stats::Registry::new(Default::default()); let stats = registry .tier(moq_net::stats::Tier::default()) - .session(moq_net::Path::from_static("room")); + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static("room"))); let (client, session, mut lease) = connect(lease.unwrap().with_stats(stats)).await; let auth = client.auth(); let (token, ()) = tokio::join!( diff --git a/rs/moq-relay/src/cluster.rs b/rs/moq-relay/src/cluster.rs index 87f6f873275..1d412effb0e 100644 --- a/rs/moq-relay/src/cluster.rs +++ b/rs/moq-relay/src/cluster.rs @@ -1567,7 +1567,10 @@ impl Cluster { ))); } - let stats = self.stats.tier(token.tier.clone()).session(&token.label); + let stats = self + .stats + .tier(token.tier.clone()) + .session(moq_net::stats::SessionInfo::new(&token.label)); tracing::info!(transport = %request.transport, ?request.role, tier = %token.tier, root = ?token.root, publish = ?publisher.as_ref().map(origin::Producer::allowed), subscribe = ?subscriber.as_ref().map(origin::Producer::allowed), @@ -2208,7 +2211,10 @@ impl Cluster { }; // The link is one presence across reconnects: each session it dials records how it // ended, and the last one to end decides whether the link failed. - let stats = self.stats.tier(self.cluster_tier()).session(Path::empty()); + let stats = self + .stats + .tier(self.cluster_tier()) + .session(moq_net::stats::SessionInfo::new(Path::empty())); let mut client = client .with_publisher(origin.consume().with_hidden(true)) .with_subscriber(origin) diff --git a/rs/moq-relay/src/internal.rs b/rs/moq-relay/src/internal.rs index 1932b01ebcf..fb92706310d 100644 --- a/rs/moq-relay/src/internal.rs +++ b/rs/moq-relay/src/internal.rs @@ -1771,7 +1771,7 @@ mod tests { for tier in ["internal", "edge"] { let session = registry .tier(moq_net::stats::Tier::new(moq_net::Path::from_static(tier))) - .session(moq_net::Path::empty()); + .session(moq_net::stats::SessionInfo::new(moq_net::Path::empty())); let source = moq_net::transport::Wire::new(); let guard = session.wire(source.clone()); source.set_sent_bytes(123); @@ -1798,7 +1798,7 @@ mod tests { ); drop(guard); drop(session); - registry.report(&mut Default::default()); + registry.report(&mut Default::default(), moq_net::time::Instant::now()); check(); let body = render_metrics(®istry.snapshot(), &[], &[]); assert!( @@ -1816,7 +1816,7 @@ mod tests { let producer = moq_tokio::origin::spawn().with_stats( stats .tier(moq_net::stats::Tier::new(moq_net::Path::from_static("edge"))) - .session(moq_net::Path::from_static("root")), + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static("root"))), ); let broadcast = producer .route("demo/retired", moq_net::origin::RouteOptions::default()) @@ -1836,7 +1836,7 @@ mod tests { drop(broadcast); drop(producer); let mut report = moq_net::stats::Report::default(); - stats.report(&mut report); + stats.report(&mut report, moq_net::time::Instant::now()); let body = render_metrics(&stats.snapshot(), &[], &[]); assert!( @@ -1861,7 +1861,9 @@ mod tests { // Default-tier egress: an untagged local publisher writes, a tagged egress // consumer reads it out, so publisher `bytes` advance on the default tier. - let default_ctx = stats.tier(Tier::default()).session(moq_net::Path::from_static("acme")); + let default_ctx = stats + .tier(Tier::default()) + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static("acme"))); let pub_origin = moq_tokio::origin::spawn(); let egress = pub_origin.consume().with_stats(default_ctx.clone()); let mut announced = egress.routes(); @@ -1874,7 +1876,7 @@ mod tests { // `bytes` advance on the regional tier. let regional_ctx = stats .tier(Tier::new(moq_net::Path::from_static("region/sjc"))) - .session(moq_net::Path::from_static("peer")); + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static("peer"))); let sub_origin = moq_tokio::origin::spawn().with_stats(regional_ctx.clone()); let sub_source = sub_origin .route("demo/x", moq_net::origin::RouteOptions::default()) @@ -1955,7 +1957,10 @@ mod tests { .unwrap(); let track = source .broadcast() - .create_track("catalog.json", timed().with_compress(true)) + .create_track( + "catalog.json", + timed().with_compression(moq_net::track::Compression::Deflate), + ) .unwrap(); let payload = format!("{{\"pad\":\"{}\"}}", "abc".repeat(300)); @@ -1963,7 +1968,7 @@ mod tests { for session in ["a", "b"] { let ctx = stats .tier(Tier::default()) - .session(moq_net::Path::new(session).unwrap()); + .session(moq_net::stats::SessionInfo::new(moq_net::Path::new(session).unwrap())); let egress = origin.consume().with_stats(ctx); let bc = egress.request("demo/x", None).await.unwrap(); readers.push(bc.track("catalog.json").unwrap().subscribe(None).await.unwrap()); @@ -2055,7 +2060,8 @@ mod tests { async fn metrics_series_are_pinned() { let stats = moq_net::stats::Registry::new(Default::default()); let edge = stats.tier(moq_net::stats::Tier::new(moq_net::Path::from_static("edge"))); - let origin = moq_tokio::origin::spawn().with_stats(edge.session(moq_net::Path::from_static("root"))); + let origin = moq_tokio::origin::spawn() + .with_stats(edge.session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static("root")))); let _broadcast = origin.route("demo", moq_net::origin::RouteOptions::default()).unwrap(); drop(edge.request(moq_net::Path::from_static("root"))); let refusals = crate::refusals::Refusals::default(); diff --git a/rs/moq-relay/src/refusals.rs b/rs/moq-relay/src/refusals.rs index c0371cc773b..1805eb3acf6 100644 --- a/rs/moq-relay/src/refusals.rs +++ b/rs/moq-relay/src/refusals.rs @@ -54,7 +54,9 @@ impl Refusals { } } pub(crate) fn record(&self, reason: RefusalKind) { - self.registry.tier(Tier::default()).refuse(Path::empty(), reason); + self.registry + .tier(Tier::default()) + .refuse(moq_net::stats::Refusal::new(Path::empty(), reason)); } pub(crate) fn record_auth(&self, err: &auth::Error) { if let auth::Error::Refused(refusal) = err @@ -68,7 +70,9 @@ impl Refusals { .as_deref() .and_then(|root| Path::new(root).ok()) .unwrap_or_default(); - self.registry.tier(tier).refuse(root, err.into()); + self.registry + .tier(tier) + .refuse(moq_net::stats::Refusal::new(root, err.into())); } else { self.record(err.into()); } @@ -111,7 +115,7 @@ mod tests { } } let mut report = moq_net::stats::Report::default(); - registry.report(&mut report); + registry.report(&mut report, moq_net::time::Instant::now()); assert_eq!(report.sessions.len(), 4); for entry in report.sessions { assert!(["", "tenant"].contains(&entry.label.as_str())); diff --git a/rs/moq-relay/src/uring.rs b/rs/moq-relay/src/uring.rs index 9a888aa7ef9..6a6d115b20d 100644 --- a/rs/moq-relay/src/uring.rs +++ b/rs/moq-relay/src/uring.rs @@ -618,7 +618,7 @@ fn serve_worker(spawn: Spawn) -> bool { .udp(member, udp) .context("failed to adopt the worker socket")?; let mut endpoint_config = moq_uring::quic::endpoint::Config::default().with_server(server); - endpoint_config.activity = serve.shutdown.activity.clone(); + endpoint_config.admission = serve.shutdown.admission.clone(); endpoint_config.handshake.timeout = serve.timeout; endpoint_config.reset_secret = serve.reset_secret; let endpoint = diff --git a/rs/moq-relay/src/web.rs b/rs/moq-relay/src/web.rs index 3b04f288e48..09e162539a4 100644 --- a/rs/moq-relay/src/web.rs +++ b/rs/moq-relay/src/web.rs @@ -1388,7 +1388,7 @@ mod tests { decider.await.unwrap(); let mut report = Report::default(); - registry.report(&mut report); + registry.report(&mut report, moq_net::time::Instant::now()); let [entry] = report.sessions.as_slice() else { panic!("expected one attributed entry: {:?}", report.sessions); }; @@ -1494,7 +1494,7 @@ mod tests { } let _leases = decider.await.unwrap(); let mut report = Report::default(); - state.cluster.stats.report(&mut report); + state.cluster.stats.report(&mut report, moq_net::time::Instant::now()); assert_eq!(report.traffic.len(), 2); assert_eq!(report.sessions.len(), 2); for label in ["first", "second"] { diff --git a/rs/moq-relay/tests/integration/auth_lifetime.rs b/rs/moq-relay/tests/integration/auth_lifetime.rs index ec565144d90..94f6fd43387 100644 --- a/rs/moq-relay/tests/integration/auth_lifetime.rs +++ b/rs/moq-relay/tests/integration/auth_lifetime.rs @@ -687,7 +687,7 @@ async fn a_moved_tier_retags_the_live_session() { // Each label's (active sessions, sent bytes, received bytes), from one report. let labels = || { let mut report = stats::Report::default(); - registry.report(&mut report); + registry.report(&mut report, moq_net::time::Instant::now()); report .sessions .into_iter() diff --git a/rs/moq-relay/tests/integration/refusals.rs b/rs/moq-relay/tests/integration/refusals.rs index 9c5f6f23dee..d02d415d079 100644 --- a/rs/moq-relay/tests/integration/refusals.rs +++ b/rs/moq-relay/tests/integration/refusals.rs @@ -279,7 +279,10 @@ async fn refused_only_stats_depth_one_has_root_totals_and_shared_embedder_metric relay .stats .tier(Tier::new(moq_net::Path::from_static("gateway"))) - .refuse(moq_net::Path::from_static("tenant"), RefusalKind::Forbidden); + .refuse(moq_net::stats::Refusal::new( + moq_net::Path::from_static("tenant"), + RefusalKind::Forbidden, + )); assert_eq!( relay.refused("forbidden").await, 1, @@ -414,7 +417,7 @@ async fn expired_verified_tokens_count_under_the_token_root_and_auth_tier() { assert_eq!(relay.refused("expired").await, 1); assert_eq!(relay.refused("refused").await, 0); let mut report = moq_net::stats::Report::default(); - relay.stats.report(&mut report); + relay.stats.report(&mut report, moq_net::time::Instant::now()); assert_eq!(report.sessions.len(), 1); let entry = &report.sessions[0]; assert_eq!(entry.tier.as_str(), tier.unwrap_or("")); diff --git a/rs/moq-stats/benches/producer_tick.rs b/rs/moq-stats/benches/producer_tick.rs index a0a8553f8ff..bff9f102c18 100644 --- a/rs/moq-stats/benches/producer_tick.rs +++ b/rs/moq-stats/benches/producer_tick.rs @@ -130,7 +130,9 @@ impl Relay { let tier_labels: Vec<_> = (0..tiers) .map(|tier| { let tier = stats::Tier::new(moq_net::Path::new(&format!("t{tier}")).unwrap()); - let session = registry.tier(tier.clone()).session(moq_net::Path::from_static("root")); + let session = registry + .tier(tier.clone()) + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static("root"))); let mut cursor = origin.consume().with_stats(session.clone()).routes(); while cursor.next().now_or_never().flatten().is_some() {} cursors.push(cursor); @@ -140,7 +142,7 @@ impl Relay { .collect(); let mut report = stats::Report::default(); - registry.report(&mut report); + registry.report(&mut report, moq_net::time::Instant::now()); assert_eq!(report.traffic.len(), paths * tiers, "one held entry per path and tier"); let depth = if groups.is_some() { 1 } else { 0 }; @@ -215,8 +217,11 @@ fn sample(relay: &mut Relay) -> Row { } } +/// The most moq-net's group cache holds, which a snapshot frame must fit. +const CAP: u64 = 32 * 1024 * 1024; + fn check_row(paths: usize, changed: usize, row: &Row) { - let cap = moq_net::group::MAX_CACHE_BYTES; + let cap = CAP; assert!(row.bytes.held > 0, "group snapshot missing"); assert!( row.bytes.held as u64 <= cap, @@ -231,7 +236,7 @@ fn check_row(paths: usize, changed: usize, row: &Row) { } fn bench(c: &mut Criterion) { - let cap = moq_net::group::MAX_CACHE_BYTES; + let cap = CAP; println!("plain frame cap: {cap} bytes"); println!("paths tiers changed% allocs/tick us/tick heldB cap% wroteB"); @@ -309,7 +314,9 @@ impl Presence { .map(|label| { registry .tier(stats::Tier::default()) - .session(moq_net::Path::new(label.as_str()).unwrap()) + .session(moq_net::stats::SessionInfo::new( + moq_net::Path::new(label.as_str()).unwrap(), + )) }) .collect(); // One set of wire counters per connection, independently of held presence tracks. diff --git a/rs/moq-stats/src/aggregate.rs b/rs/moq-stats/src/aggregate.rs index 4d55994184f..5005cc64c56 100644 --- a/rs/moq-stats/src/aggregate.rs +++ b/rs/moq-stats/src/aggregate.rs @@ -1268,7 +1268,7 @@ mod tests { let ctx = producer .registry() .tier(tier) - .session(moq_net::Path::new(label).unwrap()); + .session(moq_net::stats::SessionInfo::new(moq_net::Path::new(label).unwrap())); let feed_origin = produce_origin(); let egress = feed_origin.consume().with_stats(ctx.clone()); @@ -1791,11 +1791,11 @@ mod tests { let _sa = node_a .registry() .tier(Tier::default()) - .session(moq_net::Path::from_static("acme")); + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static("acme"))); let _sb = node_b .registry() .tier(Tier::default()) - .session(moq_net::Path::from_static("acme")); + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static("acme"))); drive_tick().await; let agg = Consumer::new(origin.consume(), Config::new()); @@ -1824,11 +1824,11 @@ mod tests { let _sa = node_a .registry() .tier(Tier::default()) - .session(moq_net::Path::from_static("acme")); + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static("acme"))); let sb = node_b .registry() .tier(Tier::default()) - .session(moq_net::Path::from_static("acme")); + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static("acme"))); drive_tick().await; let agg = Consumer::new(origin.consume(), Config::new()); @@ -1928,7 +1928,9 @@ mod tests { let session = node .registry() .tier(Tier::default()) - .session(moq_net::Path::from_static("acme/live")); + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static( + "acme/live", + ))); drive_tick().await; let mut started = 0; let mut read_until = async |want: u64, active: u64| loop { @@ -1950,7 +1952,9 @@ mod tests { let _session = node .registry() .tier(Tier::default()) - .session(moq_net::Path::from_static("acme/live")); + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static( + "acme/live", + ))); drive_tick().await; read_until(2, 1).await; } diff --git a/rs/moq-stats/src/consume.rs b/rs/moq-stats/src/consume.rs index 3d1b052c505..a4113969f50 100644 --- a/rs/moq-stats/src/consume.rs +++ b/rs/moq-stats/src/consume.rs @@ -227,7 +227,7 @@ mod tests { let ctx = producer .registry() .tier(tier) - .session(moq_net::Path::new(label).unwrap()); + .session(moq_net::stats::SessionInfo::new(moq_net::Path::new(label).unwrap())); let feed_origin = produce_origin(); let egress = feed_origin.consume().with_stats(ctx.clone()); diff --git a/rs/moq-stats/src/produce.rs b/rs/moq-stats/src/produce.rs index 5aaf91b2f62..1a24abe622c 100644 --- a/rs/moq-stats/src/produce.rs +++ b/rs/moq-stats/src/produce.rs @@ -372,7 +372,9 @@ impl Drain { /// Drain the registry and sort each entry into its pending frames, /// creating group tracks on first sight. fn collect(&mut self) { - self.task.registry.report(&mut self.report); + self.task + .registry + .report(&mut self.report, moq_net::time::Instant::now()); self.tick += 1; self.node.collect(&self.report, self.tick, self.task.depth); } @@ -565,7 +567,7 @@ struct Output { fn info() -> track::Info { track::Info::default() .with_timescale(moq_net::Timescale::MILLI) - .with_compress(true) + .with_compression(moq_net::track::Compression::Deflate) .with_refresh(8) } @@ -1403,7 +1405,9 @@ mod tests { fn a_joiner_over_the_ratio_gets_a_snapshot_next_interval() { let broadcast = moq_net::broadcast::Info::new().produce(); // Uncompressed, so the refresh ratio is judged on the plain frame sizes below. - let track = broadcast.create_track("t.json", info().with_compress(false)).unwrap(); + let track = broadcast + .create_track("t.json", info().with_compression(moq_net::track::Compression::None)) + .unwrap(); let mut snapshot = Snapshot::>::new(track.clone(), moq_json::snapshot::Config::default()); let frame = |n| Frame { entries: vec![(Path::from_static("a"), n)], @@ -1516,7 +1520,7 @@ mod tests { ]; let session = registry .tier(Tier::default()) - .session(moq_net::Path::from_static("room")); + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static("room"))); let counters = moq_net::transport::Wire::new(); let _wire = session.wire(counters.clone()); let store = |n: u64| { @@ -1718,7 +1722,9 @@ mod tests { frames: usize, frame_size: usize, ) -> Feed { - let ctx = registry.tier(tier).session(moq_net::Path::from_static("feed")); + let ctx = registry + .tier(tier) + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static("feed"))); let origin = produce_origin(); // Egress (publisher side) is tagged; the local publisher stays untagged. let egress = origin.consume().with_stats(ctx); @@ -1903,7 +1909,9 @@ mod tests { let session = producer .registry() .tier(Tier::default()) - .session(moq_net::Path::from_static("acme/live")); + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static( + "acme/live", + ))); let counters = moq_net::transport::Wire::new(); let _wire = session.wire(counters.clone()); let step = async |millis: u64| { @@ -2174,18 +2182,16 @@ mod tests { let data = produce_origin(); let source = data .clone() - .with_stats( - registry - .tier(Tier::default()) - .session(moq_net::Path::from_static("publisher")), - ) + .with_stats(registry.tier(Tier::default()).session(moq_net::stats::SessionInfo::new( + moq_net::Path::from_static("publisher"), + ))) .route("foo/bar", moq_net::origin::RouteOptions::default()) .expect("publish"); let mut video = source.broadcast().create_track("video", timed()).expect("create_track"); let egress = data.consume().with_stats( registry .tier(Tier::default()) - .session(moq_net::Path::from_static("viewer")), + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static("viewer"))), ); async fn view(egress: &origin::Consumer, video: &mut track::Producer, size: usize) { @@ -2275,15 +2281,15 @@ mod tests { let _a = producer .registry() .tier(Tier::default()) - .session(moq_net::Path::from_static("acme")); + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static("acme"))); let _b = producer .registry() .tier(Tier::default()) - .session(moq_net::Path::from_static("acme")); + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static("acme"))); let _c = producer .registry() .tier(Tier::new(moq_net::Path::from_static("region/sjc"))) - .session(moq_net::Path::from_static("peer")); + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static("peer"))); drive_tick().await; @@ -2359,15 +2365,15 @@ mod tests { let _a = producer .registry() .tier(Tier::default()) - .session(moq_net::Path::from_static("acme")); + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static("acme"))); let b = producer .registry() .tier(Tier::default()) - .session(moq_net::Path::from_static("beta")); + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static("beta"))); let _c = producer .registry() .tier(Tier::new(moq_net::Path::from_static("region/sjc"))) - .session(moq_net::Path::from_static("peer")); + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static("peer"))); drive_tick().await; let (_, broadcast) = announced(&origin).await; @@ -2405,15 +2411,21 @@ mod tests { async fn presence_track_is_cumulative_while_held() { let (producer, origin) = test_producer(Some("sjc")); let registry = producer.registry(); - let first = registry - .tier(Tier::default()) - .session(moq_net::Path::from_static("acme/live")); - let _other = registry - .tier(Tier::new(moq_net::Path::from_static("rtmp"))) - .session(moq_net::Path::from_static("acme/live")); + let first = + registry + .tier(Tier::default()) + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static( + "acme/live", + ))); + let _other = + registry + .tier(Tier::new(moq_net::Path::from_static("rtmp"))) + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static( + "acme/live", + ))); let _unrelated = registry .tier(Tier::default()) - .session(moq_net::Path::from_static("beta")); + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static("beta"))); drive_tick().await; let (_, broadcast) = announced(&origin).await; @@ -2437,9 +2449,12 @@ mod tests { assert_eq!(frame[""].active(), 0); // A new session under the label continues the count. - let _again = registry - .tier(Tier::default()) - .session(moq_net::Path::from_static("acme/live")); + let _again = + registry + .tier(Tier::default()) + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static( + "acme/live", + ))); drive_tick().await; let mut last = None; while let Some(frame) = try_presence(&mut track) { @@ -2486,7 +2501,9 @@ mod tests { assert_eq!(try_presence(&mut track), Some(PresenceFrame::new()), "held at zero"); // The label records while held: the same subscription carries it. - let _session = registry.tier(Tier::default()).session(moq_net::Path::from_static("")); + let _session = registry + .tier(Tier::default()) + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static(""))); tokio::time::advance(Duration::from_secs(1)).await; tick(); assert_eq!(try_presence(&mut track).expect("recorded")[""].active(), 1); @@ -2625,18 +2642,16 @@ mod tests { let data = produce_origin(); let source = data .clone() - .with_stats( - registry - .tier(Tier::default()) - .session(moq_net::Path::from_static("publisher")), - ) + .with_stats(registry.tier(Tier::default()).session(moq_net::stats::SessionInfo::new( + moq_net::Path::from_static("publisher"), + ))) .route("acme/live", moq_net::origin::RouteOptions::default()) .expect("publish"); let video = source.broadcast().create_track("video", timed()).expect("create_track"); let egress = data.consume().with_stats( registry .tier(Tier::default()) - .session(moq_net::Path::from_static("viewer")), + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static("viewer"))), ); let broadcast = egress.request("acme/live", None).await.expect("resolve"); let mut subs = Vec::new(); @@ -2776,7 +2791,11 @@ mod tests { assert_eq!(usage.subscriber, Traffic::default(), "no ingress moved"); assert!(!frame.tiers.contains_key("region/sjc"), "an idle tier never surfaces"); let totals = broadcast.track("totals.json").unwrap().info().await.unwrap(); - assert!(totals.compress, "the totals are compressed"); + assert_eq!( + totals.compression, + moq_net::track::Compression::Deflate, + "the totals are compressed" + ); } #[test] @@ -3039,9 +3058,12 @@ mod tests { let _link = link(&origin, &edge, "moq-lite-07-wip".parse().unwrap()).await; let start = Instant::now(); - let acme = registry - .tier(Tier::default()) - .session(moq_net::Path::from_static("acme/live")); + let acme = + registry + .tier(Tier::default()) + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static( + "acme/live", + ))); drain.collect(); drain.publish(start); let consumer = edge.consume().with_hidden(true); @@ -3055,7 +3077,7 @@ mod tests { let beta = registry .tier(Tier::default()) - .session(moq_net::Path::from_static("beta")); + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static("beta"))); assert_eq!(next_listed(&mut drain, start, &mut tracks).await, ("beta".into(), true)); // Empty, acme lingers: still listed, its totals keeping the ended session. @@ -3084,9 +3106,12 @@ mod tests { assert_eq!(frame.tiers[""].labels.keys().collect::>(), ["beta"]); // A return is listed again on the same broadcast, with no announce. - let _acme = registry - .tier(Tier::default()) - .session(moq_net::Path::from_static("acme/live")); + let _acme = + registry + .tier(Tier::default()) + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static( + "acme/live", + ))); assert_eq!( next_listed(&mut drain, lingered, &mut tracks).await, ("acme".into(), true) @@ -3112,9 +3137,12 @@ mod tests { track.next_group().await.unwrap().unwrap().sequence }; - let session = registry - .tier(Tier::default()) - .session(moq_net::Path::from_static("acme/live")); + let session = + registry + .tier(Tier::default()) + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static( + "acme/live", + ))); drive_tick().await; let mut reader = stats.group(moq_net::Path::from_static("acme")).expect("listed"); let first = reader.next().await.unwrap().unwrap(); @@ -3131,9 +3159,12 @@ mod tests { assert_eq!(last.epoch, first.epoch); assert_eq!(last.tiers[""].sessions.sessions_ended, 1); - let _session = registry - .tier(Tier::default()) - .session(moq_net::Path::from_static("acme/live")); + let _session = + registry + .tier(Tier::default()) + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static( + "acme/live", + ))); drive_tick().await; let second = stats .group(moq_net::Path::from_static("acme")) @@ -3182,10 +3213,10 @@ mod tests { let _acme = registry .tier(Tier::default()) - .session(moq_net::Path::from_static("acme")); + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static("acme"))); let _big = registry .tier(Tier::default()) - .session(moq_net::Path::from_static("big")); + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static("big"))); let mut acme = stats.group(moq_net::Path::from_static("acme")).unwrap(); let mut big = stats.group(moq_net::Path::from_static("big")).unwrap(); assert!(pumping(&mut drain, acme.next()).await.unwrap().is_some()); @@ -3193,7 +3224,11 @@ mod tests { let _huge: Vec<_> = oversized_paths("big/") .into_iter() - .map(|path| registry.tier(Tier::default()).session(path)) + .map(|path| { + registry + .tier(Tier::default()) + .session(moq_net::stats::SessionInfo::new(path)) + }) .collect(); let (end, _) = pumping(&mut drain, drain_group(&mut big)).await; assert!( @@ -3204,9 +3239,12 @@ mod tests { "{end:?}" ); - let _more = registry - .tier(Tier::default()) - .session(moq_net::Path::from_static("acme/more")); + let _more = + registry + .tier(Tier::default()) + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static( + "acme/more", + ))); let mut frame = pumping(&mut drain, acme.next()).await.unwrap().unwrap(); while frame.tiers[""].labels.len() < 2 { frame = pumping(&mut drain, acme.next()).await.unwrap().unwrap(); diff --git a/rs/moq-tokio/src/server.rs b/rs/moq-tokio/src/server.rs index 70f1ac571a4..98d17c17910 100644 --- a/rs/moq-tokio/src/server.rs +++ b/rs/moq-tokio/src/server.rs @@ -2521,7 +2521,7 @@ mod tests { let request = request.with_stats( registry .tier(Default::default()) - .session(moq_net::Path::from_static("room")), + .session(moq_net::stats::SessionInfo::new(moq_net::Path::from_static("room"))), ); let Err(err) = request.ok().await else { panic!("a reply the peer never took completed"); diff --git a/rs/moq-tokio/tests/integration/broadcast.rs b/rs/moq-tokio/tests/integration/broadcast.rs index b0e5655bc61..fff71e43125 100644 --- a/rs/moq-tokio/tests/integration/broadcast.rs +++ b/rs/moq-tokio/tests/integration/broadcast.rs @@ -2413,7 +2413,7 @@ async fn idle_subscription_releases_the_viewer_count() { let registry = moq_net::stats::Registry::new(moq_net::stats::Config::new()); let stats = registry .tier(moq_net::stats::Tier::default()) - .session(moq_net::Path::empty()); + .session(moq_net::stats::SessionInfo::new(moq_net::Path::empty())); let sub_origin = moq_tokio::origin::spawn(); let sub_consumer = sub_origin.consume(); diff --git a/swift/MIGRATE.md b/swift/MIGRATE.md index 4e8d43289f2..566b7cc7eab 100644 --- a/swift/MIGRATE.md +++ b/swift/MIGRATE.md @@ -102,7 +102,7 @@ A fixed audio playout delay `d` is `delay: Delay(min: d, max: ...)` with `estima ### Compression moves to the track `Flate` is removed: publish opaque bytes on a `TrackProducer`. -The `Json` producers and consumers drop their `compression` argument. Publish the track with `TrackInfo(compress: true)` instead; a consumer reads a compressed track with no option of its own. +The `Json` producers and consumers drop their `compression` argument. Publish the track with `TrackInfo(compression: .deflate)` instead; a consumer reads a compressed track with no option of its own. ### Paths with an empty segment are refused ([#6648](https://github.com/moq-dev/moq/pull/6648)) diff --git a/swift/README.md b/swift/README.md index da49f00b8e1..ca712d3e86c 100644 --- a/swift/README.md +++ b/swift/README.md @@ -96,7 +96,7 @@ zero `delay.max`. You opt into one of three distinct modes: `Json.SnapshotProduc (lossless append-log, every record preserved in order), or `Json.WindowProducer`/`Json.WindowConsumer` (a sliding window of records a reader can join at any point, not advertised in the catalog). Values encode/decode at the boundary with `JSONEncoder`/`JSONDecoder`; the consumer is an `AsyncSequence` of the decoded type. Publish the -track with `TrackInfo(compress: true)`; consumers read it the same either way. Every JSON write +track with `TrackInfo(compression: .deflate)`; consumers read it the same either way. Every JSON write (snapshot update, stream append, window push or pop) takes a timestamp on the broadcast clock (`Media.CatalogProducer.now()`), so the track needs a timescale. diff --git a/swift/Sources/Moq/Aliases.swift b/swift/Sources/Moq/Aliases.swift index b30d1a828e3..9e47ce26bba 100644 --- a/swift/Sources/Moq/Aliases.swift +++ b/swift/Sources/Moq/Aliases.swift @@ -75,6 +75,8 @@ public typealias FetchGroupOptions = MoqFFI.MoqFetchGroupOptions /// Publisher-side track properties: priority, group ordering, max age, /// and timescale. public typealias TrackInfo = MoqFFI.MoqTrackInfo +/// How a track's frames are compressed on the wire: `.deflate`, or `nil` in `TrackInfo` for none. +public typealias Compression = MoqFFI.MoqCompression /// A snapshot of connection statistics (RTT, bandwidth estimates, byte/packet /// counters). Fields are `nil` when the transport backend doesn't report them. diff --git a/swift/Sources/Moq/Json.swift b/swift/Sources/Moq/Json.swift index c9e8eb3bcab..bed35b50b59 100644 --- a/swift/Sources/Moq/Json.swift +++ b/swift/Sources/Moq/Json.swift @@ -10,7 +10,7 @@ import MoqFFI /// Foundation before the swift-foundation rewrite (iOS < 18 / macOS < 15), so encode an object /// or array there. /// -/// Compression is the track's: publish JSON with `TrackInfo(compress: true)`, and a consumer reads +/// Compression is the track's: publish JSON with `TrackInfo(compression: .deflate)`, and a consumer reads /// it with no option of its own. /// /// Every write (a snapshot update, a stream append, a window push or pop) takes a timestamp on the diff --git a/swift/Tests/MoqTests/SmokeTests.swift b/swift/Tests/MoqTests/SmokeTests.swift index 82a5b7f49e4..ac8348388a6 100644 --- a/swift/Tests/MoqTests/SmokeTests.swift +++ b/swift/Tests/MoqTests/SmokeTests.swift @@ -511,7 +511,8 @@ final class SmokeTests: XCTestCase { let broadcast = try BroadcastProducer() let producer = try Json.SnapshotProducer( broadcast: broadcast, - track: try broadcast.publishTrack(name: "status", info: TrackInfo(timescale: 1_000_000, compress: true))) + track: try broadcast.publishTrack( + name: "status", info: TrackInfo(timescale: 1_000_000, compression: .deflate))) let consumer = try Json.SnapshotConsumer( broadcast: try broadcast.consume(), name: "status") @@ -562,7 +563,8 @@ final class SmokeTests: XCTestCase { let broadcast = try BroadcastProducer() let producer = try Json.WindowProducer( - track: try broadcast.publishTrack(name: "log", info: TrackInfo(timescale: 1_000_000, compress: true))) + track: try broadcast.publishTrack(name: "log", info: TrackInfo(timescale: 1_000_000, compression: .deflate)) + ) let consumer = try Json.WindowConsumer( track: try await broadcast.consume().subscribeTrack(name: "log")) diff --git a/test/interop/clients/js-native/catalog.ts b/test/interop/clients/js-native/catalog.ts index b5185b88f7c..1b3c84f6190 100644 --- a/test/interop/clients/js-native/catalog.ts +++ b/test/interop/clients/js-native/catalog.ts @@ -41,13 +41,13 @@ try { priority: Catalog.PRIORITY.catalog, }); try { - const { compress } = await track.info(); - assert.equal(compress, version === "moq-lite-07-wip", "wrong compression metadata"); + const { compression } = await track.info(); + assert.equal(compression, version === "moq-lite-07-wip" ? "deflate" : "none", "wrong compression metadata"); const root = (await consumer.latest())?.value; assert(root, "catalog ended before a snapshot"); const video = Object.keys(root.video?.renditions ?? {}).sort(); const audio = Object.keys(root.audio?.renditions ?? {}).sort(); - console.error(`catalog compress=${compress} video=${video.join(",")} audio=${audio.join(",")}`); + console.error(`catalog compression=${compression} video=${video.join(",")} audio=${audio.join(",")}`); } finally { consumer.close(); } diff --git a/test/interop/clients/js-native/hls.ts b/test/interop/clients/js-native/hls.ts index b223ccb8595..2374816d08e 100644 --- a/test/interop/clients/js-native/hls.ts +++ b/test/interop/clients/js-native/hls.ts @@ -78,7 +78,7 @@ try { const track = broadcast.createTrack(Catalog.TRACK, { timescale: Moq.Time.Timescale.MILLI, priority: Catalog.PRIORITY.catalog, - compress: true, + compression: "deflate", }); const catalog = new Json.Snapshot.Producer({ track, deltas: false }); catalog.update({ diff --git a/test/interop/clients/js-native/tail.ts b/test/interop/clients/js-native/tail.ts index c7f3d7af6ad..c080ab026ff 100644 --- a/test/interop/clients/js-native/tail.ts +++ b/test/interop/clients/js-native/tail.ts @@ -145,7 +145,11 @@ try { } else { // `cached` and `late` read groups a newer one supersedes, which the default zero max age // would leave stale. - const track = broadcast.createTrack("tail", { compress, maxAge: null, ...(status ? { priority: 2 } : {}) }); + const track = broadcast.createTrack("tail", { + compression: compress ? "deflate" : "none", + maxAge: null, + ...(status ? { priority: 2 } : {}), + }); if (cached) write(track); if (history) serveHistory(track); let head: Moq.Group.Producer | undefined; @@ -236,7 +240,8 @@ try { delay: { max: Milli(drop ? 60_000 : 5000) }, ...(late ? {} : { ranges: [{ start: { absolute: 0n } }] }), }); - if (compress) assert.equal((await track.info()).compress, version === "moq-lite-07-wip"); + if (compress) + assert.equal((await track.info()).compression, version === "moq-lite-07-wip" ? "deflate" : "none"); const seen: number[] = []; try { if (late) { diff --git a/test/interop/clients/rust/catalog.rs b/test/interop/clients/rust/catalog.rs index 8376ea7e687..6a7d1860c37 100644 --- a/test/interop/clients/rust/catalog.rs +++ b/test/interop/clients/rust/catalog.rs @@ -36,7 +36,10 @@ async fn main() -> anyhow::Result<()> { let track = route .broadcast() .create_track(hang::Catalog::DEFAULT_NAME, hang::Catalog::default_track_info())?; - ensure!(track.info().compress, "hang catalogs are compressed"); + ensure!( + track.info().compression == moq_net::track::Compression::Deflate, + "hang catalogs are compressed" + ); let mut catalog = moq_json::snapshot::Producer::::new(track, Default::default()); let value = hang::Catalog::from_slice(CATALOG.as_bytes())?; catalog.update(moq_net::Timed::from(&value).at(moq_net::Timestamp::ZERO))?; diff --git a/test/interop/clients/rust/tail.rs b/test/interop/clients/rust/tail.rs index bdef9f88f82..e5a10af22e7 100644 --- a/test/interop/clients/rust/tail.rs +++ b/test/interop/clients/rust/tail.rs @@ -142,7 +142,10 @@ async fn main() -> anyhow::Result<()> { "tail", moq_net::track::Info::default() .with_timescale(moq_net::Timescale::MILLI) - .with_compress(compress) + .with_compression(match compress { + true => moq_net::track::Compression::Deflate, + false => moq_net::track::Compression::None, + }) // `cached` and `late` read groups a newer one supersedes, which the default // zero max age would leave stale. .with_max_age(None), @@ -274,7 +277,8 @@ async fn main() -> anyhow::Result<()> { let mut track = remote.subscribe(Some(options)).await?; if compress { ensure!( - track.info().compress == args.get(4).is_some_and(|version| version == "moq-lite-07-wip"), + (track.info().compression == moq_net::track::Compression::Deflate) + == args.get(4).is_some_and(|version| version == "moq-lite-07-wip"), "wrong compression metadata" ); } From 96e436f4f0f690b3b5d6ce4a31b9ec71b061397f Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sun, 8 Nov 2026 08:01:04 -0800 Subject: [PATCH 4/7] fix: merge main; record api-shape/net decisions; ffi priority wait re-checks after registering claim_continues (new on main) proxies like every other integration origin. group::Demand docs name paced flights (maintainer, 2026-11-08). The minted refusal item moves to quest/m2/instance-provenance.md. Co-Authored-By: Claude Opus 5.5 --- quest/m2/api-shape/README.md | 2 +- quest/m2/api-shape/net.md | 64 +++++++-------- quest/m2/instance-provenance.md | 80 +++++++++++++++++++ quest/m2/lite07-finalize.md | 1 + rs/moq-ffi/src/datagram.rs | 19 +++-- rs/moq-net/src/model/group.rs | 4 +- .../tests/integration/claim_continues.rs | 2 +- 7 files changed, 126 insertions(+), 46 deletions(-) create mode 100644 quest/m2/instance-provenance.md diff --git a/quest/m2/api-shape/README.md b/quest/m2/api-shape/README.md index 39b30df6b5b..f4cb01bcca2 100644 --- a/quest/m2/api-shape/README.md +++ b/quest/m2/api-shape/README.md @@ -54,7 +54,7 @@ Rejected in planning: ## Required -- [moq-net's remaining surface fixes](/quest/m2/api-shape/net.md) - the route stream un-hide after #8063, whether `group::Demand` stays public, and whether a route refuses a minted instance +- [moq-net's route stream goes public](/quest/m2/api-shape/net.md) - un-hide `origin::Consumer::routes` and reshape `RouteEvent`, now that #8063 merged - [Transports take shared types](/quest/m2/api-shape/transport.md) - moq-uring takes a congestion factory and rustls configs, and the tokio server request stops exposing its QUIC internals - [Crates re-export no whole crate](/quest/m2/api-shape/reexports.md) - no moq crate re-exports a whole crate, moq's own included, so a dependency bump is no moq break, and moq-mux's container `Guard` gets a name - [Media crates' small surface fixes](/quest/m2/api-shape/media.md) - exporters, the container consumer, catalog color range, rate grant, moq-stats, JSON, and MSF each have one path and one name diff --git a/quest/m2/api-shape/net.md b/quest/m2/api-shape/net.md index f0bdd6382d1..9a7d17ae002 100644 --- a/quest/m2/api-shape/net.md +++ b/quest/m2/api-shape/net.md @@ -1,53 +1,43 @@ -# [S] moq-net's remaining surface fixes +# [S] moq-net's route stream goes public ## Goal The rest of moq-net's small surface fixes, with their JS mirrors: -- After [moq-dev/moq#8063](https://github.com/moq-dev/moq/pull/8063) removes - `RouteEvent::Takeover`, un-hide `origin::Consumer::routes`, `Routes`, and - `RouteEvent`, documented as the relay-level stream that moq-relay and - downstream relays already consume, and fix `request`'s doc to say what #8063 made it - do. `RouteEvent` becomes `pub struct RouteEvent { pub kind: RouteKind, pub +- Un-hide `origin::Consumer::routes`, `Routes`, and `RouteEvent`, documented + as the relay-level stream that moq-relay and downstream relays already + consume, and fix `request`'s doc to say what + [moq-dev/moq#8063](https://github.com/moq-dev/moq/pull/8063) made it do. + `RouteEvent` becomes `pub struct RouteEvent { pub kind: RouteKind, pub announce: Announce }` with `pub enum RouteKind { Start, Update, Restart, End }`, mirroring JS's `{ kind } & Routed`, so callers need no or-pattern and no accessors. -- Settle whether `group::Producer::demand` and `group::Demand` stay public (see - Waiting). -- Settle whether `Producer::route` and `Request::route` refuse an instance that - `is_minted()` (see Waiting). ## Plan Found by the 2026-11-07 API shape audit (net model and net session); see the [epic](/quest/m2/api-shape/README.md). The rest of the audit's items landed in -[moq-dev/moq#8266](https://github.com/moq-dev/moq/pull/8266). Start the un-hide -once #8063 merges. The `RouteEvent` reshape replaces +[moq-dev/moq#8266](https://github.com/moq-dev/moq/pull/8266). The un-hide +waited on #8063 removing `RouteEvent::Takeover`; #8063 has merged, so it is +unblocked. The `RouteEvent` reshape replaces [moq-dev/moq#7862](https://github.com/moq-dev/moq/pull/7862)'s accessors, which closed without taking it. -## Waiting - -- Maintainer: decide whether `group::Demand` stays public. It cannot simply go - `pub(crate)`: a paced flight needs it. The audit assumed flights stop through - `Fill::poll_unwanted`, but that resolves as soon as readers take the group - (`fills.wants`), while a paced flight has to see its riders leave; - `rs/moq-net/tests/integration/flights.rs` and `rs/moq-net/benches/group.rs` - call `group::Producer::demand` for that. Options: (a) keep - `group::Producer::demand` and `group::Demand` public, documented as how a - paced flight sees its riders leave (recommended: the one spelling that works - today); (b) fold reader demand into `Fill::poll_unwanted` and - `Fill::is_wanted`, then make `group::Demand` `pub(crate)`, a behavior change - for every flight; (c) make it `pub(crate)` and move the flight test and the - group bench in-crate. -- Maintainer: decide whether a route refuses a minted instance. Refusing it in - `Producer::route`, `Request::route`, and `route_prefix` (Rust and JS) breaks - three tests outside moq-net that route `Instance::minted()` directly to stand in - for a route a pre-lite-07 session minted: moq-mux's - `follow::tests::a_named_instance_follows_a_minted_one` and @moq/watch's - `relativeBroadcast` and include tests. Options: (a) refuse, and rewrite those - tests to receive the route over a pre-lite-07 session, which needs a version - argument on moq-mux's `container/test_util.rs` `Link` and a session test helper - @moq/watch can import from @moq/net (recommended: the API then cannot claim a - minted instance as stable); (b) keep accepting it, documenting that a minted - instance proves nothing; (c) refuse it in Rust only, leaving JS as is. +Decided 2026-11-08 (maintainer): ✅ `group::Demand` and +`group::Producer::demand` stay public, documented for paced flights +(rejected: fold reader demand into `Fill::poll_unwanted` then make it +private; make it private and move the flight test and bench in-crate). +`Fill::poll_unwanted` resolves as soon as readers take the group, while a +paced flight has to see its riders leave; `tests/integration/flights.rs` and +`benches/group.rs` use it for that. Its docs say so since +[moq-dev/moq#8266](https://github.com/moq-dev/moq/pull/8266). + +Decided 2026-11-08 (maintainer): whether a route refuses a minted instance +is replaced by [Minted instances are a typed flag](/quest/m2/instance-provenance.md). +The `~` prefix is a spoofable in-band sentinel; once only a session can mint +an instance, the route needs no refusal. + +## Related + +- [Minted instances are a typed flag](/quest/m2/instance-provenance.md) - + replaces this quest's minted-route refusal item diff --git a/quest/m2/instance-provenance.md b/quest/m2/instance-provenance.md new file mode 100644 index 00000000000..8c2a965ca84 --- /dev/null +++ b/quest/m2/instance-provenance.md @@ -0,0 +1,80 @@ +# [L] Minted instances are a typed flag + +## Goal + +Whether a session minted an instance is a typed property of `Instance`, not +an in-band `~` prefix on its text: + +- `moq_net::Instance` carries a minted flag that the public API cannot set. + `FromStr` and `Instance::random()` build only named instances; only a + session mints one, for a route whose wire (moq-lite 06 or older, + moq-transport) carries none. `is_minted()` reads the flag. A named + instance may start with `~` like any other text. +- @moq/net mirrors it: `Instance.isMinted` reads the flag, and + `Instance.parse` / `Instance.random` build only named instances. +- moq-lite-07 (still the opt-in `moq-lite-07-wip`) carries an explicit + minted flag next to the instance wherever it carries one: the route an + announcement serves, and the instance a TRACK, TRACKS, SUBSCRIBE, FETCH, + or DATAGRAMS request pins. The draft drops the `~` convention. +- Minting itself stays, and so does what "minted" means: an older-wire route + gets one id shared across the lite-07 mesh (dedupe, agreed ranking), but no + continuity promise. A minted instance is never re-sourced, a catalog's + instance check against it is best effort, and signing refuses to bind it. + +## Plan + +Decided 2026-11-08 by the maintainer, replacing api-shape/net's "should a +route refuse a minted instance" item: the `~` prefix is a design flaw. It is +an in-band sentinel in a free-form string, so any caller can spoof a minted +instance by naming one `~...`, and a real name starting with `~` is +ambiguous. ✅ Typed flag that only a session sets, carried explicitly on the +lite-07 wire (rejected: refuse a minted instance in `route`, keep accepting +it with docs, refuse in Rust only). Once the API cannot build a minted +instance, `Producer::route` and `Request::route` need no refusal. + +Call sites (`git grep -n 'is_minted\|isMinted\|MINTED'` over `rs/` and +`js/`, plus `Instance::minted` / `Instance.minted`): + +- Type: `rs/moq-net/src/instance.rs` (`MINTED`, `minted()`, `is_minted()`, + `FromStr`, `Display`, tests), `js/net/src/instance.ts` (`MINTED`, + `minted()`, `isMinted()`, `parse`). JS `Instance.Valid` is a branded + string used as a map key and compared with `===` in about 34 files, so the + JS shape (an object with a stable key, or a string keyed form plus a flag) + is the main judgment call; pick one that keeps equality and map keys + correct and say why in the PR. +- Minting: `rs/moq-net/src/lite/subscriber.rs`, + `rs/moq-net/src/ietf/subscriber.rs`, `js/net/src/lite/subscriber.ts`, + `js/net/src/ietf/subscriber.ts`. +- Wire: `rs/moq-net/src/lite/instance.rs` and `js/net/src/lite/instance.ts` + (route and pin encode/decode), `drafts/draft-lcurley-moq-lite.md` (the + `~` paragraph near "A version before this one carries no Instance", and + the lite-07 changelog line on minting), and the lite corpus fixtures. +- Readers of the flag: `rs/moq-net/src/model/origin.rs`, + `rs/moq-net/src/model/broadcast.rs` / `model/track.rs` (`minted()` + state), `rs/moq-crypto/src/sign/broadcast.rs`, + `js/crypto/src/sign/broadcast.ts`, `rs/moq-mux/src/source.rs`, + `rs/moq-mux/src/follow.rs`, `rs/moq-gst/src/source/imp.rs`, + `js/net/src/consume.ts`, `js/net/src/origin.ts`, `js/watch/src/broadcast.ts`. +- Tests that route a minted instance directly + (`moq-mux` `follow::tests::a_named_instance_follows_a_minted_one`, + @moq/watch `broadcast.test.ts` and `include.test.ts`) can no longer build + one through the public API; give them a minted route over a pre-lite-07 + session or a test-only constructor, whichever is simpler. +- Docs: `doc/concept/identity.md` ("A minted instance starts with `~`"), + `doc/concept/moq-lite.md` ("marked with a leading `~`"), + `drafts/draft-lcurley-moq-hang.md` and `drafts/draft-lcurley-moq-sign.md` + where they cite the `~` mark, `rs/moq-net/MIGRATE.md`, and + `js/net/api/index.api.md`. + +This changes lite-07 bytes, so it joins +[Finalize moq-lite-07](/quest/m2/lite07-finalize.md)'s Required. +[moq-dev/moq#8220](https://github.com/moq-dev/moq/pull/8220) also changes +lite-07 (SUBSCRIBE_DROP and SUBSCRIBE_SKIP ranges) and touches +`lite/subscriber.rs`, `lite/subscribe.rs`, their JS mirrors, and the lite +draft, but not the instance encoding; expect textual conflicts only, and +whichever lands second adds its changelog line beside the other's. + +## Related + +- [moq-net's remaining surface fixes](/quest/m2/api-shape/net.md) - the + audit item this replaces diff --git a/quest/m2/lite07-finalize.md b/quest/m2/lite07-finalize.md index e24b81c2743..11675825f33 100644 --- a/quest/m2/lite07-finalize.md +++ b/quest/m2/lite07-finalize.md @@ -124,6 +124,7 @@ whose lite-07 encoding [lite-07 by start](/quest/m2/time-addressing/lite07.md) c - [Takeover](/quest/m1/stream-credit/takeover.md) - lite-07 lets a group stream take over for another group - [A group a subscriber gives up on is always reported](/quest/m2/group-drops.md) - may add SUBSCRIBE_DROP for a stopped group; leaves this list if it takes the no-wire path - [Delete the old start bookkeeping](/quest/m2/subscribe-ranges/start-bookkeeping.md) - may change START per update on lite-07 +- [Minted instances are a typed flag](/quest/m2/instance-provenance.md) - lite-07 carries an explicit minted flag beside each instance instead of the `~` prefix ## Related diff --git a/rs/moq-ffi/src/datagram.rs b/rs/moq-ffi/src/datagram.rs index 506fedb17d7..f641afef59b 100644 --- a/rs/moq-ffi/src/datagram.rs +++ b/rs/moq-ffi/src/datagram.rs @@ -159,13 +159,20 @@ impl MoqDatagramProducer { pub async fn priority_changed(&self, last: Option) -> Result, MoqError> { self.inner .wait(|producer, waiter| { + // The producer compares against what it last returned, which another call on this + // shared handle may have moved past `last`. Register first, then compare to `last`, + // so a change after the check still wakes this wait. loop { - let priority = match producer.priority() { - now if now != last => now, - _ => ready!(producer.poll_priority_changed(waiter)), - }; - if priority != last { - return Poll::Ready(Ok(priority)); + match producer.poll_priority_changed(waiter) { + Poll::Ready(priority) if priority != last => return Poll::Ready(Ok(priority)), + Poll::Ready(_) => continue, + Poll::Pending => { + let now = producer.priority(); + return match now != last { + true => Poll::Ready(Ok(now)), + false => Poll::Pending, + }; + } } } }) diff --git a/rs/moq-net/src/model/group.rs b/rs/moq-net/src/model/group.rs index d3205b95c4c..bfdb76d219d 100644 --- a/rs/moq-net/src/model/group.rs +++ b/rs/moq-net/src/model/group.rs @@ -2388,7 +2388,8 @@ impl Producer { self.handle.poll_closed(waiter) } - /// Watch reader demand without keeping the group alive. + /// Watch reader demand without keeping the group alive, such as for a paced flight to see + /// its riders leave. [`track::Fill::poll_unwanted`] resolves as soon as readers take the group. pub fn demand(&self) -> Demand { self.handle.demand() } @@ -3114,6 +3115,7 @@ fn settle(poll: Poll, kio::Ref<'_, GroupState>>>) /// A cloneable, watch-only handle to a group's readers. /// +/// A paced flight watches it to stop once its riders leave. /// A frame being read counts as a reader of its group, and a group a track subscription /// or fetch handed out keeps that track wanted until a reader reads its end /// ([`track::Demand`]). diff --git a/rs/moq-net/tests/integration/claim_continues.rs b/rs/moq-net/tests/integration/claim_continues.rs index d479dc5740d..5cf86df7345 100644 --- a/rs/moq-net/tests/integration/claim_continues.rs +++ b/rs/moq-net/tests/integration/claim_continues.rs @@ -19,7 +19,7 @@ const TEST_TIMEOUT: Duration = Duration::from_secs(600); fn produce_origin(hop: u64) -> origin::Producer { let (producer, driver) = origin::Producer::new(origin::Config::new(std::num::NonZeroU64::new(hop).unwrap())); support::harness::spawn(driver); - producer + producer.with_proxy(true) } fn lite07() -> Version { From d350370715f4b2d198e4b413d6cd9ea315ef6f85 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sun, 8 Nov 2026 08:41:18 -0800 Subject: [PATCH 5/7] docs(quest): fix pullfrog drift in instance-provenance and compression names Co-Authored-By: Claude Opus 5.5 --- quest/m2/instance-provenance.md | 5 ++--- quest/m3/stats/README.md | 2 +- quest/m5/e2ee/README.md | 2 +- quest/m5/json-value-diff.md | 2 +- quest/m5/net-wrap/e2ee.md | 4 ++-- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/quest/m2/instance-provenance.md b/quest/m2/instance-provenance.md index 8c2a965ca84..f50b685128b 100644 --- a/quest/m2/instance-provenance.md +++ b/quest/m2/instance-provenance.md @@ -50,8 +50,7 @@ Call sites (`git grep -n 'is_minted\|isMinted\|MINTED'` over `rs/` and `~` paragraph near "A version before this one carries no Instance", and the lite-07 changelog line on minting), and the lite corpus fixtures. - Readers of the flag: `rs/moq-net/src/model/origin.rs`, - `rs/moq-net/src/model/broadcast.rs` / `model/track.rs` (`minted()` - state), `rs/moq-crypto/src/sign/broadcast.rs`, + `rs/moq-crypto/src/sign/broadcast.rs`, `js/crypto/src/sign/broadcast.ts`, `rs/moq-mux/src/source.rs`, `rs/moq-mux/src/follow.rs`, `rs/moq-gst/src/source/imp.rs`, `js/net/src/consume.ts`, `js/net/src/origin.ts`, `js/watch/src/broadcast.ts`. @@ -76,5 +75,5 @@ whichever lands second adds its changelog line beside the other's. ## Related -- [moq-net's remaining surface fixes](/quest/m2/api-shape/net.md) - the +- [moq-net's route stream goes public](/quest/m2/api-shape/net.md) - the audit item this replaces diff --git a/quest/m3/stats/README.md b/quest/m3/stats/README.md index a7b70679777..7bd6cbe9bf4 100644 --- a/quest/m3/stats/README.md +++ b/quest/m3/stats/README.md @@ -93,7 +93,7 @@ kind. browser has only PROBE rtt until [#2733](https://github.com/moq-dev/moq/issues/2733)-style counters land. - **Encoding**: cumulative counters about once a second through - `moq_json::snapshot` on one track with `compress: true`, produced whenever + `moq_json::snapshot` on one track with `Compression::Deflate`, produced whenever stats are enabled. The [m1 compression migration](https://github.com/moq-dev/moq/pull/7046) removed the `.z` siblings and kept merge-patch deltas on the single track. An unsubscribed stats track never leaves the process. Gauges are carried but never summed. diff --git a/quest/m5/e2ee/README.md b/quest/m5/e2ee/README.md index 9258d7d0cf8..48cd60aae98 100644 --- a/quest/m5/e2ee/README.md +++ b/quest/m5/e2ee/README.md @@ -35,7 +35,7 @@ The Rust and TypeScript cores expose the same surface, and nothing else: - A core produces only under an epoch it minted itself (decided 2026-10-08). Only `credential.produce()` mints a producing generation, and it takes no epoch: it mints a fresh UUIDv7 and returns a `generation::Producer` owning `epoch()` for the route and `name(semantic)` for opaque track names. `credential.consume(epoch)` binds a discovered epoch as a consume-only `generation::Consumer` with `name(semantic)`. The two are separate types, so producing under a discovered or shared epoch does not compile (names decided 2026-10-11 in [#5313](https://github.com/moq-dev/moq/pull/5313)). Clones of a producing generation share publisher claims so reopening a track cannot reset its nonce counters. - Applications only handle semantic track names (maintainer, 2026-10-17). `broadcast::Producer` wraps a `moq-net` broadcast under a producing generation and `broadcast::Consumer` wraps one under a consuming generation; each derives the physical name, so only the CDN sees physical names. `generation` no longer opens tracks itself. The broadcast wrappers merged in [#5876](https://github.com/moq-dev/moq/pull/5876). - The wrappers implement the [moq-net traits](/quest/m5/net-wrap/README.md) at the broadcast, track, group, and frame levels, datagrams included (decided 2026-10-20, maintainer, because one encrypted broadcast then works with every writer and reader). moq-mux, moq-json, hang, and the CLI publish and consume an encrypted broadcast unchanged, under semantic names, and every AEAD call still has the canonical physical name and transport identity. The e2ee mux bridge ([#5822](https://github.com/moq-dev/moq/pull/5822)) is closed and superseded. -- Errors are the draft's typed codes plus the transport's. Nothing catalog-, hang-, or MSF-shaped lives here: a catalog is a track under a derived name. The catalog owner sets logical `track::Info.compress`; the [e2ee wrapper](/quest/m5/net-wrap/e2ee.md) compresses before AEAD and authenticates the logical compression metadata. +- Errors are the draft's typed codes plus the transport's. Nothing catalog-, hang-, or MSF-shaped lives here: a catalog is a track under a derived name. The catalog owner sets logical `track::Info.compression`; the [e2ee wrapper](/quest/m5/net-wrap/e2ee.md) compresses before AEAD and authenticates the logical compression metadata. - Stateless `seal`/`open` primitives with caller-chosen identities, HKDF labels and info builders, raw key bytes, and process-global claims are not public. The vectors are tested inside each core. ### Application and platform shape diff --git a/quest/m5/json-value-diff.md b/quest/m5/json-value-diff.md index b003314adb3..82435561ba0 100644 --- a/quest/m5/json-value-diff.md +++ b/quest/m5/json-value-diff.md @@ -21,7 +21,7 @@ Compare three variants: 2. The `Value` diff: serialize `T` to a `Value` once, then diff it against the previous `Value`. 3. Compression only: deltas off, a full snapshot per frame in the same group, - and group DEFLATE through the track's `with_compress`. + and group DEFLATE through the track's `with_compression(Compression::Deflate)`. Measure each on producer CPU, consumer CPU, wire bytes after DEFLATE, allocations, and code size (`cargo llvm-lines` on a consumer crate such as diff --git a/quest/m5/net-wrap/e2ee.md b/quest/m5/net-wrap/e2ee.md index a6b369ee7aa..c5e0ac4b18c 100644 --- a/quest/m5/net-wrap/e2ee.md +++ b/quest/m5/net-wrap/e2ee.md @@ -27,7 +27,7 @@ the reverse (decided 2026-10-20, maintainer): event stays on moq-crypto's own consumer, outside the trait, for callers that hold the concrete type. A trait read can't carry it without breaking the exact mirror. -- `track::Info.compress` is logical. Ciphertext doesn't compress, so the +- `track::Info.compression` is logical. Ciphertext doesn't compress, so the wrapper compresses each group, and each datagram alone with a fresh window, with moq-net's [track compression](/doc/concept/compression.md) before AEAD, creates the @@ -47,7 +47,7 @@ the reverse (decided 2026-10-20, maintainer): [JS](/quest/m5/net-wrap/js.md). - The subscriber's wrapper learns the logical flag from authenticated E2EE metadata, never from the physical track (decided 2026-10-20, maintainer): - the physical track's `compress` is always false, so it can't signal it. + the physical track's `compression` is always `Compression::None`, so it can't signal it. The metadata lives in the E2EE track mapping, and a flag that fails authentication fails the track loudly. Not the encrypted catalog: the catalog track is itself compressed, so a subscriber would need the flag From 43ceded63b2508552aeb71af78844d7cd86cdaf0 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sun, 8 Nov 2026 08:46:53 -0800 Subject: [PATCH 6/7] docs: name track compression's landed API in remaining MIGRATE notes and quests Co-Authored-By: Claude Opus 5.5 --- quest/m3/release/migrate-audit.md | 2 +- quest/m4/track-info-docs.md | 2 +- quest/m5/e2ee/rust-publish.md | 2 +- quest/m5/net-wrap/js.md | 2 +- quest/m5/teleop-mavlink.md | 2 +- quest/m5/teleop-robot.md | 2 +- rs/hang/MIGRATE.md | 4 ++-- rs/moq-stats/MIGRATE.md | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/quest/m3/release/migrate-audit.md b/quest/m3/release/migrate-audit.md index 45a62e30e0e..81cd5507de3 100644 --- a/quest/m3/release/migrate-audit.md +++ b/quest/m3/release/migrate-audit.md @@ -41,7 +41,7 @@ m1 quest on 2026-10-22. and possibly moq-audio and moq-video), because their breaks predate the backfill's merge base. The [compression migration](https://github.com/moq-dev/moq/pull/7046) deleted moq-flate before this cut: audit the migration from its published - API to ordinary tracks with `compress`, rather than promising a new + API to ordinary tracks with `compression`, rather than promising a new moq-flate transition release. - Each version-transition section, starting from the `## Unreleased` entries already on `main`, says how to migrate from the published diff --git a/quest/m4/track-info-docs.md b/quest/m4/track-info-docs.md index d1039bff7ef..265dc0ad532 100644 --- a/quest/m4/track-info-docs.md +++ b/quest/m4/track-info-docs.md @@ -16,7 +16,7 @@ Planned 2026-11-03 (maintainer, `/quest-plan`), from the follow-ups of The docs say "priority, ordering, latency budget, and timescale" (Kotlin, Dart) and "priority, group ordering, max age, and timescale" (Swift). `MoqTrackInfo` (`rs/moq-ffi/src/producer.rs`) has `priority`, `max_age`, -`refresh`, `timescale` and `compress`. Ordering and delay are subscriber-side +`refresh`, `timescale` and `compression`. Ordering and delay are subscriber-side (`MoqSubscription`). #7729 adds `max_age_unlimited`, so describe the record as it stands when this lands. diff --git a/quest/m5/e2ee/rust-publish.md b/quest/m5/e2ee/rust-publish.md index 693ae75e25d..4c83f3498f3 100644 --- a/quest/m5/e2ee/rust-publish.md +++ b/quest/m5/e2ee/rust-publish.md @@ -27,7 +27,7 @@ in advance, so it never needed the undeclared-name handler (maintainer, custom-track mappings only inside the encrypted catalog. - Encrypt the single Hang `catalog.json` left by the [m1 compression migration](https://github.com/moq-dev/moq/pull/7046), and encrypt or - suppress the MSF catalog. Set logical `compress` on protected catalog + suppress the MSF catalog. Set logical `compression` on protected catalog tracks; the [e2ee wrapper](/quest/m5/net-wrap/e2ee.md) compresses before encryption. Retain ordinary plaintext publication unchanged outside E2EE mode. - Cover every current Rust importer and capture path so a convenience API diff --git a/quest/m5/net-wrap/js.md b/quest/m5/net-wrap/js.md index 3a655fc66ec..f240f67ac67 100644 --- a/quest/m5/net-wrap/js.md +++ b/quest/m5/net-wrap/js.md @@ -18,7 +18,7 @@ its own decryption path. and `@moq/watch`'s subscriptions. - `@moq/crypto`'s broadcast, track, and group wrappers adapt to `@moq/net`'s method shapes, as moq-crypto does in Rust, with its errors mapped to - `@moq/net`'s. Like moq-crypto, it compresses a `compress` track before + `@moq/net`'s. Like moq-crypto, it compresses a `compression: "deflate"` track before encryption, publishes the physical track uncompressed, and carries the logical flag in the same authenticated E2EE metadata ([e2ee](/quest/m5/net-wrap/e2ee.md)). diff --git a/quest/m5/teleop-mavlink.md b/quest/m5/teleop-mavlink.md index bbe93b62108..6f653a91bb3 100644 --- a/quest/m5/teleop-mavlink.md +++ b/quest/m5/teleop-mavlink.md @@ -77,7 +77,7 @@ on their own retransmission across a link drop. The [compression migration](https://github.com/moq-dev/moq/pull/7046) deleted the moq-flate snapshot and stream helpers. Keep these framing rules on plain -tracks, setting `compress` when useful, rather than depending on those helpers. +tracks, setting `compression` when useful, rather than depending on those helpers. ### Deliberately out of scope diff --git a/quest/m5/teleop-robot.md b/quest/m5/teleop-robot.md index ca8d6563595..2d10477c0ea 100644 --- a/quest/m5/teleop-robot.md +++ b/quest/m5/teleop-robot.md @@ -98,7 +98,7 @@ The framing is where the guarantee lives, not the subscription flags: one needs: `moq-json`'s snapshot and stream modes for JSON; plain tracks for opaque bytes, one group per latest value or one bounded ordered group for the append-log. The [compression migration](https://github.com/moq-dev/moq/pull/7046) - deleted moq-flate's snapshot/stream helpers, so use the track's `compress` + deleted moq-flate's snapshot/stream helpers, so use the track's `compression` flag when compression is useful, not those helpers. - Per-stage timestamp instrumentation, generalised from moq-boy's `status` track. Check it against the publisher-reported stats track diff --git a/rs/hang/MIGRATE.md b/rs/hang/MIGRATE.md index 2a99b33c714..be19659df90 100644 --- a/rs/hang/MIGRATE.md +++ b/rs/hang/MIGRATE.md @@ -26,8 +26,8 @@ A refused subscription now surfaces from the first read. ### Compression moves to the track `catalog::Compression`, the `compression` field on `JsonConfig` and `BinaryConfig`, `Catalog::COMPRESSED_NAME`, and `catalog::Consumer::compressed` are gone. -A compressed track is one name with `compress: true` on its `moq_net::track::Info`, and moq-net hands every reader plain frames, so read `catalog.json` with `Consumer::new` whether or not it is compressed. -`Catalog::default_track_info()` sets `compress`, so a publisher using it compresses `catalog.json`; stop publishing `catalog.json.z`. +A compressed track is one name with `with_compression(Compression::Deflate)` on its `moq_net::track::Info`, and moq-net hands every reader plain frames, so read `catalog.json` with `Consumer::new` whether or not it is compressed. +`Catalog::default_track_info()` sets `Compression::Deflate`, so a publisher using it compresses `catalog.json`; stop publishing `catalog.json.z`. An old catalog's `"compression"` key on a data track lands in the entry's `extra`, and its frames are still app-level DEFLATE nothing here inflates. ### `moq_net::Path` has no lifetime diff --git a/rs/moq-stats/MIGRATE.md b/rs/moq-stats/MIGRATE.md index e69f55662c4..cec2a377d4c 100644 --- a/rs/moq-stats/MIGRATE.md +++ b/rs/moq-stats/MIGRATE.md @@ -35,7 +35,7 @@ The re-exported `moq_stats::Refusal` follows moq-net's rename: use `moq_stats::R ### One compressed track per stats name -The `.z` siblings are gone: `totals.json`, `