@moq/net 0.4.1 → 0.4.3

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 (184) hide show
  1. package/broadcast.d.ts +21 -7
  2. package/broadcast.d.ts.map +1 -1
  3. package/broadcast.js +38 -16
  4. package/broadcast.js.map +1 -1
  5. package/connection/accept.js +6 -4
  6. package/connection/accept.js.map +1 -1
  7. package/connection/connect.d.ts.map +1 -1
  8. package/connection/connect.js +5 -4
  9. package/connection/connect.js.map +1 -1
  10. package/connection/forward.js +54 -47
  11. package/connection/forward.js.map +1 -1
  12. package/connection/goaway.d.ts +34 -0
  13. package/connection/goaway.d.ts.map +1 -0
  14. package/connection/goaway.js +176 -0
  15. package/connection/goaway.js.map +1 -0
  16. package/connection/handshake.d.ts +4 -2
  17. package/connection/handshake.d.ts.map +1 -1
  18. package/connection/handshake.js +42 -10
  19. package/connection/handshake.js.map +1 -1
  20. package/connection/pool.d.ts +16 -1
  21. package/connection/pool.d.ts.map +1 -1
  22. package/connection/pool.js +32 -10
  23. package/connection/pool.js.map +1 -1
  24. package/connection/reload.d.ts.map +1 -1
  25. package/connection/reload.js +184 -30
  26. package/connection/reload.js.map +1 -1
  27. package/error.d.ts +11 -0
  28. package/error.d.ts.map +1 -1
  29. package/error.js +14 -0
  30. package/error.js.map +1 -1
  31. package/errors.d.ts +1 -1
  32. package/errors.d.ts.map +1 -1
  33. package/errors.js +1 -1
  34. package/errors.js.map +1 -1
  35. package/group.d.ts.map +1 -1
  36. package/group.js +5 -4
  37. package/group.js.map +1 -1
  38. package/hop.d.ts +8 -0
  39. package/hop.d.ts.map +1 -1
  40. package/hop.js +16 -0
  41. package/hop.js.map +1 -1
  42. package/ietf/adapter.d.ts +4 -0
  43. package/ietf/adapter.d.ts.map +1 -1
  44. package/ietf/adapter.js +19 -8
  45. package/ietf/adapter.js.map +1 -1
  46. package/ietf/cluster.d.ts +3 -3
  47. package/ietf/cluster.js +3 -3
  48. package/ietf/cluster.js.map +1 -1
  49. package/ietf/connection.d.ts.map +1 -1
  50. package/ietf/connection.js +110 -37
  51. package/ietf/connection.js.map +1 -1
  52. package/ietf/fetch.d.ts +7 -20
  53. package/ietf/fetch.d.ts.map +1 -1
  54. package/ietf/fetch.js +52 -22
  55. package/ietf/fetch.js.map +1 -1
  56. package/ietf/filter.d.ts +20 -4
  57. package/ietf/filter.d.ts.map +1 -1
  58. package/ietf/filter.js +165 -17
  59. package/ietf/filter.js.map +1 -1
  60. package/ietf/goaway.d.ts +9 -1
  61. package/ietf/goaway.d.ts.map +1 -1
  62. package/ietf/goaway.js +20 -0
  63. package/ietf/goaway.js.map +1 -1
  64. package/ietf/hidden.js +1 -1
  65. package/ietf/hidden.js.map +1 -1
  66. package/ietf/index.d.ts +1 -1
  67. package/ietf/index.d.ts.map +1 -1
  68. package/ietf/index.js +1 -1
  69. package/ietf/index.js.map +1 -1
  70. package/ietf/object.d.ts +9 -6
  71. package/ietf/object.d.ts.map +1 -1
  72. package/ietf/object.js +47 -38
  73. package/ietf/object.js.map +1 -1
  74. package/ietf/parameters.d.ts +13 -8
  75. package/ietf/parameters.d.ts.map +1 -1
  76. package/ietf/parameters.js +177 -30
  77. package/ietf/parameters.js.map +1 -1
  78. package/ietf/publish.d.ts +1 -0
  79. package/ietf/publish.d.ts.map +1 -1
  80. package/ietf/publish.js +1 -0
  81. package/ietf/publish.js.map +1 -1
  82. package/ietf/publish_namespace.d.ts +2 -2
  83. package/ietf/publish_namespace.js +2 -2
  84. package/ietf/publish_namespace.js.map +1 -1
  85. package/ietf/publisher.js +404 -202
  86. package/ietf/publisher.js.map +1 -1
  87. package/ietf/request_stream.d.ts +7 -0
  88. package/ietf/request_stream.d.ts.map +1 -0
  89. package/ietf/request_stream.js +20 -0
  90. package/ietf/request_stream.js.map +1 -0
  91. package/ietf/subscribe.d.ts +7 -1
  92. package/ietf/subscribe.d.ts.map +1 -1
  93. package/ietf/subscribe.js +24 -17
  94. package/ietf/subscribe.js.map +1 -1
  95. package/ietf/subscribe_namespace.d.ts.map +1 -1
  96. package/ietf/subscribe_namespace.js +7 -3
  97. package/ietf/subscribe_namespace.js.map +1 -1
  98. package/ietf/subscriber.js +83 -56
  99. package/ietf/subscriber.js.map +1 -1
  100. package/ietf/token.d.ts +2 -0
  101. package/ietf/token.d.ts.map +1 -0
  102. package/ietf/token.js +99 -0
  103. package/ietf/token.js.map +1 -0
  104. package/ietf/track.d.ts +4 -0
  105. package/ietf/track.d.ts.map +1 -1
  106. package/ietf/track.js +6 -20
  107. package/ietf/track.js.map +1 -1
  108. package/index.d.ts +1 -1
  109. package/index.d.ts.map +1 -1
  110. package/index.js.map +1 -1
  111. package/internal.d.ts +12 -3
  112. package/internal.d.ts.map +1 -1
  113. package/internal.js +32 -0
  114. package/internal.js.map +1 -1
  115. package/lite/announce.d.ts.map +1 -1
  116. package/lite/announce.js +7 -4
  117. package/lite/announce.js.map +1 -1
  118. package/lite/connection.d.ts.map +1 -1
  119. package/lite/connection.js +22 -7
  120. package/lite/connection.js.map +1 -1
  121. package/lite/datagram.d.ts +3 -2
  122. package/lite/datagram.d.ts.map +1 -1
  123. package/lite/datagram.js +7 -8
  124. package/lite/datagram.js.map +1 -1
  125. package/lite/group.d.ts +12 -8
  126. package/lite/group.d.ts.map +1 -1
  127. package/lite/group.js +37 -16
  128. package/lite/group.js.map +1 -1
  129. package/lite/message.d.ts +2 -2
  130. package/lite/message.d.ts.map +1 -1
  131. package/lite/message.js +14 -5
  132. package/lite/message.js.map +1 -1
  133. package/lite/publisher.js +39 -45
  134. package/lite/publisher.js.map +1 -1
  135. package/lite/setup.d.ts +1 -1
  136. package/lite/setup.d.ts.map +1 -1
  137. package/lite/setup.js +22 -19
  138. package/lite/setup.js.map +1 -1
  139. package/lite/subscribe.d.ts.map +1 -1
  140. package/lite/subscribe.js +4 -5
  141. package/lite/subscribe.js.map +1 -1
  142. package/lite/subscriber.d.ts.map +1 -1
  143. package/lite/subscriber.js +210 -127
  144. package/lite/subscriber.js.map +1 -1
  145. package/origin.d.ts +9 -1
  146. package/origin.d.ts.map +1 -1
  147. package/origin.js +341 -146
  148. package/origin.js.map +1 -1
  149. package/package.json +2 -2
  150. package/stream.d.ts +77 -12
  151. package/stream.d.ts.map +1 -1
  152. package/stream.js +359 -122
  153. package/stream.js.map +1 -1
  154. package/tail.d.ts +7 -0
  155. package/tail.d.ts.map +1 -1
  156. package/tail.js +68 -22
  157. package/tail.js.map +1 -1
  158. package/track.d.ts +14 -3
  159. package/track.d.ts.map +1 -1
  160. package/track.js +170 -76
  161. package/track.js.map +1 -1
  162. package/util/abort.d.ts +2 -0
  163. package/util/abort.d.ts.map +1 -0
  164. package/util/abort.js +20 -0
  165. package/util/abort.js.map +1 -0
  166. package/util/u64.d.ts +39 -0
  167. package/util/u64.d.ts.map +1 -0
  168. package/util/u64.js +83 -0
  169. package/util/u64.js.map +1 -0
  170. package/util/varint.d.ts +29 -0
  171. package/util/varint.d.ts.map +1 -0
  172. package/util/varint.js +198 -0
  173. package/util/varint.js.map +1 -0
  174. package/varint.d.ts +10 -6
  175. package/varint.d.ts.map +1 -1
  176. package/varint.js +40 -237
  177. package/varint.js.map +1 -1
  178. package/wire.d.ts +17 -3
  179. package/wire.d.ts.map +1 -1
  180. package/wire.js.map +1 -1
  181. package/ietf/control.d.ts +0 -135
  182. package/ietf/control.d.ts.map +0 -1
  183. package/ietf/control.js +0 -242
  184. package/ietf/control.js.map +0 -1
@@ -7,6 +7,7 @@ import * as Path from "../path.js";
7
7
  import * as Time from "../time.js";
8
8
  import { wireOf } from "../wire.js";
9
9
  import { connect } from "./connect.js";
10
+ import { DEFAULT_HANDOVER, dialed, handover, pinnedTransport, target } from "./goaway.js";
10
11
  /**
11
12
  * The backoff applied to whichever {@link ReloadDelay} fields a caller leaves out.
12
13
  *
@@ -90,6 +91,14 @@ export class Reload {
90
91
  consume;
91
92
  /** Backoff settings for the reconnect loop; an unset field uses its default. */
92
93
  delay;
94
+ /** How to react to the peer's GOAWAY (not reactive). */
95
+ goaway;
96
+ /**
97
+ * The URL an accepted GOAWAY redirect assigned, or undefined while the loop dials
98
+ * {@link Reload.url}. Sticky across reconnects: a redirect is an assignment, not a
99
+ * detour. Cleared when a new URL or a disable/re-enable starts another sequence.
100
+ */
101
+ redirect;
93
102
  /** The reactive effect scope driving the connect loop; closed by {@link Reload.close}. */
94
103
  #signals = new Effect();
95
104
  // Sampled from the live session; undefined while disconnected or the transport has none.
@@ -104,6 +113,14 @@ export class Reload {
104
113
  }
105
114
  #closed = new Once();
106
115
  #error = new Signal(undefined);
116
+ #redirect = new Signal(undefined);
117
+ // The configured href the redirect was assigned for.
118
+ #redirectHref;
119
+ // A session the peer sent GOAWAY on, serving its groups in flight while the replacement
120
+ // dials. Retired when it closes, at its handover cap, or when the sequence ends.
121
+ #draining;
122
+ // Whether a connect attempt is in flight, so a retiring predecessor reports the right status.
123
+ #dialing = false;
107
124
  // The current wait between attempts, doubling per failure, and when the retry window expires.
108
125
  // Both are undefined between sequences, so a later edit to `delay` applies to the next one.
109
126
  #delay;
@@ -126,6 +143,8 @@ export class Reload {
126
143
  this.url = Signal.from(props?.url);
127
144
  this.enabled = Signal.from(props?.enabled ?? true);
128
145
  this.delay = props?.delay ?? {};
146
+ this.goaway = props?.goaway ?? {};
147
+ this.redirect = this.#redirect;
129
148
  this.webtransport = props?.webtransport;
130
149
  this.websocket = props?.websocket;
131
150
  this.discovery = props?.discovery;
@@ -192,6 +211,7 @@ export class Reload {
192
211
  if (!enabled) {
193
212
  this.#givenUpHref = undefined;
194
213
  this.#resetSequence();
214
+ this.#redirect.set(undefined);
195
215
  return;
196
216
  }
197
217
  // Hide/freeze pauses an in-flight sequence without recovering from give-up.
@@ -204,6 +224,7 @@ export class Reload {
204
224
  if (!href) {
205
225
  this.#givenUpHref = undefined;
206
226
  this.#resetSequence();
227
+ this.#redirect.set(undefined);
207
228
  return;
208
229
  }
209
230
  const url = new URL(href);
@@ -212,42 +233,97 @@ export class Reload {
212
233
  }
213
234
  if (this.#sequenceHref !== href) {
214
235
  this.#resetSequence();
236
+ // A redirect was assigned for another URL; this one starts from itself. A page
237
+ // hide/show resumes the same URL, so it keeps the assignment.
238
+ if (this.#redirectHref !== href)
239
+ this.#redirect.set(undefined);
215
240
  this.#sequenceHref = href;
216
241
  this.#error.set(undefined);
217
242
  this.#givenUpHref = undefined;
218
243
  }
219
- effect.set(this.status, "connecting", "disconnected");
244
+ // A drained predecessor still serves while its replacement dials.
245
+ if (!this.#draining)
246
+ this.status.set("connecting");
220
247
  // This run's teardown, handed to connect() so a rerun cancels the attempt in flight.
221
248
  const signal = effect.abort;
249
+ // The session this run serves, closed with the run. A drained one leaves this slot
250
+ // for #draining, which outlives the run.
251
+ let current;
252
+ effect.cleanup(() => {
253
+ if (current) {
254
+ current.close();
255
+ if (this.established.peek() === current)
256
+ this.established.set(undefined);
257
+ current = undefined;
258
+ }
259
+ if (this.established.peek() === undefined)
260
+ this.status.set("disconnected");
261
+ });
222
262
  effect.spawn(async () => {
223
263
  // Set once the session is live, so #retry can tell a healthy session that
224
264
  // later dropped from a connect failure or a peer that flaps immediately.
225
265
  let connected;
226
266
  try {
227
- const connection = await connect({
228
- url,
229
- websocket: this.websocket,
230
- webtransport: this.webtransport,
231
- discovery: this.discovery,
232
- publish: this.publish,
233
- consume: this.consume,
234
- signal,
235
- });
236
- // Hand the connection to the effect, which closes it now if this run is already over.
237
- effect.cleanup(() => connection.close());
238
- if (signal.aborted)
239
- return;
240
- effect.set(this.established, connection);
241
- effect.set(this.status, "connected", "disconnected");
242
- connected = performance.now();
243
- // A cancelled effect resolves undefined, so the sentinel tells the session
244
- // closing (null for clean, an Error otherwise) apart from this run being
245
- // torn down.
246
- const closed = await effect.race(connection.closed);
247
- if (closed === undefined)
248
- return;
249
- console.warn("connection closed, reconnecting");
250
- this.#retry(effect, connected, closed ?? undefined);
267
+ // Loops only to migrate: a GOAWAY off a healthy session dials its replacement
268
+ // straight away, with no backoff.
269
+ for (;;) {
270
+ const dialing = this.#redirect.peek() ?? url;
271
+ this.#dialing = true;
272
+ let connection;
273
+ try {
274
+ connection = await connect({
275
+ url: dialing,
276
+ // A redirect names the relay; a fallback URL pinned for the old one does not follow.
277
+ websocket: this.#redirect.peek() ? { ...this.websocket, url: undefined } : this.websocket,
278
+ webtransport: this.webtransport,
279
+ discovery: this.discovery,
280
+ publish: this.publish,
281
+ consume: this.consume,
282
+ signal,
283
+ });
284
+ }
285
+ finally {
286
+ this.#dialing = false;
287
+ }
288
+ // Hand the connection to the effect, which closes it now if this run is already over.
289
+ if (signal.aborted) {
290
+ connection.close();
291
+ return;
292
+ }
293
+ current = connection;
294
+ // The replacement serves now; a predecessor keeps draining its groups in flight.
295
+ this.established.set(connection);
296
+ this.status.set("connected");
297
+ connected = performance.now();
298
+ // A cancelled effect resolves undefined, so the sentinel tells the session
299
+ // closing (null for clean, an Error otherwise) apart from this run being
300
+ // torn down. Anything else is the peer's GOAWAY.
301
+ const ended = await effect.race(connection.closed, wireOf(connection).goaway);
302
+ if (ended === undefined)
303
+ return;
304
+ if (ended === null || ended instanceof Error) {
305
+ console.warn("connection closed, reconnecting");
306
+ if (this.established.peek() === connection)
307
+ this.established.set(undefined);
308
+ this.#retry(effect, connected, ended ?? undefined);
309
+ return;
310
+ }
311
+ current = undefined;
312
+ // A pinned WebSocket URL can win the race against the primary. Judge the
313
+ // redirect against that endpoint, not the primary we never reached.
314
+ const socket = this.#redirect.peek() ? undefined : this.websocket?.url;
315
+ if (!this.#migrate(connection, dialed(dialing, connection.transport, socket), ended))
316
+ return;
317
+ // A session that outlived the initial delay was healthy, so its handover is not a
318
+ // failure. One redirected almost at once still migrates, but through the backoff,
319
+ // so two peers bouncing us between them escalate and eventually give up.
320
+ if (performance.now() - connected < this.#initial()) {
321
+ this.#retry(effect, connected, new Error("peer redirected immediately"));
322
+ return;
323
+ }
324
+ this.#delay = undefined;
325
+ this.#deadline = undefined;
326
+ }
251
327
  }
252
328
  catch (err) {
253
329
  // Treat teardown as cancellation, not a connection failure.
@@ -258,6 +334,54 @@ export class Reload {
258
334
  }
259
335
  });
260
336
  }
337
+ /**
338
+ * Act on the peer's GOAWAY for `connection`, which was dialed at `dialing`: resolve where
339
+ * to go next and leave the old session serving until it drains. Returns false when the
340
+ * redirect is refused, which ends the sequence rather than redialing.
341
+ */
342
+ #migrate(connection, dialing, drain) {
343
+ const hashes = this.webtransport?.serverCertificateHashes?.length ?? 0;
344
+ const configured = hashes > 0 || this.webtransport?.serverCertificate !== undefined;
345
+ // The pin is a WebTransport option. A WebSocket that won the race never used it.
346
+ const pinned = pinnedTransport(connection.transport, configured);
347
+ let next;
348
+ try {
349
+ next = target(this.goaway.redirect ?? "same-host", drain.uri, dialing, pinned);
350
+ }
351
+ catch (err) {
352
+ // The peer is leaving and named somewhere we won't go: redialing the old address
353
+ // would ignore it, so stop here.
354
+ console.warn("GOAWAY redirect refused:", err);
355
+ connection.close();
356
+ this.established.set(undefined);
357
+ this.status.set("disconnected");
358
+ this.#giveUp(error(err));
359
+ return false;
360
+ }
361
+ // Only an accepted redirect replaces the URL; an empty one keeps it.
362
+ if (next) {
363
+ this.#redirect.set(next);
364
+ this.#redirectHref = this.#sequenceHref;
365
+ }
366
+ console.info("GOAWAY received; migrating");
367
+ // A newer GOAWAY retires an older predecessor rather than holding two open.
368
+ this.#draining?.retire();
369
+ const cap = handover(this.goaway.handover ?? DEFAULT_HANDOVER, drain.timeout);
370
+ const draining = new Draining(connection, cap, () => {
371
+ if (this.#draining === draining)
372
+ this.#draining = undefined;
373
+ // If nothing replaced it yet, nothing is serving.
374
+ if (this.established.peek() !== connection)
375
+ return;
376
+ this.established.set(undefined);
377
+ this.status.set(this.#dialing ? "connecting" : "disconnected");
378
+ });
379
+ this.#draining = draining;
380
+ return true;
381
+ }
382
+ #initial() {
383
+ return this.delay?.initial ?? DEFAULT_DELAY.initial;
384
+ }
261
385
  /**
262
386
  * Schedule the next connect attempt after the current backoff, or stop once the retry window
263
387
  * has expired. `connected` is when the dead session was established, if it ever was, and
@@ -270,14 +394,14 @@ export class Reload {
270
394
  // optional value passes an explicit undefined, which a spread would take as the
271
395
  // answer, turning the backoff into NaN or the window into forever.
272
396
  const delay = this.delay ?? {};
273
- const initial = delay.initial ?? DEFAULT_DELAY.initial;
397
+ const initial = this.#initial();
274
398
  const multiplier = delay.multiplier ?? DEFAULT_DELAY.multiplier;
275
399
  const max = delay.max ?? DEFAULT_DELAY.max;
276
400
  const timeout = delay.timeout ?? DEFAULT_DELAY.timeout;
277
- // Any session is dead now: report disconnected during the backoff rather than
278
- // when the retry reruns the effect.
279
- this.established.set(undefined);
280
- this.status.set("disconnected");
401
+ // Report disconnected during the backoff rather than when the retry reruns the
402
+ // effect, unless a drained predecessor still serves until it retires.
403
+ if (this.established.peek() === undefined)
404
+ this.status.set("disconnected");
281
405
  // A session that outlived the initial delay was healthy, so clear the backoff and
282
406
  // start a fresh retry window: a one-off drop should reconnect promptly. Anything
283
407
  // shorter is a peer that accepts and immediately severs, which has to keep
@@ -325,6 +449,7 @@ export class Reload {
325
449
  this.#delay = undefined;
326
450
  this.#deadline = undefined;
327
451
  this.#sequenceHref = undefined;
452
+ this.#draining?.retire();
328
453
  }
329
454
  /**
330
455
  * Subscribe to broadcast announcements matching `scope`, spanning reconnects.
@@ -397,8 +522,37 @@ export class Reload {
397
522
  /** Stop reconnecting, close the current connection, and settle {@link Reload.closed}. Idempotent. */
398
523
  close(abort) {
399
524
  this.#signals.close();
525
+ this.#draining?.retire();
400
526
  if (this.#closed.peek() === undefined)
401
527
  this.#closed.set(abort ?? null);
402
528
  }
403
529
  }
530
+ /**
531
+ * A session the peer sent GOAWAY on, left serving so its groups in flight finish. It retires
532
+ * when it closes on its own or overstays its handover window, and `onRetire` runs once either way.
533
+ */
534
+ class Draining {
535
+ #connection;
536
+ #timer;
537
+ #onRetire;
538
+ #retired = false;
539
+ constructor(connection, handover, onRetire) {
540
+ this.#connection = connection;
541
+ this.#onRetire = onRetire;
542
+ this.#timer = setTimeout(() => {
543
+ console.warn("old session did not drain in time; closing");
544
+ this.retire();
545
+ }, handover);
546
+ void connection.closed.then(() => this.retire());
547
+ }
548
+ /** Close the old session now, whatever remains of its window. Idempotent. */
549
+ retire() {
550
+ if (this.#retired)
551
+ return;
552
+ this.#retired = true;
553
+ clearTimeout(this.#timer);
554
+ this.#connection.close();
555
+ this.#onRetire();
556
+ }
557
+ }
404
558
  //# sourceMappingURL=reload.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"reload.js","sourceRoot":"","sources":["../../src/connection/reload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAgC,IAAI,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAClF,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE/D,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,EAAqB,OAAO,EAA+C,MAAM,cAAc,CAAC;AAuDvG;;;;;;;;GAQG;AACH,MAAM,aAAa,GAA0B;IAC5C,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;IACzB,UAAU,EAAE,CAAC;IACb,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;IACrB,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC;CAC1B,CAAC;AAEF,2EAA2E;AAC3E,MAAM,cAAc,GAAG,GAAG,CAAC;AAK3B;;;;;GAKG;AACH,MAAM,OAAO,MAAM;IAClB,iEAAiE;IACjE,GAAG,CAA0B;IAE7B,sCAAsC;IACtC,OAAO,CAAkB;IAEzB,iCAAiC;IACjC,MAAM,GAAG,IAA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ACF,CAAC;gBAAC,MAAM,CAAC;oBACR,mFAAmF;gBACpF,CAAC;wBAAS,CAAC;oBACV,iFAAiF;oBACjF,4DAA4D;oBAC5D,IAAI,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,SAAS,EAAE,CAAC;wBAC1C,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC;4BACrC,QAAQ,CAAC,MAAM,CAAC,EAAE,GAAG,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC;wBAClD,CAAC;oBACF,CAAC;gBACF,CAAC;YACF,CAAC,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;QAC1C,KAAK,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;QAE9C,OAAO,QAAQ,CAAC;IACjB,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,KAAK;QACV,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC;IACzC,CAAC;IAED,qGAAqG;IACrG,KAAK,CAAC,KAAa;QAClB,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACtB,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,SAAS;YAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC;IACxE,CAAC;CACD","sourcesContent":["import { Effect, type GetPromise, type Getter, Once, Signal } from \"@moq/signals\";\nimport * as Announce from \"../announced.ts\";\nimport { Allocator } from \"../bandwidth.ts\";\nimport { error, SessionCode, SessionError } from \"../error.ts\";\nimport type { Consumer as OriginConsumer, Producer as OriginProducer } from \"../origin.ts\";\nimport * as Path from \"../path.ts\";\nimport * as Time from \"../time.ts\";\nimport { wireOf } from \"../wire.ts\";\nimport { type ConnectProps, connect, type WebSocketProps, type WebTransportProps } from \"./connect.ts\";\nimport type { Established } from \"./established.ts\";\nimport type { Probe, Stats } from \"./stats.ts\";\n\n/**\n * Exponential backoff settings for the reconnect loop.\n *\n * The delays carry jitter, so a fleet of tabs knocked offline together doesn't reconnect in\n * lockstep. Every failure is retried; {@link ReloadDelay.timeout} is what stops the current\n * URL. A new URL or a disable/re-enable starts another sequence.\n */\nexport type ReloadDelay = {\n\t/** The delay before reconnecting (default: 1000ms). */\n\tinitial?: Time.Milli;\n\n\t/** The multiplier for the delay (default: 2). */\n\tmultiplier?: number;\n\n\t/** The maximum delay (default: 5000ms). */\n\tmax?: Time.Milli;\n\n\t/**\n\t * Maximum total time to spend retrying the current URL before giving up\n\t * (default: 10000ms). Resets after each successful connection, a URL change, or a\n\t * disable/re-enable. Set to 0 for unlimited retries.\n\t */\n\ttimeout?: Time.Milli;\n};\n\n/**\n * Connection and retry options for {@link Reload}.\n *\n * {@link ConnectProps.transport} is excluded: a supplied session is good for exactly one\n * connection, so the reconnect loop has nothing to reuse once that session drops. Call\n * {@link connect} directly when you have a session to hand over.\n *\n * @internal\n */\nexport type ReloadProps = Omit<ConnectProps, \"url\" | \"signal\" | \"transport\"> & {\n\t/** A reload owns the abort signal for each connection attempt. */\n\tsignal?: never;\n\n\t/** A one-shot transport cannot be reused by the reconnect loop. */\n\ttransport?: never;\n\n\t/** Whether to reload the connection when it disconnects (default: true). */\n\tenabled?: boolean | Signal<boolean>;\n\n\t/** The URL of the relay server. */\n\turl?: URL | Signal<URL | undefined>;\n\n\t/** Backoff settings for the reconnect loop; every field falls back to its default. */\n\tdelay?: ReloadDelay;\n};\n\n/**\n * The backoff applied to whichever {@link ReloadDelay} fields a caller leaves out.\n *\n * The timeout is short on purpose: a failure that clears within it was transient, and one that\n * doesn't should surface on {@link Reload.error} rather than leave the page silently\n * reconnecting for minutes. A loop nobody watches wants `timeout: 0` instead, since there is\n * no one to react. Giving up does not dispose the loop: a new URL or a disable/re-enable\n * starts another sequence.\n */\nconst DEFAULT_DELAY: Required<ReloadDelay> = {\n\tinitial: Time.Milli(1000),\n\tmultiplier: 2,\n\tmax: Time.Milli(5000),\n\ttimeout: Time.Milli(10000),\n};\n\n/** How often the send-rate estimate is sampled from the live transport. */\nconst BANDWIDTH_POLL = 100;\n\n/** Current state of a reconnecting connection. */\nexport type ReloadStatus = \"connecting\" | \"connected\" | \"disconnected\";\n\n/**\n * The reconnect loop behind a Connection handle: connects, waits for the session to end, then\n * redials with exponential backoff.\n *\n * @internal\n */\nexport class Reload {\n\t/** Relay URL to connect to; updating it triggers a reconnect. */\n\turl: Signal<URL | undefined>;\n\n\t/** Whether reconnecting is active. */\n\tenabled: Signal<boolean>;\n\n\t/** Current connection status. */\n\tstatus = new Signal<ReloadStatus>(\"disconnected\");\n\n\t/**\n\t * The failure that stopped retrying the current URL, or undefined while the loop is live.\n\t *\n\t * Set on an auth rejection or when the retry window expires. Cleared when a new URL or a\n\t * disable/re-enable starts another sequence, not on a page hide/show. Transient drops\n\t * that are still being retried leave this empty.\n\t */\n\treadonly error: Getter<Error | undefined>;\n\n\t/** The currently established session, or undefined while disconnected. */\n\testablished = new Signal<Established | undefined>(undefined);\n\n\t/**\n\t * The current connection's PROBE estimates, spanning reconnects.\n\t *\n\t * Undefined while disconnected: the estimates belong to a single connection.\n\t * See {@link Established.probe}.\n\t */\n\treadonly probe: Getter<Probe | undefined>;\n\n\t/**\n\t * Divides this connection's send-rate estimate among the tracks sharing it.\n\t *\n\t * The same instance across reconnects, so reservations survive a drop. The\n\t * estimate is `undefined` while disconnected, which tells a sender to hold\n\t * its rate rather than encode at zero.\n\t */\n\treadonly bandwidth: Allocator;\n\n\t/** WebTransport options applied to each connection attempt (not reactive). */\n\twebtransport?: WebTransportProps;\n\n\t/** WebSocket fallback options applied to each connection attempt (not reactive). */\n\twebsocket: WebSocketProps | undefined;\n\n\t/**\n\t * Whether the relay supports broadcast discovery, applied to each connection attempt (not\n\t * reactive). Undefined defers to the default for the URL. See {@link Established.discovery}.\n\t */\n\tdiscovery?: boolean;\n\n\t/**\n\t * The origin whose broadcasts are served, spanning reconnects (not reactive).\n\t *\n\t * Each session announces the origin's table when it attaches, so a broadcast published\n\t * while offline surfaces on the next connection and a reconnect re-announces everything\n\t * still published. See the `publish` connect option.\n\t */\n\tpublish?: OriginConsumer;\n\n\t/**\n\t * The origin fed with the peer's announced broadcasts, spanning reconnects (not\n\t * reactive).\n\t *\n\t * The entries a session fed retract when it dies, and the next session re-populates the\n\t * table, so a consumer watching the origin sees offline/online transitions across a\n\t * reconnect. See the `consume` connect option.\n\t */\n\tconsume?: OriginProducer;\n\n\t/** Backoff settings for the reconnect loop; an unset field uses its default. */\n\tdelay: ReloadDelay;\n\n\t/** The reactive effect scope driving the connect loop; closed by {@link Reload.close}. */\n\t#signals = new Effect();\n\n\t// Sampled from the live session; undefined while disconnected or the transport has none.\n\t#estimate = new Signal<number | undefined>(undefined);\n\n\t/**\n\t * Settles once this loop is disposed via {@link Reload.close}: `null` on a clean close,\n\t * or the abort {@link Error}. Peek it synchronously (`undefined` while open), observe it\n\t * reactively, or `await` it. Attempt failures live on {@link Reload.error} instead.\n\t */\n\tget closed(): GetPromise<Error | null> {\n\t\treturn this.#closed;\n\t}\n\n\t#closed = new Once<Error | null>();\n\t#error = new Signal<Error | undefined>(undefined);\n\n\t// The current wait between attempts, doubling per failure, and when the retry window expires.\n\t// Both are undefined between sequences, so a later edit to `delay` applies to the next one.\n\t#delay: DOMHighResTimeStamp | undefined;\n\t#deadline: DOMHighResTimeStamp | undefined;\n\n\t// The URL the current retry sequence is for. Cleared when disabled, URL-less, or given\n\t// up, so the next attempt starts a fresh backoff window.\n\t#sequenceHref: string | undefined;\n\n\t// The href that exhausted its retry sequence. Survives a page hide/show so resume does\n\t// not redial credentials the peer already refused. Cleared when the URL changes or the\n\t// loop is disabled.\n\t#givenUpHref: string | undefined;\n\n\t// Increased by 1 each time to trigger a reload.\n\t#tick = new Signal(0);\n\n\t// True after the browser freezes or hides the page until it visibly resumes.\n\t#suspended = new Signal(false);\n\n\t// Use the serialized URL as the reactive connection key. URL objects use identity\n\t// equality, but replacing one with an equivalent instance should not reconnect.\n\t#url: Getter<string | undefined>;\n\tconstructor(props?: ReloadProps) {\n\t\tthis.url = Signal.from(props?.url);\n\t\tthis.enabled = Signal.from(props?.enabled ?? true);\n\t\tthis.delay = props?.delay ?? {};\n\t\tthis.webtransport = props?.webtransport;\n\t\tthis.websocket = props?.websocket;\n\t\tthis.discovery = props?.discovery;\n\t\tthis.publish = props?.publish;\n\t\tthis.consume = props?.consume;\n\n\t\t// Requests on the consume origin stay pending across a reconnect, and before the\n\t\t// first session establishes, rather than reading as unroutable the moment no session\n\t\t// is attached. Released only when this loop is disposed: giving up the current URL\n\t\t// is recoverable (a new URL or a disable/re-enable starts another sequence), so a\n\t\t// request must keep waiting rather than go unroutable in the gap.\n\t\tif (this.consume) {\n\t\t\tthis.#signals.cleanup(wireOf(this.consume).expect());\n\t\t}\n\n\t\tthis.error = this.#error;\n\n\t\tconst win = globalThis.window;\n\t\tconst doc = globalThis.document;\n\t\tif (typeof win !== \"undefined\" && typeof doc !== \"undefined\") {\n\t\t\tthis.#signals.event(win, \"pagehide\", () => this.#suspended.set(true));\n\t\t\tthis.#signals.event(win, \"pageshow\", () => this.#suspended.set(false));\n\t\t\tthis.#signals.event(win, \"unload\", () => this.#suspended.set(true));\n\t\t\tthis.#signals.event(doc, \"visibilitychange\", () => {\n\t\t\t\tif (!doc.hidden) this.#suspended.set(false);\n\t\t\t});\n\t\t}\n\n\t\tthis.probe = this.#signals.computed((effect) => {\n\t\t\tconst connection = effect.get(this.established);\n\t\t\treturn connection && effect.get(connection.probe);\n\t\t});\n\n\t\tthis.bandwidth = new Allocator(this.#estimate);\n\t\tthis.#signals.cleanup(() => this.bandwidth.close());\n\n\t\t// The transport has no event for the send-rate estimate, so sample on our\n\t\t// own schedule and skip a tick while the previous snapshot is outstanding.\n\t\tthis.#signals.run((effect) => {\n\t\t\teffect.set(this.#estimate, undefined);\n\t\t\tconst connection = effect.get(this.established);\n\t\t\tif (!connection) return;\n\n\t\t\tlet pending = false;\n\t\t\tconst sample = async () => {\n\t\t\t\tif (pending) return;\n\t\t\t\tpending = true;\n\t\t\t\ttry {\n\t\t\t\t\tconst stats = await effect.race(connection.stats());\n\t\t\t\t\tif (stats) this.#estimate.set(stats.estimatedSendRate);\n\t\t\t\t} finally {\n\t\t\t\t\tpending = false;\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tvoid sample();\n\t\t\teffect.interval(() => void sample(), BANDWIDTH_POLL);\n\t\t});\n\n\t\tthis.#url = this.#signals.computed((effect) => effect.get(this.url)?.href);\n\t\t// Create a reactive root so cleanup is easier.\n\t\tthis.#signals.run(this.#connect.bind(this));\n\t}\n\n\t#connect(effect: Effect): void {\n\t\t// Will retry when the tick changes.\n\t\teffect.get(this.#tick);\n\n\t\tconst enabled = effect.get(this.enabled);\n\t\tif (!enabled) {\n\t\t\tthis.#givenUpHref = undefined;\n\t\t\tthis.#resetSequence();\n\t\t\treturn;\n\t\t}\n\n\t\t// Hide/freeze pauses an in-flight sequence without recovering from give-up.\n\t\tconst suspended = effect.get(this.#suspended);\n\t\tif (suspended) {\n\t\t\tthis.#resetSequence();\n\t\t\treturn;\n\t\t}\n\n\t\tconst href = effect.get(this.#url);\n\t\tif (!href) {\n\t\t\tthis.#givenUpHref = undefined;\n\t\t\tthis.#resetSequence();\n\t\t\treturn;\n\t\t}\n\t\tconst url = new URL(href);\n\n\t\tif (this.#givenUpHref === href) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.#sequenceHref !== href) {\n\t\t\tthis.#resetSequence();\n\t\t\tthis.#sequenceHref = href;\n\t\t\tthis.#error.set(undefined);\n\t\t\tthis.#givenUpHref = undefined;\n\t\t}\n\n\t\teffect.set(this.status, \"connecting\", \"disconnected\");\n\n\t\t// This run's teardown, handed to connect() so a rerun cancels the attempt in flight.\n\t\tconst signal = effect.abort;\n\n\t\teffect.spawn(async () => {\n\t\t\t// Set once the session is live, so #retry can tell a healthy session that\n\t\t\t// later dropped from a connect failure or a peer that flaps immediately.\n\t\t\tlet connected: DOMHighResTimeStamp | undefined;\n\n\t\t\ttry {\n\t\t\t\tconst connection = await connect({\n\t\t\t\t\turl,\n\t\t\t\t\twebsocket: this.websocket,\n\t\t\t\t\twebtransport: this.webtransport,\n\t\t\t\t\tdiscovery: this.discovery,\n\t\t\t\t\tpublish: this.publish,\n\t\t\t\t\tconsume: this.consume,\n\t\t\t\t\tsignal,\n\t\t\t\t});\n\n\t\t\t\t// Hand the connection to the effect, which closes it now if this run is already over.\n\t\t\t\teffect.cleanup(() => connection.close());\n\t\t\t\tif (signal.aborted) return;\n\n\t\t\t\teffect.set(this.established, connection);\n\t\t\t\teffect.set(this.status, \"connected\", \"disconnected\");\n\n\t\t\t\tconnected = performance.now();\n\n\t\t\t\t// A cancelled effect resolves undefined, so the sentinel tells the session\n\t\t\t\t// closing (null for clean, an Error otherwise) apart from this run being\n\t\t\t\t// torn down.\n\t\t\t\tconst closed = await effect.race(connection.closed);\n\t\t\t\tif (closed === undefined) return;\n\n\t\t\t\tconsole.warn(\"connection closed, reconnecting\");\n\t\t\t\tthis.#retry(effect, connected, closed ?? undefined);\n\t\t\t} catch (err) {\n\t\t\t\t// Treat teardown as cancellation, not a connection failure.\n\t\t\t\tif (signal.aborted) return;\n\n\t\t\t\tconsole.warn(\"connection error:\", err);\n\t\t\t\tthis.#retry(effect, connected, err);\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Schedule the next connect attempt after the current backoff, or stop once the retry window\n\t * has expired. `connected` is when the dead session was established, if it ever was, and\n\t * `cause` the error that killed it, if it died with one.\n\t */\n\t#retry(effect: Effect, connected: DOMHighResTimeStamp | undefined, cause?: unknown): void {\n\t\t// Resolved per sequence rather than at construction, so an edit to `delay` (including\n\t\t// one that drops a field back to its default) applies to the next retry. Field by\n\t\t// field rather than by spread: a caller building `{ initial: maybeInitial }` from an\n\t\t// optional value passes an explicit undefined, which a spread would take as the\n\t\t// answer, turning the backoff into NaN or the window into forever.\n\t\tconst delay = this.delay ?? {};\n\t\tconst initial = delay.initial ?? DEFAULT_DELAY.initial;\n\t\tconst multiplier = delay.multiplier ?? DEFAULT_DELAY.multiplier;\n\t\tconst max = delay.max ?? DEFAULT_DELAY.max;\n\t\tconst timeout = delay.timeout ?? DEFAULT_DELAY.timeout;\n\n\t\t// Any session is dead now: report disconnected during the backoff rather than\n\t\t// when the retry reruns the effect.\n\t\tthis.established.set(undefined);\n\t\tthis.status.set(\"disconnected\");\n\n\t\t// A session that outlived the initial delay was healthy, so clear the backoff and\n\t\t// start a fresh retry window: a one-off drop should reconnect promptly. Anything\n\t\t// shorter is a peer that accepts and immediately severs, which has to keep\n\t\t// escalating or we hammer it forever at the initial delay.\n\t\tif (connected !== undefined && performance.now() - connected >= initial) {\n\t\t\tthis.#delay = undefined;\n\t\t\tthis.#deadline = undefined;\n\t\t}\n\n\t\t// An auth rejection stops this URL however long the session lived. UNAUTHORIZED is a\n\t\t// specified code rather than one we guessed at, so this is the peer saying these\n\t\t// credentials will never work; retrying them just burns the window. Matches\n\t\t// moq-tokio's reconnect loop, which stops on the same close. A new URL or a\n\t\t// disable/re-enable starts another sequence; the handle itself is not disposed.\n\t\t//\n\t\t// Only a session close says that. The stream registry gives 2 to DELIVERY_TIMEOUT,\n\t\t// so a stream reset during the SETUP exchange would otherwise suppress reconnect\n\t\t// for good.\n\t\tif (cause instanceof SessionError && cause.code === SessionCode.Unauthorized) {\n\t\t\tconsole.warn(\"session rejected as unauthorized, not retrying\");\n\t\t\tthis.#giveUp(cause);\n\t\t\treturn;\n\t\t}\n\n\t\tconst now = performance.now();\n\t\tthis.#delay ??= initial;\n\t\tthis.#deadline ??= timeout > 0 ? now + timeout : Number.POSITIVE_INFINITY;\n\n\t\tif (now >= this.#deadline) {\n\t\t\tconsole.warn(\"reconnect timed out\");\n\t\t\t// A graceful close has no error, so report the timeout itself.\n\t\t\tthis.#giveUp(cause === undefined ? new Error(\"reconnect timed out\") : error(cause));\n\t\t\treturn;\n\t\t}\n\n\t\t// Equal jitter, so a fleet of tabs knocked offline together doesn't reconnect on the same\n\t\t// tick, and never past the deadline the retry window promised.\n\t\tconst wait = Math.min(this.#delay * (0.5 + Math.random() / 2), this.#deadline - now);\n\t\tthis.#delay = Math.min(this.#delay * multiplier, max);\n\n\t\tconst tick = this.#tick.peek() + 1;\n\t\teffect.timer(() => this.#tick.update((prev) => Math.max(prev, tick)), wait);\n\t}\n\n\t#giveUp(cause: Error): void {\n\t\tthis.#error.set(cause);\n\t\tthis.#givenUpHref = this.#sequenceHref;\n\t\tthis.#resetSequence();\n\t}\n\n\t#resetSequence(): void {\n\t\tthis.#delay = undefined;\n\t\tthis.#deadline = undefined;\n\t\tthis.#sequenceHref = undefined;\n\t}\n\n\t/**\n\t * Subscribe to broadcast announcements matching `scope`, spanning reconnects.\n\t *\n\t * The same {@link Announce.Consumer} stream as {@link Established.announced}, but everything active\n\t * is retracted (a `retracted` update) whenever the connection drops and re-announced on\n\t * reconnect, so a consumer draining `next()` never clings to a dead route across a reconnect.\n\t *\n\t * Stays empty while the relay lacks {@link Established.discovery}.\n\t */\n\tannounced(scope: Path.Pattern = Path.Pattern.all(), options?: Announce.Options): Announce.Consumer {\n\t\t// With a consume origin the table already spans reconnects (the forwarder retracts\n\t\t// a dead session's entries), so its stream is the same thing with less machinery.\n\t\tif (this.consume) return this.consume.announced(scope, options);\n\n\t\tconst producer = new Announce.Producer();\n\t\tconst consumer = producer.consume();\n\n\t\tconst pump = new Effect();\n\t\tpump.run((effect) => {\n\t\t\tconst conn = effect.get(this.established);\n\t\t\tif (!conn) return;\n\n\t\t\t// Without discovery the upstream announce stream never yields, so leave the\n\t\t\t// consumer empty rather than opening a subscription that can't be answered.\n\t\t\tif (!conn.discovery) return;\n\n\t\t\tconst upstream = conn.announced(scope, options);\n\t\t\teffect.cleanup(() => upstream.close());\n\n\t\t\t// Track what this connection announced so we can retract it if the connection\n\t\t\t// drops; the last event rides along for the retraction.\n\t\t\tconst active = new Map<Path.Valid, Announce.Update>();\n\n\t\t\teffect.spawn(async () => {\n\t\t\t\ttry {\n\t\t\t\t\tfor (;;) {\n\t\t\t\t\t\tconst entry = await effect.race(upstream.next());\n\t\t\t\t\t\tif (!entry) break;\n\t\t\t\t\t\tif (Announce.isActive(entry.kind)) active.set(entry.prefix, entry);\n\t\t\t\t\t\telse active.delete(entry.prefix);\n\t\t\t\t\t\tproducer.append(entry);\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\t// A dropped connection resets the announce stream; the retractions below cover it.\n\t\t\t\t} finally {\n\t\t\t\t\t// Retract everything from the connection that just went away, so a per-broadcast\n\t\t\t\t\t// watcher tears down instead of clinging to the dead route.\n\t\t\t\t\tif (consumer.closed.peek() === undefined) {\n\t\t\t\t\t\tfor (const entry of active.values()) {\n\t\t\t\t\t\t\tproducer.append({ ...entry, kind: \"retracted\" });\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\n\t\tthis.#signals.cleanup(() => pump.close());\n\t\tvoid consumer.closed.then(() => pump.close());\n\n\t\treturn consumer;\n\t}\n\n\t/**\n\t * Snapshot the live connection's transport counters, or undefined while disconnected.\n\t * See {@link Established.stats}.\n\t */\n\tasync stats(): Promise<Stats | undefined> {\n\t\treturn this.established.peek()?.stats();\n\t}\n\n\t/** Stop reconnecting, close the current connection, and settle {@link Reload.closed}. Idempotent. */\n\tclose(abort?: Error) {\n\t\tthis.#signals.close();\n\t\tif (this.#closed.peek() === undefined) this.#closed.set(abort ?? null);\n\t}\n}\n"]}
1
+ {"version":3,"file":"reload.js","sourceRoot":"","sources":["../../src/connection/reload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAgC,IAAI,EAAE,MAAM,EAAE,MAAM,cA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Announce from \"../announced.ts\";\nimport { Allocator } from \"../bandwidth.ts\";\nimport { error, SessionCode, SessionError } from \"../error.ts\";\nimport type { Consumer as OriginConsumer, Producer as OriginProducer } from \"../origin.ts\";\nimport * as Path from \"../path.ts\";\nimport * as Time from \"../time.ts\";\nimport { wireOf } from \"../wire.ts\";\nimport { type ConnectProps, connect, type WebSocketProps, type WebTransportProps } from \"./connect.ts\";\nimport type { Established } from \"./established.ts\";\nimport { DEFAULT_HANDOVER, type Drain, dialed, type GoawayProps, handover, pinnedTransport, target } from \"./goaway.ts\";\nimport type { Probe, Stats } from \"./stats.ts\";\n\n/**\n * Exponential backoff settings for the reconnect loop.\n *\n * The delays carry jitter, so a fleet of tabs knocked offline together doesn't reconnect in\n * lockstep. Every failure is retried; {@link ReloadDelay.timeout} is what stops the current\n * URL. A new URL or a disable/re-enable starts another sequence.\n */\nexport type ReloadDelay = {\n\t/** The delay before reconnecting (default: 1000ms). */\n\tinitial?: Time.Milli;\n\n\t/** The multiplier for the delay (default: 2). */\n\tmultiplier?: number;\n\n\t/** The maximum delay (default: 5000ms). */\n\tmax?: Time.Milli;\n\n\t/**\n\t * Maximum total time to spend retrying the current URL before giving up\n\t * (default: 10000ms). Resets after each successful connection, a URL change, or a\n\t * disable/re-enable. Set to 0 for unlimited retries.\n\t */\n\ttimeout?: Time.Milli;\n};\n\n/**\n * Connection and retry options for {@link Reload}.\n *\n * {@link ConnectProps.transport} is excluded: a supplied session is good for exactly one\n * connection, so the reconnect loop has nothing to reuse once that session drops. Call\n * {@link connect} directly when you have a session to hand over.\n *\n * @internal\n */\nexport type ReloadProps = Omit<ConnectProps, \"url\" | \"signal\" | \"transport\"> & {\n\t/** A reload owns the abort signal for each connection attempt. */\n\tsignal?: never;\n\n\t/** A one-shot transport cannot be reused by the reconnect loop. */\n\ttransport?: never;\n\n\t/** Whether to reload the connection when it disconnects (default: true). */\n\tenabled?: boolean | Signal<boolean>;\n\n\t/** The URL of the relay server. */\n\turl?: URL | Signal<URL | undefined>;\n\n\t/** Backoff settings for the reconnect loop; every field falls back to its default. */\n\tdelay?: ReloadDelay;\n\n\t/** How to react to the peer's GOAWAY; every field falls back to its default. */\n\tgoaway?: GoawayProps;\n};\n\n/**\n * The backoff applied to whichever {@link ReloadDelay} fields a caller leaves out.\n *\n * The timeout is short on purpose: a failure that clears within it was transient, and one that\n * doesn't should surface on {@link Reload.error} rather than leave the page silently\n * reconnecting for minutes. A loop nobody watches wants `timeout: 0` instead, since there is\n * no one to react. Giving up does not dispose the loop: a new URL or a disable/re-enable\n * starts another sequence.\n */\nconst DEFAULT_DELAY: Required<ReloadDelay> = {\n\tinitial: Time.Milli(1000),\n\tmultiplier: 2,\n\tmax: Time.Milli(5000),\n\ttimeout: Time.Milli(10000),\n};\n\n/** How often the send-rate estimate is sampled from the live transport. */\nconst BANDWIDTH_POLL = 100;\n\n/** Current state of a reconnecting connection. */\nexport type ReloadStatus = \"connecting\" | \"connected\" | \"disconnected\";\n\n/**\n * The reconnect loop behind a Connection handle: connects, waits for the session to end, then\n * redials with exponential backoff.\n *\n * @internal\n */\nexport class Reload {\n\t/** Relay URL to connect to; updating it triggers a reconnect. */\n\turl: Signal<URL | undefined>;\n\n\t/** Whether reconnecting is active. */\n\tenabled: Signal<boolean>;\n\n\t/** Current connection status. */\n\tstatus = new Signal<ReloadStatus>(\"disconnected\");\n\n\t/**\n\t * The failure that stopped retrying the current URL, or undefined while the loop is live.\n\t *\n\t * Set on an auth rejection or when the retry window expires. Cleared when a new URL or a\n\t * disable/re-enable starts another sequence, not on a page hide/show. Transient drops\n\t * that are still being retried leave this empty.\n\t */\n\treadonly error: Getter<Error | undefined>;\n\n\t/** The currently established session, or undefined while disconnected. */\n\testablished = new Signal<Established | undefined>(undefined);\n\n\t/**\n\t * The current connection's PROBE estimates, spanning reconnects.\n\t *\n\t * Undefined while disconnected: the estimates belong to a single connection.\n\t * See {@link Established.probe}.\n\t */\n\treadonly probe: Getter<Probe | undefined>;\n\n\t/**\n\t * Divides this connection's send-rate estimate among the tracks sharing it.\n\t *\n\t * The same instance across reconnects, so reservations survive a drop. The\n\t * estimate is `undefined` while disconnected, which tells a sender to hold\n\t * its rate rather than encode at zero.\n\t */\n\treadonly bandwidth: Allocator;\n\n\t/** WebTransport options applied to each connection attempt (not reactive). */\n\twebtransport?: WebTransportProps;\n\n\t/** WebSocket fallback options applied to each connection attempt (not reactive). */\n\twebsocket: WebSocketProps | undefined;\n\n\t/**\n\t * Whether the relay supports broadcast discovery, applied to each connection attempt (not\n\t * reactive). Undefined defers to the default for the URL. See {@link Established.discovery}.\n\t */\n\tdiscovery?: boolean;\n\n\t/**\n\t * The origin whose broadcasts are served, spanning reconnects (not reactive).\n\t *\n\t * Each session announces the origin's table when it attaches, so a broadcast published\n\t * while offline surfaces on the next connection and a reconnect re-announces everything\n\t * still published. See the `publish` connect option.\n\t */\n\tpublish?: OriginConsumer;\n\n\t/**\n\t * The origin fed with the peer's announced broadcasts, spanning reconnects (not\n\t * reactive).\n\t *\n\t * The entries a session fed retract when it dies, and the next session re-populates the\n\t * table, so a consumer watching the origin sees offline/online transitions across a\n\t * reconnect. See the `consume` connect option.\n\t */\n\tconsume?: OriginProducer;\n\n\t/** Backoff settings for the reconnect loop; an unset field uses its default. */\n\tdelay: ReloadDelay;\n\n\t/** How to react to the peer's GOAWAY (not reactive). */\n\tgoaway: GoawayProps;\n\n\t/**\n\t * The URL an accepted GOAWAY redirect assigned, or undefined while the loop dials\n\t * {@link Reload.url}. Sticky across reconnects: a redirect is an assignment, not a\n\t * detour. Cleared when a new URL or a disable/re-enable starts another sequence.\n\t */\n\treadonly redirect: Getter<URL | undefined>;\n\n\t/** The reactive effect scope driving the connect loop; closed by {@link Reload.close}. */\n\t#signals = new Effect();\n\n\t// Sampled from the live session; undefined while disconnected or the transport has none.\n\t#estimate = new Signal<number | undefined>(undefined);\n\n\t/**\n\t * Settles once this loop is disposed via {@link Reload.close}: `null` on a clean close,\n\t * or the abort {@link Error}. Peek it synchronously (`undefined` while open), observe it\n\t * reactively, or `await` it. Attempt failures live on {@link Reload.error} instead.\n\t */\n\tget closed(): GetPromise<Error | null> {\n\t\treturn this.#closed;\n\t}\n\n\t#closed = new Once<Error | null>();\n\t#error = new Signal<Error | undefined>(undefined);\n\t#redirect = new Signal<URL | undefined>(undefined);\n\t// The configured href the redirect was assigned for.\n\t#redirectHref: string | undefined;\n\n\t// A session the peer sent GOAWAY on, serving its groups in flight while the replacement\n\t// dials. Retired when it closes, at its handover cap, or when the sequence ends.\n\t#draining: Draining | undefined;\n\n\t// Whether a connect attempt is in flight, so a retiring predecessor reports the right status.\n\t#dialing = false;\n\n\t// The current wait between attempts, doubling per failure, and when the retry window expires.\n\t// Both are undefined between sequences, so a later edit to `delay` applies to the next one.\n\t#delay: DOMHighResTimeStamp | undefined;\n\t#deadline: DOMHighResTimeStamp | undefined;\n\n\t// The URL the current retry sequence is for. Cleared when disabled, URL-less, or given\n\t// up, so the next attempt starts a fresh backoff window.\n\t#sequenceHref: string | undefined;\n\n\t// The href that exhausted its retry sequence. Survives a page hide/show so resume does\n\t// not redial credentials the peer already refused. Cleared when the URL changes or the\n\t// loop is disabled.\n\t#givenUpHref: string | undefined;\n\n\t// Increased by 1 each time to trigger a reload.\n\t#tick = new Signal(0);\n\n\t// True after the browser freezes or hides the page until it visibly resumes.\n\t#suspended = new Signal(false);\n\n\t// Use the serialized URL as the reactive connection key. URL objects use identity\n\t// equality, but replacing one with an equivalent instance should not reconnect.\n\t#url: Getter<string | undefined>;\n\tconstructor(props?: ReloadProps) {\n\t\tthis.url = Signal.from(props?.url);\n\t\tthis.enabled = Signal.from(props?.enabled ?? true);\n\t\tthis.delay = props?.delay ?? {};\n\t\tthis.goaway = props?.goaway ?? {};\n\t\tthis.redirect = this.#redirect;\n\t\tthis.webtransport = props?.webtransport;\n\t\tthis.websocket = props?.websocket;\n\t\tthis.discovery = props?.discovery;\n\t\tthis.publish = props?.publish;\n\t\tthis.consume = props?.consume;\n\n\t\t// Requests on the consume origin stay pending across a reconnect, and before the\n\t\t// first session establishes, rather than reading as unroutable the moment no session\n\t\t// is attached. Released only when this loop is disposed: giving up the current URL\n\t\t// is recoverable (a new URL or a disable/re-enable starts another sequence), so a\n\t\t// request must keep waiting rather than go unroutable in the gap.\n\t\tif (this.consume) {\n\t\t\tthis.#signals.cleanup(wireOf(this.consume).expect());\n\t\t}\n\n\t\tthis.error = this.#error;\n\n\t\tconst win = globalThis.window;\n\t\tconst doc = globalThis.document;\n\t\tif (typeof win !== \"undefined\" && typeof doc !== \"undefined\") {\n\t\t\tthis.#signals.event(win, \"pagehide\", () => this.#suspended.set(true));\n\t\t\tthis.#signals.event(win, \"pageshow\", () => this.#suspended.set(false));\n\t\t\tthis.#signals.event(win, \"unload\", () => this.#suspended.set(true));\n\t\t\tthis.#signals.event(doc, \"visibilitychange\", () => {\n\t\t\t\tif (!doc.hidden) this.#suspended.set(false);\n\t\t\t});\n\t\t}\n\n\t\tthis.probe = this.#signals.computed((effect) => {\n\t\t\tconst connection = effect.get(this.established);\n\t\t\treturn connection && effect.get(connection.probe);\n\t\t});\n\n\t\tthis.bandwidth = new Allocator(this.#estimate);\n\t\tthis.#signals.cleanup(() => this.bandwidth.close());\n\n\t\t// The transport has no event for the send-rate estimate, so sample on our\n\t\t// own schedule and skip a tick while the previous snapshot is outstanding.\n\t\tthis.#signals.run((effect) => {\n\t\t\teffect.set(this.#estimate, undefined);\n\t\t\tconst connection = effect.get(this.established);\n\t\t\tif (!connection) return;\n\n\t\t\tlet pending = false;\n\t\t\tconst sample = async () => {\n\t\t\t\tif (pending) return;\n\t\t\t\tpending = true;\n\t\t\t\ttry {\n\t\t\t\t\tconst stats = await effect.race(connection.stats());\n\t\t\t\t\tif (stats) this.#estimate.set(stats.estimatedSendRate);\n\t\t\t\t} finally {\n\t\t\t\t\tpending = false;\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tvoid sample();\n\t\t\teffect.interval(() => void sample(), BANDWIDTH_POLL);\n\t\t});\n\n\t\tthis.#url = this.#signals.computed((effect) => effect.get(this.url)?.href);\n\t\t// Create a reactive root so cleanup is easier.\n\t\tthis.#signals.run(this.#connect.bind(this));\n\t}\n\n\t#connect(effect: Effect): void {\n\t\t// Will retry when the tick changes.\n\t\teffect.get(this.#tick);\n\n\t\tconst enabled = effect.get(this.enabled);\n\t\tif (!enabled) {\n\t\t\tthis.#givenUpHref = undefined;\n\t\t\tthis.#resetSequence();\n\t\t\tthis.#redirect.set(undefined);\n\t\t\treturn;\n\t\t}\n\n\t\t// Hide/freeze pauses an in-flight sequence without recovering from give-up.\n\t\tconst suspended = effect.get(this.#suspended);\n\t\tif (suspended) {\n\t\t\tthis.#resetSequence();\n\t\t\treturn;\n\t\t}\n\n\t\tconst href = effect.get(this.#url);\n\t\tif (!href) {\n\t\t\tthis.#givenUpHref = undefined;\n\t\t\tthis.#resetSequence();\n\t\t\tthis.#redirect.set(undefined);\n\t\t\treturn;\n\t\t}\n\t\tconst url = new URL(href);\n\n\t\tif (this.#givenUpHref === href) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.#sequenceHref !== href) {\n\t\t\tthis.#resetSequence();\n\t\t\t// A redirect was assigned for another URL; this one starts from itself. A page\n\t\t\t// hide/show resumes the same URL, so it keeps the assignment.\n\t\t\tif (this.#redirectHref !== href) this.#redirect.set(undefined);\n\t\t\tthis.#sequenceHref = href;\n\t\t\tthis.#error.set(undefined);\n\t\t\tthis.#givenUpHref = undefined;\n\t\t}\n\n\t\t// A drained predecessor still serves while its replacement dials.\n\t\tif (!this.#draining) this.status.set(\"connecting\");\n\n\t\t// This run's teardown, handed to connect() so a rerun cancels the attempt in flight.\n\t\tconst signal = effect.abort;\n\n\t\t// The session this run serves, closed with the run. A drained one leaves this slot\n\t\t// for #draining, which outlives the run.\n\t\tlet current: Established | undefined;\n\t\teffect.cleanup(() => {\n\t\t\tif (current) {\n\t\t\t\tcurrent.close();\n\t\t\t\tif (this.established.peek() === current) this.established.set(undefined);\n\t\t\t\tcurrent = undefined;\n\t\t\t}\n\t\t\tif (this.established.peek() === undefined) this.status.set(\"disconnected\");\n\t\t});\n\n\t\teffect.spawn(async () => {\n\t\t\t// Set once the session is live, so #retry can tell a healthy session that\n\t\t\t// later dropped from a connect failure or a peer that flaps immediately.\n\t\t\tlet connected: DOMHighResTimeStamp | undefined;\n\n\t\t\ttry {\n\t\t\t\t// Loops only to migrate: a GOAWAY off a healthy session dials its replacement\n\t\t\t\t// straight away, with no backoff.\n\t\t\t\tfor (;;) {\n\t\t\t\t\tconst dialing = this.#redirect.peek() ?? url;\n\n\t\t\t\t\tthis.#dialing = true;\n\t\t\t\t\tlet connection: Established;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconnection = await connect({\n\t\t\t\t\t\t\turl: dialing,\n\t\t\t\t\t\t\t// A redirect names the relay; a fallback URL pinned for the old one does not follow.\n\t\t\t\t\t\t\twebsocket: this.#redirect.peek() ? { ...this.websocket, url: undefined } : this.websocket,\n\t\t\t\t\t\t\twebtransport: this.webtransport,\n\t\t\t\t\t\t\tdiscovery: this.discovery,\n\t\t\t\t\t\t\tpublish: this.publish,\n\t\t\t\t\t\t\tconsume: this.consume,\n\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t});\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tthis.#dialing = false;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Hand the connection to the effect, which closes it now if this run is already over.\n\t\t\t\t\tif (signal.aborted) {\n\t\t\t\t\t\tconnection.close();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tcurrent = connection;\n\n\t\t\t\t\t// The replacement serves now; a predecessor keeps draining its groups in flight.\n\t\t\t\t\tthis.established.set(connection);\n\t\t\t\t\tthis.status.set(\"connected\");\n\t\t\t\t\tconnected = performance.now();\n\n\t\t\t\t\t// A cancelled effect resolves undefined, so the sentinel tells the session\n\t\t\t\t\t// closing (null for clean, an Error otherwise) apart from this run being\n\t\t\t\t\t// torn down. Anything else is the peer's GOAWAY.\n\t\t\t\t\tconst ended = await effect.race(connection.closed, wireOf(connection).goaway);\n\t\t\t\t\tif (ended === undefined) return;\n\t\t\t\t\tif (ended === null || ended instanceof Error) {\n\t\t\t\t\t\tconsole.warn(\"connection closed, reconnecting\");\n\t\t\t\t\t\tif (this.established.peek() === connection) this.established.set(undefined);\n\t\t\t\t\t\tthis.#retry(effect, connected, ended ?? undefined);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tcurrent = undefined;\n\t\t\t\t\t// A pinned WebSocket URL can win the race against the primary. Judge the\n\t\t\t\t\t// redirect against that endpoint, not the primary we never reached.\n\t\t\t\t\tconst socket = this.#redirect.peek() ? undefined : this.websocket?.url;\n\t\t\t\t\tif (!this.#migrate(connection, dialed(dialing, connection.transport, socket), ended)) return;\n\n\t\t\t\t\t// A session that outlived the initial delay was healthy, so its handover is not a\n\t\t\t\t\t// failure. One redirected almost at once still migrates, but through the backoff,\n\t\t\t\t\t// so two peers bouncing us between them escalate and eventually give up.\n\t\t\t\t\tif (performance.now() - connected < this.#initial()) {\n\t\t\t\t\t\tthis.#retry(effect, connected, new Error(\"peer redirected immediately\"));\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tthis.#delay = undefined;\n\t\t\t\t\tthis.#deadline = undefined;\n\t\t\t\t}\n\t\t\t} catch (err) {\n\t\t\t\t// Treat teardown as cancellation, not a connection failure.\n\t\t\t\tif (signal.aborted) return;\n\n\t\t\t\tconsole.warn(\"connection error:\", err);\n\t\t\t\tthis.#retry(effect, connected, err);\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Act on the peer's GOAWAY for `connection`, which was dialed at `dialing`: resolve where\n\t * to go next and leave the old session serving until it drains. Returns false when the\n\t * redirect is refused, which ends the sequence rather than redialing.\n\t */\n\t#migrate(connection: Established, dialing: URL, drain: Drain): boolean {\n\t\tconst hashes = this.webtransport?.serverCertificateHashes?.length ?? 0;\n\t\tconst configured = hashes > 0 || this.webtransport?.serverCertificate !== undefined;\n\t\t// The pin is a WebTransport option. A WebSocket that won the race never used it.\n\t\tconst pinned = pinnedTransport(connection.transport, configured);\n\n\t\tlet next: URL | undefined;\n\t\ttry {\n\t\t\tnext = target(this.goaway.redirect ?? \"same-host\", drain.uri, dialing, pinned);\n\t\t} catch (err) {\n\t\t\t// The peer is leaving and named somewhere we won't go: redialing the old address\n\t\t\t// would ignore it, so stop here.\n\t\t\tconsole.warn(\"GOAWAY redirect refused:\", err);\n\t\t\tconnection.close();\n\t\t\tthis.established.set(undefined);\n\t\t\tthis.status.set(\"disconnected\");\n\t\t\tthis.#giveUp(error(err));\n\t\t\treturn false;\n\t\t}\n\n\t\t// Only an accepted redirect replaces the URL; an empty one keeps it.\n\t\tif (next) {\n\t\t\tthis.#redirect.set(next);\n\t\t\tthis.#redirectHref = this.#sequenceHref;\n\t\t}\n\n\t\tconsole.info(\"GOAWAY received; migrating\");\n\t\t// A newer GOAWAY retires an older predecessor rather than holding two open.\n\t\tthis.#draining?.retire();\n\t\tconst cap = handover(this.goaway.handover ?? DEFAULT_HANDOVER, drain.timeout);\n\t\tconst draining = new Draining(connection, cap, () => {\n\t\t\tif (this.#draining === draining) this.#draining = undefined;\n\t\t\t// If nothing replaced it yet, nothing is serving.\n\t\t\tif (this.established.peek() !== connection) return;\n\t\t\tthis.established.set(undefined);\n\t\t\tthis.status.set(this.#dialing ? \"connecting\" : \"disconnected\");\n\t\t});\n\t\tthis.#draining = draining;\n\t\treturn true;\n\t}\n\n\t#initial(): Time.Milli {\n\t\treturn this.delay?.initial ?? DEFAULT_DELAY.initial;\n\t}\n\n\t/**\n\t * Schedule the next connect attempt after the current backoff, or stop once the retry window\n\t * has expired. `connected` is when the dead session was established, if it ever was, and\n\t * `cause` the error that killed it, if it died with one.\n\t */\n\t#retry(effect: Effect, connected: DOMHighResTimeStamp | undefined, cause?: unknown): void {\n\t\t// Resolved per sequence rather than at construction, so an edit to `delay` (including\n\t\t// one that drops a field back to its default) applies to the next retry. Field by\n\t\t// field rather than by spread: a caller building `{ initial: maybeInitial }` from an\n\t\t// optional value passes an explicit undefined, which a spread would take as the\n\t\t// answer, turning the backoff into NaN or the window into forever.\n\t\tconst delay = this.delay ?? {};\n\t\tconst initial = this.#initial();\n\t\tconst multiplier = delay.multiplier ?? DEFAULT_DELAY.multiplier;\n\t\tconst max = delay.max ?? DEFAULT_DELAY.max;\n\t\tconst timeout = delay.timeout ?? DEFAULT_DELAY.timeout;\n\n\t\t// Report disconnected during the backoff rather than when the retry reruns the\n\t\t// effect, unless a drained predecessor still serves until it retires.\n\t\tif (this.established.peek() === undefined) this.status.set(\"disconnected\");\n\n\t\t// A session that outlived the initial delay was healthy, so clear the backoff and\n\t\t// start a fresh retry window: a one-off drop should reconnect promptly. Anything\n\t\t// shorter is a peer that accepts and immediately severs, which has to keep\n\t\t// escalating or we hammer it forever at the initial delay.\n\t\tif (connected !== undefined && performance.now() - connected >= initial) {\n\t\t\tthis.#delay = undefined;\n\t\t\tthis.#deadline = undefined;\n\t\t}\n\n\t\t// An auth rejection stops this URL however long the session lived. UNAUTHORIZED is a\n\t\t// specified code rather than one we guessed at, so this is the peer saying these\n\t\t// credentials will never work; retrying them just burns the window. Matches\n\t\t// moq-tokio's reconnect loop, which stops on the same close. A new URL or a\n\t\t// disable/re-enable starts another sequence; the handle itself is not disposed.\n\t\t//\n\t\t// Only a session close says that. The stream registry gives 2 to DELIVERY_TIMEOUT,\n\t\t// so a stream reset during the SETUP exchange would otherwise suppress reconnect\n\t\t// for good.\n\t\tif (cause instanceof SessionError && cause.code === SessionCode.Unauthorized) {\n\t\t\tconsole.warn(\"session rejected as unauthorized, not retrying\");\n\t\t\tthis.#giveUp(cause);\n\t\t\treturn;\n\t\t}\n\n\t\tconst now = performance.now();\n\t\tthis.#delay ??= initial;\n\t\tthis.#deadline ??= timeout > 0 ? now + timeout : Number.POSITIVE_INFINITY;\n\n\t\tif (now >= this.#deadline) {\n\t\t\tconsole.warn(\"reconnect timed out\");\n\t\t\t// A graceful close has no error, so report the timeout itself.\n\t\t\tthis.#giveUp(cause === undefined ? new Error(\"reconnect timed out\") : error(cause));\n\t\t\treturn;\n\t\t}\n\n\t\t// Equal jitter, so a fleet of tabs knocked offline together doesn't reconnect on the same\n\t\t// tick, and never past the deadline the retry window promised.\n\t\tconst wait = Math.min(this.#delay * (0.5 + Math.random() / 2), this.#deadline - now);\n\t\tthis.#delay = Math.min(this.#delay * multiplier, max);\n\n\t\tconst tick = this.#tick.peek() + 1;\n\t\teffect.timer(() => this.#tick.update((prev) => Math.max(prev, tick)), wait);\n\t}\n\n\t#giveUp(cause: Error): void {\n\t\tthis.#error.set(cause);\n\t\tthis.#givenUpHref = this.#sequenceHref;\n\t\tthis.#resetSequence();\n\t}\n\n\t#resetSequence(): void {\n\t\tthis.#delay = undefined;\n\t\tthis.#deadline = undefined;\n\t\tthis.#sequenceHref = undefined;\n\t\tthis.#draining?.retire();\n\t}\n\n\t/**\n\t * Subscribe to broadcast announcements matching `scope`, spanning reconnects.\n\t *\n\t * The same {@link Announce.Consumer} stream as {@link Established.announced}, but everything active\n\t * is retracted (a `retracted` update) whenever the connection drops and re-announced on\n\t * reconnect, so a consumer draining `next()` never clings to a dead route across a reconnect.\n\t *\n\t * Stays empty while the relay lacks {@link Established.discovery}.\n\t */\n\tannounced(scope: Path.Pattern = Path.Pattern.all(), options?: Announce.Options): Announce.Consumer {\n\t\t// With a consume origin the table already spans reconnects (the forwarder retracts\n\t\t// a dead session's entries), so its stream is the same thing with less machinery.\n\t\tif (this.consume) return this.consume.announced(scope, options);\n\n\t\tconst producer = new Announce.Producer();\n\t\tconst consumer = producer.consume();\n\n\t\tconst pump = new Effect();\n\t\tpump.run((effect) => {\n\t\t\tconst conn = effect.get(this.established);\n\t\t\tif (!conn) return;\n\n\t\t\t// Without discovery the upstream announce stream never yields, so leave the\n\t\t\t// consumer empty rather than opening a subscription that can't be answered.\n\t\t\tif (!conn.discovery) return;\n\n\t\t\tconst upstream = conn.announced(scope, options);\n\t\t\teffect.cleanup(() => upstream.close());\n\n\t\t\t// Track what this connection announced so we can retract it if the connection\n\t\t\t// drops; the last event rides along for the retraction.\n\t\t\tconst active = new Map<Path.Valid, Announce.Update>();\n\n\t\t\teffect.spawn(async () => {\n\t\t\t\ttry {\n\t\t\t\t\tfor (;;) {\n\t\t\t\t\t\tconst entry = await effect.race(upstream.next());\n\t\t\t\t\t\tif (!entry) break;\n\t\t\t\t\t\tif (Announce.isActive(entry.kind)) active.set(entry.prefix, entry);\n\t\t\t\t\t\telse active.delete(entry.prefix);\n\t\t\t\t\t\tproducer.append(entry);\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\t// A dropped connection resets the announce stream; the retractions below cover it.\n\t\t\t\t} finally {\n\t\t\t\t\t// Retract everything from the connection that just went away, so a per-broadcast\n\t\t\t\t\t// watcher tears down instead of clinging to the dead route.\n\t\t\t\t\tif (consumer.closed.peek() === undefined) {\n\t\t\t\t\t\tfor (const entry of active.values()) {\n\t\t\t\t\t\t\tproducer.append({ ...entry, kind: \"retracted\" });\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\n\t\tthis.#signals.cleanup(() => pump.close());\n\t\tvoid consumer.closed.then(() => pump.close());\n\n\t\treturn consumer;\n\t}\n\n\t/**\n\t * Snapshot the live connection's transport counters, or undefined while disconnected.\n\t * See {@link Established.stats}.\n\t */\n\tasync stats(): Promise<Stats | undefined> {\n\t\treturn this.established.peek()?.stats();\n\t}\n\n\t/** Stop reconnecting, close the current connection, and settle {@link Reload.closed}. Idempotent. */\n\tclose(abort?: Error) {\n\t\tthis.#signals.close();\n\t\tthis.#draining?.retire();\n\t\tif (this.#closed.peek() === undefined) this.#closed.set(abort ?? null);\n\t}\n}\n\n/**\n * A session the peer sent GOAWAY on, left serving so its groups in flight finish. It retires\n * when it closes on its own or overstays its handover window, and `onRetire` runs once either way.\n */\nclass Draining {\n\t#connection: Established;\n\t#timer: ReturnType<typeof setTimeout>;\n\t#onRetire: () => void;\n\t#retired = false;\n\n\tconstructor(connection: Established, handover: Time.Milli, onRetire: () => void) {\n\t\tthis.#connection = connection;\n\t\tthis.#onRetire = onRetire;\n\t\tthis.#timer = setTimeout(() => {\n\t\t\tconsole.warn(\"old session did not drain in time; closing\");\n\t\t\tthis.retire();\n\t\t}, handover);\n\t\tvoid connection.closed.then(() => this.retire());\n\t}\n\n\t/** Close the old session now, whatever remains of its window. Idempotent. */\n\tretire(): void {\n\t\tif (this.#retired) return;\n\t\tthis.#retired = true;\n\t\tclearTimeout(this.#timer);\n\t\tthis.#connection.close();\n\t\tthis.#onRetire();\n\t}\n}\n"]}
package/error.d.ts CHANGED
@@ -197,6 +197,17 @@ export declare class NotFound extends Stream {
197
197
  cause?: unknown;
198
198
  });
199
199
  }
200
+ /**
201
+ * A peer's GOAWAY named a redirect the connection refuses, or one it could not parse.
202
+ *
203
+ * Terminal: the peer is leaving, so the connection stops rather than redialing the old
204
+ * address. Mirrors the Rust `Error::RefusedRedirect`.
205
+ *
206
+ * @public
207
+ */
208
+ export declare class RefusedRedirect extends Error {
209
+ constructor(reason: string);
210
+ }
200
211
  /**
201
212
  * A peer broke the protocol in a way the spec says must end the session.
202
213
  *
package/error.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,uDAAuD;AACvD,OAAO,CAAC,MAAM,YAAY,EAAE,OAAO,MAAM,CAAC;AAE1C,oDAAoD;AACpD,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,CAAC,YAAY,CAAC,EAAE,IAAI,CAAA;CAAE,CAAC;AAErE;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,WAAW,UACF,MAAM,KAAG,WAAW;IACxC,kDAAkD;qBACnC,WAAW;IAC1B,8DAA8D;uBAC7C,WAAW;IAC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,CAAC,EAAE,OAAO,CAAA;KAAE,EAGtD;CACD;AAED;;;;;;;GAOG;AACH,qBAAa,eAAgB,SAAQ,KAAK;IACzC,YAAY,MAAM,EAAE,MAAM,EAGzB;CACD;AAED;;;;;;;;GAQG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;IAC3C,YAAY,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,EAGzD;CACD;AAED,4EAA4E;AAC5E,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,IAAI,WAAW,EAAE,YAAY,IAAI,MAAM,EAAE,CAAC;AAClF,2EAA2E;AAC3E,MAAM,MAAM,kBAAkB,GAAG,aAAa,CAAC;AAiM/C;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAa3C"}
package/error.js CHANGED
@@ -204,6 +204,20 @@ export class NotFound extends Stream {
204
204
  this.name = "NotFound";
205
205
  }
206
206
  }
207
+ /**
208
+ * A peer's GOAWAY named a redirect the connection refuses, or one it could not parse.
209
+ *
210
+ * Terminal: the peer is leaving, so the connection stops rather than redialing the old
211
+ * address. Mirrors the Rust `Error::RefusedRedirect`.
212
+ *
213
+ * @public
214
+ */
215
+ export class RefusedRedirect extends Error {
216
+ constructor(reason) {
217
+ super(`GOAWAY redirect refused: ${reason}`);
218
+ this.name = "RefusedRedirect";
219
+ }
220
+ }
207
221
  /**
208
222
  * A peer broke the protocol in a way the spec says must end the session.
209
223
  *