@moq/net 0.3.5 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (244) 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 +49 -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 +23 -28
  18. package/broadcast.d.ts.map +1 -1
  19. package/broadcast.js +61 -40
  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 +48 -25
  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 +95 -46
  31. package/connection/connect.js.map +1 -1
  32. package/connection/established.d.ts +17 -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 +166 -0
  38. package/connection/forward.js.map +1 -0
  39. package/connection/handshake.d.ts +1 -0
  40. package/connection/handshake.d.ts.map +1 -1
  41. package/connection/handshake.js +5 -2
  42. package/connection/handshake.js.map +1 -1
  43. package/connection/index.d.ts +5 -5
  44. package/connection/index.d.ts.map +1 -1
  45. package/connection/index.js +4 -5
  46. package/connection/index.js.map +1 -1
  47. package/connection/pool.d.ts +186 -0
  48. package/connection/pool.d.ts.map +1 -0
  49. package/connection/pool.js +361 -0
  50. package/connection/pool.js.map +1 -0
  51. package/connection/reload.d.ts +14 -93
  52. package/connection/reload.d.ts.map +1 -1
  53. package/connection/reload.js +217 -81
  54. package/connection/reload.js.map +1 -1
  55. package/connection/stats.d.ts +3 -26
  56. package/connection/stats.d.ts.map +1 -1
  57. package/connection/stats.js.map +1 -1
  58. package/connection/transport.d.ts +0 -7
  59. package/connection/transport.d.ts.map +1 -1
  60. package/consume.d.ts +1 -43
  61. package/consume.d.ts.map +1 -1
  62. package/consume.js +1 -1
  63. package/consume.js.map +1 -1
  64. package/error.d.ts +180 -29
  65. package/error.d.ts.map +1 -1
  66. package/error.js +331 -16
  67. package/error.js.map +1 -1
  68. package/errors.d.ts +7 -0
  69. package/errors.d.ts.map +1 -0
  70. package/errors.js +8 -0
  71. package/errors.js.map +1 -0
  72. package/group.d.ts +9 -43
  73. package/group.d.ts.map +1 -1
  74. package/group.js +283 -69
  75. package/group.js.map +1 -1
  76. package/hop.d.ts +107 -0
  77. package/hop.d.ts.map +1 -0
  78. package/hop.js +103 -0
  79. package/hop.js.map +1 -0
  80. package/ietf/adapter.d.ts +5 -1
  81. package/ietf/adapter.d.ts.map +1 -1
  82. package/ietf/adapter.js +27 -9
  83. package/ietf/adapter.js.map +1 -1
  84. package/ietf/aliases.d.ts +1 -78
  85. package/ietf/aliases.d.ts.map +1 -1
  86. package/ietf/cluster.d.ts +6 -120
  87. package/ietf/cluster.d.ts.map +1 -1
  88. package/ietf/cluster.js +81 -41
  89. package/ietf/cluster.js.map +1 -1
  90. package/ietf/connection.d.ts +6 -72
  91. package/ietf/connection.d.ts.map +1 -1
  92. package/ietf/connection.js +17 -49
  93. package/ietf/connection.js.map +1 -1
  94. package/ietf/error.d.ts +11 -0
  95. package/ietf/error.d.ts.map +1 -0
  96. package/ietf/error.js +193 -0
  97. package/ietf/error.js.map +1 -0
  98. package/ietf/filter.d.ts.map +1 -1
  99. package/ietf/filter.js +6 -1
  100. package/ietf/filter.js.map +1 -1
  101. package/ietf/goaway.d.ts.map +1 -1
  102. package/ietf/goaway.js +22 -5
  103. package/ietf/goaway.js.map +1 -1
  104. package/ietf/hidden.d.ts +2 -0
  105. package/ietf/hidden.d.ts.map +1 -0
  106. package/ietf/hidden.js +30 -0
  107. package/ietf/hidden.js.map +1 -0
  108. package/ietf/index.d.ts +1 -0
  109. package/ietf/index.d.ts.map +1 -1
  110. package/ietf/index.js +1 -0
  111. package/ietf/index.js.map +1 -1
  112. package/ietf/object.d.ts +8 -2
  113. package/ietf/object.d.ts.map +1 -1
  114. package/ietf/object.js +17 -3
  115. package/ietf/object.js.map +1 -1
  116. package/ietf/parameters.d.ts +7 -2
  117. package/ietf/parameters.d.ts.map +1 -1
  118. package/ietf/parameters.js +35 -17
  119. package/ietf/parameters.js.map +1 -1
  120. package/ietf/properties.d.ts +1 -0
  121. package/ietf/properties.d.ts.map +1 -1
  122. package/ietf/properties.js +14 -0
  123. package/ietf/properties.js.map +1 -1
  124. package/ietf/publish.d.ts +19 -2
  125. package/ietf/publish.d.ts.map +1 -1
  126. package/ietf/publish.js +40 -6
  127. package/ietf/publish.js.map +1 -1
  128. package/ietf/publish_namespace.d.ts +25 -0
  129. package/ietf/publish_namespace.d.ts.map +1 -1
  130. package/ietf/publish_namespace.js +63 -0
  131. package/ietf/publish_namespace.js.map +1 -1
  132. package/ietf/publisher.d.ts +1 -82
  133. package/ietf/publisher.d.ts.map +1 -1
  134. package/ietf/publisher.js +302 -181
  135. package/ietf/publisher.js.map +1 -1
  136. package/ietf/solicit.d.ts +1 -40
  137. package/ietf/solicit.d.ts.map +1 -1
  138. package/ietf/subscribe.d.ts +1 -5
  139. package/ietf/subscribe.d.ts.map +1 -1
  140. package/ietf/subscribe.js +11 -13
  141. package/ietf/subscribe.js.map +1 -1
  142. package/ietf/subscribe_namespace.d.ts +8 -2
  143. package/ietf/subscribe_namespace.d.ts.map +1 -1
  144. package/ietf/subscribe_namespace.js +18 -8
  145. package/ietf/subscribe_namespace.js.map +1 -1
  146. package/ietf/subscriber.d.ts +1 -65
  147. package/ietf/subscriber.d.ts.map +1 -1
  148. package/ietf/subscriber.js +325 -121
  149. package/ietf/subscriber.js.map +1 -1
  150. package/ietf/version.d.ts +12 -1
  151. package/ietf/version.d.ts.map +1 -1
  152. package/ietf/version.js +13 -0
  153. package/ietf/version.js.map +1 -1
  154. package/index.d.ts +11 -6
  155. package/index.d.ts.map +1 -1
  156. package/index.js +10 -5
  157. package/index.js.map +1 -1
  158. package/internal.d.ts +104 -1
  159. package/internal.d.ts.map +1 -1
  160. package/internal.js +76 -0
  161. package/internal.js.map +1 -1
  162. package/lite/announce.d.ts +60 -10
  163. package/lite/announce.d.ts.map +1 -1
  164. package/lite/announce.js +173 -31
  165. package/lite/announce.js.map +1 -1
  166. package/lite/connection.d.ts +9 -59
  167. package/lite/connection.d.ts.map +1 -1
  168. package/lite/connection.js +26 -32
  169. package/lite/connection.js.map +1 -1
  170. package/lite/fetch.d.ts +15 -1
  171. package/lite/fetch.d.ts.map +1 -1
  172. package/lite/fetch.js +39 -7
  173. package/lite/fetch.js.map +1 -1
  174. package/lite/goaway.d.ts.map +1 -1
  175. package/lite/goaway.js +7 -1
  176. package/lite/goaway.js.map +1 -1
  177. package/lite/group.d.ts +18 -4
  178. package/lite/group.d.ts.map +1 -1
  179. package/lite/group.js +31 -10
  180. package/lite/group.js.map +1 -1
  181. package/lite/priority.d.ts +1 -61
  182. package/lite/priority.d.ts.map +1 -1
  183. package/lite/priority.js +4 -5
  184. package/lite/priority.js.map +1 -1
  185. package/lite/publisher.d.ts +1 -69
  186. package/lite/publisher.d.ts.map +1 -1
  187. package/lite/publisher.js +593 -227
  188. package/lite/publisher.js.map +1 -1
  189. package/lite/setup.d.ts +7 -7
  190. package/lite/setup.d.ts.map +1 -1
  191. package/lite/setup.js +13 -13
  192. package/lite/setup.js.map +1 -1
  193. package/lite/subscribe.d.ts +71 -17
  194. package/lite/subscribe.d.ts.map +1 -1
  195. package/lite/subscribe.js +205 -53
  196. package/lite/subscribe.js.map +1 -1
  197. package/lite/subscriber.d.ts +15 -56
  198. package/lite/subscriber.d.ts.map +1 -1
  199. package/lite/subscriber.js +316 -188
  200. package/lite/subscriber.js.map +1 -1
  201. package/lite/track.d.ts +4 -10
  202. package/lite/track.d.ts.map +1 -1
  203. package/lite/track.js +34 -29
  204. package/lite/track.js.map +1 -1
  205. package/lite/version.d.ts +42 -6
  206. package/lite/version.d.ts.map +1 -1
  207. package/lite/version.js +126 -10
  208. package/lite/version.js.map +1 -1
  209. package/origin.d.ts +248 -29
  210. package/origin.d.ts.map +1 -1
  211. package/origin.js +1232 -37
  212. package/origin.js.map +1 -1
  213. package/package.json +8 -3
  214. package/path.d.ts +25 -7
  215. package/path.d.ts.map +1 -1
  216. package/path.js +5 -3
  217. package/path.js.map +1 -1
  218. package/stream.d.ts +2 -2
  219. package/stream.d.ts.map +1 -1
  220. package/stream.js +39 -25
  221. package/stream.js.map +1 -1
  222. package/tail.d.ts +11 -0
  223. package/tail.d.ts.map +1 -0
  224. package/tail.js +121 -0
  225. package/tail.js.map +1 -0
  226. package/time.d.ts +15 -2
  227. package/time.d.ts.map +1 -1
  228. package/time.js +28 -9
  229. package/time.js.map +1 -1
  230. package/track.d.ts +195 -84
  231. package/track.d.ts.map +1 -1
  232. package/track.js +694 -196
  233. package/track.js.map +1 -1
  234. package/wire.d.ts +69 -0
  235. package/wire.d.ts.map +1 -0
  236. package/wire.js +32 -0
  237. package/wire.js.map +1 -0
  238. package/zod.d.ts +1 -1
  239. package/zod.d.ts.map +1 -1
  240. package/zod.js.map +1 -1
  241. package/mock.d.ts +0 -66
  242. package/mock.d.ts.map +0 -1
  243. package/mock.js +0 -243
  244. package/mock.js.map +0 -1
package/ietf/aliases.d.ts CHANGED
@@ -1,79 +1,2 @@
1
- /**
2
- * The full track name an alias is bound to.
3
- *
4
- * Kept as two components rather than one joined string: a track name may contain the same
5
- * separator a broadcast path uses, so `a` + `b/c` and `a/b` + `c` would otherwise compare
6
- * equal and turn a genuine collision into apparent sharing.
7
- * @internal
8
- */
9
- export type TrackIdentity = {
10
- broadcast: string;
11
- name: string;
12
- };
13
- /**
14
- * Thrown when a group arrives for a subscription we already cancelled.
15
- *
16
- * The publisher only stops once our cancellation reaches it, so objects keep arriving for
17
- * at least a round trip afterwards. Draft-19 section 11.1 asks us to keep enough state to
18
- * discard them quickly "rather than treating them as belonging to an unknown Track Alias".
19
- *
20
- * This makes the window quiet, not safe. Once a publisher reassigns the alias the tombstone
21
- * is reclaimed, and nothing on a group stream distinguishes the old subscription's objects
22
- * from the new one's. Cancelling promptly is what bounds the exposure to a round trip.
23
- * @internal
24
- */
25
- export declare class RetiredTrackAlias extends Error {
26
- constructor(alias: bigint);
27
- }
28
- /**
29
- * Thrown when a publisher gives one alias to two subscriptions of the same track.
30
- *
31
- * Draft-19 section 5.1 permits this and expects the subscriber to demux by re-applying
32
- * each subscription's filter. Ours are all LargestObject, so they are indistinguishable and
33
- * we cannot, which costs the one subscription. It is not a protocol error, so it must not
34
- * take the session down with it.
35
- * @internal
36
- */
37
- export declare class SharedTrackAlias extends Error {
38
- constructor(alias: bigint);
39
- }
40
- /**
41
- * Thrown when a publisher points one alias at two different tracks at once, which
42
- * draft-19 section 11.1 makes fatal to the session.
43
- * @internal
44
- */
45
- export declare class DuplicateTrackAlias extends Error {
46
- constructor(alias: bigint);
47
- }
48
- /** Resolves publisher-chosen track aliases after control/data stream reordering. @internal */
49
- export declare class TrackAliases<T> {
50
- #private;
51
- /**
52
- * Waits briefly for an alias to be established by SUBSCRIBE_OK or PUBLISH.
53
- *
54
- * Throws {@link RetiredTrackAlias} at once for an alias we cancelled, rather than
55
- * waiting out the timeout for a binding that is never coming.
56
- */
57
- get(alias: bigint): Promise<T>;
58
- /**
59
- * Establishes an alias and releases any data streams waiting for it.
60
- *
61
- * `track` is the full track name the alias was bound to, which is what decides whether a
62
- * repeat is the legal sharing of an alias across subscriptions to one track
63
- * ({@link SharedTrackAlias}) or the collision that must fail the session
64
- * ({@link DuplicateTrackAlias}).
65
- */
66
- set(alias: bigint, value: T, track: TrackIdentity): void;
67
- /**
68
- * Retires an alias whose subscription was cancelled, so groups still in flight for it
69
- * are discarded promptly instead of reported as unknown.
70
- *
71
- * Only retires an alias that still belongs to the supplied value: a later subscription
72
- * may already have reclaimed it, and that binding outranks a departing owner.
73
- *
74
- * Returns whether this caller still owned the binding, so metadata keyed by the alias is
75
- * only torn down by the owner and never out from under whoever reclaimed it.
76
- */
77
- retire(alias: bigint, value: T): boolean;
78
- }
1
+ export {};
79
2
  //# sourceMappingURL=aliases.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"aliases.d.ts","sourceRoot":"","sources":["../../src/ietf/aliases.ts"],"names":[],"mappings":"AAiBA;;;;;;;GAOG;AACH,MAAM,MAAM,aAAa,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAMhE;;;;;;;;;;;GAWG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;IAC3C,YAAY,KAAK,EAAE,MAAM,EAGxB;CACD;AAED;;;;;;;;GAQG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;IAC1C,YAAY,KAAK,EAAE,MAAM,EAGxB;CACD;AAED;;;;GAIG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;IAC7C,YAAY,KAAK,EAAE,MAAM,EAGxB;CACD;AAED,8FAA8F;AAC9F,qBAAa,YAAY,CAAC,CAAC;;IAQ1B;;;;;OAKG;IACG,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAyBnC;IAED;;;;;;;OAOG;IACH,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,aAAa,QAehD;IAED;;;;;;;;;OASG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAcvC;CAOD"}
1
+ {"version":3,"file":"aliases.d.ts","sourceRoot":"","sources":["../../src/ietf/aliases.ts"],"names":[],"mappings":""}
package/ietf/cluster.d.ts CHANGED
@@ -1,13 +1,14 @@
1
1
  /**
2
- * The MoQ Cluster extension (draft-lcurley-moq-cluster-00).
2
+ * The MoQ Cluster extension (draft-lcurley-moq-cluster-01).
3
3
  *
4
4
  * moq-transport carries no routing information, so a peer cannot tell whether an
5
5
  * advertisement already passed through us. This extension adds it:
6
6
  *
7
- * - each endpoint declares its own Hop ID via the RELAY_HOPS Setup Option, which is also
8
- * what negotiates the extension;
7
+ * - each endpoint declares its own Hop ID via the HOP_ID Setup Option, which is also what
8
+ * negotiates the extension;
9
9
  * - every advertisement carries the HOP_PATH it traversed and the accumulated ROUTE_COST
10
- * of that path, as Key-Value-Pair message parameters on PUBLISH_NAMESPACE and NAMESPACE.
10
+ * of that path, as Key-Value-Pair message parameters on PUBLISH_NAMESPACE and NAMESPACE,
11
+ * and a PUBLISH_NAMESPACE is repriced with the same parameters on a REQUEST_UPDATE.
11
12
  *
12
13
  * These are the semantics moq-lite carries natively on every announcement (see
13
14
  * `lite/announce.ts`); this module is the moq-transport binding, negotiated on draft-17+
@@ -22,120 +23,5 @@
22
23
  * @module
23
24
  * @internal
24
25
  */
25
- import { type Origin } from "../origin";
26
- import type { Reader } from "../stream";
27
- import { Parameters, type SetupOptions } from "./parameters";
28
- import { type IetfVersion } from "./version";
29
- /**
30
- * Whether a version can negotiate the extension.
31
- *
32
- * Draft-17 is the first with the unified SETUP: a bare Key-Value-Pair block that a new
33
- * option slots into without touching the message shape. Earlier drafts exchange SETUP over
34
- * the legacy control stream, which this extension does not cover.
35
- *
36
- * @internal
37
- */
38
- export declare function supported(version: IetfVersion): boolean;
39
- /**
40
- * The Hop IDs this session declared, one per direction.
41
- *
42
- * @internal
43
- */
44
- export interface Hops {
45
- /** Our own Hop ID, declared in SETUP and stamped onto every advertisement we send. */
46
- self: Origin;
47
- /**
48
- * The peer's Hop ID, or `undefined` when it declared no RELAY_HOPS.
49
- *
50
- * This is what decides whether advertisements carry the parameters at all, in both
51
- * directions: a peer that declared nothing has not read ours either, so sending it a
52
- * HOP_PATH would be a protocol violation and expecting one back would reject a legal
53
- * message. A peer that declared the reserved 0 negotiated the extension but withheld its
54
- * identity, so the parameters flow and there is simply nothing to exclude.
55
- */
56
- peer?: Origin;
57
- }
58
- /**
59
- * The cluster parameters carried on one advertisement.
60
- *
61
- * Present on every PUBLISH_NAMESPACE and NAMESPACE of a session that negotiated the
62
- * extension, and on none of a session that did not.
63
- *
64
- * @internal
65
- */
66
- export interface Advert {
67
- /** HOP_PATH: the path this advertisement traversed, publisher first, sender last. */
68
- hops: Origin[];
69
- /** ROUTE_COST: the marginal cost of subscribing via this advertisement. Absent on the
70
- * wire means 0, so an endpoint that prices nothing sends nothing. */
71
- cost: bigint;
72
- }
73
- /**
74
- * Read the peer's Hop ID out of its SETUP, or `undefined` when it did not negotiate.
75
- *
76
- * @internal
77
- */
78
- export declare function fromSetup(params: SetupOptions, version: IetfVersion): Origin | undefined;
79
- /**
80
- * Declare our own Hop ID, which is also what negotiates the extension.
81
- *
82
- * @internal
83
- */
84
- export declare function intoSetup(params: SetupOptions, self: Origin, version: IetfVersion): void;
85
- /**
86
- * Whether the session negotiated the extension, which is what decides whether an
87
- * advertisement carries the parameters in either direction.
88
- *
89
- * @internal
90
- */
91
- export declare function negotiated(ids: Hops | undefined): boolean;
92
- /**
93
- * The advertisement to send for one of our own broadcasts, or `undefined` on a session
94
- * that negotiated nothing.
95
- *
96
- * The sender's own Hop ID is always the last entry, so a receiver reconstructs the full
97
- * path without the sender restating it. We originate everything we advertise, so the path
98
- * is just us and the cost is 0: a subscription costs the peer nothing but the transfer,
99
- * since we are already producing the content.
100
- *
101
- * @internal
102
- */
103
- export declare function advertise(ids: Hops | undefined): Advert | undefined;
104
- /**
105
- * Whether this advertisement looped back through `self`.
106
- *
107
- * A receiver discards such an advertisement: forwarding it would extend the loop, and
108
- * subscribing through it would route the receiver back to itself. Hop ID 0 identifies
109
- * nothing, so a receiver that withheld its own identity detects nothing.
110
- *
111
- * @internal
112
- */
113
- export declare function loops(advert: Advert, self: Origin): boolean;
114
- /**
115
- * Write an advertisement's parameters, ready to encode onto the wire.
116
- *
117
- * @internal
118
- */
119
- export declare function intoParams(advert: Advert): Parameters;
120
- /**
121
- * Read the parameters a negotiated session puts on every advertisement.
122
- *
123
- * The parameter block is mandatory there, so a message that ends before it (the base form)
124
- * or one whose block does not parse is the peer's violation, same as a block that parses but
125
- * carries no HOP_PATH.
126
- *
127
- * @internal
128
- */
129
- export declare function decodeParams(r: Reader, version: IetfVersion): Promise<Advert>;
130
- /**
131
- * Read an advertisement out of a decoded parameter block.
132
- *
133
- * Every way this fails is one the draft says to close the session over: a negotiated session
134
- * that omits HOP_PATH, entries that do not exactly fill the parameter, an empty list, or a
135
- * non-zero Hop ID appearing twice. So they all surface as one {@link ProtocolViolation},
136
- * which the session dispatch acts on.
137
- *
138
- * @internal
139
- */
140
- export declare function fromParams(params: Parameters): Advert;
26
+ export {};
141
27
  //# sourceMappingURL=cluster.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cluster.d.ts","sourceRoot":"","sources":["../../src/ietf/cluster.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAGH,OAAO,EAAY,KAAK,MAAM,EAAgC,MAAM,cAAc,CAAC;AACnF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,UAAU,EAAe,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC7E,OAAO,EAAE,KAAK,WAAW,EAAW,MAAM,cAAc,CAAC;AAEzD;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAEvD;AAED;;;;GAIG;AACH,MAAM,WAAW,IAAI;IACpB,sFAAsF;IACtF,IAAI,EAAE,MAAM,CAAC;IAEb;;;;;;;;OAQG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,MAAM;IACtB,qFAAqF;IACrF,IAAI,EAAE,MAAM,EAAE,CAAC;IAEf;yEACqE;IACrE,IAAI,EAAE,MAAM,CAAC;CACb;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,WAAW,GAAG,MAAM,GAAG,SAAS,CAYxF;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,QAGjF;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,IAAI,GAAG,SAAS,GAAG,OAAO,CAEzD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAGnE;AAED;;;;;;;;GAQG;AACH,wBAAgB,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAE3D;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAoBrD;AAED;;;;;;;;GAQG;AACH,wBAAsB,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CASnF;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAuBrD"}
1
+ {"version":3,"file":"cluster.d.ts","sourceRoot":"","sources":["../../src/ietf/cluster.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG"}
package/ietf/cluster.js CHANGED
@@ -1,14 +1,15 @@
1
1
  /* @ts-self-types="./cluster.d.ts" */
2
2
  /**
3
- * The MoQ Cluster extension (draft-lcurley-moq-cluster-00).
3
+ * The MoQ Cluster extension (draft-lcurley-moq-cluster-01).
4
4
  *
5
5
  * moq-transport carries no routing information, so a peer cannot tell whether an
6
6
  * advertisement already passed through us. This extension adds it:
7
7
  *
8
- * - each endpoint declares its own Hop ID via the RELAY_HOPS Setup Option, which is also
9
- * what negotiates the extension;
8
+ * - each endpoint declares its own Hop ID via the HOP_ID Setup Option, which is also what
9
+ * negotiates the extension;
10
10
  * - every advertisement carries the HOP_PATH it traversed and the accumulated ROUTE_COST
11
- * of that path, as Key-Value-Pair message parameters on PUBLISH_NAMESPACE and NAMESPACE.
11
+ * of that path, as Key-Value-Pair message parameters on PUBLISH_NAMESPACE and NAMESPACE,
12
+ * and a PUBLISH_NAMESPACE is repriced with the same parameters on a REQUEST_UPDATE.
12
13
  *
13
14
  * These are the semantics moq-lite carries natively on every announcement (see
14
15
  * `lite/announce.ts`); this module is the moq-transport binding, negotiated on draft-17+
@@ -24,7 +25,7 @@
24
25
  * @internal
25
26
  */
26
27
  import { ProtocolViolation, reason } from "../error.js";
27
- import { MAX_HOPS, OriginSchema, UNKNOWN_ORIGIN } from "../origin.js";
28
+ import { HopSchema, MAX_HOPS, UNKNOWN_HOP } from "../hop.js";
28
29
  import * as Varint from "../varint.js";
29
30
  import { Parameters, SetupOption } from "./parameters.js";
30
31
  import { Version } from "./version.js";
@@ -48,16 +49,11 @@ export function supported(version) {
48
49
  export function fromSetup(params, version) {
49
50
  if (!supported(version))
50
51
  return undefined;
51
- // RELAY_HOPS is odd, so its value is a length-prefixed byte string holding the sender's
52
- // Hop ID as a single varint. 0 is legal: the peer speaks the extension but withholds
53
- // its identity.
54
- const value = params.getBytes(SetupOption.RelayHops);
52
+ // 0 is legal: the peer speaks the extension but withholds its identity.
53
+ const value = params.getVarint(SetupOption.HopId);
55
54
  if (value === undefined)
56
55
  return undefined;
57
- const [origin, rest] = Varint.decodeLeadingOnes(value);
58
- if (rest.length !== 0)
59
- throw new Error("trailing bytes in RELAY_HOPS");
60
- return OriginSchema.parse(origin);
56
+ return HopSchema.parse(value);
61
57
  }
62
58
  /**
63
59
  * Declare our own Hop ID, which is also what negotiates the extension.
@@ -67,7 +63,7 @@ export function fromSetup(params, version) {
67
63
  export function intoSetup(params, self, version) {
68
64
  if (!supported(version))
69
65
  return;
70
- params.setBytes(SetupOption.RelayHops, Varint.encodeLeadingOnes(self));
66
+ params.setVarint(SetupOption.HopId, self);
71
67
  }
72
68
  /**
73
69
  * Whether the session negotiated the extension, which is what decides whether an
@@ -104,7 +100,7 @@ export function advertise(ids) {
104
100
  * @internal
105
101
  */
106
102
  export function loops(advert, self) {
107
- return self !== UNKNOWN_ORIGIN && advert.hops.includes(self);
103
+ return self !== UNKNOWN_HOP && advert.hops.includes(self);
108
104
  }
109
105
  /**
110
106
  * Write an advertisement's parameters, ready to encode onto the wire.
@@ -112,23 +108,40 @@ export function loops(advert, self) {
112
108
  * @internal
113
109
  */
114
110
  export function intoParams(advert) {
115
- validate(advert.hops);
116
111
  const params = new Parameters();
117
- // The entries fill the value, so they are written with no count of their own and framed
118
- // by the parameter's own length prefix.
119
- const hops = advert.hops.map((hop) => Varint.encodeLeadingOnes(hop));
120
- const value = new Uint8Array(hops.reduce((total, hop) => total + hop.length, 0));
121
- let offset = 0;
122
- for (const hop of hops) {
123
- value.set(hop, offset);
124
- offset += hop.length;
125
- }
126
- params.hopPath = value;
112
+ params.hopPath = encodeHops(advert.hops);
127
113
  // Absent means 0, so a free path sends nothing.
128
114
  if (advert.cost !== 0n)
129
115
  params.routeCost = advert.cost;
130
116
  return params;
131
117
  }
118
+ /**
119
+ * Write a REQUEST_UPDATE's parameters: only what changed, and a cost of 0 explicitly,
120
+ * since an omitted parameter keeps its value.
121
+ *
122
+ * @internal
123
+ */
124
+ export function updateIntoParams(update) {
125
+ const params = new Parameters();
126
+ if (update.hops !== undefined)
127
+ params.hopPath = encodeHops(update.hops);
128
+ if (update.cost !== undefined)
129
+ params.routeCost = update.cost;
130
+ return params;
131
+ }
132
+ /** Write a HOP_PATH value: the entries fill it with no count of their own, framed by the
133
+ * parameter's own length prefix. */
134
+ function encodeHops(hops) {
135
+ validate(hops);
136
+ const encoded = hops.map((hop) => Varint.encodeLeadingOnes(hop));
137
+ const value = new Uint8Array(encoded.reduce((total, hop) => total + hop.length, 0));
138
+ let offset = 0;
139
+ for (const hop of encoded) {
140
+ value.set(hop, offset);
141
+ offset += hop.length;
142
+ }
143
+ return value;
144
+ }
132
145
  /**
133
146
  * Read the parameters a negotiated session puts on every advertisement.
134
147
  *
@@ -163,25 +176,52 @@ export function fromParams(params) {
163
176
  const value = params.hopPath;
164
177
  if (value === undefined)
165
178
  throw new Error("advertisement is missing HOP_PATH");
166
- const hops = [];
167
- let rest = value;
168
- while (rest.length > 0) {
169
- // A short read here means the entries did not exactly fill the length.
170
- const [hop, remain] = Varint.decodeLeadingOnes(rest);
171
- hops.push(OriginSchema.parse(hop));
172
- rest = remain;
173
- // Bail before the buffer does: a hostile length would otherwise cost us one
174
- // allocation per entry all the way to 64KB of parameter value.
175
- if (hops.length > MAX_HOPS)
176
- throw new Error(`hop count exceeds maximum ${MAX_HOPS}`);
177
- }
178
- validate(hops);
179
- return { hops, cost: params.routeCost ?? 0n };
179
+ return { hops: decodeHops(value), cost: params.routeCost ?? 0n };
180
+ }
181
+ catch (err) {
182
+ throw new ProtocolViolation(reason(err), { cause: err });
183
+ }
184
+ }
185
+ /**
186
+ * Read a REQUEST_UPDATE's parameters: each is optional, and a malformed HOP_PATH is the
187
+ * same violation it is on an advertisement.
188
+ *
189
+ * @internal
190
+ */
191
+ export function updateFromParams(params) {
192
+ try {
193
+ const value = params.hopPath;
194
+ return { hops: value === undefined ? undefined : decodeHops(value), cost: params.routeCost };
180
195
  }
181
196
  catch (err) {
182
197
  throw new ProtocolViolation(reason(err), { cause: err });
183
198
  }
184
199
  }
200
+ /**
201
+ * The advertisement after `update` lands on `held`: an omitted parameter keeps its value.
202
+ *
203
+ * @internal
204
+ */
205
+ export function apply(held, update) {
206
+ return { hops: update.hops ?? held.hops, cost: update.cost ?? held.cost };
207
+ }
208
+ /** Read a HOP_PATH value: bare varints filling the parameter, with no count of their own. */
209
+ function decodeHops(value) {
210
+ const hops = [];
211
+ let rest = value;
212
+ while (rest.length > 0) {
213
+ // A short read here means the entries did not exactly fill the length.
214
+ const [hop, remain] = Varint.decodeLeadingOnes(rest);
215
+ hops.push(HopSchema.parse(hop));
216
+ rest = remain;
217
+ // Bail before the buffer does: a hostile length would otherwise cost us one
218
+ // allocation per entry all the way to 64KB of parameter value.
219
+ if (hops.length > MAX_HOPS)
220
+ throw new Error(`hop count exceeds maximum ${MAX_HOPS}`);
221
+ }
222
+ validate(hops);
223
+ return hops;
224
+ }
185
225
  /**
186
226
  * Reject a path that cannot have come from a conforming sender: an empty list, one longer
187
227
  * than we accept, or a non-zero Hop ID appearing twice (a loop). Duplicate zeros are legal,
@@ -195,7 +235,7 @@ function validate(hops) {
195
235
  // MAX_HOPS is 32, so the quadratic scan is cheaper than allocating a set.
196
236
  for (let i = 0; i < hops.length; i++) {
197
237
  const hop = hops[i];
198
- if (hop === UNKNOWN_ORIGIN)
238
+ if (hop === UNKNOWN_HOP)
199
239
  continue;
200
240
  if (hops.indexOf(hop, i + 1) !== -1)
201
241
  throw new Error(`hop ${hop} appears twice in the hop path`);
@@ -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,C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E,EAAE,CAAC;IAC/C,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACd,MAAM,IAAI,iBAAiB,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;IAC1D,CAAC;AACF,CAAC;AAED;;;;GAIG;AACH,SAAS,QAAQ,CAAC,IAAc;IAC/B,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,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,OAAo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,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, options?: announce.Options): 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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