@moq/net 0.3.5 → 0.4.0

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 (210) hide show
  1. package/announce.d.ts +7 -0
  2. package/announce.d.ts.map +1 -0
  3. package/announce.js +8 -0
  4. package/announce.js.map +1 -0
  5. package/announced.d.ts +35 -91
  6. package/announced.d.ts.map +1 -1
  7. package/announced.js +21 -156
  8. package/announced.js.map +1 -1
  9. package/bandwidth.d.ts +163 -0
  10. package/bandwidth.d.ts.map +1 -0
  11. package/bandwidth.js +304 -0
  12. package/bandwidth.js.map +1 -0
  13. package/bandwidth_api.d.ts +7 -0
  14. package/bandwidth_api.d.ts.map +1 -0
  15. package/bandwidth_api.js +8 -0
  16. package/bandwidth_api.js.map +1 -0
  17. package/broadcast.d.ts +20 -28
  18. package/broadcast.d.ts.map +1 -1
  19. package/broadcast.js +55 -38
  20. package/broadcast.js.map +1 -1
  21. package/connection/accept.d.ts +16 -1
  22. package/connection/accept.d.ts.map +1 -1
  23. package/connection/accept.js +39 -24
  24. package/connection/accept.js.map +1 -1
  25. package/connection/browser.d.ts.map +1 -1
  26. package/connection/browser.js +9 -7
  27. package/connection/browser.js.map +1 -1
  28. package/connection/connect.d.ts +30 -6
  29. package/connection/connect.d.ts.map +1 -1
  30. package/connection/connect.js +85 -45
  31. package/connection/connect.js.map +1 -1
  32. package/connection/established.d.ts +16 -21
  33. package/connection/established.d.ts.map +1 -1
  34. package/connection/established.js.map +1 -1
  35. package/connection/forward.d.ts +2 -0
  36. package/connection/forward.d.ts.map +1 -0
  37. package/connection/forward.js +159 -0
  38. package/connection/forward.js.map +1 -0
  39. package/connection/handshake.d.ts.map +1 -1
  40. package/connection/handshake.js +2 -2
  41. package/connection/handshake.js.map +1 -1
  42. package/connection/index.d.ts +5 -5
  43. package/connection/index.d.ts.map +1 -1
  44. package/connection/index.js +4 -5
  45. package/connection/index.js.map +1 -1
  46. package/connection/pool.d.ts +188 -0
  47. package/connection/pool.d.ts.map +1 -0
  48. package/connection/pool.js +351 -0
  49. package/connection/pool.js.map +1 -0
  50. package/connection/reload.d.ts +14 -93
  51. package/connection/reload.d.ts.map +1 -1
  52. package/connection/reload.js +216 -80
  53. package/connection/reload.js.map +1 -1
  54. package/connection/stats.d.ts +3 -26
  55. package/connection/stats.d.ts.map +1 -1
  56. package/connection/stats.js.map +1 -1
  57. package/connection/transport.d.ts +0 -7
  58. package/connection/transport.d.ts.map +1 -1
  59. package/consume.d.ts +1 -43
  60. package/consume.d.ts.map +1 -1
  61. package/consume.js +1 -1
  62. package/consume.js.map +1 -1
  63. package/error.d.ts +180 -29
  64. package/error.d.ts.map +1 -1
  65. package/error.js +310 -16
  66. package/error.js.map +1 -1
  67. package/errors.d.ts +7 -0
  68. package/errors.d.ts.map +1 -0
  69. package/errors.js +8 -0
  70. package/errors.js.map +1 -0
  71. package/group.d.ts +9 -43
  72. package/group.d.ts.map +1 -1
  73. package/group.js +283 -69
  74. package/group.js.map +1 -1
  75. package/hop.d.ts +107 -0
  76. package/hop.d.ts.map +1 -0
  77. package/hop.js +103 -0
  78. package/hop.js.map +1 -0
  79. package/ietf/aliases.d.ts +1 -78
  80. package/ietf/aliases.d.ts.map +1 -1
  81. package/ietf/cluster.d.ts +6 -120
  82. package/ietf/cluster.d.ts.map +1 -1
  83. package/ietf/cluster.js +81 -41
  84. package/ietf/cluster.js.map +1 -1
  85. package/ietf/connection.d.ts +6 -72
  86. package/ietf/connection.d.ts.map +1 -1
  87. package/ietf/connection.js +11 -47
  88. package/ietf/connection.js.map +1 -1
  89. package/ietf/error.d.ts +11 -0
  90. package/ietf/error.d.ts.map +1 -0
  91. package/ietf/error.js +168 -0
  92. package/ietf/error.js.map +1 -0
  93. package/ietf/filter.d.ts.map +1 -1
  94. package/ietf/filter.js +6 -1
  95. package/ietf/filter.js.map +1 -1
  96. package/ietf/goaway.d.ts.map +1 -1
  97. package/ietf/goaway.js +22 -5
  98. package/ietf/goaway.js.map +1 -1
  99. package/ietf/parameters.d.ts +2 -2
  100. package/ietf/parameters.d.ts.map +1 -1
  101. package/ietf/parameters.js +15 -17
  102. package/ietf/parameters.js.map +1 -1
  103. package/ietf/publish_namespace.d.ts +25 -0
  104. package/ietf/publish_namespace.d.ts.map +1 -1
  105. package/ietf/publish_namespace.js +63 -0
  106. package/ietf/publish_namespace.js.map +1 -1
  107. package/ietf/publisher.d.ts +1 -82
  108. package/ietf/publisher.d.ts.map +1 -1
  109. package/ietf/publisher.js +203 -136
  110. package/ietf/publisher.js.map +1 -1
  111. package/ietf/solicit.d.ts +1 -40
  112. package/ietf/solicit.d.ts.map +1 -1
  113. package/ietf/subscribe.d.ts +1 -5
  114. package/ietf/subscribe.d.ts.map +1 -1
  115. package/ietf/subscribe.js +8 -9
  116. package/ietf/subscribe.js.map +1 -1
  117. package/ietf/subscriber.d.ts +1 -65
  118. package/ietf/subscriber.d.ts.map +1 -1
  119. package/ietf/subscriber.js +154 -73
  120. package/ietf/subscriber.js.map +1 -1
  121. package/ietf/version.d.ts +12 -1
  122. package/ietf/version.d.ts.map +1 -1
  123. package/ietf/version.js +13 -0
  124. package/ietf/version.js.map +1 -1
  125. package/index.d.ts +11 -6
  126. package/index.d.ts.map +1 -1
  127. package/index.js +10 -5
  128. package/index.js.map +1 -1
  129. package/internal.d.ts +97 -1
  130. package/internal.d.ts.map +1 -1
  131. package/internal.js +65 -0
  132. package/internal.js.map +1 -1
  133. package/lite/announce.d.ts +15 -9
  134. package/lite/announce.d.ts.map +1 -1
  135. package/lite/announce.js +47 -20
  136. package/lite/announce.js.map +1 -1
  137. package/lite/connection.d.ts +9 -59
  138. package/lite/connection.d.ts.map +1 -1
  139. package/lite/connection.js +20 -32
  140. package/lite/connection.js.map +1 -1
  141. package/lite/fetch.d.ts +15 -1
  142. package/lite/fetch.d.ts.map +1 -1
  143. package/lite/fetch.js +39 -7
  144. package/lite/fetch.js.map +1 -1
  145. package/lite/goaway.d.ts.map +1 -1
  146. package/lite/goaway.js +7 -1
  147. package/lite/goaway.js.map +1 -1
  148. package/lite/group.d.ts +18 -4
  149. package/lite/group.d.ts.map +1 -1
  150. package/lite/group.js +31 -10
  151. package/lite/group.js.map +1 -1
  152. package/lite/priority.d.ts +1 -61
  153. package/lite/priority.d.ts.map +1 -1
  154. package/lite/priority.js +4 -5
  155. package/lite/priority.js.map +1 -1
  156. package/lite/publisher.d.ts +1 -69
  157. package/lite/publisher.d.ts.map +1 -1
  158. package/lite/publisher.js +507 -200
  159. package/lite/publisher.js.map +1 -1
  160. package/lite/setup.d.ts +7 -7
  161. package/lite/setup.d.ts.map +1 -1
  162. package/lite/setup.js +13 -13
  163. package/lite/setup.js.map +1 -1
  164. package/lite/subscribe.d.ts +61 -13
  165. package/lite/subscribe.d.ts.map +1 -1
  166. package/lite/subscribe.js +186 -44
  167. package/lite/subscribe.js.map +1 -1
  168. package/lite/subscriber.d.ts +8 -57
  169. package/lite/subscriber.d.ts.map +1 -1
  170. package/lite/subscriber.js +179 -117
  171. package/lite/subscriber.js.map +1 -1
  172. package/lite/track.d.ts +4 -10
  173. package/lite/track.d.ts.map +1 -1
  174. package/lite/track.js +34 -29
  175. package/lite/track.js.map +1 -1
  176. package/lite/version.d.ts +31 -6
  177. package/lite/version.d.ts.map +1 -1
  178. package/lite/version.js +71 -11
  179. package/lite/version.js.map +1 -1
  180. package/origin.d.ts +229 -29
  181. package/origin.d.ts.map +1 -1
  182. package/origin.js +1087 -37
  183. package/origin.js.map +1 -1
  184. package/package.json +3 -2
  185. package/path.d.ts +25 -7
  186. package/path.d.ts.map +1 -1
  187. package/path.js +5 -3
  188. package/path.js.map +1 -1
  189. package/stream.d.ts.map +1 -1
  190. package/stream.js +23 -14
  191. package/stream.js.map +1 -1
  192. package/time.d.ts +15 -2
  193. package/time.d.ts.map +1 -1
  194. package/time.js +28 -9
  195. package/time.js.map +1 -1
  196. package/track.d.ts +166 -83
  197. package/track.d.ts.map +1 -1
  198. package/track.js +617 -187
  199. package/track.js.map +1 -1
  200. package/wire.d.ts +67 -0
  201. package/wire.d.ts.map +1 -0
  202. package/wire.js +32 -0
  203. package/wire.js.map +1 -0
  204. package/zod.d.ts +1 -1
  205. package/zod.d.ts.map +1 -1
  206. package/zod.js.map +1 -1
  207. package/mock.d.ts +0 -66
  208. package/mock.d.ts.map +0 -1
  209. package/mock.js +0 -243
  210. package/mock.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"cluster.js","sourceRoot":"","sources":["../../src/ietf/cluster.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAe,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnF,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAqB,MAAM,iBAAiB,CAAC;AAC7E,OAAO,EAAoB,OAAO,EAAE,MAAM,cAAc,CAAC;AAEzD;;;;;;;;GAQG;AACH,MAAM,UAAU,SAAS,CAAC,OAAoB;IAC7C,OAAO,OAAO,KAAK,OAAO,CAAC,QAAQ,IAAI,OAAO,KAAK,OAAO,CAAC,QAAQ,IAAI,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC;AACrG,CAAC;AAwCD;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,MAAoB,EAAE,OAAoB;IACnE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;QAAE,OAAO,SAAS,CAAC;IAE1C,wFAAwF;IACxF,qFAAqF;IACrF,gBAAgB;IAChB,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;IACrD,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAE1C,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,MAAM,CAAC,iBAAiB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QACpB,IAAI,GAAG,KAAK,cAAc;YAAE,SAAS;QACrC,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,OAAO,GAAG,gCAAgC,CAAC,CAAC;IAClG,CAAC;AACF,CAAC","sourcesContent":["/**\n * The MoQ Cluster extension (draft-lcurley-moq-cluster-00).\n *\n * moq-transport carries no routing information, so a peer cannot tell whether an\n * advertisement already passed through us. This extension adds it:\n *\n * - each endpoint declares its own Hop ID via the RELAY_HOPS Setup Option, which is also\n * what negotiates the extension;\n * - every advertisement carries the HOP_PATH it traversed and the accumulated ROUTE_COST\n * of that path, as Key-Value-Pair message parameters on PUBLISH_NAMESPACE and NAMESPACE.\n *\n * These are the semantics moq-lite carries natively on every announcement (see\n * `lite/announce.ts`); this module is the moq-transport binding, negotiated on draft-17+\n * only, where SETUP is a Key-Value-Pair block.\n *\n * We are a leaf, never a relay: the only path we can advertise is our own, so we stamp a\n * single-entry HOP_PATH and seed the cost at 0. What we get out of declaring is the other\n * direction. A relay that knows our Hop ID withholds the advertisements that already flowed\n * through us, so publishing a broadcast no longer announces it back to us, which is what\n * moq-lite has always done with its own hop chain.\n *\n * @module\n * @internal\n */\n\nimport { ProtocolViolation, reason } from \"../error.ts\";\nimport { MAX_HOPS, type Origin, OriginSchema, UNKNOWN_ORIGIN } from \"../origin.ts\";\nimport type { Reader } from \"../stream.ts\";\nimport * as Varint from \"../varint.ts\";\nimport { Parameters, SetupOption, type SetupOptions } from \"./parameters.ts\";\nimport { type IetfVersion, Version } from \"./version.ts\";\n\n/**\n * Whether a version can negotiate the extension.\n *\n * Draft-17 is the first with the unified SETUP: a bare Key-Value-Pair block that a new\n * option slots into without touching the message shape. Earlier drafts exchange SETUP over\n * the legacy control stream, which this extension does not cover.\n *\n * @internal\n */\nexport function supported(version: IetfVersion): boolean {\n\treturn version !== Version.DRAFT_14 && version !== Version.DRAFT_15 && version !== Version.DRAFT_16;\n}\n\n/**\n * The Hop IDs this session declared, one per direction.\n *\n * @internal\n */\nexport interface Hops {\n\t/** Our own Hop ID, declared in SETUP and stamped onto every advertisement we send. */\n\tself: Origin;\n\n\t/**\n\t * The peer's Hop ID, or `undefined` when it declared no RELAY_HOPS.\n\t *\n\t * This is what decides whether advertisements carry the parameters at all, in both\n\t * directions: a peer that declared nothing has not read ours either, so sending it a\n\t * HOP_PATH would be a protocol violation and expecting one back would reject a legal\n\t * message. A peer that declared the reserved 0 negotiated the extension but withheld its\n\t * identity, so the parameters flow and there is simply nothing to exclude.\n\t */\n\tpeer?: Origin;\n}\n\n/**\n * The cluster parameters carried on one advertisement.\n *\n * Present on every PUBLISH_NAMESPACE and NAMESPACE of a session that negotiated the\n * extension, and on none of a session that did not.\n *\n * @internal\n */\nexport interface Advert {\n\t/** HOP_PATH: the path this advertisement traversed, publisher first, sender last. */\n\thops: Origin[];\n\n\t/** ROUTE_COST: the marginal cost of subscribing via this advertisement. Absent on the\n\t * wire means 0, so an endpoint that prices nothing sends nothing. */\n\tcost: bigint;\n}\n\n/**\n * Read the peer's Hop ID out of its SETUP, or `undefined` when it did not negotiate.\n *\n * @internal\n */\nexport function fromSetup(params: SetupOptions, version: IetfVersion): Origin | undefined {\n\tif (!supported(version)) return undefined;\n\n\t// RELAY_HOPS is odd, so its value is a length-prefixed byte string holding the sender's\n\t// Hop ID as a single varint. 0 is legal: the peer speaks the extension but withholds\n\t// its identity.\n\tconst value = params.getBytes(SetupOption.RelayHops);\n\tif (value === undefined) return undefined;\n\n\tconst [origin, rest] = Varint.decodeLeadingOnes(value);\n\tif (rest.length !== 0) throw new Error(\"trailing bytes in RELAY_HOPS\");\n\treturn OriginSchema.parse(origin);\n}\n\n/**\n * Declare our own Hop ID, which is also what negotiates the extension.\n *\n * @internal\n */\nexport function intoSetup(params: SetupOptions, self: Origin, version: IetfVersion) {\n\tif (!supported(version)) return;\n\tparams.setBytes(SetupOption.RelayHops, Varint.encodeLeadingOnes(self));\n}\n\n/**\n * Whether the session negotiated the extension, which is what decides whether an\n * advertisement carries the parameters in either direction.\n *\n * @internal\n */\nexport function negotiated(ids: Hops | undefined): boolean {\n\treturn ids?.peer !== undefined;\n}\n\n/**\n * The advertisement to send for one of our own broadcasts, or `undefined` on a session\n * that negotiated nothing.\n *\n * The sender's own Hop ID is always the last entry, so a receiver reconstructs the full\n * path without the sender restating it. We originate everything we advertise, so the path\n * is just us and the cost is 0: a subscription costs the peer nothing but the transfer,\n * since we are already producing the content.\n *\n * @internal\n */\nexport function advertise(ids: Hops | undefined): Advert | undefined {\n\tif (ids === undefined || ids.peer === undefined) return undefined;\n\treturn { hops: [ids.self], cost: 0n };\n}\n\n/**\n * Whether this advertisement looped back through `self`.\n *\n * A receiver discards such an advertisement: forwarding it would extend the loop, and\n * subscribing through it would route the receiver back to itself. Hop ID 0 identifies\n * nothing, so a receiver that withheld its own identity detects nothing.\n *\n * @internal\n */\nexport function loops(advert: Advert, self: Origin): boolean {\n\treturn self !== UNKNOWN_ORIGIN && advert.hops.includes(self);\n}\n\n/**\n * Write an advertisement's parameters, ready to encode onto the wire.\n *\n * @internal\n */\nexport function intoParams(advert: Advert): Parameters {\n\tvalidate(advert.hops);\n\n\tconst params = new Parameters();\n\n\t// The entries fill the value, so they are written with no count of their own and framed\n\t// by the parameter's own length prefix.\n\tconst hops = advert.hops.map((hop) => Varint.encodeLeadingOnes(hop));\n\tconst value = new Uint8Array(hops.reduce((total, hop) => total + hop.length, 0));\n\tlet offset = 0;\n\tfor (const hop of hops) {\n\t\tvalue.set(hop, offset);\n\t\toffset += hop.length;\n\t}\n\tparams.hopPath = value;\n\n\t// Absent means 0, so a free path sends nothing.\n\tif (advert.cost !== 0n) params.routeCost = advert.cost;\n\n\treturn params;\n}\n\n/**\n * Read the parameters a negotiated session puts on every advertisement.\n *\n * The parameter block is mandatory there, so a message that ends before it (the base form)\n * or one whose block does not parse is the peer's violation, same as a block that parses but\n * carries no HOP_PATH.\n *\n * @internal\n */\nexport async function decodeParams(r: Reader, version: IetfVersion): Promise<Advert> {\n\tlet params: Parameters;\n\ttry {\n\t\tparams = await Parameters.decode(r, version);\n\t} catch (err) {\n\t\tthrow new ProtocolViolation(reason(err), { cause: err });\n\t}\n\n\treturn fromParams(params);\n}\n\n/**\n * Read an advertisement out of a decoded parameter block.\n *\n * Every way this fails is one the draft says to close the session over: a negotiated session\n * that omits HOP_PATH, entries that do not exactly fill the parameter, an empty list, or a\n * non-zero Hop ID appearing twice. So they all surface as one {@link ProtocolViolation},\n * which the session dispatch acts on.\n *\n * @internal\n */\nexport function fromParams(params: Parameters): Advert {\n\ttry {\n\t\tconst value = params.hopPath;\n\t\tif (value === undefined) throw new Error(\"advertisement is missing HOP_PATH\");\n\n\t\tconst hops: Origin[] = [];\n\t\tlet rest = value;\n\t\twhile (rest.length > 0) {\n\t\t\t// A short read here means the entries did not exactly fill the length.\n\t\t\tconst [hop, remain] = Varint.decodeLeadingOnes(rest);\n\t\t\thops.push(OriginSchema.parse(hop));\n\t\t\trest = remain;\n\n\t\t\t// Bail before the buffer does: a hostile length would otherwise cost us one\n\t\t\t// allocation per entry all the way to 64KB of parameter value.\n\t\t\tif (hops.length > MAX_HOPS) throw new Error(`hop count exceeds maximum ${MAX_HOPS}`);\n\t\t}\n\n\t\tvalidate(hops);\n\t\treturn { hops, cost: params.routeCost ?? 0n };\n\t} catch (err) {\n\t\tthrow new ProtocolViolation(reason(err), { cause: err });\n\t}\n}\n\n/**\n * Reject a path that cannot have come from a conforming sender: an empty list, one longer\n * than we accept, or a non-zero Hop ID appearing twice (a loop). Duplicate zeros are legal,\n * since 0 identifies nothing.\n */\nfunction validate(hops: Origin[]) {\n\tif (hops.length === 0) throw new Error(\"hop path is empty\");\n\tif (hops.length > MAX_HOPS) throw new Error(`hop count ${hops.length} exceeds maximum ${MAX_HOPS}`);\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_ORIGIN) continue;\n\t\tif (hops.indexOf(hop, i + 1) !== -1) throw new Error(`hop ${hop} appears twice in the hop path`);\n\t}\n}\n"]}
1
+ {"version":3,"file":"cluster.js","sourceRoot":"","sources":["../../src/ietf/cluster.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAY,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAEvE,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAqB,MAAM,iBAAiB,CAAC;AAC7E,OAAO,EAAoB,OAAO,EAAE,MAAM,cAAc,CAAC;AAEzD;;;;;;;;GAQG;AACH,MAAM,UAAU,SAAS,CAAC,OAAoB;IAC7C,OAAO,OAAO,KAAK,OAAO,CAAC,QAAQ,IAAI,OAAO,KAAK,OAAO,CAAC,QAAQ,IAAI,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC;AACrG,CAAC;AAuDD;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,MAAoB,EAAE,OAAoB;IACnE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;QAAE,OAAO,SAAS,CAAC;IAE1C,wEAAwE;IACxE,MAAM,KAAK,GAAG,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAClD,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC1C,OAAO,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,MAAoB,EAAE,IAAS,EAAE,OAAoB;IAC9E,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;QAAE,OAAO;IAChC,MAA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CAAC,GAAG,MAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;QACrD,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;QAChC,IAAI,GAAG,MAAM,CAAC;QAEd,4EAA4E;QAC5E,+DAA+D;QAC/D,IAAI,IAAI,CAAC,MAAM,GAAG,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,6BAA6B,QAAQ,EAAE,CAAC,CAAC;IACtF,CAAC;IAED,QAAQ,CAAC,IAAI,CAAC,CAAC;IACf,OAAO,IAAI,CAAC;AACb,CAAC;AAED;;;;GAIG;AACH,SAAS,QAAQ,CAAC,IAAW;IAC5B,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;IAC5D,IAAI,IAAI,CAAC,MAAM,GAAG,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,aAAa,IAAI,CAAC,MAAM,oBAAoB,QAAQ,EAAE,CAAC,CAAC;IAEpG,0EAA0E;IAC1E,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,IAAI,GAAG,KAAK,WAAW;YAAE,SAAS;QAClC,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,OAAO,GAAG,gCAAgC,CAAC,CAAC;IAClG,CAAC;AACF,CAAC","sourcesContent":["/**\n * The MoQ Cluster extension (draft-lcurley-moq-cluster-01).\n *\n * moq-transport carries no routing information, so a peer cannot tell whether an\n * advertisement already passed through us. This extension adds it:\n *\n * - each endpoint declares its own Hop ID via the HOP_ID Setup Option, which is also what\n * negotiates the extension;\n * - every advertisement carries the HOP_PATH it traversed and the accumulated ROUTE_COST\n * of that path, as Key-Value-Pair message parameters on PUBLISH_NAMESPACE and NAMESPACE,\n * and a PUBLISH_NAMESPACE is repriced with the same parameters on a REQUEST_UPDATE.\n *\n * These are the semantics moq-lite carries natively on every announcement (see\n * `lite/announce.ts`); this module is the moq-transport binding, negotiated on draft-17+\n * only, where SETUP is a Key-Value-Pair block.\n *\n * We are a leaf, never a relay: the only path we can advertise is our own, so we stamp a\n * single-entry HOP_PATH and seed the cost at 0. What we get out of declaring is the other\n * direction. A relay that knows our Hop ID withholds the advertisements that already flowed\n * through us, so publishing a broadcast no longer announces it back to us, which is what\n * moq-lite has always done with its own hop chain.\n *\n * @module\n * @internal\n */\n\nimport { ProtocolViolation, reason } from \"../error.ts\";\nimport { type Hop, HopSchema, MAX_HOPS, UNKNOWN_HOP } from \"../hop.ts\";\nimport type { Reader } from \"../stream.ts\";\nimport * as Varint from \"../varint.ts\";\nimport { Parameters, SetupOption, type SetupOptions } from \"./parameters.ts\";\nimport { type IetfVersion, Version } from \"./version.ts\";\n\n/**\n * Whether a version can negotiate the extension.\n *\n * Draft-17 is the first with the unified SETUP: a bare Key-Value-Pair block that a new\n * option slots into without touching the message shape. Earlier drafts exchange SETUP over\n * the legacy control stream, which this extension does not cover.\n *\n * @internal\n */\nexport function supported(version: IetfVersion): boolean {\n\treturn version !== Version.DRAFT_14 && version !== Version.DRAFT_15 && version !== Version.DRAFT_16;\n}\n\n/**\n * The Hop IDs this session declared, one per direction.\n *\n * @internal\n */\nexport interface Hops {\n\t/** Our own Hop ID, declared in SETUP and stamped onto every advertisement we send. */\n\tself: Hop;\n\n\t/**\n\t * The peer's Hop ID, or `undefined` when it declared no HOP_ID.\n\t *\n\t * This is what decides whether advertisements carry the parameters at all, in both\n\t * directions: a peer that declared nothing has not read ours either, so sending it a\n\t * HOP_PATH would be a protocol violation and expecting one back would reject a legal\n\t * message. A peer that declared the reserved 0 negotiated the extension but withheld its\n\t * identity, so the parameters flow and there is simply nothing to exclude.\n\t */\n\tpeer?: Hop;\n}\n\n/**\n * The cluster parameters carried on one advertisement.\n *\n * Present on every PUBLISH_NAMESPACE and NAMESPACE of a session that negotiated the\n * extension, and on none of a session that did not.\n *\n * @internal\n */\nexport interface Advert {\n\t/** HOP_PATH: the path this advertisement traversed, publisher first, sender last. */\n\thops: Hop[];\n\n\t/** ROUTE_COST: the marginal cost of subscribing via this advertisement. Absent on the\n\t * wire means 0, so an endpoint that prices nothing sends nothing. */\n\tcost: bigint;\n}\n\n/**\n * The cluster parameters a REQUEST_UPDATE on a PUBLISH_NAMESPACE carries: only what\n * changed, since an omitted parameter keeps its value.\n *\n * @internal\n */\nexport interface Update {\n\t/** HOP_PATH, when the route changed. */\n\thops?: Hop[];\n\n\t/** ROUTE_COST, when the cost changed. A cost that dropped to 0 arrives as an explicit\n\t * 0 here, unlike the advertisement itself where absent means 0. */\n\tcost?: bigint;\n}\n\n/**\n * Read the peer's Hop ID out of its SETUP, or `undefined` when it did not negotiate.\n *\n * @internal\n */\nexport function fromSetup(params: SetupOptions, version: IetfVersion): Hop | undefined {\n\tif (!supported(version)) return undefined;\n\n\t// 0 is legal: the peer speaks the extension but withholds its identity.\n\tconst value = params.getVarint(SetupOption.HopId);\n\tif (value === undefined) return undefined;\n\treturn HopSchema.parse(value);\n}\n\n/**\n * Declare our own Hop ID, which is also what negotiates the extension.\n *\n * @internal\n */\nexport function intoSetup(params: SetupOptions, self: Hop, version: IetfVersion) {\n\tif (!supported(version)) return;\n\tparams.setVarint(SetupOption.HopId, self);\n}\n\n/**\n * Whether the session negotiated the extension, which is what decides whether an\n * advertisement carries the parameters in either direction.\n *\n * @internal\n */\nexport function negotiated(ids: Hops | undefined): boolean {\n\treturn ids?.peer !== undefined;\n}\n\n/**\n * The advertisement to send for one of our own broadcasts, or `undefined` on a session\n * that negotiated nothing.\n *\n * The sender's own Hop ID is always the last entry, so a receiver reconstructs the full\n * path without the sender restating it. We originate everything we advertise, so the path\n * is just us and the cost is 0: a subscription costs the peer nothing but the transfer,\n * since we are already producing the content.\n *\n * @internal\n */\nexport function advertise(ids: Hops | undefined): Advert | undefined {\n\tif (ids === undefined || ids.peer === undefined) return undefined;\n\treturn { hops: [ids.self], cost: 0n };\n}\n\n/**\n * Whether this advertisement looped back through `self`.\n *\n * A receiver discards such an advertisement: forwarding it would extend the loop, and\n * subscribing through it would route the receiver back to itself. Hop ID 0 identifies\n * nothing, so a receiver that withheld its own identity detects nothing.\n *\n * @internal\n */\nexport function loops(advert: Advert, self: Hop): boolean {\n\treturn self !== UNKNOWN_HOP && advert.hops.includes(self);\n}\n\n/**\n * Write an advertisement's parameters, ready to encode onto the wire.\n *\n * @internal\n */\nexport function intoParams(advert: Advert): Parameters {\n\tconst params = new Parameters();\n\tparams.hopPath = encodeHops(advert.hops);\n\n\t// Absent means 0, so a free path sends nothing.\n\tif (advert.cost !== 0n) params.routeCost = advert.cost;\n\n\treturn params;\n}\n\n/**\n * Write a REQUEST_UPDATE's parameters: only what changed, and a cost of 0 explicitly,\n * since an omitted parameter keeps its value.\n *\n * @internal\n */\nexport function updateIntoParams(update: Update): Parameters {\n\tconst params = new Parameters();\n\tif (update.hops !== undefined) params.hopPath = encodeHops(update.hops);\n\tif (update.cost !== undefined) params.routeCost = update.cost;\n\treturn params;\n}\n\n/** Write a HOP_PATH value: the entries fill it with no count of their own, framed by the\n * parameter's own length prefix. */\nfunction encodeHops(hops: Hop[]): Uint8Array {\n\tvalidate(hops);\n\n\tconst encoded = hops.map((hop) => Varint.encodeLeadingOnes(hop));\n\tconst value = new Uint8Array(encoded.reduce((total, hop) => total + hop.length, 0));\n\tlet offset = 0;\n\tfor (const hop of encoded) {\n\t\tvalue.set(hop, offset);\n\t\toffset += hop.length;\n\t}\n\treturn value;\n}\n\n/**\n * Read the parameters a negotiated session puts on every advertisement.\n *\n * The parameter block is mandatory there, so a message that ends before it (the base form)\n * or one whose block does not parse is the peer's violation, same as a block that parses but\n * carries no HOP_PATH.\n *\n * @internal\n */\nexport async function decodeParams(r: Reader, version: IetfVersion): Promise<Advert> {\n\tlet params: Parameters;\n\ttry {\n\t\tparams = await Parameters.decode(r, version);\n\t} catch (err) {\n\t\tthrow new ProtocolViolation(reason(err), { cause: err });\n\t}\n\n\treturn fromParams(params);\n}\n\n/**\n * Read an advertisement out of a decoded parameter block.\n *\n * Every way this fails is one the draft says to close the session over: a negotiated session\n * that omits HOP_PATH, entries that do not exactly fill the parameter, an empty list, or a\n * non-zero Hop ID appearing twice. So they all surface as one {@link ProtocolViolation},\n * which the session dispatch acts on.\n *\n * @internal\n */\nexport function fromParams(params: Parameters): Advert {\n\ttry {\n\t\tconst value = params.hopPath;\n\t\tif (value === undefined) throw new Error(\"advertisement is missing HOP_PATH\");\n\t\treturn { hops: decodeHops(value), cost: params.routeCost ?? 0n };\n\t} catch (err) {\n\t\tthrow new ProtocolViolation(reason(err), { cause: err });\n\t}\n}\n\n/**\n * Read a REQUEST_UPDATE's parameters: each is optional, and a malformed HOP_PATH is the\n * same violation it is on an advertisement.\n *\n * @internal\n */\nexport function updateFromParams(params: Parameters): Update {\n\ttry {\n\t\tconst value = params.hopPath;\n\t\treturn { hops: value === undefined ? undefined : decodeHops(value), cost: params.routeCost };\n\t} catch (err) {\n\t\tthrow new ProtocolViolation(reason(err), { cause: err });\n\t}\n}\n\n/**\n * The advertisement after `update` lands on `held`: an omitted parameter keeps its value.\n *\n * @internal\n */\nexport function apply(held: Advert, update: Update): Advert {\n\treturn { hops: update.hops ?? held.hops, cost: update.cost ?? held.cost };\n}\n\n/** Read a HOP_PATH value: bare varints filling the parameter, with no count of their own. */\nfunction decodeHops(value: Uint8Array): Hop[] {\n\tconst hops: Hop[] = [];\n\tlet rest = value;\n\twhile (rest.length > 0) {\n\t\t// A short read here means the entries did not exactly fill the length.\n\t\tconst [hop, remain] = Varint.decodeLeadingOnes(rest);\n\t\thops.push(HopSchema.parse(hop));\n\t\trest = remain;\n\n\t\t// Bail before the buffer does: a hostile length would otherwise cost us one\n\t\t// allocation per entry all the way to 64KB of parameter value.\n\t\tif (hops.length > MAX_HOPS) throw new Error(`hop count exceeds maximum ${MAX_HOPS}`);\n\t}\n\n\tvalidate(hops);\n\treturn hops;\n}\n\n/**\n * Reject a path that cannot have come from a conforming sender: an empty list, one longer\n * than we accept, or a non-zero Hop ID appearing twice (a loop). Duplicate zeros are legal,\n * since 0 identifies nothing.\n */\nfunction validate(hops: Hop[]) {\n\tif (hops.length === 0) throw new Error(\"hop path is empty\");\n\tif (hops.length > MAX_HOPS) throw new Error(`hop count ${hops.length} exceeds maximum ${MAX_HOPS}`);\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) throw new Error(`hop ${hop} appears twice in the hop path`);\n\t}\n}\n"]}
@@ -1,13 +1,9 @@
1
1
  import { type Getter } from "@moq/signals";
2
- import * as announce from "../announced";
3
- import type * as broadcast from "../broadcast";
2
+ import type * as announce from "../announced";
4
3
  import type { Established } from "../connection/established";
5
4
  import { type Probe, type Stats } from "../connection/stats";
6
5
  import { type Transport } from "../connection/transport";
7
- import * as Path from "../path";
8
- import { type Stream } from "../stream";
9
- import * as Cluster from "./cluster";
10
- import { type IetfVersion } from "./version";
6
+ import type * as Path from "../path";
11
7
  /**
12
8
  * Represents a connection to a MoQ server using moq-transport protocol.
13
9
  *
@@ -22,77 +18,15 @@ export declare class Connection implements Established {
22
18
  readonly discovery: boolean;
23
19
  /** moq-transport has no PROBE, so this stays empty; see {@link Established.probe}. */
24
20
  readonly probe: Getter<Probe>;
25
- /**
26
- * Creates a new Connection instance.
27
- * @param url - The URL of the connection
28
- * @param quic - The WebTransport session
29
- * @param control - The control/setup stream
30
- * @param maxRequestId - The initial max request ID
31
- * @param version - The negotiated protocol version
32
- * @param solicit - What the peer's SETUP declared (undefined when it declared nothing)
33
- * @param cluster - The Hop IDs the SETUP exchange settled, on the versions that negotiate them
34
- *
35
- * @internal
36
- */
37
- constructor({ url, quic, control, maxRequestId, version, client, discovery, solicit, cluster, }: {
38
- url: URL;
39
- quic: WebTransport;
40
- control: Stream;
41
- maxRequestId: bigint;
42
- version: IetfVersion;
43
- /** Whether this peer initiated the session, selecting the even request-ID space. */
44
- client: boolean;
45
- discovery?: boolean;
46
- /**
47
- * What the peer declared about being solicited. `undefined` means it declared
48
- * nothing, which is the one case where announcing at us unasked is not a bug.
49
- */
50
- solicit?: boolean;
51
- /**
52
- * The Hop IDs this session declared (MoQ Cluster). `undefined` on a version that
53
- * cannot negotiate the extension, as is a `peer` the peer never declared.
54
- */
55
- cluster?: Cluster.Hops;
56
- });
57
21
  /** Snapshot the transport's counters; see {@link Established.stats}. */
58
22
  stats(): Promise<Stats>;
59
23
  /**
60
24
  * Closes the connection.
61
25
  */
62
26
  close(): void;
63
- /**
64
- * Publishes a broadcast to the connection.
65
- * @param name - The broadcast path to publish
66
- * @param broadcast - The broadcast to publish
67
- */
68
- publish(path: Path.Valid, producer: broadcast.Producer): void;
69
- /**
70
- * Gets an announced reader for the specified prefix.
71
- * @param prefix - The prefix for announcements
72
- * @returns An Announced instance
73
- */
74
- announced(prefix?: Path.Valid): announce.Consumer;
75
- /**
76
- * Consumes a broadcast from the connection.
77
- *
78
- * @remarks
79
- * If the broadcast is not found, a "not found" error will be thrown when requesting any tracks.
80
- *
81
- * @param broadcast - The path of the broadcast to consume
82
- * @returns A Broadcast instance
83
- */
84
- consume(path: Path.Valid): broadcast.Consumer;
85
- /**
86
- * Watches a broadcast, live only while it is announced.
87
- *
88
- * @param path - The path of the broadcast to watch
89
- * @returns A reactive handle to the broadcast
90
- */
91
- announcedBroadcast(path: Path.Valid): announce.Broadcast;
92
- /**
93
- * Returns a promise that resolves when the connection is closed.
94
- * @returns A promise that resolves when closed
95
- */
96
- get closed(): Promise<void>;
27
+ /** Gets an announced reader for `scope`; see {@link Established.announced}. */
28
+ announced(scope?: Path.Pattern): announce.Consumer;
29
+ /** Resolves when the session closes, decoding the peer's close code; see {@link Established.closed}. */
30
+ get closed(): Promise<Error | null>;
97
31
  }
98
32
  //# sourceMappingURL=connection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/ietf/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAU,MAAM,cAAc,CAAC;AACnD,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,KAAK,KAAK,EAAE,KAAK,KAAK,EAAkB,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAAE,KAAK,SAAS,EAAe,MAAM,4BAA4B,CAAC;AAEzE,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAwB,KAAK,MAAM,EAAE,MAAM,cAAc,CAAC;AAEjE,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AAUxC,OAAO,EAAE,KAAK,WAAW,EAAwB,MAAM,cAAc,CAAC;AAEtE;;;;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;IAE5B,sFAAsF;IACtF,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,CAAyB;IAuBtD;;;;;;;;;;;OAWG;IACH,YAAY,EACX,GAAG,EACH,IAAI,EACJ,OAAO,EACP,YAAY,EACZ,OAAO,EACP,MAAM,EACN,SAAgB,EAChB,OAAO,EACP,OAAO,G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O,EAAE,KAAK,SAAS,EAAe,MAAM,4BAA4B,CAAC;AAGzE,OAAO,KAAK,KAAK,IAAI,MAAM,YAAY,CAAC;AAgBxC;;;;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;IAE5B,sFAAsF;IACtF,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,CAAyB;IAwGtD,wEAAwE;IAClE,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC,CAE5B;IAED;;OAEG;IACH,KAAK,SAYJ;IAcD,+EAA+E;IAC/E,SAAS,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC,QAAQ,CAEjD;IAuJD,wGAAwG;IACxG,IAAI,MAAM,IAAI,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,CAElC;CACD"}
@@ -1,11 +1,10 @@
1
1
  /* @ts-self-types="./connection.d.ts" */
2
2
  import { Signal } from "@moq/signals";
3
- import * as announce from "../announced.js";
4
3
  import { transportStats } from "../connection/stats.js";
5
4
  import { transportOf } from "../connection/transport.js";
6
- import { ProtocolViolation } from "../error.js";
7
- import * as Path from "../path.js";
5
+ import { error, fromClose, ProtocolViolation, StreamCode, StreamError } from "../error.js";
8
6
  import { Readers } from "../stream.js";
7
+ import { registerWire } from "../wire.js";
9
8
  import { ControlStreamAdapter, NativeSession } from "./adapter.js";
10
9
  import * as Cluster from "./cluster.js";
11
10
  import { GoAway } from "./goaway.js";
@@ -60,7 +59,7 @@ export class Connection {
60
59
  *
61
60
  * @internal
62
61
  */
63
- constructor({ url, quic, control, maxRequestId, version, client, discovery = true, solicit, cluster, }) {
62
+ constructor({ url, quic, control, maxRequestId, version, client, discovery = true, publish, solicit, cluster, }) {
64
63
  this.url = url;
65
64
  this.discovery = discovery;
66
65
  this.version = versionName(version);
@@ -85,12 +84,14 @@ export class Connection {
85
84
  this.#publisher = new Publisher({
86
85
  quic: this.#quic,
87
86
  session: this.#session,
87
+ publish,
88
88
  requiresSolicitation: solicit ?? false,
89
89
  cluster,
90
90
  });
91
91
  this.#solicit = solicit;
92
92
  this.#cluster = cluster;
93
93
  this.#subscriber = new Subscriber({ session: this.#session, cluster });
94
+ registerWire(this, { consume: (path) => this.#subscriber.consume(path) });
94
95
  void this.#run();
95
96
  }
96
97
  /** Snapshot the transport's counters; see {@link Established.stats}. */
@@ -104,7 +105,6 @@ export class Connection {
104
105
  if (this.#closed)
105
106
  return;
106
107
  this.#closed = true;
107
- this.#publisher.close();
108
108
  this.#session.close();
109
109
  try {
110
110
  this.#quic.close();
@@ -126,42 +126,9 @@ export class Connection {
126
126
  this.close();
127
127
  }
128
128
  }
129
- /**
130
- * Publishes a broadcast to the connection.
131
- * @param name - The broadcast path to publish
132
- * @param broadcast - The broadcast to publish
133
- */
134
- publish(path, producer) {
135
- this.#publisher.publish(path, producer);
136
- }
137
- /**
138
- * Gets an announced reader for the specified prefix.
139
- * @param prefix - The prefix for announcements
140
- * @returns An Announced instance
141
- */
142
- announced(prefix = Path.empty()) {
143
- return this.#subscriber.announced(prefix);
144
- }
145
- /**
146
- * Consumes a broadcast from the connection.
147
- *
148
- * @remarks
149
- * If the broadcast is not found, a "not found" error will be thrown when requesting any tracks.
150
- *
151
- * @param broadcast - The path of the broadcast to consume
152
- * @returns A Broadcast instance
153
- */
154
- consume(path) {
155
- return this.#subscriber.consume(path);
156
- }
157
- /**
158
- * Watches a broadcast, live only while it is announced.
159
- *
160
- * @param path - The path of the broadcast to watch
161
- * @returns A reactive handle to the broadcast
162
- */
163
- announcedBroadcast(path) {
164
- return new announce.Broadcast({ connection: this, path });
129
+ /** Gets an announced reader for `scope`; see {@link Established.announced}. */
130
+ announced(scope) {
131
+ return this.#subscriber.announced(scope);
165
132
  }
166
133
  /**
167
134
  * Accepts bidi streams (virtual for v14-v16, real for v17) and dispatches.
@@ -260,7 +227,7 @@ export class Connection {
260
227
  break;
261
228
  this.#runUni(stream)
262
229
  .then(() => {
263
- stream.stop(new Error("cancel"));
230
+ stream.stop(new StreamError(StreamCode.Cancel, { message: "cancel" }));
264
231
  })
265
232
  .catch((err) => {
266
233
  console.error("error processing object stream", err);
@@ -298,12 +265,9 @@ export class Connection {
298
265
  this.close();
299
266
  }
300
267
  }
301
- /**
302
- * Returns a promise that resolves when the connection is closed.
303
- * @returns A promise that resolves when closed
304
- */
268
+ /** Resolves when the session closes, decoding the peer's close code; see {@link Established.closed}. */
305
269
  get closed() {
306
- return this.#quic.closed.then(() => undefined);
270
+ return this.#quic.closed.then(fromClose, (err) => error(err));
307
271
  }
308
272
  }
309
273
  //# sourceMappingURL=connection.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/ietf/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,MAAM,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAG5C,OAAO,EAA0B,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAAkB,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAe,OAAO,EAAe,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAgB,MAAM,cAAc,CAAC;AACjF,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,C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OAAO,CAAC,IAAI,CAAC,sCAAsC,GAAG,CAAC,aAAa,EAAE,CAAC,CAAC;YACzE,CAAC;iBAAM,CAAC;gBACP,OAAO,CAAC,IAAI,CAAC,yCAAyC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;YAC9E,CAAC;QACF,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACd,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;gBACnB,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,GAAG,CAAC,CAAC;YAClD,CAAC;QACF,CAAC;gBAAS,CAAC;YACV,IAAI,CAAC,KAAK,EAAE,CAAC;QACd,CAAC;IACF,CAAC;IAED;;;OAGG;IACH,IAAI,MAAM;QACT,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IAChD,CAAC;CACD","sourcesContent":["import { type Getter, Signal } from \"@moq/signals\";\nimport * as announce from \"../announced.ts\";\nimport type * as broadcast from \"../broadcast.ts\";\nimport type { Established } from \"../connection/established.ts\";\nimport { type Probe, type Stats, transportStats } from \"../connection/stats.ts\";\nimport { type Transport, transportOf } from \"../connection/transport.ts\";\nimport { ProtocolViolation } from \"../error.ts\";\nimport * as Path from \"../path.ts\";\nimport { type Reader, Readers, type Stream } from \"../stream.ts\";\nimport { ControlStreamAdapter, NativeSession, type Session } from \"./adapter.ts\";\nimport * as Cluster from \"./cluster.ts\";\nimport { GoAway } from \"./goaway.ts\";\nimport { Group } from \"./object.ts\";\nimport { Publish } from \"./publish.ts\";\nimport { PublishNamespace } from \"./publish_namespace.ts\";\nimport { Publisher } from \"./publisher.ts\";\nimport { Subscribe, SubscribeUpdate } from \"./subscribe.ts\";\nimport { SubscribeNamespace, SubscribeNamespaceLegacy } from \"./subscribe_namespace.ts\";\nimport { Subscriber } from \"./subscriber.ts\";\nimport { TrackStatusRequest } from \"./track.ts\";\nimport { type IetfVersion, Version, versionName } from \"./version.ts\";\n\n/**\n * Represents a connection to a MoQ server using moq-transport protocol.\n *\n * @public\n */\nexport class Connection implements Established {\n\t// The URL of the connection.\n\treadonly url: URL;\n\n\t// The negotiated protocol version.\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/** moq-transport has no PROBE, so this stays empty; see {@link Established.probe}. */\n\treadonly probe: Getter<Probe> = new Signal<Probe>({});\n\n\t// The established WebTransport session.\n\t#quic: WebTransport;\n\n\t// Session abstraction: adapter for v14-v16, native for v17.\n\t#session: Session;\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// What the peer declared about being solicited; see {@link Ietf.solicitFromSetup}.\n\t#solicit: boolean | undefined;\n\n\t// The Hop IDs this session declared; see {@link Cluster}.\n\t#cluster?: Cluster.Hops;\n\n\t// Just to avoid logging when `close()` is called.\n\t#closed = false;\n\n\t/**\n\t * Creates a new Connection instance.\n\t * @param url - The URL of the connection\n\t * @param quic - The WebTransport session\n\t * @param control - The control/setup stream\n\t * @param maxRequestId - The initial max request ID\n\t * @param version - The negotiated protocol version\n\t * @param solicit - What the peer's SETUP declared (undefined when it declared nothing)\n\t * @param cluster - The Hop IDs the SETUP exchange settled, on the versions that negotiate them\n\t *\n\t * @internal\n\t */\n\tconstructor({\n\t\turl,\n\t\tquic,\n\t\tcontrol,\n\t\tmaxRequestId,\n\t\tversion,\n\t\tclient,\n\t\tdiscovery = true,\n\t\tsolicit,\n\t\tcluster,\n\t}: {\n\t\turl: URL;\n\t\tquic: WebTransport;\n\t\tcontrol: Stream;\n\t\tmaxRequestId: bigint;\n\t\tversion: IetfVersion;\n\t\t/** Whether this peer initiated the session, selecting the even request-ID space. */\n\t\tclient: boolean;\n\t\tdiscovery?: boolean;\n\t\t/**\n\t\t * What the peer declared about being solicited. `undefined` means it declared\n\t\t * nothing, which is the one case where announcing at us unasked is not a bug.\n\t\t */\n\t\tsolicit?: boolean;\n\t\t/**\n\t\t * The Hop IDs this session declared (MoQ Cluster). `undefined` on a version that\n\t\t * cannot negotiate the extension, as is a `peer` the peer never declared.\n\t\t */\n\t\tcluster?: Cluster.Hops;\n\t}) {\n\t\tthis.url = url;\n\t\tthis.discovery = discovery;\n\t\tthis.version = versionName(version);\n\t\tthis.transport = transportOf(quic);\n\t\tthis.#quic = quic;\n\n\t\t// Two-path dispatch: v14-v16 uses adapter, v17+ uses native bidi streams\n\t\tif (version >= Version.DRAFT_17) {\n\t\t\tthis.#session = new NativeSession(quic, version, client);\n\t\t\t// v17+: control/setup stream only carries GoAway\n\t\t\tvoid this.#runGoAway(control, version);\n\t\t} else {\n\t\t\tconst adapter = new ControlStreamAdapter(quic, control, version, maxRequestId, client);\n\t\t\tthis.#session = adapter;\n\t\t\t// Start the adapter read loop (routes control messages to virtual streams)\n\t\t\tvoid adapter.run().catch((err: unknown) => {\n\t\t\t\tif (!this.#closed) console.error(\"adapter error\", err);\n\t\t\t\tthis.close();\n\t\t\t});\n\t\t}\n\n\t\tthis.#publisher = new Publisher({\n\t\t\tquic: this.#quic,\n\t\t\tsession: this.#session,\n\t\t\trequiresSolicitation: solicit ?? false,\n\t\t\tcluster,\n\t\t});\n\t\tthis.#solicit = solicit;\n\t\tthis.#cluster = cluster;\n\t\tthis.#subscriber = new Subscriber({ session: this.#session, cluster });\n\n\t\tvoid this.#run();\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/**\n\t * Closes the connection.\n\t */\n\tclose() {\n\t\tif (this.#closed) return;\n\n\t\tthis.#closed = true;\n\n\t\tthis.#publisher.close();\n\t\tthis.#session.close();\n\n\t\ttry {\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\ttry {\n\t\t\tawait Promise.all([this.#runBidis(), this.#runUnis(), this.#publisher.runPublishNamespaces()]);\n\t\t} catch (err) {\n\t\t\tif (!this.#closed) {\n\t\t\t\tconsole.error(\"fatal error running connection\", err);\n\t\t\t}\n\t\t} finally {\n\t\t\tthis.close();\n\t\t}\n\t}\n\n\t/**\n\t * Publishes a broadcast to the connection.\n\t * @param name - The broadcast path to publish\n\t * @param broadcast - The broadcast to publish\n\t */\n\tpublish(path: Path.Valid, producer: broadcast.Producer) {\n\t\tthis.#publisher.publish(path, producer);\n\t}\n\n\t/**\n\t * Gets an announced reader for the specified prefix.\n\t * @param prefix - The prefix for announcements\n\t * @returns An Announced instance\n\t */\n\tannounced(prefix = Path.empty()): announce.Consumer {\n\t\treturn this.#subscriber.announced(prefix);\n\t}\n\n\t/**\n\t * Consumes a broadcast from the connection.\n\t *\n\t * @remarks\n\t * If the broadcast is not found, a \"not found\" error will be thrown when requesting any tracks.\n\t *\n\t * @param broadcast - The path of the broadcast to consume\n\t * @returns A Broadcast instance\n\t */\n\tconsume(path: Path.Valid): broadcast.Consumer {\n\t\treturn this.#subscriber.consume(path);\n\t}\n\n\t/**\n\t * Watches a broadcast, live only while it is announced.\n\t *\n\t * @param path - The path of the broadcast to watch\n\t * @returns A reactive handle to the broadcast\n\t */\n\tannouncedBroadcast(path: Path.Valid): announce.Broadcast {\n\t\treturn new announce.Broadcast({ connection: this, path });\n\t}\n\n\t/**\n\t * Accepts bidi streams (virtual for v14-v16, real for v17) and dispatches.\n\t */\n\tasync #runBidis() {\n\t\tfor (;;) {\n\t\t\tconst stream = await this.#session.acceptBi();\n\t\t\tif (!stream) break;\n\n\t\t\tvoid this.#runBidi(stream).catch((err: unknown) => {\n\t\t\t\tconsole.error(\"error processing bidi stream\", err);\n\t\t\t\tstream.abort(new Error(\"bidi stream error\"));\n\n\t\t\t\t// The peer broke the protocol, so losing the stream is not enough: nothing\n\t\t\t\t// stops it repeating the violation on the next one.\n\t\t\t\tif (err instanceof ProtocolViolation) this.close();\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Unified bidi stream dispatch. Reads typeId and routes to handler.\n\t * Matches the lite module's runBidi pattern.\n\t */\n\tasync #runBidi(stream: Stream) {\n\t\tconst typeId = await stream.reader.u53();\n\n\t\tswitch (typeId) {\n\t\t\t// Draft-18 SUBSCRIBE_NAMESPACE (0x50) and the legacy 0x11 message decode\n\t\t\t// to the same request_id + namespace; the legacy options field is ignored.\n\t\t\tcase SubscribeNamespace.id: {\n\t\t\t\tconst msg = await SubscribeNamespace.decode(stream.reader, this.#session.version);\n\t\t\t\tawait this.#publisher.runSubscribeNamespace(msg, stream);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SubscribeNamespaceLegacy.id: {\n\t\t\t\tconst legacy = await SubscribeNamespaceLegacy.decode(stream.reader, this.#session.version);\n\t\t\t\tconst msg = new SubscribeNamespace({ requestId: legacy.requestId, namespace: legacy.namespace });\n\t\t\t\tawait this.#publisher.runSubscribeNamespace(msg, stream);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SubscribeUpdate.id: {\n\t\t\t\t// REQUEST_UPDATE (0x02) is a follow-up, not a valid initial message\n\t\t\t\tstream.abort(new Error(\"unexpected REQUEST_UPDATE as initial message\"));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t// Publisher handles incoming requests\n\t\t\tcase Subscribe.id: {\n\t\t\t\tconst msg = await Subscribe.decode(stream.reader, this.#session.version);\n\t\t\t\tawait this.#publisher.runSubscribe(msg, stream);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase TrackStatusRequest.id: {\n\t\t\t\tconst msg = await TrackStatusRequest.decode(stream.reader, this.#session.version);\n\t\t\t\tawait this.#publisher.runTrackStatusRequest(msg, stream);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\t// Subscriber handles incoming notifications\n\t\t\tcase PublishNamespace.id: {\n\t\t\t\tconst msg = await PublishNamespace.decode(\n\t\t\t\t\tstream.reader,\n\t\t\t\t\tthis.#session.version,\n\t\t\t\t\tCluster.negotiated(this.#cluster),\n\t\t\t\t);\n\n\t\t\t\t// We always declare that advertisements to us must be solicited (MoQ\n\t\t\t\t// Solicit), and writing the option at all proves the peer implements the\n\t\t\t\t// extension, whichever value it chose. It also cannot have advertised\n\t\t\t\t// before reading our SETUP, since our SETUP is what says whether\n\t\t\t\t// advertising unasked is allowed. So this is a bug in the peer, and a\n\t\t\t\t// silent one on both sides if we tolerate it.\n\t\t\t\t//\n\t\t\t\t// Draft-14/15 are exempt: they have no inline NAMESPACE, so a\n\t\t\t\t// PUBLISH_NAMESPACE request is also how a peer answers our\n\t\t\t\t// SUBSCRIBE_NAMESPACE there, and the message alone does not say which.\n\t\t\t\tconst legacy = this.#session.version === Version.DRAFT_14 || this.#session.version === Version.DRAFT_15;\n\t\t\t\tif (this.#solicit !== undefined && !legacy) {\n\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t`unsolicited publish_namespace from a peer that implements MoQ Solicit: broadcast=${msg.trackNamespace}`,\n\t\t\t\t\t);\n\t\t\t\t\tthis.close();\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tawait this.#subscriber.runPublishNamespace(msg, stream);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase Publish.id: {\n\t\t\t\tconst msg = await Publish.decode(stream.reader, this.#session.version);\n\t\t\t\tawait this.#subscriber.runPublish(msg, stream);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault:\n\t\t\t\tconsole.warn(`unexpected bidi stream type: 0x${typeId.toString(16)}`);\n\t\t\t\tstream.abort(new Error(\"unexpected stream type\"));\n\t\t}\n\t}\n\n\t/**\n\t * Handles unidirectional streams for media delivery (groups).\n\t */\n\tasync #runUnis() {\n\t\tconst readers = new Readers(this.#quic, this.#session.version);\n\n\t\tfor (;;) {\n\t\t\tconst stream = await readers.next();\n\t\t\tif (!stream) break;\n\n\t\t\tthis.#runUni(stream)\n\t\t\t\t.then(() => {\n\t\t\t\t\tstream.stop(new Error(\"cancel\"));\n\t\t\t\t})\n\t\t\t\t.catch((err: unknown) => {\n\t\t\t\t\tconsole.error(\"error processing object stream\", err);\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 header = await Group.decode(stream, this.#session.version);\n\t\tawait this.#subscriber.handleGroup(header, stream);\n\t}\n\n\t/**\n\t * v17+ only: reads GoAway from the setup/control stream.\n\t */\n\tasync #runGoAway(controlStream: Stream, version: IetfVersion) {\n\t\ttry {\n\t\t\tconst done = await controlStream.reader.done();\n\t\t\tif (done) return;\n\n\t\t\tconst typeId = await controlStream.reader.u53();\n\t\t\tif (typeId === GoAway.id) {\n\t\t\t\tconst msg = await GoAway.decode(controlStream.reader, version);\n\t\t\t\tconsole.warn(`received GOAWAY with redirect URI: ${msg.newSessionUri}`);\n\t\t\t} else {\n\t\t\t\tconsole.warn(`unexpected message on setup stream: 0x${typeId.toString(16)}`);\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tif (!this.#closed) {\n\t\t\t\tconsole.error(\"error reading setup stream\", err);\n\t\t\t}\n\t\t} finally {\n\t\t\tthis.close();\n\t\t}\n\t}\n\n\t/**\n\t * Returns a promise that resolves when the connection is closed.\n\t * @returns A promise that resolves when closed\n\t */\n\tget closed(): Promise<void> {\n\t\treturn this.#quic.closed.then(() => undefined);\n\t}\n}\n"]}
1
+ {"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/ietf/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,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,UAAU,EAAE,WAAW,EAAE,M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,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAC/D,OAAO,CAAC,IAAI,CAAC,sCAAsC,GAAG,CAAC,aAAa,EAAE,CAAC,CAAC;YACzE,CAAC;iBAAM,CAAC;gBACP,OAAO,CAAC,IAAI,CAAC,yCAAyC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;YAC9E,CAAC;QACF,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACd,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;gBACnB,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,GAAG,CAAC,CAAC;YAClD,CAAC;QACF,CAAC;gBAAS,CAAC;YACV,IAAI,CAAC,KAAK,EAAE,CAAC;QACd,CAAC;IACF,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","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 { error, fromClose, ProtocolViolation, StreamCode, StreamError } from \"../error.ts\";\nimport type { Consumer as OriginConsumer } from \"../origin.ts\";\nimport type * as Path from \"../path.ts\";\nimport { type Reader, Readers, type Stream } from \"../stream.ts\";\nimport { registerWire } from \"../wire.ts\";\nimport { ControlStreamAdapter, NativeSession, type Session } from \"./adapter.ts\";\nimport * as Cluster from \"./cluster.ts\";\nimport { GoAway } from \"./goaway.ts\";\nimport { Group } from \"./object.ts\";\nimport { Publish } from \"./publish.ts\";\nimport { PublishNamespace } from \"./publish_namespace.ts\";\nimport { Publisher } from \"./publisher.ts\";\nimport { Subscribe, SubscribeUpdate } from \"./subscribe.ts\";\nimport { SubscribeNamespace, SubscribeNamespaceLegacy } from \"./subscribe_namespace.ts\";\nimport { Subscriber } from \"./subscriber.ts\";\nimport { TrackStatusRequest } from \"./track.ts\";\nimport { type IetfVersion, Version, versionName } from \"./version.ts\";\n\n/**\n * Represents a connection to a MoQ server using moq-transport protocol.\n *\n * @public\n */\nexport class Connection implements Established {\n\t// The URL of the connection.\n\treadonly url: URL;\n\n\t// The negotiated protocol version.\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/** moq-transport has no PROBE, so this stays empty; see {@link Established.probe}. */\n\treadonly probe: Getter<Probe> = new Signal<Probe>({});\n\n\t// The established WebTransport session.\n\t#quic: WebTransport;\n\n\t// Session abstraction: adapter for v14-v16, native for v17.\n\t#session: Session;\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// What the peer declared about being solicited; see {@link Ietf.solicitFromSetup}.\n\t#solicit: boolean | undefined;\n\n\t// The Hop IDs this session declared; see {@link Cluster}.\n\t#cluster?: Cluster.Hops;\n\n\t// Just to avoid logging when `close()` is called.\n\t#closed = false;\n\n\t/**\n\t * Creates a new Connection instance.\n\t * @param url - The URL of the connection\n\t * @param quic - The WebTransport session\n\t * @param control - The control/setup stream\n\t * @param maxRequestId - The initial max request ID\n\t * @param version - The negotiated protocol version\n\t * @param solicit - What the peer's SETUP declared (undefined when it declared nothing)\n\t * @param cluster - The Hop IDs the SETUP exchange settled, on the versions that negotiate them\n\t *\n\t * @internal\n\t */\n\tconstructor({\n\t\turl,\n\t\tquic,\n\t\tcontrol,\n\t\tmaxRequestId,\n\t\tversion,\n\t\tclient,\n\t\tdiscovery = true,\n\t\tpublish,\n\t\tsolicit,\n\t\tcluster,\n\t}: {\n\t\turl: URL;\n\t\tquic: WebTransport;\n\t\tcontrol: Stream;\n\t\tmaxRequestId: bigint;\n\t\tversion: IetfVersion;\n\t\t/** Whether this peer initiated the session, selecting the even request-ID space. */\n\t\tclient: boolean;\n\t\tdiscovery?: boolean;\n\t\t/** The origin whose broadcasts are served to the peer. Omit to publish nothing. */\n\t\tpublish?: OriginConsumer;\n\t\t/**\n\t\t * What the peer declared about being solicited. `undefined` means it declared\n\t\t * nothing, which is the one case where announcing at us unasked is not a bug.\n\t\t */\n\t\tsolicit?: boolean;\n\t\t/**\n\t\t * The Hop IDs this session declared (MoQ Cluster). `undefined` on a version that\n\t\t * cannot negotiate the extension, as is a `peer` the peer never declared.\n\t\t */\n\t\tcluster?: Cluster.Hops;\n\t}) {\n\t\tthis.url = url;\n\t\tthis.discovery = discovery;\n\t\tthis.version = versionName(version);\n\t\tthis.transport = transportOf(quic);\n\t\tthis.#quic = quic;\n\n\t\t// Two-path dispatch: v14-v16 uses adapter, v17+ uses native bidi streams\n\t\tif (version >= Version.DRAFT_17) {\n\t\t\tthis.#session = new NativeSession(quic, version, client);\n\t\t\t// v17+: control/setup stream only carries GoAway\n\t\t\tvoid this.#runGoAway(control, version);\n\t\t} else {\n\t\t\tconst adapter = new ControlStreamAdapter(quic, control, version, maxRequestId, client);\n\t\t\tthis.#session = adapter;\n\t\t\t// Start the adapter read loop (routes control messages to virtual streams)\n\t\t\tvoid adapter.run().catch((err: unknown) => {\n\t\t\t\tif (!this.#closed) console.error(\"adapter error\", err);\n\t\t\t\tthis.close();\n\t\t\t});\n\t\t}\n\n\t\tthis.#publisher = new Publisher({\n\t\t\tquic: this.#quic,\n\t\t\tsession: this.#session,\n\t\t\tpublish,\n\t\t\trequiresSolicitation: solicit ?? false,\n\t\t\tcluster,\n\t\t});\n\t\tthis.#solicit = solicit;\n\t\tthis.#cluster = cluster;\n\t\tthis.#subscriber = new Subscriber({ session: this.#session, cluster });\n\t\tregisterWire(this, { consume: (path) => this.#subscriber.consume(path) });\n\n\t\tvoid this.#run();\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/**\n\t * Closes the connection.\n\t */\n\tclose() {\n\t\tif (this.#closed) return;\n\n\t\tthis.#closed = true;\n\n\t\tthis.#session.close();\n\n\t\ttry {\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\ttry {\n\t\t\tawait Promise.all([this.#runBidis(), this.#runUnis(), this.#publisher.runPublishNamespaces()]);\n\t\t} catch (err) {\n\t\t\tif (!this.#closed) {\n\t\t\t\tconsole.error(\"fatal error running connection\", err);\n\t\t\t}\n\t\t} finally {\n\t\t\tthis.close();\n\t\t}\n\t}\n\n\t/** Gets an announced reader for `scope`; see {@link Established.announced}. */\n\tannounced(scope?: Path.Pattern): announce.Consumer {\n\t\treturn this.#subscriber.announced(scope);\n\t}\n\n\t/**\n\t * Accepts bidi streams (virtual for v14-v16, real for v17) and dispatches.\n\t */\n\tasync #runBidis() {\n\t\tfor (;;) {\n\t\t\tconst stream = await this.#session.acceptBi();\n\t\t\tif (!stream) break;\n\n\t\t\tvoid this.#runBidi(stream).catch((err: unknown) => {\n\t\t\t\tconsole.error(\"error processing bidi stream\", err);\n\t\t\t\tstream.abort(new Error(\"bidi stream error\"));\n\n\t\t\t\t// The peer broke the protocol, so losing the stream is not enough: nothing\n\t\t\t\t// stops it repeating the violation on the next one.\n\t\t\t\tif (err instanceof ProtocolViolation) this.close();\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Unified bidi stream dispatch. Reads typeId and routes to handler.\n\t * Matches the lite module's runBidi pattern.\n\t */\n\tasync #runBidi(stream: Stream) {\n\t\tconst typeId = await stream.reader.u53();\n\n\t\tswitch (typeId) {\n\t\t\t// Draft-18 SUBSCRIBE_NAMESPACE (0x50) and the legacy 0x11 message decode\n\t\t\t// to the same request_id + namespace; the legacy options field is ignored.\n\t\t\tcase SubscribeNamespace.id: {\n\t\t\t\tconst msg = await SubscribeNamespace.decode(stream.reader, this.#session.version);\n\t\t\t\tawait this.#publisher.runSubscribeNamespace(msg, stream);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SubscribeNamespaceLegacy.id: {\n\t\t\t\tconst legacy = await SubscribeNamespaceLegacy.decode(stream.reader, this.#session.version);\n\t\t\t\tconst msg = new SubscribeNamespace({ requestId: legacy.requestId, namespace: legacy.namespace });\n\t\t\t\tawait this.#publisher.runSubscribeNamespace(msg, stream);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SubscribeUpdate.id: {\n\t\t\t\t// REQUEST_UPDATE (0x02) is a follow-up, not a valid initial message\n\t\t\t\tstream.abort(new Error(\"unexpected REQUEST_UPDATE as initial message\"));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t// Publisher handles incoming requests\n\t\t\tcase Subscribe.id: {\n\t\t\t\tconst msg = await Subscribe.decode(stream.reader, this.#session.version);\n\t\t\t\tawait this.#publisher.runSubscribe(msg, stream);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase TrackStatusRequest.id: {\n\t\t\t\tconst msg = await TrackStatusRequest.decode(stream.reader, this.#session.version);\n\t\t\t\tawait this.#publisher.runTrackStatusRequest(msg, stream);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\t// Subscriber handles incoming notifications\n\t\t\tcase PublishNamespace.id: {\n\t\t\t\tconst msg = await PublishNamespace.decode(\n\t\t\t\t\tstream.reader,\n\t\t\t\t\tthis.#session.version,\n\t\t\t\t\tCluster.negotiated(this.#cluster),\n\t\t\t\t);\n\n\t\t\t\t// We always declare that advertisements to us must be solicited (MoQ\n\t\t\t\t// Solicit), and writing the option at all proves the peer implements the\n\t\t\t\t// extension, whichever value it chose. It also cannot have advertised\n\t\t\t\t// before reading our SETUP, since our SETUP is what says whether\n\t\t\t\t// advertising unasked is allowed. So this is a bug in the peer, and a\n\t\t\t\t// silent one on both sides if we tolerate it.\n\t\t\t\t//\n\t\t\t\t// Draft-14/15 are exempt: they have no inline NAMESPACE, so a\n\t\t\t\t// PUBLISH_NAMESPACE request is also how a peer answers our\n\t\t\t\t// SUBSCRIBE_NAMESPACE there, and the message alone does not say which.\n\t\t\t\tconst legacy = this.#session.version === Version.DRAFT_14 || this.#session.version === Version.DRAFT_15;\n\t\t\t\tif (this.#solicit !== undefined && !legacy) {\n\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t`unsolicited publish_namespace from a peer that implements MoQ Solicit: broadcast=${msg.trackNamespace}`,\n\t\t\t\t\t);\n\t\t\t\t\tthis.close();\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tawait this.#subscriber.runPublishNamespace(msg, stream);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase Publish.id: {\n\t\t\t\tconst msg = await Publish.decode(stream.reader, this.#session.version);\n\t\t\t\tawait this.#subscriber.runPublish(msg, stream);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault:\n\t\t\t\tconsole.warn(`unexpected bidi stream type: 0x${typeId.toString(16)}`);\n\t\t\t\tstream.abort(new Error(\"unexpected stream type\"));\n\t\t}\n\t}\n\n\t/**\n\t * Handles unidirectional streams for media delivery (groups).\n\t */\n\tasync #runUnis() {\n\t\tconst readers = new Readers(this.#quic, this.#session.version);\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\tconsole.error(\"error processing object stream\", err);\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 header = await Group.decode(stream, this.#session.version);\n\t\tawait this.#subscriber.handleGroup(header, stream);\n\t}\n\n\t/**\n\t * v17+ only: reads GoAway from the setup/control stream.\n\t */\n\tasync #runGoAway(controlStream: Stream, version: IetfVersion) {\n\t\ttry {\n\t\t\tconst done = await controlStream.reader.done();\n\t\t\tif (done) return;\n\n\t\t\tconst typeId = await controlStream.reader.u53();\n\t\t\tif (typeId === GoAway.id) {\n\t\t\t\tconst msg = await GoAway.decode(controlStream.reader, version);\n\t\t\t\tconsole.warn(`received GOAWAY with redirect URI: ${msg.newSessionUri}`);\n\t\t\t} else {\n\t\t\t\tconsole.warn(`unexpected message on setup stream: 0x${typeId.toString(16)}`);\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tif (!this.#closed) {\n\t\t\t\tconsole.error(\"error reading setup stream\", err);\n\t\t\t}\n\t\t} finally {\n\t\t\tthis.close();\n\t\t}\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"]}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The moq-transport error code registries, per negotiated draft.
3
+ *
4
+ * A code only means something once you know which draft carried it: the registries grew,
5
+ * moved values, and in draft-15 collapsed five per-message tables into one. Mirrors the
6
+ * Rust `moq_net::ietf::error` module, and the two have to agree value for value.
7
+ *
8
+ * @module
9
+ */
10
+ export {};
11
+ //# sourceMappingURL=error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/ietf/error.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG"}
package/ietf/error.js ADDED
@@ -0,0 +1,168 @@
1
+ /* @ts-self-types="./error.d.ts" */
2
+ /**
3
+ * The moq-transport error code registries, per negotiated draft.
4
+ *
5
+ * A code only means something once you know which draft carried it: the registries grew,
6
+ * moved values, and in draft-15 collapsed five per-message tables into one. Mirrors the
7
+ * Rust `moq_net::ietf::error` module, and the two have to agree value for value.
8
+ *
9
+ * @module
10
+ */
11
+ import { Version } from "./version.js";
12
+ /**
13
+ * Whether `code` means the same thing in the negotiated draft's stream reset registry as it
14
+ * does in moq-lite's.
15
+ *
16
+ * The two registries agree on most of what they both assign, but this one grew across the
17
+ * drafts we negotiate and moved a value on the way:
18
+ *
19
+ * | Code | draft-14/15 | draft-16/17 | draft-18+ |
20
+ * |------|-------------|-------------|-----------|
21
+ * | 0x0 | INTERNAL_ERROR | INTERNAL_ERROR | INTERNAL_ERROR |
22
+ * | 0x1 | CANCELLED | CANCELLED | CANCELLED |
23
+ * | 0x2 | DELIVERY_TIMEOUT | DELIVERY_TIMEOUT | DELIVERY_TIMEOUT |
24
+ * | 0x3 | SESSION_CLOSED | SESSION_CLOSED | SESSION_CLOSED |
25
+ * | 0x4 | - | UNKNOWN_OBJECT_STATUS | GOING_AWAY |
26
+ * | 0x5 | - | TOO_FAR_BEHIND (17) | TOO_FAR_BEHIND |
27
+ * | 0x12 | - | MALFORMED_TRACK | MALFORMED_TRACK |
28
+ *
29
+ * So GOING_AWAY sent to a draft-17 peer reads as UNKNOWN_OBJECT_STATUS, and that peer's
30
+ * UNKNOWN_OBJECT_STATUS read as GOING_AWAY would retire a session that is not going
31
+ * anywhere. Anything this says `false` about is sent as, and read as, INTERNAL_ERROR: the
32
+ * codes moq-lite assigns in its own 48-63 range, and the ones the draft assigns that
33
+ * moq-lite has no name for (UNKNOWN_OBJECT_STATUS, EXPIRED_AUTH_TOKEN, EXCESSIVE_LOAD).
34
+ *
35
+ * @internal
36
+ */
37
+ export function sharedStreamCode(code, version) {
38
+ switch (code) {
39
+ case 0x0:
40
+ case 0x1:
41
+ case 0x2:
42
+ case 0x3:
43
+ return true;
44
+ // Draft-16 and 17 give 0x4 to UNKNOWN_OBJECT_STATUS, which draft-18 moved to 0x6 when
45
+ // it took 0x4 for GOING_AWAY. Draft-14 and 15 assign it nothing.
46
+ case 0x4:
47
+ return version >= Version.DRAFT_18;
48
+ // TOO_FAR_BEHIND arrived in draft-17.
49
+ case 0x5:
50
+ return version >= Version.DRAFT_17;
51
+ // MALFORMED_TRACK arrived in draft-16.
52
+ case 0x12:
53
+ return version >= Version.DRAFT_16;
54
+ default:
55
+ return false;
56
+ }
57
+ }
58
+ /** An implementation-specific error. Assigned by every draft, for every request. */
59
+ const INTERNAL_ERROR = 0x0;
60
+ const UNAUTHORIZED = 0x1;
61
+ const TIMEOUT = 0x2;
62
+ const NOT_SUPPORTED = 0x3;
63
+ /** A draining session. Draft-17 and later. */
64
+ const GOING_AWAY = 0x6;
65
+ /** Draft-14 calls it TRACK_DOES_NOT_EXIST; draft-15 renamed it and moved it off 0x4. */
66
+ const DOES_NOT_EXIST_14 = 0x4;
67
+ const DOES_NOT_EXIST = 0x10;
68
+ /** Draft-14 assigns UNINTERESTED only to the two requests that offer content. */
69
+ const UNINTERESTED_14 = 0x4;
70
+ const UNINTERESTED = 0x20;
71
+ /** Draft-14 assigns MALFORMED_TRACK to FETCH_ERROR only. */
72
+ const MALFORMED_TRACK_14 = 0x9;
73
+ const MALFORMED_TRACK = 0x12;
74
+ /** The value for "the thing you asked for is not here", or undefined where none is assigned. */
75
+ function doesNotExist(kind, version) {
76
+ if (version !== Version.DRAFT_14)
77
+ return DOES_NOT_EXIST;
78
+ return kind === "subscribe" || kind === "fetch" ? DOES_NOT_EXIST_14 : undefined;
79
+ }
80
+ /** The value for "we do not want this", or undefined where none is assigned. */
81
+ function uninterested(kind, version) {
82
+ if (version !== Version.DRAFT_14)
83
+ return UNINTERESTED;
84
+ return kind === "publish" || kind === "publish_namespace" ? UNINTERESTED_14 : undefined;
85
+ }
86
+ /** The value for a track we could not parse, or undefined where none is assigned. */
87
+ function malformedTrack(kind, version) {
88
+ if (version !== Version.DRAFT_14)
89
+ return MALFORMED_TRACK;
90
+ return kind === "fetch" ? MALFORMED_TRACK_14 : undefined;
91
+ }
92
+ /** The value for a draining session, or undefined before draft-17 registered one. */
93
+ function goingAway(version) {
94
+ return version >= Version.DRAFT_17 ? GOING_AWAY : undefined;
95
+ }
96
+ /**
97
+ * The code to reject a request with, on the negotiated draft.
98
+ *
99
+ * A condition the draft does not register for this request falls back to INTERNAL_ERROR
100
+ * rather than borrowing a number from another draft, which would say something the peer's
101
+ * registry gives a different meaning. The renumbering is the trap: draft-14 SUBSCRIBE_ERROR
102
+ * gives 0x4 to TRACK_DOES_NOT_EXIST and 0x10 to MALFORMED_AUTH_TOKEN, and draft-15 swaps
103
+ * the two.
104
+ *
105
+ * @internal
106
+ */
107
+ export function toRequestCode(condition, kind, version) {
108
+ switch (condition) {
109
+ case "internal":
110
+ return INTERNAL_ERROR;
111
+ case "unauthorized":
112
+ return UNAUTHORIZED;
113
+ case "timeout":
114
+ return TIMEOUT;
115
+ case "not_supported":
116
+ return NOT_SUPPORTED;
117
+ case "does_not_exist":
118
+ return doesNotExist(kind, version) ?? INTERNAL_ERROR;
119
+ // A subscriber that asked for content cannot act on "we do not want it": what it needs
120
+ // to know is that we do not have it, which is the same refusal from its side. Only the
121
+ // requests that offer content say UNINTERESTED.
122
+ case "uninterested":
123
+ return kind === "subscribe" || kind === "fetch"
124
+ ? (doesNotExist(kind, version) ?? INTERNAL_ERROR)
125
+ : (uninterested(kind, version) ?? INTERNAL_ERROR);
126
+ case "malformed_track":
127
+ return malformedTrack(kind, version) ?? INTERNAL_ERROR;
128
+ case "going_away":
129
+ return goingAway(version) ?? INTERNAL_ERROR;
130
+ }
131
+ }
132
+ /**
133
+ * Read a rejection code received on the negotiated draft.
134
+ *
135
+ * A code the draft does not assign for this request, INTERNAL_ERROR included, is
136
+ * `undefined`: an error, but never one given a meaning it did not carry.
137
+ *
138
+ * @internal
139
+ */
140
+ export function fromRequestCode(code, kind, version) {
141
+ switch (code) {
142
+ case UNAUTHORIZED:
143
+ return "unauthorized";
144
+ case TIMEOUT:
145
+ return "timeout";
146
+ case NOT_SUPPORTED:
147
+ return "not_supported";
148
+ }
149
+ if (code === doesNotExist(kind, version))
150
+ return "does_not_exist";
151
+ if (code === uninterested(kind, version))
152
+ return "uninterested";
153
+ if (code === malformedTrack(kind, version))
154
+ return "malformed_track";
155
+ if (code === goingAway(version))
156
+ return "going_away";
157
+ return undefined;
158
+ }
159
+ /**
160
+ * Describe a rejection a peer sent, naming the condition when the draft registers one.
161
+ *
162
+ * @internal
163
+ */
164
+ export function requestReason(code, reasonPhrase, kind, version) {
165
+ const condition = fromRequestCode(code, kind, version) ?? "unregistered";
166
+ return `${condition} (code=${code}) ${reasonPhrase}`;
167
+ }
168
+ //# sourceMappingURL=error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/ietf/error.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAoB,OAAO,EAAE,MAAM,cAAc,CAAC;AAEzD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY,EAAE,OAAoB;IAClE,QAAQ,IAAI,EAAE,CAAC;QACd,KAAK,GAAG,CAAC;QACT,KAAK,GAAG,CAAC;QACT,KAAK,GAAG,CAAC;QACT,KAAK,GAAG;YACP,OAAO,IAAI,CAAC;QACb,sFAAsF;QACtF,iEAAiE;QACjE,KAAK,GAAG;YACP,OAAO,OAAO,IAAI,OAAO,CAAC,QAAQ,CAAC;QACpC,sCAAsC;QACtC,KAAK,GAAG;YACP,OAAO,OAAO,IAAI,OAAO,CAAC,QAAQ,CAAC;QACpC,uCAAuC;QACvC,KAAK,IAAI;YACR,OAAO,OAAO,IAAI,OAAO,CAAC,QAAQ,CAAC;QACpC;YACC,OAAO,KAAK,CAAC;IACf,CAAC;AACF,CAAC;AAuCD,oFAAoF;AACpF,MAAM,cAAc,GAAG,GAAG,CAAC;AAC3B,MAAM,YAAY,GAAG,GAAG,CAAC;AACzB,MAAM,OAAO,GAAG,GAAG,CAAC;AACpB,MAAM,aAAa,GAAG,GAAG,CAAC;AAE1B,8CAA8C;AAC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Ac,CAAC,IAAI,EAAE,OAAO,CAAC;QAAE,OAAO,iBAAiB,CAAC;IACrE,IAAI,IAAI,KAAK,SAAS,CAAC,OAAO,CAAC;QAAE,OAAO,YAAY,CAAC;IACrD,OAAO,SAAS,CAAC;AAClB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY,EAAE,YAAoB,EAAE,IAAiB,EAAE,OAAoB;IACxG,MAAM,SAAS,GAAG,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,cAAc,CAAC;IACzE,OAAO,GAAG,SAAS,UAAU,IAAI,KAAK,YAAY,EAAE,CAAC;AACtD,CAAC","sourcesContent":["/**\n * The moq-transport error code registries, per negotiated draft.\n *\n * A code only means something once you know which draft carried it: the registries grew,\n * moved values, and in draft-15 collapsed five per-message tables into one. Mirrors the\n * Rust `moq_net::ietf::error` module, and the two have to agree value for value.\n *\n * @module\n */\n\nimport { type IetfVersion, Version } from \"./version.ts\";\n\n/**\n * Whether `code` means the same thing in the negotiated draft's stream reset registry as it\n * does in moq-lite's.\n *\n * The two registries agree on most of what they both assign, but this one grew across the\n * drafts we negotiate and moved a value on the way:\n *\n * | Code | draft-14/15 | draft-16/17 | draft-18+ |\n * |------|-------------|-------------|-----------|\n * | 0x0 | INTERNAL_ERROR | INTERNAL_ERROR | INTERNAL_ERROR |\n * | 0x1 | CANCELLED | CANCELLED | CANCELLED |\n * | 0x2 | DELIVERY_TIMEOUT | DELIVERY_TIMEOUT | DELIVERY_TIMEOUT |\n * | 0x3 | SESSION_CLOSED | SESSION_CLOSED | SESSION_CLOSED |\n * | 0x4 | - | UNKNOWN_OBJECT_STATUS | GOING_AWAY |\n * | 0x5 | - | TOO_FAR_BEHIND (17) | TOO_FAR_BEHIND |\n * | 0x12 | - | MALFORMED_TRACK | MALFORMED_TRACK |\n *\n * So GOING_AWAY sent to a draft-17 peer reads as UNKNOWN_OBJECT_STATUS, and that peer's\n * UNKNOWN_OBJECT_STATUS read as GOING_AWAY would retire a session that is not going\n * anywhere. Anything this says `false` about is sent as, and read as, INTERNAL_ERROR: the\n * codes moq-lite assigns in its own 48-63 range, and the ones the draft assigns that\n * moq-lite has no name for (UNKNOWN_OBJECT_STATUS, EXPIRED_AUTH_TOKEN, EXCESSIVE_LOAD).\n *\n * @internal\n */\nexport function sharedStreamCode(code: number, version: IetfVersion): boolean {\n\tswitch (code) {\n\t\tcase 0x0:\n\t\tcase 0x1:\n\t\tcase 0x2:\n\t\tcase 0x3:\n\t\t\treturn true;\n\t\t// Draft-16 and 17 give 0x4 to UNKNOWN_OBJECT_STATUS, which draft-18 moved to 0x6 when\n\t\t// it took 0x4 for GOING_AWAY. Draft-14 and 15 assign it nothing.\n\t\tcase 0x4:\n\t\t\treturn version >= Version.DRAFT_18;\n\t\t// TOO_FAR_BEHIND arrived in draft-17.\n\t\tcase 0x5:\n\t\t\treturn version >= Version.DRAFT_17;\n\t\t// MALFORMED_TRACK arrived in draft-16.\n\t\tcase 0x12:\n\t\t\treturn version >= Version.DRAFT_16;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\n/**\n * Which request a rejection answers, so draft-14 picks the right registry.\n *\n * Draft-14 gives each error message its own registry and they disagree about 0x4; draft-15\n * folded them all into REQUEST_ERROR with a single registry, so from there on the kind\n * changes nothing.\n *\n * @internal\n */\nexport type RequestKind = \"subscribe\" | \"fetch\" | \"publish\" | \"publish_namespace\" | \"subscribe_namespace\";\n\n/**\n * What a rejection reports, before the draft picks the number for it.\n *\n * Named separately from the wire code because a rejection says less than a failure does: a\n * dozen local errors are one INTERNAL_ERROR on the wire.\n *\n * @internal\n */\nexport type RequestCondition =\n\t/** Something went wrong that the registry has no value for. */\n\t| \"internal\"\n\t/** The peer's credentials do not cover the request. */\n\t| \"unauthorized\"\n\t/** The request outlived an implementation-specific deadline. */\n\t| \"timeout\"\n\t/** This endpoint does not implement the request at all. */\n\t| \"not_supported\"\n\t/** The broadcast or track the peer asked for is not here. */\n\t| \"does_not_exist\"\n\t/** The content the peer offered is not wanted here, so it should stop offering it. */\n\t| \"uninterested\"\n\t/** The track's content could not be parsed. */\n\t| \"malformed_track\"\n\t/** A GOAWAY is draining the session, so no new request is accepted. */\n\t| \"going_away\";\n\n/** An implementation-specific error. Assigned by every draft, for every request. */\nconst INTERNAL_ERROR = 0x0;\nconst UNAUTHORIZED = 0x1;\nconst TIMEOUT = 0x2;\nconst NOT_SUPPORTED = 0x3;\n\n/** A draining session. Draft-17 and later. */\nconst GOING_AWAY = 0x6;\n\n/** Draft-14 calls it TRACK_DOES_NOT_EXIST; draft-15 renamed it and moved it off 0x4. */\nconst DOES_NOT_EXIST_14 = 0x4;\nconst DOES_NOT_EXIST = 0x10;\n\n/** Draft-14 assigns UNINTERESTED only to the two requests that offer content. */\nconst UNINTERESTED_14 = 0x4;\nconst UNINTERESTED = 0x20;\n\n/** Draft-14 assigns MALFORMED_TRACK to FETCH_ERROR only. */\nconst MALFORMED_TRACK_14 = 0x9;\nconst MALFORMED_TRACK = 0x12;\n\n/** The value for \"the thing you asked for is not here\", or undefined where none is assigned. */\nfunction doesNotExist(kind: RequestKind, version: IetfVersion): number | undefined {\n\tif (version !== Version.DRAFT_14) return DOES_NOT_EXIST;\n\treturn kind === \"subscribe\" || kind === \"fetch\" ? DOES_NOT_EXIST_14 : undefined;\n}\n\n/** The value for \"we do not want this\", or undefined where none is assigned. */\nfunction uninterested(kind: RequestKind, version: IetfVersion): number | undefined {\n\tif (version !== Version.DRAFT_14) return UNINTERESTED;\n\treturn kind === \"publish\" || kind === \"publish_namespace\" ? UNINTERESTED_14 : undefined;\n}\n\n/** The value for a track we could not parse, or undefined where none is assigned. */\nfunction malformedTrack(kind: RequestKind, version: IetfVersion): number | undefined {\n\tif (version !== Version.DRAFT_14) return MALFORMED_TRACK;\n\treturn kind === \"fetch\" ? MALFORMED_TRACK_14 : undefined;\n}\n\n/** The value for a draining session, or undefined before draft-17 registered one. */\nfunction goingAway(version: IetfVersion): number | undefined {\n\treturn version >= Version.DRAFT_17 ? GOING_AWAY : undefined;\n}\n\n/**\n * The code to reject a request with, on the negotiated draft.\n *\n * A condition the draft does not register for this request falls back to INTERNAL_ERROR\n * rather than borrowing a number from another draft, which would say something the peer's\n * registry gives a different meaning. The renumbering is the trap: draft-14 SUBSCRIBE_ERROR\n * gives 0x4 to TRACK_DOES_NOT_EXIST and 0x10 to MALFORMED_AUTH_TOKEN, and draft-15 swaps\n * the two.\n *\n * @internal\n */\nexport function toRequestCode(condition: RequestCondition, kind: RequestKind, version: IetfVersion): number {\n\tswitch (condition) {\n\t\tcase \"internal\":\n\t\t\treturn INTERNAL_ERROR;\n\t\tcase \"unauthorized\":\n\t\t\treturn UNAUTHORIZED;\n\t\tcase \"timeout\":\n\t\t\treturn TIMEOUT;\n\t\tcase \"not_supported\":\n\t\t\treturn NOT_SUPPORTED;\n\t\tcase \"does_not_exist\":\n\t\t\treturn doesNotExist(kind, version) ?? INTERNAL_ERROR;\n\t\t// A subscriber that asked for content cannot act on \"we do not want it\": what it needs\n\t\t// to know is that we do not have it, which is the same refusal from its side. Only the\n\t\t// requests that offer content say UNINTERESTED.\n\t\tcase \"uninterested\":\n\t\t\treturn kind === \"subscribe\" || kind === \"fetch\"\n\t\t\t\t? (doesNotExist(kind, version) ?? INTERNAL_ERROR)\n\t\t\t\t: (uninterested(kind, version) ?? INTERNAL_ERROR);\n\t\tcase \"malformed_track\":\n\t\t\treturn malformedTrack(kind, version) ?? INTERNAL_ERROR;\n\t\tcase \"going_away\":\n\t\t\treturn goingAway(version) ?? INTERNAL_ERROR;\n\t}\n}\n\n/**\n * Read a rejection code received on the negotiated draft.\n *\n * A code the draft does not assign for this request, INTERNAL_ERROR included, is\n * `undefined`: an error, but never one given a meaning it did not carry.\n *\n * @internal\n */\nexport function fromRequestCode(code: number, kind: RequestKind, version: IetfVersion): RequestCondition | undefined {\n\tswitch (code) {\n\t\tcase UNAUTHORIZED:\n\t\t\treturn \"unauthorized\";\n\t\tcase TIMEOUT:\n\t\t\treturn \"timeout\";\n\t\tcase NOT_SUPPORTED:\n\t\t\treturn \"not_supported\";\n\t}\n\n\tif (code === doesNotExist(kind, version)) return \"does_not_exist\";\n\tif (code === uninterested(kind, version)) return \"uninterested\";\n\tif (code === malformedTrack(kind, version)) return \"malformed_track\";\n\tif (code === goingAway(version)) return \"going_away\";\n\treturn undefined;\n}\n\n/**\n * Describe a rejection a peer sent, naming the condition when the draft registers one.\n *\n * @internal\n */\nexport function requestReason(code: number, reasonPhrase: string, kind: RequestKind, version: IetfVersion): string {\n\tconst condition = fromRequestCode(code, kind, version) ?? \"unregistered\";\n\treturn `${condition} (code=${code}) ${reasonPhrase}`;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../../src/ietf/filter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,KAAK,WAAW,EAAW,MAAM,cAAc,CAAC;AAEzD,6CAA6C;AAC7C,MAAM,MAAM,MAAM;AACjB,oEAAoE;AAClE;IAAE,IAAI,EAAE,YAAY,CAAA;CAAE;AACxB,sEAAsE;GACpE;IAAE,IAAI,EAAE,YAAY,CAAA;CAAE;AACxB;;;GAGG;GACD;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE;AACtC;;;GAGG;GACD;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAQxG;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAEvD;AAqCD,oFAAoF;AACpF,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,OAA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;;GAKG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CASvD;AAqCD,oFAAoF;AACpF,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,UAAU,CAEvE;AA6DD,oDAAoD;AACpD,wBAAgB,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,GAAG,MAAM,CAErE;AAgED;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAkB7D;AAQD;;;;;;;GAOG;AACH,MAAM,WAAW,IAAI;IACpB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;;OAIG;IACH,YAAY,EAAE,OAAO,CAAC;CACtB;AAmCD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,GAAG,UAAU,CAYvE;AAED,mEAAmE;AACnE,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,GAAG,IAAI,CAyDvE"}
package/ietf/filter.js CHANGED
@@ -18,7 +18,12 @@ const TAG_ABSOLUTE_RANGE = 0x4n;
18
18
  * present selects the meaning.
19
19
  */
20
20
  export function isDraft20(version) {
21
- return version === Version.DRAFT_20;
21
+ return (version !== Version.DRAFT_14 &&
22
+ version !== Version.DRAFT_15 &&
23
+ version !== Version.DRAFT_16 &&
24
+ version !== Version.DRAFT_17 &&
25
+ version !== Version.DRAFT_18 &&
26
+ version !== Version.DRAFT_19);
22
27
  }
23
28
  /**
24
29
  * Draft-17 replaced QUIC's two-bit-length varint with a leading-1-bits one. The two agree