@moq/net 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lite/announce.d.ts +6 -0
- package/lite/announce.d.ts.map +1 -1
- package/lite/announce.js +10 -22
- package/lite/announce.js.map +1 -1
- package/lite/announce.test.js +21 -1
- package/lite/announce.test.js.map +1 -1
- package/lite/connection.d.ts.map +1 -1
- package/lite/connection.js +3 -2
- package/lite/connection.js.map +1 -1
- package/lite/setup.d.ts +11 -1
- package/lite/setup.d.ts.map +1 -1
- package/lite/setup.js +19 -2
- package/lite/setup.js.map +1 -1
- package/lite/setup.test.js +12 -0
- package/lite/setup.test.js.map +1 -1
- package/lite/subscriber.d.ts +4 -0
- package/lite/subscriber.d.ts.map +1 -1
- package/lite/subscriber.js +13 -8
- package/lite/subscriber.js.map +1 -1
- package/lite/version.d.ts +11 -0
- package/lite/version.d.ts.map +1 -1
- package/lite/version.js +19 -0
- package/lite/version.js.map +1 -1
- package/package.json +1 -1
package/lite/announce.d.ts
CHANGED
|
@@ -54,6 +54,12 @@ export declare function decodeAnnounceBroadcastMaybe(r: Reader, version: Version
|
|
|
54
54
|
export declare class AnnounceRequest {
|
|
55
55
|
#private;
|
|
56
56
|
prefix: Path.Valid;
|
|
57
|
+
/** Lite04/05 only: the 62-bit Origin id of the peer asking for announces, which the
|
|
58
|
+
* publisher uses to skip announces that already passed through it. Zero means "no
|
|
59
|
+
* exclusion". Not on the wire elsewhere, so a value set here is ignored when encoding
|
|
60
|
+
* for another version and decodes as zero.
|
|
61
|
+
*
|
|
62
|
+
* Must be a bigint: peer origins are up to 62 bits and overflow u53. */
|
|
57
63
|
excludeHop: bigint;
|
|
58
64
|
constructor(prefix: Path.Valid, excludeHop?: bigint);
|
|
59
65
|
encode(w: Writer, version: Version): Promise<void>;
|
package/lite/announce.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"announce.d.ts","sourceRoot":"","sources":["../../src/lite/announce.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,aAAa,CAAC;AACxD,OAAO,
|
|
1
|
+
{"version":3,"file":"announce.d.ts","sourceRoot":"","sources":["../../src/lite/announce.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,aAAa,CAAC;AACxD,OAAO,EAA6D,OAAO,EAAE,MAAM,cAAc,CAAC;AAKlG,eAAO,MAAM,QAAQ,KAAK,CAAC;AAc3B;;;;;;;;;GASG;AACH,MAAM,MAAM,iBAAiB;AAC5B;gEACgE;AAC9D;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE;AACzE,0EAA0E;GACxE;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAA;CAAE;AACzC;sEACsE;GACpE;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE;AACnC;oFACoF;GAClF;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAyJpE,8FAA8F;AAC9F,wBAAsB,uBAAuB,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,iBAAiB,EAAE,OAAO,EAAE,OAAO,G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,GAAG,OAAO,CAAC,IAAI,CAAC,CAGvD;IAED,OAAa,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAGpE;CACD"}
|
package/lite/announce.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import * as Path from "../path.js";
|
|
3
3
|
import * as Message from "./message.js";
|
|
4
4
|
import { OriginSchema } from "./origin.js";
|
|
5
|
-
import { hasAnnounceId, hasAnnounceOk, hasRouteCost, Version } from "./version.js";
|
|
5
|
+
import { hasAnnounceId, hasAnnounceOk, hasExcludeHop, hasRouteCost, Version } from "./version.js";
|
|
6
6
|
// Must match the MAX_HOPS in Rust's model/origin.rs. Broadcasts with longer
|
|
7
7
|
// hop chains are rejected; this keeps loop-detection bounded and rejects
|
|
8
8
|
// pathological announcements across clusters with unbounded forwarding.
|
|
@@ -195,8 +195,12 @@ export async function decodeAnnounceBroadcastMaybe(r, version) {
|
|
|
195
195
|
*/
|
|
196
196
|
export class AnnounceRequest {
|
|
197
197
|
prefix;
|
|
198
|
-
|
|
199
|
-
|
|
198
|
+
/** Lite04/05 only: the 62-bit Origin id of the peer asking for announces, which the
|
|
199
|
+
* publisher uses to skip announces that already passed through it. Zero means "no
|
|
200
|
+
* exclusion". Not on the wire elsewhere, so a value set here is ignored when encoding
|
|
201
|
+
* for another version and decodes as zero.
|
|
202
|
+
*
|
|
203
|
+
* Must be a bigint: peer origins are up to 62 bits and overflow u53. */
|
|
200
204
|
excludeHop;
|
|
201
205
|
constructor(prefix, excludeHop = 0n) {
|
|
202
206
|
this.prefix = prefix;
|
|
@@ -204,29 +208,13 @@ export class AnnounceRequest {
|
|
|
204
208
|
}
|
|
205
209
|
async #encode(w, version) {
|
|
206
210
|
await w.string(Path.encode(this.prefix));
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
case Version.DRAFT_02:
|
|
210
|
-
case Version.DRAFT_03:
|
|
211
|
-
break;
|
|
212
|
-
default:
|
|
213
|
-
// Lite04+: exclude_hop field (u62 varint).
|
|
214
|
-
await w.u62(this.excludeHop);
|
|
215
|
-
break;
|
|
211
|
+
if (hasExcludeHop(version)) {
|
|
212
|
+
await w.u62(this.excludeHop);
|
|
216
213
|
}
|
|
217
214
|
}
|
|
218
215
|
static async #decode(r, version) {
|
|
219
216
|
const prefix = Path.decode(await r.string());
|
|
220
|
-
|
|
221
|
-
switch (version) {
|
|
222
|
-
case Version.DRAFT_01:
|
|
223
|
-
case Version.DRAFT_02:
|
|
224
|
-
case Version.DRAFT_03:
|
|
225
|
-
break;
|
|
226
|
-
default:
|
|
227
|
-
excludeHop = await r.u62();
|
|
228
|
-
break;
|
|
229
|
-
}
|
|
217
|
+
const excludeHop = hasExcludeHop(version) ? await r.u62() : 0n;
|
|
230
218
|
return new AnnounceRequest(prefix, excludeHop);
|
|
231
219
|
}
|
|
232
220
|
async encode(w, version) {
|
package/lite/announce.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"announce.js","sourceRoot":"","sources":["../../src/lite/announce.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AAEnC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,EAAe,YAAY,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEnF,4EAA4E;AAC5E,yEAAyE;AACzE,wEAAwE;AACxE,MAAM,CAAC,MAAM,QAAQ,GAAG,EAAE,CAAC;AAE3B,sFAAsF;AACtF,MAAM,YAAY,GAAG,CAAC,CAAC;AACvB,MAAM,aAAa,GAAG,CAAC,CAAC;AACxB,MAAM,cAAc,GAAG,CAAC,CAAC;AAEzB,mFAAmF;AACnF,mFAAmF;AACnF,gEAAgE;AAChE,MAAM,cAAc,GAAG,CAAC,CAAC;AACzB,MAAM,YAAY,GAAG,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AAC;IAC1B,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAS;QAC7B,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC;QAC1B,qFAAqF;QACrF,IAAI,GAAG,KAAK,EAAE;YAAE,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;QACvE,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACvC,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC;QAC7B,OAAO,IAAI,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,CAAS,EAAE,OAAgB;QACvC,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC3B,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACnD,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAS,EAAE,OAAgB;QAC9C,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC3B,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;IAC9C,CAAC;CACD","sourcesContent":["import * as Path from \"../path.ts\";\nimport type { Reader, Writer } from \"../stream.ts\";\nimport * as Message from \"./message.ts\";\nimport { type Origin, OriginSchema } from \"./origin.ts\";\nimport { hasAnnounceId, hasAnnounceOk, hasRouteCost, Version } from \"./version.ts\";\n\n// Must match the MAX_HOPS in Rust's model/origin.rs. Broadcasts with longer\n// hop chains are rejected; this keeps loop-detection bounded and rejects\n// pathological announcements across clusters with unbounded forwarding.\nexport const MAX_HOPS = 32;\n\n// Pre-lite-06 inner status values, carried inside the single ANNOUNCE_BROADCAST body.\nconst STATUS_ENDED = 0;\nconst STATUS_ACTIVE = 1;\nconst STATUS_RESTART = 2;\n\n// lite-06 announce message types: an outer discriminator carried before the length\n// prefix, so each announcement is an independently-typed, length-delimited message\n// (mirroring SUBSCRIBE_START/END/DROP on the subscribe stream).\nconst ANNOUNCE_START = 0;\nconst ANNOUNCE_END = 1;\nconst ANNOUNCE_RESTART = 2;\n\n/**\n * An announcement on the Announce Stream, advertising or retracting a broadcast.\n *\n * On lite-06+ these are three independently-typed messages (`ANNOUNCE_START`,\n * `ANNOUNCE_END`, `ANNOUNCE_RESTART`), each framed as `Type | Length | Body` like the\n * subscribe stream's responses. Each `active` (ANNOUNCE_START) implicitly assigns the\n * next announce id (a per-stream ordinal starting at 0); `endedId`/`restart` reference\n * that id instead of repeating the path. Older versions send a single ANNOUNCE_BROADCAST\n * message that retracts by path (`ended`).\n */\nexport type AnnounceBroadcast =\n\t/** A broadcast is now available, carrying the path suffix, the hop chain, and\n\t * (lite-06+) the route cost. An absent cost encodes as zero. */\n\t| { status: \"active\"; suffix: Path.Valid; hops: Origin[]; cost?: bigint }\n\t/** Pre-lite-06: a broadcast is no longer available, retracted by path. */\n\t| { status: \"ended\"; suffix: Path.Valid }\n\t/** Lite06+: a broadcast is no longer available, retracted by announce id.\n\t * The id is retired; referencing it again is a protocol violation. */\n\t| { status: \"endedId\"; id: bigint }\n\t/** Lite06+: atomically replace the announcement with this id (e.g. a new hop\n\t * chain after a relay failover, or a route whose cost moved). The id stays live. */\n\t| { status: \"restart\"; id: bigint; hops: Origin[]; cost?: bigint };\n\nfunction checkHops(hops: Origin[]) {\n\tif (hops.length > MAX_HOPS) {\n\t\tthrow new Error(`hop count ${hops.length} exceeds maximum ${MAX_HOPS}`);\n\t}\n}\n\nasync function encodeHops(w: Writer, version: Version, hops: Origin[]) {\n\tcheckHops(hops);\n\tswitch (version) {\n\t\tcase Version.DRAFT_01:\n\t\tcase Version.DRAFT_02:\n\t\t\tbreak;\n\t\tcase Version.DRAFT_03:\n\t\t\tawait w.u53(hops.length);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\t// Lite04+: hop count + individual Origin varints.\n\t\t\tawait w.u53(hops.length);\n\t\t\tfor (const origin of hops) {\n\t\t\t\tawait w.u62(origin);\n\t\t\t}\n\t\t\tbreak;\n\t}\n}\n\nasync function decodeHops(r: Reader, version: Version): Promise<Origin[]> {\n\tswitch (version) {\n\t\tcase Version.DRAFT_01:\n\t\tcase Version.DRAFT_02:\n\t\t\treturn [];\n\t\tcase Version.DRAFT_03: {\n\t\t\tconst count = await r.u53();\n\t\t\tif (count > MAX_HOPS) throw new Error(`hop count ${count} exceeds maximum ${MAX_HOPS}`);\n\t\t\t// Lite03 carries only a hop count, not individual ids. Fill with\n\t\t\t// the zero placeholder (OriginSchema accepts 0 as valid on-wire).\n\t\t\tconst placeholder = OriginSchema.parse(0n);\n\t\t\treturn new Array<Origin>(count).fill(placeholder);\n\t\t}\n\t\tdefault: {\n\t\t\t// Lite04+: hop count + individual Origin varints.\n\t\t\tconst count = await r.u53();\n\t\t\tif (count > MAX_HOPS) throw new Error(`hop count ${count} exceeds maximum ${MAX_HOPS}`);\n\t\t\tconst hops: Origin[] = [];\n\t\t\tfor (let i = 0; i < count; i++) {\n\t\t\t\thops.push(OriginSchema.parse(await r.u62()));\n\t\t\t}\n\t\t\treturn hops;\n\t\t}\n\t}\n}\n\n// The route cost rides lite-06+ announcements as a single varint; older\n// versions carry nothing and decode as zero.\nasync function encodeRouteCost(w: Writer, version: Version, cost: bigint | undefined) {\n\tif (!hasRouteCost(version)) return;\n\tawait w.u62(cost ?? 0n);\n}\n\nasync function decodeRouteCost(r: Reader, version: Version): Promise<bigint> {\n\tif (!hasRouteCost(version)) return 0n;\n\treturn await r.u62();\n}\n\n// lite-06 message body (no discriminator; the type is carried outside the length prefix).\nasync function encodeAnnounce06Body(w: Writer, msg: AnnounceBroadcast, version: Version) {\n\tswitch (msg.status) {\n\t\tcase \"active\":\n\t\t\tawait w.string(Path.encode(msg.suffix));\n\t\t\tawait encodeHops(w, version, msg.hops);\n\t\t\tawait encodeRouteCost(w, version, msg.cost);\n\t\t\tbreak;\n\t\tcase \"endedId\":\n\t\t\tawait w.u62(msg.id);\n\t\t\tbreak;\n\t\tcase \"restart\":\n\t\t\tawait w.u62(msg.id);\n\t\t\tawait encodeHops(w, version, msg.hops);\n\t\t\tawait encodeRouteCost(w, version, msg.cost);\n\t\t\tbreak;\n\t\tcase \"ended\":\n\t\t\t// The pre-lite-06 path-form retraction has no place on lite-06.\n\t\t\tthrow new Error(\"ended-by-path not supported for this version\");\n\t}\n}\n\n// lite-06 outer message type for a given announcement.\nfunction announce06Type(msg: AnnounceBroadcast): number {\n\tswitch (msg.status) {\n\t\tcase \"active\":\n\t\t\treturn ANNOUNCE_START;\n\t\tcase \"endedId\":\n\t\t\treturn ANNOUNCE_END;\n\t\tcase \"restart\":\n\t\t\treturn ANNOUNCE_RESTART;\n\t\tcase \"ended\":\n\t\t\tthrow new Error(\"ended-by-path not supported for this version\");\n\t}\n}\n\nasync function decodeAnnounce06Body(r: Reader, typ: number, version: Version): Promise<AnnounceBroadcast> {\n\tswitch (typ) {\n\t\tcase ANNOUNCE_START: {\n\t\t\tconst suffix = Path.decode(await r.string());\n\t\t\tconst hops = await decodeHops(r, version);\n\t\t\treturn { status: \"active\", suffix, hops, cost: await decodeRouteCost(r, version) };\n\t\t}\n\t\tcase ANNOUNCE_END:\n\t\t\treturn { status: \"endedId\", id: await r.u62() };\n\t\tcase ANNOUNCE_RESTART: {\n\t\t\tconst id = await r.u62();\n\t\t\tconst hops = await decodeHops(r, version);\n\t\t\treturn { status: \"restart\", id, hops, cost: await decodeRouteCost(r, version) };\n\t\t}\n\t\tdefault:\n\t\t\tthrow new Error(`unknown announce message type: ${typ}`);\n\t}\n}\n\n// Pre-lite-06 single ANNOUNCE_BROADCAST body: an inner status byte, then path + hops.\nasync function encodeLegacyBody(w: Writer, msg: AnnounceBroadcast, version: Version) {\n\tswitch (msg.status) {\n\t\tcase \"active\":\n\t\t\tawait w.u8(STATUS_ACTIVE);\n\t\t\tawait w.string(Path.encode(msg.suffix));\n\t\t\tawait encodeHops(w, version, msg.hops);\n\t\t\tbreak;\n\t\tcase \"ended\":\n\t\t\tawait w.u8(STATUS_ENDED);\n\t\t\tawait w.string(Path.encode(msg.suffix));\n\t\t\tawait encodeHops(w, version, []);\n\t\t\tbreak;\n\t\tcase \"endedId\":\n\t\tcase \"restart\":\n\t\t\t// The id-referencing forms only exist on lite-06+.\n\t\t\tthrow new Error(\"announce ids not supported for this version\");\n\t}\n}\n\nasync function decodeLegacyBody(r: Reader, version: Version): Promise<AnnounceBroadcast> {\n\tconst status = await r.u8();\n\t// On lite-05 a restart travels as a duplicate `active`, but the explicit restart\n\t// status is accepted on decode and treated the same. Older versions never defined it.\n\tconst active = status === STATUS_ACTIVE || (status === STATUS_RESTART && hasAnnounceOk(version));\n\tif (status !== STATUS_ENDED && !active) {\n\t\tthrow new Error(\"invalid announce status\");\n\t}\n\tconst suffix = Path.decode(await r.string());\n\tconst hops = await decodeHops(r, version);\n\treturn active ? { status: \"active\", suffix, hops } : { status: \"ended\", suffix };\n}\n\n/** Encode one announcement, including its type discriminator (lite-06+) and length prefix. */\nexport async function encodeAnnounceBroadcast(w: Writer, msg: AnnounceBroadcast, version: Version): Promise<void> {\n\tif (hasAnnounceId(version)) {\n\t\t// lite-06+: outer type discriminator, then a size-prefixed body (like the subscribe stream).\n\t\tawait w.u53(announce06Type(msg));\n\t\treturn Message.encode(w, (w) => encodeAnnounce06Body(w, msg, version));\n\t}\n\treturn Message.encode(w, (w) => encodeLegacyBody(w, msg, version));\n}\n\n/** Decode one announcement, including its type discriminator (lite-06+) and length prefix. */\nexport async function decodeAnnounceBroadcast(r: Reader, version: Version): Promise<AnnounceBroadcast> {\n\tif (hasAnnounceId(version)) {\n\t\tconst typ = await r.u53();\n\t\treturn Message.decode(r, (r) => decodeAnnounce06Body(r, typ, version));\n\t}\n\treturn Message.decode(r, (r) => decodeLegacyBody(r, version));\n}\n\n/** Like {@link decodeAnnounceBroadcast} but resolves `undefined` on a clean FIN. */\nexport async function decodeAnnounceBroadcastMaybe(\n\tr: Reader,\n\tversion: Version,\n): Promise<AnnounceBroadcast | undefined> {\n\tif (hasAnnounceId(version)) {\n\t\tif (await r.done()) return undefined;\n\t\tconst typ = await r.u53();\n\t\treturn Message.decode(r, (r) => decodeAnnounce06Body(r, typ, version));\n\t}\n\treturn Message.decodeMaybe(r, (r) => decodeLegacyBody(r, version));\n}\n\n/**\n * ANNOUNCE_REQUEST: sent by the subscriber to request ANNOUNCE_BROADCAST messages\n * for a path prefix. Renamed from `AnnounceInterest` in lite-05.\n */\nexport class AnnounceRequest {\n\tprefix: Path.Valid;\n\t// 62-bit Origin id of the peer asking for announces. Zero means \"no exclusion\".\n\t// Must be a bigint: peer origins are up to 62 bits and overflow u53.\n\texcludeHop: bigint;\n\n\tconstructor(prefix: Path.Valid, excludeHop: bigint = 0n) {\n\t\tthis.prefix = prefix;\n\t\tthis.excludeHop = excludeHop;\n\t}\n\n\tasync #encode(w: Writer, version: Version) {\n\t\tawait w.string(Path.encode(this.prefix));\n\t\tswitch (version) {\n\t\t\tcase Version.DRAFT_01:\n\t\t\tcase Version.DRAFT_02:\n\t\t\tcase Version.DRAFT_03:\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\t// Lite04+: exclude_hop field (u62 varint).\n\t\t\t\tawait w.u62(this.excludeHop);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tstatic async #decode(r: Reader, version: Version): Promise<AnnounceRequest> {\n\t\tconst prefix = Path.decode(await r.string());\n\t\tlet excludeHop = 0n;\n\t\tswitch (version) {\n\t\t\tcase Version.DRAFT_01:\n\t\t\tcase Version.DRAFT_02:\n\t\t\tcase Version.DRAFT_03:\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\texcludeHop = await r.u62();\n\t\t\t\tbreak;\n\t\t}\n\t\treturn new AnnounceRequest(prefix, excludeHop);\n\t}\n\n\tasync encode(w: Writer, version: Version): Promise<void> {\n\t\treturn Message.encode(w, (w) => this.#encode(w, version));\n\t}\n\n\tstatic async decode(r: Reader, version: Version): Promise<AnnounceRequest> {\n\t\treturn Message.decode(r, (r) => AnnounceRequest.#decode(r, version));\n\t}\n}\n\n/// Sent after setup to communicate the initially announced paths.\n///\n/// Used by Draft01/Draft02 only. Draft03+ uses individual Announce messages instead.\nexport class AnnounceInit {\n\tsuffixes: Path.Valid[];\n\n\tconstructor(paths: Path.Valid[]) {\n\t\tthis.suffixes = paths;\n\t}\n\n\tstatic #guard(version: Version) {\n\t\tswitch (version) {\n\t\t\tcase Version.DRAFT_01:\n\t\t\tcase Version.DRAFT_02:\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"announce init not supported for this version\");\n\t\t}\n\t}\n\n\tasync #encode(w: Writer) {\n\t\tawait w.u53(this.suffixes.length);\n\t\tfor (const path of this.suffixes) {\n\t\t\tawait w.string(Path.encode(path));\n\t\t}\n\t}\n\n\tstatic async #decode(r: Reader): Promise<AnnounceInit> {\n\t\tconst count = await r.u53();\n\t\tconst suffixes: Path.Valid[] = [];\n\t\tfor (let i = 0; i < count; i++) {\n\t\t\tsuffixes.push(Path.decode(await r.string()));\n\t\t}\n\t\treturn new AnnounceInit(suffixes);\n\t}\n\n\tasync encode(w: Writer, version: Version): Promise<void> {\n\t\tAnnounceInit.#guard(version);\n\t\treturn Message.encode(w, this.#encode.bind(this));\n\t}\n\n\tstatic async decode(r: Reader, version: Version): Promise<AnnounceInit> {\n\t\tAnnounceInit.#guard(version);\n\t\treturn Message.decode(r, AnnounceInit.#decode);\n\t}\n}\n\n/// Sent by the publisher as the first message on an announce stream, before any\n/// individual Announce messages. Lite05+ only; the successor to AnnounceInit.\n///\n/// `origin` is the responder's origin id, which the subscriber stamps onto each\n/// announce's hop chain (the publisher no longer stamps itself). `active` is the\n/// number of initial Announce messages that follow immediately.\nexport class AnnounceOk {\n\torigin: Origin;\n\tactive: number;\n\n\tconstructor(origin: Origin, active: number) {\n\t\tthis.origin = origin;\n\t\tthis.active = active;\n\t}\n\n\tstatic #guard(version: Version) {\n\t\tif (!hasAnnounceOk(version)) {\n\t\t\tthrow new Error(\"announce ok not supported for this version\");\n\t\t}\n\t}\n\n\tasync #encode(w: Writer) {\n\t\tawait w.u62(this.origin);\n\t\tawait w.u53(this.active);\n\t}\n\n\tstatic async #decode(r: Reader): Promise<AnnounceOk> {\n\t\tconst raw = await r.u62();\n\t\t// A zero responder id is never legitimate; it would stamp a placeholder onto chains.\n\t\tif (raw === 0n) throw new Error(\"announce ok origin must be non-zero\");\n\t\tconst origin = OriginSchema.parse(raw);\n\t\tconst active = await r.u53();\n\t\treturn new AnnounceOk(origin, active);\n\t}\n\n\tasync encode(w: Writer, version: Version): Promise<void> {\n\t\tAnnounceOk.#guard(version);\n\t\treturn Message.encode(w, this.#encode.bind(this));\n\t}\n\n\tstatic async decode(r: Reader, version: Version): Promise<AnnounceOk> {\n\t\tAnnounceOk.#guard(version);\n\t\treturn Message.decode(r, AnnounceOk.#decode);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"announce.js","sourceRoot":"","sources":["../../src/lite/announce.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AAEnC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,EAAe,YAAY,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAElG,4EAA4E;AAC5E,yEAAyE;AACzE,wEAAwE;AACxE,MAAM,CAAC,MAAM,QAAQ,GAAG,EAAE,CAAC;AAE3B,sFAAsF;AACtF,MAAM,YAAY,GAAG,CAAC,CAAC;AACvB,MAAM,aAAa,GAAG,CAAC,CAAC;AACxB,MAAM,cAAc,GAAG,CAAC,CAAC;AAEzB,mFAAmF;AACnF,mFAAmF;AACnF,gEAA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QACvE,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACvC,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC;QAC7B,OAAO,IAAI,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,CAAS,EAAE,OAAgB;QACvC,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC3B,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACnD,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAS,EAAE,OAAgB;QAC9C,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC3B,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;IAC9C,CAAC;CACD","sourcesContent":["import * as Path from \"../path.ts\";\nimport type { Reader, Writer } from \"../stream.ts\";\nimport * as Message from \"./message.ts\";\nimport { type Origin, OriginSchema } from \"./origin.ts\";\nimport { hasAnnounceId, hasAnnounceOk, hasExcludeHop, hasRouteCost, Version } from \"./version.ts\";\n\n// Must match the MAX_HOPS in Rust's model/origin.rs. Broadcasts with longer\n// hop chains are rejected; this keeps loop-detection bounded and rejects\n// pathological announcements across clusters with unbounded forwarding.\nexport const MAX_HOPS = 32;\n\n// Pre-lite-06 inner status values, carried inside the single ANNOUNCE_BROADCAST body.\nconst STATUS_ENDED = 0;\nconst STATUS_ACTIVE = 1;\nconst STATUS_RESTART = 2;\n\n// lite-06 announce message types: an outer discriminator carried before the length\n// prefix, so each announcement is an independently-typed, length-delimited message\n// (mirroring SUBSCRIBE_START/END/DROP on the subscribe stream).\nconst ANNOUNCE_START = 0;\nconst ANNOUNCE_END = 1;\nconst ANNOUNCE_RESTART = 2;\n\n/**\n * An announcement on the Announce Stream, advertising or retracting a broadcast.\n *\n * On lite-06+ these are three independently-typed messages (`ANNOUNCE_START`,\n * `ANNOUNCE_END`, `ANNOUNCE_RESTART`), each framed as `Type | Length | Body` like the\n * subscribe stream's responses. Each `active` (ANNOUNCE_START) implicitly assigns the\n * next announce id (a per-stream ordinal starting at 0); `endedId`/`restart` reference\n * that id instead of repeating the path. Older versions send a single ANNOUNCE_BROADCAST\n * message that retracts by path (`ended`).\n */\nexport type AnnounceBroadcast =\n\t/** A broadcast is now available, carrying the path suffix, the hop chain, and\n\t * (lite-06+) the route cost. An absent cost encodes as zero. */\n\t| { status: \"active\"; suffix: Path.Valid; hops: Origin[]; cost?: bigint }\n\t/** Pre-lite-06: a broadcast is no longer available, retracted by path. */\n\t| { status: \"ended\"; suffix: Path.Valid }\n\t/** Lite06+: a broadcast is no longer available, retracted by announce id.\n\t * The id is retired; referencing it again is a protocol violation. */\n\t| { status: \"endedId\"; id: bigint }\n\t/** Lite06+: atomically replace the announcement with this id (e.g. a new hop\n\t * chain after a relay failover, or a route whose cost moved). The id stays live. */\n\t| { status: \"restart\"; id: bigint; hops: Origin[]; cost?: bigint };\n\nfunction checkHops(hops: Origin[]) {\n\tif (hops.length > MAX_HOPS) {\n\t\tthrow new Error(`hop count ${hops.length} exceeds maximum ${MAX_HOPS}`);\n\t}\n}\n\nasync function encodeHops(w: Writer, version: Version, hops: Origin[]) {\n\tcheckHops(hops);\n\tswitch (version) {\n\t\tcase Version.DRAFT_01:\n\t\tcase Version.DRAFT_02:\n\t\t\tbreak;\n\t\tcase Version.DRAFT_03:\n\t\t\tawait w.u53(hops.length);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\t// Lite04+: hop count + individual Origin varints.\n\t\t\tawait w.u53(hops.length);\n\t\t\tfor (const origin of hops) {\n\t\t\t\tawait w.u62(origin);\n\t\t\t}\n\t\t\tbreak;\n\t}\n}\n\nasync function decodeHops(r: Reader, version: Version): Promise<Origin[]> {\n\tswitch (version) {\n\t\tcase Version.DRAFT_01:\n\t\tcase Version.DRAFT_02:\n\t\t\treturn [];\n\t\tcase Version.DRAFT_03: {\n\t\t\tconst count = await r.u53();\n\t\t\tif (count > MAX_HOPS) throw new Error(`hop count ${count} exceeds maximum ${MAX_HOPS}`);\n\t\t\t// Lite03 carries only a hop count, not individual ids. Fill with\n\t\t\t// the zero placeholder (OriginSchema accepts 0 as valid on-wire).\n\t\t\tconst placeholder = OriginSchema.parse(0n);\n\t\t\treturn new Array<Origin>(count).fill(placeholder);\n\t\t}\n\t\tdefault: {\n\t\t\t// Lite04+: hop count + individual Origin varints.\n\t\t\tconst count = await r.u53();\n\t\t\tif (count > MAX_HOPS) throw new Error(`hop count ${count} exceeds maximum ${MAX_HOPS}`);\n\t\t\tconst hops: Origin[] = [];\n\t\t\tfor (let i = 0; i < count; i++) {\n\t\t\t\thops.push(OriginSchema.parse(await r.u62()));\n\t\t\t}\n\t\t\treturn hops;\n\t\t}\n\t}\n}\n\n// The route cost rides lite-06+ announcements as a single varint; older\n// versions carry nothing and decode as zero.\nasync function encodeRouteCost(w: Writer, version: Version, cost: bigint | undefined) {\n\tif (!hasRouteCost(version)) return;\n\tawait w.u62(cost ?? 0n);\n}\n\nasync function decodeRouteCost(r: Reader, version: Version): Promise<bigint> {\n\tif (!hasRouteCost(version)) return 0n;\n\treturn await r.u62();\n}\n\n// lite-06 message body (no discriminator; the type is carried outside the length prefix).\nasync function encodeAnnounce06Body(w: Writer, msg: AnnounceBroadcast, version: Version) {\n\tswitch (msg.status) {\n\t\tcase \"active\":\n\t\t\tawait w.string(Path.encode(msg.suffix));\n\t\t\tawait encodeHops(w, version, msg.hops);\n\t\t\tawait encodeRouteCost(w, version, msg.cost);\n\t\t\tbreak;\n\t\tcase \"endedId\":\n\t\t\tawait w.u62(msg.id);\n\t\t\tbreak;\n\t\tcase \"restart\":\n\t\t\tawait w.u62(msg.id);\n\t\t\tawait encodeHops(w, version, msg.hops);\n\t\t\tawait encodeRouteCost(w, version, msg.cost);\n\t\t\tbreak;\n\t\tcase \"ended\":\n\t\t\t// The pre-lite-06 path-form retraction has no place on lite-06.\n\t\t\tthrow new Error(\"ended-by-path not supported for this version\");\n\t}\n}\n\n// lite-06 outer message type for a given announcement.\nfunction announce06Type(msg: AnnounceBroadcast): number {\n\tswitch (msg.status) {\n\t\tcase \"active\":\n\t\t\treturn ANNOUNCE_START;\n\t\tcase \"endedId\":\n\t\t\treturn ANNOUNCE_END;\n\t\tcase \"restart\":\n\t\t\treturn ANNOUNCE_RESTART;\n\t\tcase \"ended\":\n\t\t\tthrow new Error(\"ended-by-path not supported for this version\");\n\t}\n}\n\nasync function decodeAnnounce06Body(r: Reader, typ: number, version: Version): Promise<AnnounceBroadcast> {\n\tswitch (typ) {\n\t\tcase ANNOUNCE_START: {\n\t\t\tconst suffix = Path.decode(await r.string());\n\t\t\tconst hops = await decodeHops(r, version);\n\t\t\treturn { status: \"active\", suffix, hops, cost: await decodeRouteCost(r, version) };\n\t\t}\n\t\tcase ANNOUNCE_END:\n\t\t\treturn { status: \"endedId\", id: await r.u62() };\n\t\tcase ANNOUNCE_RESTART: {\n\t\t\tconst id = await r.u62();\n\t\t\tconst hops = await decodeHops(r, version);\n\t\t\treturn { status: \"restart\", id, hops, cost: await decodeRouteCost(r, version) };\n\t\t}\n\t\tdefault:\n\t\t\tthrow new Error(`unknown announce message type: ${typ}`);\n\t}\n}\n\n// Pre-lite-06 single ANNOUNCE_BROADCAST body: an inner status byte, then path + hops.\nasync function encodeLegacyBody(w: Writer, msg: AnnounceBroadcast, version: Version) {\n\tswitch (msg.status) {\n\t\tcase \"active\":\n\t\t\tawait w.u8(STATUS_ACTIVE);\n\t\t\tawait w.string(Path.encode(msg.suffix));\n\t\t\tawait encodeHops(w, version, msg.hops);\n\t\t\tbreak;\n\t\tcase \"ended\":\n\t\t\tawait w.u8(STATUS_ENDED);\n\t\t\tawait w.string(Path.encode(msg.suffix));\n\t\t\tawait encodeHops(w, version, []);\n\t\t\tbreak;\n\t\tcase \"endedId\":\n\t\tcase \"restart\":\n\t\t\t// The id-referencing forms only exist on lite-06+.\n\t\t\tthrow new Error(\"announce ids not supported for this version\");\n\t}\n}\n\nasync function decodeLegacyBody(r: Reader, version: Version): Promise<AnnounceBroadcast> {\n\tconst status = await r.u8();\n\t// On lite-05 a restart travels as a duplicate `active`, but the explicit restart\n\t// status is accepted on decode and treated the same. Older versions never defined it.\n\tconst active = status === STATUS_ACTIVE || (status === STATUS_RESTART && hasAnnounceOk(version));\n\tif (status !== STATUS_ENDED && !active) {\n\t\tthrow new Error(\"invalid announce status\");\n\t}\n\tconst suffix = Path.decode(await r.string());\n\tconst hops = await decodeHops(r, version);\n\treturn active ? { status: \"active\", suffix, hops } : { status: \"ended\", suffix };\n}\n\n/** Encode one announcement, including its type discriminator (lite-06+) and length prefix. */\nexport async function encodeAnnounceBroadcast(w: Writer, msg: AnnounceBroadcast, version: Version): Promise<void> {\n\tif (hasAnnounceId(version)) {\n\t\t// lite-06+: outer type discriminator, then a size-prefixed body (like the subscribe stream).\n\t\tawait w.u53(announce06Type(msg));\n\t\treturn Message.encode(w, (w) => encodeAnnounce06Body(w, msg, version));\n\t}\n\treturn Message.encode(w, (w) => encodeLegacyBody(w, msg, version));\n}\n\n/** Decode one announcement, including its type discriminator (lite-06+) and length prefix. */\nexport async function decodeAnnounceBroadcast(r: Reader, version: Version): Promise<AnnounceBroadcast> {\n\tif (hasAnnounceId(version)) {\n\t\tconst typ = await r.u53();\n\t\treturn Message.decode(r, (r) => decodeAnnounce06Body(r, typ, version));\n\t}\n\treturn Message.decode(r, (r) => decodeLegacyBody(r, version));\n}\n\n/** Like {@link decodeAnnounceBroadcast} but resolves `undefined` on a clean FIN. */\nexport async function decodeAnnounceBroadcastMaybe(\n\tr: Reader,\n\tversion: Version,\n): Promise<AnnounceBroadcast | undefined> {\n\tif (hasAnnounceId(version)) {\n\t\tif (await r.done()) return undefined;\n\t\tconst typ = await r.u53();\n\t\treturn Message.decode(r, (r) => decodeAnnounce06Body(r, typ, version));\n\t}\n\treturn Message.decodeMaybe(r, (r) => decodeLegacyBody(r, version));\n}\n\n/**\n * ANNOUNCE_REQUEST: sent by the subscriber to request ANNOUNCE_BROADCAST messages\n * for a path prefix. Renamed from `AnnounceInterest` in lite-05.\n */\nexport class AnnounceRequest {\n\tprefix: Path.Valid;\n\t/** Lite04/05 only: the 62-bit Origin id of the peer asking for announces, which the\n\t * publisher uses to skip announces that already passed through it. Zero means \"no\n\t * exclusion\". Not on the wire elsewhere, so a value set here is ignored when encoding\n\t * for another version and decodes as zero.\n\t *\n\t * Must be a bigint: peer origins are up to 62 bits and overflow u53. */\n\texcludeHop: bigint;\n\n\tconstructor(prefix: Path.Valid, excludeHop: bigint = 0n) {\n\t\tthis.prefix = prefix;\n\t\tthis.excludeHop = excludeHop;\n\t}\n\n\tasync #encode(w: Writer, version: Version) {\n\t\tawait w.string(Path.encode(this.prefix));\n\t\tif (hasExcludeHop(version)) {\n\t\t\tawait w.u62(this.excludeHop);\n\t\t}\n\t}\n\n\tstatic async #decode(r: Reader, version: Version): Promise<AnnounceRequest> {\n\t\tconst prefix = Path.decode(await r.string());\n\t\tconst excludeHop = hasExcludeHop(version) ? await r.u62() : 0n;\n\t\treturn new AnnounceRequest(prefix, excludeHop);\n\t}\n\n\tasync encode(w: Writer, version: Version): Promise<void> {\n\t\treturn Message.encode(w, (w) => this.#encode(w, version));\n\t}\n\n\tstatic async decode(r: Reader, version: Version): Promise<AnnounceRequest> {\n\t\treturn Message.decode(r, (r) => AnnounceRequest.#decode(r, version));\n\t}\n}\n\n/// Sent after setup to communicate the initially announced paths.\n///\n/// Used by Draft01/Draft02 only. Draft03+ uses individual Announce messages instead.\nexport class AnnounceInit {\n\tsuffixes: Path.Valid[];\n\n\tconstructor(paths: Path.Valid[]) {\n\t\tthis.suffixes = paths;\n\t}\n\n\tstatic #guard(version: Version) {\n\t\tswitch (version) {\n\t\t\tcase Version.DRAFT_01:\n\t\t\tcase Version.DRAFT_02:\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"announce init not supported for this version\");\n\t\t}\n\t}\n\n\tasync #encode(w: Writer) {\n\t\tawait w.u53(this.suffixes.length);\n\t\tfor (const path of this.suffixes) {\n\t\t\tawait w.string(Path.encode(path));\n\t\t}\n\t}\n\n\tstatic async #decode(r: Reader): Promise<AnnounceInit> {\n\t\tconst count = await r.u53();\n\t\tconst suffixes: Path.Valid[] = [];\n\t\tfor (let i = 0; i < count; i++) {\n\t\t\tsuffixes.push(Path.decode(await r.string()));\n\t\t}\n\t\treturn new AnnounceInit(suffixes);\n\t}\n\n\tasync encode(w: Writer, version: Version): Promise<void> {\n\t\tAnnounceInit.#guard(version);\n\t\treturn Message.encode(w, this.#encode.bind(this));\n\t}\n\n\tstatic async decode(r: Reader, version: Version): Promise<AnnounceInit> {\n\t\tAnnounceInit.#guard(version);\n\t\treturn Message.decode(r, AnnounceInit.#decode);\n\t}\n}\n\n/// Sent by the publisher as the first message on an announce stream, before any\n/// individual Announce messages. Lite05+ only; the successor to AnnounceInit.\n///\n/// `origin` is the responder's origin id, which the subscriber stamps onto each\n/// announce's hop chain (the publisher no longer stamps itself). `active` is the\n/// number of initial Announce messages that follow immediately.\nexport class AnnounceOk {\n\torigin: Origin;\n\tactive: number;\n\n\tconstructor(origin: Origin, active: number) {\n\t\tthis.origin = origin;\n\t\tthis.active = active;\n\t}\n\n\tstatic #guard(version: Version) {\n\t\tif (!hasAnnounceOk(version)) {\n\t\t\tthrow new Error(\"announce ok not supported for this version\");\n\t\t}\n\t}\n\n\tasync #encode(w: Writer) {\n\t\tawait w.u62(this.origin);\n\t\tawait w.u53(this.active);\n\t}\n\n\tstatic async #decode(r: Reader): Promise<AnnounceOk> {\n\t\tconst raw = await r.u62();\n\t\t// A zero responder id is never legitimate; it would stamp a placeholder onto chains.\n\t\tif (raw === 0n) throw new Error(\"announce ok origin must be non-zero\");\n\t\tconst origin = OriginSchema.parse(raw);\n\t\tconst active = await r.u53();\n\t\treturn new AnnounceOk(origin, active);\n\t}\n\n\tasync encode(w: Writer, version: Version): Promise<void> {\n\t\tAnnounceOk.#guard(version);\n\t\treturn Message.encode(w, this.#encode.bind(this));\n\t}\n\n\tstatic async decode(r: Reader, version: Version): Promise<AnnounceOk> {\n\t\tAnnounceOk.#guard(version);\n\t\treturn Message.decode(r, AnnounceOk.#decode);\n\t}\n}\n"]}
|
package/lite/announce.test.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { expect, test } from "bun:test";
|
|
3
3
|
import * as Path from "../path.js";
|
|
4
4
|
import { Reader, Writer } from "../stream.js";
|
|
5
|
-
import { decodeAnnounceBroadcast, encodeAnnounceBroadcast } from "./announce.js";
|
|
5
|
+
import { AnnounceRequest, decodeAnnounceBroadcast, encodeAnnounceBroadcast, } from "./announce.js";
|
|
6
6
|
import { OriginSchema } from "./origin.js";
|
|
7
7
|
import { Version } from "./version.js";
|
|
8
8
|
function concat(chunks) {
|
|
@@ -68,4 +68,24 @@ test("AnnounceBroadcast rejects explicit restart status before draft-05", async
|
|
|
68
68
|
wire[1] = 2;
|
|
69
69
|
await expect(decodeAnnounceBroadcast(new Reader(undefined, wire), Version.DRAFT_04)).rejects.toThrow();
|
|
70
70
|
});
|
|
71
|
+
async function requestRoundTrip(msg, version) {
|
|
72
|
+
const reader = new Reader(undefined, await bytes((w) => msg.encode(w, version)));
|
|
73
|
+
return AnnounceRequest.decode(reader, version);
|
|
74
|
+
}
|
|
75
|
+
// Draft04/05 carry the subscriber's origin id so the publisher can skip reflected
|
|
76
|
+
// announces before they hit the wire.
|
|
77
|
+
test("AnnounceRequest carries excludeHop on draft-05", async () => {
|
|
78
|
+
const got = await requestRoundTrip(new AnnounceRequest(Path.from("room/"), 42n), Version.DRAFT_05);
|
|
79
|
+
expect(got.excludeHop).toBe(42n);
|
|
80
|
+
});
|
|
81
|
+
// Draft06 dropped the field: the receiver's reflected-announce check catches the same
|
|
82
|
+
// loops, so a value set locally is simply not sent and decodes as zero.
|
|
83
|
+
test("AnnounceRequest drops excludeHop on draft-06", async () => {
|
|
84
|
+
const msg = new AnnounceRequest(Path.from("room/"), 42n);
|
|
85
|
+
const got = await requestRoundTrip(msg, Version.DRAFT_06);
|
|
86
|
+
expect(got.excludeHop).toBe(0n);
|
|
87
|
+
const with05 = await bytes((w) => msg.encode(w, Version.DRAFT_05));
|
|
88
|
+
const with06 = await bytes((w) => msg.encode(w, Version.DRAFT_06));
|
|
89
|
+
expect(with06.byteLength).toBeLessThan(with05.byteLength);
|
|
90
|
+
});
|
|
71
91
|
//# sourceMappingURL=announce.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"announce.test.js","sourceRoot":"","sources":["../../src/lite/announce.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAA0B,uBAAuB,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACzG,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,SAAS,MAAM,CAAC,MAAoB;IACnC,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;IAC/D,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;IAClC,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE,CAAC;QACxB,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;QACnB,MAAM,IAAI,CAAC,CAAC,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E,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;AACpF,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,mEAAmE,EAAE,KAAK,IAAI,EAAE;IACpF,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAC9B,uBAAuB,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,OAAO,CAAC,QAAQ,CAAC,CAC3G,CAAC;IACF,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAEZ,MAAM,MAAM,CAAC,uBAAuB,CAAC,IAAI,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;AACxG,CAAC,CAAC,CAAC","sourcesContent":["import { expect, test } from \"bun:test\";\nimport * as Path from \"../path.ts\";\nimport { Reader, Writer } from \"../stream.ts\";\nimport { type AnnounceBroadcast, decodeAnnounceBroadcast, encodeAnnounceBroadcast } from \"./announce.ts\";\nimport { OriginSchema } from \"./origin.ts\";\nimport { Version } from \"./version.ts\";\n\nfunction concat(chunks: Uint8Array[]): Uint8Array {\n\tconst total = chunks.reduce((sum, c) => sum + c.byteLength, 0);\n\tconst out = new Uint8Array(total);\n\tlet offset = 0;\n\tfor (const c of chunks) {\n\t\tout.set(c, offset);\n\t\toffset += c.byteLength;\n\t}\n\treturn out;\n}\n\nasync function bytes(f: (w: Writer) => Promise<void>): Promise<Uint8Array> {\n\tconst written: Uint8Array[] = [];\n\tconst writer = new Writer(\n\t\tnew WritableStream<Uint8Array>({ write: (chunk) => void written.push(new Uint8Array(chunk)) }),\n\t);\n\tawait f(writer);\n\twriter.close();\n\tawait writer.closed;\n\treturn concat(written);\n}\n\nasync function roundTrip(msg: AnnounceBroadcast, version: Version): Promise<AnnounceBroadcast> {\n\tconst reader = new Reader(undefined, await bytes((w) => encodeAnnounceBroadcast(w, msg, version)));\n\treturn decodeAnnounceBroadcast(reader, version);\n}\n\ntest(\"AnnounceBroadcast round-trips on draft-05\", async () => {\n\tconst hops = [OriginSchema.parse(7n)];\n\tconst gotActive = await roundTrip({ status: \"active\", suffix: Path.from(\"room/cam\"), hops }, Version.DRAFT_05);\n\texpect(gotActive).toEqual({ status: \"active\", suffix: Path.from(\"room/cam\"), hops });\n\n\tconst gotEnded = await roundTrip({ status: \"ended\", suffix: Path.from(\"room/cam\") }, Version.DRAFT_05);\n\texpect(gotEnded).toEqual({ status: \"ended\", suffix: Path.from(\"room/cam\") });\n});\n\ntest(\"AnnounceBroadcast round-trips on draft-06\", async () => {\n\tconst hops = [OriginSchema.parse(7n)];\n\t// An absent cost encodes as zero and decodes explicitly.\n\tconst gotActive = await roundTrip({ status: \"active\", suffix: Path.from(\"room/cam\"), hops }, Version.DRAFT_06);\n\texpect(gotActive).toEqual({ status: \"active\", suffix: Path.from(\"room/cam\"), hops, cost: 0n });\n\n\tconst gotCost = await roundTrip(\n\t\t{ status: \"active\", suffix: Path.from(\"room/cam\"), hops, cost: 12n },\n\t\tVersion.DRAFT_06,\n\t);\n\texpect(gotCost).toEqual({ status: \"active\", suffix: Path.from(\"room/cam\"), hops, cost: 12n });\n\n\tconst gotEnded = await roundTrip({ status: \"endedId\", id: 3n }, Version.DRAFT_06);\n\texpect(gotEnded).toEqual({ status: \"endedId\", id: 3n });\n\n\tconst gotRestart = await roundTrip({ status: \"restart\", id: 3n, hops, cost: 12n }, Version.DRAFT_06);\n\texpect(gotRestart).toEqual({ status: \"restart\", id: 3n, hops, cost: 12n });\n});\n\ntest(\"AnnounceBroadcast drops the route cost before draft-06\", async () => {\n\t// Pre-lite-06 has no room for a cost on the wire, so one set locally is\n\t// simply not sent, keeping mixed-version meshes ranking on hop count.\n\tconst got = await roundTrip(\n\t\t{ status: \"active\", suffix: Path.from(\"room/cam\"), hops: [], cost: 9n },\n\t\tVersion.DRAFT_05,\n\t);\n\texpect(got).toEqual({ status: \"active\", suffix: Path.from(\"room/cam\"), hops: [] });\n});\n\ntest(\"AnnounceBroadcast rejects cross-version forms\", async () => {\n\tawait expect(\n\t\tbytes((w) => encodeAnnounceBroadcast(w, { status: \"endedId\", id: 1n }, Version.DRAFT_05)),\n\t).rejects.toThrow();\n\tawait expect(\n\t\tbytes((w) => encodeAnnounceBroadcast(w, { status: \"restart\", id: 1n, hops: [] }, Version.DRAFT_05)),\n\t).rejects.toThrow();\n\tawait expect(\n\t\tbytes((w) => encodeAnnounceBroadcast(w, { status: \"ended\", suffix: Path.from(\"room/cam\") }, Version.DRAFT_06)),\n\t).rejects.toThrow();\n});\n\ntest(\"AnnounceBroadcast accepts explicit restart status on draft-05\", async () => {\n\tconst wire = await bytes((w) =>\n\t\tencodeAnnounceBroadcast(w, { status: \"active\", suffix: Path.from(\"room/cam\"), hops: [] }, Version.DRAFT_05),\n\t);\n\twire[1] = 2;\n\n\tconst got = await decodeAnnounceBroadcast(new Reader(undefined, wire), Version.DRAFT_05);\n\texpect(got).toEqual({ status: \"active\", suffix: Path.from(\"room/cam\"), hops: [] });\n});\n\ntest(\"AnnounceBroadcast rejects explicit restart status before draft-05\", async () => {\n\tconst wire = await bytes((w) =>\n\t\tencodeAnnounceBroadcast(w, { status: \"active\", suffix: Path.from(\"room/cam\"), hops: [] }, Version.DRAFT_04),\n\t);\n\twire[1] = 2;\n\n\tawait expect(decodeAnnounceBroadcast(new Reader(undefined, wire), Version.DRAFT_04)).rejects.toThrow();\n});\n"]}
|
|
1
|
+
{"version":3,"file":"announce.test.js","sourceRoot":"","sources":["../../src/lite/announce.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,E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,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IACnE,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,YAAY,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;AAC3D,CAAC,CAAC,CAAC","sourcesContent":["import { expect, test } from \"bun:test\";\nimport * as Path from \"../path.ts\";\nimport { Reader, Writer } from \"../stream.ts\";\nimport {\n\ttype AnnounceBroadcast,\n\tAnnounceRequest,\n\tdecodeAnnounceBroadcast,\n\tencodeAnnounceBroadcast,\n} from \"./announce.ts\";\nimport { OriginSchema } from \"./origin.ts\";\nimport { Version } from \"./version.ts\";\n\nfunction concat(chunks: Uint8Array[]): Uint8Array {\n\tconst total = chunks.reduce((sum, c) => sum + c.byteLength, 0);\n\tconst out = new Uint8Array(total);\n\tlet offset = 0;\n\tfor (const c of chunks) {\n\t\tout.set(c, offset);\n\t\toffset += c.byteLength;\n\t}\n\treturn out;\n}\n\nasync function bytes(f: (w: Writer) => Promise<void>): Promise<Uint8Array> {\n\tconst written: Uint8Array[] = [];\n\tconst writer = new Writer(\n\t\tnew WritableStream<Uint8Array>({ write: (chunk) => void written.push(new Uint8Array(chunk)) }),\n\t);\n\tawait f(writer);\n\twriter.close();\n\tawait writer.closed;\n\treturn concat(written);\n}\n\nasync function roundTrip(msg: AnnounceBroadcast, version: Version): Promise<AnnounceBroadcast> {\n\tconst reader = new Reader(undefined, await bytes((w) => encodeAnnounceBroadcast(w, msg, version)));\n\treturn decodeAnnounceBroadcast(reader, version);\n}\n\ntest(\"AnnounceBroadcast round-trips on draft-05\", async () => {\n\tconst hops = [OriginSchema.parse(7n)];\n\tconst gotActive = await roundTrip({ status: \"active\", suffix: Path.from(\"room/cam\"), hops }, Version.DRAFT_05);\n\texpect(gotActive).toEqual({ status: \"active\", suffix: Path.from(\"room/cam\"), hops });\n\n\tconst gotEnded = await roundTrip({ status: \"ended\", suffix: Path.from(\"room/cam\") }, Version.DRAFT_05);\n\texpect(gotEnded).toEqual({ status: \"ended\", suffix: Path.from(\"room/cam\") });\n});\n\ntest(\"AnnounceBroadcast round-trips on draft-06\", async () => {\n\tconst hops = [OriginSchema.parse(7n)];\n\t// An absent cost encodes as zero and decodes explicitly.\n\tconst gotActive = await roundTrip({ status: \"active\", suffix: Path.from(\"room/cam\"), hops }, Version.DRAFT_06);\n\texpect(gotActive).toEqual({ status: \"active\", suffix: Path.from(\"room/cam\"), hops, cost: 0n });\n\n\tconst gotCost = await roundTrip(\n\t\t{ status: \"active\", suffix: Path.from(\"room/cam\"), hops, cost: 12n },\n\t\tVersion.DRAFT_06,\n\t);\n\texpect(gotCost).toEqual({ status: \"active\", suffix: Path.from(\"room/cam\"), hops, cost: 12n });\n\n\tconst gotEnded = await roundTrip({ status: \"endedId\", id: 3n }, Version.DRAFT_06);\n\texpect(gotEnded).toEqual({ status: \"endedId\", id: 3n });\n\n\tconst gotRestart = await roundTrip({ status: \"restart\", id: 3n, hops, cost: 12n }, Version.DRAFT_06);\n\texpect(gotRestart).toEqual({ status: \"restart\", id: 3n, hops, cost: 12n });\n});\n\ntest(\"AnnounceBroadcast drops the route cost before draft-06\", async () => {\n\t// Pre-lite-06 has no room for a cost on the wire, so one set locally is\n\t// simply not sent, keeping mixed-version meshes ranking on hop count.\n\tconst got = await roundTrip(\n\t\t{ status: \"active\", suffix: Path.from(\"room/cam\"), hops: [], cost: 9n },\n\t\tVersion.DRAFT_05,\n\t);\n\texpect(got).toEqual({ status: \"active\", suffix: Path.from(\"room/cam\"), hops: [] });\n});\n\ntest(\"AnnounceBroadcast rejects cross-version forms\", async () => {\n\tawait expect(\n\t\tbytes((w) => encodeAnnounceBroadcast(w, { status: \"endedId\", id: 1n }, Version.DRAFT_05)),\n\t).rejects.toThrow();\n\tawait expect(\n\t\tbytes((w) => encodeAnnounceBroadcast(w, { status: \"restart\", id: 1n, hops: [] }, Version.DRAFT_05)),\n\t).rejects.toThrow();\n\tawait expect(\n\t\tbytes((w) => encodeAnnounceBroadcast(w, { status: \"ended\", suffix: Path.from(\"room/cam\") }, Version.DRAFT_06)),\n\t).rejects.toThrow();\n});\n\ntest(\"AnnounceBroadcast accepts explicit restart status on draft-05\", async () => {\n\tconst wire = await bytes((w) =>\n\t\tencodeAnnounceBroadcast(w, { status: \"active\", suffix: Path.from(\"room/cam\"), hops: [] }, Version.DRAFT_05),\n\t);\n\twire[1] = 2;\n\n\tconst got = await decodeAnnounceBroadcast(new Reader(undefined, wire), Version.DRAFT_05);\n\texpect(got).toEqual({ status: \"active\", suffix: Path.from(\"room/cam\"), hops: [] });\n});\n\ntest(\"AnnounceBroadcast rejects explicit restart status before draft-05\", async () => {\n\tconst wire = await bytes((w) =>\n\t\tencodeAnnounceBroadcast(w, { status: \"active\", suffix: Path.from(\"room/cam\"), hops: [] }, Version.DRAFT_04),\n\t);\n\twire[1] = 2;\n\n\tawait expect(decodeAnnounceBroadcast(new Reader(undefined, wire), Version.DRAFT_04)).rejects.toThrow();\n});\n\nasync function requestRoundTrip(msg: AnnounceRequest, version: Version): Promise<AnnounceRequest> {\n\tconst reader = new Reader(undefined, await bytes((w) => msg.encode(w, version)));\n\treturn AnnounceRequest.decode(reader, version);\n}\n\n// Draft04/05 carry the subscriber's origin id so the publisher can skip reflected\n// announces before they hit the wire.\ntest(\"AnnounceRequest carries excludeHop on draft-05\", async () => {\n\tconst got = await requestRoundTrip(new AnnounceRequest(Path.from(\"room/\"), 42n), Version.DRAFT_05);\n\texpect(got.excludeHop).toBe(42n);\n});\n\n// Draft06 dropped the field: the receiver's reflected-announce check catches the same\n// loops, so a value set locally is simply not sent and decodes as zero.\ntest(\"AnnounceRequest drops excludeHop on draft-06\", async () => {\n\tconst msg = new AnnounceRequest(Path.from(\"room/\"), 42n);\n\tconst got = await requestRoundTrip(msg, Version.DRAFT_06);\n\texpect(got.excludeHop).toBe(0n);\n\n\tconst with05 = await bytes((w) => msg.encode(w, Version.DRAFT_05));\n\tconst with06 = await bytes((w) => msg.encode(w, Version.DRAFT_06));\n\texpect(with06.byteLength).toBeLessThan(with05.byteLength);\n});\n"]}
|
package/lite/connection.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/lite/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAU,MAAM,cAAc,CAAC;AACnD,OAAO,KAAK,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,KAAK,KAAK,EAAE,KAAK,KAAK,EAAkB,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAAE,KAAK,SAAS,EAAe,MAAM,4BAA4B,CAAC;AACzE,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAwB,MAAM,EAAU,MAAM,cAAc,CAAC;AAKpE,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,aAAa,CAAC;AAGxD,OAAO,EAAc,KAAK,IAAI,EAAS,MAAM,YAAY,CAAC;AAK1D,OAAO,EAAgC,KAAK,OAAO,EAAe,MAAM,cAAc,CAAC;AAEvF;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC/B,iCAAiC;IACjC,GAAG,EAAE,GAAG,CAAC;IACT,4CAA4C;IAC5C,IAAI,EAAE,YAAY,CAAC;IACnB,mCAAmC;IACnC,OAAO,EAAE,OAAO,CAAC;IACjB,2DAA2D;IAC3D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,wEAAwE;IACxE,SAAS,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;;GAIG;AACH,qBAAa,UAAW,YAAW,WAAW;;IAE7C,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;IAGlB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAGzB,Q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AAC,KAAK,GAAG,SAAS,CAAC,QAAQ,CAE5C;IA+GD,wEAAwE;IAClE,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC,CAE5B;IAED,IAAI,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAE1B;CACD"}
|
package/lite/connection.js
CHANGED
|
@@ -150,12 +150,13 @@ export class Connection {
|
|
|
150
150
|
// path and leave routing to the URL. We advertise probe = Report (we measure and
|
|
151
151
|
// report bitrate over the PROBE stream, but don't actively pad the connection).
|
|
152
152
|
// Role stays Both: publish/consume are called after this point, so there is nothing
|
|
153
|
-
// to narrow yet.
|
|
153
|
+
// to narrow yet. The origin declares our session identity so the peer can filter
|
|
154
|
+
// reflected announcements (lite-06 removed ANNOUNCE_REQUEST's exclude_hop for it).
|
|
154
155
|
async #sendSetup() {
|
|
155
156
|
const writer = await Writer.open(this.#quic);
|
|
156
157
|
try {
|
|
157
158
|
await writer.u53(DataType.Setup);
|
|
158
|
-
await new Setup({ probe: ProbeLevel.Report }).encode(writer, this.#version);
|
|
159
|
+
await new Setup({ probe: ProbeLevel.Report, origin: this.origin }).encode(writer, this.#version);
|
|
159
160
|
writer.close();
|
|
160
161
|
}
|
|
161
162
|
catch (err) {
|
package/lite/connection.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/lite/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,MAAM,EAAE,MAAM,cAAc,CAAC;AAInD,OAAO,EAA0B,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAAkB,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzE,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAe,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,C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AC;QACL,CAAC;IACF,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,MAAc;QAC3B,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,GAAG,EAAE,CAAC;QAC/B,IAAI,GAAG,KAAK,QAAQ,CAAC,KAAK,EAAE,CAAC;YAC5B,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YACvC,MAAM,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QAC9C,CAAC;aAAM,IAAI,GAAG,KAAK,QAAQ,CAAC,KAAK,EAAE,CAAC;YACnC,6EAA6E;YAC7E,yDAAyD;YACzD,MAAM,KAAK,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;YACxD,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YAC3B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAChC,CAAC;aAAM,CAAC;YACP,MAAM,IAAI,KAAK,CAAC,wBAAwB,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QAC3D,CAAC;IACF,CAAC;IAED,wEAAwE;IACxE,KAAK,CAAC,KAAK;QACV,OAAO,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;IAED,IAAI,MAAM;QACT,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IAChD,CAAC;CACD","sourcesContent":["import { type Getter, Signal } from \"@moq/signals\";\nimport type * as announce from \"../announced.ts\";\nimport type * as broadcast from \"../broadcast.ts\";\nimport type { Established } from \"../connection/established.ts\";\nimport { type Probe, type Stats, transportStats } from \"../connection/stats.ts\";\nimport { type Transport, transportOf } from \"../connection/transport.ts\";\nimport * as Path from \"../path.ts\";\nimport { type Reader, Readers, Stream, Writer } from \"../stream.ts\";\nimport { AnnounceRequest } from \"./announce.ts\";\nimport { Fetch } from \"./fetch.ts\";\nimport { Goaway } from \"./goaway.ts\";\nimport { Group } from \"./group.ts\";\nimport { type Origin, randomOrigin } from \"./origin.ts\";\nimport { Publisher } from \"./publisher.ts\";\nimport { SessionInfo } from \"./session.ts\";\nimport { ProbeLevel, type Role, Setup } from \"./setup.ts\";\nimport { DataType, StreamId } from \"./stream.ts\";\nimport { Subscribe } from \"./subscribe.ts\";\nimport { Subscriber } from \"./subscriber.ts\";\nimport { Track as TrackMessage } from \"./track.ts\";\nimport { hasDatagrams, hasSetupStream, type Version, versionName } from \"./version.ts\";\n\n/**\n * Constructor options for {@link Connection}.\n *\n * @internal\n */\nexport interface ConnectionProps {\n\t/** The URL of the connection. */\n\turl: URL;\n\t/** The established WebTransport session. */\n\tquic: WebTransport;\n\t/** The negotiated wire version. */\n\tversion: Version;\n\t/** The session stream, absent on drafts that have none. */\n\tsession?: Stream;\n\t/** Whether the relay supports broadcast discovery. Defaults to true. */\n\tdiscovery?: boolean;\n}\n\n/**\n * Represents a connection to a MoQ server.\n *\n * @public\n */\nexport class Connection implements Established {\n\t// The URL of the connection.\n\treadonly url: URL;\n\n\t// The version of the connection as a human-readable string.\n\treadonly version: string;\n\n\t// The wire transport this session runs over.\n\treadonly transport: Transport;\n\n\t/** Whether the relay supports broadcast discovery; see {@link Established.discovery}. */\n\treadonly discovery: boolean;\n\n\t// The version used for encoding/decoding.\n\t#version: Version;\n\n\t// The established WebTransport session.\n\t#quic: WebTransport;\n\n\t// Use to receive/send session messages.\n\t#session?: Stream;\n\n\t// Module for contributing tracks.\n\t#publisher: Publisher;\n\n\t// Module for distributing tracks.\n\t#subscriber: Subscriber;\n\n\t/** The peer's PROBE estimates; see {@link Established.probe}. */\n\treadonly probe: Getter<Probe>;\n\n\t/** Random per-connection origin id. Shared by Publisher (for outbound hop\n\t * chains) and Subscriber (available for optional self-filtering on announces). */\n\treadonly origin: Origin;\n\n\t// The peer's SETUP, recorded once its Setup stream is read (lite-05+). Streams whose\n\t// encoding depends on a negotiated capability (e.g. PROBE) wait on this. undefined\n\t// until the peer's SETUP arrives; stays undefined forever on older drafts.\n\t#peerSetup = new Signal<Setup | undefined>(undefined);\n\n\t// Mirrors the role out of #peerSetup, so the public surface exposes the peer's declared\n\t// direction without handing out the whole SETUP (whose probe level gates our own streams).\n\t#peerRole = new Signal<Role | undefined>(undefined);\n\n\t// Written by the Subscriber as PROBE messages arrive.\n\t#probe = new Signal<Probe>({});\n\n\t/**\n\t * The {@link Role} the peer advertised in its SETUP, for a server deciding whether the\n\t * peer's authorization grants the direction it intends to use.\n\t *\n\t * `undefined` until the peer's SETUP arrives, and forever on pre-lite-05 versions, which\n\t * carry no in-band role. {@link Role.Both} is the absence of the parameter, so it is what\n\t * a peer reports when it declines to declare a direction, sends a value we don't\n\t * recognize, or is a server (which never sends one).\n\t */\n\tget peerRole(): Getter<Role | undefined> {\n\t\treturn this.#peerRole;\n\t}\n\n\t/**\n\t * Creates a new Connection instance.\n\t *\n\t * @internal\n\t */\n\tconstructor({ url, quic, version, session, discovery = true }: ConnectionProps) {\n\t\tthis.url = url;\n\t\tthis.#quic = quic;\n\t\tthis.#session = session;\n\t\tthis.version = versionName(version);\n\t\tthis.#version = version;\n\t\tthis.transport = transportOf(quic);\n\t\tthis.discovery = discovery;\n\n\t\tthis.probe = this.#probe;\n\n\t\tthis.origin = randomOrigin();\n\t\tthis.#publisher = new Publisher(this.#quic, this.#version, this.origin);\n\t\tthis.#subscriber = new Subscriber(this.#quic, this.#version, this.origin, this.#probe, this.#peerSetup);\n\n\t\tvoid this.#run();\n\t}\n\n\t/**\n\t * Closes the connection.\n\t */\n\tclose() {\n\t\tthis.#publisher.close();\n\t\tthis.#subscriber.close();\n\n\t\ttry {\n\t\t\t// TODO: For whatever reason, this try/catch doesn't seem to work..?\n\t\t\tthis.#quic.close();\n\t\t} catch {\n\t\t\t// ignore\n\t\t}\n\t}\n\n\tasync #run(): Promise<void> {\n\t\tconst tasks: Promise<void>[] = [this.#runSession(), this.#runBidis(), this.#runUnis()];\n\n\t\tif (hasSetupStream(this.#version)) {\n\t\t\ttasks.push(this.#sendSetup());\n\t\t}\n\n\t\ttasks.push(this.#subscriber.runProbe());\n\n\t\t// Route incoming QUIC datagrams into their subscriptions (lite-05+; runDatagrams\n\t\t// no-ops on a transport that doesn't carry them).\n\t\tif (hasDatagrams(this.#version)) {\n\t\t\ttasks.push(this.#subscriber.runDatagrams());\n\t\t}\n\n\t\ttry {\n\t\t\tawait Promise.all(tasks);\n\t\t} catch (err) {\n\t\t\tconsole.error(\"fatal error running connection\", err);\n\t\t} finally {\n\t\t\tthis.close();\n\t\t}\n\t}\n\n\tpublish(path: Path.Valid, producer: broadcast.Producer) {\n\t\tthis.#publisher.publish(path, producer);\n\t}\n\n\tannounced(prefix = Path.empty()): announce.Consumer {\n\t\treturn this.#subscriber.announced(prefix);\n\t}\n\n\tconsume(path: Path.Valid): broadcast.Consumer {\n\t\treturn this.#subscriber.consume(path);\n\t}\n\n\tasync #runSession() {\n\t\tif (!this.#session) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tfor (;;) {\n\t\t\t\tconst msg = await SessionInfo.decodeMaybe(this.#session.reader, this.#version);\n\t\t\t\tif (!msg) break;\n\t\t\t}\n\t\t} finally {\n\t\t\tconsole.debug(\"session stream closed\");\n\t\t}\n\t}\n\n\t// Open the unidirectional Setup Stream, send our single SETUP, and FIN (lite-05+).\n\t// The browser uses WebTransport, which carries the request URI, so we advertise no\n\t// path and leave routing to the URL. We advertise probe = Report (we measure and\n\t// report bitrate over the PROBE stream, but don't actively pad the connection).\n\t// Role stays Both: publish/consume are called after this point, so there is nothing\n\t// to narrow yet.\n\tasync #sendSetup(): Promise<void> {\n\t\tconst writer = await Writer.open(this.#quic);\n\t\ttry {\n\t\t\tawait writer.u53(DataType.Setup);\n\t\t\tawait new Setup({ probe: ProbeLevel.Report }).encode(writer, this.#version);\n\t\t\twriter.close();\n\t\t} catch (err: unknown) {\n\t\t\twriter.reset(err);\n\t\t\tthrow err;\n\t\t}\n\t}\n\n\tasync #runBidis() {\n\t\tfor (;;) {\n\t\t\tconst stream = await Stream.accept(this.#quic);\n\t\t\tif (!stream) break;\n\n\t\t\tthis.#runBidi(stream)\n\t\t\t\t.catch((err: unknown) => {\n\t\t\t\t\tstream.writer.reset(err);\n\t\t\t\t})\n\t\t\t\t.finally(() => {\n\t\t\t\t\tstream.writer.close();\n\t\t\t\t});\n\t\t}\n\t}\n\n\tasync #runBidi(stream: Stream) {\n\t\tconst typ = await stream.reader.u53();\n\n\t\tif (typ === StreamId.Session) {\n\t\t\tthrow new Error(\"duplicate session stream\");\n\t\t} else if (typ === StreamId.Announce) {\n\t\t\tconst msg = await AnnounceRequest.decode(stream.reader, this.#version);\n\t\t\tawait this.#publisher.runAnnounce(msg, stream);\n\t\t} else if (typ === StreamId.Subscribe) {\n\t\t\tconst msg = await Subscribe.decode(stream.reader, this.#version);\n\t\t\tawait this.#publisher.runSubscribe(msg, stream);\n\t\t} else if (typ === StreamId.Fetch) {\n\t\t\tconst msg = await Fetch.decode(stream.reader, this.#version);\n\t\t\tawait this.#publisher.runFetch(msg, stream);\n\t\t} else if (typ === StreamId.Track) {\n\t\t\tconst msg = await TrackMessage.decode(stream.reader, this.#version);\n\t\t\tawait this.#publisher.runTrackInfo(msg, stream);\n\t\t} else if (typ === StreamId.Probe) {\n\t\t\tawait this.#publisher.runProbe(stream);\n\t\t} else if (typ === StreamId.Goaway) {\n\t\t\tconst msg = await Goaway.decode(stream.reader, this.#version);\n\t\t\tconsole.info(\"received goaway:\", msg.uri);\n\t\t} else {\n\t\t\tthrow new Error(`unknown stream type: ${typ.toString()}`);\n\t\t}\n\t}\n\n\tasync #runUnis() {\n\t\tconst readers = new Readers(this.#quic);\n\n\t\tfor (;;) {\n\t\t\tconst stream = await readers.next();\n\t\t\tif (!stream) break;\n\n\t\t\tthis.#runUni(stream)\n\t\t\t\t.then(() => {\n\t\t\t\t\tstream.stop(new Error(\"cancel\"));\n\t\t\t\t})\n\t\t\t\t.catch((err: unknown) => {\n\t\t\t\t\tstream.stop(err);\n\t\t\t\t});\n\t\t}\n\t}\n\n\tasync #runUni(stream: Reader) {\n\t\tconst typ = await stream.u53();\n\t\tif (typ === DataType.Group) {\n\t\t\tconst msg = await Group.decode(stream);\n\t\t\tawait this.#subscriber.runGroup(msg, stream);\n\t\t} else if (typ === DataType.Setup) {\n\t\t\t// The peer sends exactly one SETUP, then FINs. Record it so capability-gated\n\t\t\t// streams (e.g. PROBE) can react, then drain to the FIN.\n\t\t\tconst setup = await Setup.decode(stream, this.#version);\n\t\t\tthis.#peerSetup.set(setup);\n\t\t\tthis.#peerRole.set(setup.role);\n\t\t} else {\n\t\t\tthrow new Error(`unknown stream type: ${typ.toString()}`);\n\t\t}\n\t}\n\n\t/** Snapshot the transport's counters; see {@link Established.stats}. */\n\tasync stats(): Promise<Stats> {\n\t\treturn transportStats(this.#quic);\n\t}\n\n\tget closed(): Promise<void> {\n\t\treturn this.#quic.closed.then(() => undefined);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/lite/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,MAAM,EAAE,MAAM,cAAc,CAAC;AAInD,OAAO,EAA0B,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAAkB,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzE,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAe,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,K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C;IAED,KAAK,CAAC,OAAO,CAAC,MAAc;QAC3B,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,GAAG,EAAE,CAAC;QAC/B,IAAI,GAAG,KAAK,QAAQ,CAAC,KAAK,EAAE,CAAC;YAC5B,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YACvC,MAAM,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QAC9C,CAAC;aAAM,IAAI,GAAG,KAAK,QAAQ,CAAC,KAAK,EAAE,CAAC;YACnC,6EAA6E;YAC7E,yDAAyD;YACzD,MAAM,KAAK,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;YACxD,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YAC3B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAChC,CAAC;aAAM,CAAC;YACP,MAAM,IAAI,KAAK,CAAC,wBAAwB,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QAC3D,CAAC;IACF,CAAC;IAED,wEAAwE;IACxE,KAAK,CAAC,KAAK;QACV,OAAO,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;IAED,IAAI,MAAM;QACT,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IAChD,CAAC;CACD","sourcesContent":["import { type Getter, Signal } from \"@moq/signals\";\nimport type * as announce from \"../announced.ts\";\nimport type * as broadcast from \"../broadcast.ts\";\nimport type { Established } from \"../connection/established.ts\";\nimport { type Probe, type Stats, transportStats } from \"../connection/stats.ts\";\nimport { type Transport, transportOf } from \"../connection/transport.ts\";\nimport * as Path from \"../path.ts\";\nimport { type Reader, Readers, Stream, Writer } from \"../stream.ts\";\nimport { AnnounceRequest } from \"./announce.ts\";\nimport { Fetch } from \"./fetch.ts\";\nimport { Goaway } from \"./goaway.ts\";\nimport { Group } from \"./group.ts\";\nimport { type Origin, randomOrigin } from \"./origin.ts\";\nimport { Publisher } from \"./publisher.ts\";\nimport { SessionInfo } from \"./session.ts\";\nimport { ProbeLevel, type Role, Setup } from \"./setup.ts\";\nimport { DataType, StreamId } from \"./stream.ts\";\nimport { Subscribe } from \"./subscribe.ts\";\nimport { Subscriber } from \"./subscriber.ts\";\nimport { Track as TrackMessage } from \"./track.ts\";\nimport { hasDatagrams, hasSetupStream, type Version, versionName } from \"./version.ts\";\n\n/**\n * Constructor options for {@link Connection}.\n *\n * @internal\n */\nexport interface ConnectionProps {\n\t/** The URL of the connection. */\n\turl: URL;\n\t/** The established WebTransport session. */\n\tquic: WebTransport;\n\t/** The negotiated wire version. */\n\tversion: Version;\n\t/** The session stream, absent on drafts that have none. */\n\tsession?: Stream;\n\t/** Whether the relay supports broadcast discovery. Defaults to true. */\n\tdiscovery?: boolean;\n}\n\n/**\n * Represents a connection to a MoQ server.\n *\n * @public\n */\nexport class Connection implements Established {\n\t// The URL of the connection.\n\treadonly url: URL;\n\n\t// The version of the connection as a human-readable string.\n\treadonly version: string;\n\n\t// The wire transport this session runs over.\n\treadonly transport: Transport;\n\n\t/** Whether the relay supports broadcast discovery; see {@link Established.discovery}. */\n\treadonly discovery: boolean;\n\n\t// The version used for encoding/decoding.\n\t#version: Version;\n\n\t// The established WebTransport session.\n\t#quic: WebTransport;\n\n\t// Use to receive/send session messages.\n\t#session?: Stream;\n\n\t// Module for contributing tracks.\n\t#publisher: Publisher;\n\n\t// Module for distributing tracks.\n\t#subscriber: Subscriber;\n\n\t/** The peer's PROBE estimates; see {@link Established.probe}. */\n\treadonly probe: Getter<Probe>;\n\n\t/** Random per-connection origin id. Shared by Publisher (for outbound hop\n\t * chains) and Subscriber (available for optional self-filtering on announces). */\n\treadonly origin: Origin;\n\n\t// The peer's SETUP, recorded once its Setup stream is read (lite-05+). Streams whose\n\t// encoding depends on a negotiated capability (e.g. PROBE) wait on this. undefined\n\t// until the peer's SETUP arrives; stays undefined forever on older drafts.\n\t#peerSetup = new Signal<Setup | undefined>(undefined);\n\n\t// Mirrors the role out of #peerSetup, so the public surface exposes the peer's declared\n\t// direction without handing out the whole SETUP (whose probe level gates our own streams).\n\t#peerRole = new Signal<Role | undefined>(undefined);\n\n\t// Written by the Subscriber as PROBE messages arrive.\n\t#probe = new Signal<Probe>({});\n\n\t/**\n\t * The {@link Role} the peer advertised in its SETUP, for a server deciding whether the\n\t * peer's authorization grants the direction it intends to use.\n\t *\n\t * `undefined` until the peer's SETUP arrives, and forever on pre-lite-05 versions, which\n\t * carry no in-band role. {@link Role.Both} is the absence of the parameter, so it is what\n\t * a peer reports when it declines to declare a direction, sends a value we don't\n\t * recognize, or is a server (which never sends one).\n\t */\n\tget peerRole(): Getter<Role | undefined> {\n\t\treturn this.#peerRole;\n\t}\n\n\t/**\n\t * Creates a new Connection instance.\n\t *\n\t * @internal\n\t */\n\tconstructor({ url, quic, version, session, discovery = true }: ConnectionProps) {\n\t\tthis.url = url;\n\t\tthis.#quic = quic;\n\t\tthis.#session = session;\n\t\tthis.version = versionName(version);\n\t\tthis.#version = version;\n\t\tthis.transport = transportOf(quic);\n\t\tthis.discovery = discovery;\n\n\t\tthis.probe = this.#probe;\n\n\t\tthis.origin = randomOrigin();\n\t\tthis.#publisher = new Publisher(this.#quic, this.#version, this.origin);\n\t\tthis.#subscriber = new Subscriber(this.#quic, this.#version, this.origin, this.#probe, this.#peerSetup);\n\n\t\tvoid this.#run();\n\t}\n\n\t/**\n\t * Closes the connection.\n\t */\n\tclose() {\n\t\tthis.#publisher.close();\n\t\tthis.#subscriber.close();\n\n\t\ttry {\n\t\t\t// TODO: For whatever reason, this try/catch doesn't seem to work..?\n\t\t\tthis.#quic.close();\n\t\t} catch {\n\t\t\t// ignore\n\t\t}\n\t}\n\n\tasync #run(): Promise<void> {\n\t\tconst tasks: Promise<void>[] = [this.#runSession(), this.#runBidis(), this.#runUnis()];\n\n\t\tif (hasSetupStream(this.#version)) {\n\t\t\ttasks.push(this.#sendSetup());\n\t\t}\n\n\t\ttasks.push(this.#subscriber.runProbe());\n\n\t\t// Route incoming QUIC datagrams into their subscriptions (lite-05+; runDatagrams\n\t\t// no-ops on a transport that doesn't carry them).\n\t\tif (hasDatagrams(this.#version)) {\n\t\t\ttasks.push(this.#subscriber.runDatagrams());\n\t\t}\n\n\t\ttry {\n\t\t\tawait Promise.all(tasks);\n\t\t} catch (err) {\n\t\t\tconsole.error(\"fatal error running connection\", err);\n\t\t} finally {\n\t\t\tthis.close();\n\t\t}\n\t}\n\n\tpublish(path: Path.Valid, producer: broadcast.Producer) {\n\t\tthis.#publisher.publish(path, producer);\n\t}\n\n\tannounced(prefix = Path.empty()): announce.Consumer {\n\t\treturn this.#subscriber.announced(prefix);\n\t}\n\n\tconsume(path: Path.Valid): broadcast.Consumer {\n\t\treturn this.#subscriber.consume(path);\n\t}\n\n\tasync #runSession() {\n\t\tif (!this.#session) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tfor (;;) {\n\t\t\t\tconst msg = await SessionInfo.decodeMaybe(this.#session.reader, this.#version);\n\t\t\t\tif (!msg) break;\n\t\t\t}\n\t\t} finally {\n\t\t\tconsole.debug(\"session stream closed\");\n\t\t}\n\t}\n\n\t// Open the unidirectional Setup Stream, send our single SETUP, and FIN (lite-05+).\n\t// The browser uses WebTransport, which carries the request URI, so we advertise no\n\t// path and leave routing to the URL. We advertise probe = Report (we measure and\n\t// report bitrate over the PROBE stream, but don't actively pad the connection).\n\t// Role stays Both: publish/consume are called after this point, so there is nothing\n\t// to narrow yet. The origin declares our session identity so the peer can filter\n\t// reflected announcements (lite-06 removed ANNOUNCE_REQUEST's exclude_hop for it).\n\tasync #sendSetup(): Promise<void> {\n\t\tconst writer = await Writer.open(this.#quic);\n\t\ttry {\n\t\t\tawait writer.u53(DataType.Setup);\n\t\t\tawait new Setup({ probe: ProbeLevel.Report, origin: this.origin }).encode(writer, this.#version);\n\t\t\twriter.close();\n\t\t} catch (err: unknown) {\n\t\t\twriter.reset(err);\n\t\t\tthrow err;\n\t\t}\n\t}\n\n\tasync #runBidis() {\n\t\tfor (;;) {\n\t\t\tconst stream = await Stream.accept(this.#quic);\n\t\t\tif (!stream) break;\n\n\t\t\tthis.#runBidi(stream)\n\t\t\t\t.catch((err: unknown) => {\n\t\t\t\t\tstream.writer.reset(err);\n\t\t\t\t})\n\t\t\t\t.finally(() => {\n\t\t\t\t\tstream.writer.close();\n\t\t\t\t});\n\t\t}\n\t}\n\n\tasync #runBidi(stream: Stream) {\n\t\tconst typ = await stream.reader.u53();\n\n\t\tif (typ === StreamId.Session) {\n\t\t\tthrow new Error(\"duplicate session stream\");\n\t\t} else if (typ === StreamId.Announce) {\n\t\t\tconst msg = await AnnounceRequest.decode(stream.reader, this.#version);\n\t\t\tawait this.#publisher.runAnnounce(msg, stream);\n\t\t} else if (typ === StreamId.Subscribe) {\n\t\t\tconst msg = await Subscribe.decode(stream.reader, this.#version);\n\t\t\tawait this.#publisher.runSubscribe(msg, stream);\n\t\t} else if (typ === StreamId.Fetch) {\n\t\t\tconst msg = await Fetch.decode(stream.reader, this.#version);\n\t\t\tawait this.#publisher.runFetch(msg, stream);\n\t\t} else if (typ === StreamId.Track) {\n\t\t\tconst msg = await TrackMessage.decode(stream.reader, this.#version);\n\t\t\tawait this.#publisher.runTrackInfo(msg, stream);\n\t\t} else if (typ === StreamId.Probe) {\n\t\t\tawait this.#publisher.runProbe(stream);\n\t\t} else if (typ === StreamId.Goaway) {\n\t\t\tconst msg = await Goaway.decode(stream.reader, this.#version);\n\t\t\tconsole.info(\"received goaway:\", msg.uri);\n\t\t} else {\n\t\t\tthrow new Error(`unknown stream type: ${typ.toString()}`);\n\t\t}\n\t}\n\n\tasync #runUnis() {\n\t\tconst readers = new Readers(this.#quic);\n\n\t\tfor (;;) {\n\t\t\tconst stream = await readers.next();\n\t\t\tif (!stream) break;\n\n\t\t\tthis.#runUni(stream)\n\t\t\t\t.then(() => {\n\t\t\t\t\tstream.stop(new Error(\"cancel\"));\n\t\t\t\t})\n\t\t\t\t.catch((err: unknown) => {\n\t\t\t\t\tstream.stop(err);\n\t\t\t\t});\n\t\t}\n\t}\n\n\tasync #runUni(stream: Reader) {\n\t\tconst typ = await stream.u53();\n\t\tif (typ === DataType.Group) {\n\t\t\tconst msg = await Group.decode(stream);\n\t\t\tawait this.#subscriber.runGroup(msg, stream);\n\t\t} else if (typ === DataType.Setup) {\n\t\t\t// The peer sends exactly one SETUP, then FINs. Record it so capability-gated\n\t\t\t// streams (e.g. PROBE) can react, then drain to the FIN.\n\t\t\tconst setup = await Setup.decode(stream, this.#version);\n\t\t\tthis.#peerSetup.set(setup);\n\t\t\tthis.#peerRole.set(setup.role);\n\t\t} else {\n\t\t\tthrow new Error(`unknown stream type: ${typ.toString()}`);\n\t\t}\n\t}\n\n\t/** Snapshot the transport's counters; see {@link Established.stats}. */\n\tasync stats(): Promise<Stats> {\n\t\treturn transportStats(this.#quic);\n\t}\n\n\tget closed(): Promise<void> {\n\t\treturn this.#quic.closed.then(() => undefined);\n\t}\n}\n"]}
|
package/lite/setup.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* @module
|
|
6
6
|
*/
|
|
7
7
|
import type { Reader, Writer } from "../stream";
|
|
8
|
+
import { type Origin } from "./origin";
|
|
8
9
|
import { type Version } from "./version";
|
|
9
10
|
/**
|
|
10
11
|
* The probe capability an endpoint advertises in SETUP.
|
|
@@ -50,6 +51,8 @@ export interface SetupProps {
|
|
|
50
51
|
path?: string;
|
|
51
52
|
/** See {@link Setup.role}. Defaults to {@link Role.Both}. */
|
|
52
53
|
role?: Role;
|
|
54
|
+
/** See {@link Setup.origin}. Omitted by default. */
|
|
55
|
+
origin?: Origin;
|
|
53
56
|
}
|
|
54
57
|
/**
|
|
55
58
|
* The SETUP message, sent once per endpoint on the unidirectional Setup Stream.
|
|
@@ -75,7 +78,14 @@ export declare class Setup {
|
|
|
75
78
|
* never sends one and a relay never forwards it.
|
|
76
79
|
*/
|
|
77
80
|
role: Role;
|
|
78
|
-
|
|
81
|
+
/**
|
|
82
|
+
* This endpoint's origin (hop) id. The peer uses it to filter announcements and
|
|
83
|
+
* subscriptions whose route flows through this endpoint (lite-06 removed the
|
|
84
|
+
* per-stream `exclude_hop` in its favor). `undefined` when the endpoint declares
|
|
85
|
+
* no identity; a wire value of 0 decodes the same way.
|
|
86
|
+
*/
|
|
87
|
+
origin?: Origin;
|
|
88
|
+
constructor({ probe, path, role, origin }?: SetupProps);
|
|
79
89
|
/** Encode the SETUP message with its size prefix. Throws on pre-lite-05 versions. */
|
|
80
90
|
encode(w: Writer, version: Version): Promise<void>;
|
|
81
91
|
/** Decode a SETUP message with its size prefix. Throws on pre-lite-05 versions. */
|
package/lite/setup.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/lite/setup.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAGnD,OAAO,EAAkB,KAAK,OAAO,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/lite/setup.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAGnD,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,aAAa,CAAC;AACxD,OAAO,EAAkB,KAAK,OAAO,EAAE,MAAM,cAAc,CAAC;AAc5D;;;;;;GAMG;AACH,eAAO,MAAM,UAAU;IACtB,wDAAwD;aACxD,IAAI,EAAE,CAAC;IACP,+EAA+E;aAC/E,MAAM,EA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G/D;CACD"}
|
package/lite/setup.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import * as Varint from "../varint.js";
|
|
9
9
|
import * as Message from "./message.js";
|
|
10
|
+
import { OriginSchema } from "./origin.js";
|
|
10
11
|
import { hasSetupStream } from "./version.js";
|
|
11
12
|
/** Setup Parameter id for the Probe capability level. */
|
|
12
13
|
const PARAM_PROBE = 0x1n;
|
|
@@ -14,6 +15,8 @@ const PARAM_PROBE = 0x1n;
|
|
|
14
15
|
const PARAM_PATH = 0x2n;
|
|
15
16
|
/** Setup Parameter id for the client's intended {@link Role} (client-only). */
|
|
16
17
|
const PARAM_ROLE = 0x3n;
|
|
18
|
+
/** Setup Parameter id for the endpoint's origin (hop) id. */
|
|
19
|
+
const PARAM_ORIGIN = 0x5n;
|
|
17
20
|
/** Cap on the number of parameters in a bag, matching the Rust decoder. */
|
|
18
21
|
const MAX_PARAMS = 64;
|
|
19
22
|
/**
|
|
@@ -157,10 +160,18 @@ export class Setup {
|
|
|
157
160
|
* never sends one and a relay never forwards it.
|
|
158
161
|
*/
|
|
159
162
|
role;
|
|
160
|
-
|
|
163
|
+
/**
|
|
164
|
+
* This endpoint's origin (hop) id. The peer uses it to filter announcements and
|
|
165
|
+
* subscriptions whose route flows through this endpoint (lite-06 removed the
|
|
166
|
+
* per-stream `exclude_hop` in its favor). `undefined` when the endpoint declares
|
|
167
|
+
* no identity; a wire value of 0 decodes the same way.
|
|
168
|
+
*/
|
|
169
|
+
origin;
|
|
170
|
+
constructor({ probe, path, role, origin } = {}) {
|
|
161
171
|
this.probe = probe ?? ProbeLevel.None;
|
|
162
172
|
this.path = path;
|
|
163
173
|
this.role = role ?? Role.Both;
|
|
174
|
+
this.origin = origin;
|
|
164
175
|
}
|
|
165
176
|
static #guard(version) {
|
|
166
177
|
if (!hasSetupStream(version)) {
|
|
@@ -180,6 +191,9 @@ export class Setup {
|
|
|
180
191
|
if (this.role !== Role.Both) {
|
|
181
192
|
params.setVarint(PARAM_ROLE, this.role);
|
|
182
193
|
}
|
|
194
|
+
if (this.origin !== undefined && this.origin !== 0n) {
|
|
195
|
+
params.setVarint(PARAM_ORIGIN, this.origin);
|
|
196
|
+
}
|
|
183
197
|
await params.encode(w);
|
|
184
198
|
}
|
|
185
199
|
static async #decode(r) {
|
|
@@ -192,7 +206,10 @@ export class Setup {
|
|
|
192
206
|
const path = pathBytes === undefined ? undefined : new TextDecoder().decode(pathBytes);
|
|
193
207
|
const roleCode = params.getVarint(PARAM_ROLE);
|
|
194
208
|
const role = roleCode === undefined ? Role.Both : roleFromCode(roleCode);
|
|
195
|
-
|
|
209
|
+
// 0 carries no identity (it cannot be excluded), so it decodes as absent.
|
|
210
|
+
const originRaw = params.getVarint(PARAM_ORIGIN);
|
|
211
|
+
const origin = originRaw === undefined || originRaw === 0n ? undefined : OriginSchema.parse(originRaw);
|
|
212
|
+
return new Setup({ probe, path, role, origin });
|
|
196
213
|
}
|
|
197
214
|
/** Encode the SETUP message with its size prefix. Throws on pre-lite-05 versions. */
|
|
198
215
|
async encode(w, version) {
|
package/lite/setup.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../../src/lite/setup.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,cAAc,EAAgB,MAAM,cAAc,CAAC;AAE5D,yDAAyD;AACzD,MAAM,WAAW,GAAG,IAAI,CAAC;AACzB,kFAAkF;AAClF,MAAM,UAAU,GAAG,IAAI,CAAC;AACxB,+EAA+E;AAC/E,MAAM,UAAU,GAAG,IAAI,CAAC;AAExB,2EAA2E;AAC3E,MAAM,UAAU,GAAG,EAAE,CAAC;AAEtB;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG;IACzB,wDAAwD;IACxD,IAAI,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U,CAAC,CAAC;QAC9C,MAAM,IAAI,GAAG,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;QAEzE,OAAO,IAAI,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IACzC,CAAC;IAED,qFAAqF;IACrF,KAAK,CAAC,MAAM,CAAC,CAAS,EAAE,OAAgB;QACvC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACtB,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACnD,CAAC;IAED,mFAAmF;IACnF,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAS,EAAE,OAAgB;QAC9C,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACtB,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;CACD","sourcesContent":["/**\n * The lite-05 SETUP message: each endpoint advertises its capabilities once, as the\n * sole message on a unidirectional Setup Stream ({@link DataType.Setup}), then closes it.\n *\n * @module\n */\n\nimport type { Reader, Writer } from \"../stream.ts\";\nimport * as Varint from \"../varint.ts\";\nimport * as Message from \"./message.ts\";\nimport { hasSetupStream, type Version } from \"./version.ts\";\n\n/** Setup Parameter id for the Probe capability level. */\nconst PARAM_PROBE = 0x1n;\n/** Setup Parameter id for the request Path (client-only, URI-less transports). */\nconst PARAM_PATH = 0x2n;\n/** Setup Parameter id for the client's intended {@link Role} (client-only). */\nconst PARAM_ROLE = 0x3n;\n\n/** Cap on the number of parameters in a bag, matching the Rust decoder. */\nconst MAX_PARAMS = 64;\n\n/**\n * The probe capability an endpoint advertises in SETUP.\n *\n * Monotonic: a higher level implies every lower one. An unknown (future) value\n * decodes as the highest level we understand, so a peer that gains a new level is\n * treated as at least {@link ProbeLevel.Increase}.\n */\nexport const ProbeLevel = {\n\t/** No probing. Equivalent to omitting the parameter. */\n\tNone: 0,\n\t/** The publisher can measure and periodically report its estimated bitrate. */\n\tReport: 1,\n\t/** The publisher can additionally pad the connection (or send redundant data). */\n\tIncrease: 2,\n} as const;\n\n/** A probe capability level. See {@link ProbeLevel}. */\nexport type ProbeLevel = (typeof ProbeLevel)[keyof typeof ProbeLevel];\n\n/** Map a wire value to a level, saturating unknown values to {@link ProbeLevel.Increase}. */\nfunction probeFromCode(code: bigint): ProbeLevel {\n\tswitch (code) {\n\t\tcase 0n:\n\t\t\treturn ProbeLevel.None;\n\t\tcase 1n:\n\t\t\treturn ProbeLevel.Report;\n\t\tdefault:\n\t\t\treturn ProbeLevel.Increase;\n\t}\n}\n\n/**\n * The direction a client intends to use the session for.\n *\n * A client advertises this in its SETUP so the server can reject a token that lacks the\n * matching scope during the handshake, instead of accepting a session that then silently\n * carries no media (a subscribe-only token used to publish, or vice versa). It only ever\n * narrows what the server grants, so it is not a security boundary: the server still\n * enforces the token's scope regardless.\n */\nexport const Role = {\n\t/** The client may do either, or declined to say. Equivalent to omitting the parameter. */\n\tBoth: 0,\n\t/** The client will publish tracks (ingest); the server must consume. */\n\tPublisher: 1,\n\t/** The client will subscribe to tracks (egress); the server must publish. */\n\tSubscriber: 2,\n} as const;\n\n/** A session role. See {@link Role}. */\nexport type Role = (typeof Role)[keyof typeof Role];\n\n/**\n * Map a wire value to a role, falling back to {@link Role.Both}.\n *\n * The draft requires a receiver that does not recognize the value to treat it as `Both`,\n * so a newer client can't break an older server: it just loses the early reject and defers\n * to the token's scope.\n */\nfunction roleFromCode(code: bigint): Role {\n\tswitch (code) {\n\t\tcase 1n:\n\t\t\treturn Role.Publisher;\n\t\tcase 2n:\n\t\t\treturn Role.Subscriber;\n\t\tdefault:\n\t\t\treturn Role.Both;\n\t}\n}\n\n/**\n * A bag of `id -> raw bytes` parameters, the body shared by SETUP. Encoded as a varint\n * count followed by `id, length, value` triples; duplicate ids are rejected on decode.\n */\nclass Parameters {\n\t#entries = new Map<bigint, Uint8Array>();\n\n\t/** Set a parameter to a raw byte value, replacing any existing entry. */\n\tsetBytes(id: bigint, value: Uint8Array) {\n\t\tthis.#entries.set(id, value);\n\t}\n\n\t/** Return a parameter's raw byte value, if present. */\n\tgetBytes(id: bigint): Uint8Array | undefined {\n\t\treturn this.#entries.get(id);\n\t}\n\n\t/** Set a parameter to a varint value, replacing any existing entry. */\n\tsetVarint(id: bigint, value: number | bigint) {\n\t\tthis.#entries.set(id, Varint.encode(Number(value)));\n\t}\n\n\t/** Decode a parameter as a single varint, if present. Throws if trailing bytes remain. */\n\tgetVarint(id: bigint): bigint | undefined {\n\t\tconst bytes = this.#entries.get(id);\n\t\tif (bytes === undefined) return undefined;\n\t\tconst [value, remain] = Varint.decode(bytes);\n\t\tif (remain.byteLength !== 0) {\n\t\t\tthrow new Error(\"trailing bytes after varint parameter\");\n\t\t}\n\t\treturn BigInt(value);\n\t}\n\n\tasync encode(w: Writer) {\n\t\tif (this.#entries.size > MAX_PARAMS) {\n\t\t\tthrow new Error(\"too many parameters\");\n\t\t}\n\n\t\tawait w.u53(this.#entries.size);\n\t\tfor (const [id, value] of this.#entries) {\n\t\t\tawait w.u62(id);\n\t\t\tawait w.u53(value.byteLength);\n\t\t\tawait w.write(value);\n\t\t}\n\t}\n\n\tstatic async decode(r: Reader): Promise<Parameters> {\n\t\tconst params = new Parameters();\n\n\t\tconst count = await r.u53();\n\t\tif (count > MAX_PARAMS) {\n\t\t\tthrow new Error(\"too many parameters\");\n\t\t}\n\n\t\tfor (let i = 0; i < count; i++) {\n\t\t\tconst id = await r.u62();\n\t\t\tif (params.#entries.has(id)) {\n\t\t\t\tthrow new Error(`duplicate parameter id: ${id.toString()}`);\n\t\t\t}\n\t\t\tconst size = await r.u53();\n\t\t\tconst value = await r.read(size);\n\t\t\tparams.#entries.set(id, value);\n\t\t}\n\n\t\treturn params;\n\t}\n}\n\n/** The capabilities a {@link Setup} advertises. Each defaults to the wire default, which is the absence of the parameter. */\nexport interface SetupProps {\n\t/** See {@link Setup.probe}. Defaults to {@link ProbeLevel.None}. */\n\tprobe?: ProbeLevel;\n\t/** See {@link Setup.path}. Omitted by default. */\n\tpath?: string;\n\t/** See {@link Setup.role}. Defaults to {@link Role.Both}. */\n\trole?: Role;\n}\n\n/**\n * The SETUP message, sent once per endpoint on the unidirectional Setup Stream.\n *\n * lite-05+ only. The two endpoints' SETUP messages are independent: neither side\n * blocks on the peer's before opening other streams, but a stream whose encoding\n * depends on a negotiated capability (e.g. PROBE) must wait for it.\n */\nexport class Setup {\n\t/** The probe capability this endpoint supports. {@link ProbeLevel.None} when absent. */\n\tprobe: ProbeLevel;\n\n\t/**\n\t * The request path, for transports that carry no request URI (native QUIC, qmux over\n\t * TCP/TLS, unix sockets). Sent only by the client; a server never sends one and a relay\n\t * never forwards it. `undefined` on URI-carrying bindings such as WebTransport, where\n\t * sending one is a protocol violation. An empty string means the same as `undefined`.\n\t */\n\tpath?: string;\n\n\t/**\n\t * The client's intended {@link Role}. `Both` is sent as the absence of the parameter, so\n\t * a client that never sets it decodes back to `Both`. Sent only by the client; a server\n\t * never sends one and a relay never forwards it.\n\t */\n\trole: Role;\n\n\tconstructor({ probe, path, role }: SetupProps = {}) {\n\t\tthis.probe = probe ?? ProbeLevel.None;\n\t\tthis.path = path;\n\t\tthis.role = role ?? Role.Both;\n\t}\n\n\tstatic #guard(version: Version) {\n\t\tif (!hasSetupStream(version)) {\n\t\t\tthrow new Error(\"setup stream not supported for this version\");\n\t\t}\n\t}\n\n\tasync #encode(w: Writer) {\n\t\tconst params = new Parameters();\n\t\t// None is the wire default, so omit it to keep the message empty when nothing is set.\n\t\tif (this.probe !== ProbeLevel.None) {\n\t\t\tparams.setVarint(PARAM_PROBE, this.probe);\n\t\t}\n\t\tif (this.path !== undefined) {\n\t\t\tparams.setBytes(PARAM_PATH, new TextEncoder().encode(this.path));\n\t\t}\n\t\t// Both is the wire default, sent as the absence of the parameter.\n\t\tif (this.role !== Role.Both) {\n\t\t\tparams.setVarint(PARAM_ROLE, this.role);\n\t\t}\n\t\tawait params.encode(w);\n\t}\n\n\tstatic async #decode(r: Reader): Promise<Setup> {\n\t\tconst params = await Parameters.decode(r);\n\n\t\tconst probeCode = params.getVarint(PARAM_PROBE);\n\t\tconst probe = probeCode === undefined ? ProbeLevel.None : probeFromCode(probeCode);\n\n\t\t// An empty path is valid and means the same as omitting the parameter, so a\n\t\t// client that wants the root doesn't have to special-case it.\n\t\tconst pathBytes = params.getBytes(PARAM_PATH);\n\t\tconst path = pathBytes === undefined ? undefined : new TextDecoder().decode(pathBytes);\n\n\t\tconst roleCode = params.getVarint(PARAM_ROLE);\n\t\tconst role = roleCode === undefined ? Role.Both : roleFromCode(roleCode);\n\n\t\treturn new Setup({ probe, path, role });\n\t}\n\n\t/** Encode the SETUP message with its size prefix. Throws on pre-lite-05 versions. */\n\tasync encode(w: Writer, version: Version): Promise<void> {\n\t\tSetup.#guard(version);\n\t\treturn Message.encode(w, this.#encode.bind(this));\n\t}\n\n\t/** Decode a SETUP message with its size prefix. Throws on pre-lite-05 versions. */\n\tstatic async decode(r: Reader, version: Version): Promise<Setup> {\n\t\tSetup.#guard(version);\n\t\treturn Message.decode(r, Setup.#decode);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../../src/lite/setup.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,EAAe,YAAY,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,cAAc,EAAgB,MAAM,cAAc,CAAC;AAE5D,yDAAyD;AACzD,MAAM,WAAW,GAAG,IAAI,CAAC;AACzB,kFAAkF;AAClF,MAAM,UAAU,GAAG,IAAI,CAAC;AACxB,+EAA+E;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AC,KAAK,CAAC,MAAM,CAAC,CAAS,EAAE,OAAgB;QAC9C,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACtB,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;CACD","sourcesContent":["/**\n * The lite-05 SETUP message: each endpoint advertises its capabilities once, as the\n * sole message on a unidirectional Setup Stream ({@link DataType.Setup}), then closes it.\n *\n * @module\n */\n\nimport type { Reader, Writer } from \"../stream.ts\";\nimport * as Varint from \"../varint.ts\";\nimport * as Message from \"./message.ts\";\nimport { type Origin, OriginSchema } from \"./origin.ts\";\nimport { hasSetupStream, type Version } from \"./version.ts\";\n\n/** Setup Parameter id for the Probe capability level. */\nconst PARAM_PROBE = 0x1n;\n/** Setup Parameter id for the request Path (client-only, URI-less transports). */\nconst PARAM_PATH = 0x2n;\n/** Setup Parameter id for the client's intended {@link Role} (client-only). */\nconst PARAM_ROLE = 0x3n;\n/** Setup Parameter id for the endpoint's origin (hop) id. */\nconst PARAM_ORIGIN = 0x5n;\n\n/** Cap on the number of parameters in a bag, matching the Rust decoder. */\nconst MAX_PARAMS = 64;\n\n/**\n * The probe capability an endpoint advertises in SETUP.\n *\n * Monotonic: a higher level implies every lower one. An unknown (future) value\n * decodes as the highest level we understand, so a peer that gains a new level is\n * treated as at least {@link ProbeLevel.Increase}.\n */\nexport const ProbeLevel = {\n\t/** No probing. Equivalent to omitting the parameter. */\n\tNone: 0,\n\t/** The publisher can measure and periodically report its estimated bitrate. */\n\tReport: 1,\n\t/** The publisher can additionally pad the connection (or send redundant data). */\n\tIncrease: 2,\n} as const;\n\n/** A probe capability level. See {@link ProbeLevel}. */\nexport type ProbeLevel = (typeof ProbeLevel)[keyof typeof ProbeLevel];\n\n/** Map a wire value to a level, saturating unknown values to {@link ProbeLevel.Increase}. */\nfunction probeFromCode(code: bigint): ProbeLevel {\n\tswitch (code) {\n\t\tcase 0n:\n\t\t\treturn ProbeLevel.None;\n\t\tcase 1n:\n\t\t\treturn ProbeLevel.Report;\n\t\tdefault:\n\t\t\treturn ProbeLevel.Increase;\n\t}\n}\n\n/**\n * The direction a client intends to use the session for.\n *\n * A client advertises this in its SETUP so the server can reject a token that lacks the\n * matching scope during the handshake, instead of accepting a session that then silently\n * carries no media (a subscribe-only token used to publish, or vice versa). It only ever\n * narrows what the server grants, so it is not a security boundary: the server still\n * enforces the token's scope regardless.\n */\nexport const Role = {\n\t/** The client may do either, or declined to say. Equivalent to omitting the parameter. */\n\tBoth: 0,\n\t/** The client will publish tracks (ingest); the server must consume. */\n\tPublisher: 1,\n\t/** The client will subscribe to tracks (egress); the server must publish. */\n\tSubscriber: 2,\n} as const;\n\n/** A session role. See {@link Role}. */\nexport type Role = (typeof Role)[keyof typeof Role];\n\n/**\n * Map a wire value to a role, falling back to {@link Role.Both}.\n *\n * The draft requires a receiver that does not recognize the value to treat it as `Both`,\n * so a newer client can't break an older server: it just loses the early reject and defers\n * to the token's scope.\n */\nfunction roleFromCode(code: bigint): Role {\n\tswitch (code) {\n\t\tcase 1n:\n\t\t\treturn Role.Publisher;\n\t\tcase 2n:\n\t\t\treturn Role.Subscriber;\n\t\tdefault:\n\t\t\treturn Role.Both;\n\t}\n}\n\n/**\n * A bag of `id -> raw bytes` parameters, the body shared by SETUP. Encoded as a varint\n * count followed by `id, length, value` triples; duplicate ids are rejected on decode.\n */\nclass Parameters {\n\t#entries = new Map<bigint, Uint8Array>();\n\n\t/** Set a parameter to a raw byte value, replacing any existing entry. */\n\tsetBytes(id: bigint, value: Uint8Array) {\n\t\tthis.#entries.set(id, value);\n\t}\n\n\t/** Return a parameter's raw byte value, if present. */\n\tgetBytes(id: bigint): Uint8Array | undefined {\n\t\treturn this.#entries.get(id);\n\t}\n\n\t/** Set a parameter to a varint value, replacing any existing entry. */\n\tsetVarint(id: bigint, value: number | bigint) {\n\t\tthis.#entries.set(id, Varint.encode(Number(value)));\n\t}\n\n\t/** Decode a parameter as a single varint, if present. Throws if trailing bytes remain. */\n\tgetVarint(id: bigint): bigint | undefined {\n\t\tconst bytes = this.#entries.get(id);\n\t\tif (bytes === undefined) return undefined;\n\t\tconst [value, remain] = Varint.decode(bytes);\n\t\tif (remain.byteLength !== 0) {\n\t\t\tthrow new Error(\"trailing bytes after varint parameter\");\n\t\t}\n\t\treturn BigInt(value);\n\t}\n\n\tasync encode(w: Writer) {\n\t\tif (this.#entries.size > MAX_PARAMS) {\n\t\t\tthrow new Error(\"too many parameters\");\n\t\t}\n\n\t\tawait w.u53(this.#entries.size);\n\t\tfor (const [id, value] of this.#entries) {\n\t\t\tawait w.u62(id);\n\t\t\tawait w.u53(value.byteLength);\n\t\t\tawait w.write(value);\n\t\t}\n\t}\n\n\tstatic async decode(r: Reader): Promise<Parameters> {\n\t\tconst params = new Parameters();\n\n\t\tconst count = await r.u53();\n\t\tif (count > MAX_PARAMS) {\n\t\t\tthrow new Error(\"too many parameters\");\n\t\t}\n\n\t\tfor (let i = 0; i < count; i++) {\n\t\t\tconst id = await r.u62();\n\t\t\tif (params.#entries.has(id)) {\n\t\t\t\tthrow new Error(`duplicate parameter id: ${id.toString()}`);\n\t\t\t}\n\t\t\tconst size = await r.u53();\n\t\t\tconst value = await r.read(size);\n\t\t\tparams.#entries.set(id, value);\n\t\t}\n\n\t\treturn params;\n\t}\n}\n\n/** The capabilities a {@link Setup} advertises. Each defaults to the wire default, which is the absence of the parameter. */\nexport interface SetupProps {\n\t/** See {@link Setup.probe}. Defaults to {@link ProbeLevel.None}. */\n\tprobe?: ProbeLevel;\n\t/** See {@link Setup.path}. Omitted by default. */\n\tpath?: string;\n\t/** See {@link Setup.role}. Defaults to {@link Role.Both}. */\n\trole?: Role;\n\t/** See {@link Setup.origin}. Omitted by default. */\n\torigin?: Origin;\n}\n\n/**\n * The SETUP message, sent once per endpoint on the unidirectional Setup Stream.\n *\n * lite-05+ only. The two endpoints' SETUP messages are independent: neither side\n * blocks on the peer's before opening other streams, but a stream whose encoding\n * depends on a negotiated capability (e.g. PROBE) must wait for it.\n */\nexport class Setup {\n\t/** The probe capability this endpoint supports. {@link ProbeLevel.None} when absent. */\n\tprobe: ProbeLevel;\n\n\t/**\n\t * The request path, for transports that carry no request URI (native QUIC, qmux over\n\t * TCP/TLS, unix sockets). Sent only by the client; a server never sends one and a relay\n\t * never forwards it. `undefined` on URI-carrying bindings such as WebTransport, where\n\t * sending one is a protocol violation. An empty string means the same as `undefined`.\n\t */\n\tpath?: string;\n\n\t/**\n\t * The client's intended {@link Role}. `Both` is sent as the absence of the parameter, so\n\t * a client that never sets it decodes back to `Both`. Sent only by the client; a server\n\t * never sends one and a relay never forwards it.\n\t */\n\trole: Role;\n\n\t/**\n\t * This endpoint's origin (hop) id. The peer uses it to filter announcements and\n\t * subscriptions whose route flows through this endpoint (lite-06 removed the\n\t * per-stream `exclude_hop` in its favor). `undefined` when the endpoint declares\n\t * no identity; a wire value of 0 decodes the same way.\n\t */\n\torigin?: Origin;\n\n\tconstructor({ probe, path, role, origin }: SetupProps = {}) {\n\t\tthis.probe = probe ?? ProbeLevel.None;\n\t\tthis.path = path;\n\t\tthis.role = role ?? Role.Both;\n\t\tthis.origin = origin;\n\t}\n\n\tstatic #guard(version: Version) {\n\t\tif (!hasSetupStream(version)) {\n\t\t\tthrow new Error(\"setup stream not supported for this version\");\n\t\t}\n\t}\n\n\tasync #encode(w: Writer) {\n\t\tconst params = new Parameters();\n\t\t// None is the wire default, so omit it to keep the message empty when nothing is set.\n\t\tif (this.probe !== ProbeLevel.None) {\n\t\t\tparams.setVarint(PARAM_PROBE, this.probe);\n\t\t}\n\t\tif (this.path !== undefined) {\n\t\t\tparams.setBytes(PARAM_PATH, new TextEncoder().encode(this.path));\n\t\t}\n\t\t// Both is the wire default, sent as the absence of the parameter.\n\t\tif (this.role !== Role.Both) {\n\t\t\tparams.setVarint(PARAM_ROLE, this.role);\n\t\t}\n\t\tif (this.origin !== undefined && this.origin !== 0n) {\n\t\t\tparams.setVarint(PARAM_ORIGIN, this.origin);\n\t\t}\n\t\tawait params.encode(w);\n\t}\n\n\tstatic async #decode(r: Reader): Promise<Setup> {\n\t\tconst params = await Parameters.decode(r);\n\n\t\tconst probeCode = params.getVarint(PARAM_PROBE);\n\t\tconst probe = probeCode === undefined ? ProbeLevel.None : probeFromCode(probeCode);\n\n\t\t// An empty path is valid and means the same as omitting the parameter, so a\n\t\t// client that wants the root doesn't have to special-case it.\n\t\tconst pathBytes = params.getBytes(PARAM_PATH);\n\t\tconst path = pathBytes === undefined ? undefined : new TextDecoder().decode(pathBytes);\n\n\t\tconst roleCode = params.getVarint(PARAM_ROLE);\n\t\tconst role = roleCode === undefined ? Role.Both : roleFromCode(roleCode);\n\n\t\t// 0 carries no identity (it cannot be excluded), so it decodes as absent.\n\t\tconst originRaw = params.getVarint(PARAM_ORIGIN);\n\t\tconst origin = originRaw === undefined || originRaw === 0n ? undefined : OriginSchema.parse(originRaw);\n\n\t\treturn new Setup({ probe, path, role, origin });\n\t}\n\n\t/** Encode the SETUP message with its size prefix. Throws on pre-lite-05 versions. */\n\tasync encode(w: Writer, version: Version): Promise<void> {\n\t\tSetup.#guard(version);\n\t\treturn Message.encode(w, this.#encode.bind(this));\n\t}\n\n\t/** Decode a SETUP message with its size prefix. Throws on pre-lite-05 versions. */\n\tstatic async decode(r: Reader, version: Version): Promise<Setup> {\n\t\tSetup.#guard(version);\n\t\treturn Message.decode(r, Setup.#decode);\n\t}\n}\n"]}
|
package/lite/setup.test.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { expect, test } from "bun:test";
|
|
3
3
|
import { Reader, Writer } from "../stream.js";
|
|
4
4
|
import * as Varint from "../varint.js";
|
|
5
|
+
import { OriginSchema } from "./origin.js";
|
|
5
6
|
import { ProbeLevel, Role, Setup } from "./setup.js";
|
|
6
7
|
import { Version } from "./version.js";
|
|
7
8
|
// Parameter ids, duplicated from setup.ts so a typo there fails a test rather than
|
|
@@ -9,6 +10,7 @@ import { Version } from "./version.js";
|
|
|
9
10
|
const PARAM_PROBE = 0x1n;
|
|
10
11
|
const PARAM_PATH = 0x2n;
|
|
11
12
|
const PARAM_ROLE = 0x3n;
|
|
13
|
+
const PARAM_ORIGIN = 0x5n;
|
|
12
14
|
function concat(chunks) {
|
|
13
15
|
const total = chunks.reduce((sum, c) => sum + c.byteLength, 0);
|
|
14
16
|
const out = new Uint8Array(total);
|
|
@@ -107,6 +109,16 @@ test("unknown probe level saturates to Increase", async () => {
|
|
|
107
109
|
const got = await decodeParam(PARAM_PROBE, Varint.encode(99));
|
|
108
110
|
expect(got.probe).toBe(ProbeLevel.Increase);
|
|
109
111
|
});
|
|
112
|
+
test("SETUP with origin round-trips", async () => {
|
|
113
|
+
const origin = OriginSchema.parse(42n);
|
|
114
|
+
const got = await roundTrip(new Setup({ origin }));
|
|
115
|
+
expect(got.origin).toBe(origin);
|
|
116
|
+
});
|
|
117
|
+
test("origin 0 decodes as absent", async () => {
|
|
118
|
+
// 0 carries no identity (it cannot be excluded), so it decodes as undefined.
|
|
119
|
+
const got = await decodeParam(PARAM_ORIGIN, Varint.encode(0));
|
|
120
|
+
expect(got.origin).toBeUndefined();
|
|
121
|
+
});
|
|
110
122
|
test("SETUP is rejected before draft-05", async () => {
|
|
111
123
|
await expect(bytes((w) => new Setup().encode(w, Version.DRAFT_04))).rejects.toThrow();
|
|
112
124
|
});
|
package/lite/setup.test.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup.test.js","sourceRoot":"","sources":["../../src/lite/setup.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAA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AAG,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;AAC7C,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,mCAAmC,EAAE,KAAK,IAAI,EAAE;IACpD,MAAM,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;AACvF,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,0CAA0C,EAAE,KAAK,IAAI,EAAE;IAC3D,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC3E,MAAM,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;AAC/F,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,gCAAgC,EAAE,KAAK,IAAI,EAAE;IACjD,8DAA8D;IAC9D,MAAM,GAAG,GAAG,MAAM,WAAW,CAAC,UAAU,EAAE,IAAI,UAAU,EAAE,CAAC,CAAC;IAC5D,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC3B,CAAC,CAAC,CAAC","sourcesContent":["import { expect, test } from \"bun:test\";\nimport { Reader, Writer } from \"../stream.ts\";\nimport * as Varint from \"../varint.ts\";\nimport { ProbeLevel, Role, Setup } from \"./setup.ts\";\nimport { Version } from \"./version.ts\";\n\n// Parameter ids, duplicated from setup.ts so a typo there fails a test rather than\n// silently agreeing with itself.\nconst PARAM_PROBE = 0x1n;\nconst PARAM_PATH = 0x2n;\nconst PARAM_ROLE = 0x3n;\n\nfunction concat(chunks: Uint8Array[]): Uint8Array {\n\tconst total = chunks.reduce((sum, c) => sum + c.byteLength, 0);\n\tconst out = new Uint8Array(total);\n\tlet offset = 0;\n\tfor (const c of chunks) {\n\t\tout.set(c, offset);\n\t\toffset += c.byteLength;\n\t}\n\treturn out;\n}\n\nasync function bytes(f: (w: Writer) => Promise<void>): Promise<Uint8Array> {\n\tconst written: Uint8Array[] = [];\n\tconst writer = new Writer(\n\t\tnew WritableStream<Uint8Array>({ write: (chunk) => void written.push(new Uint8Array(chunk)) }),\n\t);\n\tawait f(writer);\n\twriter.close();\n\tawait writer.closed;\n\treturn concat(written);\n}\n\nasync function roundTrip(msg: Setup): Promise<Setup> {\n\tconst reader = new Reader(undefined, await bytes((w) => msg.encode(w, Version.DRAFT_05)));\n\tconst got = await Setup.decode(reader, Version.DRAFT_05);\n\texpect(await reader.done()).toBe(true);\n\treturn got;\n}\n\n// Hand-frame a SETUP carrying a single raw parameter, so we can feed the decoder values\n// our own encoder would never produce (unknown levels, empty paths).\nasync function decodeParam(id: bigint, value: Uint8Array): Promise<Setup> {\n\tconst body = await bytes(async (w) => {\n\t\tawait w.u53(1); // parameter count\n\t\tawait w.u62(id);\n\t\tawait w.u53(value.byteLength);\n\t\tif (value.byteLength > 0) await w.write(value);\n\t});\n\n\tconst framed = await bytes(async (w) => {\n\t\tawait w.u53(body.byteLength); // Message size prefix\n\t\tawait w.write(body);\n\t});\n\n\treturn await Setup.decode(new Reader(undefined, framed), Version.DRAFT_05);\n}\n\ntest(\"empty SETUP round-trips on draft-05\", async () => {\n\tconst got = await roundTrip(new Setup());\n\texpect(got.probe).toBe(ProbeLevel.None);\n\texpect(got.path).toBeUndefined();\n\texpect(got.role).toBe(Role.Both);\n});\n\ntest(\"each probe level round-trips on draft-05\", async () => {\n\tfor (const probe of [ProbeLevel.None, ProbeLevel.Report, ProbeLevel.Increase]) {\n\t\tconst got = await roundTrip(new Setup({ probe }));\n\t\texpect(got.probe).toBe(probe);\n\t\texpect(got.path).toBeUndefined();\n\t}\n});\n\ntest(\"SETUP with path round-trips on draft-05\", async () => {\n\tconst got = await roundTrip(new Setup({ probe: ProbeLevel.Report, path: \"/room/123\" }));\n\texpect(got.probe).toBe(ProbeLevel.Report);\n\texpect(got.path).toBe(\"/room/123\");\n});\n\ntest(\"each role round-trips on draft-05\", async () => {\n\tfor (const role of [Role.Both, Role.Publisher, Role.Subscriber]) {\n\t\tconst got = await roundTrip(new Setup({ role }));\n\t\texpect(got.role).toBe(role);\n\t}\n});\n\ntest(\"SETUP carries role alongside probe and path\", async () => {\n\tconst got = await roundTrip(new Setup({ probe: ProbeLevel.Increase, path: \"/room/123\", role: Role.Publisher }));\n\texpect(got.probe).toBe(ProbeLevel.Increase);\n\texpect(got.path).toBe(\"/room/123\");\n\texpect(got.role).toBe(Role.Publisher);\n});\n\ntest(\"Both is the wire default, so it is omitted rather than encoded\", async () => {\n\t// Both must be the absence of the parameter, so a server that predates it decodes a\n\t// Both client back to Both. Assert the empty bag directly: comparing against another\n\t// default-constructed Setup would agree with itself even if we encoded Both.\n\tconst both = await bytes((w) => new Setup({ role: Role.Both }).encode(w, Version.DRAFT_05));\n\tconst emptyBag = await bytes(async (w) => {\n\t\tawait w.u53(1); // Message size prefix: one byte of body follows\n\t\tawait w.u53(0); // parameter count\n\t});\n\texpect(both).toEqual(emptyBag);\n\n\t// A directional role is still encoded, so the check above can actually fail.\n\tconst publisher = await bytes((w) => new Setup({ role: Role.Publisher }).encode(w, Version.DRAFT_05));\n\texpect(publisher.byteLength).toBeGreaterThan(both.byteLength);\n});\n\ntest(\"unknown role falls back to Both\", async () => {\n\t// Hand-frame a SETUP carrying an unrecognized role (99). The draft requires a receiver\n\t// that doesn't know the value to treat it as Both, so a newer client can't break us.\n\tconst got = await decodeParam(PARAM_ROLE, Varint.encode(99));\n\texpect(got.role).toBe(Role.Both);\n});\n\ntest(\"role 0 decodes as Both\", async () => {\n\tconst got = await decodeParam(PARAM_ROLE, Varint.encode(0));\n\texpect(got.role).toBe(Role.Both);\n});\n\ntest(\"unknown probe level saturates to Increase\", async () => {\n\tconst got = await decodeParam(PARAM_PROBE, Varint.encode(99));\n\texpect(got.probe).toBe(ProbeLevel.Increase);\n});\n\ntest(\"SETUP is rejected before draft-05\", async () => {\n\tawait expect(bytes((w) => new Setup().encode(w, Version.DRAFT_04))).rejects.toThrow();\n});\n\ntest(\"SETUP decode is rejected before draft-05\", async () => {\n\tconst framed = await bytes((w) => new Setup().encode(w, Version.DRAFT_05));\n\tawait expect(Setup.decode(new Reader(undefined, framed), Version.DRAFT_04)).rejects.toThrow();\n});\n\ntest(\"empty path decodes as the root\", async () => {\n\t// Valid on the wire and equivalent to omitting the parameter.\n\tconst got = await decodeParam(PARAM_PATH, new Uint8Array());\n\texpect(got.path).toBe(\"\");\n});\n"]}
|
|
1
|
+
{"version":3,"file":"setup.test.js","sourceRoot":"","sources":["../../src/lite/setup.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,mFAAmF;AACnF,iCAAiC;AACjC,MAAM,WAAW,GAAG,IAAI,CAAC;AACzB,MAAM,UAAU,GAAG,IAAI,CAAC;AACxB,MAAM,UAAU,GAAG,IAAI,CAAC;AACxB,MAAM,YAAY,GAAG,IAAI,CAAC;AAE1B,SAAS,MAAM,CAAC,MAAoB;IACnC,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,C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C;IAC5D,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC3B,CAAC,CAAC,CAAC","sourcesContent":["import { expect, test } from \"bun:test\";\nimport { Reader, Writer } from \"../stream.ts\";\nimport * as Varint from \"../varint.ts\";\nimport { OriginSchema } from \"./origin.ts\";\nimport { ProbeLevel, Role, Setup } from \"./setup.ts\";\nimport { Version } from \"./version.ts\";\n\n// Parameter ids, duplicated from setup.ts so a typo there fails a test rather than\n// silently agreeing with itself.\nconst PARAM_PROBE = 0x1n;\nconst PARAM_PATH = 0x2n;\nconst PARAM_ROLE = 0x3n;\nconst PARAM_ORIGIN = 0x5n;\n\nfunction concat(chunks: Uint8Array[]): Uint8Array {\n\tconst total = chunks.reduce((sum, c) => sum + c.byteLength, 0);\n\tconst out = new Uint8Array(total);\n\tlet offset = 0;\n\tfor (const c of chunks) {\n\t\tout.set(c, offset);\n\t\toffset += c.byteLength;\n\t}\n\treturn out;\n}\n\nasync function bytes(f: (w: Writer) => Promise<void>): Promise<Uint8Array> {\n\tconst written: Uint8Array[] = [];\n\tconst writer = new Writer(\n\t\tnew WritableStream<Uint8Array>({ write: (chunk) => void written.push(new Uint8Array(chunk)) }),\n\t);\n\tawait f(writer);\n\twriter.close();\n\tawait writer.closed;\n\treturn concat(written);\n}\n\nasync function roundTrip(msg: Setup): Promise<Setup> {\n\tconst reader = new Reader(undefined, await bytes((w) => msg.encode(w, Version.DRAFT_05)));\n\tconst got = await Setup.decode(reader, Version.DRAFT_05);\n\texpect(await reader.done()).toBe(true);\n\treturn got;\n}\n\n// Hand-frame a SETUP carrying a single raw parameter, so we can feed the decoder values\n// our own encoder would never produce (unknown levels, empty paths).\nasync function decodeParam(id: bigint, value: Uint8Array): Promise<Setup> {\n\tconst body = await bytes(async (w) => {\n\t\tawait w.u53(1); // parameter count\n\t\tawait w.u62(id);\n\t\tawait w.u53(value.byteLength);\n\t\tif (value.byteLength > 0) await w.write(value);\n\t});\n\n\tconst framed = await bytes(async (w) => {\n\t\tawait w.u53(body.byteLength); // Message size prefix\n\t\tawait w.write(body);\n\t});\n\n\treturn await Setup.decode(new Reader(undefined, framed), Version.DRAFT_05);\n}\n\ntest(\"empty SETUP round-trips on draft-05\", async () => {\n\tconst got = await roundTrip(new Setup());\n\texpect(got.probe).toBe(ProbeLevel.None);\n\texpect(got.path).toBeUndefined();\n\texpect(got.role).toBe(Role.Both);\n});\n\ntest(\"each probe level round-trips on draft-05\", async () => {\n\tfor (const probe of [ProbeLevel.None, ProbeLevel.Report, ProbeLevel.Increase]) {\n\t\tconst got = await roundTrip(new Setup({ probe }));\n\t\texpect(got.probe).toBe(probe);\n\t\texpect(got.path).toBeUndefined();\n\t}\n});\n\ntest(\"SETUP with path round-trips on draft-05\", async () => {\n\tconst got = await roundTrip(new Setup({ probe: ProbeLevel.Report, path: \"/room/123\" }));\n\texpect(got.probe).toBe(ProbeLevel.Report);\n\texpect(got.path).toBe(\"/room/123\");\n});\n\ntest(\"each role round-trips on draft-05\", async () => {\n\tfor (const role of [Role.Both, Role.Publisher, Role.Subscriber]) {\n\t\tconst got = await roundTrip(new Setup({ role }));\n\t\texpect(got.role).toBe(role);\n\t}\n});\n\ntest(\"SETUP carries role alongside probe and path\", async () => {\n\tconst got = await roundTrip(new Setup({ probe: ProbeLevel.Increase, path: \"/room/123\", role: Role.Publisher }));\n\texpect(got.probe).toBe(ProbeLevel.Increase);\n\texpect(got.path).toBe(\"/room/123\");\n\texpect(got.role).toBe(Role.Publisher);\n});\n\ntest(\"Both is the wire default, so it is omitted rather than encoded\", async () => {\n\t// Both must be the absence of the parameter, so a server that predates it decodes a\n\t// Both client back to Both. Assert the empty bag directly: comparing against another\n\t// default-constructed Setup would agree with itself even if we encoded Both.\n\tconst both = await bytes((w) => new Setup({ role: Role.Both }).encode(w, Version.DRAFT_05));\n\tconst emptyBag = await bytes(async (w) => {\n\t\tawait w.u53(1); // Message size prefix: one byte of body follows\n\t\tawait w.u53(0); // parameter count\n\t});\n\texpect(both).toEqual(emptyBag);\n\n\t// A directional role is still encoded, so the check above can actually fail.\n\tconst publisher = await bytes((w) => new Setup({ role: Role.Publisher }).encode(w, Version.DRAFT_05));\n\texpect(publisher.byteLength).toBeGreaterThan(both.byteLength);\n});\n\ntest(\"unknown role falls back to Both\", async () => {\n\t// Hand-frame a SETUP carrying an unrecognized role (99). The draft requires a receiver\n\t// that doesn't know the value to treat it as Both, so a newer client can't break us.\n\tconst got = await decodeParam(PARAM_ROLE, Varint.encode(99));\n\texpect(got.role).toBe(Role.Both);\n});\n\ntest(\"role 0 decodes as Both\", async () => {\n\tconst got = await decodeParam(PARAM_ROLE, Varint.encode(0));\n\texpect(got.role).toBe(Role.Both);\n});\n\ntest(\"unknown probe level saturates to Increase\", async () => {\n\tconst got = await decodeParam(PARAM_PROBE, Varint.encode(99));\n\texpect(got.probe).toBe(ProbeLevel.Increase);\n});\n\ntest(\"SETUP with origin round-trips\", async () => {\n\tconst origin = OriginSchema.parse(42n);\n\tconst got = await roundTrip(new Setup({ origin }));\n\texpect(got.origin).toBe(origin);\n});\n\ntest(\"origin 0 decodes as absent\", async () => {\n\t// 0 carries no identity (it cannot be excluded), so it decodes as undefined.\n\tconst got = await decodeParam(PARAM_ORIGIN, Varint.encode(0));\n\texpect(got.origin).toBeUndefined();\n});\n\ntest(\"SETUP is rejected before draft-05\", async () => {\n\tawait expect(bytes((w) => new Setup().encode(w, Version.DRAFT_04))).rejects.toThrow();\n});\n\ntest(\"SETUP decode is rejected before draft-05\", async () => {\n\tconst framed = await bytes((w) => new Setup().encode(w, Version.DRAFT_05));\n\tawait expect(Setup.decode(new Reader(undefined, framed), Version.DRAFT_04)).rejects.toThrow();\n});\n\ntest(\"empty path decodes as the root\", async () => {\n\t// Valid on the wire and equivalent to omitting the parameter.\n\tconst got = await decodeParam(PARAM_PATH, new Uint8Array());\n\texpect(got.path).toBe(\"\");\n});\n"]}
|
package/lite/subscriber.d.ts
CHANGED
|
@@ -20,6 +20,10 @@ export interface AnnouncedOptions {
|
|
|
20
20
|
* to false for backwards compatibility: existing code (notably hang.live)
|
|
21
21
|
* relies on seeing its own publishes as the signal that a namespace
|
|
22
22
|
* published successfully.
|
|
23
|
+
*
|
|
24
|
+
* Only meaningful on lite-04/05, where the peer filters reflected announces
|
|
25
|
+
* on request (ANNOUNCE_REQUEST's `Exclude Hop`). Later versions dropped that
|
|
26
|
+
* field, so reflected announces are always skipped.
|
|
23
27
|
*/
|
|
24
28
|
ignoreSelf?: boolean;
|
|
25
29
|
}
|
package/lite/subscriber.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscriber.d.ts","sourceRoot":"","sources":["../../src/lite/subscriber.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAC7C,OAAO,KAAK,EAAE,KAAK,IAAI,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAGlE,OAAO,KAAK,QAAQ,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,KAAK,MAAM,EAAU,MAAM,cAAc,CAAC;AAEnD,OAAO,KAAK,KAAK,KAAK,MAAM,aAAa,CAAC;AAM1C,OAAO,KAAK,EAAE,KAAK,IAAI,YAAY,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAc,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAIpD,OAAO,
|
|
1
|
+
{"version":3,"file":"subscriber.d.ts","sourceRoot":"","sources":["../../src/lite/subscriber.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,QAAQ,MAAM,iBA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AAC,KAAK,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAKhF;IAID,UAAU,CACT,SAAS,EAAE,IAAI,CAAC,KAAK,EACrB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,KAAK,CAAC,iBAAsB,GACnC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAgB5B;IA6ID;;;;;;OAMG;IACG,QAAQ,CAAC,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,iBA4DjD;IAED;;;;;;;;OAQG;IACG,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC,CAkClC;IAwCK,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAqC9B;IAED,KAAK,SAQJ;CACD"}
|
package/lite/subscriber.js
CHANGED
|
@@ -18,7 +18,7 @@ import { ProbeLevel } from "./setup.js";
|
|
|
18
18
|
import { StreamId } from "./stream.js";
|
|
19
19
|
import { decodeSubscribeResponse, decodeSubscribeResponseMaybe, Subscribe, SubscribeUpdate } from "./subscribe.js";
|
|
20
20
|
import { TrackInfo, Track as TrackMessage } from "./track.js";
|
|
21
|
-
import { hasAnnounceId, hasAnnounceOk, hasDatagrams, Version } from "./version.js";
|
|
21
|
+
import { hasAnnounceId, hasAnnounceOk, hasDatagrams, hasExcludeHop, Version } from "./version.js";
|
|
22
22
|
// Bound on how long stream-open plus the first response (SUBSCRIBE_OK on older
|
|
23
23
|
// drafts, or TRACK_INFO on lite-05+) may take. Browsers cap concurrent QUIC
|
|
24
24
|
// streams (Chrome ~100); past the cap createBidirectionalStream silently blocks.
|
|
@@ -100,10 +100,17 @@ export class Subscriber {
|
|
|
100
100
|
}
|
|
101
101
|
async #runAnnounced(announced, prefix, options) {
|
|
102
102
|
console.debug(`announced: prefix=${prefix}`);
|
|
103
|
-
//
|
|
104
|
-
// whose hop chain already passed through us.
|
|
105
|
-
//
|
|
103
|
+
// Lite04/05: send our own session-level origin id so the peer can skip announces
|
|
104
|
+
// whose hop chain already passed through us. Encoding drops it on every other
|
|
105
|
+
// version, where we drop the reflected announce on receipt instead. Matches the
|
|
106
|
+
// Rust subscriber's `exclude_hop: self.self_origin.id` in `run_announce_prefix`.
|
|
106
107
|
const msg = new AnnounceRequest(prefix, this.origin);
|
|
108
|
+
// Drop reflected announces so callers asking for "someone else's broadcasts"
|
|
109
|
+
// don't re-see their own publishes. A caller can always ask for this, and it is
|
|
110
|
+
// required on versions that don't carry excludeHop above: there the peer isn't
|
|
111
|
+
// filtering them out for us, so filtering here keeps what the app sees the same
|
|
112
|
+
// as lite-05. Lite01-03 carry no real hop ids, so the check never matches there.
|
|
113
|
+
const dropReflected = options.ignoreSelf || !hasExcludeHop(this.version);
|
|
107
114
|
try {
|
|
108
115
|
// Open a stream and send the announce interest.
|
|
109
116
|
const stream = await Stream.open(this.#quic);
|
|
@@ -188,11 +195,9 @@ export class Subscriber {
|
|
|
188
195
|
break;
|
|
189
196
|
}
|
|
190
197
|
}
|
|
191
|
-
//
|
|
192
|
-
// "someone else's broadcasts" don't re-see their own publishes. In
|
|
193
|
-
// Lite05+ the sender's origin arrives via AnnounceOk, not in each hop
|
|
198
|
+
// In Lite05+ the sender's origin arrives via AnnounceOk, not in each hop
|
|
194
199
|
// list, so fold it back in before checking.
|
|
195
|
-
if (hops !== undefined &&
|
|
200
|
+
if (hops !== undefined && dropReflected) {
|
|
196
201
|
const full = responderOrigin !== undefined ? [...hops, responderOrigin] : hops;
|
|
197
202
|
if (full.includes(this.origin)) {
|
|
198
203
|
continue;
|
package/lite/subscriber.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscriber.js","sourceRoot":"","sources":["../../src/lite/subscriber.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,SAAS,MAAM,i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AK;QACb,OAAO,IAAI,gBAAgB,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;IAC9E,CAAC;IAEQ,gBAAgB,CAAC,IAAY;QACrC,OAAO,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC5D,CAAC;IAEQ,UAAU,CAAC,IAAY,EAAE,QAAgB,EAAE,OAAiC;QACpF,OAAO,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;IACzE,CAAC;CACD","sourcesContent":["import { Signal } from \"@moq/signals\";\nimport * as announce from \"../announced.ts\";\nimport * as broadcast from \"../broadcast.ts\";\nimport type { Probe as ProbeStats } from \"../connection/stats.ts\";\nimport { BroadcastCache } from \"../consume.ts\";\nimport { error, reason } from \"../error.ts\";\nimport * as netGroup from \"../group.ts\";\nimport * as Path from \"../path.ts\";\nimport { type Reader, Stream } from \"../stream.ts\";\nimport * as Time from \"../time.ts\";\nimport type * as track from \"../track.ts\";\nimport { withTimeout } from \"../util/timeout.ts\";\nimport { AnnounceInit, AnnounceOk, AnnounceRequest, decodeAnnounceBroadcastMaybe } from \"./announce.ts\";\nimport { Datagram as DatagramMessage } from \"./datagram.ts\";\nimport * as DatagramStream from \"./datagram_stream.ts\";\nimport { Fetch as FetchMessage } from \"./fetch.ts\";\nimport type { Group as GroupMessage } from \"./group.ts\";\nimport type { Origin } from \"./origin.ts\";\nimport { Probe } from \"./probe.ts\";\nimport { ProbeLevel, type Setup } from \"./setup.ts\";\nimport { StreamId } from \"./stream.ts\";\nimport { decodeSubscribeResponse, decodeSubscribeResponseMaybe, Subscribe, SubscribeUpdate } from \"./subscribe.ts\";\nimport { TrackInfo, Track as TrackMessage } from \"./track.ts\";\nimport { hasAnnounceId, hasAnnounceOk, hasDatagrams, Version } from \"./version.ts\";\n\n// Bound on how long stream-open plus the first response (SUBSCRIBE_OK on older\n// drafts, or TRACK_INFO on lite-05+) may take. Browsers cap concurrent QUIC\n// streams (Chrome ~100); past the cap createBidirectionalStream silently blocks.\n// The timeout turns that into a clear error.\nconst SUBSCRIBE_SETUP_TIMEOUT_MS = 10_000;\n\n/** Decode an unsigned zigzag varint back to a signed delta (mirrors Rust `VarInt::to_zigzag`). */\nfunction unzigzag(v: bigint): bigint {\n\treturn (v >> 1n) ^ -(v & 1n);\n}\n\n// The TRACK stream and implicit SUBSCRIBE acceptance are lite-05+.\nfunction supportsTrackStream(version: Version): boolean {\n\tswitch (version) {\n\t\tcase Version.DRAFT_01:\n\t\tcase Version.DRAFT_02:\n\t\tcase Version.DRAFT_03:\n\t\tcase Version.DRAFT_04:\n\t\t\treturn false;\n\t\tdefault:\n\t\t\treturn true;\n\t}\n}\n\n/**\n * Options accepted by {@link Subscriber.announced}.\n */\nexport interface AnnouncedOptions {\n\t/**\n\t * If true, skip announcements whose hop chain contains this connection's\n\t * own origin id. Useful for meshes that reflect announces back. Defaults\n\t * to false for backwards compatibility: existing code (notably hang.live)\n\t * relies on seeing its own publishes as the signal that a namespace\n\t * published successfully.\n\t */\n\tignoreSelf?: boolean;\n}\n\ninterface SubscribeEntry {\n\t// The write side: incoming GROUP streams are routed here. The application reads\n\t// the matching track.Subscriber it got from broadcast.Consumer.subscribe.\n\ttrack: track.Producer;\n\t// Per-frame timestamp scale (0 = none). undefined until it's known (from TRACK_INFO\n\t// on lite-05+, or implicit defaults on older drafts). A non-zero value means each\n\t// frame on the group stream is prefixed with a zigzag-delta timestamp varint that\n\t// runGroup must consume to stay in sync; group streams block on it before decoding,\n\t// since a group's QUIC stream can race ahead of the subscribe stream.\n\ttimescale: Signal<number | undefined>;\n}\n\n/**\n * Handles subscribing to broadcasts and managing their lifecycle.\n *\n * @internal\n */\nexport class Subscriber {\n\t#quic: WebTransport;\n\n\t// The version of the connection.\n\treadonly version: Version;\n\n\t// Shared with the Publisher so callers can optionally filter out their\n\t// own announcements on a per-call basis (see {@link AnnouncedOptions}).\n\treadonly origin: Origin;\n\n\t// Our subscribed tracks. `timescale` resolves once known (from TRACK_INFO on\n\t// lite-05+, or implicit defaults on older drafts); group streams block on it\n\t// before decoding any frame, since a group's QUIC stream can race ahead.\n\t#subscribes = new Map<bigint, SubscribeEntry>();\n\t#subscribeNext = 0n;\n\n\t// Dedup consumed broadcasts per path: repeat consume() calls share one subscription.\n\t#consumes = new BroadcastCache();\n\n\t// Dedup in-flight one-shot fetches, keyed by [broadcast, track, sequence]. Concurrent (or\n\t// repeat, while still open) fetchGroup() calls for the same group share one FETCH stream and\n\t// each get an independent mirror; the entry is evicted once the group closes.\n\t#fetches = new Map<string, netGroup.Producer>();\n\n\t// The peer's PROBE estimates, written as they arrive (Lite03+ only).\n\t#probe?: Signal<ProbeStats>;\n\n\t// The peer's SETUP (lite-05+), undefined until it arrives. Gates opening the PROBE\n\t// stream on the peer having advertised Probe >= Report.\n\t#peerSetup?: Signal<Setup | undefined>;\n\n\t// Distinguishes failures from streams torn down by Subscriber.close().\n\t#closed = new AbortController();\n\t/**\n\t * Creates a new Subscriber instance.\n\t * @param quic - The WebTransport session to use\n\t * @param version - The protocol version\n\t * @param origin - Origin id shared with the Publisher\n\t * @param probe - Optional sink for the peer's PROBE estimates\n\t * @param peerSetup - Optional peer SETUP slot for capability gating (lite-05+)\n\t *\n\t * @internal\n\t */\n\tconstructor(\n\t\tquic: WebTransport,\n\t\tversion: Version,\n\t\torigin: Origin,\n\t\tprobe?: Signal<ProbeStats>,\n\t\tpeerSetup?: Signal<Setup | undefined>,\n\t) {\n\t\tthis.#quic = quic;\n\t\tthis.version = version;\n\t\tthis.origin = origin;\n\t\tthis.#probe = probe;\n\t\tthis.#peerSetup = peerSetup;\n\t}\n\n\t/**\n\t * Subscribe to broadcast announcements under `prefix`.\n\t *\n\t * Pass `{ ignoreSelf: true }` to skip announces that have already traversed\n\t * this connection's {@link origin}.\n\t */\n\tannounced(prefix = Path.empty(), options: AnnouncedOptions = {}): announce.Consumer {\n\t\tconst announced = new announce.Producer(prefix);\n\t\tvoid this.#runAnnounced(announced, prefix, options);\n\t\treturn announced.consume();\n\t}\n\n\tasync #runAnnounced(announced: announce.Producer, prefix: Path.Valid, options: AnnouncedOptions): Promise<void> {\n\t\tconsole.debug(`announced: prefix=${prefix}`);\n\t\t// Send our own session-level origin id so the peer can skip announces\n\t\t// whose hop chain already passed through us. Matches the Rust subscriber's\n\t\t// `exclude_hop: self.self_origin.id` in `run_announce_prefix`.\n\t\tconst msg = new AnnounceRequest(prefix, this.origin);\n\n\t\ttry {\n\t\t\t// Open a stream and send the announce interest.\n\t\t\tconst stream = await Stream.open(this.#quic);\n\t\t\tawait stream.writer.u53(StreamId.Announce);\n\t\t\tawait msg.encode(stream.writer, this.version);\n\n\t\t\t// Lite05+: the publisher reports its own origin id before any announces.\n\t\t\t// It no longer stamps itself onto each hop chain, so we append it here to\n\t\t\t// keep the ignoreSelf loop check seeing the full chain.\n\t\t\tlet responderOrigin: Origin | undefined;\n\t\t\tif (hasAnnounceOk(this.version)) {\n\t\t\t\tconst ok = await AnnounceOk.decode(stream.reader, this.version);\n\t\t\t\tresponderOrigin = ok.origin;\n\t\t\t}\n\n\t\t\tswitch (this.version) {\n\t\t\t\tcase Version.DRAFT_01:\n\t\t\t\tcase Version.DRAFT_02: {\n\t\t\t\t\t// Receive ANNOUNCE_INIT first\n\t\t\t\t\tconst init = await AnnounceInit.decode(stream.reader, this.version);\n\n\t\t\t\t\t// Process initial announcements\n\t\t\t\t\tfor (const suffix of init.suffixes) {\n\t\t\t\t\t\tconst path = Path.join(prefix, suffix);\n\t\t\t\t\t\tconsole.debug(`announced: broadcast=${path} active=true`);\n\t\t\t\t\t\tannounced.append({ path: suffix, active: true });\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\t// Draft03+: no AnnounceInit, initial state comes via Announce messages.\n\t\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\t// Lite06+: announce ids. Each received `active` implicitly assigns the next\n\t\t\t// per-stream ordinal; `endedId`/`restart` reference it. Tracked even for\n\t\t\t// announces we skip via ignoreSelf, since the sender doesn't know we skipped.\n\t\t\tlet nextAnnounceId = 0n;\n\t\t\tconst announcedById = new Map<bigint, Path.Valid>();\n\n\t\t\t// Receive announce updates (for Draft03, this includes initial state)\n\t\t\tfor (;;) {\n\t\t\t\tconst announce = await Promise.race([\n\t\t\t\t\tdecodeAnnounceBroadcastMaybe(stream.reader, this.version),\n\t\t\t\t\tannounced.closed,\n\t\t\t\t]);\n\t\t\t\t// undefined: the stream ended. null: the consumer closed cleanly.\n\t\t\t\tif (!announce) break;\n\t\t\t\tif (announce instanceof Error) throw announce;\n\n\t\t\t\tlet suffix: Path.Valid;\n\t\t\t\tlet active: boolean;\n\t\t\t\t// Present on active/restart; ended messages never carry hops worth checking.\n\t\t\t\tlet hops: Origin[] | undefined;\n\n\t\t\t\tswitch (announce.status) {\n\t\t\t\t\tcase \"active\":\n\t\t\t\t\t\tsuffix = announce.suffix;\n\t\t\t\t\t\tactive = true;\n\t\t\t\t\t\thops = announce.hops;\n\t\t\t\t\t\tif (hasAnnounceId(this.version)) {\n\t\t\t\t\t\t\tannouncedById.set(nextAnnounceId++, announce.suffix);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"ended\":\n\t\t\t\t\t\tsuffix = announce.suffix;\n\t\t\t\t\t\tactive = false;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"endedId\": {\n\t\t\t\t\t\t// Resolve and retire the id; an unknown or retired id is a protocol violation.\n\t\t\t\t\t\tconst path = announcedById.get(announce.id);\n\t\t\t\t\t\tif (path === undefined) throw new Error(`unknown announce id: ${announce.id}`);\n\t\t\t\t\t\tannouncedById.delete(announce.id);\n\t\t\t\t\t\tsuffix = path;\n\t\t\t\t\t\tactive = false;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"restart\": {\n\t\t\t\t\t\t// Resolve the id; it stays live (the replacement reuses it).\n\t\t\t\t\t\tconst path = announcedById.get(announce.id);\n\t\t\t\t\t\tif (path === undefined) throw new Error(`unknown announce id: ${announce.id}`);\n\t\t\t\t\t\tsuffix = path;\n\t\t\t\t\t\tactive = true;\n\t\t\t\t\t\thops = announce.hops;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Optionally drop reflected announces so callers asking for\n\t\t\t\t// \"someone else's broadcasts\" don't re-see their own publishes. In\n\t\t\t\t// Lite05+ the sender's origin arrives via AnnounceOk, not in each hop\n\t\t\t\t// list, so fold it back in before checking.\n\t\t\t\tif (hops !== undefined && options.ignoreSelf) {\n\t\t\t\t\tconst full = responderOrigin !== undefined ? [...hops, responderOrigin] : hops;\n\t\t\t\t\tif (full.includes(this.origin)) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst path = Path.join(prefix, suffix);\n\n\t\t\t\tconsole.debug(`announced: broadcast=${path} active=${active}`);\n\t\t\t\tannounced.append({ path: suffix, active });\n\t\t\t}\n\n\t\t\tannounced.close();\n\t\t} catch (err: unknown) {\n\t\t\tannounced.close(error(err));\n\t\t}\n\t}\n\n\t/**\n\t * Consumes a broadcast from the connection.\n\t *\n\t * Deduplicated per path: repeat calls for the same still-live path share one reference-counted\n\t * broadcast (and one upstream subscription). The shared broadcast closes once every caller has\n\t * closed its handle, so callers close normally.\n\t *\n\t * @param name - The name of the broadcast to consume\n\t * @returns A Broadcast instance\n\t */\n\tconsume(path: Path.Valid): broadcast.Consumer {\n\t\treturn this.#consumes.get(path) ?? this.#consumes.insert(path, this.#createConsume(path));\n\t}\n\n\t#createConsume(path: Path.Valid): broadcast.Consumer {\n\t\t// A consumed broadcast resolves info() and fetchGroup() over the wire by reaching\n\t\t// back into this Subscriber (see ConsumeBroadcast below), rather than the wire\n\t\t// installing callbacks on the broadcast.\n\t\tconst consumer = new ConsumeBroadcast(this, path);\n\n\t\tvoid (async () => {\n\t\t\tfor (;;) {\n\t\t\t\tconst request = await consumer.requested();\n\t\t\t\tif (!request) break;\n\t\t\t\tvoid this.#runSubscribe(path, request);\n\t\t\t}\n\t\t})();\n\n\t\treturn consumer;\n\t}\n\n\tasync #runSubscribe(broadcast: Path.Valid, request: track.Request) {\n\t\tconst id = this.#subscribeNext++;\n\n\t\t// `timescale` stays undefined until TRACK_INFO (or, on older drafts,\n\t\t// implicit defaults) resolves it; runGroup blocks on it before decoding.\n\t\tconst timescale = new Signal<number | undefined>(undefined);\n\n\t\tconsole.debug(`subscribe start: id=${id} broadcast=${broadcast} track=${request.name}`);\n\n\t\tconst msg = new Subscribe({ id, broadcast, track: request.name, priority: request.priority });\n\n\t\t// Open the stream under a timeout. The stream handle flows back via `state`\n\t\t// so the timeout path can abort it if it finishes opening after the deadline.\n\t\tconst state: { stream?: Stream } = {};\n\t\tconst setup = this.#openSubscribe(state, msg, request, id, timescale);\n\n\t\tlet opened: { stream: Stream; producer: track.Producer };\n\t\ttry {\n\t\t\topened = await withTimeout(\n\t\t\t\tsetup,\n\t\t\t\tSUBSCRIBE_SETUP_TIMEOUT_MS,\n\t\t\t\t`subscribe timed out after ${SUBSCRIBE_SETUP_TIMEOUT_MS}ms waiting for the first response (browser stream limit reached?)`,\n\t\t\t);\n\t\t\tconsole.debug(`subscribe ok: id=${id} broadcast=${broadcast} track=${request.name}`);\n\t\t} catch (err) {\n\t\t\tconst e = error(err);\n\t\t\trequest.reject(e);\n\t\t\tthis.#subscribes.delete(id);\n\t\t\tconsole.warn(`subscribe error: id=${id} broadcast=${broadcast} track=${request.name} error=${reason(e)}`);\n\t\t\t// If the stream eventually opens after the timeout, abort it so we\n\t\t\t// don't leak it. Cover both branches: setup may resolve late, or it\n\t\t\t// may reject (e.g. encode/decode failure) after the stream is open.\n\t\t\tsetup.then(\n\t\t\t\t() => state.stream?.abort(e),\n\t\t\t\t() => state.stream?.abort(e),\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tconst { stream, producer } = opened;\n\t\ttry {\n\t\t\t// Watch for priority changes and send SUBSCRIBE_UPDATE. Lite01/Lite02\n\t\t\t// don't carry SUBSCRIBE_UPDATE on the wire, so skip the watcher there\n\t\t\t// and just wait on the stream/track like before.\n\t\t\t//\n\t\t\t// On lite-05+ the publisher sends SUBSCRIBE_START/END/DROP on this stream;\n\t\t\t// drain them (we don't drive delivery off the resolved range) so the FIN is\n\t\t\t// observed. Older drafts just wait for the stream to close.\n\t\t\tconst closed = supportsTrackStream(this.version) ? this.#drainResponses(stream) : stream.reader.closed;\n\t\t\tconst priorityUpdates =\n\t\t\t\tthis.version === Version.DRAFT_01 || this.version === Version.DRAFT_02\n\t\t\t\t\t? undefined\n\t\t\t\t\t: this.#runPriorityUpdates(id, broadcast, producer, msg, stream);\n\n\t\t\t// Terminal conditions (stream end, track close, a failed priority update) settle at most\n\t\t\t// once; race them into one stable promise so the demand loop doesn't re-subscribe each pass.\n\t\t\tconst terminal: PromiseLike<unknown>[] = [closed, producer.closed];\n\t\t\tif (priorityUpdates !== undefined) terminal.push(priorityUpdates);\n\t\t\tconst done = Promise.race(terminal);\n\n\t\t\t// Serve until a terminal condition fires or the last local subscriber leaves. The unused\n\t\t\t// wake is level-triggered: re-check demand so a subscriber that returns before we tear\n\t\t\t// down (e.g. a quickly unmuted tile) resumes on the same subscription.\n\t\t\tconst idle = Symbol(\"idle\");\n\t\t\tfor (;;) {\n\t\t\t\tconst reason = await Promise.race([done, producer.unused().then(() => idle)]);\n\t\t\t\tif (reason === idle && producer.closed.peek() === undefined && producer.used.peek()) continue;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tproducer.close();\n\t\t\tstream.close();\n\t\t\tconsole.debug(`subscribe close: id=${id} broadcast=${broadcast} track=${request.name}`);\n\t\t} catch (err) {\n\t\t\tconst e = error(err);\n\t\t\tproducer.close(e);\n\t\t\tconsole.warn(`subscribe error: id=${id} broadcast=${broadcast} track=${request.name} error=${reason(e)}`);\n\t\t\tstream.abort(e);\n\t\t} finally {\n\t\t\tthis.#subscribes.delete(id);\n\t\t}\n\t}\n\n\t// Determine the track's immutable properties, accept the request (so the\n\t// application's track.Subscriber resolves and incoming groups have a producer to\n\t// write into), register it, then open the subscribe stream. `state.stream` is\n\t// populated as soon as the subscribe stream opens so the caller can clean it up\n\t// on timeout even before this promise settles.\n\t//\n\t// On lite-05+ the properties come from a TRACK stream opened first, and the\n\t// SUBSCRIBE is accepted implicitly (no SUBSCRIBE_OK). Older drafts carry no\n\t// per-track properties, so they resolve to defaults and just drain SUBSCRIBE_OK.\n\tasync #openSubscribe(\n\t\tstate: { stream?: Stream },\n\t\tmsg: Subscribe,\n\t\trequest: track.Request,\n\t\tid: bigint,\n\t\ttimescale: Signal<number | undefined>,\n\t): Promise<{ stream: Stream; producer: track.Producer }> {\n\t\tlet producer: track.Producer;\n\t\tlet drainOk = false;\n\n\t\tif (supportsTrackStream(this.version)) {\n\t\t\t// Fetch the immutable properties once via the TRACK stream.\n\t\t\tconst info = await this.#trackInfo(msg.broadcast, msg.track);\n\t\t\tproducer = request.accept(this.#toModelInfo(info));\n\t\t\ttimescale.set(info.timescale);\n\t\t} else {\n\t\t\t// Older drafts negotiate nothing per-track: verbatim frames, no timescale.\n\t\t\tproducer = request.accept();\n\t\t\ttimescale.set(0);\n\t\t\tdrainOk = true;\n\t\t}\n\n\t\t// Register before opening SUBSCRIBE so a racing GROUP stream finds the entry.\n\t\tthis.#subscribes.set(id, { track: producer, timescale });\n\n\t\tstate.stream = await Stream.open(this.#quic);\n\t\tawait state.stream.writer.u53(StreamId.Subscribe);\n\t\tawait msg.encode(state.stream.writer, this.version);\n\n\t\tif (drainOk) {\n\t\t\t// The first response MUST be a SUBSCRIBE_OK (older drafts only).\n\t\t\tconst resp = await decodeSubscribeResponse(state.stream.reader, this.version);\n\t\t\tif (!(\"ok\" in resp)) {\n\t\t\t\tthrow new Error(\"first subscribe response must be SUBSCRIBE_OK\");\n\t\t\t}\n\t\t}\n\n\t\treturn { stream: state.stream, producer };\n\t}\n\n\t// Opens a TRACK stream, reads the single TRACK_INFO, and FINs. Lite-05+ only.\n\tasync #trackInfo(broadcast: Path.Valid, track: string): Promise<TrackInfo> {\n\t\tconst stream = await Stream.open(this.#quic);\n\t\ttry {\n\t\t\tawait stream.writer.u53(StreamId.Track);\n\t\t\tawait new TrackMessage(broadcast, track).encode(stream.writer, this.version);\n\t\t\tconst info = await TrackInfo.decode(stream.reader, this.version);\n\t\t\t// The publisher FINs after TRACK_INFO; FIN our side too.\n\t\t\tstream.close();\n\t\t\treturn info;\n\t\t} catch (err) {\n\t\t\tstream.abort(error(err));\n\t\t\tthrow err;\n\t\t}\n\t}\n\n\t// Map the wire TRACK_INFO onto the model track.Info a producer/consumer holds.\n\t#toModelInfo(info: TrackInfo): track.Info {\n\t\treturn {\n\t\t\ttimescale: Time.Timescale(info.timescale),\n\t\t\t// Publisher Max Latency rides on the wire, so the local retention window\n\t\t\t// matches what the upstream advertises (relays re-serve with the same bound).\n\t\t\tlatencyMax: info.latencyMax,\n\t\t\tpriority: info.priority,\n\t\t\tordered: info.ordered,\n\t\t};\n\t}\n\n\t// Resolve a track's immutable model info via a TRACK stream (lite-05+), for the\n\t// ConsumeBroadcast backing track.Consumer.info(). On older drafts there's no TRACK\n\t// stream, so this rejects rather than fabricating defaults.\n\tasync resolveTrackInfo(broadcast: Path.Valid, track: string): Promise<track.Info> {\n\t\tif (!supportsTrackStream(this.version)) {\n\t\t\tthrow new Error(\"track info requires moq-lite-05 or newer\");\n\t\t}\n\t\treturn this.#toModelInfo(await this.#trackInfo(broadcast, track));\n\t}\n\n\t// Open a FETCH stream for one group and stream its bare frames into a group, for the\n\t// ConsumeBroadcast backing track.Consumer.fetchGroup() (lite-05+).\n\tfetchGroup(\n\t\tbroadcast: Path.Valid,\n\t\ttrack: string,\n\t\tsequence: number,\n\t\toptions: track.FetchGroupOptions = {},\n\t): Promise<netGroup.Consumer> {\n\t\t// Coalesce onto a still-open fetch of the same group so we don't open a second FETCH\n\t\t// stream (and re-download it); each caller reads an independent mirror.\n\t\tconst key = JSON.stringify([broadcast, track, sequence]);\n\t\tconst existing = this.#fetches.get(key);\n\t\tif (existing && !existing.isClosed) return Promise.resolve(existing.mirror());\n\n\t\t// Create and cache the group synchronously (before any await) so a concurrent fetch for\n\t\t// the same group finds it and coalesces rather than racing to open its own stream.\n\t\tconst group = new netGroup.Producer(sequence);\n\t\tthis.#fetches.set(key, group);\n\t\tvoid group.closed.then(() => {\n\t\t\tif (this.#fetches.get(key) === group) this.#fetches.delete(key);\n\t\t});\n\n\t\treturn this.#runFetch(broadcast, track, sequence, options, group);\n\t}\n\n\t// Open the FETCH stream and pump the response into the shared group. Setup errors close the\n\t// group (so coalesced mirrors observe them and the entry evicts) and reject this caller.\n\tasync #runFetch(\n\t\tbroadcast: Path.Valid,\n\t\ttrack: string,\n\t\tsequence: number,\n\t\toptions: track.FetchGroupOptions,\n\t\tgroup: netGroup.Producer,\n\t): Promise<netGroup.Consumer> {\n\t\ttry {\n\t\t\tif (!supportsTrackStream(this.version)) {\n\t\t\t\tthrow new Error(\"fetch group requires moq-lite-05 or newer\");\n\t\t\t}\n\n\t\t\tconst info = await this.#trackInfo(broadcast, track);\n\t\t\tconst priority = options.priority ?? 0;\n\t\t\tconst stream = await Stream.open(this.#quic, undefined, priority);\n\n\t\t\ttry {\n\t\t\t\tawait stream.writer.u53(StreamId.Fetch);\n\t\t\t\tawait new FetchMessage(broadcast, track, priority, sequence).encode(stream.writer, this.version);\n\t\t\t} catch (err: unknown) {\n\t\t\t\tstream.abort(error(err));\n\t\t\t\tthrow err;\n\t\t\t}\n\n\t\t\t// Mint this caller's reader before starting the pump, so the group has demand when the\n\t\t\t// pump begins watching it (an abandoned fetch cancels once every reader has left).\n\t\t\tconst consumer = group.mirror();\n\t\t\tvoid this.#runFetchResponse(stream, group, Time.Timescale(info.timescale));\n\t\t\treturn consumer;\n\t\t} catch (err: unknown) {\n\t\t\tgroup.close(error(err));\n\t\t\tthrow err;\n\t\t}\n\t}\n\n\t// Read the FETCH response (bare zigzag-delta-timestamped frames) into the group, then\n\t// FIN. A stream-level failure aborts the group so its reader observes the gap.\n\tasync #runFetchResponse(stream: Stream, group: netGroup.Producer, timescale: Time.Timescale): Promise<void> {\n\t\ttry {\n\t\t\tlet prevTs = 0n;\n\n\t\t\t// Serve until the stream FINs, the group closes, or every reader leaves. A group can\n\t\t\t// stay open indefinitely (a catalog or JSON stream), so an abandoned fetch is stopped by\n\t\t\t// demand, not by the stream ending. `closed` and `unused` are watched across frames as\n\t\t\t// stable promises (not re-subscribed to the signals each frame); the unused check is\n\t\t\t// level-triggered, so a coalesced fetch that arrives before we cancel re-arms and resumes.\n\t\t\tconst idle = Symbol(\"idle\");\n\t\t\tconst closed = Promise.resolve<Error | null>(group.closed);\n\t\t\tlet unused = group.unused().then(() => idle);\n\t\t\tfor (;;) {\n\t\t\t\tconst done = await Promise.race([stream.reader.done(), closed, unused]);\n\t\t\t\tif (done === idle) {\n\t\t\t\t\tif (!group.isClosed && group.used.peek()) {\n\t\t\t\t\t\tunused = group.unused().then(() => idle);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (done !== false) break;\n\n\t\t\t\tprevTs += unzigzag(await stream.reader.u62());\n\t\t\t\tconst timestamp = new Time.Timestamp(Number(prevTs), timescale);\n\t\t\t\tconst size = await stream.reader.u53();\n\t\t\t\tconst payload = await stream.reader.read(size);\n\t\t\t\tif (!payload) break;\n\t\t\t\tgroup.writeFrame({ payload, timestamp });\n\t\t\t}\n\n\t\t\tgroup.close();\n\t\t\tstream.close();\n\t\t} catch (err: unknown) {\n\t\t\tconst e = error(err);\n\t\t\tgroup.close(e);\n\t\t\tstream.abort(e);\n\t\t}\n\t}\n\n\t// Drains SUBSCRIBE_START/END/DROP on the subscribe stream until FIN (lite-05+).\n\t// The resolved range is informational here; the producer already orders groups.\n\t// Resolves (never rejects) on FIN or on the stream being reset out from under it,\n\t// so it's safe to drop from a Promise.race without an unhandled rejection.\n\tasync #drainResponses(stream: Stream): Promise<void> {\n\t\ttry {\n\t\t\tfor (;;) {\n\t\t\t\tconst resp = await decodeSubscribeResponseMaybe(stream.reader, this.version);\n\t\t\t\tif (!resp) return;\n\t\t\t}\n\t\t} catch {\n\t\t\t// Stream closed or reset; nothing more to drain.\n\t\t}\n\t}\n\n\t/**\n\t * Send SUBSCRIBE_UPDATE messages whenever the track's priority signal changes.\n\t *\n\t * Resolves cleanly when the stream or track closes, so the caller can include\n\t * this in Promise.race without leaving a dangling pending write that would\n\t * become an unhandled rejection if the user calls updatePriority after close.\n\t *\n\t * Peeks the signal at the top of every iteration so that updates which landed\n\t * before SubscribeOk arrived (or between iterations, before .next() registered\n\t * its listener) aren't lost.\n\t */\n\tasync #runPriorityUpdates(\n\t\tid: bigint,\n\t\tbroadcast: Path.Valid,\n\t\ttrack: track.Producer,\n\t\tmsg: Subscribe,\n\t\tstream: Stream,\n\t): Promise<void> {\n\t\tconst stopped: Promise<null> = Promise.race([track.closed, stream.reader.closed]).then(() => null);\n\t\tlet lastSent: number | undefined;\n\n\t\tfor (;;) {\n\t\t\tconst current = track.subscription.peek()?.priority;\n\t\t\tif (current === undefined || current === lastSent) {\n\t\t\t\t// Nothing new to send; wait for a change or termination.\n\t\t\t\tconst next = await Promise.race([track.subscription.changed(), stopped]);\n\t\t\t\tif (next === null) return;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Round-trip the other Subscribe parameters so the publisher doesn't\n\t\t\t// interpret SUBSCRIBE_UPDATE as a reset of ordered/maxLatency/etc.\n\t\t\tconst update = new SubscribeUpdate({\n\t\t\t\tpriority: current,\n\t\t\t\tordered: msg.ordered,\n\t\t\t\tmaxLatency: msg.maxLatency,\n\t\t\t\tstartGroup: msg.startGroup,\n\t\t\t\tendGroup: msg.endGroup,\n\t\t\t});\n\t\t\tawait update.encode(stream.writer, this.version);\n\t\t\tlastSent = current;\n\t\t\tconsole.debug(`subscribe update: id=${id} broadcast=${broadcast} track=${track.name} priority=${current}`);\n\t\t}\n\t}\n\n\t/**\n\t * Handles a group message.\n\t * @param group - The group message\n\t * @param stream - The stream to read frames from\n\t *\n\t * @internal\n\t */\n\tasync runGroup(group: GroupMessage, stream: Reader) {\n\t\tconst entry = this.#subscribes.get(group.subscribe);\n\t\tif (!entry) {\n\t\t\tif (group.subscribe >= this.#subscribeNext) {\n\t\t\t\tthrow new Error(`unknown subscription: id=${group.subscribe}`);\n\t\t\t}\n\n\t\t\treturn;\n\t\t}\n\n\t\tconst { track, timescale } = entry;\n\t\tconst producer = new netGroup.Producer(group.sequence);\n\t\ttrack.writeGroup(producer);\n\n\t\ttry {\n\t\t\t// Block until the timescale is known; the group's stream can arrive before\n\t\t\t// TRACK_INFO (or implicit defaults) resolves it on the subscribe stream.\n\t\t\tlet scale = timescale.peek();\n\t\t\twhile (scale === undefined) {\n\t\t\t\tif (track.closed.peek() !== undefined) {\n\t\t\t\t\t// Subscription ended before the scale resolved; nothing to decode.\n\t\t\t\t\tproducer.close();\n\t\t\t\t\tstream.stop(new Error(\"cancel\"));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tawait Signal.race(timescale, track.closed);\n\t\t\t\tscale = timescale.peek();\n\t\t\t}\n\n\t\t\t// A non-zero scale means every frame is prefixed with a zigzag-delta timestamp\n\t\t\t// (the lite-05 FRAME format), which we decode into a Timestamp at that scale.\n\t\t\t// Scale 0 (pre-lite-05) carries no timestamp, so we wall-clock-stamp.\n\t\t\tlet prevTs = 0n;\n\n\t\t\tfor (;;) {\n\t\t\t\tconst done = await Promise.race([stream.done(), track.closed, producer.closed]);\n\t\t\t\tif (done !== false) break;\n\n\t\t\t\tlet timestamp: Time.Timestamp;\n\t\t\t\tif (scale !== 0) {\n\t\t\t\t\tprevTs += unzigzag(await stream.u62());\n\t\t\t\t\ttimestamp = new Time.Timestamp(Number(prevTs), Time.Timescale(scale));\n\t\t\t\t} else {\n\t\t\t\t\ttimestamp = Time.Timestamp.now();\n\t\t\t\t}\n\n\t\t\t\tconst size = await stream.u53();\n\t\t\t\tconst payload = await stream.read(size);\n\t\t\t\tif (!payload) break;\n\n\t\t\t\tproducer.writeFrame({ payload, timestamp });\n\t\t\t}\n\n\t\t\tproducer.close();\n\t\t\tstream.stop(new Error(\"cancel\"));\n\t\t} catch (err: unknown) {\n\t\t\tconst e = error(err);\n\t\t\tproducer.close(e);\n\t\t\tstream.stop(e);\n\t\t}\n\t}\n\n\t/**\n\t * Receives QUIC datagrams and routes each to its subscription's track producer (lite-05 §6.4).\n\t *\n\t * Returns immediately on a non-datagram transport or pre-lite-05 version. A decode error or an\n\t * unknown subscribe id drops that datagram without tearing down the session (best-effort); the\n\t * loop ends only when the datagram stream closes.\n\t *\n\t * @internal\n\t */\n\tasync runDatagrams(): Promise<void> {\n\t\tif (!hasDatagrams(this.version) || DatagramStream.maxDatagramSize(this.#quic) === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Never reject: this loop is awaited alongside the connection's other tasks, so a\n\t\t// datagram-stream failure must not tear the whole session down (it's best-effort).\n\t\tconst reader = DatagramStream.datagramReader(this.#quic);\n\t\tif (!reader) return;\n\n\t\ttry {\n\t\t\ttry {\n\t\t\t\tfor (;;) {\n\t\t\t\t\tconst { value, done } = await reader.read();\n\t\t\t\t\tif (done) break;\n\t\t\t\t\tif (!value) continue;\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait this.#routeDatagram(value);\n\t\t\t\t\t} catch (err: unknown) {\n\t\t\t\t\t\tconsole.debug(`dropping datagram: ${reason(err)}`);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} finally {\n\t\t\t\treader.releaseLock();\n\t\t\t}\n\t\t} catch (err: unknown) {\n\t\t\tconst e = error(err);\n\t\t\tif (e.message === \"The session is closed.\") {\n\t\t\t\tconsole.debug(`datagram receive stopped: ${e.message}`);\n\t\t\t} else {\n\t\t\t\tconsole.warn(\"datagram stream error\", err);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Decode one datagram body and hand it to the matching subscription's producer. Drops the\n\t// datagram (best-effort) if the subscription is unknown/closed or its timescale isn't resolved.\n\tasync #routeDatagram(payload: Uint8Array): Promise<void> {\n\t\tconst dg = await DatagramMessage.decode(payload);\n\n\t\tconst entry = this.#subscribes.get(dg.subscribe);\n\t\tif (!entry) return; // Unknown or already-closed subscription.\n\n\t\t// Datagrams are lite-05+, which always negotiates a timescale; if it hasn't resolved\n\t\t// yet (the datagram raced ahead of TRACK_INFO), drop rather than guess.\n\t\tconst scale = entry.timescale.peek();\n\t\tif (!scale) return;\n\n\t\tconst timestamp = new Time.Timestamp(dg.timestamp, Time.Timescale(scale));\n\t\tentry.track.writeDatagram({ sequence: dg.sequence, timestamp, payload: dg.payload });\n\t}\n\n\t/**\n\t * Opens a PROBE bidi stream to receive bandwidth estimates from the publisher.\n\t * Returns immediately if recv bandwidth is not supported.\n\t *\n\t * Probe is best-effort telemetry: a stream-level failure (peer reset, FIN,\n\t * missing peer support, transport hiccup) is caught and logged, never\n\t * propagated to the connection. On exit the bandwidth/RTT signals are\n\t * cleared so consumers see them as stale.\n\t *\n\t * @internal\n\t */\n\t// Await the peer's advertised probe level, blocking until its SETUP arrives. The peer\n\t// MUST send exactly one SETUP, so this resolves once that stream is read.\n\tasync #peerProbeLevel(peerSetup: Signal<Setup | undefined>): Promise<ProbeLevel> {\n\t\tlet setup = peerSetup.peek();\n\t\twhile (setup === undefined) {\n\t\t\tsetup = await peerSetup.changed();\n\t\t}\n\t\treturn setup.probe;\n\t}\n\n\tasync runProbe(): Promise<void> {\n\t\tif (!this.#probe) return;\n\t\tif (this.version === Version.DRAFT_01 || this.version === Version.DRAFT_02) return;\n\n\t\t// Lite-05+ gates the PROBE stream on the peer advertising Probe >= Report in its\n\t\t// SETUP. Wait for the SETUP, then bail if the peer can't report bitrate. Older\n\t\t// drafts have no SETUP, so they keep probing unconditionally.\n\t\tif (this.#peerSetup) {\n\t\t\tconst probe = await this.#peerProbeLevel(this.#peerSetup);\n\t\t\tif (probe < ProbeLevel.Report) return;\n\t\t}\n\n\t\t// Probe is best-effort: any failure (stream reset by peer, missing peer support,\n\t\t// transport hiccup) MUST NOT tear down the connection. On error, drop the\n\t\t// estimates so consumers know they're stale.\n\t\ttry {\n\t\t\tconst stream = await Stream.open(this.#quic);\n\t\t\tawait stream.writer.u53(StreamId.Probe);\n\n\t\t\tfor (;;) {\n\t\t\t\tconst probe = await Probe.decodeMaybe(stream.reader, this.version);\n\t\t\t\tif (!probe) break;\n\t\t\t\t// A message that omits the RTT leaves the last one standing, so a\n\t\t\t\t// bitrate-only report doesn't blank it.\n\t\t\t\tconst prev = this.#probe.peek();\n\t\t\t\tthis.#probe.set({\n\t\t\t\t\testimatedRecvRate: probe.bitrate ?? undefined,\n\t\t\t\t\trtt: probe.rtt !== undefined ? Time.Milli(probe.rtt) : prev.rtt,\n\t\t\t\t});\n\t\t\t}\n\t\t} catch (err: unknown) {\n\t\t\tif (!this.#closed.signal.aborted) {\n\t\t\t\tconsole.warn(\"probe stream error\", err);\n\t\t\t}\n\t\t} finally {\n\t\t\tthis.#probe.set({});\n\t\t}\n\t}\n\n\tclose() {\n\t\tthis.#closed.abort();\n\n\t\tfor (const { track } of this.#subscribes.values()) {\n\t\t\ttrack.close();\n\t\t}\n\n\t\tthis.#subscribes.clear();\n\t}\n}\n\n/**\n * A broadcast consumed from a lite session. It resolves `track.Consumer.info()` and\n * `.fetchGroup()` over the wire (lite-05+ TRACK / FETCH streams) by reaching into the\n * {@link Subscriber} it was opened from, the way the Rust `BroadcastConsumer` holds its\n * session. Live subscribes still flow through the inherited requested() queue.\n */\nclass ConsumeBroadcast extends broadcast.Consumer {\n\t#subscriber: Subscriber;\n\t#path: Path.Valid;\n\n\tconstructor(subscriber: Subscriber, path: Path.Valid, state?: never) {\n\t\tsuper(state);\n\t\tthis.#subscriber = subscriber;\n\t\tthis.#path = path;\n\t}\n\n\t// Preserve the subclass (and its wire-backed info/fetchGroup) when the consume cache shares\n\t// this broadcast across callers.\n\toverride clone(): ConsumeBroadcast {\n\t\treturn new ConsumeBroadcast(this.#subscriber, this.#path, this.shareState());\n\t}\n\n\toverride resolveTrackInfo(name: string): Promise<track.Info> {\n\t\treturn this.#subscriber.resolveTrackInfo(this.#path, name);\n\t}\n\n\toverride fetchGroup(name: string, sequence: number, options?: track.FetchGroupOptions): Promise<netGroup.Consumer> {\n\t\treturn this.#subscriber.fetchGroup(this.#path, name, sequence, options);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"subscriber.js","sourceRoot":"","sources":["../../src/lite/subscriber.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,QAAQ,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAe,MAAM,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AAEnC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,eAAe,EAAE,4BAA4B,EAAE,MAAM,eAAe,CAAC;AACxG,OAAO,EAAE,QAAQ,IAAI,eAAe,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,KAAK,cAAc,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,KAAK,IAAI,YAAY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C;IACzE,CAAC;CACD","sourcesContent":["import { Signal } from \"@moq/signals\";\nimport * as announce from \"../announced.ts\";\nimport * as broadcast from \"../broadcast.ts\";\nimport type { Probe as ProbeStats } from \"../connection/stats.ts\";\nimport { BroadcastCache } from \"../consume.ts\";\nimport { error, reason } from \"../error.ts\";\nimport * as netGroup from \"../group.ts\";\nimport * as Path from \"../path.ts\";\nimport { type Reader, Stream } from \"../stream.ts\";\nimport * as Time from \"../time.ts\";\nimport type * as track from \"../track.ts\";\nimport { withTimeout } from \"../util/timeout.ts\";\nimport { AnnounceInit, AnnounceOk, AnnounceRequest, decodeAnnounceBroadcastMaybe } from \"./announce.ts\";\nimport { Datagram as DatagramMessage } from \"./datagram.ts\";\nimport * as DatagramStream from \"./datagram_stream.ts\";\nimport { Fetch as FetchMessage } from \"./fetch.ts\";\nimport type { Group as GroupMessage } from \"./group.ts\";\nimport type { Origin } from \"./origin.ts\";\nimport { Probe } from \"./probe.ts\";\nimport { ProbeLevel, type Setup } from \"./setup.ts\";\nimport { StreamId } from \"./stream.ts\";\nimport { decodeSubscribeResponse, decodeSubscribeResponseMaybe, Subscribe, SubscribeUpdate } from \"./subscribe.ts\";\nimport { TrackInfo, Track as TrackMessage } from \"./track.ts\";\nimport { hasAnnounceId, hasAnnounceOk, hasDatagrams, hasExcludeHop, Version } from \"./version.ts\";\n\n// Bound on how long stream-open plus the first response (SUBSCRIBE_OK on older\n// drafts, or TRACK_INFO on lite-05+) may take. Browsers cap concurrent QUIC\n// streams (Chrome ~100); past the cap createBidirectionalStream silently blocks.\n// The timeout turns that into a clear error.\nconst SUBSCRIBE_SETUP_TIMEOUT_MS = 10_000;\n\n/** Decode an unsigned zigzag varint back to a signed delta (mirrors Rust `VarInt::to_zigzag`). */\nfunction unzigzag(v: bigint): bigint {\n\treturn (v >> 1n) ^ -(v & 1n);\n}\n\n// The TRACK stream and implicit SUBSCRIBE acceptance are lite-05+.\nfunction supportsTrackStream(version: Version): boolean {\n\tswitch (version) {\n\t\tcase Version.DRAFT_01:\n\t\tcase Version.DRAFT_02:\n\t\tcase Version.DRAFT_03:\n\t\tcase Version.DRAFT_04:\n\t\t\treturn false;\n\t\tdefault:\n\t\t\treturn true;\n\t}\n}\n\n/**\n * Options accepted by {@link Subscriber.announced}.\n */\nexport interface AnnouncedOptions {\n\t/**\n\t * If true, skip announcements whose hop chain contains this connection's\n\t * own origin id. Useful for meshes that reflect announces back. Defaults\n\t * to false for backwards compatibility: existing code (notably hang.live)\n\t * relies on seeing its own publishes as the signal that a namespace\n\t * published successfully.\n\t *\n\t * Only meaningful on lite-04/05, where the peer filters reflected announces\n\t * on request (ANNOUNCE_REQUEST's `Exclude Hop`). Later versions dropped that\n\t * field, so reflected announces are always skipped.\n\t */\n\tignoreSelf?: boolean;\n}\n\ninterface SubscribeEntry {\n\t// The write side: incoming GROUP streams are routed here. The application reads\n\t// the matching track.Subscriber it got from broadcast.Consumer.subscribe.\n\ttrack: track.Producer;\n\t// Per-frame timestamp scale (0 = none). undefined until it's known (from TRACK_INFO\n\t// on lite-05+, or implicit defaults on older drafts). A non-zero value means each\n\t// frame on the group stream is prefixed with a zigzag-delta timestamp varint that\n\t// runGroup must consume to stay in sync; group streams block on it before decoding,\n\t// since a group's QUIC stream can race ahead of the subscribe stream.\n\ttimescale: Signal<number | undefined>;\n}\n\n/**\n * Handles subscribing to broadcasts and managing their lifecycle.\n *\n * @internal\n */\nexport class Subscriber {\n\t#quic: WebTransport;\n\n\t// The version of the connection.\n\treadonly version: Version;\n\n\t// Shared with the Publisher so callers can optionally filter out their\n\t// own announcements on a per-call basis (see {@link AnnouncedOptions}).\n\treadonly origin: Origin;\n\n\t// Our subscribed tracks. `timescale` resolves once known (from TRACK_INFO on\n\t// lite-05+, or implicit defaults on older drafts); group streams block on it\n\t// before decoding any frame, since a group's QUIC stream can race ahead.\n\t#subscribes = new Map<bigint, SubscribeEntry>();\n\t#subscribeNext = 0n;\n\n\t// Dedup consumed broadcasts per path: repeat consume() calls share one subscription.\n\t#consumes = new BroadcastCache();\n\n\t// Dedup in-flight one-shot fetches, keyed by [broadcast, track, sequence]. Concurrent (or\n\t// repeat, while still open) fetchGroup() calls for the same group share one FETCH stream and\n\t// each get an independent mirror; the entry is evicted once the group closes.\n\t#fetches = new Map<string, netGroup.Producer>();\n\n\t// The peer's PROBE estimates, written as they arrive (Lite03+ only).\n\t#probe?: Signal<ProbeStats>;\n\n\t// The peer's SETUP (lite-05+), undefined until it arrives. Gates opening the PROBE\n\t// stream on the peer having advertised Probe >= Report.\n\t#peerSetup?: Signal<Setup | undefined>;\n\n\t// Distinguishes failures from streams torn down by Subscriber.close().\n\t#closed = new AbortController();\n\t/**\n\t * Creates a new Subscriber instance.\n\t * @param quic - The WebTransport session to use\n\t * @param version - The protocol version\n\t * @param origin - Origin id shared with the Publisher\n\t * @param probe - Optional sink for the peer's PROBE estimates\n\t * @param peerSetup - Optional peer SETUP slot for capability gating (lite-05+)\n\t *\n\t * @internal\n\t */\n\tconstructor(\n\t\tquic: WebTransport,\n\t\tversion: Version,\n\t\torigin: Origin,\n\t\tprobe?: Signal<ProbeStats>,\n\t\tpeerSetup?: Signal<Setup | undefined>,\n\t) {\n\t\tthis.#quic = quic;\n\t\tthis.version = version;\n\t\tthis.origin = origin;\n\t\tthis.#probe = probe;\n\t\tthis.#peerSetup = peerSetup;\n\t}\n\n\t/**\n\t * Subscribe to broadcast announcements under `prefix`.\n\t *\n\t * Pass `{ ignoreSelf: true }` to skip announces that have already traversed\n\t * this connection's {@link origin}.\n\t */\n\tannounced(prefix = Path.empty(), options: AnnouncedOptions = {}): announce.Consumer {\n\t\tconst announced = new announce.Producer(prefix);\n\t\tvoid this.#runAnnounced(announced, prefix, options);\n\t\treturn announced.consume();\n\t}\n\n\tasync #runAnnounced(announced: announce.Producer, prefix: Path.Valid, options: AnnouncedOptions): Promise<void> {\n\t\tconsole.debug(`announced: prefix=${prefix}`);\n\t\t// Lite04/05: send our own session-level origin id so the peer can skip announces\n\t\t// whose hop chain already passed through us. Encoding drops it on every other\n\t\t// version, where we drop the reflected announce on receipt instead. Matches the\n\t\t// Rust subscriber's `exclude_hop: self.self_origin.id` in `run_announce_prefix`.\n\t\tconst msg = new AnnounceRequest(prefix, this.origin);\n\n\t\t// Drop reflected announces so callers asking for \"someone else's broadcasts\"\n\t\t// don't re-see their own publishes. A caller can always ask for this, and it is\n\t\t// required on versions that don't carry excludeHop above: there the peer isn't\n\t\t// filtering them out for us, so filtering here keeps what the app sees the same\n\t\t// as lite-05. Lite01-03 carry no real hop ids, so the check never matches there.\n\t\tconst dropReflected = options.ignoreSelf || !hasExcludeHop(this.version);\n\n\t\ttry {\n\t\t\t// Open a stream and send the announce interest.\n\t\t\tconst stream = await Stream.open(this.#quic);\n\t\t\tawait stream.writer.u53(StreamId.Announce);\n\t\t\tawait msg.encode(stream.writer, this.version);\n\n\t\t\t// Lite05+: the publisher reports its own origin id before any announces.\n\t\t\t// It no longer stamps itself onto each hop chain, so we append it here to\n\t\t\t// keep the ignoreSelf loop check seeing the full chain.\n\t\t\tlet responderOrigin: Origin | undefined;\n\t\t\tif (hasAnnounceOk(this.version)) {\n\t\t\t\tconst ok = await AnnounceOk.decode(stream.reader, this.version);\n\t\t\t\tresponderOrigin = ok.origin;\n\t\t\t}\n\n\t\t\tswitch (this.version) {\n\t\t\t\tcase Version.DRAFT_01:\n\t\t\t\tcase Version.DRAFT_02: {\n\t\t\t\t\t// Receive ANNOUNCE_INIT first\n\t\t\t\t\tconst init = await AnnounceInit.decode(stream.reader, this.version);\n\n\t\t\t\t\t// Process initial announcements\n\t\t\t\t\tfor (const suffix of init.suffixes) {\n\t\t\t\t\t\tconst path = Path.join(prefix, suffix);\n\t\t\t\t\t\tconsole.debug(`announced: broadcast=${path} active=true`);\n\t\t\t\t\t\tannounced.append({ path: suffix, active: true });\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\t// Draft03+: no AnnounceInit, initial state comes via Announce messages.\n\t\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\t// Lite06+: announce ids. Each received `active` implicitly assigns the next\n\t\t\t// per-stream ordinal; `endedId`/`restart` reference it. Tracked even for\n\t\t\t// announces we skip via ignoreSelf, since the sender doesn't know we skipped.\n\t\t\tlet nextAnnounceId = 0n;\n\t\t\tconst announcedById = new Map<bigint, Path.Valid>();\n\n\t\t\t// Receive announce updates (for Draft03, this includes initial state)\n\t\t\tfor (;;) {\n\t\t\t\tconst announce = await Promise.race([\n\t\t\t\t\tdecodeAnnounceBroadcastMaybe(stream.reader, this.version),\n\t\t\t\t\tannounced.closed,\n\t\t\t\t]);\n\t\t\t\t// undefined: the stream ended. null: the consumer closed cleanly.\n\t\t\t\tif (!announce) break;\n\t\t\t\tif (announce instanceof Error) throw announce;\n\n\t\t\t\tlet suffix: Path.Valid;\n\t\t\t\tlet active: boolean;\n\t\t\t\t// Present on active/restart; ended messages never carry hops worth checking.\n\t\t\t\tlet hops: Origin[] | undefined;\n\n\t\t\t\tswitch (announce.status) {\n\t\t\t\t\tcase \"active\":\n\t\t\t\t\t\tsuffix = announce.suffix;\n\t\t\t\t\t\tactive = true;\n\t\t\t\t\t\thops = announce.hops;\n\t\t\t\t\t\tif (hasAnnounceId(this.version)) {\n\t\t\t\t\t\t\tannouncedById.set(nextAnnounceId++, announce.suffix);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"ended\":\n\t\t\t\t\t\tsuffix = announce.suffix;\n\t\t\t\t\t\tactive = false;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"endedId\": {\n\t\t\t\t\t\t// Resolve and retire the id; an unknown or retired id is a protocol violation.\n\t\t\t\t\t\tconst path = announcedById.get(announce.id);\n\t\t\t\t\t\tif (path === undefined) throw new Error(`unknown announce id: ${announce.id}`);\n\t\t\t\t\t\tannouncedById.delete(announce.id);\n\t\t\t\t\t\tsuffix = path;\n\t\t\t\t\t\tactive = false;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"restart\": {\n\t\t\t\t\t\t// Resolve the id; it stays live (the replacement reuses it).\n\t\t\t\t\t\tconst path = announcedById.get(announce.id);\n\t\t\t\t\t\tif (path === undefined) throw new Error(`unknown announce id: ${announce.id}`);\n\t\t\t\t\t\tsuffix = path;\n\t\t\t\t\t\tactive = true;\n\t\t\t\t\t\thops = announce.hops;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// In Lite05+ the sender's origin arrives via AnnounceOk, not in each hop\n\t\t\t\t// list, so fold it back in before checking.\n\t\t\t\tif (hops !== undefined && dropReflected) {\n\t\t\t\t\tconst full = responderOrigin !== undefined ? [...hops, responderOrigin] : hops;\n\t\t\t\t\tif (full.includes(this.origin)) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst path = Path.join(prefix, suffix);\n\n\t\t\t\tconsole.debug(`announced: broadcast=${path} active=${active}`);\n\t\t\t\tannounced.append({ path: suffix, active });\n\t\t\t}\n\n\t\t\tannounced.close();\n\t\t} catch (err: unknown) {\n\t\t\tannounced.close(error(err));\n\t\t}\n\t}\n\n\t/**\n\t * Consumes a broadcast from the connection.\n\t *\n\t * Deduplicated per path: repeat calls for the same still-live path share one reference-counted\n\t * broadcast (and one upstream subscription). The shared broadcast closes once every caller has\n\t * closed its handle, so callers close normally.\n\t *\n\t * @param name - The name of the broadcast to consume\n\t * @returns A Broadcast instance\n\t */\n\tconsume(path: Path.Valid): broadcast.Consumer {\n\t\treturn this.#consumes.get(path) ?? this.#consumes.insert(path, this.#createConsume(path));\n\t}\n\n\t#createConsume(path: Path.Valid): broadcast.Consumer {\n\t\t// A consumed broadcast resolves info() and fetchGroup() over the wire by reaching\n\t\t// back into this Subscriber (see ConsumeBroadcast below), rather than the wire\n\t\t// installing callbacks on the broadcast.\n\t\tconst consumer = new ConsumeBroadcast(this, path);\n\n\t\tvoid (async () => {\n\t\t\tfor (;;) {\n\t\t\t\tconst request = await consumer.requested();\n\t\t\t\tif (!request) break;\n\t\t\t\tvoid this.#runSubscribe(path, request);\n\t\t\t}\n\t\t})();\n\n\t\treturn consumer;\n\t}\n\n\tasync #runSubscribe(broadcast: Path.Valid, request: track.Request) {\n\t\tconst id = this.#subscribeNext++;\n\n\t\t// `timescale` stays undefined until TRACK_INFO (or, on older drafts,\n\t\t// implicit defaults) resolves it; runGroup blocks on it before decoding.\n\t\tconst timescale = new Signal<number | undefined>(undefined);\n\n\t\tconsole.debug(`subscribe start: id=${id} broadcast=${broadcast} track=${request.name}`);\n\n\t\tconst msg = new Subscribe({ id, broadcast, track: request.name, priority: request.priority });\n\n\t\t// Open the stream under a timeout. The stream handle flows back via `state`\n\t\t// so the timeout path can abort it if it finishes opening after the deadline.\n\t\tconst state: { stream?: Stream } = {};\n\t\tconst setup = this.#openSubscribe(state, msg, request, id, timescale);\n\n\t\tlet opened: { stream: Stream; producer: track.Producer };\n\t\ttry {\n\t\t\topened = await withTimeout(\n\t\t\t\tsetup,\n\t\t\t\tSUBSCRIBE_SETUP_TIMEOUT_MS,\n\t\t\t\t`subscribe timed out after ${SUBSCRIBE_SETUP_TIMEOUT_MS}ms waiting for the first response (browser stream limit reached?)`,\n\t\t\t);\n\t\t\tconsole.debug(`subscribe ok: id=${id} broadcast=${broadcast} track=${request.name}`);\n\t\t} catch (err) {\n\t\t\tconst e = error(err);\n\t\t\trequest.reject(e);\n\t\t\tthis.#subscribes.delete(id);\n\t\t\tconsole.warn(`subscribe error: id=${id} broadcast=${broadcast} track=${request.name} error=${reason(e)}`);\n\t\t\t// If the stream eventually opens after the timeout, abort it so we\n\t\t\t// don't leak it. Cover both branches: setup may resolve late, or it\n\t\t\t// may reject (e.g. encode/decode failure) after the stream is open.\n\t\t\tsetup.then(\n\t\t\t\t() => state.stream?.abort(e),\n\t\t\t\t() => state.stream?.abort(e),\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tconst { stream, producer } = opened;\n\t\ttry {\n\t\t\t// Watch for priority changes and send SUBSCRIBE_UPDATE. Lite01/Lite02\n\t\t\t// don't carry SUBSCRIBE_UPDATE on the wire, so skip the watcher there\n\t\t\t// and just wait on the stream/track like before.\n\t\t\t//\n\t\t\t// On lite-05+ the publisher sends SUBSCRIBE_START/END/DROP on this stream;\n\t\t\t// drain them (we don't drive delivery off the resolved range) so the FIN is\n\t\t\t// observed. Older drafts just wait for the stream to close.\n\t\t\tconst closed = supportsTrackStream(this.version) ? this.#drainResponses(stream) : stream.reader.closed;\n\t\t\tconst priorityUpdates =\n\t\t\t\tthis.version === Version.DRAFT_01 || this.version === Version.DRAFT_02\n\t\t\t\t\t? undefined\n\t\t\t\t\t: this.#runPriorityUpdates(id, broadcast, producer, msg, stream);\n\n\t\t\t// Terminal conditions (stream end, track close, a failed priority update) settle at most\n\t\t\t// once; race them into one stable promise so the demand loop doesn't re-subscribe each pass.\n\t\t\tconst terminal: PromiseLike<unknown>[] = [closed, producer.closed];\n\t\t\tif (priorityUpdates !== undefined) terminal.push(priorityUpdates);\n\t\t\tconst done = Promise.race(terminal);\n\n\t\t\t// Serve until a terminal condition fires or the last local subscriber leaves. The unused\n\t\t\t// wake is level-triggered: re-check demand so a subscriber that returns before we tear\n\t\t\t// down (e.g. a quickly unmuted tile) resumes on the same subscription.\n\t\t\tconst idle = Symbol(\"idle\");\n\t\t\tfor (;;) {\n\t\t\t\tconst reason = await Promise.race([done, producer.unused().then(() => idle)]);\n\t\t\t\tif (reason === idle && producer.closed.peek() === undefined && producer.used.peek()) continue;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tproducer.close();\n\t\t\tstream.close();\n\t\t\tconsole.debug(`subscribe close: id=${id} broadcast=${broadcast} track=${request.name}`);\n\t\t} catch (err) {\n\t\t\tconst e = error(err);\n\t\t\tproducer.close(e);\n\t\t\tconsole.warn(`subscribe error: id=${id} broadcast=${broadcast} track=${request.name} error=${reason(e)}`);\n\t\t\tstream.abort(e);\n\t\t} finally {\n\t\t\tthis.#subscribes.delete(id);\n\t\t}\n\t}\n\n\t// Determine the track's immutable properties, accept the request (so the\n\t// application's track.Subscriber resolves and incoming groups have a producer to\n\t// write into), register it, then open the subscribe stream. `state.stream` is\n\t// populated as soon as the subscribe stream opens so the caller can clean it up\n\t// on timeout even before this promise settles.\n\t//\n\t// On lite-05+ the properties come from a TRACK stream opened first, and the\n\t// SUBSCRIBE is accepted implicitly (no SUBSCRIBE_OK). Older drafts carry no\n\t// per-track properties, so they resolve to defaults and just drain SUBSCRIBE_OK.\n\tasync #openSubscribe(\n\t\tstate: { stream?: Stream },\n\t\tmsg: Subscribe,\n\t\trequest: track.Request,\n\t\tid: bigint,\n\t\ttimescale: Signal<number | undefined>,\n\t): Promise<{ stream: Stream; producer: track.Producer }> {\n\t\tlet producer: track.Producer;\n\t\tlet drainOk = false;\n\n\t\tif (supportsTrackStream(this.version)) {\n\t\t\t// Fetch the immutable properties once via the TRACK stream.\n\t\t\tconst info = await this.#trackInfo(msg.broadcast, msg.track);\n\t\t\tproducer = request.accept(this.#toModelInfo(info));\n\t\t\ttimescale.set(info.timescale);\n\t\t} else {\n\t\t\t// Older drafts negotiate nothing per-track: verbatim frames, no timescale.\n\t\t\tproducer = request.accept();\n\t\t\ttimescale.set(0);\n\t\t\tdrainOk = true;\n\t\t}\n\n\t\t// Register before opening SUBSCRIBE so a racing GROUP stream finds the entry.\n\t\tthis.#subscribes.set(id, { track: producer, timescale });\n\n\t\tstate.stream = await Stream.open(this.#quic);\n\t\tawait state.stream.writer.u53(StreamId.Subscribe);\n\t\tawait msg.encode(state.stream.writer, this.version);\n\n\t\tif (drainOk) {\n\t\t\t// The first response MUST be a SUBSCRIBE_OK (older drafts only).\n\t\t\tconst resp = await decodeSubscribeResponse(state.stream.reader, this.version);\n\t\t\tif (!(\"ok\" in resp)) {\n\t\t\t\tthrow new Error(\"first subscribe response must be SUBSCRIBE_OK\");\n\t\t\t}\n\t\t}\n\n\t\treturn { stream: state.stream, producer };\n\t}\n\n\t// Opens a TRACK stream, reads the single TRACK_INFO, and FINs. Lite-05+ only.\n\tasync #trackInfo(broadcast: Path.Valid, track: string): Promise<TrackInfo> {\n\t\tconst stream = await Stream.open(this.#quic);\n\t\ttry {\n\t\t\tawait stream.writer.u53(StreamId.Track);\n\t\t\tawait new TrackMessage(broadcast, track).encode(stream.writer, this.version);\n\t\t\tconst info = await TrackInfo.decode(stream.reader, this.version);\n\t\t\t// The publisher FINs after TRACK_INFO; FIN our side too.\n\t\t\tstream.close();\n\t\t\treturn info;\n\t\t} catch (err) {\n\t\t\tstream.abort(error(err));\n\t\t\tthrow err;\n\t\t}\n\t}\n\n\t// Map the wire TRACK_INFO onto the model track.Info a producer/consumer holds.\n\t#toModelInfo(info: TrackInfo): track.Info {\n\t\treturn {\n\t\t\ttimescale: Time.Timescale(info.timescale),\n\t\t\t// Publisher Max Latency rides on the wire, so the local retention window\n\t\t\t// matches what the upstream advertises (relays re-serve with the same bound).\n\t\t\tlatencyMax: info.latencyMax,\n\t\t\tpriority: info.priority,\n\t\t\tordered: info.ordered,\n\t\t};\n\t}\n\n\t// Resolve a track's immutable model info via a TRACK stream (lite-05+), for the\n\t// ConsumeBroadcast backing track.Consumer.info(). On older drafts there's no TRACK\n\t// stream, so this rejects rather than fabricating defaults.\n\tasync resolveTrackInfo(broadcast: Path.Valid, track: string): Promise<track.Info> {\n\t\tif (!supportsTrackStream(this.version)) {\n\t\t\tthrow new Error(\"track info requires moq-lite-05 or newer\");\n\t\t}\n\t\treturn this.#toModelInfo(await this.#trackInfo(broadcast, track));\n\t}\n\n\t// Open a FETCH stream for one group and stream its bare frames into a group, for the\n\t// ConsumeBroadcast backing track.Consumer.fetchGroup() (lite-05+).\n\tfetchGroup(\n\t\tbroadcast: Path.Valid,\n\t\ttrack: string,\n\t\tsequence: number,\n\t\toptions: track.FetchGroupOptions = {},\n\t): Promise<netGroup.Consumer> {\n\t\t// Coalesce onto a still-open fetch of the same group so we don't open a second FETCH\n\t\t// stream (and re-download it); each caller reads an independent mirror.\n\t\tconst key = JSON.stringify([broadcast, track, sequence]);\n\t\tconst existing = this.#fetches.get(key);\n\t\tif (existing && !existing.isClosed) return Promise.resolve(existing.mirror());\n\n\t\t// Create and cache the group synchronously (before any await) so a concurrent fetch for\n\t\t// the same group finds it and coalesces rather than racing to open its own stream.\n\t\tconst group = new netGroup.Producer(sequence);\n\t\tthis.#fetches.set(key, group);\n\t\tvoid group.closed.then(() => {\n\t\t\tif (this.#fetches.get(key) === group) this.#fetches.delete(key);\n\t\t});\n\n\t\treturn this.#runFetch(broadcast, track, sequence, options, group);\n\t}\n\n\t// Open the FETCH stream and pump the response into the shared group. Setup errors close the\n\t// group (so coalesced mirrors observe them and the entry evicts) and reject this caller.\n\tasync #runFetch(\n\t\tbroadcast: Path.Valid,\n\t\ttrack: string,\n\t\tsequence: number,\n\t\toptions: track.FetchGroupOptions,\n\t\tgroup: netGroup.Producer,\n\t): Promise<netGroup.Consumer> {\n\t\ttry {\n\t\t\tif (!supportsTrackStream(this.version)) {\n\t\t\t\tthrow new Error(\"fetch group requires moq-lite-05 or newer\");\n\t\t\t}\n\n\t\t\tconst info = await this.#trackInfo(broadcast, track);\n\t\t\tconst priority = options.priority ?? 0;\n\t\t\tconst stream = await Stream.open(this.#quic, undefined, priority);\n\n\t\t\ttry {\n\t\t\t\tawait stream.writer.u53(StreamId.Fetch);\n\t\t\t\tawait new FetchMessage(broadcast, track, priority, sequence).encode(stream.writer, this.version);\n\t\t\t} catch (err: unknown) {\n\t\t\t\tstream.abort(error(err));\n\t\t\t\tthrow err;\n\t\t\t}\n\n\t\t\t// Mint this caller's reader before starting the pump, so the group has demand when the\n\t\t\t// pump begins watching it (an abandoned fetch cancels once every reader has left).\n\t\t\tconst consumer = group.mirror();\n\t\t\tvoid this.#runFetchResponse(stream, group, Time.Timescale(info.timescale));\n\t\t\treturn consumer;\n\t\t} catch (err: unknown) {\n\t\t\tgroup.close(error(err));\n\t\t\tthrow err;\n\t\t}\n\t}\n\n\t// Read the FETCH response (bare zigzag-delta-timestamped frames) into the group, then\n\t// FIN. A stream-level failure aborts the group so its reader observes the gap.\n\tasync #runFetchResponse(stream: Stream, group: netGroup.Producer, timescale: Time.Timescale): Promise<void> {\n\t\ttry {\n\t\t\tlet prevTs = 0n;\n\n\t\t\t// Serve until the stream FINs, the group closes, or every reader leaves. A group can\n\t\t\t// stay open indefinitely (a catalog or JSON stream), so an abandoned fetch is stopped by\n\t\t\t// demand, not by the stream ending. `closed` and `unused` are watched across frames as\n\t\t\t// stable promises (not re-subscribed to the signals each frame); the unused check is\n\t\t\t// level-triggered, so a coalesced fetch that arrives before we cancel re-arms and resumes.\n\t\t\tconst idle = Symbol(\"idle\");\n\t\t\tconst closed = Promise.resolve<Error | null>(group.closed);\n\t\t\tlet unused = group.unused().then(() => idle);\n\t\t\tfor (;;) {\n\t\t\t\tconst done = await Promise.race([stream.reader.done(), closed, unused]);\n\t\t\t\tif (done === idle) {\n\t\t\t\t\tif (!group.isClosed && group.used.peek()) {\n\t\t\t\t\t\tunused = group.unused().then(() => idle);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (done !== false) break;\n\n\t\t\t\tprevTs += unzigzag(await stream.reader.u62());\n\t\t\t\tconst timestamp = new Time.Timestamp(Number(prevTs), timescale);\n\t\t\t\tconst size = await stream.reader.u53();\n\t\t\t\tconst payload = await stream.reader.read(size);\n\t\t\t\tif (!payload) break;\n\t\t\t\tgroup.writeFrame({ payload, timestamp });\n\t\t\t}\n\n\t\t\tgroup.close();\n\t\t\tstream.close();\n\t\t} catch (err: unknown) {\n\t\t\tconst e = error(err);\n\t\t\tgroup.close(e);\n\t\t\tstream.abort(e);\n\t\t}\n\t}\n\n\t// Drains SUBSCRIBE_START/END/DROP on the subscribe stream until FIN (lite-05+).\n\t// The resolved range is informational here; the producer already orders groups.\n\t// Resolves (never rejects) on FIN or on the stream being reset out from under it,\n\t// so it's safe to drop from a Promise.race without an unhandled rejection.\n\tasync #drainResponses(stream: Stream): Promise<void> {\n\t\ttry {\n\t\t\tfor (;;) {\n\t\t\t\tconst resp = await decodeSubscribeResponseMaybe(stream.reader, this.version);\n\t\t\t\tif (!resp) return;\n\t\t\t}\n\t\t} catch {\n\t\t\t// Stream closed or reset; nothing more to drain.\n\t\t}\n\t}\n\n\t/**\n\t * Send SUBSCRIBE_UPDATE messages whenever the track's priority signal changes.\n\t *\n\t * Resolves cleanly when the stream or track closes, so the caller can include\n\t * this in Promise.race without leaving a dangling pending write that would\n\t * become an unhandled rejection if the user calls updatePriority after close.\n\t *\n\t * Peeks the signal at the top of every iteration so that updates which landed\n\t * before SubscribeOk arrived (or between iterations, before .next() registered\n\t * its listener) aren't lost.\n\t */\n\tasync #runPriorityUpdates(\n\t\tid: bigint,\n\t\tbroadcast: Path.Valid,\n\t\ttrack: track.Producer,\n\t\tmsg: Subscribe,\n\t\tstream: Stream,\n\t): Promise<void> {\n\t\tconst stopped: Promise<null> = Promise.race([track.closed, stream.reader.closed]).then(() => null);\n\t\tlet lastSent: number | undefined;\n\n\t\tfor (;;) {\n\t\t\tconst current = track.subscription.peek()?.priority;\n\t\t\tif (current === undefined || current === lastSent) {\n\t\t\t\t// Nothing new to send; wait for a change or termination.\n\t\t\t\tconst next = await Promise.race([track.subscription.changed(), stopped]);\n\t\t\t\tif (next === null) return;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Round-trip the other Subscribe parameters so the publisher doesn't\n\t\t\t// interpret SUBSCRIBE_UPDATE as a reset of ordered/maxLatency/etc.\n\t\t\tconst update = new SubscribeUpdate({\n\t\t\t\tpriority: current,\n\t\t\t\tordered: msg.ordered,\n\t\t\t\tmaxLatency: msg.maxLatency,\n\t\t\t\tstartGroup: msg.startGroup,\n\t\t\t\tendGroup: msg.endGroup,\n\t\t\t});\n\t\t\tawait update.encode(stream.writer, this.version);\n\t\t\tlastSent = current;\n\t\t\tconsole.debug(`subscribe update: id=${id} broadcast=${broadcast} track=${track.name} priority=${current}`);\n\t\t}\n\t}\n\n\t/**\n\t * Handles a group message.\n\t * @param group - The group message\n\t * @param stream - The stream to read frames from\n\t *\n\t * @internal\n\t */\n\tasync runGroup(group: GroupMessage, stream: Reader) {\n\t\tconst entry = this.#subscribes.get(group.subscribe);\n\t\tif (!entry) {\n\t\t\tif (group.subscribe >= this.#subscribeNext) {\n\t\t\t\tthrow new Error(`unknown subscription: id=${group.subscribe}`);\n\t\t\t}\n\n\t\t\treturn;\n\t\t}\n\n\t\tconst { track, timescale } = entry;\n\t\tconst producer = new netGroup.Producer(group.sequence);\n\t\ttrack.writeGroup(producer);\n\n\t\ttry {\n\t\t\t// Block until the timescale is known; the group's stream can arrive before\n\t\t\t// TRACK_INFO (or implicit defaults) resolves it on the subscribe stream.\n\t\t\tlet scale = timescale.peek();\n\t\t\twhile (scale === undefined) {\n\t\t\t\tif (track.closed.peek() !== undefined) {\n\t\t\t\t\t// Subscription ended before the scale resolved; nothing to decode.\n\t\t\t\t\tproducer.close();\n\t\t\t\t\tstream.stop(new Error(\"cancel\"));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tawait Signal.race(timescale, track.closed);\n\t\t\t\tscale = timescale.peek();\n\t\t\t}\n\n\t\t\t// A non-zero scale means every frame is prefixed with a zigzag-delta timestamp\n\t\t\t// (the lite-05 FRAME format), which we decode into a Timestamp at that scale.\n\t\t\t// Scale 0 (pre-lite-05) carries no timestamp, so we wall-clock-stamp.\n\t\t\tlet prevTs = 0n;\n\n\t\t\tfor (;;) {\n\t\t\t\tconst done = await Promise.race([stream.done(), track.closed, producer.closed]);\n\t\t\t\tif (done !== false) break;\n\n\t\t\t\tlet timestamp: Time.Timestamp;\n\t\t\t\tif (scale !== 0) {\n\t\t\t\t\tprevTs += unzigzag(await stream.u62());\n\t\t\t\t\ttimestamp = new Time.Timestamp(Number(prevTs), Time.Timescale(scale));\n\t\t\t\t} else {\n\t\t\t\t\ttimestamp = Time.Timestamp.now();\n\t\t\t\t}\n\n\t\t\t\tconst size = await stream.u53();\n\t\t\t\tconst payload = await stream.read(size);\n\t\t\t\tif (!payload) break;\n\n\t\t\t\tproducer.writeFrame({ payload, timestamp });\n\t\t\t}\n\n\t\t\tproducer.close();\n\t\t\tstream.stop(new Error(\"cancel\"));\n\t\t} catch (err: unknown) {\n\t\t\tconst e = error(err);\n\t\t\tproducer.close(e);\n\t\t\tstream.stop(e);\n\t\t}\n\t}\n\n\t/**\n\t * Receives QUIC datagrams and routes each to its subscription's track producer (lite-05 §6.4).\n\t *\n\t * Returns immediately on a non-datagram transport or pre-lite-05 version. A decode error or an\n\t * unknown subscribe id drops that datagram without tearing down the session (best-effort); the\n\t * loop ends only when the datagram stream closes.\n\t *\n\t * @internal\n\t */\n\tasync runDatagrams(): Promise<void> {\n\t\tif (!hasDatagrams(this.version) || DatagramStream.maxDatagramSize(this.#quic) === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Never reject: this loop is awaited alongside the connection's other tasks, so a\n\t\t// datagram-stream failure must not tear the whole session down (it's best-effort).\n\t\tconst reader = DatagramStream.datagramReader(this.#quic);\n\t\tif (!reader) return;\n\n\t\ttry {\n\t\t\ttry {\n\t\t\t\tfor (;;) {\n\t\t\t\t\tconst { value, done } = await reader.read();\n\t\t\t\t\tif (done) break;\n\t\t\t\t\tif (!value) continue;\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait this.#routeDatagram(value);\n\t\t\t\t\t} catch (err: unknown) {\n\t\t\t\t\t\tconsole.debug(`dropping datagram: ${reason(err)}`);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} finally {\n\t\t\t\treader.releaseLock();\n\t\t\t}\n\t\t} catch (err: unknown) {\n\t\t\tconst e = error(err);\n\t\t\tif (e.message === \"The session is closed.\") {\n\t\t\t\tconsole.debug(`datagram receive stopped: ${e.message}`);\n\t\t\t} else {\n\t\t\t\tconsole.warn(\"datagram stream error\", err);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Decode one datagram body and hand it to the matching subscription's producer. Drops the\n\t// datagram (best-effort) if the subscription is unknown/closed or its timescale isn't resolved.\n\tasync #routeDatagram(payload: Uint8Array): Promise<void> {\n\t\tconst dg = await DatagramMessage.decode(payload);\n\n\t\tconst entry = this.#subscribes.get(dg.subscribe);\n\t\tif (!entry) return; // Unknown or already-closed subscription.\n\n\t\t// Datagrams are lite-05+, which always negotiates a timescale; if it hasn't resolved\n\t\t// yet (the datagram raced ahead of TRACK_INFO), drop rather than guess.\n\t\tconst scale = entry.timescale.peek();\n\t\tif (!scale) return;\n\n\t\tconst timestamp = new Time.Timestamp(dg.timestamp, Time.Timescale(scale));\n\t\tentry.track.writeDatagram({ sequence: dg.sequence, timestamp, payload: dg.payload });\n\t}\n\n\t/**\n\t * Opens a PROBE bidi stream to receive bandwidth estimates from the publisher.\n\t * Returns immediately if recv bandwidth is not supported.\n\t *\n\t * Probe is best-effort telemetry: a stream-level failure (peer reset, FIN,\n\t * missing peer support, transport hiccup) is caught and logged, never\n\t * propagated to the connection. On exit the bandwidth/RTT signals are\n\t * cleared so consumers see them as stale.\n\t *\n\t * @internal\n\t */\n\t// Await the peer's advertised probe level, blocking until its SETUP arrives. The peer\n\t// MUST send exactly one SETUP, so this resolves once that stream is read.\n\tasync #peerProbeLevel(peerSetup: Signal<Setup | undefined>): Promise<ProbeLevel> {\n\t\tlet setup = peerSetup.peek();\n\t\twhile (setup === undefined) {\n\t\t\tsetup = await peerSetup.changed();\n\t\t}\n\t\treturn setup.probe;\n\t}\n\n\tasync runProbe(): Promise<void> {\n\t\tif (!this.#probe) return;\n\t\tif (this.version === Version.DRAFT_01 || this.version === Version.DRAFT_02) return;\n\n\t\t// Lite-05+ gates the PROBE stream on the peer advertising Probe >= Report in its\n\t\t// SETUP. Wait for the SETUP, then bail if the peer can't report bitrate. Older\n\t\t// drafts have no SETUP, so they keep probing unconditionally.\n\t\tif (this.#peerSetup) {\n\t\t\tconst probe = await this.#peerProbeLevel(this.#peerSetup);\n\t\t\tif (probe < ProbeLevel.Report) return;\n\t\t}\n\n\t\t// Probe is best-effort: any failure (stream reset by peer, missing peer support,\n\t\t// transport hiccup) MUST NOT tear down the connection. On error, drop the\n\t\t// estimates so consumers know they're stale.\n\t\ttry {\n\t\t\tconst stream = await Stream.open(this.#quic);\n\t\t\tawait stream.writer.u53(StreamId.Probe);\n\n\t\t\tfor (;;) {\n\t\t\t\tconst probe = await Probe.decodeMaybe(stream.reader, this.version);\n\t\t\t\tif (!probe) break;\n\t\t\t\t// A message that omits the RTT leaves the last one standing, so a\n\t\t\t\t// bitrate-only report doesn't blank it.\n\t\t\t\tconst prev = this.#probe.peek();\n\t\t\t\tthis.#probe.set({\n\t\t\t\t\testimatedRecvRate: probe.bitrate ?? undefined,\n\t\t\t\t\trtt: probe.rtt !== undefined ? Time.Milli(probe.rtt) : prev.rtt,\n\t\t\t\t});\n\t\t\t}\n\t\t} catch (err: unknown) {\n\t\t\tif (!this.#closed.signal.aborted) {\n\t\t\t\tconsole.warn(\"probe stream error\", err);\n\t\t\t}\n\t\t} finally {\n\t\t\tthis.#probe.set({});\n\t\t}\n\t}\n\n\tclose() {\n\t\tthis.#closed.abort();\n\n\t\tfor (const { track } of this.#subscribes.values()) {\n\t\t\ttrack.close();\n\t\t}\n\n\t\tthis.#subscribes.clear();\n\t}\n}\n\n/**\n * A broadcast consumed from a lite session. It resolves `track.Consumer.info()` and\n * `.fetchGroup()` over the wire (lite-05+ TRACK / FETCH streams) by reaching into the\n * {@link Subscriber} it was opened from, the way the Rust `BroadcastConsumer` holds its\n * session. Live subscribes still flow through the inherited requested() queue.\n */\nclass ConsumeBroadcast extends broadcast.Consumer {\n\t#subscriber: Subscriber;\n\t#path: Path.Valid;\n\n\tconstructor(subscriber: Subscriber, path: Path.Valid, state?: never) {\n\t\tsuper(state);\n\t\tthis.#subscriber = subscriber;\n\t\tthis.#path = path;\n\t}\n\n\t// Preserve the subclass (and its wire-backed info/fetchGroup) when the consume cache shares\n\t// this broadcast across callers.\n\toverride clone(): ConsumeBroadcast {\n\t\treturn new ConsumeBroadcast(this.#subscriber, this.#path, this.shareState());\n\t}\n\n\toverride resolveTrackInfo(name: string): Promise<track.Info> {\n\t\treturn this.#subscriber.resolveTrackInfo(this.#path, name);\n\t}\n\n\toverride fetchGroup(name: string, sequence: number, options?: track.FetchGroupOptions): Promise<netGroup.Consumer> {\n\t\treturn this.#subscriber.fetchGroup(this.#path, name, sequence, options);\n\t}\n}\n"]}
|
package/lite/version.d.ts
CHANGED
|
@@ -15,6 +15,17 @@ export declare function hasAnnounceOk(version: Version): boolean;
|
|
|
15
15
|
* per-stream ordinal, and `ended`/`restart` reference that id instead of repeating the
|
|
16
16
|
* path. Added in lite-06. */
|
|
17
17
|
export declare function hasAnnounceId(version: Version): boolean;
|
|
18
|
+
/** Whether ANNOUNCE_REQUEST carries the Exclude Hop field: the subscriber's own
|
|
19
|
+
* origin id, which the publisher uses to skip announces whose hop chain already
|
|
20
|
+
* passed through the subscriber. Present in lite-04 and lite-05 only.
|
|
21
|
+
*
|
|
22
|
+
* The receiver's own reflected-announce check drops those announces anyway (and
|
|
23
|
+
* catches loops of any length, not just the two-hop case), so lite-06 drops the
|
|
24
|
+
* field and keeps the check.
|
|
25
|
+
*
|
|
26
|
+
* Unlike the gates above, this lists the versions that *have* the field: it was
|
|
27
|
+
* removed rather than added, so future versions default to not carrying it. */
|
|
28
|
+
export declare function hasExcludeHop(version: Version): boolean;
|
|
18
29
|
/** Whether announcements carry a route cost varint alongside the hop chain: the
|
|
19
30
|
* marginal cost of pulling the broadcast via this route, accumulated per link.
|
|
20
31
|
* Added in lite-06. Older versions carry nothing, so a received route stays at
|
package/lite/version.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/lite/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAA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CAAC;AAI7D,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAWxD;AAKD,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAWtD;AAED,wGAAwG;AACxG,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAWvD;AAED;;6BAE6B;AAC7B,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAYvD;AAED;;;;;;;;;+EAS+E;AAC/E,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAQvD;AAED;;;6DAG6D;AAC7D,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAYtD;AAID,eAAO,MAAM,IAAI,SAAS,CAAC;AAG3B,eAAO,MAAM,OAAO,gBAAgB,CAAC;AAGrC,eAAO,MAAM,OAAO,gBAAgB,CAAC;AAGrC,eAAO,MAAM,OAAO,gBAAgB,CAAC;AAKrC,eAAO,MAAM,WAAW,oBAAoB,CAAC;AAW7C,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAE9C"}
|
package/lite/version.js
CHANGED
|
@@ -68,6 +68,25 @@ export function hasAnnounceId(version) {
|
|
|
68
68
|
return true;
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
+
/** Whether ANNOUNCE_REQUEST carries the Exclude Hop field: the subscriber's own
|
|
72
|
+
* origin id, which the publisher uses to skip announces whose hop chain already
|
|
73
|
+
* passed through the subscriber. Present in lite-04 and lite-05 only.
|
|
74
|
+
*
|
|
75
|
+
* The receiver's own reflected-announce check drops those announces anyway (and
|
|
76
|
+
* catches loops of any length, not just the two-hop case), so lite-06 drops the
|
|
77
|
+
* field and keeps the check.
|
|
78
|
+
*
|
|
79
|
+
* Unlike the gates above, this lists the versions that *have* the field: it was
|
|
80
|
+
* removed rather than added, so future versions default to not carrying it. */
|
|
81
|
+
export function hasExcludeHop(version) {
|
|
82
|
+
switch (version) {
|
|
83
|
+
case Version.DRAFT_04:
|
|
84
|
+
case Version.DRAFT_05:
|
|
85
|
+
return true;
|
|
86
|
+
default:
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
71
90
|
/** Whether announcements carry a route cost varint alongside the hop chain: the
|
|
72
91
|
* marginal cost of pulling the broadcast via this route, accumulated per link.
|
|
73
92
|
* Added in lite-06. Older versions carry nothing, so a received route stays at
|
package/lite/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/lite/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG;IACtB,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,UAAU;IACpB,mFAAmF;IACnF,iFAAiF;IACjF,+EAA+E;IAC/E,QAAQ,EAAE,UAAU;CACX,CAAC;AAIX,2FAA2F;AAC3F,wFAAwF;AACxF,MAAM,UAAU,cAAc,CAAC,OAAgB;IAC9C,kFAAkF;IAClF,QAAQ,OAAO,EAAE,CAAC;QACjB,KAAK,OAAO,CAAC,QAAQ,CAAC;QACtB,KAAK,OAAO,CAAC,QAAQ,CAAC;QACtB,KAAK,OAAO,CAAC,QAAQ,CAAC;QACtB,KAAK,OAAO,CAAC,QAAQ;YACpB,OAAO,KAAK,CAAC;QACd;YACC,OAAO,IAAI,CAAC;IACd,CAAC;AACF,CAAC;AAED,yFAAyF;AACzF,mGAAmG;AACnG,mGAAmG;AACnG,MAAM,UAAU,YAAY,CAAC,OAAgB;IAC5C,iFAAiF;IACjF,QAAQ,OAAO,EAAE,CAAC;QACjB,KAAK,OAAO,CAAC,QAAQ,CAAC;QACtB,KAAK,OAAO,CAAC,QAAQ,CAAC;QACtB,KAAK,OAAO,CAAC,QAAQ,CAAC;QACtB,KAAK,OAAO,CAA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G,aAAa,CAAC;AAErC,2EAA2E;AAC3E,MAAM,CAAC,MAAM,OAAO,GAAG,aAAa,CAAC;AAErC,2EAA2E;AAC3E,MAAM,CAAC,MAAM,OAAO,GAAG,aAAa,CAAC;AAErC,8EAA8E;AAC9E,kFAAkF;AAClF,+EAA+E;AAC/E,MAAM,CAAC,MAAM,WAAW,GAAG,iBAAiB,CAAC;AAE7C,MAAM,aAAa,GAA2B;IAC7C,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,aAAa;IACjC,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,aAAa;IACjC,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,aAAa;IACjC,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,aAAa;IACjC,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,aAAa;IACjC,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,iBAAiB;CACrC,CAAC;AAEF,MAAM,UAAU,WAAW,CAAC,CAAU;IACrC,OAAO,aAAa,CAAC,CAAC,CAAC,IAAI,aAAa,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,CAAC;AAC3D,CAAC","sourcesContent":["export const Version = {\n\tDRAFT_01: 0xff0dad01,\n\tDRAFT_02: 0xff0dad02,\n\tDRAFT_03: 0xff0dad03,\n\tDRAFT_04: 0xff0dad04,\n\tDRAFT_05: 0xff0dad05,\n\t/// Work-in-progress lite-06, advertised as the preferred WebTransport subprotocol.\n\t/// Adds announce ids: each active ANNOUNCE_BROADCAST implicitly assigns the next\n\t/// ordinal, and ended/restart reference that id instead of repeating the path.\n\tDRAFT_06: 0xff0dad06,\n} as const;\n\nexport type Version = (typeof Version)[keyof typeof Version];\n\n/// Whether the session opens a unidirectional Setup Stream carrying a single SETUP message\n/// (capabilities + optional Path). Added in lite-05; older drafts have no Setup Stream.\nexport function hasSetupStream(version: Version): boolean {\n\t// Explicitly list older versions so future versions default to having the stream.\n\tswitch (version) {\n\t\tcase Version.DRAFT_01:\n\t\tcase Version.DRAFT_02:\n\t\tcase Version.DRAFT_03:\n\t\tcase Version.DRAFT_04:\n\t\t\treturn false;\n\t\tdefault:\n\t\t\treturn true;\n\t}\n}\n\n/// Whether the session may deliver groups over unreliable QUIC datagrams (lite-05 §6.4).\n/// A datagram carries one single-frame group's `subscribe | sequence | timestamp | payload` and is\n/// routed over the existing subscription. Added in lite-05; older versions never send/accept them.\nexport function hasDatagrams(version: Version): boolean {\n\t// Explicitly list older versions so future versions default to having datagrams.\n\tswitch (version) {\n\t\tcase Version.DRAFT_01:\n\t\tcase Version.DRAFT_02:\n\t\tcase Version.DRAFT_03:\n\t\tcase Version.DRAFT_04:\n\t\t\treturn false;\n\t\tdefault:\n\t\t\treturn true;\n\t}\n}\n\n/** Whether announce streams begin with ANNOUNCE_OK and omit the sender's origin from each hop chain. */\nexport function hasAnnounceOk(version: Version): boolean {\n\t// Explicitly list older versions so future versions keep the lite-05+ announce behavior.\n\tswitch (version) {\n\t\tcase Version.DRAFT_01:\n\t\tcase Version.DRAFT_02:\n\t\tcase Version.DRAFT_03:\n\t\tcase Version.DRAFT_04:\n\t\t\treturn false;\n\t\tdefault:\n\t\t\treturn true;\n\t}\n}\n\n/** Whether announcements carry implicit announce ids: each `active` assigns the next\n * per-stream ordinal, and `ended`/`restart` reference that id instead of repeating the\n * path. Added in lite-06. */\nexport function hasAnnounceId(version: Version): boolean {\n\t// Explicitly list older versions so future versions keep the lite-06+ announce behavior.\n\tswitch (version) {\n\t\tcase Version.DRAFT_01:\n\t\tcase Version.DRAFT_02:\n\t\tcase Version.DRAFT_03:\n\t\tcase Version.DRAFT_04:\n\t\tcase Version.DRAFT_05:\n\t\t\treturn false;\n\t\tdefault:\n\t\t\treturn true;\n\t}\n}\n\n/** Whether announcements carry a route cost varint alongside the hop chain: the\n * marginal cost of pulling the broadcast via this route, accumulated per link.\n * Added in lite-06. Older versions carry nothing, so a received route stays at\n * zero and routing falls back to the hop-count tie-break. */\nexport function hasRouteCost(version: Version): boolean {\n\t// Explicitly list older versions so future versions keep the lite-06+ behavior.\n\tswitch (version) {\n\t\tcase Version.DRAFT_01:\n\t\tcase Version.DRAFT_02:\n\t\tcase Version.DRAFT_03:\n\t\tcase Version.DRAFT_04:\n\t\tcase Version.DRAFT_05:\n\t\t\treturn false;\n\t\tdefault:\n\t\t\treturn true;\n\t}\n}\n\n/// The WebTransport subprotocol identifier for moq-lite.\n/// Version negotiation still happens via SETUP when this is used.\nexport const ALPN = \"moql\";\n\n/// The ALPN string for Draft03, which uses ALPN-based version negotiation.\nexport const ALPN_03 = \"moq-lite-03\";\n\n/// The ALPN string for Draft04, which uses ALPN-based version negotiation.\nexport const ALPN_04 = \"moq-lite-04\";\n\n/// The ALPN string for Draft05, which uses ALPN-based version negotiation.\nexport const ALPN_05 = \"moq-lite-05\";\n\n/// The ALPN string for the work-in-progress Draft06. It is NOT in the default\n/// WebTransport `protocols` list, so lite-06 is never advertised or negotiated by\n/// default; a peer only reaches it when both sides explicitly offer this ALPN.\nexport const ALPN_06_WIP = \"moq-lite-06-wip\";\n\nconst VERSION_NAMES: Record<number, string> = {\n\t[Version.DRAFT_01]: \"moq-lite-01\",\n\t[Version.DRAFT_02]: \"moq-lite-02\",\n\t[Version.DRAFT_03]: \"moq-lite-03\",\n\t[Version.DRAFT_04]: \"moq-lite-04\",\n\t[Version.DRAFT_05]: \"moq-lite-05\",\n\t[Version.DRAFT_06]: \"moq-lite-06-wip\",\n};\n\nexport function versionName(v: Version): string {\n\treturn VERSION_NAMES[v] ?? `unknown(0x${v.toString(16)})`;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/lite/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG;IACtB,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,UAAU;IACpB,mFAAmF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,QAAQ,CAAC,EAAE,aAAa;IACjC,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,aAAa;IACjC,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,aAAa;IACjC,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,aAAa;IACjC,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,iBAAiB;CACrC,CAAC;AAEF,MAAM,UAAU,WAAW,CAAC,CAAU;IACrC,OAAO,aAAa,CAAC,CAAC,CAAC,IAAI,aAAa,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,CAAC;AAC3D,CAAC","sourcesContent":["export const Version = {\n\tDRAFT_01: 0xff0dad01,\n\tDRAFT_02: 0xff0dad02,\n\tDRAFT_03: 0xff0dad03,\n\tDRAFT_04: 0xff0dad04,\n\tDRAFT_05: 0xff0dad05,\n\t/// Work-in-progress lite-06, advertised as the preferred WebTransport subprotocol.\n\t/// Adds announce ids: each active ANNOUNCE_BROADCAST implicitly assigns the next\n\t/// ordinal, and ended/restart reference that id instead of repeating the path.\n\tDRAFT_06: 0xff0dad06,\n} as const;\n\nexport type Version = (typeof Version)[keyof typeof Version];\n\n/// Whether the session opens a unidirectional Setup Stream carrying a single SETUP message\n/// (capabilities + optional Path). Added in lite-05; older drafts have no Setup Stream.\nexport function hasSetupStream(version: Version): boolean {\n\t// Explicitly list older versions so future versions default to having the stream.\n\tswitch (version) {\n\t\tcase Version.DRAFT_01:\n\t\tcase Version.DRAFT_02:\n\t\tcase Version.DRAFT_03:\n\t\tcase Version.DRAFT_04:\n\t\t\treturn false;\n\t\tdefault:\n\t\t\treturn true;\n\t}\n}\n\n/// Whether the session may deliver groups over unreliable QUIC datagrams (lite-05 §6.4).\n/// A datagram carries one single-frame group's `subscribe | sequence | timestamp | payload` and is\n/// routed over the existing subscription. Added in lite-05; older versions never send/accept them.\nexport function hasDatagrams(version: Version): boolean {\n\t// Explicitly list older versions so future versions default to having datagrams.\n\tswitch (version) {\n\t\tcase Version.DRAFT_01:\n\t\tcase Version.DRAFT_02:\n\t\tcase Version.DRAFT_03:\n\t\tcase Version.DRAFT_04:\n\t\t\treturn false;\n\t\tdefault:\n\t\t\treturn true;\n\t}\n}\n\n/** Whether announce streams begin with ANNOUNCE_OK and omit the sender's origin from each hop chain. */\nexport function hasAnnounceOk(version: Version): boolean {\n\t// Explicitly list older versions so future versions keep the lite-05+ announce behavior.\n\tswitch (version) {\n\t\tcase Version.DRAFT_01:\n\t\tcase Version.DRAFT_02:\n\t\tcase Version.DRAFT_03:\n\t\tcase Version.DRAFT_04:\n\t\t\treturn false;\n\t\tdefault:\n\t\t\treturn true;\n\t}\n}\n\n/** Whether announcements carry implicit announce ids: each `active` assigns the next\n * per-stream ordinal, and `ended`/`restart` reference that id instead of repeating the\n * path. Added in lite-06. */\nexport function hasAnnounceId(version: Version): boolean {\n\t// Explicitly list older versions so future versions keep the lite-06+ announce behavior.\n\tswitch (version) {\n\t\tcase Version.DRAFT_01:\n\t\tcase Version.DRAFT_02:\n\t\tcase Version.DRAFT_03:\n\t\tcase Version.DRAFT_04:\n\t\tcase Version.DRAFT_05:\n\t\t\treturn false;\n\t\tdefault:\n\t\t\treturn true;\n\t}\n}\n\n/** Whether ANNOUNCE_REQUEST carries the Exclude Hop field: the subscriber's own\n * origin id, which the publisher uses to skip announces whose hop chain already\n * passed through the subscriber. Present in lite-04 and lite-05 only.\n *\n * The receiver's own reflected-announce check drops those announces anyway (and\n * catches loops of any length, not just the two-hop case), so lite-06 drops the\n * field and keeps the check.\n *\n * Unlike the gates above, this lists the versions that *have* the field: it was\n * removed rather than added, so future versions default to not carrying it. */\nexport function hasExcludeHop(version: Version): boolean {\n\tswitch (version) {\n\t\tcase Version.DRAFT_04:\n\t\tcase Version.DRAFT_05:\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\n/** Whether announcements carry a route cost varint alongside the hop chain: the\n * marginal cost of pulling the broadcast via this route, accumulated per link.\n * Added in lite-06. Older versions carry nothing, so a received route stays at\n * zero and routing falls back to the hop-count tie-break. */\nexport function hasRouteCost(version: Version): boolean {\n\t// Explicitly list older versions so future versions keep the lite-06+ behavior.\n\tswitch (version) {\n\t\tcase Version.DRAFT_01:\n\t\tcase Version.DRAFT_02:\n\t\tcase Version.DRAFT_03:\n\t\tcase Version.DRAFT_04:\n\t\tcase Version.DRAFT_05:\n\t\t\treturn false;\n\t\tdefault:\n\t\t\treturn true;\n\t}\n}\n\n/// The WebTransport subprotocol identifier for moq-lite.\n/// Version negotiation still happens via SETUP when this is used.\nexport const ALPN = \"moql\";\n\n/// The ALPN string for Draft03, which uses ALPN-based version negotiation.\nexport const ALPN_03 = \"moq-lite-03\";\n\n/// The ALPN string for Draft04, which uses ALPN-based version negotiation.\nexport const ALPN_04 = \"moq-lite-04\";\n\n/// The ALPN string for Draft05, which uses ALPN-based version negotiation.\nexport const ALPN_05 = \"moq-lite-05\";\n\n/// The ALPN string for the work-in-progress Draft06. It is NOT in the default\n/// WebTransport `protocols` list, so lite-06 is never advertised or negotiated by\n/// default; a peer only reaches it when both sides explicitly offer this ALPN.\nexport const ALPN_06_WIP = \"moq-lite-06-wip\";\n\nconst VERSION_NAMES: Record<number, string> = {\n\t[Version.DRAFT_01]: \"moq-lite-01\",\n\t[Version.DRAFT_02]: \"moq-lite-02\",\n\t[Version.DRAFT_03]: \"moq-lite-03\",\n\t[Version.DRAFT_04]: \"moq-lite-04\",\n\t[Version.DRAFT_05]: \"moq-lite-05\",\n\t[Version.DRAFT_06]: \"moq-lite-06-wip\",\n};\n\nexport function versionName(v: Version): string {\n\treturn VERSION_NAMES[v] ?? `unknown(0x${v.toString(16)})`;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moq/net",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.2",
|
|
5
5
|
"description": "The networking layer for Media over QUIC: real-time pub/sub with built-in caching, fan-out, and prioritization.",
|
|
6
6
|
"license": "(MIT OR Apache-2.0)",
|
|
7
7
|
"repository": "github:moq-dev/moq",
|