From c5859f1315b0d3eb038202d5ab0818f6c09b1d3d Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 27 Oct 2026 18:50:05 -0700 Subject: [PATCH 1/9] chore(quest): claim quest/m1/lite-timestamps-through.md Quest-Claim: ce48bd54dedffcad From 906b4054b78d12b43d94fe8353fdcfb47f5f808d Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 27 Oct 2026 19:08:46 -0700 Subject: [PATCH 2/9] wip: pass lite-05/06 timestamps through --- c/moq/test/probe.c | 4 +- cpp/moq/test/probe.cpp | 3 +- doc/concept/moq-lite.md | 14 +-- doc/setup/upgrade.md | 6 +- drafts/draft-lcurley-moq-ietf.md | 8 +- drafts/draft-lcurley-moq-lite.md | 8 +- js/e2ee/src/transport.test.ts | 4 +- js/net/src/ietf/subscriber.ts | 2 +- js/net/src/lite/group.ts | 7 +- js/net/src/lite/publisher.test.ts | 17 ++-- js/net/src/lite/publisher.ts | 16 ++-- js/net/src/lite/subscriber.test.ts | 17 ++-- js/net/src/lite/subscriber.ts | 12 +-- js/net/src/lite/track_stream.test.ts | 11 +-- js/net/src/lite/version.ts | 4 +- js/net/src/resume.ts | 7 +- js/net/src/track.test.ts | 9 +- js/net/src/track.ts | 14 +-- js/net/src/untimed.test.ts | 33 +++---- rs/moq-cli/src/publish.rs | 5 +- rs/moq-net/src/lite/ietf.rs | 36 ++++---- rs/moq-net/src/lite/publisher.rs | 46 ++++------ rs/moq-net/src/lite/subscriber.rs | 53 +++++------- rs/moq-net/src/lite/track.rs | 7 +- rs/moq-net/src/lite/version.rs | 2 +- rs/moq-net/src/model/group.rs | 7 -- rs/moq-net/src/model/track.rs | 47 +++++++--- rs/moq-net/tests/integration/datagram.rs | 1 - rs/moq-net/tests/integration/range_anchors.rs | 9 +- .../tests/integration/received_rewind.rs | 85 ++++++++++++------- rs/moq-net/tests/integration/untimed.rs | 31 ++++--- rs/moq-net/tests/integration/wide_sequence.rs | 4 +- rs/moq-relay/tests/integration/connection.rs | 4 +- rs/moq-tokio/tests/integration/broadcast.rs | 30 ++++--- test/wasm/baseline/consumer.ts | 4 +- test/wasm/generator.md | 2 +- test/wasm/uniffi/cases.ts | 4 +- 37 files changed, 297 insertions(+), 276 deletions(-) diff --git a/c/moq/test/probe.c b/c/moq/test/probe.c index 154f2a4e7d9..81df12a3d53 100644 --- a/c/moq/test/probe.c +++ b/c/moq/test/probe.c @@ -344,8 +344,8 @@ int main(void) { CHECK(received); CHECK(received->payload.len == sizeof(hello)); CHECK(memcmp(received->payload.data, hello, sizeof(hello)) == 0); - /* The default moq-lite-06 session drops received timestamps, so the track arrives untimed. */ - CHECK(!received->timestamp_us.has_value); + CHECK(received->timestamp_us.has_value); + CHECK(received->timestamp_us.value == 1000); moq_frame_free(received); CHECK(!cancelled.done); diff --git a/cpp/moq/test/probe.cpp b/cpp/moq/test/probe.cpp index fb119acc372..e722993f083 100644 --- a/cpp/moq/test/probe.cpp +++ b/cpp/moq/test/probe.cpp @@ -262,8 +262,7 @@ int main() { CHECK(!reading.valid()); CHECK(frame.has_value()); CHECK(frame->payload == bytes("hello")); - // The default moq-lite-06 session drops received timestamps, so the track arrives untimed. - CHECK(!frame->timestamp_us.has_value()); + CHECK(frame->timestamp_us == 1000); // A continuation receives the next frame on the executor. { diff --git a/doc/concept/moq-lite.md b/doc/concept/moq-lite.md index 23d6e26371a..faa8659c3ac 100644 --- a/doc/concept/moq-lite.md +++ b/doc/concept/moq-lite.md @@ -330,13 +330,13 @@ frames go out stamped with their send time; the work-in-progress 07 carries it untimed. A publisher refuses a group that starts before a lower one, and so does a -moq-lite 07 receiver. Since moq-lite 05 and 06 send times look like media time, -a receiver drops every timestamp it gets over them and the track arrives -untimed. -Timestamps received over moq-transport, whose peers may stamp arrival times, -are not checked. Rust relays preserve them across moq-lite 07 when both peers -negotiate the [ietf extension](/draft/moq-ietf), which carries their origin and -keeps them unchecked. A moq-lite peer without it receives that track untimed. +moq-lite 07 receiver. A receiver passes on the timestamps it gets over moq-lite +05 and 06 without checking them, since their send times look like media time and +an older group fetched later would look like a rewind. Timestamps received over +moq-transport, whose peers may stamp arrival times, are not checked either. A +relay serves both on over every version. Over moq-lite 07 the +[ietf extension](/draft/moq-ietf) keeps moq-transport ones unchecked; without +it, the receiver checks them and may refuse a group that rewinds. A publisher may compress a track, which pays off for repetitive data such as JSON and not for media. Each group's frames become one DEFLATE stream diff --git a/doc/setup/upgrade.md b/doc/setup/upgrade.md index b90b5591a28..b0538b6d1e2 100644 --- a/doc/setup/upgrade.md +++ b/doc/setup/upgrade.md @@ -84,10 +84,8 @@ These land with the next breaking release. receive.** Tracks from moq-lite before 05, and moq-transport tracks without `TIMESCALE` arrive untimed instead of stamped with their arrival time. moq-lite 05 and 06 can't encode absence and - carry a send time instead, so their receivers drop every timestamp and those - tracks arrive untimed too: read media time from the payload. moq-transport - timestamps are served to moq-lite untimed; see - [untimed tracks](/concept/moq-lite#subscriptions). A new subscriber with no + carry a send time instead, which their receivers pass through as the track's + time; see [untimed tracks](/concept/moq-lite#subscriptions). A new subscriber with no start on an untimed track starts at the latest group. - **Max age and max delay count wall-clock time too.** A superseded group is stale once its successor arrived a full budget ago, as well as by media diff --git a/drafts/draft-lcurley-moq-ietf.md b/drafts/draft-lcurley-moq-ietf.md index 9ef9dd9068a..bfb6fb929f8 100644 --- a/drafts/draft-lcurley-moq-ietf.md +++ b/drafts/draft-lcurley-moq-ietf.md @@ -143,10 +143,10 @@ The Version also gives each property its meaning: drafts 18 and 19 serialize a b Other properties are opaque to this extension. ## Timestamps {#timestamps} -A relay MUST preserve a relayed track's Timescale and timestamps across a negotiated hop, except in a listing ({{track}}). +A relay MUST preserve a relayed track's Timescale and timestamps across a negotiated hop. A nonzero Version identifies timestamps from MoQ Transport, which may be arrival times and need not rise with Group Sequence. The receiver MUST NOT apply moq-lite's group-start rewind check to such a track; a Version of zero retains that check. -Without this extension, a relay MUST serve a MoQ Transport track untimed as {{moql}} requires. +Without this extension, or in a listing ({{track}}), the receiver may check them like native moq-lite timestamps and refuse a Group that rewinds. On a timed track, the FRAME's Timestamp, or the datagram's for a datagram, is the object's time, and nothing else carries it. The Property Block MUST NOT contain a mutable Timestamp (0x10) there; a receiver MUST treat one as malformed. @@ -199,7 +199,7 @@ The receiver parses the keys inside the Immutable Properties from its value, whi It SHOULD read them from the value when needed rather than hold them beside it, as a list of IDs can cost several times the value. A TRACKS_ADD ({{moql}} Tracks Stream) embeds TRACK_INFO without TRACK_PROPERTIES, so when the extension is negotiated a subscriber MUST NOT skip the Track Stream for a track it learned from a listing. -Lacking the Version, a TRACKS_ADD cannot mark a {{moqt}} track's timestamps as unchecked ({{timestamps}}), so it lists that track untimed even when the extension is negotiated. +Lacking the Version, a TRACKS_ADD cannot mark a {{moqt}} track's timestamps as unchecked ({{timestamps}}). # Datagrams {#datagrams} @@ -264,7 +264,7 @@ A high, distinctive value is used to avoid collisions with the low values {{moql ## Since draft-lcurley-moq-ietf-00 (in progress) -- Preserve relayed track timestamps and their unchecked MoQ Transport provenance across negotiated hops. +- Preserve relayed track timestamps and their unchecked MoQ Transport provenance across negotiated hops. Without the extension a relay serves them as native moq-lite timestamps rather than untimed. - Initial version. # Acknowledgments diff --git a/drafts/draft-lcurley-moq-lite.md b/drafts/draft-lcurley-moq-lite.md index 64c24e9d7c1..fc916b88093 100644 --- a/drafts/draft-lcurley-moq-lite.md +++ b/drafts/draft-lcurley-moq-lite.md @@ -188,12 +188,12 @@ A Group Stream normally starts at frame 0, but MAY start later when the publishe Each frame of a timed Track carries a presentation timestamp expressed in the Track's `Timescale` (see [TRACK_INFO](#track-info)), used by the moq-lite layer for [expiration](#expiration) decisions. A Track without a `Timescale` is untimed: its frames and datagrams carry no timestamp. A timestamp MUST be less than 2^61: lite-05 and lite-06 zigzag a Group's first [Timestamp Delta](#frame) into a QUIC varint, which carries no more, and the bound lets a relay forward any timestamp to any version. -A receiver treats a larger timestamp as a malformed Track, even one it discards. +A receiver treats a larger timestamp as a malformed Track. Unless a negotiated extension specifies otherwise, a publisher MUST NOT start a timed Group's frame 0 earlier than that of any lower-sequence Group it publishes. lite-05 and lite-06 cannot encode an untimed Track, so a publisher on those versions declares a `Timescale` of 1000 for it and stamps every frame and datagram with its send time in milliseconds. -A receiver cannot tell such send times from presentation timestamps, and they need not rise with sequence, so it discards every timestamp received on those versions and treats the Track as untimed. +A receiver cannot tell such send times from presentation timestamps, and they need not rise with sequence, so it keeps the timestamps received on those versions as the Track's and does not check received Groups against this rule. On later versions a receiver MAY check a received Group against this rule, refusing a violating Group's stream (STOP_SENDING) with TIMESTAMP_MISMATCH. -A relay that cannot vouch for a Track's timestamps, such as ones received over another protocol, MUST serve the Track untimed unless a negotiated extension identifies their unchecked provenance. +A relay serves a Track's timestamps on as it received them, including ones it did not check, unless a negotiated extension specifies otherwise. ## Positions {#positions} A Position is a (Group Sequence, Frame Index) pair identifying one frame within a Track. @@ -1848,7 +1848,7 @@ The `Message Length` describes the payload size on the wire. - Replaced ANNOUNCE_OK Active Count with an ordered, empty SYNCED event (0x4), marking the initial set without retaining routes that end before delivery. -- A publisher must not start a timed Group's frame 0 earlier than a lower-sequence Group's, and a receiver may refuse a Group that does. A receiver discards the timestamps it receives over lite-05/06, which may be send times, and a relay serves a Track whose timestamps it cannot vouch for untimed unless a negotiated extension identifies their unchecked provenance. +- A publisher must not start a timed Group's frame 0 earlier than a lower-sequence Group's, and a receiver may refuse a Group that does. A receiver keeps the timestamps it receives over lite-05/06, which may be send times, without checking them, and a relay serves every Track's timestamps on as received. - Bounded every timestamp below 2^61, since a lite-05/06 Group's first Timestamp Delta carries no more, so a relay never holds one it cannot forward. A larger one is a malformed Track. diff --git a/js/e2ee/src/transport.test.ts b/js/e2ee/src/transport.test.ts index 0dad9d490d0..5de03955a8f 100644 --- a/js/e2ee/src/transport.test.ts +++ b/js/e2ee/src/transport.test.ts @@ -48,10 +48,10 @@ async function active(origin: Origin.Producer, path: Path.Valid): Promise WireFrame { +export function frameDecoder({ scale, compress = false }: FrameFormat): (c: Cursor) => WireFrame { const timescale = scale === 0 ? undefined : Time.Timescale(scale); let prevTs = 0n; return (c) => { @@ -100,8 +98,7 @@ export function frameDecoder({ scale, timed = true, compress = false }: FrameFor const payload = c.read(size); // Commit the delta only after the last read: an incomplete decode gets retried. prevTs += delta; - // Read to stay in step, but dropped where it may be a send time. - const timestamp = timescale === undefined || !timed ? undefined : new Time.Timestamp(Number(prevTs), timescale); + const timestamp = timescale === undefined ? undefined : new Time.Timestamp(Number(prevTs), timescale); return { payload, inflated, timestamp }; }; } diff --git a/js/net/src/lite/publisher.test.ts b/js/net/src/lite/publisher.test.ts index 604cbaa3dcc..ed0fbd69bfa 100644 --- a/js/net/src/lite/publisher.test.ts +++ b/js/net/src/lite/publisher.test.ts @@ -6,7 +6,6 @@ import { Producer as BroadcastProducer } from "../broadcast.ts"; import { fromTransport, SessionCode, StreamCode, StreamError, toStreamCode } from "../error.ts"; import type { Producer as GroupProducer } from "../group.ts"; import { randomHop } from "../hop.ts"; -import { Version as IetfVersion } from "../ietf/version.ts"; import { hooks } from "../internal.ts"; import { createMockTransportPair, textFrame } from "../mock.ts"; import { Producer as OriginProducer } from "../origin.ts"; @@ -594,15 +593,15 @@ test.each([0, 5, 6, 7])("a fetched cached tail keeps absolute indices from %s", } }); -// An unchecked track goes out untimed, so lite-06 carries its send time, never the frame's own -// timestamp, which may be a moq-transport arrival time. -test("lite draft-06: an unchecked track's fetched frames carry their send time", async () => { +// An unchecked track's frames go out with their own timestamps, which may be moq-transport +// arrival times, rather than their send time. +test("lite draft-06: an unchecked track's fetched frames carry their own timestamp", async () => { const pair = createMockTransportPair(ALPN_06); const origin = new OriginProducer(); const publisher = new Publisher(pair.server, Version.DRAFT_06, randomHop(), origin.consume()); const broadcast = publish(origin, Path.from("test")); - const track = broadcast.createTrack("video", { timescale: Timescale.MICRO, ietf: IetfVersion.DRAFT_22 }); + const track = broadcast.createTrack("video", { timescale: Timescale.MICRO, unchecked: true }); const group = track.createGroup(0); group.writeFrame(textFrame("hello", Timestamp.fromMillis(36_000_000))); @@ -614,14 +613,10 @@ test("lite draft-06: an unchecked track's fetched frames carry their send time", const msg = new Fetch({ broadcast: Path.from("test"), track: "video", priority: 0, group: 0 }); try { - const before = Math.floor(Timestamp.now().value); await publisher.runFetch(msg, server); - const after = Math.ceil(Timestamp.now().value); - // The first frame's zigzag delta is against 0, in the milliseconds TRACK_INFO declares. - const sent = Number((await client.reader.u62()) >> 1n); - expect(sent).toBeGreaterThanOrEqual(before); - expect(sent).toBeLessThanOrEqual(after); + // The first frame's zigzag delta is against 0, in the microseconds TRACK_INFO declares. + expect(await client.reader.u62()).toBe(36_000_000_000n << 1n); } finally { publisher.close(); client.close(); diff --git a/js/net/src/lite/publisher.ts b/js/net/src/lite/publisher.ts index e79414d0bdc..3af7a77342d 100644 --- a/js/net/src/lite/publisher.ts +++ b/js/net/src/lite/publisher.ts @@ -74,17 +74,12 @@ interface Stamp { timescale: Timescale; /** * Whether each frame's own timestamp goes out. Lite-05/06 cannot encode an untimed track, so - * one served untimed carries its send time instead, unchecked ones included. + * an untimed one carries its send time instead. */ timed: boolean; } -/** The timescale a moq-lite hop serves a track at: none for an {@link track.Info.ietf} one. */ -function liteTimescale(info: track.Info): Timescale | undefined { - return info.ietf === undefined ? (info.timescale ?? undefined) : undefined; -} - -/** How `version` stamps a track served at `timescale` (see `liteTimescale`), or undefined when it carries none. */ +/** How `version` stamps a track with `timescale`, or undefined when it carries none. */ function stamping(version: Version, timescale: Timescale | undefined): Stamp | undefined { const wire = wireTimescale(version, timescale); return wire === undefined ? undefined : { timescale: wire, timed: timescale !== undefined }; @@ -111,9 +106,8 @@ function trackInfoMessage(info: track.Info, version: Version): TrackInfoMessage // Publisher Max Age: the publisher's retention bound, advertised so relays re-serve // with the same window. maxAge: info.maxAge, - // `#serveGroup` emits each frame converted to it. Unchecked timestamps never enter - // moq-lite, whose receivers check them. - timescale: liteTimescale(info), + // `#serveGroup` emits each frame converted to it. + timescale: info.timescale ?? undefined, // An older peer is served the frames inflated. compress: hasCompression(version) && !!info.compress, }); @@ -904,7 +898,7 @@ export class Publisher { // The timescale is an immutable property, so serving MUST use exactly // what TRACK_INFO advertised. It comes from the producer's accept(), so // they always agree. - stamp = stamping(this.version, liteTimescale(info)); + stamp = stamping(this.version, info.timescale ?? undefined); compress = hasCompression(this.version) && !!info.compress; } else { // Older drafts acknowledge with SUBSCRIBE_OK and stream frames verbatim. diff --git a/js/net/src/lite/subscriber.test.ts b/js/net/src/lite/subscriber.test.ts index 427b58a06cf..03348f5a4fc 100644 --- a/js/net/src/lite/subscriber.test.ts +++ b/js/net/src/lite/subscriber.test.ts @@ -20,6 +20,7 @@ import { hooks } from "../internal.ts"; import { GRACE } from "../ledger.ts"; import * as Path from "../path.ts"; import { Reader, Writer } from "../stream.ts"; +import { Timescale } from "../time.ts"; import type { Producer } from "../track.ts"; import { type AnnounceBroadcast, AnnounceInit, AnnounceOk, encodeAnnounceBroadcast } from "./announce.ts"; import { Group } from "./group.ts"; @@ -2104,9 +2105,9 @@ async function groupStream(timestamp: number, version: Version = Version.DRAFT_0 } // Lite-05/06 stamp an untimed track's frames with their send time, which a receiver cannot tell -// from media time, so it drops every timestamp there: a group that rewinds or lands out of order is -// accepted untimed. -test.each([Version.DRAFT_05, Version.DRAFT_06])("version %p drops received timestamps", async (version) => { +// from media time, so it keeps every timestamp there unchecked: a group that rewinds or lands out +// of order is accepted with its timestamp. +test.each([Version.DRAFT_05, Version.DRAFT_06])("version %p passes received timestamps through", async (version) => { const { quic, streams, opened } = fakeSession(); const subscriber = new Subscriber(quic, version, HopSchema.parse(1n)); const broadcast = subscriber.consume(Path.from("room")); @@ -2125,14 +2126,14 @@ test.each([Version.DRAFT_05, Version.DRAFT_06])("version %p drops received times for (let i = 0; i < 3; i++) { const group = await track.recvGroup(); const frame = await group?.readFrame(); - got.push([group?.sequence, frame?.payload.length, frame?.timestamp]); + got.push([group?.sequence, frame?.payload.length, frame?.timestamp?.value]); } expect(got).toEqual([ - [3, 1, undefined], - [4, 1, undefined], - [5, 1, undefined], + [3, 1, 2000], + [4, 1, 1000], + [5, 1, 500], ]); - expect((await track.info()).timescale).toBeUndefined(); + expect((await track.info()).timescale).toBe(Timescale.MILLI); expect(track.closed.peek()).toBeUndefined(); } finally { track.close(); diff --git a/js/net/src/lite/subscriber.ts b/js/net/src/lite/subscriber.ts index b62fcab33ba..4f0a80a502f 100644 --- a/js/net/src/lite/subscriber.ts +++ b/js/net/src/lite/subscriber.ts @@ -1175,14 +1175,15 @@ export class Subscriber { // Map the wire TRACK_INFO onto the model track.Info a producer/consumer holds. #toModelInfo(info: TrackInfo): track.Info { return { - // Lite-05/06 timestamps may be send times, so the copy is untimed and the ingest drops them. - timescale: hasMediaTime(this.version) ? info.timescale : undefined, + timescale: info.timescale, // Publisher Max Age rides on the wire, so the local media-time budget // matches what the upstream advertises (relays re-serve with the same bound). maxAge: info.maxAge === undefined ? undefined : Milli(info.maxAge), priority: info.priority, refresh: info.refresh, compress: info.compress, + // Lite-05/06 timestamps may be send times, so the copy's groups skip the rewind check. + ...(hasMediaTime(this.version) ? {} : { unchecked: true }), }; } @@ -1376,7 +1377,6 @@ export class Subscriber { try { const decode = frameDecoder({ scale: info.timescale ?? 0, - timed: hasMediaTime(this.version), compress: info.compress, }); @@ -1679,7 +1679,6 @@ export class Subscriber { await readFrames(stream, producer, { scale: timescale, - timed: hasMediaTime(this.version), compress: entry.compress, }); @@ -1759,11 +1758,8 @@ export class Subscriber { const scale = entry.timescale; - // Dropped where it may be a send time, like a frame's. const timestamp = - dg.timestamp === undefined || !hasMediaTime(this.version) - ? undefined - : new Time.Timestamp(dg.timestamp, Time.Timescale(scale)); + dg.timestamp === undefined ? undefined : new Time.Timestamp(dg.timestamp, Time.Timescale(scale)); // A datagram's sequence is never owed a stream, so it never holds the tail open. entry.tail.account(dg.sequence, dg.sequence + 1); hooks.writeDatagram(entry.track, { sequence: dg.sequence, timestamp, payload: dg.payload }, dg.inflated); diff --git a/js/net/src/lite/track_stream.test.ts b/js/net/src/lite/track_stream.test.ts index 97bdb20ac3f..dd6dc6fabb7 100644 --- a/js/net/src/lite/track_stream.test.ts +++ b/js/net/src/lite/track_stream.test.ts @@ -4,7 +4,6 @@ import { describe, expect, test } from "bun:test"; import { Milli } from "@moq/clock"; import { randomHop } from "../hop.ts"; -import { Version as IetfVersion } from "../ietf/version.ts"; import { createMockTransportPair } from "../mock.ts"; import { Producer as OriginProducer } from "../origin.ts"; import * as Path from "../path.ts"; @@ -392,10 +391,8 @@ describe.each([Version.DRAFT_05, Version.DRAFT_06, Version.DRAFT_07])("%s", (ver origin.close(); }); - // Timestamps received over moq-transport may be arrival times, so they never enter moq-lite, - // whose receivers check every timestamp: the track is served untimed (milliseconds of send - // time before lite-07). - test("an unchecked track is served untimed", async () => { + // An unchecked track's timestamps go out as received, so TRACK_INFO declares its own scale. + test("an unchecked track is served with its timescale", async () => { const pair = createMockTransportPair(ALPN_05); const origin = new OriginProducer(); const publisher = new Publisher(pair.server, version, randomHop(), origin.consume()); @@ -406,7 +403,7 @@ describe.each([Version.DRAFT_05, Version.DRAFT_06, Version.DRAFT_07])("%s", (ver for (;;) { const request = await wireOf(broadcast).requested(); if (!request) return; - request.accept({ timescale: Timescale.MICRO, ietf: IetfVersion.DRAFT_22 }); + request.accept({ timescale: Timescale.MICRO, unchecked: true }); } })(); @@ -416,7 +413,7 @@ describe.each([Version.DRAFT_05, Version.DRAFT_06, Version.DRAFT_07])("%s", (ver void publisher.runTrackInfo(new TrackMessage(Path.from("room"), "video"), server); const info = await TrackInfo.decode(client.reader, version); - expect(info.timescale).toBe(version === Version.DRAFT_07 ? undefined : Timescale.MILLI); + expect(info.timescale).toBe(Timescale.MICRO); client.writer.close(); publisher.close(); diff --git a/js/net/src/lite/version.ts b/js/net/src/lite/version.ts index a1a50db4127..fe9ce8cf54d 100644 --- a/js/net/src/lite/version.ts +++ b/js/net/src/lite/version.ts @@ -475,8 +475,8 @@ export function hasRefresh(version: Version): boolean { } /** Whether received frame timestamps are the publisher's media time. Lite-05/06 stamp an untimed - * track's payloads with their send time, which a receiver cannot tell from it, so it drops every - * timestamp received on them and the track arrives untimed. */ + * track's payloads with their send time, which a receiver cannot tell from it, so it passes them + * through as the track's time without checking them for a rewind. */ export function hasMediaTime(version: Version): boolean { // Explicitly list older versions so future versions keep the lite-07+ behavior. switch (version) { diff --git a/js/net/src/resume.ts b/js/net/src/resume.ts index 7ffef6a7e75..c0fb6ef3ae8 100644 --- a/js/net/src/resume.ts +++ b/js/net/src/resume.ts @@ -101,15 +101,16 @@ export function routeFailed(err: Error): boolean { return err instanceof SessionError || sessionClosed(err); } -// Every `track.Info` field, so one added later fails to compile until it is listed here. +// Every `track.Info` field but `unchecked`, so one added later fails to compile until it is +// listed here. `unchecked` says how a copy arrived, not what it holds, so copies over different +// versions still match. const INFO_FIELDS = Object.keys({ compress: true, timescale: true, maxAge: true, priority: true, refresh: true, - ietf: true, -} satisfies Record) as (keyof track.Info)[]; +} satisfies Record, true>) as (keyof track.Info)[]; /** Two copies claiming the same content must agree on all of it, like Rust's `Info` equality. */ function compatible(a: track.Info, b: track.Info): boolean { diff --git a/js/net/src/track.test.ts b/js/net/src/track.test.ts index 761120a0d75..eeb769cdc7d 100644 --- a/js/net/src/track.test.ts +++ b/js/net/src/track.test.ts @@ -5,7 +5,6 @@ import { ProtocolViolation, StreamCode, StreamError, TimestampMismatch, TooFarBe import { Decoder } from "./flate/decoder.ts"; import { Encoder } from "./flate/encoder.ts"; import { type Consumer as GroupConsumer, type Producer as GroupProducer, MAX_GROUP_FRAMES } from "./group.ts"; -import { Version as IetfVersion } from "./ietf/version.ts"; import { hooks } from "./internal.ts"; import { textFrame } from "./mock.ts"; import { Timescale, Timestamp } from "./time.ts"; @@ -3367,13 +3366,13 @@ test("an endless track with gaps remembers only those within the budget", () => } }); -test("IETF provenance survives normalization on timed and untimed tracks", () => { +test("unchecked survives normalization on timed and untimed tracks", () => { for (const timescale of [undefined, Timescale.MILLI]) { - const info = infoDefaults({ ietf: IetfVersion.DRAFT_22, timescale }); - expect(info.ietf).toBe(IetfVersion.DRAFT_22); + const info = infoDefaults({ unchecked: true, timescale }); + expect(info.unchecked).toBe(true); expect(info.timescale).toBe(timescale); } - const producer = new TrackProducer("ietf").accept({ timescale: Timescale.MILLI, ietf: IetfVersion.DRAFT_22 }); + const producer = new TrackProducer("ietf").accept({ timescale: Timescale.MILLI, unchecked: true }); try { stampGroup(producer, 0, 1000); stampGroup(producer, 1, 500); diff --git a/js/net/src/track.ts b/js/net/src/track.ts index 6341f0d270a..f6a184103b6 100644 --- a/js/net/src/track.ts +++ b/js/net/src/track.ts @@ -19,7 +19,6 @@ import { } from "./error.ts"; import { datagramSlice, type Stored, sliceView } from "./flate/group.ts"; import { type Frame, type Consumer as GroupConsumer, Producer as GroupProducer } from "./group.ts"; -import type { IetfVersion } from "./ietf/version.ts"; import { type DropRun, dropAt, @@ -153,8 +152,11 @@ export interface Info { * one is pending. `0` asks on any join after a delta. An integer in `0..2^32`. */ refresh?: number; - /** The original moq-transport publisher's draft, whose timestamps may rewind. @internal */ - ietf?: IetfVersion; + /** + * Whether this copy's groups skip the rewind check, since its timestamps may be moq-transport + * arrival times or lite-05/06 send times. Mirrors the Rust `track::Info::unchecked`. @internal + */ + unchecked?: boolean; } // Normalize a duration for the wire, which carries it as an unsigned varint. @@ -192,7 +194,7 @@ export function infoDefaults(info: Partial = {}): Info { maxAge: info.maxAge === undefined ? undefined : wireMillis("maxAge", info.maxAge), priority: priorityValue(info.priority ?? DEFAULT_PRIORITY), refresh: info.refresh == null ? undefined : refreshRatio(info.refresh), - ...(info.ietf === undefined ? {} : { ietf: info.ietf }), + ...(info.unchecked ? { unchecked: true } : {}), }; } @@ -1448,9 +1450,9 @@ export class Producer { return group; } - // Whether this track's timestamps may rewind (see {@link Info.ietf}). + // Whether this track's timestamps may rewind (see {@link Info.unchecked}). #unchecked(): boolean { - return this.#state.info.peek()?.ietf !== undefined; + return this.#state.info.peek()?.unchecked === true; } // Fan a datagram out to every live subscriber, dropping the oldest once the ring is full. diff --git a/js/net/src/untimed.test.ts b/js/net/src/untimed.test.ts index 3579fbf1b8d..8339b7cec7c 100644 --- a/js/net/src/untimed.test.ts +++ b/js/net/src/untimed.test.ts @@ -1,5 +1,6 @@ -// A track keeps its timedness end to end: no receive path fills in arrival time, and a -// wire that can't declare a timeline delivers frames untimed. Mirrors rs/moq-net/tests/integration/untimed.rs. +// A track keeps its timedness end to end: no receive path fills in arrival time, a wire that +// can't declare a timeline delivers frames untimed, and lite-05/06, which can't declare an +// untimed one, deliver its send times. Mirrors rs/moq-net/tests/integration/untimed.rs. import { expect, test } from "bun:test"; import { type Consumer as BroadcastConsumer, Producer as BroadcastProducer } from "./broadcast.ts"; import { accept, connect } from "./connection/index.ts"; @@ -19,18 +20,20 @@ interface Wire { name: string; protocol: string; version?: number; - /** Whether a timed track arrives timed. Lite-05/06 receivers drop timestamps, which may be send times. */ + /** Whether a timed track arrives timed. */ declares: boolean; + /** Whether an untimed track arrives timed in milliseconds with its send times, as on lite-05/06. */ + sends: boolean; } const WIRES: Wire[] = [ - { name: "lite-01", protocol: "", version: Lite.Version.DRAFT_01, declares: false }, - { name: "lite-03", protocol: Lite.ALPN_03, declares: false }, - { name: "lite-04", protocol: Lite.ALPN_04, declares: false }, - { name: "lite-05", protocol: Lite.ALPN_05, declares: false }, - { name: "lite-06", protocol: Lite.ALPN_06, declares: false }, - { name: "lite-07-wip", protocol: Lite.ALPN_07_WIP, declares: true }, - { name: "ietf-22", protocol: Ietf.ALPN.DRAFT_22, declares: true }, + { name: "lite-01", protocol: "", version: Lite.Version.DRAFT_01, declares: false, sends: false }, + { name: "lite-03", protocol: Lite.ALPN_03, declares: false, sends: false }, + { name: "lite-04", protocol: Lite.ALPN_04, declares: false, sends: false }, + { name: "lite-05", protocol: Lite.ALPN_05, declares: true, sends: true }, + { name: "lite-06", protocol: Lite.ALPN_06, declares: true, sends: true }, + { name: "lite-07-wip", protocol: Lite.ALPN_07_WIP, declares: true, sends: false }, + { name: "ietf-22", protocol: Ietf.ALPN.DRAFT_22, declares: true, sends: false }, ]; /** Serve one group of `timestamps` on a track with `timescale`, and read it back over `wire`. */ @@ -155,11 +158,11 @@ test("a forwarded untimed track stays untimed", async () => { }); for (const wire of WIRES) { - test(`${wire.name}: an untimed track arrives untimed`, async () => { + test(`${wire.name}: an untimed track arrives ${wire.sends ? "with its send times" : "untimed"}`, async () => { const { info, frames } = await roundTrip(wire, undefined, [undefined, undefined]); expect(frames.map((frame) => frame.payload[0])).toEqual([0, 1]); - expect(info.timescale).toBeUndefined(); - for (const frame of frames) expect(frame.timestamp).toBeUndefined(); + expect(info.timescale).toBe(wire.sends ? Timescale.MILLI : undefined); + for (const frame of frames) expect(frame.timestamp !== undefined).toBe(wire.sends); }); test(`${wire.name}: a timed track keeps its timestamps only where the wire delivers them`, async () => { @@ -181,7 +184,7 @@ for (const wire of WIRES) { } for (const wire of WIRES.filter((wire) => wire.name === "lite-06" || wire.name === "lite-07-wip")) { - test(`${wire.name}: an untimed datagram arrives untimed`, async () => { + test(`${wire.name}: an untimed datagram arrives ${wire.sends ? "with its send time" : "untimed"}`, async () => { const pair = createMockTransportPair(wire.protocol); const origin = new OriginProducer(); const [client, server] = await Promise.all([ @@ -205,7 +208,7 @@ for (const wire of WIRES.filter((wire) => wire.name === "lite-06" || wire.name = const datagram = await subscriber.recvDatagram(); expect(datagram?.payload).toEqual(new Uint8Array([7])); - expect(datagram?.timestamp).toBeUndefined(); + expect(datagram?.timestamp !== undefined).toBe(wire.sends); broadcast.close(); subscriber.close(); diff --git a/rs/moq-cli/src/publish.rs b/rs/moq-cli/src/publish.rs index eda3a8a3fe3..08cd96473c5 100644 --- a/rs/moq-cli/src/publish.rs +++ b/rs/moq-cli/src/publish.rs @@ -1441,9 +1441,8 @@ pub(crate) mod tests { // Joining once every group is out, with a budget half the jump, reads every group // after it past the marker, and none of the groups the jump left more than // the budget behind. An IETF subscription starts at the newest group, so only lite - // has the groups behind it to read, and a lite-06 subscriber drops the timestamps - // that carry the jump. - if version == "moq-lite-07-wip" { + // has the groups behind it to read. + if version.starts_with("moq-lite") { let late = read(start(moq_net::track::Subscription::default().with_max_delay(Duration::from_secs(10))).await) .await diff --git a/rs/moq-net/src/lite/ietf.rs b/rs/moq-net/src/lite/ietf.rs index 8538d900856..e5492601260 100644 --- a/rs/moq-net/src/lite/ietf.rs +++ b/rs/moq-net/src/lite/ietf.rs @@ -1136,7 +1136,7 @@ mod hop_tests { // The upstream group is still open. let frame = next(&mut received).await.unwrap(); assert_eq!(&frame.payload.contiguous(0)[..], b"a"); - assert_eq!(frame.timestamp, negotiated.then(|| ts(0))); + assert_eq!(frame.timestamp, Some(ts(0))); match negotiated { true => { assert_eq!(fields(&frame), Some((first.id, first.properties.clone())), "{offer:?}"); @@ -1177,7 +1177,7 @@ mod hop_tests { (info.max_age, info.timescale, info.priority, info.refresh), ( Some(Duration::from_secs(7)), - negotiated.then_some(Timescale::MILLI), + Some(Timescale::MILLI), 9, Some(0) ), @@ -1436,9 +1436,9 @@ mod hop_tests { } } - /// Provenance keeps IETF times unchecked after a hop, while a peer declining the - /// extension gets no timeline. SUBSCRIBE, FETCH, and datagrams must agree with TRACK_INFO, - /// while a listing stays untimed. + /// Every hop carries IETF times, and provenance keeps them unchecked after a hop that + /// negotiated the extension. A peer declining it checks them like native moq-lite, as a + /// listing's copy does. SUBSCRIBE, FETCH, and datagrams must agree with TRACK_INFO. #[moq_clock::test] async fn ietf_timestamps_keep_their_provenance_across_a_hop() { for offer in [[true, true], [true, false], [false, true]] { @@ -1455,8 +1455,7 @@ mod hop_tests { head.finish().unwrap(); let (downstream, sessions) = test_hop(&upstream, "room", offer).await; let broadcast = downstream.consume().request_broadcast("room", None).await.unwrap(); - // A listing cannot carry the provenance, so it lists the track untimed even when - // negotiated: a relay re-listing it would otherwise advertise it as native lite. + // A listing carries no provenance, so it lists the track as native lite. let mut tracks = broadcast.tracks().unwrap(); let listed = loop { match moq_clock::timeout(TIMEOUT, tracks.next()).await.unwrap().unwrap() { @@ -1465,10 +1464,14 @@ mod hop_tests { None => panic!("listing ended before the track"), } }; - assert_eq!((listed.timescale, listed.ietf()), (None, None), "{offer:?}"); + assert_eq!( + (listed.timescale, listed.ietf()), + (Some(Timescale::MILLI), None), + "{offer:?}" + ); let copy = broadcast.track("video").unwrap(); let info = moq_clock::timeout(TIMEOUT, copy.info()).await.unwrap().unwrap(); - assert_eq!(info.timescale, negotiated.then_some(Timescale::MILLI), "{offer:?}"); + assert_eq!(info.timescale, Some(Timescale::MILLI), "{offer:?}"); assert_eq!( info.ietf(), negotiated.then_some(crate::ietf::Version::Draft22), @@ -1480,7 +1483,7 @@ mod hop_tests { .await .unwrap() .unwrap(); - assert_eq!(next(&mut fetched).await.unwrap().timestamp, negotiated.then(|| ts(100))); + assert_eq!(next(&mut fetched).await.unwrap().timestamp, Some(ts(100))); assert!(next(&mut fetched).await.is_none()); let mut subscriber = moq_clock::timeout(TIMEOUT, copy.subscribe(track::Subscription::default().with_start(1))) @@ -1488,23 +1491,26 @@ mod hop_tests { .unwrap() .unwrap(); // A peer may have stamped arrival times. The second group's rewind must not - // acquire native moq-lite checks merely because it crossed a relay hop. + // acquire native moq-lite checks merely because it crossed a negotiated hop; + // without the extension, the copy is checked, so it advances instead. + let start = if negotiated { ts(50) } else { ts(150) }; let mut group = track.create_group(1u64.into()).unwrap(); - group.write_frame(ts(50), b"frame".to_vec()).unwrap(); + group.write_frame(start, b"frame".to_vec()).unwrap(); group.finish().unwrap(); let mut received = recv(&mut subscriber).await; assert_eq!(received.sequence, 1); let frame = next(&mut received).await.unwrap(); - assert_eq!(frame.timestamp, negotiated.then(|| ts(50)), "{offer:?}"); + assert_eq!(frame.timestamp, Some(start), "{offer:?}"); assert_eq!(&frame.payload.contiguous(0)[..], b"frame"); assert!(next(&mut received).await.is_none()); - track.insert_datagram(2, ts(25), b"datagram".to_vec()).unwrap(); + let time = if negotiated { ts(25) } else { ts(200) }; + track.insert_datagram(2, time, b"datagram".to_vec()).unwrap(); let datagram = moq_clock::timeout(TIMEOUT, kio::wait(|waiter| subscriber.poll_recv_wire_datagram(waiter))) .await .unwrap() .unwrap() .unwrap(); - assert_eq!(datagram.timestamp, negotiated.then(|| ts(25)), "{offer:?}"); + assert_eq!(datagram.timestamp, Some(time), "{offer:?}"); assert_eq!(&datagram.payload[..], b"datagram"); drop(sessions); } diff --git a/rs/moq-net/src/lite/publisher.rs b/rs/moq-net/src/lite/publisher.rs index f242d3ff797..3f34e3e520a 100644 --- a/rs/moq-net/src/lite/publisher.rs +++ b/rs/moq-net/src/lite/publisher.rs @@ -1835,7 +1835,7 @@ impl Request for TrackInfoServe { crate::ietf::flate::egress(&info, shared.version.has_compression())?; // TRACK_INFO only flows on Lite05+ (the encode errors otherwise). - writer.buffer(&lite::TrackInfo::serve(&info, shared.version, ietf))?; + writer.buffer(&lite::TrackInfo::serve(&info, shared.version))?; if ietf { writer.buffer(&lite::ietf::TrackProperties(info.properties.clone()))?; } @@ -1891,9 +1891,7 @@ impl Request for TracksServe { let event = match ready!(self.tracks.poll_next(waiter))? { Some(crate::broadcast::TracksEvent::Added { name, info }) => lite::TracksEvent::Added { name: name.to_string().into(), - // Untimed even to an extension peer: TRACKS_ADD has no TRACK_PROPERTIES to - // carry the unchecked provenance, so a relay would re-list it as native lite. - info: lite::TrackInfo::serve(&info, shared.version, false), + info: lite::TrackInfo::serve(&info, shared.version), }, Some(crate::broadcast::TracksEvent::Removed { name }) => lite::TracksEvent::Removed { name: name.to_string().into(), @@ -1998,7 +1996,6 @@ impl Request for SubscribeServe { loop { match self { Self::Query { querying, .. } => { - let ietf = ready!(shared.peer_setup.poll_ietf(waiter)); let info = ready!(querying.poll_ok(waiter))?; let Self::Query { msg, @@ -2016,7 +2013,7 @@ impl Request for SubscribeServe { else { unreachable!() }; - let bounds = Bounds::new(&msg.ranges, info.lite_timescale(ietf))?; + let bounds = Bounds::new(&msg.ranges, info.timescale)?; *self = Self::subscribe(shared, *msg, bounds, &track, latest, update); } Self::Confirm { subscribing, .. } => { @@ -2043,7 +2040,7 @@ impl Request for SubscribeServe { // `None` omits the per-frame timestamp prefix: an untimed track on // Lite07+, or any track before Lite05 (whose frames still carry // timestamps in the model, just not on this wire). - let stamp = Stamp::new(shared.version, track.info().lite_timescale(ietf)); + let stamp = Stamp::new(shared.version, track.info().timescale); // Lite05+ accepts implicitly: no SUBSCRIBE_OK, the immutable properties // live in TRACK_INFO, and the resolved range arrives as @@ -2252,7 +2249,7 @@ impl Request for FetchServe { let mut group = group.with_end(msg.end_frame.and_then(|end| end.checked_add(1))); // Matches the timescale TRACK_INFO declared for the track. - let stamp = Stamp::new(shared.version, group.lite_timescale(ietf)); + let stamp = Stamp::new(shared.version, group.timescale()); // And its compression, which a lite-07 peer receives as stored. if shared.version.has_compression() { group = group.compressed(); @@ -3337,13 +3334,12 @@ struct Stamp { /// The wire timescale TRACK_INFO declared (see [`Version::wire_timescale`]). timescale: crate::Timescale, /// Whether each frame's own timestamp goes out. Lite05/06 cannot encode an untimed - /// track, so one served untimed carries its send time instead, unchecked ones included. + /// track, so an untimed one carries its send time instead. timed: bool, } impl Stamp { - /// How `version` stamps a track served at `timescale` (see - /// [`track::Info::lite_timescale`]), or `None` when it carries no timestamps. + /// How `version` stamps a track with `timescale`, or `None` when it carries no timestamps. fn new(version: Version, timescale: Option) -> Option { Some(Self { timescale: version.wire_timescale(timescale)?, @@ -5016,29 +5012,21 @@ mod serve_group_test { } } - /// A track served untimed to lite-05/06 carries its send time, never its frames' own - /// timestamps: those of an unchecked track may be moq-transport arrival times. + /// Lite-05/06 cannot encode an untimed track, so one carries its send time there and + /// nothing on lite-07, while a timed track carries its own timestamps on every version. #[moq_clock::test] - async fn an_unchecked_track_goes_out_with_send_times() { + async fn only_an_untimed_track_goes_out_with_send_times() { let runtime = crate::time::sim(); let stamped = Timestamp::from_millis(36_000_000).unwrap(); let sent = Timestamp::from(runtime.now()).value(); - let checked = track::Info::timed(); - let unchecked = track::Info { - properties: Some(std::sync::Arc::new(crate::model::object::TrackProperties { - version: crate::ietf::Version::Draft22, - values: Vec::new(), - })), - ..track::Info::timed() - }; - let stamp = Stamp::new(Version::Lite06, checked.lite_timescale(false)).unwrap(); - assert_eq!(stamp.wire(Some(stamped), &runtime).unwrap(), stamped.value()); - let stamp = Stamp::new(Version::Lite06, unchecked.lite_timescale(false)).unwrap(); - assert_eq!(stamp.wire(Some(stamped), &runtime).unwrap(), sent); - assert!(Stamp::new(Version::Lite07, unchecked.lite_timescale(false)).is_none()); - let stamp = Stamp::new(Version::Lite07, unchecked.lite_timescale(true)).unwrap(); - assert_eq!(stamp.wire(Some(stamped), &runtime).unwrap(), stamped.value()); + for version in [Version::Lite06, Version::Lite07] { + let stamp = Stamp::new(version, Some(crate::Timescale::MILLI)).unwrap(); + assert_eq!(stamp.wire(Some(stamped), &runtime).unwrap(), stamped.value(), "{version}"); + } + let stamp = Stamp::new(Version::Lite06, None).unwrap(); + assert_eq!(stamp.wire(None, &runtime).unwrap(), sent); + assert!(Stamp::new(Version::Lite07, None).is_none()); } #[moq_clock::test] diff --git a/rs/moq-net/src/lite/subscriber.rs b/rs/moq-net/src/lite/subscriber.rs index bb790d734d8..911d267a604 100644 --- a/rs/moq-net/src/lite/subscriber.rs +++ b/rs/moq-net/src/lite/subscriber.rs @@ -497,9 +497,7 @@ impl Subscriber { .zip(entry.framing.timescale) .map(|(value, scale)| Timestamp::new(value, scale)) .transpose() - .map_err(|_| Error::BoundsExceeded(crate::coding::BoundsExceeded))? - // Dropped where it may be a send time, like a frame's. - .filter(|_| self.version.has_media_time()); + .map_err(|_| Error::BoundsExceeded(crate::coding::BoundsExceeded))?; // A datagram is never owed a stream, so it never holds the subscription's end open. if let Ok(mut tail) = entry.tail.write() { @@ -1042,7 +1040,7 @@ impl GroupRecv { self.state = GroupRecvState::Serve { group: crate::recv::Group::new(group), track, - ingest: FrameIngest::new(framing, self.subscriber.version, ietf, hdr.frame_start), + ingest: FrameIngest::new(framing, ietf, hdr.frame_start), _reading: reading, }; } @@ -1113,9 +1111,6 @@ struct FrameIngest { /// `Some` once the Group State of the `ietf` extension arrived: every frame follows an /// object record. records: Option, - /// Whether the session's timestamps are media time. Lite-05/06 ones may be send times, - /// so they are read to stay in step and dropped. - media_time: bool, } /// A group's object records on ingest, under the `ietf` extension. @@ -1161,7 +1156,7 @@ enum IngestPhase { impl FrameIngest { /// `ietf` when the session negotiated the extension, so the stream starts with a Group State. - fn new(framing: lite::Framing, version: Version, ietf: bool, frame_start: u64) -> Self { + fn new(framing: lite::Framing, ietf: bool, frame_start: u64) -> Self { Self { framing, prev_ts: 0, @@ -1171,7 +1166,6 @@ impl FrameIngest { }, frame_start, records: None, - media_time: version.has_media_time(), } } @@ -1293,9 +1287,8 @@ impl FrameIngest { self.prev_ts = next; let timestamp = Timestamp::new(next, scale) .map_err(|_| Error::BoundsExceeded(crate::coding::BoundsExceeded))?; - // Read to stay in step, but dropped where it may be a send time. self.phase = IngestPhase::Inflated { - timestamp: self.media_time.then_some(timestamp), + timestamp: Some(timestamp), }; } IngestPhase::Inflated { timestamp } => { @@ -2920,11 +2913,10 @@ mod tests { going_away: Default::default(), auth: crate::auth::Link::new(false), }); - // The track is untimed where the subscriber drops received timestamps. let track = track::Producer::new( std::sync::Arc::new(crate::broadcast::Info::default()), "video", - crate::track::Info::default().with_timescale(version.has_media_time().then_some(Timescale::MILLI)), + crate::track::Info::timed(), ); let mut consumer = track.consume().subscribe(None).await.unwrap(); subscriber.subscribes.lock().insert( @@ -3261,16 +3253,15 @@ mod tests { auth: crate::auth::Link::new(false), }); - // The copy is untimed where the wire's timestamps may be send times. - let timed = version.has_media_time(); - let info = match timed { - true => crate::track::Info::timed(), - false => crate::track::Info::default(), + // Unchecked where the wire's timestamps may be send times, as the copy is accepted. + let info = crate::track::Info { + unchecked: !version.has_media_time(), + ..crate::track::Info::timed() }; let track = track::Producer::new(std::sync::Arc::new(crate::broadcast::Info::default()), "video", info); let mut before = track.create_group(4u64.into()).unwrap(); before - .write_frame(timed.then(|| Timestamp::from_millis(1000).unwrap()), &b"before"[..]) + .write_frame(Timestamp::from_millis(1000).unwrap(), &b"before"[..]) .unwrap(); before.finish().unwrap(); subscriber.subscribes.lock().insert( @@ -3295,10 +3286,10 @@ mod tests { (res, track) } - /// Lite-05/06 timestamps may be send times, so a received frame is read past its - /// timestamp and lands untimed: nothing rewinds, and the track stays open. + /// Lite-05/06 timestamps may be send times, so a received group that rewinds keeps its + /// timestamp unchecked, and the track stays open. #[moq_clock::test] - async fn lite06_timestamps_are_dropped() { + async fn a_lite06_rewind_passes_through() { for version in [Version::Lite05, Version::Lite06] { // Frame 0 at 500ms, before group 4's 1000ms. let (res, track) = receive_group(version, &[500]).await; @@ -3309,7 +3300,7 @@ mod tests { assert_eq!(group.sequence, 5, "{version}"); let frame = group.read_frame().now_or_never().unwrap().unwrap().unwrap(); assert_eq!(frame.payload.as_ref(), b"frame", "{version}"); - assert_eq!(frame.timestamp, None, "{version}"); + assert_eq!(frame.timestamp, Timestamp::from_millis(500).ok(), "{version}"); } } @@ -3324,7 +3315,6 @@ mod tests { /// A received timestamp past 2^61 - 1 is refused at every version, so a relay never /// holds one that lite-05/06 could not carry as a group's first frame. lite-06 reaches /// it with a second delta, lite-07 with a first frame its 64-bit varint can encode. - /// lite-05/06 drop the timestamp, but a stream carrying one past the bound is still malformed. #[moq_clock::test] async fn a_received_timestamp_past_2_61_is_refused() { let max: i64 = (1 << 61) - 1; @@ -3333,8 +3323,7 @@ mod tests { res.unwrap_or_else(|err| panic!("{version}: {err:?}")); let mut group = track.consume().peek_group(5).unwrap(); let frame = group.read_frame().now_or_never().unwrap().unwrap().unwrap(); - let kept = version.has_media_time().then_some(max as u64); - assert_eq!(frame.timestamp.map(Timestamp::value), kept, "{version}"); + assert_eq!(frame.timestamp.map(Timestamp::value), Some(max as u64), "{version}"); let (res, _) = receive_group(version, &[max, 1]).await; assert!(matches!(res, Err(Error::BoundsExceeded(_))), "{version}: {res:?}"); @@ -3856,9 +3845,8 @@ mod tests { let broadcast = crate::broadcast::Info::new().produce(); // The broadcast keeps only a weak handle, so the map below owns the only strong // `track::Producer`: dropping it is what ends the track. - // Untimed, as the subscriber drops lite-05 timestamps. let producer = broadcast - .create_track("datagrams", crate::track::Info::default()) + .create_track("datagrams", crate::track::Info::timed()) .unwrap(); let mut received = producer.subscribe(None); subscriber.subscribes.lock().insert( @@ -7173,11 +7161,9 @@ impl kio::Task for TrackServeRun { let request = request.take().expect("request pending"); match res { Ok((mut info, held)) => { - // Lite05/06 timestamps may be send times, so the copy is untimed - // and the ingest reads past them (see `lite::Framing::new`). - if !self.serve.subscriber.version.has_media_time() { - info.timescale = None; - } + // Lite05/06 timestamps may be send times, so the copy's groups + // skip the rewind check. + info.unchecked = !self.serve.subscriber.version.has_media_time(); let mut serve_loop = ServeLoop::new(&self.serve, request, info); serve_loop.held = Some(held); self.state = TrackRunState::Serve(serve_loop); @@ -8440,7 +8426,6 @@ impl kio::Task for FetchServeRun { readers, ingest: Box::new(FrameIngest::new( lite::Framing::new(&self.info, self.serve.subscriber.version), - self.serve.subscriber.version, ietf, frame_start, )), diff --git a/rs/moq-net/src/lite/track.rs b/rs/moq-net/src/lite/track.rs index 61a72eaa746..de89759e90b 100644 --- a/rs/moq-net/src/lite/track.rs +++ b/rs/moq-net/src/lite/track.rs @@ -79,13 +79,12 @@ pub struct TrackInfo { impl TrackInfo { /// The TRACK_INFO a publisher serves for `info` on `version`. - pub(crate) fn serve(info: &crate::track::Info, version: Version, ietf: bool) -> Self { + pub(crate) fn serve(info: &crate::track::Info, version: Version) -> Self { Self { refresh: info.refresh, priority: info.priority, max_age: info.max_age, - // Only an extension peer knows the original publisher may stamp arrival times. - timescale: info.lite_timescale(ietf), + timescale: info.timescale, // An older peer is served the frames inflated. compress: info.compress && version.has_compression(), } @@ -319,7 +318,7 @@ mod test { #[test] fn track_info_defaults_match_cross_language_wire_bytes() { // The default track is untimed, which lite-05 declares as milliseconds. - let info = TrackInfo::serve(&crate::track::Info::default(), Version::Lite05, false); + let info = TrackInfo::serve(&crate::track::Info::default(), Version::Lite05); let mut buf = Vec::new(); info.encode(&mut Encoder::new(&mut buf, Version::Lite05.into()), Version::Lite05) .unwrap(); diff --git a/rs/moq-net/src/lite/version.rs b/rs/moq-net/src/lite/version.rs index 601ec193de6..2351d5485e5 100644 --- a/rs/moq-net/src/lite/version.rs +++ b/rs/moq-net/src/lite/version.rs @@ -310,7 +310,7 @@ impl Version { /// Whether received frame timestamps are the publisher's media time. Lite05/06 stamp an /// untimed track's payloads with their send time, which a receiver cannot tell from it, - /// so it drops every timestamp received on them and the track arrives untimed. + /// so it passes them through as the track's time without checking them for a rewind. pub(crate) fn has_media_time(self) -> bool { !matches!( self, diff --git a/rs/moq-net/src/model/group.rs b/rs/moq-net/src/model/group.rs index aaaa927dec5..e4cbaf9fc1e 100644 --- a/rs/moq-net/src/model/group.rs +++ b/rs/moq-net/src/model/group.rs @@ -3250,13 +3250,6 @@ impl Consumer { self.track.timescale } - /// The timescale a moq-lite hop serves the parent track at (see - /// [`track::Info::lite_timescale`]). - #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] - pub(crate) fn lite_timescale(&self, ietf: bool) -> Option { - self.track.lite_timescale(ietf) - } - /// The draft the parent track's moq-transport publisher spoke, which serialized every /// object's properties, or `None` for a moq-lite one. #[cfg(feature = "async")] diff --git a/rs/moq-net/src/model/track.rs b/rs/moq-net/src/model/track.rs index 1fa3ee98068..7e3ed453bfc 100644 --- a/rs/moq-net/src/model/track.rs +++ b/rs/moq-net/src/model/track.rs @@ -102,7 +102,7 @@ pub(crate) const IDLE_LINGER: Duration = Duration::from_secs(30); // Deliberately not `Copy`, even though it's now a plain value: adding `Copy` turns // every existing `info.clone()` in a consumer's code into a `clippy::clone_on_copy` // error under `-D warnings`. -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Clone, Debug)] #[non_exhaustive] pub struct Info { /// Units per second for per-frame timestamps on this track, or `None` for an untimed @@ -175,8 +175,37 @@ pub struct Info { /// Shared, since every group holds a copy of the info. #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] pub(crate) properties: Option>, + /// Whether this copy's groups skip the rewind check: set on a lite-05/06 copy, whose + /// untimed origin stamps send times, so an older group fetched later looks like a rewind. + /// A track with moq-transport provenance ([`Self::ietf`]) skips it too. + #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] + pub(crate) unchecked: bool, } +// `unchecked` says how this copy arrived, not what it holds, so copies of one track over +// different versions still match. +impl PartialEq for Info { + fn eq(&self, other: &Self) -> bool { + let Self { + timescale, + max_age, + priority, + compress, + refresh, + properties, + unchecked: _, + } = self; + *timescale == other.timescale + && *max_age == other.max_age + && *priority == other.priority + && *compress == other.compress + && *refresh == other.refresh + && *properties == other.properties + } +} + +impl Eq for Info {} + impl Default for Info { fn default() -> Self { Self { @@ -186,6 +215,7 @@ impl Default for Info { compress: false, refresh: None, properties: None, + unchecked: false, } } } @@ -225,13 +255,6 @@ impl Info { self } - /// The timescale served on a moq-lite hop, preserving moq-transport timestamps only - /// when the hop negotiated the `ietf` extension. - #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] - pub(crate) fn lite_timescale(&self, ietf: bool) -> Option { - self.timescale.filter(|_| self.ietf().is_none() || ietf) - } - /// The original moq-transport publisher's draft, whose timestamps may rewind, or /// `None` for a native moq-lite track. pub(crate) fn ietf(&self) -> Option { @@ -821,9 +844,13 @@ impl TrackState { /// so the watermark caps it instead. /// /// Usually one group lookup each way; only unstarted or partial neighbors are skipped. - /// `None` on a track with moq-transport provenance, whose timestamps may rewind. + /// `None` on an [unchecked](Info::unchecked) track, whose timestamps may rewind. pub(super) fn neighbors(&self, sequence: u64) -> Option { - if self.info.as_ref().is_some_and(|info| info.ietf().is_some()) { + if self + .info + .as_ref() + .is_some_and(|info| info.unchecked || info.ietf().is_some()) + { return None; } let bounds = self.bounds.lock().unwrap_or_else(PoisonError::into_inner); diff --git a/rs/moq-net/tests/integration/datagram.rs b/rs/moq-net/tests/integration/datagram.rs index 08b7219addb..a860a130253 100644 --- a/rs/moq-net/tests/integration/datagram.rs +++ b/rs/moq-net/tests/integration/datagram.rs @@ -48,7 +48,6 @@ async fn connect_datagram_track() -> Fixture { let producer = broadcast.create_track("datagrams", timed()).unwrap(); broadcast.announce(Default::default()).unwrap(); - // Lite-07, since a lite-05/06 subscriber drops every timestamp it receives. let mut options = MockConnectOptions::new("moq-lite-07-wip".parse::().unwrap()); options.server_publish = Some(publisher.consume()); options.client_subscribe = Some(consumer_origin.clone()); diff --git a/rs/moq-net/tests/integration/range_anchors.rs b/rs/moq-net/tests/integration/range_anchors.rs index 71850dd535b..61b987eb273 100644 --- a/rs/moq-net/tests/integration/range_anchors.rs +++ b/rs/moq-net/tests/integration/range_anchors.rs @@ -123,14 +123,11 @@ fn anchored() -> [(Range, Vec); 6] { #[moq_clock::test] async fn each_wire_refuses_only_the_anchors_it_drops() { for version in std::iter::once(None).chain(VERSIONS.iter().copied().map(Some)) { - // Lite-07 reports the largest and media time and asks for everything the budget - // allows, so its copy resolves every anchor where it is held. + // Lite-07 reports the largest and asks for everything the budget allows, so its copy + // resolves every anchor where it is held. let carried = matches!(version, None | Some("moq-lite-07-wip")); // A wire without timestamps refuses a time anchor for that first. - let timed = !matches!( - version, - Some("moq-lite-03" | "moq-lite-04" | "moq-lite-05" | "moq-lite-06") - ); + let timed = !matches!(version, Some("moq-lite-03" | "moq-lite-04")); for (range, held) in anchored() { let result = read(version, range).await; let time = matches!(range.start, Anchor::Time(_)) || matches!(range.end, Some(Anchor::Time(_))); diff --git a/rs/moq-net/tests/integration/received_rewind.rs b/rs/moq-net/tests/integration/received_rewind.rs index 6b8bd7cda19..27ea70d3f8f 100644 --- a/rs/moq-net/tests/integration/received_rewind.rs +++ b/rs/moq-net/tests/integration/received_rewind.rs @@ -1,11 +1,12 @@ #![cfg(feature = "async")] -//! A relay drops the timestamps it receives over lite-05/06. +//! A relay passes on the timestamps it receives over lite-05/06, unchecked. //! //! Lite-06 stamps an untimed track's frames with their send time and declares //! milliseconds, so a group sent after a higher one carries the later stamp. The relay -//! cannot tell that from media time, so its copy is untimed and every hop past it sees an -//! untimed track that nothing can refuse. +//! cannot tell that from media time, so its copy skips the rewind check, as a +//! moq-transport one does, and serves the timestamps on over every version. A lite-07 +//! receiver checks them, so it refuses that out-of-order group. use crate::support; @@ -17,6 +18,13 @@ use support::harness::{MockConnectOptions, connect_mock}; const TIMEOUT: Duration = Duration::from_secs(10); +/// A group's sequence and its first frame's timestamp, or the error reading it. +type Read = (u64, Result, moq_net::Error>); + +fn millis(ms: u64) -> moq_net::Timestamp { + moq_net::Timestamp::from_millis(ms).unwrap() +} + /// Long enough that both groups are fresh. const BUDGET: Duration = Duration::from_secs(60); @@ -32,19 +40,20 @@ fn write_group(track: &moq_net::track::Producer, sequence: u64) { let timestamp = track .info() .timescale - .map(|_| moq_net::Timestamp::from_millis(sequence * 1000).unwrap()); + .map(|_| millis(sequence * 1000)); let mut group = track.create_group(moq_net::group::Info { sequence }).unwrap(); group.write_frame(timestamp, &b"x"[..]).unwrap(); group.finish().unwrap(); } /// Groups 1 then 0 of a track at `timescale`, into a relay over `upstream` and out over -/// `downstream`. Returns the scale the subscriber learned and the groups it read. +/// `downstream`. Returns the scale the subscriber learned and, per group read, its sequence +/// and its first frame's timestamp or the error reading it. async fn relay( upstream: &str, downstream: &str, timescale: Option, -) -> (Option, Vec) { +) -> (Option, Vec) { let publisher = produce_origin(1); let broadcast = publisher.create_broadcast("bcast").unwrap(); let track = broadcast @@ -91,13 +100,11 @@ async fn relay( let Some(mut group) = next.expect("recv_group") else { break; }; - while moq_clock::timeout(TIMEOUT, group.read_frame()) + let read = moq_clock::timeout(TIMEOUT, group.read_frame()) .await .expect("read_frame timed out") - .expect("read_frame") - .is_some() - {} - got.push(group.sequence); + .map(|frame| frame.expect("a frame").timestamp); + got.push((group.sequence, read)); } (timescale, got) }); @@ -121,32 +128,47 @@ async fn relay( got } +/// A relay passes on lite-06 send times unchecked, so a lite-06 or moq-transport reader +/// reads both groups timed and the track stays open. A lite-07 reader checks them and +/// refuses the group that rewinds, the cost of an untimed origin on lite-06. #[moq_clock::test] async fn a_relay_forwards_descending_send_times_without_closing_the_track() { let mut failures = Vec::new(); for downstream in ["moq-lite-06", "moq-lite-07-wip", "moq-transport-22"] { - let got = relay("moq-lite-06", downstream, None).await; - if got.0.is_some() || got.1 != [1, 0] { - failures.push(format!("{downstream}: {got:?}")); + let (timescale, got) = relay("moq-lite-06", downstream, None).await; + let sequences: Vec<_> = got.iter().map(|(sequence, _)| *sequence).collect(); + let refused = downstream == "moq-lite-07-wip"; + let ok = timescale == Some(moq_net::Timescale::MILLI) + && sequences == [1, 0] + && matches!(got[0].1, Ok(Some(_))) + && match &got[1].1 { + Err(moq_net::Error::TimestampMismatch) => refused, + Ok(Some(_)) => !refused, + _ => false, + }; + if !ok { + failures.push(format!("{downstream}: {timescale:?} {got:?}")); } } assert!(failures.is_empty(), "{failures:#?}"); } -/// A moq-transport peer may stamp arrival times, so a relay keeps a timed track's timestamps -/// unchecked and passes them on only over moq-transport: a moq-lite hop, which checks every -/// timestamp it receives, is served the track untimed. +/// A timed track's timestamps cross a lite-06 or moq-transport hop between two origins with +/// their values, and the relay serves them on over every version. #[moq_clock::test] -async fn moq_transport_timestamps_stay_on_moq_transport() { +async fn a_timed_track_keeps_its_timestamps_through_a_relay() { let mut failures = Vec::new(); - for (downstream, expected) in [ - ("moq-lite-06", None), - ("moq-lite-07-wip", None), - ("moq-transport-22", Some(moq_net::Timescale::MILLI)), - ] { - let got = relay("moq-transport-22", downstream, Some(moq_net::Timescale::MILLI)).await; - if got.0 != expected || got.1 != [1, 0] { - failures.push(format!("{downstream}: {got:?}")); + for upstream in ["moq-lite-06", "moq-transport-22"] { + for downstream in ["moq-lite-06", "moq-lite-07-wip", "moq-transport-22"] { + let (timescale, got) = relay(upstream, downstream, Some(moq_net::Timescale::MILLI)).await; + let ok = timescale == Some(moq_net::Timescale::MILLI) + && matches!( + got.as_slice(), + [(1, Ok(Some(one))), (0, Ok(Some(zero)))] if *one == millis(1000) && *zero == millis(0) + ); + if !ok { + failures.push(format!("{upstream} -> {downstream}: {timescale:?} {got:?}")); + } } } assert!(failures.is_empty(), "{failures:#?}"); @@ -154,8 +176,9 @@ async fn moq_transport_timestamps_stay_on_moq_transport() { /// Fetch groups 1 then 0 of a finished untimed track over `version`, with no live /// subscription. Each answer carries its send time, so group 0 lands after group 1; the -/// copy the fetches fill drops them, so neither is refused. -async fn fetch_only(version: &str) -> Vec> { +/// copy the fetches fill is unchecked, so neither is refused. Returns each first frame's +/// timestamp. +async fn fetch_only(version: &str) -> Vec, moq_net::Error>> { let publisher = produce_origin(1); let broadcast = publisher.create_broadcast("bcast").unwrap(); let track = broadcast.create_track("data", Info::default()).unwrap(); @@ -184,8 +207,9 @@ async fn fetch_only(version: &str) -> Vec> { for sequence in [1, 0] { let read = async { let mut group = remote.track("data").unwrap().fetch_group(sequence, None).await?; + let timestamp = group.read_frame().await?.expect("a frame").timestamp; while group.read_frame().await?.is_some() {} - Ok(group.sequence) + Ok(timestamp) }; got.push(moq_clock::timeout(TIMEOUT, read).await.expect("fetch timed out")); // Answered later, so group 0's send time lands after group 1's. @@ -200,7 +224,8 @@ async fn fetches_alone_accept_descending_send_times() { let mut failures = Vec::new(); for version in ["moq-lite-05", "moq-lite-06"] { let got = fetch_only(version).await; - if got.iter().any(Result::is_err) { + // Both arrive timed with their send times, the later fetch's last. + if !matches!(got.as_slice(), [Ok(Some(one)), Ok(Some(zero))] if zero > one) { failures.push(format!("{version}: {got:?}")); } } diff --git a/rs/moq-net/tests/integration/untimed.rs b/rs/moq-net/tests/integration/untimed.rs index c313a31f23a..a94b24fb907 100644 --- a/rs/moq-net/tests/integration/untimed.rs +++ b/rs/moq-net/tests/integration/untimed.rs @@ -4,8 +4,8 @@ //! that can say so, and a timed track keeps its timestamps. //! //! No receiver fills in arrival time. Lite-05 and lite-06 cannot encode absence, so their -//! encoder writes its send time instead, and their receivers drop every timestamp, which -//! leaves a timed track untimed too. +//! encoder writes its send time instead, which their receivers pass through as the track's +//! time. use crate::support; @@ -27,14 +27,17 @@ const TIMEOUT: Duration = Duration::from_secs(10); enum Arrives { /// Both keep what the publisher wrote. Faithful, - /// The wire carries no trustworthy timescale, so even the timed track arrives untimed. + /// The timed track keeps its timestamps, but the untimed one arrives timed in + /// milliseconds with its send times. + SendTimes, + /// The wire carries no timescale, so even the timed track arrives untimed. Untimed, } fn expected(version: &str) -> Arrives { match version { - // Lite-05 and lite-06 stamp untimed tracks with send times, so their receivers drop them. - "moq-lite-03" | "moq-lite-04" | "moq-lite-05" | "moq-lite-06" => Arrives::Untimed, + "moq-lite-03" | "moq-lite-04" => Arrives::Untimed, + "moq-lite-05" | "moq-lite-06" => Arrives::SendTimes, _ => Arrives::Faithful, } } @@ -130,6 +133,11 @@ async fn frames_arrive_as_published() { assert_eq!(untimed, None, "{version}: absence survives"); assert_eq!(untimed_info.timescale, None, "{version}: no timeline is declared"); } + Arrives::SendTimes => { + assert_eq!(timed, Some(millis(7)), "{version}: the timestamp survives"); + assert!(untimed.is_some(), "{version}: the send time arrives"); + assert_eq!(untimed_info.timescale, Some(Timescale::MILLI), "{version}"); + } Arrives::Untimed => { assert_eq!(timed, None, "{version}: no units, so no timestamp"); assert_eq!(timed_info.timescale, None, "{version}: no timeline is declared"); @@ -197,8 +205,8 @@ async fn an_explicit_start_holds_on_an_untimed_track() { } } -/// An untimed track's datagram arrives untimed, though lite-05 and lite-06 carry a send -/// time that the receiver drops. +/// An untimed track's datagram arrives untimed, except that lite-05 and lite-06 carry its +/// send time. #[moq_clock::test] async fn datagrams_arrive_as_published() { for version in ["moq-lite-05", "moq-lite-07-wip", "moq-transport-22"] { @@ -219,11 +227,13 @@ async fn datagrams_arrive_as_published() { .expect("datagram timeout") .unwrap() .expect("a datagram"); - assert_eq!(datagram.timestamp, None, "{version}"); + let sent = expected(version) == Arrives::SendTimes; + assert_eq!(datagram.timestamp.is_some(), sent, "{version}"); } } -/// A standalone FETCH of an untimed track answers with untimed objects. +/// A standalone FETCH of an untimed track answers with untimed objects, except that lite-05 +/// and lite-06 carry each one's send time. #[moq_clock::test] async fn a_fetched_untimed_frame_arrives_untimed() { for version in ["moq-lite-06", "moq-lite-07-wip", "moq-transport-18"] { @@ -251,6 +261,7 @@ async fn a_fetched_untimed_frame_arrives_untimed() { let mut fetched = waiting.await.unwrap(); let frame = fetched.read_frame().await.unwrap().unwrap(); - assert_eq!(frame.timestamp, None, "{version}"); + let sent = expected(version) == Arrives::SendTimes; + assert_eq!(frame.timestamp.is_some(), sent, "{version}"); } } diff --git a/rs/moq-net/tests/integration/wide_sequence.rs b/rs/moq-net/tests/integration/wide_sequence.rs index f3c337aba5e..73991510d4c 100644 --- a/rs/moq-net/tests/integration/wide_sequence.rs +++ b/rs/moq-net/tests/integration/wide_sequence.rs @@ -52,8 +52,8 @@ async fn largest_quic_sequence_reaches_the_subscriber() { assert_eq!(got.sequence, sequence, "{alpn} relayed={relayed}"); let frame = got.read_frame().await.unwrap().unwrap(); assert_eq!(frame.payload, b"ladder".as_ref()); - // Lite-02 carries no timestamps, and a lite-06 subscriber drops them. - let timed = alpn == "moq-transport-18"; + // Lite-02 carries no timestamps. + let timed = alpn != "moq-lite-02"; assert_eq!(frame.timestamp, timed.then_some(timestamp), "{alpn} relayed={relayed}"); } } diff --git a/rs/moq-relay/tests/integration/connection.rs b/rs/moq-relay/tests/integration/connection.rs index 0e9e537e165..24ce729866a 100644 --- a/rs/moq-relay/tests/integration/connection.rs +++ b/rs/moq-relay/tests/integration/connection.rs @@ -60,8 +60,8 @@ async fn largest_quic_sequence_reaches_the_subscriber() { assert_eq!(got.sequence, sequence, "{alpn}"); let frame = got.read_frame().await.unwrap().unwrap(); assert_eq!(frame.payload, b"ladder".as_ref()); - // Lite-02 carries no timestamps, and a lite-06 subscriber drops them. - let timed = alpn == "moq-transport-22"; + // Lite-02 carries no timestamps. + let timed = alpn != "moq-lite-02"; assert_eq!(frame.timestamp, timed.then_some(timestamp), "{alpn}"); } } diff --git a/rs/moq-tokio/tests/integration/broadcast.rs b/rs/moq-tokio/tests/integration/broadcast.rs index d6cbe68f8ef..574a39addee 100644 --- a/rs/moq-tokio/tests/integration/broadcast.rs +++ b/rs/moq-tokio/tests/integration/broadcast.rs @@ -135,9 +135,7 @@ async fn broadcast_test(scheme: &str, client_version: Option<&str>, server_versi } /// Lite05 publisher↔subscriber round-trip exercising the per-frame timestamp -/// delta encoding, including negative deltas (B-frame ordering). The subscriber decodes -/// each delta to stay in step with the payloads, then drops it, since a lite-05 timestamp -/// may be a send time. +/// delta encoding, including negative deltas (B-frame ordering). async fn lite05_timestamp_roundtrip(scheme: &str) { use moq_tokio::moq_net::{Timescale, Timestamp}; @@ -231,7 +229,10 @@ async fn lite05_timestamp_roundtrip(scheme: &str) { .expect("next_frame failed") .expect("group closed prematurely"); - assert_eq!(frame_sub.timestamp, None, "a lite-05 subscriber drops timestamps"); + let ts = frame_sub.timestamp.expect("timed frame"); + assert_eq!(ts.scale(), Timescale::MICRO); + assert_eq!(ts.value(), expected_us); + let payload = frame_sub.read_all().await.expect("failed to read frame"); assert_eq!(payload, bytes::Bytes::from(format!("frame@{expected_us}"))); } @@ -251,7 +252,7 @@ async fn broadcast_moq_lite_05_timestamps_webtransport() { /// Lite05 FETCH round-trip: retrieve a past group by sequence without holding a /// subscription, exercising the bare-FRAME fetch response and per-frame timestamp -/// decoding on the fetch stream, whose timestamps the subscriber then drops. The track is also `compress`-hinted, so the +/// decoding on the fetch stream. The track is also `compress`-hinted, so the /// fetched frames are Deflate-compressed (matching TRACK_INFO) and inflated by the /// subscriber, exercising fetch/TRACK_INFO codec consistency. async fn lite05_fetch_roundtrip(scheme: &str) { @@ -340,7 +341,9 @@ async fn lite05_fetch_roundtrip(scheme: &str) { .expect("next_frame failed") .expect("group closed prematurely"); - assert_eq!(frame_sub.timestamp, None, "a lite-05 subscriber drops timestamps"); + let ts = frame_sub.timestamp.expect("timed frame"); + assert_eq!(ts.scale(), Timescale::MICRO); + assert_eq!(ts.value(), expected_us); let payload = frame_sub.read_all().await.expect("failed to read frame"); assert_eq!(payload, bytes::Bytes::from(format!("frame@{expected_us}"))); @@ -609,11 +612,13 @@ async fn broadcast_moq_lite_05_fetch_during_subscribe_webtransport() { } /// Lite05 can't declare an untimed track, so a track that sets no timescale goes out -/// in milliseconds, its frames stamped with their send time. The subscriber drops them, -/// so the track arrives untimed. +/// in milliseconds, its frames stamped with their send time. The subscriber receives +/// `Some(ts)` at that scale. #[tracing_test::traced_test] #[tokio::test] async fn broadcast_moq_lite_05_untimed_track() { + use moq_tokio::moq_net::Timescale; + let pub_origin = moq_tokio::origin::spawn(); let broadcast = pub_origin.create_broadcast("test").expect("create broadcast"); broadcast.announce(Default::default()).expect("create broadcast"); @@ -685,8 +690,13 @@ async fn broadcast_moq_lite_05_untimed_track() { .expect("next_frame failed") .expect("group closed"); - assert_eq!(frame_sub.timestamp, None, "the send time is dropped"); - assert_eq!(track_sub.info().timescale, None, "the track arrives untimed"); + let ts = frame_sub.timestamp.expect("timed frame"); + assert_eq!( + ts.scale(), + Timescale::MILLI, + "an untimed track's send times are milliseconds" + ); + assert_eq!(track_sub.info().timescale, Some(Timescale::MILLI)); drop(connection); server_handle diff --git a/test/wasm/baseline/consumer.ts b/test/wasm/baseline/consumer.ts index 1b30a668051..458a256eb62 100644 --- a/test/wasm/baseline/consumer.ts +++ b/test/wasm/baseline/consumer.ts @@ -36,8 +36,8 @@ async function run(config: Sample) { let grew = false; let received = 0; const frames = config.publishers * config.subscribers * config.frames; - // Lite-02 carries no timestamps, and a lite-05/06 subscriber drops them. - const timed = !/^moq-lite-0[1-6]$/.test(config.version); + // Lite-01 to lite-04 carry no timestamps. + const timed = !/^moq-lite-0[1-4]$/.test(config.version); const check = (bytes: Uint8Array, frame: number) => { first ??= performance.now() - start; verify(bytes, config.size, frame); diff --git a/test/wasm/generator.md b/test/wasm/generator.md index 18b236417b2..e53fe6eb74e 100644 --- a/test/wasm/generator.md +++ b/test/wasm/generator.md @@ -179,7 +179,7 @@ three bindings. moq-wasm's column is the existing suite in [`src/main.ts`](src/m | reads a published broadcast, every byte, 128 KiB frames | yes | yes | yes | | refuses a missing track | yes | yes: rejects with `NotFound` (transport-19) or `Protocol` (lite) | yes: rejects with the slice's `Net { reason: "not found" }` | | publishes | no: consume only | yes | yes | -| frame timestamps | no: payload only | yes, exact, as `bigint` microseconds on a version that delivers them (not lite-02 or lite-06) | yes | +| frame timestamps | no: payload only | yes, exact, as `bigint` microseconds on a version that carries them (not lite-02) | yes | | u64 sequence above 2^53, end to end | not testable: no publisher can send it | yes, 2^53+1 on all three; 2^62-1 on lite-02 and transport-19 (see bugs) | same as moq-ffi | | cancellation through `AbortSignal` | no: `free()` rejects pending calls | rejects with `AbortError`; the next call still gets the next frame | UniFFI: `AbortError`; BoltFFI: `BoltFFICancelledError`; neither steals the next frame | | aborting releases the call's state | n/a | yes: a track's demand drops only once the aborted future is freed | not testable: the slice has no demand | diff --git a/test/wasm/uniffi/cases.ts b/test/wasm/uniffi/cases.ts index fb08d31051b..d44da5117e4 100644 --- a/test/wasm/uniffi/cases.ts +++ b/test/wasm/uniffi/cases.ts @@ -350,8 +350,8 @@ const remote: Record Promise> = { | undefined; if (got?.sequence() !== sequence) throw new Error(`sequence ${got?.sequence()} != ${sequence}`); const frame = await got.readFrame(); - // Lite-02 carries no timestamp and a lite-05/06 subscriber drops it; the rest keep it exact. - const expected = /^moq-lite-0[1-6]$/.test(relay.version) ? undefined : stamp(sequence); + // Lite-01 to lite-04 carry no timestamp; the rest keep it exact. + const expected = /^moq-lite-0[1-4]$/.test(relay.version) ? undefined : stamp(sequence); if (frame?.timestampUs !== expected) throw new Error(`timestamp ${frame?.timestampUs} != ${expected}`); seen.push(String(sequence)); } From ff7113275541333726b460f3f4d0da39a871cba9 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 27 Oct 2026 19:16:26 -0700 Subject: [PATCH 3/9] style: just fix --- rs/moq-net/src/lite/ietf.rs | 7 +------ rs/moq-net/src/lite/publisher.rs | 6 +++++- rs/moq-net/tests/integration/received_rewind.rs | 5 +---- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/rs/moq-net/src/lite/ietf.rs b/rs/moq-net/src/lite/ietf.rs index e5492601260..3a76e58b324 100644 --- a/rs/moq-net/src/lite/ietf.rs +++ b/rs/moq-net/src/lite/ietf.rs @@ -1175,12 +1175,7 @@ mod hop_tests { let info = moq_clock::timeout(TIMEOUT, copy.info()).await.unwrap().unwrap(); assert_eq!( (info.max_age, info.timescale, info.priority, info.refresh), - ( - Some(Duration::from_secs(7)), - Some(Timescale::MILLI), - 9, - Some(0) - ), + (Some(Duration::from_secs(7)), Some(Timescale::MILLI), 9, Some(0)), "{offer:?}" ); match negotiated { diff --git a/rs/moq-net/src/lite/publisher.rs b/rs/moq-net/src/lite/publisher.rs index 3f34e3e520a..4dfa3138f67 100644 --- a/rs/moq-net/src/lite/publisher.rs +++ b/rs/moq-net/src/lite/publisher.rs @@ -5022,7 +5022,11 @@ mod serve_group_test { for version in [Version::Lite06, Version::Lite07] { let stamp = Stamp::new(version, Some(crate::Timescale::MILLI)).unwrap(); - assert_eq!(stamp.wire(Some(stamped), &runtime).unwrap(), stamped.value(), "{version}"); + assert_eq!( + stamp.wire(Some(stamped), &runtime).unwrap(), + stamped.value(), + "{version}" + ); } let stamp = Stamp::new(Version::Lite06, None).unwrap(); assert_eq!(stamp.wire(None, &runtime).unwrap(), sent); diff --git a/rs/moq-net/tests/integration/received_rewind.rs b/rs/moq-net/tests/integration/received_rewind.rs index 27ea70d3f8f..8400f7baa51 100644 --- a/rs/moq-net/tests/integration/received_rewind.rs +++ b/rs/moq-net/tests/integration/received_rewind.rs @@ -37,10 +37,7 @@ fn produce_origin(hop: u64) -> moq_net::origin::Producer { fn write_group(track: &moq_net::track::Producer, sequence: u64) { // A timed track's group starts at its sequence in seconds, so none rewinds. - let timestamp = track - .info() - .timescale - .map(|_| millis(sequence * 1000)); + let timestamp = track.info().timescale.map(|_| millis(sequence * 1000)); let mut group = track.create_group(moq_net::group::Info { sequence }).unwrap(); group.write_frame(timestamp, &b"x"[..]).unwrap(); group.finish().unwrap(); From b8b7b3590bee6ed09438ef15e33b2b1783030cd1 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 27 Oct 2026 19:56:46 -0700 Subject: [PATCH 4/9] test(interop): a lite-06 health frame may carry its send time; finish the quest --- quest/m1/README.md | 1 - quest/m1/lite-timestamps-through.md | 41 ------------------------ quest/m1/time-addressing/model.md | 1 - test/interop/clients/c/subscribe.c | 3 +- test/interop/clients/js-native/finish.ts | 7 ++-- 5 files changed, 4 insertions(+), 49 deletions(-) delete mode 100644 quest/m1/lite-timestamps-through.md diff --git a/quest/m1/README.md b/quest/m1/README.md index 9ef86731938..b4f8252c93a 100644 --- a/quest/m1/README.md +++ b/quest/m1/README.md @@ -120,7 +120,6 @@ surface and zero-copy texture import, land before the cut. - [Cluster routing](/quest/m1/cluster-routing/README.md) - prove shared routing contracts, implement per-origin routes, and connect outbound local clusters - [Routing guide](/quest/m1/routing-guide.md) - concepts and practical outbound federation setup - [moq-c at parity](/quest/m1/c/README.md) - the hand-written `moq-c` ships at the cut with every m1 binding feature moq-ffi gains -- [Lite-05/06 timestamps pass through](/quest/m1/lite-timestamps-through.md) - a timed track received over lite-05/06 stays timed and is forwarded with its timestamps over every version - [Exact timestamps in every binding](/quest/m1/binding-timestamps.md) - bindings carry `{value, scale}` timestamps instead of lossy microseconds - [Announcement takeover](/quest/m1/announce-takeover.md) - a new independent route explicitly continues instances served through its predecessor, with shared Rust/JS semantics and lite-07 wire - [Subscribe ranges](/quest/m1/subscribe-ranges/README.md) - a lite-07 SUBSCRIBE asks for past and live ranges with absolute or relative ends, in either order, and replaces FETCH; merged ranges never starve a subscriber; relays fill misses by range, including over moq-transport diff --git a/quest/m1/lite-timestamps-through.md b/quest/m1/lite-timestamps-through.md deleted file mode 100644 index a2cfbb5e52c..00000000000 --- a/quest/m1/lite-timestamps-through.md +++ /dev/null @@ -1,41 +0,0 @@ -# [M] Lite-05/06 timestamps pass through - -## Goal - -A timed track received over moq-lite-05/06 keeps its frame and datagram -timestamps, and a relay forwards them over every version, so a lite-06 -reader of a timed feed (such as a stats feed) sees timed frames instead of -untimed ones. Partly reverses -[moq-dev/moq#6150](https://github.com/moq-dev/moq/pull/6150), which drops -every lite-05/06 timestamp a receiver reads. - -## Plan - -Decided 2026-10-25 (maintainer): "We dropped lite timestamps because they -defaulted to wall clock timestamps, but we should pass them through instead." - -- A track received over lite-05/06 is timed and marked crate-private - `unchecked`, like a moq-transport one: its groups skip the - [moq-dev/moq#5803](https://github.com/moq-dev/moq/pull/5803) rewind check - on ingress, because an untimed origin stamps send times at serve time and - an older group fetched later would look like a rewind. -- Unchecked tracks, lite-05/06 and moq-transport alike, go out with their own - timestamps over every version: lite-05/06, lite-07, and moq-transport. A - moq-transport track served to a lite-05/06 peer stops being stamped with - send times. -- A lite-07 receiver keeps checking every received group (no wire flag), so a - send-time origin's out-of-order group may be refused downstream; rewinds - are unsupported, and the cost was accepted. -- A lite-05/06 sender serving an untimed track keeps the published rule: - timescale 1000 and each payload's send time in milliseconds. Receivers now - pass that through as the track's time. - -Update the draft's lite-05/06 receiver text and changelog, -`doc/concept/moq-lite.md`, and the PR's Impact migration note, in Rust -and `@moq/net` alike. The cut's migration audit reconciles the existing #6150 -notes with that Impact section. Test a lite-06 hop between two relays: a timed track -arrives timed with its values, and an out-of-order fetched group from an -untimed origin is accepted on lite-05/06. - -Public API: none (crate-private `unchecked`). Wire: none for lite-05/06; -receiver behavior changes, and the lite draft text says so. diff --git a/quest/m1/time-addressing/model.md b/quest/m1/time-addressing/model.md index e8d0bd401d2..4754e1c3b24 100644 --- a/quest/m1/time-addressing/model.md +++ b/quest/m1/time-addressing/model.md @@ -119,7 +119,6 @@ Wire: no format change; legacy and lite-07-wip group IDs become start ticks. - [Fetch as a range](/quest/m1/subscribe-ranges/fetch-range.md) - the one-range reads this rework moves onto times - [Lite-07 ranges](/quest/m1/subscribe-ranges/lite.md) - the range ends and drops this rework moves onto times - [Delete the old start bookkeeping](/quest/m1/subscribe-ranges/start-bookkeeping.md) - the lite cursor state lives in the model before the cut rekeys it -- [Lite-05/06 timestamps pass through](/quest/m1/lite-timestamps-through.md) - lite-05/06 tracks stay timed, so their ingest keeps real starts - [Drop set](/quest/m1/drop-set.md) - its dropped and expired runs convert mechanically from sequences to starts ## Related diff --git a/test/interop/clients/c/subscribe.c b/test/interop/clients/c/subscribe.c index 0353ce0ddaf..8938605bbb1 100644 --- a/test/interop/clients/c/subscribe.c +++ b/test/interop/clients/c/subscribe.c @@ -376,9 +376,10 @@ static void on_finish_health_frame(void *ud, int32_t frame) { int32_t read = moq_consume_track_frame((uint32_t)frame, &info); const char payload[] = "session-alive"; pthread_mutex_lock(&c->mu); + // Its timestamp goes unchecked: lite-05/06 carry an untimed track's send time. if (read < 0 || info.payload_size != sizeof(payload) - 1 || memcmp(info.payload, payload, sizeof(payload) - 1) != 0 || - info.timestamp_present || ++c->finish.health_frames != 1) c->finish.failed = 1; + ++c->finish.health_frames != 1) c->finish.failed = 1; pthread_cond_broadcast(&c->cv); pthread_mutex_unlock(&c->mu); moq_consume_track_frame_free((uint32_t)frame); diff --git a/test/interop/clients/js-native/finish.ts b/test/interop/clients/js-native/finish.ts index 9410e834946..4429531584b 100644 --- a/test/interop/clients/js-native/finish.ts +++ b/test/interop/clients/js-native/finish.ts @@ -69,11 +69,8 @@ export async function readFinish( if (!group) throw new Error("no health group"); try { const frame = await group.readFrame(); - if ( - !frame || - new TextDecoder().decode(frame.payload) !== "session-alive" || - frame.timestamp !== undefined - ) + // Its timestamp goes unchecked: lite-05/06 carry an untimed track's send time. + if (!frame || new TextDecoder().decode(frame.payload) !== "session-alive") throw new Error("health frame"); if ((await group.readFrame()) !== undefined || (await track.recvGroup()) !== undefined) throw new Error("health EOF"); From 731d9a63770adbf7f1fefc93f62404f0ae9668b9 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 27 Oct 2026 20:37:04 -0700 Subject: [PATCH 5/9] test(interop): a relayed health frame may carry a lite-06 send time --- test/interop/clients/cpp/main.cpp | 5 +++-- test/interop/clients/go/main.go | 5 +++-- test/interop/clients/python/interop.py | 5 +++-- test/interop/clients/rust/finish.rs | 6 ++---- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/test/interop/clients/cpp/main.cpp b/test/interop/clients/cpp/main.cpp index 1a7f5b50f78..b167ef43f74 100644 --- a/test/interop/clients/cpp/main.cpp +++ b/test/interop/clients/cpp/main.cpp @@ -405,8 +405,9 @@ int subscribe( auto group = until(track->next_group(), read_deadline, "health group"); if (!group) fail("missing health group"); auto frame = until(group->read_frame(), read_deadline, "health frame"); - if (!frame || std::string(frame->payload.begin(), frame->payload.end()) != "session-alive" || frame->timestamp_us) { - fail("health payload or timestamp"); + // Its timestamp goes unchecked: lite-05/06 carry an untimed track's send time. + if (!frame || std::string(frame->payload.begin(), frame->payload.end()) != "session-alive") { + fail("health payload"); } if (until(group->read_frame(), read_deadline, "health group EOF") || until(track->next_group(), read_deadline, "health track EOF") || session->state().connects != 1) { diff --git a/test/interop/clients/go/main.go b/test/interop/clients/go/main.go index 196b3f2bdd1..25b5d778847 100644 --- a/test/interop/clients/go/main.go +++ b/test/interop/clients/go/main.go @@ -427,8 +427,9 @@ func finishSubscribe(ctx context.Context, client *moq.Client, broadcast string, if err != nil { return err } - if frame == nil || string(frame.Payload) != "session-alive" || frame.Timestamp != nil { - return errors.New("unexpected session health payload or timestamp") + // Its timestamp goes unchecked: lite-05/06 carry an untimed track's send time. + if frame == nil || string(frame.Payload) != "session-alive" { + return errors.New("unexpected session health payload") } frame, err = group.ReadFrame(ctx) if err != nil { diff --git a/test/interop/clients/python/interop.py b/test/interop/clients/python/interop.py index 23a071c9815..3776f5bbeba 100644 --- a/test/interop/clients/python/interop.py +++ b/test/interop/clients/python/interop.py @@ -230,8 +230,9 @@ async def _finish_subscribe(client: moq.Client, broadcast: str, frames: int) -> async for group in live: async with group: async for frame in group: - if seen or frame.payload != b"session-alive" or frame.timestamp is not None: - raise RuntimeError("unexpected session health payload or timestamp") + # Its timestamp goes unchecked: lite-05/06 carry an untimed track's send time. + if seen or frame.payload != b"session-alive": + raise RuntimeError("unexpected session health payload") seen = True if not seen: raise RuntimeError("missing session health payload") diff --git a/test/interop/clients/rust/finish.rs b/test/interop/clients/rust/finish.rs index 6e6deb4712d..741ca2b2c54 100644 --- a/test/interop/clients/rust/finish.rs +++ b/test/interop/clients/rust/finish.rs @@ -166,10 +166,8 @@ async fn main() -> anyhow::Result<()> { let mut track = health.track("live")?.subscribe(None).await?; let mut group = track.recv_group().await?.context("no health group")?; let frame = group.read_frame().await?.context("no health frame")?; - ensure!( - frame.payload.as_ref() == b"session-alive" && frame.timestamp.is_none(), - "health payload or timestamp" - ); + // Its timestamp goes unchecked: lite-05/06 carry an untimed track's send time. + ensure!(frame.payload.as_ref() == b"session-alive", "health payload"); ensure!( group.read_frame().await?.is_none() && track.recv_group().await?.is_none(), "health EOF" From c7db73b9b81d9d7dccc47217dbffb22634f3d885 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 31 Oct 2026 15:01:31 -0700 Subject: [PATCH 6/9] test(net): fuzz lite-05/06 ingest as timed, now that their timestamps pass through Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/fuzz/ingest.rs | 7 ++++--- rs/moq-net/src/lite/track.rs | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/rs/moq-net/src/fuzz/ingest.rs b/rs/moq-net/src/fuzz/ingest.rs index f44e7a4aabd..6ce9547b480 100644 --- a/rs/moq-net/src/fuzz/ingest.rs +++ b/rs/moq-net/src/fuzz/ingest.rs @@ -87,8 +87,9 @@ pub fn ingest(data: &[u8]) -> bool { let (session, info, body) = match selector % 2 { 0 => { let version = super::LITE_VERSIONS[(*selector as usize / 2) % super::LITE_VERSIONS.len()]; - // Lite05/06 timestamps may be send times, so their tracks arrive untimed. - let timed = timed && version.has_media_time(); + // The track arrives timed exactly when the wire stamps it: never before Lite05, + // always on Lite05/06 (an untimed one carries its send times), as declared after. + let timed = version.wire_timescale(timed.then_some(Timescale::MILLI)).is_some(); let session = Session::Lite { version, records: settings & 0x10 != 0 && version.has_ietf(), @@ -220,7 +221,7 @@ fn run(session: Session, info: &track::Info, body: &[u8], chunk: usize) -> Optio let consumer = producer.consume(); let mut group = crate::recv::Group::new(producer); let framing = lite::Framing::new(info, version); - let mut ingest = lite::FrameIngest::new(framing, version, records, frame_start); + let mut ingest = lite::FrameIngest::new(framing, records, frame_start); let end = drive(body.len(), |waiter| ingest.poll(&mut reader, &mut group, waiter)); (end.map(|()| "fin".to_string()), (group, consumer)) } diff --git a/rs/moq-net/src/lite/track.rs b/rs/moq-net/src/lite/track.rs index def03c974b3..cc493363af4 100644 --- a/rs/moq-net/src/lite/track.rs +++ b/rs/moq-net/src/lite/track.rs @@ -132,8 +132,8 @@ pub(crate) struct Framing { } impl Framing { - /// How `version` frames a track accepted as `info`. Lite05/06 stamp every frame, so a - /// track received untimed there still has timestamps to read past. + /// How `version` frames a track accepted as `info`. Lite05/06 stamp every frame, an + /// untimed track's with its send time in milliseconds. pub fn new(info: &crate::track::Info, version: Version) -> Self { Self { timescale: version.wire_timescale(info.timescale), From 24ffd7f064d5e4154f0512692afa09305b7827c0 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 31 Oct 2026 15:02:02 -0700 Subject: [PATCH 7/9] docs(net): migration notes say lite-05/06 timestamps pass through Co-Authored-By: Claude Opus 5.5 --- js/net/MIGRATE.md | 4 ++-- rs/moq-net/MIGRATE.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/js/net/MIGRATE.md b/js/net/MIGRATE.md index 5f5894f0bc0..9f3f7e9901b 100644 --- a/js/net/MIGRATE.md +++ b/js/net/MIGRATE.md @@ -152,8 +152,8 @@ A new group or datagram raises it at frame 0 before any frame lands, and it can A local write whose first frame starts before a lower-sequence group's, or after a higher one's, throws `TimestampMismatch`. A group received over moq-lite-07 is checked the same way. -A track received over moq-lite-05/06 arrives untimed, since its timestamps may be send times: read times from the payload, such as the hang container's, instead of the frame's `timestamp`. -One received over moq-transport keeps its timestamps unchecked, and a relay serves it to moq-lite untimed. +A track received over moq-lite-05/06 keeps its timestamps unchecked, since they may be an untimed origin's send times, and so does one received over moq-transport. +A relay serves both on over every version, where a moq-lite-07 receiver checks them and may refuse a group that rewinds. A publisher whose timeline restarts publishes a new broadcast instead. ### `Auth.Auth` is `Auth.Handle`, and `Auth.Token` is `Auth.Auth` (#5695) diff --git a/rs/moq-net/MIGRATE.md b/rs/moq-net/MIGRATE.md index eede46d4122..b1d9c4efbc3 100644 --- a/rs/moq-net/MIGRATE.md +++ b/rs/moq-net/MIGRATE.md @@ -368,8 +368,8 @@ let rate = bandwidth.as_ref().and_then(|b| b.peek()); A local write whose first frame starts before a lower-sequence group's, or after a higher one's, fails with `TimestampMismatch`; `@moq/net` throws it the same way. A group received over moq-lite-07 is checked the same way. -A track received over moq-lite-05/06 arrives untimed, since its timestamps may be send times: read times from the payload, such as the hang container's, instead of `frame::Frame::timestamp`. -One received over moq-transport keeps its timestamps unchecked, and a relay serves it to moq-lite untimed. +A track received over moq-lite-05/06 keeps its timestamps unchecked, since they may be an untimed origin's send times, and so does one received over moq-transport. +A relay serves both on over every version, where a moq-lite-07 receiver checks them and may refuse a group that rewinds. A publisher whose timeline restarts, such as an HLS `EXT-X-DISCONTINUITY` that resets decode times, publishes a new broadcast instead. ### Broadcast `finish` is gone From ef4f23037b5538108ded700e76d9e12cadb971c3 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 31 Oct 2026 15:21:25 -0700 Subject: [PATCH 8/9] test(net): a lite-06 copy keeps media time, so a narrow reader skips a re-offer Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/tests/integration/widened_max_age.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/rs/moq-net/tests/integration/widened_max_age.rs b/rs/moq-net/tests/integration/widened_max_age.rs index b2df58aaa21..a4562fc55d1 100644 --- a/rs/moq-net/tests/integration/widened_max_age.rs +++ b/rs/moq-net/tests/integration/widened_max_age.rs @@ -4,8 +4,8 @@ //! relay would: the widened SUBSCRIBE_UPDATE has the publisher re-offer the cached groups //! it skipped as stale, below where the copy started. //! -//! Lite-06 relies on that re-offer alone: its copy is untimed and its FETCH carries no max -//! age, so a reader asks no fills below the start the publisher resolved from the budget. +//! Lite-06 relies on that re-offer alone: its FETCH carries no max age, so a reader asks no +//! fills below the start the publisher resolved from the budget. use std::collections::BTreeSet; use std::time::Duration; @@ -186,14 +186,10 @@ async fn a_warm_relay_serves_a_wider_newcomer_what_a_cold_one_would() { let mut wide = moq_clock::timeout(TIMEOUT, warm.subscribe(WIDE)).await.unwrap(); let got = moq_clock::timeout(TIMEOUT, received(&mut wide)).await.unwrap(); assert_eq!(got, want, "{version}: warm"); - // A lite-06 copy has no media time to find the re-offer stale by, and each group in - // it arrives just now, so the narrow reader takes it too, once per widening. + // The copy keeps the publisher's media time, lite-06's included, so the narrow + // reader finds the re-offered groups stale and takes none of them. let late = moq_clock::timeout(TIMEOUT, received(&mut narrow)).await.unwrap(); - let reoffered = match version { - "moq-lite-06" => (2..6).collect(), - _ => BTreeSet::new(), - }; - assert_eq!(late, reoffered, "{version}: what the narrow reader takes late"); + assert_eq!(late, BTreeSet::new(), "{version}: what the narrow reader takes late"); } } From a2a70978f5bc0ac61d6f4a8076326a955b1824af Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 31 Oct 2026 16:00:42 -0700 Subject: [PATCH 9/9] fix(net): keep moq-transport provenance in JS resume compatibility The rename of track.Info.ietf to unchecked dropped the draft version from the resume comparison, so JS would splice a moq-transport copy beside a native one, or another draft's, where Rust's properties equality refuses it. Restore ietf as compared provenance and keep unchecked for lite-05/06 copies only, as in Rust. Co-Authored-By: Claude Opus 5.5 --- js/net/src/ietf/subscriber.ts | 2 +- js/net/src/resume.test.ts | 41 ++++++++++++++++++++++++++++------- js/net/src/resume.ts | 3 ++- js/net/src/track.test.ts | 38 ++++++++++++++++++-------------- js/net/src/track.ts | 14 ++++++++---- 5 files changed, 68 insertions(+), 30 deletions(-) diff --git a/js/net/src/ietf/subscriber.ts b/js/net/src/ietf/subscriber.ts index 9b0bffe8b50..11fd75c881f 100644 --- a/js/net/src/ietf/subscriber.ts +++ b/js/net/src/ietf/subscriber.ts @@ -1315,7 +1315,7 @@ export class Subscriber { priority: fromWire(ok.properties.priority ?? DEFAULT_WIRE), maxAge: maxCacheDuration === undefined ? undefined : Milli(Number(maxCacheDuration)), // A moq-transport peer may stamp arrival times, and nothing on the wire says it didn't. - unchecked: true, + ietf: version, }); const producer = staged.producer; const tail = new Tail(); diff --git a/js/net/src/resume.test.ts b/js/net/src/resume.test.ts index 0ed7fd77e2f..96f4b925599 100644 --- a/js/net/src/resume.test.ts +++ b/js/net/src/resume.test.ts @@ -7,6 +7,7 @@ import { type Consumer as GroupConsumer, Producer as GroupProducer } from "./gro import { Route } from "./hop.ts"; import type { Session as IetfSession } from "./ietf/session.ts"; import { Subscriber as IetfSubscriber } from "./ietf/subscriber.ts"; +import { Version as IetfVersion } from "./ietf/version.ts"; import { hooks, MAX_DATAGRAMS } from "./internal.ts"; import type { Lister } from "./listing.ts"; import { Producer } from "./origin.ts"; @@ -561,19 +562,43 @@ test("a group no route continues is given up once a newer one supersedes it", as close(); }); -test("a replacement claiming different track properties is refused once the old copy runs out", async () => { +// Moq-transport provenance is content, like Rust's `properties`: a copy over another draft differs. +for (const [name, before, after] of [ + ["track properties", { priority: 1 }, { priority: 2 }], + ["moq-transport provenance", { ietf: IetfVersion.DRAFT_22 }, {}], +] as const) { + test(`a replacement claiming different ${name} is refused once the old copy runs out`, async () => { + const { a, b, swap, active, close } = await setup(); + const old = a.createTrack("seq", before); + b.createTrack("seq", after); + const sub = active.track("seq").subscribe(); + expect(await sub.info()).toMatchObject(before); + await swap(); + expect(sub.closed.peek()).toBeUndefined(); + + // The old copy failing with its route is what ends the track. + old.abort(new StreamError(StreamCode.SessionClosed)); + await settle(); + expect(() => sub.tryRecvGroup()).toThrow("changed its properties"); + + sub.close(); + close(); + }); +} + +// `unchecked` records how a copy arrived (lite-05/06), so it splices beside a lite-07 copy. +test("a replacement differing only in unchecked takes over", async () => { const { a, b, swap, active, close } = await setup(); - const old = a.createTrack("seq", { priority: 1 }); - b.createTrack("seq", { priority: 2 }); + const old = a.createTrack("seq", { unchecked: true }); + const tb = copy(b); const sub = active.track("seq").subscribe(); - expect((await sub.info()).priority).toBe(1); + await sub.info(); await swap(); - expect(sub.closed.peek()).toBeUndefined(); - - // The old copy failing with its route is what ends the track. + tb.write(0); old.abort(new StreamError(StreamCode.SessionClosed)); await settle(); - expect(() => sub.tryRecvGroup()).toThrow("changed its properties"); + expect(sub.closed.peek()).toBeUndefined(); + expect(drain(sub)).toEqual([0]); sub.close(); close(); diff --git a/js/net/src/resume.ts b/js/net/src/resume.ts index 8ce40808727..a55b12a9cf2 100644 --- a/js/net/src/resume.ts +++ b/js/net/src/resume.ts @@ -104,13 +104,14 @@ export function routeFailed(err: Error): boolean { // Every `track.Info` field but `unchecked`, so one added later fails to compile until it is // listed here. `unchecked` says how a copy arrived, not what it holds, so copies over different -// versions still match. +// lite versions still match. `ietf` is compared, like Rust's moq-transport `properties`. const INFO_FIELDS = Object.keys({ compress: true, timescale: true, maxAge: true, priority: true, refresh: true, + ietf: true, } satisfies Record, true>) as (keyof track.Info)[]; /** Two copies claiming the same content must agree on all of it, like Rust's `Info` equality. */ diff --git a/js/net/src/track.test.ts b/js/net/src/track.test.ts index 4297be97314..52f95478596 100644 --- a/js/net/src/track.test.ts +++ b/js/net/src/track.test.ts @@ -5,6 +5,7 @@ import { ProtocolViolation, StreamCode, StreamError, TimestampMismatch, TooFarBe import { Decoder } from "./flate/decoder.ts"; import { Encoder } from "./flate/encoder.ts"; import { type Consumer as GroupConsumer, type Producer as GroupProducer, MAX_GROUP_FRAMES } from "./group.ts"; +import { Version as IetfVersion } from "./ietf/version.ts"; import { hooks } from "./internal.ts"; import { textFrame } from "./mock.ts"; import { Timescale, Timestamp } from "./time.ts"; @@ -3407,22 +3408,27 @@ test("an endless track with gaps remembers only those within the budget", () => } }); -test("unchecked survives normalization on timed and untimed tracks", () => { - for (const timescale of [undefined, Timescale.MILLI]) { - const info = infoDefaults({ unchecked: true, timescale }); - expect(info.unchecked).toBe(true); - expect(info.timescale).toBe(timescale); - } - const producer = new TrackProducer("ietf").accept({ timescale: Timescale.MILLI, unchecked: true }); - try { - stampGroup(producer, 0, 1000); - stampGroup(producer, 1, 500); - producer.writeFrame({ payload: enc.encode("arrival"), timestamp: Timestamp.fromMillis(250) }); - } finally { - producer.finish(); - producer.close(); - } -}); +for (const [name, extra] of [ + ["unchecked", { unchecked: true }], + ["IETF provenance", { ietf: IetfVersion.DRAFT_22 }], +] as const) { + test(`${name} survives normalization and skips the rewind check`, () => { + for (const timescale of [undefined, Timescale.MILLI]) { + const info = infoDefaults({ ...extra, timescale }); + expect(info).toMatchObject(extra); + expect(info.timescale).toBe(timescale); + } + const producer = new TrackProducer("rewind").accept({ timescale: Timescale.MILLI, ...extra }); + try { + stampGroup(producer, 0, 1000); + stampGroup(producer, 1, 500); + producer.writeFrame({ payload: enc.encode("arrival"), timestamp: Timestamp.fromMillis(250) }); + } finally { + producer.finish(); + producer.close(); + } + }); +} test("an appended rewind is refused and an equal start is not", () => { const producer = new TrackProducer("test").accept({ timescale: Timescale.MILLI }); diff --git a/js/net/src/track.ts b/js/net/src/track.ts index 267d6ec2531..14076c384e0 100644 --- a/js/net/src/track.ts +++ b/js/net/src/track.ts @@ -19,6 +19,7 @@ import { } from "./error.ts"; import { datagramSlice, type Stored, sliceView } from "./flate/group.ts"; import { type Frame, type Consumer as GroupConsumer, Producer as GroupProducer } from "./group.ts"; +import type { IetfVersion } from "./ietf/version.ts"; import { type DropRun, dropAt, @@ -154,9 +155,12 @@ export interface Info { * one is pending. `0` asks on any join after a delta. An integer in `0..2^32`. */ refresh?: number; + /** The original moq-transport publisher's draft, whose timestamps may rewind. @internal */ + ietf?: IetfVersion; /** - * Whether this copy's groups skip the rewind check, since its timestamps may be moq-transport - * arrival times or lite-05/06 send times. Mirrors the Rust `track::Info::unchecked`. @internal + * Whether this copy's groups skip the rewind check, since its timestamps may be lite-05/06 send + * times. An {@link Info.ietf} track skips it too. Mirrors the Rust `track::Info::unchecked`. + * @internal */ unchecked?: boolean; } @@ -196,6 +200,7 @@ export function infoDefaults(info: Partial = {}): Info { maxAge: info.maxAge === undefined ? undefined : wireMillis("maxAge", info.maxAge), priority: priorityValue(info.priority ?? DEFAULT_PRIORITY), refresh: info.refresh == null ? undefined : refreshRatio(info.refresh), + ...(info.ietf === undefined ? {} : { ietf: info.ietf }), ...(info.unchecked ? { unchecked: true } : {}), }; } @@ -1476,9 +1481,10 @@ export class Producer { return group; } - // Whether this track's timestamps may rewind (see {@link Info.unchecked}). + // Whether this track's timestamps may rewind (see {@link Info.unchecked} and {@link Info.ietf}). #unchecked(): boolean { - return this.#state.info.peek()?.unchecked === true; + const info = this.#state.info.peek(); + return info?.unchecked === true || info?.ietf !== undefined; } // Fan a datagram out to every live subscriber, dropping the oldest once the ring is full.