diff --git a/doc/.vitepress/drafts.test.ts b/doc/.vitepress/drafts.test.ts
index df79be4f232..476f408c437 100644
--- a/doc/.vitepress/drafts.test.ts
+++ b/doc/.vitepress/drafts.test.ts
@@ -128,20 +128,20 @@ describe("tables render as tables", () => {
const rendered = html(page as DraftPage);
- // The Bidirectional Streams table: one header, seven body rows, each
+ // The Bidirectional Streams table: one header, eight body rows, each
// separated by a kramdown rule in the source. Cells carry the source's
// alignment, so match around the style attribute.
const header = /
]*>Stream<\/th>/.exec(rendered);
expect(header).not.toBeNull();
- for (const stream of ["Announce", "Subscribe", "Fetch", "Probe", "Goaway", "Track", "Auth"]) {
+ for (const stream of ["Announce", "Subscribe", "Fetch", "Probe", "Goaway", "Track", "Auth", "Subscribe All"]) {
expect(rendered).toMatch(new RegExp(` | ]*>${stream} | `));
}
- // One header row plus seven body rows, in a single table.
+ // One header row plus eight body rows, in a single table.
const start = rendered.lastIndexOf("")[0];
- expect(rows.match(//g) ?? []).toHaveLength(8);
+ expect(rows.match(/
/g) ?? []).toHaveLength(9);
});
});
diff --git a/doc/concept/moq-lite.md b/doc/concept/moq-lite.md
index 4a207f14975..ed9f5a6c18c 100644
--- a/doc/concept/moq-lite.md
+++ b/doc/concept/moq-lite.md
@@ -209,6 +209,13 @@ JSON snapshot). Groups can also be fetched by sequence number, which is how the
[HLS gateway](/bin/hls) and the relay's [HTTP fetch](/bin/relay/http) serve
history.
+On moq-lite 07 (`moq-lite-07-wip`, opt-in) a subscriber can instead ask for
+every track of every broadcast under a path prefix in one request, including
+tracks and broadcasts that appear later, so it records everything without
+reading a catalog. Only tracks a publisher creates are listed, never ones it
+serves on request, and a relay answers every such request for a prefix with
+one request upstream. Rust only for now.
+
Each subscription carries the knobs that decide behavior under congestion:
| Knob | Effect |
diff --git a/drafts/draft-lcurley-moq-lite.md b/drafts/draft-lcurley-moq-lite.md
index 941072fbbe6..e857a65d1fe 100644
--- a/drafts/draft-lcurley-moq-lite.md
+++ b/drafts/draft-lcurley-moq-lite.md
@@ -396,6 +396,8 @@ There's a 1-byte STREAM_TYPE at the beginning of each stream.
| ------- | ------------- | ----------- |
| 0x7 | Auth | Either |
| ------- | ------------- | ----------- |
+| 0x8 | Subscribe All | Subscriber |
+| ------- | ------------- | ----------- |
### Announce
A subscriber can open an Announce Stream to discover routes matching a prefix.
@@ -519,6 +521,29 @@ A publisher closing its session gracefully MUST wait for the subscriber's FIN or
A subscriber MAY cancel by closing its side (FIN); the publisher then closes its side (FIN) without owing SUBSCRIBE_END.
Unbounded subscriptions stay open until SUBSCRIBE_END, and either endpoint MAY reset the stream at any time.
+### Subscribe All {#subscribe-all-stream}
+A subscriber opens a Subscribe All Stream (0x8) to subscribe to every Track of every Broadcast under a prefix, including Tracks and Broadcasts that appear later.
+A subscriber that wants every Track, such as an archive, needs no catalog and opens no stream per Track.
+
+The subscriber sends a SUBSCRIBE_ALL message followed by any number of SUBSCRIBE_ALL_UPDATE messages, each of which applies to every Track of the request.
+The publisher sends a BROADCAST_START for each Broadcast it holds under the prefix, as it learns of it, and a BROADCAST_START for a new publisher instance at the same path even while the old one is listed.
+A Broadcast whose path has a `.`-prefixed segment below the prefix is not listed (see [Hidden Paths](#hidden)).
+The publisher then sends a TRACK_START for each Track the Broadcast's producer creates, and serves it as if the subscriber had sent a SUBSCRIBE for it with the request's preferences and no bounds: TRACK_OK and TRACK_END stand in for the Track's SUBSCRIBE_OK and SUBSCRIBE_END, its groups arrive on Track Group Streams (0x2), and a TRACK_RESET stands in for the reset of its Subscribe Stream.
+A Track served only on request, which a producer never creates, is never listed.
+A publisher MUST NOT deliver a Track of a SUBSCRIBE_ALL as a datagram.
+Once a Broadcast ends, the publisher sends a BROADCAST_END and lists no more of its Tracks; each listed Track still ends with its own TRACK_END or TRACK_RESET.
+
+A Track Group Stream can arrive before the TRACK_START naming its Track, since the two travel on different streams.
+The subscriber MUST NOT reject such a stream while the request is open; it waits for the TRACK_START.
+
+The request needs subscribe permission on the prefix, and the publisher MUST NOT list a Broadcast the session does not allow.
+It counts as one subscription against the publisher's bound (see [Resource Exhaustion](#resource-exhaustion)).
+A relay MAY answer every SUBSCRIBE_ALL for a prefix with one request upstream.
+Such a relay sends the highest `Subscriber Priority` and `Subscriber Max Age` its downstream readers ask for, with SUBSCRIBE_ALL_UPDATE as they change.
+A subscriber that wants a listed Track's groups below its TRACK_OK `Group` sends a SUBSCRIBE for them that ends before that `Group`; a relay without them does the same upstream.
+The subscriber cancels by closing its side (FIN), and the publisher then closes its own without owing anything further.
+The publisher closes its side once it will list no more Broadcasts and every listed Track has ended.
+
### Fetch
A subscriber opens a Fetch Stream (0x3) to request a single Group from a Track.
@@ -699,6 +724,8 @@ Unidirectional streams are used for data transmission.
| ------ | -------- | ----------- |
| 0x1 | Setup | Either |
| ------ | -------- | ----------- |
+| 0x2 | Track Group | Publisher |
+| ------ | -------- | ----------- |
### Setup {#setup-stream}
Each endpoint MUST open a Setup Stream (0x1) at the start of the session to advertise the optional capabilities and extensions it supports.
@@ -710,7 +737,8 @@ An endpoint with no optional capabilities sends a SETUP with an empty parameter
See the [Session](#session) section for how an endpoint avoids waiting on the peer's SETUP before exchanging other streams.
### Group
-A publisher creates Group Streams in response to a Subscribe Stream.
+A publisher creates Group Streams in response to a Subscribe Stream, and Track Group Streams (0x2) for a Track of a [Subscribe All Stream](#subscribe-all-stream).
+A Track Group Stream starts with a TRACK_GROUP message instead of a GROUP message and is otherwise the same.
A Group Stream MUST start with a GROUP message and MAY be followed by any number of FRAME messages.
A Group MAY contain zero FRAME messages, potentially indicating a gap in the track.
@@ -1342,6 +1370,129 @@ The publisher MUST NOT send SUBSCRIBE_END until every Group Stream it will open
The subscriber has received every Group Stream once it has read the header of `Stream Count` of them, which MAY happen after SUBSCRIBE_END or the FIN since streams are not ordered.
A Group Stream reset before its header arrived is never seen, so a subscriber SHOULD bound how long it waits for the rest, for example by `Subscriber Max Age`.
+## SUBSCRIBE_ALL {#subscribe-all}
+SUBSCRIBE_ALL is the first message on a Subscribe All Stream.
+
+~~~
+SUBSCRIBE_ALL Message {
+ Message Length (i)
+ Subscribe ID (i)
+ Broadcast Path Prefix (s)
+ Subscriber Priority (8)
+ Group Order (8)
+ Subscriber Max Age (i)
+}
+~~~
+
+**Subscribe ID**:
+Drawn from the same space as the SUBSCRIBE `Subscribe ID`, and named by every TRACK_GROUP of the request.
+
+**Broadcast Path Prefix**:
+The prefix whose Broadcasts are listed.
+
+See [SUBSCRIBE](#subscribe) for the other fields, which apply to every listed Track.
+
+## SUBSCRIBE_ALL_UPDATE
+SUBSCRIBE_ALL_UPDATE changes the preferences of every Track of a SUBSCRIBE_ALL.
+
+~~~
+SUBSCRIBE_ALL_UPDATE Message {
+ Message Length (i)
+ Subscriber Priority (8)
+ Group Order (8)
+ Subscriber Max Age (i)
+}
+~~~
+
+## BROADCAST_START {#broadcast-start}
+BROADCAST_START lists a Broadcast on a Subscribe All Stream.
+Each one implicitly assigns the next Broadcast ID, starting at 0.
+
+~~~
+BROADCAST_START Message {
+ Type (i) = 0x0
+ Message Length (i)
+ Broadcast Path Suffix (s)
+ Epoch (b)
+}
+~~~
+
+**Broadcast Path Suffix**:
+The Broadcast's path, relative to the requested prefix.
+
+**Epoch**:
+The publisher instance, encoded as in [ANNOUNCE_START](#announce-start).
+
+## BROADCAST_END
+BROADCAST_END says a listed Broadcast has ended: no further Track of it is listed.
+
+~~~
+BROADCAST_END Message {
+ Type (i) = 0x1
+ Message Length (i)
+ Broadcast ID (i)
+}
+~~~
+
+## TRACK_START {#track-start}
+TRACK_START lists a Track of a listed Broadcast, with its [TRACK_INFO](#track-info) fields.
+Each one implicitly assigns the next Track ID, starting at 0.
+A Broadcast ID that is unknown or has ended is a PROTOCOL_VIOLATION.
+
+~~~
+TRACK_START Message {
+ Type (i) = 0x2
+ Message Length (i)
+ Broadcast ID (i)
+ Track Name (s)
+ Publisher Priority (8)
+ Publisher Max Age (i)
+ Timescale (i)
+}
+~~~
+
+## TRACK_OK
+TRACK_OK is a listed Track's [SUBSCRIBE_OK](#subscribe-ok).
+
+~~~
+TRACK_OK Message {
+ Type (i) = 0x3
+ Message Length (i)
+ Track ID (i)
+ Group (i)
+ Largest Group (i)
+ [Largest Frame (i)]
+}
+~~~
+
+## TRACK_END
+TRACK_END is a listed Track's [SUBSCRIBE_END](#subscribe-end), counting its Track Group Streams.
+
+~~~
+TRACK_END Message {
+ Type (i) = 0x4
+ Message Length (i)
+ Track ID (i)
+ Group (i)
+ Stream Count (i)
+}
+~~~
+
+## TRACK_RESET
+TRACK_RESET ends a listed Track with an error, as a reset of its Subscribe Stream would.
+
+~~~
+TRACK_RESET Message {
+ Type (i) = 0x5
+ Message Length (i)
+ Track ID (i)
+ Error Code (i)
+}
+~~~
+
+**Error Code**:
+A stream error code (see [Stream Error Codes](#stream-error-codes)).
+
## FETCH
FETCH is sent by a subscriber to request a single group from a track.
@@ -1555,6 +1706,27 @@ A non-zero value means the leading frames are not on this stream, either because
The subscriber MUST NOT assume it will receive the missing frames on another stream; they are a gap unless a separate subscription or FETCH covers them.
+## TRACK_GROUP
+The TRACK_GROUP message starts a Track Group Stream: a GROUP of a Track listed by a SUBSCRIBE_ALL.
+
+~~~
+TRACK_GROUP Message {
+ Message Length (i)
+ Subscribe ID (i)
+ Track ID (i)
+ Group Sequence (i)
+ Frame Start (i)
+}
+~~~
+
+**Subscribe ID**:
+The SUBSCRIBE_ALL's Subscribe ID.
+
+**Track ID**:
+The Track, as assigned by its TRACK_START.
+
+See [GROUP](#group) for the other fields.
+
## FRAME
The FRAME message is a payload within a group.
@@ -1634,6 +1806,7 @@ The `Message Length` describes the payload size on the wire.
- Any Setup Stream or bidirectional stream message that fails to decode closes the session with PROTOCOL_VIOLATION; previously only an unexpected Message Length did, as a SHOULD. A stream ending mid-message outside the Setup and Auth Streams, a malformed GROUP or FRAME, and a stream type the negotiated version predates still affect only that stream.
- A Report-level publisher reads and ignores PROBE targets instead of resetting the Probe Stream.
- Added NOT_SUPPORTED (0x30) to session errors; unsupported Auth Stream tokens and grants use AUTH_ERROR before or after a grant.
+- Added the Subscribe All Stream (0x8) and the Track Group Stream (0x2): SUBSCRIBE_ALL subscribes to every Track of every Broadcast under a prefix, listed with BROADCAST_START, BROADCAST_END, and TRACK_START, and served with TRACK_OK, TRACK_END, and TRACK_RESET. Earlier versions have neither.
- Added the Auth Stream (0x7) with AUTH, AUTH_OK, and AUTH_ERROR: either endpoint presents a token on its own stream and learns the [path patterns](#path-pattern) it may publish and subscribe to. The union of a session's open grants is its scope. A shrink withdraws what it no longer covers, and an announcement outside the scope closes the session with UNAUTHORIZED. A peer without the stream resets it.
## moq-lite-06
diff --git a/quest/m1/archive/README.md b/quest/m1/archive/README.md
index be321e5fc98..b16b2a0f28a 100644
--- a/quest/m1/archive/README.md
+++ b/quest/m1/archive/README.md
@@ -77,6 +77,7 @@ from a host. Each child fixes the stale docs it touches.
## Required
- [SUBSCRIBE_ALL](/quest/m1/archive/subscribe-all.md) - one prefix-scoped moq-lite-07 request delivers every track of every broadcast under a path, including later ones, and relays fan it out from one upstream request
+- [SUBSCRIBE_ALL in js/net](/quest/m1/archive/subscribe-all-js.md) - `@moq/net` lists and serves every track of every broadcast under a prefix over lite-07, mirroring the Rust names
- [Archive producer](/quest/m1/archive/producer.md) - `archive::Producer` stores every matching broadcast as duration-cut per-track objects keyed by group and pts, recording gaps instead of stalling, with an optional DVR mode
- [Archive consumer](/quest/m1/archive/consumer.md) - `archive::Consumer` serves a stored prefix as a broadcast from its key listing, and `moq export/import archive` use the new pair
- [Catalog HLS field](/quest/m1/archive/catalog-hls.md) - the root `archive` section is gone; an opt-in per-rendition `hls` field marks each aligned HLS segment's first group and pts and declares its nominal duration
diff --git a/quest/m1/archive/subscribe-all-js.md b/quest/m1/archive/subscribe-all-js.md
new file mode 100644
index 00000000000..10d740c526e
--- /dev/null
+++ b/quest/m1/archive/subscribe-all-js.md
@@ -0,0 +1,35 @@
+# [L] SUBSCRIBE_ALL in js/net
+
+## Goal
+
+`@moq/net` speaks moq-lite-07's SUBSCRIBE_ALL in both directions. A JS
+consumer lists every broadcast under a prefix and every track each one's
+producer creates, with the Rust names mirrored (`broadcasts(prefix)` on the
+origin consumer, `tracks()` on the broadcast consumer). A JS publisher answers
+a peer's SUBSCRIBE_ALL from its own broadcasts. Older versions refuse the
+stream, as in Rust.
+
+## Plan
+
+See [SUBSCRIBE_ALL](/quest/m1/archive/subscribe-all.md) for the decisions and
+the wire, which the Rust half fixed in `drafts/draft-lcurley-moq-lite.md`.
+
+- Codec: SUBSCRIBE_ALL, SUBSCRIBE_ALL_UPDATE, the six typed responses, and the
+ TRACK_GROUP header (uni 0x2), refused before lite-07.
+- Subscriber: one request per prefix per session, shared by every listing of
+ it; a TRACK_GROUP stream ahead of its TRACK_START waits for it.
+- Publisher: list each broadcast as it appears and each track as its producer
+ creates it, never one served only on request; no datagrams.
+- Mirror whatever the Rust half settles for the open decisions it left
+ (start floor, sharing listed tracks with ordinary requests).
+
+Tests: Rust and JS list each other's broadcasts over lite-07, directly and
+through moq-relay, including a track added later and a broadcast ending; a
+lite-06 session lists nothing.
+
+Public API: `broadcasts(prefix)` and `tracks()` in `@moq/net`. Wire: none
+beyond the Rust half.
+
+## Required
+
+- [SUBSCRIBE_ALL](/quest/m1/archive/subscribe-all.md) - fixes the lite-07 wire and the Rust model this mirrors
diff --git a/quest/m1/archive/subscribe-all.md b/quest/m1/archive/subscribe-all.md
index de814093b9e..73b50b2f33a 100644
--- a/quest/m1/archive/subscribe-all.md
+++ b/quest/m1/archive/subscribe-all.md
@@ -9,7 +9,8 @@ request and broadcasts that appear later, and delivers their groups; a
broadcast's tracks end when it ends. It never creates a track the publisher
serves only on request (an any-name `broadcast::Dynamic` handler such as a
transcoder). A relay answers many downstream SUBSCRIBE_ALLs from one upstream
-request. Rust and JS both speak it.
+request. Rust speaks it here, and
+[SUBSCRIBE_ALL in js/net](/quest/m1/archive/subscribe-all-js.md) mirrors it.
## Plan
@@ -60,15 +61,14 @@ Guidance:
delivered.
- Fan-out: benchmark downstream requests against broadcast and track count per
the AGENTS.md fan-out rule.
-- Split the JS half into its own quest if the PR grows too large to review.
+- The JS half is [SUBSCRIBE_ALL in js/net](/quest/m1/archive/subscribe-all-js.md).
Test on mock time, directly and through a relay: tracks present at the
request, a track added later (its first group arrives), a broadcast appearing
and ending under the prefix, a new epoch at the same path, a dynamic-only track
never created, and two downstream requests sharing one upstream request.
-Public API: the new prefix hook in Rust and `@moq/net`, mirrored names. Wire:
-a new lite-07-wip request.
+Public API: the new prefix hook in Rust. Wire: a new lite-07-wip request.
## Related
diff --git a/quest/m1/lite07-finalize.md b/quest/m1/lite07-finalize.md
index cafd9f22258..a1fc4dade0b 100644
--- a/quest/m1/lite07-finalize.md
+++ b/quest/m1/lite07-finalize.md
@@ -89,6 +89,7 @@ is published; older versions are unchanged.
- [Compressed tracks in Rust](/quest/m1/compress/core.md) - TRACK_INFO carries the compress flag and the frame header each compressed frame's inflated size
- [Compressed tracks in js/net](/quest/m1/compress/js.md) - JS reads and writes compressed lite-07 tracks instead of refusing them
- [SUBSCRIBE_ALL](/quest/m1/archive/subscribe-all.md) - lite-07 carries the prefix-scoped request for every track of every broadcast under a path
+- [SUBSCRIBE_ALL in js/net](/quest/m1/archive/subscribe-all-js.md) - JS speaks SUBSCRIBE_ALL in both directions instead of refusing it
## Related
diff --git a/rs/moq-net/Cargo.toml b/rs/moq-net/Cargo.toml
index 42161b3c94b..539d56c624b 100644
--- a/rs/moq-net/Cargo.toml
+++ b/rs/moq-net/Cargo.toml
@@ -187,3 +187,8 @@ required-features = ["async"]
name = "memory"
harness = false
required-features = ["async"]
+
+[[bench]]
+name = "subscribe-all"
+harness = false
+required-features = ["async"]
diff --git a/rs/moq-net/benches/subscribe-all.rs b/rs/moq-net/benches/subscribe-all.rs
new file mode 100644
index 00000000000..34dfe082b0c
--- /dev/null
+++ b/rs/moq-net/benches/subscribe-all.rs
@@ -0,0 +1,285 @@
+//! SUBSCRIBE_ALL through a relay: listers each open one `broadcasts(prefix)` that covers
+//! every track of a publisher, over the in-memory mock transport.
+//!
+//! `subscribe_all_round` times one round: every track writes a group and every lister
+//! reads it. `subscribe_round` is its control, each track requested with its own SUBSCRIBE.
+//! `subscribe_all_new_broadcast` times one broadcast's life: created with one track,
+//! listed and read by every lister, then dropped; `subscribe_new_broadcast` is its control. Each sweeps listers against the
+//! broadcasts already listed, so a cost that grows with the table instead of the touched
+//! track shows as a slope.
+//!
+//! Everything runs on one current-thread runtime, so the only work measured is the
+//! protocol and model code, never scheduling across threads.
+//!
+//! Run with `cargo bench -p moq-net --bench subscribe-all`.
+
+// Custom timings measure the real time the work took, not the ambient clock.
+#![allow(clippy::disallowed_methods)]
+
+#[path = "../tests/integration/support/mod.rs"]
+mod support;
+
+use std::time::{Duration, Instant};
+
+use criterion::{BenchmarkId, Criterion, Throughput, criterion_group, criterion_main};
+use moq_net::{Epoch, Hop, Timestamp, Version, broadcast, origin, track};
+use support::harness::{MockConnectOptions, MockPair, connect_mock};
+
+const VERSION: &str = "moq-lite-07-wip";
+
+/// Tracks per broadcast, as a small rendition ladder plus audio.
+const TRACKS: usize = 4;
+
+/// Listers sharing the relay.
+const LISTERS: [usize; 3] = [1, 8, 32];
+
+/// Broadcasts already published under the prefix.
+const BROADCASTS: [usize; 3] = [1, 16, 64];
+
+fn runtime() -> tokio::runtime::Runtime {
+ tokio::runtime::Builder::new_current_thread()
+ .enable_time()
+ .build()
+ .unwrap()
+}
+
+fn timed() -> track::Info {
+ track::Info::default().with_timescale(moq_net::Timescale::MILLI)
+}
+
+fn produce(hop: u64) -> origin::Producer {
+ let (producer, driver) = origin::Producer::new(origin::Config::new(Hop::new(hop).unwrap()));
+ support::harness::spawn(driver);
+ producer
+}
+
+/// Have `to` pull everything `from` publishes.
+async fn link(from: &origin::Producer, to: &origin::Producer) -> MockPair {
+ let mut options = MockConnectOptions::new(VERSION.parse::().unwrap());
+ options.server_publish = Some(from.consume());
+ options.client_subscribe = Some(to.clone());
+ connect_mock(options).await
+}
+
+fn write(track: &track::Producer, sequence: u64) {
+ let mut group = track.create_group(moq_net::group::Info { sequence }).unwrap();
+ group
+ .write_frame(Timestamp::from_millis(sequence).unwrap(), &[0u8; 64][..])
+ .unwrap();
+ group.finish().unwrap();
+}
+
+/// Read the next group whole, returning its sequence.
+async fn read(subscriber: &mut track::Subscriber) -> u64 {
+ let mut group = subscriber.recv_group().await.unwrap().expect("track ended");
+ while group.read_frame().await.unwrap().is_some() {}
+ group.sequence
+}
+
+/// Announced with an epoch, so a relay's listing and its requests share one copy.
+fn route() -> origin::Route {
+ origin::Route::default().with_epoch(Epoch::mint())
+}
+
+fn subscription() -> track::Subscription {
+ track::Subscription::default().with_max_delay(Duration::from_secs(60))
+}
+
+/// A lister's open request, with every listed track subscribed.
+struct Lister {
+ /// None for the control, which requests each track by name.
+ cursor: Option,
+ subscribers: Vec,
+ origin: origin::Producer,
+ _pair: MockPair,
+}
+
+/// A publisher with `broadcasts` broadcasts of [`TRACKS`] tracks, a relay, and `listers`
+/// listers that have read group 0 of every track.
+struct Room {
+ publisher: origin::Producer,
+ tracks: Vec,
+ listers: Vec,
+ _broadcasts: Vec,
+ _relay: origin::Producer,
+ _pair: MockPair,
+ sequence: u64,
+}
+
+impl Room {
+ /// `listed` subscribes through SUBSCRIBE_ALL, otherwise through a SUBSCRIBE per track.
+ async fn new(broadcasts: usize, listers: usize, listed: bool) -> Self {
+ let publisher = produce(1);
+ let relay = produce(2);
+ let pair = link(&publisher, &relay).await;
+
+ let mut tracks = Vec::new();
+ let mut held = Vec::new();
+ for index in 0..broadcasts {
+ let broadcast = publisher.create_broadcast(format!("room/{index}")).unwrap();
+ for name in 0..TRACKS {
+ let track = broadcast.create_track(name.to_string(), timed()).unwrap();
+ write(&track, 0);
+ tracks.push(track);
+ }
+ broadcast.announce(route()).unwrap();
+ held.push(broadcast);
+ }
+
+ let mut room = Self {
+ publisher,
+ tracks,
+ listers: Vec::new(),
+ _broadcasts: held,
+ _relay: relay.clone(),
+ _pair: pair,
+ sequence: 0,
+ };
+ for lister in 0..listers {
+ let origin = produce(3 + lister as u64);
+ let pair = link(&relay, &origin).await;
+ let consumer = origin.consume();
+ consumer
+ .routed(format!("room/{}", broadcasts - 1))
+ .await
+ .expect("announced");
+ let mut tracks = Vec::new();
+ let cursor = match listed {
+ true => {
+ let mut cursor = consumer.broadcasts("room").unwrap();
+ let mut listed = Vec::new();
+ for _ in 0..broadcasts {
+ listed.push(cursor.next().await.expect("listing ended").tracks());
+ }
+ for listed in &mut listed {
+ for _ in 0..TRACKS {
+ tracks.push(listed.next().await.expect("tracks ended"));
+ }
+ }
+ Some(cursor)
+ }
+ false => {
+ for index in 0..broadcasts {
+ let broadcast = consumer.routed_broadcast(format!("room/{index}")).await.unwrap();
+ for name in 0..TRACKS {
+ tracks.push(broadcast.track(&name.to_string()).unwrap());
+ }
+ }
+ None
+ }
+ };
+ let mut subscribers = Vec::new();
+ for track in tracks {
+ let mut subscriber = track.subscribe(subscription()).await.unwrap();
+ assert_eq!(read(&mut subscriber).await, 0);
+ subscribers.push(subscriber);
+ }
+ room.listers.push(Lister {
+ cursor,
+ subscribers,
+ origin,
+ _pair: pair,
+ });
+ }
+ room
+ }
+
+ /// Every track writes a group and every lister reads it.
+ async fn round(&mut self) {
+ self.sequence += 1;
+ for track in &self.tracks {
+ write(track, self.sequence);
+ }
+ for lister in &mut self.listers {
+ for subscriber in &mut lister.subscribers {
+ assert_eq!(read(subscriber).await, self.sequence);
+ }
+ }
+ }
+
+ /// A new broadcast with one track, listed and read by every lister, then dropped.
+ async fn new_broadcast(&mut self, index: usize) {
+ let broadcast = self.publisher.create_broadcast(format!("room/new{index}")).unwrap();
+ let track = broadcast.create_track("0", timed()).unwrap();
+ write(&track, 0);
+ broadcast.announce(route()).unwrap();
+ for lister in &mut self.listers {
+ let consumer = match lister.cursor.as_mut() {
+ Some(cursor) => {
+ let listed = cursor.next().await.expect("listing ended");
+ listed.tracks().next().await.expect("tracks ended")
+ }
+ None => {
+ let path = format!("room/new{index}");
+ let listed = lister.origin.consume().routed_broadcast(path).await.unwrap();
+ listed.track("0").unwrap()
+ }
+ };
+ let mut subscriber = consumer.subscribe(subscription()).await.unwrap();
+ assert_eq!(read(&mut subscriber).await, 0);
+ }
+ }
+}
+
+fn round(c: &mut Criterion) {
+ round_with(c, "subscribe_all_round", true);
+ round_with(c, "subscribe_round", false);
+}
+
+fn round_with(c: &mut Criterion, name: &str, listed: bool) {
+ let rt = runtime();
+ let mut group = c.benchmark_group(name);
+ for listers in LISTERS {
+ for broadcasts in BROADCASTS {
+ let mut room = rt.block_on(Room::new(broadcasts, listers, listed));
+ group.throughput(Throughput::Elements((listers * broadcasts * TRACKS) as u64));
+ group.bench_function(
+ BenchmarkId::new(format!("listers={listers}"), format!("broadcasts={broadcasts}")),
+ |b| {
+ b.iter_custom(|iterations| {
+ let start = Instant::now();
+ for _ in 0..iterations {
+ rt.block_on(room.round());
+ }
+ start.elapsed()
+ })
+ },
+ );
+ }
+ }
+ group.finish();
+}
+
+fn new_broadcast(c: &mut Criterion) {
+ new_broadcast_with(c, "subscribe_all_new_broadcast", true);
+ new_broadcast_with(c, "subscribe_new_broadcast", false);
+}
+
+fn new_broadcast_with(c: &mut Criterion, name: &str, listed: bool) {
+ let rt = runtime();
+ let mut group = c.benchmark_group(name);
+ for listers in LISTERS {
+ for broadcasts in BROADCASTS {
+ let mut room = rt.block_on(Room::new(broadcasts, listers, listed));
+ let mut next = 0;
+ group.throughput(Throughput::Elements(listers as u64));
+ group.bench_function(
+ BenchmarkId::new(format!("listers={listers}"), format!("broadcasts={broadcasts}")),
+ |b| {
+ b.iter_custom(|iterations| {
+ let start = Instant::now();
+ for _ in 0..iterations {
+ rt.block_on(room.new_broadcast(next));
+ next += 1;
+ }
+ start.elapsed()
+ })
+ },
+ );
+ }
+ }
+ group.finish();
+}
+
+criterion_group!(benches, round, new_broadcast);
+criterion_main!(benches);
diff --git a/rs/moq-net/src/lite/all_recv.rs b/rs/moq-net/src/lite/all_recv.rs
new file mode 100644
index 00000000000..b950905ccd9
--- /dev/null
+++ b/rs/moq-net/src/lite/all_recv.rs
@@ -0,0 +1,585 @@
+//! The SUBSCRIBE_ALL a session opens upstream for one prefix, feeding every listing of it.
+//!
+//! Every route the peer announces shares the session's lister, so readers ask the session
+//! once per prefix, and the session answers with a single request: the peer lists
+//! everything it holds there, whichever of its routes serves it.
+//!
+//! A listed broadcast resolves to the session's copy of it, the one a request the origin
+//! routes here gets too, and each listed track is served by the same serve loop as a
+//! requested one. The feed carries the track from its live edge, so the loop subscribes
+//! upstream only for a floor a reader asks for below it; a track a request already serves
+//! hands its subscription over to the feed instead. The request carries the aggregate of
+//! what its tracks' readers ask for, updated as that moves.
+
+use super::*;
+
+use crate::coding::StreamCodes;
+
+/// The request-wide preferences a SUBSCRIBE_ALL and its updates carry.
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+pub(super) struct Prefs {
+ priority: u8,
+ order: crate::track::Order,
+ max_delay: Duration,
+}
+
+impl Prefs {
+ fn of(subscription: &Subscription) -> Self {
+ Self {
+ priority: subscription.priority,
+ order: subscription.order,
+ max_delay: subscription.max_delay,
+ }
+ }
+}
+
+impl Default for Prefs {
+ fn default() -> Self {
+ Self::of(&Subscription::default())
+ }
+}
+
+/// What the readers of one request's tracks ask for, counted per track, so the request
+/// carries their aggregate the way one track's subscribers combine: the highest priority,
+/// the longest max delay, and ascending order only when every track asks for it.
+#[derive(Default)]
+pub(super) struct Demands {
+ priority: BTreeMap,
+ max_delay: BTreeMap,
+ tracks: usize,
+ descending: usize,
+}
+
+impl Demands {
+ fn add(&mut self, prefs: Prefs) {
+ *self.priority.entry(prefs.priority).or_default() += 1;
+ *self.max_delay.entry(prefs.max_delay).or_default() += 1;
+ self.tracks += 1;
+ if prefs.order == crate::track::Order::Descending {
+ self.descending += 1;
+ }
+ }
+
+ fn remove(&mut self, prefs: Prefs) {
+ fn take(counts: &mut BTreeMap, key: K) {
+ if let std::collections::btree_map::Entry::Occupied(mut entry) = counts.entry(key) {
+ *entry.get_mut() -= 1;
+ if *entry.get() == 0 {
+ entry.remove();
+ }
+ }
+ }
+ take(&mut self.priority, prefs.priority);
+ take(&mut self.max_delay, prefs.max_delay);
+ self.tracks -= 1;
+ if prefs.order == crate::track::Order::Descending {
+ self.descending -= 1;
+ }
+ }
+
+ fn aggregate(&self) -> Prefs {
+ let none = Prefs::default();
+ Prefs {
+ priority: self.priority.keys().next_back().copied().unwrap_or(none.priority),
+ max_delay: self.max_delay.keys().next_back().copied().unwrap_or(none.max_delay),
+ order: match (self.tracks, self.descending) {
+ (0, _) => none.order,
+ (_, 0) => crate::track::Order::Ascending,
+ _ => crate::track::Order::Descending,
+ },
+ }
+ }
+}
+
+/// A listed track's TRACK_OK, TRACK_END or TRACK_RESET, for its serve loop.
+pub(super) enum ListedResponse {
+ Ok(lite::SubscribeStart),
+ End(lite::SubscribeEnd),
+ Reset(Error),
+}
+
+/// One track's feed from a SUBSCRIBE_ALL, as its serve loop holds it.
+///
+/// Dropping it stops routing the feed's group streams to the track and takes its readers
+/// out of the request's aggregate.
+pub(super) struct ListedFeed {
+ /// The track's responses in wire order, closed once the request stops feeding it.
+ pub(super) responses: kio::Queue,
+ /// The feed's group streams, counted against its end.
+ pub(super) tail: kio::Producer,
+ feed: Feed,
+ subscribes: Lock>,
+ demands: kio::Producer,
+ counted: Option,
+}
+
+impl ListedFeed {
+ /// Count what the track's readers ask for, `None` for no reader, in the request's
+ /// aggregate.
+ pub(super) fn count(&mut self, subscription: Option<&Subscription>) {
+ let prefs = subscription.map(Prefs::of);
+ if prefs == self.counted {
+ return;
+ }
+ if let Ok(mut demands) = self.demands.write() {
+ if let Some(counted) = self.counted {
+ demands.remove(counted);
+ }
+ if let Some(prefs) = prefs {
+ demands.add(prefs);
+ }
+ }
+ self.counted = prefs;
+ }
+}
+
+impl Drop for ListedFeed {
+ fn drop(&mut self) {
+ self.count(None);
+ self.subscribes.lock().remove(&self.feed);
+ }
+}
+
+/// One upstream SUBSCRIBE_ALL and the listings it fills.
+pub(super) struct ListServe {
+ subscriber: Subscriber,
+ /// The prefix as the wire names it, relative to the session's root.
+ prefix: PathOwned,
+ /// Further listings of the same prefix, joining this request.
+ input: kio::Queue,
+ outputs: Vec