@dxos/network-manager 0.8.4-main.72ec0f3 → 0.8.4-main.74a063c4e0

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 (83) hide show
  1. package/dist/lib/browser/{chunk-E3P563GT.mjs → chunk-Y2FDDNGM.mjs} +548 -876
  2. package/dist/lib/browser/chunk-Y2FDDNGM.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +342 -4
  4. package/dist/lib/browser/index.mjs.map +4 -4
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/testing/index.mjs +14 -4
  7. package/dist/lib/browser/testing/index.mjs.map +3 -3
  8. package/dist/lib/browser/transport/tcp/index.mjs +2 -33
  9. package/dist/lib/browser/transport/tcp/index.mjs.map +4 -4
  10. package/dist/lib/browser/transport/tcp/tcp-transport.browser.mjs +36 -0
  11. package/dist/lib/browser/transport/tcp/tcp-transport.browser.mjs.map +7 -0
  12. package/dist/lib/browser/transport/tcp/tcp-transport.mjs +160 -0
  13. package/dist/lib/browser/transport/tcp/tcp-transport.mjs.map +7 -0
  14. package/dist/lib/node-esm/{chunk-PKBROUZV.mjs → chunk-OU3FYVBA.mjs} +548 -876
  15. package/dist/lib/node-esm/chunk-OU3FYVBA.mjs.map +7 -0
  16. package/dist/lib/node-esm/index.mjs +342 -4
  17. package/dist/lib/node-esm/index.mjs.map +4 -4
  18. package/dist/lib/node-esm/meta.json +1 -1
  19. package/dist/lib/node-esm/testing/index.mjs +14 -4
  20. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  21. package/dist/lib/node-esm/transport/tcp/index.mjs +2 -157
  22. package/dist/lib/node-esm/transport/tcp/index.mjs.map +4 -4
  23. package/dist/lib/node-esm/transport/tcp/tcp-transport.browser.mjs +36 -0
  24. package/dist/lib/node-esm/transport/tcp/tcp-transport.browser.mjs.map +7 -0
  25. package/dist/lib/node-esm/transport/tcp/tcp-transport.mjs +160 -0
  26. package/dist/lib/node-esm/transport/tcp/tcp-transport.mjs.map +7 -0
  27. package/dist/types/src/network-manager.d.ts +5 -4
  28. package/dist/types/src/network-manager.d.ts.map +1 -1
  29. package/dist/types/src/signal/signal-connection.d.ts +3 -2
  30. package/dist/types/src/signal/signal-connection.d.ts.map +1 -1
  31. package/dist/types/src/signal/signal-messenger.d.ts +3 -2
  32. package/dist/types/src/signal/signal-messenger.d.ts.map +1 -1
  33. package/dist/types/src/signal/swarm-messenger.d.ts +7 -7
  34. package/dist/types/src/signal/swarm-messenger.d.ts.map +1 -1
  35. package/dist/types/src/swarm/connection.d.ts +2 -1
  36. package/dist/types/src/swarm/connection.d.ts.map +1 -1
  37. package/dist/types/src/swarm/peer.d.ts +4 -3
  38. package/dist/types/src/swarm/peer.d.ts.map +1 -1
  39. package/dist/types/src/swarm/swarm.d.ts +3 -2
  40. package/dist/types/src/swarm/swarm.d.ts.map +1 -1
  41. package/dist/types/src/testing/test-builder.d.ts.map +1 -1
  42. package/dist/types/src/tests/basic-test-suite.d.ts.map +1 -1
  43. package/dist/types/src/tests/property-test-suite.d.ts.map +1 -1
  44. package/dist/types/src/transport/tcp/index.d.ts +1 -1
  45. package/dist/types/src/transport/tcp/index.d.ts.map +1 -1
  46. package/dist/types/src/transport/webrtc/rtc-peer-connection.d.ts.map +1 -1
  47. package/dist/types/src/transport/webrtc/rtc-transport-channel.d.ts.map +1 -1
  48. package/dist/types/src/transport/webrtc/rtc-transport-factory.d.ts.map +1 -1
  49. package/dist/types/src/transport/webrtc/rtc-transport-proxy.d.ts.map +1 -1
  50. package/dist/types/src/transport/webrtc/rtc-transport-service.d.ts.map +1 -1
  51. package/dist/types/src/wire-protocol.d.ts +5 -5
  52. package/dist/types/src/wire-protocol.d.ts.map +1 -1
  53. package/dist/types/tsconfig.tsbuildinfo +1 -1
  54. package/package.json +32 -22
  55. package/src/network-manager.ts +19 -15
  56. package/src/signal/integration.node.test.ts +11 -10
  57. package/src/signal/signal-connection.ts +3 -2
  58. package/src/signal/signal-messenger.ts +3 -2
  59. package/src/signal/swarm-messenger.node.test.ts +25 -24
  60. package/src/signal/swarm-messenger.ts +65 -55
  61. package/src/swarm/connection.test.ts +6 -7
  62. package/src/swarm/connection.ts +12 -10
  63. package/src/swarm/peer.ts +7 -7
  64. package/src/swarm/swarm.test.ts +2 -3
  65. package/src/swarm/swarm.ts +9 -10
  66. package/src/testing/test-builder.ts +4 -4
  67. package/src/tests/basic-test-suite.ts +0 -1
  68. package/src/tests/memory-transport.test.ts +0 -2
  69. package/src/tests/property-test-suite.ts +4 -3
  70. package/src/tests/tcp-transport.node.test.ts +0 -2
  71. package/src/tests/webrtc-transport.test.ts +0 -1
  72. package/src/transport/tcp/index.ts +1 -1
  73. package/src/transport/webrtc/rtc-peer-connection.ts +1 -2
  74. package/src/transport/webrtc/rtc-transport-channel.test.ts +0 -2
  75. package/src/transport/webrtc/rtc-transport-channel.ts +1 -2
  76. package/src/transport/webrtc/rtc-transport-factory.ts +0 -1
  77. package/src/transport/webrtc/rtc-transport-proxy.test.ts +0 -2
  78. package/src/transport/webrtc/rtc-transport-proxy.ts +6 -4
  79. package/src/transport/webrtc/rtc-transport-service.ts +0 -1
  80. package/src/transport/webrtc/rtc-transport.test.ts +0 -1
  81. package/src/wire-protocol.ts +6 -6
  82. package/dist/lib/browser/chunk-E3P563GT.mjs.map +0 -7
  83. package/dist/lib/node-esm/chunk-PKBROUZV.mjs.map +0 -7
@@ -60,7 +60,7 @@ var Connection = class {
60
60
  _instanceId = PublicKey.random().toHex();
61
61
  transportStats = new Event();
62
62
  _signalSendTask = new DeferredTask(this._ctx, async () => {
63
- await this._flushSignalBuffer();
63
+ await this._flushSignalBuffer(this._ctx);
64
64
  });
65
65
  _signallingDelay = STARTING_SIGNALLING_DELAY;
66
66
  constructor(topic, localInfo, remoteInfo, sessionId, initiator, _signalMessaging, _protocol, _transportFactory, _callbacks) {
@@ -144,21 +144,25 @@ var Connection = class {
144
144
  });
145
145
  this._protocolClosed.wake();
146
146
  this.close({
147
- error: new ProtocolError("protocol stream closed")
147
+ error: new ProtocolError({
148
+ message: "protocol stream closed"
149
+ })
148
150
  }).catch((err) => this.errors.raise(err));
149
151
  });
150
152
  scheduleTask(this.connectedTimeoutContext, async () => {
151
153
  log.info(`timeout waiting ${TRANSPORT_CONNECTION_TIMEOUT / 1e3}s for transport to connect, aborting`, void 0, {
152
154
  F: __dxlog_file,
153
- L: 194,
155
+ L: 196,
154
156
  S: this,
155
157
  C: (f, a) => f(...a)
156
158
  });
157
- await this.abort(new TimeoutError(`${TRANSPORT_CONNECTION_TIMEOUT / 1e3}s for transport to connect`)).catch((err) => this.errors.raise(err));
159
+ await this.abort(new TimeoutError({
160
+ message: `${TRANSPORT_CONNECTION_TIMEOUT / 1e3}s for transport to connect`
161
+ })).catch((err) => this.errors.raise(err));
158
162
  }, TRANSPORT_CONNECTION_TIMEOUT);
159
163
  invariant(!this._transport, void 0, {
160
164
  F: __dxlog_file,
161
- L: 202,
165
+ L: 204,
162
166
  S: this,
163
167
  A: [
164
168
  "!this._transport",
@@ -185,7 +189,7 @@ var Connection = class {
185
189
  this._transportClosed.wake();
186
190
  log("abort triggered by transport close", void 0, {
187
191
  F: __dxlog_file,
188
- L: 224,
192
+ L: 226,
189
193
  S: this,
190
194
  C: (f, a) => f(...a)
191
195
  });
@@ -196,7 +200,7 @@ var Connection = class {
196
200
  err
197
201
  }, {
198
202
  F: __dxlog_file,
199
- L: 229,
203
+ L: 231,
200
204
  S: this,
201
205
  C: (f, a) => f(...a)
202
206
  });
@@ -206,7 +210,7 @@ var Connection = class {
206
210
  if (err instanceof ConnectionResetError) {
207
211
  log.info("aborting due to transport ConnectionResetError", void 0, {
208
212
  F: __dxlog_file,
209
- L: 236,
213
+ L: 238,
210
214
  S: this,
211
215
  C: (f, a) => f(...a)
212
216
  });
@@ -214,7 +218,7 @@ var Connection = class {
214
218
  } else if (err instanceof ConnectivityError) {
215
219
  log.info("aborting due to transport ConnectivityError", void 0, {
216
220
  F: __dxlog_file,
217
- L: 239,
221
+ L: 241,
218
222
  S: this,
219
223
  C: (f, a) => f(...a)
220
224
  });
@@ -234,7 +238,7 @@ var Connection = class {
234
238
  id: this._instanceId
235
239
  }), {
236
240
  F: __dxlog_file,
237
- L: 258,
241
+ L: 260,
238
242
  S: this,
239
243
  C: (f, a) => f(...a)
240
244
  });
@@ -244,14 +248,14 @@ var Connection = class {
244
248
  err
245
249
  }, {
246
250
  F: __dxlog_file,
247
- L: 265,
251
+ L: 267,
248
252
  S: this,
249
253
  C: (f, a) => f(...a)
250
254
  });
251
255
  if (this._state === "CLOSED" || this._state === "ABORTED") {
252
256
  log(`abort ignored: already ${this._state}`, this.closeReason, {
253
257
  F: __dxlog_file,
254
- L: 267,
258
+ L: 269,
255
259
  S: this,
256
260
  C: (f, a) => f(...a)
257
261
  });
@@ -268,7 +272,7 @@ var Connection = class {
268
272
  err
269
273
  }, {
270
274
  F: __dxlog_file,
271
- L: 279,
275
+ L: 281,
272
276
  S: this,
273
277
  C: (f, a) => f(...a)
274
278
  });
@@ -279,7 +283,7 @@ var Connection = class {
279
283
  } catch (err2) {
280
284
  log.catch(err2, void 0, {
281
285
  F: __dxlog_file,
282
- L: 285,
286
+ L: 287,
283
287
  S: this,
284
288
  C: (f, a) => f(...a)
285
289
  });
@@ -289,7 +293,7 @@ var Connection = class {
289
293
  } catch (err2) {
290
294
  log.catch(err2, void 0, {
291
295
  F: __dxlog_file,
292
- L: 292,
296
+ L: 294,
293
297
  S: this,
294
298
  C: (f, a) => f(...a)
295
299
  });
@@ -299,7 +303,7 @@ var Connection = class {
299
303
  } catch (err2) {
300
304
  log.catch(err2, void 0, {
301
305
  F: __dxlog_file,
302
- L: 298,
306
+ L: 300,
303
307
  S: this,
304
308
  C: (f, a) => f(...a)
305
309
  });
@@ -311,7 +315,7 @@ var Connection = class {
311
315
  error
312
316
  }, {
313
317
  F: __dxlog_file,
314
- L: 305,
318
+ L: 307,
315
319
  S: this,
316
320
  C: (f, a) => f(...a)
317
321
  });
@@ -326,7 +330,7 @@ var Connection = class {
326
330
  error
327
331
  }, {
328
332
  F: __dxlog_file,
329
- L: 316,
333
+ L: 318,
330
334
  S: this,
331
335
  C: (f, a) => f(...a)
332
336
  });
@@ -340,7 +344,7 @@ var Connection = class {
340
344
  if (lastState !== "CONNECTED" || error != null) {
341
345
  log(`graceful close requested when we were in ${lastState} state? aborting`, void 0, {
342
346
  F: __dxlog_file,
343
- L: 327,
347
+ L: 329,
344
348
  S: this,
345
349
  C: (f, a) => f(...a)
346
350
  });
@@ -352,7 +356,7 @@ var Connection = class {
352
356
  error
353
357
  }, {
354
358
  F: __dxlog_file,
355
- L: 331,
359
+ L: 333,
356
360
  S: this,
357
361
  C: (f, a) => f(...a)
358
362
  });
@@ -363,7 +367,7 @@ var Connection = class {
363
367
  } catch (err) {
364
368
  log.catch(err, void 0, {
365
369
  F: __dxlog_file,
366
- L: 336,
370
+ L: 338,
367
371
  S: this,
368
372
  C: (f, a) => f(...a)
369
373
  });
@@ -373,7 +377,7 @@ var Connection = class {
373
377
  } catch (err) {
374
378
  log.catch(err, void 0, {
375
379
  F: __dxlog_file,
376
- L: 342,
380
+ L: 344,
377
381
  S: this,
378
382
  C: (f, a) => f(...a)
379
383
  });
@@ -382,7 +386,7 @@ var Connection = class {
382
386
  peerId: this.localInfo
383
387
  }, {
384
388
  F: __dxlog_file,
385
- L: 345,
389
+ L: 347,
386
390
  S: this,
387
391
  C: (f, a) => f(...a)
388
392
  });
@@ -392,7 +396,7 @@ var Connection = class {
392
396
  async _closeProtocol(options) {
393
397
  log("closing protocol", options, {
394
398
  F: __dxlog_file,
395
- L: 351,
399
+ L: 353,
396
400
  S: this,
397
401
  C: (f, a) => f(...a)
398
402
  });
@@ -402,7 +406,7 @@ var Connection = class {
402
406
  ]);
403
407
  log("protocol closed", options, {
404
408
  F: __dxlog_file,
405
- L: 353,
409
+ L: 355,
406
410
  S: this,
407
411
  C: (f, a) => f(...a)
408
412
  });
@@ -410,7 +414,7 @@ var Connection = class {
410
414
  async _closeTransport() {
411
415
  log("closing transport", void 0, {
412
416
  F: __dxlog_file,
413
- L: 357,
417
+ L: 359,
414
418
  S: this,
415
419
  C: (f, a) => f(...a)
416
420
  });
@@ -420,7 +424,7 @@ var Connection = class {
420
424
  ]);
421
425
  log("transport closed", void 0, {
422
426
  F: __dxlog_file,
423
- L: 359,
427
+ L: 361,
424
428
  S: this,
425
429
  C: (f, a) => f(...a)
426
430
  });
@@ -429,20 +433,20 @@ var Connection = class {
429
433
  this._outgoingSignalBuffer.push(signal);
430
434
  this._signalSendTask.schedule();
431
435
  }
432
- async _flushSignalBuffer() {
436
+ async _flushSignalBuffer(ctx) {
433
437
  if (this._outgoingSignalBuffer.length === 0) {
434
438
  return;
435
439
  }
436
440
  try {
437
441
  if (true) {
438
- await cancelWithContext(this._ctx, sleep(this._signallingDelay));
442
+ await cancelWithContext(ctx, sleep(this._signallingDelay));
439
443
  this._signallingDelay = Math.min(this._signallingDelay * 2, MAX_SIGNALLING_DELAY);
440
444
  }
441
445
  const signals = [
442
446
  ...this._outgoingSignalBuffer
443
447
  ];
444
448
  this._outgoingSignalBuffer.length = 0;
445
- await this._signalMessaging.signal({
449
+ await this._signalMessaging.signal(ctx, {
446
450
  author: this.localInfo,
447
451
  recipient: this.remoteInfo,
448
452
  sessionId: this.sessionId,
@@ -461,22 +465,25 @@ var Connection = class {
461
465
  err
462
466
  }, {
463
467
  F: __dxlog_file,
464
- L: 399,
468
+ L: 401,
465
469
  S: this,
466
470
  C: (f, a) => f(...a)
467
471
  });
468
472
  await this.close({
469
- error: new ConnectivityError("signal message failed to deliver", err)
473
+ error: new ConnectivityError({
474
+ message: "signal message failed to deliver",
475
+ cause: err
476
+ })
470
477
  });
471
478
  }
472
479
  }
473
480
  /**
474
481
  * Receive a signal from the remote peer.
475
482
  */
476
- async signal(msg) {
483
+ async signal(_ctx, msg) {
477
484
  invariant(msg.sessionId, void 0, {
478
485
  F: __dxlog_file,
479
- L: 408,
486
+ L: 410,
480
487
  S: this,
481
488
  A: [
482
489
  "msg.sessionId",
@@ -486,7 +493,7 @@ var Connection = class {
486
493
  if (!msg.sessionId.equals(this.sessionId)) {
487
494
  log("dropping signal for incorrect session id", void 0, {
488
495
  F: __dxlog_file,
489
- L: 410,
496
+ L: 412,
490
497
  S: this,
491
498
  C: (f, a) => f(...a)
492
499
  });
@@ -494,7 +501,7 @@ var Connection = class {
494
501
  }
495
502
  invariant(msg.data.signal || msg.data.signalBatch, void 0, {
496
503
  F: __dxlog_file,
497
- L: 413,
504
+ L: 415,
498
505
  S: this,
499
506
  A: [
500
507
  "msg.data.signal || msg.data.signalBatch",
@@ -503,7 +510,7 @@ var Connection = class {
503
510
  });
504
511
  invariant(msg.author.peerKey === this.remoteInfo.peerKey, void 0, {
505
512
  F: __dxlog_file,
506
- L: 414,
513
+ L: 416,
507
514
  S: this,
508
515
  A: [
509
516
  "msg.author.peerKey === this.remoteInfo.peerKey",
@@ -512,7 +519,7 @@ var Connection = class {
512
519
  });
513
520
  invariant(msg.recipient.peerKey === this.localInfo.peerKey, void 0, {
514
521
  F: __dxlog_file,
515
- L: 415,
522
+ L: 417,
516
523
  S: this,
517
524
  A: [
518
525
  "msg.recipient.peerKey === this.localInfo.peerKey",
@@ -536,7 +543,7 @@ var Connection = class {
536
543
  msg: msg.data
537
544
  }, {
538
545
  F: __dxlog_file,
539
- L: 424,
546
+ L: 426,
540
547
  S: this,
541
548
  C: (f, a) => f(...a)
542
549
  });
@@ -544,7 +551,7 @@ var Connection = class {
544
551
  } else {
545
552
  invariant(this._transport, "Connection not ready to accept signals.", {
546
553
  F: __dxlog_file,
547
- L: 427,
554
+ L: 429,
548
555
  S: this,
549
556
  A: [
550
557
  "this._transport",
@@ -557,7 +564,7 @@ var Connection = class {
557
564
  msg: msg.data
558
565
  }, {
559
566
  F: __dxlog_file,
560
- L: 428,
567
+ L: 430,
561
568
  S: this,
562
569
  C: (f, a) => f(...a)
563
570
  });
@@ -575,13 +582,13 @@ var Connection = class {
575
582
  peerId: this.localInfo
576
583
  }, {
577
584
  F: __dxlog_file,
578
- L: 439,
585
+ L: 441,
579
586
  S: this,
580
587
  C: (f, a) => f(...a)
581
588
  });
582
589
  invariant(state !== this._state, "Already in this state.", {
583
590
  F: __dxlog_file,
584
- L: 440,
591
+ L: 442,
585
592
  S: this,
586
593
  A: [
587
594
  "state !== this._state",
@@ -608,54 +615,16 @@ _ts_decorate([
608
615
  synchronized
609
616
  ], Connection.prototype, "close", null);
610
617
 
611
- // src/signal/ice.ts
612
- import { asyncTimeout } from "@dxos/async";
613
- import { log as log2 } from "@dxos/log";
614
- import { isNonNullable } from "@dxos/util";
615
- var __dxlog_file2 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/signal/ice.ts";
616
- var createIceProvider = (iceProviders) => {
617
- let cachedIceServers;
618
- return {
619
- getIceServers: async () => {
620
- if (cachedIceServers) {
621
- return cachedIceServers;
622
- }
623
- cachedIceServers = (await Promise.all(iceProviders.map(({ urls }) => asyncTimeout(fetch(urls, {
624
- method: "GET"
625
- }), 1e4).then((response) => response.json()).catch((err) => {
626
- const isDev = typeof window !== "undefined" && window.location.href.includes("localhost");
627
- if (!isDev) {
628
- log2.error("Failed to fetch ICE servers from provider", {
629
- urls,
630
- err
631
- }, {
632
- F: __dxlog_file2,
633
- L: 30,
634
- S: void 0,
635
- C: (f, a) => f(...a)
636
- });
637
- }
638
- })))).filter(isNonNullable).map(({ iceServers }) => iceServers).flat();
639
- return cachedIceServers;
640
- }
641
- };
642
- };
643
-
644
618
  // src/signal/swarm-messenger.ts
645
- import { Context as Context2 } from "@dxos/context";
646
619
  import { invariant as invariant2 } from "@dxos/invariant";
647
620
  import { PublicKey as PublicKey2 } from "@dxos/keys";
648
- import { log as log3 } from "@dxos/log";
621
+ import { log as log2 } from "@dxos/log";
649
622
  import { TimeoutError as TimeoutError2 } from "@dxos/protocols";
650
623
  import { schema } from "@dxos/protocols/proto";
651
624
  import { ComplexMap } from "@dxos/util";
652
- var __dxlog_file3 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
625
+ var __dxlog_file2 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
653
626
  var SwarmMessage = schema.getCodecForType("dxos.mesh.swarm.SwarmMessage");
654
627
  var SwarmMessenger = class {
655
- _ctx = new Context2(void 0, {
656
- F: __dxlog_file3,
657
- L: 35
658
- });
659
628
  _sendMessage;
660
629
  _onSignal;
661
630
  _onOffer;
@@ -667,7 +636,7 @@ var SwarmMessenger = class {
667
636
  this._onOffer = onOffer;
668
637
  this._topic = topic;
669
638
  }
670
- async receiveMessage({ author, recipient, payload }) {
639
+ async receiveMessage(ctx, { author, recipient, payload }) {
671
640
  if (payload.type_url !== "dxos.mesh.swarm.SwarmMessage") {
672
641
  return;
673
642
  }
@@ -675,18 +644,18 @@ var SwarmMessenger = class {
675
644
  if (!this._topic.equals(message.topic)) {
676
645
  return;
677
646
  }
678
- log3("received", {
647
+ log2("received", {
679
648
  from: author,
680
649
  to: recipient,
681
650
  msg: message
682
651
  }, {
683
- F: __dxlog_file3,
684
- L: 71,
652
+ F: __dxlog_file2,
653
+ L: 72,
685
654
  S: this,
686
655
  C: (f, a) => f(...a)
687
656
  });
688
657
  if (message.data?.offer) {
689
- await this._handleOffer({
658
+ await this._handleOffer(ctx, {
690
659
  author,
691
660
  recipient,
692
661
  message
@@ -694,45 +663,45 @@ var SwarmMessenger = class {
694
663
  } else if (message.data?.answer) {
695
664
  await this._resolveAnswers(message);
696
665
  } else if (message.data?.signal) {
697
- await this._handleSignal({
666
+ await this._handleSignal(ctx, {
698
667
  author,
699
668
  recipient,
700
669
  message
701
670
  });
702
671
  } else if (message.data?.signalBatch) {
703
- await this._handleSignal({
672
+ await this._handleSignal(ctx, {
704
673
  author,
705
674
  recipient,
706
675
  message
707
676
  });
708
677
  } else {
709
- log3.warn("unknown message", {
678
+ log2.warn("unknown message", {
710
679
  message
711
680
  }, {
712
- F: __dxlog_file3,
713
- L: 82,
681
+ F: __dxlog_file2,
682
+ L: 83,
714
683
  S: this,
715
684
  C: (f, a) => f(...a)
716
685
  });
717
686
  }
718
687
  }
719
- async signal(message) {
688
+ async signal(ctx, message) {
720
689
  invariant2(message.data?.signal || message.data?.signalBatch, "Invalid message", {
721
- F: __dxlog_file3,
722
- L: 87,
690
+ F: __dxlog_file2,
691
+ L: 88,
723
692
  S: this,
724
693
  A: [
725
694
  "message.data?.signal || message.data?.signalBatch",
726
695
  "'Invalid message'"
727
696
  ]
728
697
  });
729
- await this._sendReliableMessage({
698
+ await this._sendReliableMessage(ctx, {
730
699
  author: message.author,
731
700
  recipient: message.recipient,
732
701
  message
733
702
  });
734
703
  }
735
- async offer(message) {
704
+ async offer(ctx, message) {
736
705
  const networkMessage = {
737
706
  ...message,
738
707
  messageId: PublicKey2.random()
@@ -741,30 +710,30 @@ var SwarmMessenger = class {
741
710
  this._offerRecords.set(networkMessage.messageId, {
742
711
  resolve
743
712
  });
744
- this._sendReliableMessage({
713
+ this._sendReliableMessage(ctx, {
745
714
  author: message.author,
746
715
  recipient: message.recipient,
747
716
  message: networkMessage
748
717
  }).catch((err) => reject(err));
749
718
  });
750
719
  }
751
- async _sendReliableMessage({ author, recipient, message }) {
720
+ async _sendReliableMessage(ctx, { author, recipient, message }) {
752
721
  const networkMessage = {
753
722
  ...message,
754
723
  // Setting unique message_id if it not specified yet.
755
724
  messageId: message.messageId ?? PublicKey2.random()
756
725
  };
757
- log3("sending", {
726
+ log2("sending", {
758
727
  from: author,
759
728
  to: recipient,
760
729
  msg: networkMessage
761
730
  }, {
762
- F: __dxlog_file3,
763
- L: 125,
731
+ F: __dxlog_file2,
732
+ L: 129,
764
733
  S: this,
765
734
  C: (f, a) => f(...a)
766
735
  });
767
- await this._sendMessage({
736
+ await this._sendMessage(ctx, {
768
737
  author,
769
738
  recipient,
770
739
  payload: {
@@ -775,8 +744,8 @@ var SwarmMessenger = class {
775
744
  }
776
745
  async _resolveAnswers(message) {
777
746
  invariant2(message.data?.answer?.offerMessageId, "No offerMessageId", {
778
- F: __dxlog_file3,
779
- L: 137,
747
+ F: __dxlog_file2,
748
+ L: 141,
780
749
  S: this,
781
750
  A: [
782
751
  "message.data?.answer?.offerMessageId",
@@ -787,29 +756,29 @@ var SwarmMessenger = class {
787
756
  if (offerRecord) {
788
757
  this._offerRecords.delete(message.data.answer.offerMessageId);
789
758
  invariant2(message.data?.answer, "No answer", {
790
- F: __dxlog_file3,
791
- L: 141,
759
+ F: __dxlog_file2,
760
+ L: 145,
792
761
  S: this,
793
762
  A: [
794
763
  "message.data?.answer",
795
764
  "'No answer'"
796
765
  ]
797
766
  });
798
- log3("resolving", {
767
+ log2("resolving", {
799
768
  answer: message.data.answer
800
769
  }, {
801
- F: __dxlog_file3,
802
- L: 142,
770
+ F: __dxlog_file2,
771
+ L: 146,
803
772
  S: this,
804
773
  C: (f, a) => f(...a)
805
774
  });
806
775
  offerRecord.resolve(message.data.answer);
807
776
  }
808
777
  }
809
- async _handleOffer({ author, recipient, message }) {
778
+ async _handleOffer(ctx, { author, recipient, message }) {
810
779
  invariant2(message.data.offer, "No offer", {
811
- F: __dxlog_file3,
812
- L: 156,
780
+ F: __dxlog_file2,
781
+ L: 163,
813
782
  S: this,
814
783
  A: [
815
784
  "message.data.offer",
@@ -824,10 +793,10 @@ var SwarmMessenger = class {
824
793
  offer: message.data.offer
825
794
  }
826
795
  };
827
- const answer = await this._onOffer(offerMessage);
796
+ const answer = await this._onOffer(ctx, offerMessage);
828
797
  answer.offerMessageId = message.messageId;
829
798
  try {
830
- await this._sendReliableMessage({
799
+ await this._sendReliableMessage(ctx, {
831
800
  author: recipient,
832
801
  recipient: author,
833
802
  message: {
@@ -840,30 +809,30 @@ var SwarmMessenger = class {
840
809
  });
841
810
  } catch (err) {
842
811
  if (err instanceof TimeoutError2) {
843
- log3.info("timeout sending answer to offer", {
812
+ log2.info("timeout sending answer to offer", {
844
813
  err
845
814
  }, {
846
- F: __dxlog_file3,
847
- L: 177,
815
+ F: __dxlog_file2,
816
+ L: 184,
848
817
  S: this,
849
818
  C: (f, a) => f(...a)
850
819
  });
851
820
  } else {
852
- log3.info("error sending answer to offer", {
821
+ log2.info("error sending answer to offer", {
853
822
  err
854
823
  }, {
855
- F: __dxlog_file3,
856
- L: 179,
824
+ F: __dxlog_file2,
825
+ L: 186,
857
826
  S: this,
858
827
  C: (f, a) => f(...a)
859
828
  });
860
829
  }
861
830
  }
862
831
  }
863
- async _handleSignal({ author, recipient, message }) {
832
+ async _handleSignal(ctx, { author, recipient, message }) {
864
833
  invariant2(message.messageId, void 0, {
865
- F: __dxlog_file3,
866
- L: 193,
834
+ F: __dxlog_file2,
835
+ L: 203,
867
836
  S: this,
868
837
  A: [
869
838
  "message.messageId",
@@ -871,8 +840,8 @@ var SwarmMessenger = class {
871
840
  ]
872
841
  });
873
842
  invariant2(message.data.signal || message.data.signalBatch, "Invalid message", {
874
- F: __dxlog_file3,
875
- L: 194,
843
+ F: __dxlog_file2,
844
+ L: 204,
876
845
  S: this,
877
846
  A: [
878
847
  "message.data.signal || message.data.signalBatch",
@@ -888,27 +857,27 @@ var SwarmMessenger = class {
888
857
  signalBatch: message.data.signalBatch
889
858
  }
890
859
  };
891
- await this._onSignal(signalMessage);
860
+ await this._onSignal(ctx, signalMessage);
892
861
  }
893
862
  };
894
863
 
895
864
  // src/swarm/swarm.ts
896
865
  import { Event as Event3, scheduleTask as scheduleTask3, sleep as sleep2, synchronized as synchronized3 } from "@dxos/async";
897
- import { Context as Context4 } from "@dxos/context";
866
+ import { Context as Context3 } from "@dxos/context";
898
867
  import { ErrorStream as ErrorStream2 } from "@dxos/debug";
899
868
  import { invariant as invariant4 } from "@dxos/invariant";
900
869
  import { PublicKey as PublicKey4 } from "@dxos/keys";
901
- import { log as log5, logInfo as logInfo2 } from "@dxos/log";
870
+ import { log as log4, logInfo as logInfo2 } from "@dxos/log";
902
871
  import { PeerInfoHash } from "@dxos/messaging";
903
872
  import { trace as trace2 } from "@dxos/protocols";
904
- import { ComplexMap as ComplexMap2, isNonNullable as isNonNullable2 } from "@dxos/util";
873
+ import { ComplexMap as ComplexMap2, isNonNullable } from "@dxos/util";
905
874
 
906
875
  // src/swarm/peer.ts
907
876
  import { Event as Event2, scheduleTask as scheduleTask2, synchronized as synchronized2 } from "@dxos/async";
908
- import { Context as Context3 } from "@dxos/context";
877
+ import { Context as Context2 } from "@dxos/context";
909
878
  import { invariant as invariant3 } from "@dxos/invariant";
910
879
  import { PublicKey as PublicKey3 } from "@dxos/keys";
911
- import { log as log4 } from "@dxos/log";
880
+ import { log as log3 } from "@dxos/log";
912
881
  import { CancelledError as CancelledError2, SystemError } from "@dxos/protocols";
913
882
  function _ts_decorate2(decorators, target, key, desc) {
914
883
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -916,10 +885,12 @@ function _ts_decorate2(decorators, target, key, desc) {
916
885
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
917
886
  return c > 3 && r && Object.defineProperty(target, key, r), r;
918
887
  }
919
- var __dxlog_file4 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts";
888
+ var __dxlog_file3 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts";
920
889
  var ConnectionDisplacedError = class extends SystemError {
921
890
  constructor() {
922
- super("Connection displaced by remote initiator.");
891
+ super({
892
+ message: "Connection displaced by remote initiator."
893
+ });
923
894
  }
924
895
  };
925
896
  var CONNECTION_COUNTS_STABLE_AFTER = 5e3;
@@ -938,9 +909,9 @@ var Peer = class {
938
909
  _availableAfter = 0;
939
910
  availableToConnect = true;
940
911
  _lastConnectionTime;
941
- _ctx = new Context3(void 0, {
942
- F: __dxlog_file4,
943
- L: 81
912
+ _ctx = new Context2(void 0, {
913
+ F: __dxlog_file3,
914
+ L: 80
944
915
  });
945
916
  _connectionCtx;
946
917
  connection;
@@ -963,16 +934,16 @@ var Peer = class {
963
934
  /**
964
935
  * Respond to remote offer.
965
936
  */
966
- async onOffer(message) {
937
+ async onOffer(_ctx, message) {
967
938
  const remote = message.author;
968
939
  if (this.connection && ![
969
940
  ConnectionState.CREATED,
970
941
  ConnectionState.INITIAL,
971
942
  ConnectionState.CONNECTING
972
943
  ].includes(this.connection.state)) {
973
- log4.info(`received offer when connection already in ${this.connection.state} state`, void 0, {
974
- F: __dxlog_file4,
975
- L: 116,
944
+ log3.info(`received offer when connection already in ${this.connection.state} state`, void 0, {
945
+ F: __dxlog_file3,
946
+ L: 115,
976
947
  S: this,
977
948
  C: (f, a) => f(...a)
978
949
  });
@@ -982,14 +953,14 @@ var Peer = class {
982
953
  }
983
954
  if (this.connection || this.initiating) {
984
955
  if (remote.peerKey < this.localInfo.peerKey) {
985
- log4("close local connection", {
956
+ log3("close local connection", {
986
957
  localPeer: this.localInfo,
987
958
  topic: this.topic,
988
959
  remotePeer: this.remoteInfo,
989
960
  sessionId: this.connection?.sessionId
990
961
  }, {
991
- F: __dxlog_file4,
992
- L: 125,
962
+ F: __dxlog_file3,
963
+ L: 124,
993
964
  S: this,
994
965
  C: (f, a) => f(...a)
995
966
  });
@@ -1005,8 +976,8 @@ var Peer = class {
1005
976
  if (await this._callbacks.onOffer(remote)) {
1006
977
  if (!this.connection) {
1007
978
  invariant3(message.sessionId, void 0, {
1008
- F: __dxlog_file4,
1009
- L: 145,
979
+ F: __dxlog_file3,
980
+ L: 144,
1010
981
  S: this,
1011
982
  A: [
1012
983
  "message.sessionId",
@@ -1020,14 +991,14 @@ var Peer = class {
1020
991
  await connection.openConnection();
1021
992
  } catch (err) {
1022
993
  if (!(err instanceof CancelledError2)) {
1023
- log4.info("connection error", {
994
+ log3.info("connection error", {
1024
995
  topic: this.topic,
1025
996
  peerId: this.localInfo,
1026
997
  remoteId: this.remoteInfo,
1027
998
  err
1028
999
  }, {
1029
- F: __dxlog_file4,
1030
- L: 155,
1000
+ F: __dxlog_file3,
1001
+ L: 154,
1031
1002
  S: this,
1032
1003
  C: (f, a) => f(...a)
1033
1004
  });
@@ -1046,9 +1017,9 @@ var Peer = class {
1046
1017
  /**
1047
1018
  * Initiate a connection to the remote peer.
1048
1019
  */
1049
- async initiateConnection() {
1020
+ async initiateConnection(ctx) {
1050
1021
  invariant3(!this.initiating, "Initiation in progress.", {
1051
- F: __dxlog_file4,
1022
+ F: __dxlog_file3,
1052
1023
  L: 172,
1053
1024
  S: this,
1054
1025
  A: [
@@ -1057,7 +1028,7 @@ var Peer = class {
1057
1028
  ]
1058
1029
  });
1059
1030
  invariant3(!this.connection, "Already connected.", {
1060
- F: __dxlog_file4,
1031
+ F: __dxlog_file3,
1061
1032
  L: 173,
1062
1033
  S: this,
1063
1034
  A: [
@@ -1066,13 +1037,13 @@ var Peer = class {
1066
1037
  ]
1067
1038
  });
1068
1039
  const sessionId = PublicKey3.random();
1069
- log4("initiating...", {
1040
+ log3("initiating...", {
1070
1041
  local: this.localInfo,
1071
1042
  topic: this.topic,
1072
1043
  remote: this.remoteInfo,
1073
1044
  sessionId
1074
1045
  }, {
1075
- F: __dxlog_file4,
1046
+ F: __dxlog_file3,
1076
1047
  L: 175,
1077
1048
  S: this,
1078
1049
  C: (f, a) => f(...a)
@@ -1083,7 +1054,7 @@ var Peer = class {
1083
1054
  try {
1084
1055
  await this._connectionLimiter.connecting(sessionId);
1085
1056
  connection.initiate();
1086
- answer = await this._signalMessaging.offer({
1057
+ answer = await this._signalMessaging.offer(ctx, {
1087
1058
  author: this.localInfo,
1088
1059
  recipient: this.remoteInfo,
1089
1060
  sessionId,
@@ -1092,20 +1063,20 @@ var Peer = class {
1092
1063
  offer: {}
1093
1064
  }
1094
1065
  });
1095
- log4("received", {
1066
+ log3("received", {
1096
1067
  answer,
1097
1068
  topic: this.topic,
1098
1069
  local: this.localInfo,
1099
1070
  remote: this.remoteInfo
1100
1071
  }, {
1101
- F: __dxlog_file4,
1072
+ F: __dxlog_file3,
1102
1073
  L: 192,
1103
1074
  S: this,
1104
1075
  C: (f, a) => f(...a)
1105
1076
  });
1106
1077
  if (connection.state !== ConnectionState.INITIAL) {
1107
- log4("ignoring response", void 0, {
1108
- F: __dxlog_file4,
1078
+ log3("ignoring response", void 0, {
1079
+ F: __dxlog_file3,
1109
1080
  L: 194,
1110
1081
  S: this,
1111
1082
  C: (f, a) => f(...a)
@@ -1113,13 +1084,13 @@ var Peer = class {
1113
1084
  return;
1114
1085
  }
1115
1086
  } catch (err) {
1116
- log4("initiation error: send offer", {
1087
+ log3("initiation error: send offer", {
1117
1088
  err,
1118
1089
  topic: this.topic,
1119
1090
  local: this.localInfo,
1120
1091
  remote: this.remoteInfo
1121
1092
  }, {
1122
- F: __dxlog_file4,
1093
+ F: __dxlog_file3,
1123
1094
  L: 198,
1124
1095
  S: this,
1125
1096
  C: (f, a) => f(...a)
@@ -1135,13 +1106,13 @@ var Peer = class {
1135
1106
  return;
1136
1107
  }
1137
1108
  } catch (err) {
1138
- log4("initiation error: accept answer", {
1109
+ log3("initiation error: accept answer", {
1139
1110
  err,
1140
1111
  topic: this.topic,
1141
1112
  local: this.localInfo,
1142
1113
  remote: this.remoteInfo
1143
1114
  }, {
1144
- F: __dxlog_file4,
1115
+ F: __dxlog_file3,
1145
1116
  L: 211,
1146
1117
  S: this,
1147
1118
  C: (f, a) => f(...a)
@@ -1152,8 +1123,8 @@ var Peer = class {
1152
1123
  this.initiating = false;
1153
1124
  }
1154
1125
  try {
1155
- log4("opening connection as initiator", void 0, {
1156
- F: __dxlog_file4,
1126
+ log3("opening connection as initiator", void 0, {
1127
+ F: __dxlog_file3,
1157
1128
  L: 224,
1158
1129
  S: this,
1159
1130
  C: (f, a) => f(...a)
@@ -1161,21 +1132,21 @@ var Peer = class {
1161
1132
  await connection.openConnection();
1162
1133
  this._callbacks.onAccepted();
1163
1134
  } catch (err) {
1164
- log4("initiation error: open connection", {
1135
+ log3("initiation error: open connection", {
1165
1136
  err,
1166
1137
  topic: this.topic,
1167
1138
  local: this.localInfo,
1168
1139
  remote: this.remoteInfo
1169
1140
  }, {
1170
- F: __dxlog_file4,
1141
+ F: __dxlog_file3,
1171
1142
  L: 228,
1172
1143
  S: this,
1173
1144
  C: (f, a) => f(...a)
1174
1145
  });
1175
- log4.warn("closing connection due to unhandled error on openConnection", {
1146
+ log3.warn("closing connection due to unhandled error on openConnection", {
1176
1147
  err
1177
1148
  }, {
1178
- F: __dxlog_file4,
1149
+ F: __dxlog_file3,
1179
1150
  L: 235,
1180
1151
  S: this,
1181
1152
  C: (f, a) => f(...a)
@@ -1191,20 +1162,20 @@ var Peer = class {
1191
1162
  * Either we're initiating a connection or creating one in response to an offer from the other peer.
1192
1163
  */
1193
1164
  _createConnection(initiator, sessionId) {
1194
- log4("creating connection", {
1165
+ log3("creating connection", {
1195
1166
  topic: this.topic,
1196
1167
  peerId: this.localInfo,
1197
1168
  remoteId: this.remoteInfo,
1198
1169
  initiator,
1199
1170
  sessionId
1200
1171
  }, {
1201
- F: __dxlog_file4,
1172
+ F: __dxlog_file3,
1202
1173
  L: 249,
1203
1174
  S: this,
1204
1175
  C: (f, a) => f(...a)
1205
1176
  });
1206
1177
  invariant3(!this.connection, "Already connected.", {
1207
- F: __dxlog_file4,
1178
+ F: __dxlog_file3,
1208
1179
  L: 256,
1209
1180
  S: this,
1210
1181
  A: [
@@ -1233,14 +1204,14 @@ var Peer = class {
1233
1204
  this._lastConnectionTime = Date.now();
1234
1205
  this._callbacks.onConnected();
1235
1206
  this._connectionLimiter.doneConnecting(sessionId);
1236
- log4.trace("dxos.mesh.connection.connected", {
1207
+ log3.trace("dxos.mesh.connection.connected", {
1237
1208
  topic: this.topic,
1238
1209
  localPeerId: this.localInfo,
1239
1210
  remotePeerId: this.remoteInfo,
1240
1211
  sessionId,
1241
1212
  initiator
1242
1213
  }, {
1243
- F: __dxlog_file4,
1214
+ F: __dxlog_file3,
1244
1215
  L: 280,
1245
1216
  S: this,
1246
1217
  C: (f, a) => f(...a)
@@ -1253,15 +1224,15 @@ var Peer = class {
1253
1224
  remoteId: this.remoteInfo,
1254
1225
  initiator
1255
1226
  };
1256
- log4("connection closed", logMeta, {
1257
- F: __dxlog_file4,
1227
+ log3("connection closed", logMeta, {
1228
+ F: __dxlog_file3,
1258
1229
  L: 290,
1259
1230
  S: this,
1260
1231
  C: (f, a) => f(...a)
1261
1232
  });
1262
1233
  this._connectionLimiter.doneConnecting(sessionId);
1263
1234
  invariant3(this.connection === connection, "Connection mismatch (race condition).", {
1264
- F: __dxlog_file4,
1235
+ F: __dxlog_file3,
1265
1236
  L: 295,
1266
1237
  S: this,
1267
1238
  A: [
@@ -1269,14 +1240,14 @@ var Peer = class {
1269
1240
  "'Connection mismatch (race condition).'"
1270
1241
  ]
1271
1242
  });
1272
- log4.trace("dxos.mesh.connection.closed", {
1243
+ log3.trace("dxos.mesh.connection.closed", {
1273
1244
  topic: this.topic,
1274
1245
  localPeerId: this.localInfo,
1275
1246
  remotePeerId: this.remoteInfo,
1276
1247
  sessionId,
1277
1248
  initiator
1278
1249
  }, {
1279
- F: __dxlog_file4,
1250
+ F: __dxlog_file3,
1280
1251
  L: 297,
1281
1252
  S: this,
1282
1253
  C: (f, a) => f(...a)
@@ -1292,8 +1263,8 @@ var Peer = class {
1292
1263
  }
1293
1264
  this._callbacks.onDisconnected();
1294
1265
  scheduleTask2(this._connectionCtx, () => {
1295
- log4("peer became available", logMeta, {
1296
- F: __dxlog_file4,
1266
+ log3("peer became available", logMeta, {
1267
+ F: __dxlog_file3,
1297
1268
  L: 321,
1298
1269
  S: this,
1299
1270
  C: (f, a) => f(...a)
@@ -1310,19 +1281,19 @@ var Peer = class {
1310
1281
  void this._connectionCtx?.dispose();
1311
1282
  this._connectionCtx = this._ctx.derive();
1312
1283
  connection.errors.handle((err) => {
1313
- log4.info("connection error, closing", {
1284
+ log3.info("connection error, closing", {
1314
1285
  topic: this.topic,
1315
1286
  peerId: this.localInfo,
1316
1287
  remoteId: this.remoteInfo,
1317
1288
  initiator,
1318
1289
  err
1319
1290
  }, {
1320
- F: __dxlog_file4,
1291
+ F: __dxlog_file3,
1321
1292
  L: 339,
1322
1293
  S: this,
1323
1294
  C: (f, a) => f(...a)
1324
1295
  });
1325
- log4.trace("dxos.mesh.connection.error", {
1296
+ log3.trace("dxos.mesh.connection.error", {
1326
1297
  topic: this.topic,
1327
1298
  localPeerId: this.localInfo,
1328
1299
  remotePeerId: this.remoteInfo,
@@ -1330,7 +1301,7 @@ var Peer = class {
1330
1301
  initiator,
1331
1302
  err
1332
1303
  }, {
1333
- F: __dxlog_file4,
1304
+ F: __dxlog_file3,
1334
1305
  L: 346,
1335
1306
  S: this,
1336
1307
  C: (f, a) => f(...a)
@@ -1345,11 +1316,11 @@ var Peer = class {
1345
1316
  return;
1346
1317
  }
1347
1318
  const connection = this.connection;
1348
- log4("closing...", {
1319
+ log3("closing...", {
1349
1320
  peerId: this.remoteInfo,
1350
1321
  sessionId: connection.sessionId
1351
1322
  }, {
1352
- F: __dxlog_file4,
1323
+ F: __dxlog_file3,
1353
1324
  L: 371,
1354
1325
  S: this,
1355
1326
  C: (f, a) => f(...a)
@@ -1357,37 +1328,37 @@ var Peer = class {
1357
1328
  await connection.close({
1358
1329
  error: err
1359
1330
  });
1360
- log4("closed", {
1331
+ log3("closed", {
1361
1332
  peerId: this.remoteInfo,
1362
1333
  sessionId: connection.sessionId
1363
1334
  }, {
1364
- F: __dxlog_file4,
1335
+ F: __dxlog_file3,
1365
1336
  L: 377,
1366
1337
  S: this,
1367
1338
  C: (f, a) => f(...a)
1368
1339
  });
1369
1340
  }
1370
- async onSignal(message) {
1341
+ async onSignal(ctx, message) {
1371
1342
  if (!this.connection) {
1372
- log4("dropping signal message for non-existent connection", {
1343
+ log3("dropping signal message for non-existent connection", {
1373
1344
  message
1374
1345
  }, {
1375
- F: __dxlog_file4,
1346
+ F: __dxlog_file3,
1376
1347
  L: 382,
1377
1348
  S: this,
1378
1349
  C: (f, a) => f(...a)
1379
1350
  });
1380
1351
  return;
1381
1352
  }
1382
- await this.connection.signal(message);
1353
+ await this.connection.signal(ctx, message);
1383
1354
  }
1384
1355
  async safeDestroy(reason) {
1385
1356
  await this._ctx.dispose();
1386
- log4("Destroying peer", {
1357
+ log3("Destroying peer", {
1387
1358
  peerId: this.remoteInfo,
1388
1359
  topic: this.topic
1389
1360
  }, {
1390
- F: __dxlog_file4,
1361
+ F: __dxlog_file3,
1391
1362
  L: 392,
1392
1363
  S: this,
1393
1364
  C: (f, a) => f(...a)
@@ -1420,7 +1391,7 @@ function _ts_decorate3(decorators, target, key, desc) {
1420
1391
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1421
1392
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1422
1393
  }
1423
- var __dxlog_file5 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts";
1394
+ var __dxlog_file4 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts";
1424
1395
  var INITIATION_DELAY = 100;
1425
1396
  var getClassName = (obj) => Object.getPrototypeOf(obj).constructor.name;
1426
1397
  var Swarm = class {
@@ -1434,9 +1405,9 @@ var Swarm = class {
1434
1405
  _connectionLimiter;
1435
1406
  _initiationDelay;
1436
1407
  _swarmMessenger;
1437
- _ctx = new Context4(void 0, {
1438
- F: __dxlog_file5,
1439
- L: 39
1408
+ _ctx = new Context3(void 0, {
1409
+ F: __dxlog_file4,
1410
+ L: 38
1440
1411
  });
1441
1412
  _listeningHandle = void 0;
1442
1413
  /**
@@ -1476,44 +1447,44 @@ var Swarm = class {
1476
1447
  this._label = _label;
1477
1448
  this._connectionLimiter = _connectionLimiter;
1478
1449
  this._initiationDelay = _initiationDelay;
1479
- log5.trace("dxos.mesh.swarm.constructor", trace2.begin({
1450
+ log4.trace("dxos.mesh.swarm.constructor", trace2.begin({
1480
1451
  id: this._instanceId,
1481
1452
  data: {
1482
1453
  topic: this._topic.toHex(),
1483
1454
  peer: this._ownPeer
1484
1455
  }
1485
1456
  }), {
1486
- F: __dxlog_file5,
1487
- L: 89,
1457
+ F: __dxlog_file4,
1458
+ L: 88,
1488
1459
  S: this,
1489
1460
  C: (f, a) => f(...a)
1490
1461
  });
1491
- log5("creating swarm", {
1462
+ log4("creating swarm", {
1492
1463
  peerId: _ownPeer
1493
1464
  }, {
1494
- F: __dxlog_file5,
1495
- L: 93,
1465
+ F: __dxlog_file4,
1466
+ L: 92,
1496
1467
  S: this,
1497
1468
  C: (f, a) => f(...a)
1498
1469
  });
1499
1470
  _topology.init(this._getSwarmController());
1500
1471
  this._swarmMessenger = new SwarmMessenger({
1501
- sendMessage: async (msg) => await this._messenger.sendMessage(msg),
1502
- onSignal: async (msg) => await this.onSignal(msg),
1503
- onOffer: async (msg) => await this.onOffer(msg),
1472
+ sendMessage: async (ctx, msg) => await this._messenger.sendMessage(ctx, msg),
1473
+ onSignal: async (ctx, msg) => await this.onSignal(ctx, msg),
1474
+ onOffer: async (ctx, msg) => await this.onOffer(ctx, msg),
1504
1475
  topic: this._topic
1505
1476
  });
1506
- log5.trace("dxos.mesh.swarm.constructor", trace2.end({
1477
+ log4.trace("dxos.mesh.swarm.constructor", trace2.end({
1507
1478
  id: this._instanceId
1508
1479
  }), {
1509
- F: __dxlog_file5,
1510
- L: 102,
1480
+ F: __dxlog_file4,
1481
+ L: 101,
1511
1482
  S: this,
1512
1483
  C: (f, a) => f(...a)
1513
1484
  });
1514
1485
  }
1515
1486
  get connections() {
1516
- return Array.from(this._peers.values()).map((peer) => peer.connection).filter(isNonNullable2);
1487
+ return Array.from(this._peers.values()).map((peer) => peer.connection).filter(isNonNullable);
1517
1488
  }
1518
1489
  get ownPeerId() {
1519
1490
  return PublicKey4.from(this._ownPeer.peerKey);
@@ -1532,8 +1503,8 @@ var Swarm = class {
1532
1503
  }
1533
1504
  async open() {
1534
1505
  invariant4(!this._listeningHandle, void 0, {
1535
- F: __dxlog_file5,
1536
- L: 133,
1506
+ F: __dxlog_file4,
1507
+ L: 132,
1537
1508
  S: this,
1538
1509
  A: [
1539
1510
  "!this._listeningHandle",
@@ -1544,11 +1515,11 @@ var Swarm = class {
1544
1515
  peer: this._ownPeer,
1545
1516
  payloadType: "dxos.mesh.swarm.SwarmMessage",
1546
1517
  onMessage: async (message) => {
1547
- await this._swarmMessenger.receiveMessage(message).catch((err) => log5.info("Error while receiving message", {
1518
+ await this._swarmMessenger.receiveMessage(this._ctx, message).catch((err) => log4.info("Error while receiving message", {
1548
1519
  err
1549
1520
  }, {
1550
- F: __dxlog_file5,
1551
- L: 141,
1521
+ F: __dxlog_file4,
1522
+ L: 140,
1552
1523
  S: this,
1553
1524
  C: (f, a) => f(...a)
1554
1525
  }));
@@ -1556,9 +1527,9 @@ var Swarm = class {
1556
1527
  });
1557
1528
  }
1558
1529
  async destroy() {
1559
- log5("destroying...", void 0, {
1560
- F: __dxlog_file5,
1561
- L: 147,
1530
+ log4("destroying...", void 0, {
1531
+ F: __dxlog_file4,
1532
+ L: 146,
1562
1533
  S: this,
1563
1534
  C: (f, a) => f(...a)
1564
1535
  });
@@ -1567,17 +1538,17 @@ var Swarm = class {
1567
1538
  await this._ctx.dispose();
1568
1539
  await this._topology.destroy();
1569
1540
  await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key, "swarm destroyed")));
1570
- log5("destroyed", void 0, {
1571
- F: __dxlog_file5,
1572
- L: 154,
1541
+ log4("destroyed", void 0, {
1542
+ F: __dxlog_file4,
1543
+ L: 153,
1573
1544
  S: this,
1574
1545
  C: (f, a) => f(...a)
1575
1546
  });
1576
1547
  }
1577
1548
  async setTopology(topology) {
1578
1549
  invariant4(!this._ctx.disposed, "Swarm is offline", {
1579
- F: __dxlog_file5,
1580
- L: 158,
1550
+ F: __dxlog_file4,
1551
+ L: 157,
1581
1552
  S: this,
1582
1553
  A: [
1583
1554
  "!this._ctx.disposed",
@@ -1587,12 +1558,12 @@ var Swarm = class {
1587
1558
  if (topology === this._topology) {
1588
1559
  return;
1589
1560
  }
1590
- log5("setting topology", {
1561
+ log4("setting topology", {
1591
1562
  previous: getClassName(this._topology),
1592
1563
  topology: getClassName(topology)
1593
1564
  }, {
1594
- F: __dxlog_file5,
1595
- L: 162,
1565
+ F: __dxlog_file4,
1566
+ L: 161,
1596
1567
  S: this,
1597
1568
  C: (f, a) => f(...a)
1598
1569
  });
@@ -1602,18 +1573,18 @@ var Swarm = class {
1602
1573
  this._topology.update();
1603
1574
  }
1604
1575
  async onSwarmEvent(swarmEvent) {
1605
- log5("swarm event", {
1576
+ log4("swarm event", {
1606
1577
  swarmEvent
1607
1578
  }, {
1608
- F: __dxlog_file5,
1609
- L: 175,
1579
+ F: __dxlog_file4,
1580
+ L: 174,
1610
1581
  S: this,
1611
1582
  C: (f, a) => f(...a)
1612
1583
  });
1613
1584
  if (this._ctx.disposed) {
1614
- log5("swarm event ignored for disposed swarm", void 0, {
1615
- F: __dxlog_file5,
1616
- L: 178,
1585
+ log4("swarm event ignored for disposed swarm", void 0, {
1586
+ F: __dxlog_file4,
1587
+ L: 177,
1617
1588
  S: this,
1618
1589
  C: (f, a) => f(...a)
1619
1590
  });
@@ -1622,11 +1593,11 @@ var Swarm = class {
1622
1593
  if (swarmEvent.peerAvailable) {
1623
1594
  const peerId = swarmEvent.peerAvailable.peer.peerKey;
1624
1595
  if (peerId !== this._ownPeer.peerKey) {
1625
- log5("new peer", {
1596
+ log4("new peer", {
1626
1597
  peerId
1627
1598
  }, {
1628
- F: __dxlog_file5,
1629
- L: 185,
1599
+ F: __dxlog_file4,
1600
+ L: 184,
1630
1601
  S: this,
1631
1602
  C: (f, a) => f(...a)
1632
1603
  });
@@ -1638,25 +1609,25 @@ var Swarm = class {
1638
1609
  if (peer) {
1639
1610
  peer.advertizing = false;
1640
1611
  if (this._isConnectionEstablishmentInProgress(peer)) {
1641
- log5(`destroying peer, state: ${peer.connection?.state}`, void 0, {
1642
- F: __dxlog_file5,
1643
- L: 196,
1612
+ log4(`destroying peer, state: ${peer.connection?.state}`, void 0, {
1613
+ F: __dxlog_file4,
1614
+ L: 195,
1644
1615
  S: this,
1645
1616
  C: (f, a) => f(...a)
1646
1617
  });
1647
- void this._destroyPeer(swarmEvent.peerLeft.peer, "peer left").catch((err) => log5.catch(err, void 0, {
1648
- F: __dxlog_file5,
1649
- L: 197,
1618
+ void this._destroyPeer(swarmEvent.peerLeft.peer, "peer left").catch((err) => log4.catch(err, void 0, {
1619
+ F: __dxlog_file4,
1620
+ L: 196,
1650
1621
  S: this,
1651
1622
  C: (f, a) => f(...a)
1652
1623
  }));
1653
1624
  }
1654
1625
  } else {
1655
- log5("received peerLeft but no peer found", {
1626
+ log4("received peerLeft but no peer found", {
1656
1627
  peer: swarmEvent.peerLeft.peer.peerKey
1657
1628
  }, {
1658
- F: __dxlog_file5,
1659
- L: 200,
1629
+ F: __dxlog_file4,
1630
+ L: 199,
1660
1631
  S: this,
1661
1632
  C: (f, a) => f(...a)
1662
1633
  });
@@ -1664,19 +1635,19 @@ var Swarm = class {
1664
1635
  }
1665
1636
  this._topology.update();
1666
1637
  }
1667
- async onOffer(message) {
1668
- log5("offer", {
1638
+ async onOffer(ctx, message) {
1639
+ log4("offer", {
1669
1640
  message
1670
1641
  }, {
1671
- F: __dxlog_file5,
1672
- L: 209,
1642
+ F: __dxlog_file4,
1643
+ L: 208,
1673
1644
  S: this,
1674
1645
  C: (f, a) => f(...a)
1675
1646
  });
1676
1647
  if (this._ctx.disposed) {
1677
- log5("ignored for disposed swarm", void 0, {
1678
- F: __dxlog_file5,
1679
- L: 211,
1648
+ log4("ignored for disposed swarm", void 0, {
1649
+ F: __dxlog_file4,
1650
+ L: 210,
1680
1651
  S: this,
1681
1652
  C: (f, a) => f(...a)
1682
1653
  });
@@ -1685,8 +1656,8 @@ var Swarm = class {
1685
1656
  };
1686
1657
  }
1687
1658
  invariant4(message.author, void 0, {
1688
- F: __dxlog_file5,
1689
- L: 216,
1659
+ F: __dxlog_file4,
1660
+ L: 215,
1690
1661
  S: this,
1691
1662
  A: [
1692
1663
  "message.author",
@@ -1694,11 +1665,11 @@ var Swarm = class {
1694
1665
  ]
1695
1666
  });
1696
1667
  if (message.recipient.peerKey !== this._ownPeer.peerKey) {
1697
- log5("rejecting offer with incorrect peerId", {
1668
+ log4("rejecting offer with incorrect peerId", {
1698
1669
  message
1699
1670
  }, {
1700
- F: __dxlog_file5,
1701
- L: 218,
1671
+ F: __dxlog_file4,
1672
+ L: 217,
1702
1673
  S: this,
1703
1674
  C: (f, a) => f(...a)
1704
1675
  });
@@ -1707,11 +1678,11 @@ var Swarm = class {
1707
1678
  };
1708
1679
  }
1709
1680
  if (!message.topic?.equals(this._topic)) {
1710
- log5("rejecting offer with incorrect topic", {
1681
+ log4("rejecting offer with incorrect topic", {
1711
1682
  message
1712
1683
  }, {
1713
- F: __dxlog_file5,
1714
- L: 222,
1684
+ F: __dxlog_file4,
1685
+ L: 221,
1715
1686
  S: this,
1716
1687
  C: (f, a) => f(...a)
1717
1688
  });
@@ -1720,7 +1691,7 @@ var Swarm = class {
1720
1691
  };
1721
1692
  }
1722
1693
  const peer = this._getOfferSenderPeer(message.author);
1723
- const answer = await peer.onOffer(message);
1694
+ const answer = await peer.onOffer(ctx, message);
1724
1695
  this._topology.update();
1725
1696
  return answer;
1726
1697
  }
@@ -1734,27 +1705,27 @@ var Swarm = class {
1734
1705
  }
1735
1706
  return peer;
1736
1707
  }
1737
- async onSignal(message) {
1738
- log5("signal", {
1708
+ async onSignal(ctx, message) {
1709
+ log4("signal", {
1739
1710
  message
1740
1711
  }, {
1741
- F: __dxlog_file5,
1742
- L: 247,
1712
+ F: __dxlog_file4,
1713
+ L: 246,
1743
1714
  S: this,
1744
1715
  C: (f, a) => f(...a)
1745
1716
  });
1746
1717
  if (this._ctx.disposed) {
1747
- log5.info("ignored for offline swarm", void 0, {
1748
- F: __dxlog_file5,
1749
- L: 249,
1718
+ log4.info("ignored for offline swarm", void 0, {
1719
+ F: __dxlog_file4,
1720
+ L: 248,
1750
1721
  S: this,
1751
1722
  C: (f, a) => f(...a)
1752
1723
  });
1753
1724
  return;
1754
1725
  }
1755
1726
  invariant4(message.recipient.peerKey === this._ownPeer.peerKey, `Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`, {
1756
- F: __dxlog_file5,
1757
- L: 252,
1727
+ F: __dxlog_file4,
1728
+ L: 251,
1758
1729
  S: this,
1759
1730
  A: [
1760
1731
  "message.recipient.peerKey === this._ownPeer.peerKey",
@@ -1762,8 +1733,8 @@ var Swarm = class {
1762
1733
  ]
1763
1734
  });
1764
1735
  invariant4(message.topic?.equals(this._topic), void 0, {
1765
- F: __dxlog_file5,
1766
- L: 256,
1736
+ F: __dxlog_file4,
1737
+ L: 255,
1767
1738
  S: this,
1768
1739
  A: [
1769
1740
  "message.topic?.equals(this._topic)",
@@ -1771,8 +1742,8 @@ var Swarm = class {
1771
1742
  ]
1772
1743
  });
1773
1744
  invariant4(message.author, void 0, {
1774
- F: __dxlog_file5,
1775
- L: 257,
1745
+ F: __dxlog_file4,
1746
+ L: 256,
1776
1747
  S: this,
1777
1748
  A: [
1778
1749
  "message.author",
@@ -1780,7 +1751,7 @@ var Swarm = class {
1780
1751
  ]
1781
1752
  });
1782
1753
  const peer = this._getOrCreatePeer(message.author);
1783
- await peer.onSignal(message);
1754
+ await peer.onSignal(ctx, message);
1784
1755
  }
1785
1756
  // For debug purposes
1786
1757
  async goOffline() {
@@ -1791,15 +1762,15 @@ var Swarm = class {
1791
1762
  }
1792
1763
  // For debug purposes
1793
1764
  async goOnline() {
1794
- this._ctx = new Context4(void 0, {
1795
- F: __dxlog_file5,
1796
- L: 273
1765
+ this._ctx = new Context3(void 0, {
1766
+ F: __dxlog_file4,
1767
+ L: 272
1797
1768
  });
1798
1769
  }
1799
1770
  _getOrCreatePeer(peerInfo) {
1800
1771
  invariant4(peerInfo.peerKey, "PeerInfo.peerKey is required", {
1801
- F: __dxlog_file5,
1802
- L: 277,
1772
+ F: __dxlog_file4,
1773
+ L: 276,
1803
1774
  S: this,
1804
1775
  A: [
1805
1776
  "peerInfo.peerKey",
@@ -1817,9 +1788,9 @@ var Swarm = class {
1817
1788
  },
1818
1789
  onDisconnected: async () => {
1819
1790
  if (this._isUnregistered(peer)) {
1820
- log5.verbose("ignored onDisconnected for unregistered peer", void 0, {
1821
- F: __dxlog_file5,
1822
- L: 297,
1791
+ log4.verbose("ignored onDisconnected for unregistered peer", void 0, {
1792
+ F: __dxlog_file4,
1793
+ L: 296,
1823
1794
  S: this,
1824
1795
  C: (f, a) => f(...a)
1825
1796
  });
@@ -1833,11 +1804,11 @@ var Swarm = class {
1833
1804
  },
1834
1805
  onRejected: () => {
1835
1806
  if (!this._isUnregistered(peer)) {
1836
- log5("peer rejected connection", {
1807
+ log4("peer rejected connection", {
1837
1808
  peerInfo
1838
1809
  }, {
1839
- F: __dxlog_file5,
1840
- L: 311,
1810
+ F: __dxlog_file4,
1811
+ L: 310,
1841
1812
  S: this,
1842
1813
  C: (f, a) => f(...a)
1843
1814
  });
@@ -1859,19 +1830,19 @@ var Swarm = class {
1859
1830
  return peer;
1860
1831
  }
1861
1832
  async _destroyPeer(peerInfo, reason) {
1862
- log5("destroy peer", {
1833
+ log4("destroy peer", {
1863
1834
  peerKey: peerInfo.peerKey,
1864
1835
  reason
1865
1836
  }, {
1866
- F: __dxlog_file5,
1867
- L: 333,
1837
+ F: __dxlog_file4,
1838
+ L: 332,
1868
1839
  S: this,
1869
1840
  C: (f, a) => f(...a)
1870
1841
  });
1871
1842
  const peer = this._peers.get(peerInfo);
1872
1843
  invariant4(peer, void 0, {
1873
- F: __dxlog_file5,
1874
- L: 335,
1844
+ F: __dxlog_file4,
1845
+ L: 334,
1875
1846
  S: this,
1876
1847
  A: [
1877
1848
  "peer",
@@ -1899,9 +1870,9 @@ var Swarm = class {
1899
1870
  peerKey: peer.toHex()
1900
1871
  });
1901
1872
  } catch (err) {
1902
- log5("initiation error", err, {
1903
- F: __dxlog_file5,
1904
- L: 362,
1873
+ log4("initiation error", err, {
1874
+ F: __dxlog_file4,
1875
+ L: 361,
1905
1876
  S: this,
1906
1877
  C: (f, a) => f(...a)
1907
1878
  });
@@ -1928,11 +1899,11 @@ var Swarm = class {
1928
1899
  const ctx = this._ctx;
1929
1900
  const peer = this._getOrCreatePeer(remotePeer);
1930
1901
  if (remotePeer.peerKey < this._ownPeer.peerKey) {
1931
- log5("initiation delay", {
1902
+ log4("initiation delay", {
1932
1903
  remotePeer
1933
1904
  }, {
1934
- F: __dxlog_file5,
1935
- L: 390,
1905
+ F: __dxlog_file4,
1906
+ L: 389,
1936
1907
  S: this,
1937
1908
  C: (f, a) => f(...a)
1938
1909
  });
@@ -1947,21 +1918,21 @@ var Swarm = class {
1947
1918
  if (peer.connection) {
1948
1919
  return;
1949
1920
  }
1950
- log5("initiating connection...", {
1921
+ log4("initiating connection...", {
1951
1922
  remotePeer
1952
1923
  }, {
1953
- F: __dxlog_file5,
1954
- L: 406,
1924
+ F: __dxlog_file4,
1925
+ L: 405,
1955
1926
  S: this,
1956
1927
  C: (f, a) => f(...a)
1957
1928
  });
1958
- await peer.initiateConnection();
1929
+ await peer.initiateConnection(ctx);
1959
1930
  this._topology.update();
1960
- log5("initiated", {
1931
+ log4("initiated", {
1961
1932
  remotePeer
1962
1933
  }, {
1963
- F: __dxlog_file5,
1964
- L: 409,
1934
+ F: __dxlog_file4,
1935
+ L: 408,
1965
1936
  S: this,
1966
1937
  C: (f, a) => f(...a)
1967
1938
  });
@@ -2012,10 +1983,10 @@ _ts_decorate3([
2012
1983
  // src/swarm/swarm-mapper.ts
2013
1984
  import { Event as Event4, SubscriptionList } from "@dxos/async";
2014
1985
  import { PublicKey as PublicKey5 } from "@dxos/keys";
2015
- import { log as log6 } from "@dxos/log";
1986
+ import { log as log5 } from "@dxos/log";
2016
1987
  import { PeerInfoHash as PeerInfoHash2 } from "@dxos/messaging";
2017
1988
  import { ComplexMap as ComplexMap3 } from "@dxos/util";
2018
- var __dxlog_file6 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
1989
+ var __dxlog_file5 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
2019
1990
  var SwarmMapper = class {
2020
1991
  _swarm;
2021
1992
  _subscriptions = new SubscriptionList();
@@ -2041,8 +2012,8 @@ var SwarmMapper = class {
2041
2012
  this._update();
2042
2013
  }
2043
2014
  _update() {
2044
- log6("updating swarm", void 0, {
2045
- F: __dxlog_file6,
2015
+ log5("updating swarm", void 0, {
2016
+ F: __dxlog_file5,
2046
2017
  L: 71,
2047
2018
  S: this,
2048
2019
  C: (f, a) => f(...a)
@@ -2062,11 +2033,11 @@ var SwarmMapper = class {
2062
2033
  ]
2063
2034
  });
2064
2035
  }
2065
- log6("graph changed", {
2036
+ log5("graph changed", {
2066
2037
  directConnections: this._swarm.connections.length,
2067
2038
  totalPeersInSwarm: this._peers.size
2068
2039
  }, {
2069
- F: __dxlog_file6,
2040
+ F: __dxlog_file5,
2070
2041
  L: 112,
2071
2042
  S: this,
2072
2043
  C: (f, a) => f(...a)
@@ -2083,17 +2054,17 @@ var SwarmMapper = class {
2083
2054
 
2084
2055
  // src/swarm/connection-limiter.ts
2085
2056
  import { DeferredTask as DeferredTask2 } from "@dxos/async";
2086
- import { Context as Context5 } from "@dxos/context";
2057
+ import { Context as Context4 } from "@dxos/context";
2087
2058
  import { invariant as invariant5 } from "@dxos/invariant";
2088
2059
  import { PublicKey as PublicKey6 } from "@dxos/keys";
2089
- import { log as log7 } from "@dxos/log";
2060
+ import { log as log6 } from "@dxos/log";
2090
2061
  import { CancelledError as CancelledError3 } from "@dxos/protocols";
2091
2062
  import { ComplexMap as ComplexMap4 } from "@dxos/util";
2092
- var __dxlog_file7 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
2063
+ var __dxlog_file6 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
2093
2064
  var MAX_CONCURRENT_INITIATING_CONNECTIONS = 50;
2094
2065
  var ConnectionLimiter = class {
2095
- _ctx = new Context5(void 0, {
2096
- F: __dxlog_file7,
2066
+ _ctx = new Context4(void 0, {
2067
+ F: __dxlog_file6,
2097
2068
  L: 23
2098
2069
  });
2099
2070
  _maxConcurrentInitConnections;
@@ -2114,7 +2085,7 @@ var ConnectionLimiter = class {
2114
2085
  */
2115
2086
  async connecting(sessionId) {
2116
2087
  invariant5(!this._waitingPromises.has(sessionId), "Peer is already waiting for connection", {
2117
- F: __dxlog_file7,
2088
+ F: __dxlog_file6,
2118
2089
  L: 48,
2119
2090
  S: this,
2120
2091
  A: [
@@ -2122,10 +2093,10 @@ var ConnectionLimiter = class {
2122
2093
  "'Peer is already waiting for connection'"
2123
2094
  ]
2124
2095
  });
2125
- log7("waiting", {
2096
+ log6("waiting", {
2126
2097
  sessionId
2127
2098
  }, {
2128
- F: __dxlog_file7,
2099
+ F: __dxlog_file6,
2129
2100
  L: 49,
2130
2101
  S: this,
2131
2102
  C: (f, a) => f(...a)
@@ -2137,10 +2108,10 @@ var ConnectionLimiter = class {
2137
2108
  });
2138
2109
  this.resolveWaitingPromises.schedule();
2139
2110
  });
2140
- log7("allow", {
2111
+ log6("allow", {
2141
2112
  sessionId
2142
2113
  }, {
2143
- F: __dxlog_file7,
2114
+ F: __dxlog_file6,
2144
2115
  L: 57,
2145
2116
  S: this,
2146
2117
  C: (f, a) => f(...a)
@@ -2150,10 +2121,10 @@ var ConnectionLimiter = class {
2150
2121
  * Rejects promise returned by `connecting` method.
2151
2122
  */
2152
2123
  doneConnecting(sessionId) {
2153
- log7("done", {
2124
+ log6("done", {
2154
2125
  sessionId
2155
2126
  }, {
2156
- F: __dxlog_file7,
2127
+ F: __dxlog_file6,
2157
2128
  L: 64,
2158
2129
  S: this,
2159
2130
  C: (f, a) => f(...a)
@@ -2261,7 +2232,7 @@ var gcSwarm = (swarm) => {
2261
2232
  import { Event as Event6, synchronized as synchronized4 } from "@dxos/async";
2262
2233
  import { invariant as invariant6 } from "@dxos/invariant";
2263
2234
  import { PublicKey as PublicKey8 } from "@dxos/keys";
2264
- import { log as log8 } from "@dxos/log";
2235
+ import { log as log7 } from "@dxos/log";
2265
2236
  import { Messenger } from "@dxos/messaging";
2266
2237
  import { trace as trace3 } from "@dxos/protocols";
2267
2238
  import { ConnectionState as ConnectionState2 } from "@dxos/protocols/proto/dxos/client/services";
@@ -2272,7 +2243,7 @@ function _ts_decorate4(decorators, target, key, desc) {
2272
2243
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2273
2244
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2274
2245
  }
2275
- var __dxlog_file8 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts";
2246
+ var __dxlog_file7 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts";
2276
2247
  var SwarmNetworkManager = class {
2277
2248
  /**
2278
2249
  * @internal
@@ -2298,8 +2269,8 @@ var SwarmNetworkManager = class {
2298
2269
  signalManager: this._signalManager
2299
2270
  });
2300
2271
  this._signalConnection = {
2301
- join: (opts) => this._signalManager.join(opts),
2302
- leave: (opts) => this._signalManager.leave(opts)
2272
+ join: (ctx, opts) => this._signalManager.join(ctx, opts),
2273
+ leave: (ctx, opts) => this._signalManager.leave(ctx, opts)
2303
2274
  };
2304
2275
  this._peerInfo = peerInfo;
2305
2276
  this._connectionLimiter = new ConnectionLimiter();
@@ -2328,31 +2299,31 @@ var SwarmNetworkManager = class {
2328
2299
  this._peerInfo = peerInfo;
2329
2300
  }
2330
2301
  async open() {
2331
- log8.trace("dxos.mesh.network-manager.open", trace3.begin({
2302
+ log7.trace("dxos.mesh.network-manager.open", trace3.begin({
2332
2303
  id: this._instanceId
2333
2304
  }), {
2334
- F: __dxlog_file8,
2335
- L: 133,
2305
+ F: __dxlog_file7,
2306
+ L: 134,
2336
2307
  S: this,
2337
2308
  C: (f, a) => f(...a)
2338
2309
  });
2339
2310
  await this._messenger.open();
2340
2311
  await this._signalManager.open();
2341
- log8.trace("dxos.mesh.network-manager.open", trace3.end({
2312
+ log7.trace("dxos.mesh.network-manager.open", trace3.end({
2342
2313
  id: this._instanceId
2343
2314
  }), {
2344
- F: __dxlog_file8,
2345
- L: 136,
2315
+ F: __dxlog_file7,
2316
+ L: 137,
2346
2317
  S: this,
2347
2318
  C: (f, a) => f(...a)
2348
2319
  });
2349
2320
  }
2350
- async close() {
2321
+ async close(ctx) {
2351
2322
  for (const topic of this._swarms.keys()) {
2352
- await this.leaveSwarm(topic).catch((err) => {
2353
- log8(err, void 0, {
2354
- F: __dxlog_file8,
2355
- L: 142,
2323
+ await this.leaveSwarm(ctx, topic).catch((err) => {
2324
+ log7(err, void 0, {
2325
+ F: __dxlog_file7,
2326
+ L: 143,
2356
2327
  S: this,
2357
2328
  C: (f, a) => f(...a)
2358
2329
  });
@@ -2364,10 +2335,10 @@ var SwarmNetworkManager = class {
2364
2335
  /**
2365
2336
  * Join the swarm.
2366
2337
  */
2367
- async joinSwarm({ topic, topology, protocolProvider: protocol, label }) {
2338
+ async joinSwarm(ctx, { topic, topology, protocolProvider: protocol, label }) {
2368
2339
  invariant6(PublicKey8.isPublicKey(topic), void 0, {
2369
- F: __dxlog_file8,
2370
- L: 160,
2340
+ F: __dxlog_file7,
2341
+ L: 164,
2371
2342
  S: this,
2372
2343
  A: [
2373
2344
  "PublicKey.isPublicKey(topic)",
@@ -2375,8 +2346,8 @@ var SwarmNetworkManager = class {
2375
2346
  ]
2376
2347
  });
2377
2348
  invariant6(topology, void 0, {
2378
- F: __dxlog_file8,
2379
- L: 161,
2349
+ F: __dxlog_file7,
2350
+ L: 165,
2380
2351
  S: this,
2381
2352
  A: [
2382
2353
  "topology",
@@ -2384,8 +2355,8 @@ var SwarmNetworkManager = class {
2384
2355
  ]
2385
2356
  });
2386
2357
  invariant6(this._peerInfo, void 0, {
2387
- F: __dxlog_file8,
2388
- L: 162,
2358
+ F: __dxlog_file7,
2359
+ L: 166,
2389
2360
  S: this,
2390
2361
  A: [
2391
2362
  "this._peerInfo",
@@ -2393,8 +2364,8 @@ var SwarmNetworkManager = class {
2393
2364
  ]
2394
2365
  });
2395
2366
  invariant6(typeof protocol === "function", void 0, {
2396
- F: __dxlog_file8,
2397
- L: 163,
2367
+ F: __dxlog_file7,
2368
+ L: 167,
2398
2369
  S: this,
2399
2370
  A: [
2400
2371
  "typeof protocol === 'function'",
@@ -2404,23 +2375,23 @@ var SwarmNetworkManager = class {
2404
2375
  if (this._swarms.has(topic)) {
2405
2376
  throw new Error(`Already connected to swarm: ${PublicKey8.from(topic)}`);
2406
2377
  }
2407
- log8("joining", {
2378
+ log7("joining", {
2408
2379
  topic: PublicKey8.from(topic),
2409
2380
  peerInfo: this._peerInfo,
2410
2381
  topology: topology.toString()
2411
2382
  }, {
2412
- F: __dxlog_file8,
2413
- L: 168,
2383
+ F: __dxlog_file7,
2384
+ L: 172,
2414
2385
  S: this,
2415
2386
  C: (f, a) => f(...a)
2416
2387
  });
2417
2388
  const swarm = new Swarm(topic, this._peerInfo, topology, protocol, this._messenger, this._transportFactory, label, this._connectionLimiter);
2418
2389
  swarm.errors.handle((error) => {
2419
- log8("swarm error", {
2390
+ log7("swarm error", {
2420
2391
  error
2421
2392
  }, {
2422
- F: __dxlog_file8,
2423
- L: 181,
2393
+ F: __dxlog_file7,
2394
+ L: 185,
2424
2395
  S: this,
2425
2396
  C: (f, a) => f(...a)
2426
2397
  });
@@ -2428,47 +2399,47 @@ var SwarmNetworkManager = class {
2428
2399
  this._swarms.set(topic, swarm);
2429
2400
  this._mappers.set(topic, new SwarmMapper(swarm));
2430
2401
  await swarm.open();
2431
- this._signalConnection.join({
2402
+ this._signalConnection.join(ctx, {
2432
2403
  topic,
2433
2404
  peer: this._peerInfo
2434
- }).catch((error) => log8.catch(error, void 0, {
2435
- F: __dxlog_file8,
2436
- L: 190,
2405
+ }).catch((error) => log7.catch(error, void 0, {
2406
+ F: __dxlog_file7,
2407
+ L: 194,
2437
2408
  S: this,
2438
2409
  C: (f, a) => f(...a)
2439
2410
  }));
2440
2411
  this.topicsUpdated.emit();
2441
2412
  this._connectionLog?.joinedSwarm(swarm);
2442
- log8("joined", {
2413
+ log7("joined", {
2443
2414
  topic: PublicKey8.from(topic),
2444
2415
  count: this._swarms.size
2445
2416
  }, {
2446
- F: __dxlog_file8,
2447
- L: 194,
2417
+ F: __dxlog_file7,
2418
+ L: 198,
2448
2419
  S: this,
2449
2420
  C: (f, a) => f(...a)
2450
2421
  });
2451
2422
  return {
2452
- close: () => this.leaveSwarm(topic)
2423
+ close: (ctx2) => this.leaveSwarm(ctx2, topic)
2453
2424
  };
2454
2425
  }
2455
2426
  /**
2456
2427
  * Close the connection.
2457
2428
  */
2458
- async leaveSwarm(topic) {
2429
+ async leaveSwarm(ctx, topic) {
2459
2430
  if (!this._swarms.has(topic)) {
2460
2431
  return;
2461
2432
  }
2462
- log8("leaving", {
2433
+ log7("leaving", {
2463
2434
  topic: PublicKey8.from(topic)
2464
2435
  }, {
2465
- F: __dxlog_file8,
2466
- L: 211,
2436
+ F: __dxlog_file7,
2437
+ L: 215,
2467
2438
  S: this,
2468
2439
  C: (f, a) => f(...a)
2469
2440
  });
2470
2441
  const swarm = this._swarms.get(topic);
2471
- await this._signalConnection.leave({
2442
+ await this._signalConnection.leave(ctx, {
2472
2443
  topic,
2473
2444
  peer: swarm.ownPeer
2474
2445
  });
@@ -2479,12 +2450,12 @@ var SwarmNetworkManager = class {
2479
2450
  await swarm.destroy();
2480
2451
  this._swarms.delete(topic);
2481
2452
  this.topicsUpdated.emit();
2482
- log8("left", {
2453
+ log7("left", {
2483
2454
  topic: PublicKey8.from(topic),
2484
2455
  count: this._swarms.size
2485
2456
  }, {
2486
- F: __dxlog_file8,
2487
- L: 225,
2457
+ F: __dxlog_file7,
2458
+ L: 229,
2488
2459
  S: this,
2489
2460
  C: (f, a) => f(...a)
2490
2461
  });
@@ -2525,7 +2496,7 @@ _ts_decorate4([
2525
2496
 
2526
2497
  // src/topology/fully-connected-topology.ts
2527
2498
  import { invariant as invariant7 } from "@dxos/invariant";
2528
- var __dxlog_file9 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
2499
+ var __dxlog_file8 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
2529
2500
  var FullyConnectedTopology = class {
2530
2501
  _controller;
2531
2502
  toString() {
@@ -2533,7 +2504,7 @@ var FullyConnectedTopology = class {
2533
2504
  }
2534
2505
  init(controller) {
2535
2506
  invariant7(!this._controller, "Already initialized", {
2536
- F: __dxlog_file9,
2507
+ F: __dxlog_file8,
2537
2508
  L: 18,
2538
2509
  S: this,
2539
2510
  A: [
@@ -2545,7 +2516,7 @@ var FullyConnectedTopology = class {
2545
2516
  }
2546
2517
  update() {
2547
2518
  invariant7(this._controller, "Not initialized", {
2548
- F: __dxlog_file9,
2519
+ F: __dxlog_file8,
2549
2520
  L: 23,
2550
2521
  S: this,
2551
2522
  A: [
@@ -2565,321 +2536,13 @@ var FullyConnectedTopology = class {
2565
2536
  }
2566
2537
  };
2567
2538
 
2568
- // src/topology/mmst-topology.ts
2569
- import { invariant as invariant8 } from "@dxos/invariant";
2570
- import { log as log9 } from "@dxos/log";
2571
- var __dxlog_file10 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/topology/mmst-topology.ts";
2572
- var MIN_UPDATE_INTERVAL = 1e3 * 10;
2573
- var MAX_CHANGES_PER_UPDATE = 1;
2574
- var MMSTTopology = class {
2575
- _originateConnections;
2576
- _maxPeers;
2577
- _sampleSize;
2578
- _controller;
2579
- _sampleCollected = false;
2580
- _lastAction = /* @__PURE__ */ new Date(0);
2581
- constructor({ originateConnections = 2, maxPeers = 4, sampleSize = 10 } = {}) {
2582
- this._originateConnections = originateConnections;
2583
- this._maxPeers = maxPeers;
2584
- this._sampleSize = sampleSize;
2585
- }
2586
- init(controller) {
2587
- invariant8(!this._controller, "Already initialized", {
2588
- F: __dxlog_file10,
2589
- L: 49,
2590
- S: this,
2591
- A: [
2592
- "!this._controller",
2593
- "'Already initialized'"
2594
- ]
2595
- });
2596
- this._controller = controller;
2597
- }
2598
- update() {
2599
- invariant8(this._controller, "Not initialized", {
2600
- F: __dxlog_file10,
2601
- L: 54,
2602
- S: this,
2603
- A: [
2604
- "this._controller",
2605
- "'Not initialized'"
2606
- ]
2607
- });
2608
- const { connected, candidates } = this._controller.getState();
2609
- if (this._sampleCollected || connected.length > this._maxPeers || candidates.length > 0) {
2610
- log9("Running the algorithm.", void 0, {
2611
- F: __dxlog_file10,
2612
- L: 58,
2613
- S: this,
2614
- C: (f, a) => f(...a)
2615
- });
2616
- this._sampleCollected = true;
2617
- this._runAlgorithm();
2618
- }
2619
- }
2620
- forceUpdate() {
2621
- this._lastAction = /* @__PURE__ */ new Date(0);
2622
- this.update();
2623
- }
2624
- async onOffer(peer) {
2625
- invariant8(this._controller, "Not initialized", {
2626
- F: __dxlog_file10,
2627
- L: 70,
2628
- S: this,
2629
- A: [
2630
- "this._controller",
2631
- "'Not initialized'"
2632
- ]
2633
- });
2634
- const { connected } = this._controller.getState();
2635
- const accept = connected.length < this._maxPeers;
2636
- log9(`Offer ${peer} accept=${accept}`, void 0, {
2637
- F: __dxlog_file10,
2638
- L: 73,
2639
- S: this,
2640
- C: (f, a) => f(...a)
2641
- });
2642
- return accept;
2643
- }
2644
- async destroy() {
2645
- }
2646
- _runAlgorithm() {
2647
- invariant8(this._controller, "Not initialized", {
2648
- F: __dxlog_file10,
2649
- L: 82,
2650
- S: this,
2651
- A: [
2652
- "this._controller",
2653
- "'Not initialized'"
2654
- ]
2655
- });
2656
- const { connected, candidates, ownPeerId } = this._controller.getState();
2657
- if (connected.length > this._maxPeers) {
2658
- log9(`disconnect ${connected.length - this._maxPeers} peers.`, void 0, {
2659
- F: __dxlog_file10,
2660
- L: 88,
2661
- S: this,
2662
- C: (f, a) => f(...a)
2663
- });
2664
- const sorted = sortByXorDistance(connected, ownPeerId).reverse().slice(0, this._maxPeers - connected.length);
2665
- invariant8(sorted.length === 0, void 0, {
2666
- F: __dxlog_file10,
2667
- L: 92,
2668
- S: this,
2669
- A: [
2670
- "sorted.length === 0",
2671
- ""
2672
- ]
2673
- });
2674
- if (sorted.length > MAX_CHANGES_PER_UPDATE) {
2675
- log9(`want to disconnect ${sorted.length} peers but limited to ${MAX_CHANGES_PER_UPDATE}`, void 0, {
2676
- F: __dxlog_file10,
2677
- L: 95,
2678
- S: this,
2679
- C: (f, a) => f(...a)
2680
- });
2681
- }
2682
- if (Date.now() - this._lastAction.getTime() > MIN_UPDATE_INTERVAL) {
2683
- for (const peer of sorted.slice(0, MAX_CHANGES_PER_UPDATE)) {
2684
- log9(`Disconnect ${peer}.`, void 0, {
2685
- F: __dxlog_file10,
2686
- L: 100,
2687
- S: this,
2688
- C: (f, a) => f(...a)
2689
- });
2690
- this._controller.disconnect(peer);
2691
- }
2692
- this._lastAction = /* @__PURE__ */ new Date();
2693
- } else {
2694
- log9("rate limited disconnect", void 0, {
2695
- F: __dxlog_file10,
2696
- L: 105,
2697
- S: this,
2698
- C: (f, a) => f(...a)
2699
- });
2700
- }
2701
- } else if (connected.length < this._originateConnections) {
2702
- log9(`connect ${this._originateConnections - connected.length} peers.`, void 0, {
2703
- F: __dxlog_file10,
2704
- L: 109,
2705
- S: this,
2706
- C: (f, a) => f(...a)
2707
- });
2708
- const sample = candidates.sort(() => Math.random() - 0.5).slice(0, this._sampleSize);
2709
- const sorted = sortByXorDistance(sample, ownPeerId).slice(0, this._originateConnections - connected.length);
2710
- if (sorted.length > MAX_CHANGES_PER_UPDATE) {
2711
- log9(`want to connect ${sorted.length} peers but limited to ${MAX_CHANGES_PER_UPDATE}`, void 0, {
2712
- F: __dxlog_file10,
2713
- L: 114,
2714
- S: this,
2715
- C: (f, a) => f(...a)
2716
- });
2717
- }
2718
- if (Date.now() - this._lastAction.getTime() > MIN_UPDATE_INTERVAL) {
2719
- for (const peer of sorted.slice(0, MAX_CHANGES_PER_UPDATE)) {
2720
- log9(`Connect ${peer}.`, void 0, {
2721
- F: __dxlog_file10,
2722
- L: 118,
2723
- S: this,
2724
- C: (f, a) => f(...a)
2725
- });
2726
- this._controller.connect(peer);
2727
- }
2728
- this._lastAction = /* @__PURE__ */ new Date();
2729
- } else {
2730
- log9("rate limited connect", void 0, {
2731
- F: __dxlog_file10,
2732
- L: 123,
2733
- S: this,
2734
- C: (f, a) => f(...a)
2735
- });
2736
- }
2737
- }
2738
- }
2739
- toString() {
2740
- return "MMSTTopology";
2741
- }
2742
- };
2743
- var sortByXorDistance = (keys, reference) => {
2744
- const sorted = keys.sort((a, b) => {
2745
- return compareXor(distXor(a.asBuffer(), reference.asBuffer()), distXor(b.asBuffer(), reference.asBuffer()));
2746
- });
2747
- log9("Sorted keys", {
2748
- keys,
2749
- reference,
2750
- sorted
2751
- }, {
2752
- F: __dxlog_file10,
2753
- L: 137,
2754
- S: void 0,
2755
- C: (f, a) => f(...a)
2756
- });
2757
- return sorted;
2758
- };
2759
- var distXor = (a, b) => {
2760
- const maxLength = Math.max(a.length, b.length);
2761
- const result = Buffer.allocUnsafe(maxLength);
2762
- for (let i = 0; i < maxLength; i++) {
2763
- result[i] = (a[i] || 0) ^ (b[i] || 0);
2764
- }
2765
- return result;
2766
- };
2767
- var compareXor = (a, b) => {
2768
- const maxLength = Math.max(a.length, b.length);
2769
- for (let i = 0; i < maxLength; i++) {
2770
- if ((a[i] || 0) === (b[i] || 0)) {
2771
- continue;
2772
- }
2773
- return (a[i] || 0) < (b[i] || 0) ? -1 : 1;
2774
- }
2775
- return 0;
2776
- };
2777
-
2778
- // src/topology/star-topology.ts
2779
- import { invariant as invariant9 } from "@dxos/invariant";
2780
- import { log as log10 } from "@dxos/log";
2781
- var __dxlog_file11 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/topology/star-topology.ts";
2782
- var StarTopology = class {
2783
- _centralPeer;
2784
- _controller;
2785
- constructor(_centralPeer) {
2786
- this._centralPeer = _centralPeer;
2787
- }
2788
- toString() {
2789
- return `StarTopology(${this._centralPeer.truncate()})`;
2790
- }
2791
- init(controller) {
2792
- invariant9(!this._controller, "Already initialized.", {
2793
- F: __dxlog_file11,
2794
- L: 21,
2795
- S: this,
2796
- A: [
2797
- "!this._controller",
2798
- "'Already initialized.'"
2799
- ]
2800
- });
2801
- this._controller = controller;
2802
- }
2803
- update() {
2804
- invariant9(this._controller, "Not initialized.", {
2805
- F: __dxlog_file11,
2806
- L: 26,
2807
- S: this,
2808
- A: [
2809
- "this._controller",
2810
- "'Not initialized.'"
2811
- ]
2812
- });
2813
- const { candidates, connected, ownPeerId } = this._controller.getState();
2814
- if (!ownPeerId.equals(this._centralPeer)) {
2815
- log10("leaf peer dropping all connections apart from central peer.", void 0, {
2816
- F: __dxlog_file11,
2817
- L: 29,
2818
- S: this,
2819
- C: (f, a) => f(...a)
2820
- });
2821
- for (const peer of connected) {
2822
- if (!peer.equals(this._centralPeer)) {
2823
- log10("dropping connection", {
2824
- peer
2825
- }, {
2826
- F: __dxlog_file11,
2827
- L: 34,
2828
- S: this,
2829
- C: (f, a) => f(...a)
2830
- });
2831
- this._controller.disconnect(peer);
2832
- }
2833
- }
2834
- }
2835
- for (const peer of candidates) {
2836
- if (peer.equals(this._centralPeer) || ownPeerId.equals(this._centralPeer)) {
2837
- log10("connecting to peer", {
2838
- peer
2839
- }, {
2840
- F: __dxlog_file11,
2841
- L: 43,
2842
- S: this,
2843
- C: (f, a) => f(...a)
2844
- });
2845
- this._controller.connect(peer);
2846
- }
2847
- }
2848
- }
2849
- async onOffer(peer) {
2850
- invariant9(this._controller, "Not initialized.", {
2851
- F: __dxlog_file11,
2852
- L: 50,
2853
- S: this,
2854
- A: [
2855
- "this._controller",
2856
- "'Not initialized.'"
2857
- ]
2858
- });
2859
- const { ownPeerId } = this._controller.getState();
2860
- log10("offer", {
2861
- peer,
2862
- isCentral: peer.equals(this._centralPeer),
2863
- isSelfCentral: ownPeerId.equals(this._centralPeer)
2864
- }, {
2865
- F: __dxlog_file11,
2866
- L: 52,
2867
- S: this,
2868
- C: (f, a) => f(...a)
2869
- });
2870
- return ownPeerId.equals(this._centralPeer) || peer.equals(this._centralPeer);
2871
- }
2872
- async destroy() {
2873
- }
2874
- };
2875
-
2876
2539
  // src/transport/memory-transport.ts
2877
2540
  import { Transform } from "@dxos/node-std/stream";
2878
2541
  import { Event as Event7, Trigger as Trigger2 } from "@dxos/async";
2879
2542
  import { ErrorStream as ErrorStream3 } from "@dxos/debug";
2880
- import { invariant as invariant10 } from "@dxos/invariant";
2543
+ import { invariant as invariant8 } from "@dxos/invariant";
2881
2544
  import { PublicKey as PublicKey9 } from "@dxos/keys";
2882
- import { log as log11, logInfo as logInfo3 } from "@dxos/log";
2545
+ import { log as log8, logInfo as logInfo3 } from "@dxos/log";
2883
2546
  import { ComplexMap as ComplexMap7 } from "@dxos/util";
2884
2547
  function _ts_decorate5(decorators, target, key, desc) {
2885
2548
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -2887,7 +2550,7 @@ function _ts_decorate5(decorators, target, key, desc) {
2887
2550
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2888
2551
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2889
2552
  }
2890
- var __dxlog_file12 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
2553
+ var __dxlog_file9 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
2891
2554
  var MEMORY_TRANSPORT_DELAY = 1;
2892
2555
  var createStreamDelay = (delay) => {
2893
2556
  return new Transform({
@@ -2916,8 +2579,8 @@ var MemoryTransport = class _MemoryTransport {
2916
2579
  errors = new ErrorStream3();
2917
2580
  constructor(_options) {
2918
2581
  this._options = _options;
2919
- invariant10(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection", {
2920
- F: __dxlog_file12,
2582
+ invariant8(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection", {
2583
+ F: __dxlog_file9,
2921
2584
  L: 64,
2922
2585
  S: this,
2923
2586
  A: [
@@ -2931,15 +2594,15 @@ var MemoryTransport = class _MemoryTransport {
2931
2594
  return !this._closed;
2932
2595
  }
2933
2596
  async open() {
2934
- log11("opening...", void 0, {
2935
- F: __dxlog_file12,
2597
+ log8("opening...", void 0, {
2598
+ F: __dxlog_file9,
2936
2599
  L: 74,
2937
2600
  S: this,
2938
2601
  C: (f, a) => f(...a)
2939
2602
  });
2940
2603
  if (this._options.initiator) {
2941
- log11("sending signal", void 0, {
2942
- F: __dxlog_file12,
2604
+ log8("sending signal", void 0, {
2605
+ F: __dxlog_file9,
2943
2606
  L: 78,
2944
2607
  S: this,
2945
2608
  C: (f, a) => f(...a)
@@ -2969,8 +2632,8 @@ var MemoryTransport = class _MemoryTransport {
2969
2632
  this.closed.emit();
2970
2633
  return;
2971
2634
  }
2972
- invariant10(!this._remoteConnection._remoteConnection, `Remote already connected: ${this._remoteInstanceId}`, {
2973
- F: __dxlog_file12,
2635
+ invariant8(!this._remoteConnection._remoteConnection, `Remote already connected: ${this._remoteInstanceId}`, {
2636
+ F: __dxlog_file9,
2974
2637
  L: 104,
2975
2638
  S: this,
2976
2639
  A: [
@@ -2980,8 +2643,8 @@ var MemoryTransport = class _MemoryTransport {
2980
2643
  });
2981
2644
  this._remoteConnection._remoteConnection = this;
2982
2645
  this._remoteConnection._remoteInstanceId = this._instanceId;
2983
- log11("connected", void 0, {
2984
- F: __dxlog_file12,
2646
+ log8("connected", void 0, {
2647
+ F: __dxlog_file9,
2985
2648
  L: 108,
2986
2649
  S: this,
2987
2650
  C: (f, a) => f(...a)
@@ -2999,8 +2662,8 @@ var MemoryTransport = class _MemoryTransport {
2999
2662
  return this;
3000
2663
  }
3001
2664
  async close() {
3002
- log11("closing...", void 0, {
3003
- F: __dxlog_file12,
2665
+ log8("closing...", void 0, {
2666
+ F: __dxlog_file9,
3004
2667
  L: 130,
3005
2668
  S: this,
3006
2669
  C: (f, a) => f(...a)
@@ -3020,8 +2683,8 @@ var MemoryTransport = class _MemoryTransport {
3020
2683
  this._remoteConnection = void 0;
3021
2684
  }
3022
2685
  this.closed.emit();
3023
- log11("closed", void 0, {
3024
- F: __dxlog_file12,
2686
+ log8("closed", void 0, {
2687
+ F: __dxlog_file9,
3025
2688
  L: 158,
3026
2689
  S: this,
3027
2690
  C: (f, a) => f(...a)
@@ -3029,10 +2692,10 @@ var MemoryTransport = class _MemoryTransport {
3029
2692
  return this;
3030
2693
  }
3031
2694
  async onSignal({ payload }) {
3032
- log11("received signal", {
2695
+ log8("received signal", {
3033
2696
  payload
3034
2697
  }, {
3035
- F: __dxlog_file12,
2698
+ F: __dxlog_file9,
3036
2699
  L: 163,
3037
2700
  S: this,
3038
2701
  C: (f, a) => f(...a)
@@ -3122,8 +2785,8 @@ var getRtcConnectionFactory = () => {
3122
2785
 
3123
2786
  // src/transport/webrtc/rtc-peer-connection.ts
3124
2787
  import { Mutex as Mutex2, Trigger as Trigger3, synchronized as synchronized5 } from "@dxos/async";
3125
- import { invariant as invariant12 } from "@dxos/invariant";
3126
- import { log as log13, logInfo as logInfo4 } from "@dxos/log";
2788
+ import { invariant as invariant10 } from "@dxos/invariant";
2789
+ import { log as log10, logInfo as logInfo4 } from "@dxos/log";
3127
2790
  import { ConnectivityError as ConnectivityError3 } from "@dxos/protocols";
3128
2791
  import { trace as trace4 } from "@dxos/tracing";
3129
2792
 
@@ -3132,8 +2795,8 @@ import { Duplex } from "@dxos/node-std/stream";
3132
2795
  import { Event as AsyncEvent } from "@dxos/async";
3133
2796
  import { Resource } from "@dxos/context";
3134
2797
  import { ErrorStream as ErrorStream4 } from "@dxos/debug";
3135
- import { invariant as invariant11 } from "@dxos/invariant";
3136
- import { log as log12 } from "@dxos/log";
2798
+ import { invariant as invariant9 } from "@dxos/invariant";
2799
+ import { log as log9 } from "@dxos/log";
3137
2800
  import { ConnectivityError as ConnectivityError2 } from "@dxos/protocols";
3138
2801
 
3139
2802
  // src/transport/webrtc/rtc-transport-stats.ts
@@ -3184,7 +2847,7 @@ var getRtcConnectionStats = async (connection, channelTopic) => {
3184
2847
  };
3185
2848
 
3186
2849
  // src/transport/webrtc/rtc-transport-channel.ts
3187
- var __dxlog_file13 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-channel.ts";
2850
+ var __dxlog_file10 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-channel.ts";
3188
2851
  var MAX_MESSAGE_SIZE = 64 * 1024;
3189
2852
  var MAX_BUFFERED_AMOUNT = 64 * 1024;
3190
2853
  var RtcTransportChannel = class extends Resource {
@@ -3209,9 +2872,9 @@ var RtcTransportChannel = class extends Resource {
3209
2872
  }
3210
2873
  }
3211
2874
  async _open() {
3212
- invariant11(!this._isChannelCreationInProgress, void 0, {
3213
- F: __dxlog_file13,
3214
- L: 57,
2875
+ invariant9(!this._isChannelCreationInProgress, void 0, {
2876
+ F: __dxlog_file10,
2877
+ L: 56,
3215
2878
  S: this,
3216
2879
  A: [
3217
2880
  "!this._isChannelCreationInProgress",
@@ -3228,14 +2891,16 @@ var RtcTransportChannel = class extends Resource {
3228
2891
  }
3229
2892
  }).catch((err) => {
3230
2893
  if (this.isOpen) {
3231
- const error = err instanceof Error ? err : new ConnectivityError2(`Failed to create a channel: ${JSON.stringify(err?.message)}`);
2894
+ const error = err instanceof Error ? err : new ConnectivityError2({
2895
+ message: `Failed to create a channel: ${JSON.stringify(err?.message)}`
2896
+ });
3232
2897
  this.errors.raise(error);
3233
2898
  } else {
3234
- log12.verbose("connection establishment failed after transport was closed", {
2899
+ log9.verbose("connection establishment failed after transport was closed", {
3235
2900
  err
3236
2901
  }, {
3237
- F: __dxlog_file13,
3238
- L: 77,
2902
+ F: __dxlog_file10,
2903
+ L: 76,
3239
2904
  S: this,
3240
2905
  C: (f, a) => f(...a)
3241
2906
  });
@@ -3251,9 +2916,9 @@ var RtcTransportChannel = class extends Resource {
3251
2916
  this._stream = void 0;
3252
2917
  }
3253
2918
  this.closed.emit();
3254
- log12("closed", void 0, {
3255
- F: __dxlog_file13,
3256
- L: 93,
2919
+ log9("closed", void 0, {
2920
+ F: __dxlog_file10,
2921
+ L: 92,
3257
2922
  S: this,
3258
2923
  C: (f, a) => f(...a)
3259
2924
  });
@@ -3262,20 +2927,20 @@ var RtcTransportChannel = class extends Resource {
3262
2927
  Object.assign(channel, {
3263
2928
  onopen: () => {
3264
2929
  if (!this.isOpen) {
3265
- log12.warn("channel opened in a closed transport", {
2930
+ log9.warn("channel opened in a closed transport", {
3266
2931
  topic: this._options.topic
3267
2932
  }, {
3268
- F: __dxlog_file13,
3269
- L: 100,
2933
+ F: __dxlog_file10,
2934
+ L: 99,
3270
2935
  S: this,
3271
2936
  C: (f, a) => f(...a)
3272
2937
  });
3273
2938
  this._safeCloseChannel(channel);
3274
2939
  return;
3275
2940
  }
3276
- log12("onopen", void 0, {
3277
- F: __dxlog_file13,
3278
- L: 105,
2941
+ log9("onopen", void 0, {
2942
+ F: __dxlog_file10,
2943
+ L: 104,
3279
2944
  S: this,
3280
2945
  C: (f, a) => f(...a)
3281
2946
  });
@@ -3291,9 +2956,9 @@ var RtcTransportChannel = class extends Resource {
3291
2956
  this.connected.emit();
3292
2957
  },
3293
2958
  onclose: async () => {
3294
- log12("onclose", void 0, {
3295
- F: __dxlog_file13,
3296
- L: 118,
2959
+ log9("onclose", void 0, {
2960
+ F: __dxlog_file10,
2961
+ L: 117,
3297
2962
  S: this,
3298
2963
  C: (f, a) => f(...a)
3299
2964
  });
@@ -3301,9 +2966,9 @@ var RtcTransportChannel = class extends Resource {
3301
2966
  },
3302
2967
  onmessage: async (event) => {
3303
2968
  if (!this._stream) {
3304
- log12.warn("ignoring message on a closed channel", void 0, {
3305
- F: __dxlog_file13,
3306
- L: 124,
2969
+ log9.warn("ignoring message on a closed channel", void 0, {
2970
+ F: __dxlog_file10,
2971
+ L: 123,
3307
2972
  S: this,
3308
2973
  C: (f, a) => f(...a)
3309
2974
  });
@@ -3332,9 +2997,9 @@ var RtcTransportChannel = class extends Resource {
3332
2997
  }
3333
2998
  async _handleChannelWrite(chunk, callback) {
3334
2999
  if (!this._channel) {
3335
- log12.warn("writing to a channel after a connection was closed", void 0, {
3336
- F: __dxlog_file13,
3337
- L: 154,
3000
+ log9.warn("writing to a channel after a connection was closed", void 0, {
3001
+ F: __dxlog_file10,
3002
+ L: 153,
3338
3003
  S: this,
3339
3004
  C: (f, a) => f(...a)
3340
3005
  });
@@ -3355,9 +3020,9 @@ var RtcTransportChannel = class extends Resource {
3355
3020
  }
3356
3021
  if (this._channel.bufferedAmount > MAX_BUFFERED_AMOUNT) {
3357
3022
  if (this._streamDataFlushedCallback !== null) {
3358
- log12.error("consumer trying to write before we are ready for more data", void 0, {
3359
- F: __dxlog_file13,
3360
- L: 175,
3023
+ log9.error("consumer trying to write before we are ready for more data", void 0, {
3024
+ F: __dxlog_file10,
3025
+ L: 174,
3361
3026
  S: this,
3362
3027
  C: (f, a) => f(...a)
3363
3028
  });
@@ -3371,9 +3036,9 @@ var RtcTransportChannel = class extends Resource {
3371
3036
  try {
3372
3037
  channel.close();
3373
3038
  } catch (error) {
3374
- log12.catch(error, void 0, {
3375
- F: __dxlog_file13,
3376
- L: 187,
3039
+ log9.catch(error, void 0, {
3040
+ F: __dxlog_file10,
3041
+ L: 186,
3377
3042
  S: this,
3378
3043
  C: (f, a) => f(...a)
3379
3044
  });
@@ -3423,7 +3088,7 @@ function _ts_decorate6(decorators, target, key, desc) {
3423
3088
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3424
3089
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3425
3090
  }
3426
- var __dxlog_file14 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-peer-connection.ts";
3091
+ var __dxlog_file11 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-peer-connection.ts";
3427
3092
  var RtcPeerConnection = class {
3428
3093
  _factory;
3429
3094
  _options;
@@ -3471,9 +3136,9 @@ var RtcPeerConnection = class {
3471
3136
  if (existingChannel) {
3472
3137
  return existingChannel;
3473
3138
  }
3474
- log13("waiting for initiator-peer to open a data channel", void 0, {
3475
- F: __dxlog_file14,
3476
- L: 96,
3139
+ log10("waiting for initiator-peer to open a data channel", void 0, {
3140
+ F: __dxlog_file11,
3141
+ L: 95,
3477
3142
  S: this,
3478
3143
  C: (f, a) => f(...a)
3479
3144
  });
@@ -3500,11 +3165,11 @@ var RtcPeerConnection = class {
3500
3165
  if (this._connection) {
3501
3166
  return this._connection;
3502
3167
  }
3503
- log13("initializing connection...", () => ({
3168
+ log10("initializing connection...", () => ({
3504
3169
  remotePeer: this._options.remotePeerKey
3505
3170
  }), {
3506
- F: __dxlog_file14,
3507
- L: 121,
3171
+ F: __dxlog_file11,
3172
+ L: 120,
3508
3173
  S: this,
3509
3174
  C: (f, a) => f(...a)
3510
3175
  });
@@ -3513,9 +3178,9 @@ var RtcPeerConnection = class {
3513
3178
  const iceCandidateErrors = [];
3514
3179
  Object.assign(connection, {
3515
3180
  onnegotiationneeded: async () => {
3516
- invariant12(this._initiator, void 0, {
3517
- F: __dxlog_file14,
3518
- L: 136,
3181
+ invariant10(this._initiator, void 0, {
3182
+ F: __dxlog_file11,
3183
+ L: 135,
3519
3184
  S: this,
3520
3185
  A: [
3521
3186
  "this._initiator",
@@ -3526,9 +3191,9 @@ var RtcPeerConnection = class {
3526
3191
  this._onConnectionCallbackAfterClose("onnegotiationneeded", connection);
3527
3192
  return;
3528
3193
  }
3529
- log13("onnegotiationneeded", void 0, {
3530
- F: __dxlog_file14,
3531
- L: 143,
3194
+ log10("onnegotiationneeded", void 0, {
3195
+ F: __dxlog_file11,
3196
+ L: 142,
3532
3197
  S: this,
3533
3198
  C: (f, a) => f(...a)
3534
3199
  });
@@ -3548,19 +3213,19 @@ var RtcPeerConnection = class {
3548
3213
  return;
3549
3214
  }
3550
3215
  if (event.candidate) {
3551
- log13("onicecandidate", {
3216
+ log10("onicecandidate", {
3552
3217
  candidate: event.candidate.candidate
3553
3218
  }, {
3554
- F: __dxlog_file14,
3555
- L: 162,
3219
+ F: __dxlog_file11,
3220
+ L: 161,
3556
3221
  S: this,
3557
3222
  C: (f, a) => f(...a)
3558
3223
  });
3559
3224
  await this._sendIceCandidate(event.candidate);
3560
3225
  } else {
3561
- log13("onicecandidate gathering complete", void 0, {
3562
- F: __dxlog_file14,
3563
- L: 165,
3226
+ log10("onicecandidate gathering complete", void 0, {
3227
+ F: __dxlog_file11,
3228
+ L: 164,
3564
3229
  S: this,
3565
3230
  C: (f, a) => f(...a)
3566
3231
  });
@@ -3584,11 +3249,11 @@ var RtcPeerConnection = class {
3584
3249
  this._onConnectionCallbackAfterClose("oniceconnectionstatechange", connection);
3585
3250
  return;
3586
3251
  }
3587
- log13("oniceconnectionstatechange", {
3252
+ log10("oniceconnectionstatechange", {
3588
3253
  state: connection.iceConnectionState
3589
3254
  }, {
3590
- F: __dxlog_file14,
3591
- L: 185,
3255
+ F: __dxlog_file11,
3256
+ L: 184,
3592
3257
  S: this,
3593
3258
  C: (f, a) => f(...a)
3594
3259
  });
@@ -3606,11 +3271,11 @@ var RtcPeerConnection = class {
3606
3271
  }
3607
3272
  return;
3608
3273
  }
3609
- log13("onconnectionstatechange", {
3274
+ log10("onconnectionstatechange", {
3610
3275
  state: connection.connectionState
3611
3276
  }, {
3612
- F: __dxlog_file14,
3613
- L: 202,
3277
+ F: __dxlog_file11,
3278
+ L: 201,
3614
3279
  S: this,
3615
3280
  C: (f, a) => f(...a)
3616
3281
  });
@@ -3619,11 +3284,11 @@ var RtcPeerConnection = class {
3619
3284
  }
3620
3285
  },
3621
3286
  onsignalingstatechange: () => {
3622
- log13("onsignalingstatechange", {
3287
+ log10("onsignalingstatechange", {
3623
3288
  state: connection.signalingState
3624
3289
  }, {
3625
- F: __dxlog_file14,
3626
- L: 209,
3290
+ F: __dxlog_file11,
3291
+ L: 208,
3627
3292
  S: this,
3628
3293
  C: (f, a) => f(...a)
3629
3294
  });
@@ -3631,9 +3296,9 @@ var RtcPeerConnection = class {
3631
3296
  // When channel is added to connection.
3632
3297
  // https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/datachannel_event
3633
3298
  ondatachannel: (event) => {
3634
- invariant12(!this._initiator, "Initiator is expected to create data channels.", {
3635
- F: __dxlog_file14,
3636
- L: 215,
3299
+ invariant10(!this._initiator, "Initiator is expected to create data channels.", {
3300
+ F: __dxlog_file11,
3301
+ L: 214,
3637
3302
  S: this,
3638
3303
  A: [
3639
3304
  "!this._initiator",
@@ -3644,11 +3309,11 @@ var RtcPeerConnection = class {
3644
3309
  this._onConnectionCallbackAfterClose("ondatachannel", connection);
3645
3310
  return;
3646
3311
  }
3647
- log13("ondatachannel", {
3312
+ log10("ondatachannel", {
3648
3313
  label: event.channel.label
3649
3314
  }, {
3650
- F: __dxlog_file14,
3651
- L: 222,
3315
+ F: __dxlog_file11,
3316
+ L: 221,
3652
3317
  S: this,
3653
3318
  C: (f, a) => f(...a)
3654
3319
  });
@@ -3672,11 +3337,11 @@ var RtcPeerConnection = class {
3672
3337
  }
3673
3338
  _abortConnection(connection, error) {
3674
3339
  if (connection !== this._connection) {
3675
- log13.error("attempted to abort an inactive connection", {
3340
+ log10.error("attempted to abort an inactive connection", {
3676
3341
  error
3677
3342
  }, {
3678
- F: __dxlog_file14,
3679
- L: 247,
3343
+ F: __dxlog_file11,
3344
+ L: 246,
3680
3345
  S: this,
3681
3346
  C: (f, a) => f(...a)
3682
3347
  });
@@ -3693,19 +3358,19 @@ var RtcPeerConnection = class {
3693
3358
  }
3694
3359
  this._transportChannels.clear();
3695
3360
  this._safeCloseConnection();
3696
- log13("connection aborted", {
3361
+ log10("connection aborted", {
3697
3362
  reason: error.message
3698
3363
  }, {
3699
- F: __dxlog_file14,
3700
- L: 261,
3364
+ F: __dxlog_file11,
3365
+ L: 260,
3701
3366
  S: this,
3702
3367
  C: (f, a) => f(...a)
3703
3368
  });
3704
3369
  }
3705
3370
  async _lockAndCloseConnection() {
3706
- invariant12(this._transportChannels.size === 0, void 0, {
3707
- F: __dxlog_file14,
3708
- L: 266,
3371
+ invariant10(this._transportChannels.size === 0, void 0, {
3372
+ F: __dxlog_file11,
3373
+ L: 265,
3709
3374
  S: this,
3710
3375
  A: [
3711
3376
  "this._transportChannels.size === 0",
@@ -3714,9 +3379,9 @@ var RtcPeerConnection = class {
3714
3379
  });
3715
3380
  if (this._connection) {
3716
3381
  this._safeCloseConnection();
3717
- log13("connection closed", void 0, {
3718
- F: __dxlog_file14,
3719
- L: 269,
3382
+ log10("connection closed", void 0, {
3383
+ F: __dxlog_file11,
3384
+ L: 268,
3720
3385
  S: this,
3721
3386
  C: (f, a) => f(...a)
3722
3387
  });
@@ -3725,11 +3390,11 @@ var RtcPeerConnection = class {
3725
3390
  async onSignal(signal) {
3726
3391
  const connection = this._connection;
3727
3392
  if (!connection) {
3728
- log13.warn("a signal ignored because the connection was closed", {
3393
+ log10.warn("a signal ignored because the connection was closed", {
3729
3394
  type: signal.payload.data.type
3730
3395
  }, {
3731
- F: __dxlog_file14,
3732
- L: 277,
3396
+ F: __dxlog_file11,
3397
+ L: 276,
3733
3398
  S: this,
3734
3399
  C: (f, a) => f(...a)
3735
3400
  });
@@ -3792,11 +3457,11 @@ var RtcPeerConnection = class {
3792
3457
  this._abortConnection(connection, new Error(`Unknown signal type ${data.type}.`));
3793
3458
  break;
3794
3459
  }
3795
- log13("signal processed", {
3460
+ log10("signal processed", {
3796
3461
  type: data.type
3797
3462
  }, {
3798
- F: __dxlog_file14,
3799
- L: 336,
3463
+ F: __dxlog_file11,
3464
+ L: 335,
3800
3465
  S: this,
3801
3466
  C: (f, a) => f(...a)
3802
3467
  });
@@ -3805,20 +3470,20 @@ var RtcPeerConnection = class {
3805
3470
  try {
3806
3471
  await this._readyForCandidates.wait();
3807
3472
  if (connection === this._connection) {
3808
- log13("adding ice candidate", {
3473
+ log10("adding ice candidate", {
3809
3474
  candidate
3810
3475
  }, {
3811
- F: __dxlog_file14,
3812
- L: 344,
3476
+ F: __dxlog_file11,
3477
+ L: 343,
3813
3478
  S: this,
3814
3479
  C: (f, a) => f(...a)
3815
3480
  });
3816
3481
  await connection.addIceCandidate(candidate);
3817
3482
  }
3818
3483
  } catch (err) {
3819
- log13.catch(err, void 0, {
3820
- F: __dxlog_file14,
3821
- L: 348,
3484
+ log10.catch(err, void 0, {
3485
+ F: __dxlog_file11,
3486
+ L: 347,
3822
3487
  S: this,
3823
3488
  C: (f, a) => f(...a)
3824
3489
  });
@@ -3826,29 +3491,29 @@ var RtcPeerConnection = class {
3826
3491
  }
3827
3492
  _onSessionNegotiated(connection) {
3828
3493
  if (connection === this._connection) {
3829
- log13("ready to process ice candidates", void 0, {
3830
- F: __dxlog_file14,
3831
- L: 354,
3494
+ log10("ready to process ice candidates", void 0, {
3495
+ F: __dxlog_file11,
3496
+ L: 353,
3832
3497
  S: this,
3833
3498
  C: (f, a) => f(...a)
3834
3499
  });
3835
3500
  this._readyForCandidates.wake();
3836
3501
  } else {
3837
- log13.warn("session was negotiated after connection became inactive", void 0, {
3838
- F: __dxlog_file14,
3839
- L: 357,
3502
+ log10.warn("session was negotiated after connection became inactive", void 0, {
3503
+ F: __dxlog_file11,
3504
+ L: 356,
3840
3505
  S: this,
3841
3506
  C: (f, a) => f(...a)
3842
3507
  });
3843
3508
  }
3844
3509
  }
3845
3510
  _onConnectionCallbackAfterClose(callback, connection) {
3846
- log13.warn("callback invoked after a connection was destroyed, this is probably a bug", {
3511
+ log10.warn("callback invoked after a connection was destroyed, this is probably a bug", {
3847
3512
  callback,
3848
3513
  state: connection.connectionState
3849
3514
  }, {
3850
- F: __dxlog_file14,
3851
- L: 362,
3515
+ F: __dxlog_file11,
3516
+ L: 361,
3852
3517
  S: this,
3853
3518
  C: (f, a) => f(...a)
3854
3519
  });
@@ -3859,9 +3524,9 @@ var RtcPeerConnection = class {
3859
3524
  try {
3860
3525
  connection?.close();
3861
3526
  } catch (err) {
3862
- log13.catch(err, void 0, {
3863
- F: __dxlog_file14,
3864
- L: 374,
3527
+ log10.catch(err, void 0, {
3528
+ F: __dxlog_file11,
3529
+ L: 373,
3865
3530
  S: this,
3866
3531
  C: (f, a) => f(...a)
3867
3532
  });
@@ -3870,9 +3535,9 @@ var RtcPeerConnection = class {
3870
3535
  this._connection = void 0;
3871
3536
  this._dataChannels.clear();
3872
3537
  this._readyForCandidates.wake();
3873
- void this._factory.onConnectionDestroyed().catch((err) => log13.catch(err, void 0, {
3874
- F: __dxlog_file14,
3875
- L: 380,
3538
+ void this._factory.onConnectionDestroyed().catch((err) => log10.catch(err, void 0, {
3539
+ F: __dxlog_file11,
3540
+ L: 379,
3876
3541
  S: this,
3877
3542
  C: (f, a) => f(...a)
3878
3543
  }));
@@ -3895,9 +3560,9 @@ var RtcPeerConnection = class {
3895
3560
  ];
3896
3561
  }
3897
3562
  } catch (error) {
3898
- log13.catch(error, void 0, {
3899
- F: __dxlog_file14,
3900
- L: 396,
3563
+ log10.catch(error, void 0, {
3564
+ F: __dxlog_file11,
3565
+ L: 395,
3901
3566
  S: this,
3902
3567
  C: (f, a) => f(...a)
3903
3568
  });
@@ -3920,11 +3585,11 @@ var RtcPeerConnection = class {
3920
3585
  }
3921
3586
  });
3922
3587
  } catch (err) {
3923
- log13.warn("signaling error", {
3588
+ log10.warn("signaling error", {
3924
3589
  err
3925
3590
  }, {
3926
- F: __dxlog_file14,
3927
- L: 417,
3591
+ F: __dxlog_file11,
3592
+ L: 416,
3928
3593
  S: this,
3929
3594
  C: (f, a) => f(...a)
3930
3595
  });
@@ -4001,8 +3666,10 @@ var isRemoteDescriptionSet = (connection, data) => {
4001
3666
  };
4002
3667
  var createIceFailureError = (details) => {
4003
3668
  const candidateErrors = details.map(({ url, errorCode, errorText }) => `${errorCode} ${url}: ${errorText}`);
4004
- return new ConnectivityError3(`ICE failed:
4005
- ${candidateErrors.join("\n")}`);
3669
+ return new ConnectivityError3({
3670
+ message: `ICE failed:
3671
+ ${candidateErrors.join("\n")}`
3672
+ });
4006
3673
  };
4007
3674
 
4008
3675
  // src/transport/webrtc/rtc-transport-factory.ts
@@ -4028,13 +3695,13 @@ import { Writable } from "@dxos/node-std/stream";
4028
3695
  import { Event as Event8, scheduleTask as scheduleTask4 } from "@dxos/async";
4029
3696
  import { Resource as Resource2 } from "@dxos/context";
4030
3697
  import { ErrorStream as ErrorStream5 } from "@dxos/debug";
4031
- import { invariant as invariant13 } from "@dxos/invariant";
3698
+ import { invariant as invariant11 } from "@dxos/invariant";
4032
3699
  import { PublicKey as PublicKey10 } from "@dxos/keys";
4033
- import { log as log14 } from "@dxos/log";
3700
+ import { log as log11 } from "@dxos/log";
4034
3701
  import { ConnectionResetError as ConnectionResetError2, ConnectivityError as ConnectivityError4, TimeoutError as TimeoutError3 } from "@dxos/protocols";
4035
3702
  import { ConnectionState as ConnectionState3 } from "@dxos/protocols/proto/dxos/mesh/bridge";
4036
3703
  import { arrayToBuffer } from "@dxos/util";
4037
- var __dxlog_file15 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-proxy.ts";
3704
+ var __dxlog_file12 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-proxy.ts";
4038
3705
  var RPC_TIMEOUT = 1e4;
4039
3706
  var CLOSE_RPC_TIMEOUT = 3e3;
4040
3707
  var RESP_MIN_THRESHOLD = 500;
@@ -4067,8 +3734,8 @@ var RtcTransportProxy = class extends Resource2 {
4067
3734
  this._serviceStream = stream;
4068
3735
  stream.waitUntilReady().then(() => {
4069
3736
  stream.subscribe(async (event) => {
4070
- log14("rtc transport proxy event", event, {
4071
- F: __dxlog_file15,
3737
+ log11("rtc transport proxy event", event, {
3738
+ F: __dxlog_file12,
4072
3739
  L: 66,
4073
3740
  S: this,
4074
3741
  C: (f, a) => f(...a)
@@ -4081,10 +3748,10 @@ var RtcTransportProxy = class extends Resource2 {
4081
3748
  await this._handleSignal(event.signal);
4082
3749
  }
4083
3750
  }, (err) => {
4084
- log14("rtc bridge stream closed", {
3751
+ log11("rtc bridge stream closed", {
4085
3752
  err
4086
3753
  }, {
4087
- F: __dxlog_file15,
3754
+ F: __dxlog_file12,
4088
3755
  L: 76,
4089
3756
  S: this,
4090
3757
  C: (f, a) => f(...a)
@@ -4105,8 +3772,8 @@ var RtcTransportProxy = class extends Resource2 {
4105
3772
  timeout: RPC_TIMEOUT
4106
3773
  }).then(() => {
4107
3774
  if (Date.now() - sendStartMs > RESP_MIN_THRESHOLD) {
4108
- log14("slow response, delaying callback", void 0, {
4109
- F: __dxlog_file15,
3775
+ log11("slow response, delaying callback", void 0, {
3776
+ F: __dxlog_file12,
4110
3777
  L: 93,
4111
3778
  S: this,
4112
3779
  C: (f, a) => f(...a)
@@ -4138,8 +3805,8 @@ var RtcTransportProxy = class extends Resource2 {
4138
3805
  await this._serviceStream?.close();
4139
3806
  this._serviceStream = void 0;
4140
3807
  } catch (err) {
4141
- log14.catch(err, void 0, {
4142
- F: __dxlog_file15,
3808
+ log11.catch(err, void 0, {
3809
+ F: __dxlog_file12,
4143
3810
  L: 128,
4144
3811
  S: this,
4145
3812
  C: (f, a) => f(...a)
@@ -4152,8 +3819,8 @@ var RtcTransportProxy = class extends Resource2 {
4152
3819
  timeout: CLOSE_RPC_TIMEOUT
4153
3820
  });
4154
3821
  } catch (err) {
4155
- log14.catch(err, void 0, {
4156
- F: __dxlog_file15,
3822
+ log11.catch(err, void 0, {
3823
+ F: __dxlog_file12,
4157
3824
  L: 134,
4158
3825
  S: this,
4159
3826
  C: (f, a) => f(...a)
@@ -4198,7 +3865,9 @@ var RtcTransportProxy = class extends Resource2 {
4198
3865
  } catch (error) {
4199
3866
  const type = signalEvent.payload.payload.data?.type;
4200
3867
  if (type === "offer" || type === "answer") {
4201
- this._raiseIfOpen(new ConnectivityError4(`Session establishment failed: ${type} couldn't be sent.`));
3868
+ this._raiseIfOpen(new ConnectivityError4({
3869
+ message: `Session establishment failed: ${type} couldn't be sent.`
3870
+ }));
4202
3871
  }
4203
3872
  }
4204
3873
  }
@@ -4236,11 +3905,11 @@ var RtcTransportProxy = class extends Resource2 {
4236
3905
  if (this.isOpen) {
4237
3906
  this.errors.raise(error);
4238
3907
  } else {
4239
- log14.info("error swallowed because transport was closed", {
3908
+ log11.info("error swallowed because transport was closed", {
4240
3909
  message: error.message
4241
3910
  }, {
4242
- F: __dxlog_file15,
4243
- L: 215,
3911
+ F: __dxlog_file12,
3912
+ L: 217,
4244
3913
  S: this,
4245
3914
  C: (f, a) => f(...a)
4246
3915
  });
@@ -4269,9 +3938,9 @@ var RtcTransportProxyFactory = class {
4269
3938
  return this;
4270
3939
  }
4271
3940
  createTransport(options) {
4272
- invariant13(this._bridgeService, "RtcTransportProxyFactory is not ready to open connections", {
4273
- F: __dxlog_file15,
4274
- L: 245,
3941
+ invariant11(this._bridgeService, "RtcTransportProxyFactory is not ready to open connections", {
3942
+ F: __dxlog_file12,
3943
+ L: 247,
4275
3944
  S: this,
4276
3945
  A: [
4277
3946
  "this._bridgeService",
@@ -4292,11 +3961,17 @@ var RtcTransportProxyFactory = class {
4292
3961
  var decodeError = (err) => {
4293
3962
  const message = typeof err === "string" ? err : err.message;
4294
3963
  if (message.includes("CONNECTION_RESET")) {
4295
- return new ConnectionResetError2(message);
3964
+ return new ConnectionResetError2({
3965
+ message
3966
+ });
4296
3967
  } else if (message.includes("TIMEOUT")) {
4297
- return new TimeoutError3(message);
3968
+ return new TimeoutError3({
3969
+ message
3970
+ });
4298
3971
  } else if (message.includes("CONNECTIVITY_ERROR")) {
4299
- return new ConnectivityError4(message);
3972
+ return new ConnectivityError4({
3973
+ message
3974
+ });
4300
3975
  } else {
4301
3976
  return typeof err === "string" ? new Error(err) : err;
4302
3977
  }
@@ -4305,12 +3980,12 @@ var decodeError = (err) => {
4305
3980
  // src/transport/webrtc/rtc-transport-service.ts
4306
3981
  import { Duplex as Duplex2 } from "@dxos/node-std/stream";
4307
3982
  import { Stream } from "@dxos/codec-protobuf/stream";
4308
- import { invariant as invariant14 } from "@dxos/invariant";
3983
+ import { invariant as invariant12 } from "@dxos/invariant";
4309
3984
  import { PublicKey as PublicKey11 } from "@dxos/keys";
4310
- import { log as log15 } from "@dxos/log";
3985
+ import { log as log12 } from "@dxos/log";
4311
3986
  import { ConnectionState as ConnectionState4 } from "@dxos/protocols/proto/dxos/mesh/bridge";
4312
3987
  import { ComplexMap as ComplexMap8 } from "@dxos/util";
4313
- var __dxlog_file16 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-service.ts";
3988
+ var __dxlog_file13 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-service.ts";
4314
3989
  var RtcTransportService = class {
4315
3990
  _transportFactory;
4316
3991
  _openTransports = new ComplexMap8(PublicKey11.hash);
@@ -4323,9 +3998,9 @@ var RtcTransportService = class {
4323
3998
  open(request) {
4324
3999
  const existingTransport = this._openTransports.get(request.proxyId);
4325
4000
  if (existingTransport) {
4326
- log15.error("requesting a new transport bridge for an existing proxy", void 0, {
4327
- F: __dxlog_file16,
4328
- L: 54,
4001
+ log12.error("requesting a new transport bridge for an existing proxy", void 0, {
4002
+ F: __dxlog_file13,
4003
+ L: 53,
4329
4004
  S: this,
4330
4005
  C: (f, a) => f(...a)
4331
4006
  });
@@ -4389,9 +4064,9 @@ var RtcTransportService = class {
4389
4064
  close(err);
4390
4065
  });
4391
4066
  ready();
4392
- log15("stream ready", void 0, {
4393
- F: __dxlog_file16,
4394
- L: 116,
4067
+ log12("stream ready", void 0, {
4068
+ F: __dxlog_file13,
4069
+ L: 115,
4395
4070
  S: this,
4396
4071
  C: (f, a) => f(...a)
4397
4072
  });
@@ -4400,9 +4075,9 @@ var RtcTransportService = class {
4400
4075
  }
4401
4076
  async sendSignal({ proxyId, signal }) {
4402
4077
  const transport = this._openTransports.get(proxyId);
4403
- invariant14(transport, void 0, {
4404
- F: __dxlog_file16,
4405
- L: 124,
4078
+ invariant12(transport, void 0, {
4079
+ F: __dxlog_file13,
4080
+ L: 123,
4406
4081
  S: this,
4407
4082
  A: [
4408
4083
  "transport",
@@ -4413,9 +4088,9 @@ var RtcTransportService = class {
4413
4088
  }
4414
4089
  async getDetails({ proxyId }) {
4415
4090
  const transport = this._openTransports.get(proxyId);
4416
- invariant14(transport, void 0, {
4417
- F: __dxlog_file16,
4418
- L: 131,
4091
+ invariant12(transport, void 0, {
4092
+ F: __dxlog_file13,
4093
+ L: 130,
4419
4094
  S: this,
4420
4095
  A: [
4421
4096
  "transport",
@@ -4428,9 +4103,9 @@ var RtcTransportService = class {
4428
4103
  }
4429
4104
  async getStats({ proxyId }) {
4430
4105
  const transport = this._openTransports.get(proxyId);
4431
- invariant14(transport, void 0, {
4432
- F: __dxlog_file16,
4433
- L: 138,
4106
+ invariant12(transport, void 0, {
4107
+ F: __dxlog_file13,
4108
+ L: 137,
4434
4109
  S: this,
4435
4110
  A: [
4436
4111
  "transport",
@@ -4443,9 +4118,9 @@ var RtcTransportService = class {
4443
4118
  }
4444
4119
  async sendData({ proxyId, payload }) {
4445
4120
  const transport = this._openTransports.get(proxyId);
4446
- invariant14(transport, void 0, {
4447
- F: __dxlog_file16,
4448
- L: 145,
4121
+ invariant12(transport, void 0, {
4122
+ F: __dxlog_file13,
4123
+ L: 144,
4449
4124
  S: this,
4450
4125
  A: [
4451
4126
  "transport",
@@ -4475,11 +4150,11 @@ var RtcTransportService = class {
4475
4150
  try {
4476
4151
  await transport.transport.close();
4477
4152
  } catch (error) {
4478
- log15.warn("transport close error", {
4153
+ log12.warn("transport close error", {
4479
4154
  message: error?.message
4480
4155
  }, {
4481
- F: __dxlog_file16,
4482
- L: 175,
4156
+ F: __dxlog_file13,
4157
+ L: 174,
4483
4158
  S: this,
4484
4159
  C: (f, a) => f(...a)
4485
4160
  });
@@ -4487,18 +4162,18 @@ var RtcTransportService = class {
4487
4162
  try {
4488
4163
  transport.connectorStream.end();
4489
4164
  } catch (error) {
4490
- log15.warn("connectorStream close error", {
4165
+ log12.warn("connectorStream close error", {
4491
4166
  message: error?.message
4492
4167
  }, {
4493
- F: __dxlog_file16,
4494
- L: 180,
4168
+ F: __dxlog_file13,
4169
+ L: 179,
4495
4170
  S: this,
4496
4171
  C: (f, a) => f(...a)
4497
4172
  });
4498
4173
  }
4499
- log15("closed", void 0, {
4500
- F: __dxlog_file16,
4501
- L: 182,
4174
+ log12("closed", void 0, {
4175
+ F: __dxlog_file13,
4176
+ L: 181,
4502
4177
  S: this,
4503
4178
  C: (f, a) => f(...a)
4504
4179
  });
@@ -4519,10 +4194,10 @@ var createStateUpdater = (next) => {
4519
4194
 
4520
4195
  // src/wire-protocol.ts
4521
4196
  import { Teleport } from "@dxos/teleport";
4522
- var createTeleportProtocolFactory = (onConnection, defaultParams) => {
4197
+ var createTeleportProtocolFactory = (onConnection, defaultProps) => {
4523
4198
  return (params) => {
4524
4199
  const teleport = new Teleport({
4525
- ...defaultParams,
4200
+ ...defaultProps,
4526
4201
  ...params
4527
4202
  });
4528
4203
  return {
@@ -4544,7 +4219,6 @@ var createTeleportProtocolFactory = (onConnection, defaultParams) => {
4544
4219
  export {
4545
4220
  ConnectionState,
4546
4221
  Connection,
4547
- createIceProvider,
4548
4222
  SwarmMessenger,
4549
4223
  Swarm,
4550
4224
  SwarmMapper,
@@ -4554,8 +4228,6 @@ export {
4554
4228
  ConnectionLog,
4555
4229
  SwarmNetworkManager,
4556
4230
  FullyConnectedTopology,
4557
- MMSTTopology,
4558
- StarTopology,
4559
4231
  MemoryTransportFactory,
4560
4232
  MemoryTransport,
4561
4233
  TransportKind,
@@ -4565,4 +4237,4 @@ export {
4565
4237
  RtcTransportService,
4566
4238
  createTeleportProtocolFactory
4567
4239
  };
4568
- //# sourceMappingURL=chunk-E3P563GT.mjs.map
4240
+ //# sourceMappingURL=chunk-Y2FDDNGM.mjs.map