@moq/net 0.4.0 → 0.4.1

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.
Files changed (121) hide show
  1. package/announced.d.ts +14 -0
  2. package/announced.d.ts.map +1 -1
  3. package/announced.js.map +1 -1
  4. package/broadcast.d.ts +6 -3
  5. package/broadcast.d.ts.map +1 -1
  6. package/broadcast.js +9 -5
  7. package/broadcast.js.map +1 -1
  8. package/connection/accept.js +9 -1
  9. package/connection/accept.js.map +1 -1
  10. package/connection/connect.d.ts.map +1 -1
  11. package/connection/connect.js +10 -1
  12. package/connection/connect.js.map +1 -1
  13. package/connection/established.d.ts +2 -1
  14. package/connection/established.d.ts.map +1 -1
  15. package/connection/established.js.map +1 -1
  16. package/connection/forward.js +9 -2
  17. package/connection/forward.js.map +1 -1
  18. package/connection/handshake.d.ts +1 -0
  19. package/connection/handshake.d.ts.map +1 -1
  20. package/connection/handshake.js +3 -0
  21. package/connection/handshake.js.map +1 -1
  22. package/connection/pool.d.ts +8 -10
  23. package/connection/pool.d.ts.map +1 -1
  24. package/connection/pool.js +18 -8
  25. package/connection/pool.js.map +1 -1
  26. package/connection/reload.js +6 -6
  27. package/connection/reload.js.map +1 -1
  28. package/error.d.ts.map +1 -1
  29. package/error.js +21 -0
  30. package/error.js.map +1 -1
  31. package/ietf/adapter.d.ts +5 -1
  32. package/ietf/adapter.d.ts.map +1 -1
  33. package/ietf/adapter.js +27 -9
  34. package/ietf/adapter.js.map +1 -1
  35. package/ietf/connection.d.ts +1 -1
  36. package/ietf/connection.d.ts.map +1 -1
  37. package/ietf/connection.js +9 -5
  38. package/ietf/connection.js.map +1 -1
  39. package/ietf/error.js +27 -2
  40. package/ietf/error.js.map +1 -1
  41. package/ietf/hidden.d.ts +2 -0
  42. package/ietf/hidden.d.ts.map +1 -0
  43. package/ietf/hidden.js +30 -0
  44. package/ietf/hidden.js.map +1 -0
  45. package/ietf/index.d.ts +1 -0
  46. package/ietf/index.d.ts.map +1 -1
  47. package/ietf/index.js +1 -0
  48. package/ietf/index.js.map +1 -1
  49. package/ietf/object.d.ts +8 -2
  50. package/ietf/object.d.ts.map +1 -1
  51. package/ietf/object.js +17 -3
  52. package/ietf/object.js.map +1 -1
  53. package/ietf/parameters.d.ts +5 -0
  54. package/ietf/parameters.d.ts.map +1 -1
  55. package/ietf/parameters.js +20 -0
  56. package/ietf/parameters.js.map +1 -1
  57. package/ietf/properties.d.ts +1 -0
  58. package/ietf/properties.d.ts.map +1 -1
  59. package/ietf/properties.js +14 -0
  60. package/ietf/properties.js.map +1 -1
  61. package/ietf/publish.d.ts +19 -2
  62. package/ietf/publish.d.ts.map +1 -1
  63. package/ietf/publish.js +40 -6
  64. package/ietf/publish.js.map +1 -1
  65. package/ietf/publisher.js +114 -60
  66. package/ietf/publisher.js.map +1 -1
  67. package/ietf/subscribe.d.ts.map +1 -1
  68. package/ietf/subscribe.js +3 -4
  69. package/ietf/subscribe.js.map +1 -1
  70. package/ietf/subscribe_namespace.d.ts +8 -2
  71. package/ietf/subscribe_namespace.d.ts.map +1 -1
  72. package/ietf/subscribe_namespace.js +18 -8
  73. package/ietf/subscribe_namespace.js.map +1 -1
  74. package/ietf/subscriber.js +189 -66
  75. package/ietf/subscriber.js.map +1 -1
  76. package/internal.d.ts +7 -0
  77. package/internal.d.ts.map +1 -1
  78. package/internal.js +11 -0
  79. package/internal.js.map +1 -1
  80. package/lite/announce.d.ts +46 -2
  81. package/lite/announce.d.ts.map +1 -1
  82. package/lite/announce.js +126 -11
  83. package/lite/announce.js.map +1 -1
  84. package/lite/connection.d.ts +1 -1
  85. package/lite/connection.d.ts.map +1 -1
  86. package/lite/connection.js +9 -3
  87. package/lite/connection.js.map +1 -1
  88. package/lite/publisher.js +168 -109
  89. package/lite/publisher.js.map +1 -1
  90. package/lite/subscribe.d.ts +10 -4
  91. package/lite/subscribe.d.ts.map +1 -1
  92. package/lite/subscribe.js +20 -10
  93. package/lite/subscribe.js.map +1 -1
  94. package/lite/subscriber.d.ts +10 -2
  95. package/lite/subscriber.d.ts.map +1 -1
  96. package/lite/subscriber.js +159 -93
  97. package/lite/subscriber.js.map +1 -1
  98. package/lite/version.d.ts +11 -0
  99. package/lite/version.d.ts.map +1 -1
  100. package/lite/version.js +56 -0
  101. package/lite/version.js.map +1 -1
  102. package/origin.d.ts +37 -18
  103. package/origin.d.ts.map +1 -1
  104. package/origin.js +248 -103
  105. package/origin.js.map +1 -1
  106. package/package.json +7 -3
  107. package/stream.d.ts +2 -2
  108. package/stream.d.ts.map +1 -1
  109. package/stream.js +16 -11
  110. package/stream.js.map +1 -1
  111. package/tail.d.ts +11 -0
  112. package/tail.d.ts.map +1 -0
  113. package/tail.js +121 -0
  114. package/tail.js.map +1 -0
  115. package/track.d.ts +33 -5
  116. package/track.d.ts.map +1 -1
  117. package/track.js +98 -30
  118. package/track.js.map +1 -1
  119. package/wire.d.ts +2 -0
  120. package/wire.d.ts.map +1 -1
  121. package/wire.js.map +1 -1
package/lite/announce.js CHANGED
@@ -3,7 +3,7 @@ import { ProtocolViolation } from "../error.js";
3
3
  import { HopSchema, MAX_HOPS, UNKNOWN_HOP } from "../hop.js";
4
4
  import * as Path from "../path.js";
5
5
  import * as Message from "./message.js";
6
- import { hasAnnounceId, hasAnnounceOk, hasExcludeHop, hasRouteCost, Version } from "./version.js";
6
+ import { hasAnnounceCompression, hasAnnounceId, hasAnnounceOk, hasExcludeHop, hasHidden, hasRouteCost, Version, } from "./version.js";
7
7
  // Pre-lite-06 inner status values, carried inside the single ANNOUNCE_BROADCAST body.
8
8
  const STATUS_ENDED = 0;
9
9
  const STATUS_ACTIVE = 1;
@@ -80,6 +80,52 @@ async function decodeHops(r, version) {
80
80
  }
81
81
  }
82
82
  }
83
+ // Lite-07 carries a base around a path and a hop list. A distance of 0 names
84
+ // nothing, and a keep without a base is a violation. Other versions have no room for
85
+ // a base at all.
86
+ function checkBase(version, base) {
87
+ if (base && !hasAnnounceCompression(version)) {
88
+ throw new Error("announce compression not supported for this version");
89
+ }
90
+ }
91
+ function toBase(distance, keep) {
92
+ if (distance !== 0n)
93
+ return { distance, keep };
94
+ if (keep !== 0)
95
+ throw new ProtocolViolation("announce keep without a base");
96
+ return undefined;
97
+ }
98
+ async function encodePath(w, version, suffix, base) {
99
+ checkBase(version, base);
100
+ if (hasAnnounceCompression(version)) {
101
+ await w.u62(base?.distance ?? 0n);
102
+ await w.u53(base?.keep ?? 0);
103
+ }
104
+ await w.string(Path.encode(suffix));
105
+ }
106
+ async function decodePath(r, version) {
107
+ if (!hasAnnounceCompression(version))
108
+ return { suffix: Path.decode(await r.string()) };
109
+ const pathBase = toBase(await r.u62(), await r.u53());
110
+ const suffix = Path.decode(await r.string());
111
+ return pathBase ? { suffix, pathBase } : { suffix };
112
+ }
113
+ async function encodeHopsBlock(w, version, hops, base) {
114
+ checkBase(version, base);
115
+ if (!hasAnnounceCompression(version))
116
+ return encodeHops(w, version, hops);
117
+ await w.u62(base?.distance ?? 0n);
118
+ await encodeHops(w, version, hops);
119
+ await w.u53(base?.keep ?? 0);
120
+ }
121
+ async function decodeHopsBlock(r, version) {
122
+ if (!hasAnnounceCompression(version))
123
+ return { hops: await decodeHops(r, version) };
124
+ const distance = await r.u62();
125
+ const hops = await decodeHops(r, version);
126
+ const hopBase = toBase(distance, await r.u53());
127
+ return hopBase ? { hops, hopBase } : { hops };
128
+ }
83
129
  // The route cost rides lite-06+ announcements as two varints, warm then cold; older
84
130
  // versions carry neither.
85
131
  async function encodeRouteCost(w, version, cost) {
@@ -97,8 +143,8 @@ async function decodeRouteCost(r, version) {
97
143
  async function encodeAnnounce06Body(w, msg, version) {
98
144
  switch (msg.status) {
99
145
  case "active":
100
- await w.string(Path.encode(msg.suffix));
101
- await encodeHops(w, version, msg.hops);
146
+ await encodePath(w, version, msg.suffix, msg.pathBase);
147
+ await encodeHopsBlock(w, version, msg.hops, msg.hopBase);
102
148
  await encodeRouteCost(w, version, msg.cost);
103
149
  break;
104
150
  case "endedId":
@@ -106,7 +152,7 @@ async function encodeAnnounce06Body(w, msg, version) {
106
152
  break;
107
153
  case "restart":
108
154
  await w.u62(msg.id);
109
- await encodeHops(w, version, msg.hops);
155
+ await encodeHopsBlock(w, version, msg.hops, msg.hopBase);
110
156
  await encodeRouteCost(w, version, msg.cost);
111
157
  break;
112
158
  case "ended":
@@ -134,16 +180,16 @@ function announce06Type(msg) {
134
180
  async function decodeAnnounce06Body(r, typ, version) {
135
181
  switch (typ) {
136
182
  case ANNOUNCE_START: {
137
- const suffix = Path.decode(await r.string());
138
- const hops = await decodeHops(r, version);
139
- return { status: "active", suffix, hops, cost: await decodeRouteCost(r, version) };
183
+ const path = await decodePath(r, version);
184
+ const hops = await decodeHopsBlock(r, version);
185
+ return { status: "active", ...path, ...hops, cost: await decodeRouteCost(r, version) };
140
186
  }
141
187
  case ANNOUNCE_END:
142
188
  return { status: "endedId", id: await r.u62() };
143
189
  case ANNOUNCE_RESTART: {
144
190
  const id = await r.u62();
145
- const hops = await decodeHops(r, version);
146
- return { status: "restart", id, hops, cost: await decodeRouteCost(r, version) };
191
+ const hops = await decodeHopsBlock(r, version);
192
+ return { status: "restart", id, ...hops, cost: await decodeRouteCost(r, version) };
147
193
  }
148
194
  default:
149
195
  // Skip the length-prefixed body so an earlier Lite06 build negotiating
@@ -156,6 +202,7 @@ async function decodeAnnounce06Body(r, typ, version) {
156
202
  async function encodeLegacyBody(w, msg, version) {
157
203
  switch (msg.status) {
158
204
  case "active":
205
+ checkBase(version, msg.pathBase ?? msg.hopBase);
159
206
  await w.u8(STATUS_ACTIVE);
160
207
  await w.string(Path.encode(msg.suffix));
161
208
  await encodeHops(w, version, msg.hops);
@@ -211,6 +258,65 @@ export async function decodeAnnounceBroadcastMaybe(r, version) {
211
258
  }
212
259
  return Message.decodeMaybe(r, (r) => decodeLegacyBody(r, version));
213
260
  }
261
+ /**
262
+ * The live announcements on one lite-06+ announce stream, by Announce ID: what
263
+ * ANNOUNCE_END and ANNOUNCE_UPDATE reference, and what a lite-07 base copies from.
264
+ * Every violation throws {@link ProtocolViolation}.
265
+ */
266
+ export class AnnounceHistory {
267
+ #next = 0n;
268
+ #live = new Map();
269
+ #base(base) {
270
+ const live = this.#live.get(this.#next - base.distance);
271
+ if (!live)
272
+ throw new ProtocolViolation(`announce base ${base.distance} is not live`);
273
+ return live;
274
+ }
275
+ #hops(hops, base) {
276
+ if (!base)
277
+ return hops;
278
+ const tail = this.#base(base).hops;
279
+ if (base.keep > tail.length)
280
+ throw new ProtocolViolation(`announce keeps ${base.keep} of ${tail.length} hops`);
281
+ const resolved = [...hops, ...tail.slice(tail.length - base.keep)];
282
+ checkHops(resolved);
283
+ return resolved;
284
+ }
285
+ /** An ANNOUNCE_START: resolve it and assign it the next id. */
286
+ start(msg) {
287
+ let suffix = msg.suffix;
288
+ if (msg.pathBase) {
289
+ const head = Path.parts(this.#base(msg.pathBase).suffix);
290
+ const keep = msg.pathBase.keep;
291
+ if (keep > head.length)
292
+ throw new ProtocolViolation(`announce keeps ${keep} of ${head.length} segments`);
293
+ suffix = Path.join(Path.from(...head.slice(0, keep)), suffix);
294
+ if (Path.parts(suffix).length > Path.MAX_PARTS) {
295
+ throw new ProtocolViolation(`path exceeds ${Path.MAX_PARTS} parts`);
296
+ }
297
+ }
298
+ const hops = this.#hops(msg.hops, msg.hopBase);
299
+ this.#live.set(this.#next++, { suffix, hops });
300
+ return { suffix, hops };
301
+ }
302
+ /** An ANNOUNCE_UPDATE: resolve its chain before replacing the old one, which it may be based on. */
303
+ update(msg) {
304
+ const hops = this.#hops(msg.hops, msg.hopBase);
305
+ const live = this.#live.get(msg.id);
306
+ if (!live)
307
+ throw new ProtocolViolation(`unknown announce id: ${msg.id}`);
308
+ this.#live.set(msg.id, { suffix: live.suffix, hops });
309
+ return { suffix: live.suffix, hops };
310
+ }
311
+ /** An ANNOUNCE_END: retire the id, returning its suffix. */
312
+ end(id) {
313
+ const live = this.#live.get(id);
314
+ if (!live)
315
+ throw new ProtocolViolation(`unknown announce id: ${id}`);
316
+ this.#live.delete(id);
317
+ return live.suffix;
318
+ }
319
+ }
214
320
  /**
215
321
  * ANNOUNCE_REQUEST: sent by the subscriber to request ANNOUNCE_BROADCAST messages
216
322
  * for a path prefix. Renamed from `AnnounceInterest` in lite-05.
@@ -224,20 +330,29 @@ export class AnnounceRequest {
224
330
  *
225
331
  * Must be a bigint: peer origins are up to 62 bits and overflow u53. */
226
332
  excludeHop;
227
- constructor(prefix, excludeHop = 0n) {
333
+ /** Lite07+: also announce routes with a `.`-prefixed segment below the prefix. Not on
334
+ * the wire earlier, so a value set here is ignored when encoding for an older version
335
+ * and decodes as false. */
336
+ hidden;
337
+ constructor(prefix, excludeHop = 0n, hidden = false) {
228
338
  this.prefix = prefix;
229
339
  this.excludeHop = excludeHop;
340
+ this.hidden = hidden;
230
341
  }
231
342
  async #encode(w, version) {
232
343
  await w.string(Path.encode(this.prefix));
233
344
  if (hasExcludeHop(version)) {
234
345
  await w.u62(this.excludeHop);
235
346
  }
347
+ if (hasHidden(version)) {
348
+ await w.bool(this.hidden);
349
+ }
236
350
  }
237
351
  static async #decode(r, version) {
238
352
  const prefix = Path.decode(await r.string());
239
353
  const excludeHop = hasExcludeHop(version) ? await r.u62() : 0n;
240
- return new AnnounceRequest(prefix, excludeHop);
354
+ const hidden = hasHidden(version) ? await r.bool() : false;
355
+ return new AnnounceRequest(prefix, excludeHop, hidden);
241
356
  }
242
357
  async encode(w, version) {
243
358
  return Message.encode(w, (w) => this.#encode(w, version));
@@ -1 +1 @@
1
- {"version":3,"file":"announce.js","sourceRoot":"","sources":["../../src/lite/announce.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAuB,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAClF,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AAEnC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,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AAC;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 { ProtocolViolation } from \"../error.ts\";\nimport { type Cost, type Hop, HopSchema, MAX_HOPS, UNKNOWN_HOP } from \"../hop.ts\";\nimport * as Path from \"../path.ts\";\nimport type { Reader, Writer } from \"../stream.ts\";\nimport * as Message from \"./message.ts\";\nimport { hasAnnounceId, hasAnnounceOk, hasExcludeHop, hasRouteCost, Version } from \"./version.ts\";\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\nexport type { Cost };\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; it decodes as\n\t * `undefined` on a wire with no room for one. */\n\t| { status: \"active\"; suffix: Path.Valid; hops: Hop[]; cost?: Cost }\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: Hop[]; cost?: Cost }\n\t/** An unknown lite-06+ announce type, skipped by length. Does not assign an id. */\n\t| { status: \"skipped\" };\n\n// Both wire rules on a hop chain, applied to what we send and to what we receive: a\n// chain that revisits a hop looped, so neither forwarding it nor subscribing through it\n// is safe, and a receiver must end the session over one. `UNKNOWN_HOP` identifies\n// nothing, so any number of hops may be unknown.\n//\n// `ProtocolViolation` so a receipt takes the session down rather than the one stream,\n// matching what `ietf/cluster.ts` throws for the identical rule.\nfunction checkHops(hops: Hop[]) {\n\tif (hops.length > MAX_HOPS) {\n\t\tthrow new ProtocolViolation(`hop count ${hops.length} exceeds maximum ${MAX_HOPS}`);\n\t}\n\n\t// MAX_HOPS is 32, so the quadratic scan is cheaper than allocating a set.\n\tfor (let i = 0; i < hops.length; i++) {\n\t\tconst hop = hops[i];\n\t\tif (hop === UNKNOWN_HOP) continue;\n\t\tif (hops.indexOf(hop, i + 1) !== -1) {\n\t\t\tthrow new ProtocolViolation(`hop ${hop} appears twice in the chain`);\n\t\t}\n\t}\n}\n\nasync function encodeHops(w: Writer, version: Version, hops: Hop[]) {\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 Hop 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<Hop[]> {\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, so every entry is\n\t\t\t// the reserved \"no identity\" id.\n\t\t\treturn new Array<Hop>(count).fill(UNKNOWN_HOP);\n\t\t}\n\t\tdefault: {\n\t\t\t// Lite04+: hop count + individual Hop 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: Hop[] = [];\n\t\t\tfor (let i = 0; i < count; i++) {\n\t\t\t\thops.push(HopSchema.parse(await r.u62()));\n\t\t\t}\n\t\t\tcheckHops(hops);\n\t\t\treturn hops;\n\t\t}\n\t}\n}\n\n// The route cost rides lite-06+ announcements as two varints, warm then cold; older\n// versions carry neither.\nasync function encodeRouteCost(w: Writer, version: Version, cost: Cost | undefined) {\n\tif (!hasRouteCost(version)) return;\n\tawait w.u62(cost?.warm ?? 0n);\n\tawait w.u62(cost?.cold ?? 0n);\n}\n\nasync function decodeRouteCost(r: Reader, version: Version): Promise<Cost | undefined> {\n\tif (!hasRouteCost(version)) return undefined;\n\treturn { warm: await r.u62(), cold: 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\tcase \"skipped\":\n\t\t\tthrow new Error(\"decode-only announce type cannot be encoded\");\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\tcase \"skipped\":\n\t\t\tthrow new Error(\"decode-only announce type cannot be encoded\");\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\t// Skip the length-prefixed body so an earlier Lite06 build negotiating\n\t\t\t// the same ALPN does not kill the announce stream.\n\t\t\tawait r.readAll();\n\t\t\treturn { status: \"skipped\" };\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\tcase \"skipped\":\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 Hop 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 Hop ID, which the subscriber stamps onto each\n/// announce's hop chain (the publisher no longer stamps itself), or the reserved\n/// {@link UNKNOWN_HOP} when the responder has no identity to give. `active` is\n/// the number of initial Announce messages that follow immediately.\nexport class AnnounceOk {\n\thop: Hop;\n\tactive: number;\n\n\tconstructor(hop: Hop, active: number) {\n\t\tthis.hop = hop;\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.hop);\n\t\tawait w.u53(this.active);\n\t}\n\n\tstatic async #decode(r: Reader): Promise<AnnounceOk> {\n\t\t// The draft reserves 0 for \"unknown\": the responder was never assigned an id, or\n\t\t// withholds it to obscure its routing. It names nobody, so callers must not stamp\n\t\t// it onto a hop chain, but it is a legal message and not grounds to drop the stream.\n\t\tconst origin = HopSchema.parse(await r.u62());\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,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAuB,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAClF,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AAEnC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,EACN,sBAAsB,EACtB,aAAa,EACb,aAAa,EACb,aAAa,EACb,SAAS,EACT,YAAY,EACZ,OAAO,GACP,MAAM,c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D","sourcesContent":["import { ProtocolViolation } from \"../error.ts\";\nimport { type Cost, type Hop, HopSchema, MAX_HOPS, UNKNOWN_HOP } from \"../hop.ts\";\nimport * as Path from \"../path.ts\";\nimport type { Reader, Writer } from \"../stream.ts\";\nimport * as Message from \"./message.ts\";\nimport {\n\thasAnnounceCompression,\n\thasAnnounceId,\n\thasAnnounceOk,\n\thasExcludeHop,\n\thasHidden,\n\thasRouteCost,\n\tVersion,\n} from \"./version.ts\";\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\nexport type { Cost };\n\n/**\n * Lite-07: copy `keep` path segments (from the head) or hops (from the tail) of the\n * live announcement `distance` back from the stream's next Announce ID, where 1 is the\n * latest ANNOUNCE_START. Resolved by {@link AnnounceHistory}.\n */\nexport type Base = { distance: bigint; keep: number };\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; it decodes as\n\t * `undefined` on a wire with no room for one. On lite-07, `suffix` follows the\n\t * segments `pathBase` copies and `hops` precede the ones `hopBase` copies. */\n\t| { status: \"active\"; suffix: Path.Valid; hops: Hop[]; cost?: Cost; pathBase?: Base; hopBase?: Base }\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: Hop[]; cost?: Cost; hopBase?: Base }\n\t/** An unknown lite-06+ announce type, skipped by length. Does not assign an id. */\n\t| { status: \"skipped\" };\n\n// Both wire rules on a hop chain, applied to what we send and to what we receive: a\n// chain that revisits a hop looped, so neither forwarding it nor subscribing through it\n// is safe, and a receiver must end the session over one. `UNKNOWN_HOP` identifies\n// nothing, so any number of hops may be unknown.\n//\n// `ProtocolViolation` so a receipt takes the session down rather than the one stream,\n// matching what `ietf/cluster.ts` throws for the identical rule.\nfunction checkHops(hops: Hop[]) {\n\tif (hops.length > MAX_HOPS) {\n\t\tthrow new ProtocolViolation(`hop count ${hops.length} exceeds maximum ${MAX_HOPS}`);\n\t}\n\n\t// MAX_HOPS is 32, so the quadratic scan is cheaper than allocating a set.\n\tfor (let i = 0; i < hops.length; i++) {\n\t\tconst hop = hops[i];\n\t\tif (hop === UNKNOWN_HOP) continue;\n\t\tif (hops.indexOf(hop, i + 1) !== -1) {\n\t\t\tthrow new ProtocolViolation(`hop ${hop} appears twice in the chain`);\n\t\t}\n\t}\n}\n\nasync function encodeHops(w: Writer, version: Version, hops: Hop[]) {\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 Hop 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<Hop[]> {\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, so every entry is\n\t\t\t// the reserved \"no identity\" id.\n\t\t\treturn new Array<Hop>(count).fill(UNKNOWN_HOP);\n\t\t}\n\t\tdefault: {\n\t\t\t// Lite04+: hop count + individual Hop 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: Hop[] = [];\n\t\t\tfor (let i = 0; i < count; i++) {\n\t\t\t\thops.push(HopSchema.parse(await r.u62()));\n\t\t\t}\n\t\t\tcheckHops(hops);\n\t\t\treturn hops;\n\t\t}\n\t}\n}\n\n// Lite-07 carries a base around a path and a hop list. A distance of 0 names\n// nothing, and a keep without a base is a violation. Other versions have no room for\n// a base at all.\nfunction checkBase(version: Version, base: Base | undefined) {\n\tif (base && !hasAnnounceCompression(version)) {\n\t\tthrow new Error(\"announce compression not supported for this version\");\n\t}\n}\n\nfunction toBase(distance: bigint, keep: number): Base | undefined {\n\tif (distance !== 0n) return { distance, keep };\n\tif (keep !== 0) throw new ProtocolViolation(\"announce keep without a base\");\n\treturn undefined;\n}\n\nasync function encodePath(w: Writer, version: Version, suffix: Path.Valid, base: Base | undefined) {\n\tcheckBase(version, base);\n\tif (hasAnnounceCompression(version)) {\n\t\tawait w.u62(base?.distance ?? 0n);\n\t\tawait w.u53(base?.keep ?? 0);\n\t}\n\tawait w.string(Path.encode(suffix));\n}\n\nasync function decodePath(r: Reader, version: Version): Promise<{ suffix: Path.Valid; pathBase?: Base }> {\n\tif (!hasAnnounceCompression(version)) return { suffix: Path.decode(await r.string()) };\n\tconst pathBase = toBase(await r.u62(), await r.u53());\n\tconst suffix = Path.decode(await r.string());\n\treturn pathBase ? { suffix, pathBase } : { suffix };\n}\n\nasync function encodeHopsBlock(w: Writer, version: Version, hops: Hop[], base: Base | undefined) {\n\tcheckBase(version, base);\n\tif (!hasAnnounceCompression(version)) return encodeHops(w, version, hops);\n\tawait w.u62(base?.distance ?? 0n);\n\tawait encodeHops(w, version, hops);\n\tawait w.u53(base?.keep ?? 0);\n}\n\nasync function decodeHopsBlock(r: Reader, version: Version): Promise<{ hops: Hop[]; hopBase?: Base }> {\n\tif (!hasAnnounceCompression(version)) return { hops: await decodeHops(r, version) };\n\tconst distance = await r.u62();\n\tconst hops = await decodeHops(r, version);\n\tconst hopBase = toBase(distance, await r.u53());\n\treturn hopBase ? { hops, hopBase } : { hops };\n}\n\n// The route cost rides lite-06+ announcements as two varints, warm then cold; older\n// versions carry neither.\nasync function encodeRouteCost(w: Writer, version: Version, cost: Cost | undefined) {\n\tif (!hasRouteCost(version)) return;\n\tawait w.u62(cost?.warm ?? 0n);\n\tawait w.u62(cost?.cold ?? 0n);\n}\n\nasync function decodeRouteCost(r: Reader, version: Version): Promise<Cost | undefined> {\n\tif (!hasRouteCost(version)) return undefined;\n\treturn { warm: await r.u62(), cold: 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 encodePath(w, version, msg.suffix, msg.pathBase);\n\t\t\tawait encodeHopsBlock(w, version, msg.hops, msg.hopBase);\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 encodeHopsBlock(w, version, msg.hops, msg.hopBase);\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\tcase \"skipped\":\n\t\t\tthrow new Error(\"decode-only announce type cannot be encoded\");\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\tcase \"skipped\":\n\t\t\tthrow new Error(\"decode-only announce type cannot be encoded\");\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 path = await decodePath(r, version);\n\t\t\tconst hops = await decodeHopsBlock(r, version);\n\t\t\treturn { status: \"active\", ...path, ...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 decodeHopsBlock(r, version);\n\t\t\treturn { status: \"restart\", id, ...hops, cost: await decodeRouteCost(r, version) };\n\t\t}\n\t\tdefault:\n\t\t\t// Skip the length-prefixed body so an earlier Lite06 build negotiating\n\t\t\t// the same ALPN does not kill the announce stream.\n\t\t\tawait r.readAll();\n\t\t\treturn { status: \"skipped\" };\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\tcheckBase(version, msg.pathBase ?? msg.hopBase);\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\tcase \"skipped\":\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\ntype Advertised = { suffix: Path.Valid; hops: Hop[] };\n\n/**\n * The live announcements on one lite-06+ announce stream, by Announce ID: what\n * ANNOUNCE_END and ANNOUNCE_UPDATE reference, and what a lite-07 base copies from.\n * Every violation throws {@link ProtocolViolation}.\n */\nexport class AnnounceHistory {\n\t#next = 0n;\n\t#live = new Map<bigint, Advertised>();\n\n\t#base(base: Base): Advertised {\n\t\tconst live = this.#live.get(this.#next - base.distance);\n\t\tif (!live) throw new ProtocolViolation(`announce base ${base.distance} is not live`);\n\t\treturn live;\n\t}\n\n\t#hops(hops: Hop[], base: Base | undefined): Hop[] {\n\t\tif (!base) return hops;\n\t\tconst tail = this.#base(base).hops;\n\t\tif (base.keep > tail.length) throw new ProtocolViolation(`announce keeps ${base.keep} of ${tail.length} hops`);\n\t\tconst resolved = [...hops, ...tail.slice(tail.length - base.keep)];\n\t\tcheckHops(resolved);\n\t\treturn resolved;\n\t}\n\n\t/** An ANNOUNCE_START: resolve it and assign it the next id. */\n\tstart(msg: { suffix: Path.Valid; hops: Hop[]; pathBase?: Base; hopBase?: Base }): Advertised {\n\t\tlet suffix = msg.suffix;\n\t\tif (msg.pathBase) {\n\t\t\tconst head = Path.parts(this.#base(msg.pathBase).suffix);\n\t\t\tconst keep = msg.pathBase.keep;\n\t\t\tif (keep > head.length) throw new ProtocolViolation(`announce keeps ${keep} of ${head.length} segments`);\n\t\t\tsuffix = Path.join(Path.from(...head.slice(0, keep)), suffix);\n\t\t\tif (Path.parts(suffix).length > Path.MAX_PARTS) {\n\t\t\t\tthrow new ProtocolViolation(`path exceeds ${Path.MAX_PARTS} parts`);\n\t\t\t}\n\t\t}\n\t\tconst hops = this.#hops(msg.hops, msg.hopBase);\n\t\tthis.#live.set(this.#next++, { suffix, hops });\n\t\treturn { suffix, hops };\n\t}\n\n\t/** An ANNOUNCE_UPDATE: resolve its chain before replacing the old one, which it may be based on. */\n\tupdate(msg: { id: bigint; hops: Hop[]; hopBase?: Base }): Advertised {\n\t\tconst hops = this.#hops(msg.hops, msg.hopBase);\n\t\tconst live = this.#live.get(msg.id);\n\t\tif (!live) throw new ProtocolViolation(`unknown announce id: ${msg.id}`);\n\t\tthis.#live.set(msg.id, { suffix: live.suffix, hops });\n\t\treturn { suffix: live.suffix, hops };\n\t}\n\n\t/** An ANNOUNCE_END: retire the id, returning its suffix. */\n\tend(id: bigint): Path.Valid {\n\t\tconst live = this.#live.get(id);\n\t\tif (!live) throw new ProtocolViolation(`unknown announce id: ${id}`);\n\t\tthis.#live.delete(id);\n\t\treturn live.suffix;\n\t}\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 Hop 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\t/** Lite07+: also announce routes with a `.`-prefixed segment below the prefix. Not on\n\t * the wire earlier, so a value set here is ignored when encoding for an older version\n\t * and decodes as false. */\n\thidden: boolean;\n\n\tconstructor(prefix: Path.Valid, excludeHop: bigint = 0n, hidden = false) {\n\t\tthis.prefix = prefix;\n\t\tthis.excludeHop = excludeHop;\n\t\tthis.hidden = hidden;\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\tif (hasHidden(version)) {\n\t\t\tawait w.bool(this.hidden);\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\tconst hidden = hasHidden(version) ? await r.bool() : false;\n\t\treturn new AnnounceRequest(prefix, excludeHop, hidden);\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 Hop ID, which the subscriber stamps onto each\n/// announce's hop chain (the publisher no longer stamps itself), or the reserved\n/// {@link UNKNOWN_HOP} when the responder has no identity to give. `active` is\n/// the number of initial Announce messages that follow immediately.\nexport class AnnounceOk {\n\thop: Hop;\n\tactive: number;\n\n\tconstructor(hop: Hop, active: number) {\n\t\tthis.hop = hop;\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.hop);\n\t\tawait w.u53(this.active);\n\t}\n\n\tstatic async #decode(r: Reader): Promise<AnnounceOk> {\n\t\t// The draft reserves 0 for \"unknown\": the responder was never assigned an id, or\n\t\t// withholds it to obscure its routing. It names nobody, so callers must not stamp\n\t\t// it onto a hop chain, but it is a legal message and not grounds to drop the stream.\n\t\tconst origin = HopSchema.parse(await r.u62());\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"]}
@@ -37,7 +37,7 @@ export declare class Connection implements Established {
37
37
  * Closes the connection.
38
38
  */
39
39
  close(): void;
40
- announced(scope?: Path.Pattern): announce.Consumer;
40
+ announced(scope?: Path.Pattern, options?: announce.Options): announce.Consumer;
41
41
  /** Snapshot the transport's counters; see {@link Established.stats}. */
42
42
  stats(): Promise<Stats>;
43
43
  /** Resolves when the session closes, decoding the peer's close code; see {@link Established.closed}. */
@@ -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,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;AAEzE,OAAO,EAAE,KAAK,GAAG,EAAa,MAAM,WAAW,CAAC;AAEhD,OAAO,KAAK,KAAK,IAAI,MAAM,YAAY,CAAC;AASxC,OAAO,EAAc,KAAK,IAAI,EAAS,MAAM,YAAY,CAAC;AA2B1D;;;;GAIG;AACH,qBAAa,UAAW,YAAW,WAAW;;IAE7C,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;IAGlB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAGzB,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAE9B,yFAAyF;IACzF,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAiB5B,iEAAiE;IACjE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;IAE9B;sFACkF;IAClF,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;IAclB;;;;;;;;OAQG;I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AAG,CAAC;IAclB;;;;;;;;OAQG;IACH,IAAI,QAAQ,IAAI,MAAM,CAAC,IAAI,GAAG,SAAS,CAAC,CAEvC;IA0BD;;OAEG;IACH,KAAK,SAUJ;IAgCD,SAAS,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,QAAQ,CAAC,OAAO,GAAG,QAAQ,CAAC,QAAQ,CAE7E;IAiHD,wEAAwE;IAClE,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC,CAE5B;IAED,wGAAwG;IACxG,IAAI,MAAM,IAAI,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,CAElC;CACD"}
@@ -2,7 +2,7 @@
2
2
  import { Signal } from "@moq/signals";
3
3
  import { transportStats } from "../connection/stats.js";
4
4
  import { transportOf } from "../connection/transport.js";
5
- import { error, fromClose, StreamCode, StreamError } from "../error.js";
5
+ import { closeError, error, fromClose, StreamCode, StreamError, sessionCause } from "../error.js";
6
6
  import { randomHop } from "../hop.js";
7
7
  import { Readers, Stream, Writer } from "../stream.js";
8
8
  import { registerWire } from "../wire.js";
@@ -113,18 +113,24 @@ export class Connection {
113
113
  if (hasDatagrams(this.#version)) {
114
114
  tasks.push(this.#subscriber.runDatagrams());
115
115
  }
116
+ let fatal;
116
117
  try {
117
118
  await Promise.all(tasks);
118
119
  }
119
120
  catch (err) {
120
121
  console.error("fatal error running connection", err);
122
+ // A session-sourced failure is the peer's close, not the raw transport error.
123
+ fatal = await sessionCause(this.#quic, err);
121
124
  }
122
125
  finally {
126
+ // The session died under every track it was receiving, so they end with its
127
+ // error. A deliberate close() already ended them cleanly, which makes this a no-op.
128
+ this.#subscriber.close(fatal ?? (await closeError(this.#quic)));
123
129
  this.close();
124
130
  }
125
131
  }
126
- announced(scope) {
127
- return this.#subscriber.announced(scope);
132
+ announced(scope, options) {
133
+ return this.#subscriber.announced(scope, options);
128
134
  }
129
135
  async #runSession() {
130
136
  if (!this.#session) {
@@ -1 +1 @@
1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* as announce from \"../announced.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 { error, fromClose, StreamCode, StreamError } from \"../error.ts\";\nimport { type Hop, randomHop } from \"../hop.ts\";\nimport type { Consumer as OriginConsumer } from \"../origin.ts\";\nimport type * as Path from \"../path.ts\";\nimport { type Reader, Readers, Stream, Writer } from \"../stream.ts\";\nimport { registerWire } from \"../wire.ts\";\nimport { AnnounceRequest } from \"./announce.ts\";\nimport { Fetch } from \"./fetch.ts\";\nimport { Goaway } from \"./goaway.ts\";\nimport { Group } from \"./group.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, hasProbeRtt, 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\t/** The origin whose broadcasts are served to the peer. Omit to publish nothing. */\n\tpublish?: OriginConsumer;\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 Hop ID. Shared by Publisher (for outbound hop\n\t * chains) and Subscriber (available for optional self-filtering on announces). */\n\treadonly hop: Hop;\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, publish }: 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.hop = randomHop();\n\t\tthis.#publisher = new Publisher(this.#quic, this.#version, this.hop, publish);\n\t\tthis.#subscriber = new Subscriber(this.#quic, this.#version, this.hop, this.#probe, this.#peerSetup);\n\t\tregisterWire(this, { consume: (path) => this.#subscriber.consume(path) });\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\tannounced(scope?: Path.Pattern): announce.Consumer {\n\t\treturn this.#subscriber.announced(scope);\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. The probe level reflects what this transport\n\t// can actually measure; we never pad, so we never advertise Increase.\n\t// Role stays Both: the publish origin starts empty and fills later, and consume is\n\t// called after this point, so there is nothing to narrow yet. The origin declares\n\t// 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\tconst probe = await probeLevel(this.#quic, this.#version);\n\t\t\tawait new Setup({ probe, hop: this.hop }).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 StreamError(StreamCode.Cancel, { message: \"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, this.#version);\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\t/** Resolves when the session closes, decoding the peer's close code; see {@link Established.closed}. */\n\tget closed(): Promise<Error | null> {\n\t\treturn this.#quic.closed.then(fromClose, (err: unknown) => error(err));\n\t}\n}\n\n/**\n * The probe level to advertise in SETUP, from what the transport can measure.\n *\n * `Report` claims we can measure and periodically report, so it is only truthful\n * when a metric this version can carry actually exists. The qmux/WebSocket fallback\n * implements no `getStats()` at all, and even a transport that has one may report\n * neither figure. Advertising `Report` and then holding the subscriber's PROBE\n * stream open with nothing to send is the state this avoids; the subscriber's own\n * gate then skips a stream it could not use.\n *\n * Mirrors `ProbeLevel::detect` in `moq-net`, including its limitation: a metric\n * that only appears after SETUP reads as unsupported here.\n *\n * @internal\n */\nexport async function probeLevel(quic: WebTransport, version: Version): Promise<ProbeLevel> {\n\tconst getStats = (\n\t\tquic as unknown as {\n\t\t\tgetStats?: () => Promise<{ estimatedSendRate: number | null; smoothedRtt?: number | null }>;\n\t\t}\n\t).getStats;\n\tif (typeof getStats !== \"function\") return ProbeLevel.None;\n\n\t// A transport that can't answer tells us nothing, which is itself an answer.\n\tlet stats: { estimatedSendRate: number | null; smoothedRtt?: number | null };\n\ttry {\n\t\tstats = await getStats.call(quic);\n\t} catch {\n\t\treturn ProbeLevel.None;\n\t}\n\n\tconst rtt = hasProbeRtt(version) ? stats.smoothedRtt : undefined;\n\treturn stats.estimatedSendRate != null || rtt != null ? ProbeLevel.Report : ProbeLevel.None;\n}\n"]}
1
+ {"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/lite/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,MAAM,EAAE,MAAM,cAAc,CAAC;AAGnD,OAAO,EAA0B,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAAkB,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAClG,OAAO,EAAY,SAAS,EAAE,MAAM,WAAW,CAAC;AAGhD,OAAO,EAAe,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,eAA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wEAAwE;IACxE,KAAK,CAAC,KAAK;QACV,OAAO,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;IAED,wGAAwG;IACxG,IAAI,MAAM;QACT,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,GAAY,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;IACxE,CAAC;CACD;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,IAAkB,EAAE,OAAgB;IACpE,MAAM,QAAQ,GACb,IAGA,CAAC,QAAQ,CAAC;IACX,IAAI,OAAO,QAAQ,KAAK,UAAU;QAAE,OAAO,UAAU,CAAC,IAAI,CAAC;IAE3D,6EAA6E;IAC7E,IAAI,KAAwE,CAAC;IAC7E,IAAI,CAAC;QACJ,KAAK,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,UAAU,CAAC,IAAI,CAAC;IACxB,CAAC;IAED,MAAM,GAAG,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC;IACjE,OAAO,KAAK,CAAC,iBAAiB,IAAI,IAAI,IAAI,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC;AAC7F,CAAC","sourcesContent":["import { type Getter, Signal } from \"@moq/signals\";\nimport type * as announce from \"../announced.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 { closeError, error, fromClose, StreamCode, StreamError, sessionCause } from \"../error.ts\";\nimport { type Hop, randomHop } from \"../hop.ts\";\nimport type { Consumer as OriginConsumer } from \"../origin.ts\";\nimport type * as Path from \"../path.ts\";\nimport { type Reader, Readers, Stream, Writer } from \"../stream.ts\";\nimport { registerWire } from \"../wire.ts\";\nimport { AnnounceRequest } from \"./announce.ts\";\nimport { Fetch } from \"./fetch.ts\";\nimport { Goaway } from \"./goaway.ts\";\nimport { Group } from \"./group.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, hasProbeRtt, 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\t/** The origin whose broadcasts are served to the peer. Omit to publish nothing. */\n\tpublish?: OriginConsumer;\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 Hop ID. Shared by Publisher (for outbound hop\n\t * chains) and Subscriber (available for optional self-filtering on announces). */\n\treadonly hop: Hop;\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, publish }: 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.hop = randomHop();\n\t\tthis.#publisher = new Publisher(this.#quic, this.#version, this.hop, publish);\n\t\tthis.#subscriber = new Subscriber(this.#quic, this.#version, this.hop, this.#probe, this.#peerSetup);\n\t\tregisterWire(this, { consume: (path) => this.#subscriber.consume(path) });\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\tlet fatal: Error | undefined;\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\t// A session-sourced failure is the peer's close, not the raw transport error.\n\t\t\tfatal = await sessionCause(this.#quic, err);\n\t\t} finally {\n\t\t\t// The session died under every track it was receiving, so they end with its\n\t\t\t// error. A deliberate close() already ended them cleanly, which makes this a no-op.\n\t\t\tthis.#subscriber.close(fatal ?? (await closeError(this.#quic)));\n\t\t\tthis.close();\n\t\t}\n\t}\n\n\tannounced(scope?: Path.Pattern, options?: announce.Options): announce.Consumer {\n\t\treturn this.#subscriber.announced(scope, options);\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. The probe level reflects what this transport\n\t// can actually measure; we never pad, so we never advertise Increase.\n\t// Role stays Both: the publish origin starts empty and fills later, and consume is\n\t// called after this point, so there is nothing to narrow yet. The origin declares\n\t// 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\tconst probe = await probeLevel(this.#quic, this.#version);\n\t\t\tawait new Setup({ probe, hop: this.hop }).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 StreamError(StreamCode.Cancel, { message: \"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, this.#version);\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\t/** Resolves when the session closes, decoding the peer's close code; see {@link Established.closed}. */\n\tget closed(): Promise<Error | null> {\n\t\treturn this.#quic.closed.then(fromClose, (err: unknown) => error(err));\n\t}\n}\n\n/**\n * The probe level to advertise in SETUP, from what the transport can measure.\n *\n * `Report` claims we can measure and periodically report, so it is only truthful\n * when a metric this version can carry actually exists. The qmux/WebSocket fallback\n * implements no `getStats()` at all, and even a transport that has one may report\n * neither figure. Advertising `Report` and then holding the subscriber's PROBE\n * stream open with nothing to send is the state this avoids; the subscriber's own\n * gate then skips a stream it could not use.\n *\n * Mirrors `ProbeLevel::detect` in `moq-net`, including its limitation: a metric\n * that only appears after SETUP reads as unsupported here.\n *\n * @internal\n */\nexport async function probeLevel(quic: WebTransport, version: Version): Promise<ProbeLevel> {\n\tconst getStats = (\n\t\tquic as unknown as {\n\t\t\tgetStats?: () => Promise<{ estimatedSendRate: number | null; smoothedRtt?: number | null }>;\n\t\t}\n\t).getStats;\n\tif (typeof getStats !== \"function\") return ProbeLevel.None;\n\n\t// A transport that can't answer tells us nothing, which is itself an answer.\n\tlet stats: { estimatedSendRate: number | null; smoothedRtt?: number | null };\n\ttry {\n\t\tstats = await getStats.call(quic);\n\t} catch {\n\t\treturn ProbeLevel.None;\n\t}\n\n\tconst rtt = hasProbeRtt(version) ? stats.smoothedRtt : undefined;\n\treturn stats.estimatedSendRate != null || rtt != null ? ProbeLevel.Report : ProbeLevel.None;\n}\n"]}