@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/lite/announce.js CHANGED
@@ -1,8 +1,9 @@
1
1
  /* @ts-self-types="./announce.d.ts" */
2
- import { MAX_HOPS, OriginSchema, UNKNOWN_ORIGIN } from "../origin.js";
2
+ import { ProtocolViolation } from "../error.js";
3
+ import { HopSchema, MAX_HOPS, UNKNOWN_HOP } from "../hop.js";
3
4
  import * as Path from "../path.js";
4
5
  import * as Message from "./message.js";
5
- import { hasAnnounceId, hasAnnounceOk, hasExcludeHop, hasRouteCost, Version } from "./version.js";
6
+ import { hasAnnounceCompression, hasAnnounceId, hasAnnounceOk, hasExcludeHop, hasHidden, hasRouteCost, Version, } from "./version.js";
6
7
  // Pre-lite-06 inner status values, carried inside the single ANNOUNCE_BROADCAST body.
7
8
  const STATUS_ENDED = 0;
8
9
  const STATUS_ACTIVE = 1;
@@ -13,9 +14,25 @@ const STATUS_RESTART = 2;
13
14
  const ANNOUNCE_START = 0;
14
15
  const ANNOUNCE_END = 1;
15
16
  const ANNOUNCE_RESTART = 2;
17
+ // Both wire rules on a hop chain, applied to what we send and to what we receive: a
18
+ // chain that revisits a hop looped, so neither forwarding it nor subscribing through it
19
+ // is safe, and a receiver must end the session over one. `UNKNOWN_HOP` identifies
20
+ // nothing, so any number of hops may be unknown.
21
+ //
22
+ // `ProtocolViolation` so a receipt takes the session down rather than the one stream,
23
+ // matching what `ietf/cluster.ts` throws for the identical rule.
16
24
  function checkHops(hops) {
17
25
  if (hops.length > MAX_HOPS) {
18
- throw new Error(`hop count ${hops.length} exceeds maximum ${MAX_HOPS}`);
26
+ throw new ProtocolViolation(`hop count ${hops.length} exceeds maximum ${MAX_HOPS}`);
27
+ }
28
+ // MAX_HOPS is 32, so the quadratic scan is cheaper than allocating a set.
29
+ for (let i = 0; i < hops.length; i++) {
30
+ const hop = hops[i];
31
+ if (hop === UNKNOWN_HOP)
32
+ continue;
33
+ if (hops.indexOf(hop, i + 1) !== -1) {
34
+ throw new ProtocolViolation(`hop ${hop} appears twice in the chain`);
35
+ }
19
36
  }
20
37
  }
21
38
  async function encodeHops(w, version, hops) {
@@ -28,7 +45,7 @@ async function encodeHops(w, version, hops) {
28
45
  await w.u53(hops.length);
29
46
  break;
30
47
  default:
31
- // Lite04+: hop count + individual Origin varints.
48
+ // Lite04+: hop count + individual Hop varints.
32
49
  await w.u53(hops.length);
33
50
  for (const origin of hops) {
34
51
  await w.u62(origin);
@@ -47,39 +64,87 @@ async function decodeHops(r, version) {
47
64
  throw new Error(`hop count ${count} exceeds maximum ${MAX_HOPS}`);
48
65
  // Lite03 carries only a hop count, not individual ids, so every entry is
49
66
  // the reserved "no identity" id.
50
- return new Array(count).fill(UNKNOWN_ORIGIN);
67
+ return new Array(count).fill(UNKNOWN_HOP);
51
68
  }
52
69
  default: {
53
- // Lite04+: hop count + individual Origin varints.
70
+ // Lite04+: hop count + individual Hop varints.
54
71
  const count = await r.u53();
55
72
  if (count > MAX_HOPS)
56
73
  throw new Error(`hop count ${count} exceeds maximum ${MAX_HOPS}`);
57
74
  const hops = [];
58
75
  for (let i = 0; i < count; i++) {
59
- hops.push(OriginSchema.parse(await r.u62()));
76
+ hops.push(HopSchema.parse(await r.u62()));
60
77
  }
78
+ checkHops(hops);
61
79
  return hops;
62
80
  }
63
81
  }
64
82
  }
65
- // The route cost rides lite-06+ announcements as a single varint; older
66
- // versions carry nothing and decode as zero.
83
+ // Lite-07 carries a base around a path and a hop list. A distance of 0 names
84
+ // nothing, and a keep without a base is a violation. Other versions have no room for
85
+ // a base at all.
86
+ function checkBase(version, base) {
87
+ if (base && !hasAnnounceCompression(version)) {
88
+ throw new Error("announce compression not supported for this version");
89
+ }
90
+ }
91
+ function toBase(distance, keep) {
92
+ if (distance !== 0n)
93
+ return { distance, keep };
94
+ if (keep !== 0)
95
+ throw new ProtocolViolation("announce keep without a base");
96
+ return undefined;
97
+ }
98
+ async function encodePath(w, version, suffix, base) {
99
+ checkBase(version, base);
100
+ if (hasAnnounceCompression(version)) {
101
+ await w.u62(base?.distance ?? 0n);
102
+ await w.u53(base?.keep ?? 0);
103
+ }
104
+ await w.string(Path.encode(suffix));
105
+ }
106
+ async function decodePath(r, version) {
107
+ if (!hasAnnounceCompression(version))
108
+ return { suffix: Path.decode(await r.string()) };
109
+ const pathBase = toBase(await r.u62(), await r.u53());
110
+ const suffix = Path.decode(await r.string());
111
+ return pathBase ? { suffix, pathBase } : { suffix };
112
+ }
113
+ async function encodeHopsBlock(w, version, hops, base) {
114
+ checkBase(version, base);
115
+ if (!hasAnnounceCompression(version))
116
+ return encodeHops(w, version, hops);
117
+ await w.u62(base?.distance ?? 0n);
118
+ await encodeHops(w, version, hops);
119
+ await w.u53(base?.keep ?? 0);
120
+ }
121
+ async function decodeHopsBlock(r, version) {
122
+ if (!hasAnnounceCompression(version))
123
+ return { hops: await decodeHops(r, version) };
124
+ const distance = await r.u62();
125
+ const hops = await decodeHops(r, version);
126
+ const hopBase = toBase(distance, await r.u53());
127
+ return hopBase ? { hops, hopBase } : { hops };
128
+ }
129
+ // The route cost rides lite-06+ announcements as two varints, warm then cold; older
130
+ // versions carry neither.
67
131
  async function encodeRouteCost(w, version, cost) {
68
132
  if (!hasRouteCost(version))
69
133
  return;
70
- await w.u62(cost ?? 0n);
134
+ await w.u62(cost?.warm ?? 0n);
135
+ await w.u62(cost?.cold ?? 0n);
71
136
  }
72
137
  async function decodeRouteCost(r, version) {
73
138
  if (!hasRouteCost(version))
74
- return 0n;
75
- return await r.u62();
139
+ return undefined;
140
+ return { warm: await r.u62(), cold: await r.u62() };
76
141
  }
77
142
  // lite-06 message body (no discriminator; the type is carried outside the length prefix).
78
143
  async function encodeAnnounce06Body(w, msg, version) {
79
144
  switch (msg.status) {
80
145
  case "active":
81
- await w.string(Path.encode(msg.suffix));
82
- await encodeHops(w, version, msg.hops);
146
+ await encodePath(w, version, msg.suffix, msg.pathBase);
147
+ await encodeHopsBlock(w, version, msg.hops, msg.hopBase);
83
148
  await encodeRouteCost(w, version, msg.cost);
84
149
  break;
85
150
  case "endedId":
@@ -87,12 +152,14 @@ async function encodeAnnounce06Body(w, msg, version) {
87
152
  break;
88
153
  case "restart":
89
154
  await w.u62(msg.id);
90
- await encodeHops(w, version, msg.hops);
155
+ await encodeHopsBlock(w, version, msg.hops, msg.hopBase);
91
156
  await encodeRouteCost(w, version, msg.cost);
92
157
  break;
93
158
  case "ended":
94
159
  // The pre-lite-06 path-form retraction has no place on lite-06.
95
160
  throw new Error("ended-by-path not supported for this version");
161
+ case "skipped":
162
+ throw new Error("decode-only announce type cannot be encoded");
96
163
  }
97
164
  }
98
165
  // lite-06 outer message type for a given announcement.
@@ -106,30 +173,36 @@ function announce06Type(msg) {
106
173
  return ANNOUNCE_RESTART;
107
174
  case "ended":
108
175
  throw new Error("ended-by-path not supported for this version");
176
+ case "skipped":
177
+ throw new Error("decode-only announce type cannot be encoded");
109
178
  }
110
179
  }
111
180
  async function decodeAnnounce06Body(r, typ, version) {
112
181
  switch (typ) {
113
182
  case ANNOUNCE_START: {
114
- const suffix = Path.decode(await r.string());
115
- const hops = await decodeHops(r, version);
116
- return { status: "active", suffix, hops, cost: await decodeRouteCost(r, version) };
183
+ const path = await decodePath(r, version);
184
+ const hops = await decodeHopsBlock(r, version);
185
+ return { status: "active", ...path, ...hops, cost: await decodeRouteCost(r, version) };
117
186
  }
118
187
  case ANNOUNCE_END:
119
188
  return { status: "endedId", id: await r.u62() };
120
189
  case ANNOUNCE_RESTART: {
121
190
  const id = await r.u62();
122
- const hops = await decodeHops(r, version);
123
- return { status: "restart", id, hops, cost: await decodeRouteCost(r, version) };
191
+ const hops = await decodeHopsBlock(r, version);
192
+ return { status: "restart", id, ...hops, cost: await decodeRouteCost(r, version) };
124
193
  }
125
194
  default:
126
- throw new Error(`unknown announce message type: ${typ}`);
195
+ // Skip the length-prefixed body so an earlier Lite06 build negotiating
196
+ // the same ALPN does not kill the announce stream.
197
+ await r.readAll();
198
+ return { status: "skipped" };
127
199
  }
128
200
  }
129
201
  // Pre-lite-06 single ANNOUNCE_BROADCAST body: an inner status byte, then path + hops.
130
202
  async function encodeLegacyBody(w, msg, version) {
131
203
  switch (msg.status) {
132
204
  case "active":
205
+ checkBase(version, msg.pathBase ?? msg.hopBase);
133
206
  await w.u8(STATUS_ACTIVE);
134
207
  await w.string(Path.encode(msg.suffix));
135
208
  await encodeHops(w, version, msg.hops);
@@ -141,6 +214,7 @@ async function encodeLegacyBody(w, msg, version) {
141
214
  break;
142
215
  case "endedId":
143
216
  case "restart":
217
+ case "skipped":
144
218
  // The id-referencing forms only exist on lite-06+.
145
219
  throw new Error("announce ids not supported for this version");
146
220
  }
@@ -184,33 +258,101 @@ export async function decodeAnnounceBroadcastMaybe(r, version) {
184
258
  }
185
259
  return Message.decodeMaybe(r, (r) => decodeLegacyBody(r, version));
186
260
  }
261
+ /**
262
+ * The live announcements on one lite-06+ announce stream, by Announce ID: what
263
+ * ANNOUNCE_END and ANNOUNCE_UPDATE reference, and what a lite-07 base copies from.
264
+ * Every violation throws {@link ProtocolViolation}.
265
+ */
266
+ export class AnnounceHistory {
267
+ #next = 0n;
268
+ #live = new Map();
269
+ #base(base) {
270
+ const live = this.#live.get(this.#next - base.distance);
271
+ if (!live)
272
+ throw new ProtocolViolation(`announce base ${base.distance} is not live`);
273
+ return live;
274
+ }
275
+ #hops(hops, base) {
276
+ if (!base)
277
+ return hops;
278
+ const tail = this.#base(base).hops;
279
+ if (base.keep > tail.length)
280
+ throw new ProtocolViolation(`announce keeps ${base.keep} of ${tail.length} hops`);
281
+ const resolved = [...hops, ...tail.slice(tail.length - base.keep)];
282
+ checkHops(resolved);
283
+ return resolved;
284
+ }
285
+ /** An ANNOUNCE_START: resolve it and assign it the next id. */
286
+ start(msg) {
287
+ let suffix = msg.suffix;
288
+ if (msg.pathBase) {
289
+ const head = Path.parts(this.#base(msg.pathBase).suffix);
290
+ const keep = msg.pathBase.keep;
291
+ if (keep > head.length)
292
+ throw new ProtocolViolation(`announce keeps ${keep} of ${head.length} segments`);
293
+ suffix = Path.join(Path.from(...head.slice(0, keep)), suffix);
294
+ if (Path.parts(suffix).length > Path.MAX_PARTS) {
295
+ throw new ProtocolViolation(`path exceeds ${Path.MAX_PARTS} parts`);
296
+ }
297
+ }
298
+ const hops = this.#hops(msg.hops, msg.hopBase);
299
+ this.#live.set(this.#next++, { suffix, hops });
300
+ return { suffix, hops };
301
+ }
302
+ /** An ANNOUNCE_UPDATE: resolve its chain before replacing the old one, which it may be based on. */
303
+ update(msg) {
304
+ const hops = this.#hops(msg.hops, msg.hopBase);
305
+ const live = this.#live.get(msg.id);
306
+ if (!live)
307
+ throw new ProtocolViolation(`unknown announce id: ${msg.id}`);
308
+ this.#live.set(msg.id, { suffix: live.suffix, hops });
309
+ return { suffix: live.suffix, hops };
310
+ }
311
+ /** An ANNOUNCE_END: retire the id, returning its suffix. */
312
+ end(id) {
313
+ const live = this.#live.get(id);
314
+ if (!live)
315
+ throw new ProtocolViolation(`unknown announce id: ${id}`);
316
+ this.#live.delete(id);
317
+ return live.suffix;
318
+ }
319
+ }
187
320
  /**
188
321
  * ANNOUNCE_REQUEST: sent by the subscriber to request ANNOUNCE_BROADCAST messages
189
322
  * for a path prefix. Renamed from `AnnounceInterest` in lite-05.
190
323
  */
191
324
  export class AnnounceRequest {
192
325
  prefix;
193
- /** Lite04/05 only: the 62-bit Origin id of the peer asking for announces, which the
326
+ /** Lite04/05 only: the 62-bit Hop id of the peer asking for announces, which the
194
327
  * publisher uses to skip announces that already passed through it. Zero means "no
195
328
  * exclusion". Not on the wire elsewhere, so a value set here is ignored when encoding
196
329
  * for another version and decodes as zero.
197
330
  *
198
331
  * Must be a bigint: peer origins are up to 62 bits and overflow u53. */
199
332
  excludeHop;
200
- constructor(prefix, excludeHop = 0n) {
333
+ /** Lite07+: also announce routes with a `.`-prefixed segment below the prefix. Not on
334
+ * the wire earlier, so a value set here is ignored when encoding for an older version
335
+ * and decodes as false. */
336
+ hidden;
337
+ constructor(prefix, excludeHop = 0n, hidden = false) {
201
338
  this.prefix = prefix;
202
339
  this.excludeHop = excludeHop;
340
+ this.hidden = hidden;
203
341
  }
204
342
  async #encode(w, version) {
205
343
  await w.string(Path.encode(this.prefix));
206
344
  if (hasExcludeHop(version)) {
207
345
  await w.u62(this.excludeHop);
208
346
  }
347
+ if (hasHidden(version)) {
348
+ await w.bool(this.hidden);
349
+ }
209
350
  }
210
351
  static async #decode(r, version) {
211
352
  const prefix = Path.decode(await r.string());
212
353
  const excludeHop = hasExcludeHop(version) ? await r.u62() : 0n;
213
- return new AnnounceRequest(prefix, excludeHop);
354
+ const hidden = hasHidden(version) ? await r.bool() : false;
355
+ return new AnnounceRequest(prefix, excludeHop, hidden);
214
356
  }
215
357
  async encode(w, version) {
216
358
  return Message.encode(w, (w) => this.#encode(w, version));
@@ -262,15 +404,15 @@ export class AnnounceInit {
262
404
  /// Sent by the publisher as the first message on an announce stream, before any
263
405
  /// individual Announce messages. Lite05+ only; the successor to AnnounceInit.
264
406
  ///
265
- /// `origin` is the responder's origin id, which the subscriber stamps onto each
407
+ /// `origin` is the responder's Hop ID, which the subscriber stamps onto each
266
408
  /// announce's hop chain (the publisher no longer stamps itself), or the reserved
267
- /// {@link UNKNOWN_ORIGIN} when the responder has no identity to give. `active` is
409
+ /// {@link UNKNOWN_HOP} when the responder has no identity to give. `active` is
268
410
  /// the number of initial Announce messages that follow immediately.
269
411
  export class AnnounceOk {
270
- origin;
412
+ hop;
271
413
  active;
272
- constructor(origin, active) {
273
- this.origin = origin;
414
+ constructor(hop, active) {
415
+ this.hop = hop;
274
416
  this.active = active;
275
417
  }
276
418
  static #guard(version) {
@@ -279,14 +421,14 @@ export class AnnounceOk {
279
421
  }
280
422
  }
281
423
  async #encode(w) {
282
- await w.u62(this.origin);
424
+ await w.u62(this.hop);
283
425
  await w.u53(this.active);
284
426
  }
285
427
  static async #decode(r) {
286
428
  // The draft reserves 0 for "unknown": the responder was never assigned an id, or
287
429
  // withholds it to obscure its routing. It names nobody, so callers must not stamp
288
430
  // it onto a hop chain, but it is a legal message and not grounds to drop the stream.
289
- const origin = OriginSchema.parse(await r.u62());
431
+ const origin = HopSchema.parse(await r.u62());
290
432
  const active = await r.u53();
291
433
  return new AnnounceOk(origin, active);
292
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MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;QAC/D,CAAC;IACF,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,CAAS;QACtB,MAAM,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACzB,MAAM,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC1B,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAS;QAC7B,iFAAiF;QACjF,kFAAkF;QAClF,qFAAqF;QACrF,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;QACjD,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC;QAC7B,OAAO,IAAI,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,CAAS,EAAE,OAAgB;QACvC,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC3B,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACnD,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAS,EAAE,OAAgB;QAC9C,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC3B,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;IAC9C,CAAC;CACD","sourcesContent":["import { MAX_HOPS, type Origin, OriginSchema, UNKNOWN_ORIGIN } from \"../origin.ts\";\nimport * as Path from \"../path.ts\";\nimport type { Reader, Writer } from \"../stream.ts\";\nimport * as Message from \"./message.ts\";\nimport { hasAnnounceId, hasAnnounceOk, hasExcludeHop, hasRouteCost, Version } from \"./version.ts\";\n\n// Pre-lite-06 inner status values, carried inside the single ANNOUNCE_BROADCAST body.\nconst STATUS_ENDED = 0;\nconst STATUS_ACTIVE = 1;\nconst STATUS_RESTART = 2;\n\n// lite-06 announce message types: an outer discriminator carried before the length\n// prefix, so each announcement is an independently-typed, length-delimited message\n// (mirroring SUBSCRIBE_START/END/DROP on the subscribe stream).\nconst ANNOUNCE_START = 0;\nconst ANNOUNCE_END = 1;\nconst ANNOUNCE_RESTART = 2;\n\n/**\n * An announcement on the Announce Stream, advertising or retracting a broadcast.\n *\n * On lite-06+ these are three independently-typed messages (`ANNOUNCE_START`,\n * `ANNOUNCE_END`, `ANNOUNCE_RESTART`), each framed as `Type | Length | Body` like the\n * subscribe stream's responses. Each `active` (ANNOUNCE_START) implicitly assigns the\n * next announce id (a per-stream ordinal starting at 0); `endedId`/`restart` reference\n * that id instead of repeating the path. Older versions send a single ANNOUNCE_BROADCAST\n * message that retracts by path (`ended`).\n */\nexport type AnnounceBroadcast =\n\t/** A broadcast is now available, carrying the path suffix, the hop chain, and\n\t * (lite-06+) the route cost. An absent cost encodes as zero. */\n\t| { status: \"active\"; suffix: Path.Valid; hops: Origin[]; cost?: bigint }\n\t/** Pre-lite-06: a broadcast is no longer available, retracted by path. */\n\t| { status: \"ended\"; suffix: Path.Valid }\n\t/** Lite06+: a broadcast is no longer available, retracted by announce id.\n\t * The id is retired; referencing it again is a protocol violation. */\n\t| { status: \"endedId\"; id: bigint }\n\t/** Lite06+: atomically replace the announcement with this id (e.g. a new hop\n\t * chain after a relay failover, or a route whose cost moved). The id stays live. */\n\t| { status: \"restart\"; id: bigint; hops: Origin[]; cost?: bigint };\n\nfunction checkHops(hops: Origin[]) {\n\tif (hops.length > MAX_HOPS) {\n\t\tthrow new Error(`hop count ${hops.length} exceeds maximum ${MAX_HOPS}`);\n\t}\n}\n\nasync function encodeHops(w: Writer, version: Version, hops: Origin[]) {\n\tcheckHops(hops);\n\tswitch (version) {\n\t\tcase Version.DRAFT_01:\n\t\tcase Version.DRAFT_02:\n\t\t\tbreak;\n\t\tcase Version.DRAFT_03:\n\t\t\tawait w.u53(hops.length);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\t// Lite04+: hop count + individual Origin varints.\n\t\t\tawait w.u53(hops.length);\n\t\t\tfor (const origin of hops) {\n\t\t\t\tawait w.u62(origin);\n\t\t\t}\n\t\t\tbreak;\n\t}\n}\n\nasync function decodeHops(r: Reader, version: Version): Promise<Origin[]> {\n\tswitch (version) {\n\t\tcase Version.DRAFT_01:\n\t\tcase Version.DRAFT_02:\n\t\t\treturn [];\n\t\tcase Version.DRAFT_03: {\n\t\t\tconst count = await r.u53();\n\t\t\tif (count > MAX_HOPS) throw new Error(`hop count ${count} exceeds maximum ${MAX_HOPS}`);\n\t\t\t// Lite03 carries only a hop count, not individual ids, so every entry is\n\t\t\t// the reserved \"no identity\" id.\n\t\t\treturn new Array<Origin>(count).fill(UNKNOWN_ORIGIN);\n\t\t}\n\t\tdefault: {\n\t\t\t// Lite04+: hop count + individual Origin varints.\n\t\t\tconst count = await r.u53();\n\t\t\tif (count > MAX_HOPS) throw new Error(`hop count ${count} exceeds maximum ${MAX_HOPS}`);\n\t\t\tconst hops: Origin[] = [];\n\t\t\tfor (let i = 0; i < count; i++) {\n\t\t\t\thops.push(OriginSchema.parse(await r.u62()));\n\t\t\t}\n\t\t\treturn hops;\n\t\t}\n\t}\n}\n\n// The route cost rides lite-06+ announcements as a single varint; older\n// versions carry nothing and decode as zero.\nasync function encodeRouteCost(w: Writer, version: Version, cost: bigint | undefined) {\n\tif (!hasRouteCost(version)) return;\n\tawait w.u62(cost ?? 0n);\n}\n\nasync function decodeRouteCost(r: Reader, version: Version): Promise<bigint> {\n\tif (!hasRouteCost(version)) return 0n;\n\treturn await r.u62();\n}\n\n// lite-06 message body (no discriminator; the type is carried outside the length prefix).\nasync function encodeAnnounce06Body(w: Writer, msg: AnnounceBroadcast, version: Version) {\n\tswitch (msg.status) {\n\t\tcase \"active\":\n\t\t\tawait w.string(Path.encode(msg.suffix));\n\t\t\tawait encodeHops(w, version, msg.hops);\n\t\t\tawait encodeRouteCost(w, version, msg.cost);\n\t\t\tbreak;\n\t\tcase \"endedId\":\n\t\t\tawait w.u62(msg.id);\n\t\t\tbreak;\n\t\tcase \"restart\":\n\t\t\tawait w.u62(msg.id);\n\t\t\tawait encodeHops(w, version, msg.hops);\n\t\t\tawait encodeRouteCost(w, version, msg.cost);\n\t\t\tbreak;\n\t\tcase \"ended\":\n\t\t\t// The pre-lite-06 path-form retraction has no place on lite-06.\n\t\t\tthrow new Error(\"ended-by-path not supported for this version\");\n\t}\n}\n\n// lite-06 outer message type for a given announcement.\nfunction announce06Type(msg: AnnounceBroadcast): number {\n\tswitch (msg.status) {\n\t\tcase \"active\":\n\t\t\treturn ANNOUNCE_START;\n\t\tcase \"endedId\":\n\t\t\treturn ANNOUNCE_END;\n\t\tcase \"restart\":\n\t\t\treturn ANNOUNCE_RESTART;\n\t\tcase \"ended\":\n\t\t\tthrow new Error(\"ended-by-path not supported for this version\");\n\t}\n}\n\nasync function decodeAnnounce06Body(r: Reader, typ: number, version: Version): Promise<AnnounceBroadcast> {\n\tswitch (typ) {\n\t\tcase ANNOUNCE_START: {\n\t\t\tconst suffix = Path.decode(await r.string());\n\t\t\tconst hops = await decodeHops(r, version);\n\t\t\treturn { status: \"active\", suffix, hops, cost: await decodeRouteCost(r, version) };\n\t\t}\n\t\tcase ANNOUNCE_END:\n\t\t\treturn { status: \"endedId\", id: await r.u62() };\n\t\tcase ANNOUNCE_RESTART: {\n\t\t\tconst id = await r.u62();\n\t\t\tconst hops = await decodeHops(r, version);\n\t\t\treturn { status: \"restart\", id, hops, cost: await decodeRouteCost(r, version) };\n\t\t}\n\t\tdefault:\n\t\t\tthrow new Error(`unknown announce message type: ${typ}`);\n\t}\n}\n\n// Pre-lite-06 single ANNOUNCE_BROADCAST body: an inner status byte, then path + hops.\nasync function encodeLegacyBody(w: Writer, msg: AnnounceBroadcast, version: Version) {\n\tswitch (msg.status) {\n\t\tcase \"active\":\n\t\t\tawait w.u8(STATUS_ACTIVE);\n\t\t\tawait w.string(Path.encode(msg.suffix));\n\t\t\tawait encodeHops(w, version, msg.hops);\n\t\t\tbreak;\n\t\tcase \"ended\":\n\t\t\tawait w.u8(STATUS_ENDED);\n\t\t\tawait w.string(Path.encode(msg.suffix));\n\t\t\tawait encodeHops(w, version, []);\n\t\t\tbreak;\n\t\tcase \"endedId\":\n\t\tcase \"restart\":\n\t\t\t// The id-referencing forms only exist on lite-06+.\n\t\t\tthrow new Error(\"announce ids not supported for this version\");\n\t}\n}\n\nasync function decodeLegacyBody(r: Reader, version: Version): Promise<AnnounceBroadcast> {\n\tconst status = await r.u8();\n\t// On lite-05 a restart travels as a duplicate `active`, but the explicit restart\n\t// status is accepted on decode and treated the same. Older versions never defined it.\n\tconst active = status === STATUS_ACTIVE || (status === STATUS_RESTART && hasAnnounceOk(version));\n\tif (status !== STATUS_ENDED && !active) {\n\t\tthrow new Error(\"invalid announce status\");\n\t}\n\tconst suffix = Path.decode(await r.string());\n\tconst hops = await decodeHops(r, version);\n\treturn active ? { status: \"active\", suffix, hops } : { status: \"ended\", suffix };\n}\n\n/** Encode one announcement, including its type discriminator (lite-06+) and length prefix. */\nexport async function encodeAnnounceBroadcast(w: Writer, msg: AnnounceBroadcast, version: Version): Promise<void> {\n\tif (hasAnnounceId(version)) {\n\t\t// lite-06+: outer type discriminator, then a size-prefixed body (like the subscribe stream).\n\t\tawait w.u53(announce06Type(msg));\n\t\treturn Message.encode(w, (w) => encodeAnnounce06Body(w, msg, version));\n\t}\n\treturn Message.encode(w, (w) => encodeLegacyBody(w, msg, version));\n}\n\n/** Decode one announcement, including its type discriminator (lite-06+) and length prefix. */\nexport async function decodeAnnounceBroadcast(r: Reader, version: Version): Promise<AnnounceBroadcast> {\n\tif (hasAnnounceId(version)) {\n\t\tconst typ = await r.u53();\n\t\treturn Message.decode(r, (r) => decodeAnnounce06Body(r, typ, version));\n\t}\n\treturn Message.decode(r, (r) => decodeLegacyBody(r, version));\n}\n\n/** Like {@link decodeAnnounceBroadcast} but resolves `undefined` on a clean FIN. */\nexport async function decodeAnnounceBroadcastMaybe(\n\tr: Reader,\n\tversion: Version,\n): Promise<AnnounceBroadcast | undefined> {\n\tif (hasAnnounceId(version)) {\n\t\tif (await r.done()) return undefined;\n\t\tconst typ = await r.u53();\n\t\treturn Message.decode(r, (r) => decodeAnnounce06Body(r, typ, version));\n\t}\n\treturn Message.decodeMaybe(r, (r) => decodeLegacyBody(r, version));\n}\n\n/**\n * ANNOUNCE_REQUEST: sent by the subscriber to request ANNOUNCE_BROADCAST messages\n * for a path prefix. Renamed from `AnnounceInterest` in lite-05.\n */\nexport class AnnounceRequest {\n\tprefix: Path.Valid;\n\t/** Lite04/05 only: the 62-bit Origin id of the peer asking for announces, which the\n\t * publisher uses to skip announces that already passed through it. Zero means \"no\n\t * exclusion\". Not on the wire elsewhere, so a value set here is ignored when encoding\n\t * for another version and decodes as zero.\n\t *\n\t * Must be a bigint: peer origins are up to 62 bits and overflow u53. */\n\texcludeHop: bigint;\n\n\tconstructor(prefix: Path.Valid, excludeHop: bigint = 0n) {\n\t\tthis.prefix = prefix;\n\t\tthis.excludeHop = excludeHop;\n\t}\n\n\tasync #encode(w: Writer, version: Version) {\n\t\tawait w.string(Path.encode(this.prefix));\n\t\tif (hasExcludeHop(version)) {\n\t\t\tawait w.u62(this.excludeHop);\n\t\t}\n\t}\n\n\tstatic async #decode(r: Reader, version: Version): Promise<AnnounceRequest> {\n\t\tconst prefix = Path.decode(await r.string());\n\t\tconst excludeHop = hasExcludeHop(version) ? await r.u62() : 0n;\n\t\treturn new AnnounceRequest(prefix, excludeHop);\n\t}\n\n\tasync encode(w: Writer, version: Version): Promise<void> {\n\t\treturn Message.encode(w, (w) => this.#encode(w, version));\n\t}\n\n\tstatic async decode(r: Reader, version: Version): Promise<AnnounceRequest> {\n\t\treturn Message.decode(r, (r) => AnnounceRequest.#decode(r, version));\n\t}\n}\n\n/// Sent after setup to communicate the initially announced paths.\n///\n/// Used by Draft01/Draft02 only. Draft03+ uses individual Announce messages instead.\nexport class AnnounceInit {\n\tsuffixes: Path.Valid[];\n\n\tconstructor(paths: Path.Valid[]) {\n\t\tthis.suffixes = paths;\n\t}\n\n\tstatic #guard(version: Version) {\n\t\tswitch (version) {\n\t\t\tcase Version.DRAFT_01:\n\t\t\tcase Version.DRAFT_02:\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"announce init not supported for this version\");\n\t\t}\n\t}\n\n\tasync #encode(w: Writer) {\n\t\tawait w.u53(this.suffixes.length);\n\t\tfor (const path of this.suffixes) {\n\t\t\tawait w.string(Path.encode(path));\n\t\t}\n\t}\n\n\tstatic async #decode(r: Reader): Promise<AnnounceInit> {\n\t\tconst count = await r.u53();\n\t\tconst suffixes: Path.Valid[] = [];\n\t\tfor (let i = 0; i < count; i++) {\n\t\t\tsuffixes.push(Path.decode(await r.string()));\n\t\t}\n\t\treturn new AnnounceInit(suffixes);\n\t}\n\n\tasync encode(w: Writer, version: Version): Promise<void> {\n\t\tAnnounceInit.#guard(version);\n\t\treturn Message.encode(w, this.#encode.bind(this));\n\t}\n\n\tstatic async decode(r: Reader, version: Version): Promise<AnnounceInit> {\n\t\tAnnounceInit.#guard(version);\n\t\treturn Message.decode(r, AnnounceInit.#decode);\n\t}\n}\n\n/// Sent by the publisher as the first message on an announce stream, before any\n/// individual Announce messages. Lite05+ only; the successor to AnnounceInit.\n///\n/// `origin` is the responder's origin id, which the subscriber stamps onto each\n/// announce's hop chain (the publisher no longer stamps itself), or the reserved\n/// {@link UNKNOWN_ORIGIN} when the responder has no identity to give. `active` is\n/// the number of initial Announce messages that follow immediately.\nexport class AnnounceOk {\n\torigin: Origin;\n\tactive: number;\n\n\tconstructor(origin: Origin, active: number) {\n\t\tthis.origin = origin;\n\t\tthis.active = active;\n\t}\n\n\tstatic #guard(version: Version) {\n\t\tif (!hasAnnounceOk(version)) {\n\t\t\tthrow new Error(\"announce ok not supported for this version\");\n\t\t}\n\t}\n\n\tasync #encode(w: Writer) {\n\t\tawait w.u62(this.origin);\n\t\tawait w.u53(this.active);\n\t}\n\n\tstatic async #decode(r: Reader): Promise<AnnounceOk> {\n\t\t// The draft reserves 0 for \"unknown\": the responder was never assigned an id, or\n\t\t// withholds it to obscure its routing. It names nobody, so callers must not stamp\n\t\t// it onto a hop chain, but it is a legal message and not grounds to drop the stream.\n\t\tconst origin = OriginSchema.parse(await r.u62());\n\t\tconst active = await r.u53();\n\t\treturn new AnnounceOk(origin, active);\n\t}\n\n\tasync encode(w: Writer, version: Version): Promise<void> {\n\t\tAnnounceOk.#guard(version);\n\t\treturn Message.encode(w, this.#encode.bind(this));\n\t}\n\n\tstatic async decode(r: Reader, version: Version): Promise<AnnounceOk> {\n\t\tAnnounceOk.#guard(version);\n\t\treturn Message.decode(r, AnnounceOk.#decode);\n\t}\n}\n"]}
1
+ {"version":3,"file":"announce.js","sourceRoot":"","sources":["../../src/lite/announce.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAuB,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAClF,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AAEnC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,EACN,sBAAsB,EACtB,aAAa,EACb,aAAa,EACb,aAAa,EACb,SAAS,EACT,YAAY,EACZ,OAAO,GACP,MAAM,cAAc,CAAC;AAEtB,sFAAsF;AACtF,MAAM,YAAY,GAAG,CAAC,CAAC;AACvB,MAAM,aAAa,GAAG,CAAC,CAAC;AACxB,MAAM,cAAc,GAAG,CAAC,CAAC;AAEzB,mFAAmF;AACnF,mFAAmF;AACnF,gEAAgE;AAChE,MAAM,cAAc,GAAG,CAAC,CAAC;AACzB,MAAM,YAAY,GAAG,CAAC,CAAC;AACvB,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAsC3B,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AC;IACF,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,CAAS;QACtB,MAAM,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACtB,MAAM,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC1B,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAS;QAC7B,iFAAiF;QACjF,kFAAkF;QAClF,qFAAqF;QACrF,MAAM,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;QAC9C,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC;QAC7B,OAAO,IAAI,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,CAAS,EAAE,OAAgB;QACvC,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC3B,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACnD,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAS,EAAE,OAAgB;QAC9C,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC3B,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;IAC9C,CAAC;CACD","sourcesContent":["import { ProtocolViolation } from \"../error.ts\";\nimport { type Cost, type Hop, HopSchema, MAX_HOPS, UNKNOWN_HOP } from \"../hop.ts\";\nimport * as Path from \"../path.ts\";\nimport type { Reader, Writer } from \"../stream.ts\";\nimport * as Message from \"./message.ts\";\nimport {\n\thasAnnounceCompression,\n\thasAnnounceId,\n\thasAnnounceOk,\n\thasExcludeHop,\n\thasHidden,\n\thasRouteCost,\n\tVersion,\n} from \"./version.ts\";\n\n// Pre-lite-06 inner status values, carried inside the single ANNOUNCE_BROADCAST body.\nconst STATUS_ENDED = 0;\nconst STATUS_ACTIVE = 1;\nconst STATUS_RESTART = 2;\n\n// lite-06 announce message types: an outer discriminator carried before the length\n// prefix, so each announcement is an independently-typed, length-delimited message\n// (mirroring SUBSCRIBE_START/END/DROP on the subscribe stream).\nconst ANNOUNCE_START = 0;\nconst ANNOUNCE_END = 1;\nconst ANNOUNCE_RESTART = 2;\n\nexport type { Cost };\n\n/**\n * Lite-07: copy `keep` path segments (from the head) or hops (from the tail) of the\n * live announcement `distance` back from the stream's next Announce ID, where 1 is the\n * latest ANNOUNCE_START. Resolved by {@link AnnounceHistory}.\n */\nexport type Base = { distance: bigint; keep: number };\n\n/**\n * An announcement on the Announce Stream, advertising or retracting a broadcast.\n *\n * On lite-06+ these are three independently-typed messages (`ANNOUNCE_START`,\n * `ANNOUNCE_END`, `ANNOUNCE_RESTART`), each framed as `Type | Length | Body` like the\n * subscribe stream's responses. Each `active` (ANNOUNCE_START) implicitly assigns the\n * next announce id (a per-stream ordinal starting at 0); `endedId`/`restart` reference\n * that id instead of repeating the path. Older versions send a single ANNOUNCE_BROADCAST\n * message that retracts by path (`ended`).\n */\nexport type AnnounceBroadcast =\n\t/** A broadcast is now available, carrying the path suffix, the hop chain, and\n\t * (lite-06+) the route cost. An absent cost encodes as zero; it decodes as\n\t * `undefined` on a wire with no room for one. On lite-07, `suffix` follows the\n\t * segments `pathBase` copies and `hops` precede the ones `hopBase` copies. */\n\t| { status: \"active\"; suffix: Path.Valid; hops: Hop[]; cost?: Cost; pathBase?: Base; hopBase?: Base }\n\t/** Pre-lite-06: a broadcast is no longer available, retracted by path. */\n\t| { status: \"ended\"; suffix: Path.Valid }\n\t/** Lite06+: a broadcast is no longer available, retracted by announce id.\n\t * The id is retired; referencing it again is a protocol violation. */\n\t| { status: \"endedId\"; id: bigint }\n\t/** Lite06+: atomically replace the announcement with this id (e.g. a new hop\n\t * chain after a relay failover, or a route whose cost moved). The id stays live. */\n\t| { status: \"restart\"; id: bigint; hops: Hop[]; cost?: Cost; hopBase?: Base }\n\t/** An unknown lite-06+ announce type, skipped by length. Does not assign an id. */\n\t| { status: \"skipped\" };\n\n// Both wire rules on a hop chain, applied to what we send and to what we receive: a\n// chain that revisits a hop looped, so neither forwarding it nor subscribing through it\n// is safe, and a receiver must end the session over one. `UNKNOWN_HOP` identifies\n// nothing, so any number of hops may be unknown.\n//\n// `ProtocolViolation` so a receipt takes the session down rather than the one stream,\n// matching what `ietf/cluster.ts` throws for the identical rule.\nfunction checkHops(hops: Hop[]) {\n\tif (hops.length > MAX_HOPS) {\n\t\tthrow new ProtocolViolation(`hop count ${hops.length} exceeds maximum ${MAX_HOPS}`);\n\t}\n\n\t// MAX_HOPS is 32, so the quadratic scan is cheaper than allocating a set.\n\tfor (let i = 0; i < hops.length; i++) {\n\t\tconst hop = hops[i];\n\t\tif (hop === UNKNOWN_HOP) continue;\n\t\tif (hops.indexOf(hop, i + 1) !== -1) {\n\t\t\tthrow new ProtocolViolation(`hop ${hop} appears twice in the chain`);\n\t\t}\n\t}\n}\n\nasync function encodeHops(w: Writer, version: Version, hops: Hop[]) {\n\tcheckHops(hops);\n\tswitch (version) {\n\t\tcase Version.DRAFT_01:\n\t\tcase Version.DRAFT_02:\n\t\t\tbreak;\n\t\tcase Version.DRAFT_03:\n\t\t\tawait w.u53(hops.length);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\t// Lite04+: hop count + individual Hop varints.\n\t\t\tawait w.u53(hops.length);\n\t\t\tfor (const origin of hops) {\n\t\t\t\tawait w.u62(origin);\n\t\t\t}\n\t\t\tbreak;\n\t}\n}\n\nasync function decodeHops(r: Reader, version: Version): Promise<Hop[]> {\n\tswitch (version) {\n\t\tcase Version.DRAFT_01:\n\t\tcase Version.DRAFT_02:\n\t\t\treturn [];\n\t\tcase Version.DRAFT_03: {\n\t\t\tconst count = await r.u53();\n\t\t\tif (count > MAX_HOPS) throw new Error(`hop count ${count} exceeds maximum ${MAX_HOPS}`);\n\t\t\t// Lite03 carries only a hop count, not individual ids, so every entry is\n\t\t\t// the reserved \"no identity\" id.\n\t\t\treturn new Array<Hop>(count).fill(UNKNOWN_HOP);\n\t\t}\n\t\tdefault: {\n\t\t\t// Lite04+: hop count + individual Hop varints.\n\t\t\tconst count = await r.u53();\n\t\t\tif (count > MAX_HOPS) throw new Error(`hop count ${count} exceeds maximum ${MAX_HOPS}`);\n\t\t\tconst hops: Hop[] = [];\n\t\t\tfor (let i = 0; i < count; i++) {\n\t\t\t\thops.push(HopSchema.parse(await r.u62()));\n\t\t\t}\n\t\t\tcheckHops(hops);\n\t\t\treturn hops;\n\t\t}\n\t}\n}\n\n// Lite-07 carries a base around a path and a hop list. A distance of 0 names\n// nothing, and a keep without a base is a violation. Other versions have no room for\n// a base at all.\nfunction checkBase(version: Version, base: Base | undefined) {\n\tif (base && !hasAnnounceCompression(version)) {\n\t\tthrow new Error(\"announce compression not supported for this version\");\n\t}\n}\n\nfunction toBase(distance: bigint, keep: number): Base | undefined {\n\tif (distance !== 0n) return { distance, keep };\n\tif (keep !== 0) throw new ProtocolViolation(\"announce keep without a base\");\n\treturn undefined;\n}\n\nasync function encodePath(w: Writer, version: Version, suffix: Path.Valid, base: Base | undefined) {\n\tcheckBase(version, base);\n\tif (hasAnnounceCompression(version)) {\n\t\tawait w.u62(base?.distance ?? 0n);\n\t\tawait w.u53(base?.keep ?? 0);\n\t}\n\tawait w.string(Path.encode(suffix));\n}\n\nasync function decodePath(r: Reader, version: Version): Promise<{ suffix: Path.Valid; pathBase?: Base }> {\n\tif (!hasAnnounceCompression(version)) return { suffix: Path.decode(await r.string()) };\n\tconst pathBase = toBase(await r.u62(), await r.u53());\n\tconst suffix = Path.decode(await r.string());\n\treturn pathBase ? { suffix, pathBase } : { suffix };\n}\n\nasync function encodeHopsBlock(w: Writer, version: Version, hops: Hop[], base: Base | undefined) {\n\tcheckBase(version, base);\n\tif (!hasAnnounceCompression(version)) return encodeHops(w, version, hops);\n\tawait w.u62(base?.distance ?? 0n);\n\tawait encodeHops(w, version, hops);\n\tawait w.u53(base?.keep ?? 0);\n}\n\nasync function decodeHopsBlock(r: Reader, version: Version): Promise<{ hops: Hop[]; hopBase?: Base }> {\n\tif (!hasAnnounceCompression(version)) return { hops: await decodeHops(r, version) };\n\tconst distance = await r.u62();\n\tconst hops = await decodeHops(r, version);\n\tconst hopBase = toBase(distance, await r.u53());\n\treturn hopBase ? { hops, hopBase } : { hops };\n}\n\n// The route cost rides lite-06+ announcements as two varints, warm then cold; older\n// versions carry neither.\nasync function encodeRouteCost(w: Writer, version: Version, cost: Cost | undefined) {\n\tif (!hasRouteCost(version)) return;\n\tawait w.u62(cost?.warm ?? 0n);\n\tawait w.u62(cost?.cold ?? 0n);\n}\n\nasync function decodeRouteCost(r: Reader, version: Version): Promise<Cost | undefined> {\n\tif (!hasRouteCost(version)) return undefined;\n\treturn { warm: await r.u62(), cold: await r.u62() };\n}\n\n// lite-06 message body (no discriminator; the type is carried outside the length prefix).\nasync function encodeAnnounce06Body(w: Writer, msg: AnnounceBroadcast, version: Version) {\n\tswitch (msg.status) {\n\t\tcase \"active\":\n\t\t\tawait encodePath(w, version, msg.suffix, msg.pathBase);\n\t\t\tawait encodeHopsBlock(w, version, msg.hops, msg.hopBase);\n\t\t\tawait encodeRouteCost(w, version, msg.cost);\n\t\t\tbreak;\n\t\tcase \"endedId\":\n\t\t\tawait w.u62(msg.id);\n\t\t\tbreak;\n\t\tcase \"restart\":\n\t\t\tawait w.u62(msg.id);\n\t\t\tawait encodeHopsBlock(w, version, msg.hops, msg.hopBase);\n\t\t\tawait encodeRouteCost(w, version, msg.cost);\n\t\t\tbreak;\n\t\tcase \"ended\":\n\t\t\t// The pre-lite-06 path-form retraction has no place on lite-06.\n\t\t\tthrow new Error(\"ended-by-path not supported for this version\");\n\t\tcase \"skipped\":\n\t\t\tthrow new Error(\"decode-only announce type cannot be encoded\");\n\t}\n}\n\n// lite-06 outer message type for a given announcement.\nfunction announce06Type(msg: AnnounceBroadcast): number {\n\tswitch (msg.status) {\n\t\tcase \"active\":\n\t\t\treturn ANNOUNCE_START;\n\t\tcase \"endedId\":\n\t\t\treturn ANNOUNCE_END;\n\t\tcase \"restart\":\n\t\t\treturn ANNOUNCE_RESTART;\n\t\tcase \"ended\":\n\t\t\tthrow new Error(\"ended-by-path not supported for this version\");\n\t\tcase \"skipped\":\n\t\t\tthrow new Error(\"decode-only announce type cannot be encoded\");\n\t}\n}\n\nasync function decodeAnnounce06Body(r: Reader, typ: number, version: Version): Promise<AnnounceBroadcast> {\n\tswitch (typ) {\n\t\tcase ANNOUNCE_START: {\n\t\t\tconst path = await decodePath(r, version);\n\t\t\tconst hops = await decodeHopsBlock(r, version);\n\t\t\treturn { status: \"active\", ...path, ...hops, cost: await decodeRouteCost(r, version) };\n\t\t}\n\t\tcase ANNOUNCE_END:\n\t\t\treturn { status: \"endedId\", id: await r.u62() };\n\t\tcase ANNOUNCE_RESTART: {\n\t\t\tconst id = await r.u62();\n\t\t\tconst hops = await decodeHopsBlock(r, version);\n\t\t\treturn { status: \"restart\", id, ...hops, cost: await decodeRouteCost(r, version) };\n\t\t}\n\t\tdefault:\n\t\t\t// Skip the length-prefixed body so an earlier Lite06 build negotiating\n\t\t\t// the same ALPN does not kill the announce stream.\n\t\t\tawait r.readAll();\n\t\t\treturn { status: \"skipped\" };\n\t}\n}\n\n// Pre-lite-06 single ANNOUNCE_BROADCAST body: an inner status byte, then path + hops.\nasync function encodeLegacyBody(w: Writer, msg: AnnounceBroadcast, version: Version) {\n\tswitch (msg.status) {\n\t\tcase \"active\":\n\t\t\tcheckBase(version, msg.pathBase ?? msg.hopBase);\n\t\t\tawait w.u8(STATUS_ACTIVE);\n\t\t\tawait w.string(Path.encode(msg.suffix));\n\t\t\tawait encodeHops(w, version, msg.hops);\n\t\t\tbreak;\n\t\tcase \"ended\":\n\t\t\tawait w.u8(STATUS_ENDED);\n\t\t\tawait w.string(Path.encode(msg.suffix));\n\t\t\tawait encodeHops(w, version, []);\n\t\t\tbreak;\n\t\tcase \"endedId\":\n\t\tcase \"restart\":\n\t\tcase \"skipped\":\n\t\t\t// The id-referencing forms only exist on lite-06+.\n\t\t\tthrow new Error(\"announce ids not supported for this version\");\n\t}\n}\n\nasync function decodeLegacyBody(r: Reader, version: Version): Promise<AnnounceBroadcast> {\n\tconst status = await r.u8();\n\t// On lite-05 a restart travels as a duplicate `active`, but the explicit restart\n\t// status is accepted on decode and treated the same. Older versions never defined it.\n\tconst active = status === STATUS_ACTIVE || (status === STATUS_RESTART && hasAnnounceOk(version));\n\tif (status !== STATUS_ENDED && !active) {\n\t\tthrow new Error(\"invalid announce status\");\n\t}\n\tconst suffix = Path.decode(await r.string());\n\tconst hops = await decodeHops(r, version);\n\treturn active ? { status: \"active\", suffix, hops } : { status: \"ended\", suffix };\n}\n\n/** Encode one announcement, including its type discriminator (lite-06+) and length prefix. */\nexport async function encodeAnnounceBroadcast(w: Writer, msg: AnnounceBroadcast, version: Version): Promise<void> {\n\tif (hasAnnounceId(version)) {\n\t\t// lite-06+: outer type discriminator, then a size-prefixed body (like the subscribe stream).\n\t\tawait w.u53(announce06Type(msg));\n\t\treturn Message.encode(w, (w) => encodeAnnounce06Body(w, msg, version));\n\t}\n\treturn Message.encode(w, (w) => encodeLegacyBody(w, msg, version));\n}\n\n/** Decode one announcement, including its type discriminator (lite-06+) and length prefix. */\nexport async function decodeAnnounceBroadcast(r: Reader, version: Version): Promise<AnnounceBroadcast> {\n\tif (hasAnnounceId(version)) {\n\t\tconst typ = await r.u53();\n\t\treturn Message.decode(r, (r) => decodeAnnounce06Body(r, typ, version));\n\t}\n\treturn Message.decode(r, (r) => decodeLegacyBody(r, version));\n}\n\n/** Like {@link decodeAnnounceBroadcast} but resolves `undefined` on a clean FIN. */\nexport async function decodeAnnounceBroadcastMaybe(\n\tr: Reader,\n\tversion: Version,\n): Promise<AnnounceBroadcast | undefined> {\n\tif (hasAnnounceId(version)) {\n\t\tif (await r.done()) return undefined;\n\t\tconst typ = await r.u53();\n\t\treturn Message.decode(r, (r) => decodeAnnounce06Body(r, typ, version));\n\t}\n\treturn Message.decodeMaybe(r, (r) => decodeLegacyBody(r, version));\n}\n\ntype Advertised = { suffix: Path.Valid; hops: Hop[] };\n\n/**\n * The live announcements on one lite-06+ announce stream, by Announce ID: what\n * ANNOUNCE_END and ANNOUNCE_UPDATE reference, and what a lite-07 base copies from.\n * Every violation throws {@link ProtocolViolation}.\n */\nexport class AnnounceHistory {\n\t#next = 0n;\n\t#live = new Map<bigint, Advertised>();\n\n\t#base(base: Base): Advertised {\n\t\tconst live = this.#live.get(this.#next - base.distance);\n\t\tif (!live) throw new ProtocolViolation(`announce base ${base.distance} is not live`);\n\t\treturn live;\n\t}\n\n\t#hops(hops: Hop[], base: Base | undefined): Hop[] {\n\t\tif (!base) return hops;\n\t\tconst tail = this.#base(base).hops;\n\t\tif (base.keep > tail.length) throw new ProtocolViolation(`announce keeps ${base.keep} of ${tail.length} hops`);\n\t\tconst resolved = [...hops, ...tail.slice(tail.length - base.keep)];\n\t\tcheckHops(resolved);\n\t\treturn resolved;\n\t}\n\n\t/** An ANNOUNCE_START: resolve it and assign it the next id. */\n\tstart(msg: { suffix: Path.Valid; hops: Hop[]; pathBase?: Base; hopBase?: Base }): Advertised {\n\t\tlet suffix = msg.suffix;\n\t\tif (msg.pathBase) {\n\t\t\tconst head = Path.parts(this.#base(msg.pathBase).suffix);\n\t\t\tconst keep = msg.pathBase.keep;\n\t\t\tif (keep > head.length) throw new ProtocolViolation(`announce keeps ${keep} of ${head.length} segments`);\n\t\t\tsuffix = Path.join(Path.from(...head.slice(0, keep)), suffix);\n\t\t\tif (Path.parts(suffix).length > Path.MAX_PARTS) {\n\t\t\t\tthrow new ProtocolViolation(`path exceeds ${Path.MAX_PARTS} parts`);\n\t\t\t}\n\t\t}\n\t\tconst hops = this.#hops(msg.hops, msg.hopBase);\n\t\tthis.#live.set(this.#next++, { suffix, hops });\n\t\treturn { suffix, hops };\n\t}\n\n\t/** An ANNOUNCE_UPDATE: resolve its chain before replacing the old one, which it may be based on. */\n\tupdate(msg: { id: bigint; hops: Hop[]; hopBase?: Base }): Advertised {\n\t\tconst hops = this.#hops(msg.hops, msg.hopBase);\n\t\tconst live = this.#live.get(msg.id);\n\t\tif (!live) throw new ProtocolViolation(`unknown announce id: ${msg.id}`);\n\t\tthis.#live.set(msg.id, { suffix: live.suffix, hops });\n\t\treturn { suffix: live.suffix, hops };\n\t}\n\n\t/** An ANNOUNCE_END: retire the id, returning its suffix. */\n\tend(id: bigint): Path.Valid {\n\t\tconst live = this.#live.get(id);\n\t\tif (!live) throw new ProtocolViolation(`unknown announce id: ${id}`);\n\t\tthis.#live.delete(id);\n\t\treturn live.suffix;\n\t}\n}\n\n/**\n * ANNOUNCE_REQUEST: sent by the subscriber to request ANNOUNCE_BROADCAST messages\n * for a path prefix. Renamed from `AnnounceInterest` in lite-05.\n */\nexport class AnnounceRequest {\n\tprefix: Path.Valid;\n\t/** Lite04/05 only: the 62-bit Hop id of the peer asking for announces, which the\n\t * publisher uses to skip announces that already passed through it. Zero means \"no\n\t * exclusion\". Not on the wire elsewhere, so a value set here is ignored when encoding\n\t * for another version and decodes as zero.\n\t *\n\t * Must be a bigint: peer origins are up to 62 bits and overflow u53. */\n\texcludeHop: bigint;\n\t/** Lite07+: also announce routes with a `.`-prefixed segment below the prefix. Not on\n\t * the wire earlier, so a value set here is ignored when encoding for an older version\n\t * and decodes as false. */\n\thidden: boolean;\n\n\tconstructor(prefix: Path.Valid, excludeHop: bigint = 0n, hidden = false) {\n\t\tthis.prefix = prefix;\n\t\tthis.excludeHop = excludeHop;\n\t\tthis.hidden = hidden;\n\t}\n\n\tasync #encode(w: Writer, version: Version) {\n\t\tawait w.string(Path.encode(this.prefix));\n\t\tif (hasExcludeHop(version)) {\n\t\t\tawait w.u62(this.excludeHop);\n\t\t}\n\t\tif (hasHidden(version)) {\n\t\t\tawait w.bool(this.hidden);\n\t\t}\n\t}\n\n\tstatic async #decode(r: Reader, version: Version): Promise<AnnounceRequest> {\n\t\tconst prefix = Path.decode(await r.string());\n\t\tconst excludeHop = hasExcludeHop(version) ? await r.u62() : 0n;\n\t\tconst hidden = hasHidden(version) ? await r.bool() : false;\n\t\treturn new AnnounceRequest(prefix, excludeHop, hidden);\n\t}\n\n\tasync encode(w: Writer, version: Version): Promise<void> {\n\t\treturn Message.encode(w, (w) => this.#encode(w, version));\n\t}\n\n\tstatic async decode(r: Reader, version: Version): Promise<AnnounceRequest> {\n\t\treturn Message.decode(r, (r) => AnnounceRequest.#decode(r, version));\n\t}\n}\n\n/// Sent after setup to communicate the initially announced paths.\n///\n/// Used by Draft01/Draft02 only. Draft03+ uses individual Announce messages instead.\nexport class AnnounceInit {\n\tsuffixes: Path.Valid[];\n\n\tconstructor(paths: Path.Valid[]) {\n\t\tthis.suffixes = paths;\n\t}\n\n\tstatic #guard(version: Version) {\n\t\tswitch (version) {\n\t\t\tcase Version.DRAFT_01:\n\t\t\tcase Version.DRAFT_02:\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"announce init not supported for this version\");\n\t\t}\n\t}\n\n\tasync #encode(w: Writer) {\n\t\tawait w.u53(this.suffixes.length);\n\t\tfor (const path of this.suffixes) {\n\t\t\tawait w.string(Path.encode(path));\n\t\t}\n\t}\n\n\tstatic async #decode(r: Reader): Promise<AnnounceInit> {\n\t\tconst count = await r.u53();\n\t\tconst suffixes: Path.Valid[] = [];\n\t\tfor (let i = 0; i < count; i++) {\n\t\t\tsuffixes.push(Path.decode(await r.string()));\n\t\t}\n\t\treturn new AnnounceInit(suffixes);\n\t}\n\n\tasync encode(w: Writer, version: Version): Promise<void> {\n\t\tAnnounceInit.#guard(version);\n\t\treturn Message.encode(w, this.#encode.bind(this));\n\t}\n\n\tstatic async decode(r: Reader, version: Version): Promise<AnnounceInit> {\n\t\tAnnounceInit.#guard(version);\n\t\treturn Message.decode(r, AnnounceInit.#decode);\n\t}\n}\n\n/// Sent by the publisher as the first message on an announce stream, before any\n/// individual Announce messages. Lite05+ only; the successor to AnnounceInit.\n///\n/// `origin` is the responder's Hop ID, which the subscriber stamps onto each\n/// announce's hop chain (the publisher no longer stamps itself), or the reserved\n/// {@link UNKNOWN_HOP} when the responder has no identity to give. `active` is\n/// the number of initial Announce messages that follow immediately.\nexport class AnnounceOk {\n\thop: Hop;\n\tactive: number;\n\n\tconstructor(hop: Hop, active: number) {\n\t\tthis.hop = hop;\n\t\tthis.active = active;\n\t}\n\n\tstatic #guard(version: Version) {\n\t\tif (!hasAnnounceOk(version)) {\n\t\t\tthrow new Error(\"announce ok not supported for this version\");\n\t\t}\n\t}\n\n\tasync #encode(w: Writer) {\n\t\tawait w.u62(this.hop);\n\t\tawait w.u53(this.active);\n\t}\n\n\tstatic async #decode(r: Reader): Promise<AnnounceOk> {\n\t\t// The draft reserves 0 for \"unknown\": the responder was never assigned an id, or\n\t\t// withholds it to obscure its routing. It names nobody, so callers must not stamp\n\t\t// it onto a hop chain, but it is a legal message and not grounds to drop the stream.\n\t\tconst origin = HopSchema.parse(await r.u62());\n\t\tconst active = await r.u53();\n\t\treturn new AnnounceOk(origin, active);\n\t}\n\n\tasync encode(w: Writer, version: Version): Promise<void> {\n\t\tAnnounceOk.#guard(version);\n\t\treturn Message.encode(w, this.#encode.bind(this));\n\t}\n\n\tstatic async decode(r: Reader, version: Version): Promise<AnnounceOk> {\n\t\tAnnounceOk.#guard(version);\n\t\treturn Message.decode(r, AnnounceOk.#decode);\n\t}\n}\n"]}
@@ -1,31 +1,11 @@
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 { type Origin } from "../origin";
8
- import * as Path from "../path";
9
- import { Stream } from "../stream";
10
- import { ProbeLevel, type Role } from "./setup";
11
- import { type Version } from "./version";
12
- /**
13
- * Constructor options for {@link Connection}.
14
- *
15
- * @internal
16
- */
17
- export interface ConnectionProps {
18
- /** The URL of the connection. */
19
- url: URL;
20
- /** The established WebTransport session. */
21
- quic: WebTransport;
22
- /** The negotiated wire version. */
23
- version: Version;
24
- /** The session stream, absent on drafts that have none. */
25
- session?: Stream;
26
- /** Whether the relay supports broadcast discovery. Defaults to true. */
27
- discovery?: boolean;
28
- }
6
+ import { type Hop } from "../hop";
7
+ import type * as Path from "../path";
8
+ import { type Role } from "./setup";
29
9
  /**
30
10
  * Represents a connection to a MoQ server.
31
11
  *
@@ -40,9 +20,9 @@ export declare class Connection implements Established {
40
20
  readonly discovery: boolean;
41
21
  /** The peer's PROBE estimates; see {@link Established.probe}. */
42
22
  readonly probe: Getter<Probe>;
43
- /** Random per-connection origin id. Shared by Publisher (for outbound hop
23
+ /** Random per-connection Hop ID. Shared by Publisher (for outbound hop
44
24
  * chains) and Subscriber (available for optional self-filtering on announces). */
45
- readonly origin: Origin;
25
+ readonly hop: Hop;
46
26
  /**
47
27
  * The {@link Role} the peer advertised in its SETUP, for a server deciding whether the
48
28
  * peer's authorization grants the direction it intends to use.
@@ -53,44 +33,14 @@ export declare class Connection implements Established {
53
33
  * recognize, or is a server (which never sends one).
54
34
  */
55
35
  get peerRole(): Getter<Role | undefined>;
56
- /**
57
- * Creates a new Connection instance.
58
- *
59
- * @internal
60
- */
61
- constructor({ url, quic, version, session, discovery }: ConnectionProps);
62
36
  /**
63
37
  * Closes the connection.
64
38
  */
65
39
  close(): void;
66
- publish(path: Path.Valid, producer: broadcast.Producer): void;
67
- announced(prefix?: Path.Valid): announce.Consumer;
68
- consume(path: Path.Valid): broadcast.Consumer;
69
- /**
70
- * Watches a broadcast, live only while it is announced.
71
- *
72
- * @param path - The path of the broadcast to watch
73
- * @returns A reactive handle to the broadcast
74
- */
75
- announcedBroadcast(path: Path.Valid): announce.Broadcast;
40
+ announced(scope?: Path.Pattern, options?: announce.Options): announce.Consumer;
76
41
  /** Snapshot the transport's counters; see {@link Established.stats}. */
77
42
  stats(): Promise<Stats>;
78
- get closed(): Promise<void>;
43
+ /** Resolves when the session closes, decoding the peer's close code; see {@link Established.closed}. */
44
+ get closed(): Promise<Error | null>;
79
45
  }
80
- /**
81
- * The probe level to advertise in SETUP, from what the transport can measure.
82
- *
83
- * `Report` claims we can measure and periodically report, so it is only truthful
84
- * when a metric this version can carry actually exists. The qmux/WebSocket fallback
85
- * implements no `getStats()` at all, and even a transport that has one may report
86
- * neither figure. Advertising `Report` and then holding the subscriber's PROBE
87
- * stream open with nothing to send is the state this avoids; the subscriber's own
88
- * gate then skips a stream it could not use.
89
- *
90
- * Mirrors `ProbeLevel::detect` in `moq-net`, including its limitation: a metric
91
- * that only appears after SETUP reads as unsupported here.
92
- *
93
- * @internal
94
- */
95
- export declare function probeLevel(quic: WebTransport, version: Version): Promise<ProbeLevel>;
96
46
  //# sourceMappingURL=connection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/lite/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAU,MAAM,cAAc,CAAC;AACnD,OAAO,KAAK,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;AACzE,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,cAAc,CAAC;AACzD,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAwB,MAAM,EAAU,MAAM,cAAc,CAAC;AAOpE,OAAO,EAAE,UAAU,EAAE,KAAK,IAAI,EA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