@dxos/network-manager 0.3.1-main.5e68e9d → 0.3.1-main.b9bb100

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, scheduleTask, synchronized } from "@dxos/async";
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
10
  import { invariant } from "@dxos/invariant";
@@ -23,7 +23,6 @@ function _ts_decorate(decorators, target, key, desc) {
23
23
  }
24
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;
27
26
  var MAX_SIGNALLING_DELAY = 300;
28
27
  var ConnectionState;
29
28
  (function(ConnectionState5) {
@@ -79,7 +78,6 @@ var Connection = class {
79
78
  this._transportFactory = _transportFactory;
80
79
  this._callbacks = _callbacks;
81
80
  this._ctx = new Context();
82
- this.connectedTimeoutContext = new Context();
83
81
  this._state = ConnectionState.CREATED;
84
82
  this._incomingSignalBuffer = [];
85
83
  this._outgoingSignalBuffer = [];
@@ -98,7 +96,7 @@ var Connection = class {
98
96
  initiator: this.initiator
99
97
  }, {
100
98
  F: __dxlog_file,
101
- L: 129,
99
+ L: 123,
102
100
  S: this,
103
101
  C: (f, a) => f(...a)
104
102
  });
@@ -118,7 +116,7 @@ var Connection = class {
118
116
  async openConnection() {
119
117
  invariant(this._state === ConnectionState.INITIAL, "Invalid state.", {
120
118
  F: __dxlog_file,
121
- L: 154,
119
+ L: 148,
122
120
  S: this,
123
121
  A: [
124
122
  "this._state === ConnectionState.INITIAL",
@@ -129,7 +127,7 @@ var Connection = class {
129
127
  id: this._instanceId
130
128
  }), {
131
129
  F: __dxlog_file,
132
- L: 155,
130
+ L: 149,
133
131
  S: this,
134
132
  C: (f, a) => f(...a)
135
133
  });
@@ -141,7 +139,7 @@ var Connection = class {
141
139
  initiator: this.initiator
142
140
  }, {
143
141
  F: __dxlog_file,
144
- L: 156,
142
+ L: 150,
145
143
  S: this,
146
144
  C: (f, a) => f(...a)
147
145
  });
@@ -152,24 +150,15 @@ var Connection = class {
152
150
  this._protocol.stream.on("close", () => {
153
151
  log("protocol stream closed", void 0, {
154
152
  F: __dxlog_file,
155
- L: 173,
153
+ L: 167,
156
154
  S: this,
157
155
  C: (f, a) => f(...a)
158
156
  });
159
157
  this.close(new ProtocolError("protocol stream closed")).catch((err) => this.errors.raise(err));
160
158
  });
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);
170
159
  invariant(!this._transport, void 0, {
171
160
  F: __dxlog_file,
172
- L: 186,
161
+ L: 171,
173
162
  S: this,
174
163
  A: [
175
164
  "!this._transport",
@@ -181,27 +170,26 @@ var Connection = class {
181
170
  stream: this._protocol.stream,
182
171
  sendSignal: async (signal) => this._sendSignal(signal)
183
172
  });
184
- this._transport.connected.once(async () => {
173
+ this._transport.connected.once(() => {
185
174
  this._changeState(ConnectionState.CONNECTED);
186
- await this.connectedTimeoutContext.dispose();
187
175
  this._callbacks?.onConnected?.();
188
176
  });
189
177
  this._transport.closed.once(() => {
190
178
  this._transport = void 0;
191
179
  log("abort triggered by transport close", void 0, {
192
180
  F: __dxlog_file,
193
- L: 201,
181
+ L: 185,
194
182
  S: this,
195
183
  C: (f, a) => f(...a)
196
184
  });
197
185
  this.abort().catch((err) => this.errors.raise(err));
198
186
  });
199
- this._transport.errors.handle(async (err) => {
187
+ this._transport.errors.handle((err) => {
200
188
  log("transport error:", {
201
189
  err
202
190
  }, {
203
191
  F: __dxlog_file,
204
- L: 206,
192
+ L: 190,
205
193
  S: this,
206
194
  C: (f, a) => f(...a)
207
195
  });
@@ -211,7 +199,7 @@ var Connection = class {
211
199
  if (err instanceof ConnectionResetError) {
212
200
  log.warn("aborting due to transport ConnectionResetError", void 0, {
213
201
  F: __dxlog_file,
214
- L: 213,
202
+ L: 197,
215
203
  S: this,
216
204
  C: (f, a) => f(...a)
217
205
  });
@@ -219,7 +207,7 @@ var Connection = class {
219
207
  } else if (err instanceof ConnectivityError) {
220
208
  log.warn("aborting due to transport ConnectivityError", void 0, {
221
209
  F: __dxlog_file,
222
- L: 216,
210
+ L: 200,
223
211
  S: this,
224
212
  C: (f, a) => f(...a)
225
213
  });
@@ -229,13 +217,12 @@ var Connection = class {
229
217
  err
230
218
  }, {
231
219
  F: __dxlog_file,
232
- L: 219,
220
+ L: 203,
233
221
  S: this,
234
222
  C: (f, a) => f(...a)
235
223
  });
236
224
  }
237
225
  if (this._state !== ConnectionState.CLOSED && this._state !== ConnectionState.CLOSING) {
238
- await this.connectedTimeoutContext.dispose();
239
226
  this.errors.raise(err);
240
227
  }
241
228
  });
@@ -247,7 +234,7 @@ var Connection = class {
247
234
  id: this._instanceId
248
235
  }), {
249
236
  F: __dxlog_file,
250
- L: 235,
237
+ L: 218,
251
238
  S: this,
252
239
  C: (f, a) => f(...a)
253
240
  });
@@ -257,20 +244,19 @@ var Connection = class {
257
244
  err
258
245
  }, {
259
246
  F: __dxlog_file,
260
- L: 242,
247
+ L: 225,
261
248
  S: this,
262
249
  C: (f, a) => f(...a)
263
250
  });
264
251
  if (this._state === ConnectionState.CLOSED || this._state === ConnectionState.ABORTED) {
265
252
  log(`abort ignored: already ${this._state}`, this.closeReason, {
266
253
  F: __dxlog_file,
267
- L: 244,
254
+ L: 227,
268
255
  S: this,
269
256
  C: (f, a) => f(...a)
270
257
  });
271
258
  return;
272
259
  }
273
- await this.connectedTimeoutContext.dispose();
274
260
  this._changeState(ConnectionState.ABORTING);
275
261
  if (!this.closeReason) {
276
262
  this.closeReason = err?.message;
@@ -281,7 +267,7 @@ var Connection = class {
281
267
  proto: this._protocol
282
268
  }, {
283
269
  F: __dxlog_file,
284
- L: 258,
270
+ L: 240,
285
271
  S: this,
286
272
  C: (f, a) => f(...a)
287
273
  });
@@ -289,7 +275,7 @@ var Connection = class {
289
275
  } catch (err2) {
290
276
  log.catch(err2, void 0, {
291
277
  F: __dxlog_file,
292
- L: 261,
278
+ L: 243,
293
279
  S: this,
294
280
  C: (f, a) => f(...a)
295
281
  });
@@ -299,7 +285,7 @@ var Connection = class {
299
285
  } catch (err2) {
300
286
  log.catch(err2, void 0, {
301
287
  F: __dxlog_file,
302
- L: 268,
288
+ L: 250,
303
289
  S: this,
304
290
  C: (f, a) => f(...a)
305
291
  });
@@ -309,7 +295,7 @@ var Connection = class {
309
295
  } catch (err2) {
310
296
  log.catch(err2, void 0, {
311
297
  F: __dxlog_file,
312
- L: 274,
298
+ L: 256,
313
299
  S: this,
314
300
  C: (f, a) => f(...a)
315
301
  });
@@ -319,21 +305,18 @@ var Connection = class {
319
305
  async close(err) {
320
306
  if (!this.closeReason) {
321
307
  this.closeReason = err?.message;
322
- } else {
323
- this.closeReason += `; ${err?.message}`;
324
308
  }
325
309
  if (this._state === ConnectionState.CLOSED || this._state === ConnectionState.ABORTING || this._state === ConnectionState.ABORTED) {
326
310
  return;
327
311
  }
328
312
  const lastState = this._state;
329
313
  this._changeState(ConnectionState.CLOSING);
330
- await this.connectedTimeoutContext.dispose();
331
314
  await this._ctx.dispose();
332
315
  log("closing...", {
333
316
  peerId: this.ownId
334
317
  }, {
335
318
  F: __dxlog_file,
336
- L: 299,
319
+ L: 278,
337
320
  S: this,
338
321
  C: (f, a) => f(...a)
339
322
  });
@@ -343,7 +326,7 @@ var Connection = class {
343
326
  } catch (err2) {
344
327
  log.catch(err2, void 0, {
345
328
  F: __dxlog_file,
346
- L: 306,
329
+ L: 285,
347
330
  S: this,
348
331
  C: (f, a) => f(...a)
349
332
  });
@@ -353,7 +336,7 @@ var Connection = class {
353
336
  } catch (err2) {
354
337
  log.catch(err2, void 0, {
355
338
  F: __dxlog_file,
356
- L: 313,
339
+ L: 292,
357
340
  S: this,
358
341
  C: (f, a) => f(...a)
359
342
  });
@@ -363,7 +346,7 @@ var Connection = class {
363
346
  peerId: this.ownId
364
347
  }, {
365
348
  F: __dxlog_file,
366
- L: 317,
349
+ L: 296,
367
350
  S: this,
368
351
  C: (f, a) => f(...a)
369
352
  });
@@ -399,14 +382,14 @@ var Connection = class {
399
382
  }
400
383
  });
401
384
  } catch (err) {
402
- if (err instanceof CancelledError || err instanceof Error && err.message?.includes("CANCELLED")) {
385
+ if (err instanceof CancelledError) {
403
386
  return;
404
387
  }
405
388
  log.warn("signal failed", {
406
389
  err
407
390
  }, {
408
391
  F: __dxlog_file,
409
- L: 355,
392
+ L: 333,
410
393
  S: this,
411
394
  C: (f, a) => f(...a)
412
395
  });
@@ -419,7 +402,7 @@ var Connection = class {
419
402
  async signal(msg) {
420
403
  invariant(msg.sessionId, void 0, {
421
404
  F: __dxlog_file,
422
- L: 364,
405
+ L: 342,
423
406
  S: this,
424
407
  A: [
425
408
  "msg.sessionId",
@@ -429,7 +412,7 @@ var Connection = class {
429
412
  if (!msg.sessionId.equals(this.sessionId)) {
430
413
  log("dropping signal for incorrect session id", void 0, {
431
414
  F: __dxlog_file,
432
- L: 366,
415
+ L: 344,
433
416
  S: this,
434
417
  C: (f, a) => f(...a)
435
418
  });
@@ -437,7 +420,7 @@ var Connection = class {
437
420
  }
438
421
  invariant(msg.data.signal || msg.data.signalBatch, void 0, {
439
422
  F: __dxlog_file,
440
- L: 369,
423
+ L: 347,
441
424
  S: this,
442
425
  A: [
443
426
  "msg.data.signal || msg.data.signalBatch",
@@ -446,7 +429,7 @@ var Connection = class {
446
429
  });
447
430
  invariant(msg.author?.equals(this.remoteId), void 0, {
448
431
  F: __dxlog_file,
449
- L: 370,
432
+ L: 348,
450
433
  S: this,
451
434
  A: [
452
435
  "msg.author?.equals(this.remoteId)",
@@ -455,7 +438,7 @@ var Connection = class {
455
438
  });
456
439
  invariant(msg.recipient?.equals(this.ownId), void 0, {
457
440
  F: __dxlog_file,
458
- L: 371,
441
+ L: 349,
459
442
  S: this,
460
443
  A: [
461
444
  "msg.recipient?.equals(this.ownId)",
@@ -479,7 +462,7 @@ var Connection = class {
479
462
  msg: msg.data
480
463
  }, {
481
464
  F: __dxlog_file,
482
- L: 380,
465
+ L: 358,
483
466
  S: this,
484
467
  C: (f, a) => f(...a)
485
468
  });
@@ -487,7 +470,7 @@ var Connection = class {
487
470
  } else {
488
471
  invariant(this._transport, "Connection not ready to accept signals.", {
489
472
  F: __dxlog_file,
490
- L: 383,
473
+ L: 361,
491
474
  S: this,
492
475
  A: [
493
476
  "this._transport",
@@ -500,7 +483,7 @@ var Connection = class {
500
483
  msg: msg.data
501
484
  }, {
502
485
  F: __dxlog_file,
503
- L: 384,
486
+ L: 362,
504
487
  S: this,
505
488
  C: (f, a) => f(...a)
506
489
  });
@@ -518,13 +501,13 @@ var Connection = class {
518
501
  peerId: this.ownId
519
502
  }, {
520
503
  F: __dxlog_file,
521
- L: 395,
504
+ L: 373,
522
505
  S: this,
523
506
  C: (f, a) => f(...a)
524
507
  });
525
508
  invariant(state !== this._state, "Already in this state.", {
526
509
  F: __dxlog_file,
527
- L: 396,
510
+ L: 374,
528
511
  S: this,
529
512
  A: [
530
513
  "state !== this._state",
@@ -775,7 +758,7 @@ var SwarmMessenger = class {
775
758
  };
776
759
 
777
760
  // packages/core/mesh/network-manager/src/swarm/swarm.ts
778
- import { Event as Event3, scheduleTask as scheduleTask3, sleep as sleep2, synchronized as synchronized3 } from "@dxos/async";
761
+ import { Event as Event3, scheduleTask as scheduleTask2, sleep as sleep2, synchronized as synchronized3 } from "@dxos/async";
779
762
  import { Context as Context4 } from "@dxos/context";
780
763
  import { ErrorStream as ErrorStream2 } from "@dxos/debug";
781
764
  import { invariant as invariant4 } from "@dxos/invariant";
@@ -785,12 +768,12 @@ import { trace as trace2 } from "@dxos/protocols";
785
768
  import { ComplexMap as ComplexMap2, isNotNullOrUndefined } from "@dxos/util";
786
769
 
787
770
  // packages/core/mesh/network-manager/src/swarm/peer.ts
788
- import { Event as Event2, scheduleTask as scheduleTask2, synchronized as synchronized2 } from "@dxos/async";
771
+ import { Event as Event2, scheduleTask, synchronized as synchronized2 } from "@dxos/async";
789
772
  import { Context as Context3 } from "@dxos/context";
790
773
  import { invariant as invariant3 } from "@dxos/invariant";
791
774
  import { PublicKey as PublicKey3 } from "@dxos/keys";
792
775
  import { log as log3 } from "@dxos/log";
793
- import { CancelledError as CancelledError2, SystemError } from "@dxos/protocols";
776
+ import { CancelledError as CancelledError2, SystemError, TimeoutError } from "@dxos/protocols";
794
777
  function _ts_decorate2(decorators, target, key, desc) {
795
778
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
796
779
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -833,12 +816,11 @@ var Peer = class {
833
816
  const remoteId = message.author;
834
817
  if (this.connection && ![
835
818
  ConnectionState.CREATED,
836
- ConnectionState.INITIAL,
837
- ConnectionState.CONNECTING
819
+ ConnectionState.INITIAL
838
820
  ].includes(this.connection.state)) {
839
821
  log3.info(`received offer when connection already in ${this.connection.state} state`, void 0, {
840
822
  F: __dxlog_file3,
841
- L: 115,
823
+ L: 112,
842
824
  S: this,
843
825
  C: (f, a) => f(...a)
844
826
  });
@@ -855,7 +837,7 @@ var Peer = class {
855
837
  sessionId: this.connection?.sessionId
856
838
  }, {
857
839
  F: __dxlog_file3,
858
- L: 124,
840
+ L: 121,
859
841
  S: this,
860
842
  C: (f, a) => f(...a)
861
843
  });
@@ -872,7 +854,7 @@ var Peer = class {
872
854
  if (!this.connection) {
873
855
  invariant3(message.sessionId, void 0, {
874
856
  F: __dxlog_file3,
875
- L: 144,
857
+ L: 141,
876
858
  S: this,
877
859
  A: [
878
860
  "message.sessionId",
@@ -893,7 +875,7 @@ var Peer = class {
893
875
  err
894
876
  }, {
895
877
  F: __dxlog_file3,
896
- L: 154,
878
+ L: 151,
897
879
  S: this,
898
880
  C: (f, a) => f(...a)
899
881
  });
@@ -915,7 +897,7 @@ var Peer = class {
915
897
  async initiateConnection() {
916
898
  invariant3(!this.initiating, "Initiation in progress.", {
917
899
  F: __dxlog_file3,
918
- L: 171,
900
+ L: 168,
919
901
  S: this,
920
902
  A: [
921
903
  "!this.initiating",
@@ -924,7 +906,7 @@ var Peer = class {
924
906
  });
925
907
  invariant3(!this.connection, "Already connected.", {
926
908
  F: __dxlog_file3,
927
- L: 172,
909
+ L: 169,
928
910
  S: this,
929
911
  A: [
930
912
  "!this.connection",
@@ -939,17 +921,16 @@ var Peer = class {
939
921
  sessionId
940
922
  }, {
941
923
  F: __dxlog_file3,
942
- L: 174,
924
+ L: 171,
943
925
  S: this,
944
926
  C: (f, a) => f(...a)
945
927
  });
946
928
  const connection = this._createConnection(true, sessionId);
947
929
  this.initiating = true;
948
- let answer;
949
930
  try {
950
931
  await this._connectionLimiter.connecting(sessionId);
951
932
  connection.initiate();
952
- answer = await this._signalMessaging.offer({
933
+ const answer = await this._signalMessaging.offer({
953
934
  author: this.localPeerId,
954
935
  recipient: this.id,
955
936
  sessionId,
@@ -965,87 +946,46 @@ var Peer = class {
965
946
  remoteId: this.id
966
947
  }, {
967
948
  F: __dxlog_file3,
968
- L: 191,
949
+ L: 187,
969
950
  S: this,
970
951
  C: (f, a) => f(...a)
971
952
  });
972
953
  if (connection.state !== ConnectionState.INITIAL) {
973
954
  log3("ignoring response", void 0, {
974
955
  F: __dxlog_file3,
975
- L: 193,
956
+ L: 189,
976
957
  S: this,
977
958
  C: (f, a) => f(...a)
978
959
  });
979
960
  return;
980
961
  }
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 {
999
962
  if (!answer.accept) {
1000
963
  this._callbacks.onRejected();
1001
964
  return;
1002
965
  }
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
- });
1027
966
  await connection.openConnection();
1028
967
  this._callbacks.onAccepted();
1029
968
  } catch (err) {
1030
- log3("initiation error: open connection", {
969
+ log3("initiation error", {
1031
970
  err,
1032
971
  topic: this.topic,
1033
972
  peerId: this.localPeerId,
1034
973
  remoteId: this.id
1035
974
  }, {
1036
975
  F: __dxlog_file3,
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,
976
+ L: 200,
1046
977
  S: this,
1047
978
  C: (f, a) => f(...a)
1048
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
+ }
1049
989
  await this.closeConnection(err);
1050
990
  throw err;
1051
991
  } finally {
@@ -1065,13 +1005,13 @@ var Peer = class {
1065
1005
  sessionId
1066
1006
  }, {
1067
1007
  F: __dxlog_file3,
1068
- L: 248,
1008
+ L: 218,
1069
1009
  S: this,
1070
1010
  C: (f, a) => f(...a)
1071
1011
  });
1072
1012
  invariant3(!this.connection, "Already connected.", {
1073
1013
  F: __dxlog_file3,
1074
- L: 255,
1014
+ L: 225,
1075
1015
  S: this,
1076
1016
  A: [
1077
1017
  "!this.connection",
@@ -1107,7 +1047,7 @@ var Peer = class {
1107
1047
  initiator
1108
1048
  }, {
1109
1049
  F: __dxlog_file3,
1110
- L: 274,
1050
+ L: 244,
1111
1051
  S: this,
1112
1052
  C: (f, a) => f(...a)
1113
1053
  });
@@ -1120,14 +1060,14 @@ var Peer = class {
1120
1060
  initiator
1121
1061
  }, {
1122
1062
  F: __dxlog_file3,
1123
- L: 283,
1063
+ L: 253,
1124
1064
  S: this,
1125
1065
  C: (f, a) => f(...a)
1126
1066
  });
1127
1067
  this._connectionLimiter.doneConnecting(sessionId);
1128
1068
  invariant3(this.connection === connection, "Connection mismatch (race condition).", {
1129
1069
  F: __dxlog_file3,
1130
- L: 288,
1070
+ L: 258,
1131
1071
  S: this,
1132
1072
  A: [
1133
1073
  "this.connection === connection",
@@ -1142,7 +1082,7 @@ var Peer = class {
1142
1082
  initiator
1143
1083
  }, {
1144
1084
  F: __dxlog_file3,
1145
- L: 290,
1085
+ L: 260,
1146
1086
  S: this,
1147
1087
  C: (f, a) => f(...a)
1148
1088
  });
@@ -1156,7 +1096,7 @@ var Peer = class {
1156
1096
  this._availableAfter = increaseInterval(this._availableAfter);
1157
1097
  }
1158
1098
  this._callbacks.onDisconnected();
1159
- scheduleTask2(this._connectionCtx, () => {
1099
+ scheduleTask(this._connectionCtx, () => {
1160
1100
  this.availableToConnect = true;
1161
1101
  this._callbacks.onPeerAvailable();
1162
1102
  }, this._availableAfter);
@@ -1169,7 +1109,7 @@ var Peer = class {
1169
1109
  void this._connectionCtx?.dispose();
1170
1110
  this._connectionCtx = this._ctx.derive();
1171
1111
  connection.errors.handle((err) => {
1172
- log3.warn("connection error, closing", {
1112
+ log3.warn("connection error", {
1173
1113
  topic: this.topic,
1174
1114
  peerId: this.localPeerId,
1175
1115
  remoteId: this.id,
@@ -1177,7 +1117,7 @@ var Peer = class {
1177
1117
  err
1178
1118
  }, {
1179
1119
  F: __dxlog_file3,
1180
- L: 330,
1120
+ L: 300,
1181
1121
  S: this,
1182
1122
  C: (f, a) => f(...a)
1183
1123
  });
@@ -1190,7 +1130,7 @@ var Peer = class {
1190
1130
  err
1191
1131
  }, {
1192
1132
  F: __dxlog_file3,
1193
- L: 337,
1133
+ L: 301,
1194
1134
  S: this,
1195
1135
  C: (f, a) => f(...a)
1196
1136
  });
@@ -1209,7 +1149,7 @@ var Peer = class {
1209
1149
  sessionId: connection.sessionId
1210
1150
  }, {
1211
1151
  F: __dxlog_file3,
1212
- L: 362,
1152
+ L: 326,
1213
1153
  S: this,
1214
1154
  C: (f, a) => f(...a)
1215
1155
  });
@@ -1219,7 +1159,7 @@ var Peer = class {
1219
1159
  sessionId: connection.sessionId
1220
1160
  }, {
1221
1161
  F: __dxlog_file3,
1222
- L: 368,
1162
+ L: 332,
1223
1163
  S: this,
1224
1164
  C: (f, a) => f(...a)
1225
1165
  });
@@ -1230,7 +1170,7 @@ var Peer = class {
1230
1170
  message
1231
1171
  }, {
1232
1172
  F: __dxlog_file3,
1233
- L: 373,
1173
+ L: 337,
1234
1174
  S: this,
1235
1175
  C: (f, a) => f(...a)
1236
1176
  });
@@ -1238,18 +1178,18 @@ var Peer = class {
1238
1178
  }
1239
1179
  await this.connection.signal(message);
1240
1180
  }
1241
- async destroy(reason) {
1181
+ async destroy() {
1242
1182
  await this._ctx.dispose();
1243
1183
  log3("Destroying peer", {
1244
1184
  peerId: this.id,
1245
1185
  topic: this.topic
1246
1186
  }, {
1247
1187
  F: __dxlog_file3,
1248
- L: 383,
1188
+ L: 347,
1249
1189
  S: this,
1250
1190
  C: (f, a) => f(...a)
1251
1191
  });
1252
- await this?.connection?.close(reason);
1192
+ await this?.connection?.close();
1253
1193
  }
1254
1194
  };
1255
1195
  _ts_decorate2([
@@ -1390,7 +1330,7 @@ var Swarm = class {
1390
1330
  this._listeningHandle = void 0;
1391
1331
  await this._ctx.dispose();
1392
1332
  await this._topology.destroy();
1393
- await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key, "swarm destroyed")));
1333
+ await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key)));
1394
1334
  log4("destroyed", void 0, {
1395
1335
  F: __dxlog_file4,
1396
1336
  L: 148,
@@ -1462,22 +1402,13 @@ var Swarm = class {
1462
1402
  if (peer) {
1463
1403
  peer.advertizing = false;
1464
1404
  if (peer.connection?.state !== ConnectionState.CONNECTED) {
1465
- void this._destroyPeer(peer.id, "peer left").catch((err) => log4.catch(err, void 0, {
1405
+ void this._destroyPeer(peer.id).catch((err) => log4.catch(err, void 0, {
1466
1406
  F: __dxlog_file4,
1467
1407
  L: 189,
1468
1408
  S: this,
1469
1409
  C: (f, a) => f(...a)
1470
1410
  }));
1471
1411
  }
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
- });
1481
1412
  }
1482
1413
  }
1483
1414
  this._topology.update();
@@ -1487,14 +1418,14 @@ var Swarm = class {
1487
1418
  message
1488
1419
  }, {
1489
1420
  F: __dxlog_file4,
1490
- L: 201,
1421
+ L: 199,
1491
1422
  S: this,
1492
1423
  C: (f, a) => f(...a)
1493
1424
  });
1494
1425
  if (this._ctx.disposed) {
1495
1426
  log4("ignored for disposed swarm", void 0, {
1496
1427
  F: __dxlog_file4,
1497
- L: 203,
1428
+ L: 201,
1498
1429
  S: this,
1499
1430
  C: (f, a) => f(...a)
1500
1431
  });
@@ -1504,7 +1435,7 @@ var Swarm = class {
1504
1435
  }
1505
1436
  invariant4(message.author, void 0, {
1506
1437
  F: __dxlog_file4,
1507
- L: 208,
1438
+ L: 206,
1508
1439
  S: this,
1509
1440
  A: [
1510
1441
  "message.author",
@@ -1516,7 +1447,7 @@ var Swarm = class {
1516
1447
  message
1517
1448
  }, {
1518
1449
  F: __dxlog_file4,
1519
- L: 210,
1450
+ L: 208,
1520
1451
  S: this,
1521
1452
  C: (f, a) => f(...a)
1522
1453
  });
@@ -1529,7 +1460,7 @@ var Swarm = class {
1529
1460
  message
1530
1461
  }, {
1531
1462
  F: __dxlog_file4,
1532
- L: 214,
1463
+ L: 212,
1533
1464
  S: this,
1534
1465
  C: (f, a) => f(...a)
1535
1466
  });
@@ -1547,14 +1478,14 @@ var Swarm = class {
1547
1478
  message
1548
1479
  }, {
1549
1480
  F: __dxlog_file4,
1550
- L: 225,
1481
+ L: 223,
1551
1482
  S: this,
1552
1483
  C: (f, a) => f(...a)
1553
1484
  });
1554
1485
  if (this._ctx.disposed) {
1555
1486
  log4.info("ignored for offline swarm", void 0, {
1556
1487
  F: __dxlog_file4,
1557
- L: 227,
1488
+ L: 225,
1558
1489
  S: this,
1559
1490
  C: (f, a) => f(...a)
1560
1491
  });
@@ -1562,7 +1493,7 @@ var Swarm = class {
1562
1493
  }
1563
1494
  invariant4(message.recipient?.equals(this._ownPeerId), `Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`, {
1564
1495
  F: __dxlog_file4,
1565
- L: 230,
1496
+ L: 228,
1566
1497
  S: this,
1567
1498
  A: [
1568
1499
  "message.recipient?.equals(this._ownPeerId)",
@@ -1571,7 +1502,7 @@ var Swarm = class {
1571
1502
  });
1572
1503
  invariant4(message.topic?.equals(this._topic), void 0, {
1573
1504
  F: __dxlog_file4,
1574
- L: 234,
1505
+ L: 232,
1575
1506
  S: this,
1576
1507
  A: [
1577
1508
  "message.topic?.equals(this._topic)",
@@ -1580,7 +1511,7 @@ var Swarm = class {
1580
1511
  });
1581
1512
  invariant4(message.author, void 0, {
1582
1513
  F: __dxlog_file4,
1583
- L: 235,
1514
+ L: 233,
1584
1515
  S: this,
1585
1516
  A: [
1586
1517
  "message.author",
@@ -1595,7 +1526,7 @@ var Swarm = class {
1595
1526
  await this._ctx.dispose();
1596
1527
  await Promise.all([
1597
1528
  ...this._peers.keys()
1598
- ].map((peerId) => this._destroyPeer(peerId, "goOffline")));
1529
+ ].map((peerId) => this._destroyPeer(peerId)));
1599
1530
  }
1600
1531
  // For debug purposes
1601
1532
  async goOnline() {
@@ -1613,22 +1544,14 @@ var Swarm = class {
1613
1544
  },
1614
1545
  onDisconnected: async () => {
1615
1546
  if (!peer.advertizing) {
1616
- await this._destroyPeer(peer.id, "peer disconnected");
1547
+ await this._destroyPeer(peer.id);
1617
1548
  }
1618
1549
  this.disconnected.emit(peerId);
1619
1550
  this._topology.update();
1620
1551
  },
1621
1552
  onRejected: () => {
1622
1553
  if (this._peers.has(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");
1554
+ void this._destroyPeer(peerId);
1632
1555
  }
1633
1556
  },
1634
1557
  onAccepted: () => {
@@ -1645,17 +1568,17 @@ var Swarm = class {
1645
1568
  }
1646
1569
  return peer;
1647
1570
  }
1648
- async _destroyPeer(peerId, reason) {
1571
+ async _destroyPeer(peerId) {
1649
1572
  invariant4(this._peers.has(peerId), void 0, {
1650
1573
  F: __dxlog_file4,
1651
- L: 306,
1574
+ L: 303,
1652
1575
  S: this,
1653
1576
  A: [
1654
1577
  "this._peers.has(peerId)",
1655
1578
  ""
1656
1579
  ]
1657
1580
  });
1658
- await this._peers.get(peerId).destroy(new Error(reason));
1581
+ await this._peers.get(peerId).destroy();
1659
1582
  this._peers.delete(peerId);
1660
1583
  }
1661
1584
  _getSwarmController() {
@@ -1669,13 +1592,13 @@ var Swarm = class {
1669
1592
  if (this._ctx.disposed) {
1670
1593
  return;
1671
1594
  }
1672
- scheduleTask3(this._ctx, async () => {
1595
+ scheduleTask2(this._ctx, async () => {
1673
1596
  try {
1674
1597
  await this._initiateConnection(peer);
1675
1598
  } catch (err) {
1676
1599
  log4("initiation error", err, {
1677
1600
  F: __dxlog_file4,
1678
- L: 332,
1601
+ L: 329,
1679
1602
  S: this,
1680
1603
  C: (f, a) => f(...a)
1681
1604
  });
@@ -1686,7 +1609,7 @@ var Swarm = class {
1686
1609
  if (this._ctx.disposed) {
1687
1610
  return;
1688
1611
  }
1689
- scheduleTask3(this._ctx, async () => {
1612
+ scheduleTask2(this._ctx, async () => {
1690
1613
  await this._closeConnection(peer);
1691
1614
  this._topology.update();
1692
1615
  });
@@ -1703,7 +1626,7 @@ var Swarm = class {
1703
1626
  remoteId
1704
1627
  }, {
1705
1628
  F: __dxlog_file4,
1706
- L: 359,
1629
+ L: 356,
1707
1630
  S: this,
1708
1631
  C: (f, a) => f(...a)
1709
1632
  });
@@ -1720,7 +1643,7 @@ var Swarm = class {
1720
1643
  remoteId
1721
1644
  }, {
1722
1645
  F: __dxlog_file4,
1723
- L: 373,
1646
+ L: 370,
1724
1647
  S: this,
1725
1648
  C: (f, a) => f(...a)
1726
1649
  });
@@ -1730,7 +1653,7 @@ var Swarm = class {
1730
1653
  remoteId
1731
1654
  }, {
1732
1655
  F: __dxlog_file4,
1733
- L: 376,
1656
+ L: 373,
1734
1657
  S: this,
1735
1658
  C: (f, a) => f(...a)
1736
1659
  });
@@ -3018,7 +2941,7 @@ import { ErrorStream as ErrorStream5 } from "@dxos/debug";
3018
2941
  import { invariant as invariant13 } from "@dxos/invariant";
3019
2942
  import { PublicKey as PublicKey12 } from "@dxos/keys";
3020
2943
  import { log as log13 } from "@dxos/log";
3021
- import { ConnectionResetError as ConnectionResetError3, TimeoutError, ProtocolError as ProtocolError3, ConnectivityError as ConnectivityError3, UnknownProtocolError as UnknownProtocolError3 } from "@dxos/protocols";
2944
+ import { ConnectionResetError as ConnectionResetError3, TimeoutError as TimeoutError2, ProtocolError as ProtocolError3, ConnectivityError as ConnectivityError3, UnknownProtocolError as UnknownProtocolError3 } from "@dxos/protocols";
3022
2945
  import { ConnectionState as ConnectionState4 } from "@dxos/protocols/proto/dxos/mesh/bridge";
3023
2946
  import { arrayToBuffer } from "@dxos/util";
3024
2947
  var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport-proxy.ts";
@@ -3171,7 +3094,7 @@ var decodeError = (err) => {
3171
3094
  if (message.includes("CONNECTION_RESET")) {
3172
3095
  return new ConnectionResetError3(message);
3173
3096
  } else if (message.includes("TIMEOUT")) {
3174
- return new TimeoutError(message);
3097
+ return new TimeoutError2(message);
3175
3098
  } else if (message.includes("PROTOCOL_ERROR")) {
3176
3099
  return new ProtocolError3(message);
3177
3100
  } else if (message.includes("CONNECTIVITY_ERROR")) {
@@ -3591,4 +3514,4 @@ export {
3591
3514
  TcpTransport,
3592
3515
  createTeleportProtocolFactory
3593
3516
  };
3594
- //# sourceMappingURL=chunk-54UAGQNZ.mjs.map
3517
+ //# sourceMappingURL=chunk-TRMX3E42.mjs.map