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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -560,7 +560,7 @@ function _ts_decorate(decorators, target, key, desc) {
560
560
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
561
561
  return c > 3 && r && Object.defineProperty(target, key, r), r;
562
562
  }
563
- var __dxlog_file = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/connection.ts";
563
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts";
564
564
  var STARTING_SIGNALLING_DELAY = 10;
565
565
  var MAX_SIGNALLING_DELAY = 300;
566
566
  var ConnectionState;
@@ -602,6 +602,8 @@ var ConnectionState;
602
602
  */
603
603
  "CLOSED"
604
604
  ] = "CLOSED";
605
+ ConnectionState5["ABORTING"] = "ABORTING";
606
+ ConnectionState5["ABORTED"] = "ABORTED";
605
607
  })(ConnectionState || (ConnectionState = {}));
606
608
  var Connection = class {
607
609
  constructor(topic, ownId, remoteId, sessionId, initiator, _signalMessaging, _protocol, _transportFactory, _callbacks) {
@@ -633,7 +635,7 @@ var Connection = class {
633
635
  initiator: this.initiator
634
636
  }, {
635
637
  F: __dxlog_file,
636
- L: 114,
638
+ L: 123,
637
639
  S: this,
638
640
  C: (f, a) => f(...a)
639
641
  });
@@ -653,7 +655,7 @@ var Connection = class {
653
655
  async openConnection() {
654
656
  (0, import_invariant.invariant)(this._state === ConnectionState.INITIAL, "Invalid state.", {
655
657
  F: __dxlog_file,
656
- L: 139,
658
+ L: 148,
657
659
  S: this,
658
660
  A: [
659
661
  "this._state === ConnectionState.INITIAL",
@@ -664,7 +666,7 @@ var Connection = class {
664
666
  id: this._instanceId
665
667
  }), {
666
668
  F: __dxlog_file,
667
- L: 140,
669
+ L: 149,
668
670
  S: this,
669
671
  C: (f, a) => f(...a)
670
672
  });
@@ -676,7 +678,7 @@ var Connection = class {
676
678
  initiator: this.initiator
677
679
  }, {
678
680
  F: __dxlog_file,
679
- L: 141,
681
+ L: 150,
680
682
  S: this,
681
683
  C: (f, a) => f(...a)
682
684
  });
@@ -687,15 +689,15 @@ var Connection = class {
687
689
  this._protocol.stream.on("close", () => {
688
690
  (0, import_log.log)("protocol stream closed", void 0, {
689
691
  F: __dxlog_file,
690
- L: 158,
692
+ L: 167,
691
693
  S: this,
692
694
  C: (f, a) => f(...a)
693
695
  });
694
- this.close().catch((err) => this.errors.raise(err));
696
+ this.close(new import_errors.ProtocolError("protocol stream closed")).catch((err) => this.errors.raise(err));
695
697
  });
696
698
  (0, import_invariant.invariant)(!this._transport, void 0, {
697
699
  F: __dxlog_file,
698
- L: 162,
700
+ L: 171,
699
701
  S: this,
700
702
  A: [
701
703
  "!this._transport",
@@ -715,7 +717,7 @@ var Connection = class {
715
717
  this._transport = void 0;
716
718
  (0, import_log.log)("abort triggered by transport close", void 0, {
717
719
  F: __dxlog_file,
718
- L: 176,
720
+ L: 185,
719
721
  S: this,
720
722
  C: (f, a) => f(...a)
721
723
  });
@@ -726,21 +728,38 @@ var Connection = class {
726
728
  err
727
729
  }, {
728
730
  F: __dxlog_file,
729
- L: 181,
731
+ L: 190,
730
732
  S: this,
731
733
  C: (f, a) => f(...a)
732
734
  });
733
735
  if (!this.closeReason) {
734
736
  this.closeReason = err?.message;
735
737
  }
736
- if (err?.message.includes("OperationError")) {
737
- (0, import_log.log)("aborting due to transport OperationError", void 0, {
738
+ if (err instanceof import_errors.ConnectionResetError) {
739
+ (0, import_log.log)("aborting due to transport ConnectionResetError", void 0, {
738
740
  F: __dxlog_file,
739
- L: 187,
741
+ L: 197,
740
742
  S: this,
741
743
  C: (f, a) => f(...a)
742
744
  });
743
745
  this.abort().catch((err2) => this.errors.raise(err2));
746
+ } else if (err instanceof import_errors.ConnectivityError) {
747
+ (0, import_log.log)("aborting due to transport ConnectivityError", void 0, {
748
+ F: __dxlog_file,
749
+ L: 200,
750
+ S: this,
751
+ C: (f, a) => f(...a)
752
+ });
753
+ this.abort().catch((err2) => this.errors.raise(err2));
754
+ } else if (err instanceof import_errors.UnknownProtocolError) {
755
+ (0, import_log.log)("unsure what to do for UnknownProtocolError", {
756
+ err
757
+ }, {
758
+ F: __dxlog_file,
759
+ L: 203,
760
+ S: this,
761
+ C: (f, a) => f(...a)
762
+ });
744
763
  }
745
764
  if (this._state !== ConnectionState.CLOSED && this._state !== ConnectionState.CLOSING) {
746
765
  this.errors.raise(err);
@@ -754,7 +773,7 @@ var Connection = class {
754
773
  id: this._instanceId
755
774
  }), {
756
775
  F: __dxlog_file,
757
- L: 203,
776
+ L: 218,
758
777
  S: this,
759
778
  C: (f, a) => f(...a)
760
779
  });
@@ -764,30 +783,30 @@ var Connection = class {
764
783
  err
765
784
  }, {
766
785
  F: __dxlog_file,
767
- L: 209,
786
+ L: 224,
768
787
  S: this,
769
788
  C: (f, a) => f(...a)
770
789
  });
771
- if (!this.closeReason) {
772
- this.closeReason = err?.message;
773
- }
774
- if (this._state === ConnectionState.CLOSED) {
775
- (0, import_log.log)("abort ignored: already closed", this.closeReason, {
790
+ if (this._state === ConnectionState.CLOSED || this._state === ConnectionState.ABORTED) {
791
+ (0, import_log.log)(`abort ignored: already ${this._state}`, this.closeReason, {
776
792
  F: __dxlog_file,
777
- L: 214,
793
+ L: 226,
778
794
  S: this,
779
795
  C: (f, a) => f(...a)
780
796
  });
781
797
  return;
782
798
  }
783
- this._changeState(ConnectionState.CLOSING);
799
+ this._changeState(ConnectionState.ABORTING);
800
+ if (!this.closeReason) {
801
+ this.closeReason = err?.message;
802
+ }
784
803
  await this._ctx.dispose();
785
804
  try {
786
805
  (0, import_log.log)("aborting protocol... ", {
787
806
  proto: this._protocol
788
807
  }, {
789
808
  F: __dxlog_file,
790
- L: 224,
809
+ L: 239,
791
810
  S: this,
792
811
  C: (f, a) => f(...a)
793
812
  });
@@ -795,7 +814,7 @@ var Connection = class {
795
814
  } catch (err2) {
796
815
  import_log.log.catch(err2, void 0, {
797
816
  F: __dxlog_file,
798
- L: 227,
817
+ L: 242,
799
818
  S: this,
800
819
  C: (f, a) => f(...a)
801
820
  });
@@ -805,56 +824,68 @@ var Connection = class {
805
824
  } catch (err2) {
806
825
  import_log.log.catch(err2, void 0, {
807
826
  F: __dxlog_file,
808
- L: 234,
827
+ L: 249,
809
828
  S: this,
810
829
  C: (f, a) => f(...a)
811
830
  });
812
831
  }
813
- this._changeState(ConnectionState.CLOSED);
814
- this._callbacks?.onClosed?.(err);
832
+ try {
833
+ this._callbacks?.onClosed?.(err);
834
+ } catch (err2) {
835
+ import_log.log.catch(err2, void 0, {
836
+ F: __dxlog_file,
837
+ L: 255,
838
+ S: this,
839
+ C: (f, a) => f(...a)
840
+ });
841
+ }
842
+ this._changeState(ConnectionState.ABORTED);
815
843
  }
816
844
  async close(err) {
817
845
  if (!this.closeReason) {
818
846
  this.closeReason = err?.message;
819
847
  }
820
- if (this._state === ConnectionState.CLOSED) {
848
+ if (this._state === ConnectionState.CLOSED || this._state === ConnectionState.ABORTING || this._state === ConnectionState.ABORTED) {
821
849
  return;
822
850
  }
851
+ const lastState = this._state;
823
852
  this._changeState(ConnectionState.CLOSING);
824
853
  await this._ctx.dispose();
825
854
  (0, import_log.log)("closing...", {
826
855
  peerId: this.ownId
827
856
  }, {
828
857
  F: __dxlog_file,
829
- L: 253,
858
+ L: 277,
830
859
  S: this,
831
860
  C: (f, a) => f(...a)
832
861
  });
833
- try {
834
- await this._protocol.close();
835
- } catch (err2) {
836
- import_log.log.catch(err2, void 0, {
837
- F: __dxlog_file,
838
- L: 259,
839
- S: this,
840
- C: (f, a) => f(...a)
841
- });
842
- }
843
- try {
844
- await this._transport?.destroy();
845
- } catch (err2) {
846
- import_log.log.catch(err2, void 0, {
847
- F: __dxlog_file,
848
- L: 266,
849
- S: this,
850
- C: (f, a) => f(...a)
851
- });
862
+ if (lastState === ConnectionState.CONNECTED) {
863
+ try {
864
+ await this._protocol.close();
865
+ } catch (err2) {
866
+ import_log.log.catch(err2, void 0, {
867
+ F: __dxlog_file,
868
+ L: 284,
869
+ S: this,
870
+ C: (f, a) => f(...a)
871
+ });
872
+ }
873
+ try {
874
+ await this._transport?.destroy();
875
+ } catch (err2) {
876
+ import_log.log.catch(err2, void 0, {
877
+ F: __dxlog_file,
878
+ L: 291,
879
+ S: this,
880
+ C: (f, a) => f(...a)
881
+ });
882
+ }
852
883
  }
853
884
  (0, import_log.log)("closed", {
854
885
  peerId: this.ownId
855
886
  }, {
856
887
  F: __dxlog_file,
857
- L: 269,
888
+ L: 295,
858
889
  S: this,
859
890
  C: (f, a) => f(...a)
860
891
  });
@@ -897,7 +928,7 @@ var Connection = class {
897
928
  err
898
929
  }, {
899
930
  F: __dxlog_file,
900
- L: 306,
931
+ L: 332,
901
932
  S: this,
902
933
  C: (f, a) => f(...a)
903
934
  });
@@ -910,7 +941,7 @@ var Connection = class {
910
941
  async signal(msg) {
911
942
  (0, import_invariant.invariant)(msg.sessionId, void 0, {
912
943
  F: __dxlog_file,
913
- L: 315,
944
+ L: 341,
914
945
  S: this,
915
946
  A: [
916
947
  "msg.sessionId",
@@ -920,7 +951,7 @@ var Connection = class {
920
951
  if (!msg.sessionId.equals(this.sessionId)) {
921
952
  (0, import_log.log)("dropping signal for incorrect session id", void 0, {
922
953
  F: __dxlog_file,
923
- L: 317,
954
+ L: 343,
924
955
  S: this,
925
956
  C: (f, a) => f(...a)
926
957
  });
@@ -928,7 +959,7 @@ var Connection = class {
928
959
  }
929
960
  (0, import_invariant.invariant)(msg.data.signal || msg.data.signalBatch, void 0, {
930
961
  F: __dxlog_file,
931
- L: 320,
962
+ L: 346,
932
963
  S: this,
933
964
  A: [
934
965
  "msg.data.signal || msg.data.signalBatch",
@@ -937,7 +968,7 @@ var Connection = class {
937
968
  });
938
969
  (0, import_invariant.invariant)(msg.author?.equals(this.remoteId), void 0, {
939
970
  F: __dxlog_file,
940
- L: 321,
971
+ L: 347,
941
972
  S: this,
942
973
  A: [
943
974
  "msg.author?.equals(this.remoteId)",
@@ -946,7 +977,7 @@ var Connection = class {
946
977
  });
947
978
  (0, import_invariant.invariant)(msg.recipient?.equals(this.ownId), void 0, {
948
979
  F: __dxlog_file,
949
- L: 322,
980
+ L: 348,
950
981
  S: this,
951
982
  A: [
952
983
  "msg.recipient?.equals(this.ownId)",
@@ -970,7 +1001,7 @@ var Connection = class {
970
1001
  msg: msg.data
971
1002
  }, {
972
1003
  F: __dxlog_file,
973
- L: 331,
1004
+ L: 357,
974
1005
  S: this,
975
1006
  C: (f, a) => f(...a)
976
1007
  });
@@ -978,7 +1009,7 @@ var Connection = class {
978
1009
  } else {
979
1010
  (0, import_invariant.invariant)(this._transport, "Connection not ready to accept signals.", {
980
1011
  F: __dxlog_file,
981
- L: 334,
1012
+ L: 360,
982
1013
  S: this,
983
1014
  A: [
984
1015
  "this._transport",
@@ -991,7 +1022,7 @@ var Connection = class {
991
1022
  msg: msg.data
992
1023
  }, {
993
1024
  F: __dxlog_file,
994
- L: 335,
1025
+ L: 361,
995
1026
  S: this,
996
1027
  C: (f, a) => f(...a)
997
1028
  });
@@ -1005,17 +1036,17 @@ var Connection = class {
1005
1036
  _changeState(state) {
1006
1037
  (0, import_log.log)("stateChanged", {
1007
1038
  from: this._state,
1008
- too: state,
1039
+ to: state,
1009
1040
  peerId: this.ownId
1010
1041
  }, {
1011
1042
  F: __dxlog_file,
1012
- L: 346,
1043
+ L: 372,
1013
1044
  S: this,
1014
1045
  C: (f, a) => f(...a)
1015
1046
  });
1016
1047
  (0, import_invariant.invariant)(state !== this._state, "Already in this state.", {
1017
1048
  F: __dxlog_file,
1018
- L: 347,
1049
+ L: 373,
1019
1050
  S: this,
1020
1051
  A: [
1021
1052
  "state !== this._state",
@@ -1050,7 +1081,7 @@ var import_keys2 = require("@dxos/keys");
1050
1081
  var import_log2 = require("@dxos/log");
1051
1082
  var import_protocols2 = require("@dxos/protocols");
1052
1083
  var import_util = require("@dxos/util");
1053
- var __dxlog_file2 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
1084
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
1054
1085
  var SwarmMessage = import_protocols2.schema.getCodecForType("dxos.mesh.swarm.SwarmMessage");
1055
1086
  var SwarmMessenger = class {
1056
1087
  constructor({ sendMessage, onSignal, onOffer, topic }) {
@@ -1292,7 +1323,7 @@ function _ts_decorate2(decorators, target, key, desc) {
1292
1323
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1293
1324
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1294
1325
  }
1295
- var __dxlog_file3 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/peer.ts";
1326
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts";
1296
1327
  var ConnectionDisplacedError = class extends import_errors2.SystemError {
1297
1328
  constructor() {
1298
1329
  super("Connection displaced by remote initiator.");
@@ -1471,6 +1502,9 @@ var Peer = class {
1471
1502
  S: this,
1472
1503
  C: (f, a) => f(...a)
1473
1504
  });
1505
+ if (err instanceof import_errors2.TimeoutError) {
1506
+ await connection.abort(err);
1507
+ }
1474
1508
  await this.closeConnection(err);
1475
1509
  throw err;
1476
1510
  } finally {
@@ -1490,13 +1524,13 @@ var Peer = class {
1490
1524
  sessionId
1491
1525
  }, {
1492
1526
  F: __dxlog_file3,
1493
- L: 210,
1527
+ L: 213,
1494
1528
  S: this,
1495
1529
  C: (f, a) => f(...a)
1496
1530
  });
1497
1531
  (0, import_invariant3.invariant)(!this.connection, "Already connected.", {
1498
1532
  F: __dxlog_file3,
1499
- L: 217,
1533
+ L: 220,
1500
1534
  S: this,
1501
1535
  A: [
1502
1536
  "!this.connection",
@@ -1532,7 +1566,7 @@ var Peer = class {
1532
1566
  initiator
1533
1567
  }, {
1534
1568
  F: __dxlog_file3,
1535
- L: 236,
1569
+ L: 239,
1536
1570
  S: this,
1537
1571
  C: (f, a) => f(...a)
1538
1572
  });
@@ -1545,14 +1579,14 @@ var Peer = class {
1545
1579
  initiator
1546
1580
  }, {
1547
1581
  F: __dxlog_file3,
1548
- L: 245,
1582
+ L: 248,
1549
1583
  S: this,
1550
1584
  C: (f, a) => f(...a)
1551
1585
  });
1552
1586
  this._connectionLimiter.doneConnecting(sessionId);
1553
1587
  (0, import_invariant3.invariant)(this.connection === connection, "Connection mismatch (race condition).", {
1554
1588
  F: __dxlog_file3,
1555
- L: 250,
1589
+ L: 253,
1556
1590
  S: this,
1557
1591
  A: [
1558
1592
  "this.connection === connection",
@@ -1567,7 +1601,7 @@ var Peer = class {
1567
1601
  initiator
1568
1602
  }, {
1569
1603
  F: __dxlog_file3,
1570
- L: 252,
1604
+ L: 255,
1571
1605
  S: this,
1572
1606
  C: (f, a) => f(...a)
1573
1607
  });
@@ -1602,7 +1636,7 @@ var Peer = class {
1602
1636
  err
1603
1637
  }, {
1604
1638
  F: __dxlog_file3,
1605
- L: 292,
1639
+ L: 295,
1606
1640
  S: this,
1607
1641
  C: (f, a) => f(...a)
1608
1642
  });
@@ -1615,7 +1649,7 @@ var Peer = class {
1615
1649
  err
1616
1650
  }, {
1617
1651
  F: __dxlog_file3,
1618
- L: 293,
1652
+ L: 296,
1619
1653
  S: this,
1620
1654
  C: (f, a) => f(...a)
1621
1655
  });
@@ -1634,7 +1668,7 @@ var Peer = class {
1634
1668
  sessionId: connection.sessionId
1635
1669
  }, {
1636
1670
  F: __dxlog_file3,
1637
- L: 318,
1671
+ L: 321,
1638
1672
  S: this,
1639
1673
  C: (f, a) => f(...a)
1640
1674
  });
@@ -1644,7 +1678,7 @@ var Peer = class {
1644
1678
  sessionId: connection.sessionId
1645
1679
  }, {
1646
1680
  F: __dxlog_file3,
1647
- L: 324,
1681
+ L: 327,
1648
1682
  S: this,
1649
1683
  C: (f, a) => f(...a)
1650
1684
  });
@@ -1655,7 +1689,7 @@ var Peer = class {
1655
1689
  message
1656
1690
  }, {
1657
1691
  F: __dxlog_file3,
1658
- L: 329,
1692
+ L: 332,
1659
1693
  S: this,
1660
1694
  C: (f, a) => f(...a)
1661
1695
  });
@@ -1670,7 +1704,7 @@ var Peer = class {
1670
1704
  topic: this.topic
1671
1705
  }, {
1672
1706
  F: __dxlog_file3,
1673
- L: 339,
1707
+ L: 342,
1674
1708
  S: this,
1675
1709
  C: (f, a) => f(...a)
1676
1710
  });
@@ -1704,7 +1738,7 @@ function _ts_decorate3(decorators, target, key, desc) {
1704
1738
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1705
1739
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1706
1740
  }
1707
- var __dxlog_file4 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/swarm.ts";
1741
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts";
1708
1742
  var INITIATION_DELAY = 100;
1709
1743
  var getClassName = (obj) => Object.getPrototypeOf(obj).constructor.name;
1710
1744
  var Swarm = class {
@@ -2178,7 +2212,7 @@ var import_async4 = require("@dxos/async");
2178
2212
  var import_keys5 = require("@dxos/keys");
2179
2213
  var import_log5 = require("@dxos/log");
2180
2214
  var import_util3 = require("@dxos/util");
2181
- var __dxlog_file5 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
2215
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
2182
2216
  var SwarmMapper = class {
2183
2217
  get peers() {
2184
2218
  return Array.from(this._peers.values());
@@ -2251,7 +2285,7 @@ var import_invariant5 = require("@dxos/invariant");
2251
2285
  var import_keys6 = require("@dxos/keys");
2252
2286
  var import_log6 = require("@dxos/log");
2253
2287
  var import_util4 = require("@dxos/util");
2254
- var __dxlog_file6 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
2288
+ var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
2255
2289
  var MAX_CONCURRENT_INITIATING_CONNECTIONS = 10;
2256
2290
  var ConnectionLimiter = class {
2257
2291
  constructor({ maxConcurrentInitConnections = MAX_CONCURRENT_INITIATING_CONNECTIONS } = {}) {
@@ -2400,7 +2434,7 @@ var import_messaging = require("@dxos/messaging");
2400
2434
  var import_protocols4 = require("@dxos/protocols");
2401
2435
  var import_services = require("@dxos/protocols/proto/dxos/client/services");
2402
2436
  var import_util6 = require("@dxos/util");
2403
- var __dxlog_file7 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/network-manager.ts";
2437
+ var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts";
2404
2438
  var NetworkManager = class {
2405
2439
  constructor({ transportFactory, signalManager, log: log1 }) {
2406
2440
  /**
@@ -2636,7 +2670,7 @@ var NetworkManager = class {
2636
2670
 
2637
2671
  // packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts
2638
2672
  var import_invariant7 = require("@dxos/invariant");
2639
- var __dxlog_file8 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
2673
+ var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
2640
2674
  var FullyConnectedTopology = class {
2641
2675
  toString() {
2642
2676
  return "FullyConnectedTopology";
@@ -2679,7 +2713,7 @@ var FullyConnectedTopology = class {
2679
2713
  var import_xor_distance = __toESM(require("xor-distance"));
2680
2714
  var import_invariant8 = require("@dxos/invariant");
2681
2715
  var import_log8 = require("@dxos/log");
2682
- var __dxlog_file9 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/topology/mmst-topology.ts";
2716
+ var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/mmst-topology.ts";
2683
2717
  var MMSTTopology = class {
2684
2718
  constructor({ originateConnections = 2, maxPeers = 4, sampleSize = 10 } = {}) {
2685
2719
  this._sampleCollected = false;
@@ -2788,7 +2822,7 @@ var sortByXorDistance = (keys, reference) => keys.sort((a, b) => import_xor_dist
2788
2822
  // packages/core/mesh/network-manager/src/topology/star-topology.ts
2789
2823
  var import_invariant9 = require("@dxos/invariant");
2790
2824
  var import_log9 = require("@dxos/log");
2791
- var __dxlog_file10 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/topology/star-topology.ts";
2825
+ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/star-topology.ts";
2792
2826
  var StarTopology = class {
2793
2827
  // prettier-ignore
2794
2828
  constructor(_centralPeer) {
@@ -2900,7 +2934,7 @@ function _ts_decorate4(decorators, target, key, desc) {
2900
2934
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2901
2935
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2902
2936
  }
2903
- var __dxlog_file11 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
2937
+ var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
2904
2938
  var MEMORY_TRANSPORT_DELAY = 1;
2905
2939
  var createStreamDelay = (delay) => {
2906
2940
  return new import_node_stream.Transform({
@@ -3082,6 +3116,7 @@ var import_simple_peer = __toESM(require("simple-peer"));
3082
3116
  var import_tiny_invariant = __toESM(require("tiny-invariant"));
3083
3117
  var import_async9 = require("@dxos/async");
3084
3118
  var import_debug5 = require("@dxos/debug");
3119
+ var import_errors4 = require("@dxos/errors");
3085
3120
  var import_keys10 = require("@dxos/keys");
3086
3121
  var import_log11 = require("@dxos/log");
3087
3122
  var import_protocols5 = require("@dxos/protocols");
@@ -3094,7 +3129,7 @@ try {
3094
3129
  }
3095
3130
 
3096
3131
  // packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts
3097
- var __dxlog_file12 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts";
3132
+ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts";
3098
3133
  var SimplePeerTransport = class {
3099
3134
  constructor(params) {
3100
3135
  this.params = params;
@@ -3107,13 +3142,13 @@ var SimplePeerTransport = class {
3107
3142
  id: this._instanceId
3108
3143
  }), {
3109
3144
  F: __dxlog_file12,
3110
- L: 39,
3145
+ L: 41,
3111
3146
  S: this,
3112
3147
  C: (f, a) => f(...a)
3113
3148
  });
3114
3149
  (0, import_log11.log)("created connection", params, {
3115
3150
  F: __dxlog_file12,
3116
- L: 40,
3151
+ L: 42,
3117
3152
  S: this,
3118
3153
  C: (f, a) => f(...a)
3119
3154
  });
@@ -3126,7 +3161,7 @@ var SimplePeerTransport = class {
3126
3161
  this._peer.on("signal", async (data) => {
3127
3162
  (0, import_log11.log)("signal", data, {
3128
3163
  F: __dxlog_file12,
3129
- L: 49,
3164
+ L: 51,
3130
3165
  S: this,
3131
3166
  C: (f, a) => f(...a)
3132
3167
  });
@@ -3139,7 +3174,7 @@ var SimplePeerTransport = class {
3139
3174
  this._peer.on("connect", () => {
3140
3175
  (0, import_log11.log)("connected", void 0, {
3141
3176
  F: __dxlog_file12,
3142
- L: 54,
3177
+ L: 56,
3143
3178
  S: this,
3144
3179
  C: (f, a) => f(...a)
3145
3180
  });
@@ -3149,7 +3184,7 @@ var SimplePeerTransport = class {
3149
3184
  this._peer.on("close", async () => {
3150
3185
  (0, import_log11.log)("closed", void 0, {
3151
3186
  F: __dxlog_file12,
3152
- L: 60,
3187
+ L: 62,
3153
3188
  S: this,
3154
3189
  C: (f, a) => f(...a)
3155
3190
  });
@@ -3157,7 +3192,35 @@ var SimplePeerTransport = class {
3157
3192
  this.closed.emit();
3158
3193
  });
3159
3194
  this._peer.on("error", async (err) => {
3160
- this.errors.raise(err);
3195
+ if (typeof RTCError !== "undefined" && err instanceof RTCError) {
3196
+ if (err.errorDetail === "sctp-failure") {
3197
+ this.errors.raise(new import_errors4.ConnectionResetError("sctp-failure from RTCError", err));
3198
+ } else {
3199
+ this.errors.raise(new import_errors4.UnknownProtocolError("unknown RTCError", err));
3200
+ }
3201
+ } else if (err.name === "InvalidStateError") {
3202
+ this.errors.raise(new import_errors4.ConnectionResetError("safari WebRTC error", err));
3203
+ } else if ("code" in err) {
3204
+ switch (err.code) {
3205
+ case "ERR_WEBRTC_SUPPORT":
3206
+ this.errors.raise(new import_errors4.ProtocolError("WebRTC not supported", err));
3207
+ case "ERR_ICE_CONNECTION_FAILURE":
3208
+ case "ERR_DATA_CHANNEL":
3209
+ case "ERR_CONNECTION_FAILURE":
3210
+ case "ERR_SIGNALING":
3211
+ this.errors.raise(new import_errors4.ConnectivityError("unknown communication failure", err));
3212
+ case "ERR_CREATE_OFFER":
3213
+ case "ERR_CREATE_ANSWER":
3214
+ case "ERR_SET_LOCAL_DESCRIPTION":
3215
+ case "ERR_SET_REMOTE_DESCRIPTION":
3216
+ case "ERR_ADD_ICE_CANDIDATE":
3217
+ this.errors.raise(new import_errors4.UnknownProtocolError("unknown simple-peer library failure", err));
3218
+ default:
3219
+ this.errors.raise(new Error("unknown simple-peer error"));
3220
+ }
3221
+ } else {
3222
+ this.errors.raise(err);
3223
+ }
3161
3224
  try {
3162
3225
  if (typeof this._peer?._pc.getStats === "function") {
3163
3226
  this._peer._pc.getStats().then((stats) => {
@@ -3166,13 +3229,19 @@ var SimplePeerTransport = class {
3166
3229
  stats
3167
3230
  }, {
3168
3231
  F: __dxlog_file12,
3169
- L: 72,
3232
+ L: 107,
3170
3233
  S: this,
3171
3234
  C: (f, a) => f(...a)
3172
3235
  });
3173
3236
  });
3174
3237
  }
3175
- } catch {
3238
+ } catch (err2) {
3239
+ import_log11.log.catch(err2, void 0, {
3240
+ F: __dxlog_file12,
3241
+ L: 114,
3242
+ S: this,
3243
+ C: (f, a) => f(...a)
3244
+ });
3176
3245
  }
3177
3246
  await this.destroy();
3178
3247
  });
@@ -3180,7 +3249,7 @@ var SimplePeerTransport = class {
3180
3249
  id: this._instanceId
3181
3250
  }), {
3182
3251
  F: __dxlog_file12,
3183
- L: 82,
3252
+ L: 119,
3184
3253
  S: this,
3185
3254
  C: (f, a) => f(...a)
3186
3255
  });
@@ -3188,7 +3257,7 @@ var SimplePeerTransport = class {
3188
3257
  async destroy() {
3189
3258
  (0, import_log11.log)("closing...", void 0, {
3190
3259
  F: __dxlog_file12,
3191
- L: 86,
3260
+ L: 123,
3192
3261
  S: this,
3193
3262
  C: (f, a) => f(...a)
3194
3263
  });
@@ -3198,7 +3267,7 @@ var SimplePeerTransport = class {
3198
3267
  this.closed.emit();
3199
3268
  (0, import_log11.log)("closed", void 0, {
3200
3269
  F: __dxlog_file12,
3201
- L: 91,
3270
+ L: 128,
3202
3271
  S: this,
3203
3272
  C: (f, a) => f(...a)
3204
3273
  });
@@ -3229,7 +3298,7 @@ var import_keys11 = require("@dxos/keys");
3229
3298
  var import_log12 = require("@dxos/log");
3230
3299
  var import_bridge = require("@dxos/protocols/proto/dxos/mesh/bridge");
3231
3300
  var import_util8 = require("@dxos/util");
3232
- var __dxlog_file13 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/simplepeer-transport-service.ts";
3301
+ var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport-service.ts";
3233
3302
  var SimplePeerTransportService = class {
3234
3303
  // prettier-ignore
3235
3304
  constructor(_webrtcConfig) {
@@ -3356,12 +3425,13 @@ var import_node_stream3 = require("node:stream");
3356
3425
  var import_async10 = require("@dxos/async");
3357
3426
  var import_context6 = require("@dxos/context");
3358
3427
  var import_debug6 = require("@dxos/debug");
3428
+ var import_errors5 = require("@dxos/errors");
3359
3429
  var import_invariant12 = require("@dxos/invariant");
3360
3430
  var import_keys12 = require("@dxos/keys");
3361
3431
  var import_log13 = require("@dxos/log");
3362
3432
  var import_bridge2 = require("@dxos/protocols/proto/dxos/mesh/bridge");
3363
3433
  var import_util9 = require("@dxos/util");
3364
- var __dxlog_file14 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/simplepeer-transport-proxy.ts";
3434
+ var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport-proxy.ts";
3365
3435
  var SimplePeerTransportProxy = class {
3366
3436
  // prettier-ignore
3367
3437
  constructor(_params) {
@@ -3380,7 +3450,7 @@ var SimplePeerTransportProxy = class {
3380
3450
  this._serviceStream.subscribe(async (event) => {
3381
3451
  (0, import_log13.log)("SimplePeerTransportProxy: event", event, {
3382
3452
  F: __dxlog_file14,
3383
- L: 51,
3453
+ L: 58,
3384
3454
  S: this,
3385
3455
  C: (f, a) => f(...a)
3386
3456
  });
@@ -3400,7 +3470,7 @@ var SimplePeerTransportProxy = class {
3400
3470
  }).then(() => callback(), (err) => {
3401
3471
  import_log13.log.catch(err, void 0, {
3402
3472
  F: __dxlog_file14,
3403
- L: 69,
3473
+ L: 76,
3404
3474
  S: this,
3405
3475
  C: (f, a) => f(...a)
3406
3476
  });
@@ -3409,14 +3479,14 @@ var SimplePeerTransportProxy = class {
3409
3479
  }));
3410
3480
  }, (error) => import_log13.log.catch(error, void 0, {
3411
3481
  F: __dxlog_file14,
3412
- L: 75,
3482
+ L: 82,
3413
3483
  S: this,
3414
3484
  C: (f, a) => f(...a)
3415
3485
  }));
3416
3486
  }
3417
3487
  async _handleConnection(connectionEvent) {
3418
3488
  if (connectionEvent.error) {
3419
- this.errors.raise(new Error(connectionEvent.error));
3489
+ this.errors.raise(decodeError(connectionEvent.error));
3420
3490
  }
3421
3491
  switch (connectionEvent.state) {
3422
3492
  case import_bridge2.ConnectionState.CONNECTED: {
@@ -3439,7 +3509,7 @@ var SimplePeerTransportProxy = class {
3439
3509
  this._params.bridgeService.sendSignal({
3440
3510
  proxyId: this._proxyId,
3441
3511
  signal
3442
- }).catch((err) => this.errors.raise(err));
3512
+ }).catch((err) => this.errors.raise(decodeError(err)));
3443
3513
  }
3444
3514
  // TODO(burdon): Move open from constructor.
3445
3515
  async destroy() {
@@ -3455,7 +3525,7 @@ var SimplePeerTransportProxy = class {
3455
3525
  } catch (err) {
3456
3526
  import_log13.log.catch(err, void 0, {
3457
3527
  F: __dxlog_file14,
3458
- L: 126,
3528
+ L: 133,
3459
3529
  S: this,
3460
3530
  C: (f, a) => f(...a)
3461
3531
  });
@@ -3491,7 +3561,7 @@ var SimplePeerTransportProxyFactory = class {
3491
3561
  createTransport(options) {
3492
3562
  (0, import_invariant12.invariant)(this._bridgeService, "SimplePeerTransportProxyFactory is not ready to open connections", {
3493
3563
  F: __dxlog_file14,
3494
- L: 163,
3564
+ L: 170,
3495
3565
  S: this,
3496
3566
  A: [
3497
3567
  "this._bridgeService",
@@ -3507,6 +3577,22 @@ var SimplePeerTransportProxyFactory = class {
3507
3577
  return transport;
3508
3578
  }
3509
3579
  };
3580
+ var decodeError = (err) => {
3581
+ const message = typeof err === "string" ? err : err.message;
3582
+ if (message.includes("ConnectionResetError")) {
3583
+ return new import_errors5.ConnectionResetError(message);
3584
+ } else if (message.includes("TimeoutError")) {
3585
+ return new import_errors5.TimeoutError(message);
3586
+ } else if (message.includes("ProtocolError")) {
3587
+ return new import_errors5.ProtocolError(message);
3588
+ } else if (message.includes("ConnectivityError")) {
3589
+ return new import_errors5.ConnectivityError(message);
3590
+ } else if (message.includes("UnknownProtocolError")) {
3591
+ return new import_errors5.UnknownProtocolError(message);
3592
+ } else {
3593
+ return typeof err === "string" ? new Error(err) : err;
3594
+ }
3595
+ };
3510
3596
 
3511
3597
  // packages/core/mesh/network-manager/src/transport/index.ts
3512
3598
  init_datachannel();
@@ -3526,7 +3612,7 @@ function _ts_decorate5(decorators, target, key, desc) {
3526
3612
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3527
3613
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3528
3614
  }
3529
- var __dxlog_file15 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/libdatachannel-transport.ts";
3615
+ var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/libdatachannel-transport.ts";
3530
3616
  var DATACHANNEL_LABEL = "dxos.mesh.transport";
3531
3617
  var MAX_BUFFERED_AMOUNT = 64 * 1024;
3532
3618
  var MAX_MESSAGE_SIZE = 64 * 1024;