@moq/net 0.4.0 → 0.4.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.
Files changed (204) 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 +27 -10
  5. package/broadcast.d.ts.map +1 -1
  6. package/broadcast.js +47 -21
  7. package/broadcast.js.map +1 -1
  8. package/connection/accept.js +14 -4
  9. package/connection/accept.js.map +1 -1
  10. package/connection/connect.d.ts.map +1 -1
  11. package/connection/connect.js +14 -4
  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 +61 -47
  17. package/connection/forward.js.map +1 -1
  18. package/connection/goaway.d.ts +34 -0
  19. package/connection/goaway.d.ts.map +1 -0
  20. package/connection/goaway.js +176 -0
  21. package/connection/goaway.js.map +1 -0
  22. package/connection/handshake.d.ts +5 -2
  23. package/connection/handshake.d.ts.map +1 -1
  24. package/connection/handshake.js +45 -10
  25. package/connection/handshake.js.map +1 -1
  26. package/connection/pool.d.ts +24 -11
  27. package/connection/pool.d.ts.map +1 -1
  28. package/connection/pool.js +50 -18
  29. package/connection/pool.js.map +1 -1
  30. package/connection/reload.d.ts.map +1 -1
  31. package/connection/reload.js +189 -35
  32. package/connection/reload.js.map +1 -1
  33. package/error.d.ts +11 -0
  34. package/error.d.ts.map +1 -1
  35. package/error.js +35 -0
  36. package/error.js.map +1 -1
  37. package/errors.d.ts +1 -1
  38. package/errors.d.ts.map +1 -1
  39. package/errors.js +1 -1
  40. package/errors.js.map +1 -1
  41. package/group.d.ts.map +1 -1
  42. package/group.js +5 -4
  43. package/group.js.map +1 -1
  44. package/hop.d.ts +8 -0
  45. package/hop.d.ts.map +1 -1
  46. package/hop.js +16 -0
  47. package/hop.js.map +1 -1
  48. package/ietf/adapter.d.ts +9 -1
  49. package/ietf/adapter.d.ts.map +1 -1
  50. package/ietf/adapter.js +46 -17
  51. package/ietf/adapter.js.map +1 -1
  52. package/ietf/cluster.d.ts +3 -3
  53. package/ietf/cluster.js +3 -3
  54. package/ietf/cluster.js.map +1 -1
  55. package/ietf/connection.d.ts +1 -1
  56. package/ietf/connection.d.ts.map +1 -1
  57. package/ietf/connection.js +118 -41
  58. package/ietf/connection.js.map +1 -1
  59. package/ietf/error.js +27 -2
  60. package/ietf/error.js.map +1 -1
  61. package/ietf/fetch.d.ts +7 -20
  62. package/ietf/fetch.d.ts.map +1 -1
  63. package/ietf/fetch.js +52 -22
  64. package/ietf/fetch.js.map +1 -1
  65. package/ietf/filter.d.ts +2 -0
  66. package/ietf/filter.d.ts.map +1 -1
  67. package/ietf/filter.js +4 -0
  68. package/ietf/filter.js.map +1 -1
  69. package/ietf/goaway.d.ts +9 -1
  70. package/ietf/goaway.d.ts.map +1 -1
  71. package/ietf/goaway.js +20 -0
  72. package/ietf/goaway.js.map +1 -1
  73. package/ietf/hidden.d.ts +2 -0
  74. package/ietf/hidden.d.ts.map +1 -0
  75. package/ietf/hidden.js +30 -0
  76. package/ietf/hidden.js.map +1 -0
  77. package/ietf/index.d.ts +2 -1
  78. package/ietf/index.d.ts.map +1 -1
  79. package/ietf/index.js +2 -1
  80. package/ietf/index.js.map +1 -1
  81. package/ietf/object.d.ts +15 -8
  82. package/ietf/object.d.ts.map +1 -1
  83. package/ietf/object.js +54 -36
  84. package/ietf/object.js.map +1 -1
  85. package/ietf/parameters.d.ts +12 -0
  86. package/ietf/parameters.d.ts.map +1 -1
  87. package/ietf/parameters.js +82 -12
  88. package/ietf/parameters.js.map +1 -1
  89. package/ietf/properties.d.ts +1 -0
  90. package/ietf/properties.d.ts.map +1 -1
  91. package/ietf/properties.js +14 -0
  92. package/ietf/properties.js.map +1 -1
  93. package/ietf/publish.d.ts +19 -2
  94. package/ietf/publish.d.ts.map +1 -1
  95. package/ietf/publish.js +40 -6
  96. package/ietf/publish.js.map +1 -1
  97. package/ietf/publish_namespace.d.ts +2 -2
  98. package/ietf/publish_namespace.js +2 -2
  99. package/ietf/publish_namespace.js.map +1 -1
  100. package/ietf/publisher.js +383 -214
  101. package/ietf/publisher.js.map +1 -1
  102. package/ietf/subscribe.d.ts +7 -1
  103. package/ietf/subscribe.d.ts.map +1 -1
  104. package/ietf/subscribe.js +25 -18
  105. package/ietf/subscribe.js.map +1 -1
  106. package/ietf/subscribe_namespace.d.ts +8 -2
  107. package/ietf/subscribe_namespace.d.ts.map +1 -1
  108. package/ietf/subscribe_namespace.js +20 -11
  109. package/ietf/subscribe_namespace.js.map +1 -1
  110. package/ietf/subscriber.js +226 -88
  111. package/ietf/subscriber.js.map +1 -1
  112. package/ietf/token.d.ts +2 -0
  113. package/ietf/token.d.ts.map +1 -0
  114. package/ietf/token.js +99 -0
  115. package/ietf/token.js.map +1 -0
  116. package/ietf/track.d.ts +4 -0
  117. package/ietf/track.d.ts.map +1 -1
  118. package/ietf/track.js +6 -20
  119. package/ietf/track.js.map +1 -1
  120. package/index.d.ts +1 -1
  121. package/index.d.ts.map +1 -1
  122. package/index.js.map +1 -1
  123. package/internal.d.ts +19 -3
  124. package/internal.d.ts.map +1 -1
  125. package/internal.js +43 -0
  126. package/internal.js.map +1 -1
  127. package/lite/announce.d.ts +46 -2
  128. package/lite/announce.d.ts.map +1 -1
  129. package/lite/announce.js +133 -15
  130. package/lite/announce.js.map +1 -1
  131. package/lite/connection.d.ts +1 -1
  132. package/lite/connection.d.ts.map +1 -1
  133. package/lite/connection.js +30 -9
  134. package/lite/connection.js.map +1 -1
  135. package/lite/datagram.d.ts +3 -2
  136. package/lite/datagram.d.ts.map +1 -1
  137. package/lite/datagram.js +7 -8
  138. package/lite/datagram.js.map +1 -1
  139. package/lite/group.d.ts +12 -8
  140. package/lite/group.d.ts.map +1 -1
  141. package/lite/group.js +37 -16
  142. package/lite/group.js.map +1 -1
  143. package/lite/message.d.ts +2 -2
  144. package/lite/message.d.ts.map +1 -1
  145. package/lite/message.js +14 -5
  146. package/lite/message.js.map +1 -1
  147. package/lite/publisher.js +174 -133
  148. package/lite/publisher.js.map +1 -1
  149. package/lite/setup.d.ts +1 -1
  150. package/lite/setup.d.ts.map +1 -1
  151. package/lite/setup.js +22 -19
  152. package/lite/setup.js.map +1 -1
  153. package/lite/subscribe.d.ts +10 -4
  154. package/lite/subscribe.d.ts.map +1 -1
  155. package/lite/subscribe.js +20 -10
  156. package/lite/subscribe.js.map +1 -1
  157. package/lite/subscriber.d.ts +10 -2
  158. package/lite/subscriber.d.ts.map +1 -1
  159. package/lite/subscriber.js +333 -188
  160. package/lite/subscriber.js.map +1 -1
  161. package/lite/version.d.ts +11 -0
  162. package/lite/version.d.ts.map +1 -1
  163. package/lite/version.js +56 -0
  164. package/lite/version.js.map +1 -1
  165. package/origin.d.ts +46 -19
  166. package/origin.d.ts.map +1 -1
  167. package/origin.js +529 -189
  168. package/origin.js.map +1 -1
  169. package/package.json +8 -4
  170. package/stream.d.ts +79 -14
  171. package/stream.d.ts.map +1 -1
  172. package/stream.js +375 -133
  173. package/stream.js.map +1 -1
  174. package/tail.d.ts +18 -0
  175. package/tail.d.ts.map +1 -0
  176. package/tail.js +167 -0
  177. package/tail.js.map +1 -0
  178. package/track.d.ts +46 -7
  179. package/track.d.ts.map +1 -1
  180. package/track.js +263 -101
  181. package/track.js.map +1 -1
  182. package/util/abort.d.ts +2 -0
  183. package/util/abort.d.ts.map +1 -0
  184. package/util/abort.js +20 -0
  185. package/util/abort.js.map +1 -0
  186. package/util/u64.d.ts +39 -0
  187. package/util/u64.d.ts.map +1 -0
  188. package/util/u64.js +83 -0
  189. package/util/u64.js.map +1 -0
  190. package/util/varint.d.ts +29 -0
  191. package/util/varint.d.ts.map +1 -0
  192. package/util/varint.js +198 -0
  193. package/util/varint.js.map +1 -0
  194. package/varint.d.ts +10 -6
  195. package/varint.d.ts.map +1 -1
  196. package/varint.js +40 -237
  197. package/varint.js.map +1 -1
  198. package/wire.d.ts +19 -3
  199. package/wire.d.ts.map +1 -1
  200. package/wire.js.map +1 -1
  201. package/ietf/control.d.ts +0 -135
  202. package/ietf/control.d.ts.map +0 -1
  203. package/ietf/control.js +0 -242
  204. package/ietf/control.js.map +0 -1
package/group.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"group.js","sourceRoot":"","sources":["../src/group.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAA8C,IAAI,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACxF,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACxE,OAAO,EAAE,KAAK,EAAuB,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,4GAA4G;AAC5G,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAEtD,uHAAuH;AACvH,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAmCrC,4EAA4E;AAC5E,MAAM,UAAU;IACN,QAAQ,CAAS;IAC1B,MAAM,GAAG,IAAI,MAAM,CAAU,EAAE,CAAC,CAAC;IACjC,MAAM,GAAG,IAAI,IAAI,EAAgB,CAAC;IAClC,KAAK,GAAG,IAAI,MAAM,CAAS,CAAC,CAAC,CAAC,CAAC,mDAAmD;IAElF,mFAAmF;IACnF,kCAAkC;IAClC,KAAK,GAAG,CAAC,CAAC;IAEV,UAAU,GAAG,CAAC,CAAC;IACf,qDAAqD;IACrD,SAAS,CAAa;IACtB,gFAAgF;IAChF,MAAM,CAAa;IAEnB,YAAY,QAAgB;QAC3B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC1B,CAAC;CACD;AAED,SAAS,WAAW,CAAC,KAAiB,EAAE,KAAY;IACnD,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,SAAS;QAAE,MAAM,IAAI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;YAAE,OAAO,CAAC,iBAAiB;QACtE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC;IACvC,CAAC;CACD","sourcesContent":["/**\n * Group role handles: an ordered stream of frames within a track, delivered over one QUIC stream.\n *\n * @module\n */\nimport { type Dispose, type GetPromise, type Getter, Once, Signal } from \"@moq/signals\";\nimport { FrameTooLarge, GroupTooLarge, TooFarBehind } from \"./error.ts\";\nimport { hooks, type ReadGroupFrame } from \"./internal.ts\";\nimport { Timestamp } from \"./time.ts\";\n\n/** Maximum bytes of frames in a group. A write that would exceed this aborts with {@link GroupTooLarge}. */\nexport const MAX_GROUP_CACHE_BYTES = 32 * 1024 * 1024;\n\n/** Maximum number of frames in a group. 8192 is the largest legal group; the 8193rd write is {@link GroupTooLarge}. */\nexport const MAX_GROUP_FRAMES = 8192;\n\n/**\n * A frame buffered in a group: its presentation {@link Timestamp} and payload bytes.\n *\n * The timestamp carries its own scale, so a track can pick its units; the wire layer\n * converts it into the track's negotiated timescale.\n */\nexport interface Frame {\n\t/** The frame payload. */\n\tpayload: Uint8Array;\n\t/**\n\t * Presentation timestamp. Required: for a payload with no presentation time of its own\n\t * (a JSON catalog, control state) pass {@link Timestamp.now} explicitly.\n\t */\n\ttimestamp: Timestamp;\n}\n\n/** Options for a sequence-aware frame read. */\nexport interface ReadOptions {\n\t/**\n\t * The lowest sequence number the caller wants; defaults to the whole group.\n\t *\n\t * Frames below it are discarded instead of returned. The group still starts at frame 0,\n\t * so this is a reader filter, not a missing prefix.\n\t */\n\tfrom?: number;\n}\n\n/** Immutable group metadata. */\nexport interface Info {\n\t/** Sequence number of this group within its track. */\n\tsequence: number;\n}\n\n/** Reactive backing state shared by the group producer and one consumer. */\nclass GroupState {\n\treadonly sequence: number;\n\tframes = new Signal<Frame[]>([]);\n\tclosed = new Once<Error | null>();\n\ttotal = new Signal<number>(0); // The total number of frames in the group thus far\n\n\t// Absolute sequence of the frame at the front of `frames`, advanced by a read: the\n\t// sequence the next read returns.\n\tstart = 0;\n\n\tcacheBytes = 0;\n\t// The first frame's timestamp, retained after reads.\n\ttimestamp?: Timestamp;\n\t// The newest frame's timestamp: where a reader that has taken every frame sits.\n\tlatest?: Timestamp;\n\n\tconstructor(sequence: number) {\n\t\tthis.sequence = sequence;\n\t}\n}\n\nfunction appendFrame(state: GroupState, frame: Frame) {\n\tif (state.closed.peek() !== undefined) throw new Error(\"group is closed\");\n\n\tstate.timestamp ??= frame.timestamp;\n\tstate.latest = frame.timestamp;\n\tstate.cacheBytes += frame.payload.byteLength;\n\tstate.frames.mutate((frames) => {\n\t\tframes.push(frame);\n\t});\n\n\tstate.total.update((total) => total + 1);\n}\n\n/**\n * The write side of an ordered stream of frames within a track.\n *\n * @public\n */\nexport class Producer {\n\t/** Sequence number of this group within its track. */\n\treadonly sequence: number;\n\n\t#state: GroupState;\n\t#mirrors?: Set<GroupState>;\n\n\t// Whether any mirror reader is attached (see {@link used}). Fetch coalescing watches it to\n\t// cancel an abandoned download; a group can stay open indefinitely (a catalog or JSON stream),\n\t// so this is what stops a reader-less fetch instead of the stream ending on its own.\n\t#used = new Signal<boolean>(false);\n\n\t// When the group was created or last written. Retention ages a group from this,\n\t// not from its creation, so a group still being filled is never reclaimed.\n\t#activity = performance.now();\n\n\tconstructor(sequence: number) {\n\t\tthis.#state = new GroupState(sequence);\n\t\tthis.sequence = sequence;\n\t}\n\n\t/**\n\t * When the group was created or last written, in `performance.now()` milliseconds.\n\t *\n\t * @internal Track retention only.\n\t */\n\tget activity(): number {\n\t\treturn this.#activity;\n\t}\n\n\t/**\n\t * Settles once the group closes: `null` on a clean close, or the abort {@link Error}.\n\t * Peek it synchronously (`undefined` while open), observe it reactively, or `await` it.\n\t */\n\tget closed(): GetPromise<Error | null> {\n\t\treturn this.#state.closed;\n\t}\n\n\t/** A read handle for this group. */\n\tconsume(): Consumer {\n\t\treturn makeConsumer(this.#state);\n\t}\n\n\t/**\n\t * Create an independent read handle that receives every frame written here.\n\t *\n\t * Frames written so far are replayed synchronously; later writes and close are teed\n\t * in as they happen.\n\t *\n\t * @internal Track fan-out and fetch coalescing only. Use {@link consume} instead.\n\t */\n\tmirror(): Consumer {\n\t\tconst dst = new GroupState(this.sequence);\n\t\tdst.timestamp = this.#state.timestamp;\n\t\tdst.latest = this.#state.latest;\n\t\tfor (const frame of this.#state.frames.peek()) appendFrame(dst, frame);\n\t\tdst.start = this.#state.start;\n\t\t// The replay only covers what is still buffered, so the count has to come from the\n\t\t// source: it is what names a frame's absolute sequence, and what a publisher reads\n\t\t// to resolve the live edge.\n\t\tdst.total.set(this.#state.total.peek());\n\n\t\tconst closed = this.#state.closed.peek();\n\t\tif (closed !== undefined) {\n\t\t\tdst.closed.set(closed);\n\t\t\treturn makeConsumer(dst);\n\t\t}\n\n\t\tthis.#mirrors ??= new Set();\n\t\tthis.#mirrors.add(dst);\n\t\tthis.#used.set(true);\n\n\t\t// Track this mirror's close eagerly (not just lazily on the next write) so demand drops the\n\t\t// moment the last reader leaves, letting an abandoned fetch cancel even with no more frames.\n\t\tconst dispose = dst.closed.subscribe((c) => {\n\t\t\tif (c === undefined) return;\n\t\t\tthis.#mirrors?.delete(dst);\n\t\t\tthis.#used.set((this.#mirrors?.size ?? 0) > 0);\n\t\t\tdispose();\n\t\t});\n\n\t\treturn makeConsumer(dst);\n\t}\n\n\t/**\n\t * Whether any mirror reader is currently attached.\n\t *\n\t * Pairs with {@link unused}. Fetch coalescing watches it to cancel a download once every reader\n\t * has gone: a group can stay open indefinitely (a catalog track, a JSON stream), so it can't\n\t * rely on the stream ending on its own.\n\t *\n\t * @internal Track fan-out and fetch coalescing only.\n\t */\n\tget used(): Getter<boolean> {\n\t\treturn this.#used;\n\t}\n\n\t/**\n\t * Resolves once no mirror reader remains (or the group closes).\n\t *\n\t * @internal Track fan-out and fetch coalescing only.\n\t */\n\tasync unused(): Promise<void> {\n\t\twhile (this.#used.peek() && this.#state.closed.peek() === undefined) {\n\t\t\tawait Signal.race(this.#used, this.#state.closed);\n\t\t}\n\t}\n\n\t/** Writes a frame to the group. */\n\twriteFrame(frame: Frame) {\n\t\t// Closed first: a write after a clean close at the cap would otherwise take the\n\t\t// overflow path, wipe committed frames, and leave readers with an empty success.\n\t\tif (this.#state.closed.peek() !== undefined) throw new Error(\"group is closed\");\n\t\t// A frame past the cache cap would make the group exceed its budget by itself, so\n\t\t// accepting it would report success for a write nothing can ever read. Rust rejects\n\t\t// it up front with `Error::FrameTooLarge`; do the same rather than silently dropping it.\n\t\tif (frame.payload.byteLength > MAX_GROUP_CACHE_BYTES) throw new FrameTooLarge();\n\t\tif (\n\t\t\tthis.#state.total.peek() >= MAX_GROUP_FRAMES ||\n\t\t\tthis.#state.cacheBytes + frame.payload.byteLength > MAX_GROUP_CACHE_BYTES\n\t\t) {\n\t\t\tconst err = new GroupTooLarge();\n\t\t\tthis.#state.frames.set([]);\n\t\t\tthis.#state.cacheBytes = 0;\n\t\t\tif (this.#mirrors) {\n\t\t\t\tfor (const mirror of this.#mirrors) {\n\t\t\t\t\tmirror.frames.set([]);\n\t\t\t\t\tmirror.cacheBytes = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.close(err);\n\t\t\tthrow err;\n\t\t}\n\n\t\tthis.#activity = performance.now();\n\t\tappendFrame(this.#state, frame);\n\n\t\tif (this.#mirrors) {\n\t\t\tfor (const mirror of this.#mirrors) {\n\t\t\t\tif (mirror.closed.peek() !== undefined) this.#mirrors.delete(mirror);\n\t\t\t\telse appendFrame(mirror, frame);\n\t\t\t}\n\t\t}\n\t}\n\n\t/** Write a string as a single UTF-8 encoded frame, stamped with {@link Timestamp.now}. */\n\twriteString(str: string) {\n\t\tthis.writeFrame({ payload: new TextEncoder().encode(str), timestamp: Timestamp.now() });\n\t}\n\n\t/** Write a value as a single JSON-encoded frame, stamped with {@link Timestamp.now}. */\n\twriteJson(json: unknown) {\n\t\tthis.writeString(JSON.stringify(json));\n\t}\n\n\t/** Write a boolean as a single one-byte frame, stamped with {@link Timestamp.now}. */\n\twriteBool(bool: boolean) {\n\t\tthis.writeFrame({ payload: new Uint8Array([bool ? 1 : 0]), timestamp: Timestamp.now() });\n\t}\n\n\t/** True once the group has been closed. */\n\tget isClosed(): boolean {\n\t\treturn this.#state.closed.peek() !== undefined;\n\t}\n\n\t/** Closes the group, optionally with an error to abort readers. */\n\tclose(abort?: Error) {\n\t\tif (this.#state.closed.peek() !== undefined) return;\n\t\tthis.#state.closed.set(abort ?? null);\n\n\t\tif (this.#mirrors) {\n\t\t\tfor (const mirror of this.#mirrors) {\n\t\t\t\tif (mirror.closed.peek() === undefined) mirror.closed.set(abort ?? null);\n\t\t\t}\n\t\t\tthis.#mirrors.clear();\n\t\t}\n\t}\n}\n\nlet makeConsumer: (state: GroupState) => Consumer;\n\n// A consumer can finish from its own expiry verdict or from the shared group state. Keep\n// one stable public handle while letting peek() observe either source synchronously, before\n// signal subscribers run in the next microtask.\nclass CombinedClosed implements GetPromise<Error | null> {\n\t#preferred: Once<Error | null>;\n\t#source: Once<Error | null>;\n\t#sourceCleanReady: () => boolean;\n\t#value = new Once<Error | null>();\n\t#dispose?: Dispose;\n\n\tconstructor(preferred: Once<Error | null>, source: Once<Error | null>, sourceCleanReady: () => boolean) {\n\t\tthis.#preferred = preferred;\n\t\tthis.#source = source;\n\t\tthis.#sourceCleanReady = sourceCleanReady;\n\t\tif (this.#sync()) return;\n\n\t\tconst dispose = [preferred.changed(() => this.#sync()), source.changed(() => this.#sync())];\n\t\tthis.#dispose = () => {\n\t\t\tfor (const close of dispose) close();\n\t\t};\n\t}\n\n\t#sync(): boolean {\n\t\tif (this.#value.peek() !== undefined) return true;\n\t\tconst preferred = this.#preferred.peek();\n\t\tconst source = this.#source.peek();\n\t\tconst value =\n\t\t\tpreferred !== undefined\n\t\t\t\t? preferred\n\t\t\t\t: source instanceof Error || this.#sourceCleanReady()\n\t\t\t\t\t? source\n\t\t\t\t\t: undefined;\n\t\tif (value === undefined) return false;\n\n\t\tthis.#value.set(value);\n\t\tthis.#dispose?.();\n\t\tthis.#dispose = undefined;\n\t\treturn true;\n\t}\n\n\trefresh() {\n\t\tthis.#sync();\n\t}\n\n\tpeek(): Error | null | undefined {\n\t\tthis.#sync();\n\t\treturn this.#value.peek();\n\t}\n\n\tchanged(): Promise<Error | null | undefined>;\n\tchanged(fn: (value: Error | null | undefined) => void): Dispose;\n\tchanged(fn?: (value: Error | null | undefined) => void): Promise<Error | null | undefined> | Dispose {\n\t\tthis.#sync();\n\t\treturn fn ? this.#value.changed(fn) : this.#value.changed();\n\t}\n\n\tsubscribe(fn: (value: Error | null | undefined) => void): Dispose {\n\t\tthis.#sync();\n\t\treturn this.#value.subscribe(fn);\n\t}\n\n\t// biome-ignore lint/suspicious/noThenProperty: CombinedClosed is intentionally awaitable.\n\tthen<R1 = Error | null, R2 = never>(\n\t\tonFulfilled?: ((value: Error | null) => R1 | PromiseLike<R1>) | null,\n\t\tonRejected?: ((reason: unknown) => R2 | PromiseLike<R2>) | null,\n\t): PromiseLike<R1 | R2> {\n\t\tthis.#sync();\n\t\treturn this.#value.then(onFulfilled, onRejected);\n\t}\n}\n\n/**\n * The read side of an ordered stream of frames within a track.\n *\n * Created internally: obtain one from {@link Producer.consume} or a track subscriber's\n * group reads.\n *\n * @public\n */\nexport class Consumer {\n\t/** Sequence number of this group within its track. */\n\treadonly sequence: number;\n\n\t#state: GroupState;\n\t#expiry?: { expired: () => boolean; changed: readonly Getter<unknown>[] };\n\t// Sticky verdicts, set once. `#ended` is a drained group the budget gave up on,\n\t// which is indistinguishable from one that ended: nothing was lost, so it reads as\n\t// the end of the group. `#terminal` is a failure, including a budget that gave up\n\t// while content was still unread.\n\t#ended = false;\n\t#terminal?: Error;\n\t#verdict = new Once<Error | null>();\n\t#closed?: CombinedClosed;\n\t#pendingFrames = 0;\n\n\tprivate constructor(state: GroupState) {\n\t\tthis.#state = state;\n\t\tthis.sequence = state.sequence;\n\t}\n\n\t/**\n\t * Settles when this consumer reaches a terminal state: `null` after a clean close has no\n\t * unread or in-flight frames, or the terminal {@link Error}.\n\t * Peek it synchronously (`undefined` while open), observe it reactively, or `await` it.\n\t */\n\tget closed(): GetPromise<Error | null> {\n\t\tthis.#closed ??= new CombinedClosed(\n\t\t\tthis.#verdict,\n\t\t\tthis.#state.closed,\n\t\t\t() => this.#state.frames.peek().length === 0 && this.#pendingFrames === 0,\n\t\t);\n\t\treturn this.#closed;\n\t}\n\n\tstatic {\n\t\tmakeConsumer = (state) => new Consumer(state);\n\t\thooks.groupTimestamp = (group) => group.#state.timestamp;\n\t\thooks.groupLatest = (group) => group.#state.latest;\n\t\thooks.expireGroup = (group, expiry) => {\n\t\t\tgroup.#expiry = expiry;\n\t\t};\n\t\thooks.guardGroup = (group, operation) => group.#guard(operation);\n\t\thooks.readGroupFrame = (group, from) => group.#readFramePosition(true, from);\n\t\thooks.evictGroup = (group) => {\n\t\t\tgroup.#evict();\n\t\t};\n\t}\n\n\t// Evaluate the drift budget for a read that has nothing buffered and is about to\n\t// wait. A group with frames in hand is always drained: the budget bounds a group\n\t// that has stalled while the live edge moved on, not a reader slower than the wire.\n\t// Returns true if a verdict was just reached, so the caller re-checks.\n\t//\n\t// `unread` is for a caller that still holds content the reader has not seen (a\n\t// publisher part-way through writing a frame): giving up there is a truncation, so\n\t// it fails rather than ending.\n\t#expire(unread = false): boolean {\n\t\tif (this.#terminal || this.#ended) return false;\n\t\tif (this.#state.closed.peek() instanceof Error) return false;\n\t\tif (!this.#expiry?.expired()) return false;\n\n\t\tif (unread) {\n\t\t\tthis.#terminal = new Error(\"group exceeded the subscription max age budget\");\n\t\t} else {\n\t\t\tthis.#ended = true;\n\t\t}\n\t\tif (this.#verdict.peek() === undefined) this.#verdict.set(this.#terminal ?? null);\n\t\treturn true;\n\t}\n\n\t#guard<T>(operation: Promise<T>): Promise<T> {\n\t\tif (this.#expire(true)) return Promise.reject(this.#terminal);\n\t\tif (this.#terminal) return Promise.reject(this.#terminal);\n\t\tconst expiry = this.#expiry;\n\t\tif (!expiry) return operation;\n\n\t\treturn new Promise<T>((resolve, reject) => {\n\t\t\tlet settled = false;\n\t\t\tconst disposes: Dispose[] = [];\n\t\t\tconst finish = (fn: () => void) => {\n\t\t\t\tif (settled) return;\n\t\t\t\tsettled = true;\n\t\t\t\tfor (const dispose of disposes) dispose();\n\t\t\t\tfn();\n\t\t\t};\n\t\t\tconst check = () => {\n\t\t\t\tthis.#expire(true);\n\t\t\t\tif (this.#terminal) {\n\t\t\t\t\tconst error = this.#terminal;\n\t\t\t\t\tfinish(() => reject(error));\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tfor (const changed of expiry.changed) disposes.push(changed.subscribe(check));\n\t\t\toperation.then(\n\t\t\t\t(value) => finish(() => resolve(value)),\n\t\t\t\t(error: unknown) => finish(() => reject(error)),\n\t\t\t);\n\t\t\tcheck();\n\t\t});\n\t}\n\n\t#evict() {\n\t\tconst frames = this.#state.frames.peek();\n\t\tif (frames.length > 0) {\n\t\t\t// Unread content is going away either way. If the budget had already given up\n\t\t\t// on this group that is the more specific reason, so ask it first; otherwise\n\t\t\t// the reader simply lagged behind the cache.\n\t\t\tthis.#expire(true);\n\t\t\tif (!this.#terminal && !this.#ended) {\n\t\t\t\tthis.#terminal = new TooFarBehind();\n\t\t\t\tif (this.#verdict.peek() === undefined) this.#verdict.set(this.#terminal);\n\t\t\t}\n\t\t}\n\t\tif (frames.length > 0) {\n\t\t\tthis.#state.start += frames.length;\n\t\t}\n\t\tthis.#state.cacheBytes = 0;\n\t\tthis.#state.frames.set([]);\n\t}\n\n\tasync #changed(): Promise<void> {\n\t\tif (!this.#expiry) {\n\t\t\tawait Signal.race(this.#state.frames, this.#state.closed);\n\t\t\treturn;\n\t\t}\n\t\tawait Signal.race(this.#state.frames, this.#state.closed, ...this.#expiry.changed);\n\t}\n\n\t#readBufferedFrame(pending = false): ReadGroupFrame | undefined {\n\t\tconst frames = this.#state.frames.peek();\n\t\tconst buffered = frames.shift();\n\t\tif (!buffered) return undefined;\n\n\t\tconst sequence = this.#state.start++;\n\t\tif (pending) this.#pendingFrames++;\n\t\tlet completed = false;\n\t\treturn {\n\t\t\tsequence,\n\t\t\tframe: buffered,\n\t\t\tcomplete: () => {\n\t\t\t\tif (completed) return;\n\t\t\t\tcompleted = true;\n\t\t\t\tif (pending) this.#pendingFrames--;\n\t\t\t\tthis.#closed?.refresh();\n\t\t\t},\n\t\t};\n\t}\n\n\t/** True once no further frames can be read: the group has closed and every buffered frame is read. */\n\tget done(): boolean {\n\t\treturn (\n\t\t\tthis.#terminal !== undefined ||\n\t\t\tthis.#ended ||\n\t\t\t(this.#state.frames.peek().length === 0 && this.#state.closed.peek() !== undefined)\n\t\t);\n\t}\n\n\t/** True once the group has been closed, regardless of whether buffered frames remain unread. Synchronous complement to the {@link closed} promise. */\n\tget isClosed(): boolean {\n\t\treturn this.#terminal !== undefined || this.#ended || this.#state.closed.peek() !== undefined;\n\t}\n\n\t/**\n\t * How many frames the group has held, including any already read.\n\t *\n\t * It is also the next frame's sequence number, so `frameCount - 1` names the newest\n\t * frame written so far. A publisher snapshots it to resolve the track's live edge.\n\t */\n\tget frameCount(): number {\n\t\treturn this.#state.total.peek();\n\t}\n\n\t/**\n\t * Reads the next already-buffered frame without blocking.\n\t * Treat the returned frame bytes as read-only; they are shared with other consumers.\n\t *\n\t * Returns `undefined` when nothing is buffered right now. That is not by itself\n\t * end-of-group: check {@link done} to tell \"no frame buffered yet\" from \"finished\".\n\t */\n\ttryReadFrame(): Frame | undefined {\n\t\tif (this.#terminal || this.#ended) return undefined;\n\t\tconst read = this.#readBufferedFrame();\n\t\tread?.complete();\n\t\treturn read?.frame;\n\t}\n\n\t/** Like {@link tryReadFrame} but also reports the frame's sequence number within the group. */\n\ttryReadFrameSequence(): ({ sequence: number } & Frame) | undefined {\n\t\tif (this.#terminal || this.#ended) return undefined;\n\t\tconst read = this.#readBufferedFrame();\n\t\tif (!read) return undefined;\n\t\tread.complete();\n\t\treturn { sequence: read.sequence, payload: read.frame.payload, timestamp: read.frame.timestamp };\n\t}\n\n\t/** Resolves once {@link readFrame} would not block. */\n\tasync readable(): Promise<void> {\n\t\tfor (;;) {\n\t\t\tif (this.#terminal || this.#ended) return;\n\t\t\tif (this.#state.frames.peek().length > 0) return;\n\t\t\tif (this.#state.closed.peek() !== undefined) {\n\t\t\t\tthis.#closed?.refresh();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (this.#expire()) return;\n\t\t\tawait this.#changed();\n\t\t}\n\t}\n\n\t/**\n\t * Reads the next frame from the group.\n\t * Treat the returned frame bytes as read-only; they are shared with other consumers.\n\t */\n\tasync readFrame(): Promise<Frame | undefined> {\n\t\treturn (await this.#readFramePosition())?.frame;\n\t}\n\n\tasync #readFramePosition(pending = false, from = 0): Promise<ReadGroupFrame | undefined> {\n\t\tfor (;;) {\n\t\t\tif (this.#terminal) throw this.#terminal;\n\t\t\tif (this.#ended) return;\n\n\t\t\tconst read = this.#readBufferedFrame(pending);\n\t\t\tif (read) {\n\t\t\t\tif (read.sequence < from) {\n\t\t\t\t\tread.complete();\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (!pending) read.complete();\n\t\t\t\treturn read;\n\t\t\t}\n\n\t\t\tconst closed = this.#state.closed.peek();\n\t\t\tif (closed instanceof Error) throw closed;\n\t\t\tif (closed !== undefined) {\n\t\t\t\tthis.#closed?.refresh();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Nothing buffered and the group is still open: this wait is the stall the\n\t\t\t// drift budget bounds, and the only place it applies.\n\t\t\tif (this.#expire()) continue;\n\t\t\tawait this.#changed();\n\t\t}\n\t}\n\n\t/**\n\t * Reads the next frame along with its sequence number within the group.\n\t * Treat the returned frame bytes as read-only; they are shared with other consumers.\n\t */\n\tasync readFrameSequence(options?: ReadOptions): Promise<({ sequence: number } & Frame) | undefined> {\n\t\tconst read = await this.#readFramePosition(false, options?.from ?? 0);\n\t\tif (!read) return undefined;\n\t\treturn { sequence: read.sequence, payload: read.frame.payload, timestamp: read.frame.timestamp };\n\t}\n\n\t/** Reads the next frame and decodes its payload as a UTF-8 string. */\n\tasync readString(): Promise<string | undefined> {\n\t\tconst frame = await this.readFrame();\n\t\treturn frame ? new TextDecoder().decode(frame.payload) : undefined;\n\t}\n\n\t/** Reads the next frame and parses its payload as JSON. */\n\tasync readJson(): Promise<unknown | undefined> {\n\t\tconst frame = await this.readString();\n\t\treturn frame ? JSON.parse(frame) : undefined;\n\t}\n\n\t/** Reads the next frame and decodes its payload as a one-byte boolean. */\n\tasync readBool(): Promise<boolean | undefined> {\n\t\tconst frame = await this.readFrame();\n\t\treturn frame ? frame.payload[0] === 1 : undefined;\n\t}\n\n\t/** Closes the group, optionally with an error to abort readers. Idempotent. */\n\tclose(abort?: Error) {\n\t\tif (this.#state.closed.peek() !== undefined) return; // already closed\n\t\tthis.#state.closed.set(abort ?? null);\n\t}\n}\n"]}
1
+ {"version":3,"file":"group.js","sourceRoot":"","sources":["../src/group.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAA8C,IAAI,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACxF,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACxE,OAAO,EAAE,KAAK,EAAuB,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,4GAA4G;AAC5G,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAEtD,uHAAuH;AACvH,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAmCrC,4EAA4E;AAC5E,MAAM,UAAU;IACN,QAAQ,CAAS;IAC1B,MAAM,GAAG,IAAI,MAAM,CAAU,EAAE,CAAC,CAAC;IACjC,MAAM,GAAG,IAAI,IAAI,EAAgB,CAAC;IAClC,KAAK,GAAG,IAAI,MAAM,CAAS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C,SAAS,CAAC;IAC9C,CAAC;IAED,0EAA0E;IAC1E,KAAK,CAAC,QAAQ;QACb,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC;QACrC,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACnD,CAAC;IAED,+EAA+E;IAC/E,KAAK,CAAC,KAAa;QAClB,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,SAAS;YAAE,OAAO,CAAC,iBAAiB;QACtE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC;IACvC,CAAC;CACD","sourcesContent":["/**\n * Group role handles: an ordered stream of frames within a track, delivered over one QUIC stream.\n *\n * @module\n */\nimport { type Dispose, type GetPromise, type Getter, Once, Signal } from \"@moq/signals\";\nimport { FrameTooLarge, GroupTooLarge, TooFarBehind } from \"./error.ts\";\nimport { hooks, type ReadGroupFrame } from \"./internal.ts\";\nimport { Timestamp } from \"./time.ts\";\n\n/** Maximum bytes of frames in a group. A write that would exceed this aborts with {@link GroupTooLarge}. */\nexport const MAX_GROUP_CACHE_BYTES = 32 * 1024 * 1024;\n\n/** Maximum number of frames in a group. 8192 is the largest legal group; the 8193rd write is {@link GroupTooLarge}. */\nexport const MAX_GROUP_FRAMES = 8192;\n\n/**\n * A frame buffered in a group: its presentation {@link Timestamp} and payload bytes.\n *\n * The timestamp carries its own scale, so a track can pick its units; the wire layer\n * converts it into the track's negotiated timescale.\n */\nexport interface Frame {\n\t/** The frame payload. */\n\tpayload: Uint8Array;\n\t/**\n\t * Presentation timestamp. Required: for a payload with no presentation time of its own\n\t * (a JSON catalog, control state) pass {@link Timestamp.now} explicitly.\n\t */\n\ttimestamp: Timestamp;\n}\n\n/** Options for a sequence-aware frame read. */\nexport interface ReadOptions {\n\t/**\n\t * The lowest sequence number the caller wants; defaults to the whole group.\n\t *\n\t * Frames below it are discarded instead of returned. The group still starts at frame 0,\n\t * so this is a reader filter, not a missing prefix.\n\t */\n\tfrom?: number;\n}\n\n/** Immutable group metadata. */\nexport interface Info {\n\t/** Sequence number of this group within its track. */\n\tsequence: number;\n}\n\n/** Reactive backing state shared by the group producer and one consumer. */\nclass GroupState {\n\treadonly sequence: number;\n\tframes = new Signal<Frame[]>([]);\n\tclosed = new Once<Error | null>();\n\ttotal = new Signal<number>(0); // The total number of frames in the group thus far\n\n\t// Absolute sequence of the frame at the front of `frames`, advanced by a read: the\n\t// sequence the next read returns.\n\tstart = 0;\n\n\tcacheBytes = 0;\n\t// The first frame's timestamp, retained after reads.\n\ttimestamp?: Timestamp;\n\t// The newest frame's timestamp: where a reader that has taken every frame sits.\n\tlatest?: Timestamp;\n\n\tconstructor(sequence: number) {\n\t\tthis.sequence = sequence;\n\t}\n}\n\nfunction appendFrame(state: GroupState, frame: Frame) {\n\tif (state.closed.peek() !== undefined) throw new Error(\"group is closed\");\n\n\tstate.timestamp ??= frame.timestamp;\n\tstate.latest = frame.timestamp;\n\tstate.cacheBytes += frame.payload.byteLength;\n\tstate.frames.mutate((frames) => {\n\t\tframes.push(frame);\n\t});\n\n\tstate.total.update((total) => total + 1);\n}\n\n/**\n * The write side of an ordered stream of frames within a track.\n *\n * @public\n */\nexport class Producer {\n\t/** Sequence number of this group within its track. */\n\treadonly sequence: number;\n\n\t#state: GroupState;\n\t#mirrors?: Set<GroupState>;\n\n\t// Whether any mirror reader is attached (see {@link used}). Fetch coalescing watches it to\n\t// cancel an abandoned download; a group can stay open indefinitely (a catalog or JSON stream),\n\t// so this is what stops a reader-less fetch instead of the stream ending on its own.\n\t#used = new Signal<boolean>(false);\n\n\t// When the group was created or last written. Retention ages a group from this,\n\t// not from its creation, so a group still being filled is never reclaimed.\n\t#activity = performance.now();\n\n\tconstructor(sequence: number) {\n\t\tthis.#state = new GroupState(sequence);\n\t\tthis.sequence = sequence;\n\t}\n\n\t/**\n\t * When the group was created or last written, in `performance.now()` milliseconds.\n\t *\n\t * @internal Track retention only.\n\t */\n\tget activity(): number {\n\t\treturn this.#activity;\n\t}\n\n\t/**\n\t * Settles once the group closes: `null` on a clean close, or the abort {@link Error}.\n\t * Peek it synchronously (`undefined` while open), observe it reactively, or `await` it.\n\t */\n\tget closed(): GetPromise<Error | null> {\n\t\treturn this.#state.closed;\n\t}\n\n\t/** A read handle for this group. */\n\tconsume(): Consumer {\n\t\treturn makeConsumer(this.#state);\n\t}\n\n\t/**\n\t * Create an independent read handle that receives every frame written here.\n\t *\n\t * Frames written so far are replayed synchronously; later writes and close are teed\n\t * in as they happen.\n\t *\n\t * @internal Track fan-out and fetch coalescing only. Use {@link consume} instead.\n\t */\n\tmirror(): Consumer {\n\t\tconst dst = new GroupState(this.sequence);\n\t\tdst.timestamp = this.#state.timestamp;\n\t\tdst.latest = this.#state.latest;\n\t\tfor (const frame of this.#state.frames.peek()) appendFrame(dst, frame);\n\t\tdst.start = this.#state.start;\n\t\t// The replay only covers what is still buffered, so the count has to come from the\n\t\t// source: it is what names a frame's absolute sequence, and what a publisher reads\n\t\t// to resolve the live edge.\n\t\tdst.total.set(this.#state.total.peek());\n\n\t\tconst closed = this.#state.closed.peek();\n\t\tif (closed !== undefined) {\n\t\t\tdst.closed.set(closed);\n\t\t\treturn makeConsumer(dst);\n\t\t}\n\n\t\tthis.#mirrors ??= new Set();\n\t\tthis.#mirrors.add(dst);\n\t\tthis.#used.set(true);\n\n\t\t// Track this mirror's close eagerly (not just lazily on the next write) so demand drops the\n\t\t// moment the last reader leaves, letting an abandoned fetch cancel even with no more frames.\n\t\tconst dispose = dst.closed.subscribe((c) => {\n\t\t\tif (c === undefined) return;\n\t\t\tthis.#mirrors?.delete(dst);\n\t\t\tthis.#used.set((this.#mirrors?.size ?? 0) > 0);\n\t\t\tdispose();\n\t\t});\n\n\t\treturn makeConsumer(dst);\n\t}\n\n\t/**\n\t * Whether any mirror reader is currently attached.\n\t *\n\t * Pairs with {@link unused}. Fetch coalescing watches it to cancel a download once every reader\n\t * has gone: a group can stay open indefinitely (a catalog track, a JSON stream), so it can't\n\t * rely on the stream ending on its own.\n\t *\n\t * @internal Track fan-out and fetch coalescing only.\n\t */\n\tget used(): Getter<boolean> {\n\t\treturn this.#used;\n\t}\n\n\t/**\n\t * Resolves once no mirror reader remains (or the group closes).\n\t *\n\t * @internal Track fan-out and fetch coalescing only.\n\t */\n\tasync unused(): Promise<void> {\n\t\twhile (this.#used.peek() && this.#state.closed.peek() === undefined) {\n\t\t\tawait Signal.race(this.#used, this.#state.closed);\n\t\t}\n\t}\n\n\t/** Writes a frame to the group. */\n\twriteFrame(frame: Frame) {\n\t\t// Closed first: a write after a clean close at the cap would otherwise take the\n\t\t// overflow path, wipe committed frames, and leave readers with an empty success.\n\t\tif (this.#state.closed.peek() !== undefined) throw new Error(\"group is closed\");\n\t\t// A frame past the cache cap would make the group exceed its budget by itself, so\n\t\t// accepting it would report success for a write nothing can ever read. Rust rejects\n\t\t// it up front with `Error::FrameTooLarge`; do the same rather than silently dropping it.\n\t\tif (frame.payload.byteLength > MAX_GROUP_CACHE_BYTES) throw new FrameTooLarge();\n\t\tif (\n\t\t\tthis.#state.total.peek() >= MAX_GROUP_FRAMES ||\n\t\t\tthis.#state.cacheBytes + frame.payload.byteLength > MAX_GROUP_CACHE_BYTES\n\t\t) {\n\t\t\tconst err = new GroupTooLarge();\n\t\t\tthis.#state.frames.set([]);\n\t\t\tthis.#state.cacheBytes = 0;\n\t\t\tif (this.#mirrors) {\n\t\t\t\tfor (const mirror of this.#mirrors) {\n\t\t\t\t\tmirror.frames.set([]);\n\t\t\t\t\tmirror.cacheBytes = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.close(err);\n\t\t\tthrow err;\n\t\t}\n\n\t\tthis.#activity = performance.now();\n\t\tappendFrame(this.#state, frame);\n\n\t\tif (this.#mirrors) {\n\t\t\tfor (const mirror of this.#mirrors) {\n\t\t\t\tif (mirror.closed.peek() !== undefined) this.#mirrors.delete(mirror);\n\t\t\t\telse appendFrame(mirror, frame);\n\t\t\t}\n\t\t}\n\t}\n\n\t/** Write a string as a single UTF-8 encoded frame, stamped with {@link Timestamp.now}. */\n\twriteString(str: string) {\n\t\tthis.writeFrame({ payload: new TextEncoder().encode(str), timestamp: Timestamp.now() });\n\t}\n\n\t/** Write a value as a single JSON-encoded frame, stamped with {@link Timestamp.now}. */\n\twriteJson(json: unknown) {\n\t\tthis.writeString(JSON.stringify(json));\n\t}\n\n\t/** Write a boolean as a single one-byte frame, stamped with {@link Timestamp.now}. */\n\twriteBool(bool: boolean) {\n\t\tthis.writeFrame({ payload: new Uint8Array([bool ? 1 : 0]), timestamp: Timestamp.now() });\n\t}\n\n\t/** True once the group has been closed. */\n\tget isClosed(): boolean {\n\t\treturn this.#state.closed.peek() !== undefined;\n\t}\n\n\t/** Closes the group, optionally with an error to abort readers. */\n\tclose(abort?: Error) {\n\t\tif (this.#state.closed.peek() !== undefined) return;\n\t\tthis.#state.closed.set(abort ?? null);\n\n\t\tif (this.#mirrors) {\n\t\t\tfor (const mirror of this.#mirrors) {\n\t\t\t\tif (mirror.closed.peek() === undefined) mirror.closed.set(abort ?? null);\n\t\t\t}\n\t\t\tthis.#mirrors.clear();\n\t\t}\n\t}\n}\n\nlet makeConsumer: (state: GroupState) => Consumer;\n\n// A consumer can finish from its own expiry verdict or from the shared group state. Keep\n// one stable public handle while letting peek() observe either source synchronously, before\n// signal subscribers run in the next microtask.\nclass CombinedClosed implements GetPromise<Error | null> {\n\t#preferred: Once<Error | null>;\n\t#source: Once<Error | null>;\n\t#sourceCleanReady: () => boolean;\n\t#value = new Once<Error | null>();\n\t#dispose?: Dispose;\n\n\tconstructor(preferred: Once<Error | null>, source: Once<Error | null>, sourceCleanReady: () => boolean) {\n\t\tthis.#preferred = preferred;\n\t\tthis.#source = source;\n\t\tthis.#sourceCleanReady = sourceCleanReady;\n\t\tif (this.#sync()) return;\n\n\t\tconst dispose = [preferred.changed(() => this.#sync()), source.changed(() => this.#sync())];\n\t\tthis.#dispose = () => {\n\t\t\tfor (const close of dispose) close();\n\t\t};\n\t}\n\n\t#sync(): boolean {\n\t\tif (this.#value.peek() !== undefined) return true;\n\t\tconst preferred = this.#preferred.peek();\n\t\tconst source = this.#source.peek();\n\t\tconst value =\n\t\t\tpreferred !== undefined\n\t\t\t\t? preferred\n\t\t\t\t: source instanceof Error || this.#sourceCleanReady()\n\t\t\t\t\t? source\n\t\t\t\t\t: undefined;\n\t\tif (value === undefined) return false;\n\n\t\tthis.#value.set(value);\n\t\tthis.#dispose?.();\n\t\tthis.#dispose = undefined;\n\t\treturn true;\n\t}\n\n\trefresh() {\n\t\tthis.#sync();\n\t}\n\n\tpeek(): Error | null | undefined {\n\t\tthis.#sync();\n\t\treturn this.#value.peek();\n\t}\n\n\tchanged(): Promise<Error | null | undefined>;\n\tchanged(fn: (value: Error | null | undefined) => void): Dispose;\n\tchanged(fn?: (value: Error | null | undefined) => void): Promise<Error | null | undefined> | Dispose {\n\t\tthis.#sync();\n\t\treturn fn ? this.#value.changed(fn) : this.#value.changed();\n\t}\n\n\tsubscribe(fn: (value: Error | null | undefined) => void): Dispose {\n\t\tthis.#sync();\n\t\treturn this.#value.subscribe(fn);\n\t}\n\n\t// biome-ignore lint/suspicious/noThenProperty: CombinedClosed is intentionally awaitable.\n\tthen<R1 = Error | null, R2 = never>(\n\t\tonFulfilled?: ((value: Error | null) => R1 | PromiseLike<R1>) | null,\n\t\tonRejected?: ((reason: unknown) => R2 | PromiseLike<R2>) | null,\n\t): PromiseLike<R1 | R2> {\n\t\tthis.#sync();\n\t\treturn this.#value.then(onFulfilled, onRejected);\n\t}\n}\n\n/**\n * The read side of an ordered stream of frames within a track.\n *\n * Created internally: obtain one from {@link Producer.consume} or a track subscriber's\n * group reads.\n *\n * @public\n */\nexport class Consumer {\n\t/** Sequence number of this group within its track. */\n\treadonly sequence: number;\n\n\t#state: GroupState;\n\t#expiry?: { expired: () => boolean; changed: readonly Getter<unknown>[] };\n\t// Sticky verdicts, set once. `#ended` is a drained group the budget gave up on,\n\t// which is indistinguishable from one that ended: nothing was lost, so it reads as\n\t// the end of the group. `#terminal` is a failure, including a budget that gave up\n\t// while content was still unread.\n\t#ended = false;\n\t#terminal?: Error;\n\t#verdict = new Once<Error | null>();\n\t#closed?: CombinedClosed;\n\t#pendingFrames = 0;\n\n\tprivate constructor(state: GroupState) {\n\t\tthis.#state = state;\n\t\tthis.sequence = state.sequence;\n\t}\n\n\t/**\n\t * Settles when this consumer reaches a terminal state: `null` after a clean close has no\n\t * unread or in-flight frames, or the terminal {@link Error}.\n\t * Peek it synchronously (`undefined` while open), observe it reactively, or `await` it.\n\t */\n\tget closed(): GetPromise<Error | null> {\n\t\tthis.#closed ??= new CombinedClosed(\n\t\t\tthis.#verdict,\n\t\t\tthis.#state.closed,\n\t\t\t() => this.#state.frames.peek().length === 0 && this.#pendingFrames === 0,\n\t\t);\n\t\treturn this.#closed;\n\t}\n\n\tstatic {\n\t\tmakeConsumer = (state) => new Consumer(state);\n\t\thooks.groupTimestamp = (group) => group.#state.timestamp;\n\t\thooks.groupLatest = (group) => group.#state.latest;\n\t\thooks.expireGroup = (group, expiry) => {\n\t\t\tgroup.#expiry = expiry;\n\t\t};\n\t\thooks.guardGroup = (group, operation) => group.#guard(operation);\n\t\thooks.readGroupFrame = (group, from) => group.#readFramePosition(true, from);\n\t\thooks.evictGroup = (group) => {\n\t\t\tgroup.#evict();\n\t\t};\n\t}\n\n\t// Evaluate the drift budget for a read that has nothing buffered and is about to\n\t// wait. A group with frames in hand is always drained: the budget bounds a group\n\t// that has stalled while the live edge moved on, not a reader slower than the wire.\n\t// Returns true if a verdict was just reached, so the caller re-checks.\n\t//\n\t// `unread` is for a caller that still holds content the reader has not seen (a\n\t// publisher part-way through writing a frame): giving up there is a truncation, so\n\t// it fails rather than ending.\n\t#expire(unread = false): boolean {\n\t\tif (this.#terminal || this.#ended) return false;\n\t\tif (this.#state.closed.peek() instanceof Error) return false;\n\t\tif (!this.#expiry?.expired()) return false;\n\n\t\tif (unread) {\n\t\t\tthis.#terminal = new Error(\"group exceeded the subscription max age budget\");\n\t\t} else {\n\t\t\tthis.#ended = true;\n\t\t}\n\t\tif (this.#verdict.peek() === undefined) this.#verdict.set(this.#terminal ?? null);\n\t\treturn true;\n\t}\n\n\t// Takes a thunk rather than a started promise, so a group already past its budget\n\t// never begins the write: an abandoned write would reject later with no handler.\n\t#guard<T>(operation: () => Promise<T>): Promise<T> {\n\t\tthis.#expire(true);\n\t\tif (this.#terminal) return Promise.reject(this.#terminal);\n\t\tconst expiry = this.#expiry;\n\t\tif (!expiry) return operation();\n\n\t\treturn new Promise<T>((resolve, reject) => {\n\t\t\tlet settled = false;\n\t\t\tconst disposes: Dispose[] = [];\n\t\t\tconst finish = (fn: () => void) => {\n\t\t\t\tif (settled) return;\n\t\t\t\tsettled = true;\n\t\t\t\tfor (const dispose of disposes) dispose();\n\t\t\t\tfn();\n\t\t\t};\n\t\t\tconst check = () => {\n\t\t\t\tthis.#expire(true);\n\t\t\t\tif (this.#terminal) {\n\t\t\t\t\tconst error = this.#terminal;\n\t\t\t\t\tfinish(() => reject(error));\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tfor (const changed of expiry.changed) disposes.push(changed.subscribe(check));\n\t\t\toperation().then(\n\t\t\t\t(value) => finish(() => resolve(value)),\n\t\t\t\t(error: unknown) => finish(() => reject(error)),\n\t\t\t);\n\t\t\tcheck();\n\t\t});\n\t}\n\n\t#evict() {\n\t\tconst frames = this.#state.frames.peek();\n\t\tif (frames.length > 0) {\n\t\t\t// Unread content is going away either way. If the budget had already given up\n\t\t\t// on this group that is the more specific reason, so ask it first; otherwise\n\t\t\t// the reader simply lagged behind the cache.\n\t\t\tthis.#expire(true);\n\t\t\tif (!this.#terminal && !this.#ended) {\n\t\t\t\tthis.#terminal = new TooFarBehind();\n\t\t\t\tif (this.#verdict.peek() === undefined) this.#verdict.set(this.#terminal);\n\t\t\t}\n\t\t}\n\t\tif (frames.length > 0) {\n\t\t\tthis.#state.start += frames.length;\n\t\t}\n\t\tthis.#state.cacheBytes = 0;\n\t\tthis.#state.frames.set([]);\n\t}\n\n\tasync #changed(): Promise<void> {\n\t\tif (!this.#expiry) {\n\t\t\tawait Signal.race(this.#state.frames, this.#state.closed);\n\t\t\treturn;\n\t\t}\n\t\tawait Signal.race(this.#state.frames, this.#state.closed, ...this.#expiry.changed);\n\t}\n\n\t#readBufferedFrame(pending = false): ReadGroupFrame | undefined {\n\t\tconst frames = this.#state.frames.peek();\n\t\tconst buffered = frames.shift();\n\t\tif (!buffered) return undefined;\n\n\t\tconst sequence = this.#state.start++;\n\t\tif (pending) this.#pendingFrames++;\n\t\tlet completed = false;\n\t\treturn {\n\t\t\tsequence,\n\t\t\tframe: buffered,\n\t\t\tcomplete: () => {\n\t\t\t\tif (completed) return;\n\t\t\t\tcompleted = true;\n\t\t\t\tif (pending) this.#pendingFrames--;\n\t\t\t\tthis.#closed?.refresh();\n\t\t\t},\n\t\t};\n\t}\n\n\t/** True once no further frames can be read: the group has closed and every buffered frame is read. */\n\tget done(): boolean {\n\t\treturn (\n\t\t\tthis.#terminal !== undefined ||\n\t\t\tthis.#ended ||\n\t\t\t(this.#state.frames.peek().length === 0 && this.#state.closed.peek() !== undefined)\n\t\t);\n\t}\n\n\t/** True once the group has been closed, regardless of whether buffered frames remain unread. Synchronous complement to the {@link closed} promise. */\n\tget isClosed(): boolean {\n\t\treturn this.#terminal !== undefined || this.#ended || this.#state.closed.peek() !== undefined;\n\t}\n\n\t/**\n\t * How many frames the group has held, including any already read.\n\t *\n\t * It is also the next frame's sequence number, so `frameCount - 1` names the newest\n\t * frame written so far. A publisher snapshots it to resolve the track's live edge.\n\t */\n\tget frameCount(): number {\n\t\treturn this.#state.total.peek();\n\t}\n\n\t/**\n\t * Reads the next already-buffered frame without blocking.\n\t * Treat the returned frame bytes as read-only; they are shared with other consumers.\n\t *\n\t * Returns `undefined` when nothing is buffered right now. That is not by itself\n\t * end-of-group: check {@link done} to tell \"no frame buffered yet\" from \"finished\".\n\t */\n\ttryReadFrame(): Frame | undefined {\n\t\tif (this.#terminal || this.#ended) return undefined;\n\t\tconst read = this.#readBufferedFrame();\n\t\tread?.complete();\n\t\treturn read?.frame;\n\t}\n\n\t/** Like {@link tryReadFrame} but also reports the frame's sequence number within the group. */\n\ttryReadFrameSequence(): ({ sequence: number } & Frame) | undefined {\n\t\tif (this.#terminal || this.#ended) return undefined;\n\t\tconst read = this.#readBufferedFrame();\n\t\tif (!read) return undefined;\n\t\tread.complete();\n\t\treturn { sequence: read.sequence, payload: read.frame.payload, timestamp: read.frame.timestamp };\n\t}\n\n\t/** Resolves once {@link readFrame} would not block. */\n\tasync readable(): Promise<void> {\n\t\tfor (;;) {\n\t\t\tif (this.#terminal || this.#ended) return;\n\t\t\tif (this.#state.frames.peek().length > 0) return;\n\t\t\tif (this.#state.closed.peek() !== undefined) {\n\t\t\t\tthis.#closed?.refresh();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (this.#expire()) return;\n\t\t\tawait this.#changed();\n\t\t}\n\t}\n\n\t/**\n\t * Reads the next frame from the group.\n\t * Treat the returned frame bytes as read-only; they are shared with other consumers.\n\t */\n\tasync readFrame(): Promise<Frame | undefined> {\n\t\treturn (await this.#readFramePosition())?.frame;\n\t}\n\n\tasync #readFramePosition(pending = false, from = 0): Promise<ReadGroupFrame | undefined> {\n\t\tfor (;;) {\n\t\t\tif (this.#terminal) throw this.#terminal;\n\t\t\tif (this.#ended) return;\n\n\t\t\tconst read = this.#readBufferedFrame(pending);\n\t\t\tif (read) {\n\t\t\t\tif (read.sequence < from) {\n\t\t\t\t\tread.complete();\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (!pending) read.complete();\n\t\t\t\treturn read;\n\t\t\t}\n\n\t\t\tconst closed = this.#state.closed.peek();\n\t\t\tif (closed instanceof Error) throw closed;\n\t\t\tif (closed !== undefined) {\n\t\t\t\tthis.#closed?.refresh();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Nothing buffered and the group is still open: this wait is the stall the\n\t\t\t// drift budget bounds, and the only place it applies.\n\t\t\tif (this.#expire()) continue;\n\t\t\tawait this.#changed();\n\t\t}\n\t}\n\n\t/**\n\t * Reads the next frame along with its sequence number within the group.\n\t * Treat the returned frame bytes as read-only; they are shared with other consumers.\n\t */\n\tasync readFrameSequence(options?: ReadOptions): Promise<({ sequence: number } & Frame) | undefined> {\n\t\tconst read = await this.#readFramePosition(false, options?.from ?? 0);\n\t\tif (!read) return undefined;\n\t\treturn { sequence: read.sequence, payload: read.frame.payload, timestamp: read.frame.timestamp };\n\t}\n\n\t/** Reads the next frame and decodes its payload as a UTF-8 string. */\n\tasync readString(): Promise<string | undefined> {\n\t\tconst frame = await this.readFrame();\n\t\treturn frame ? new TextDecoder().decode(frame.payload) : undefined;\n\t}\n\n\t/** Reads the next frame and parses its payload as JSON. */\n\tasync readJson(): Promise<unknown | undefined> {\n\t\tconst frame = await this.readString();\n\t\treturn frame ? JSON.parse(frame) : undefined;\n\t}\n\n\t/** Reads the next frame and decodes its payload as a one-byte boolean. */\n\tasync readBool(): Promise<boolean | undefined> {\n\t\tconst frame = await this.readFrame();\n\t\treturn frame ? frame.payload[0] === 1 : undefined;\n\t}\n\n\t/** Closes the group, optionally with an error to abort readers. Idempotent. */\n\tclose(abort?: Error) {\n\t\tif (this.#state.closed.peek() !== undefined) return; // already closed\n\t\tthis.#state.closed.set(abort ?? null);\n\t}\n}\n"]}
package/hop.d.ts CHANGED
@@ -50,6 +50,14 @@ export declare const MAX_HOPS = 32;
50
50
  * bundles. Mirrors `Hop::random` in rs/moq-net.
51
51
  */
52
52
  export declare function randomHop(): Hop;
53
+ /**
54
+ * Name an unknown original publisher: put `stamp`, the receiving connection's own random id,
55
+ * in front of a chain that starts with 0, and turn an empty chain into `[stamp, 0]`. A
56
+ * publisher that reconnects then reads downstream as a new first hop, while the 0 after the
57
+ * stamp keeps the route ranked as anonymous. `undefined` if the chain is full or already holds
58
+ * `stamp`. Mirrors `Hops::stamp` in rs/moq-net.
59
+ */
60
+ export declare function stampHops(hops: readonly Hop[], stamp: Hop): Hop[] | undefined;
53
61
  /**
54
62
  * What pulling content via a route costs, in two magnitudes accumulated together
55
63
  * and compared in that order: lower {@link Cost.warm} wins, and {@link Cost.cold}
package/hop.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"hop.d.ts","sourceRoot":"","sources":["../src/hop.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAE9B;;;;;;;;;;GAUG;AACH,eAAO,MAAM,SAAS,2DAGR,CAAC;AAEf,MAAM,MAAM,GAAG,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,SAAS,CAAC,CAAC;AAE5C;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,EAAE,GAAyB,CAAC;AAEpD;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,KAAK,CAAC;AAE3B;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,IAAI,GAAG,CAO/B;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,IAAI;IACpB,qFAAqF;IACrF,IAAI,EAAE,MAAM,CAAC;IACb,sDAAsD;IACtD,IAAI,EAAE,MAAM,CAAC;CACb;AAED,qCAAqC;AACrC,eAAO,MAAM,IAAI;IAChB,mEAAmE;IACnE,IAAI,EAA4B,IAAI;CACpC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,WAAW,KAAK;IACrB,+DAA+D;IAC/D,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,6DAA6D;IAC7D,IAAI,EAAE,IAAI,CAAC;CACX;AAED,kDAAkD;AAClD,eAAO,MAAM,KAAK;IACjB,oFAAoF;IACpF,OAAO,EAAmC,KAAK;IAE/C,uFAAuF;IACvF,SAAS,SAAQ,KAAK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EAAE,CAAC;IACZ,6DAA6D;IAC7D,IAAI,EAAE,IAAI,CAAC;CACX;AAED,kDAAkD;AAClD,eAAO,MAAM,KAAK;IACjB,oFAAoF;IACpF,OAAO,EAAmC,KAAK;IAE/C,uFAAuF;IACvF,SAAS,SAAQ,KAAK,GAAG;QAAE,IAAI,CAAC,EAAE,SAAS,GAAG,EAAE,CAAC;QAAC,IAAI,CAAC,EAAE,IAAI,GAAG,MAAM,CAAA;KAAE,GAAQ,KAAK;CAOrF,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAEjD;AAED,2DAA2D;AAC3D,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,GAAG,SAAS,EAAE,CAAC,EAAE,KAAK,GAAG,SAAS,GAAG,OAAO,CAS/E"}
package/hop.js CHANGED
@@ -60,6 +60,22 @@ export function randomHop() {
60
60
  // Guard against the (astronomically unlikely) zero draw.
61
61
  return HopSchema.parse(raw === 0n ? 1n : raw);
62
62
  }
63
+ /**
64
+ * Name an unknown original publisher: put `stamp`, the receiving connection's own random id,
65
+ * in front of a chain that starts with 0, and turn an empty chain into `[stamp, 0]`. A
66
+ * publisher that reconnects then reads downstream as a new first hop, while the 0 after the
67
+ * stamp keeps the route ranked as anonymous. `undefined` if the chain is full or already holds
68
+ * `stamp`. Mirrors `Hops::stamp` in rs/moq-net.
69
+ */
70
+ export function stampHops(hops, stamp) {
71
+ if (hops.length === 0)
72
+ return [stamp, UNKNOWN_HOP];
73
+ if (hops[0] !== UNKNOWN_HOP)
74
+ return [...hops];
75
+ if (hops.length >= MAX_HOPS || hops.includes(stamp))
76
+ return undefined;
77
+ return [stamp, ...hops];
78
+ }
63
79
  /** Constructors for {@link Cost}. */
64
80
  export const Cost = {
65
81
  /** A free path in both magnitudes: what a live publisher seeds. */
package/hop.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"hop.js","sourceRoot":"","sources":["../src/hop.ts"],"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,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAC3C,CAAC;AACH,CAAC","sourcesContent":["/**\n * Endpoint identity within a hop chain, shared by both wire protocols.\n *\n * moq-lite carries these natively on every announcement; moq-transport carries them\n * via the MoQ Cluster extension (see `ietf/cluster.ts`). Mirrors `Hop` in\n * `rs/moq-net`.\n *\n * @module\n */\nimport * as z from \"zod/mini\";\n\n/**\n * One relay's identity in a broadcast's hop chain, encoded as a 62-bit varint on the wire.\n *\n * Names a *hop*, not an {@link !Origin | Origin} routing table: this is the id a relay\n * stamps into a chain as an announcement passes through, so a receiver can spot its own\n * id and reject a loop. The SETUP parameter that carries it session-wide is `Hop` too.\n *\n * The {@link HopSchema} validates any incoming value and brands it so the type system\n * enforces \"only validated ids flow into hop chains.\" Internal code that synthesizes one\n * (e.g. {@link randomHop}) uses `HopSchema.parse(...)` to brand a raw bigint.\n */\nexport const HopSchema = z\n\t.bigint()\n\t.check(z.refine((value) => value >= 0n && value < 1n << 62n, \"Hop must be a non-negative 62-bit integer\"))\n\t.brand(\"Hop\");\n\nexport type Hop = z.infer<typeof HopSchema>;\n\n/**\n * The reserved id 0, meaning \"no identity\".\n *\n * It stands in for an endpoint that never declared one, and any number of endpoints can\n * be 0, so it identifies nothing: it is never a loop, never a publisher two chains have\n * in common, and never excluded from an advertisement. A chain that holds a 0 anywhere\n * is anonymous for route selection.\n */\nexport const UNKNOWN_HOP: Hop = HopSchema.parse(0n);\n\n/**\n * Maximum length of a hop chain. Must match `MAX_HOPS` in Rust's `model/origin.rs`.\n *\n * Broadcasts with longer chains are rejected, which bounds loop detection and rejects\n * pathological announcements across clusters with unbounded forwarding.\n */\nexport const MAX_HOPS = 32;\n\n/**\n * Generate a fresh hop with a random non-zero id.\n *\n * `crypto.getRandomValues` is overkill for best-effort loop detection, but\n * used for slightly better distribution than `Math.random` at negligible cost.\n *\n * TEMPORARY: the wire format allows 62 bits, but older `@moq/lite` JS clients\n * decode `AnnounceInterest.exclude_hop` as a u53 (number) and throw on anything\n * > 2^53-1. To keep those clients alive against fresh peers, we cap the random\n * id at 53 bits. Restore to 62 bits once the u62 fix has propagated to deployed\n * bundles. Mirrors `Hop::random` in rs/moq-net.\n */\nexport function randomHop(): Hop {\n\tconst buf = new BigUint64Array(1);\n\tcrypto.getRandomValues(buf);\n\t// Mask to 53 bits.\n\tconst raw = buf[0] & 0x1f_ffff_ffff_ffffn;\n\t// Guard against the (astronomically unlikely) zero draw.\n\treturn HopSchema.parse(raw === 0n ? 1n : raw);\n}\n\n/**\n * What pulling content via a route costs, in two magnitudes accumulated together\n * and compared in that order: lower {@link Cost.warm} wins, and {@link Cost.cold}\n * breaks the tie.\n *\n * Both price the same path against different cache states. `warm` is what one more\n * subscription would cost the mesh right now, so it collapses to zero at any relay\n * already carrying the broadcast. `cold` prices the identical path as if nothing were\n * cached, so it keeps flowing through a warm relay unchanged and still says which of\n * two warm relays sits closer to the publisher.\n */\nexport interface Cost {\n\t/** The cost as the mesh stands today, discounted to zero at every carrying relay. */\n\twarm: bigint;\n\t/** The same path with every warm discount removed. */\n\tcold: bigint;\n}\n\n/** Constructors for {@link Cost}. */\nexport const Cost = {\n\t/** A free path in both magnitudes: what a live publisher seeds. */\n\tzero: { warm: 0n, cold: 0n } as Cost,\n};\n\n/**\n * The path a route took through the mesh and what using it costs.\n *\n * The metadata half of an advertisement: an origin `dynamic()` pairs it with the\n * pattern it covers, a broadcast `announce()` with the broadcast's exact path, and\n * an announce event carries it so consumers can read it back.\n */\nexport interface Route {\n\t/** The chain of hops the route has traversed, oldest first. */\n\thops: Hop[];\n\t/** What pulling content via this route costs; lower wins. */\n\tcost: Cost;\n}\n\n/** Constructors and helpers for {@link Route}. */\nexport const Route = {\n\t/** An empty hop chain at zero cost: what a publisher seeds for a live broadcast. */\n\tdefault: { hops: [], cost: Cost.zero } as Route,\n\n\t/** Normalize a partial route, treating a bare bigint cost as both magnitudes alike. */\n\tnormalize(route: Route | { hops?: readonly Hop[]; cost?: Cost | bigint } = {}): Route {\n\t\tconst hops = route.hops ? [...route.hops] : [];\n\t\tconst cost = route.cost;\n\t\tif (cost === undefined) return { hops, cost: Cost.zero };\n\t\tif (typeof cost === \"bigint\") return { hops, cost: { warm: cost, cold: cost } };\n\t\treturn { hops, cost: { warm: cost.warm, cold: cost.cold } };\n\t},\n};\n\n/**\n * Whether this route passed through an anonymous hop (id 0) at any depth.\n *\n * An empty chain is a local announcement, not the anonymous mark. Ingress fills a\n * received empty list with {@link UNKNOWN_HOP} before yielding it.\n */\nexport function isAnonymous(route: Route): boolean {\n\treturn route.hops.includes(UNKNOWN_HOP);\n}\n\n/** Whether two routes name the same hop chain and cost. */\nexport function routesEqual(a: Route | undefined, b: Route | undefined): boolean {\n\tif (a === b) return true;\n\tif (!a || !b) return false;\n\treturn (\n\t\ta.cost.warm === b.cost.warm &&\n\t\ta.cost.cold === b.cost.cold &&\n\t\ta.hops.length === b.hops.length &&\n\t\ta.hops.every((hop, i) => hop === b.hops[i])\n\t);\n}\n"]}
1
+ {"version":3,"file":"hop.js","sourceRoot":"","sources":["../src/hop.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAE9B;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC;KACxB,MAAM,EAAE;KACR,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,IAAI,EAAE,IAAI,KAAK,GAAG,EAAE,IAAI,GAAG,EAAE,2CAA2C,CAAC,CAAC;KACzG,KAAK,CAAC,KAAK,CAAC,CAAC;AAIf;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,WAAW,GAAQ,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AAEpD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,EAAE,CAAC;AAE3B;;;;;;;;;;;GAWG;AACH,MAAM,UAA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* moq-lite carries these natively on every announcement; moq-transport carries them\n * via the MoQ Cluster extension (see `ietf/cluster.ts`). Mirrors `Hop` in\n * `rs/moq-net`.\n *\n * @module\n */\nimport * as z from \"zod/mini\";\n\n/**\n * One relay's identity in a broadcast's hop chain, encoded as a 62-bit varint on the wire.\n *\n * Names a *hop*, not an {@link !Origin | Origin} routing table: this is the id a relay\n * stamps into a chain as an announcement passes through, so a receiver can spot its own\n * id and reject a loop. The SETUP parameter that carries it session-wide is `Hop` too.\n *\n * The {@link HopSchema} validates any incoming value and brands it so the type system\n * enforces \"only validated ids flow into hop chains.\" Internal code that synthesizes one\n * (e.g. {@link randomHop}) uses `HopSchema.parse(...)` to brand a raw bigint.\n */\nexport const HopSchema = z\n\t.bigint()\n\t.check(z.refine((value) => value >= 0n && value < 1n << 62n, \"Hop must be a non-negative 62-bit integer\"))\n\t.brand(\"Hop\");\n\nexport type Hop = z.infer<typeof HopSchema>;\n\n/**\n * The reserved id 0, meaning \"no identity\".\n *\n * It stands in for an endpoint that never declared one, and any number of endpoints can\n * be 0, so it identifies nothing: it is never a loop, never a publisher two chains have\n * in common, and never excluded from an advertisement. A chain that holds a 0 anywhere\n * is anonymous for route selection.\n */\nexport const UNKNOWN_HOP: Hop = HopSchema.parse(0n);\n\n/**\n * Maximum length of a hop chain. Must match `MAX_HOPS` in Rust's `model/origin.rs`.\n *\n * Broadcasts with longer chains are rejected, which bounds loop detection and rejects\n * pathological announcements across clusters with unbounded forwarding.\n */\nexport const MAX_HOPS = 32;\n\n/**\n * Generate a fresh hop with a random non-zero id.\n *\n * `crypto.getRandomValues` is overkill for best-effort loop detection, but\n * used for slightly better distribution than `Math.random` at negligible cost.\n *\n * TEMPORARY: the wire format allows 62 bits, but older `@moq/lite` JS clients\n * decode `AnnounceInterest.exclude_hop` as a u53 (number) and throw on anything\n * > 2^53-1. To keep those clients alive against fresh peers, we cap the random\n * id at 53 bits. Restore to 62 bits once the u62 fix has propagated to deployed\n * bundles. Mirrors `Hop::random` in rs/moq-net.\n */\nexport function randomHop(): Hop {\n\tconst buf = new BigUint64Array(1);\n\tcrypto.getRandomValues(buf);\n\t// Mask to 53 bits.\n\tconst raw = buf[0] & 0x1f_ffff_ffff_ffffn;\n\t// Guard against the (astronomically unlikely) zero draw.\n\treturn HopSchema.parse(raw === 0n ? 1n : raw);\n}\n\n/**\n * Name an unknown original publisher: put `stamp`, the receiving connection's own random id,\n * in front of a chain that starts with 0, and turn an empty chain into `[stamp, 0]`. A\n * publisher that reconnects then reads downstream as a new first hop, while the 0 after the\n * stamp keeps the route ranked as anonymous. `undefined` if the chain is full or already holds\n * `stamp`. Mirrors `Hops::stamp` in rs/moq-net.\n */\nexport function stampHops(hops: readonly Hop[], stamp: Hop): Hop[] | undefined {\n\tif (hops.length === 0) return [stamp, UNKNOWN_HOP];\n\tif (hops[0] !== UNKNOWN_HOP) return [...hops];\n\tif (hops.length >= MAX_HOPS || hops.includes(stamp)) return undefined;\n\treturn [stamp, ...hops];\n}\n\n/**\n * What pulling content via a route costs, in two magnitudes accumulated together\n * and compared in that order: lower {@link Cost.warm} wins, and {@link Cost.cold}\n * breaks the tie.\n *\n * Both price the same path against different cache states. `warm` is what one more\n * subscription would cost the mesh right now, so it collapses to zero at any relay\n * already carrying the broadcast. `cold` prices the identical path as if nothing were\n * cached, so it keeps flowing through a warm relay unchanged and still says which of\n * two warm relays sits closer to the publisher.\n */\nexport interface Cost {\n\t/** The cost as the mesh stands today, discounted to zero at every carrying relay. */\n\twarm: bigint;\n\t/** The same path with every warm discount removed. */\n\tcold: bigint;\n}\n\n/** Constructors for {@link Cost}. */\nexport const Cost = {\n\t/** A free path in both magnitudes: what a live publisher seeds. */\n\tzero: { warm: 0n, cold: 0n } as Cost,\n};\n\n/**\n * The path a route took through the mesh and what using it costs.\n *\n * The metadata half of an advertisement: an origin `dynamic()` pairs it with the\n * pattern it covers, a broadcast `announce()` with the broadcast's exact path, and\n * an announce event carries it so consumers can read it back.\n */\nexport interface Route {\n\t/** The chain of hops the route has traversed, oldest first. */\n\thops: Hop[];\n\t/** What pulling content via this route costs; lower wins. */\n\tcost: Cost;\n}\n\n/** Constructors and helpers for {@link Route}. */\nexport const Route = {\n\t/** An empty hop chain at zero cost: what a publisher seeds for a live broadcast. */\n\tdefault: { hops: [], cost: Cost.zero } as Route,\n\n\t/** Normalize a partial route, treating a bare bigint cost as both magnitudes alike. */\n\tnormalize(route: Route | { hops?: readonly Hop[]; cost?: Cost | bigint } = {}): Route {\n\t\tconst hops = route.hops ? [...route.hops] : [];\n\t\tconst cost = route.cost;\n\t\tif (cost === undefined) return { hops, cost: Cost.zero };\n\t\tif (typeof cost === \"bigint\") return { hops, cost: { warm: cost, cold: cost } };\n\t\treturn { hops, cost: { warm: cost.warm, cold: cost.cold } };\n\t},\n};\n\n/**\n * Whether this route passed through an anonymous hop (id 0) at any depth.\n *\n * An empty chain is a local announcement, not the anonymous mark. Ingress fills a\n * received empty list with {@link UNKNOWN_HOP} before yielding it.\n */\nexport function isAnonymous(route: Route): boolean {\n\treturn route.hops.includes(UNKNOWN_HOP);\n}\n\n/** Whether two routes name the same hop chain and cost. */\nexport function routesEqual(a: Route | undefined, b: Route | undefined): boolean {\n\tif (a === b) return true;\n\tif (!a || !b) return false;\n\treturn (\n\t\ta.cost.warm === b.cost.warm &&\n\t\ta.cost.cold === b.cost.cold &&\n\t\ta.hops.length === b.hops.length &&\n\t\ta.hops.every((hop, i) => hop === b.hops[i])\n\t);\n}\n"]}
package/ietf/adapter.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { Once } from "@moq/signals";
2
+ import type { Drain } from "../connection/goaway";
1
3
  import { Stream } from "../stream";
2
4
  import { type IetfVersion } from "./version";
3
5
  /**
@@ -36,6 +38,8 @@ export declare class NativeSession implements Session {
36
38
  export declare class ControlStreamAdapter implements Session {
37
39
  #private;
38
40
  readonly version: IetfVersion;
41
+ /** The peer's GOAWAY, which draft-14 to -16 carry on the shared control stream. */
42
+ readonly goaway: Once<Drain>;
39
43
  constructor(quic: WebTransport, controlStream: Stream, version: IetfVersion, maxRequestId: bigint, client: boolean);
40
44
  /**
41
45
  * Accept the next incoming virtual bidi stream.
@@ -62,6 +66,10 @@ export declare class ControlStreamAdapter implements Session {
62
66
  * Must be called after construction. Runs until the control stream closes.
63
67
  */
64
68
  run(): Promise<void>;
65
- close(): void;
69
+ /**
70
+ * Ends every virtual stream: cleanly for a deliberate close, or with `err` when the
71
+ * control stream died under them, since every request riding it was cut off.
72
+ */
73
+ close(err?: Error): void;
66
74
  }
67
75
  //# sourceMappingURL=adapter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/ietf/adapter.ts"],"names":[],"mappings":"AACA,OAAO,EAAU,MAAM,EAAe,MAAM,cAAc,CAAC;AAG3D,OAAO,EAAE,KAAK,WAAW,EAAW,MAAM,cAAc,CAAC;AAEzD;;;GAGG;AACH,MAAM,WAAW,OAAO;IACvB,MAAM,IAAI,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACnC,YAAY,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IACjC,QAAQ,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IACxC,aAAa,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IAC7C,KAAK,IAAI,IAAI,CAAC;IACd,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;CAC9B;AAED;;;GAGG;AACH,qBAAa,aAAc,YAAW,OAAO;;IAK5C,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;IAE9B,YAAY,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAIpE;IAEK,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,CAE9B;IAEK,QAAQ,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAE5C;IAEK,aAAa,IAAI,OAAO,CAAC,MAAM,G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QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;CAC9B;AAED;;;GAGG;AACH,qBAAa,aAAc,YAAW,OAAO;;IAK5C,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;IAE9B,YAAY,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAIpE;IAEK,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,CAE9B;IAEK,QAAQ,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAE5C;IAEK,aAAa,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAIjD;IAED,kDAAkD;IAClD,KAAK,SAEJ;CACD;AAqBD;;;;;;GAMG;AACH,qBAAa,oBAAqB,YAAW,OAAO;;IAQnD,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;IAE9B,mFAAmF;IACnF,QAAQ,CAAC,MAAM,cAAqB;IAsCpC,YACC,IAAI,EAAE,YAAY,EAClB,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,WAAW,EACpB,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,OAAO,EAWf;IAED;;;OAGG;IACG,QAAQ,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAS5C;IAED;;;;;OAKG;IACH,MAAM,IAAI,MAAM,CAoDf;IAED;;OAEG;IACG,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC,CAEpC;IAED;;OAEG;IACG,aAAa,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAYjD;IAED;;;OAGG;IACG,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,CAkEzB;IAqaD;;;OAGG;IACH,KAAK,CAAC,GAAG,CAAC,EAAE,KAAK,QA8BhB;CACD"}
package/ietf/adapter.js CHANGED
@@ -1,7 +1,10 @@
1
1
  /* @ts-self-types="./adapter.d.ts" */
2
+ import { Once } from "@moq/signals";
2
3
  import { Mutex } from "async-mutex";
4
+ import { error, ProtocolViolation } from "../error.js";
3
5
  import { Reader, Stream } from "../stream.js";
4
6
  import * as Varint from "../varint.js";
7
+ import { GoAway } from "./goaway.js";
5
8
  import * as Namespace from "./namespace.js";
6
9
  import { Version } from "./version.js";
7
10
  /**
@@ -39,7 +42,7 @@ export class NativeSession {
39
42
  const Route = {
40
43
  NewRequest: 0, // Create virtual bidi stream, push initial message
41
44
  Response: 1, // Push message to existing stream (keep open)
42
- ErrorResponse: 2, // Push message to existing stream, then close
45
+ ErrorResponse: 2, // Push a final message to existing stream, then close
43
46
  CloseStream: 3, // Close stream recv (no bytes pushed)
44
47
  FollowUp: 4, // Push follow-up message to existing stream
45
48
  MaxRequestId: 5, // Update flow control
@@ -61,6 +64,8 @@ export class ControlStreamAdapter {
61
64
  #writer;
62
65
  #writeMutex = new Mutex();
63
66
  version;
67
+ /** The peer's GOAWAY, which draft-14 to -16 carry on the shared control stream. */
68
+ goaway = new Once();
64
69
  // Virtual streams keyed by requestId
65
70
  #streams = new Map();
66
71
  // Namespace → requestId reverse lookups for v14/v15 namespace-keyed messages.
@@ -87,6 +92,8 @@ export class ControlStreamAdapter {
87
92
  #maxRequestId;
88
93
  #maxRequestIdResolves = [];
89
94
  #closed = false;
95
+ // Whether this side opened the session. Only a server may name a redirect.
96
+ #client;
90
97
  constructor(quic, controlStream, version, maxRequestId, client) {
91
98
  this.#quic = quic;
92
99
  this.#reader = controlStream.reader;
@@ -96,6 +103,7 @@ export class ControlStreamAdapter {
96
103
  this.version = version;
97
104
  this.#maxRequestId = maxRequestId;
98
105
  this.#requestId = client ? 0n : 1n;
106
+ this.#client = client;
99
107
  }
100
108
  /**
101
109
  * Accept the next incoming virtual bidi stream.
@@ -160,9 +168,7 @@ export class ControlStreamAdapter {
160
168
  }
161
169
  },
162
170
  });
163
- const stream = new Stream({ readable, writable: sendWritable });
164
- stream.reader.version = this.version;
165
- stream.writer.version = this.version;
171
+ const stream = new Stream({ readable, writable: sendWritable, version: this.version });
166
172
  return stream;
167
173
  }
168
174
  /**
@@ -193,6 +199,8 @@ export class ControlStreamAdapter {
193
199
  * Must be called after construction. Runs until the control stream closes.
194
200
  */
195
201
  async run() {
202
+ // Why the virtual streams end: undefined only for a GOAWAY, which is not a failure.
203
+ let cause;
196
204
  try {
197
205
  // v16: also accept real bidi streams (for SubscribeNamespace)
198
206
  if (this.version === Version.DRAFT_16) {
@@ -200,15 +208,25 @@ export class ControlStreamAdapter {
200
208
  }
201
209
  for (;;) {
202
210
  const done = await this.#reader.done();
203
- if (done)
211
+ if (done) {
212
+ cause = new ProtocolViolation("control stream closed");
204
213
  break;
214
+ }
205
215
  const typeId = await this.#reader.u53();
206
216
  const size = await this.#reader.u16();
207
217
  const body = await this.#reader.read(size);
208
218
  const classified = await this.#classify(typeId, body);
209
219
  if (classified.route === Route.GoAway) {
210
- console.warn("received GOAWAY on control stream");
211
- return;
220
+ // The session keeps serving: a GOAWAY asks us to migrate, not to stop reading.
221
+ const msg = await GoAway.decodeBody(body, this.version);
222
+ if (this.goaway.peek() !== undefined)
223
+ throw new ProtocolViolation("duplicate GOAWAY");
224
+ // A client may leave, but only the server may name where to go.
225
+ if (!this.#client && msg.newSessionUri !== "") {
226
+ throw new ProtocolViolation("client GOAWAY must not name a redirect");
227
+ }
228
+ this.goaway.set(msg.drain());
229
+ continue;
212
230
  }
213
231
  const { route, requestId } = classified;
214
232
  switch (route) {
@@ -237,8 +255,12 @@ export class ControlStreamAdapter {
237
255
  }
238
256
  }
239
257
  }
258
+ catch (err) {
259
+ cause = error(err);
260
+ throw err;
261
+ }
240
262
  finally {
241
- this.close();
263
+ this.close(cause);
242
264
  }
243
265
  }
244
266
  /** Accept real WebTransport bidi streams and queue them for acceptBi (v16). */
@@ -272,9 +294,7 @@ export class ControlStreamAdapter {
272
294
  },
273
295
  });
274
296
  const sendWritable = this.#createSendWritable();
275
- const stream = new Stream({ readable, writable: sendWritable });
276
- stream.reader.version = this.version;
277
- stream.writer.version = this.version;
297
+ const stream = new Stream({ readable, writable: sendWritable, version: this.version });
278
298
  this.#streams.set(requestId, { controller });
279
299
  // Push initial message bytes so the dispatcher can read typeId + decode
280
300
  controller.enqueue(this.#encodeRaw(typeId, size, body));
@@ -558,7 +578,10 @@ export class ControlStreamAdapter {
558
578
  return { route: Route.FollowUp, requestId: subNs08 };
559
579
  }
560
580
  case 0x0e: {
561
- // v15: NamespaceDone entry (no requestId) — route to SubscribeNamespace stream
581
+ if (this.version === Version.DRAFT_14 || this.version === Version.DRAFT_15) {
582
+ throw new Error("unexpected message 0x0e");
583
+ }
584
+ // v16+: NamespaceDone entry (no requestId) — route to SubscribeNamespace stream
562
585
  const subNs0e = this.#subscribeNamespaces.values().next().value;
563
586
  if (subNs0e === undefined)
564
587
  throw new Error("unexpected message 0x0e: no SubscribeNamespace stream");
@@ -578,9 +601,9 @@ export class ControlStreamAdapter {
578
601
  return { route: Route.CloseStream, requestId };
579
602
  }
580
603
  case 0x0b: {
581
- // PublishDone
604
+ // PublishDone: the subscriber reads its status and stream count before the end.
582
605
  const requestId = await readRequestId();
583
- return { route: Route.CloseStream, requestId };
606
+ return { route: Route.ErrorResponse, requestId };
584
607
  }
585
608
  case 0x17: {
586
609
  // FetchCancel
@@ -637,15 +660,21 @@ export class ControlStreamAdapter {
637
660
  throw new Error(`unknown control message type: 0x${typeId.toString(16)}`);
638
661
  }
639
662
  }
640
- close() {
663
+ /**
664
+ * Ends every virtual stream: cleanly for a deliberate close, or with `err` when the
665
+ * control stream died under them, since every request riding it was cut off.
666
+ */
667
+ close(err) {
641
668
  if (this.#closed)
642
669
  return;
643
670
  this.#closed = true;
644
671
  console.debug("adapter: close() called");
645
- // Close all virtual streams
646
672
  for (const entry of this.#streams.values()) {
647
673
  try {
648
- entry.controller.close();
674
+ if (err)
675
+ entry.controller.error(err);
676
+ else
677
+ entry.controller.close();
649
678
  }
650
679
  catch {
651
680
  // Already closed