@dxos/network-manager 0.1.57 → 0.1.58-main.31dfb10

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.
@@ -7,7 +7,7 @@ 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";
10
+ import { CancelledError, ProtocolError, ConnectionResetError, ConnectivityError, UnknownProtocolError } from "@dxos/errors";
11
11
  import { invariant } from "@dxos/invariant";
12
12
  import { PublicKey } from "@dxos/keys";
13
13
  import { log } from "@dxos/log";
@@ -22,7 +22,7 @@ function _ts_decorate(decorators, target, key, desc) {
22
22
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
23
23
  return c > 3 && r && Object.defineProperty(target, key, r), r;
24
24
  }
25
- var __dxlog_file = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/connection.ts";
25
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts";
26
26
  var STARTING_SIGNALLING_DELAY = 10;
27
27
  var MAX_SIGNALLING_DELAY = 300;
28
28
  var ConnectionState;
@@ -64,6 +64,8 @@ var ConnectionState;
64
64
  */
65
65
  "CLOSED"
66
66
  ] = "CLOSED";
67
+ ConnectionState5["ABORTING"] = "ABORTING";
68
+ ConnectionState5["ABORTED"] = "ABORTED";
67
69
  })(ConnectionState || (ConnectionState = {}));
68
70
  var Connection = class {
69
71
  constructor(topic, ownId, remoteId, sessionId, initiator, _signalMessaging, _protocol, _transportFactory, _callbacks) {
@@ -95,7 +97,7 @@ var Connection = class {
95
97
  initiator: this.initiator
96
98
  }, {
97
99
  F: __dxlog_file,
98
- L: 114,
100
+ L: 123,
99
101
  S: this,
100
102
  C: (f, a) => f(...a)
101
103
  });
@@ -115,7 +117,7 @@ var Connection = class {
115
117
  async openConnection() {
116
118
  invariant(this._state === ConnectionState.INITIAL, "Invalid state.", {
117
119
  F: __dxlog_file,
118
- L: 139,
120
+ L: 148,
119
121
  S: this,
120
122
  A: [
121
123
  "this._state === ConnectionState.INITIAL",
@@ -126,7 +128,7 @@ var Connection = class {
126
128
  id: this._instanceId
127
129
  }), {
128
130
  F: __dxlog_file,
129
- L: 140,
131
+ L: 149,
130
132
  S: this,
131
133
  C: (f, a) => f(...a)
132
134
  });
@@ -138,7 +140,7 @@ var Connection = class {
138
140
  initiator: this.initiator
139
141
  }, {
140
142
  F: __dxlog_file,
141
- L: 141,
143
+ L: 150,
142
144
  S: this,
143
145
  C: (f, a) => f(...a)
144
146
  });
@@ -149,15 +151,15 @@ var Connection = class {
149
151
  this._protocol.stream.on("close", () => {
150
152
  log("protocol stream closed", void 0, {
151
153
  F: __dxlog_file,
152
- L: 158,
154
+ L: 167,
153
155
  S: this,
154
156
  C: (f, a) => f(...a)
155
157
  });
156
- this.close().catch((err) => this.errors.raise(err));
158
+ this.close(new ProtocolError("protocol stream closed")).catch((err) => this.errors.raise(err));
157
159
  });
158
160
  invariant(!this._transport, void 0, {
159
161
  F: __dxlog_file,
160
- L: 162,
162
+ L: 171,
161
163
  S: this,
162
164
  A: [
163
165
  "!this._transport",
@@ -177,7 +179,7 @@ var Connection = class {
177
179
  this._transport = void 0;
178
180
  log("abort triggered by transport close", void 0, {
179
181
  F: __dxlog_file,
180
- L: 176,
182
+ L: 185,
181
183
  S: this,
182
184
  C: (f, a) => f(...a)
183
185
  });
@@ -188,21 +190,38 @@ var Connection = class {
188
190
  err
189
191
  }, {
190
192
  F: __dxlog_file,
191
- L: 181,
193
+ L: 190,
192
194
  S: this,
193
195
  C: (f, a) => f(...a)
194
196
  });
195
197
  if (!this.closeReason) {
196
198
  this.closeReason = err?.message;
197
199
  }
198
- if (err?.message.includes("OperationError")) {
199
- log("aborting due to transport OperationError", void 0, {
200
+ if (err instanceof ConnectionResetError) {
201
+ log("aborting due to transport ConnectionResetError", void 0, {
200
202
  F: __dxlog_file,
201
- L: 187,
203
+ L: 197,
202
204
  S: this,
203
205
  C: (f, a) => f(...a)
204
206
  });
205
207
  this.abort().catch((err2) => this.errors.raise(err2));
208
+ } else if (err instanceof ConnectivityError) {
209
+ log("aborting due to transport ConnectivityError", void 0, {
210
+ F: __dxlog_file,
211
+ L: 200,
212
+ S: this,
213
+ C: (f, a) => f(...a)
214
+ });
215
+ this.abort().catch((err2) => this.errors.raise(err2));
216
+ } else if (err instanceof UnknownProtocolError) {
217
+ log("unsure what to do for UnknownProtocolError", {
218
+ err
219
+ }, {
220
+ F: __dxlog_file,
221
+ L: 203,
222
+ S: this,
223
+ C: (f, a) => f(...a)
224
+ });
206
225
  }
207
226
  if (this._state !== ConnectionState.CLOSED && this._state !== ConnectionState.CLOSING) {
208
227
  this.errors.raise(err);
@@ -216,7 +235,7 @@ var Connection = class {
216
235
  id: this._instanceId
217
236
  }), {
218
237
  F: __dxlog_file,
219
- L: 203,
238
+ L: 218,
220
239
  S: this,
221
240
  C: (f, a) => f(...a)
222
241
  });
@@ -226,30 +245,30 @@ var Connection = class {
226
245
  err
227
246
  }, {
228
247
  F: __dxlog_file,
229
- L: 209,
248
+ L: 224,
230
249
  S: this,
231
250
  C: (f, a) => f(...a)
232
251
  });
233
- if (!this.closeReason) {
234
- this.closeReason = err?.message;
235
- }
236
- if (this._state === ConnectionState.CLOSED) {
237
- log("abort ignored: already closed", this.closeReason, {
252
+ if (this._state === ConnectionState.CLOSED || this._state === ConnectionState.ABORTED) {
253
+ log(`abort ignored: already ${this._state}`, this.closeReason, {
238
254
  F: __dxlog_file,
239
- L: 214,
255
+ L: 226,
240
256
  S: this,
241
257
  C: (f, a) => f(...a)
242
258
  });
243
259
  return;
244
260
  }
245
- this._changeState(ConnectionState.CLOSING);
261
+ this._changeState(ConnectionState.ABORTING);
262
+ if (!this.closeReason) {
263
+ this.closeReason = err?.message;
264
+ }
246
265
  await this._ctx.dispose();
247
266
  try {
248
267
  log("aborting protocol... ", {
249
268
  proto: this._protocol
250
269
  }, {
251
270
  F: __dxlog_file,
252
- L: 224,
271
+ L: 239,
253
272
  S: this,
254
273
  C: (f, a) => f(...a)
255
274
  });
@@ -257,7 +276,7 @@ var Connection = class {
257
276
  } catch (err2) {
258
277
  log.catch(err2, void 0, {
259
278
  F: __dxlog_file,
260
- L: 227,
279
+ L: 242,
261
280
  S: this,
262
281
  C: (f, a) => f(...a)
263
282
  });
@@ -267,56 +286,68 @@ var Connection = class {
267
286
  } catch (err2) {
268
287
  log.catch(err2, void 0, {
269
288
  F: __dxlog_file,
270
- L: 234,
289
+ L: 249,
271
290
  S: this,
272
291
  C: (f, a) => f(...a)
273
292
  });
274
293
  }
275
- this._changeState(ConnectionState.CLOSED);
276
- this._callbacks?.onClosed?.(err);
294
+ try {
295
+ this._callbacks?.onClosed?.(err);
296
+ } catch (err2) {
297
+ log.catch(err2, void 0, {
298
+ F: __dxlog_file,
299
+ L: 255,
300
+ S: this,
301
+ C: (f, a) => f(...a)
302
+ });
303
+ }
304
+ this._changeState(ConnectionState.ABORTED);
277
305
  }
278
306
  async close(err) {
279
307
  if (!this.closeReason) {
280
308
  this.closeReason = err?.message;
281
309
  }
282
- if (this._state === ConnectionState.CLOSED) {
310
+ if (this._state === ConnectionState.CLOSED || this._state === ConnectionState.ABORTING || this._state === ConnectionState.ABORTED) {
283
311
  return;
284
312
  }
313
+ const lastState = this._state;
285
314
  this._changeState(ConnectionState.CLOSING);
286
315
  await this._ctx.dispose();
287
316
  log("closing...", {
288
317
  peerId: this.ownId
289
318
  }, {
290
319
  F: __dxlog_file,
291
- L: 253,
320
+ L: 277,
292
321
  S: this,
293
322
  C: (f, a) => f(...a)
294
323
  });
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
- });
324
+ if (lastState === ConnectionState.CONNECTED) {
325
+ try {
326
+ await this._protocol.close();
327
+ } catch (err2) {
328
+ log.catch(err2, void 0, {
329
+ F: __dxlog_file,
330
+ L: 284,
331
+ S: this,
332
+ C: (f, a) => f(...a)
333
+ });
334
+ }
335
+ try {
336
+ await this._transport?.destroy();
337
+ } catch (err2) {
338
+ log.catch(err2, void 0, {
339
+ F: __dxlog_file,
340
+ L: 291,
341
+ S: this,
342
+ C: (f, a) => f(...a)
343
+ });
344
+ }
314
345
  }
315
346
  log("closed", {
316
347
  peerId: this.ownId
317
348
  }, {
318
349
  F: __dxlog_file,
319
- L: 269,
350
+ L: 295,
320
351
  S: this,
321
352
  C: (f, a) => f(...a)
322
353
  });
@@ -359,7 +390,7 @@ var Connection = class {
359
390
  err
360
391
  }, {
361
392
  F: __dxlog_file,
362
- L: 306,
393
+ L: 332,
363
394
  S: this,
364
395
  C: (f, a) => f(...a)
365
396
  });
@@ -372,7 +403,7 @@ var Connection = class {
372
403
  async signal(msg) {
373
404
  invariant(msg.sessionId, void 0, {
374
405
  F: __dxlog_file,
375
- L: 315,
406
+ L: 341,
376
407
  S: this,
377
408
  A: [
378
409
  "msg.sessionId",
@@ -382,7 +413,7 @@ var Connection = class {
382
413
  if (!msg.sessionId.equals(this.sessionId)) {
383
414
  log("dropping signal for incorrect session id", void 0, {
384
415
  F: __dxlog_file,
385
- L: 317,
416
+ L: 343,
386
417
  S: this,
387
418
  C: (f, a) => f(...a)
388
419
  });
@@ -390,7 +421,7 @@ var Connection = class {
390
421
  }
391
422
  invariant(msg.data.signal || msg.data.signalBatch, void 0, {
392
423
  F: __dxlog_file,
393
- L: 320,
424
+ L: 346,
394
425
  S: this,
395
426
  A: [
396
427
  "msg.data.signal || msg.data.signalBatch",
@@ -399,7 +430,7 @@ var Connection = class {
399
430
  });
400
431
  invariant(msg.author?.equals(this.remoteId), void 0, {
401
432
  F: __dxlog_file,
402
- L: 321,
433
+ L: 347,
403
434
  S: this,
404
435
  A: [
405
436
  "msg.author?.equals(this.remoteId)",
@@ -408,7 +439,7 @@ var Connection = class {
408
439
  });
409
440
  invariant(msg.recipient?.equals(this.ownId), void 0, {
410
441
  F: __dxlog_file,
411
- L: 322,
442
+ L: 348,
412
443
  S: this,
413
444
  A: [
414
445
  "msg.recipient?.equals(this.ownId)",
@@ -432,7 +463,7 @@ var Connection = class {
432
463
  msg: msg.data
433
464
  }, {
434
465
  F: __dxlog_file,
435
- L: 331,
466
+ L: 357,
436
467
  S: this,
437
468
  C: (f, a) => f(...a)
438
469
  });
@@ -440,7 +471,7 @@ var Connection = class {
440
471
  } else {
441
472
  invariant(this._transport, "Connection not ready to accept signals.", {
442
473
  F: __dxlog_file,
443
- L: 334,
474
+ L: 360,
444
475
  S: this,
445
476
  A: [
446
477
  "this._transport",
@@ -453,7 +484,7 @@ var Connection = class {
453
484
  msg: msg.data
454
485
  }, {
455
486
  F: __dxlog_file,
456
- L: 335,
487
+ L: 361,
457
488
  S: this,
458
489
  C: (f, a) => f(...a)
459
490
  });
@@ -467,17 +498,17 @@ var Connection = class {
467
498
  _changeState(state) {
468
499
  log("stateChanged", {
469
500
  from: this._state,
470
- too: state,
501
+ to: state,
471
502
  peerId: this.ownId
472
503
  }, {
473
504
  F: __dxlog_file,
474
- L: 346,
505
+ L: 372,
475
506
  S: this,
476
507
  C: (f, a) => f(...a)
477
508
  });
478
509
  invariant(state !== this._state, "Already in this state.", {
479
510
  F: __dxlog_file,
480
- L: 347,
511
+ L: 373,
481
512
  S: this,
482
513
  A: [
483
514
  "state !== this._state",
@@ -502,7 +533,7 @@ import { PublicKey as PublicKey2 } from "@dxos/keys";
502
533
  import { log as log2 } from "@dxos/log";
503
534
  import { schema } from "@dxos/protocols";
504
535
  import { ComplexMap } from "@dxos/util";
505
- var __dxlog_file2 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
536
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
506
537
  var SwarmMessage = schema.getCodecForType("dxos.mesh.swarm.SwarmMessage");
507
538
  var SwarmMessenger = class {
508
539
  constructor({ sendMessage, onSignal, onOffer, topic }) {
@@ -740,7 +771,7 @@ import { ComplexMap as ComplexMap2, isNotNullOrUndefined } from "@dxos/util";
740
771
  // packages/core/mesh/network-manager/src/swarm/peer.ts
741
772
  import { Event as Event2, scheduleTask, synchronized as synchronized2 } from "@dxos/async";
742
773
  import { Context as Context3 } from "@dxos/context";
743
- import { CancelledError as CancelledError2, SystemError } from "@dxos/errors";
774
+ import { CancelledError as CancelledError2, SystemError, TimeoutError } from "@dxos/errors";
744
775
  import { invariant as invariant3 } from "@dxos/invariant";
745
776
  import { PublicKey as PublicKey3 } from "@dxos/keys";
746
777
  import { log as log3 } from "@dxos/log";
@@ -754,7 +785,7 @@ function _ts_decorate2(decorators, target, key, desc) {
754
785
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
755
786
  return c > 3 && r && Object.defineProperty(target, key, r), r;
756
787
  }
757
- var __dxlog_file3 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/peer.ts";
788
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts";
758
789
  var ConnectionDisplacedError = class extends SystemError {
759
790
  constructor() {
760
791
  super("Connection displaced by remote initiator.");
@@ -933,6 +964,9 @@ var Peer = class {
933
964
  S: this,
934
965
  C: (f, a) => f(...a)
935
966
  });
967
+ if (err instanceof TimeoutError) {
968
+ await connection.abort(err);
969
+ }
936
970
  await this.closeConnection(err);
937
971
  throw err;
938
972
  } finally {
@@ -952,13 +986,13 @@ var Peer = class {
952
986
  sessionId
953
987
  }, {
954
988
  F: __dxlog_file3,
955
- L: 210,
989
+ L: 213,
956
990
  S: this,
957
991
  C: (f, a) => f(...a)
958
992
  });
959
993
  invariant3(!this.connection, "Already connected.", {
960
994
  F: __dxlog_file3,
961
- L: 217,
995
+ L: 220,
962
996
  S: this,
963
997
  A: [
964
998
  "!this.connection",
@@ -994,7 +1028,7 @@ var Peer = class {
994
1028
  initiator
995
1029
  }, {
996
1030
  F: __dxlog_file3,
997
- L: 236,
1031
+ L: 239,
998
1032
  S: this,
999
1033
  C: (f, a) => f(...a)
1000
1034
  });
@@ -1007,14 +1041,14 @@ var Peer = class {
1007
1041
  initiator
1008
1042
  }, {
1009
1043
  F: __dxlog_file3,
1010
- L: 245,
1044
+ L: 248,
1011
1045
  S: this,
1012
1046
  C: (f, a) => f(...a)
1013
1047
  });
1014
1048
  this._connectionLimiter.doneConnecting(sessionId);
1015
1049
  invariant3(this.connection === connection, "Connection mismatch (race condition).", {
1016
1050
  F: __dxlog_file3,
1017
- L: 250,
1051
+ L: 253,
1018
1052
  S: this,
1019
1053
  A: [
1020
1054
  "this.connection === connection",
@@ -1029,7 +1063,7 @@ var Peer = class {
1029
1063
  initiator
1030
1064
  }, {
1031
1065
  F: __dxlog_file3,
1032
- L: 252,
1066
+ L: 255,
1033
1067
  S: this,
1034
1068
  C: (f, a) => f(...a)
1035
1069
  });
@@ -1064,7 +1098,7 @@ var Peer = class {
1064
1098
  err
1065
1099
  }, {
1066
1100
  F: __dxlog_file3,
1067
- L: 292,
1101
+ L: 295,
1068
1102
  S: this,
1069
1103
  C: (f, a) => f(...a)
1070
1104
  });
@@ -1077,7 +1111,7 @@ var Peer = class {
1077
1111
  err
1078
1112
  }, {
1079
1113
  F: __dxlog_file3,
1080
- L: 293,
1114
+ L: 296,
1081
1115
  S: this,
1082
1116
  C: (f, a) => f(...a)
1083
1117
  });
@@ -1096,7 +1130,7 @@ var Peer = class {
1096
1130
  sessionId: connection.sessionId
1097
1131
  }, {
1098
1132
  F: __dxlog_file3,
1099
- L: 318,
1133
+ L: 321,
1100
1134
  S: this,
1101
1135
  C: (f, a) => f(...a)
1102
1136
  });
@@ -1106,7 +1140,7 @@ var Peer = class {
1106
1140
  sessionId: connection.sessionId
1107
1141
  }, {
1108
1142
  F: __dxlog_file3,
1109
- L: 324,
1143
+ L: 327,
1110
1144
  S: this,
1111
1145
  C: (f, a) => f(...a)
1112
1146
  });
@@ -1117,7 +1151,7 @@ var Peer = class {
1117
1151
  message
1118
1152
  }, {
1119
1153
  F: __dxlog_file3,
1120
- L: 329,
1154
+ L: 332,
1121
1155
  S: this,
1122
1156
  C: (f, a) => f(...a)
1123
1157
  });
@@ -1132,7 +1166,7 @@ var Peer = class {
1132
1166
  topic: this.topic
1133
1167
  }, {
1134
1168
  F: __dxlog_file3,
1135
- L: 339,
1169
+ L: 342,
1136
1170
  S: this,
1137
1171
  C: (f, a) => f(...a)
1138
1172
  });
@@ -1166,7 +1200,7 @@ function _ts_decorate3(decorators, target, key, desc) {
1166
1200
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1167
1201
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1168
1202
  }
1169
- var __dxlog_file4 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/swarm.ts";
1203
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts";
1170
1204
  var INITIATION_DELAY = 100;
1171
1205
  var getClassName = (obj) => Object.getPrototypeOf(obj).constructor.name;
1172
1206
  var Swarm = class {
@@ -1640,7 +1674,7 @@ import { Event as Event4, EventSubscriptions } from "@dxos/async";
1640
1674
  import { PublicKey as PublicKey5 } from "@dxos/keys";
1641
1675
  import { log as log5 } from "@dxos/log";
1642
1676
  import { ComplexMap as ComplexMap3 } from "@dxos/util";
1643
- var __dxlog_file5 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
1677
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
1644
1678
  var SwarmMapper = class {
1645
1679
  get peers() {
1646
1680
  return Array.from(this._peers.values());
@@ -1713,7 +1747,7 @@ import { invariant as invariant5 } from "@dxos/invariant";
1713
1747
  import { PublicKey as PublicKey6 } from "@dxos/keys";
1714
1748
  import { log as log6 } from "@dxos/log";
1715
1749
  import { ComplexMap as ComplexMap4 } from "@dxos/util";
1716
- var __dxlog_file6 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
1750
+ var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
1717
1751
  var MAX_CONCURRENT_INITIATING_CONNECTIONS = 10;
1718
1752
  var ConnectionLimiter = class {
1719
1753
  constructor({ maxConcurrentInitConnections = MAX_CONCURRENT_INITIATING_CONNECTIONS } = {}) {
@@ -1866,7 +1900,7 @@ import { Messenger } from "@dxos/messaging";
1866
1900
  import { trace as trace3 } from "@dxos/protocols";
1867
1901
  import { ConnectionState as ConnectionState2 } from "@dxos/protocols/proto/dxos/client/services";
1868
1902
  import { ComplexMap as ComplexMap6 } from "@dxos/util";
1869
- var __dxlog_file7 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/network-manager.ts";
1903
+ var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts";
1870
1904
  var NetworkManager = class {
1871
1905
  constructor({ transportFactory, signalManager, log: log1 }) {
1872
1906
  /**
@@ -2102,7 +2136,7 @@ var NetworkManager = class {
2102
2136
 
2103
2137
  // packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts
2104
2138
  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";
2139
+ var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
2106
2140
  var FullyConnectedTopology = class {
2107
2141
  toString() {
2108
2142
  return "FullyConnectedTopology";
@@ -2145,7 +2179,7 @@ var FullyConnectedTopology = class {
2145
2179
  import distance from "xor-distance";
2146
2180
  import { invariant as invariant8 } from "@dxos/invariant";
2147
2181
  import { log as log8 } from "@dxos/log";
2148
- var __dxlog_file9 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/topology/mmst-topology.ts";
2182
+ var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/mmst-topology.ts";
2149
2183
  var MMSTTopology = class {
2150
2184
  constructor({ originateConnections = 2, maxPeers = 4, sampleSize = 10 } = {}) {
2151
2185
  this._sampleCollected = false;
@@ -2254,7 +2288,7 @@ var sortByXorDistance = (keys, reference) => keys.sort((a, b) => distance.gt(dis
2254
2288
  // packages/core/mesh/network-manager/src/topology/star-topology.ts
2255
2289
  import { invariant as invariant9 } from "@dxos/invariant";
2256
2290
  import { log as log9 } from "@dxos/log";
2257
- var __dxlog_file10 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/topology/star-topology.ts";
2291
+ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/star-topology.ts";
2258
2292
  var StarTopology = class {
2259
2293
  // prettier-ignore
2260
2294
  constructor(_centralPeer) {
@@ -2366,7 +2400,7 @@ function _ts_decorate4(decorators, target, key, desc) {
2366
2400
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2367
2401
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2368
2402
  }
2369
- var __dxlog_file11 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
2403
+ var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
2370
2404
  var MEMORY_TRANSPORT_DELAY = 1;
2371
2405
  var createStreamDelay = (delay) => {
2372
2406
  return new Transform({
@@ -2548,6 +2582,7 @@ import SimplePeerConstructor from "simple-peer";
2548
2582
  import invariant11 from "tiny-invariant";
2549
2583
  import { Event as Event8 } from "@dxos/async";
2550
2584
  import { ErrorStream as ErrorStream4, raise as raise2 } from "@dxos/debug";
2585
+ import { ConnectionResetError as ConnectionResetError2, ConnectivityError as ConnectivityError2, ProtocolError as ProtocolError2, UnknownProtocolError as UnknownProtocolError2 } from "@dxos/errors";
2551
2586
  import { PublicKey as PublicKey10 } from "@dxos/keys";
2552
2587
  import { log as log11 } from "@dxos/log";
2553
2588
  import { trace as trace4 } from "@dxos/protocols";
@@ -2560,7 +2595,7 @@ try {
2560
2595
  }
2561
2596
 
2562
2597
  // 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";
2598
+ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts";
2564
2599
  var SimplePeerTransport = class {
2565
2600
  constructor(params) {
2566
2601
  this.params = params;
@@ -2573,13 +2608,13 @@ var SimplePeerTransport = class {
2573
2608
  id: this._instanceId
2574
2609
  }), {
2575
2610
  F: __dxlog_file12,
2576
- L: 39,
2611
+ L: 41,
2577
2612
  S: this,
2578
2613
  C: (f, a) => f(...a)
2579
2614
  });
2580
2615
  log11("created connection", params, {
2581
2616
  F: __dxlog_file12,
2582
- L: 40,
2617
+ L: 42,
2583
2618
  S: this,
2584
2619
  C: (f, a) => f(...a)
2585
2620
  });
@@ -2592,7 +2627,7 @@ var SimplePeerTransport = class {
2592
2627
  this._peer.on("signal", async (data) => {
2593
2628
  log11("signal", data, {
2594
2629
  F: __dxlog_file12,
2595
- L: 49,
2630
+ L: 51,
2596
2631
  S: this,
2597
2632
  C: (f, a) => f(...a)
2598
2633
  });
@@ -2605,7 +2640,7 @@ var SimplePeerTransport = class {
2605
2640
  this._peer.on("connect", () => {
2606
2641
  log11("connected", void 0, {
2607
2642
  F: __dxlog_file12,
2608
- L: 54,
2643
+ L: 56,
2609
2644
  S: this,
2610
2645
  C: (f, a) => f(...a)
2611
2646
  });
@@ -2615,7 +2650,7 @@ var SimplePeerTransport = class {
2615
2650
  this._peer.on("close", async () => {
2616
2651
  log11("closed", void 0, {
2617
2652
  F: __dxlog_file12,
2618
- L: 60,
2653
+ L: 62,
2619
2654
  S: this,
2620
2655
  C: (f, a) => f(...a)
2621
2656
  });
@@ -2623,7 +2658,35 @@ var SimplePeerTransport = class {
2623
2658
  this.closed.emit();
2624
2659
  });
2625
2660
  this._peer.on("error", async (err) => {
2626
- this.errors.raise(err);
2661
+ if (typeof RTCError !== "undefined" && err instanceof RTCError) {
2662
+ if (err.errorDetail === "sctp-failure") {
2663
+ this.errors.raise(new ConnectionResetError2("sctp-failure from RTCError", err));
2664
+ } else {
2665
+ this.errors.raise(new UnknownProtocolError2("unknown RTCError", err));
2666
+ }
2667
+ } else if (err.name === "InvalidStateError") {
2668
+ this.errors.raise(new ConnectionResetError2("safari WebRTC error", err));
2669
+ } else if ("code" in err) {
2670
+ switch (err.code) {
2671
+ case "ERR_WEBRTC_SUPPORT":
2672
+ this.errors.raise(new ProtocolError2("WebRTC not supported", err));
2673
+ case "ERR_ICE_CONNECTION_FAILURE":
2674
+ case "ERR_DATA_CHANNEL":
2675
+ case "ERR_CONNECTION_FAILURE":
2676
+ case "ERR_SIGNALING":
2677
+ this.errors.raise(new ConnectivityError2("unknown communication failure", err));
2678
+ case "ERR_CREATE_OFFER":
2679
+ case "ERR_CREATE_ANSWER":
2680
+ case "ERR_SET_LOCAL_DESCRIPTION":
2681
+ case "ERR_SET_REMOTE_DESCRIPTION":
2682
+ case "ERR_ADD_ICE_CANDIDATE":
2683
+ this.errors.raise(new UnknownProtocolError2("unknown simple-peer library failure", err));
2684
+ default:
2685
+ this.errors.raise(new Error("unknown simple-peer error"));
2686
+ }
2687
+ } else {
2688
+ this.errors.raise(err);
2689
+ }
2627
2690
  try {
2628
2691
  if (typeof this._peer?._pc.getStats === "function") {
2629
2692
  this._peer._pc.getStats().then((stats) => {
@@ -2632,13 +2695,19 @@ var SimplePeerTransport = class {
2632
2695
  stats
2633
2696
  }, {
2634
2697
  F: __dxlog_file12,
2635
- L: 72,
2698
+ L: 107,
2636
2699
  S: this,
2637
2700
  C: (f, a) => f(...a)
2638
2701
  });
2639
2702
  });
2640
2703
  }
2641
- } catch {
2704
+ } catch (err2) {
2705
+ log11.catch(err2, void 0, {
2706
+ F: __dxlog_file12,
2707
+ L: 114,
2708
+ S: this,
2709
+ C: (f, a) => f(...a)
2710
+ });
2642
2711
  }
2643
2712
  await this.destroy();
2644
2713
  });
@@ -2646,7 +2715,7 @@ var SimplePeerTransport = class {
2646
2715
  id: this._instanceId
2647
2716
  }), {
2648
2717
  F: __dxlog_file12,
2649
- L: 82,
2718
+ L: 119,
2650
2719
  S: this,
2651
2720
  C: (f, a) => f(...a)
2652
2721
  });
@@ -2654,7 +2723,7 @@ var SimplePeerTransport = class {
2654
2723
  async destroy() {
2655
2724
  log11("closing...", void 0, {
2656
2725
  F: __dxlog_file12,
2657
- L: 86,
2726
+ L: 123,
2658
2727
  S: this,
2659
2728
  C: (f, a) => f(...a)
2660
2729
  });
@@ -2664,7 +2733,7 @@ var SimplePeerTransport = class {
2664
2733
  this.closed.emit();
2665
2734
  log11("closed", void 0, {
2666
2735
  F: __dxlog_file12,
2667
- L: 91,
2736
+ L: 128,
2668
2737
  S: this,
2669
2738
  C: (f, a) => f(...a)
2670
2739
  });
@@ -2695,7 +2764,7 @@ import { PublicKey as PublicKey11 } from "@dxos/keys";
2695
2764
  import { log as log12 } from "@dxos/log";
2696
2765
  import { ConnectionState as ConnectionState3 } from "@dxos/protocols/proto/dxos/mesh/bridge";
2697
2766
  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";
2767
+ var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport-service.ts";
2699
2768
  var SimplePeerTransportService = class {
2700
2769
  // prettier-ignore
2701
2770
  constructor(_webrtcConfig) {
@@ -2822,12 +2891,13 @@ import { Writable } from "@dxos/node-std/stream";
2822
2891
  import { Event as Event9 } from "@dxos/async";
2823
2892
  import { Context as Context6 } from "@dxos/context";
2824
2893
  import { ErrorStream as ErrorStream5 } from "@dxos/debug";
2894
+ import { ConnectionResetError as ConnectionResetError3, TimeoutError as TimeoutError2, ProtocolError as ProtocolError3, ConnectivityError as ConnectivityError3, UnknownProtocolError as UnknownProtocolError3 } from "@dxos/errors";
2825
2895
  import { invariant as invariant13 } from "@dxos/invariant";
2826
2896
  import { PublicKey as PublicKey12 } from "@dxos/keys";
2827
2897
  import { log as log13 } from "@dxos/log";
2828
2898
  import { ConnectionState as ConnectionState4 } from "@dxos/protocols/proto/dxos/mesh/bridge";
2829
2899
  import { arrayToBuffer } from "@dxos/util";
2830
- var __dxlog_file14 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/simplepeer-transport-proxy.ts";
2900
+ var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport-proxy.ts";
2831
2901
  var SimplePeerTransportProxy = class {
2832
2902
  // prettier-ignore
2833
2903
  constructor(_params) {
@@ -2846,7 +2916,7 @@ var SimplePeerTransportProxy = class {
2846
2916
  this._serviceStream.subscribe(async (event) => {
2847
2917
  log13("SimplePeerTransportProxy: event", event, {
2848
2918
  F: __dxlog_file14,
2849
- L: 51,
2919
+ L: 58,
2850
2920
  S: this,
2851
2921
  C: (f, a) => f(...a)
2852
2922
  });
@@ -2866,7 +2936,7 @@ var SimplePeerTransportProxy = class {
2866
2936
  }).then(() => callback(), (err) => {
2867
2937
  log13.catch(err, void 0, {
2868
2938
  F: __dxlog_file14,
2869
- L: 69,
2939
+ L: 76,
2870
2940
  S: this,
2871
2941
  C: (f, a) => f(...a)
2872
2942
  });
@@ -2875,14 +2945,14 @@ var SimplePeerTransportProxy = class {
2875
2945
  }));
2876
2946
  }, (error) => log13.catch(error, void 0, {
2877
2947
  F: __dxlog_file14,
2878
- L: 75,
2948
+ L: 82,
2879
2949
  S: this,
2880
2950
  C: (f, a) => f(...a)
2881
2951
  }));
2882
2952
  }
2883
2953
  async _handleConnection(connectionEvent) {
2884
2954
  if (connectionEvent.error) {
2885
- this.errors.raise(new Error(connectionEvent.error));
2955
+ this.errors.raise(decodeError(connectionEvent.error));
2886
2956
  }
2887
2957
  switch (connectionEvent.state) {
2888
2958
  case ConnectionState4.CONNECTED: {
@@ -2905,7 +2975,7 @@ var SimplePeerTransportProxy = class {
2905
2975
  this._params.bridgeService.sendSignal({
2906
2976
  proxyId: this._proxyId,
2907
2977
  signal
2908
- }).catch((err) => this.errors.raise(err));
2978
+ }).catch((err) => this.errors.raise(decodeError(err)));
2909
2979
  }
2910
2980
  // TODO(burdon): Move open from constructor.
2911
2981
  async destroy() {
@@ -2921,7 +2991,7 @@ var SimplePeerTransportProxy = class {
2921
2991
  } catch (err) {
2922
2992
  log13.catch(err, void 0, {
2923
2993
  F: __dxlog_file14,
2924
- L: 126,
2994
+ L: 133,
2925
2995
  S: this,
2926
2996
  C: (f, a) => f(...a)
2927
2997
  });
@@ -2957,7 +3027,7 @@ var SimplePeerTransportProxyFactory = class {
2957
3027
  createTransport(options) {
2958
3028
  invariant13(this._bridgeService, "SimplePeerTransportProxyFactory is not ready to open connections", {
2959
3029
  F: __dxlog_file14,
2960
- L: 163,
3030
+ L: 170,
2961
3031
  S: this,
2962
3032
  A: [
2963
3033
  "this._bridgeService",
@@ -2973,6 +3043,22 @@ var SimplePeerTransportProxyFactory = class {
2973
3043
  return transport;
2974
3044
  }
2975
3045
  };
3046
+ var decodeError = (err) => {
3047
+ const message = typeof err === "string" ? err : err.message;
3048
+ if (message.includes("ConnectionResetError")) {
3049
+ return new ConnectionResetError3(message);
3050
+ } else if (message.includes("TimeoutError")) {
3051
+ return new TimeoutError2(message);
3052
+ } else if (message.includes("ProtocolError")) {
3053
+ return new ProtocolError3(message);
3054
+ } else if (message.includes("ConnectivityError")) {
3055
+ return new ConnectivityError3(message);
3056
+ } else if (message.includes("UnknownProtocolError")) {
3057
+ return new UnknownProtocolError3(message);
3058
+ } else {
3059
+ return typeof err === "string" ? new Error(err) : err;
3060
+ }
3061
+ };
2976
3062
 
2977
3063
  // packages/core/mesh/network-manager/src/transport/libdatachannel-transport.ts
2978
3064
  import { Duplex as Duplex2 } from "stream";
@@ -2989,7 +3075,7 @@ function _ts_decorate5(decorators, target, key, desc) {
2989
3075
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2990
3076
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2991
3077
  }
2992
- var __dxlog_file15 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/libdatachannel-transport.ts";
3078
+ var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/libdatachannel-transport.ts";
2993
3079
  var DATACHANNEL_LABEL = "dxos.mesh.transport";
2994
3080
  var MAX_BUFFERED_AMOUNT = 64 * 1024;
2995
3081
  var MAX_MESSAGE_SIZE = 64 * 1024;
@@ -3360,4 +3446,4 @@ export {
3360
3446
  createLibDataChannelTransportFactory,
3361
3447
  createTeleportProtocolFactory
3362
3448
  };
3363
- //# sourceMappingURL=chunk-UKMTAO4L.mjs.map
3449
+ //# sourceMappingURL=chunk-O2SMNRBC.mjs.map