Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion doc/concept/moq-lite.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ exchange on draft-17+ through the [MoQ Auth extension](/draft/moq-auth), limited
to namespace prefixes. Older versions have no grant; the URL token keeps working
everywhere. On moq-transport an added token is kept even without the extension,
so an announcement can name it: it rides that `PUBLISH_NAMESPACE` as its
authorization token. The token belongs to the session that added it, so after a
authorization token. Naming a fresh token renews the announcement in place with
`REQUEST_UPDATE` from draft 16, and re-announces it on drafts 14 and 15, so it
can outlive the token it started with. The token belongs to the session that added it, so after a
reconnect the application adds it again and re-announces. moq-lite has no
per-request token, so there an announcement rides the session's scope.

Expand Down
2 changes: 1 addition & 1 deletion doc/concept/standard.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ subset drops. What a peer actually observes against this implementation:
- **History is one group.** In Rust, Object ID gaps must be marked by Prior Object ID Gap properties for a group to be fetchable. A `FETCH` returns one group from the cache, or on drafts 14 through 19 the saved prefix of the group a new subscription just joined. A range of groups is refused, as is a draft 20+ `LOCATION_FILTER` that ends at Largest Object rather than an absolute End Location. On draft 20 and later, `FETCH_OK`'s End Location is the requested end, capped at Largest Object: a range holding no objects gets an empty fetch stream, and only a start past Largest Object is refused, with `INVALID_RANGE`. A relay's copy with no upstream subscription can't know Largest Object short of the track's end, so it echoes the requested end instead. JavaScript publishing refuses every `FETCH`. Datagrams are never fetchable. A Rust reader that only fetches learns the track from `TRACK_STATUS` instead of subscribing, so a finished track stays fetchable; draft 17 still subscribes, since its `TRACK_STATUS` answer cannot say whether the track is timed, and so does a reader whose publisher refuses `TRACK_STATUS` as `NOT_SUPPORTED`.
- **Timing.** A track whose `SUBSCRIBE_OK` declares no `TIMESCALE` is untimed, as is every track on drafts 14 through 16. A Rust reader that never subscribed takes the units from `TRACK_STATUS` on draft 18 and later.
- **Strict SETUP and parameters.** Repeated unknown `SETUP` options, GREASE included, are accepted if well-formed; a repeated known option is rejected. On draft 17 and later, a `GROUP_ORDER` other than Ascending (1) or Descending (2) closes the session. Message parameters follow the negotiated draft's lists: drafts 14 and 15 ignore an unknown or misplaced parameter, draft 16 ignores one defined only for another message but closes the session on an unknown one, and draft 17 and later close it on both. Other malformed control input closes the session with the draft's code too, such as a server `SETUP` carrying `PATH` or `AUTHORITY`, a request cut short by FIN, or a second `GOAWAY` on one stream; a first `GOAWAY` on a request stream is legal.
- **One `SETUP` credential**, forwarded to the [auth server](/bin/relay/auth#the-contract) unverified. A second `SETUP` token closes the session. We advertise no token cache, so an alias reference in `SETUP` closes it with `PROTOCOL_VIOLATION`, one on a request with `UNKNOWN_AUTH_TOKEN_ALIAS`, and a registration on a request with `AUTH_TOKEN_CACHE_OVERFLOW`. Where the Rust side authorizes the peer or verifies tokens, a token on a `SUBSCRIBE` or `PUBLISH_NAMESPACE` is verified like an in-band session token and authorizes that one request alone, even where that authorization already covers it; it never widens the session. It is refused with `NOT_SUPPORTED` when nothing verifies it, when it is empty, or when its Token Type is anything but 0 (out of band). A side that does neither, JavaScript included, ignores the token. Rust refuses a request carrying more than one distinct token with `NOT_SUPPORTED`, since it verifies one; JavaScript, which verifies none, ignores them all. A token-authorized `SUBSCRIBE` still stays within the grant the peer gave us. A token-authorized `PUBLISH_NAMESPACE` needs a grant covering everything beneath the namespace, and the tracks we subscribe under it rely on that announce instead of our limit, ending with it. An update renews the token, except on a drafts 14 and 15 `PUBLISH_NAMESPACE`, which has no update, and a refused renewal ends only that request. Rust and JavaScript send the token a route names (`Route::auth`) on its `PUBLISH_NAMESPACE`, including the one drafts 14 and 15 answer a solicited `SUBSCRIBE_NAMESPACE` with, and swapping it renews the request with `REQUEST_UPDATE` from draft 17, or ends and re-sends it before; the inline `NAMESPACE` that answers a solicited `SUBSCRIBE_NAMESPACE` from draft 16 carries no token. The token belongs to the session that added it, so a reconnect means adding it again and re-announcing. A token on any other request is decoded and grants nothing, and a request repeating one is refused with `MALFORMED_AUTH_TOKEN`. `SUBSCRIBE_TRACKS` reads its namespace before refusal; its token is not decoded. On draft 17 and later, the negotiated [MoQ Auth extension](/concept/moq-lite#authorization) accepts additional session tokens in band.
- **One `SETUP` credential**, forwarded to the [auth server](/bin/relay/auth#the-contract) unverified. A second `SETUP` token closes the session. We advertise no token cache, so an alias reference in `SETUP` closes it with `PROTOCOL_VIOLATION`, one on a request with `UNKNOWN_AUTH_TOKEN_ALIAS`, and a registration on a request with `AUTH_TOKEN_CACHE_OVERFLOW`. Where the Rust side authorizes the peer or verifies tokens, a token on a `SUBSCRIBE` or `PUBLISH_NAMESPACE` is verified like an in-band session token and authorizes that one request alone, even where that authorization already covers it; it never widens the session. It is refused with `NOT_SUPPORTED` when nothing verifies it, when it is empty, or when its Token Type is anything but 0 (out of band). A side that does neither, JavaScript included, ignores the token. Rust refuses a request carrying more than one distinct token with `NOT_SUPPORTED`, since it verifies one; JavaScript, which verifies none, ignores them all. A token-authorized `SUBSCRIBE` still stays within the grant the peer gave us. A token-authorized `PUBLISH_NAMESPACE` needs a grant covering everything beneath the namespace, and the tracks we subscribe under it rely on that announce instead of our limit, ending with it. An update renews the token, except on a drafts 14 and 15 `PUBLISH_NAMESPACE`, which has no update, and a refused renewal ends only that request. Rust and JavaScript send the token a route names (`Route::auth`) on its `PUBLISH_NAMESPACE`, including the one drafts 14 and 15 answer a solicited `SUBSCRIBE_NAMESPACE` with, and swapping it renews the request with `REQUEST_UPDATE` from draft 16, or ends and re-sends it before; the inline `NAMESPACE` that answers a solicited `SUBSCRIBE_NAMESPACE` from draft 16 carries no token. The token belongs to the session that added it, so a reconnect means adding it again and re-announcing. A token on any other request is decoded and grants nothing, and a request repeating one is refused with `MALFORMED_AUTH_TOKEN`. `SUBSCRIBE_TRACKS` reads its namespace before refusal; its token is not decoded. On draft 17 and later, the negotiated [MoQ Auth extension](/concept/moq-lite#authorization) accepts additional session tokens in band.
- **Refused, not fatal.** A legal request this stack does not serve is rejected on its own and the session stays up: `FORWARD=0`, `SUBSCRIBE_TRACKS`, and the fetch forms above get `NOT_SUPPORTED`. Range Filters get `INVALID_FILTER` on draft 19 and later because the advertised filter limit is zero. On draft 21 and later, namespaces whose first tuple field is exactly `.` or `.session` get `DOES_NOT_EXIST` before application lookup; other dot prefixes still reach the application. Subscription updates accept priority, negotiated subscriber max age, and delivery timeouts; Rust also renews request tokens and judges `NEW_GROUP_REQUEST` as a join (see dynamic groups below). Other supported-but-unimplemented preferences end that subscription; a `TRACK_PROPERTY_FILTER` there closes the session with `PROTOCOL_VIOLATION`, since it belongs only to `SUBSCRIBE_TRACKS`. On draft 18 and later a namespace update may change its prefix; suffixes after the acknowledgement are relative to that new prefix.
- **Objects and datagrams.** Only subgroup 0 is accepted: a stream for any other subgroup, whether its header gives the ID or takes it from the first Object ID, is stopped and the session stays up. Rust relays preserve Object IDs, gaps, object properties, FIRST\_OBJECT, and END\_OF\_GROUP status objects between moq-transport peers for subgroup 0. Datagrams retain their IDs, properties, priority, and status. Plain Rust readers and moq-lite peers see consecutive frames and normal datagram payloads; JavaScript supports only normal datagrams at Object ID 0. A malformed datagram closes the session; a relayed one the downstream draft cannot carry is dropped. A relayed Timestamp leaves in the units the downstream response declares, and is dropped where it declares none (drafts 14 through 16), as for a plain frame; an immutable one that would change or vanish is refused. Only property 0x10 is read as a Timestamp. Property 0x06 stays opaque and keeps its value regardless of timestamp units; it is dropped across the draft-19 boundary, or refused when immutable, because draft 19 assigns it to SUBGROUP\_DELIVERY\_TIMEOUT. From draft 15, a status object carrying properties is refused, and one relayed from draft 14 leaves without them. Draft 14 allows them, but an END\_OF\_TRACK carrying properties ends the subscription as unsupported, since a track end has nowhere to keep them. A `FETCH` carries the END\_OF\_GROUP object on drafts 14 and 15; later drafts have no FETCH status, so their response ends at the last frame. A group cannot resume across route changes by frame ordinal once Object IDs skip ahead of the ordinals on either route; recovery refuses it instead of splicing different objects.
- **Dynamic groups.** A track advertises `DYNAMIC_GROUPS` when its publisher sets a refresh ratio, and a track received with `DYNAMIC_GROUPS` gets a ratio of 0. A `NEW_GROUP_REQUEST` (draft 15 and later) counts as one more subscriber joining, which a `SUBSCRIBE` already is: it asks for a new group only when the newest group's bytes after its first frame exceed the ratio times the first frame. Joins coalesce until the asked-for group arrives. A Rust relay sends `NEW_GROUP_REQUEST` upstream, on the `SUBSCRIBE` or in a `REQUEST_UPDATE`, once a join wants a group past the newest it holds; a relay holding nothing yet asks for none. On a track without a ratio, an update carrying one ends the subscription with `UPDATE_FAILED`. On drafts 15 and 16, whose `TRACK_STATUS` answer has no room for it, a relay copy first learned from `TRACK_STATUS` (a fetch-only reader) does not advertise it to later subscribers. moq-lite hops do not carry requests yet.
Expand Down
2 changes: 1 addition & 1 deletion js/net/src/hop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export interface Route {
* token on its moq-transport PUBLISH_NAMESPACE: any other session, the inline NAMESPACE
* answering a solicited SUBSCRIBE_NAMESPACE from draft 16 on (drafts 14 and 15 answer
* with a PUBLISH_NAMESPACE, which carries it), and moq-lite advertise the route unnamed.
* Swapping it renews the request with REQUEST_UPDATE from draft 17, or ends and makes it
* Swapping it renews the request with REQUEST_UPDATE from draft 16, or ends and makes it
* again before. Local: a relay never forwards it. Mirrors `Route::auth` in rs/moq-net.
*/
auth?: Auth;
Expand Down
79 changes: 77 additions & 2 deletions js/net/src/ietf/adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ import { Stream } from "../stream.ts";
import { ControlStreamAdapter } from "./adapter.ts";
import { toRequestCode } from "./error.ts";
import { GoAway } from "./goaway.ts";
import { PublishNamespace, PublishNamespaceCancel, PublishNamespaceDone } from "./publish_namespace.ts";
import { initialMaxRequestId, MaxRequestId, REQUEST_WINDOW, RequestError } from "./request.ts";
import {
PublishNamespace,
PublishNamespaceCancel,
PublishNamespaceDone,
PublishNamespaceUpdate,
} from "./publish_namespace.ts";
import { initialMaxRequestId, MaxRequestId, REQUEST_WINDOW, RequestError, RequestOk } from "./request.ts";
import { Subscribe, SubscribeUpdate } from "./subscribe.ts";
import { SubscribeNamespaceLegacy } from "./subscribe_namespace.ts";
import { TrackStatusRequest } from "./track.ts";
Expand Down Expand Up @@ -713,3 +718,73 @@ test("a canceled request ID wait never spends a later grant", async () => {
}
}
});

// Draft 16 answers our REQUEST_UPDATE by the update's own request ID. The answer reaches the
// request it updated, and a refusal leaves that request open. Draft 15's reaches nothing.
test("an answer to our update reaches the request it updated on draft 16 only", async () => {
for (const [version, alpn] of [
[Version.DRAFT_15, ALPN.DRAFT_15],
[Version.DRAFT_16, ALPN.DRAFT_16],
] as const) {
const { adapter, peer, running } = await windowed(version, alpn, 8n, true);
try {
const stream = adapter.openBi();
await stream.writer.u53(PublishNamespace.id);
await new PublishNamespace({ requestId: 0n, trackNamespace: Path.from("ns") }).encode(
stream.writer,
version,
);
// The mock transport schedules nothing on timers, so settled promise chains are final.
const next = async () => {
let id: number | undefined;
const read = stream.reader.u53().then((value) => {
id = value;
});
for (let i = 0; i < 20 && id === undefined; i++) await new Promise((resolve) => setImmediate(resolve));
void read.catch(() => undefined);
return id;
};
const renew = async (own: bigint) => {
await stream.writer.u53(SubscribeUpdate.id);
const update =
version === Version.DRAFT_16
? new PublishNamespaceUpdate({ requestId: own, namespaceRequestId: 0n, update: {} })
: new SubscribeUpdate({ requestId: 0n, ownRequestId: own });
await update.encode(stream.writer, version);
};
const ok = async (requestId: bigint) => {
await peer.writer.u53(RequestOk.id);
await new RequestOk({ requestId }).encode(peer.writer, version);
};

await ok(0n);
expect(await next()).toBe(RequestOk.id);
await RequestOk.decode(stream.reader, version);

await renew(2n);
await ok(2n);
await renew(4n);
await peer.writer.u53(RequestError.id);
await new RequestError({ requestId: 4n, errorCode: 0, reasonPhrase: "refused" }).encode(
peer.writer,
version,
);
if (version === Version.DRAFT_15) {
expect(await next()).toBeUndefined();
continue;
}
expect(await next()).toBe(RequestOk.id);
await RequestOk.decode(stream.reader, version);
expect(await next()).toBe(RequestError.id);
await RequestError.decode(stream.reader, version);

// Still open: a later message for the request reaches it after the refusal.
await ok(0n);
expect(await next()).toBe(RequestOk.id);
} finally {
peer.close();
adapter.close();
void running;
}
}
});
24 changes: 19 additions & 5 deletions js/net/src/ietf/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,10 @@ export class ControlStreamAdapter implements Session {
// SubscribeNamespace requestIds — for routing 0x08/0x0E entries that lack requestId (v14/v15)
#subscribeNamespaces = new Set<bigint>();

// Our updates' own request IDs on drafts 15 and 16, whose answer names that ID rather than
// the request it updated. Nothing waits on it, so it is consumed here.
#updates = new Set<bigint>();
// Our updates' own request IDs on drafts 15 and 16 → the request each updated, since the
// answer names only the update. Draft 16's reaches that request's stream; draft 15's is
// consumed here, since nothing there reads one. An entry goes with its answer or its request.
#updates = new Map<bigint, bigint>();

// Incoming stream queue (for acceptBi)
#incomingQueue: Stream[] = [];
Expand Down Expand Up @@ -397,7 +398,12 @@ export class ControlStreamAdapter implements Session {
}
} else {
spent = this.#updateId(toFlush);
if (spent !== undefined && this.version !== Version.DRAFT_14) this.#updates.add(spent);
if (
spent !== undefined &&
registeredRequestId !== undefined &&
this.version !== Version.DRAFT_14
)
this.#updates.set(spent, registeredRequestId);
}

await this.#send(toFlush, spent);
Expand Down Expand Up @@ -504,8 +510,13 @@ export class ControlStreamAdapter implements Session {
}

const { route, requestId } = classified;
if ((route === Route.Response || route === Route.ErrorResponse) && this.#updates.delete(requestId))
const updated = this.#updates.get(requestId);
if ((route === Route.Response || route === Route.ErrorResponse) && updated !== undefined) {
// A refused update leaves its request open: the answer is all it ends.
this.#updates.delete(requestId);
if (this.version === Version.DRAFT_16) this.#pushMessage(updated, typeId, size, body);
Comment thread
kixelated marked this conversation as resolved.
Resolved
continue;
}

switch (route) {
case Route.NewRequest:
Expand Down Expand Up @@ -643,6 +654,9 @@ export class ControlStreamAdapter implements Session {
const held = this.#open.delete(requestId);
this.#streams.delete(requestId);
this.#subscribeNamespaces.delete(requestId);
for (const [update, updated] of this.#updates) {
if (updated === requestId) this.#updates.delete(update);
}

const registered = this.#namespacesByRequestId.get(requestId);
if (registered !== undefined) {
Expand Down
Loading