diff --git a/doc/bin/relay/cluster.md b/doc/bin/relay/cluster.md index 4054ff05e3d..4de861e35b3 100644 --- a/doc/bin/relay/cluster.md +++ b/doc/bin/relay/cluster.md @@ -16,6 +16,12 @@ same way so the cluster converges instead of flapping. Both wire protocols carry it: natively on moq-lite, and via the [cluster extension](/draft/moq-cluster) on moq-transport 17+. +moq-transport drafts 14 and 15 cannot ask for every broadcast, since an empty +namespace prefix is illegal before draft 16. On such a link to a peer without +the MoQ Solicit extension, such as moxygen, the relay does not ask for the +whole namespace and learns only what the peer announces unasked. moxygen +announces nothing unasked on draft 14, so that link discovers no broadcasts. + When a moq-lite-04 or later peer withdraws its last advertisement for a broadcast, a relay drops every other route to it that passed through that peer, since each was relayed from what the peer just withdrew, rather than falling back to them one diff --git a/js/net/src/goaway-requests.test.ts b/js/net/src/goaway-requests.test.ts index e58fc5e2e38..9724288716a 100644 --- a/js/net/src/goaway-requests.test.ts +++ b/js/net/src/goaway-requests.test.ts @@ -254,7 +254,8 @@ test("announcing and subscribing after GOAWAY still open streams, on the adapter close() {}, }; - const subscriber = new Subscriber({ session, goaway }); + // A soliciting peer, so draft-14 still asks it for the empty namespace. + const subscriber = new Subscriber({ session, goaway, solicit: true }); const track = subscriber.consume(Path.from("room")).track("video").subscribe(); await track.closed; expect(opened).toBe(true); diff --git a/js/net/src/ietf/connection.ts b/js/net/src/ietf/connection.ts index 9a751a92627..194a50c8876 100644 --- a/js/net/src/ietf/connection.ts +++ b/js/net/src/ietf/connection.ts @@ -167,7 +167,14 @@ export class Connection implements Established { }); this.#solicit = solicit; this.#cluster = cluster; - this.#subscriber = new Subscriber({ session: this.#session, quic, cluster, hidden, goaway: this.#goaway }); + this.#subscriber = new Subscriber({ + session: this.#session, + quic, + cluster, + hidden, + solicit, + goaway: this.#goaway, + }); registerWire(this, { consume: (path) => this.#subscriber.consume(path), goaway: this.#goaway }); void this.#run(early); diff --git a/js/net/src/ietf/subscriber.test.ts b/js/net/src/ietf/subscriber.test.ts index dffffc17932..c57d4465105 100644 --- a/js/net/src/ietf/subscriber.test.ts +++ b/js/net/src/ietf/subscriber.test.ts @@ -67,6 +67,82 @@ test("every peer is asked", async () => { expect(await nextStream(pair.client)).toBeDefined(); }); +/** + * Draft-16 is the first that allows a zero-field track namespace. Asking a foreign peer + * (one that declared no MoQ Solicit) for one earlier is a protocol violation, so an + * unscoped subscriber sends nothing and still takes an unsolicited announcement. + */ +test.each([ + ["draft-14", Version.DRAFT_14, ALPN.DRAFT_14], + ["draft-15", Version.DRAFT_15, ALPN.DRAFT_15], +] as const)("%s does not ask a foreign peer for the empty namespace", async (_name, version, alpn) => { + const pair = createMockTransportPair(alpn); + const session = new NativeSession(pair.server, version, true); + const subscriber = new Subscriber({ session }); + const announced = subscriber.announced(); + + expect(await nextStream(pair.client)).toBeUndefined(); + + const stream = await Stream.open(pair.server, { version }); + void subscriber.runPublishNamespace( + new PublishNamespace({ requestId: 0n, trackNamespace: Path.from("surprise") }), + stream, + ); + expect(await announced.next()).toMatchObject({ prefix: Path.from("surprise"), kind: "start" }); + announced.close(); +}); + +/** With no request stream to end it, the unasked reader ends with the session, from either side. */ +test.each([ + ["local", "server"], + ["remote", "client"], +] as const)("an unasked draft-14 reader ends on a %s close", async (_name, side) => { + const pair = createMockTransportPair(ALPN.DRAFT_14); + const session = new NativeSession(pair.server, Version.DRAFT_14, true); + const subscriber = new Subscriber({ session, quic: pair.server }); + const announced = subscriber.announced(); + + pair[side].close(); + + expect(await announced.next()).toBeUndefined(); +}); + +/** A peer that declared MoQ Solicit is ours: it only tells when asked, so it still is. */ +test.each([ + ["draft-14", Version.DRAFT_14, ALPN.DRAFT_14], + ["draft-15", Version.DRAFT_15, ALPN.DRAFT_15], +] as const)("%s still asks a soliciting peer for the empty namespace", async (_name, version, alpn) => { + const pair = createMockTransportPair(alpn); + const session = new NativeSession(pair.server, version, true); + const subscriber = new Subscriber({ session, solicit: true }); + + subscriber.announced(); + + expect(await nextStream(pair.client)).toBeDefined(); +}); + +/** A named prefix is still legal on the drafts that reject the empty one. */ +test("draft-14 still asks for a named prefix", async () => { + const pair = createMockTransportPair(ALPN.DRAFT_14); + const session = new NativeSession(pair.server, Version.DRAFT_14, true); + const subscriber = new Subscriber({ session }); + + subscriber.announced(Path.Pattern.subtree(Path.from("cam"))); + + expect(await nextStream(pair.client)).toBeDefined(); +}); + +/** The empty prefix is the "every namespace" request from draft-16 on. */ +test("draft-16 still asks for the empty namespace", async () => { + const pair = createMockTransportPair(ALPN.DRAFT_16); + const session = new NativeSession(pair.server, Version.DRAFT_16, true); + const subscriber = new Subscriber({ session }); + + subscriber.announced(); + + expect(await nextStream(pair.client)).toBeDefined(); +}); + /** * The other half of discovery: a peer that tells us unasked. Asking must not make us deaf * to a PUBLISH_NAMESPACE that arrives on its own stream instead. diff --git a/js/net/src/ietf/subscriber.ts b/js/net/src/ietf/subscriber.ts index 7db20096835..401bd968da1 100644 --- a/js/net/src/ietf/subscriber.ts +++ b/js/net/src/ietf/subscriber.ts @@ -156,6 +156,10 @@ export class Subscriber { // Whether the peer understands the HIDDEN parameter (MoQ Hidden). #hidden: boolean; + // What the peer's SETUP declared about being solicited (MoQ Solicit), `undefined` + // when it declared nothing. + #solicit?: boolean; + // Settles when the peer sends GOAWAY, repricing this session's routes to the drain cost. #goaway?: GetPromise; @@ -174,6 +178,7 @@ export class Subscriber { quic, cluster, hidden = false, + solicit, goaway, }: { /** The session abstraction for bidi streams and request IDs. */ @@ -184,6 +189,8 @@ export class Subscriber { cluster?: Cluster.Hops; /** Whether the peer understands the HIDDEN parameter (MoQ Hidden). */ hidden?: boolean; + /** What the peer's SETUP declared about being solicited (MoQ Solicit). */ + solicit?: boolean; /** Settles when the peer sends GOAWAY. */ goaway?: GetPromise; }) { @@ -191,6 +198,7 @@ export class Subscriber { this.#quic = quic; this.#cluster = cluster; this.#hidden = hidden; + this.#solicit = solicit; this.#goaway = goaway; // A draining peer usually stops publishing namespaces, so reprice from the signal // itself. Waiting for another message would leave the route primary until close. @@ -242,7 +250,9 @@ export class Subscriber { * * The peer is asked with SUBSCRIBE_NAMESPACE regardless of what it declared, and an * unsolicited PUBLISH_NAMESPACE lands here too, so a peer that only tells and one - * that only answers are both discovered. + * that only answers are both discovered. A draft-14 or draft-15 peer that declared no + * MoQ Solicit is not asked for the empty prefix, so an unscoped subscriber only hears + * what that peer tells. * * Hidden routes (a `.`-prefixed segment below the scope's head) are left out unless * `options.hidden` opts in. The opt-in rides the SUBSCRIBE_NAMESPACE when the peer @@ -352,6 +362,20 @@ export class Subscriber { async #runAnnounced(announced: announce.Producer, prefix: Path.Valid, hidden: boolean) { const version = this.#session.version; + // A zero-field track namespace was a protocol violation until draft-16 allowed + // it. A peer that never declared MoQ Solicit is not ours: it may enforce that, and + // it tells us unasked anyway, so send nothing and stay registered for its + // unsolicited PUBLISH_NAMESPACE. Returning would drop this consumer before one + // could land. A peer that declared Solicit only tells when asked, so it still is. + const legacy = version === Version.DRAFT_14 || version === Version.DRAFT_15; + if (legacy && prefix.length === 0 && this.#solicit === undefined) { + // No request stream ends this wait, so the session's end has to. + const ends: PromiseLike[] = [announced.closed]; + if (this.#quic) ends.push(this.#quic.closed.catch(() => undefined)); + await Promise.race(ends); + return; + } + // Suffixes live on this stream, so a repeat is recognized as an update to the // advertisement rather than a second one, which would leak the count. const live = new Set(); diff --git a/quest/m0/README.md b/quest/m0/README.md index a19f547afcf..848bc443c19 100644 --- a/quest/m0/README.md +++ b/quest/m0/README.md @@ -55,7 +55,6 @@ a published `@moq/watch` break. - [Held group wakes](/quest/m0/held-group-wakes.md) - a group held across a route switch is woken when its successor's first timestamp or abort makes it stale, not at the next unrelated append - [Draft-22 LOCATION_FILTER](/quest/m0/ietf-location-filter-22.md) - moqt-22 LOCATION_FILTER carries its type instead of a Length in Rust and JS, so a draft-22 peer reads our Next Object correctly - [moq-transport parameters per draft](/quest/m0/ietf-params-per-draft.md) - every control message accepts exactly the parameters its draft allows, so moqx's draft-16 SUBSCRIBE_NAMESPACE with FORWARD stops failing -- [No empty d14 prefix](/quest/m0/ietf-d14-root-prefix.md) - draft-14 never sends SUBSCRIBE_NAMESPACE with an empty prefix, and the docs say to scope a d14 link to moxygen - [End of Track Location](/quest/m0/ietf-end-of-track-location.md) - a relay forwards END_OF_TRACK at its upstream's Location, on the last group's stream, instead of re-sending it at the next group's object 0 - [End of Group status](/quest/m0/ietf-end-of-group-status.md) - an End of Group status on a stream whose header already marks the group's end is accepted, so imquic's last object per group arrives - [Subgroup at object 0](/quest/m0/ietf-first-object-zero.md) - a draft-18 subgroup with FIRST_OBJECT clear that starts at object 0 is read whole diff --git a/quest/m0/ietf-d14-root-prefix.md b/quest/m0/ietf-d14-root-prefix.md deleted file mode 100644 index 3c3fc0866d2..00000000000 --- a/quest/m0/ietf-d14-root-prefix.md +++ /dev/null @@ -1,39 +0,0 @@ -# [XS] No empty namespace prefix on draft-14 - -## Goal - -On draft-14, moq-net never sends SUBSCRIBE_NAMESPACE with an empty prefix. -d14 ยง9.28 makes a prefix with N = 0 a PROTOCOL_VIOLATION, and moxygen -refuses it today when an unscoped moq-relay cluster link dials it. The -relay docs say an unscoped d14 link discovers nothing from moxygen, so -operators scope it. - -## Plan - -Triaged from Fastly's moq-relay-interop report (2026-09-23 run, item 2) on -2026-10-07. - -Decided 2026-10-07: on d14, skip a SUBSCRIBE_NAMESPACE whose prefix is -empty. Keep today's warn-and-continue when the peer refuses a namespace -subscription. Rejected: failing the link on refusal, and requiring a scope -on d14 links at startup. - -Revised 2026-10-07 after Fastly's pcap runs (#issuecomment-6046932019): -moxygen sends no PUBLISH_NAMESPACE on d14 to a peer that has not -subscribed, and moqx no longer speaks d14. So skipping alone leaves an -unscoped moq-dev downstream of moxygen with no namespaces. Decided to keep -the quest narrow and document the gap, since moxygen on d14 is the only -affected pair and scoped links already work. Rejected: subscribing per -prefix on demand when a local subscriber misses, and routing unknown -SUBSCRIBEs upstream; both need a hook on origin misses. - -Where it lives: `subscribe_prefixes` (`rs/moq-net/src/ietf/subscriber.rs`, -around line 600) returns `interest_prefixes(origin.allowed())`, which is -`[""]` for an unscoped origin. `run_subscribe_namespace` (around line 861) -sends it. Log at debug when the root is skipped. The note belongs in -`doc/bin/relay/cluster.md`. - -Test: a d14 session with an unscoped origin sends no SUBSCRIBE_NAMESPACE, -and a scoped one still does. Check `js/net` for the same path. - -Public API: none. Wire: d14 stops sending a message the draft forbids. diff --git a/rs/moq-net/src/ietf/session.rs b/rs/moq-net/src/ietf/session.rs index 33d6c9021d5..505e0e3b6b5 100644 --- a/rs/moq-net/src/ietf/session.rs +++ b/rs/moq-net/src/ietf/session.rs @@ -1256,6 +1256,109 @@ mod tests { assert_eq!(occurrences(&log, b"rootns"), 0, "asked the peer for our local root"); } + /// The bytes of one legacy SUBSCRIBE_NAMESPACE, as the session writes them. + async fn subscribe_namespace_legacy(version: Version, namespace: &str) -> Vec { + let log = crate::lite::test_transport::Log::default(); + let mut writer = Writer::new(crate::lite::test_transport::SinkSend::new(log.clone()), version); + let msg = ietf::SubscribeNamespaceLegacy { + request_id: RequestId(0), + namespace: crate::Path::new(namespace), + subscribe_options: ietf::SubscribeOptions::Namespace, + hidden: false, + }; + writer.varint(ietf::SubscribeNamespaceLegacy::ID).await.unwrap(); + writer.encode(&msg).await.unwrap(); + log.writes.lock().unwrap().clone() + } + + /// How many times a session with this scope writes SUBSCRIBE_NAMESPACE for it. + /// + /// `prefix: None` is an unscoped origin, whose only interest head is empty. `solicit` + /// is what the peer's SETUP declared (MoQ Solicit). + async fn asked_namespace(version: Version, prefix: Option<&str>, solicit: Option) -> usize { + let origin = crate::origin::Config::new(crate::Hop::new(1).unwrap()).produce(); + let subscribe = match prefix { + Some(name) => { + let scope: crate::Patterns = [crate::Pattern::subtree(name).unwrap()].into_iter().collect(); + origin.scope("rootns", &scope).expect("scope the origin") + } + None => origin, + }; + + let gate = kio::Producer::new(true); + let mut session = crate::lite::test_transport::SinkSession::gated_bi(gate.consume()); + let log = session.log.clone(); + let setup = Stream::open(&mut session, version) + .await + .expect("open the control stream"); + + let (driver, _goaway, _) = start(Config { + runtime: crate::time::Clock::sim(), + session, + setup: Some(setup), + request_id_max: None, + limits: Default::default(), + client: true, + publish: None, + subscribe: Some(subscribe), + peer_hop: None, + cost: None, + version, + path: None, + authority: None, + peer_setup_stream: None, + peer_declared: Some(peer::Peer { + solicit, + ..Default::default() + }), + early_unis: Vec::new(), + }) + .expect("start the session"); + let driver = moq_net_sim::spawn(driver); + + let needle = subscribe_namespace_legacy(version, prefix.unwrap_or("")).await; + for _ in 0..ANNOUNCE_TURNS { + if occurrences(&log, &needle) > 0 { + break; + } + moq_net_sim::sleep(std::time::Duration::from_millis(1)).await; + } + + assert!(!driver.is_finished(), "{version:?} ended the session"); + assert!(log.closes().is_empty(), "{version:?} closed: {:?}", log.closes()); + occurrences(&log, &needle) + } + + /// Draft-14 and draft-15 reject a zero-field track namespace, so a foreign peer (one + /// that declared no MoQ Solicit) is not asked for it, and a real prefix still goes + /// out. A peer that declared Solicit is ours: it only tells when asked, so it still + /// gets the empty prefix. Draft-16 made the empty prefix legal, so it stays. + #[moq_net_sim::test] + async fn an_empty_namespace_is_not_asked_of_a_foreign_peer_before_draft_16() { + for version in [Version::Draft14, Version::Draft15] { + assert_eq!( + asked_namespace(version, None, None).await, + 0, + "{version:?} asked a foreign peer for every namespace" + ); + assert_eq!( + asked_namespace(version, Some("cam"), None).await, + 1, + "{version:?} skipped a real prefix" + ); + assert_eq!( + asked_namespace(version, None, Some(true)).await, + 1, + "{version:?} did not ask a soliciting peer for every namespace" + ); + } + assert_eq!( + asked_namespace(Version::Draft16, None, None).await, + 1, + "draft-16 dropped the empty prefix" + ); + } + /// How many scheduling turns an advertisement gets before the count is taken. Time is /// paused in these tests, so each turn costs nothing and only runs the driver until it /// parks again; a busy machine cannot turn a slow announce into a passing silence. diff --git a/rs/moq-net/src/ietf/subscriber.rs b/rs/moq-net/src/ietf/subscriber.rs index 8d47b040f16..6cdd6750d64 100644 --- a/rs/moq-net/src/ietf/subscriber.rs +++ b/rs/moq-net/src/ietf/subscriber.rs @@ -599,7 +599,8 @@ pub(super) struct Subscriber { /// subscriber asks for its scope and mounts the replies under the root. /// /// Asked unconditionally: a peer with nothing to advertise answers with an empty set, -/// which costs one stream. +/// which costs one stream. [`Subscriber::run_subscribe_namespace`] holds back the empty +/// prefix from a foreign draft-14/15 peer. pub(super) fn subscribe_prefixes(origin: &origin::Producer) -> Vec { crate::model::interest_prefixes(&origin.allowed()) } @@ -851,6 +852,18 @@ where let declared = self.peer_setup.get().await; let hidden = declared.hidden; + // Draft-16 is the first to allow a zero-field namespace, so the empty prefix is a + // protocol violation on draft-14/15. A peer that never declared MoQ Solicit is not + // ours: it may enforce that, and it tells us unasked anyway. One that declared it + // accepts the empty prefix and only tells when asked, so it still gets one. + if prefix.is_empty() + && declared.solicit.is_none() + && matches!(self.version, Version::Draft14 | Version::Draft15) + { + tracing::debug!(version = ?self.version, "not asking a foreign peer for the empty namespace"); + return Ok(()); + } + let request_id = self.control.next_request_id(&self.runtime).await?; // Draft-18+ uses SUBSCRIBE_NAMESPACE (0x50); earlier drafts use the legacy