@dxos/network-manager 0.1.57 → 0.1.58-main.0009f6a

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 (56) hide show
  1. package/dist/lib/browser/{chunk-UKMTAO4L.mjs → chunk-26KK6XOP.mjs} +266 -140
  2. package/dist/lib/browser/chunk-26KK6XOP.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +1 -1
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/testing/index.mjs +10 -7
  6. package/dist/lib/browser/testing/index.mjs.map +3 -3
  7. package/dist/lib/node/index.cjs +837 -577
  8. package/dist/lib/node/index.cjs.map +4 -4
  9. package/dist/lib/node/meta.json +1 -1
  10. package/dist/lib/node/testing/index.cjs +1125 -865
  11. package/dist/lib/node/testing/index.cjs.map +4 -4
  12. package/dist/types/src/swarm/connection-limiter.d.ts +1 -1
  13. package/dist/types/src/swarm/connection-limiter.d.ts.map +1 -1
  14. package/dist/types/src/swarm/connection.d.ts +3 -1
  15. package/dist/types/src/swarm/connection.d.ts.map +1 -1
  16. package/dist/types/src/swarm/peer.d.ts +3 -3
  17. package/dist/types/src/swarm/peer.d.ts.map +1 -1
  18. package/dist/types/src/swarm/swarm-mapper.d.ts.map +1 -1
  19. package/dist/types/src/swarm/swarm.d.ts +2 -2
  20. package/dist/types/src/swarm/swarm.d.ts.map +1 -1
  21. package/dist/types/src/testing/test-builder.d.ts +1 -1
  22. package/dist/types/src/testing/test-builder.d.ts.map +1 -1
  23. package/dist/types/src/tests/basic-test-suite.d.ts.map +1 -1
  24. package/dist/types/src/tests/tcp-transport.test.d.ts +2 -0
  25. package/dist/types/src/tests/tcp-transport.test.d.ts.map +1 -0
  26. package/dist/types/src/topology/star-topology.d.ts.map +1 -1
  27. package/dist/types/src/transport/index.d.ts +1 -0
  28. package/dist/types/src/transport/index.d.ts.map +1 -1
  29. package/dist/types/src/transport/simplepeer-transport-proxy.d.ts.map +1 -1
  30. package/dist/types/src/transport/simplepeer-transport-service.d.ts.map +1 -1
  31. package/dist/types/src/transport/simplepeer-transport.d.ts.map +1 -1
  32. package/dist/types/src/transport/tcp-transport.d.ts +23 -0
  33. package/dist/types/src/transport/tcp-transport.d.ts.map +1 -0
  34. package/dist/types/src/transport/transport.d.ts +2 -1
  35. package/dist/types/src/transport/transport.d.ts.map +1 -1
  36. package/package.json +18 -18
  37. package/src/swarm/connection-limiter.ts +2 -2
  38. package/src/swarm/connection.test.ts +1 -1
  39. package/src/swarm/connection.ts +54 -27
  40. package/src/swarm/peer.ts +11 -3
  41. package/src/swarm/swarm-mapper.ts +4 -7
  42. package/src/swarm/swarm.test.ts +3 -3
  43. package/src/swarm/swarm.ts +3 -3
  44. package/src/testing/test-builder.ts +6 -2
  45. package/src/tests/basic-test-suite.ts +1 -1
  46. package/src/tests/memory-transport.test.ts +2 -2
  47. package/src/tests/tcp-transport.test.ts +67 -0
  48. package/src/tests/webrtc-transport.test.ts +1 -1
  49. package/src/topology/star-topology.ts +1 -4
  50. package/src/transport/index.ts +1 -0
  51. package/src/transport/simplepeer-transport-proxy.ts +48 -21
  52. package/src/transport/simplepeer-transport-service.ts +9 -5
  53. package/src/transport/simplepeer-transport.ts +43 -4
  54. package/src/transport/tcp-transport.ts +107 -0
  55. package/src/transport/transport.ts +1 -0
  56. package/dist/lib/browser/chunk-UKMTAO4L.mjs.map +0 -7
@@ -7,11 +7,10 @@ import {
7
7
  import { DeferredTask, Event, sleep, synchronized } from "@dxos/async";
8
8
  import { Context, cancelWithContext } from "@dxos/context";
9
9
  import { ErrorStream } from "@dxos/debug";
10
- import { CancelledError } from "@dxos/errors";
11
10
  import { invariant } from "@dxos/invariant";
12
11
  import { PublicKey } from "@dxos/keys";
13
12
  import { log } from "@dxos/log";
14
- import { trace } from "@dxos/protocols";
13
+ import { CancelledError, ProtocolError, ConnectionResetError, ConnectivityError, UnknownProtocolError, trace } from "@dxos/protocols";
15
14
  function _ts_decorate(decorators, target, key, desc) {
16
15
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
17
16
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -22,7 +21,7 @@ function _ts_decorate(decorators, target, key, desc) {
22
21
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
23
22
  return c > 3 && r && Object.defineProperty(target, key, r), r;
24
23
  }
25
- var __dxlog_file = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/connection.ts";
24
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts";
26
25
  var STARTING_SIGNALLING_DELAY = 10;
27
26
  var MAX_SIGNALLING_DELAY = 300;
28
27
  var ConnectionState;
@@ -64,6 +63,8 @@ var ConnectionState;
64
63
  */
65
64
  "CLOSED"
66
65
  ] = "CLOSED";
66
+ ConnectionState5["ABORTING"] = "ABORTING";
67
+ ConnectionState5["ABORTED"] = "ABORTED";
67
68
  })(ConnectionState || (ConnectionState = {}));
68
69
  var Connection = class {
69
70
  constructor(topic, ownId, remoteId, sessionId, initiator, _signalMessaging, _protocol, _transportFactory, _callbacks) {
@@ -95,7 +96,7 @@ var Connection = class {
95
96
  initiator: this.initiator
96
97
  }, {
97
98
  F: __dxlog_file,
98
- L: 114,
99
+ L: 123,
99
100
  S: this,
100
101
  C: (f, a) => f(...a)
101
102
  });
@@ -115,7 +116,7 @@ var Connection = class {
115
116
  async openConnection() {
116
117
  invariant(this._state === ConnectionState.INITIAL, "Invalid state.", {
117
118
  F: __dxlog_file,
118
- L: 139,
119
+ L: 148,
119
120
  S: this,
120
121
  A: [
121
122
  "this._state === ConnectionState.INITIAL",
@@ -126,7 +127,7 @@ var Connection = class {
126
127
  id: this._instanceId
127
128
  }), {
128
129
  F: __dxlog_file,
129
- L: 140,
130
+ L: 149,
130
131
  S: this,
131
132
  C: (f, a) => f(...a)
132
133
  });
@@ -138,7 +139,7 @@ var Connection = class {
138
139
  initiator: this.initiator
139
140
  }, {
140
141
  F: __dxlog_file,
141
- L: 141,
142
+ L: 150,
142
143
  S: this,
143
144
  C: (f, a) => f(...a)
144
145
  });
@@ -149,15 +150,15 @@ var Connection = class {
149
150
  this._protocol.stream.on("close", () => {
150
151
  log("protocol stream closed", void 0, {
151
152
  F: __dxlog_file,
152
- L: 158,
153
+ L: 167,
153
154
  S: this,
154
155
  C: (f, a) => f(...a)
155
156
  });
156
- this.close().catch((err) => this.errors.raise(err));
157
+ this.close(new ProtocolError("protocol stream closed")).catch((err) => this.errors.raise(err));
157
158
  });
158
159
  invariant(!this._transport, void 0, {
159
160
  F: __dxlog_file,
160
- L: 162,
161
+ L: 171,
161
162
  S: this,
162
163
  A: [
163
164
  "!this._transport",
@@ -177,7 +178,7 @@ var Connection = class {
177
178
  this._transport = void 0;
178
179
  log("abort triggered by transport close", void 0, {
179
180
  F: __dxlog_file,
180
- L: 176,
181
+ L: 185,
181
182
  S: this,
182
183
  C: (f, a) => f(...a)
183
184
  });
@@ -188,21 +189,38 @@ var Connection = class {
188
189
  err
189
190
  }, {
190
191
  F: __dxlog_file,
191
- L: 181,
192
+ L: 190,
192
193
  S: this,
193
194
  C: (f, a) => f(...a)
194
195
  });
195
196
  if (!this.closeReason) {
196
197
  this.closeReason = err?.message;
197
198
  }
198
- if (err?.message.includes("OperationError")) {
199
- log("aborting due to transport OperationError", void 0, {
199
+ if (err instanceof ConnectionResetError) {
200
+ log.warn("aborting due to transport ConnectionResetError", void 0, {
201
+ F: __dxlog_file,
202
+ L: 197,
203
+ S: this,
204
+ C: (f, a) => f(...a)
205
+ });
206
+ this.abort().catch((err2) => this.errors.raise(err2));
207
+ } else if (err instanceof ConnectivityError) {
208
+ log.warn("aborting due to transport ConnectivityError", void 0, {
200
209
  F: __dxlog_file,
201
- L: 187,
210
+ L: 200,
202
211
  S: this,
203
212
  C: (f, a) => f(...a)
204
213
  });
205
214
  this.abort().catch((err2) => this.errors.raise(err2));
215
+ } else if (err instanceof UnknownProtocolError) {
216
+ log.warn("unsure what to do with UnknownProtocolError, will keep on truckin", {
217
+ err
218
+ }, {
219
+ F: __dxlog_file,
220
+ L: 203,
221
+ S: this,
222
+ C: (f, a) => f(...a)
223
+ });
206
224
  }
207
225
  if (this._state !== ConnectionState.CLOSED && this._state !== ConnectionState.CLOSING) {
208
226
  this.errors.raise(err);
@@ -216,7 +234,7 @@ var Connection = class {
216
234
  id: this._instanceId
217
235
  }), {
218
236
  F: __dxlog_file,
219
- L: 203,
237
+ L: 218,
220
238
  S: this,
221
239
  C: (f, a) => f(...a)
222
240
  });
@@ -226,30 +244,30 @@ var Connection = class {
226
244
  err
227
245
  }, {
228
246
  F: __dxlog_file,
229
- L: 209,
247
+ L: 225,
230
248
  S: this,
231
249
  C: (f, a) => f(...a)
232
250
  });
233
- if (!this.closeReason) {
234
- this.closeReason = err?.message;
235
- }
236
- if (this._state === ConnectionState.CLOSED) {
237
- log("abort ignored: already closed", this.closeReason, {
251
+ if (this._state === ConnectionState.CLOSED || this._state === ConnectionState.ABORTED) {
252
+ log(`abort ignored: already ${this._state}`, this.closeReason, {
238
253
  F: __dxlog_file,
239
- L: 214,
254
+ L: 227,
240
255
  S: this,
241
256
  C: (f, a) => f(...a)
242
257
  });
243
258
  return;
244
259
  }
245
- this._changeState(ConnectionState.CLOSING);
260
+ this._changeState(ConnectionState.ABORTING);
261
+ if (!this.closeReason) {
262
+ this.closeReason = err?.message;
263
+ }
246
264
  await this._ctx.dispose();
247
265
  try {
248
266
  log("aborting protocol... ", {
249
267
  proto: this._protocol
250
268
  }, {
251
269
  F: __dxlog_file,
252
- L: 224,
270
+ L: 240,
253
271
  S: this,
254
272
  C: (f, a) => f(...a)
255
273
  });
@@ -257,7 +275,7 @@ var Connection = class {
257
275
  } catch (err2) {
258
276
  log.catch(err2, void 0, {
259
277
  F: __dxlog_file,
260
- L: 227,
278
+ L: 243,
261
279
  S: this,
262
280
  C: (f, a) => f(...a)
263
281
  });
@@ -267,56 +285,68 @@ var Connection = class {
267
285
  } catch (err2) {
268
286
  log.catch(err2, void 0, {
269
287
  F: __dxlog_file,
270
- L: 234,
288
+ L: 250,
271
289
  S: this,
272
290
  C: (f, a) => f(...a)
273
291
  });
274
292
  }
275
- this._changeState(ConnectionState.CLOSED);
276
- this._callbacks?.onClosed?.(err);
293
+ try {
294
+ this._callbacks?.onClosed?.(err);
295
+ } catch (err2) {
296
+ log.catch(err2, void 0, {
297
+ F: __dxlog_file,
298
+ L: 256,
299
+ S: this,
300
+ C: (f, a) => f(...a)
301
+ });
302
+ }
303
+ this._changeState(ConnectionState.ABORTED);
277
304
  }
278
305
  async close(err) {
279
306
  if (!this.closeReason) {
280
307
  this.closeReason = err?.message;
281
308
  }
282
- if (this._state === ConnectionState.CLOSED) {
309
+ if (this._state === ConnectionState.CLOSED || this._state === ConnectionState.ABORTING || this._state === ConnectionState.ABORTED) {
283
310
  return;
284
311
  }
312
+ const lastState = this._state;
285
313
  this._changeState(ConnectionState.CLOSING);
286
314
  await this._ctx.dispose();
287
315
  log("closing...", {
288
316
  peerId: this.ownId
289
317
  }, {
290
318
  F: __dxlog_file,
291
- L: 253,
319
+ L: 278,
292
320
  S: this,
293
321
  C: (f, a) => f(...a)
294
322
  });
295
- try {
296
- await this._protocol.close();
297
- } catch (err2) {
298
- log.catch(err2, void 0, {
299
- F: __dxlog_file,
300
- L: 259,
301
- S: this,
302
- C: (f, a) => f(...a)
303
- });
304
- }
305
- try {
306
- await this._transport?.destroy();
307
- } catch (err2) {
308
- log.catch(err2, void 0, {
309
- F: __dxlog_file,
310
- L: 266,
311
- S: this,
312
- C: (f, a) => f(...a)
313
- });
323
+ if (lastState === ConnectionState.CONNECTED) {
324
+ try {
325
+ await this._protocol.close();
326
+ } catch (err2) {
327
+ log.catch(err2, void 0, {
328
+ F: __dxlog_file,
329
+ L: 285,
330
+ S: this,
331
+ C: (f, a) => f(...a)
332
+ });
333
+ }
334
+ try {
335
+ await this._transport?.destroy();
336
+ } catch (err2) {
337
+ log.catch(err2, void 0, {
338
+ F: __dxlog_file,
339
+ L: 292,
340
+ S: this,
341
+ C: (f, a) => f(...a)
342
+ });
343
+ }
314
344
  }
315
345
  log("closed", {
316
346
  peerId: this.ownId
317
347
  }, {
318
348
  F: __dxlog_file,
319
- L: 269,
349
+ L: 296,
320
350
  S: this,
321
351
  C: (f, a) => f(...a)
322
352
  });
@@ -359,7 +389,7 @@ var Connection = class {
359
389
  err
360
390
  }, {
361
391
  F: __dxlog_file,
362
- L: 306,
392
+ L: 333,
363
393
  S: this,
364
394
  C: (f, a) => f(...a)
365
395
  });
@@ -372,7 +402,7 @@ var Connection = class {
372
402
  async signal(msg) {
373
403
  invariant(msg.sessionId, void 0, {
374
404
  F: __dxlog_file,
375
- L: 315,
405
+ L: 342,
376
406
  S: this,
377
407
  A: [
378
408
  "msg.sessionId",
@@ -382,7 +412,7 @@ var Connection = class {
382
412
  if (!msg.sessionId.equals(this.sessionId)) {
383
413
  log("dropping signal for incorrect session id", void 0, {
384
414
  F: __dxlog_file,
385
- L: 317,
415
+ L: 344,
386
416
  S: this,
387
417
  C: (f, a) => f(...a)
388
418
  });
@@ -390,7 +420,7 @@ var Connection = class {
390
420
  }
391
421
  invariant(msg.data.signal || msg.data.signalBatch, void 0, {
392
422
  F: __dxlog_file,
393
- L: 320,
423
+ L: 347,
394
424
  S: this,
395
425
  A: [
396
426
  "msg.data.signal || msg.data.signalBatch",
@@ -399,7 +429,7 @@ var Connection = class {
399
429
  });
400
430
  invariant(msg.author?.equals(this.remoteId), void 0, {
401
431
  F: __dxlog_file,
402
- L: 321,
432
+ L: 348,
403
433
  S: this,
404
434
  A: [
405
435
  "msg.author?.equals(this.remoteId)",
@@ -408,7 +438,7 @@ var Connection = class {
408
438
  });
409
439
  invariant(msg.recipient?.equals(this.ownId), void 0, {
410
440
  F: __dxlog_file,
411
- L: 322,
441
+ L: 349,
412
442
  S: this,
413
443
  A: [
414
444
  "msg.recipient?.equals(this.ownId)",
@@ -432,7 +462,7 @@ var Connection = class {
432
462
  msg: msg.data
433
463
  }, {
434
464
  F: __dxlog_file,
435
- L: 331,
465
+ L: 358,
436
466
  S: this,
437
467
  C: (f, a) => f(...a)
438
468
  });
@@ -440,7 +470,7 @@ var Connection = class {
440
470
  } else {
441
471
  invariant(this._transport, "Connection not ready to accept signals.", {
442
472
  F: __dxlog_file,
443
- L: 334,
473
+ L: 361,
444
474
  S: this,
445
475
  A: [
446
476
  "this._transport",
@@ -453,7 +483,7 @@ var Connection = class {
453
483
  msg: msg.data
454
484
  }, {
455
485
  F: __dxlog_file,
456
- L: 335,
486
+ L: 362,
457
487
  S: this,
458
488
  C: (f, a) => f(...a)
459
489
  });
@@ -467,17 +497,17 @@ var Connection = class {
467
497
  _changeState(state) {
468
498
  log("stateChanged", {
469
499
  from: this._state,
470
- too: state,
500
+ to: state,
471
501
  peerId: this.ownId
472
502
  }, {
473
503
  F: __dxlog_file,
474
- L: 346,
504
+ L: 373,
475
505
  S: this,
476
506
  C: (f, a) => f(...a)
477
507
  });
478
508
  invariant(state !== this._state, "Already in this state.", {
479
509
  F: __dxlog_file,
480
- L: 347,
510
+ L: 374,
481
511
  S: this,
482
512
  A: [
483
513
  "state !== this._state",
@@ -502,7 +532,7 @@ import { PublicKey as PublicKey2 } from "@dxos/keys";
502
532
  import { log as log2 } from "@dxos/log";
503
533
  import { schema } from "@dxos/protocols";
504
534
  import { ComplexMap } from "@dxos/util";
505
- var __dxlog_file2 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
535
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
506
536
  var SwarmMessage = schema.getCodecForType("dxos.mesh.swarm.SwarmMessage");
507
537
  var SwarmMessenger = class {
508
538
  constructor({ sendMessage, onSignal, onOffer, topic }) {
@@ -740,10 +770,10 @@ import { ComplexMap as ComplexMap2, isNotNullOrUndefined } from "@dxos/util";
740
770
  // packages/core/mesh/network-manager/src/swarm/peer.ts
741
771
  import { Event as Event2, scheduleTask, synchronized as synchronized2 } from "@dxos/async";
742
772
  import { Context as Context3 } from "@dxos/context";
743
- import { CancelledError as CancelledError2, SystemError } from "@dxos/errors";
744
773
  import { invariant as invariant3 } from "@dxos/invariant";
745
774
  import { PublicKey as PublicKey3 } from "@dxos/keys";
746
775
  import { log as log3 } from "@dxos/log";
776
+ import { CancelledError as CancelledError2, SystemError, TimeoutError } from "@dxos/protocols";
747
777
  function _ts_decorate2(decorators, target, key, desc) {
748
778
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
749
779
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -754,7 +784,7 @@ function _ts_decorate2(decorators, target, key, desc) {
754
784
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
755
785
  return c > 3 && r && Object.defineProperty(target, key, r), r;
756
786
  }
757
- var __dxlog_file3 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/peer.ts";
787
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts";
758
788
  var ConnectionDisplacedError = class extends SystemError {
759
789
  constructor() {
760
790
  super("Connection displaced by remote initiator.");
@@ -784,6 +814,20 @@ var Peer = class {
784
814
  */
785
815
  async onOffer(message) {
786
816
  const remoteId = message.author;
817
+ if (this.connection && ![
818
+ ConnectionState.CREATED,
819
+ ConnectionState.INITIAL
820
+ ].includes(this.connection.state)) {
821
+ log3.info(`received offer when connection already in ${this.connection.state} state`, void 0, {
822
+ F: __dxlog_file3,
823
+ L: 112,
824
+ S: this,
825
+ C: (f, a) => f(...a)
826
+ });
827
+ return {
828
+ accept: false
829
+ };
830
+ }
787
831
  if (this.connection || this.initiating) {
788
832
  if (remoteId.toHex() < this.localPeerId.toHex()) {
789
833
  log3("close local connection", {
@@ -793,7 +837,7 @@ var Peer = class {
793
837
  sessionId: this.connection?.sessionId
794
838
  }, {
795
839
  F: __dxlog_file3,
796
- L: 117,
840
+ L: 121,
797
841
  S: this,
798
842
  C: (f, a) => f(...a)
799
843
  });
@@ -810,7 +854,7 @@ var Peer = class {
810
854
  if (!this.connection) {
811
855
  invariant3(message.sessionId, void 0, {
812
856
  F: __dxlog_file3,
813
- L: 137,
857
+ L: 141,
814
858
  S: this,
815
859
  A: [
816
860
  "message.sessionId",
@@ -831,7 +875,7 @@ var Peer = class {
831
875
  err
832
876
  }, {
833
877
  F: __dxlog_file3,
834
- L: 147,
878
+ L: 151,
835
879
  S: this,
836
880
  C: (f, a) => f(...a)
837
881
  });
@@ -853,7 +897,7 @@ var Peer = class {
853
897
  async initiateConnection() {
854
898
  invariant3(!this.initiating, "Initiation in progress.", {
855
899
  F: __dxlog_file3,
856
- L: 164,
900
+ L: 168,
857
901
  S: this,
858
902
  A: [
859
903
  "!this.initiating",
@@ -862,7 +906,7 @@ var Peer = class {
862
906
  });
863
907
  invariant3(!this.connection, "Already connected.", {
864
908
  F: __dxlog_file3,
865
- L: 165,
909
+ L: 169,
866
910
  S: this,
867
911
  A: [
868
912
  "!this.connection",
@@ -877,7 +921,7 @@ var Peer = class {
877
921
  sessionId
878
922
  }, {
879
923
  F: __dxlog_file3,
880
- L: 167,
924
+ L: 171,
881
925
  S: this,
882
926
  C: (f, a) => f(...a)
883
927
  });
@@ -902,14 +946,14 @@ var Peer = class {
902
946
  remoteId: this.id
903
947
  }, {
904
948
  F: __dxlog_file3,
905
- L: 183,
949
+ L: 187,
906
950
  S: this,
907
951
  C: (f, a) => f(...a)
908
952
  });
909
953
  if (connection.state !== ConnectionState.INITIAL) {
910
954
  log3("ignoring response", void 0, {
911
955
  F: __dxlog_file3,
912
- L: 185,
956
+ L: 189,
913
957
  S: this,
914
958
  C: (f, a) => f(...a)
915
959
  });
@@ -929,10 +973,19 @@ var Peer = class {
929
973
  remoteId: this.id
930
974
  }, {
931
975
  F: __dxlog_file3,
932
- L: 196,
976
+ L: 200,
933
977
  S: this,
934
978
  C: (f, a) => f(...a)
935
979
  });
980
+ if (err instanceof TimeoutError) {
981
+ log3.warn("aborting connection due to signalling failure", void 0, {
982
+ F: __dxlog_file3,
983
+ L: 202,
984
+ S: this,
985
+ C: (f, a) => f(...a)
986
+ });
987
+ await connection.abort(err);
988
+ }
936
989
  await this.closeConnection(err);
937
990
  throw err;
938
991
  } finally {
@@ -952,13 +1005,13 @@ var Peer = class {
952
1005
  sessionId
953
1006
  }, {
954
1007
  F: __dxlog_file3,
955
- L: 210,
1008
+ L: 218,
956
1009
  S: this,
957
1010
  C: (f, a) => f(...a)
958
1011
  });
959
1012
  invariant3(!this.connection, "Already connected.", {
960
1013
  F: __dxlog_file3,
961
- L: 217,
1014
+ L: 225,
962
1015
  S: this,
963
1016
  A: [
964
1017
  "!this.connection",
@@ -994,7 +1047,7 @@ var Peer = class {
994
1047
  initiator
995
1048
  }, {
996
1049
  F: __dxlog_file3,
997
- L: 236,
1050
+ L: 244,
998
1051
  S: this,
999
1052
  C: (f, a) => f(...a)
1000
1053
  });
@@ -1007,14 +1060,14 @@ var Peer = class {
1007
1060
  initiator
1008
1061
  }, {
1009
1062
  F: __dxlog_file3,
1010
- L: 245,
1063
+ L: 253,
1011
1064
  S: this,
1012
1065
  C: (f, a) => f(...a)
1013
1066
  });
1014
1067
  this._connectionLimiter.doneConnecting(sessionId);
1015
1068
  invariant3(this.connection === connection, "Connection mismatch (race condition).", {
1016
1069
  F: __dxlog_file3,
1017
- L: 250,
1070
+ L: 258,
1018
1071
  S: this,
1019
1072
  A: [
1020
1073
  "this.connection === connection",
@@ -1029,7 +1082,7 @@ var Peer = class {
1029
1082
  initiator
1030
1083
  }, {
1031
1084
  F: __dxlog_file3,
1032
- L: 252,
1085
+ L: 260,
1033
1086
  S: this,
1034
1087
  C: (f, a) => f(...a)
1035
1088
  });
@@ -1064,7 +1117,7 @@ var Peer = class {
1064
1117
  err
1065
1118
  }, {
1066
1119
  F: __dxlog_file3,
1067
- L: 292,
1120
+ L: 300,
1068
1121
  S: this,
1069
1122
  C: (f, a) => f(...a)
1070
1123
  });
@@ -1077,7 +1130,7 @@ var Peer = class {
1077
1130
  err
1078
1131
  }, {
1079
1132
  F: __dxlog_file3,
1080
- L: 293,
1133
+ L: 301,
1081
1134
  S: this,
1082
1135
  C: (f, a) => f(...a)
1083
1136
  });
@@ -1096,7 +1149,7 @@ var Peer = class {
1096
1149
  sessionId: connection.sessionId
1097
1150
  }, {
1098
1151
  F: __dxlog_file3,
1099
- L: 318,
1152
+ L: 326,
1100
1153
  S: this,
1101
1154
  C: (f, a) => f(...a)
1102
1155
  });
@@ -1106,7 +1159,7 @@ var Peer = class {
1106
1159
  sessionId: connection.sessionId
1107
1160
  }, {
1108
1161
  F: __dxlog_file3,
1109
- L: 324,
1162
+ L: 332,
1110
1163
  S: this,
1111
1164
  C: (f, a) => f(...a)
1112
1165
  });
@@ -1117,7 +1170,7 @@ var Peer = class {
1117
1170
  message
1118
1171
  }, {
1119
1172
  F: __dxlog_file3,
1120
- L: 329,
1173
+ L: 337,
1121
1174
  S: this,
1122
1175
  C: (f, a) => f(...a)
1123
1176
  });
@@ -1132,7 +1185,7 @@ var Peer = class {
1132
1185
  topic: this.topic
1133
1186
  }, {
1134
1187
  F: __dxlog_file3,
1135
- L: 339,
1188
+ L: 347,
1136
1189
  S: this,
1137
1190
  C: (f, a) => f(...a)
1138
1191
  });
@@ -1166,7 +1219,7 @@ function _ts_decorate3(decorators, target, key, desc) {
1166
1219
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1167
1220
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1168
1221
  }
1169
- var __dxlog_file4 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/swarm.ts";
1222
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts";
1170
1223
  var INITIATION_DELAY = 100;
1171
1224
  var getClassName = (obj) => Object.getPrototypeOf(obj).constructor.name;
1172
1225
  var Swarm = class {
@@ -1640,12 +1693,11 @@ import { Event as Event4, EventSubscriptions } from "@dxos/async";
1640
1693
  import { PublicKey as PublicKey5 } from "@dxos/keys";
1641
1694
  import { log as log5 } from "@dxos/log";
1642
1695
  import { ComplexMap as ComplexMap3 } from "@dxos/util";
1643
- var __dxlog_file5 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
1696
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
1644
1697
  var SwarmMapper = class {
1645
1698
  get peers() {
1646
1699
  return Array.from(this._peers.values());
1647
1700
  }
1648
- // prettier-ignore
1649
1701
  constructor(_swarm) {
1650
1702
  this._swarm = _swarm;
1651
1703
  this._subscriptions = new EventSubscriptions();
@@ -1668,7 +1720,7 @@ var SwarmMapper = class {
1668
1720
  _update() {
1669
1721
  log5("updating swarm", void 0, {
1670
1722
  F: __dxlog_file5,
1671
- L: 75,
1723
+ L: 72,
1672
1724
  S: this,
1673
1725
  C: (f, a) => f(...a)
1674
1726
  });
@@ -1692,7 +1744,7 @@ var SwarmMapper = class {
1692
1744
  totalPeersInSwarm: this._peers.size
1693
1745
  }, {
1694
1746
  F: __dxlog_file5,
1695
- L: 116,
1747
+ L: 113,
1696
1748
  S: this,
1697
1749
  C: (f, a) => f(...a)
1698
1750
  });
@@ -1708,13 +1760,13 @@ var SwarmMapper = class {
1708
1760
  // packages/core/mesh/network-manager/src/swarm/connection-limiter.ts
1709
1761
  import { DeferredTask as DeferredTask2 } from "@dxos/async";
1710
1762
  import { Context as Context5 } from "@dxos/context";
1711
- import { CancelledError as CancelledError3 } from "@dxos/errors";
1712
1763
  import { invariant as invariant5 } from "@dxos/invariant";
1713
1764
  import { PublicKey as PublicKey6 } from "@dxos/keys";
1714
1765
  import { log as log6 } from "@dxos/log";
1766
+ import { CancelledError as CancelledError3 } from "@dxos/protocols";
1715
1767
  import { ComplexMap as ComplexMap4 } from "@dxos/util";
1716
- var __dxlog_file6 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
1717
- var MAX_CONCURRENT_INITIATING_CONNECTIONS = 10;
1768
+ var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
1769
+ var MAX_CONCURRENT_INITIATING_CONNECTIONS = 50;
1718
1770
  var ConnectionLimiter = class {
1719
1771
  constructor({ maxConcurrentInitConnections = MAX_CONCURRENT_INITIATING_CONNECTIONS } = {}) {
1720
1772
  this._ctx = new Context5();
@@ -1866,7 +1918,7 @@ import { Messenger } from "@dxos/messaging";
1866
1918
  import { trace as trace3 } from "@dxos/protocols";
1867
1919
  import { ConnectionState as ConnectionState2 } from "@dxos/protocols/proto/dxos/client/services";
1868
1920
  import { ComplexMap as ComplexMap6 } from "@dxos/util";
1869
- var __dxlog_file7 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/network-manager.ts";
1921
+ var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts";
1870
1922
  var NetworkManager = class {
1871
1923
  constructor({ transportFactory, signalManager, log: log1 }) {
1872
1924
  /**
@@ -2102,7 +2154,7 @@ var NetworkManager = class {
2102
2154
 
2103
2155
  // packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts
2104
2156
  import { invariant as invariant7 } from "@dxos/invariant";
2105
- var __dxlog_file8 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
2157
+ var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
2106
2158
  var FullyConnectedTopology = class {
2107
2159
  toString() {
2108
2160
  return "FullyConnectedTopology";
@@ -2145,7 +2197,7 @@ var FullyConnectedTopology = class {
2145
2197
  import distance from "xor-distance";
2146
2198
  import { invariant as invariant8 } from "@dxos/invariant";
2147
2199
  import { log as log8 } from "@dxos/log";
2148
- var __dxlog_file9 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/topology/mmst-topology.ts";
2200
+ var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/mmst-topology.ts";
2149
2201
  var MMSTTopology = class {
2150
2202
  constructor({ originateConnections = 2, maxPeers = 4, sampleSize = 10 } = {}) {
2151
2203
  this._sampleCollected = false;
@@ -2254,9 +2306,8 @@ var sortByXorDistance = (keys, reference) => keys.sort((a, b) => distance.gt(dis
2254
2306
  // packages/core/mesh/network-manager/src/topology/star-topology.ts
2255
2307
  import { invariant as invariant9 } from "@dxos/invariant";
2256
2308
  import { log as log9 } from "@dxos/log";
2257
- var __dxlog_file10 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/topology/star-topology.ts";
2309
+ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/star-topology.ts";
2258
2310
  var StarTopology = class {
2259
- // prettier-ignore
2260
2311
  constructor(_centralPeer) {
2261
2312
  this._centralPeer = _centralPeer;
2262
2313
  }
@@ -2266,7 +2317,7 @@ var StarTopology = class {
2266
2317
  init(controller) {
2267
2318
  invariant9(!this._controller, "Already initialized.", {
2268
2319
  F: __dxlog_file10,
2269
- L: 24,
2320
+ L: 21,
2270
2321
  S: this,
2271
2322
  A: [
2272
2323
  "!this._controller",
@@ -2278,7 +2329,7 @@ var StarTopology = class {
2278
2329
  update() {
2279
2330
  invariant9(this._controller, "Not initialized.", {
2280
2331
  F: __dxlog_file10,
2281
- L: 29,
2332
+ L: 26,
2282
2333
  S: this,
2283
2334
  A: [
2284
2335
  "this._controller",
@@ -2289,7 +2340,7 @@ var StarTopology = class {
2289
2340
  if (!ownPeerId.equals(this._centralPeer)) {
2290
2341
  log9("leaf peer dropping all connections apart from central peer.", void 0, {
2291
2342
  F: __dxlog_file10,
2292
- L: 32,
2343
+ L: 29,
2293
2344
  S: this,
2294
2345
  C: (f, a) => f(...a)
2295
2346
  });
@@ -2299,7 +2350,7 @@ var StarTopology = class {
2299
2350
  peer
2300
2351
  }, {
2301
2352
  F: __dxlog_file10,
2302
- L: 37,
2353
+ L: 34,
2303
2354
  S: this,
2304
2355
  C: (f, a) => f(...a)
2305
2356
  });
@@ -2313,7 +2364,7 @@ var StarTopology = class {
2313
2364
  peer
2314
2365
  }, {
2315
2366
  F: __dxlog_file10,
2316
- L: 46,
2367
+ L: 43,
2317
2368
  S: this,
2318
2369
  C: (f, a) => f(...a)
2319
2370
  });
@@ -2324,7 +2375,7 @@ var StarTopology = class {
2324
2375
  async onOffer(peer) {
2325
2376
  invariant9(this._controller, "Not initialized.", {
2326
2377
  F: __dxlog_file10,
2327
- L: 53,
2378
+ L: 50,
2328
2379
  S: this,
2329
2380
  A: [
2330
2381
  "this._controller",
@@ -2338,7 +2389,7 @@ var StarTopology = class {
2338
2389
  isSelfCentral: ownPeerId.equals(this._centralPeer)
2339
2390
  }, {
2340
2391
  F: __dxlog_file10,
2341
- L: 55,
2392
+ L: 52,
2342
2393
  S: this,
2343
2394
  C: (f, a) => f(...a)
2344
2395
  });
@@ -2366,7 +2417,7 @@ function _ts_decorate4(decorators, target, key, desc) {
2366
2417
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2367
2418
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2368
2419
  }
2369
- var __dxlog_file11 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
2420
+ var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
2370
2421
  var MEMORY_TRANSPORT_DELAY = 1;
2371
2422
  var createStreamDelay = (delay) => {
2372
2423
  return new Transform({
@@ -2541,6 +2592,7 @@ var TransportKind;
2541
2592
  TransportKind2["LIBDATACHANNEL"] = "LIBDATACHANNEL";
2542
2593
  TransportKind2["SIMPLE_PEER_PROXY"] = "SIMPLE_PEER_PROXY";
2543
2594
  TransportKind2["MEMORY"] = "MEMORY";
2595
+ TransportKind2["TCP"] = "TCP";
2544
2596
  })(TransportKind || (TransportKind = {}));
2545
2597
 
2546
2598
  // packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts
@@ -2550,7 +2602,7 @@ import { Event as Event8 } from "@dxos/async";
2550
2602
  import { ErrorStream as ErrorStream4, raise as raise2 } from "@dxos/debug";
2551
2603
  import { PublicKey as PublicKey10 } from "@dxos/keys";
2552
2604
  import { log as log11 } from "@dxos/log";
2553
- import { trace as trace4 } from "@dxos/protocols";
2605
+ import { ConnectionResetError as ConnectionResetError2, ConnectivityError as ConnectivityError2, ProtocolError as ProtocolError2, UnknownProtocolError as UnknownProtocolError2, trace as trace4 } from "@dxos/protocols";
2554
2606
 
2555
2607
  // packages/core/mesh/network-manager/src/transport/webrtc.ts
2556
2608
  var wrtc = null;
@@ -2560,7 +2612,7 @@ try {
2560
2612
  }
2561
2613
 
2562
2614
  // packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts
2563
- var __dxlog_file12 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts";
2615
+ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts";
2564
2616
  var SimplePeerTransport = class {
2565
2617
  constructor(params) {
2566
2618
  this.params = params;
@@ -2573,13 +2625,13 @@ var SimplePeerTransport = class {
2573
2625
  id: this._instanceId
2574
2626
  }), {
2575
2627
  F: __dxlog_file12,
2576
- L: 39,
2628
+ L: 40,
2577
2629
  S: this,
2578
2630
  C: (f, a) => f(...a)
2579
2631
  });
2580
2632
  log11("created connection", params, {
2581
2633
  F: __dxlog_file12,
2582
- L: 40,
2634
+ L: 41,
2583
2635
  S: this,
2584
2636
  C: (f, a) => f(...a)
2585
2637
  });
@@ -2592,7 +2644,7 @@ var SimplePeerTransport = class {
2592
2644
  this._peer.on("signal", async (data) => {
2593
2645
  log11("signal", data, {
2594
2646
  F: __dxlog_file12,
2595
- L: 49,
2647
+ L: 50,
2596
2648
  S: this,
2597
2649
  C: (f, a) => f(...a)
2598
2650
  });
@@ -2605,7 +2657,7 @@ var SimplePeerTransport = class {
2605
2657
  this._peer.on("connect", () => {
2606
2658
  log11("connected", void 0, {
2607
2659
  F: __dxlog_file12,
2608
- L: 54,
2660
+ L: 55,
2609
2661
  S: this,
2610
2662
  C: (f, a) => f(...a)
2611
2663
  });
@@ -2615,7 +2667,7 @@ var SimplePeerTransport = class {
2615
2667
  this._peer.on("close", async () => {
2616
2668
  log11("closed", void 0, {
2617
2669
  F: __dxlog_file12,
2618
- L: 60,
2670
+ L: 61,
2619
2671
  S: this,
2620
2672
  C: (f, a) => f(...a)
2621
2673
  });
@@ -2623,22 +2675,70 @@ var SimplePeerTransport = class {
2623
2675
  this.closed.emit();
2624
2676
  });
2625
2677
  this._peer.on("error", async (err) => {
2626
- this.errors.raise(err);
2678
+ if (typeof RTCError !== "undefined" && err instanceof RTCError) {
2679
+ if (err.errorDetail === "sctp-failure") {
2680
+ this.errors.raise(new ConnectionResetError2("sctp-failure from RTCError", err));
2681
+ } else {
2682
+ this.errors.raise(new UnknownProtocolError2("unknown RTCError", err));
2683
+ }
2684
+ } else if ("code" in err) {
2685
+ log11.info("simple-peer error", err, {
2686
+ F: __dxlog_file12,
2687
+ L: 77,
2688
+ S: this,
2689
+ C: (f, a) => f(...a)
2690
+ });
2691
+ switch (err.code) {
2692
+ case "ERR_WEBRTC_SUPPORT":
2693
+ this.errors.raise(new ProtocolError2("WebRTC not supported", err));
2694
+ break;
2695
+ case "ERR_ICE_CONNECTION_FAILURE":
2696
+ case "ERR_DATA_CHANNEL":
2697
+ case "ERR_CONNECTION_FAILURE":
2698
+ case "ERR_SIGNALING":
2699
+ this.errors.raise(new ConnectivityError2("unknown communication failure", err));
2700
+ break;
2701
+ case "ERR_CREATE_OFFER":
2702
+ case "ERR_CREATE_ANSWER":
2703
+ case "ERR_SET_LOCAL_DESCRIPTION":
2704
+ case "ERR_SET_REMOTE_DESCRIPTION":
2705
+ case "ERR_ADD_ICE_CANDIDATE":
2706
+ this.errors.raise(new UnknownProtocolError2("unknown simple-peer library failure", err));
2707
+ break;
2708
+ default:
2709
+ this.errors.raise(new Error("unknown simple-peer error"));
2710
+ break;
2711
+ }
2712
+ } else {
2713
+ log11.info("unknown peer connection error", err, {
2714
+ F: __dxlog_file12,
2715
+ L: 101,
2716
+ S: this,
2717
+ C: (f, a) => f(...a)
2718
+ });
2719
+ this.errors.raise(err);
2720
+ }
2627
2721
  try {
2628
- if (typeof this._peer?._pc.getStats === "function") {
2722
+ if (typeof this._peer?._pc?.getStats === "function") {
2629
2723
  this._peer._pc.getStats().then((stats) => {
2630
2724
  log11.warn("report after webrtc error", {
2631
2725
  config: this.params.webrtcConfig,
2632
2726
  stats
2633
2727
  }, {
2634
2728
  F: __dxlog_file12,
2635
- L: 72,
2729
+ L: 109,
2636
2730
  S: this,
2637
2731
  C: (f, a) => f(...a)
2638
2732
  });
2639
2733
  });
2640
2734
  }
2641
- } catch {
2735
+ } catch (err2) {
2736
+ log11.catch(err2, void 0, {
2737
+ F: __dxlog_file12,
2738
+ L: 116,
2739
+ S: this,
2740
+ C: (f, a) => f(...a)
2741
+ });
2642
2742
  }
2643
2743
  await this.destroy();
2644
2744
  });
@@ -2646,7 +2746,7 @@ var SimplePeerTransport = class {
2646
2746
  id: this._instanceId
2647
2747
  }), {
2648
2748
  F: __dxlog_file12,
2649
- L: 82,
2749
+ L: 121,
2650
2750
  S: this,
2651
2751
  C: (f, a) => f(...a)
2652
2752
  });
@@ -2654,7 +2754,7 @@ var SimplePeerTransport = class {
2654
2754
  async destroy() {
2655
2755
  log11("closing...", void 0, {
2656
2756
  F: __dxlog_file12,
2657
- L: 86,
2757
+ L: 125,
2658
2758
  S: this,
2659
2759
  C: (f, a) => f(...a)
2660
2760
  });
@@ -2664,7 +2764,7 @@ var SimplePeerTransport = class {
2664
2764
  this.closed.emit();
2665
2765
  log11("closed", void 0, {
2666
2766
  F: __dxlog_file12,
2667
- L: 91,
2767
+ L: 130,
2668
2768
  S: this,
2669
2769
  C: (f, a) => f(...a)
2670
2770
  });
@@ -2695,9 +2795,8 @@ import { PublicKey as PublicKey11 } from "@dxos/keys";
2695
2795
  import { log as log12 } from "@dxos/log";
2696
2796
  import { ConnectionState as ConnectionState3 } from "@dxos/protocols/proto/dxos/mesh/bridge";
2697
2797
  import { ComplexMap as ComplexMap8 } from "@dxos/util";
2698
- var __dxlog_file13 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/simplepeer-transport-service.ts";
2798
+ var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport-service.ts";
2699
2799
  var SimplePeerTransportService = class {
2700
- // prettier-ignore
2701
2800
  constructor(_webrtcConfig) {
2702
2801
  this._webrtcConfig = _webrtcConfig;
2703
2802
  this.transports = new ComplexMap8(PublicKey11.hash);
@@ -2767,7 +2866,8 @@ var SimplePeerTransportService = class {
2767
2866
  const transportState = {
2768
2867
  transport,
2769
2868
  stream: duplex,
2770
- writeCallbacks: []
2869
+ writeCallbacks: [],
2870
+ state: "OPEN"
2771
2871
  };
2772
2872
  ready();
2773
2873
  this.transports.set(request.proxyId, transportState);
@@ -2777,7 +2877,7 @@ var SimplePeerTransportService = class {
2777
2877
  async sendSignal({ proxyId, signal }) {
2778
2878
  invariant12(this.transports.has(proxyId), void 0, {
2779
2879
  F: __dxlog_file13,
2780
- L: 113,
2880
+ L: 112,
2781
2881
  S: this,
2782
2882
  A: [
2783
2883
  "this.transports.has(proxyId)",
@@ -2787,9 +2887,17 @@ var SimplePeerTransportService = class {
2787
2887
  await this.transports.get(proxyId).transport.signal(signal);
2788
2888
  }
2789
2889
  async sendData({ proxyId, payload }) {
2890
+ if (this.transports.get(proxyId)?.state !== "OPEN") {
2891
+ log12.debug("transport is closed", void 0, {
2892
+ F: __dxlog_file13,
2893
+ L: 118,
2894
+ S: this,
2895
+ C: (f, a) => f(...a)
2896
+ });
2897
+ }
2790
2898
  invariant12(this.transports.has(proxyId), void 0, {
2791
2899
  F: __dxlog_file13,
2792
- L: 118,
2900
+ L: 120,
2793
2901
  S: this,
2794
2902
  A: [
2795
2903
  "this.transports.has(proxyId)",
@@ -2807,10 +2915,12 @@ var SimplePeerTransportService = class {
2807
2915
  async close({ proxyId }) {
2808
2916
  await this.transports.get(proxyId)?.transport.destroy();
2809
2917
  await this.transports.get(proxyId)?.stream.end();
2810
- this.transports.delete(proxyId);
2918
+ if (this.transports.get(proxyId)) {
2919
+ this.transports.get(proxyId).state = "CLOSED";
2920
+ }
2811
2921
  log12("Closed.", void 0, {
2812
2922
  F: __dxlog_file13,
2813
- L: 132,
2923
+ L: 136,
2814
2924
  S: this,
2815
2925
  C: (f, a) => f(...a)
2816
2926
  });
@@ -2825,11 +2935,11 @@ import { ErrorStream as ErrorStream5 } from "@dxos/debug";
2825
2935
  import { invariant as invariant13 } from "@dxos/invariant";
2826
2936
  import { PublicKey as PublicKey12 } from "@dxos/keys";
2827
2937
  import { log as log13 } from "@dxos/log";
2938
+ import { ConnectionResetError as ConnectionResetError3, TimeoutError as TimeoutError2, ProtocolError as ProtocolError3, ConnectivityError as ConnectivityError3, UnknownProtocolError as UnknownProtocolError3 } from "@dxos/protocols";
2828
2939
  import { ConnectionState as ConnectionState4 } from "@dxos/protocols/proto/dxos/mesh/bridge";
2829
2940
  import { arrayToBuffer } from "@dxos/util";
2830
- var __dxlog_file14 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/simplepeer-transport-proxy.ts";
2941
+ var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport-proxy.ts";
2831
2942
  var SimplePeerTransportProxy = class {
2832
- // prettier-ignore
2833
2943
  constructor(_params) {
2834
2944
  this._params = _params;
2835
2945
  this._proxyId = PublicKey12.random();
@@ -2846,7 +2956,7 @@ var SimplePeerTransportProxy = class {
2846
2956
  this._serviceStream.subscribe(async (event) => {
2847
2957
  log13("SimplePeerTransportProxy: event", event, {
2848
2958
  F: __dxlog_file14,
2849
- L: 51,
2959
+ L: 55,
2850
2960
  S: this,
2851
2961
  C: (f, a) => f(...a)
2852
2962
  });
@@ -2866,7 +2976,7 @@ var SimplePeerTransportProxy = class {
2866
2976
  }).then(() => callback(), (err) => {
2867
2977
  log13.catch(err, void 0, {
2868
2978
  F: __dxlog_file14,
2869
- L: 69,
2979
+ L: 76,
2870
2980
  S: this,
2871
2981
  C: (f, a) => f(...a)
2872
2982
  });
@@ -2875,14 +2985,14 @@ var SimplePeerTransportProxy = class {
2875
2985
  }));
2876
2986
  }, (error) => log13.catch(error, void 0, {
2877
2987
  F: __dxlog_file14,
2878
- L: 75,
2988
+ L: 83,
2879
2989
  S: this,
2880
2990
  C: (f, a) => f(...a)
2881
2991
  }));
2882
2992
  }
2883
2993
  async _handleConnection(connectionEvent) {
2884
2994
  if (connectionEvent.error) {
2885
- this.errors.raise(new Error(connectionEvent.error));
2995
+ this.errors.raise(decodeError(connectionEvent.error));
2886
2996
  }
2887
2997
  switch (connectionEvent.state) {
2888
2998
  case ConnectionState4.CONNECTED: {
@@ -2905,7 +3015,7 @@ var SimplePeerTransportProxy = class {
2905
3015
  this._params.bridgeService.sendSignal({
2906
3016
  proxyId: this._proxyId,
2907
3017
  signal
2908
- }).catch((err) => this.errors.raise(err));
3018
+ }).catch((err) => this.errors.raise(decodeError(err)));
2909
3019
  }
2910
3020
  // TODO(burdon): Move open from constructor.
2911
3021
  async destroy() {
@@ -2921,7 +3031,7 @@ var SimplePeerTransportProxy = class {
2921
3031
  } catch (err) {
2922
3032
  log13.catch(err, void 0, {
2923
3033
  F: __dxlog_file14,
2924
- L: 126,
3034
+ L: 134,
2925
3035
  S: this,
2926
3036
  C: (f, a) => f(...a)
2927
3037
  });
@@ -2957,7 +3067,7 @@ var SimplePeerTransportProxyFactory = class {
2957
3067
  createTransport(options) {
2958
3068
  invariant13(this._bridgeService, "SimplePeerTransportProxyFactory is not ready to open connections", {
2959
3069
  F: __dxlog_file14,
2960
- L: 163,
3070
+ L: 171,
2961
3071
  S: this,
2962
3072
  A: [
2963
3073
  "this._bridgeService",
@@ -2973,6 +3083,22 @@ var SimplePeerTransportProxyFactory = class {
2973
3083
  return transport;
2974
3084
  }
2975
3085
  };
3086
+ var decodeError = (err) => {
3087
+ const message = typeof err === "string" ? err : err.message;
3088
+ if (message.includes("CONNECTION_RESET")) {
3089
+ return new ConnectionResetError3(message);
3090
+ } else if (message.includes("TIMEOUT")) {
3091
+ return new TimeoutError2(message);
3092
+ } else if (message.includes("PROTOCOL_ERROR")) {
3093
+ return new ProtocolError3(message);
3094
+ } else if (message.includes("CONNECTIVITY_ERROR")) {
3095
+ return new ConnectivityError3(message);
3096
+ } else if (message.includes("UNKNOWN_PROTOCOL_ERROR")) {
3097
+ return new UnknownProtocolError3(message);
3098
+ } else {
3099
+ return typeof err === "string" ? new Error(err) : err;
3100
+ }
3101
+ };
2976
3102
 
2977
3103
  // packages/core/mesh/network-manager/src/transport/libdatachannel-transport.ts
2978
3104
  import { Duplex as Duplex2 } from "stream";
@@ -2989,7 +3115,7 @@ function _ts_decorate5(decorators, target, key, desc) {
2989
3115
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2990
3116
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2991
3117
  }
2992
- var __dxlog_file15 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/libdatachannel-transport.ts";
3118
+ var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/libdatachannel-transport.ts";
2993
3119
  var DATACHANNEL_LABEL = "dxos.mesh.transport";
2994
3120
  var MAX_BUFFERED_AMOUNT = 64 * 1024;
2995
3121
  var MAX_MESSAGE_SIZE = 64 * 1024;
@@ -3360,4 +3486,4 @@ export {
3360
3486
  createLibDataChannelTransportFactory,
3361
3487
  createTeleportProtocolFactory
3362
3488
  };
3363
- //# sourceMappingURL=chunk-UKMTAO4L.mjs.map
3489
+ //# sourceMappingURL=chunk-26KK6XOP.mjs.map