@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.
@@ -555,7 +555,7 @@ function _ts_decorate(decorators, target, key, desc) {
555
555
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
556
556
  return c > 3 && r && Object.defineProperty(target, key, r), r;
557
557
  }
558
- var __dxlog_file = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/connection.ts";
558
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts";
559
559
  var STARTING_SIGNALLING_DELAY = 10;
560
560
  var MAX_SIGNALLING_DELAY = 300;
561
561
  var ConnectionState;
@@ -597,6 +597,8 @@ var ConnectionState;
597
597
  */
598
598
  "CLOSED"
599
599
  ] = "CLOSED";
600
+ ConnectionState6["ABORTING"] = "ABORTING";
601
+ ConnectionState6["ABORTED"] = "ABORTED";
600
602
  })(ConnectionState || (ConnectionState = {}));
601
603
  var Connection = class {
602
604
  constructor(topic, ownId, remoteId, sessionId, initiator, _signalMessaging, _protocol, _transportFactory, _callbacks) {
@@ -628,7 +630,7 @@ var Connection = class {
628
630
  initiator: this.initiator
629
631
  }, {
630
632
  F: __dxlog_file,
631
- L: 114,
633
+ L: 123,
632
634
  S: this,
633
635
  C: (f, a) => f(...a)
634
636
  });
@@ -648,7 +650,7 @@ var Connection = class {
648
650
  async openConnection() {
649
651
  (0, import_invariant.invariant)(this._state === ConnectionState.INITIAL, "Invalid state.", {
650
652
  F: __dxlog_file,
651
- L: 139,
653
+ L: 148,
652
654
  S: this,
653
655
  A: [
654
656
  "this._state === ConnectionState.INITIAL",
@@ -659,7 +661,7 @@ var Connection = class {
659
661
  id: this._instanceId
660
662
  }), {
661
663
  F: __dxlog_file,
662
- L: 140,
664
+ L: 149,
663
665
  S: this,
664
666
  C: (f, a) => f(...a)
665
667
  });
@@ -671,7 +673,7 @@ var Connection = class {
671
673
  initiator: this.initiator
672
674
  }, {
673
675
  F: __dxlog_file,
674
- L: 141,
676
+ L: 150,
675
677
  S: this,
676
678
  C: (f, a) => f(...a)
677
679
  });
@@ -682,15 +684,15 @@ var Connection = class {
682
684
  this._protocol.stream.on("close", () => {
683
685
  (0, import_log.log)("protocol stream closed", void 0, {
684
686
  F: __dxlog_file,
685
- L: 158,
687
+ L: 167,
686
688
  S: this,
687
689
  C: (f, a) => f(...a)
688
690
  });
689
- this.close().catch((err) => this.errors.raise(err));
691
+ this.close(new import_errors.ProtocolError("protocol stream closed")).catch((err) => this.errors.raise(err));
690
692
  });
691
693
  (0, import_invariant.invariant)(!this._transport, void 0, {
692
694
  F: __dxlog_file,
693
- L: 162,
695
+ L: 171,
694
696
  S: this,
695
697
  A: [
696
698
  "!this._transport",
@@ -710,7 +712,7 @@ var Connection = class {
710
712
  this._transport = void 0;
711
713
  (0, import_log.log)("abort triggered by transport close", void 0, {
712
714
  F: __dxlog_file,
713
- L: 176,
715
+ L: 185,
714
716
  S: this,
715
717
  C: (f, a) => f(...a)
716
718
  });
@@ -721,21 +723,38 @@ var Connection = class {
721
723
  err
722
724
  }, {
723
725
  F: __dxlog_file,
724
- L: 181,
726
+ L: 190,
725
727
  S: this,
726
728
  C: (f, a) => f(...a)
727
729
  });
728
730
  if (!this.closeReason) {
729
731
  this.closeReason = err?.message;
730
732
  }
731
- if (err?.message.includes("OperationError")) {
732
- (0, import_log.log)("aborting due to transport OperationError", void 0, {
733
+ if (err instanceof import_errors.ConnectionResetError) {
734
+ (0, import_log.log)("aborting due to transport ConnectionResetError", void 0, {
733
735
  F: __dxlog_file,
734
- L: 187,
736
+ L: 197,
735
737
  S: this,
736
738
  C: (f, a) => f(...a)
737
739
  });
738
740
  this.abort().catch((err2) => this.errors.raise(err2));
741
+ } else if (err instanceof import_errors.ConnectivityError) {
742
+ (0, import_log.log)("aborting due to transport ConnectivityError", void 0, {
743
+ F: __dxlog_file,
744
+ L: 200,
745
+ S: this,
746
+ C: (f, a) => f(...a)
747
+ });
748
+ this.abort().catch((err2) => this.errors.raise(err2));
749
+ } else if (err instanceof import_errors.UnknownProtocolError) {
750
+ (0, import_log.log)("unsure what to do for UnknownProtocolError", {
751
+ err
752
+ }, {
753
+ F: __dxlog_file,
754
+ L: 203,
755
+ S: this,
756
+ C: (f, a) => f(...a)
757
+ });
739
758
  }
740
759
  if (this._state !== ConnectionState.CLOSED && this._state !== ConnectionState.CLOSING) {
741
760
  this.errors.raise(err);
@@ -749,7 +768,7 @@ var Connection = class {
749
768
  id: this._instanceId
750
769
  }), {
751
770
  F: __dxlog_file,
752
- L: 203,
771
+ L: 218,
753
772
  S: this,
754
773
  C: (f, a) => f(...a)
755
774
  });
@@ -759,30 +778,30 @@ var Connection = class {
759
778
  err
760
779
  }, {
761
780
  F: __dxlog_file,
762
- L: 209,
781
+ L: 224,
763
782
  S: this,
764
783
  C: (f, a) => f(...a)
765
784
  });
766
- if (!this.closeReason) {
767
- this.closeReason = err?.message;
768
- }
769
- if (this._state === ConnectionState.CLOSED) {
770
- (0, import_log.log)("abort ignored: already closed", this.closeReason, {
785
+ if (this._state === ConnectionState.CLOSED || this._state === ConnectionState.ABORTED) {
786
+ (0, import_log.log)(`abort ignored: already ${this._state}`, this.closeReason, {
771
787
  F: __dxlog_file,
772
- L: 214,
788
+ L: 226,
773
789
  S: this,
774
790
  C: (f, a) => f(...a)
775
791
  });
776
792
  return;
777
793
  }
778
- this._changeState(ConnectionState.CLOSING);
794
+ this._changeState(ConnectionState.ABORTING);
795
+ if (!this.closeReason) {
796
+ this.closeReason = err?.message;
797
+ }
779
798
  await this._ctx.dispose();
780
799
  try {
781
800
  (0, import_log.log)("aborting protocol... ", {
782
801
  proto: this._protocol
783
802
  }, {
784
803
  F: __dxlog_file,
785
- L: 224,
804
+ L: 239,
786
805
  S: this,
787
806
  C: (f, a) => f(...a)
788
807
  });
@@ -790,7 +809,7 @@ var Connection = class {
790
809
  } catch (err2) {
791
810
  import_log.log.catch(err2, void 0, {
792
811
  F: __dxlog_file,
793
- L: 227,
812
+ L: 242,
794
813
  S: this,
795
814
  C: (f, a) => f(...a)
796
815
  });
@@ -800,56 +819,68 @@ var Connection = class {
800
819
  } catch (err2) {
801
820
  import_log.log.catch(err2, void 0, {
802
821
  F: __dxlog_file,
803
- L: 234,
822
+ L: 249,
804
823
  S: this,
805
824
  C: (f, a) => f(...a)
806
825
  });
807
826
  }
808
- this._changeState(ConnectionState.CLOSED);
809
- this._callbacks?.onClosed?.(err);
827
+ try {
828
+ this._callbacks?.onClosed?.(err);
829
+ } catch (err2) {
830
+ import_log.log.catch(err2, void 0, {
831
+ F: __dxlog_file,
832
+ L: 255,
833
+ S: this,
834
+ C: (f, a) => f(...a)
835
+ });
836
+ }
837
+ this._changeState(ConnectionState.ABORTED);
810
838
  }
811
839
  async close(err) {
812
840
  if (!this.closeReason) {
813
841
  this.closeReason = err?.message;
814
842
  }
815
- if (this._state === ConnectionState.CLOSED) {
843
+ if (this._state === ConnectionState.CLOSED || this._state === ConnectionState.ABORTING || this._state === ConnectionState.ABORTED) {
816
844
  return;
817
845
  }
846
+ const lastState = this._state;
818
847
  this._changeState(ConnectionState.CLOSING);
819
848
  await this._ctx.dispose();
820
849
  (0, import_log.log)("closing...", {
821
850
  peerId: this.ownId
822
851
  }, {
823
852
  F: __dxlog_file,
824
- L: 253,
853
+ L: 277,
825
854
  S: this,
826
855
  C: (f, a) => f(...a)
827
856
  });
828
- try {
829
- await this._protocol.close();
830
- } catch (err2) {
831
- import_log.log.catch(err2, void 0, {
832
- F: __dxlog_file,
833
- L: 259,
834
- S: this,
835
- C: (f, a) => f(...a)
836
- });
837
- }
838
- try {
839
- await this._transport?.destroy();
840
- } catch (err2) {
841
- import_log.log.catch(err2, void 0, {
842
- F: __dxlog_file,
843
- L: 266,
844
- S: this,
845
- C: (f, a) => f(...a)
846
- });
857
+ if (lastState === ConnectionState.CONNECTED) {
858
+ try {
859
+ await this._protocol.close();
860
+ } catch (err2) {
861
+ import_log.log.catch(err2, void 0, {
862
+ F: __dxlog_file,
863
+ L: 284,
864
+ S: this,
865
+ C: (f, a) => f(...a)
866
+ });
867
+ }
868
+ try {
869
+ await this._transport?.destroy();
870
+ } catch (err2) {
871
+ import_log.log.catch(err2, void 0, {
872
+ F: __dxlog_file,
873
+ L: 291,
874
+ S: this,
875
+ C: (f, a) => f(...a)
876
+ });
877
+ }
847
878
  }
848
879
  (0, import_log.log)("closed", {
849
880
  peerId: this.ownId
850
881
  }, {
851
882
  F: __dxlog_file,
852
- L: 269,
883
+ L: 295,
853
884
  S: this,
854
885
  C: (f, a) => f(...a)
855
886
  });
@@ -892,7 +923,7 @@ var Connection = class {
892
923
  err
893
924
  }, {
894
925
  F: __dxlog_file,
895
- L: 306,
926
+ L: 332,
896
927
  S: this,
897
928
  C: (f, a) => f(...a)
898
929
  });
@@ -905,7 +936,7 @@ var Connection = class {
905
936
  async signal(msg) {
906
937
  (0, import_invariant.invariant)(msg.sessionId, void 0, {
907
938
  F: __dxlog_file,
908
- L: 315,
939
+ L: 341,
909
940
  S: this,
910
941
  A: [
911
942
  "msg.sessionId",
@@ -915,7 +946,7 @@ var Connection = class {
915
946
  if (!msg.sessionId.equals(this.sessionId)) {
916
947
  (0, import_log.log)("dropping signal for incorrect session id", void 0, {
917
948
  F: __dxlog_file,
918
- L: 317,
949
+ L: 343,
919
950
  S: this,
920
951
  C: (f, a) => f(...a)
921
952
  });
@@ -923,7 +954,7 @@ var Connection = class {
923
954
  }
924
955
  (0, import_invariant.invariant)(msg.data.signal || msg.data.signalBatch, void 0, {
925
956
  F: __dxlog_file,
926
- L: 320,
957
+ L: 346,
927
958
  S: this,
928
959
  A: [
929
960
  "msg.data.signal || msg.data.signalBatch",
@@ -932,7 +963,7 @@ var Connection = class {
932
963
  });
933
964
  (0, import_invariant.invariant)(msg.author?.equals(this.remoteId), void 0, {
934
965
  F: __dxlog_file,
935
- L: 321,
966
+ L: 347,
936
967
  S: this,
937
968
  A: [
938
969
  "msg.author?.equals(this.remoteId)",
@@ -941,7 +972,7 @@ var Connection = class {
941
972
  });
942
973
  (0, import_invariant.invariant)(msg.recipient?.equals(this.ownId), void 0, {
943
974
  F: __dxlog_file,
944
- L: 322,
975
+ L: 348,
945
976
  S: this,
946
977
  A: [
947
978
  "msg.recipient?.equals(this.ownId)",
@@ -965,7 +996,7 @@ var Connection = class {
965
996
  msg: msg.data
966
997
  }, {
967
998
  F: __dxlog_file,
968
- L: 331,
999
+ L: 357,
969
1000
  S: this,
970
1001
  C: (f, a) => f(...a)
971
1002
  });
@@ -973,7 +1004,7 @@ var Connection = class {
973
1004
  } else {
974
1005
  (0, import_invariant.invariant)(this._transport, "Connection not ready to accept signals.", {
975
1006
  F: __dxlog_file,
976
- L: 334,
1007
+ L: 360,
977
1008
  S: this,
978
1009
  A: [
979
1010
  "this._transport",
@@ -986,7 +1017,7 @@ var Connection = class {
986
1017
  msg: msg.data
987
1018
  }, {
988
1019
  F: __dxlog_file,
989
- L: 335,
1020
+ L: 361,
990
1021
  S: this,
991
1022
  C: (f, a) => f(...a)
992
1023
  });
@@ -1000,17 +1031,17 @@ var Connection = class {
1000
1031
  _changeState(state) {
1001
1032
  (0, import_log.log)("stateChanged", {
1002
1033
  from: this._state,
1003
- too: state,
1034
+ to: state,
1004
1035
  peerId: this.ownId
1005
1036
  }, {
1006
1037
  F: __dxlog_file,
1007
- L: 346,
1038
+ L: 372,
1008
1039
  S: this,
1009
1040
  C: (f, a) => f(...a)
1010
1041
  });
1011
1042
  (0, import_invariant.invariant)(state !== this._state, "Already in this state.", {
1012
1043
  F: __dxlog_file,
1013
- L: 347,
1044
+ L: 373,
1014
1045
  S: this,
1015
1046
  A: [
1016
1047
  "state !== this._state",
@@ -1045,7 +1076,7 @@ var import_keys2 = require("@dxos/keys");
1045
1076
  var import_log2 = require("@dxos/log");
1046
1077
  var import_protocols2 = require("@dxos/protocols");
1047
1078
  var import_util = require("@dxos/util");
1048
- var __dxlog_file2 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
1079
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
1049
1080
  var SwarmMessage = import_protocols2.schema.getCodecForType("dxos.mesh.swarm.SwarmMessage");
1050
1081
  var SwarmMessenger = class {
1051
1082
  constructor({ sendMessage, onSignal, onOffer, topic }) {
@@ -1287,7 +1318,7 @@ function _ts_decorate2(decorators, target, key, desc) {
1287
1318
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1288
1319
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1289
1320
  }
1290
- var __dxlog_file3 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/peer.ts";
1321
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts";
1291
1322
  var ConnectionDisplacedError = class extends import_errors2.SystemError {
1292
1323
  constructor() {
1293
1324
  super("Connection displaced by remote initiator.");
@@ -1466,6 +1497,9 @@ var Peer = class {
1466
1497
  S: this,
1467
1498
  C: (f, a) => f(...a)
1468
1499
  });
1500
+ if (err instanceof import_errors2.TimeoutError) {
1501
+ await connection.abort(err);
1502
+ }
1469
1503
  await this.closeConnection(err);
1470
1504
  throw err;
1471
1505
  } finally {
@@ -1485,13 +1519,13 @@ var Peer = class {
1485
1519
  sessionId
1486
1520
  }, {
1487
1521
  F: __dxlog_file3,
1488
- L: 210,
1522
+ L: 213,
1489
1523
  S: this,
1490
1524
  C: (f, a) => f(...a)
1491
1525
  });
1492
1526
  (0, import_invariant3.invariant)(!this.connection, "Already connected.", {
1493
1527
  F: __dxlog_file3,
1494
- L: 217,
1528
+ L: 220,
1495
1529
  S: this,
1496
1530
  A: [
1497
1531
  "!this.connection",
@@ -1527,7 +1561,7 @@ var Peer = class {
1527
1561
  initiator
1528
1562
  }, {
1529
1563
  F: __dxlog_file3,
1530
- L: 236,
1564
+ L: 239,
1531
1565
  S: this,
1532
1566
  C: (f, a) => f(...a)
1533
1567
  });
@@ -1540,14 +1574,14 @@ var Peer = class {
1540
1574
  initiator
1541
1575
  }, {
1542
1576
  F: __dxlog_file3,
1543
- L: 245,
1577
+ L: 248,
1544
1578
  S: this,
1545
1579
  C: (f, a) => f(...a)
1546
1580
  });
1547
1581
  this._connectionLimiter.doneConnecting(sessionId);
1548
1582
  (0, import_invariant3.invariant)(this.connection === connection, "Connection mismatch (race condition).", {
1549
1583
  F: __dxlog_file3,
1550
- L: 250,
1584
+ L: 253,
1551
1585
  S: this,
1552
1586
  A: [
1553
1587
  "this.connection === connection",
@@ -1562,7 +1596,7 @@ var Peer = class {
1562
1596
  initiator
1563
1597
  }, {
1564
1598
  F: __dxlog_file3,
1565
- L: 252,
1599
+ L: 255,
1566
1600
  S: this,
1567
1601
  C: (f, a) => f(...a)
1568
1602
  });
@@ -1597,7 +1631,7 @@ var Peer = class {
1597
1631
  err
1598
1632
  }, {
1599
1633
  F: __dxlog_file3,
1600
- L: 292,
1634
+ L: 295,
1601
1635
  S: this,
1602
1636
  C: (f, a) => f(...a)
1603
1637
  });
@@ -1610,7 +1644,7 @@ var Peer = class {
1610
1644
  err
1611
1645
  }, {
1612
1646
  F: __dxlog_file3,
1613
- L: 293,
1647
+ L: 296,
1614
1648
  S: this,
1615
1649
  C: (f, a) => f(...a)
1616
1650
  });
@@ -1629,7 +1663,7 @@ var Peer = class {
1629
1663
  sessionId: connection.sessionId
1630
1664
  }, {
1631
1665
  F: __dxlog_file3,
1632
- L: 318,
1666
+ L: 321,
1633
1667
  S: this,
1634
1668
  C: (f, a) => f(...a)
1635
1669
  });
@@ -1639,7 +1673,7 @@ var Peer = class {
1639
1673
  sessionId: connection.sessionId
1640
1674
  }, {
1641
1675
  F: __dxlog_file3,
1642
- L: 324,
1676
+ L: 327,
1643
1677
  S: this,
1644
1678
  C: (f, a) => f(...a)
1645
1679
  });
@@ -1650,7 +1684,7 @@ var Peer = class {
1650
1684
  message
1651
1685
  }, {
1652
1686
  F: __dxlog_file3,
1653
- L: 329,
1687
+ L: 332,
1654
1688
  S: this,
1655
1689
  C: (f, a) => f(...a)
1656
1690
  });
@@ -1665,7 +1699,7 @@ var Peer = class {
1665
1699
  topic: this.topic
1666
1700
  }, {
1667
1701
  F: __dxlog_file3,
1668
- L: 339,
1702
+ L: 342,
1669
1703
  S: this,
1670
1704
  C: (f, a) => f(...a)
1671
1705
  });
@@ -1699,7 +1733,7 @@ function _ts_decorate3(decorators, target, key, desc) {
1699
1733
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1700
1734
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1701
1735
  }
1702
- var __dxlog_file4 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/swarm.ts";
1736
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts";
1703
1737
  var INITIATION_DELAY = 100;
1704
1738
  var getClassName = (obj) => Object.getPrototypeOf(obj).constructor.name;
1705
1739
  var Swarm = class {
@@ -2173,7 +2207,7 @@ var import_async4 = require("@dxos/async");
2173
2207
  var import_keys5 = require("@dxos/keys");
2174
2208
  var import_log5 = require("@dxos/log");
2175
2209
  var import_util3 = require("@dxos/util");
2176
- var __dxlog_file5 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
2210
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
2177
2211
  var SwarmMapper = class {
2178
2212
  get peers() {
2179
2213
  return Array.from(this._peers.values());
@@ -2246,7 +2280,7 @@ var import_invariant5 = require("@dxos/invariant");
2246
2280
  var import_keys6 = require("@dxos/keys");
2247
2281
  var import_log6 = require("@dxos/log");
2248
2282
  var import_util4 = require("@dxos/util");
2249
- var __dxlog_file6 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
2283
+ var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
2250
2284
  var MAX_CONCURRENT_INITIATING_CONNECTIONS = 10;
2251
2285
  var ConnectionLimiter = class {
2252
2286
  constructor({ maxConcurrentInitConnections = MAX_CONCURRENT_INITIATING_CONNECTIONS } = {}) {
@@ -2387,7 +2421,7 @@ var ConnectionLog = class {
2387
2421
  };
2388
2422
 
2389
2423
  // packages/core/mesh/network-manager/src/network-manager.ts
2390
- var __dxlog_file7 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/network-manager.ts";
2424
+ var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts";
2391
2425
  var NetworkManager = class {
2392
2426
  constructor({ transportFactory, signalManager, log: log1 }) {
2393
2427
  /**
@@ -2623,7 +2657,7 @@ var NetworkManager = class {
2623
2657
 
2624
2658
  // packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts
2625
2659
  var import_invariant7 = require("@dxos/invariant");
2626
- var __dxlog_file8 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
2660
+ var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
2627
2661
  var FullyConnectedTopology = class {
2628
2662
  toString() {
2629
2663
  return "FullyConnectedTopology";
@@ -2689,7 +2723,7 @@ function _ts_decorate4(decorators, target, key, desc) {
2689
2723
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2690
2724
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2691
2725
  }
2692
- var __dxlog_file9 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
2726
+ var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
2693
2727
  var MEMORY_TRANSPORT_DELAY = 1;
2694
2728
  var createStreamDelay = (delay) => {
2695
2729
  return new import_node_stream.Transform({
@@ -2871,6 +2905,7 @@ var import_simple_peer = __toESM(require("simple-peer"));
2871
2905
  var import_tiny_invariant = __toESM(require("tiny-invariant"));
2872
2906
  var import_async9 = require("@dxos/async");
2873
2907
  var import_debug5 = require("@dxos/debug");
2908
+ var import_errors4 = require("@dxos/errors");
2874
2909
  var import_keys10 = require("@dxos/keys");
2875
2910
  var import_log11 = require("@dxos/log");
2876
2911
  var import_protocols5 = require("@dxos/protocols");
@@ -2883,7 +2918,7 @@ try {
2883
2918
  }
2884
2919
 
2885
2920
  // packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts
2886
- var __dxlog_file10 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts";
2921
+ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts";
2887
2922
  var SimplePeerTransport = class {
2888
2923
  constructor(params) {
2889
2924
  this.params = params;
@@ -2896,13 +2931,13 @@ var SimplePeerTransport = class {
2896
2931
  id: this._instanceId
2897
2932
  }), {
2898
2933
  F: __dxlog_file10,
2899
- L: 39,
2934
+ L: 41,
2900
2935
  S: this,
2901
2936
  C: (f, a) => f(...a)
2902
2937
  });
2903
2938
  (0, import_log11.log)("created connection", params, {
2904
2939
  F: __dxlog_file10,
2905
- L: 40,
2940
+ L: 42,
2906
2941
  S: this,
2907
2942
  C: (f, a) => f(...a)
2908
2943
  });
@@ -2915,7 +2950,7 @@ var SimplePeerTransport = class {
2915
2950
  this._peer.on("signal", async (data) => {
2916
2951
  (0, import_log11.log)("signal", data, {
2917
2952
  F: __dxlog_file10,
2918
- L: 49,
2953
+ L: 51,
2919
2954
  S: this,
2920
2955
  C: (f, a) => f(...a)
2921
2956
  });
@@ -2928,7 +2963,7 @@ var SimplePeerTransport = class {
2928
2963
  this._peer.on("connect", () => {
2929
2964
  (0, import_log11.log)("connected", void 0, {
2930
2965
  F: __dxlog_file10,
2931
- L: 54,
2966
+ L: 56,
2932
2967
  S: this,
2933
2968
  C: (f, a) => f(...a)
2934
2969
  });
@@ -2938,7 +2973,7 @@ var SimplePeerTransport = class {
2938
2973
  this._peer.on("close", async () => {
2939
2974
  (0, import_log11.log)("closed", void 0, {
2940
2975
  F: __dxlog_file10,
2941
- L: 60,
2976
+ L: 62,
2942
2977
  S: this,
2943
2978
  C: (f, a) => f(...a)
2944
2979
  });
@@ -2946,7 +2981,35 @@ var SimplePeerTransport = class {
2946
2981
  this.closed.emit();
2947
2982
  });
2948
2983
  this._peer.on("error", async (err) => {
2949
- this.errors.raise(err);
2984
+ if (typeof RTCError !== "undefined" && err instanceof RTCError) {
2985
+ if (err.errorDetail === "sctp-failure") {
2986
+ this.errors.raise(new import_errors4.ConnectionResetError("sctp-failure from RTCError", err));
2987
+ } else {
2988
+ this.errors.raise(new import_errors4.UnknownProtocolError("unknown RTCError", err));
2989
+ }
2990
+ } else if (err.name === "InvalidStateError") {
2991
+ this.errors.raise(new import_errors4.ConnectionResetError("safari WebRTC error", err));
2992
+ } else if ("code" in err) {
2993
+ switch (err.code) {
2994
+ case "ERR_WEBRTC_SUPPORT":
2995
+ this.errors.raise(new import_errors4.ProtocolError("WebRTC not supported", err));
2996
+ case "ERR_ICE_CONNECTION_FAILURE":
2997
+ case "ERR_DATA_CHANNEL":
2998
+ case "ERR_CONNECTION_FAILURE":
2999
+ case "ERR_SIGNALING":
3000
+ this.errors.raise(new import_errors4.ConnectivityError("unknown communication failure", err));
3001
+ case "ERR_CREATE_OFFER":
3002
+ case "ERR_CREATE_ANSWER":
3003
+ case "ERR_SET_LOCAL_DESCRIPTION":
3004
+ case "ERR_SET_REMOTE_DESCRIPTION":
3005
+ case "ERR_ADD_ICE_CANDIDATE":
3006
+ this.errors.raise(new import_errors4.UnknownProtocolError("unknown simple-peer library failure", err));
3007
+ default:
3008
+ this.errors.raise(new Error("unknown simple-peer error"));
3009
+ }
3010
+ } else {
3011
+ this.errors.raise(err);
3012
+ }
2950
3013
  try {
2951
3014
  if (typeof this._peer?._pc.getStats === "function") {
2952
3015
  this._peer._pc.getStats().then((stats) => {
@@ -2955,13 +3018,19 @@ var SimplePeerTransport = class {
2955
3018
  stats
2956
3019
  }, {
2957
3020
  F: __dxlog_file10,
2958
- L: 72,
3021
+ L: 107,
2959
3022
  S: this,
2960
3023
  C: (f, a) => f(...a)
2961
3024
  });
2962
3025
  });
2963
3026
  }
2964
- } catch {
3027
+ } catch (err2) {
3028
+ import_log11.log.catch(err2, void 0, {
3029
+ F: __dxlog_file10,
3030
+ L: 114,
3031
+ S: this,
3032
+ C: (f, a) => f(...a)
3033
+ });
2965
3034
  }
2966
3035
  await this.destroy();
2967
3036
  });
@@ -2969,7 +3038,7 @@ var SimplePeerTransport = class {
2969
3038
  id: this._instanceId
2970
3039
  }), {
2971
3040
  F: __dxlog_file10,
2972
- L: 82,
3041
+ L: 119,
2973
3042
  S: this,
2974
3043
  C: (f, a) => f(...a)
2975
3044
  });
@@ -2977,7 +3046,7 @@ var SimplePeerTransport = class {
2977
3046
  async destroy() {
2978
3047
  (0, import_log11.log)("closing...", void 0, {
2979
3048
  F: __dxlog_file10,
2980
- L: 86,
3049
+ L: 123,
2981
3050
  S: this,
2982
3051
  C: (f, a) => f(...a)
2983
3052
  });
@@ -2987,7 +3056,7 @@ var SimplePeerTransport = class {
2987
3056
  this.closed.emit();
2988
3057
  (0, import_log11.log)("closed", void 0, {
2989
3058
  F: __dxlog_file10,
2990
- L: 91,
3059
+ L: 128,
2991
3060
  S: this,
2992
3061
  C: (f, a) => f(...a)
2993
3062
  });
@@ -3018,7 +3087,7 @@ var import_keys11 = require("@dxos/keys");
3018
3087
  var import_log12 = require("@dxos/log");
3019
3088
  var import_bridge = require("@dxos/protocols/proto/dxos/mesh/bridge");
3020
3089
  var import_util8 = require("@dxos/util");
3021
- var __dxlog_file11 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/simplepeer-transport-service.ts";
3090
+ var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport-service.ts";
3022
3091
  var SimplePeerTransportService = class {
3023
3092
  // prettier-ignore
3024
3093
  constructor(_webrtcConfig) {
@@ -3145,12 +3214,13 @@ var import_node_stream3 = require("node:stream");
3145
3214
  var import_async10 = require("@dxos/async");
3146
3215
  var import_context6 = require("@dxos/context");
3147
3216
  var import_debug6 = require("@dxos/debug");
3217
+ var import_errors5 = require("@dxos/errors");
3148
3218
  var import_invariant12 = require("@dxos/invariant");
3149
3219
  var import_keys12 = require("@dxos/keys");
3150
3220
  var import_log13 = require("@dxos/log");
3151
3221
  var import_bridge2 = require("@dxos/protocols/proto/dxos/mesh/bridge");
3152
3222
  var import_util9 = require("@dxos/util");
3153
- var __dxlog_file12 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/simplepeer-transport-proxy.ts";
3223
+ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport-proxy.ts";
3154
3224
  var SimplePeerTransportProxy = class {
3155
3225
  // prettier-ignore
3156
3226
  constructor(_params) {
@@ -3169,7 +3239,7 @@ var SimplePeerTransportProxy = class {
3169
3239
  this._serviceStream.subscribe(async (event) => {
3170
3240
  (0, import_log13.log)("SimplePeerTransportProxy: event", event, {
3171
3241
  F: __dxlog_file12,
3172
- L: 51,
3242
+ L: 58,
3173
3243
  S: this,
3174
3244
  C: (f, a) => f(...a)
3175
3245
  });
@@ -3189,7 +3259,7 @@ var SimplePeerTransportProxy = class {
3189
3259
  }).then(() => callback(), (err) => {
3190
3260
  import_log13.log.catch(err, void 0, {
3191
3261
  F: __dxlog_file12,
3192
- L: 69,
3262
+ L: 76,
3193
3263
  S: this,
3194
3264
  C: (f, a) => f(...a)
3195
3265
  });
@@ -3198,14 +3268,14 @@ var SimplePeerTransportProxy = class {
3198
3268
  }));
3199
3269
  }, (error) => import_log13.log.catch(error, void 0, {
3200
3270
  F: __dxlog_file12,
3201
- L: 75,
3271
+ L: 82,
3202
3272
  S: this,
3203
3273
  C: (f, a) => f(...a)
3204
3274
  }));
3205
3275
  }
3206
3276
  async _handleConnection(connectionEvent) {
3207
3277
  if (connectionEvent.error) {
3208
- this.errors.raise(new Error(connectionEvent.error));
3278
+ this.errors.raise(decodeError(connectionEvent.error));
3209
3279
  }
3210
3280
  switch (connectionEvent.state) {
3211
3281
  case import_bridge2.ConnectionState.CONNECTED: {
@@ -3228,7 +3298,7 @@ var SimplePeerTransportProxy = class {
3228
3298
  this._params.bridgeService.sendSignal({
3229
3299
  proxyId: this._proxyId,
3230
3300
  signal
3231
- }).catch((err) => this.errors.raise(err));
3301
+ }).catch((err) => this.errors.raise(decodeError(err)));
3232
3302
  }
3233
3303
  // TODO(burdon): Move open from constructor.
3234
3304
  async destroy() {
@@ -3244,7 +3314,7 @@ var SimplePeerTransportProxy = class {
3244
3314
  } catch (err) {
3245
3315
  import_log13.log.catch(err, void 0, {
3246
3316
  F: __dxlog_file12,
3247
- L: 126,
3317
+ L: 133,
3248
3318
  S: this,
3249
3319
  C: (f, a) => f(...a)
3250
3320
  });
@@ -3280,7 +3350,7 @@ var SimplePeerTransportProxyFactory = class {
3280
3350
  createTransport(options) {
3281
3351
  (0, import_invariant12.invariant)(this._bridgeService, "SimplePeerTransportProxyFactory is not ready to open connections", {
3282
3352
  F: __dxlog_file12,
3283
- L: 163,
3353
+ L: 170,
3284
3354
  S: this,
3285
3355
  A: [
3286
3356
  "this._bridgeService",
@@ -3296,6 +3366,22 @@ var SimplePeerTransportProxyFactory = class {
3296
3366
  return transport;
3297
3367
  }
3298
3368
  };
3369
+ var decodeError = (err) => {
3370
+ const message = typeof err === "string" ? err : err.message;
3371
+ if (message.includes("ConnectionResetError")) {
3372
+ return new import_errors5.ConnectionResetError(message);
3373
+ } else if (message.includes("TimeoutError")) {
3374
+ return new import_errors5.TimeoutError(message);
3375
+ } else if (message.includes("ProtocolError")) {
3376
+ return new import_errors5.ProtocolError(message);
3377
+ } else if (message.includes("ConnectivityError")) {
3378
+ return new import_errors5.ConnectivityError(message);
3379
+ } else if (message.includes("UnknownProtocolError")) {
3380
+ return new import_errors5.UnknownProtocolError(message);
3381
+ } else {
3382
+ return typeof err === "string" ? new Error(err) : err;
3383
+ }
3384
+ };
3299
3385
 
3300
3386
  // packages/core/mesh/network-manager/src/transport/index.ts
3301
3387
  init_datachannel();
@@ -3315,7 +3401,7 @@ function _ts_decorate5(decorators, target, key, desc) {
3315
3401
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3316
3402
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3317
3403
  }
3318
- var __dxlog_file13 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/libdatachannel-transport.ts";
3404
+ var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/libdatachannel-transport.ts";
3319
3405
  var DATACHANNEL_LABEL = "dxos.mesh.transport";
3320
3406
  var MAX_BUFFERED_AMOUNT = 64 * 1024;
3321
3407
  var MAX_MESSAGE_SIZE = 64 * 1024;
@@ -3668,7 +3754,7 @@ var createTeleportProtocolFactory = (onConnection) => {
3668
3754
  };
3669
3755
 
3670
3756
  // packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts
3671
- var __dxlog_file14 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts";
3757
+ var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts";
3672
3758
  var TestWireProtocol = class {
3673
3759
  constructor(peerId, _extensionFactory = () => []) {
3674
3760
  this.peerId = peerId;
@@ -3752,7 +3838,7 @@ var TestWireProtocol = class {
3752
3838
  };
3753
3839
 
3754
3840
  // packages/core/mesh/network-manager/src/testing/test-builder.ts
3755
- var __dxlog_file15 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/testing/test-builder.ts";
3841
+ var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-builder.ts";
3756
3842
  var port = process.env.SIGNAL_PORT ?? 4e3;
3757
3843
  var TEST_SIGNAL_HOSTS = [
3758
3844
  {