@dxos/network-manager 0.3.0 → 0.3.1-main.0fddbd4

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.
@@ -4,7 +4,7 @@ import {
4
4
  } from "./chunk-YERMWDRB.mjs";
5
5
 
6
6
  // packages/core/mesh/network-manager/src/swarm/connection.ts
7
- import { DeferredTask, Event, sleep, synchronized } from "@dxos/async";
7
+ import { DeferredTask, Event, sleep, scheduleTask, synchronized } from "@dxos/async";
8
8
  import { Context, cancelWithContext } from "@dxos/context";
9
9
  import { ErrorStream } from "@dxos/debug";
10
10
  import { invariant } from "@dxos/invariant";
@@ -21,8 +21,9 @@ function _ts_decorate(decorators, target, key, desc) {
21
21
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
22
  return c > 3 && r && Object.defineProperty(target, key, r), r;
23
23
  }
24
- 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";
25
25
  var STARTING_SIGNALLING_DELAY = 10;
26
+ var TRANSPORT_CONNECTION_TIMEOUT = 1e4;
26
27
  var MAX_SIGNALLING_DELAY = 300;
27
28
  var ConnectionState;
28
29
  (function(ConnectionState5) {
@@ -78,6 +79,7 @@ var Connection = class {
78
79
  this._transportFactory = _transportFactory;
79
80
  this._callbacks = _callbacks;
80
81
  this._ctx = new Context();
82
+ this.connectedTimeoutContext = new Context();
81
83
  this._state = ConnectionState.CREATED;
82
84
  this._incomingSignalBuffer = [];
83
85
  this._outgoingSignalBuffer = [];
@@ -96,7 +98,7 @@ var Connection = class {
96
98
  initiator: this.initiator
97
99
  }, {
98
100
  F: __dxlog_file,
99
- L: 123,
101
+ L: 129,
100
102
  S: this,
101
103
  C: (f, a) => f(...a)
102
104
  });
@@ -116,7 +118,7 @@ var Connection = class {
116
118
  async openConnection() {
117
119
  invariant(this._state === ConnectionState.INITIAL, "Invalid state.", {
118
120
  F: __dxlog_file,
119
- L: 148,
121
+ L: 154,
120
122
  S: this,
121
123
  A: [
122
124
  "this._state === ConnectionState.INITIAL",
@@ -127,7 +129,7 @@ var Connection = class {
127
129
  id: this._instanceId
128
130
  }), {
129
131
  F: __dxlog_file,
130
- L: 149,
132
+ L: 155,
131
133
  S: this,
132
134
  C: (f, a) => f(...a)
133
135
  });
@@ -139,7 +141,7 @@ var Connection = class {
139
141
  initiator: this.initiator
140
142
  }, {
141
143
  F: __dxlog_file,
142
- L: 150,
144
+ L: 156,
143
145
  S: this,
144
146
  C: (f, a) => f(...a)
145
147
  });
@@ -150,15 +152,24 @@ var Connection = class {
150
152
  this._protocol.stream.on("close", () => {
151
153
  log("protocol stream closed", void 0, {
152
154
  F: __dxlog_file,
153
- L: 167,
155
+ L: 173,
154
156
  S: this,
155
157
  C: (f, a) => f(...a)
156
158
  });
157
159
  this.close(new ProtocolError("protocol stream closed")).catch((err) => this.errors.raise(err));
158
160
  });
161
+ scheduleTask(this.connectedTimeoutContext, async () => {
162
+ log.warn("timeout waiting for transport to connect, aborting", void 0, {
163
+ F: __dxlog_file,
164
+ L: 180,
165
+ S: this,
166
+ C: (f, a) => f(...a)
167
+ });
168
+ await this.abort().catch((err) => this.errors.raise(err));
169
+ }, TRANSPORT_CONNECTION_TIMEOUT);
159
170
  invariant(!this._transport, void 0, {
160
171
  F: __dxlog_file,
161
- L: 171,
172
+ L: 186,
162
173
  S: this,
163
174
  A: [
164
175
  "!this._transport",
@@ -170,26 +181,27 @@ var Connection = class {
170
181
  stream: this._protocol.stream,
171
182
  sendSignal: async (signal) => this._sendSignal(signal)
172
183
  });
173
- this._transport.connected.once(() => {
184
+ this._transport.connected.once(async () => {
174
185
  this._changeState(ConnectionState.CONNECTED);
186
+ await this.connectedTimeoutContext.dispose();
175
187
  this._callbacks?.onConnected?.();
176
188
  });
177
189
  this._transport.closed.once(() => {
178
190
  this._transport = void 0;
179
191
  log("abort triggered by transport close", void 0, {
180
192
  F: __dxlog_file,
181
- L: 185,
193
+ L: 201,
182
194
  S: this,
183
195
  C: (f, a) => f(...a)
184
196
  });
185
197
  this.abort().catch((err) => this.errors.raise(err));
186
198
  });
187
- this._transport.errors.handle((err) => {
199
+ this._transport.errors.handle(async (err) => {
188
200
  log("transport error:", {
189
201
  err
190
202
  }, {
191
203
  F: __dxlog_file,
192
- L: 190,
204
+ L: 206,
193
205
  S: this,
194
206
  C: (f, a) => f(...a)
195
207
  });
@@ -199,7 +211,7 @@ var Connection = class {
199
211
  if (err instanceof ConnectionResetError) {
200
212
  log.warn("aborting due to transport ConnectionResetError", void 0, {
201
213
  F: __dxlog_file,
202
- L: 197,
214
+ L: 213,
203
215
  S: this,
204
216
  C: (f, a) => f(...a)
205
217
  });
@@ -207,7 +219,7 @@ var Connection = class {
207
219
  } else if (err instanceof ConnectivityError) {
208
220
  log.warn("aborting due to transport ConnectivityError", void 0, {
209
221
  F: __dxlog_file,
210
- L: 200,
222
+ L: 216,
211
223
  S: this,
212
224
  C: (f, a) => f(...a)
213
225
  });
@@ -217,12 +229,13 @@ var Connection = class {
217
229
  err
218
230
  }, {
219
231
  F: __dxlog_file,
220
- L: 203,
232
+ L: 219,
221
233
  S: this,
222
234
  C: (f, a) => f(...a)
223
235
  });
224
236
  }
225
237
  if (this._state !== ConnectionState.CLOSED && this._state !== ConnectionState.CLOSING) {
238
+ await this.connectedTimeoutContext.dispose();
226
239
  this.errors.raise(err);
227
240
  }
228
241
  });
@@ -234,7 +247,7 @@ var Connection = class {
234
247
  id: this._instanceId
235
248
  }), {
236
249
  F: __dxlog_file,
237
- L: 218,
250
+ L: 235,
238
251
  S: this,
239
252
  C: (f, a) => f(...a)
240
253
  });
@@ -244,19 +257,20 @@ var Connection = class {
244
257
  err
245
258
  }, {
246
259
  F: __dxlog_file,
247
- L: 225,
260
+ L: 242,
248
261
  S: this,
249
262
  C: (f, a) => f(...a)
250
263
  });
251
264
  if (this._state === ConnectionState.CLOSED || this._state === ConnectionState.ABORTED) {
252
265
  log(`abort ignored: already ${this._state}`, this.closeReason, {
253
266
  F: __dxlog_file,
254
- L: 227,
267
+ L: 244,
255
268
  S: this,
256
269
  C: (f, a) => f(...a)
257
270
  });
258
271
  return;
259
272
  }
273
+ await this.connectedTimeoutContext.dispose();
260
274
  this._changeState(ConnectionState.ABORTING);
261
275
  if (!this.closeReason) {
262
276
  this.closeReason = err?.message;
@@ -267,7 +281,7 @@ var Connection = class {
267
281
  proto: this._protocol
268
282
  }, {
269
283
  F: __dxlog_file,
270
- L: 240,
284
+ L: 258,
271
285
  S: this,
272
286
  C: (f, a) => f(...a)
273
287
  });
@@ -275,7 +289,7 @@ var Connection = class {
275
289
  } catch (err2) {
276
290
  log.catch(err2, void 0, {
277
291
  F: __dxlog_file,
278
- L: 243,
292
+ L: 261,
279
293
  S: this,
280
294
  C: (f, a) => f(...a)
281
295
  });
@@ -285,7 +299,7 @@ var Connection = class {
285
299
  } catch (err2) {
286
300
  log.catch(err2, void 0, {
287
301
  F: __dxlog_file,
288
- L: 250,
302
+ L: 268,
289
303
  S: this,
290
304
  C: (f, a) => f(...a)
291
305
  });
@@ -295,7 +309,7 @@ var Connection = class {
295
309
  } catch (err2) {
296
310
  log.catch(err2, void 0, {
297
311
  F: __dxlog_file,
298
- L: 256,
312
+ L: 274,
299
313
  S: this,
300
314
  C: (f, a) => f(...a)
301
315
  });
@@ -305,18 +319,21 @@ var Connection = class {
305
319
  async close(err) {
306
320
  if (!this.closeReason) {
307
321
  this.closeReason = err?.message;
322
+ } else {
323
+ this.closeReason += `; ${err?.message}`;
308
324
  }
309
325
  if (this._state === ConnectionState.CLOSED || this._state === ConnectionState.ABORTING || this._state === ConnectionState.ABORTED) {
310
326
  return;
311
327
  }
312
328
  const lastState = this._state;
313
329
  this._changeState(ConnectionState.CLOSING);
330
+ await this.connectedTimeoutContext.dispose();
314
331
  await this._ctx.dispose();
315
332
  log("closing...", {
316
333
  peerId: this.ownId
317
334
  }, {
318
335
  F: __dxlog_file,
319
- L: 278,
336
+ L: 299,
320
337
  S: this,
321
338
  C: (f, a) => f(...a)
322
339
  });
@@ -326,7 +343,7 @@ var Connection = class {
326
343
  } catch (err2) {
327
344
  log.catch(err2, void 0, {
328
345
  F: __dxlog_file,
329
- L: 285,
346
+ L: 306,
330
347
  S: this,
331
348
  C: (f, a) => f(...a)
332
349
  });
@@ -336,7 +353,7 @@ var Connection = class {
336
353
  } catch (err2) {
337
354
  log.catch(err2, void 0, {
338
355
  F: __dxlog_file,
339
- L: 292,
356
+ L: 313,
340
357
  S: this,
341
358
  C: (f, a) => f(...a)
342
359
  });
@@ -346,7 +363,7 @@ var Connection = class {
346
363
  peerId: this.ownId
347
364
  }, {
348
365
  F: __dxlog_file,
349
- L: 296,
366
+ L: 317,
350
367
  S: this,
351
368
  C: (f, a) => f(...a)
352
369
  });
@@ -382,14 +399,14 @@ var Connection = class {
382
399
  }
383
400
  });
384
401
  } catch (err) {
385
- if (err instanceof CancelledError) {
402
+ if (err instanceof CancelledError || err instanceof Error && err.message?.includes("CANCELLED")) {
386
403
  return;
387
404
  }
388
405
  log.warn("signal failed", {
389
406
  err
390
407
  }, {
391
408
  F: __dxlog_file,
392
- L: 333,
409
+ L: 355,
393
410
  S: this,
394
411
  C: (f, a) => f(...a)
395
412
  });
@@ -402,7 +419,7 @@ var Connection = class {
402
419
  async signal(msg) {
403
420
  invariant(msg.sessionId, void 0, {
404
421
  F: __dxlog_file,
405
- L: 342,
422
+ L: 364,
406
423
  S: this,
407
424
  A: [
408
425
  "msg.sessionId",
@@ -412,7 +429,7 @@ var Connection = class {
412
429
  if (!msg.sessionId.equals(this.sessionId)) {
413
430
  log("dropping signal for incorrect session id", void 0, {
414
431
  F: __dxlog_file,
415
- L: 344,
432
+ L: 366,
416
433
  S: this,
417
434
  C: (f, a) => f(...a)
418
435
  });
@@ -420,7 +437,7 @@ var Connection = class {
420
437
  }
421
438
  invariant(msg.data.signal || msg.data.signalBatch, void 0, {
422
439
  F: __dxlog_file,
423
- L: 347,
440
+ L: 369,
424
441
  S: this,
425
442
  A: [
426
443
  "msg.data.signal || msg.data.signalBatch",
@@ -429,7 +446,7 @@ var Connection = class {
429
446
  });
430
447
  invariant(msg.author?.equals(this.remoteId), void 0, {
431
448
  F: __dxlog_file,
432
- L: 348,
449
+ L: 370,
433
450
  S: this,
434
451
  A: [
435
452
  "msg.author?.equals(this.remoteId)",
@@ -438,7 +455,7 @@ var Connection = class {
438
455
  });
439
456
  invariant(msg.recipient?.equals(this.ownId), void 0, {
440
457
  F: __dxlog_file,
441
- L: 349,
458
+ L: 371,
442
459
  S: this,
443
460
  A: [
444
461
  "msg.recipient?.equals(this.ownId)",
@@ -462,7 +479,7 @@ var Connection = class {
462
479
  msg: msg.data
463
480
  }, {
464
481
  F: __dxlog_file,
465
- L: 358,
482
+ L: 380,
466
483
  S: this,
467
484
  C: (f, a) => f(...a)
468
485
  });
@@ -470,7 +487,7 @@ var Connection = class {
470
487
  } else {
471
488
  invariant(this._transport, "Connection not ready to accept signals.", {
472
489
  F: __dxlog_file,
473
- L: 361,
490
+ L: 383,
474
491
  S: this,
475
492
  A: [
476
493
  "this._transport",
@@ -483,7 +500,7 @@ var Connection = class {
483
500
  msg: msg.data
484
501
  }, {
485
502
  F: __dxlog_file,
486
- L: 362,
503
+ L: 384,
487
504
  S: this,
488
505
  C: (f, a) => f(...a)
489
506
  });
@@ -501,13 +518,13 @@ var Connection = class {
501
518
  peerId: this.ownId
502
519
  }, {
503
520
  F: __dxlog_file,
504
- L: 373,
521
+ L: 395,
505
522
  S: this,
506
523
  C: (f, a) => f(...a)
507
524
  });
508
525
  invariant(state !== this._state, "Already in this state.", {
509
526
  F: __dxlog_file,
510
- L: 374,
527
+ L: 396,
511
528
  S: this,
512
529
  A: [
513
530
  "state !== this._state",
@@ -532,7 +549,7 @@ import { PublicKey as PublicKey2 } from "@dxos/keys";
532
549
  import { log as log2 } from "@dxos/log";
533
550
  import { schema } from "@dxos/protocols";
534
551
  import { ComplexMap } from "@dxos/util";
535
- var __dxlog_file2 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
552
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
536
553
  var SwarmMessage = schema.getCodecForType("dxos.mesh.swarm.SwarmMessage");
537
554
  var SwarmMessenger = class {
538
555
  constructor({ sendMessage, onSignal, onOffer, topic }) {
@@ -758,7 +775,7 @@ var SwarmMessenger = class {
758
775
  };
759
776
 
760
777
  // packages/core/mesh/network-manager/src/swarm/swarm.ts
761
- import { Event as Event3, scheduleTask as scheduleTask2, sleep as sleep2, synchronized as synchronized3 } from "@dxos/async";
778
+ import { Event as Event3, scheduleTask as scheduleTask3, sleep as sleep2, synchronized as synchronized3 } from "@dxos/async";
762
779
  import { Context as Context4 } from "@dxos/context";
763
780
  import { ErrorStream as ErrorStream2 } from "@dxos/debug";
764
781
  import { invariant as invariant4 } from "@dxos/invariant";
@@ -768,12 +785,12 @@ import { trace as trace2 } from "@dxos/protocols";
768
785
  import { ComplexMap as ComplexMap2, isNotNullOrUndefined } from "@dxos/util";
769
786
 
770
787
  // packages/core/mesh/network-manager/src/swarm/peer.ts
771
- import { Event as Event2, scheduleTask, synchronized as synchronized2 } from "@dxos/async";
788
+ import { Event as Event2, scheduleTask as scheduleTask2, synchronized as synchronized2 } from "@dxos/async";
772
789
  import { Context as Context3 } from "@dxos/context";
773
790
  import { invariant as invariant3 } from "@dxos/invariant";
774
791
  import { PublicKey as PublicKey3 } from "@dxos/keys";
775
792
  import { log as log3 } from "@dxos/log";
776
- import { CancelledError as CancelledError2, SystemError, TimeoutError } from "@dxos/protocols";
793
+ import { CancelledError as CancelledError2, SystemError } from "@dxos/protocols";
777
794
  function _ts_decorate2(decorators, target, key, desc) {
778
795
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
779
796
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -784,7 +801,7 @@ function _ts_decorate2(decorators, target, key, desc) {
784
801
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
785
802
  return c > 3 && r && Object.defineProperty(target, key, r), r;
786
803
  }
787
- var __dxlog_file3 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/peer.ts";
804
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts";
788
805
  var ConnectionDisplacedError = class extends SystemError {
789
806
  constructor() {
790
807
  super("Connection displaced by remote initiator.");
@@ -816,11 +833,12 @@ var Peer = class {
816
833
  const remoteId = message.author;
817
834
  if (this.connection && ![
818
835
  ConnectionState.CREATED,
819
- ConnectionState.INITIAL
836
+ ConnectionState.INITIAL,
837
+ ConnectionState.CONNECTING
820
838
  ].includes(this.connection.state)) {
821
839
  log3.info(`received offer when connection already in ${this.connection.state} state`, void 0, {
822
840
  F: __dxlog_file3,
823
- L: 112,
841
+ L: 115,
824
842
  S: this,
825
843
  C: (f, a) => f(...a)
826
844
  });
@@ -837,7 +855,7 @@ var Peer = class {
837
855
  sessionId: this.connection?.sessionId
838
856
  }, {
839
857
  F: __dxlog_file3,
840
- L: 121,
858
+ L: 124,
841
859
  S: this,
842
860
  C: (f, a) => f(...a)
843
861
  });
@@ -854,7 +872,7 @@ var Peer = class {
854
872
  if (!this.connection) {
855
873
  invariant3(message.sessionId, void 0, {
856
874
  F: __dxlog_file3,
857
- L: 141,
875
+ L: 144,
858
876
  S: this,
859
877
  A: [
860
878
  "message.sessionId",
@@ -875,7 +893,7 @@ var Peer = class {
875
893
  err
876
894
  }, {
877
895
  F: __dxlog_file3,
878
- L: 151,
896
+ L: 154,
879
897
  S: this,
880
898
  C: (f, a) => f(...a)
881
899
  });
@@ -897,7 +915,7 @@ var Peer = class {
897
915
  async initiateConnection() {
898
916
  invariant3(!this.initiating, "Initiation in progress.", {
899
917
  F: __dxlog_file3,
900
- L: 168,
918
+ L: 171,
901
919
  S: this,
902
920
  A: [
903
921
  "!this.initiating",
@@ -906,7 +924,7 @@ var Peer = class {
906
924
  });
907
925
  invariant3(!this.connection, "Already connected.", {
908
926
  F: __dxlog_file3,
909
- L: 169,
927
+ L: 172,
910
928
  S: this,
911
929
  A: [
912
930
  "!this.connection",
@@ -921,16 +939,17 @@ var Peer = class {
921
939
  sessionId
922
940
  }, {
923
941
  F: __dxlog_file3,
924
- L: 171,
942
+ L: 174,
925
943
  S: this,
926
944
  C: (f, a) => f(...a)
927
945
  });
928
946
  const connection = this._createConnection(true, sessionId);
929
947
  this.initiating = true;
948
+ let answer;
930
949
  try {
931
950
  await this._connectionLimiter.connecting(sessionId);
932
951
  connection.initiate();
933
- const answer = await this._signalMessaging.offer({
952
+ answer = await this._signalMessaging.offer({
934
953
  author: this.localPeerId,
935
954
  recipient: this.id,
936
955
  sessionId,
@@ -946,46 +965,87 @@ var Peer = class {
946
965
  remoteId: this.id
947
966
  }, {
948
967
  F: __dxlog_file3,
949
- L: 187,
968
+ L: 191,
950
969
  S: this,
951
970
  C: (f, a) => f(...a)
952
971
  });
953
972
  if (connection.state !== ConnectionState.INITIAL) {
954
973
  log3("ignoring response", void 0, {
955
974
  F: __dxlog_file3,
956
- L: 189,
975
+ L: 193,
957
976
  S: this,
958
977
  C: (f, a) => f(...a)
959
978
  });
960
979
  return;
961
980
  }
981
+ } catch (err) {
982
+ log3("initiation error: send offer", {
983
+ err,
984
+ topic: this.topic,
985
+ peerId: this.localPeerId,
986
+ remoteId: this.id
987
+ }, {
988
+ F: __dxlog_file3,
989
+ L: 197,
990
+ S: this,
991
+ C: (f, a) => f(...a)
992
+ });
993
+ await connection.abort(err);
994
+ throw err;
995
+ } finally {
996
+ this.initiating = false;
997
+ }
998
+ try {
962
999
  if (!answer.accept) {
963
1000
  this._callbacks.onRejected();
964
1001
  return;
965
1002
  }
1003
+ } catch (err) {
1004
+ log3("initiation error: accept answer", {
1005
+ err,
1006
+ topic: this.topic,
1007
+ peerId: this.localPeerId,
1008
+ remoteId: this.id
1009
+ }, {
1010
+ F: __dxlog_file3,
1011
+ L: 210,
1012
+ S: this,
1013
+ C: (f, a) => f(...a)
1014
+ });
1015
+ await connection.abort(err);
1016
+ throw err;
1017
+ } finally {
1018
+ this.initiating = false;
1019
+ }
1020
+ try {
1021
+ log3("opening connection as initiator", void 0, {
1022
+ F: __dxlog_file3,
1023
+ L: 223,
1024
+ S: this,
1025
+ C: (f, a) => f(...a)
1026
+ });
966
1027
  await connection.openConnection();
967
1028
  this._callbacks.onAccepted();
968
1029
  } catch (err) {
969
- log3("initiation error", {
1030
+ log3("initiation error: open connection", {
970
1031
  err,
971
1032
  topic: this.topic,
972
1033
  peerId: this.localPeerId,
973
1034
  remoteId: this.id
974
1035
  }, {
975
1036
  F: __dxlog_file3,
976
- L: 200,
1037
+ L: 227,
1038
+ S: this,
1039
+ C: (f, a) => f(...a)
1040
+ });
1041
+ log3.warn("closing connection due to unhandled error on openConnection", {
1042
+ err
1043
+ }, {
1044
+ F: __dxlog_file3,
1045
+ L: 234,
977
1046
  S: this,
978
1047
  C: (f, a) => f(...a)
979
1048
  });
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
- }
989
1049
  await this.closeConnection(err);
990
1050
  throw err;
991
1051
  } finally {
@@ -1005,13 +1065,13 @@ var Peer = class {
1005
1065
  sessionId
1006
1066
  }, {
1007
1067
  F: __dxlog_file3,
1008
- L: 218,
1068
+ L: 248,
1009
1069
  S: this,
1010
1070
  C: (f, a) => f(...a)
1011
1071
  });
1012
1072
  invariant3(!this.connection, "Already connected.", {
1013
1073
  F: __dxlog_file3,
1014
- L: 225,
1074
+ L: 255,
1015
1075
  S: this,
1016
1076
  A: [
1017
1077
  "!this.connection",
@@ -1047,7 +1107,7 @@ var Peer = class {
1047
1107
  initiator
1048
1108
  }, {
1049
1109
  F: __dxlog_file3,
1050
- L: 244,
1110
+ L: 274,
1051
1111
  S: this,
1052
1112
  C: (f, a) => f(...a)
1053
1113
  });
@@ -1060,14 +1120,14 @@ var Peer = class {
1060
1120
  initiator
1061
1121
  }, {
1062
1122
  F: __dxlog_file3,
1063
- L: 253,
1123
+ L: 283,
1064
1124
  S: this,
1065
1125
  C: (f, a) => f(...a)
1066
1126
  });
1067
1127
  this._connectionLimiter.doneConnecting(sessionId);
1068
1128
  invariant3(this.connection === connection, "Connection mismatch (race condition).", {
1069
1129
  F: __dxlog_file3,
1070
- L: 258,
1130
+ L: 288,
1071
1131
  S: this,
1072
1132
  A: [
1073
1133
  "this.connection === connection",
@@ -1082,7 +1142,7 @@ var Peer = class {
1082
1142
  initiator
1083
1143
  }, {
1084
1144
  F: __dxlog_file3,
1085
- L: 260,
1145
+ L: 290,
1086
1146
  S: this,
1087
1147
  C: (f, a) => f(...a)
1088
1148
  });
@@ -1096,7 +1156,7 @@ var Peer = class {
1096
1156
  this._availableAfter = increaseInterval(this._availableAfter);
1097
1157
  }
1098
1158
  this._callbacks.onDisconnected();
1099
- scheduleTask(this._connectionCtx, () => {
1159
+ scheduleTask2(this._connectionCtx, () => {
1100
1160
  this.availableToConnect = true;
1101
1161
  this._callbacks.onPeerAvailable();
1102
1162
  }, this._availableAfter);
@@ -1109,7 +1169,7 @@ var Peer = class {
1109
1169
  void this._connectionCtx?.dispose();
1110
1170
  this._connectionCtx = this._ctx.derive();
1111
1171
  connection.errors.handle((err) => {
1112
- log3.warn("connection error", {
1172
+ log3.warn("connection error, closing", {
1113
1173
  topic: this.topic,
1114
1174
  peerId: this.localPeerId,
1115
1175
  remoteId: this.id,
@@ -1117,7 +1177,7 @@ var Peer = class {
1117
1177
  err
1118
1178
  }, {
1119
1179
  F: __dxlog_file3,
1120
- L: 300,
1180
+ L: 330,
1121
1181
  S: this,
1122
1182
  C: (f, a) => f(...a)
1123
1183
  });
@@ -1130,7 +1190,7 @@ var Peer = class {
1130
1190
  err
1131
1191
  }, {
1132
1192
  F: __dxlog_file3,
1133
- L: 301,
1193
+ L: 337,
1134
1194
  S: this,
1135
1195
  C: (f, a) => f(...a)
1136
1196
  });
@@ -1149,7 +1209,7 @@ var Peer = class {
1149
1209
  sessionId: connection.sessionId
1150
1210
  }, {
1151
1211
  F: __dxlog_file3,
1152
- L: 326,
1212
+ L: 362,
1153
1213
  S: this,
1154
1214
  C: (f, a) => f(...a)
1155
1215
  });
@@ -1159,7 +1219,7 @@ var Peer = class {
1159
1219
  sessionId: connection.sessionId
1160
1220
  }, {
1161
1221
  F: __dxlog_file3,
1162
- L: 332,
1222
+ L: 368,
1163
1223
  S: this,
1164
1224
  C: (f, a) => f(...a)
1165
1225
  });
@@ -1170,7 +1230,7 @@ var Peer = class {
1170
1230
  message
1171
1231
  }, {
1172
1232
  F: __dxlog_file3,
1173
- L: 337,
1233
+ L: 373,
1174
1234
  S: this,
1175
1235
  C: (f, a) => f(...a)
1176
1236
  });
@@ -1178,18 +1238,18 @@ var Peer = class {
1178
1238
  }
1179
1239
  await this.connection.signal(message);
1180
1240
  }
1181
- async destroy() {
1241
+ async destroy(reason) {
1182
1242
  await this._ctx.dispose();
1183
1243
  log3("Destroying peer", {
1184
1244
  peerId: this.id,
1185
1245
  topic: this.topic
1186
1246
  }, {
1187
1247
  F: __dxlog_file3,
1188
- L: 347,
1248
+ L: 383,
1189
1249
  S: this,
1190
1250
  C: (f, a) => f(...a)
1191
1251
  });
1192
- await this?.connection?.close();
1252
+ await this?.connection?.close(reason);
1193
1253
  }
1194
1254
  };
1195
1255
  _ts_decorate2([
@@ -1219,7 +1279,7 @@ function _ts_decorate3(decorators, target, key, desc) {
1219
1279
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1220
1280
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1221
1281
  }
1222
- var __dxlog_file4 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/swarm.ts";
1282
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts";
1223
1283
  var INITIATION_DELAY = 100;
1224
1284
  var getClassName = (obj) => Object.getPrototypeOf(obj).constructor.name;
1225
1285
  var Swarm = class {
@@ -1330,7 +1390,7 @@ var Swarm = class {
1330
1390
  this._listeningHandle = void 0;
1331
1391
  await this._ctx.dispose();
1332
1392
  await this._topology.destroy();
1333
- await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key)));
1393
+ await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key, "swarm destroyed")));
1334
1394
  log4("destroyed", void 0, {
1335
1395
  F: __dxlog_file4,
1336
1396
  L: 148,
@@ -1402,13 +1462,22 @@ var Swarm = class {
1402
1462
  if (peer) {
1403
1463
  peer.advertizing = false;
1404
1464
  if (peer.connection?.state !== ConnectionState.CONNECTED) {
1405
- void this._destroyPeer(peer.id).catch((err) => log4.catch(err, void 0, {
1465
+ void this._destroyPeer(peer.id, "peer left").catch((err) => log4.catch(err, void 0, {
1406
1466
  F: __dxlog_file4,
1407
1467
  L: 189,
1408
1468
  S: this,
1409
1469
  C: (f, a) => f(...a)
1410
1470
  }));
1411
1471
  }
1472
+ } else {
1473
+ log4("received peerLeft but no peer found", {
1474
+ peer: swarmEvent.peerLeft.peer
1475
+ }, {
1476
+ F: __dxlog_file4,
1477
+ L: 192,
1478
+ S: this,
1479
+ C: (f, a) => f(...a)
1480
+ });
1412
1481
  }
1413
1482
  }
1414
1483
  this._topology.update();
@@ -1418,14 +1487,14 @@ var Swarm = class {
1418
1487
  message
1419
1488
  }, {
1420
1489
  F: __dxlog_file4,
1421
- L: 199,
1490
+ L: 201,
1422
1491
  S: this,
1423
1492
  C: (f, a) => f(...a)
1424
1493
  });
1425
1494
  if (this._ctx.disposed) {
1426
1495
  log4("ignored for disposed swarm", void 0, {
1427
1496
  F: __dxlog_file4,
1428
- L: 201,
1497
+ L: 203,
1429
1498
  S: this,
1430
1499
  C: (f, a) => f(...a)
1431
1500
  });
@@ -1435,7 +1504,7 @@ var Swarm = class {
1435
1504
  }
1436
1505
  invariant4(message.author, void 0, {
1437
1506
  F: __dxlog_file4,
1438
- L: 206,
1507
+ L: 208,
1439
1508
  S: this,
1440
1509
  A: [
1441
1510
  "message.author",
@@ -1447,7 +1516,7 @@ var Swarm = class {
1447
1516
  message
1448
1517
  }, {
1449
1518
  F: __dxlog_file4,
1450
- L: 208,
1519
+ L: 210,
1451
1520
  S: this,
1452
1521
  C: (f, a) => f(...a)
1453
1522
  });
@@ -1460,7 +1529,7 @@ var Swarm = class {
1460
1529
  message
1461
1530
  }, {
1462
1531
  F: __dxlog_file4,
1463
- L: 212,
1532
+ L: 214,
1464
1533
  S: this,
1465
1534
  C: (f, a) => f(...a)
1466
1535
  });
@@ -1478,14 +1547,14 @@ var Swarm = class {
1478
1547
  message
1479
1548
  }, {
1480
1549
  F: __dxlog_file4,
1481
- L: 223,
1550
+ L: 225,
1482
1551
  S: this,
1483
1552
  C: (f, a) => f(...a)
1484
1553
  });
1485
1554
  if (this._ctx.disposed) {
1486
1555
  log4.info("ignored for offline swarm", void 0, {
1487
1556
  F: __dxlog_file4,
1488
- L: 225,
1557
+ L: 227,
1489
1558
  S: this,
1490
1559
  C: (f, a) => f(...a)
1491
1560
  });
@@ -1493,7 +1562,7 @@ var Swarm = class {
1493
1562
  }
1494
1563
  invariant4(message.recipient?.equals(this._ownPeerId), `Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`, {
1495
1564
  F: __dxlog_file4,
1496
- L: 228,
1565
+ L: 230,
1497
1566
  S: this,
1498
1567
  A: [
1499
1568
  "message.recipient?.equals(this._ownPeerId)",
@@ -1502,7 +1571,7 @@ var Swarm = class {
1502
1571
  });
1503
1572
  invariant4(message.topic?.equals(this._topic), void 0, {
1504
1573
  F: __dxlog_file4,
1505
- L: 232,
1574
+ L: 234,
1506
1575
  S: this,
1507
1576
  A: [
1508
1577
  "message.topic?.equals(this._topic)",
@@ -1511,7 +1580,7 @@ var Swarm = class {
1511
1580
  });
1512
1581
  invariant4(message.author, void 0, {
1513
1582
  F: __dxlog_file4,
1514
- L: 233,
1583
+ L: 235,
1515
1584
  S: this,
1516
1585
  A: [
1517
1586
  "message.author",
@@ -1526,7 +1595,7 @@ var Swarm = class {
1526
1595
  await this._ctx.dispose();
1527
1596
  await Promise.all([
1528
1597
  ...this._peers.keys()
1529
- ].map((peerId) => this._destroyPeer(peerId)));
1598
+ ].map((peerId) => this._destroyPeer(peerId, "goOffline")));
1530
1599
  }
1531
1600
  // For debug purposes
1532
1601
  async goOnline() {
@@ -1544,14 +1613,22 @@ var Swarm = class {
1544
1613
  },
1545
1614
  onDisconnected: async () => {
1546
1615
  if (!peer.advertizing) {
1547
- await this._destroyPeer(peer.id);
1616
+ await this._destroyPeer(peer.id, "peer disconnected");
1548
1617
  }
1549
1618
  this.disconnected.emit(peerId);
1550
1619
  this._topology.update();
1551
1620
  },
1552
1621
  onRejected: () => {
1553
1622
  if (this._peers.has(peerId)) {
1554
- void this._destroyPeer(peerId);
1623
+ log4("peer rejected connection", {
1624
+ peerId
1625
+ }, {
1626
+ F: __dxlog_file4,
1627
+ L: 284,
1628
+ S: this,
1629
+ C: (f, a) => f(...a)
1630
+ });
1631
+ void this._destroyPeer(peerId, "peer rejected connection");
1555
1632
  }
1556
1633
  },
1557
1634
  onAccepted: () => {
@@ -1568,17 +1645,17 @@ var Swarm = class {
1568
1645
  }
1569
1646
  return peer;
1570
1647
  }
1571
- async _destroyPeer(peerId) {
1648
+ async _destroyPeer(peerId, reason) {
1572
1649
  invariant4(this._peers.has(peerId), void 0, {
1573
1650
  F: __dxlog_file4,
1574
- L: 303,
1651
+ L: 306,
1575
1652
  S: this,
1576
1653
  A: [
1577
1654
  "this._peers.has(peerId)",
1578
1655
  ""
1579
1656
  ]
1580
1657
  });
1581
- await this._peers.get(peerId).destroy();
1658
+ await this._peers.get(peerId).destroy(new Error(reason));
1582
1659
  this._peers.delete(peerId);
1583
1660
  }
1584
1661
  _getSwarmController() {
@@ -1592,13 +1669,13 @@ var Swarm = class {
1592
1669
  if (this._ctx.disposed) {
1593
1670
  return;
1594
1671
  }
1595
- scheduleTask2(this._ctx, async () => {
1672
+ scheduleTask3(this._ctx, async () => {
1596
1673
  try {
1597
1674
  await this._initiateConnection(peer);
1598
1675
  } catch (err) {
1599
1676
  log4("initiation error", err, {
1600
1677
  F: __dxlog_file4,
1601
- L: 329,
1678
+ L: 332,
1602
1679
  S: this,
1603
1680
  C: (f, a) => f(...a)
1604
1681
  });
@@ -1609,7 +1686,7 @@ var Swarm = class {
1609
1686
  if (this._ctx.disposed) {
1610
1687
  return;
1611
1688
  }
1612
- scheduleTask2(this._ctx, async () => {
1689
+ scheduleTask3(this._ctx, async () => {
1613
1690
  await this._closeConnection(peer);
1614
1691
  this._topology.update();
1615
1692
  });
@@ -1626,7 +1703,7 @@ var Swarm = class {
1626
1703
  remoteId
1627
1704
  }, {
1628
1705
  F: __dxlog_file4,
1629
- L: 356,
1706
+ L: 359,
1630
1707
  S: this,
1631
1708
  C: (f, a) => f(...a)
1632
1709
  });
@@ -1643,7 +1720,7 @@ var Swarm = class {
1643
1720
  remoteId
1644
1721
  }, {
1645
1722
  F: __dxlog_file4,
1646
- L: 370,
1723
+ L: 373,
1647
1724
  S: this,
1648
1725
  C: (f, a) => f(...a)
1649
1726
  });
@@ -1653,7 +1730,7 @@ var Swarm = class {
1653
1730
  remoteId
1654
1731
  }, {
1655
1732
  F: __dxlog_file4,
1656
- L: 373,
1733
+ L: 376,
1657
1734
  S: this,
1658
1735
  C: (f, a) => f(...a)
1659
1736
  });
@@ -1693,7 +1770,7 @@ import { Event as Event4, EventSubscriptions } from "@dxos/async";
1693
1770
  import { PublicKey as PublicKey5 } from "@dxos/keys";
1694
1771
  import { log as log5 } from "@dxos/log";
1695
1772
  import { ComplexMap as ComplexMap3 } from "@dxos/util";
1696
- var __dxlog_file5 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
1773
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
1697
1774
  var SwarmMapper = class {
1698
1775
  get peers() {
1699
1776
  return Array.from(this._peers.values());
@@ -1765,7 +1842,7 @@ import { PublicKey as PublicKey6 } from "@dxos/keys";
1765
1842
  import { log as log6 } from "@dxos/log";
1766
1843
  import { CancelledError as CancelledError3 } from "@dxos/protocols";
1767
1844
  import { ComplexMap as ComplexMap4 } from "@dxos/util";
1768
- var __dxlog_file6 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
1845
+ var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
1769
1846
  var MAX_CONCURRENT_INITIATING_CONNECTIONS = 50;
1770
1847
  var ConnectionLimiter = class {
1771
1848
  constructor({ maxConcurrentInitConnections = MAX_CONCURRENT_INITIATING_CONNECTIONS } = {}) {
@@ -1918,7 +1995,7 @@ import { Messenger } from "@dxos/messaging";
1918
1995
  import { trace as trace3 } from "@dxos/protocols";
1919
1996
  import { ConnectionState as ConnectionState2 } from "@dxos/protocols/proto/dxos/client/services";
1920
1997
  import { ComplexMap as ComplexMap6 } from "@dxos/util";
1921
- var __dxlog_file7 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/network-manager.ts";
1998
+ var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts";
1922
1999
  var NetworkManager = class {
1923
2000
  constructor({ transportFactory, signalManager, log: log1 }) {
1924
2001
  /**
@@ -2154,7 +2231,7 @@ var NetworkManager = class {
2154
2231
 
2155
2232
  // packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts
2156
2233
  import { invariant as invariant7 } from "@dxos/invariant";
2157
- var __dxlog_file8 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
2234
+ var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
2158
2235
  var FullyConnectedTopology = class {
2159
2236
  toString() {
2160
2237
  return "FullyConnectedTopology";
@@ -2197,7 +2274,7 @@ var FullyConnectedTopology = class {
2197
2274
  import distance from "xor-distance";
2198
2275
  import { invariant as invariant8 } from "@dxos/invariant";
2199
2276
  import { log as log8 } from "@dxos/log";
2200
- var __dxlog_file9 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/topology/mmst-topology.ts";
2277
+ var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/mmst-topology.ts";
2201
2278
  var MMSTTopology = class {
2202
2279
  constructor({ originateConnections = 2, maxPeers = 4, sampleSize = 10 } = {}) {
2203
2280
  this._sampleCollected = false;
@@ -2306,7 +2383,7 @@ var sortByXorDistance = (keys, reference) => keys.sort((a, b) => distance.gt(dis
2306
2383
  // packages/core/mesh/network-manager/src/topology/star-topology.ts
2307
2384
  import { invariant as invariant9 } from "@dxos/invariant";
2308
2385
  import { log as log9 } from "@dxos/log";
2309
- var __dxlog_file10 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/topology/star-topology.ts";
2386
+ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/star-topology.ts";
2310
2387
  var StarTopology = class {
2311
2388
  constructor(_centralPeer) {
2312
2389
  this._centralPeer = _centralPeer;
@@ -2417,7 +2494,7 @@ function _ts_decorate4(decorators, target, key, desc) {
2417
2494
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2418
2495
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2419
2496
  }
2420
- var __dxlog_file11 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
2497
+ var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
2421
2498
  var MEMORY_TRANSPORT_DELAY = 1;
2422
2499
  var createStreamDelay = (delay) => {
2423
2500
  return new Transform({
@@ -2612,7 +2689,7 @@ try {
2612
2689
  }
2613
2690
 
2614
2691
  // packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts
2615
- var __dxlog_file12 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts";
2692
+ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts";
2616
2693
  var SimplePeerTransport = class {
2617
2694
  constructor(params) {
2618
2695
  this.params = params;
@@ -2801,7 +2878,7 @@ import { PublicKey as PublicKey11 } from "@dxos/keys";
2801
2878
  import { log as log12 } from "@dxos/log";
2802
2879
  import { ConnectionState as ConnectionState3 } from "@dxos/protocols/proto/dxos/mesh/bridge";
2803
2880
  import { ComplexMap as ComplexMap8 } from "@dxos/util";
2804
- var __dxlog_file13 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/simplepeer-transport-service.ts";
2881
+ var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport-service.ts";
2805
2882
  var SimplePeerTransportService = class {
2806
2883
  constructor(_webrtcConfig) {
2807
2884
  this._webrtcConfig = _webrtcConfig;
@@ -2941,10 +3018,10 @@ import { ErrorStream as ErrorStream5 } from "@dxos/debug";
2941
3018
  import { invariant as invariant13 } from "@dxos/invariant";
2942
3019
  import { PublicKey as PublicKey12 } from "@dxos/keys";
2943
3020
  import { log as log13 } from "@dxos/log";
2944
- import { ConnectionResetError as ConnectionResetError3, TimeoutError as TimeoutError2, ProtocolError as ProtocolError3, ConnectivityError as ConnectivityError3, UnknownProtocolError as UnknownProtocolError3 } from "@dxos/protocols";
3021
+ import { ConnectionResetError as ConnectionResetError3, TimeoutError, ProtocolError as ProtocolError3, ConnectivityError as ConnectivityError3, UnknownProtocolError as UnknownProtocolError3 } from "@dxos/protocols";
2945
3022
  import { ConnectionState as ConnectionState4 } from "@dxos/protocols/proto/dxos/mesh/bridge";
2946
3023
  import { arrayToBuffer } from "@dxos/util";
2947
- var __dxlog_file14 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/simplepeer-transport-proxy.ts";
3024
+ var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport-proxy.ts";
2948
3025
  var SimplePeerTransportProxy = class {
2949
3026
  constructor(_params) {
2950
3027
  this._params = _params;
@@ -3094,7 +3171,7 @@ var decodeError = (err) => {
3094
3171
  if (message.includes("CONNECTION_RESET")) {
3095
3172
  return new ConnectionResetError3(message);
3096
3173
  } else if (message.includes("TIMEOUT")) {
3097
- return new TimeoutError2(message);
3174
+ return new TimeoutError(message);
3098
3175
  } else if (message.includes("PROTOCOL_ERROR")) {
3099
3176
  return new ProtocolError3(message);
3100
3177
  } else if (message.includes("CONNECTIVITY_ERROR")) {
@@ -3121,7 +3198,7 @@ function _ts_decorate5(decorators, target, key, desc) {
3121
3198
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3122
3199
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3123
3200
  }
3124
- var __dxlog_file15 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/libdatachannel-transport.ts";
3201
+ var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/libdatachannel-transport.ts";
3125
3202
  var DATACHANNEL_LABEL = "dxos.mesh.transport";
3126
3203
  var MAX_BUFFERED_AMOUNT = 64 * 1024;
3127
3204
  var MAX_MESSAGE_SIZE = 64 * 1024;
@@ -3514,4 +3591,4 @@ export {
3514
3591
  TcpTransport,
3515
3592
  createTeleportProtocolFactory
3516
3593
  };
3517
- //# sourceMappingURL=chunk-LN6AHVN6.mjs.map
3594
+ //# sourceMappingURL=chunk-54UAGQNZ.mjs.map