@dxos/network-manager 0.1.57 → 0.1.58-main.0e9c99e

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.
Files changed (37) hide show
  1. package/dist/lib/browser/{chunk-UKMTAO4L.mjs → chunk-CNQ55TFQ.mjs} +197 -112
  2. package/dist/lib/browser/chunk-CNQ55TFQ.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +1 -1
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/testing/index.mjs +155 -22
  6. package/dist/lib/browser/testing/index.mjs.map +4 -4
  7. package/dist/lib/node/index.cjs +207 -122
  8. package/dist/lib/node/index.cjs.map +3 -3
  9. package/dist/lib/node/meta.json +1 -1
  10. package/dist/lib/node/testing/index.cjs +363 -145
  11. package/dist/lib/node/testing/index.cjs.map +4 -4
  12. package/dist/types/src/swarm/connection-limiter.d.ts +1 -1
  13. package/dist/types/src/swarm/connection-limiter.d.ts.map +1 -1
  14. package/dist/types/src/swarm/connection.d.ts +3 -1
  15. package/dist/types/src/swarm/connection.d.ts.map +1 -1
  16. package/dist/types/src/swarm/peer.d.ts +1 -1
  17. package/dist/types/src/swarm/peer.d.ts.map +1 -1
  18. package/dist/types/src/testing/test-builder.d.ts.map +1 -1
  19. package/dist/types/src/tests/tcp-transport.test.d.ts +2 -0
  20. package/dist/types/src/tests/tcp-transport.test.d.ts.map +1 -0
  21. package/dist/types/src/transport/simplepeer-transport-proxy.d.ts.map +1 -1
  22. package/dist/types/src/transport/simplepeer-transport.d.ts.map +1 -1
  23. package/dist/types/src/transport/tcp-transport.d.ts +23 -0
  24. package/dist/types/src/transport/tcp-transport.d.ts.map +1 -0
  25. package/dist/types/src/transport/transport.d.ts +2 -1
  26. package/dist/types/src/transport/transport.d.ts.map +1 -1
  27. package/package.json +17 -18
  28. package/src/swarm/connection-limiter.ts +2 -2
  29. package/src/swarm/connection.ts +53 -27
  30. package/src/swarm/peer.ts +4 -1
  31. package/src/testing/test-builder.ts +5 -1
  32. package/src/tests/tcp-transport.test.ts +67 -0
  33. package/src/transport/simplepeer-transport-proxy.ts +28 -2
  34. package/src/transport/simplepeer-transport.ts +39 -3
  35. package/src/transport/tcp-transport.ts +107 -0
  36. package/src/transport/transport.ts +1 -0
  37. package/dist/lib/browser/chunk-UKMTAO4L.mjs.map +0 -7
@@ -513,9 +513,9 @@ module.exports = __toCommonJS(testing_exports);
513
513
 
514
514
  // packages/core/mesh/network-manager/src/testing/test-builder.ts
515
515
  var import_keys14 = require("@dxos/keys");
516
- var import_log16 = require("@dxos/log");
516
+ var import_log17 = require("@dxos/log");
517
517
  var import_messaging2 = require("@dxos/messaging");
518
- var import_protocols6 = require("@dxos/protocols");
518
+ var import_protocols9 = require("@dxos/protocols");
519
519
  var import_services2 = require("@dxos/protocols/proto/dxos/client/services");
520
520
  var import_rpc = require("@dxos/rpc");
521
521
  var import_util11 = require("@dxos/util");
@@ -526,7 +526,7 @@ var import_invariant6 = require("@dxos/invariant");
526
526
  var import_keys8 = require("@dxos/keys");
527
527
  var import_log7 = require("@dxos/log");
528
528
  var import_messaging = require("@dxos/messaging");
529
- var import_protocols4 = require("@dxos/protocols");
529
+ var import_protocols6 = require("@dxos/protocols");
530
530
  var import_services = require("@dxos/protocols/proto/dxos/client/services");
531
531
  var import_util6 = require("@dxos/util");
532
532
 
@@ -540,7 +540,6 @@ var import_util5 = require("@dxos/util");
540
540
  var import_async = require("@dxos/async");
541
541
  var import_context = require("@dxos/context");
542
542
  var import_debug = require("@dxos/debug");
543
- var import_errors = require("@dxos/errors");
544
543
  var import_invariant = require("@dxos/invariant");
545
544
  var import_keys = require("@dxos/keys");
546
545
  var import_log = require("@dxos/log");
@@ -555,7 +554,7 @@ function _ts_decorate(decorators, target, key, desc) {
555
554
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
556
555
  return c > 3 && r && Object.defineProperty(target, key, r), r;
557
556
  }
558
- var __dxlog_file = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/connection.ts";
557
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts";
559
558
  var STARTING_SIGNALLING_DELAY = 10;
560
559
  var MAX_SIGNALLING_DELAY = 300;
561
560
  var ConnectionState;
@@ -597,6 +596,8 @@ var ConnectionState;
597
596
  */
598
597
  "CLOSED"
599
598
  ] = "CLOSED";
599
+ ConnectionState6["ABORTING"] = "ABORTING";
600
+ ConnectionState6["ABORTED"] = "ABORTED";
600
601
  })(ConnectionState || (ConnectionState = {}));
601
602
  var Connection = class {
602
603
  constructor(topic, ownId, remoteId, sessionId, initiator, _signalMessaging, _protocol, _transportFactory, _callbacks) {
@@ -628,7 +629,7 @@ var Connection = class {
628
629
  initiator: this.initiator
629
630
  }, {
630
631
  F: __dxlog_file,
631
- L: 114,
632
+ L: 123,
632
633
  S: this,
633
634
  C: (f, a) => f(...a)
634
635
  });
@@ -648,7 +649,7 @@ var Connection = class {
648
649
  async openConnection() {
649
650
  (0, import_invariant.invariant)(this._state === ConnectionState.INITIAL, "Invalid state.", {
650
651
  F: __dxlog_file,
651
- L: 139,
652
+ L: 148,
652
653
  S: this,
653
654
  A: [
654
655
  "this._state === ConnectionState.INITIAL",
@@ -659,7 +660,7 @@ var Connection = class {
659
660
  id: this._instanceId
660
661
  }), {
661
662
  F: __dxlog_file,
662
- L: 140,
663
+ L: 149,
663
664
  S: this,
664
665
  C: (f, a) => f(...a)
665
666
  });
@@ -671,7 +672,7 @@ var Connection = class {
671
672
  initiator: this.initiator
672
673
  }, {
673
674
  F: __dxlog_file,
674
- L: 141,
675
+ L: 150,
675
676
  S: this,
676
677
  C: (f, a) => f(...a)
677
678
  });
@@ -682,15 +683,15 @@ var Connection = class {
682
683
  this._protocol.stream.on("close", () => {
683
684
  (0, import_log.log)("protocol stream closed", void 0, {
684
685
  F: __dxlog_file,
685
- L: 158,
686
+ L: 167,
686
687
  S: this,
687
688
  C: (f, a) => f(...a)
688
689
  });
689
- this.close().catch((err) => this.errors.raise(err));
690
+ this.close(new import_protocols.ProtocolError("protocol stream closed")).catch((err) => this.errors.raise(err));
690
691
  });
691
692
  (0, import_invariant.invariant)(!this._transport, void 0, {
692
693
  F: __dxlog_file,
693
- L: 162,
694
+ L: 171,
694
695
  S: this,
695
696
  A: [
696
697
  "!this._transport",
@@ -710,7 +711,7 @@ var Connection = class {
710
711
  this._transport = void 0;
711
712
  (0, import_log.log)("abort triggered by transport close", void 0, {
712
713
  F: __dxlog_file,
713
- L: 176,
714
+ L: 185,
714
715
  S: this,
715
716
  C: (f, a) => f(...a)
716
717
  });
@@ -721,21 +722,38 @@ var Connection = class {
721
722
  err
722
723
  }, {
723
724
  F: __dxlog_file,
724
- L: 181,
725
+ L: 190,
725
726
  S: this,
726
727
  C: (f, a) => f(...a)
727
728
  });
728
729
  if (!this.closeReason) {
729
730
  this.closeReason = err?.message;
730
731
  }
731
- if (err?.message.includes("OperationError")) {
732
- (0, import_log.log)("aborting due to transport OperationError", void 0, {
732
+ if (err instanceof import_protocols.ConnectionResetError) {
733
+ (0, import_log.log)("aborting due to transport ConnectionResetError", void 0, {
734
+ F: __dxlog_file,
735
+ L: 197,
736
+ S: this,
737
+ C: (f, a) => f(...a)
738
+ });
739
+ this.abort().catch((err2) => this.errors.raise(err2));
740
+ } else if (err instanceof import_protocols.ConnectivityError) {
741
+ (0, import_log.log)("aborting due to transport ConnectivityError", void 0, {
733
742
  F: __dxlog_file,
734
- L: 187,
743
+ L: 200,
735
744
  S: this,
736
745
  C: (f, a) => f(...a)
737
746
  });
738
747
  this.abort().catch((err2) => this.errors.raise(err2));
748
+ } else if (err instanceof import_protocols.UnknownProtocolError) {
749
+ (0, import_log.log)("unsure what to do for UnknownProtocolError", {
750
+ err
751
+ }, {
752
+ F: __dxlog_file,
753
+ L: 203,
754
+ S: this,
755
+ C: (f, a) => f(...a)
756
+ });
739
757
  }
740
758
  if (this._state !== ConnectionState.CLOSED && this._state !== ConnectionState.CLOSING) {
741
759
  this.errors.raise(err);
@@ -749,7 +767,7 @@ var Connection = class {
749
767
  id: this._instanceId
750
768
  }), {
751
769
  F: __dxlog_file,
752
- L: 203,
770
+ L: 218,
753
771
  S: this,
754
772
  C: (f, a) => f(...a)
755
773
  });
@@ -759,30 +777,30 @@ var Connection = class {
759
777
  err
760
778
  }, {
761
779
  F: __dxlog_file,
762
- L: 209,
780
+ L: 224,
763
781
  S: this,
764
782
  C: (f, a) => f(...a)
765
783
  });
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, {
784
+ if (this._state === ConnectionState.CLOSED || this._state === ConnectionState.ABORTED) {
785
+ (0, import_log.log)(`abort ignored: already ${this._state}`, this.closeReason, {
771
786
  F: __dxlog_file,
772
- L: 214,
787
+ L: 226,
773
788
  S: this,
774
789
  C: (f, a) => f(...a)
775
790
  });
776
791
  return;
777
792
  }
778
- this._changeState(ConnectionState.CLOSING);
793
+ this._changeState(ConnectionState.ABORTING);
794
+ if (!this.closeReason) {
795
+ this.closeReason = err?.message;
796
+ }
779
797
  await this._ctx.dispose();
780
798
  try {
781
799
  (0, import_log.log)("aborting protocol... ", {
782
800
  proto: this._protocol
783
801
  }, {
784
802
  F: __dxlog_file,
785
- L: 224,
803
+ L: 239,
786
804
  S: this,
787
805
  C: (f, a) => f(...a)
788
806
  });
@@ -790,7 +808,7 @@ var Connection = class {
790
808
  } catch (err2) {
791
809
  import_log.log.catch(err2, void 0, {
792
810
  F: __dxlog_file,
793
- L: 227,
811
+ L: 242,
794
812
  S: this,
795
813
  C: (f, a) => f(...a)
796
814
  });
@@ -800,56 +818,68 @@ var Connection = class {
800
818
  } catch (err2) {
801
819
  import_log.log.catch(err2, void 0, {
802
820
  F: __dxlog_file,
803
- L: 234,
821
+ L: 249,
804
822
  S: this,
805
823
  C: (f, a) => f(...a)
806
824
  });
807
825
  }
808
- this._changeState(ConnectionState.CLOSED);
809
- this._callbacks?.onClosed?.(err);
826
+ try {
827
+ this._callbacks?.onClosed?.(err);
828
+ } catch (err2) {
829
+ import_log.log.catch(err2, void 0, {
830
+ F: __dxlog_file,
831
+ L: 255,
832
+ S: this,
833
+ C: (f, a) => f(...a)
834
+ });
835
+ }
836
+ this._changeState(ConnectionState.ABORTED);
810
837
  }
811
838
  async close(err) {
812
839
  if (!this.closeReason) {
813
840
  this.closeReason = err?.message;
814
841
  }
815
- if (this._state === ConnectionState.CLOSED) {
842
+ if (this._state === ConnectionState.CLOSED || this._state === ConnectionState.ABORTING || this._state === ConnectionState.ABORTED) {
816
843
  return;
817
844
  }
845
+ const lastState = this._state;
818
846
  this._changeState(ConnectionState.CLOSING);
819
847
  await this._ctx.dispose();
820
848
  (0, import_log.log)("closing...", {
821
849
  peerId: this.ownId
822
850
  }, {
823
851
  F: __dxlog_file,
824
- L: 253,
852
+ L: 277,
825
853
  S: this,
826
854
  C: (f, a) => f(...a)
827
855
  });
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
- });
856
+ if (lastState === ConnectionState.CONNECTED) {
857
+ try {
858
+ await this._protocol.close();
859
+ } catch (err2) {
860
+ import_log.log.catch(err2, void 0, {
861
+ F: __dxlog_file,
862
+ L: 284,
863
+ S: this,
864
+ C: (f, a) => f(...a)
865
+ });
866
+ }
867
+ try {
868
+ await this._transport?.destroy();
869
+ } catch (err2) {
870
+ import_log.log.catch(err2, void 0, {
871
+ F: __dxlog_file,
872
+ L: 291,
873
+ S: this,
874
+ C: (f, a) => f(...a)
875
+ });
876
+ }
847
877
  }
848
878
  (0, import_log.log)("closed", {
849
879
  peerId: this.ownId
850
880
  }, {
851
881
  F: __dxlog_file,
852
- L: 269,
882
+ L: 295,
853
883
  S: this,
854
884
  C: (f, a) => f(...a)
855
885
  });
@@ -885,14 +915,14 @@ var Connection = class {
885
915
  }
886
916
  });
887
917
  } catch (err) {
888
- if (err instanceof import_errors.CancelledError) {
918
+ if (err instanceof import_protocols.CancelledError) {
889
919
  return;
890
920
  }
891
921
  import_log.log.warn("signal failed", {
892
922
  err
893
923
  }, {
894
924
  F: __dxlog_file,
895
- L: 306,
925
+ L: 332,
896
926
  S: this,
897
927
  C: (f, a) => f(...a)
898
928
  });
@@ -905,7 +935,7 @@ var Connection = class {
905
935
  async signal(msg) {
906
936
  (0, import_invariant.invariant)(msg.sessionId, void 0, {
907
937
  F: __dxlog_file,
908
- L: 315,
938
+ L: 341,
909
939
  S: this,
910
940
  A: [
911
941
  "msg.sessionId",
@@ -915,7 +945,7 @@ var Connection = class {
915
945
  if (!msg.sessionId.equals(this.sessionId)) {
916
946
  (0, import_log.log)("dropping signal for incorrect session id", void 0, {
917
947
  F: __dxlog_file,
918
- L: 317,
948
+ L: 343,
919
949
  S: this,
920
950
  C: (f, a) => f(...a)
921
951
  });
@@ -923,7 +953,7 @@ var Connection = class {
923
953
  }
924
954
  (0, import_invariant.invariant)(msg.data.signal || msg.data.signalBatch, void 0, {
925
955
  F: __dxlog_file,
926
- L: 320,
956
+ L: 346,
927
957
  S: this,
928
958
  A: [
929
959
  "msg.data.signal || msg.data.signalBatch",
@@ -932,7 +962,7 @@ var Connection = class {
932
962
  });
933
963
  (0, import_invariant.invariant)(msg.author?.equals(this.remoteId), void 0, {
934
964
  F: __dxlog_file,
935
- L: 321,
965
+ L: 347,
936
966
  S: this,
937
967
  A: [
938
968
  "msg.author?.equals(this.remoteId)",
@@ -941,7 +971,7 @@ var Connection = class {
941
971
  });
942
972
  (0, import_invariant.invariant)(msg.recipient?.equals(this.ownId), void 0, {
943
973
  F: __dxlog_file,
944
- L: 322,
974
+ L: 348,
945
975
  S: this,
946
976
  A: [
947
977
  "msg.recipient?.equals(this.ownId)",
@@ -965,7 +995,7 @@ var Connection = class {
965
995
  msg: msg.data
966
996
  }, {
967
997
  F: __dxlog_file,
968
- L: 331,
998
+ L: 357,
969
999
  S: this,
970
1000
  C: (f, a) => f(...a)
971
1001
  });
@@ -973,7 +1003,7 @@ var Connection = class {
973
1003
  } else {
974
1004
  (0, import_invariant.invariant)(this._transport, "Connection not ready to accept signals.", {
975
1005
  F: __dxlog_file,
976
- L: 334,
1006
+ L: 360,
977
1007
  S: this,
978
1008
  A: [
979
1009
  "this._transport",
@@ -986,7 +1016,7 @@ var Connection = class {
986
1016
  msg: msg.data
987
1017
  }, {
988
1018
  F: __dxlog_file,
989
- L: 335,
1019
+ L: 361,
990
1020
  S: this,
991
1021
  C: (f, a) => f(...a)
992
1022
  });
@@ -1000,17 +1030,17 @@ var Connection = class {
1000
1030
  _changeState(state) {
1001
1031
  (0, import_log.log)("stateChanged", {
1002
1032
  from: this._state,
1003
- too: state,
1033
+ to: state,
1004
1034
  peerId: this.ownId
1005
1035
  }, {
1006
1036
  F: __dxlog_file,
1007
- L: 346,
1037
+ L: 372,
1008
1038
  S: this,
1009
1039
  C: (f, a) => f(...a)
1010
1040
  });
1011
1041
  (0, import_invariant.invariant)(state !== this._state, "Already in this state.", {
1012
1042
  F: __dxlog_file,
1013
- L: 347,
1043
+ L: 373,
1014
1044
  S: this,
1015
1045
  A: [
1016
1046
  "state !== this._state",
@@ -1035,7 +1065,7 @@ var import_debug2 = require("@dxos/debug");
1035
1065
  var import_invariant4 = require("@dxos/invariant");
1036
1066
  var import_keys4 = require("@dxos/keys");
1037
1067
  var import_log4 = require("@dxos/log");
1038
- var import_protocols3 = require("@dxos/protocols");
1068
+ var import_protocols4 = require("@dxos/protocols");
1039
1069
  var import_util2 = require("@dxos/util");
1040
1070
 
1041
1071
  // packages/core/mesh/network-manager/src/signal/swarm-messenger.ts
@@ -1045,7 +1075,7 @@ var import_keys2 = require("@dxos/keys");
1045
1075
  var import_log2 = require("@dxos/log");
1046
1076
  var import_protocols2 = require("@dxos/protocols");
1047
1077
  var import_util = require("@dxos/util");
1048
- var __dxlog_file2 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
1078
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
1049
1079
  var SwarmMessage = import_protocols2.schema.getCodecForType("dxos.mesh.swarm.SwarmMessage");
1050
1080
  var SwarmMessenger = class {
1051
1081
  constructor({ sendMessage, onSignal, onOffer, topic }) {
@@ -1273,10 +1303,10 @@ var SwarmMessenger = class {
1273
1303
  // packages/core/mesh/network-manager/src/swarm/peer.ts
1274
1304
  var import_async2 = require("@dxos/async");
1275
1305
  var import_context3 = require("@dxos/context");
1276
- var import_errors2 = require("@dxos/errors");
1277
1306
  var import_invariant3 = require("@dxos/invariant");
1278
1307
  var import_keys3 = require("@dxos/keys");
1279
1308
  var import_log3 = require("@dxos/log");
1309
+ var import_protocols3 = require("@dxos/protocols");
1280
1310
  function _ts_decorate2(decorators, target, key, desc) {
1281
1311
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1282
1312
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -1287,8 +1317,8 @@ function _ts_decorate2(decorators, target, key, desc) {
1287
1317
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1288
1318
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1289
1319
  }
1290
- var __dxlog_file3 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/peer.ts";
1291
- var ConnectionDisplacedError = class extends import_errors2.SystemError {
1320
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts";
1321
+ var ConnectionDisplacedError = class extends import_protocols3.SystemError {
1292
1322
  constructor() {
1293
1323
  super("Connection displaced by remote initiator.");
1294
1324
  }
@@ -1356,7 +1386,7 @@ var Peer = class {
1356
1386
  connection.initiate();
1357
1387
  await connection.openConnection();
1358
1388
  } catch (err) {
1359
- if (!(err instanceof import_errors2.CancelledError)) {
1389
+ if (!(err instanceof import_protocols3.CancelledError)) {
1360
1390
  import_log3.log.warn("connection error", {
1361
1391
  topic: this.topic,
1362
1392
  peerId: this.localPeerId,
@@ -1466,6 +1496,9 @@ var Peer = class {
1466
1496
  S: this,
1467
1497
  C: (f, a) => f(...a)
1468
1498
  });
1499
+ if (err instanceof import_protocols3.TimeoutError) {
1500
+ await connection.abort(err);
1501
+ }
1469
1502
  await this.closeConnection(err);
1470
1503
  throw err;
1471
1504
  } finally {
@@ -1485,13 +1518,13 @@ var Peer = class {
1485
1518
  sessionId
1486
1519
  }, {
1487
1520
  F: __dxlog_file3,
1488
- L: 210,
1521
+ L: 213,
1489
1522
  S: this,
1490
1523
  C: (f, a) => f(...a)
1491
1524
  });
1492
1525
  (0, import_invariant3.invariant)(!this.connection, "Already connected.", {
1493
1526
  F: __dxlog_file3,
1494
- L: 217,
1527
+ L: 220,
1495
1528
  S: this,
1496
1529
  A: [
1497
1530
  "!this.connection",
@@ -1527,7 +1560,7 @@ var Peer = class {
1527
1560
  initiator
1528
1561
  }, {
1529
1562
  F: __dxlog_file3,
1530
- L: 236,
1563
+ L: 239,
1531
1564
  S: this,
1532
1565
  C: (f, a) => f(...a)
1533
1566
  });
@@ -1540,14 +1573,14 @@ var Peer = class {
1540
1573
  initiator
1541
1574
  }, {
1542
1575
  F: __dxlog_file3,
1543
- L: 245,
1576
+ L: 248,
1544
1577
  S: this,
1545
1578
  C: (f, a) => f(...a)
1546
1579
  });
1547
1580
  this._connectionLimiter.doneConnecting(sessionId);
1548
1581
  (0, import_invariant3.invariant)(this.connection === connection, "Connection mismatch (race condition).", {
1549
1582
  F: __dxlog_file3,
1550
- L: 250,
1583
+ L: 253,
1551
1584
  S: this,
1552
1585
  A: [
1553
1586
  "this.connection === connection",
@@ -1562,7 +1595,7 @@ var Peer = class {
1562
1595
  initiator
1563
1596
  }, {
1564
1597
  F: __dxlog_file3,
1565
- L: 252,
1598
+ L: 255,
1566
1599
  S: this,
1567
1600
  C: (f, a) => f(...a)
1568
1601
  });
@@ -1597,7 +1630,7 @@ var Peer = class {
1597
1630
  err
1598
1631
  }, {
1599
1632
  F: __dxlog_file3,
1600
- L: 292,
1633
+ L: 295,
1601
1634
  S: this,
1602
1635
  C: (f, a) => f(...a)
1603
1636
  });
@@ -1610,7 +1643,7 @@ var Peer = class {
1610
1643
  err
1611
1644
  }, {
1612
1645
  F: __dxlog_file3,
1613
- L: 293,
1646
+ L: 296,
1614
1647
  S: this,
1615
1648
  C: (f, a) => f(...a)
1616
1649
  });
@@ -1629,7 +1662,7 @@ var Peer = class {
1629
1662
  sessionId: connection.sessionId
1630
1663
  }, {
1631
1664
  F: __dxlog_file3,
1632
- L: 318,
1665
+ L: 321,
1633
1666
  S: this,
1634
1667
  C: (f, a) => f(...a)
1635
1668
  });
@@ -1639,7 +1672,7 @@ var Peer = class {
1639
1672
  sessionId: connection.sessionId
1640
1673
  }, {
1641
1674
  F: __dxlog_file3,
1642
- L: 324,
1675
+ L: 327,
1643
1676
  S: this,
1644
1677
  C: (f, a) => f(...a)
1645
1678
  });
@@ -1650,7 +1683,7 @@ var Peer = class {
1650
1683
  message
1651
1684
  }, {
1652
1685
  F: __dxlog_file3,
1653
- L: 329,
1686
+ L: 332,
1654
1687
  S: this,
1655
1688
  C: (f, a) => f(...a)
1656
1689
  });
@@ -1665,7 +1698,7 @@ var Peer = class {
1665
1698
  topic: this.topic
1666
1699
  }, {
1667
1700
  F: __dxlog_file3,
1668
- L: 339,
1701
+ L: 342,
1669
1702
  S: this,
1670
1703
  C: (f, a) => f(...a)
1671
1704
  });
@@ -1699,7 +1732,7 @@ function _ts_decorate3(decorators, target, key, desc) {
1699
1732
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1700
1733
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1701
1734
  }
1702
- var __dxlog_file4 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/swarm.ts";
1735
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts";
1703
1736
  var INITIATION_DELAY = 100;
1704
1737
  var getClassName = (obj) => Object.getPrototypeOf(obj).constructor.name;
1705
1738
  var Swarm = class {
@@ -1723,7 +1756,7 @@ var Swarm = class {
1723
1756
  this.disconnected = new import_async3.Event();
1724
1757
  this.connected = new import_async3.Event();
1725
1758
  this.errors = new import_debug2.ErrorStream();
1726
- import_log4.log.trace("dxos.mesh.swarm.constructor", import_protocols3.trace.begin({
1759
+ import_log4.log.trace("dxos.mesh.swarm.constructor", import_protocols4.trace.begin({
1727
1760
  id: this._instanceId,
1728
1761
  data: {
1729
1762
  topic: this._topic.toHex(),
@@ -1750,7 +1783,7 @@ var Swarm = class {
1750
1783
  onOffer: async (msg) => await this.onOffer(msg),
1751
1784
  topic: this._topic
1752
1785
  });
1753
- import_log4.log.trace("dxos.mesh.swarm.constructor", import_protocols3.trace.end({
1786
+ import_log4.log.trace("dxos.mesh.swarm.constructor", import_protocols4.trace.end({
1754
1787
  id: this._instanceId
1755
1788
  }), {
1756
1789
  F: __dxlog_file4,
@@ -2173,7 +2206,7 @@ var import_async4 = require("@dxos/async");
2173
2206
  var import_keys5 = require("@dxos/keys");
2174
2207
  var import_log5 = require("@dxos/log");
2175
2208
  var import_util3 = require("@dxos/util");
2176
- var __dxlog_file5 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
2209
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
2177
2210
  var SwarmMapper = class {
2178
2211
  get peers() {
2179
2212
  return Array.from(this._peers.values());
@@ -2241,13 +2274,13 @@ var SwarmMapper = class {
2241
2274
  // packages/core/mesh/network-manager/src/swarm/connection-limiter.ts
2242
2275
  var import_async5 = require("@dxos/async");
2243
2276
  var import_context5 = require("@dxos/context");
2244
- var import_errors3 = require("@dxos/errors");
2245
2277
  var import_invariant5 = require("@dxos/invariant");
2246
2278
  var import_keys6 = require("@dxos/keys");
2247
2279
  var import_log6 = require("@dxos/log");
2280
+ var import_protocols5 = require("@dxos/protocols");
2248
2281
  var import_util4 = require("@dxos/util");
2249
- var __dxlog_file6 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
2250
- var MAX_CONCURRENT_INITIATING_CONNECTIONS = 10;
2282
+ var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
2283
+ var MAX_CONCURRENT_INITIATING_CONNECTIONS = 50;
2251
2284
  var ConnectionLimiter = class {
2252
2285
  constructor({ maxConcurrentInitConnections = MAX_CONCURRENT_INITIATING_CONNECTIONS } = {}) {
2253
2286
  this._ctx = new import_context5.Context();
@@ -2314,7 +2347,7 @@ var ConnectionLimiter = class {
2314
2347
  if (!this._waitingPromises.has(sessionId)) {
2315
2348
  return;
2316
2349
  }
2317
- this._waitingPromises.get(sessionId).reject(new import_errors3.CancelledError());
2350
+ this._waitingPromises.get(sessionId).reject(new import_protocols5.CancelledError());
2318
2351
  this._waitingPromises.delete(sessionId);
2319
2352
  this.resolveWaitingPromises.schedule();
2320
2353
  }
@@ -2387,7 +2420,7 @@ var ConnectionLog = class {
2387
2420
  };
2388
2421
 
2389
2422
  // 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";
2423
+ var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts";
2391
2424
  var NetworkManager = class {
2392
2425
  constructor({ transportFactory, signalManager, log: log1 }) {
2393
2426
  /**
@@ -2432,7 +2465,7 @@ var NetworkManager = class {
2432
2465
  return this._swarms.get(topic);
2433
2466
  }
2434
2467
  async open() {
2435
- import_log7.log.trace("dxos.mesh.network-manager.open", import_protocols4.trace.begin({
2468
+ import_log7.log.trace("dxos.mesh.network-manager.open", import_protocols6.trace.begin({
2436
2469
  id: this._instanceId
2437
2470
  }), {
2438
2471
  F: __dxlog_file7,
@@ -2442,7 +2475,7 @@ var NetworkManager = class {
2442
2475
  });
2443
2476
  await this._messenger.open();
2444
2477
  await this._signalManager.open();
2445
- import_log7.log.trace("dxos.mesh.network-manager.open", import_protocols4.trace.end({
2478
+ import_log7.log.trace("dxos.mesh.network-manager.open", import_protocols6.trace.end({
2446
2479
  id: this._instanceId
2447
2480
  }), {
2448
2481
  F: __dxlog_file7,
@@ -2623,7 +2656,7 @@ var NetworkManager = class {
2623
2656
 
2624
2657
  // packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts
2625
2658
  var import_invariant7 = require("@dxos/invariant");
2626
- var __dxlog_file8 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
2659
+ var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
2627
2660
  var FullyConnectedTopology = class {
2628
2661
  toString() {
2629
2662
  return "FullyConnectedTopology";
@@ -2689,7 +2722,7 @@ function _ts_decorate4(decorators, target, key, desc) {
2689
2722
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2690
2723
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2691
2724
  }
2692
- var __dxlog_file9 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
2725
+ var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
2693
2726
  var MEMORY_TRANSPORT_DELAY = 1;
2694
2727
  var createStreamDelay = (delay) => {
2695
2728
  return new import_node_stream.Transform({
@@ -2864,6 +2897,7 @@ var TransportKind;
2864
2897
  TransportKind2["LIBDATACHANNEL"] = "LIBDATACHANNEL";
2865
2898
  TransportKind2["SIMPLE_PEER_PROXY"] = "SIMPLE_PEER_PROXY";
2866
2899
  TransportKind2["MEMORY"] = "MEMORY";
2900
+ TransportKind2["TCP"] = "TCP";
2867
2901
  })(TransportKind || (TransportKind = {}));
2868
2902
 
2869
2903
  // packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts
@@ -2873,7 +2907,7 @@ var import_async9 = require("@dxos/async");
2873
2907
  var import_debug5 = require("@dxos/debug");
2874
2908
  var import_keys10 = require("@dxos/keys");
2875
2909
  var import_log11 = require("@dxos/log");
2876
- var import_protocols5 = require("@dxos/protocols");
2910
+ var import_protocols7 = require("@dxos/protocols");
2877
2911
 
2878
2912
  // packages/core/mesh/network-manager/src/transport/webrtc.ts
2879
2913
  var wrtc = null;
@@ -2883,7 +2917,7 @@ try {
2883
2917
  }
2884
2918
 
2885
2919
  // 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";
2920
+ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts";
2887
2921
  var SimplePeerTransport = class {
2888
2922
  constructor(params) {
2889
2923
  this.params = params;
@@ -2892,17 +2926,17 @@ var SimplePeerTransport = class {
2892
2926
  this.connected = new import_async9.Event();
2893
2927
  this.errors = new import_debug5.ErrorStream();
2894
2928
  this._instanceId = import_keys10.PublicKey.random().toHex();
2895
- import_log11.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols5.trace.begin({
2929
+ import_log11.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols7.trace.begin({
2896
2930
  id: this._instanceId
2897
2931
  }), {
2898
2932
  F: __dxlog_file10,
2899
- L: 39,
2933
+ L: 40,
2900
2934
  S: this,
2901
2935
  C: (f, a) => f(...a)
2902
2936
  });
2903
2937
  (0, import_log11.log)("created connection", params, {
2904
2938
  F: __dxlog_file10,
2905
- L: 40,
2939
+ L: 41,
2906
2940
  S: this,
2907
2941
  C: (f, a) => f(...a)
2908
2942
  });
@@ -2915,7 +2949,7 @@ var SimplePeerTransport = class {
2915
2949
  this._peer.on("signal", async (data) => {
2916
2950
  (0, import_log11.log)("signal", data, {
2917
2951
  F: __dxlog_file10,
2918
- L: 49,
2952
+ L: 50,
2919
2953
  S: this,
2920
2954
  C: (f, a) => f(...a)
2921
2955
  });
@@ -2928,7 +2962,7 @@ var SimplePeerTransport = class {
2928
2962
  this._peer.on("connect", () => {
2929
2963
  (0, import_log11.log)("connected", void 0, {
2930
2964
  F: __dxlog_file10,
2931
- L: 54,
2965
+ L: 55,
2932
2966
  S: this,
2933
2967
  C: (f, a) => f(...a)
2934
2968
  });
@@ -2938,7 +2972,7 @@ var SimplePeerTransport = class {
2938
2972
  this._peer.on("close", async () => {
2939
2973
  (0, import_log11.log)("closed", void 0, {
2940
2974
  F: __dxlog_file10,
2941
- L: 60,
2975
+ L: 61,
2942
2976
  S: this,
2943
2977
  C: (f, a) => f(...a)
2944
2978
  });
@@ -2946,7 +2980,35 @@ var SimplePeerTransport = class {
2946
2980
  this.closed.emit();
2947
2981
  });
2948
2982
  this._peer.on("error", async (err) => {
2949
- this.errors.raise(err);
2983
+ if (typeof RTCError !== "undefined" && err instanceof RTCError) {
2984
+ if (err.errorDetail === "sctp-failure") {
2985
+ this.errors.raise(new import_protocols7.ConnectionResetError("sctp-failure from RTCError", err));
2986
+ } else {
2987
+ this.errors.raise(new import_protocols7.UnknownProtocolError("unknown RTCError", err));
2988
+ }
2989
+ } else if (err.name === "InvalidStateError") {
2990
+ this.errors.raise(new import_protocols7.ConnectionResetError("safari WebRTC error", err));
2991
+ } else if ("code" in err) {
2992
+ switch (err.code) {
2993
+ case "ERR_WEBRTC_SUPPORT":
2994
+ this.errors.raise(new import_protocols7.ProtocolError("WebRTC not supported", err));
2995
+ case "ERR_ICE_CONNECTION_FAILURE":
2996
+ case "ERR_DATA_CHANNEL":
2997
+ case "ERR_CONNECTION_FAILURE":
2998
+ case "ERR_SIGNALING":
2999
+ this.errors.raise(new import_protocols7.ConnectivityError("unknown communication failure", err));
3000
+ case "ERR_CREATE_OFFER":
3001
+ case "ERR_CREATE_ANSWER":
3002
+ case "ERR_SET_LOCAL_DESCRIPTION":
3003
+ case "ERR_SET_REMOTE_DESCRIPTION":
3004
+ case "ERR_ADD_ICE_CANDIDATE":
3005
+ this.errors.raise(new import_protocols7.UnknownProtocolError("unknown simple-peer library failure", err));
3006
+ default:
3007
+ this.errors.raise(new Error("unknown simple-peer error"));
3008
+ }
3009
+ } else {
3010
+ this.errors.raise(err);
3011
+ }
2950
3012
  try {
2951
3013
  if (typeof this._peer?._pc.getStats === "function") {
2952
3014
  this._peer._pc.getStats().then((stats) => {
@@ -2955,21 +3017,27 @@ var SimplePeerTransport = class {
2955
3017
  stats
2956
3018
  }, {
2957
3019
  F: __dxlog_file10,
2958
- L: 72,
3020
+ L: 106,
2959
3021
  S: this,
2960
3022
  C: (f, a) => f(...a)
2961
3023
  });
2962
3024
  });
2963
3025
  }
2964
- } catch {
3026
+ } catch (err2) {
3027
+ import_log11.log.catch(err2, void 0, {
3028
+ F: __dxlog_file10,
3029
+ L: 113,
3030
+ S: this,
3031
+ C: (f, a) => f(...a)
3032
+ });
2965
3033
  }
2966
3034
  await this.destroy();
2967
3035
  });
2968
- import_log11.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols5.trace.end({
3036
+ import_log11.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols7.trace.end({
2969
3037
  id: this._instanceId
2970
3038
  }), {
2971
3039
  F: __dxlog_file10,
2972
- L: 82,
3040
+ L: 118,
2973
3041
  S: this,
2974
3042
  C: (f, a) => f(...a)
2975
3043
  });
@@ -2977,7 +3045,7 @@ var SimplePeerTransport = class {
2977
3045
  async destroy() {
2978
3046
  (0, import_log11.log)("closing...", void 0, {
2979
3047
  F: __dxlog_file10,
2980
- L: 86,
3048
+ L: 122,
2981
3049
  S: this,
2982
3050
  C: (f, a) => f(...a)
2983
3051
  });
@@ -2987,7 +3055,7 @@ var SimplePeerTransport = class {
2987
3055
  this.closed.emit();
2988
3056
  (0, import_log11.log)("closed", void 0, {
2989
3057
  F: __dxlog_file10,
2990
- L: 91,
3058
+ L: 127,
2991
3059
  S: this,
2992
3060
  C: (f, a) => f(...a)
2993
3061
  });
@@ -3018,7 +3086,7 @@ var import_keys11 = require("@dxos/keys");
3018
3086
  var import_log12 = require("@dxos/log");
3019
3087
  var import_bridge = require("@dxos/protocols/proto/dxos/mesh/bridge");
3020
3088
  var import_util8 = require("@dxos/util");
3021
- var __dxlog_file11 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/simplepeer-transport-service.ts";
3089
+ var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport-service.ts";
3022
3090
  var SimplePeerTransportService = class {
3023
3091
  // prettier-ignore
3024
3092
  constructor(_webrtcConfig) {
@@ -3148,9 +3216,10 @@ var import_debug6 = require("@dxos/debug");
3148
3216
  var import_invariant12 = require("@dxos/invariant");
3149
3217
  var import_keys12 = require("@dxos/keys");
3150
3218
  var import_log13 = require("@dxos/log");
3219
+ var import_protocols8 = require("@dxos/protocols");
3151
3220
  var import_bridge2 = require("@dxos/protocols/proto/dxos/mesh/bridge");
3152
3221
  var import_util9 = require("@dxos/util");
3153
- var __dxlog_file12 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/simplepeer-transport-proxy.ts";
3222
+ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport-proxy.ts";
3154
3223
  var SimplePeerTransportProxy = class {
3155
3224
  // prettier-ignore
3156
3225
  constructor(_params) {
@@ -3169,7 +3238,7 @@ var SimplePeerTransportProxy = class {
3169
3238
  this._serviceStream.subscribe(async (event) => {
3170
3239
  (0, import_log13.log)("SimplePeerTransportProxy: event", event, {
3171
3240
  F: __dxlog_file12,
3172
- L: 51,
3241
+ L: 58,
3173
3242
  S: this,
3174
3243
  C: (f, a) => f(...a)
3175
3244
  });
@@ -3189,7 +3258,7 @@ var SimplePeerTransportProxy = class {
3189
3258
  }).then(() => callback(), (err) => {
3190
3259
  import_log13.log.catch(err, void 0, {
3191
3260
  F: __dxlog_file12,
3192
- L: 69,
3261
+ L: 76,
3193
3262
  S: this,
3194
3263
  C: (f, a) => f(...a)
3195
3264
  });
@@ -3198,14 +3267,14 @@ var SimplePeerTransportProxy = class {
3198
3267
  }));
3199
3268
  }, (error) => import_log13.log.catch(error, void 0, {
3200
3269
  F: __dxlog_file12,
3201
- L: 75,
3270
+ L: 82,
3202
3271
  S: this,
3203
3272
  C: (f, a) => f(...a)
3204
3273
  }));
3205
3274
  }
3206
3275
  async _handleConnection(connectionEvent) {
3207
3276
  if (connectionEvent.error) {
3208
- this.errors.raise(new Error(connectionEvent.error));
3277
+ this.errors.raise(decodeError(connectionEvent.error));
3209
3278
  }
3210
3279
  switch (connectionEvent.state) {
3211
3280
  case import_bridge2.ConnectionState.CONNECTED: {
@@ -3228,7 +3297,7 @@ var SimplePeerTransportProxy = class {
3228
3297
  this._params.bridgeService.sendSignal({
3229
3298
  proxyId: this._proxyId,
3230
3299
  signal
3231
- }).catch((err) => this.errors.raise(err));
3300
+ }).catch((err) => this.errors.raise(decodeError(err)));
3232
3301
  }
3233
3302
  // TODO(burdon): Move open from constructor.
3234
3303
  async destroy() {
@@ -3244,7 +3313,7 @@ var SimplePeerTransportProxy = class {
3244
3313
  } catch (err) {
3245
3314
  import_log13.log.catch(err, void 0, {
3246
3315
  F: __dxlog_file12,
3247
- L: 126,
3316
+ L: 133,
3248
3317
  S: this,
3249
3318
  C: (f, a) => f(...a)
3250
3319
  });
@@ -3280,7 +3349,7 @@ var SimplePeerTransportProxyFactory = class {
3280
3349
  createTransport(options) {
3281
3350
  (0, import_invariant12.invariant)(this._bridgeService, "SimplePeerTransportProxyFactory is not ready to open connections", {
3282
3351
  F: __dxlog_file12,
3283
- L: 163,
3352
+ L: 170,
3284
3353
  S: this,
3285
3354
  A: [
3286
3355
  "this._bridgeService",
@@ -3296,6 +3365,22 @@ var SimplePeerTransportProxyFactory = class {
3296
3365
  return transport;
3297
3366
  }
3298
3367
  };
3368
+ var decodeError = (err) => {
3369
+ const message = typeof err === "string" ? err : err.message;
3370
+ if (message.includes("ConnectionResetError")) {
3371
+ return new import_protocols8.ConnectionResetError(message);
3372
+ } else if (message.includes("TimeoutError")) {
3373
+ return new import_protocols8.TimeoutError(message);
3374
+ } else if (message.includes("ProtocolError")) {
3375
+ return new import_protocols8.ProtocolError(message);
3376
+ } else if (message.includes("ConnectivityError")) {
3377
+ return new import_protocols8.ConnectivityError(message);
3378
+ } else if (message.includes("UnknownProtocolError")) {
3379
+ return new import_protocols8.UnknownProtocolError(message);
3380
+ } else {
3381
+ return typeof err === "string" ? new Error(err) : err;
3382
+ }
3383
+ };
3299
3384
 
3300
3385
  // packages/core/mesh/network-manager/src/transport/index.ts
3301
3386
  init_datachannel();
@@ -3315,7 +3400,7 @@ function _ts_decorate5(decorators, target, key, desc) {
3315
3400
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3316
3401
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3317
3402
  }
3318
- var __dxlog_file13 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/libdatachannel-transport.ts";
3403
+ var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/libdatachannel-transport.ts";
3319
3404
  var DATACHANNEL_LABEL = "dxos.mesh.transport";
3320
3405
  var MAX_BUFFERED_AMOUNT = 64 * 1024;
3321
3406
  var MAX_MESSAGE_SIZE = 64 * 1024;
@@ -3639,10 +3724,140 @@ var createLibDataChannelTransportFactory = (webrtcConfig) => ({
3639
3724
  })
3640
3725
  });
3641
3726
 
3642
- // packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts
3727
+ // packages/core/mesh/network-manager/src/transport/tcp-transport.ts
3728
+ var import_node_net = require("node:net");
3643
3729
  var import_async12 = require("@dxos/async");
3644
- var import_keys13 = require("@dxos/keys");
3730
+ var import_debug8 = require("@dxos/debug");
3645
3731
  var import_log15 = require("@dxos/log");
3732
+ var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/tcp-transport.ts";
3733
+ var TcpTransportFactory = {
3734
+ createTransport: (params) => new TcpTransport(params)
3735
+ };
3736
+ var TcpTransport = class {
3737
+ constructor(options) {
3738
+ this.options = options;
3739
+ this._server = void 0;
3740
+ this._socket = void 0;
3741
+ this.closed = new import_async12.Event();
3742
+ this.connected = new import_async12.Event();
3743
+ this.errors = new import_debug8.ErrorStream();
3744
+ this._destroyed = false;
3745
+ this._connected = false;
3746
+ (0, import_log15.log)("creating", void 0, {
3747
+ F: __dxlog_file14,
3748
+ L: 34,
3749
+ S: this,
3750
+ C: (f, a) => f(...a)
3751
+ });
3752
+ if (this.options.initiator) {
3753
+ setTimeout(async () => {
3754
+ const { Server } = await import("node:net");
3755
+ this._server = new Server((socket) => {
3756
+ (0, import_log15.log)("new connection", void 0, {
3757
+ F: __dxlog_file14,
3758
+ L: 42,
3759
+ S: this,
3760
+ C: (f, a) => f(...a)
3761
+ });
3762
+ if (this._connected) {
3763
+ socket.destroy();
3764
+ }
3765
+ this._handleSocket(socket);
3766
+ });
3767
+ this._server.on("listening", () => {
3768
+ const { port: port2 } = this._server.address();
3769
+ (0, import_log15.log)("listening", {
3770
+ port: port2
3771
+ }, {
3772
+ F: __dxlog_file14,
3773
+ L: 51,
3774
+ S: this,
3775
+ C: (f, a) => f(...a)
3776
+ });
3777
+ void this.options.sendSignal({
3778
+ payload: {
3779
+ port: port2
3780
+ }
3781
+ }).catch((err) => {
3782
+ if (!this._destroyed) {
3783
+ this.errors.raise(err);
3784
+ }
3785
+ });
3786
+ });
3787
+ this._server.on("error", (err) => {
3788
+ this.errors.raise(err);
3789
+ });
3790
+ this._server.listen(0);
3791
+ });
3792
+ }
3793
+ }
3794
+ async destroy() {
3795
+ (0, import_log15.log)("closing", void 0, {
3796
+ F: __dxlog_file14,
3797
+ L: 72,
3798
+ S: this,
3799
+ C: (f, a) => f(...a)
3800
+ });
3801
+ this._socket?.destroy();
3802
+ this._server?.close();
3803
+ this._destroyed = true;
3804
+ }
3805
+ signal({ payload }) {
3806
+ (0, import_log15.log)("received signal", {
3807
+ payload
3808
+ }, {
3809
+ F: __dxlog_file14,
3810
+ L: 80,
3811
+ S: this,
3812
+ C: (f, a) => f(...a)
3813
+ });
3814
+ if (this.options.initiator || this._connected) {
3815
+ return;
3816
+ }
3817
+ const socket = new import_node_net.Socket();
3818
+ this._handleSocket(socket);
3819
+ socket.connect({
3820
+ port: payload.port,
3821
+ host: "localhost"
3822
+ });
3823
+ }
3824
+ _handleSocket(socket) {
3825
+ (0, import_log15.log)("handling socket", {
3826
+ remotePort: socket.remotePort,
3827
+ localPort: socket.localPort
3828
+ }, {
3829
+ F: __dxlog_file14,
3830
+ L: 91,
3831
+ S: this,
3832
+ C: (f, a) => f(...a)
3833
+ });
3834
+ this._socket = socket;
3835
+ this.connected.emit();
3836
+ this.options.stream.pipe(this._socket).pipe(this.options.stream);
3837
+ this._socket.on("connect", () => {
3838
+ (0, import_log15.log)("connected to", {
3839
+ port: this._socket?.remotePort
3840
+ }, {
3841
+ F: __dxlog_file14,
3842
+ L: 97,
3843
+ S: this,
3844
+ C: (f, a) => f(...a)
3845
+ });
3846
+ this._connected = true;
3847
+ });
3848
+ this._socket.on("error", (err) => {
3849
+ this.errors.raise(err);
3850
+ });
3851
+ this._socket.on("close", () => {
3852
+ this.closed.emit();
3853
+ });
3854
+ }
3855
+ };
3856
+
3857
+ // packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts
3858
+ var import_async13 = require("@dxos/async");
3859
+ var import_keys13 = require("@dxos/keys");
3860
+ var import_log16 = require("@dxos/log");
3646
3861
  var import_teleport2 = require("@dxos/teleport");
3647
3862
  var import_util10 = require("@dxos/util");
3648
3863
 
@@ -3668,21 +3883,21 @@ var createTeleportProtocolFactory = (onConnection) => {
3668
3883
  };
3669
3884
 
3670
3885
  // 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";
3886
+ var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts";
3672
3887
  var TestWireProtocol = class {
3673
3888
  constructor(peerId, _extensionFactory = () => []) {
3674
3889
  this.peerId = peerId;
3675
3890
  this._extensionFactory = _extensionFactory;
3676
3891
  this.connections = new import_util10.ComplexMap(import_keys13.PublicKey.hash);
3677
3892
  this.streamConnections = new import_util10.ComplexMap(import_keys13.PublicKey.hash);
3678
- this.connected = new import_async12.Event();
3679
- this.disconnected = new import_async12.Event();
3893
+ this.connected = new import_async13.Event();
3894
+ this.disconnected = new import_async13.Event();
3680
3895
  this.otherConnections = new import_util10.ComplexMap(({ remotePeerId, extension }) => remotePeerId.toHex() + extension);
3681
3896
  this.factory = createTeleportProtocolFactory(async (teleport) => {
3682
- (0, import_log15.log)("create", {
3897
+ (0, import_log16.log)("create", {
3683
3898
  remotePeerId: teleport.remotePeerId
3684
3899
  }, {
3685
- F: __dxlog_file14,
3900
+ F: __dxlog_file15,
3686
3901
  L: 38,
3687
3902
  S: this,
3688
3903
  C: (f, a) => f(...a)
@@ -3716,15 +3931,15 @@ var TestWireProtocol = class {
3716
3931
  if (this.connections.has(peerId)) {
3717
3932
  return this.connections.get(peerId);
3718
3933
  }
3719
- (0, import_log15.log)("waitForConnection", {
3934
+ (0, import_log16.log)("waitForConnection", {
3720
3935
  peerId
3721
3936
  }, {
3722
- F: __dxlog_file14,
3937
+ F: __dxlog_file15,
3723
3938
  L: 67,
3724
3939
  S: this,
3725
3940
  C: (f, a) => f(...a)
3726
3941
  });
3727
- await (0, import_async12.asyncTimeout)(
3942
+ await (0, import_async13.asyncTimeout)(
3728
3943
  this.connected.waitFor((connectedId) => connectedId.equals(peerId)),
3729
3944
  // TODO(nf): Make this configurable.
3730
3945
  1e4
@@ -3752,7 +3967,7 @@ var TestWireProtocol = class {
3752
3967
  };
3753
3968
 
3754
3969
  // 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";
3970
+ var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-builder.ts";
3756
3971
  var port = process.env.SIGNAL_PORT ?? 4e3;
3757
3972
  var TEST_SIGNAL_HOSTS = [
3758
3973
  {
@@ -3794,15 +4009,18 @@ var TestPeer = class {
3794
4009
  createNetworkManager(transport) {
3795
4010
  let transportFactory;
3796
4011
  if (this.testBuilder.options.signalHosts) {
3797
- import_log16.log.info(`using ${transport} transport with signal server.`, void 0, {
3798
- F: __dxlog_file15,
3799
- L: 104,
4012
+ import_log17.log.info(`using ${transport} transport with signal server.`, void 0, {
4013
+ F: __dxlog_file16,
4014
+ L: 105,
3800
4015
  S: this,
3801
4016
  C: (f, a) => f(...a)
3802
4017
  });
3803
4018
  switch (transport) {
3804
4019
  case TransportKind.MEMORY:
3805
4020
  throw new Error("Memory transport not supported with signal server.");
4021
+ case TransportKind.TCP:
4022
+ transportFactory = TcpTransportFactory;
4023
+ break;
3806
4024
  case TransportKind.SIMPLE_PEER:
3807
4025
  transportFactory = createSimplePeerTransportFactory();
3808
4026
  break;
@@ -3815,7 +4033,7 @@ var TestPeer = class {
3815
4033
  this._proxy = (0, import_rpc.createProtoRpcPeer)({
3816
4034
  port: proxyPort,
3817
4035
  requested: {
3818
- BridgeService: import_protocols6.schema.getService("dxos.mesh.bridge.BridgeService")
4036
+ BridgeService: import_protocols9.schema.getService("dxos.mesh.bridge.BridgeService")
3819
4037
  },
3820
4038
  noHandshake: true,
3821
4039
  encodingOptions: {
@@ -3825,7 +4043,7 @@ var TestPeer = class {
3825
4043
  this._service = (0, import_rpc.createProtoRpcPeer)({
3826
4044
  port: servicePort,
3827
4045
  exposed: {
3828
- BridgeService: import_protocols6.schema.getService("dxos.mesh.bridge.BridgeService")
4046
+ BridgeService: import_protocols9.schema.getService("dxos.mesh.bridge.BridgeService")
3829
4047
  },
3830
4048
  handlers: {
3831
4049
  BridgeService: new SimplePeerTransportService()
@@ -3842,17 +4060,17 @@ var TestPeer = class {
3842
4060
  throw new Error(`Unsupported transport: ${transport}`);
3843
4061
  }
3844
4062
  } else {
3845
- if (transport !== TransportKind.MEMORY) {
3846
- import_log16.log.warn(`specified transport ${transport} but no signalling configured, using memory transport instead`, void 0, {
3847
- F: __dxlog_file15,
3848
- L: 150,
4063
+ if (transport !== TransportKind.MEMORY && transport !== TransportKind.TCP) {
4064
+ import_log17.log.warn(`specified transport ${transport} but no signalling configured, using memory transport instead`, void 0, {
4065
+ F: __dxlog_file16,
4066
+ L: 154,
3849
4067
  S: this,
3850
4068
  C: (f, a) => f(...a)
3851
4069
  });
3852
4070
  }
3853
- import_log16.log.info(`using ${transport} transport without signal server.`, void 0, {
3854
- F: __dxlog_file15,
3855
- L: 152,
4071
+ import_log17.log.info(`using ${transport} transport without signal server.`, void 0, {
4072
+ F: __dxlog_file16,
4073
+ L: 156,
3856
4074
  S: this,
3857
4075
  C: (f, a) => f(...a)
3858
4076
  });