@dxos/network-manager 0.8.3 → 0.8.4-main.1068cf700f

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 (102) hide show
  1. package/dist/lib/browser/{chunk-LFKR6BAF.mjs → chunk-AQSYW43M.mjs} +731 -955
  2. package/dist/lib/browser/chunk-AQSYW43M.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 +70 -51
  7. package/dist/lib/browser/testing/index.mjs.map +3 -3
  8. package/dist/lib/browser/transport/tcp/index.mjs +2 -35
  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/{node/transport/tcp/index.cjs.map → browser/transport/tcp/tcp-transport.mjs.map} +3 -3
  14. package/dist/lib/node-esm/{chunk-QQY4BF6O.mjs → chunk-SCX3PZRE.mjs} +731 -955
  15. package/dist/lib/node-esm/chunk-SCX3PZRE.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 +70 -51
  20. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  21. package/dist/lib/node-esm/transport/tcp/index.mjs +2 -156
  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/transport/tcp/index.cjs → node-esm/transport/tcp/tcp-transport.mjs} +27 -58
  26. package/dist/lib/node-esm/transport/tcp/tcp-transport.mjs.map +7 -0
  27. package/dist/types/src/connection-log.d.ts.map +1 -1
  28. package/dist/types/src/index.d.ts +1 -1
  29. package/dist/types/src/index.d.ts.map +1 -1
  30. package/dist/types/src/network-manager.d.ts.map +1 -1
  31. package/dist/types/src/signal/index.d.ts +2 -2
  32. package/dist/types/src/signal/index.d.ts.map +1 -1
  33. package/dist/types/src/signal/swarm-messenger.d.ts +1 -1
  34. package/dist/types/src/signal/swarm-messenger.d.ts.map +1 -1
  35. package/dist/types/src/swarm/connection.d.ts.map +1 -1
  36. package/dist/types/src/swarm/peer.d.ts +2 -2
  37. package/dist/types/src/swarm/peer.d.ts.map +1 -1
  38. package/dist/types/src/swarm/swarm.d.ts +3 -3
  39. package/dist/types/src/swarm/swarm.d.ts.map +1 -1
  40. package/dist/types/src/testing/test-builder.d.ts +1 -1
  41. package/dist/types/src/testing/test-builder.d.ts.map +1 -1
  42. package/dist/types/src/testing/test-wire-protocol.d.ts +1 -1
  43. package/dist/types/src/testing/test-wire-protocol.d.ts.map +1 -1
  44. package/dist/types/src/tests/basic-test-suite.d.ts.map +1 -1
  45. package/dist/types/src/topology/index.d.ts +1 -1
  46. package/dist/types/src/topology/index.d.ts.map +1 -1
  47. package/dist/types/src/transport/tcp/index.d.ts +1 -1
  48. package/dist/types/src/transport/tcp/index.d.ts.map +1 -1
  49. package/dist/types/src/transport/webrtc/rtc-peer-connection.d.ts +2 -2
  50. package/dist/types/src/transport/webrtc/rtc-peer-connection.d.ts.map +1 -1
  51. package/dist/types/src/transport/webrtc/rtc-transport-channel.d.ts +1 -1
  52. package/dist/types/src/transport/webrtc/rtc-transport-channel.d.ts.map +1 -1
  53. package/dist/types/src/transport/webrtc/rtc-transport-factory.d.ts.map +1 -1
  54. package/dist/types/src/transport/webrtc/rtc-transport-proxy.d.ts.map +1 -1
  55. package/dist/types/src/transport/webrtc/rtc-transport-service.d.ts +1 -1
  56. package/dist/types/src/transport/webrtc/rtc-transport-service.d.ts.map +1 -1
  57. package/dist/types/src/wire-protocol.d.ts +5 -5
  58. package/dist/types/src/wire-protocol.d.ts.map +1 -1
  59. package/dist/types/tsconfig.tsbuildinfo +1 -1
  60. package/package.json +39 -35
  61. package/src/connection-log.ts +1 -1
  62. package/src/index.ts +1 -1
  63. package/src/network-manager.ts +1 -1
  64. package/src/signal/ice.test.ts +1 -1
  65. package/src/signal/index.ts +2 -2
  66. package/src/signal/integration.node.test.ts +2 -2
  67. package/src/signal/swarm-messenger.node.test.ts +1 -1
  68. package/src/signal/swarm-messenger.ts +1 -1
  69. package/src/swarm/connection.test.ts +4 -2
  70. package/src/swarm/connection.ts +11 -9
  71. package/src/swarm/peer.ts +5 -3
  72. package/src/swarm/swarm-mapper.ts +1 -1
  73. package/src/swarm/swarm.test.ts +7 -5
  74. package/src/swarm/swarm.ts +5 -4
  75. package/src/testing/test-builder.ts +12 -4
  76. package/src/testing/test-wire-protocol.ts +2 -2
  77. package/src/tests/basic-test-suite.ts +3 -2
  78. package/src/tests/memory-transport.test.ts +4 -2
  79. package/src/tests/tcp-transport.node.test.ts +4 -2
  80. package/src/tests/webrtc-transport.test.ts +6 -3
  81. package/src/topology/index.ts +1 -1
  82. package/src/transport/tcp/index.ts +1 -1
  83. package/src/transport/tcp/tcp-transport.ts +1 -1
  84. package/src/transport/webrtc/rtc-connection-factory.ts +1 -1
  85. package/src/transport/webrtc/rtc-peer-connection.ts +5 -4
  86. package/src/transport/webrtc/rtc-transport-channel.test.ts +3 -1
  87. package/src/transport/webrtc/rtc-transport-channel.ts +3 -2
  88. package/src/transport/webrtc/rtc-transport-factory.ts +3 -2
  89. package/src/transport/webrtc/rtc-transport-proxy.test.ts +7 -4
  90. package/src/transport/webrtc/rtc-transport-proxy.ts +6 -4
  91. package/src/transport/webrtc/rtc-transport-service.ts +6 -5
  92. package/src/transport/webrtc/rtc-transport.test.ts +6 -4
  93. package/src/wire-protocol.ts +6 -6
  94. package/dist/lib/browser/chunk-LFKR6BAF.mjs.map +0 -7
  95. package/dist/lib/node/chunk-2G6RZMS5.cjs +0 -4460
  96. package/dist/lib/node/chunk-2G6RZMS5.cjs.map +0 -7
  97. package/dist/lib/node/index.cjs +0 -71
  98. package/dist/lib/node/index.cjs.map +0 -7
  99. package/dist/lib/node/meta.json +0 -1
  100. package/dist/lib/node/testing/index.cjs +0 -296
  101. package/dist/lib/node/testing/index.cjs.map +0 -7
  102. package/dist/lib/node-esm/chunk-QQY4BF6O.mjs.map +0 -7
@@ -1,25 +1,25 @@
1
1
  import "@dxos/node-std/globals";
2
2
 
3
- // packages/core/mesh/network-manager/src/swarm/connection.ts
4
- import { DeferredTask, Event, sleep, scheduleTask, scheduleTaskInterval, synchronized, Trigger } from "@dxos/async";
5
- import { Context, cancelWithContext, ContextDisposedError } from "@dxos/context";
3
+ // src/swarm/connection.ts
4
+ import { DeferredTask, Event, Trigger, scheduleTask, scheduleTaskInterval, sleep, synchronized } from "@dxos/async";
5
+ import { Context, ContextDisposedError, cancelWithContext } from "@dxos/context";
6
6
  import { ErrorStream } from "@dxos/debug";
7
7
  import { invariant } from "@dxos/invariant";
8
8
  import { PublicKey } from "@dxos/keys";
9
9
  import { log, logInfo } from "@dxos/log";
10
- import { CancelledError, ProtocolError, ConnectionResetError, ConnectivityError, TimeoutError, trace } from "@dxos/protocols";
10
+ import { CancelledError, ConnectionResetError, ConnectivityError, ProtocolError, TimeoutError, trace } from "@dxos/protocols";
11
11
  function _ts_decorate(decorators, target, key, desc) {
12
12
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
13
13
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
14
14
  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;
15
15
  return c > 3 && r && Object.defineProperty(target, key, r), r;
16
16
  }
17
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts";
17
+ var __dxlog_file = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts";
18
18
  var STARTING_SIGNALLING_DELAY = 10;
19
19
  var TRANSPORT_CONNECTION_TIMEOUT = 1e4;
20
20
  var TRANSPORT_STATS_INTERVAL = 5e3;
21
21
  var MAX_SIGNALLING_DELAY = 300;
22
- var ConnectionState = /* @__PURE__ */ function(ConnectionState5) {
22
+ var ConnectionState = /* @__PURE__ */ (function(ConnectionState5) {
23
23
  ConnectionState5["CREATED"] = "CREATED";
24
24
  ConnectionState5["INITIAL"] = "INITIAL";
25
25
  ConnectionState5["CONNECTING"] = "CONNECTING";
@@ -29,8 +29,40 @@ var ConnectionState = /* @__PURE__ */ function(ConnectionState5) {
29
29
  ConnectionState5["ABORTING"] = "ABORTING";
30
30
  ConnectionState5["ABORTED"] = "ABORTED";
31
31
  return ConnectionState5;
32
- }({});
32
+ })({});
33
33
  var Connection = class {
34
+ topic;
35
+ localInfo;
36
+ remoteInfo;
37
+ sessionId;
38
+ initiator;
39
+ _signalMessaging;
40
+ _protocol;
41
+ _transportFactory;
42
+ _callbacks;
43
+ _ctx = new Context(void 0, {
44
+ F: __dxlog_file,
45
+ L: 100
46
+ });
47
+ connectedTimeoutContext = new Context(void 0, {
48
+ F: __dxlog_file,
49
+ L: 101
50
+ });
51
+ _protocolClosed = new Trigger();
52
+ _transportClosed = new Trigger();
53
+ _state = "CREATED";
54
+ _transport;
55
+ closeReason;
56
+ _incomingSignalBuffer = [];
57
+ _outgoingSignalBuffer = [];
58
+ stateChanged = new Event();
59
+ errors = new ErrorStream();
60
+ _instanceId = PublicKey.random().toHex();
61
+ transportStats = new Event();
62
+ _signalSendTask = new DeferredTask(this._ctx, async () => {
63
+ await this._flushSignalBuffer();
64
+ });
65
+ _signallingDelay = STARTING_SIGNALLING_DELAY;
34
66
  constructor(topic, localInfo, remoteInfo, sessionId, initiator, _signalMessaging, _protocol, _transportFactory, _callbacks) {
35
67
  this.topic = topic;
36
68
  this.localInfo = localInfo;
@@ -41,27 +73,6 @@ var Connection = class {
41
73
  this._protocol = _protocol;
42
74
  this._transportFactory = _transportFactory;
43
75
  this._callbacks = _callbacks;
44
- this._ctx = new Context(void 0, {
45
- F: __dxlog_file,
46
- L: 100
47
- });
48
- this.connectedTimeoutContext = new Context(void 0, {
49
- F: __dxlog_file,
50
- L: 101
51
- });
52
- this._protocolClosed = new Trigger();
53
- this._transportClosed = new Trigger();
54
- this._state = "CREATED";
55
- this._incomingSignalBuffer = [];
56
- this._outgoingSignalBuffer = [];
57
- this.stateChanged = new Event();
58
- this.errors = new ErrorStream();
59
- this._instanceId = PublicKey.random().toHex();
60
- this.transportStats = new Event();
61
- this._signalSendTask = new DeferredTask(this._ctx, async () => {
62
- await this._flushSignalBuffer();
63
- });
64
- this._signallingDelay = STARTING_SIGNALLING_DELAY;
65
76
  log.trace("dxos.mesh.connection.construct", {
66
77
  sessionId: this.sessionId,
67
78
  topic: this.topic,
@@ -133,21 +144,25 @@ var Connection = class {
133
144
  });
134
145
  this._protocolClosed.wake();
135
146
  this.close({
136
- error: new ProtocolError("protocol stream closed")
147
+ error: new ProtocolError({
148
+ message: "protocol stream closed"
149
+ })
137
150
  }).catch((err) => this.errors.raise(err));
138
151
  });
139
152
  scheduleTask(this.connectedTimeoutContext, async () => {
140
153
  log.info(`timeout waiting ${TRANSPORT_CONNECTION_TIMEOUT / 1e3}s for transport to connect, aborting`, void 0, {
141
154
  F: __dxlog_file,
142
- L: 194,
155
+ L: 196,
143
156
  S: this,
144
157
  C: (f, a) => f(...a)
145
158
  });
146
- 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));
147
162
  }, TRANSPORT_CONNECTION_TIMEOUT);
148
163
  invariant(!this._transport, void 0, {
149
164
  F: __dxlog_file,
150
- L: 202,
165
+ L: 204,
151
166
  S: this,
152
167
  A: [
153
168
  "!this._transport",
@@ -174,7 +189,7 @@ var Connection = class {
174
189
  this._transportClosed.wake();
175
190
  log("abort triggered by transport close", void 0, {
176
191
  F: __dxlog_file,
177
- L: 224,
192
+ L: 226,
178
193
  S: this,
179
194
  C: (f, a) => f(...a)
180
195
  });
@@ -185,7 +200,7 @@ var Connection = class {
185
200
  err
186
201
  }, {
187
202
  F: __dxlog_file,
188
- L: 229,
203
+ L: 231,
189
204
  S: this,
190
205
  C: (f, a) => f(...a)
191
206
  });
@@ -195,7 +210,7 @@ var Connection = class {
195
210
  if (err instanceof ConnectionResetError) {
196
211
  log.info("aborting due to transport ConnectionResetError", void 0, {
197
212
  F: __dxlog_file,
198
- L: 236,
213
+ L: 238,
199
214
  S: this,
200
215
  C: (f, a) => f(...a)
201
216
  });
@@ -203,7 +218,7 @@ var Connection = class {
203
218
  } else if (err instanceof ConnectivityError) {
204
219
  log.info("aborting due to transport ConnectivityError", void 0, {
205
220
  F: __dxlog_file,
206
- L: 239,
221
+ L: 241,
207
222
  S: this,
208
223
  C: (f, a) => f(...a)
209
224
  });
@@ -223,7 +238,7 @@ var Connection = class {
223
238
  id: this._instanceId
224
239
  }), {
225
240
  F: __dxlog_file,
226
- L: 258,
241
+ L: 260,
227
242
  S: this,
228
243
  C: (f, a) => f(...a)
229
244
  });
@@ -233,14 +248,14 @@ var Connection = class {
233
248
  err
234
249
  }, {
235
250
  F: __dxlog_file,
236
- L: 265,
251
+ L: 267,
237
252
  S: this,
238
253
  C: (f, a) => f(...a)
239
254
  });
240
255
  if (this._state === "CLOSED" || this._state === "ABORTED") {
241
256
  log(`abort ignored: already ${this._state}`, this.closeReason, {
242
257
  F: __dxlog_file,
243
- L: 267,
258
+ L: 269,
244
259
  S: this,
245
260
  C: (f, a) => f(...a)
246
261
  });
@@ -257,7 +272,7 @@ var Connection = class {
257
272
  err
258
273
  }, {
259
274
  F: __dxlog_file,
260
- L: 279,
275
+ L: 281,
261
276
  S: this,
262
277
  C: (f, a) => f(...a)
263
278
  });
@@ -268,7 +283,7 @@ var Connection = class {
268
283
  } catch (err2) {
269
284
  log.catch(err2, void 0, {
270
285
  F: __dxlog_file,
271
- L: 285,
286
+ L: 287,
272
287
  S: this,
273
288
  C: (f, a) => f(...a)
274
289
  });
@@ -278,7 +293,7 @@ var Connection = class {
278
293
  } catch (err2) {
279
294
  log.catch(err2, void 0, {
280
295
  F: __dxlog_file,
281
- L: 292,
296
+ L: 294,
282
297
  S: this,
283
298
  C: (f, a) => f(...a)
284
299
  });
@@ -288,7 +303,7 @@ var Connection = class {
288
303
  } catch (err2) {
289
304
  log.catch(err2, void 0, {
290
305
  F: __dxlog_file,
291
- L: 298,
306
+ L: 300,
292
307
  S: this,
293
308
  C: (f, a) => f(...a)
294
309
  });
@@ -300,7 +315,7 @@ var Connection = class {
300
315
  error
301
316
  }, {
302
317
  F: __dxlog_file,
303
- L: 305,
318
+ L: 307,
304
319
  S: this,
305
320
  C: (f, a) => f(...a)
306
321
  });
@@ -315,7 +330,7 @@ var Connection = class {
315
330
  error
316
331
  }, {
317
332
  F: __dxlog_file,
318
- L: 316,
333
+ L: 318,
319
334
  S: this,
320
335
  C: (f, a) => f(...a)
321
336
  });
@@ -329,7 +344,7 @@ var Connection = class {
329
344
  if (lastState !== "CONNECTED" || error != null) {
330
345
  log(`graceful close requested when we were in ${lastState} state? aborting`, void 0, {
331
346
  F: __dxlog_file,
332
- L: 327,
347
+ L: 329,
333
348
  S: this,
334
349
  C: (f, a) => f(...a)
335
350
  });
@@ -341,7 +356,7 @@ var Connection = class {
341
356
  error
342
357
  }, {
343
358
  F: __dxlog_file,
344
- L: 331,
359
+ L: 333,
345
360
  S: this,
346
361
  C: (f, a) => f(...a)
347
362
  });
@@ -352,7 +367,7 @@ var Connection = class {
352
367
  } catch (err) {
353
368
  log.catch(err, void 0, {
354
369
  F: __dxlog_file,
355
- L: 336,
370
+ L: 338,
356
371
  S: this,
357
372
  C: (f, a) => f(...a)
358
373
  });
@@ -362,7 +377,7 @@ var Connection = class {
362
377
  } catch (err) {
363
378
  log.catch(err, void 0, {
364
379
  F: __dxlog_file,
365
- L: 342,
380
+ L: 344,
366
381
  S: this,
367
382
  C: (f, a) => f(...a)
368
383
  });
@@ -371,7 +386,7 @@ var Connection = class {
371
386
  peerId: this.localInfo
372
387
  }, {
373
388
  F: __dxlog_file,
374
- L: 345,
389
+ L: 347,
375
390
  S: this,
376
391
  C: (f, a) => f(...a)
377
392
  });
@@ -381,7 +396,7 @@ var Connection = class {
381
396
  async _closeProtocol(options) {
382
397
  log("closing protocol", options, {
383
398
  F: __dxlog_file,
384
- L: 351,
399
+ L: 353,
385
400
  S: this,
386
401
  C: (f, a) => f(...a)
387
402
  });
@@ -391,7 +406,7 @@ var Connection = class {
391
406
  ]);
392
407
  log("protocol closed", options, {
393
408
  F: __dxlog_file,
394
- L: 353,
409
+ L: 355,
395
410
  S: this,
396
411
  C: (f, a) => f(...a)
397
412
  });
@@ -399,7 +414,7 @@ var Connection = class {
399
414
  async _closeTransport() {
400
415
  log("closing transport", void 0, {
401
416
  F: __dxlog_file,
402
- L: 357,
417
+ L: 359,
403
418
  S: this,
404
419
  C: (f, a) => f(...a)
405
420
  });
@@ -409,7 +424,7 @@ var Connection = class {
409
424
  ]);
410
425
  log("transport closed", void 0, {
411
426
  F: __dxlog_file,
412
- L: 359,
427
+ L: 361,
413
428
  S: this,
414
429
  C: (f, a) => f(...a)
415
430
  });
@@ -450,12 +465,15 @@ var Connection = class {
450
465
  err
451
466
  }, {
452
467
  F: __dxlog_file,
453
- L: 399,
468
+ L: 401,
454
469
  S: this,
455
470
  C: (f, a) => f(...a)
456
471
  });
457
472
  await this.close({
458
- error: new ConnectivityError("signal message failed to deliver", err)
473
+ error: new ConnectivityError({
474
+ message: "signal message failed to deliver",
475
+ cause: err
476
+ })
459
477
  });
460
478
  }
461
479
  }
@@ -465,7 +483,7 @@ var Connection = class {
465
483
  async signal(msg) {
466
484
  invariant(msg.sessionId, void 0, {
467
485
  F: __dxlog_file,
468
- L: 408,
486
+ L: 410,
469
487
  S: this,
470
488
  A: [
471
489
  "msg.sessionId",
@@ -475,7 +493,7 @@ var Connection = class {
475
493
  if (!msg.sessionId.equals(this.sessionId)) {
476
494
  log("dropping signal for incorrect session id", void 0, {
477
495
  F: __dxlog_file,
478
- L: 410,
496
+ L: 412,
479
497
  S: this,
480
498
  C: (f, a) => f(...a)
481
499
  });
@@ -483,7 +501,7 @@ var Connection = class {
483
501
  }
484
502
  invariant(msg.data.signal || msg.data.signalBatch, void 0, {
485
503
  F: __dxlog_file,
486
- L: 413,
504
+ L: 415,
487
505
  S: this,
488
506
  A: [
489
507
  "msg.data.signal || msg.data.signalBatch",
@@ -492,7 +510,7 @@ var Connection = class {
492
510
  });
493
511
  invariant(msg.author.peerKey === this.remoteInfo.peerKey, void 0, {
494
512
  F: __dxlog_file,
495
- L: 414,
513
+ L: 416,
496
514
  S: this,
497
515
  A: [
498
516
  "msg.author.peerKey === this.remoteInfo.peerKey",
@@ -501,7 +519,7 @@ var Connection = class {
501
519
  });
502
520
  invariant(msg.recipient.peerKey === this.localInfo.peerKey, void 0, {
503
521
  F: __dxlog_file,
504
- L: 415,
522
+ L: 417,
505
523
  S: this,
506
524
  A: [
507
525
  "msg.recipient.peerKey === this.localInfo.peerKey",
@@ -525,7 +543,7 @@ var Connection = class {
525
543
  msg: msg.data
526
544
  }, {
527
545
  F: __dxlog_file,
528
- L: 424,
546
+ L: 426,
529
547
  S: this,
530
548
  C: (f, a) => f(...a)
531
549
  });
@@ -533,7 +551,7 @@ var Connection = class {
533
551
  } else {
534
552
  invariant(this._transport, "Connection not ready to accept signals.", {
535
553
  F: __dxlog_file,
536
- L: 427,
554
+ L: 429,
537
555
  S: this,
538
556
  A: [
539
557
  "this._transport",
@@ -546,7 +564,7 @@ var Connection = class {
546
564
  msg: msg.data
547
565
  }, {
548
566
  F: __dxlog_file,
549
- L: 428,
567
+ L: 430,
550
568
  S: this,
551
569
  C: (f, a) => f(...a)
552
570
  });
@@ -564,13 +582,13 @@ var Connection = class {
564
582
  peerId: this.localInfo
565
583
  }, {
566
584
  F: __dxlog_file,
567
- L: 439,
585
+ L: 441,
568
586
  S: this,
569
587
  C: (f, a) => f(...a)
570
588
  });
571
589
  invariant(state !== this._state, "Already in this state.", {
572
590
  F: __dxlog_file,
573
- L: 440,
591
+ L: 442,
574
592
  S: this,
575
593
  A: [
576
594
  "state !== this._state",
@@ -597,56 +615,27 @@ _ts_decorate([
597
615
  synchronized
598
616
  ], Connection.prototype, "close", null);
599
617
 
600
- // packages/core/mesh/network-manager/src/signal/ice.ts
601
- import { asyncTimeout } from "@dxos/async";
602
- import { log as log2 } from "@dxos/log";
603
- import { isNonNullable } from "@dxos/util";
604
- var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/signal/ice.ts";
605
- var createIceProvider = (iceProviders) => {
606
- let cachedIceServers;
607
- return {
608
- getIceServers: async () => {
609
- if (cachedIceServers) {
610
- return cachedIceServers;
611
- }
612
- cachedIceServers = (await Promise.all(iceProviders.map(({ urls }) => asyncTimeout(fetch(urls, {
613
- method: "GET"
614
- }), 1e4).then((response) => response.json()).catch((err) => {
615
- const isDev = typeof window !== "undefined" && window.location.href.includes("localhost");
616
- if (!isDev) {
617
- log2.error("Failed to fetch ICE servers from provider", {
618
- urls,
619
- err
620
- }, {
621
- F: __dxlog_file2,
622
- L: 30,
623
- S: void 0,
624
- C: (f, a) => f(...a)
625
- });
626
- }
627
- })))).filter(isNonNullable).map(({ iceServers }) => iceServers).flat();
628
- return cachedIceServers;
629
- }
630
- };
631
- };
632
-
633
- // packages/core/mesh/network-manager/src/signal/swarm-messenger.ts
618
+ // src/signal/swarm-messenger.ts
634
619
  import { Context as Context2 } from "@dxos/context";
635
620
  import { invariant as invariant2 } from "@dxos/invariant";
636
621
  import { PublicKey as PublicKey2 } from "@dxos/keys";
637
- import { log as log3 } from "@dxos/log";
622
+ import { log as log2 } from "@dxos/log";
638
623
  import { TimeoutError as TimeoutError2 } from "@dxos/protocols";
639
624
  import { schema } from "@dxos/protocols/proto";
640
625
  import { ComplexMap } from "@dxos/util";
641
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
626
+ var __dxlog_file2 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
642
627
  var SwarmMessage = schema.getCodecForType("dxos.mesh.swarm.SwarmMessage");
643
628
  var SwarmMessenger = class {
629
+ _ctx = new Context2(void 0, {
630
+ F: __dxlog_file2,
631
+ L: 35
632
+ });
633
+ _sendMessage;
634
+ _onSignal;
635
+ _onOffer;
636
+ _topic;
637
+ _offerRecords = new ComplexMap((key) => key.toHex());
644
638
  constructor({ sendMessage, onSignal, onOffer, topic }) {
645
- this._ctx = new Context2(void 0, {
646
- F: __dxlog_file3,
647
- L: 35
648
- });
649
- this._offerRecords = new ComplexMap((key) => key.toHex());
650
639
  this._sendMessage = sendMessage;
651
640
  this._onSignal = onSignal;
652
641
  this._onOffer = onOffer;
@@ -660,12 +649,12 @@ var SwarmMessenger = class {
660
649
  if (!this._topic.equals(message.topic)) {
661
650
  return;
662
651
  }
663
- log3("received", {
652
+ log2("received", {
664
653
  from: author,
665
654
  to: recipient,
666
655
  msg: message
667
656
  }, {
668
- F: __dxlog_file3,
657
+ F: __dxlog_file2,
669
658
  L: 71,
670
659
  S: this,
671
660
  C: (f, a) => f(...a)
@@ -691,10 +680,10 @@ var SwarmMessenger = class {
691
680
  message
692
681
  });
693
682
  } else {
694
- log3.warn("unknown message", {
683
+ log2.warn("unknown message", {
695
684
  message
696
685
  }, {
697
- F: __dxlog_file3,
686
+ F: __dxlog_file2,
698
687
  L: 82,
699
688
  S: this,
700
689
  C: (f, a) => f(...a)
@@ -703,7 +692,7 @@ var SwarmMessenger = class {
703
692
  }
704
693
  async signal(message) {
705
694
  invariant2(message.data?.signal || message.data?.signalBatch, "Invalid message", {
706
- F: __dxlog_file3,
695
+ F: __dxlog_file2,
707
696
  L: 87,
708
697
  S: this,
709
698
  A: [
@@ -739,12 +728,12 @@ var SwarmMessenger = class {
739
728
  // Setting unique message_id if it not specified yet.
740
729
  messageId: message.messageId ?? PublicKey2.random()
741
730
  };
742
- log3("sending", {
731
+ log2("sending", {
743
732
  from: author,
744
733
  to: recipient,
745
734
  msg: networkMessage
746
735
  }, {
747
- F: __dxlog_file3,
736
+ F: __dxlog_file2,
748
737
  L: 125,
749
738
  S: this,
750
739
  C: (f, a) => f(...a)
@@ -760,7 +749,7 @@ var SwarmMessenger = class {
760
749
  }
761
750
  async _resolveAnswers(message) {
762
751
  invariant2(message.data?.answer?.offerMessageId, "No offerMessageId", {
763
- F: __dxlog_file3,
752
+ F: __dxlog_file2,
764
753
  L: 137,
765
754
  S: this,
766
755
  A: [
@@ -772,7 +761,7 @@ var SwarmMessenger = class {
772
761
  if (offerRecord) {
773
762
  this._offerRecords.delete(message.data.answer.offerMessageId);
774
763
  invariant2(message.data?.answer, "No answer", {
775
- F: __dxlog_file3,
764
+ F: __dxlog_file2,
776
765
  L: 141,
777
766
  S: this,
778
767
  A: [
@@ -780,10 +769,10 @@ var SwarmMessenger = class {
780
769
  "'No answer'"
781
770
  ]
782
771
  });
783
- log3("resolving", {
772
+ log2("resolving", {
784
773
  answer: message.data.answer
785
774
  }, {
786
- F: __dxlog_file3,
775
+ F: __dxlog_file2,
787
776
  L: 142,
788
777
  S: this,
789
778
  C: (f, a) => f(...a)
@@ -793,7 +782,7 @@ var SwarmMessenger = class {
793
782
  }
794
783
  async _handleOffer({ author, recipient, message }) {
795
784
  invariant2(message.data.offer, "No offer", {
796
- F: __dxlog_file3,
785
+ F: __dxlog_file2,
797
786
  L: 156,
798
787
  S: this,
799
788
  A: [
@@ -825,19 +814,19 @@ var SwarmMessenger = class {
825
814
  });
826
815
  } catch (err) {
827
816
  if (err instanceof TimeoutError2) {
828
- log3.info("timeout sending answer to offer", {
817
+ log2.info("timeout sending answer to offer", {
829
818
  err
830
819
  }, {
831
- F: __dxlog_file3,
820
+ F: __dxlog_file2,
832
821
  L: 177,
833
822
  S: this,
834
823
  C: (f, a) => f(...a)
835
824
  });
836
825
  } else {
837
- log3.info("error sending answer to offer", {
826
+ log2.info("error sending answer to offer", {
838
827
  err
839
828
  }, {
840
- F: __dxlog_file3,
829
+ F: __dxlog_file2,
841
830
  L: 179,
842
831
  S: this,
843
832
  C: (f, a) => f(...a)
@@ -847,7 +836,7 @@ var SwarmMessenger = class {
847
836
  }
848
837
  async _handleSignal({ author, recipient, message }) {
849
838
  invariant2(message.messageId, void 0, {
850
- F: __dxlog_file3,
839
+ F: __dxlog_file2,
851
840
  L: 193,
852
841
  S: this,
853
842
  A: [
@@ -856,7 +845,7 @@ var SwarmMessenger = class {
856
845
  ]
857
846
  });
858
847
  invariant2(message.data.signal || message.data.signalBatch, "Invalid message", {
859
- F: __dxlog_file3,
848
+ F: __dxlog_file2,
860
849
  L: 194,
861
850
  S: this,
862
851
  A: [
@@ -877,23 +866,23 @@ var SwarmMessenger = class {
877
866
  }
878
867
  };
879
868
 
880
- // packages/core/mesh/network-manager/src/swarm/swarm.ts
869
+ // src/swarm/swarm.ts
881
870
  import { Event as Event3, scheduleTask as scheduleTask3, sleep as sleep2, synchronized as synchronized3 } from "@dxos/async";
882
871
  import { Context as Context4 } from "@dxos/context";
883
872
  import { ErrorStream as ErrorStream2 } from "@dxos/debug";
884
873
  import { invariant as invariant4 } from "@dxos/invariant";
885
874
  import { PublicKey as PublicKey4 } from "@dxos/keys";
886
- import { log as log5, logInfo as logInfo2 } from "@dxos/log";
875
+ import { log as log4, logInfo as logInfo2 } from "@dxos/log";
887
876
  import { PeerInfoHash } from "@dxos/messaging";
888
877
  import { trace as trace2 } from "@dxos/protocols";
889
- import { ComplexMap as ComplexMap2, isNonNullable as isNonNullable2 } from "@dxos/util";
878
+ import { ComplexMap as ComplexMap2, isNonNullable } from "@dxos/util";
890
879
 
891
- // packages/core/mesh/network-manager/src/swarm/peer.ts
880
+ // src/swarm/peer.ts
892
881
  import { Event as Event2, scheduleTask as scheduleTask2, synchronized as synchronized2 } from "@dxos/async";
893
882
  import { Context as Context3 } from "@dxos/context";
894
883
  import { invariant as invariant3 } from "@dxos/invariant";
895
884
  import { PublicKey as PublicKey3 } from "@dxos/keys";
896
- import { log as log4 } from "@dxos/log";
885
+ import { log as log3 } from "@dxos/log";
897
886
  import { CancelledError as CancelledError2, SystemError } from "@dxos/protocols";
898
887
  function _ts_decorate2(decorators, target, key, desc) {
899
888
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -901,14 +890,42 @@ function _ts_decorate2(decorators, target, key, desc) {
901
890
  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;
902
891
  return c > 3 && r && Object.defineProperty(target, key, r), r;
903
892
  }
904
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts";
893
+ var __dxlog_file3 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts";
905
894
  var ConnectionDisplacedError = class extends SystemError {
906
895
  constructor() {
907
- super("Connection displaced by remote initiator.");
896
+ super({
897
+ message: "Connection displaced by remote initiator."
898
+ });
908
899
  }
909
900
  };
910
901
  var CONNECTION_COUNTS_STABLE_AFTER = 5e3;
911
902
  var Peer = class {
903
+ remoteInfo;
904
+ topic;
905
+ localInfo;
906
+ _signalMessaging;
907
+ _protocolProvider;
908
+ _transportFactory;
909
+ _connectionLimiter;
910
+ _callbacks;
911
+ /**
912
+ * Will be available to connect after this time.
913
+ */
914
+ _availableAfter = 0;
915
+ availableToConnect = true;
916
+ _lastConnectionTime;
917
+ _ctx = new Context3(void 0, {
918
+ F: __dxlog_file3,
919
+ L: 81
920
+ });
921
+ _connectionCtx;
922
+ connection;
923
+ /**
924
+ * Whether the peer is currently advertizing itself on the signal-network.
925
+ */
926
+ advertizing = false;
927
+ initiating = false;
928
+ connectionDisplaced = new Event2();
912
929
  constructor(remoteInfo, topic, localInfo, _signalMessaging, _protocolProvider, _transportFactory, _connectionLimiter, _callbacks) {
913
930
  this.remoteInfo = remoteInfo;
914
931
  this.topic = topic;
@@ -918,15 +935,6 @@ var Peer = class {
918
935
  this._transportFactory = _transportFactory;
919
936
  this._connectionLimiter = _connectionLimiter;
920
937
  this._callbacks = _callbacks;
921
- this._availableAfter = 0;
922
- this.availableToConnect = true;
923
- this._ctx = new Context3(void 0, {
924
- F: __dxlog_file4,
925
- L: 80
926
- });
927
- this.advertizing = false;
928
- this.initiating = false;
929
- this.connectionDisplaced = new Event2();
930
938
  }
931
939
  /**
932
940
  * Respond to remote offer.
@@ -938,9 +946,9 @@ var Peer = class {
938
946
  ConnectionState.INITIAL,
939
947
  ConnectionState.CONNECTING
940
948
  ].includes(this.connection.state)) {
941
- log4.info(`received offer when connection already in ${this.connection.state} state`, void 0, {
942
- F: __dxlog_file4,
943
- L: 115,
949
+ log3.info(`received offer when connection already in ${this.connection.state} state`, void 0, {
950
+ F: __dxlog_file3,
951
+ L: 116,
944
952
  S: this,
945
953
  C: (f, a) => f(...a)
946
954
  });
@@ -950,14 +958,14 @@ var Peer = class {
950
958
  }
951
959
  if (this.connection || this.initiating) {
952
960
  if (remote.peerKey < this.localInfo.peerKey) {
953
- log4("close local connection", {
961
+ log3("close local connection", {
954
962
  localPeer: this.localInfo,
955
963
  topic: this.topic,
956
964
  remotePeer: this.remoteInfo,
957
965
  sessionId: this.connection?.sessionId
958
966
  }, {
959
- F: __dxlog_file4,
960
- L: 124,
967
+ F: __dxlog_file3,
968
+ L: 125,
961
969
  S: this,
962
970
  C: (f, a) => f(...a)
963
971
  });
@@ -973,8 +981,8 @@ var Peer = class {
973
981
  if (await this._callbacks.onOffer(remote)) {
974
982
  if (!this.connection) {
975
983
  invariant3(message.sessionId, void 0, {
976
- F: __dxlog_file4,
977
- L: 144,
984
+ F: __dxlog_file3,
985
+ L: 145,
978
986
  S: this,
979
987
  A: [
980
988
  "message.sessionId",
@@ -988,14 +996,14 @@ var Peer = class {
988
996
  await connection.openConnection();
989
997
  } catch (err) {
990
998
  if (!(err instanceof CancelledError2)) {
991
- log4.info("connection error", {
999
+ log3.info("connection error", {
992
1000
  topic: this.topic,
993
1001
  peerId: this.localInfo,
994
1002
  remoteId: this.remoteInfo,
995
1003
  err
996
1004
  }, {
997
- F: __dxlog_file4,
998
- L: 154,
1005
+ F: __dxlog_file3,
1006
+ L: 155,
999
1007
  S: this,
1000
1008
  C: (f, a) => f(...a)
1001
1009
  });
@@ -1016,8 +1024,8 @@ var Peer = class {
1016
1024
  */
1017
1025
  async initiateConnection() {
1018
1026
  invariant3(!this.initiating, "Initiation in progress.", {
1019
- F: __dxlog_file4,
1020
- L: 171,
1027
+ F: __dxlog_file3,
1028
+ L: 173,
1021
1029
  S: this,
1022
1030
  A: [
1023
1031
  "!this.initiating",
@@ -1025,8 +1033,8 @@ var Peer = class {
1025
1033
  ]
1026
1034
  });
1027
1035
  invariant3(!this.connection, "Already connected.", {
1028
- F: __dxlog_file4,
1029
- L: 172,
1036
+ F: __dxlog_file3,
1037
+ L: 174,
1030
1038
  S: this,
1031
1039
  A: [
1032
1040
  "!this.connection",
@@ -1034,14 +1042,14 @@ var Peer = class {
1034
1042
  ]
1035
1043
  });
1036
1044
  const sessionId = PublicKey3.random();
1037
- log4("initiating...", {
1045
+ log3("initiating...", {
1038
1046
  local: this.localInfo,
1039
1047
  topic: this.topic,
1040
1048
  remote: this.remoteInfo,
1041
1049
  sessionId
1042
1050
  }, {
1043
- F: __dxlog_file4,
1044
- L: 174,
1051
+ F: __dxlog_file3,
1052
+ L: 176,
1045
1053
  S: this,
1046
1054
  C: (f, a) => f(...a)
1047
1055
  });
@@ -1060,35 +1068,35 @@ var Peer = class {
1060
1068
  offer: {}
1061
1069
  }
1062
1070
  });
1063
- log4("received", {
1071
+ log3("received", {
1064
1072
  answer,
1065
1073
  topic: this.topic,
1066
1074
  local: this.localInfo,
1067
1075
  remote: this.remoteInfo
1068
1076
  }, {
1069
- F: __dxlog_file4,
1070
- L: 191,
1077
+ F: __dxlog_file3,
1078
+ L: 193,
1071
1079
  S: this,
1072
1080
  C: (f, a) => f(...a)
1073
1081
  });
1074
1082
  if (connection.state !== ConnectionState.INITIAL) {
1075
- log4("ignoring response", void 0, {
1076
- F: __dxlog_file4,
1077
- L: 193,
1083
+ log3("ignoring response", void 0, {
1084
+ F: __dxlog_file3,
1085
+ L: 195,
1078
1086
  S: this,
1079
1087
  C: (f, a) => f(...a)
1080
1088
  });
1081
1089
  return;
1082
1090
  }
1083
1091
  } catch (err) {
1084
- log4("initiation error: send offer", {
1092
+ log3("initiation error: send offer", {
1085
1093
  err,
1086
1094
  topic: this.topic,
1087
1095
  local: this.localInfo,
1088
1096
  remote: this.remoteInfo
1089
1097
  }, {
1090
- F: __dxlog_file4,
1091
- L: 197,
1098
+ F: __dxlog_file3,
1099
+ L: 199,
1092
1100
  S: this,
1093
1101
  C: (f, a) => f(...a)
1094
1102
  });
@@ -1103,14 +1111,14 @@ var Peer = class {
1103
1111
  return;
1104
1112
  }
1105
1113
  } catch (err) {
1106
- log4("initiation error: accept answer", {
1114
+ log3("initiation error: accept answer", {
1107
1115
  err,
1108
1116
  topic: this.topic,
1109
1117
  local: this.localInfo,
1110
1118
  remote: this.remoteInfo
1111
1119
  }, {
1112
- F: __dxlog_file4,
1113
- L: 210,
1120
+ F: __dxlog_file3,
1121
+ L: 212,
1114
1122
  S: this,
1115
1123
  C: (f, a) => f(...a)
1116
1124
  });
@@ -1120,31 +1128,31 @@ var Peer = class {
1120
1128
  this.initiating = false;
1121
1129
  }
1122
1130
  try {
1123
- log4("opening connection as initiator", void 0, {
1124
- F: __dxlog_file4,
1125
- L: 223,
1131
+ log3("opening connection as initiator", void 0, {
1132
+ F: __dxlog_file3,
1133
+ L: 225,
1126
1134
  S: this,
1127
1135
  C: (f, a) => f(...a)
1128
1136
  });
1129
1137
  await connection.openConnection();
1130
1138
  this._callbacks.onAccepted();
1131
1139
  } catch (err) {
1132
- log4("initiation error: open connection", {
1140
+ log3("initiation error: open connection", {
1133
1141
  err,
1134
1142
  topic: this.topic,
1135
1143
  local: this.localInfo,
1136
1144
  remote: this.remoteInfo
1137
1145
  }, {
1138
- F: __dxlog_file4,
1139
- L: 227,
1146
+ F: __dxlog_file3,
1147
+ L: 229,
1140
1148
  S: this,
1141
1149
  C: (f, a) => f(...a)
1142
1150
  });
1143
- log4.warn("closing connection due to unhandled error on openConnection", {
1151
+ log3.warn("closing connection due to unhandled error on openConnection", {
1144
1152
  err
1145
1153
  }, {
1146
- F: __dxlog_file4,
1147
- L: 234,
1154
+ F: __dxlog_file3,
1155
+ L: 236,
1148
1156
  S: this,
1149
1157
  C: (f, a) => f(...a)
1150
1158
  });
@@ -1159,21 +1167,21 @@ var Peer = class {
1159
1167
  * Either we're initiating a connection or creating one in response to an offer from the other peer.
1160
1168
  */
1161
1169
  _createConnection(initiator, sessionId) {
1162
- log4("creating connection", {
1170
+ log3("creating connection", {
1163
1171
  topic: this.topic,
1164
1172
  peerId: this.localInfo,
1165
1173
  remoteId: this.remoteInfo,
1166
1174
  initiator,
1167
1175
  sessionId
1168
1176
  }, {
1169
- F: __dxlog_file4,
1170
- L: 248,
1177
+ F: __dxlog_file3,
1178
+ L: 250,
1171
1179
  S: this,
1172
1180
  C: (f, a) => f(...a)
1173
1181
  });
1174
1182
  invariant3(!this.connection, "Already connected.", {
1175
- F: __dxlog_file4,
1176
- L: 255,
1183
+ F: __dxlog_file3,
1184
+ L: 257,
1177
1185
  S: this,
1178
1186
  A: [
1179
1187
  "!this.connection",
@@ -1201,15 +1209,15 @@ var Peer = class {
1201
1209
  this._lastConnectionTime = Date.now();
1202
1210
  this._callbacks.onConnected();
1203
1211
  this._connectionLimiter.doneConnecting(sessionId);
1204
- log4.trace("dxos.mesh.connection.connected", {
1212
+ log3.trace("dxos.mesh.connection.connected", {
1205
1213
  topic: this.topic,
1206
1214
  localPeerId: this.localInfo,
1207
1215
  remotePeerId: this.remoteInfo,
1208
1216
  sessionId,
1209
1217
  initiator
1210
1218
  }, {
1211
- F: __dxlog_file4,
1212
- L: 279,
1219
+ F: __dxlog_file3,
1220
+ L: 281,
1213
1221
  S: this,
1214
1222
  C: (f, a) => f(...a)
1215
1223
  });
@@ -1221,31 +1229,31 @@ var Peer = class {
1221
1229
  remoteId: this.remoteInfo,
1222
1230
  initiator
1223
1231
  };
1224
- log4("connection closed", logMeta, {
1225
- F: __dxlog_file4,
1226
- L: 289,
1232
+ log3("connection closed", logMeta, {
1233
+ F: __dxlog_file3,
1234
+ L: 291,
1227
1235
  S: this,
1228
1236
  C: (f, a) => f(...a)
1229
1237
  });
1230
1238
  this._connectionLimiter.doneConnecting(sessionId);
1231
1239
  invariant3(this.connection === connection, "Connection mismatch (race condition).", {
1232
- F: __dxlog_file4,
1233
- L: 294,
1240
+ F: __dxlog_file3,
1241
+ L: 296,
1234
1242
  S: this,
1235
1243
  A: [
1236
1244
  "this.connection === connection",
1237
1245
  "'Connection mismatch (race condition).'"
1238
1246
  ]
1239
1247
  });
1240
- log4.trace("dxos.mesh.connection.closed", {
1248
+ log3.trace("dxos.mesh.connection.closed", {
1241
1249
  topic: this.topic,
1242
1250
  localPeerId: this.localInfo,
1243
1251
  remotePeerId: this.remoteInfo,
1244
1252
  sessionId,
1245
1253
  initiator
1246
1254
  }, {
1247
- F: __dxlog_file4,
1248
- L: 296,
1255
+ F: __dxlog_file3,
1256
+ L: 298,
1249
1257
  S: this,
1250
1258
  C: (f, a) => f(...a)
1251
1259
  });
@@ -1260,9 +1268,9 @@ var Peer = class {
1260
1268
  }
1261
1269
  this._callbacks.onDisconnected();
1262
1270
  scheduleTask2(this._connectionCtx, () => {
1263
- log4("peer became available", logMeta, {
1264
- F: __dxlog_file4,
1265
- L: 320,
1271
+ log3("peer became available", logMeta, {
1272
+ F: __dxlog_file3,
1273
+ L: 322,
1266
1274
  S: this,
1267
1275
  C: (f, a) => f(...a)
1268
1276
  });
@@ -1278,19 +1286,19 @@ var Peer = class {
1278
1286
  void this._connectionCtx?.dispose();
1279
1287
  this._connectionCtx = this._ctx.derive();
1280
1288
  connection.errors.handle((err) => {
1281
- log4.info("connection error, closing", {
1289
+ log3.info("connection error, closing", {
1282
1290
  topic: this.topic,
1283
1291
  peerId: this.localInfo,
1284
1292
  remoteId: this.remoteInfo,
1285
1293
  initiator,
1286
1294
  err
1287
1295
  }, {
1288
- F: __dxlog_file4,
1289
- L: 338,
1296
+ F: __dxlog_file3,
1297
+ L: 340,
1290
1298
  S: this,
1291
1299
  C: (f, a) => f(...a)
1292
1300
  });
1293
- log4.trace("dxos.mesh.connection.error", {
1301
+ log3.trace("dxos.mesh.connection.error", {
1294
1302
  topic: this.topic,
1295
1303
  localPeerId: this.localInfo,
1296
1304
  remotePeerId: this.remoteInfo,
@@ -1298,8 +1306,8 @@ var Peer = class {
1298
1306
  initiator,
1299
1307
  err
1300
1308
  }, {
1301
- F: __dxlog_file4,
1302
- L: 345,
1309
+ F: __dxlog_file3,
1310
+ L: 347,
1303
1311
  S: this,
1304
1312
  C: (f, a) => f(...a)
1305
1313
  });
@@ -1313,35 +1321,35 @@ var Peer = class {
1313
1321
  return;
1314
1322
  }
1315
1323
  const connection = this.connection;
1316
- log4("closing...", {
1324
+ log3("closing...", {
1317
1325
  peerId: this.remoteInfo,
1318
1326
  sessionId: connection.sessionId
1319
1327
  }, {
1320
- F: __dxlog_file4,
1321
- L: 370,
1328
+ F: __dxlog_file3,
1329
+ L: 372,
1322
1330
  S: this,
1323
1331
  C: (f, a) => f(...a)
1324
1332
  });
1325
1333
  await connection.close({
1326
1334
  error: err
1327
1335
  });
1328
- log4("closed", {
1336
+ log3("closed", {
1329
1337
  peerId: this.remoteInfo,
1330
1338
  sessionId: connection.sessionId
1331
1339
  }, {
1332
- F: __dxlog_file4,
1333
- L: 376,
1340
+ F: __dxlog_file3,
1341
+ L: 378,
1334
1342
  S: this,
1335
1343
  C: (f, a) => f(...a)
1336
1344
  });
1337
1345
  }
1338
1346
  async onSignal(message) {
1339
1347
  if (!this.connection) {
1340
- log4("dropping signal message for non-existent connection", {
1348
+ log3("dropping signal message for non-existent connection", {
1341
1349
  message
1342
1350
  }, {
1343
- F: __dxlog_file4,
1344
- L: 381,
1351
+ F: __dxlog_file3,
1352
+ L: 383,
1345
1353
  S: this,
1346
1354
  C: (f, a) => f(...a)
1347
1355
  });
@@ -1351,12 +1359,12 @@ var Peer = class {
1351
1359
  }
1352
1360
  async safeDestroy(reason) {
1353
1361
  await this._ctx.dispose();
1354
- log4("Destroying peer", {
1362
+ log3("Destroying peer", {
1355
1363
  peerId: this.remoteInfo,
1356
1364
  topic: this.topic
1357
1365
  }, {
1358
- F: __dxlog_file4,
1359
- L: 391,
1366
+ F: __dxlog_file3,
1367
+ L: 393,
1360
1368
  S: this,
1361
1369
  C: (f, a) => f(...a)
1362
1370
  });
@@ -1381,17 +1389,57 @@ var increaseInterval = (interval) => {
1381
1389
  return 1e4;
1382
1390
  };
1383
1391
 
1384
- // packages/core/mesh/network-manager/src/swarm/swarm.ts
1392
+ // src/swarm/swarm.ts
1385
1393
  function _ts_decorate3(decorators, target, key, desc) {
1386
1394
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1387
1395
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1388
1396
  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;
1389
1397
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1390
1398
  }
1391
- var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts";
1399
+ var __dxlog_file4 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts";
1392
1400
  var INITIATION_DELAY = 100;
1393
1401
  var getClassName = (obj) => Object.getPrototypeOf(obj).constructor.name;
1394
1402
  var Swarm = class {
1403
+ _topic;
1404
+ _ownPeer;
1405
+ _topology;
1406
+ _protocolProvider;
1407
+ _messenger;
1408
+ _transportFactory;
1409
+ _label;
1410
+ _connectionLimiter;
1411
+ _initiationDelay;
1412
+ _swarmMessenger;
1413
+ _ctx = new Context4(void 0, {
1414
+ F: __dxlog_file4,
1415
+ L: 39
1416
+ });
1417
+ _listeningHandle = void 0;
1418
+ /**
1419
+ * PeerInfo -> Peer.
1420
+ * @internal
1421
+ */
1422
+ _peers = new ComplexMap2(PeerInfoHash);
1423
+ /**
1424
+ * Unique id of the swarm, local to the current peer, generated when swarm is joined.
1425
+ */
1426
+ _instanceId = PublicKey4.random().toHex();
1427
+ /**
1428
+ * New connection to a peer is started.
1429
+ * @internal
1430
+ */
1431
+ connectionAdded = new Event3();
1432
+ /**
1433
+ * Connection to a peer is dropped.
1434
+ * @internal
1435
+ */
1436
+ disconnected = new Event3();
1437
+ /**
1438
+ * Connection is established to a new peer.
1439
+ * @internal
1440
+ */
1441
+ connected = new Event3();
1442
+ errors = new ErrorStream2();
1395
1443
  // TODO(burdon): Swarm => Peer.create/destroy =< Connection.open/close
1396
1444
  // TODO(burdon): Pass in object.
1397
1445
  constructor(_topic, _ownPeer, _topology, _protocolProvider, _messenger, _transportFactory, _label, _connectionLimiter, _initiationDelay = INITIATION_DELAY) {
@@ -1404,34 +1452,23 @@ var Swarm = class {
1404
1452
  this._label = _label;
1405
1453
  this._connectionLimiter = _connectionLimiter;
1406
1454
  this._initiationDelay = _initiationDelay;
1407
- this._ctx = new Context4(void 0, {
1408
- F: __dxlog_file5,
1409
- L: 38
1410
- });
1411
- this._listeningHandle = void 0;
1412
- this._peers = new ComplexMap2(PeerInfoHash);
1413
- this._instanceId = PublicKey4.random().toHex();
1414
- this.connectionAdded = new Event3();
1415
- this.disconnected = new Event3();
1416
- this.connected = new Event3();
1417
- this.errors = new ErrorStream2();
1418
- log5.trace("dxos.mesh.swarm.constructor", trace2.begin({
1455
+ log4.trace("dxos.mesh.swarm.constructor", trace2.begin({
1419
1456
  id: this._instanceId,
1420
1457
  data: {
1421
1458
  topic: this._topic.toHex(),
1422
1459
  peer: this._ownPeer
1423
1460
  }
1424
1461
  }), {
1425
- F: __dxlog_file5,
1426
- L: 88,
1462
+ F: __dxlog_file4,
1463
+ L: 89,
1427
1464
  S: this,
1428
1465
  C: (f, a) => f(...a)
1429
1466
  });
1430
- log5("creating swarm", {
1467
+ log4("creating swarm", {
1431
1468
  peerId: _ownPeer
1432
1469
  }, {
1433
- F: __dxlog_file5,
1434
- L: 92,
1470
+ F: __dxlog_file4,
1471
+ L: 93,
1435
1472
  S: this,
1436
1473
  C: (f, a) => f(...a)
1437
1474
  });
@@ -1442,17 +1479,17 @@ var Swarm = class {
1442
1479
  onOffer: async (msg) => await this.onOffer(msg),
1443
1480
  topic: this._topic
1444
1481
  });
1445
- log5.trace("dxos.mesh.swarm.constructor", trace2.end({
1482
+ log4.trace("dxos.mesh.swarm.constructor", trace2.end({
1446
1483
  id: this._instanceId
1447
1484
  }), {
1448
- F: __dxlog_file5,
1449
- L: 101,
1485
+ F: __dxlog_file4,
1486
+ L: 102,
1450
1487
  S: this,
1451
1488
  C: (f, a) => f(...a)
1452
1489
  });
1453
1490
  }
1454
1491
  get connections() {
1455
- return Array.from(this._peers.values()).map((peer) => peer.connection).filter(isNonNullable2);
1492
+ return Array.from(this._peers.values()).map((peer) => peer.connection).filter(isNonNullable);
1456
1493
  }
1457
1494
  get ownPeerId() {
1458
1495
  return PublicKey4.from(this._ownPeer.peerKey);
@@ -1471,8 +1508,8 @@ var Swarm = class {
1471
1508
  }
1472
1509
  async open() {
1473
1510
  invariant4(!this._listeningHandle, void 0, {
1474
- F: __dxlog_file5,
1475
- L: 132,
1511
+ F: __dxlog_file4,
1512
+ L: 133,
1476
1513
  S: this,
1477
1514
  A: [
1478
1515
  "!this._listeningHandle",
@@ -1483,11 +1520,11 @@ var Swarm = class {
1483
1520
  peer: this._ownPeer,
1484
1521
  payloadType: "dxos.mesh.swarm.SwarmMessage",
1485
1522
  onMessage: async (message) => {
1486
- await this._swarmMessenger.receiveMessage(message).catch((err) => log5.info("Error while receiving message", {
1523
+ await this._swarmMessenger.receiveMessage(message).catch((err) => log4.info("Error while receiving message", {
1487
1524
  err
1488
1525
  }, {
1489
- F: __dxlog_file5,
1490
- L: 140,
1526
+ F: __dxlog_file4,
1527
+ L: 141,
1491
1528
  S: this,
1492
1529
  C: (f, a) => f(...a)
1493
1530
  }));
@@ -1495,9 +1532,9 @@ var Swarm = class {
1495
1532
  });
1496
1533
  }
1497
1534
  async destroy() {
1498
- log5("destroying...", void 0, {
1499
- F: __dxlog_file5,
1500
- L: 146,
1535
+ log4("destroying...", void 0, {
1536
+ F: __dxlog_file4,
1537
+ L: 147,
1501
1538
  S: this,
1502
1539
  C: (f, a) => f(...a)
1503
1540
  });
@@ -1506,17 +1543,17 @@ var Swarm = class {
1506
1543
  await this._ctx.dispose();
1507
1544
  await this._topology.destroy();
1508
1545
  await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key, "swarm destroyed")));
1509
- log5("destroyed", void 0, {
1510
- F: __dxlog_file5,
1511
- L: 153,
1546
+ log4("destroyed", void 0, {
1547
+ F: __dxlog_file4,
1548
+ L: 154,
1512
1549
  S: this,
1513
1550
  C: (f, a) => f(...a)
1514
1551
  });
1515
1552
  }
1516
1553
  async setTopology(topology) {
1517
1554
  invariant4(!this._ctx.disposed, "Swarm is offline", {
1518
- F: __dxlog_file5,
1519
- L: 157,
1555
+ F: __dxlog_file4,
1556
+ L: 158,
1520
1557
  S: this,
1521
1558
  A: [
1522
1559
  "!this._ctx.disposed",
@@ -1526,12 +1563,12 @@ var Swarm = class {
1526
1563
  if (topology === this._topology) {
1527
1564
  return;
1528
1565
  }
1529
- log5("setting topology", {
1566
+ log4("setting topology", {
1530
1567
  previous: getClassName(this._topology),
1531
1568
  topology: getClassName(topology)
1532
1569
  }, {
1533
- F: __dxlog_file5,
1534
- L: 161,
1570
+ F: __dxlog_file4,
1571
+ L: 162,
1535
1572
  S: this,
1536
1573
  C: (f, a) => f(...a)
1537
1574
  });
@@ -1541,18 +1578,18 @@ var Swarm = class {
1541
1578
  this._topology.update();
1542
1579
  }
1543
1580
  async onSwarmEvent(swarmEvent) {
1544
- log5("swarm event", {
1581
+ log4("swarm event", {
1545
1582
  swarmEvent
1546
1583
  }, {
1547
- F: __dxlog_file5,
1548
- L: 174,
1584
+ F: __dxlog_file4,
1585
+ L: 175,
1549
1586
  S: this,
1550
1587
  C: (f, a) => f(...a)
1551
1588
  });
1552
1589
  if (this._ctx.disposed) {
1553
- log5("swarm event ignored for disposed swarm", void 0, {
1554
- F: __dxlog_file5,
1555
- L: 177,
1590
+ log4("swarm event ignored for disposed swarm", void 0, {
1591
+ F: __dxlog_file4,
1592
+ L: 178,
1556
1593
  S: this,
1557
1594
  C: (f, a) => f(...a)
1558
1595
  });
@@ -1561,11 +1598,11 @@ var Swarm = class {
1561
1598
  if (swarmEvent.peerAvailable) {
1562
1599
  const peerId = swarmEvent.peerAvailable.peer.peerKey;
1563
1600
  if (peerId !== this._ownPeer.peerKey) {
1564
- log5("new peer", {
1601
+ log4("new peer", {
1565
1602
  peerId
1566
1603
  }, {
1567
- F: __dxlog_file5,
1568
- L: 184,
1604
+ F: __dxlog_file4,
1605
+ L: 185,
1569
1606
  S: this,
1570
1607
  C: (f, a) => f(...a)
1571
1608
  });
@@ -1577,25 +1614,25 @@ var Swarm = class {
1577
1614
  if (peer) {
1578
1615
  peer.advertizing = false;
1579
1616
  if (this._isConnectionEstablishmentInProgress(peer)) {
1580
- log5(`destroying peer, state: ${peer.connection?.state}`, void 0, {
1581
- F: __dxlog_file5,
1582
- L: 195,
1617
+ log4(`destroying peer, state: ${peer.connection?.state}`, void 0, {
1618
+ F: __dxlog_file4,
1619
+ L: 196,
1583
1620
  S: this,
1584
1621
  C: (f, a) => f(...a)
1585
1622
  });
1586
- void this._destroyPeer(swarmEvent.peerLeft.peer, "peer left").catch((err) => log5.catch(err, void 0, {
1587
- F: __dxlog_file5,
1588
- L: 196,
1623
+ void this._destroyPeer(swarmEvent.peerLeft.peer, "peer left").catch((err) => log4.catch(err, void 0, {
1624
+ F: __dxlog_file4,
1625
+ L: 197,
1589
1626
  S: this,
1590
1627
  C: (f, a) => f(...a)
1591
1628
  }));
1592
1629
  }
1593
1630
  } else {
1594
- log5("received peerLeft but no peer found", {
1631
+ log4("received peerLeft but no peer found", {
1595
1632
  peer: swarmEvent.peerLeft.peer.peerKey
1596
1633
  }, {
1597
- F: __dxlog_file5,
1598
- L: 199,
1634
+ F: __dxlog_file4,
1635
+ L: 200,
1599
1636
  S: this,
1600
1637
  C: (f, a) => f(...a)
1601
1638
  });
@@ -1604,18 +1641,18 @@ var Swarm = class {
1604
1641
  this._topology.update();
1605
1642
  }
1606
1643
  async onOffer(message) {
1607
- log5("offer", {
1644
+ log4("offer", {
1608
1645
  message
1609
1646
  }, {
1610
- F: __dxlog_file5,
1611
- L: 208,
1647
+ F: __dxlog_file4,
1648
+ L: 209,
1612
1649
  S: this,
1613
1650
  C: (f, a) => f(...a)
1614
1651
  });
1615
1652
  if (this._ctx.disposed) {
1616
- log5("ignored for disposed swarm", void 0, {
1617
- F: __dxlog_file5,
1618
- L: 210,
1653
+ log4("ignored for disposed swarm", void 0, {
1654
+ F: __dxlog_file4,
1655
+ L: 211,
1619
1656
  S: this,
1620
1657
  C: (f, a) => f(...a)
1621
1658
  });
@@ -1624,8 +1661,8 @@ var Swarm = class {
1624
1661
  };
1625
1662
  }
1626
1663
  invariant4(message.author, void 0, {
1627
- F: __dxlog_file5,
1628
- L: 215,
1664
+ F: __dxlog_file4,
1665
+ L: 216,
1629
1666
  S: this,
1630
1667
  A: [
1631
1668
  "message.author",
@@ -1633,11 +1670,11 @@ var Swarm = class {
1633
1670
  ]
1634
1671
  });
1635
1672
  if (message.recipient.peerKey !== this._ownPeer.peerKey) {
1636
- log5("rejecting offer with incorrect peerId", {
1673
+ log4("rejecting offer with incorrect peerId", {
1637
1674
  message
1638
1675
  }, {
1639
- F: __dxlog_file5,
1640
- L: 217,
1676
+ F: __dxlog_file4,
1677
+ L: 218,
1641
1678
  S: this,
1642
1679
  C: (f, a) => f(...a)
1643
1680
  });
@@ -1646,11 +1683,11 @@ var Swarm = class {
1646
1683
  };
1647
1684
  }
1648
1685
  if (!message.topic?.equals(this._topic)) {
1649
- log5("rejecting offer with incorrect topic", {
1686
+ log4("rejecting offer with incorrect topic", {
1650
1687
  message
1651
1688
  }, {
1652
- F: __dxlog_file5,
1653
- L: 221,
1689
+ F: __dxlog_file4,
1690
+ L: 222,
1654
1691
  S: this,
1655
1692
  C: (f, a) => f(...a)
1656
1693
  });
@@ -1674,26 +1711,26 @@ var Swarm = class {
1674
1711
  return peer;
1675
1712
  }
1676
1713
  async onSignal(message) {
1677
- log5("signal", {
1714
+ log4("signal", {
1678
1715
  message
1679
1716
  }, {
1680
- F: __dxlog_file5,
1681
- L: 246,
1717
+ F: __dxlog_file4,
1718
+ L: 247,
1682
1719
  S: this,
1683
1720
  C: (f, a) => f(...a)
1684
1721
  });
1685
1722
  if (this._ctx.disposed) {
1686
- log5.info("ignored for offline swarm", void 0, {
1687
- F: __dxlog_file5,
1688
- L: 248,
1723
+ log4.info("ignored for offline swarm", void 0, {
1724
+ F: __dxlog_file4,
1725
+ L: 249,
1689
1726
  S: this,
1690
1727
  C: (f, a) => f(...a)
1691
1728
  });
1692
1729
  return;
1693
1730
  }
1694
1731
  invariant4(message.recipient.peerKey === this._ownPeer.peerKey, `Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`, {
1695
- F: __dxlog_file5,
1696
- L: 251,
1732
+ F: __dxlog_file4,
1733
+ L: 252,
1697
1734
  S: this,
1698
1735
  A: [
1699
1736
  "message.recipient.peerKey === this._ownPeer.peerKey",
@@ -1701,8 +1738,8 @@ var Swarm = class {
1701
1738
  ]
1702
1739
  });
1703
1740
  invariant4(message.topic?.equals(this._topic), void 0, {
1704
- F: __dxlog_file5,
1705
- L: 255,
1741
+ F: __dxlog_file4,
1742
+ L: 256,
1706
1743
  S: this,
1707
1744
  A: [
1708
1745
  "message.topic?.equals(this._topic)",
@@ -1710,8 +1747,8 @@ var Swarm = class {
1710
1747
  ]
1711
1748
  });
1712
1749
  invariant4(message.author, void 0, {
1713
- F: __dxlog_file5,
1714
- L: 256,
1750
+ F: __dxlog_file4,
1751
+ L: 257,
1715
1752
  S: this,
1716
1753
  A: [
1717
1754
  "message.author",
@@ -1731,14 +1768,14 @@ var Swarm = class {
1731
1768
  // For debug purposes
1732
1769
  async goOnline() {
1733
1770
  this._ctx = new Context4(void 0, {
1734
- F: __dxlog_file5,
1735
- L: 272
1771
+ F: __dxlog_file4,
1772
+ L: 273
1736
1773
  });
1737
1774
  }
1738
1775
  _getOrCreatePeer(peerInfo) {
1739
1776
  invariant4(peerInfo.peerKey, "PeerInfo.peerKey is required", {
1740
- F: __dxlog_file5,
1741
- L: 276,
1777
+ F: __dxlog_file4,
1778
+ L: 277,
1742
1779
  S: this,
1743
1780
  A: [
1744
1781
  "peerInfo.peerKey",
@@ -1756,9 +1793,9 @@ var Swarm = class {
1756
1793
  },
1757
1794
  onDisconnected: async () => {
1758
1795
  if (this._isUnregistered(peer)) {
1759
- log5.verbose("ignored onDisconnected for unregistered peer", void 0, {
1760
- F: __dxlog_file5,
1761
- L: 296,
1796
+ log4.verbose("ignored onDisconnected for unregistered peer", void 0, {
1797
+ F: __dxlog_file4,
1798
+ L: 297,
1762
1799
  S: this,
1763
1800
  C: (f, a) => f(...a)
1764
1801
  });
@@ -1772,11 +1809,11 @@ var Swarm = class {
1772
1809
  },
1773
1810
  onRejected: () => {
1774
1811
  if (!this._isUnregistered(peer)) {
1775
- log5("peer rejected connection", {
1812
+ log4("peer rejected connection", {
1776
1813
  peerInfo
1777
1814
  }, {
1778
- F: __dxlog_file5,
1779
- L: 310,
1815
+ F: __dxlog_file4,
1816
+ L: 311,
1780
1817
  S: this,
1781
1818
  C: (f, a) => f(...a)
1782
1819
  });
@@ -1798,19 +1835,19 @@ var Swarm = class {
1798
1835
  return peer;
1799
1836
  }
1800
1837
  async _destroyPeer(peerInfo, reason) {
1801
- log5("destroy peer", {
1838
+ log4("destroy peer", {
1802
1839
  peerKey: peerInfo.peerKey,
1803
1840
  reason
1804
1841
  }, {
1805
- F: __dxlog_file5,
1806
- L: 332,
1842
+ F: __dxlog_file4,
1843
+ L: 333,
1807
1844
  S: this,
1808
1845
  C: (f, a) => f(...a)
1809
1846
  });
1810
1847
  const peer = this._peers.get(peerInfo);
1811
1848
  invariant4(peer, void 0, {
1812
- F: __dxlog_file5,
1813
- L: 334,
1849
+ F: __dxlog_file4,
1850
+ L: 335,
1814
1851
  S: this,
1815
1852
  A: [
1816
1853
  "peer",
@@ -1838,9 +1875,9 @@ var Swarm = class {
1838
1875
  peerKey: peer.toHex()
1839
1876
  });
1840
1877
  } catch (err) {
1841
- log5("initiation error", err, {
1842
- F: __dxlog_file5,
1843
- L: 361,
1878
+ log4("initiation error", err, {
1879
+ F: __dxlog_file4,
1880
+ L: 362,
1844
1881
  S: this,
1845
1882
  C: (f, a) => f(...a)
1846
1883
  });
@@ -1867,11 +1904,11 @@ var Swarm = class {
1867
1904
  const ctx = this._ctx;
1868
1905
  const peer = this._getOrCreatePeer(remotePeer);
1869
1906
  if (remotePeer.peerKey < this._ownPeer.peerKey) {
1870
- log5("initiation delay", {
1907
+ log4("initiation delay", {
1871
1908
  remotePeer
1872
1909
  }, {
1873
- F: __dxlog_file5,
1874
- L: 389,
1910
+ F: __dxlog_file4,
1911
+ L: 390,
1875
1912
  S: this,
1876
1913
  C: (f, a) => f(...a)
1877
1914
  });
@@ -1886,21 +1923,21 @@ var Swarm = class {
1886
1923
  if (peer.connection) {
1887
1924
  return;
1888
1925
  }
1889
- log5("initiating connection...", {
1926
+ log4("initiating connection...", {
1890
1927
  remotePeer
1891
1928
  }, {
1892
- F: __dxlog_file5,
1893
- L: 405,
1929
+ F: __dxlog_file4,
1930
+ L: 406,
1894
1931
  S: this,
1895
1932
  C: (f, a) => f(...a)
1896
1933
  });
1897
1934
  await peer.initiateConnection();
1898
1935
  this._topology.update();
1899
- log5("initiated", {
1936
+ log4("initiated", {
1900
1937
  remotePeer
1901
1938
  }, {
1902
- F: __dxlog_file5,
1903
- L: 408,
1939
+ F: __dxlog_file4,
1940
+ L: 409,
1904
1941
  S: this,
1905
1942
  C: (f, a) => f(...a)
1906
1943
  });
@@ -1948,23 +1985,24 @@ _ts_decorate3([
1948
1985
  synchronized3
1949
1986
  ], Swarm.prototype, "goOnline", null);
1950
1987
 
1951
- // packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts
1988
+ // src/swarm/swarm-mapper.ts
1952
1989
  import { Event as Event4, SubscriptionList } from "@dxos/async";
1953
1990
  import { PublicKey as PublicKey5 } from "@dxos/keys";
1954
- import { log as log6 } from "@dxos/log";
1991
+ import { log as log5 } from "@dxos/log";
1955
1992
  import { PeerInfoHash as PeerInfoHash2 } from "@dxos/messaging";
1956
1993
  import { ComplexMap as ComplexMap3 } from "@dxos/util";
1957
- var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
1994
+ var __dxlog_file5 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
1958
1995
  var SwarmMapper = class {
1996
+ _swarm;
1997
+ _subscriptions = new SubscriptionList();
1998
+ _connectionSubscriptions = new ComplexMap3(PeerInfoHash2);
1999
+ _peers = new ComplexMap3(PeerInfoHash2);
2000
+ mapUpdated = new Event4();
1959
2001
  get peers() {
1960
2002
  return Array.from(this._peers.values());
1961
2003
  }
1962
2004
  constructor(_swarm) {
1963
2005
  this._swarm = _swarm;
1964
- this._subscriptions = new SubscriptionList();
1965
- this._connectionSubscriptions = new ComplexMap3(PeerInfoHash2);
1966
- this._peers = new ComplexMap3(PeerInfoHash2);
1967
- this.mapUpdated = new Event4();
1968
2006
  this._subscriptions.add(_swarm.connectionAdded.on((connection) => {
1969
2007
  this._update();
1970
2008
  this._connectionSubscriptions.set(connection.remoteInfo, connection.stateChanged.on(() => {
@@ -1979,8 +2017,8 @@ var SwarmMapper = class {
1979
2017
  this._update();
1980
2018
  }
1981
2019
  _update() {
1982
- log6("updating swarm", void 0, {
1983
- F: __dxlog_file6,
2020
+ log5("updating swarm", void 0, {
2021
+ F: __dxlog_file5,
1984
2022
  L: 71,
1985
2023
  S: this,
1986
2024
  C: (f, a) => f(...a)
@@ -2000,11 +2038,11 @@ var SwarmMapper = class {
2000
2038
  ]
2001
2039
  });
2002
2040
  }
2003
- log6("graph changed", {
2041
+ log5("graph changed", {
2004
2042
  directConnections: this._swarm.connections.length,
2005
2043
  totalPeersInSwarm: this._peers.size
2006
2044
  }, {
2007
- F: __dxlog_file6,
2045
+ F: __dxlog_file5,
2008
2046
  L: 112,
2009
2047
  S: this,
2010
2048
  C: (f, a) => f(...a)
@@ -2019,31 +2057,32 @@ var SwarmMapper = class {
2019
2057
  }
2020
2058
  };
2021
2059
 
2022
- // packages/core/mesh/network-manager/src/swarm/connection-limiter.ts
2060
+ // src/swarm/connection-limiter.ts
2023
2061
  import { DeferredTask as DeferredTask2 } from "@dxos/async";
2024
2062
  import { Context as Context5 } from "@dxos/context";
2025
2063
  import { invariant as invariant5 } from "@dxos/invariant";
2026
2064
  import { PublicKey as PublicKey6 } from "@dxos/keys";
2027
- import { log as log7 } from "@dxos/log";
2065
+ import { log as log6 } from "@dxos/log";
2028
2066
  import { CancelledError as CancelledError3 } from "@dxos/protocols";
2029
2067
  import { ComplexMap as ComplexMap4 } from "@dxos/util";
2030
- var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
2068
+ var __dxlog_file6 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
2031
2069
  var MAX_CONCURRENT_INITIATING_CONNECTIONS = 50;
2032
2070
  var ConnectionLimiter = class {
2033
- constructor({ maxConcurrentInitConnections = MAX_CONCURRENT_INITIATING_CONNECTIONS } = {}) {
2034
- this._ctx = new Context5(void 0, {
2035
- F: __dxlog_file7,
2036
- L: 23
2037
- });
2038
- /**
2039
- * Queue of promises to resolve when initiating connections amount is below the limit.
2040
- */
2041
- this._waitingPromises = new ComplexMap4(PublicKey6.hash);
2042
- this.resolveWaitingPromises = new DeferredTask2(this._ctx, async () => {
2043
- Array.from(this._waitingPromises.values()).slice(0, this._maxConcurrentInitConnections).forEach(({ resolve }) => {
2044
- resolve();
2045
- });
2071
+ _ctx = new Context5(void 0, {
2072
+ F: __dxlog_file6,
2073
+ L: 23
2074
+ });
2075
+ _maxConcurrentInitConnections;
2076
+ /**
2077
+ * Queue of promises to resolve when initiating connections amount is below the limit.
2078
+ */
2079
+ _waitingPromises = new ComplexMap4(PublicKey6.hash);
2080
+ resolveWaitingPromises = new DeferredTask2(this._ctx, async () => {
2081
+ Array.from(this._waitingPromises.values()).slice(0, this._maxConcurrentInitConnections).forEach(({ resolve }) => {
2082
+ resolve();
2046
2083
  });
2084
+ });
2085
+ constructor({ maxConcurrentInitConnections = MAX_CONCURRENT_INITIATING_CONNECTIONS } = {}) {
2047
2086
  this._maxConcurrentInitConnections = maxConcurrentInitConnections;
2048
2087
  }
2049
2088
  /**
@@ -2051,7 +2090,7 @@ var ConnectionLimiter = class {
2051
2090
  */
2052
2091
  async connecting(sessionId) {
2053
2092
  invariant5(!this._waitingPromises.has(sessionId), "Peer is already waiting for connection", {
2054
- F: __dxlog_file7,
2093
+ F: __dxlog_file6,
2055
2094
  L: 48,
2056
2095
  S: this,
2057
2096
  A: [
@@ -2059,10 +2098,10 @@ var ConnectionLimiter = class {
2059
2098
  "'Peer is already waiting for connection'"
2060
2099
  ]
2061
2100
  });
2062
- log7("waiting", {
2101
+ log6("waiting", {
2063
2102
  sessionId
2064
2103
  }, {
2065
- F: __dxlog_file7,
2104
+ F: __dxlog_file6,
2066
2105
  L: 49,
2067
2106
  S: this,
2068
2107
  C: (f, a) => f(...a)
@@ -2074,10 +2113,10 @@ var ConnectionLimiter = class {
2074
2113
  });
2075
2114
  this.resolveWaitingPromises.schedule();
2076
2115
  });
2077
- log7("allow", {
2116
+ log6("allow", {
2078
2117
  sessionId
2079
2118
  }, {
2080
- F: __dxlog_file7,
2119
+ F: __dxlog_file6,
2081
2120
  L: 57,
2082
2121
  S: this,
2083
2122
  C: (f, a) => f(...a)
@@ -2087,10 +2126,10 @@ var ConnectionLimiter = class {
2087
2126
  * Rejects promise returned by `connecting` method.
2088
2127
  */
2089
2128
  doneConnecting(sessionId) {
2090
- log7("done", {
2129
+ log6("done", {
2091
2130
  sessionId
2092
2131
  }, {
2093
- F: __dxlog_file7,
2132
+ F: __dxlog_file6,
2094
2133
  L: 64,
2095
2134
  S: this,
2096
2135
  C: (f, a) => f(...a)
@@ -2104,28 +2143,26 @@ var ConnectionLimiter = class {
2104
2143
  }
2105
2144
  };
2106
2145
 
2107
- // packages/core/mesh/network-manager/src/connection-log.ts
2146
+ // src/connection-log.ts
2108
2147
  import { Event as Event5 } from "@dxos/async";
2109
2148
  import { raise } from "@dxos/debug";
2110
2149
  import { PublicKey as PublicKey7 } from "@dxos/keys";
2111
2150
  import { ComplexMap as ComplexMap5 } from "@dxos/util";
2112
2151
  var CONNECTION_GC_THRESHOLD = 1e3 * 60 * 15;
2113
- var EventType = /* @__PURE__ */ function(EventType2) {
2152
+ var EventType = /* @__PURE__ */ (function(EventType2) {
2114
2153
  EventType2["CONNECTION_STATE_CHANGED"] = "CONNECTION_STATE_CHANGED";
2115
2154
  EventType2["PROTOCOL_ERROR"] = "PROTOCOL_ERROR";
2116
2155
  EventType2["PROTOCOL_EXTENSIONS_INITIALIZED"] = "PROTOCOL_EXTENSIONS_INITIALIZED";
2117
2156
  EventType2["PROTOCOL_EXTENSIONS_HANDSHAKE"] = "PROTOCOL_EXTENSIONS_HANDSHAKE";
2118
2157
  EventType2["PROTOCOL_HANDSHAKE"] = "PROTOCOL_HANDSHAKE";
2119
2158
  return EventType2;
2120
- }({});
2159
+ })({});
2121
2160
  var ConnectionLog = class {
2122
- constructor() {
2123
- /**
2124
- * SwarmId => info
2125
- */
2126
- this._swarms = new ComplexMap5(PublicKey7.hash);
2127
- this.update = new Event5();
2128
- }
2161
+ /**
2162
+ * SwarmId => info
2163
+ */
2164
+ _swarms = new ComplexMap5(PublicKey7.hash);
2165
+ update = new Event5();
2129
2166
  getSwarmInfo(swarmId) {
2130
2167
  return this._swarms.get(swarmId) ?? raise(new Error(`Swarm not found: ${swarmId}`));
2131
2168
  }
@@ -2196,11 +2233,11 @@ var gcSwarm = (swarm) => {
2196
2233
  });
2197
2234
  };
2198
2235
 
2199
- // packages/core/mesh/network-manager/src/network-manager.ts
2236
+ // src/network-manager.ts
2200
2237
  import { Event as Event6, synchronized as synchronized4 } from "@dxos/async";
2201
2238
  import { invariant as invariant6 } from "@dxos/invariant";
2202
2239
  import { PublicKey as PublicKey8 } from "@dxos/keys";
2203
- import { log as log8 } from "@dxos/log";
2240
+ import { log as log7 } from "@dxos/log";
2204
2241
  import { Messenger } from "@dxos/messaging";
2205
2242
  import { trace as trace3 } from "@dxos/protocols";
2206
2243
  import { ConnectionState as ConnectionState2 } from "@dxos/protocols/proto/dxos/client/services";
@@ -2211,19 +2248,25 @@ function _ts_decorate4(decorators, target, key, desc) {
2211
2248
  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;
2212
2249
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2213
2250
  }
2214
- var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts";
2251
+ var __dxlog_file7 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts";
2215
2252
  var SwarmNetworkManager = class {
2253
+ /**
2254
+ * @internal
2255
+ */
2256
+ _swarms = new ComplexMap6(PublicKey8.hash);
2257
+ _mappers = new ComplexMap6(PublicKey8.hash);
2258
+ _transportFactory;
2259
+ _signalManager;
2260
+ _messenger;
2261
+ _signalConnection;
2262
+ _connectionLimiter;
2263
+ _connectionLog;
2264
+ _instanceId = PublicKey8.random().toHex();
2265
+ _peerInfo = void 0;
2266
+ _connectionState = ConnectionState2.ONLINE;
2267
+ connectionStateChanged = new Event6();
2268
+ topicsUpdated = new Event6();
2216
2269
  constructor({ transportFactory, signalManager, enableDevtoolsLogging, peerInfo }) {
2217
- /**
2218
- * @internal
2219
- */
2220
- this._swarms = new ComplexMap6(PublicKey8.hash);
2221
- this._mappers = new ComplexMap6(PublicKey8.hash);
2222
- this._instanceId = PublicKey8.random().toHex();
2223
- this._peerInfo = void 0;
2224
- this._connectionState = ConnectionState2.ONLINE;
2225
- this.connectionStateChanged = new Event6();
2226
- this.topicsUpdated = new Event6();
2227
2270
  this._transportFactory = transportFactory;
2228
2271
  this._signalManager = signalManager;
2229
2272
  this._signalManager.swarmEvent.on((event) => this._swarms.get(event.topic)?.onSwarmEvent(event));
@@ -2261,20 +2304,20 @@ var SwarmNetworkManager = class {
2261
2304
  this._peerInfo = peerInfo;
2262
2305
  }
2263
2306
  async open() {
2264
- log8.trace("dxos.mesh.network-manager.open", trace3.begin({
2307
+ log7.trace("dxos.mesh.network-manager.open", trace3.begin({
2265
2308
  id: this._instanceId
2266
2309
  }), {
2267
- F: __dxlog_file8,
2310
+ F: __dxlog_file7,
2268
2311
  L: 133,
2269
2312
  S: this,
2270
2313
  C: (f, a) => f(...a)
2271
2314
  });
2272
2315
  await this._messenger.open();
2273
2316
  await this._signalManager.open();
2274
- log8.trace("dxos.mesh.network-manager.open", trace3.end({
2317
+ log7.trace("dxos.mesh.network-manager.open", trace3.end({
2275
2318
  id: this._instanceId
2276
2319
  }), {
2277
- F: __dxlog_file8,
2320
+ F: __dxlog_file7,
2278
2321
  L: 136,
2279
2322
  S: this,
2280
2323
  C: (f, a) => f(...a)
@@ -2283,8 +2326,8 @@ var SwarmNetworkManager = class {
2283
2326
  async close() {
2284
2327
  for (const topic of this._swarms.keys()) {
2285
2328
  await this.leaveSwarm(topic).catch((err) => {
2286
- log8(err, void 0, {
2287
- F: __dxlog_file8,
2329
+ log7(err, void 0, {
2330
+ F: __dxlog_file7,
2288
2331
  L: 142,
2289
2332
  S: this,
2290
2333
  C: (f, a) => f(...a)
@@ -2299,7 +2342,7 @@ var SwarmNetworkManager = class {
2299
2342
  */
2300
2343
  async joinSwarm({ topic, topology, protocolProvider: protocol, label }) {
2301
2344
  invariant6(PublicKey8.isPublicKey(topic), void 0, {
2302
- F: __dxlog_file8,
2345
+ F: __dxlog_file7,
2303
2346
  L: 160,
2304
2347
  S: this,
2305
2348
  A: [
@@ -2308,7 +2351,7 @@ var SwarmNetworkManager = class {
2308
2351
  ]
2309
2352
  });
2310
2353
  invariant6(topology, void 0, {
2311
- F: __dxlog_file8,
2354
+ F: __dxlog_file7,
2312
2355
  L: 161,
2313
2356
  S: this,
2314
2357
  A: [
@@ -2317,7 +2360,7 @@ var SwarmNetworkManager = class {
2317
2360
  ]
2318
2361
  });
2319
2362
  invariant6(this._peerInfo, void 0, {
2320
- F: __dxlog_file8,
2363
+ F: __dxlog_file7,
2321
2364
  L: 162,
2322
2365
  S: this,
2323
2366
  A: [
@@ -2326,7 +2369,7 @@ var SwarmNetworkManager = class {
2326
2369
  ]
2327
2370
  });
2328
2371
  invariant6(typeof protocol === "function", void 0, {
2329
- F: __dxlog_file8,
2372
+ F: __dxlog_file7,
2330
2373
  L: 163,
2331
2374
  S: this,
2332
2375
  A: [
@@ -2337,22 +2380,22 @@ var SwarmNetworkManager = class {
2337
2380
  if (this._swarms.has(topic)) {
2338
2381
  throw new Error(`Already connected to swarm: ${PublicKey8.from(topic)}`);
2339
2382
  }
2340
- log8("joining", {
2383
+ log7("joining", {
2341
2384
  topic: PublicKey8.from(topic),
2342
2385
  peerInfo: this._peerInfo,
2343
2386
  topology: topology.toString()
2344
2387
  }, {
2345
- F: __dxlog_file8,
2388
+ F: __dxlog_file7,
2346
2389
  L: 168,
2347
2390
  S: this,
2348
2391
  C: (f, a) => f(...a)
2349
2392
  });
2350
2393
  const swarm = new Swarm(topic, this._peerInfo, topology, protocol, this._messenger, this._transportFactory, label, this._connectionLimiter);
2351
2394
  swarm.errors.handle((error) => {
2352
- log8("swarm error", {
2395
+ log7("swarm error", {
2353
2396
  error
2354
2397
  }, {
2355
- F: __dxlog_file8,
2398
+ F: __dxlog_file7,
2356
2399
  L: 181,
2357
2400
  S: this,
2358
2401
  C: (f, a) => f(...a)
@@ -2364,19 +2407,19 @@ var SwarmNetworkManager = class {
2364
2407
  this._signalConnection.join({
2365
2408
  topic,
2366
2409
  peer: this._peerInfo
2367
- }).catch((error) => log8.catch(error, void 0, {
2368
- F: __dxlog_file8,
2410
+ }).catch((error) => log7.catch(error, void 0, {
2411
+ F: __dxlog_file7,
2369
2412
  L: 190,
2370
2413
  S: this,
2371
2414
  C: (f, a) => f(...a)
2372
2415
  }));
2373
2416
  this.topicsUpdated.emit();
2374
2417
  this._connectionLog?.joinedSwarm(swarm);
2375
- log8("joined", {
2418
+ log7("joined", {
2376
2419
  topic: PublicKey8.from(topic),
2377
2420
  count: this._swarms.size
2378
2421
  }, {
2379
- F: __dxlog_file8,
2422
+ F: __dxlog_file7,
2380
2423
  L: 194,
2381
2424
  S: this,
2382
2425
  C: (f, a) => f(...a)
@@ -2392,10 +2435,10 @@ var SwarmNetworkManager = class {
2392
2435
  if (!this._swarms.has(topic)) {
2393
2436
  return;
2394
2437
  }
2395
- log8("leaving", {
2438
+ log7("leaving", {
2396
2439
  topic: PublicKey8.from(topic)
2397
2440
  }, {
2398
- F: __dxlog_file8,
2441
+ F: __dxlog_file7,
2399
2442
  L: 211,
2400
2443
  S: this,
2401
2444
  C: (f, a) => f(...a)
@@ -2412,11 +2455,11 @@ var SwarmNetworkManager = class {
2412
2455
  await swarm.destroy();
2413
2456
  this._swarms.delete(topic);
2414
2457
  this.topicsUpdated.emit();
2415
- log8("left", {
2458
+ log7("left", {
2416
2459
  topic: PublicKey8.from(topic),
2417
2460
  count: this._swarms.size
2418
2461
  }, {
2419
- F: __dxlog_file8,
2462
+ F: __dxlog_file7,
2420
2463
  L: 225,
2421
2464
  S: this,
2422
2465
  C: (f, a) => f(...a)
@@ -2456,16 +2499,17 @@ _ts_decorate4([
2456
2499
  synchronized4
2457
2500
  ], SwarmNetworkManager.prototype, "leaveSwarm", null);
2458
2501
 
2459
- // packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts
2502
+ // src/topology/fully-connected-topology.ts
2460
2503
  import { invariant as invariant7 } from "@dxos/invariant";
2461
- var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
2504
+ var __dxlog_file8 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
2462
2505
  var FullyConnectedTopology = class {
2506
+ _controller;
2463
2507
  toString() {
2464
2508
  return "FullyConnectedTopology";
2465
2509
  }
2466
2510
  init(controller) {
2467
2511
  invariant7(!this._controller, "Already initialized", {
2468
- F: __dxlog_file9,
2512
+ F: __dxlog_file8,
2469
2513
  L: 18,
2470
2514
  S: this,
2471
2515
  A: [
@@ -2477,7 +2521,7 @@ var FullyConnectedTopology = class {
2477
2521
  }
2478
2522
  update() {
2479
2523
  invariant7(this._controller, "Not initialized", {
2480
- F: __dxlog_file9,
2524
+ F: __dxlog_file8,
2481
2525
  L: 23,
2482
2526
  S: this,
2483
2527
  A: [
@@ -2497,315 +2541,13 @@ var FullyConnectedTopology = class {
2497
2541
  }
2498
2542
  };
2499
2543
 
2500
- // packages/core/mesh/network-manager/src/topology/mmst-topology.ts
2544
+ // src/transport/memory-transport.ts
2545
+ import { Transform } from "@dxos/node-std/stream";
2546
+ import { Event as Event7, Trigger as Trigger2 } from "@dxos/async";
2547
+ import { ErrorStream as ErrorStream3 } from "@dxos/debug";
2501
2548
  import { invariant as invariant8 } from "@dxos/invariant";
2502
- import { log as log9 } from "@dxos/log";
2503
- var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/mmst-topology.ts";
2504
- var MIN_UPDATE_INTERVAL = 1e3 * 10;
2505
- var MAX_CHANGES_PER_UPDATE = 1;
2506
- var MMSTTopology = class {
2507
- constructor({ originateConnections = 2, maxPeers = 4, sampleSize = 10 } = {}) {
2508
- this._sampleCollected = false;
2509
- this._lastAction = /* @__PURE__ */ new Date(0);
2510
- this._originateConnections = originateConnections;
2511
- this._maxPeers = maxPeers;
2512
- this._sampleSize = sampleSize;
2513
- }
2514
- init(controller) {
2515
- invariant8(!this._controller, "Already initialized", {
2516
- F: __dxlog_file10,
2517
- L: 49,
2518
- S: this,
2519
- A: [
2520
- "!this._controller",
2521
- "'Already initialized'"
2522
- ]
2523
- });
2524
- this._controller = controller;
2525
- }
2526
- update() {
2527
- invariant8(this._controller, "Not initialized", {
2528
- F: __dxlog_file10,
2529
- L: 54,
2530
- S: this,
2531
- A: [
2532
- "this._controller",
2533
- "'Not initialized'"
2534
- ]
2535
- });
2536
- const { connected, candidates } = this._controller.getState();
2537
- if (this._sampleCollected || connected.length > this._maxPeers || candidates.length > 0) {
2538
- log9("Running the algorithm.", void 0, {
2539
- F: __dxlog_file10,
2540
- L: 58,
2541
- S: this,
2542
- C: (f, a) => f(...a)
2543
- });
2544
- this._sampleCollected = true;
2545
- this._runAlgorithm();
2546
- }
2547
- }
2548
- forceUpdate() {
2549
- this._lastAction = /* @__PURE__ */ new Date(0);
2550
- this.update();
2551
- }
2552
- async onOffer(peer) {
2553
- invariant8(this._controller, "Not initialized", {
2554
- F: __dxlog_file10,
2555
- L: 70,
2556
- S: this,
2557
- A: [
2558
- "this._controller",
2559
- "'Not initialized'"
2560
- ]
2561
- });
2562
- const { connected } = this._controller.getState();
2563
- const accept = connected.length < this._maxPeers;
2564
- log9(`Offer ${peer} accept=${accept}`, void 0, {
2565
- F: __dxlog_file10,
2566
- L: 73,
2567
- S: this,
2568
- C: (f, a) => f(...a)
2569
- });
2570
- return accept;
2571
- }
2572
- async destroy() {
2573
- }
2574
- _runAlgorithm() {
2575
- invariant8(this._controller, "Not initialized", {
2576
- F: __dxlog_file10,
2577
- L: 82,
2578
- S: this,
2579
- A: [
2580
- "this._controller",
2581
- "'Not initialized'"
2582
- ]
2583
- });
2584
- const { connected, candidates, ownPeerId } = this._controller.getState();
2585
- if (connected.length > this._maxPeers) {
2586
- log9(`disconnect ${connected.length - this._maxPeers} peers.`, void 0, {
2587
- F: __dxlog_file10,
2588
- L: 88,
2589
- S: this,
2590
- C: (f, a) => f(...a)
2591
- });
2592
- const sorted = sortByXorDistance(connected, ownPeerId).reverse().slice(0, this._maxPeers - connected.length);
2593
- invariant8(sorted.length === 0, void 0, {
2594
- F: __dxlog_file10,
2595
- L: 92,
2596
- S: this,
2597
- A: [
2598
- "sorted.length === 0",
2599
- ""
2600
- ]
2601
- });
2602
- if (sorted.length > MAX_CHANGES_PER_UPDATE) {
2603
- log9(`want to disconnect ${sorted.length} peers but limited to ${MAX_CHANGES_PER_UPDATE}`, void 0, {
2604
- F: __dxlog_file10,
2605
- L: 95,
2606
- S: this,
2607
- C: (f, a) => f(...a)
2608
- });
2609
- }
2610
- if (Date.now() - this._lastAction.getTime() > MIN_UPDATE_INTERVAL) {
2611
- for (const peer of sorted.slice(0, MAX_CHANGES_PER_UPDATE)) {
2612
- log9(`Disconnect ${peer}.`, void 0, {
2613
- F: __dxlog_file10,
2614
- L: 100,
2615
- S: this,
2616
- C: (f, a) => f(...a)
2617
- });
2618
- this._controller.disconnect(peer);
2619
- }
2620
- this._lastAction = /* @__PURE__ */ new Date();
2621
- } else {
2622
- log9("rate limited disconnect", void 0, {
2623
- F: __dxlog_file10,
2624
- L: 105,
2625
- S: this,
2626
- C: (f, a) => f(...a)
2627
- });
2628
- }
2629
- } else if (connected.length < this._originateConnections) {
2630
- log9(`connect ${this._originateConnections - connected.length} peers.`, void 0, {
2631
- F: __dxlog_file10,
2632
- L: 109,
2633
- S: this,
2634
- C: (f, a) => f(...a)
2635
- });
2636
- const sample = candidates.sort(() => Math.random() - 0.5).slice(0, this._sampleSize);
2637
- const sorted = sortByXorDistance(sample, ownPeerId).slice(0, this._originateConnections - connected.length);
2638
- if (sorted.length > MAX_CHANGES_PER_UPDATE) {
2639
- log9(`want to connect ${sorted.length} peers but limited to ${MAX_CHANGES_PER_UPDATE}`, void 0, {
2640
- F: __dxlog_file10,
2641
- L: 114,
2642
- S: this,
2643
- C: (f, a) => f(...a)
2644
- });
2645
- }
2646
- if (Date.now() - this._lastAction.getTime() > MIN_UPDATE_INTERVAL) {
2647
- for (const peer of sorted.slice(0, MAX_CHANGES_PER_UPDATE)) {
2648
- log9(`Connect ${peer}.`, void 0, {
2649
- F: __dxlog_file10,
2650
- L: 118,
2651
- S: this,
2652
- C: (f, a) => f(...a)
2653
- });
2654
- this._controller.connect(peer);
2655
- }
2656
- this._lastAction = /* @__PURE__ */ new Date();
2657
- } else {
2658
- log9("rate limited connect", void 0, {
2659
- F: __dxlog_file10,
2660
- L: 123,
2661
- S: this,
2662
- C: (f, a) => f(...a)
2663
- });
2664
- }
2665
- }
2666
- }
2667
- toString() {
2668
- return "MMSTTopology";
2669
- }
2670
- };
2671
- var sortByXorDistance = (keys, reference) => {
2672
- const sorted = keys.sort((a, b) => {
2673
- return compareXor(distXor(a.asBuffer(), reference.asBuffer()), distXor(b.asBuffer(), reference.asBuffer()));
2674
- });
2675
- log9("Sorted keys", {
2676
- keys,
2677
- reference,
2678
- sorted
2679
- }, {
2680
- F: __dxlog_file10,
2681
- L: 137,
2682
- S: void 0,
2683
- C: (f, a) => f(...a)
2684
- });
2685
- return sorted;
2686
- };
2687
- var distXor = (a, b) => {
2688
- const maxLength = Math.max(a.length, b.length);
2689
- const result = Buffer.allocUnsafe(maxLength);
2690
- for (let i = 0; i < maxLength; i++) {
2691
- result[i] = (a[i] || 0) ^ (b[i] || 0);
2692
- }
2693
- return result;
2694
- };
2695
- var compareXor = (a, b) => {
2696
- const maxLength = Math.max(a.length, b.length);
2697
- for (let i = 0; i < maxLength; i++) {
2698
- if ((a[i] || 0) === (b[i] || 0)) {
2699
- continue;
2700
- }
2701
- return (a[i] || 0) < (b[i] || 0) ? -1 : 1;
2702
- }
2703
- return 0;
2704
- };
2705
-
2706
- // packages/core/mesh/network-manager/src/topology/star-topology.ts
2707
- import { invariant as invariant9 } from "@dxos/invariant";
2708
- import { log as log10 } from "@dxos/log";
2709
- var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/star-topology.ts";
2710
- var StarTopology = class {
2711
- constructor(_centralPeer) {
2712
- this._centralPeer = _centralPeer;
2713
- }
2714
- toString() {
2715
- return `StarTopology(${this._centralPeer.truncate()})`;
2716
- }
2717
- init(controller) {
2718
- invariant9(!this._controller, "Already initialized.", {
2719
- F: __dxlog_file11,
2720
- L: 21,
2721
- S: this,
2722
- A: [
2723
- "!this._controller",
2724
- "'Already initialized.'"
2725
- ]
2726
- });
2727
- this._controller = controller;
2728
- }
2729
- update() {
2730
- invariant9(this._controller, "Not initialized.", {
2731
- F: __dxlog_file11,
2732
- L: 26,
2733
- S: this,
2734
- A: [
2735
- "this._controller",
2736
- "'Not initialized.'"
2737
- ]
2738
- });
2739
- const { candidates, connected, ownPeerId } = this._controller.getState();
2740
- if (!ownPeerId.equals(this._centralPeer)) {
2741
- log10("leaf peer dropping all connections apart from central peer.", void 0, {
2742
- F: __dxlog_file11,
2743
- L: 29,
2744
- S: this,
2745
- C: (f, a) => f(...a)
2746
- });
2747
- for (const peer of connected) {
2748
- if (!peer.equals(this._centralPeer)) {
2749
- log10("dropping connection", {
2750
- peer
2751
- }, {
2752
- F: __dxlog_file11,
2753
- L: 34,
2754
- S: this,
2755
- C: (f, a) => f(...a)
2756
- });
2757
- this._controller.disconnect(peer);
2758
- }
2759
- }
2760
- }
2761
- for (const peer of candidates) {
2762
- if (peer.equals(this._centralPeer) || ownPeerId.equals(this._centralPeer)) {
2763
- log10("connecting to peer", {
2764
- peer
2765
- }, {
2766
- F: __dxlog_file11,
2767
- L: 43,
2768
- S: this,
2769
- C: (f, a) => f(...a)
2770
- });
2771
- this._controller.connect(peer);
2772
- }
2773
- }
2774
- }
2775
- async onOffer(peer) {
2776
- invariant9(this._controller, "Not initialized.", {
2777
- F: __dxlog_file11,
2778
- L: 50,
2779
- S: this,
2780
- A: [
2781
- "this._controller",
2782
- "'Not initialized.'"
2783
- ]
2784
- });
2785
- const { ownPeerId } = this._controller.getState();
2786
- log10("offer", {
2787
- peer,
2788
- isCentral: peer.equals(this._centralPeer),
2789
- isSelfCentral: ownPeerId.equals(this._centralPeer)
2790
- }, {
2791
- F: __dxlog_file11,
2792
- L: 52,
2793
- S: this,
2794
- C: (f, a) => f(...a)
2795
- });
2796
- return ownPeerId.equals(this._centralPeer) || peer.equals(this._centralPeer);
2797
- }
2798
- async destroy() {
2799
- }
2800
- };
2801
-
2802
- // packages/core/mesh/network-manager/src/transport/memory-transport.ts
2803
- import { Transform } from "@dxos/node-std/stream";
2804
- import { Event as Event7, Trigger as Trigger2 } from "@dxos/async";
2805
- import { ErrorStream as ErrorStream3 } from "@dxos/debug";
2806
- import { invariant as invariant10 } from "@dxos/invariant";
2807
2549
  import { PublicKey as PublicKey9 } from "@dxos/keys";
2808
- import { log as log11, logInfo as logInfo3 } from "@dxos/log";
2550
+ import { log as log8, logInfo as logInfo3 } from "@dxos/log";
2809
2551
  import { ComplexMap as ComplexMap7 } from "@dxos/util";
2810
2552
  function _ts_decorate5(decorators, target, key, desc) {
2811
2553
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -2813,7 +2555,7 @@ function _ts_decorate5(decorators, target, key, desc) {
2813
2555
  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;
2814
2556
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2815
2557
  }
2816
- var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
2558
+ var __dxlog_file9 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
2817
2559
  var MEMORY_TRANSPORT_DELAY = 1;
2818
2560
  var createStreamDelay = (delay) => {
2819
2561
  return new Transform({
@@ -2827,22 +2569,23 @@ var MemoryTransportFactory = {
2827
2569
  createTransport: (options) => new MemoryTransport(options)
2828
2570
  };
2829
2571
  var MemoryTransport = class _MemoryTransport {
2830
- static {
2831
- // TODO(burdon): Remove static properties (inject context into constructor).
2832
- this._connections = new ComplexMap7(PublicKey9.hash);
2833
- }
2572
+ _options;
2573
+ // TODO(burdon): Remove static properties (inject context into constructor).
2574
+ static _connections = new ComplexMap7(PublicKey9.hash);
2575
+ _instanceId = PublicKey9.random();
2576
+ _remote = new Trigger2();
2577
+ _outgoingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
2578
+ _incomingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
2579
+ _closed = false;
2580
+ _remoteInstanceId;
2581
+ _remoteConnection;
2582
+ closed = new Event7();
2583
+ connected = new Event7();
2584
+ errors = new ErrorStream3();
2834
2585
  constructor(_options) {
2835
2586
  this._options = _options;
2836
- this._instanceId = PublicKey9.random();
2837
- this._remote = new Trigger2();
2838
- this._outgoingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
2839
- this._incomingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
2840
- this._closed = false;
2841
- this.closed = new Event7();
2842
- this.connected = new Event7();
2843
- this.errors = new ErrorStream3();
2844
- invariant10(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection", {
2845
- F: __dxlog_file12,
2587
+ invariant8(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection", {
2588
+ F: __dxlog_file9,
2846
2589
  L: 64,
2847
2590
  S: this,
2848
2591
  A: [
@@ -2856,15 +2599,15 @@ var MemoryTransport = class _MemoryTransport {
2856
2599
  return !this._closed;
2857
2600
  }
2858
2601
  async open() {
2859
- log11("opening...", void 0, {
2860
- F: __dxlog_file12,
2602
+ log8("opening...", void 0, {
2603
+ F: __dxlog_file9,
2861
2604
  L: 74,
2862
2605
  S: this,
2863
2606
  C: (f, a) => f(...a)
2864
2607
  });
2865
2608
  if (this._options.initiator) {
2866
- log11("sending signal", void 0, {
2867
- F: __dxlog_file12,
2609
+ log8("sending signal", void 0, {
2610
+ F: __dxlog_file9,
2868
2611
  L: 78,
2869
2612
  S: this,
2870
2613
  C: (f, a) => f(...a)
@@ -2894,8 +2637,8 @@ var MemoryTransport = class _MemoryTransport {
2894
2637
  this.closed.emit();
2895
2638
  return;
2896
2639
  }
2897
- invariant10(!this._remoteConnection._remoteConnection, `Remote already connected: ${this._remoteInstanceId}`, {
2898
- F: __dxlog_file12,
2640
+ invariant8(!this._remoteConnection._remoteConnection, `Remote already connected: ${this._remoteInstanceId}`, {
2641
+ F: __dxlog_file9,
2899
2642
  L: 104,
2900
2643
  S: this,
2901
2644
  A: [
@@ -2905,8 +2648,8 @@ var MemoryTransport = class _MemoryTransport {
2905
2648
  });
2906
2649
  this._remoteConnection._remoteConnection = this;
2907
2650
  this._remoteConnection._remoteInstanceId = this._instanceId;
2908
- log11("connected", void 0, {
2909
- F: __dxlog_file12,
2651
+ log8("connected", void 0, {
2652
+ F: __dxlog_file9,
2910
2653
  L: 108,
2911
2654
  S: this,
2912
2655
  C: (f, a) => f(...a)
@@ -2924,8 +2667,8 @@ var MemoryTransport = class _MemoryTransport {
2924
2667
  return this;
2925
2668
  }
2926
2669
  async close() {
2927
- log11("closing...", void 0, {
2928
- F: __dxlog_file12,
2670
+ log8("closing...", void 0, {
2671
+ F: __dxlog_file9,
2929
2672
  L: 130,
2930
2673
  S: this,
2931
2674
  C: (f, a) => f(...a)
@@ -2945,8 +2688,8 @@ var MemoryTransport = class _MemoryTransport {
2945
2688
  this._remoteConnection = void 0;
2946
2689
  }
2947
2690
  this.closed.emit();
2948
- log11("closed", void 0, {
2949
- F: __dxlog_file12,
2691
+ log8("closed", void 0, {
2692
+ F: __dxlog_file9,
2950
2693
  L: 158,
2951
2694
  S: this,
2952
2695
  C: (f, a) => f(...a)
@@ -2954,10 +2697,10 @@ var MemoryTransport = class _MemoryTransport {
2954
2697
  return this;
2955
2698
  }
2956
2699
  async onSignal({ payload }) {
2957
- log11("received signal", {
2700
+ log8("received signal", {
2958
2701
  payload
2959
2702
  }, {
2960
- F: __dxlog_file12,
2703
+ F: __dxlog_file9,
2961
2704
  L: 163,
2962
2705
  S: this,
2963
2706
  C: (f, a) => f(...a)
@@ -2991,16 +2734,16 @@ _ts_decorate5([
2991
2734
  ], MemoryTransport.prototype, "_remoteInstanceId", void 0);
2992
2735
  var toError = (err) => err instanceof Error ? err : new Error(String(err));
2993
2736
 
2994
- // packages/core/mesh/network-manager/src/transport/transport.ts
2995
- var TransportKind = /* @__PURE__ */ function(TransportKind2) {
2737
+ // src/transport/transport.ts
2738
+ var TransportKind = /* @__PURE__ */ (function(TransportKind2) {
2996
2739
  TransportKind2["WEB_RTC"] = "WEB-RTC";
2997
2740
  TransportKind2["WEB_RTC_PROXY"] = "WEB-RTC_PROXY";
2998
2741
  TransportKind2["MEMORY"] = "MEMORY";
2999
2742
  TransportKind2["TCP"] = "TCP";
3000
2743
  return TransportKind2;
3001
- }({});
2744
+ })({});
3002
2745
 
3003
- // packages/core/mesh/network-manager/src/transport/webrtc/rtc-connection-factory.ts
2746
+ // src/transport/webrtc/rtc-connection-factory.ts
3004
2747
  import { Mutex } from "@dxos/async";
3005
2748
  var BrowserRtcConnectionFactory = class {
3006
2749
  async initialize() {
@@ -3014,14 +2757,10 @@ var BrowserRtcConnectionFactory = class {
3014
2757
  }
3015
2758
  };
3016
2759
  var NodeRtcConnectionFactory = class _NodeRtcConnectionFactory {
3017
- static {
3018
- this._createdConnections = 0;
3019
- }
3020
- static {
3021
- this._cleanupMutex = new Mutex();
3022
- }
2760
+ static _createdConnections = 0;
2761
+ static _cleanupMutex = new Mutex();
3023
2762
  // This should be inside the function to avoid triggering `eval` in the global scope.
3024
- // eslint-disable-next-line no-new-func
2763
+ // eslint-disable-next-line @typescript-eslint/no-implied-eval
3025
2764
  // TODO(burdon): Do imports here?
3026
2765
  async initialize() {
3027
2766
  }
@@ -3049,23 +2788,23 @@ var getRtcConnectionFactory = () => {
3049
2788
  return typeof globalThis.RTCPeerConnection === "undefined" ? new NodeRtcConnectionFactory() : new BrowserRtcConnectionFactory();
3050
2789
  };
3051
2790
 
3052
- // packages/core/mesh/network-manager/src/transport/webrtc/rtc-peer-connection.ts
3053
- import { synchronized as synchronized5, Trigger as Trigger3, Mutex as Mutex2 } from "@dxos/async";
3054
- import { invariant as invariant12 } from "@dxos/invariant";
3055
- import { log as log13, logInfo as logInfo4 } from "@dxos/log";
2791
+ // src/transport/webrtc/rtc-peer-connection.ts
2792
+ import { Mutex as Mutex2, Trigger as Trigger3, synchronized as synchronized5 } from "@dxos/async";
2793
+ import { invariant as invariant10 } from "@dxos/invariant";
2794
+ import { log as log10, logInfo as logInfo4 } from "@dxos/log";
3056
2795
  import { ConnectivityError as ConnectivityError3 } from "@dxos/protocols";
3057
2796
  import { trace as trace4 } from "@dxos/tracing";
3058
2797
 
3059
- // packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-channel.ts
2798
+ // src/transport/webrtc/rtc-transport-channel.ts
3060
2799
  import { Duplex } from "@dxos/node-std/stream";
3061
2800
  import { Event as AsyncEvent } from "@dxos/async";
3062
2801
  import { Resource } from "@dxos/context";
3063
2802
  import { ErrorStream as ErrorStream4 } from "@dxos/debug";
3064
- import { invariant as invariant11 } from "@dxos/invariant";
3065
- import { log as log12 } from "@dxos/log";
2803
+ import { invariant as invariant9 } from "@dxos/invariant";
2804
+ import { log as log9 } from "@dxos/log";
3066
2805
  import { ConnectivityError as ConnectivityError2 } from "@dxos/protocols";
3067
2806
 
3068
- // packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-stats.ts
2807
+ // src/transport/webrtc/rtc-transport-stats.ts
3069
2808
  var describeSelectedRemoteCandidate = async (connection) => {
3070
2809
  const stats = connection && await getRtcConnectionStats(connection);
3071
2810
  const rc = stats?.remoteCandidate;
@@ -3112,13 +2851,22 @@ var getRtcConnectionStats = async (connection, channelTopic) => {
3112
2851
  };
3113
2852
  };
3114
2853
 
3115
- // packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-channel.ts
3116
- var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-channel.ts";
2854
+ // src/transport/webrtc/rtc-transport-channel.ts
2855
+ var __dxlog_file10 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-channel.ts";
3117
2856
  var MAX_MESSAGE_SIZE = 64 * 1024;
3118
2857
  var MAX_BUFFERED_AMOUNT = 64 * 1024;
3119
2858
  var RtcTransportChannel = class extends Resource {
2859
+ _connection;
2860
+ _options;
2861
+ closed = new AsyncEvent();
2862
+ connected = new AsyncEvent();
2863
+ errors = new ErrorStream4();
2864
+ _channel;
2865
+ _stream;
2866
+ _streamDataFlushedCallback = null;
2867
+ _isChannelCreationInProgress = false;
3120
2868
  constructor(_connection, _options) {
3121
- super(), this._connection = _connection, this._options = _options, this.closed = new AsyncEvent(), this.connected = new AsyncEvent(), this.errors = new ErrorStream4(), this._streamDataFlushedCallback = null, this._isChannelCreationInProgress = false;
2869
+ super(), this._connection = _connection, this._options = _options;
3122
2870
  }
3123
2871
  get isRtcChannelCreationInProgress() {
3124
2872
  return this._isChannelCreationInProgress;
@@ -3129,9 +2877,9 @@ var RtcTransportChannel = class extends Resource {
3129
2877
  }
3130
2878
  }
3131
2879
  async _open() {
3132
- invariant11(!this._isChannelCreationInProgress, void 0, {
3133
- F: __dxlog_file13,
3134
- L: 56,
2880
+ invariant9(!this._isChannelCreationInProgress, void 0, {
2881
+ F: __dxlog_file10,
2882
+ L: 57,
3135
2883
  S: this,
3136
2884
  A: [
3137
2885
  "!this._isChannelCreationInProgress",
@@ -3148,14 +2896,16 @@ var RtcTransportChannel = class extends Resource {
3148
2896
  }
3149
2897
  }).catch((err) => {
3150
2898
  if (this.isOpen) {
3151
- const error = err instanceof Error ? err : new ConnectivityError2(`Failed to create a channel: ${JSON.stringify(err?.message)}`);
2899
+ const error = err instanceof Error ? err : new ConnectivityError2({
2900
+ message: `Failed to create a channel: ${JSON.stringify(err?.message)}`
2901
+ });
3152
2902
  this.errors.raise(error);
3153
2903
  } else {
3154
- log12.verbose("connection establishment failed after transport was closed", {
2904
+ log9.verbose("connection establishment failed after transport was closed", {
3155
2905
  err
3156
2906
  }, {
3157
- F: __dxlog_file13,
3158
- L: 76,
2907
+ F: __dxlog_file10,
2908
+ L: 77,
3159
2909
  S: this,
3160
2910
  C: (f, a) => f(...a)
3161
2911
  });
@@ -3171,9 +2921,9 @@ var RtcTransportChannel = class extends Resource {
3171
2921
  this._stream = void 0;
3172
2922
  }
3173
2923
  this.closed.emit();
3174
- log12("closed", void 0, {
3175
- F: __dxlog_file13,
3176
- L: 92,
2924
+ log9("closed", void 0, {
2925
+ F: __dxlog_file10,
2926
+ L: 93,
3177
2927
  S: this,
3178
2928
  C: (f, a) => f(...a)
3179
2929
  });
@@ -3182,20 +2932,20 @@ var RtcTransportChannel = class extends Resource {
3182
2932
  Object.assign(channel, {
3183
2933
  onopen: () => {
3184
2934
  if (!this.isOpen) {
3185
- log12.warn("channel opened in a closed transport", {
2935
+ log9.warn("channel opened in a closed transport", {
3186
2936
  topic: this._options.topic
3187
2937
  }, {
3188
- F: __dxlog_file13,
3189
- L: 99,
2938
+ F: __dxlog_file10,
2939
+ L: 100,
3190
2940
  S: this,
3191
2941
  C: (f, a) => f(...a)
3192
2942
  });
3193
2943
  this._safeCloseChannel(channel);
3194
2944
  return;
3195
2945
  }
3196
- log12("onopen", void 0, {
3197
- F: __dxlog_file13,
3198
- L: 104,
2946
+ log9("onopen", void 0, {
2947
+ F: __dxlog_file10,
2948
+ L: 105,
3199
2949
  S: this,
3200
2950
  C: (f, a) => f(...a)
3201
2951
  });
@@ -3211,9 +2961,9 @@ var RtcTransportChannel = class extends Resource {
3211
2961
  this.connected.emit();
3212
2962
  },
3213
2963
  onclose: async () => {
3214
- log12("onclose", void 0, {
3215
- F: __dxlog_file13,
3216
- L: 117,
2964
+ log9("onclose", void 0, {
2965
+ F: __dxlog_file10,
2966
+ L: 118,
3217
2967
  S: this,
3218
2968
  C: (f, a) => f(...a)
3219
2969
  });
@@ -3221,9 +2971,9 @@ var RtcTransportChannel = class extends Resource {
3221
2971
  },
3222
2972
  onmessage: async (event) => {
3223
2973
  if (!this._stream) {
3224
- log12.warn("ignoring message on a closed channel", void 0, {
3225
- F: __dxlog_file13,
3226
- L: 123,
2974
+ log9.warn("ignoring message on a closed channel", void 0, {
2975
+ F: __dxlog_file10,
2976
+ L: 124,
3227
2977
  S: this,
3228
2978
  C: (f, a) => f(...a)
3229
2979
  });
@@ -3252,9 +3002,9 @@ var RtcTransportChannel = class extends Resource {
3252
3002
  }
3253
3003
  async _handleChannelWrite(chunk, callback) {
3254
3004
  if (!this._channel) {
3255
- log12.warn("writing to a channel after a connection was closed", void 0, {
3256
- F: __dxlog_file13,
3257
- L: 153,
3005
+ log9.warn("writing to a channel after a connection was closed", void 0, {
3006
+ F: __dxlog_file10,
3007
+ L: 154,
3258
3008
  S: this,
3259
3009
  C: (f, a) => f(...a)
3260
3010
  });
@@ -3275,9 +3025,9 @@ var RtcTransportChannel = class extends Resource {
3275
3025
  }
3276
3026
  if (this._channel.bufferedAmount > MAX_BUFFERED_AMOUNT) {
3277
3027
  if (this._streamDataFlushedCallback !== null) {
3278
- log12.error("consumer trying to write before we are ready for more data", void 0, {
3279
- F: __dxlog_file13,
3280
- L: 174,
3028
+ log9.error("consumer trying to write before we are ready for more data", void 0, {
3029
+ F: __dxlog_file10,
3030
+ L: 175,
3281
3031
  S: this,
3282
3032
  C: (f, a) => f(...a)
3283
3033
  });
@@ -3291,9 +3041,9 @@ var RtcTransportChannel = class extends Resource {
3291
3041
  try {
3292
3042
  channel.close();
3293
3043
  } catch (error) {
3294
- log12.catch(error, void 0, {
3295
- F: __dxlog_file13,
3296
- L: 186,
3044
+ log9.catch(error, void 0, {
3045
+ F: __dxlog_file10,
3046
+ L: 187,
3297
3047
  S: this,
3298
3048
  C: (f, a) => f(...a)
3299
3049
  });
@@ -3310,7 +3060,7 @@ var RtcTransportChannel = class extends Resource {
3310
3060
  }
3311
3061
  };
3312
3062
 
3313
- // packages/core/mesh/network-manager/src/transport/webrtc/utils.ts
3063
+ // src/transport/webrtc/utils.ts
3314
3064
  var chooseInitiatorPeer = (peer1Key, peer2Key) => peer1Key < peer2Key ? peer1Key : peer2Key;
3315
3065
  var areSdpEqual = (sdp1, sdp2) => {
3316
3066
  const sdp1Lines = deduplicatedSdpLines(sdp1);
@@ -3336,23 +3086,36 @@ var deduplicatedSdpLines = (sdp) => {
3336
3086
  return deduplicatedLines;
3337
3087
  };
3338
3088
 
3339
- // packages/core/mesh/network-manager/src/transport/webrtc/rtc-peer-connection.ts
3089
+ // src/transport/webrtc/rtc-peer-connection.ts
3340
3090
  function _ts_decorate6(decorators, target, key, desc) {
3341
3091
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3342
3092
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
3343
3093
  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;
3344
3094
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3345
3095
  }
3346
- var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-peer-connection.ts";
3096
+ var __dxlog_file11 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-peer-connection.ts";
3347
3097
  var RtcPeerConnection = class {
3098
+ _factory;
3099
+ _options;
3100
+ // A peer who is not the initiator waits for another party to open a channel.
3101
+ _channelCreatedCallbacks = /* @__PURE__ */ new Map();
3102
+ // Channels indexed by topic.
3103
+ _transportChannels = /* @__PURE__ */ new Map();
3104
+ _dataChannels = /* @__PURE__ */ new Map();
3105
+ // A peer is ready to receive ICE candidates when local and remote description were set.
3106
+ _readyForCandidates = new Trigger3();
3107
+ _offerProcessingMutex = new Mutex2();
3108
+ /**
3109
+ * Can't use peer.connection.initiator, because if two connections to the same peer are created in
3110
+ * different swarms, we might be the initiator of the first one, but not of the other one.
3111
+ * Use a stable peer keypair property (key ordering) to decide who's acting as the initiator of
3112
+ * transport connection establishment and data channel creation.
3113
+ */
3114
+ _initiator;
3115
+ _connection;
3348
3116
  constructor(_factory, _options) {
3349
3117
  this._factory = _factory;
3350
3118
  this._options = _options;
3351
- this._channelCreatedCallbacks = /* @__PURE__ */ new Map();
3352
- this._transportChannels = /* @__PURE__ */ new Map();
3353
- this._dataChannels = /* @__PURE__ */ new Map();
3354
- this._readyForCandidates = new Trigger3();
3355
- this._offerProcessingMutex = new Mutex2();
3356
3119
  this._initiator = chooseInitiatorPeer(_options.ownPeerKey, _options.remotePeerKey) === _options.ownPeerKey;
3357
3120
  }
3358
3121
  get transportChannelCount() {
@@ -3378,9 +3141,9 @@ var RtcPeerConnection = class {
3378
3141
  if (existingChannel) {
3379
3142
  return existingChannel;
3380
3143
  }
3381
- log13("waiting for initiator-peer to open a data channel", void 0, {
3382
- F: __dxlog_file14,
3383
- L: 95,
3144
+ log10("waiting for initiator-peer to open a data channel", void 0, {
3145
+ F: __dxlog_file11,
3146
+ L: 96,
3384
3147
  S: this,
3385
3148
  C: (f, a) => f(...a)
3386
3149
  });
@@ -3407,11 +3170,11 @@ var RtcPeerConnection = class {
3407
3170
  if (this._connection) {
3408
3171
  return this._connection;
3409
3172
  }
3410
- log13("initializing connection...", () => ({
3173
+ log10("initializing connection...", () => ({
3411
3174
  remotePeer: this._options.remotePeerKey
3412
3175
  }), {
3413
- F: __dxlog_file14,
3414
- L: 120,
3176
+ F: __dxlog_file11,
3177
+ L: 121,
3415
3178
  S: this,
3416
3179
  C: (f, a) => f(...a)
3417
3180
  });
@@ -3420,9 +3183,9 @@ var RtcPeerConnection = class {
3420
3183
  const iceCandidateErrors = [];
3421
3184
  Object.assign(connection, {
3422
3185
  onnegotiationneeded: async () => {
3423
- invariant12(this._initiator, void 0, {
3424
- F: __dxlog_file14,
3425
- L: 135,
3186
+ invariant10(this._initiator, void 0, {
3187
+ F: __dxlog_file11,
3188
+ L: 136,
3426
3189
  S: this,
3427
3190
  A: [
3428
3191
  "this._initiator",
@@ -3433,9 +3196,9 @@ var RtcPeerConnection = class {
3433
3196
  this._onConnectionCallbackAfterClose("onnegotiationneeded", connection);
3434
3197
  return;
3435
3198
  }
3436
- log13("onnegotiationneeded", void 0, {
3437
- F: __dxlog_file14,
3438
- L: 142,
3199
+ log10("onnegotiationneeded", void 0, {
3200
+ F: __dxlog_file11,
3201
+ L: 143,
3439
3202
  S: this,
3440
3203
  C: (f, a) => f(...a)
3441
3204
  });
@@ -3455,19 +3218,19 @@ var RtcPeerConnection = class {
3455
3218
  return;
3456
3219
  }
3457
3220
  if (event.candidate) {
3458
- log13("onicecandidate", {
3221
+ log10("onicecandidate", {
3459
3222
  candidate: event.candidate.candidate
3460
3223
  }, {
3461
- F: __dxlog_file14,
3462
- L: 161,
3224
+ F: __dxlog_file11,
3225
+ L: 162,
3463
3226
  S: this,
3464
3227
  C: (f, a) => f(...a)
3465
3228
  });
3466
3229
  await this._sendIceCandidate(event.candidate);
3467
3230
  } else {
3468
- log13("onicecandidate gathering complete", void 0, {
3469
- F: __dxlog_file14,
3470
- L: 164,
3231
+ log10("onicecandidate gathering complete", void 0, {
3232
+ F: __dxlog_file11,
3233
+ L: 165,
3471
3234
  S: this,
3472
3235
  C: (f, a) => f(...a)
3473
3236
  });
@@ -3491,11 +3254,11 @@ var RtcPeerConnection = class {
3491
3254
  this._onConnectionCallbackAfterClose("oniceconnectionstatechange", connection);
3492
3255
  return;
3493
3256
  }
3494
- log13("oniceconnectionstatechange", {
3257
+ log10("oniceconnectionstatechange", {
3495
3258
  state: connection.iceConnectionState
3496
3259
  }, {
3497
- F: __dxlog_file14,
3498
- L: 184,
3260
+ F: __dxlog_file11,
3261
+ L: 185,
3499
3262
  S: this,
3500
3263
  C: (f, a) => f(...a)
3501
3264
  });
@@ -3513,11 +3276,11 @@ var RtcPeerConnection = class {
3513
3276
  }
3514
3277
  return;
3515
3278
  }
3516
- log13("onconnectionstatechange", {
3279
+ log10("onconnectionstatechange", {
3517
3280
  state: connection.connectionState
3518
3281
  }, {
3519
- F: __dxlog_file14,
3520
- L: 201,
3282
+ F: __dxlog_file11,
3283
+ L: 202,
3521
3284
  S: this,
3522
3285
  C: (f, a) => f(...a)
3523
3286
  });
@@ -3526,11 +3289,11 @@ var RtcPeerConnection = class {
3526
3289
  }
3527
3290
  },
3528
3291
  onsignalingstatechange: () => {
3529
- log13("onsignalingstatechange", {
3292
+ log10("onsignalingstatechange", {
3530
3293
  state: connection.signalingState
3531
3294
  }, {
3532
- F: __dxlog_file14,
3533
- L: 208,
3295
+ F: __dxlog_file11,
3296
+ L: 209,
3534
3297
  S: this,
3535
3298
  C: (f, a) => f(...a)
3536
3299
  });
@@ -3538,9 +3301,9 @@ var RtcPeerConnection = class {
3538
3301
  // When channel is added to connection.
3539
3302
  // https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/datachannel_event
3540
3303
  ondatachannel: (event) => {
3541
- invariant12(!this._initiator, "Initiator is expected to create data channels.", {
3542
- F: __dxlog_file14,
3543
- L: 214,
3304
+ invariant10(!this._initiator, "Initiator is expected to create data channels.", {
3305
+ F: __dxlog_file11,
3306
+ L: 215,
3544
3307
  S: this,
3545
3308
  A: [
3546
3309
  "!this._initiator",
@@ -3551,11 +3314,11 @@ var RtcPeerConnection = class {
3551
3314
  this._onConnectionCallbackAfterClose("ondatachannel", connection);
3552
3315
  return;
3553
3316
  }
3554
- log13("ondatachannel", {
3317
+ log10("ondatachannel", {
3555
3318
  label: event.channel.label
3556
3319
  }, {
3557
- F: __dxlog_file14,
3558
- L: 221,
3320
+ F: __dxlog_file11,
3321
+ L: 222,
3559
3322
  S: this,
3560
3323
  C: (f, a) => f(...a)
3561
3324
  });
@@ -3579,11 +3342,11 @@ var RtcPeerConnection = class {
3579
3342
  }
3580
3343
  _abortConnection(connection, error) {
3581
3344
  if (connection !== this._connection) {
3582
- log13.error("attempted to abort an inactive connection", {
3345
+ log10.error("attempted to abort an inactive connection", {
3583
3346
  error
3584
3347
  }, {
3585
- F: __dxlog_file14,
3586
- L: 246,
3348
+ F: __dxlog_file11,
3349
+ L: 247,
3587
3350
  S: this,
3588
3351
  C: (f, a) => f(...a)
3589
3352
  });
@@ -3600,19 +3363,19 @@ var RtcPeerConnection = class {
3600
3363
  }
3601
3364
  this._transportChannels.clear();
3602
3365
  this._safeCloseConnection();
3603
- log13("connection aborted", {
3366
+ log10("connection aborted", {
3604
3367
  reason: error.message
3605
3368
  }, {
3606
- F: __dxlog_file14,
3607
- L: 260,
3369
+ F: __dxlog_file11,
3370
+ L: 261,
3608
3371
  S: this,
3609
3372
  C: (f, a) => f(...a)
3610
3373
  });
3611
3374
  }
3612
3375
  async _lockAndCloseConnection() {
3613
- invariant12(this._transportChannels.size === 0, void 0, {
3614
- F: __dxlog_file14,
3615
- L: 265,
3376
+ invariant10(this._transportChannels.size === 0, void 0, {
3377
+ F: __dxlog_file11,
3378
+ L: 266,
3616
3379
  S: this,
3617
3380
  A: [
3618
3381
  "this._transportChannels.size === 0",
@@ -3621,9 +3384,9 @@ var RtcPeerConnection = class {
3621
3384
  });
3622
3385
  if (this._connection) {
3623
3386
  this._safeCloseConnection();
3624
- log13("connection closed", void 0, {
3625
- F: __dxlog_file14,
3626
- L: 268,
3387
+ log10("connection closed", void 0, {
3388
+ F: __dxlog_file11,
3389
+ L: 269,
3627
3390
  S: this,
3628
3391
  C: (f, a) => f(...a)
3629
3392
  });
@@ -3632,11 +3395,11 @@ var RtcPeerConnection = class {
3632
3395
  async onSignal(signal) {
3633
3396
  const connection = this._connection;
3634
3397
  if (!connection) {
3635
- log13.warn("a signal ignored because the connection was closed", {
3398
+ log10.warn("a signal ignored because the connection was closed", {
3636
3399
  type: signal.payload.data.type
3637
3400
  }, {
3638
- F: __dxlog_file14,
3639
- L: 276,
3401
+ F: __dxlog_file11,
3402
+ L: 277,
3640
3403
  S: this,
3641
3404
  C: (f, a) => f(...a)
3642
3405
  });
@@ -3699,11 +3462,11 @@ var RtcPeerConnection = class {
3699
3462
  this._abortConnection(connection, new Error(`Unknown signal type ${data.type}.`));
3700
3463
  break;
3701
3464
  }
3702
- log13("signal processed", {
3465
+ log10("signal processed", {
3703
3466
  type: data.type
3704
3467
  }, {
3705
- F: __dxlog_file14,
3706
- L: 335,
3468
+ F: __dxlog_file11,
3469
+ L: 336,
3707
3470
  S: this,
3708
3471
  C: (f, a) => f(...a)
3709
3472
  });
@@ -3712,20 +3475,20 @@ var RtcPeerConnection = class {
3712
3475
  try {
3713
3476
  await this._readyForCandidates.wait();
3714
3477
  if (connection === this._connection) {
3715
- log13("adding ice candidate", {
3478
+ log10("adding ice candidate", {
3716
3479
  candidate
3717
3480
  }, {
3718
- F: __dxlog_file14,
3719
- L: 343,
3481
+ F: __dxlog_file11,
3482
+ L: 344,
3720
3483
  S: this,
3721
3484
  C: (f, a) => f(...a)
3722
3485
  });
3723
3486
  await connection.addIceCandidate(candidate);
3724
3487
  }
3725
3488
  } catch (err) {
3726
- log13.catch(err, void 0, {
3727
- F: __dxlog_file14,
3728
- L: 347,
3489
+ log10.catch(err, void 0, {
3490
+ F: __dxlog_file11,
3491
+ L: 348,
3729
3492
  S: this,
3730
3493
  C: (f, a) => f(...a)
3731
3494
  });
@@ -3733,29 +3496,29 @@ var RtcPeerConnection = class {
3733
3496
  }
3734
3497
  _onSessionNegotiated(connection) {
3735
3498
  if (connection === this._connection) {
3736
- log13("ready to process ice candidates", void 0, {
3737
- F: __dxlog_file14,
3738
- L: 353,
3499
+ log10("ready to process ice candidates", void 0, {
3500
+ F: __dxlog_file11,
3501
+ L: 354,
3739
3502
  S: this,
3740
3503
  C: (f, a) => f(...a)
3741
3504
  });
3742
3505
  this._readyForCandidates.wake();
3743
3506
  } else {
3744
- log13.warn("session was negotiated after connection became inactive", void 0, {
3745
- F: __dxlog_file14,
3746
- L: 356,
3507
+ log10.warn("session was negotiated after connection became inactive", void 0, {
3508
+ F: __dxlog_file11,
3509
+ L: 357,
3747
3510
  S: this,
3748
3511
  C: (f, a) => f(...a)
3749
3512
  });
3750
3513
  }
3751
3514
  }
3752
3515
  _onConnectionCallbackAfterClose(callback, connection) {
3753
- log13.warn("callback invoked after a connection was destroyed, this is probably a bug", {
3516
+ log10.warn("callback invoked after a connection was destroyed, this is probably a bug", {
3754
3517
  callback,
3755
3518
  state: connection.connectionState
3756
3519
  }, {
3757
- F: __dxlog_file14,
3758
- L: 361,
3520
+ F: __dxlog_file11,
3521
+ L: 362,
3759
3522
  S: this,
3760
3523
  C: (f, a) => f(...a)
3761
3524
  });
@@ -3766,9 +3529,9 @@ var RtcPeerConnection = class {
3766
3529
  try {
3767
3530
  connection?.close();
3768
3531
  } catch (err) {
3769
- log13.catch(err, void 0, {
3770
- F: __dxlog_file14,
3771
- L: 373,
3532
+ log10.catch(err, void 0, {
3533
+ F: __dxlog_file11,
3534
+ L: 374,
3772
3535
  S: this,
3773
3536
  C: (f, a) => f(...a)
3774
3537
  });
@@ -3777,9 +3540,9 @@ var RtcPeerConnection = class {
3777
3540
  this._connection = void 0;
3778
3541
  this._dataChannels.clear();
3779
3542
  this._readyForCandidates.wake();
3780
- void this._factory.onConnectionDestroyed().catch((err) => log13.catch(err, void 0, {
3781
- F: __dxlog_file14,
3782
- L: 379,
3543
+ void this._factory.onConnectionDestroyed().catch((err) => log10.catch(err, void 0, {
3544
+ F: __dxlog_file11,
3545
+ L: 380,
3783
3546
  S: this,
3784
3547
  C: (f, a) => f(...a)
3785
3548
  }));
@@ -3802,9 +3565,9 @@ var RtcPeerConnection = class {
3802
3565
  ];
3803
3566
  }
3804
3567
  } catch (error) {
3805
- log13.catch(error, void 0, {
3806
- F: __dxlog_file14,
3807
- L: 395,
3568
+ log10.catch(error, void 0, {
3569
+ F: __dxlog_file11,
3570
+ L: 396,
3808
3571
  S: this,
3809
3572
  C: (f, a) => f(...a)
3810
3573
  });
@@ -3827,11 +3590,11 @@ var RtcPeerConnection = class {
3827
3590
  }
3828
3591
  });
3829
3592
  } catch (err) {
3830
- log13.warn("signaling error", {
3593
+ log10.warn("signaling error", {
3831
3594
  err
3832
3595
  }, {
3833
- F: __dxlog_file14,
3834
- L: 416,
3596
+ F: __dxlog_file11,
3597
+ L: 417,
3835
3598
  S: this,
3836
3599
  C: (f, a) => f(...a)
3837
3600
  });
@@ -3908,11 +3671,13 @@ var isRemoteDescriptionSet = (connection, data) => {
3908
3671
  };
3909
3672
  var createIceFailureError = (details) => {
3910
3673
  const candidateErrors = details.map(({ url, errorCode, errorText }) => `${errorCode} ${url}: ${errorText}`);
3911
- return new ConnectivityError3(`ICE failed:
3912
- ${candidateErrors.join("\n")}`);
3674
+ return new ConnectivityError3({
3675
+ message: `ICE failed:
3676
+ ${candidateErrors.join("\n")}`
3677
+ });
3913
3678
  };
3914
3679
 
3915
- // packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-factory.ts
3680
+ // src/transport/webrtc/rtc-transport-factory.ts
3916
3681
  var createRtcTransportFactory = (webrtcConfig, iceProvider) => {
3917
3682
  const connectionFactory = getRtcConnectionFactory();
3918
3683
  return {
@@ -3930,24 +3695,30 @@ var createRtcTransportFactory = (webrtcConfig, iceProvider) => {
3930
3695
  };
3931
3696
  };
3932
3697
 
3933
- // packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-proxy.ts
3698
+ // src/transport/webrtc/rtc-transport-proxy.ts
3934
3699
  import { Writable } from "@dxos/node-std/stream";
3935
3700
  import { Event as Event8, scheduleTask as scheduleTask4 } from "@dxos/async";
3936
3701
  import { Resource as Resource2 } from "@dxos/context";
3937
3702
  import { ErrorStream as ErrorStream5 } from "@dxos/debug";
3938
- import { invariant as invariant13 } from "@dxos/invariant";
3703
+ import { invariant as invariant11 } from "@dxos/invariant";
3939
3704
  import { PublicKey as PublicKey10 } from "@dxos/keys";
3940
- import { log as log14 } from "@dxos/log";
3705
+ import { log as log11 } from "@dxos/log";
3941
3706
  import { ConnectionResetError as ConnectionResetError2, ConnectivityError as ConnectivityError4, TimeoutError as TimeoutError3 } from "@dxos/protocols";
3942
3707
  import { ConnectionState as ConnectionState3 } from "@dxos/protocols/proto/dxos/mesh/bridge";
3943
3708
  import { arrayToBuffer } from "@dxos/util";
3944
- var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-proxy.ts";
3709
+ var __dxlog_file12 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-proxy.ts";
3945
3710
  var RPC_TIMEOUT = 1e4;
3946
3711
  var CLOSE_RPC_TIMEOUT = 3e3;
3947
3712
  var RESP_MIN_THRESHOLD = 500;
3948
3713
  var RtcTransportProxy = class extends Resource2 {
3714
+ _options;
3715
+ _proxyId = PublicKey10.random();
3716
+ closed = new Event8();
3717
+ connected = new Event8();
3718
+ errors = new ErrorStream5();
3719
+ _serviceStream;
3949
3720
  constructor(_options) {
3950
- super(), this._options = _options, this._proxyId = PublicKey10.random(), this.closed = new Event8(), this.connected = new Event8(), this.errors = new ErrorStream5();
3721
+ super(), this._options = _options;
3951
3722
  }
3952
3723
  async _open() {
3953
3724
  let stream;
@@ -3968,8 +3739,8 @@ var RtcTransportProxy = class extends Resource2 {
3968
3739
  this._serviceStream = stream;
3969
3740
  stream.waitUntilReady().then(() => {
3970
3741
  stream.subscribe(async (event) => {
3971
- log14("rtc transport proxy event", event, {
3972
- F: __dxlog_file15,
3742
+ log11("rtc transport proxy event", event, {
3743
+ F: __dxlog_file12,
3973
3744
  L: 66,
3974
3745
  S: this,
3975
3746
  C: (f, a) => f(...a)
@@ -3982,10 +3753,10 @@ var RtcTransportProxy = class extends Resource2 {
3982
3753
  await this._handleSignal(event.signal);
3983
3754
  }
3984
3755
  }, (err) => {
3985
- log14("rtc bridge stream closed", {
3756
+ log11("rtc bridge stream closed", {
3986
3757
  err
3987
3758
  }, {
3988
- F: __dxlog_file15,
3759
+ F: __dxlog_file12,
3989
3760
  L: 76,
3990
3761
  S: this,
3991
3762
  C: (f, a) => f(...a)
@@ -4006,8 +3777,8 @@ var RtcTransportProxy = class extends Resource2 {
4006
3777
  timeout: RPC_TIMEOUT
4007
3778
  }).then(() => {
4008
3779
  if (Date.now() - sendStartMs > RESP_MIN_THRESHOLD) {
4009
- log14("slow response, delaying callback", void 0, {
4010
- F: __dxlog_file15,
3780
+ log11("slow response, delaying callback", void 0, {
3781
+ F: __dxlog_file12,
4011
3782
  L: 93,
4012
3783
  S: this,
4013
3784
  C: (f, a) => f(...a)
@@ -4039,8 +3810,8 @@ var RtcTransportProxy = class extends Resource2 {
4039
3810
  await this._serviceStream?.close();
4040
3811
  this._serviceStream = void 0;
4041
3812
  } catch (err) {
4042
- log14.catch(err, void 0, {
4043
- F: __dxlog_file15,
3813
+ log11.catch(err, void 0, {
3814
+ F: __dxlog_file12,
4044
3815
  L: 128,
4045
3816
  S: this,
4046
3817
  C: (f, a) => f(...a)
@@ -4053,8 +3824,8 @@ var RtcTransportProxy = class extends Resource2 {
4053
3824
  timeout: CLOSE_RPC_TIMEOUT
4054
3825
  });
4055
3826
  } catch (err) {
4056
- log14.catch(err, void 0, {
4057
- F: __dxlog_file15,
3827
+ log11.catch(err, void 0, {
3828
+ F: __dxlog_file12,
4058
3829
  L: 134,
4059
3830
  S: this,
4060
3831
  C: (f, a) => f(...a)
@@ -4099,7 +3870,9 @@ var RtcTransportProxy = class extends Resource2 {
4099
3870
  } catch (error) {
4100
3871
  const type = signalEvent.payload.payload.data?.type;
4101
3872
  if (type === "offer" || type === "answer") {
4102
- this._raiseIfOpen(new ConnectivityError4(`Session establishment failed: ${type} couldn't be sent.`));
3873
+ this._raiseIfOpen(new ConnectivityError4({
3874
+ message: `Session establishment failed: ${type} couldn't be sent.`
3875
+ }));
4103
3876
  }
4104
3877
  }
4105
3878
  }
@@ -4137,11 +3910,11 @@ var RtcTransportProxy = class extends Resource2 {
4137
3910
  if (this.isOpen) {
4138
3911
  this.errors.raise(error);
4139
3912
  } else {
4140
- log14.info("error swallowed because transport was closed", {
3913
+ log11.info("error swallowed because transport was closed", {
4141
3914
  message: error.message
4142
3915
  }, {
4143
- F: __dxlog_file15,
4144
- L: 215,
3916
+ F: __dxlog_file12,
3917
+ L: 217,
4145
3918
  S: this,
4146
3919
  C: (f, a) => f(...a)
4147
3920
  });
@@ -4156,9 +3929,8 @@ var RtcTransportProxy = class extends Resource2 {
4156
3929
  }
4157
3930
  };
4158
3931
  var RtcTransportProxyFactory = class {
4159
- constructor() {
4160
- this._connections = /* @__PURE__ */ new Set();
4161
- }
3932
+ _bridgeService;
3933
+ _connections = /* @__PURE__ */ new Set();
4162
3934
  /**
4163
3935
  * Sets the current BridgeService to be used to open connections.
4164
3936
  * Calling this method will close any existing connections.
@@ -4171,9 +3943,9 @@ var RtcTransportProxyFactory = class {
4171
3943
  return this;
4172
3944
  }
4173
3945
  createTransport(options) {
4174
- invariant13(this._bridgeService, "RtcTransportProxyFactory is not ready to open connections", {
4175
- F: __dxlog_file15,
4176
- L: 245,
3946
+ invariant11(this._bridgeService, "RtcTransportProxyFactory is not ready to open connections", {
3947
+ F: __dxlog_file12,
3948
+ L: 247,
4177
3949
  S: this,
4178
3950
  A: [
4179
3951
  "this._bridgeService",
@@ -4194,29 +3966,36 @@ var RtcTransportProxyFactory = class {
4194
3966
  var decodeError = (err) => {
4195
3967
  const message = typeof err === "string" ? err : err.message;
4196
3968
  if (message.includes("CONNECTION_RESET")) {
4197
- return new ConnectionResetError2(message);
3969
+ return new ConnectionResetError2({
3970
+ message
3971
+ });
4198
3972
  } else if (message.includes("TIMEOUT")) {
4199
- return new TimeoutError3(message);
3973
+ return new TimeoutError3({
3974
+ message
3975
+ });
4200
3976
  } else if (message.includes("CONNECTIVITY_ERROR")) {
4201
- return new ConnectivityError4(message);
3977
+ return new ConnectivityError4({
3978
+ message
3979
+ });
4202
3980
  } else {
4203
3981
  return typeof err === "string" ? new Error(err) : err;
4204
3982
  }
4205
3983
  };
4206
3984
 
4207
- // packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-service.ts
3985
+ // src/transport/webrtc/rtc-transport-service.ts
4208
3986
  import { Duplex as Duplex2 } from "@dxos/node-std/stream";
4209
3987
  import { Stream } from "@dxos/codec-protobuf/stream";
4210
- import { invariant as invariant14 } from "@dxos/invariant";
3988
+ import { invariant as invariant12 } from "@dxos/invariant";
4211
3989
  import { PublicKey as PublicKey11 } from "@dxos/keys";
4212
- import { log as log15 } from "@dxos/log";
3990
+ import { log as log12 } from "@dxos/log";
4213
3991
  import { ConnectionState as ConnectionState4 } from "@dxos/protocols/proto/dxos/mesh/bridge";
4214
3992
  import { ComplexMap as ComplexMap8 } from "@dxos/util";
4215
- var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-service.ts";
3993
+ var __dxlog_file13 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-service.ts";
4216
3994
  var RtcTransportService = class {
3995
+ _transportFactory;
3996
+ _openTransports = new ComplexMap8(PublicKey11.hash);
4217
3997
  constructor(webrtcConfig, iceProvider, _transportFactory = createRtcTransportFactory(webrtcConfig, iceProvider)) {
4218
3998
  this._transportFactory = _transportFactory;
4219
- this._openTransports = new ComplexMap8(PublicKey11.hash);
4220
3999
  }
4221
4000
  hasOpenTransports() {
4222
4001
  return this._openTransports.size > 0;
@@ -4224,9 +4003,9 @@ var RtcTransportService = class {
4224
4003
  open(request) {
4225
4004
  const existingTransport = this._openTransports.get(request.proxyId);
4226
4005
  if (existingTransport) {
4227
- log15.error("requesting a new transport bridge for an existing proxy", void 0, {
4228
- F: __dxlog_file16,
4229
- L: 53,
4006
+ log12.error("requesting a new transport bridge for an existing proxy", void 0, {
4007
+ F: __dxlog_file13,
4008
+ L: 54,
4230
4009
  S: this,
4231
4010
  C: (f, a) => f(...a)
4232
4011
  });
@@ -4290,9 +4069,9 @@ var RtcTransportService = class {
4290
4069
  close(err);
4291
4070
  });
4292
4071
  ready();
4293
- log15("stream ready", void 0, {
4294
- F: __dxlog_file16,
4295
- L: 115,
4072
+ log12("stream ready", void 0, {
4073
+ F: __dxlog_file13,
4074
+ L: 116,
4296
4075
  S: this,
4297
4076
  C: (f, a) => f(...a)
4298
4077
  });
@@ -4301,9 +4080,9 @@ var RtcTransportService = class {
4301
4080
  }
4302
4081
  async sendSignal({ proxyId, signal }) {
4303
4082
  const transport = this._openTransports.get(proxyId);
4304
- invariant14(transport, void 0, {
4305
- F: __dxlog_file16,
4306
- L: 123,
4083
+ invariant12(transport, void 0, {
4084
+ F: __dxlog_file13,
4085
+ L: 124,
4307
4086
  S: this,
4308
4087
  A: [
4309
4088
  "transport",
@@ -4314,9 +4093,9 @@ var RtcTransportService = class {
4314
4093
  }
4315
4094
  async getDetails({ proxyId }) {
4316
4095
  const transport = this._openTransports.get(proxyId);
4317
- invariant14(transport, void 0, {
4318
- F: __dxlog_file16,
4319
- L: 130,
4096
+ invariant12(transport, void 0, {
4097
+ F: __dxlog_file13,
4098
+ L: 131,
4320
4099
  S: this,
4321
4100
  A: [
4322
4101
  "transport",
@@ -4329,9 +4108,9 @@ var RtcTransportService = class {
4329
4108
  }
4330
4109
  async getStats({ proxyId }) {
4331
4110
  const transport = this._openTransports.get(proxyId);
4332
- invariant14(transport, void 0, {
4333
- F: __dxlog_file16,
4334
- L: 137,
4111
+ invariant12(transport, void 0, {
4112
+ F: __dxlog_file13,
4113
+ L: 138,
4335
4114
  S: this,
4336
4115
  A: [
4337
4116
  "transport",
@@ -4344,9 +4123,9 @@ var RtcTransportService = class {
4344
4123
  }
4345
4124
  async sendData({ proxyId, payload }) {
4346
4125
  const transport = this._openTransports.get(proxyId);
4347
- invariant14(transport, void 0, {
4348
- F: __dxlog_file16,
4349
- L: 144,
4126
+ invariant12(transport, void 0, {
4127
+ F: __dxlog_file13,
4128
+ L: 145,
4350
4129
  S: this,
4351
4130
  A: [
4352
4131
  "transport",
@@ -4376,11 +4155,11 @@ var RtcTransportService = class {
4376
4155
  try {
4377
4156
  await transport.transport.close();
4378
4157
  } catch (error) {
4379
- log15.warn("transport close error", {
4158
+ log12.warn("transport close error", {
4380
4159
  message: error?.message
4381
4160
  }, {
4382
- F: __dxlog_file16,
4383
- L: 174,
4161
+ F: __dxlog_file13,
4162
+ L: 175,
4384
4163
  S: this,
4385
4164
  C: (f, a) => f(...a)
4386
4165
  });
@@ -4388,18 +4167,18 @@ var RtcTransportService = class {
4388
4167
  try {
4389
4168
  transport.connectorStream.end();
4390
4169
  } catch (error) {
4391
- log15.warn("connectorStream close error", {
4170
+ log12.warn("connectorStream close error", {
4392
4171
  message: error?.message
4393
4172
  }, {
4394
- F: __dxlog_file16,
4395
- L: 179,
4173
+ F: __dxlog_file13,
4174
+ L: 180,
4396
4175
  S: this,
4397
4176
  C: (f, a) => f(...a)
4398
4177
  });
4399
4178
  }
4400
- log15("closed", void 0, {
4401
- F: __dxlog_file16,
4402
- L: 181,
4179
+ log12("closed", void 0, {
4180
+ F: __dxlog_file13,
4181
+ L: 182,
4403
4182
  S: this,
4404
4183
  C: (f, a) => f(...a)
4405
4184
  });
@@ -4418,12 +4197,12 @@ var createStateUpdater = (next) => {
4418
4197
  };
4419
4198
  };
4420
4199
 
4421
- // packages/core/mesh/network-manager/src/wire-protocol.ts
4200
+ // src/wire-protocol.ts
4422
4201
  import { Teleport } from "@dxos/teleport";
4423
- var createTeleportProtocolFactory = (onConnection, defaultParams) => {
4202
+ var createTeleportProtocolFactory = (onConnection, defaultProps) => {
4424
4203
  return (params) => {
4425
4204
  const teleport = new Teleport({
4426
- ...defaultParams,
4205
+ ...defaultProps,
4427
4206
  ...params
4428
4207
  });
4429
4208
  return {
@@ -4445,7 +4224,6 @@ var createTeleportProtocolFactory = (onConnection, defaultParams) => {
4445
4224
  export {
4446
4225
  ConnectionState,
4447
4226
  Connection,
4448
- createIceProvider,
4449
4227
  SwarmMessenger,
4450
4228
  Swarm,
4451
4229
  SwarmMapper,
@@ -4455,8 +4233,6 @@ export {
4455
4233
  ConnectionLog,
4456
4234
  SwarmNetworkManager,
4457
4235
  FullyConnectedTopology,
4458
- MMSTTopology,
4459
- StarTopology,
4460
4236
  MemoryTransportFactory,
4461
4237
  MemoryTransport,
4462
4238
  TransportKind,
@@ -4466,4 +4242,4 @@ export {
4466
4242
  RtcTransportService,
4467
4243
  createTeleportProtocolFactory
4468
4244
  };
4469
- //# sourceMappingURL=chunk-LFKR6BAF.mjs.map
4245
+ //# sourceMappingURL=chunk-AQSYW43M.mjs.map