@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.
@@ -549,7 +549,7 @@ var createTeleportProtocolFactory = (onConnection) => {
549
549
  };
550
550
 
551
551
  // packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts
552
- var __dxlog_file = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts";
552
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts";
553
553
  var TestWireProtocol = class {
554
554
  constructor(peerId, _extensionFactory = () => []) {
555
555
  this.peerId = peerId;
@@ -666,8 +666,9 @@ function _ts_decorate(decorators, target, key, desc) {
666
666
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
667
667
  return c > 3 && r && Object.defineProperty(target, key, r), r;
668
668
  }
669
- var __dxlog_file2 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/connection.ts";
669
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts";
670
670
  var STARTING_SIGNALLING_DELAY = 10;
671
+ var TRANSPORT_CONNECTION_TIMEOUT = 1e4;
671
672
  var MAX_SIGNALLING_DELAY = 300;
672
673
  var ConnectionState;
673
674
  (function(ConnectionState6) {
@@ -723,6 +724,7 @@ var Connection = class {
723
724
  this._transportFactory = _transportFactory;
724
725
  this._callbacks = _callbacks;
725
726
  this._ctx = new import_context.Context();
727
+ this.connectedTimeoutContext = new import_context.Context();
726
728
  this._state = ConnectionState.CREATED;
727
729
  this._incomingSignalBuffer = [];
728
730
  this._outgoingSignalBuffer = [];
@@ -741,7 +743,7 @@ var Connection = class {
741
743
  initiator: this.initiator
742
744
  }, {
743
745
  F: __dxlog_file2,
744
- L: 123,
746
+ L: 129,
745
747
  S: this,
746
748
  C: (f, a) => f(...a)
747
749
  });
@@ -761,7 +763,7 @@ var Connection = class {
761
763
  async openConnection() {
762
764
  (0, import_invariant.invariant)(this._state === ConnectionState.INITIAL, "Invalid state.", {
763
765
  F: __dxlog_file2,
764
- L: 148,
766
+ L: 154,
765
767
  S: this,
766
768
  A: [
767
769
  "this._state === ConnectionState.INITIAL",
@@ -772,7 +774,7 @@ var Connection = class {
772
774
  id: this._instanceId
773
775
  }), {
774
776
  F: __dxlog_file2,
775
- L: 149,
777
+ L: 155,
776
778
  S: this,
777
779
  C: (f, a) => f(...a)
778
780
  });
@@ -784,7 +786,7 @@ var Connection = class {
784
786
  initiator: this.initiator
785
787
  }, {
786
788
  F: __dxlog_file2,
787
- L: 150,
789
+ L: 156,
788
790
  S: this,
789
791
  C: (f, a) => f(...a)
790
792
  });
@@ -795,15 +797,24 @@ var Connection = class {
795
797
  this._protocol.stream.on("close", () => {
796
798
  (0, import_log2.log)("protocol stream closed", void 0, {
797
799
  F: __dxlog_file2,
798
- L: 167,
800
+ L: 173,
799
801
  S: this,
800
802
  C: (f, a) => f(...a)
801
803
  });
802
804
  this.close(new import_protocols.ProtocolError("protocol stream closed")).catch((err) => this.errors.raise(err));
803
805
  });
806
+ (0, import_async2.scheduleTask)(this.connectedTimeoutContext, async () => {
807
+ import_log2.log.warn("timeout waiting for transport to connect, aborting", void 0, {
808
+ F: __dxlog_file2,
809
+ L: 180,
810
+ S: this,
811
+ C: (f, a) => f(...a)
812
+ });
813
+ await this.abort().catch((err) => this.errors.raise(err));
814
+ }, TRANSPORT_CONNECTION_TIMEOUT);
804
815
  (0, import_invariant.invariant)(!this._transport, void 0, {
805
816
  F: __dxlog_file2,
806
- L: 171,
817
+ L: 186,
807
818
  S: this,
808
819
  A: [
809
820
  "!this._transport",
@@ -815,26 +826,27 @@ var Connection = class {
815
826
  stream: this._protocol.stream,
816
827
  sendSignal: async (signal) => this._sendSignal(signal)
817
828
  });
818
- this._transport.connected.once(() => {
829
+ this._transport.connected.once(async () => {
819
830
  this._changeState(ConnectionState.CONNECTED);
831
+ await this.connectedTimeoutContext.dispose();
820
832
  this._callbacks?.onConnected?.();
821
833
  });
822
834
  this._transport.closed.once(() => {
823
835
  this._transport = void 0;
824
836
  (0, import_log2.log)("abort triggered by transport close", void 0, {
825
837
  F: __dxlog_file2,
826
- L: 185,
838
+ L: 201,
827
839
  S: this,
828
840
  C: (f, a) => f(...a)
829
841
  });
830
842
  this.abort().catch((err) => this.errors.raise(err));
831
843
  });
832
- this._transport.errors.handle((err) => {
844
+ this._transport.errors.handle(async (err) => {
833
845
  (0, import_log2.log)("transport error:", {
834
846
  err
835
847
  }, {
836
848
  F: __dxlog_file2,
837
- L: 190,
849
+ L: 206,
838
850
  S: this,
839
851
  C: (f, a) => f(...a)
840
852
  });
@@ -844,7 +856,7 @@ var Connection = class {
844
856
  if (err instanceof import_protocols.ConnectionResetError) {
845
857
  import_log2.log.warn("aborting due to transport ConnectionResetError", void 0, {
846
858
  F: __dxlog_file2,
847
- L: 197,
859
+ L: 213,
848
860
  S: this,
849
861
  C: (f, a) => f(...a)
850
862
  });
@@ -852,7 +864,7 @@ var Connection = class {
852
864
  } else if (err instanceof import_protocols.ConnectivityError) {
853
865
  import_log2.log.warn("aborting due to transport ConnectivityError", void 0, {
854
866
  F: __dxlog_file2,
855
- L: 200,
867
+ L: 216,
856
868
  S: this,
857
869
  C: (f, a) => f(...a)
858
870
  });
@@ -862,12 +874,13 @@ var Connection = class {
862
874
  err
863
875
  }, {
864
876
  F: __dxlog_file2,
865
- L: 203,
877
+ L: 219,
866
878
  S: this,
867
879
  C: (f, a) => f(...a)
868
880
  });
869
881
  }
870
882
  if (this._state !== ConnectionState.CLOSED && this._state !== ConnectionState.CLOSING) {
883
+ await this.connectedTimeoutContext.dispose();
871
884
  this.errors.raise(err);
872
885
  }
873
886
  });
@@ -879,7 +892,7 @@ var Connection = class {
879
892
  id: this._instanceId
880
893
  }), {
881
894
  F: __dxlog_file2,
882
- L: 218,
895
+ L: 235,
883
896
  S: this,
884
897
  C: (f, a) => f(...a)
885
898
  });
@@ -889,19 +902,20 @@ var Connection = class {
889
902
  err
890
903
  }, {
891
904
  F: __dxlog_file2,
892
- L: 225,
905
+ L: 242,
893
906
  S: this,
894
907
  C: (f, a) => f(...a)
895
908
  });
896
909
  if (this._state === ConnectionState.CLOSED || this._state === ConnectionState.ABORTED) {
897
910
  (0, import_log2.log)(`abort ignored: already ${this._state}`, this.closeReason, {
898
911
  F: __dxlog_file2,
899
- L: 227,
912
+ L: 244,
900
913
  S: this,
901
914
  C: (f, a) => f(...a)
902
915
  });
903
916
  return;
904
917
  }
918
+ await this.connectedTimeoutContext.dispose();
905
919
  this._changeState(ConnectionState.ABORTING);
906
920
  if (!this.closeReason) {
907
921
  this.closeReason = err?.message;
@@ -912,7 +926,7 @@ var Connection = class {
912
926
  proto: this._protocol
913
927
  }, {
914
928
  F: __dxlog_file2,
915
- L: 240,
929
+ L: 258,
916
930
  S: this,
917
931
  C: (f, a) => f(...a)
918
932
  });
@@ -920,7 +934,7 @@ var Connection = class {
920
934
  } catch (err2) {
921
935
  import_log2.log.catch(err2, void 0, {
922
936
  F: __dxlog_file2,
923
- L: 243,
937
+ L: 261,
924
938
  S: this,
925
939
  C: (f, a) => f(...a)
926
940
  });
@@ -930,7 +944,7 @@ var Connection = class {
930
944
  } catch (err2) {
931
945
  import_log2.log.catch(err2, void 0, {
932
946
  F: __dxlog_file2,
933
- L: 250,
947
+ L: 268,
934
948
  S: this,
935
949
  C: (f, a) => f(...a)
936
950
  });
@@ -940,7 +954,7 @@ var Connection = class {
940
954
  } catch (err2) {
941
955
  import_log2.log.catch(err2, void 0, {
942
956
  F: __dxlog_file2,
943
- L: 256,
957
+ L: 274,
944
958
  S: this,
945
959
  C: (f, a) => f(...a)
946
960
  });
@@ -950,18 +964,21 @@ var Connection = class {
950
964
  async close(err) {
951
965
  if (!this.closeReason) {
952
966
  this.closeReason = err?.message;
967
+ } else {
968
+ this.closeReason += `; ${err?.message}`;
953
969
  }
954
970
  if (this._state === ConnectionState.CLOSED || this._state === ConnectionState.ABORTING || this._state === ConnectionState.ABORTED) {
955
971
  return;
956
972
  }
957
973
  const lastState = this._state;
958
974
  this._changeState(ConnectionState.CLOSING);
975
+ await this.connectedTimeoutContext.dispose();
959
976
  await this._ctx.dispose();
960
977
  (0, import_log2.log)("closing...", {
961
978
  peerId: this.ownId
962
979
  }, {
963
980
  F: __dxlog_file2,
964
- L: 278,
981
+ L: 299,
965
982
  S: this,
966
983
  C: (f, a) => f(...a)
967
984
  });
@@ -971,7 +988,7 @@ var Connection = class {
971
988
  } catch (err2) {
972
989
  import_log2.log.catch(err2, void 0, {
973
990
  F: __dxlog_file2,
974
- L: 285,
991
+ L: 306,
975
992
  S: this,
976
993
  C: (f, a) => f(...a)
977
994
  });
@@ -981,7 +998,7 @@ var Connection = class {
981
998
  } catch (err2) {
982
999
  import_log2.log.catch(err2, void 0, {
983
1000
  F: __dxlog_file2,
984
- L: 292,
1001
+ L: 313,
985
1002
  S: this,
986
1003
  C: (f, a) => f(...a)
987
1004
  });
@@ -991,7 +1008,7 @@ var Connection = class {
991
1008
  peerId: this.ownId
992
1009
  }, {
993
1010
  F: __dxlog_file2,
994
- L: 296,
1011
+ L: 317,
995
1012
  S: this,
996
1013
  C: (f, a) => f(...a)
997
1014
  });
@@ -1027,14 +1044,14 @@ var Connection = class {
1027
1044
  }
1028
1045
  });
1029
1046
  } catch (err) {
1030
- if (err instanceof import_protocols.CancelledError) {
1047
+ if (err instanceof import_protocols.CancelledError || err instanceof Error && err.message?.includes("CANCELLED")) {
1031
1048
  return;
1032
1049
  }
1033
1050
  import_log2.log.warn("signal failed", {
1034
1051
  err
1035
1052
  }, {
1036
1053
  F: __dxlog_file2,
1037
- L: 333,
1054
+ L: 355,
1038
1055
  S: this,
1039
1056
  C: (f, a) => f(...a)
1040
1057
  });
@@ -1047,7 +1064,7 @@ var Connection = class {
1047
1064
  async signal(msg) {
1048
1065
  (0, import_invariant.invariant)(msg.sessionId, void 0, {
1049
1066
  F: __dxlog_file2,
1050
- L: 342,
1067
+ L: 364,
1051
1068
  S: this,
1052
1069
  A: [
1053
1070
  "msg.sessionId",
@@ -1057,7 +1074,7 @@ var Connection = class {
1057
1074
  if (!msg.sessionId.equals(this.sessionId)) {
1058
1075
  (0, import_log2.log)("dropping signal for incorrect session id", void 0, {
1059
1076
  F: __dxlog_file2,
1060
- L: 344,
1077
+ L: 366,
1061
1078
  S: this,
1062
1079
  C: (f, a) => f(...a)
1063
1080
  });
@@ -1065,7 +1082,7 @@ var Connection = class {
1065
1082
  }
1066
1083
  (0, import_invariant.invariant)(msg.data.signal || msg.data.signalBatch, void 0, {
1067
1084
  F: __dxlog_file2,
1068
- L: 347,
1085
+ L: 369,
1069
1086
  S: this,
1070
1087
  A: [
1071
1088
  "msg.data.signal || msg.data.signalBatch",
@@ -1074,7 +1091,7 @@ var Connection = class {
1074
1091
  });
1075
1092
  (0, import_invariant.invariant)(msg.author?.equals(this.remoteId), void 0, {
1076
1093
  F: __dxlog_file2,
1077
- L: 348,
1094
+ L: 370,
1078
1095
  S: this,
1079
1096
  A: [
1080
1097
  "msg.author?.equals(this.remoteId)",
@@ -1083,7 +1100,7 @@ var Connection = class {
1083
1100
  });
1084
1101
  (0, import_invariant.invariant)(msg.recipient?.equals(this.ownId), void 0, {
1085
1102
  F: __dxlog_file2,
1086
- L: 349,
1103
+ L: 371,
1087
1104
  S: this,
1088
1105
  A: [
1089
1106
  "msg.recipient?.equals(this.ownId)",
@@ -1107,7 +1124,7 @@ var Connection = class {
1107
1124
  msg: msg.data
1108
1125
  }, {
1109
1126
  F: __dxlog_file2,
1110
- L: 358,
1127
+ L: 380,
1111
1128
  S: this,
1112
1129
  C: (f, a) => f(...a)
1113
1130
  });
@@ -1115,7 +1132,7 @@ var Connection = class {
1115
1132
  } else {
1116
1133
  (0, import_invariant.invariant)(this._transport, "Connection not ready to accept signals.", {
1117
1134
  F: __dxlog_file2,
1118
- L: 361,
1135
+ L: 383,
1119
1136
  S: this,
1120
1137
  A: [
1121
1138
  "this._transport",
@@ -1128,7 +1145,7 @@ var Connection = class {
1128
1145
  msg: msg.data
1129
1146
  }, {
1130
1147
  F: __dxlog_file2,
1131
- L: 362,
1148
+ L: 384,
1132
1149
  S: this,
1133
1150
  C: (f, a) => f(...a)
1134
1151
  });
@@ -1146,13 +1163,13 @@ var Connection = class {
1146
1163
  peerId: this.ownId
1147
1164
  }, {
1148
1165
  F: __dxlog_file2,
1149
- L: 373,
1166
+ L: 395,
1150
1167
  S: this,
1151
1168
  C: (f, a) => f(...a)
1152
1169
  });
1153
1170
  (0, import_invariant.invariant)(state !== this._state, "Already in this state.", {
1154
1171
  F: __dxlog_file2,
1155
- L: 374,
1172
+ L: 396,
1156
1173
  S: this,
1157
1174
  A: [
1158
1175
  "state !== this._state",
@@ -1197,7 +1214,7 @@ function _ts_decorate2(decorators, target, key, desc) {
1197
1214
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1198
1215
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1199
1216
  }
1200
- var __dxlog_file3 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/peer.ts";
1217
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts";
1201
1218
  var ConnectionDisplacedError = class extends import_protocols2.SystemError {
1202
1219
  constructor() {
1203
1220
  super("Connection displaced by remote initiator.");
@@ -1229,11 +1246,12 @@ var Peer = class {
1229
1246
  const remoteId = message.author;
1230
1247
  if (this.connection && ![
1231
1248
  ConnectionState.CREATED,
1232
- ConnectionState.INITIAL
1249
+ ConnectionState.INITIAL,
1250
+ ConnectionState.CONNECTING
1233
1251
  ].includes(this.connection.state)) {
1234
1252
  import_log3.log.info(`received offer when connection already in ${this.connection.state} state`, void 0, {
1235
1253
  F: __dxlog_file3,
1236
- L: 112,
1254
+ L: 115,
1237
1255
  S: this,
1238
1256
  C: (f, a) => f(...a)
1239
1257
  });
@@ -1250,7 +1268,7 @@ var Peer = class {
1250
1268
  sessionId: this.connection?.sessionId
1251
1269
  }, {
1252
1270
  F: __dxlog_file3,
1253
- L: 121,
1271
+ L: 124,
1254
1272
  S: this,
1255
1273
  C: (f, a) => f(...a)
1256
1274
  });
@@ -1267,7 +1285,7 @@ var Peer = class {
1267
1285
  if (!this.connection) {
1268
1286
  (0, import_invariant2.invariant)(message.sessionId, void 0, {
1269
1287
  F: __dxlog_file3,
1270
- L: 141,
1288
+ L: 144,
1271
1289
  S: this,
1272
1290
  A: [
1273
1291
  "message.sessionId",
@@ -1288,7 +1306,7 @@ var Peer = class {
1288
1306
  err
1289
1307
  }, {
1290
1308
  F: __dxlog_file3,
1291
- L: 151,
1309
+ L: 154,
1292
1310
  S: this,
1293
1311
  C: (f, a) => f(...a)
1294
1312
  });
@@ -1310,7 +1328,7 @@ var Peer = class {
1310
1328
  async initiateConnection() {
1311
1329
  (0, import_invariant2.invariant)(!this.initiating, "Initiation in progress.", {
1312
1330
  F: __dxlog_file3,
1313
- L: 168,
1331
+ L: 171,
1314
1332
  S: this,
1315
1333
  A: [
1316
1334
  "!this.initiating",
@@ -1319,7 +1337,7 @@ var Peer = class {
1319
1337
  });
1320
1338
  (0, import_invariant2.invariant)(!this.connection, "Already connected.", {
1321
1339
  F: __dxlog_file3,
1322
- L: 169,
1340
+ L: 172,
1323
1341
  S: this,
1324
1342
  A: [
1325
1343
  "!this.connection",
@@ -1334,16 +1352,17 @@ var Peer = class {
1334
1352
  sessionId
1335
1353
  }, {
1336
1354
  F: __dxlog_file3,
1337
- L: 171,
1355
+ L: 174,
1338
1356
  S: this,
1339
1357
  C: (f, a) => f(...a)
1340
1358
  });
1341
1359
  const connection = this._createConnection(true, sessionId);
1342
1360
  this.initiating = true;
1361
+ let answer;
1343
1362
  try {
1344
1363
  await this._connectionLimiter.connecting(sessionId);
1345
1364
  connection.initiate();
1346
- const answer = await this._signalMessaging.offer({
1365
+ answer = await this._signalMessaging.offer({
1347
1366
  author: this.localPeerId,
1348
1367
  recipient: this.id,
1349
1368
  sessionId,
@@ -1359,46 +1378,87 @@ var Peer = class {
1359
1378
  remoteId: this.id
1360
1379
  }, {
1361
1380
  F: __dxlog_file3,
1362
- L: 187,
1381
+ L: 191,
1363
1382
  S: this,
1364
1383
  C: (f, a) => f(...a)
1365
1384
  });
1366
1385
  if (connection.state !== ConnectionState.INITIAL) {
1367
1386
  (0, import_log3.log)("ignoring response", void 0, {
1368
1387
  F: __dxlog_file3,
1369
- L: 189,
1388
+ L: 193,
1370
1389
  S: this,
1371
1390
  C: (f, a) => f(...a)
1372
1391
  });
1373
1392
  return;
1374
1393
  }
1394
+ } catch (err) {
1395
+ (0, import_log3.log)("initiation error: send offer", {
1396
+ err,
1397
+ topic: this.topic,
1398
+ peerId: this.localPeerId,
1399
+ remoteId: this.id
1400
+ }, {
1401
+ F: __dxlog_file3,
1402
+ L: 197,
1403
+ S: this,
1404
+ C: (f, a) => f(...a)
1405
+ });
1406
+ await connection.abort(err);
1407
+ throw err;
1408
+ } finally {
1409
+ this.initiating = false;
1410
+ }
1411
+ try {
1375
1412
  if (!answer.accept) {
1376
1413
  this._callbacks.onRejected();
1377
1414
  return;
1378
1415
  }
1416
+ } catch (err) {
1417
+ (0, import_log3.log)("initiation error: accept answer", {
1418
+ err,
1419
+ topic: this.topic,
1420
+ peerId: this.localPeerId,
1421
+ remoteId: this.id
1422
+ }, {
1423
+ F: __dxlog_file3,
1424
+ L: 210,
1425
+ S: this,
1426
+ C: (f, a) => f(...a)
1427
+ });
1428
+ await connection.abort(err);
1429
+ throw err;
1430
+ } finally {
1431
+ this.initiating = false;
1432
+ }
1433
+ try {
1434
+ (0, import_log3.log)("opening connection as initiator", void 0, {
1435
+ F: __dxlog_file3,
1436
+ L: 223,
1437
+ S: this,
1438
+ C: (f, a) => f(...a)
1439
+ });
1379
1440
  await connection.openConnection();
1380
1441
  this._callbacks.onAccepted();
1381
1442
  } catch (err) {
1382
- (0, import_log3.log)("initiation error", {
1443
+ (0, import_log3.log)("initiation error: open connection", {
1383
1444
  err,
1384
1445
  topic: this.topic,
1385
1446
  peerId: this.localPeerId,
1386
1447
  remoteId: this.id
1387
1448
  }, {
1388
1449
  F: __dxlog_file3,
1389
- L: 200,
1450
+ L: 227,
1451
+ S: this,
1452
+ C: (f, a) => f(...a)
1453
+ });
1454
+ import_log3.log.warn("closing connection due to unhandled error on openConnection", {
1455
+ err
1456
+ }, {
1457
+ F: __dxlog_file3,
1458
+ L: 234,
1390
1459
  S: this,
1391
1460
  C: (f, a) => f(...a)
1392
1461
  });
1393
- if (err instanceof import_protocols2.TimeoutError) {
1394
- import_log3.log.warn("aborting connection due to signalling failure", void 0, {
1395
- F: __dxlog_file3,
1396
- L: 202,
1397
- S: this,
1398
- C: (f, a) => f(...a)
1399
- });
1400
- await connection.abort(err);
1401
- }
1402
1462
  await this.closeConnection(err);
1403
1463
  throw err;
1404
1464
  } finally {
@@ -1418,13 +1478,13 @@ var Peer = class {
1418
1478
  sessionId
1419
1479
  }, {
1420
1480
  F: __dxlog_file3,
1421
- L: 218,
1481
+ L: 248,
1422
1482
  S: this,
1423
1483
  C: (f, a) => f(...a)
1424
1484
  });
1425
1485
  (0, import_invariant2.invariant)(!this.connection, "Already connected.", {
1426
1486
  F: __dxlog_file3,
1427
- L: 225,
1487
+ L: 255,
1428
1488
  S: this,
1429
1489
  A: [
1430
1490
  "!this.connection",
@@ -1460,7 +1520,7 @@ var Peer = class {
1460
1520
  initiator
1461
1521
  }, {
1462
1522
  F: __dxlog_file3,
1463
- L: 244,
1523
+ L: 274,
1464
1524
  S: this,
1465
1525
  C: (f, a) => f(...a)
1466
1526
  });
@@ -1473,14 +1533,14 @@ var Peer = class {
1473
1533
  initiator
1474
1534
  }, {
1475
1535
  F: __dxlog_file3,
1476
- L: 253,
1536
+ L: 283,
1477
1537
  S: this,
1478
1538
  C: (f, a) => f(...a)
1479
1539
  });
1480
1540
  this._connectionLimiter.doneConnecting(sessionId);
1481
1541
  (0, import_invariant2.invariant)(this.connection === connection, "Connection mismatch (race condition).", {
1482
1542
  F: __dxlog_file3,
1483
- L: 258,
1543
+ L: 288,
1484
1544
  S: this,
1485
1545
  A: [
1486
1546
  "this.connection === connection",
@@ -1495,7 +1555,7 @@ var Peer = class {
1495
1555
  initiator
1496
1556
  }, {
1497
1557
  F: __dxlog_file3,
1498
- L: 260,
1558
+ L: 290,
1499
1559
  S: this,
1500
1560
  C: (f, a) => f(...a)
1501
1561
  });
@@ -1522,7 +1582,7 @@ var Peer = class {
1522
1582
  void this._connectionCtx?.dispose();
1523
1583
  this._connectionCtx = this._ctx.derive();
1524
1584
  connection.errors.handle((err) => {
1525
- import_log3.log.warn("connection error", {
1585
+ import_log3.log.warn("connection error, closing", {
1526
1586
  topic: this.topic,
1527
1587
  peerId: this.localPeerId,
1528
1588
  remoteId: this.id,
@@ -1530,7 +1590,7 @@ var Peer = class {
1530
1590
  err
1531
1591
  }, {
1532
1592
  F: __dxlog_file3,
1533
- L: 300,
1593
+ L: 330,
1534
1594
  S: this,
1535
1595
  C: (f, a) => f(...a)
1536
1596
  });
@@ -1543,7 +1603,7 @@ var Peer = class {
1543
1603
  err
1544
1604
  }, {
1545
1605
  F: __dxlog_file3,
1546
- L: 301,
1606
+ L: 337,
1547
1607
  S: this,
1548
1608
  C: (f, a) => f(...a)
1549
1609
  });
@@ -1562,7 +1622,7 @@ var Peer = class {
1562
1622
  sessionId: connection.sessionId
1563
1623
  }, {
1564
1624
  F: __dxlog_file3,
1565
- L: 326,
1625
+ L: 362,
1566
1626
  S: this,
1567
1627
  C: (f, a) => f(...a)
1568
1628
  });
@@ -1572,7 +1632,7 @@ var Peer = class {
1572
1632
  sessionId: connection.sessionId
1573
1633
  }, {
1574
1634
  F: __dxlog_file3,
1575
- L: 332,
1635
+ L: 368,
1576
1636
  S: this,
1577
1637
  C: (f, a) => f(...a)
1578
1638
  });
@@ -1583,7 +1643,7 @@ var Peer = class {
1583
1643
  message
1584
1644
  }, {
1585
1645
  F: __dxlog_file3,
1586
- L: 337,
1646
+ L: 373,
1587
1647
  S: this,
1588
1648
  C: (f, a) => f(...a)
1589
1649
  });
@@ -1591,18 +1651,18 @@ var Peer = class {
1591
1651
  }
1592
1652
  await this.connection.signal(message);
1593
1653
  }
1594
- async destroy() {
1654
+ async destroy(reason) {
1595
1655
  await this._ctx.dispose();
1596
1656
  (0, import_log3.log)("Destroying peer", {
1597
1657
  peerId: this.id,
1598
1658
  topic: this.topic
1599
1659
  }, {
1600
1660
  F: __dxlog_file3,
1601
- L: 347,
1661
+ L: 383,
1602
1662
  S: this,
1603
1663
  C: (f, a) => f(...a)
1604
1664
  });
1605
- await this?.connection?.close();
1665
+ await this?.connection?.close(reason);
1606
1666
  }
1607
1667
  };
1608
1668
  _ts_decorate2([
@@ -1628,7 +1688,7 @@ var import_keys4 = require("@dxos/keys");
1628
1688
  var import_log4 = require("@dxos/log");
1629
1689
  var import_protocols3 = require("@dxos/protocols");
1630
1690
  var import_util2 = require("@dxos/util");
1631
- var __dxlog_file4 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
1691
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
1632
1692
  var SwarmMessage = import_protocols3.schema.getCodecForType("dxos.mesh.swarm.SwarmMessage");
1633
1693
  var SwarmMessenger = class {
1634
1694
  constructor({ sendMessage, onSignal, onOffer, topic }) {
@@ -1864,7 +1924,7 @@ function _ts_decorate3(decorators, target, key, desc) {
1864
1924
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1865
1925
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1866
1926
  }
1867
- var __dxlog_file5 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/swarm.ts";
1927
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts";
1868
1928
  var INITIATION_DELAY = 100;
1869
1929
  var getClassName = (obj) => Object.getPrototypeOf(obj).constructor.name;
1870
1930
  var Swarm = class {
@@ -1975,7 +2035,7 @@ var Swarm = class {
1975
2035
  this._listeningHandle = void 0;
1976
2036
  await this._ctx.dispose();
1977
2037
  await this._topology.destroy();
1978
- await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key)));
2038
+ await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key, "swarm destroyed")));
1979
2039
  (0, import_log5.log)("destroyed", void 0, {
1980
2040
  F: __dxlog_file5,
1981
2041
  L: 148,
@@ -2047,13 +2107,22 @@ var Swarm = class {
2047
2107
  if (peer) {
2048
2108
  peer.advertizing = false;
2049
2109
  if (peer.connection?.state !== ConnectionState.CONNECTED) {
2050
- void this._destroyPeer(peer.id).catch((err) => import_log5.log.catch(err, void 0, {
2110
+ void this._destroyPeer(peer.id, "peer left").catch((err) => import_log5.log.catch(err, void 0, {
2051
2111
  F: __dxlog_file5,
2052
2112
  L: 189,
2053
2113
  S: this,
2054
2114
  C: (f, a) => f(...a)
2055
2115
  }));
2056
2116
  }
2117
+ } else {
2118
+ (0, import_log5.log)("received peerLeft but no peer found", {
2119
+ peer: swarmEvent.peerLeft.peer
2120
+ }, {
2121
+ F: __dxlog_file5,
2122
+ L: 192,
2123
+ S: this,
2124
+ C: (f, a) => f(...a)
2125
+ });
2057
2126
  }
2058
2127
  }
2059
2128
  this._topology.update();
@@ -2063,14 +2132,14 @@ var Swarm = class {
2063
2132
  message
2064
2133
  }, {
2065
2134
  F: __dxlog_file5,
2066
- L: 199,
2135
+ L: 201,
2067
2136
  S: this,
2068
2137
  C: (f, a) => f(...a)
2069
2138
  });
2070
2139
  if (this._ctx.disposed) {
2071
2140
  (0, import_log5.log)("ignored for disposed swarm", void 0, {
2072
2141
  F: __dxlog_file5,
2073
- L: 201,
2142
+ L: 203,
2074
2143
  S: this,
2075
2144
  C: (f, a) => f(...a)
2076
2145
  });
@@ -2080,7 +2149,7 @@ var Swarm = class {
2080
2149
  }
2081
2150
  (0, import_invariant4.invariant)(message.author, void 0, {
2082
2151
  F: __dxlog_file5,
2083
- L: 206,
2152
+ L: 208,
2084
2153
  S: this,
2085
2154
  A: [
2086
2155
  "message.author",
@@ -2092,7 +2161,7 @@ var Swarm = class {
2092
2161
  message
2093
2162
  }, {
2094
2163
  F: __dxlog_file5,
2095
- L: 208,
2164
+ L: 210,
2096
2165
  S: this,
2097
2166
  C: (f, a) => f(...a)
2098
2167
  });
@@ -2105,7 +2174,7 @@ var Swarm = class {
2105
2174
  message
2106
2175
  }, {
2107
2176
  F: __dxlog_file5,
2108
- L: 212,
2177
+ L: 214,
2109
2178
  S: this,
2110
2179
  C: (f, a) => f(...a)
2111
2180
  });
@@ -2123,14 +2192,14 @@ var Swarm = class {
2123
2192
  message
2124
2193
  }, {
2125
2194
  F: __dxlog_file5,
2126
- L: 223,
2195
+ L: 225,
2127
2196
  S: this,
2128
2197
  C: (f, a) => f(...a)
2129
2198
  });
2130
2199
  if (this._ctx.disposed) {
2131
2200
  import_log5.log.info("ignored for offline swarm", void 0, {
2132
2201
  F: __dxlog_file5,
2133
- L: 225,
2202
+ L: 227,
2134
2203
  S: this,
2135
2204
  C: (f, a) => f(...a)
2136
2205
  });
@@ -2138,7 +2207,7 @@ var Swarm = class {
2138
2207
  }
2139
2208
  (0, import_invariant4.invariant)(message.recipient?.equals(this._ownPeerId), `Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`, {
2140
2209
  F: __dxlog_file5,
2141
- L: 228,
2210
+ L: 230,
2142
2211
  S: this,
2143
2212
  A: [
2144
2213
  "message.recipient?.equals(this._ownPeerId)",
@@ -2147,7 +2216,7 @@ var Swarm = class {
2147
2216
  });
2148
2217
  (0, import_invariant4.invariant)(message.topic?.equals(this._topic), void 0, {
2149
2218
  F: __dxlog_file5,
2150
- L: 232,
2219
+ L: 234,
2151
2220
  S: this,
2152
2221
  A: [
2153
2222
  "message.topic?.equals(this._topic)",
@@ -2156,7 +2225,7 @@ var Swarm = class {
2156
2225
  });
2157
2226
  (0, import_invariant4.invariant)(message.author, void 0, {
2158
2227
  F: __dxlog_file5,
2159
- L: 233,
2228
+ L: 235,
2160
2229
  S: this,
2161
2230
  A: [
2162
2231
  "message.author",
@@ -2171,7 +2240,7 @@ var Swarm = class {
2171
2240
  await this._ctx.dispose();
2172
2241
  await Promise.all([
2173
2242
  ...this._peers.keys()
2174
- ].map((peerId) => this._destroyPeer(peerId)));
2243
+ ].map((peerId) => this._destroyPeer(peerId, "goOffline")));
2175
2244
  }
2176
2245
  // For debug purposes
2177
2246
  async goOnline() {
@@ -2189,14 +2258,22 @@ var Swarm = class {
2189
2258
  },
2190
2259
  onDisconnected: async () => {
2191
2260
  if (!peer.advertizing) {
2192
- await this._destroyPeer(peer.id);
2261
+ await this._destroyPeer(peer.id, "peer disconnected");
2193
2262
  }
2194
2263
  this.disconnected.emit(peerId);
2195
2264
  this._topology.update();
2196
2265
  },
2197
2266
  onRejected: () => {
2198
2267
  if (this._peers.has(peerId)) {
2199
- void this._destroyPeer(peerId);
2268
+ (0, import_log5.log)("peer rejected connection", {
2269
+ peerId
2270
+ }, {
2271
+ F: __dxlog_file5,
2272
+ L: 284,
2273
+ S: this,
2274
+ C: (f, a) => f(...a)
2275
+ });
2276
+ void this._destroyPeer(peerId, "peer rejected connection");
2200
2277
  }
2201
2278
  },
2202
2279
  onAccepted: () => {
@@ -2213,17 +2290,17 @@ var Swarm = class {
2213
2290
  }
2214
2291
  return peer;
2215
2292
  }
2216
- async _destroyPeer(peerId) {
2293
+ async _destroyPeer(peerId, reason) {
2217
2294
  (0, import_invariant4.invariant)(this._peers.has(peerId), void 0, {
2218
2295
  F: __dxlog_file5,
2219
- L: 303,
2296
+ L: 306,
2220
2297
  S: this,
2221
2298
  A: [
2222
2299
  "this._peers.has(peerId)",
2223
2300
  ""
2224
2301
  ]
2225
2302
  });
2226
- await this._peers.get(peerId).destroy();
2303
+ await this._peers.get(peerId).destroy(new Error(reason));
2227
2304
  this._peers.delete(peerId);
2228
2305
  }
2229
2306
  _getSwarmController() {
@@ -2243,7 +2320,7 @@ var Swarm = class {
2243
2320
  } catch (err) {
2244
2321
  (0, import_log5.log)("initiation error", err, {
2245
2322
  F: __dxlog_file5,
2246
- L: 329,
2323
+ L: 332,
2247
2324
  S: this,
2248
2325
  C: (f, a) => f(...a)
2249
2326
  });
@@ -2271,7 +2348,7 @@ var Swarm = class {
2271
2348
  remoteId
2272
2349
  }, {
2273
2350
  F: __dxlog_file5,
2274
- L: 356,
2351
+ L: 359,
2275
2352
  S: this,
2276
2353
  C: (f, a) => f(...a)
2277
2354
  });
@@ -2288,7 +2365,7 @@ var Swarm = class {
2288
2365
  remoteId
2289
2366
  }, {
2290
2367
  F: __dxlog_file5,
2291
- L: 370,
2368
+ L: 373,
2292
2369
  S: this,
2293
2370
  C: (f, a) => f(...a)
2294
2371
  });
@@ -2298,7 +2375,7 @@ var Swarm = class {
2298
2375
  remoteId
2299
2376
  }, {
2300
2377
  F: __dxlog_file5,
2301
- L: 373,
2378
+ L: 376,
2302
2379
  S: this,
2303
2380
  C: (f, a) => f(...a)
2304
2381
  });
@@ -2338,7 +2415,7 @@ var import_async5 = require("@dxos/async");
2338
2415
  var import_keys6 = require("@dxos/keys");
2339
2416
  var import_log6 = require("@dxos/log");
2340
2417
  var import_util4 = require("@dxos/util");
2341
- var __dxlog_file6 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
2418
+ var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
2342
2419
  var SwarmMapper = class {
2343
2420
  get peers() {
2344
2421
  return Array.from(this._peers.values());
@@ -2410,7 +2487,7 @@ var import_keys7 = require("@dxos/keys");
2410
2487
  var import_log7 = require("@dxos/log");
2411
2488
  var import_protocols5 = require("@dxos/protocols");
2412
2489
  var import_util5 = require("@dxos/util");
2413
- var __dxlog_file7 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
2490
+ var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
2414
2491
  var MAX_CONCURRENT_INITIATING_CONNECTIONS = 50;
2415
2492
  var ConnectionLimiter = class {
2416
2493
  constructor({ maxConcurrentInitConnections = MAX_CONCURRENT_INITIATING_CONNECTIONS } = {}) {
@@ -2551,7 +2628,7 @@ var ConnectionLog = class {
2551
2628
  };
2552
2629
 
2553
2630
  // packages/core/mesh/network-manager/src/network-manager.ts
2554
- var __dxlog_file8 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/network-manager.ts";
2631
+ var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts";
2555
2632
  var NetworkManager = class {
2556
2633
  constructor({ transportFactory, signalManager, log: log1 }) {
2557
2634
  /**
@@ -2787,7 +2864,7 @@ var NetworkManager = class {
2787
2864
 
2788
2865
  // packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts
2789
2866
  var import_invariant7 = require("@dxos/invariant");
2790
- var __dxlog_file9 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
2867
+ var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
2791
2868
  var FullyConnectedTopology = class {
2792
2869
  toString() {
2793
2870
  return "FullyConnectedTopology";
@@ -2853,7 +2930,7 @@ function _ts_decorate4(decorators, target, key, desc) {
2853
2930
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2854
2931
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2855
2932
  }
2856
- var __dxlog_file10 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
2933
+ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
2857
2934
  var MEMORY_TRANSPORT_DELAY = 1;
2858
2935
  var createStreamDelay = (delay) => {
2859
2936
  return new import_node_stream.Transform({
@@ -3048,7 +3125,7 @@ try {
3048
3125
  }
3049
3126
 
3050
3127
  // packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts
3051
- var __dxlog_file11 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts";
3128
+ var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts";
3052
3129
  var SimplePeerTransport = class {
3053
3130
  constructor(params) {
3054
3131
  this.params = params;
@@ -3237,7 +3314,7 @@ var import_keys12 = require("@dxos/keys");
3237
3314
  var import_log13 = require("@dxos/log");
3238
3315
  var import_bridge = require("@dxos/protocols/proto/dxos/mesh/bridge");
3239
3316
  var import_util9 = require("@dxos/util");
3240
- var __dxlog_file12 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/simplepeer-transport-service.ts";
3317
+ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport-service.ts";
3241
3318
  var SimplePeerTransportService = class {
3242
3319
  constructor(_webrtcConfig) {
3243
3320
  this._webrtcConfig = _webrtcConfig;
@@ -3380,7 +3457,7 @@ var import_log14 = require("@dxos/log");
3380
3457
  var import_protocols8 = require("@dxos/protocols");
3381
3458
  var import_bridge2 = require("@dxos/protocols/proto/dxos/mesh/bridge");
3382
3459
  var import_util10 = require("@dxos/util");
3383
- var __dxlog_file13 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/simplepeer-transport-proxy.ts";
3460
+ var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport-proxy.ts";
3384
3461
  var SimplePeerTransportProxy = class {
3385
3462
  constructor(_params) {
3386
3463
  this._params = _params;
@@ -3560,7 +3637,7 @@ function _ts_decorate5(decorators, target, key, desc) {
3560
3637
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3561
3638
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3562
3639
  }
3563
- var __dxlog_file14 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/libdatachannel-transport.ts";
3640
+ var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/libdatachannel-transport.ts";
3564
3641
  var DATACHANNEL_LABEL = "dxos.mesh.transport";
3565
3642
  var MAX_BUFFERED_AMOUNT = 64 * 1024;
3566
3643
  var MAX_MESSAGE_SIZE = 64 * 1024;
@@ -3889,7 +3966,7 @@ var import_node_net = require("node:net");
3889
3966
  var import_async13 = require("@dxos/async");
3890
3967
  var import_debug8 = require("@dxos/debug");
3891
3968
  var import_log16 = require("@dxos/log");
3892
- var __dxlog_file15 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/tcp-transport.ts";
3969
+ var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/tcp-transport.ts";
3893
3970
  var TcpTransportFactory = {
3894
3971
  createTransport: (params) => new TcpTransport(params)
3895
3972
  };
@@ -4015,7 +4092,7 @@ var TcpTransport = class {
4015
4092
  };
4016
4093
 
4017
4094
  // packages/core/mesh/network-manager/src/testing/test-builder.ts
4018
- var __dxlog_file16 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/testing/test-builder.ts";
4095
+ var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-builder.ts";
4019
4096
  var port = process.env.SIGNAL_PORT ?? 4e3;
4020
4097
  var TEST_SIGNAL_HOSTS = [
4021
4098
  {