@dxos/network-manager 0.1.58-next.3349da8 → 0.1.58-next.ffb4cc4

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 (50) hide show
  1. package/dist/lib/browser/{chunk-PSWNMALH.mjs → chunk-3KLH55NB.mjs} +155 -94
  2. package/dist/lib/browser/chunk-3KLH55NB.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +5 -1
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/testing/index.mjs +19 -148
  6. package/dist/lib/browser/testing/index.mjs.map +4 -4
  7. package/dist/lib/node/index.cjs +631 -458
  8. package/dist/lib/node/index.cjs.map +4 -4
  9. package/dist/lib/node/meta.json +1 -1
  10. package/dist/lib/node/testing/index.cjs +957 -917
  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.map +1 -1
  15. package/dist/types/src/swarm/peer.d.ts +3 -3
  16. package/dist/types/src/swarm/peer.d.ts.map +1 -1
  17. package/dist/types/src/swarm/swarm-mapper.d.ts.map +1 -1
  18. package/dist/types/src/swarm/swarm.d.ts +2 -2
  19. package/dist/types/src/swarm/swarm.d.ts.map +1 -1
  20. package/dist/types/src/testing/test-builder.d.ts +1 -1
  21. package/dist/types/src/testing/test-builder.d.ts.map +1 -1
  22. package/dist/types/src/tests/basic-test-suite.d.ts.map +1 -1
  23. package/dist/types/src/topology/star-topology.d.ts.map +1 -1
  24. package/dist/types/src/transport/index.d.ts +1 -0
  25. package/dist/types/src/transport/index.d.ts.map +1 -1
  26. package/dist/types/src/transport/simplepeer-transport-proxy.d.ts.map +1 -1
  27. package/dist/types/src/transport/simplepeer-transport-service.d.ts.map +1 -1
  28. package/dist/types/src/transport/simplepeer-transport.d.ts.map +1 -1
  29. package/dist/types/src/transport/tcp-transport.browser.d.ts +12 -0
  30. package/dist/types/src/transport/tcp-transport.browser.d.ts.map +1 -0
  31. package/package.json +18 -18
  32. package/src/swarm/connection-limiter.ts +2 -2
  33. package/src/swarm/connection.test.ts +1 -1
  34. package/src/swarm/connection.ts +9 -8
  35. package/src/swarm/peer.ts +8 -3
  36. package/src/swarm/swarm-mapper.ts +4 -7
  37. package/src/swarm/swarm.test.ts +3 -3
  38. package/src/swarm/swarm.ts +3 -3
  39. package/src/testing/test-builder.ts +1 -1
  40. package/src/tests/basic-test-suite.ts +1 -1
  41. package/src/tests/memory-transport.test.ts +2 -2
  42. package/src/tests/tcp-transport.test.ts +2 -2
  43. package/src/tests/webrtc-transport.test.ts +1 -1
  44. package/src/topology/star-topology.ts +1 -4
  45. package/src/transport/index.ts +1 -0
  46. package/src/transport/simplepeer-transport-proxy.ts +29 -28
  47. package/src/transport/simplepeer-transport-service.ts +9 -5
  48. package/src/transport/simplepeer-transport.ts +9 -7
  49. package/src/transport/tcp-transport.browser.ts +28 -0
  50. package/dist/lib/browser/chunk-PSWNMALH.mjs.map +0 -7
@@ -515,35 +515,146 @@ module.exports = __toCommonJS(testing_exports);
515
515
  var import_keys14 = require("@dxos/keys");
516
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");
522
522
 
523
+ // packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts
524
+ var import_async = require("@dxos/async");
525
+ var import_keys = require("@dxos/keys");
526
+ var import_log = require("@dxos/log");
527
+ var import_teleport2 = require("@dxos/teleport");
528
+ var import_util = require("@dxos/util");
529
+
530
+ // packages/core/mesh/network-manager/src/wire-protocol.ts
531
+ var import_teleport = require("@dxos/teleport");
532
+ var createTeleportProtocolFactory = (onConnection) => {
533
+ return (params) => {
534
+ const teleport = new import_teleport.Teleport(params);
535
+ return {
536
+ stream: teleport.stream,
537
+ open: async () => {
538
+ await teleport.open();
539
+ await onConnection(teleport);
540
+ },
541
+ close: async () => {
542
+ await teleport.close();
543
+ },
544
+ abort: async () => {
545
+ await teleport.abort();
546
+ }
547
+ };
548
+ };
549
+ };
550
+
551
+ // packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts
552
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts";
553
+ var TestWireProtocol = class {
554
+ constructor(peerId, _extensionFactory = () => []) {
555
+ this.peerId = peerId;
556
+ this._extensionFactory = _extensionFactory;
557
+ this.connections = new import_util.ComplexMap(import_keys.PublicKey.hash);
558
+ this.streamConnections = new import_util.ComplexMap(import_keys.PublicKey.hash);
559
+ this.connected = new import_async.Event();
560
+ this.disconnected = new import_async.Event();
561
+ this.otherConnections = new import_util.ComplexMap(({ remotePeerId, extension }) => remotePeerId.toHex() + extension);
562
+ this.factory = createTeleportProtocolFactory(async (teleport) => {
563
+ (0, import_log.log)("create", {
564
+ remotePeerId: teleport.remotePeerId
565
+ }, {
566
+ F: __dxlog_file,
567
+ L: 38,
568
+ S: this,
569
+ C: (f, a) => f(...a)
570
+ });
571
+ const extension = new import_teleport2.TestExtension({
572
+ onClose: async () => {
573
+ this.connections.delete(teleport.remotePeerId);
574
+ this.disconnected.emit(teleport.remotePeerId);
575
+ }
576
+ });
577
+ this.connections.set(teleport.remotePeerId, extension);
578
+ teleport.addExtension("test", extension);
579
+ this.connected.emit(teleport.remotePeerId);
580
+ const streamExtension = new import_teleport2.TestExtensionWithStreams({
581
+ onClose: async () => {
582
+ this.streamConnections.delete(teleport.remotePeerId);
583
+ }
584
+ });
585
+ this.streamConnections.set(teleport.remotePeerId, streamExtension);
586
+ teleport.addExtension("test-stream", streamExtension);
587
+ for (const { name, extension: extension2 } of this._extensionFactory()) {
588
+ this.otherConnections.set({
589
+ remotePeerId: teleport.remotePeerId,
590
+ extension: name
591
+ }, extension2);
592
+ teleport.addExtension(name, extension2);
593
+ }
594
+ });
595
+ }
596
+ async waitForConnection(peerId) {
597
+ if (this.connections.has(peerId)) {
598
+ return this.connections.get(peerId);
599
+ }
600
+ (0, import_log.log)("waitForConnection", {
601
+ peerId
602
+ }, {
603
+ F: __dxlog_file,
604
+ L: 67,
605
+ S: this,
606
+ C: (f, a) => f(...a)
607
+ });
608
+ await (0, import_async.asyncTimeout)(
609
+ this.connected.waitFor((connectedId) => connectedId.equals(peerId)),
610
+ // TODO(nf): Make this configurable.
611
+ 1e4
612
+ );
613
+ return this.connections.get(peerId);
614
+ }
615
+ async testConnection(peerId, message) {
616
+ const connection = await this.waitForConnection(peerId);
617
+ await connection.test(message);
618
+ }
619
+ async openStream(peerId, streamTag, streamLoadInterval, streamLoadChunkSize) {
620
+ if (!this.streamConnections.has(peerId)) {
621
+ throw new Error("Connection does not exist.");
622
+ }
623
+ const connection = this.streamConnections.get(peerId);
624
+ return connection.addNewStream(streamLoadInterval, streamLoadChunkSize, streamTag);
625
+ }
626
+ async closeStream(peerId, streamTag) {
627
+ if (!this.streamConnections.has(peerId)) {
628
+ throw new Error("Connection does not exist.");
629
+ }
630
+ const connection = this.streamConnections.get(peerId);
631
+ return connection.closeStream(streamTag);
632
+ }
633
+ };
634
+
523
635
  // packages/core/mesh/network-manager/src/network-manager.ts
524
- var import_async7 = require("@dxos/async");
636
+ var import_async8 = require("@dxos/async");
525
637
  var import_invariant6 = require("@dxos/invariant");
526
- var import_keys8 = require("@dxos/keys");
527
- var import_log7 = require("@dxos/log");
638
+ var import_keys9 = require("@dxos/keys");
639
+ var import_log8 = require("@dxos/log");
528
640
  var import_messaging = require("@dxos/messaging");
529
- var import_protocols4 = require("@dxos/protocols");
641
+ var import_protocols6 = require("@dxos/protocols");
530
642
  var import_services = require("@dxos/protocols/proto/dxos/client/services");
531
- var import_util6 = require("@dxos/util");
643
+ var import_util7 = require("@dxos/util");
532
644
 
533
645
  // packages/core/mesh/network-manager/src/connection-log.ts
534
- var import_async6 = require("@dxos/async");
646
+ var import_async7 = require("@dxos/async");
535
647
  var import_debug3 = require("@dxos/debug");
536
- var import_keys7 = require("@dxos/keys");
537
- var import_util5 = require("@dxos/util");
648
+ var import_keys8 = require("@dxos/keys");
649
+ var import_util6 = require("@dxos/util");
538
650
 
539
651
  // packages/core/mesh/network-manager/src/swarm/connection.ts
540
- var import_async = require("@dxos/async");
652
+ var import_async2 = require("@dxos/async");
541
653
  var import_context = require("@dxos/context");
542
654
  var import_debug = require("@dxos/debug");
543
- var import_errors = require("@dxos/errors");
544
655
  var import_invariant = require("@dxos/invariant");
545
- var import_keys = require("@dxos/keys");
546
- var import_log = require("@dxos/log");
656
+ var import_keys2 = require("@dxos/keys");
657
+ var import_log2 = require("@dxos/log");
547
658
  var import_protocols = require("@dxos/protocols");
548
659
  function _ts_decorate(decorators, target, key, desc) {
549
660
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -555,7 +666,7 @@ function _ts_decorate(decorators, target, key, desc) {
555
666
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
556
667
  return c > 3 && r && Object.defineProperty(target, key, r), r;
557
668
  }
558
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts";
669
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts";
559
670
  var STARTING_SIGNALLING_DELAY = 10;
560
671
  var MAX_SIGNALLING_DELAY = 300;
561
672
  var ConnectionState;
@@ -615,21 +726,21 @@ var Connection = class {
615
726
  this._state = ConnectionState.CREATED;
616
727
  this._incomingSignalBuffer = [];
617
728
  this._outgoingSignalBuffer = [];
618
- this.stateChanged = new import_async.Event();
729
+ this.stateChanged = new import_async2.Event();
619
730
  this.errors = new import_debug.ErrorStream();
620
- this._instanceId = import_keys.PublicKey.random().toHex();
621
- this._signalSendTask = new import_async.DeferredTask(this._ctx, async () => {
731
+ this._instanceId = import_keys2.PublicKey.random().toHex();
732
+ this._signalSendTask = new import_async2.DeferredTask(this._ctx, async () => {
622
733
  await this._flushSignalBuffer();
623
734
  });
624
735
  this._signallingDelay = STARTING_SIGNALLING_DELAY;
625
- import_log.log.trace("dxos.mesh.connection.construct", {
736
+ import_log2.log.trace("dxos.mesh.connection.construct", {
626
737
  sessionId: this.sessionId,
627
738
  topic: this.topic,
628
739
  localPeerId: this.ownId,
629
740
  remotePeerId: this.remoteId,
630
741
  initiator: this.initiator
631
742
  }, {
632
- F: __dxlog_file,
743
+ F: __dxlog_file2,
633
744
  L: 123,
634
745
  S: this,
635
746
  C: (f, a) => f(...a)
@@ -649,7 +760,7 @@ var Connection = class {
649
760
  */
650
761
  async openConnection() {
651
762
  (0, import_invariant.invariant)(this._state === ConnectionState.INITIAL, "Invalid state.", {
652
- F: __dxlog_file,
763
+ F: __dxlog_file2,
653
764
  L: 148,
654
765
  S: this,
655
766
  A: [
@@ -657,22 +768,22 @@ var Connection = class {
657
768
  "'Invalid state.'"
658
769
  ]
659
770
  });
660
- import_log.log.trace("dxos.mesh.connection.open-connection", import_protocols.trace.begin({
771
+ import_log2.log.trace("dxos.mesh.connection.open-connection", import_protocols.trace.begin({
661
772
  id: this._instanceId
662
773
  }), {
663
- F: __dxlog_file,
774
+ F: __dxlog_file2,
664
775
  L: 149,
665
776
  S: this,
666
777
  C: (f, a) => f(...a)
667
778
  });
668
- import_log.log.trace("dxos.mesh.connection.open", {
779
+ import_log2.log.trace("dxos.mesh.connection.open", {
669
780
  sessionId: this.sessionId,
670
781
  topic: this.topic,
671
782
  localPeerId: this.ownId,
672
783
  remotePeerId: this.remoteId,
673
784
  initiator: this.initiator
674
785
  }, {
675
- F: __dxlog_file,
786
+ F: __dxlog_file2,
676
787
  L: 150,
677
788
  S: this,
678
789
  C: (f, a) => f(...a)
@@ -682,16 +793,16 @@ var Connection = class {
682
793
  this.errors.raise(err);
683
794
  });
684
795
  this._protocol.stream.on("close", () => {
685
- (0, import_log.log)("protocol stream closed", void 0, {
686
- F: __dxlog_file,
796
+ (0, import_log2.log)("protocol stream closed", void 0, {
797
+ F: __dxlog_file2,
687
798
  L: 167,
688
799
  S: this,
689
800
  C: (f, a) => f(...a)
690
801
  });
691
- this.close(new import_errors.ProtocolError("protocol stream closed")).catch((err) => this.errors.raise(err));
802
+ this.close(new import_protocols.ProtocolError("protocol stream closed")).catch((err) => this.errors.raise(err));
692
803
  });
693
804
  (0, import_invariant.invariant)(!this._transport, void 0, {
694
- F: __dxlog_file,
805
+ F: __dxlog_file2,
695
806
  L: 171,
696
807
  S: this,
697
808
  A: [
@@ -710,8 +821,8 @@ var Connection = class {
710
821
  });
711
822
  this._transport.closed.once(() => {
712
823
  this._transport = void 0;
713
- (0, import_log.log)("abort triggered by transport close", void 0, {
714
- F: __dxlog_file,
824
+ (0, import_log2.log)("abort triggered by transport close", void 0, {
825
+ F: __dxlog_file2,
715
826
  L: 185,
716
827
  S: this,
717
828
  C: (f, a) => f(...a)
@@ -719,10 +830,10 @@ var Connection = class {
719
830
  this.abort().catch((err) => this.errors.raise(err));
720
831
  });
721
832
  this._transport.errors.handle((err) => {
722
- (0, import_log.log)("transport error:", {
833
+ (0, import_log2.log)("transport error:", {
723
834
  err
724
835
  }, {
725
- F: __dxlog_file,
836
+ F: __dxlog_file2,
726
837
  L: 190,
727
838
  S: this,
728
839
  C: (f, a) => f(...a)
@@ -730,27 +841,27 @@ var Connection = class {
730
841
  if (!this.closeReason) {
731
842
  this.closeReason = err?.message;
732
843
  }
733
- if (err instanceof import_errors.ConnectionResetError) {
734
- (0, import_log.log)("aborting due to transport ConnectionResetError", void 0, {
735
- F: __dxlog_file,
844
+ if (err instanceof import_protocols.ConnectionResetError) {
845
+ import_log2.log.warn("aborting due to transport ConnectionResetError", void 0, {
846
+ F: __dxlog_file2,
736
847
  L: 197,
737
848
  S: this,
738
849
  C: (f, a) => f(...a)
739
850
  });
740
851
  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,
852
+ } else if (err instanceof import_protocols.ConnectivityError) {
853
+ import_log2.log.warn("aborting due to transport ConnectivityError", void 0, {
854
+ F: __dxlog_file2,
744
855
  L: 200,
745
856
  S: this,
746
857
  C: (f, a) => f(...a)
747
858
  });
748
859
  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", {
860
+ } else if (err instanceof import_protocols.UnknownProtocolError) {
861
+ import_log2.log.warn("unsure what to do with UnknownProtocolError, will keep on truckin", {
751
862
  err
752
863
  }, {
753
- F: __dxlog_file,
864
+ F: __dxlog_file2,
754
865
  L: 203,
755
866
  S: this,
756
867
  C: (f, a) => f(...a)
@@ -764,28 +875,28 @@ var Connection = class {
764
875
  void this._transport.signal(signal);
765
876
  }
766
877
  this._incomingSignalBuffer = [];
767
- import_log.log.trace("dxos.mesh.connection.open-connection", import_protocols.trace.end({
878
+ import_log2.log.trace("dxos.mesh.connection.open-connection", import_protocols.trace.end({
768
879
  id: this._instanceId
769
880
  }), {
770
- F: __dxlog_file,
881
+ F: __dxlog_file2,
771
882
  L: 218,
772
883
  S: this,
773
884
  C: (f, a) => f(...a)
774
885
  });
775
886
  }
776
887
  async abort(err) {
777
- (0, import_log.log)("aborting...", {
888
+ (0, import_log2.log)("aborting...", {
778
889
  err
779
890
  }, {
780
- F: __dxlog_file,
781
- L: 224,
891
+ F: __dxlog_file2,
892
+ L: 225,
782
893
  S: this,
783
894
  C: (f, a) => f(...a)
784
895
  });
785
896
  if (this._state === ConnectionState.CLOSED || this._state === ConnectionState.ABORTED) {
786
- (0, import_log.log)(`abort ignored: already ${this._state}`, this.closeReason, {
787
- F: __dxlog_file,
788
- L: 226,
897
+ (0, import_log2.log)(`abort ignored: already ${this._state}`, this.closeReason, {
898
+ F: __dxlog_file2,
899
+ L: 227,
789
900
  S: this,
790
901
  C: (f, a) => f(...a)
791
902
  });
@@ -797,19 +908,19 @@ var Connection = class {
797
908
  }
798
909
  await this._ctx.dispose();
799
910
  try {
800
- (0, import_log.log)("aborting protocol... ", {
911
+ (0, import_log2.log)("aborting protocol... ", {
801
912
  proto: this._protocol
802
913
  }, {
803
- F: __dxlog_file,
804
- L: 239,
914
+ F: __dxlog_file2,
915
+ L: 240,
805
916
  S: this,
806
917
  C: (f, a) => f(...a)
807
918
  });
808
919
  await this._protocol.abort();
809
920
  } catch (err2) {
810
- import_log.log.catch(err2, void 0, {
811
- F: __dxlog_file,
812
- L: 242,
921
+ import_log2.log.catch(err2, void 0, {
922
+ F: __dxlog_file2,
923
+ L: 243,
813
924
  S: this,
814
925
  C: (f, a) => f(...a)
815
926
  });
@@ -817,9 +928,9 @@ var Connection = class {
817
928
  try {
818
929
  await this._transport?.destroy();
819
930
  } catch (err2) {
820
- import_log.log.catch(err2, void 0, {
821
- F: __dxlog_file,
822
- L: 249,
931
+ import_log2.log.catch(err2, void 0, {
932
+ F: __dxlog_file2,
933
+ L: 250,
823
934
  S: this,
824
935
  C: (f, a) => f(...a)
825
936
  });
@@ -827,9 +938,9 @@ var Connection = class {
827
938
  try {
828
939
  this._callbacks?.onClosed?.(err);
829
940
  } catch (err2) {
830
- import_log.log.catch(err2, void 0, {
831
- F: __dxlog_file,
832
- L: 255,
941
+ import_log2.log.catch(err2, void 0, {
942
+ F: __dxlog_file2,
943
+ L: 256,
833
944
  S: this,
834
945
  C: (f, a) => f(...a)
835
946
  });
@@ -846,11 +957,11 @@ var Connection = class {
846
957
  const lastState = this._state;
847
958
  this._changeState(ConnectionState.CLOSING);
848
959
  await this._ctx.dispose();
849
- (0, import_log.log)("closing...", {
960
+ (0, import_log2.log)("closing...", {
850
961
  peerId: this.ownId
851
962
  }, {
852
- F: __dxlog_file,
853
- L: 277,
963
+ F: __dxlog_file2,
964
+ L: 278,
854
965
  S: this,
855
966
  C: (f, a) => f(...a)
856
967
  });
@@ -858,9 +969,9 @@ var Connection = class {
858
969
  try {
859
970
  await this._protocol.close();
860
971
  } catch (err2) {
861
- import_log.log.catch(err2, void 0, {
862
- F: __dxlog_file,
863
- L: 284,
972
+ import_log2.log.catch(err2, void 0, {
973
+ F: __dxlog_file2,
974
+ L: 285,
864
975
  S: this,
865
976
  C: (f, a) => f(...a)
866
977
  });
@@ -868,19 +979,19 @@ var Connection = class {
868
979
  try {
869
980
  await this._transport?.destroy();
870
981
  } catch (err2) {
871
- import_log.log.catch(err2, void 0, {
872
- F: __dxlog_file,
873
- L: 291,
982
+ import_log2.log.catch(err2, void 0, {
983
+ F: __dxlog_file2,
984
+ L: 292,
874
985
  S: this,
875
986
  C: (f, a) => f(...a)
876
987
  });
877
988
  }
878
989
  }
879
- (0, import_log.log)("closed", {
990
+ (0, import_log2.log)("closed", {
880
991
  peerId: this.ownId
881
992
  }, {
882
- F: __dxlog_file,
883
- L: 295,
993
+ F: __dxlog_file2,
994
+ L: 296,
884
995
  S: this,
885
996
  C: (f, a) => f(...a)
886
997
  });
@@ -897,7 +1008,7 @@ var Connection = class {
897
1008
  }
898
1009
  try {
899
1010
  if (process.env.NODE_ENV !== "test") {
900
- await (0, import_context.cancelWithContext)(this._ctx, (0, import_async.sleep)(this._signallingDelay));
1011
+ await (0, import_context.cancelWithContext)(this._ctx, (0, import_async2.sleep)(this._signallingDelay));
901
1012
  this._signallingDelay = Math.min(this._signallingDelay * 2, MAX_SIGNALLING_DELAY);
902
1013
  }
903
1014
  const signals = [
@@ -916,14 +1027,14 @@ var Connection = class {
916
1027
  }
917
1028
  });
918
1029
  } catch (err) {
919
- if (err instanceof import_errors.CancelledError) {
1030
+ if (err instanceof import_protocols.CancelledError) {
920
1031
  return;
921
1032
  }
922
- import_log.log.warn("signal failed", {
1033
+ import_log2.log.warn("signal failed", {
923
1034
  err
924
1035
  }, {
925
- F: __dxlog_file,
926
- L: 332,
1036
+ F: __dxlog_file2,
1037
+ L: 333,
927
1038
  S: this,
928
1039
  C: (f, a) => f(...a)
929
1040
  });
@@ -935,8 +1046,8 @@ var Connection = class {
935
1046
  */
936
1047
  async signal(msg) {
937
1048
  (0, import_invariant.invariant)(msg.sessionId, void 0, {
938
- F: __dxlog_file,
939
- L: 341,
1049
+ F: __dxlog_file2,
1050
+ L: 342,
940
1051
  S: this,
941
1052
  A: [
942
1053
  "msg.sessionId",
@@ -944,17 +1055,17 @@ var Connection = class {
944
1055
  ]
945
1056
  });
946
1057
  if (!msg.sessionId.equals(this.sessionId)) {
947
- (0, import_log.log)("dropping signal for incorrect session id", void 0, {
948
- F: __dxlog_file,
949
- L: 343,
1058
+ (0, import_log2.log)("dropping signal for incorrect session id", void 0, {
1059
+ F: __dxlog_file2,
1060
+ L: 344,
950
1061
  S: this,
951
1062
  C: (f, a) => f(...a)
952
1063
  });
953
1064
  return;
954
1065
  }
955
1066
  (0, import_invariant.invariant)(msg.data.signal || msg.data.signalBatch, void 0, {
956
- F: __dxlog_file,
957
- L: 346,
1067
+ F: __dxlog_file2,
1068
+ L: 347,
958
1069
  S: this,
959
1070
  A: [
960
1071
  "msg.data.signal || msg.data.signalBatch",
@@ -962,8 +1073,8 @@ var Connection = class {
962
1073
  ]
963
1074
  });
964
1075
  (0, import_invariant.invariant)(msg.author?.equals(this.remoteId), void 0, {
965
- F: __dxlog_file,
966
- L: 347,
1076
+ F: __dxlog_file2,
1077
+ L: 348,
967
1078
  S: this,
968
1079
  A: [
969
1080
  "msg.author?.equals(this.remoteId)",
@@ -971,8 +1082,8 @@ var Connection = class {
971
1082
  ]
972
1083
  });
973
1084
  (0, import_invariant.invariant)(msg.recipient?.equals(this.ownId), void 0, {
974
- F: __dxlog_file,
975
- L: 348,
1085
+ F: __dxlog_file2,
1086
+ L: 349,
976
1087
  S: this,
977
1088
  A: [
978
1089
  "msg.recipient?.equals(this.ownId)",
@@ -990,34 +1101,34 @@ var Connection = class {
990
1101
  ConnectionState.CREATED,
991
1102
  ConnectionState.INITIAL
992
1103
  ].includes(this.state)) {
993
- (0, import_log.log)("buffered signal", {
1104
+ (0, import_log2.log)("buffered signal", {
994
1105
  peerId: this.ownId,
995
1106
  remoteId: this.remoteId,
996
1107
  msg: msg.data
997
1108
  }, {
998
- F: __dxlog_file,
999
- L: 357,
1109
+ F: __dxlog_file2,
1110
+ L: 358,
1000
1111
  S: this,
1001
1112
  C: (f, a) => f(...a)
1002
1113
  });
1003
1114
  this._incomingSignalBuffer.push(signal);
1004
1115
  } else {
1005
1116
  (0, import_invariant.invariant)(this._transport, "Connection not ready to accept signals.", {
1006
- F: __dxlog_file,
1007
- L: 360,
1117
+ F: __dxlog_file2,
1118
+ L: 361,
1008
1119
  S: this,
1009
1120
  A: [
1010
1121
  "this._transport",
1011
1122
  "'Connection not ready to accept signals.'"
1012
1123
  ]
1013
1124
  });
1014
- (0, import_log.log)("received signal", {
1125
+ (0, import_log2.log)("received signal", {
1015
1126
  peerId: this.ownId,
1016
1127
  remoteId: this.remoteId,
1017
1128
  msg: msg.data
1018
1129
  }, {
1019
- F: __dxlog_file,
1020
- L: 361,
1130
+ F: __dxlog_file2,
1131
+ L: 362,
1021
1132
  S: this,
1022
1133
  C: (f, a) => f(...a)
1023
1134
  });
@@ -1029,19 +1140,19 @@ var Connection = class {
1029
1140
  this._changeState(ConnectionState.INITIAL);
1030
1141
  }
1031
1142
  _changeState(state) {
1032
- (0, import_log.log)("stateChanged", {
1143
+ (0, import_log2.log)("stateChanged", {
1033
1144
  from: this._state,
1034
1145
  to: state,
1035
1146
  peerId: this.ownId
1036
1147
  }, {
1037
- F: __dxlog_file,
1038
- L: 372,
1148
+ F: __dxlog_file2,
1149
+ L: 373,
1039
1150
  S: this,
1040
1151
  C: (f, a) => f(...a)
1041
1152
  });
1042
1153
  (0, import_invariant.invariant)(state !== this._state, "Already in this state.", {
1043
- F: __dxlog_file,
1044
- L: 373,
1154
+ F: __dxlog_file2,
1155
+ L: 374,
1045
1156
  S: this,
1046
1157
  A: [
1047
1158
  "state !== this._state",
@@ -1053,301 +1164,83 @@ var Connection = class {
1053
1164
  }
1054
1165
  };
1055
1166
  _ts_decorate([
1056
- import_async.synchronized
1167
+ import_async2.synchronized
1057
1168
  ], Connection.prototype, "abort", null);
1058
1169
  _ts_decorate([
1059
- import_async.synchronized
1170
+ import_async2.synchronized
1060
1171
  ], Connection.prototype, "close", null);
1061
1172
 
1062
1173
  // packages/core/mesh/network-manager/src/swarm/swarm.ts
1063
- var import_async3 = require("@dxos/async");
1174
+ var import_async4 = require("@dxos/async");
1064
1175
  var import_context4 = require("@dxos/context");
1065
1176
  var import_debug2 = require("@dxos/debug");
1066
1177
  var import_invariant4 = require("@dxos/invariant");
1067
- var import_keys4 = require("@dxos/keys");
1068
- var import_log4 = require("@dxos/log");
1069
- var import_protocols3 = require("@dxos/protocols");
1070
- var import_util2 = require("@dxos/util");
1178
+ var import_keys5 = require("@dxos/keys");
1179
+ var import_log5 = require("@dxos/log");
1180
+ var import_protocols4 = require("@dxos/protocols");
1181
+ var import_util3 = require("@dxos/util");
1071
1182
 
1072
- // packages/core/mesh/network-manager/src/signal/swarm-messenger.ts
1183
+ // packages/core/mesh/network-manager/src/swarm/peer.ts
1184
+ var import_async3 = require("@dxos/async");
1073
1185
  var import_context2 = require("@dxos/context");
1074
1186
  var import_invariant2 = require("@dxos/invariant");
1075
- var import_keys2 = require("@dxos/keys");
1076
- var import_log2 = require("@dxos/log");
1187
+ var import_keys3 = require("@dxos/keys");
1188
+ var import_log3 = require("@dxos/log");
1077
1189
  var import_protocols2 = require("@dxos/protocols");
1078
- var import_util = require("@dxos/util");
1079
- var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
1080
- var SwarmMessage = import_protocols2.schema.getCodecForType("dxos.mesh.swarm.SwarmMessage");
1081
- var SwarmMessenger = class {
1082
- constructor({ sendMessage, onSignal, onOffer, topic }) {
1190
+ function _ts_decorate2(decorators, target, key, desc) {
1191
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1192
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
1193
+ r = Reflect.decorate(decorators, target, key, desc);
1194
+ else
1195
+ for (var i = decorators.length - 1; i >= 0; i--)
1196
+ if (d = decorators[i])
1197
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1198
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1199
+ }
1200
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts";
1201
+ var ConnectionDisplacedError = class extends import_protocols2.SystemError {
1202
+ constructor() {
1203
+ super("Connection displaced by remote initiator.");
1204
+ }
1205
+ };
1206
+ var CONNECTION_COUNTS_STABLE_AFTER = 5e3;
1207
+ var Peer = class {
1208
+ // TODO(burdon): Convert to map?
1209
+ constructor(id, topic, localPeerId, _signalMessaging, _protocolProvider, _transportFactory, _connectionLimiter, _callbacks) {
1210
+ this.id = id;
1211
+ this.topic = topic;
1212
+ this.localPeerId = localPeerId;
1213
+ this._signalMessaging = _signalMessaging;
1214
+ this._protocolProvider = _protocolProvider;
1215
+ this._transportFactory = _transportFactory;
1216
+ this._connectionLimiter = _connectionLimiter;
1217
+ this._callbacks = _callbacks;
1218
+ this._availableAfter = 0;
1219
+ this.availableToConnect = true;
1083
1220
  this._ctx = new import_context2.Context();
1084
- this._offerRecords = new import_util.ComplexMap((key) => key.toHex());
1085
- this._sendMessage = sendMessage;
1086
- this._onSignal = onSignal;
1087
- this._onOffer = onOffer;
1088
- this._topic = topic;
1089
- }
1090
- async receiveMessage({ author, recipient, payload }) {
1091
- if (payload.type_url !== "dxos.mesh.swarm.SwarmMessage") {
1092
- return;
1093
- }
1094
- const message = SwarmMessage.decode(payload.value);
1095
- if (!this._topic.equals(message.topic)) {
1096
- return;
1097
- }
1098
- (0, import_log2.log)("received", {
1099
- from: author,
1100
- to: recipient,
1101
- msg: message
1102
- }, {
1103
- F: __dxlog_file2,
1104
- L: 69,
1105
- S: this,
1106
- C: (f, a) => f(...a)
1107
- });
1108
- if (message.data?.offer) {
1109
- await this._handleOffer({
1110
- author,
1111
- recipient,
1112
- message
1113
- });
1114
- } else if (message.data?.answer) {
1115
- await this._resolveAnswers(message);
1116
- } else if (message.data?.signal) {
1117
- await this._handleSignal({
1118
- author,
1119
- recipient,
1120
- message
1121
- });
1122
- } else if (message.data?.signalBatch) {
1123
- await this._handleSignal({
1124
- author,
1125
- recipient,
1126
- message
1127
- });
1128
- } else {
1129
- import_log2.log.warn("unknown message", {
1130
- message
1131
- }, {
1132
- F: __dxlog_file2,
1133
- L: 80,
1134
- S: this,
1135
- C: (f, a) => f(...a)
1136
- });
1137
- }
1138
- }
1139
- async signal(message) {
1140
- (0, import_invariant2.invariant)(message.data?.signal || message.data?.signalBatch, "Invalid message", {
1141
- F: __dxlog_file2,
1142
- L: 85,
1143
- S: this,
1144
- A: [
1145
- "message.data?.signal || message.data?.signalBatch",
1146
- "'Invalid message'"
1147
- ]
1148
- });
1149
- await this._sendReliableMessage({
1150
- author: message.author,
1151
- recipient: message.recipient,
1152
- message
1153
- });
1154
- }
1155
- async offer(message) {
1156
- const networkMessage = {
1157
- ...message,
1158
- messageId: import_keys2.PublicKey.random()
1159
- };
1160
- return new Promise((resolve, reject) => {
1161
- this._offerRecords.set(networkMessage.messageId, {
1162
- resolve
1163
- });
1164
- this._sendReliableMessage({
1165
- author: message.author,
1166
- recipient: message.recipient,
1167
- message: networkMessage
1168
- }).catch((err) => reject(err));
1169
- });
1170
- }
1171
- async _sendReliableMessage({ author, recipient, message }) {
1172
- const networkMessage = {
1173
- ...message,
1174
- // Setting unique message_id if it not specified yet.
1175
- messageId: message.messageId ?? import_keys2.PublicKey.random()
1176
- };
1177
- (0, import_log2.log)("sending", {
1178
- from: author,
1179
- to: recipient,
1180
- msg: networkMessage
1181
- }, {
1182
- F: __dxlog_file2,
1183
- L: 123,
1184
- S: this,
1185
- C: (f, a) => f(...a)
1186
- });
1187
- await this._sendMessage({
1188
- author,
1189
- recipient,
1190
- payload: {
1191
- type_url: "dxos.mesh.swarm.SwarmMessage",
1192
- value: SwarmMessage.encode(networkMessage)
1193
- }
1194
- });
1195
- }
1196
- async _resolveAnswers(message) {
1197
- (0, import_invariant2.invariant)(message.data?.answer?.offerMessageId, "No offerMessageId", {
1198
- F: __dxlog_file2,
1199
- L: 135,
1200
- S: this,
1201
- A: [
1202
- "message.data?.answer?.offerMessageId",
1203
- "'No offerMessageId'"
1204
- ]
1205
- });
1206
- const offerRecord = this._offerRecords.get(message.data.answer.offerMessageId);
1207
- if (offerRecord) {
1208
- this._offerRecords.delete(message.data.answer.offerMessageId);
1209
- (0, import_invariant2.invariant)(message.data?.answer, "No answer", {
1210
- F: __dxlog_file2,
1211
- L: 139,
1212
- S: this,
1213
- A: [
1214
- "message.data?.answer",
1215
- "'No answer'"
1216
- ]
1217
- });
1218
- (0, import_log2.log)("resolving", {
1219
- answer: message.data.answer
1220
- }, {
1221
- F: __dxlog_file2,
1222
- L: 140,
1223
- S: this,
1224
- C: (f, a) => f(...a)
1225
- });
1226
- offerRecord.resolve(message.data.answer);
1227
- }
1228
- }
1229
- async _handleOffer({ author, recipient, message }) {
1230
- (0, import_invariant2.invariant)(message.data.offer, "No offer", {
1231
- F: __dxlog_file2,
1232
- L: 154,
1233
- S: this,
1234
- A: [
1235
- "message.data.offer",
1236
- "'No offer'"
1237
- ]
1238
- });
1239
- const offerMessage = {
1240
- author,
1241
- recipient,
1242
- ...message,
1243
- data: {
1244
- offer: message.data.offer
1245
- }
1246
- };
1247
- const answer = await this._onOffer(offerMessage);
1248
- answer.offerMessageId = message.messageId;
1249
- try {
1250
- await this._sendReliableMessage({
1251
- author: recipient,
1252
- recipient: author,
1253
- message: {
1254
- topic: message.topic,
1255
- sessionId: message.sessionId,
1256
- data: {
1257
- answer
1258
- }
1259
- }
1260
- });
1261
- } catch (err) {
1262
- import_log2.log.warn("error sending answer", {
1263
- err
1264
- }, {
1265
- F: __dxlog_file2,
1266
- L: 174,
1267
- S: this,
1268
- C: (f, a) => f(...a)
1269
- });
1270
- }
1271
- }
1272
- async _handleSignal({ author, recipient, message }) {
1273
- (0, import_invariant2.invariant)(message.messageId, void 0, {
1274
- F: __dxlog_file2,
1275
- L: 187,
1276
- S: this,
1277
- A: [
1278
- "message.messageId",
1279
- ""
1280
- ]
1281
- });
1282
- (0, import_invariant2.invariant)(message.data.signal || message.data.signalBatch, "Invalid message", {
1283
- F: __dxlog_file2,
1284
- L: 188,
1285
- S: this,
1286
- A: [
1287
- "message.data.signal || message.data.signalBatch",
1288
- "'Invalid message'"
1289
- ]
1290
- });
1291
- const signalMessage = {
1292
- author,
1293
- recipient,
1294
- ...message,
1295
- data: {
1296
- signal: message.data.signal,
1297
- signalBatch: message.data.signalBatch
1298
- }
1299
- };
1300
- await this._onSignal(signalMessage);
1301
- }
1302
- };
1303
-
1304
- // packages/core/mesh/network-manager/src/swarm/peer.ts
1305
- var import_async2 = require("@dxos/async");
1306
- var import_context3 = require("@dxos/context");
1307
- var import_errors2 = require("@dxos/errors");
1308
- var import_invariant3 = require("@dxos/invariant");
1309
- var import_keys3 = require("@dxos/keys");
1310
- var import_log3 = require("@dxos/log");
1311
- function _ts_decorate2(decorators, target, key, desc) {
1312
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1313
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
1314
- r = Reflect.decorate(decorators, target, key, desc);
1315
- else
1316
- for (var i = decorators.length - 1; i >= 0; i--)
1317
- if (d = decorators[i])
1318
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1319
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1320
- }
1321
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts";
1322
- var ConnectionDisplacedError = class extends import_errors2.SystemError {
1323
- constructor() {
1324
- super("Connection displaced by remote initiator.");
1325
- }
1326
- };
1327
- var CONNECTION_COUNTS_STABLE_AFTER = 5e3;
1328
- var Peer = class {
1329
- // TODO(burdon): Convert to map?
1330
- constructor(id, topic, localPeerId, _signalMessaging, _protocolProvider, _transportFactory, _connectionLimiter, _callbacks) {
1331
- this.id = id;
1332
- this.topic = topic;
1333
- this.localPeerId = localPeerId;
1334
- this._signalMessaging = _signalMessaging;
1335
- this._protocolProvider = _protocolProvider;
1336
- this._transportFactory = _transportFactory;
1337
- this._connectionLimiter = _connectionLimiter;
1338
- this._callbacks = _callbacks;
1339
- this._availableAfter = 0;
1340
- this.availableToConnect = true;
1341
- this._ctx = new import_context3.Context();
1342
- this.advertizing = false;
1343
- this.initiating = false;
1344
- this.connectionDisplaced = new import_async2.Event();
1221
+ this.advertizing = false;
1222
+ this.initiating = false;
1223
+ this.connectionDisplaced = new import_async3.Event();
1345
1224
  }
1346
1225
  /**
1347
1226
  * Respond to remote offer.
1348
1227
  */
1349
1228
  async onOffer(message) {
1350
1229
  const remoteId = message.author;
1230
+ if (this.connection && ![
1231
+ ConnectionState.CREATED,
1232
+ ConnectionState.INITIAL
1233
+ ].includes(this.connection.state)) {
1234
+ import_log3.log.info(`received offer when connection already in ${this.connection.state} state`, void 0, {
1235
+ F: __dxlog_file3,
1236
+ L: 112,
1237
+ S: this,
1238
+ C: (f, a) => f(...a)
1239
+ });
1240
+ return {
1241
+ accept: false
1242
+ };
1243
+ }
1351
1244
  if (this.connection || this.initiating) {
1352
1245
  if (remoteId.toHex() < this.localPeerId.toHex()) {
1353
1246
  (0, import_log3.log)("close local connection", {
@@ -1357,7 +1250,7 @@ var Peer = class {
1357
1250
  sessionId: this.connection?.sessionId
1358
1251
  }, {
1359
1252
  F: __dxlog_file3,
1360
- L: 117,
1253
+ L: 121,
1361
1254
  S: this,
1362
1255
  C: (f, a) => f(...a)
1363
1256
  });
@@ -1372,9 +1265,9 @@ var Peer = class {
1372
1265
  }
1373
1266
  if (await this._callbacks.onOffer(remoteId)) {
1374
1267
  if (!this.connection) {
1375
- (0, import_invariant3.invariant)(message.sessionId, void 0, {
1268
+ (0, import_invariant2.invariant)(message.sessionId, void 0, {
1376
1269
  F: __dxlog_file3,
1377
- L: 137,
1270
+ L: 141,
1378
1271
  S: this,
1379
1272
  A: [
1380
1273
  "message.sessionId",
@@ -1387,7 +1280,7 @@ var Peer = class {
1387
1280
  connection.initiate();
1388
1281
  await connection.openConnection();
1389
1282
  } catch (err) {
1390
- if (!(err instanceof import_errors2.CancelledError)) {
1283
+ if (!(err instanceof import_protocols2.CancelledError)) {
1391
1284
  import_log3.log.warn("connection error", {
1392
1285
  topic: this.topic,
1393
1286
  peerId: this.localPeerId,
@@ -1395,7 +1288,7 @@ var Peer = class {
1395
1288
  err
1396
1289
  }, {
1397
1290
  F: __dxlog_file3,
1398
- L: 147,
1291
+ L: 151,
1399
1292
  S: this,
1400
1293
  C: (f, a) => f(...a)
1401
1294
  });
@@ -1415,18 +1308,18 @@ var Peer = class {
1415
1308
  * Initiate a connection to the remote peer.
1416
1309
  */
1417
1310
  async initiateConnection() {
1418
- (0, import_invariant3.invariant)(!this.initiating, "Initiation in progress.", {
1311
+ (0, import_invariant2.invariant)(!this.initiating, "Initiation in progress.", {
1419
1312
  F: __dxlog_file3,
1420
- L: 164,
1313
+ L: 168,
1421
1314
  S: this,
1422
1315
  A: [
1423
1316
  "!this.initiating",
1424
1317
  "'Initiation in progress.'"
1425
1318
  ]
1426
1319
  });
1427
- (0, import_invariant3.invariant)(!this.connection, "Already connected.", {
1320
+ (0, import_invariant2.invariant)(!this.connection, "Already connected.", {
1428
1321
  F: __dxlog_file3,
1429
- L: 165,
1322
+ L: 169,
1430
1323
  S: this,
1431
1324
  A: [
1432
1325
  "!this.connection",
@@ -1441,7 +1334,7 @@ var Peer = class {
1441
1334
  sessionId
1442
1335
  }, {
1443
1336
  F: __dxlog_file3,
1444
- L: 167,
1337
+ L: 171,
1445
1338
  S: this,
1446
1339
  C: (f, a) => f(...a)
1447
1340
  });
@@ -1466,14 +1359,14 @@ var Peer = class {
1466
1359
  remoteId: this.id
1467
1360
  }, {
1468
1361
  F: __dxlog_file3,
1469
- L: 183,
1362
+ L: 187,
1470
1363
  S: this,
1471
1364
  C: (f, a) => f(...a)
1472
1365
  });
1473
1366
  if (connection.state !== ConnectionState.INITIAL) {
1474
1367
  (0, import_log3.log)("ignoring response", void 0, {
1475
1368
  F: __dxlog_file3,
1476
- L: 185,
1369
+ L: 189,
1477
1370
  S: this,
1478
1371
  C: (f, a) => f(...a)
1479
1372
  });
@@ -1493,11 +1386,17 @@ var Peer = class {
1493
1386
  remoteId: this.id
1494
1387
  }, {
1495
1388
  F: __dxlog_file3,
1496
- L: 196,
1389
+ L: 200,
1497
1390
  S: this,
1498
1391
  C: (f, a) => f(...a)
1499
1392
  });
1500
- if (err instanceof import_errors2.TimeoutError) {
1393
+ if (err instanceof import_protocols2.TimeoutError) {
1394
+ import_log3.log.warn("aborting connection due to signalling failure", void 0, {
1395
+ F: __dxlog_file3,
1396
+ L: 202,
1397
+ S: this,
1398
+ C: (f, a) => f(...a)
1399
+ });
1501
1400
  await connection.abort(err);
1502
1401
  }
1503
1402
  await this.closeConnection(err);
@@ -1519,13 +1418,13 @@ var Peer = class {
1519
1418
  sessionId
1520
1419
  }, {
1521
1420
  F: __dxlog_file3,
1522
- L: 213,
1421
+ L: 218,
1523
1422
  S: this,
1524
1423
  C: (f, a) => f(...a)
1525
1424
  });
1526
- (0, import_invariant3.invariant)(!this.connection, "Already connected.", {
1425
+ (0, import_invariant2.invariant)(!this.connection, "Already connected.", {
1527
1426
  F: __dxlog_file3,
1528
- L: 220,
1427
+ L: 225,
1529
1428
  S: this,
1530
1429
  A: [
1531
1430
  "!this.connection",
@@ -1561,7 +1460,7 @@ var Peer = class {
1561
1460
  initiator
1562
1461
  }, {
1563
1462
  F: __dxlog_file3,
1564
- L: 239,
1463
+ L: 244,
1565
1464
  S: this,
1566
1465
  C: (f, a) => f(...a)
1567
1466
  });
@@ -1574,14 +1473,14 @@ var Peer = class {
1574
1473
  initiator
1575
1474
  }, {
1576
1475
  F: __dxlog_file3,
1577
- L: 248,
1476
+ L: 253,
1578
1477
  S: this,
1579
1478
  C: (f, a) => f(...a)
1580
1479
  });
1581
1480
  this._connectionLimiter.doneConnecting(sessionId);
1582
- (0, import_invariant3.invariant)(this.connection === connection, "Connection mismatch (race condition).", {
1481
+ (0, import_invariant2.invariant)(this.connection === connection, "Connection mismatch (race condition).", {
1583
1482
  F: __dxlog_file3,
1584
- L: 253,
1483
+ L: 258,
1585
1484
  S: this,
1586
1485
  A: [
1587
1486
  "this.connection === connection",
@@ -1596,7 +1495,7 @@ var Peer = class {
1596
1495
  initiator
1597
1496
  }, {
1598
1497
  F: __dxlog_file3,
1599
- L: 255,
1498
+ L: 260,
1600
1499
  S: this,
1601
1500
  C: (f, a) => f(...a)
1602
1501
  });
@@ -1610,7 +1509,7 @@ var Peer = class {
1610
1509
  this._availableAfter = increaseInterval(this._availableAfter);
1611
1510
  }
1612
1511
  this._callbacks.onDisconnected();
1613
- (0, import_async2.scheduleTask)(this._connectionCtx, () => {
1512
+ (0, import_async3.scheduleTask)(this._connectionCtx, () => {
1614
1513
  this.availableToConnect = true;
1615
1514
  this._callbacks.onPeerAvailable();
1616
1515
  }, this._availableAfter);
@@ -1631,95 +1530,327 @@ var Peer = class {
1631
1530
  err
1632
1531
  }, {
1633
1532
  F: __dxlog_file3,
1634
- L: 295,
1533
+ L: 300,
1534
+ S: this,
1535
+ C: (f, a) => f(...a)
1536
+ });
1537
+ import_log3.log.trace("dxos.mesh.connection.error", {
1538
+ topic: this.topic,
1539
+ localPeerId: this.localPeerId,
1540
+ remotePeerId: this.id,
1541
+ sessionId,
1542
+ initiator,
1543
+ err
1544
+ }, {
1545
+ F: __dxlog_file3,
1546
+ L: 301,
1547
+ S: this,
1548
+ C: (f, a) => f(...a)
1549
+ });
1550
+ void this.closeConnection(err);
1551
+ });
1552
+ this.connection = connection;
1553
+ return connection;
1554
+ }
1555
+ async closeConnection(err) {
1556
+ if (!this.connection) {
1557
+ return;
1558
+ }
1559
+ const connection = this.connection;
1560
+ (0, import_log3.log)("closing...", {
1561
+ peerId: this.id,
1562
+ sessionId: connection.sessionId
1563
+ }, {
1564
+ F: __dxlog_file3,
1565
+ L: 326,
1566
+ S: this,
1567
+ C: (f, a) => f(...a)
1568
+ });
1569
+ await connection.close(err);
1570
+ (0, import_log3.log)("closed", {
1571
+ peerId: this.id,
1572
+ sessionId: connection.sessionId
1573
+ }, {
1574
+ F: __dxlog_file3,
1575
+ L: 332,
1576
+ S: this,
1577
+ C: (f, a) => f(...a)
1578
+ });
1579
+ }
1580
+ async onSignal(message) {
1581
+ if (!this.connection) {
1582
+ (0, import_log3.log)("dropping signal message for non-existent connection", {
1583
+ message
1584
+ }, {
1585
+ F: __dxlog_file3,
1586
+ L: 337,
1587
+ S: this,
1588
+ C: (f, a) => f(...a)
1589
+ });
1590
+ return;
1591
+ }
1592
+ await this.connection.signal(message);
1593
+ }
1594
+ async destroy() {
1595
+ await this._ctx.dispose();
1596
+ (0, import_log3.log)("Destroying peer", {
1597
+ peerId: this.id,
1598
+ topic: this.topic
1599
+ }, {
1600
+ F: __dxlog_file3,
1601
+ L: 347,
1602
+ S: this,
1603
+ C: (f, a) => f(...a)
1604
+ });
1605
+ await this?.connection?.close();
1606
+ }
1607
+ };
1608
+ _ts_decorate2([
1609
+ import_async3.synchronized
1610
+ ], Peer.prototype, "destroy", null);
1611
+ var increaseInterval = (interval) => {
1612
+ if (interval === 0) {
1613
+ return 50;
1614
+ } else if (interval < 500) {
1615
+ return 500;
1616
+ } else if (interval < 1e3) {
1617
+ return 1e3;
1618
+ } else if (interval < 5e3) {
1619
+ return 5e3;
1620
+ }
1621
+ return 1e4;
1622
+ };
1623
+
1624
+ // packages/core/mesh/network-manager/src/signal/swarm-messenger.ts
1625
+ var import_context3 = require("@dxos/context");
1626
+ var import_invariant3 = require("@dxos/invariant");
1627
+ var import_keys4 = require("@dxos/keys");
1628
+ var import_log4 = require("@dxos/log");
1629
+ var import_protocols3 = require("@dxos/protocols");
1630
+ var import_util2 = require("@dxos/util");
1631
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
1632
+ var SwarmMessage = import_protocols3.schema.getCodecForType("dxos.mesh.swarm.SwarmMessage");
1633
+ var SwarmMessenger = class {
1634
+ constructor({ sendMessage, onSignal, onOffer, topic }) {
1635
+ this._ctx = new import_context3.Context();
1636
+ this._offerRecords = new import_util2.ComplexMap((key) => key.toHex());
1637
+ this._sendMessage = sendMessage;
1638
+ this._onSignal = onSignal;
1639
+ this._onOffer = onOffer;
1640
+ this._topic = topic;
1641
+ }
1642
+ async receiveMessage({ author, recipient, payload }) {
1643
+ if (payload.type_url !== "dxos.mesh.swarm.SwarmMessage") {
1644
+ return;
1645
+ }
1646
+ const message = SwarmMessage.decode(payload.value);
1647
+ if (!this._topic.equals(message.topic)) {
1648
+ return;
1649
+ }
1650
+ (0, import_log4.log)("received", {
1651
+ from: author,
1652
+ to: recipient,
1653
+ msg: message
1654
+ }, {
1655
+ F: __dxlog_file4,
1656
+ L: 69,
1657
+ S: this,
1658
+ C: (f, a) => f(...a)
1659
+ });
1660
+ if (message.data?.offer) {
1661
+ await this._handleOffer({
1662
+ author,
1663
+ recipient,
1664
+ message
1665
+ });
1666
+ } else if (message.data?.answer) {
1667
+ await this._resolveAnswers(message);
1668
+ } else if (message.data?.signal) {
1669
+ await this._handleSignal({
1670
+ author,
1671
+ recipient,
1672
+ message
1673
+ });
1674
+ } else if (message.data?.signalBatch) {
1675
+ await this._handleSignal({
1676
+ author,
1677
+ recipient,
1678
+ message
1679
+ });
1680
+ } else {
1681
+ import_log4.log.warn("unknown message", {
1682
+ message
1683
+ }, {
1684
+ F: __dxlog_file4,
1685
+ L: 80,
1686
+ S: this,
1687
+ C: (f, a) => f(...a)
1688
+ });
1689
+ }
1690
+ }
1691
+ async signal(message) {
1692
+ (0, import_invariant3.invariant)(message.data?.signal || message.data?.signalBatch, "Invalid message", {
1693
+ F: __dxlog_file4,
1694
+ L: 85,
1695
+ S: this,
1696
+ A: [
1697
+ "message.data?.signal || message.data?.signalBatch",
1698
+ "'Invalid message'"
1699
+ ]
1700
+ });
1701
+ await this._sendReliableMessage({
1702
+ author: message.author,
1703
+ recipient: message.recipient,
1704
+ message
1705
+ });
1706
+ }
1707
+ async offer(message) {
1708
+ const networkMessage = {
1709
+ ...message,
1710
+ messageId: import_keys4.PublicKey.random()
1711
+ };
1712
+ return new Promise((resolve, reject) => {
1713
+ this._offerRecords.set(networkMessage.messageId, {
1714
+ resolve
1715
+ });
1716
+ this._sendReliableMessage({
1717
+ author: message.author,
1718
+ recipient: message.recipient,
1719
+ message: networkMessage
1720
+ }).catch((err) => reject(err));
1721
+ });
1722
+ }
1723
+ async _sendReliableMessage({ author, recipient, message }) {
1724
+ const networkMessage = {
1725
+ ...message,
1726
+ // Setting unique message_id if it not specified yet.
1727
+ messageId: message.messageId ?? import_keys4.PublicKey.random()
1728
+ };
1729
+ (0, import_log4.log)("sending", {
1730
+ from: author,
1731
+ to: recipient,
1732
+ msg: networkMessage
1733
+ }, {
1734
+ F: __dxlog_file4,
1735
+ L: 123,
1736
+ S: this,
1737
+ C: (f, a) => f(...a)
1738
+ });
1739
+ await this._sendMessage({
1740
+ author,
1741
+ recipient,
1742
+ payload: {
1743
+ type_url: "dxos.mesh.swarm.SwarmMessage",
1744
+ value: SwarmMessage.encode(networkMessage)
1745
+ }
1746
+ });
1747
+ }
1748
+ async _resolveAnswers(message) {
1749
+ (0, import_invariant3.invariant)(message.data?.answer?.offerMessageId, "No offerMessageId", {
1750
+ F: __dxlog_file4,
1751
+ L: 135,
1752
+ S: this,
1753
+ A: [
1754
+ "message.data?.answer?.offerMessageId",
1755
+ "'No offerMessageId'"
1756
+ ]
1757
+ });
1758
+ const offerRecord = this._offerRecords.get(message.data.answer.offerMessageId);
1759
+ if (offerRecord) {
1760
+ this._offerRecords.delete(message.data.answer.offerMessageId);
1761
+ (0, import_invariant3.invariant)(message.data?.answer, "No answer", {
1762
+ F: __dxlog_file4,
1763
+ L: 139,
1635
1764
  S: this,
1636
- C: (f, a) => f(...a)
1765
+ A: [
1766
+ "message.data?.answer",
1767
+ "'No answer'"
1768
+ ]
1637
1769
  });
1638
- import_log3.log.trace("dxos.mesh.connection.error", {
1639
- topic: this.topic,
1640
- localPeerId: this.localPeerId,
1641
- remotePeerId: this.id,
1642
- sessionId,
1643
- initiator,
1644
- err
1770
+ (0, import_log4.log)("resolving", {
1771
+ answer: message.data.answer
1645
1772
  }, {
1646
- F: __dxlog_file3,
1647
- L: 296,
1773
+ F: __dxlog_file4,
1774
+ L: 140,
1648
1775
  S: this,
1649
1776
  C: (f, a) => f(...a)
1650
1777
  });
1651
- void this.closeConnection(err);
1652
- });
1653
- this.connection = connection;
1654
- return connection;
1655
- }
1656
- async closeConnection(err) {
1657
- if (!this.connection) {
1658
- return;
1778
+ offerRecord.resolve(message.data.answer);
1659
1779
  }
1660
- const connection = this.connection;
1661
- (0, import_log3.log)("closing...", {
1662
- peerId: this.id,
1663
- sessionId: connection.sessionId
1664
- }, {
1665
- F: __dxlog_file3,
1666
- L: 321,
1667
- S: this,
1668
- C: (f, a) => f(...a)
1669
- });
1670
- await connection.close(err);
1671
- (0, import_log3.log)("closed", {
1672
- peerId: this.id,
1673
- sessionId: connection.sessionId
1674
- }, {
1675
- F: __dxlog_file3,
1676
- L: 327,
1780
+ }
1781
+ async _handleOffer({ author, recipient, message }) {
1782
+ (0, import_invariant3.invariant)(message.data.offer, "No offer", {
1783
+ F: __dxlog_file4,
1784
+ L: 154,
1677
1785
  S: this,
1678
- C: (f, a) => f(...a)
1786
+ A: [
1787
+ "message.data.offer",
1788
+ "'No offer'"
1789
+ ]
1679
1790
  });
1680
- }
1681
- async onSignal(message) {
1682
- if (!this.connection) {
1683
- (0, import_log3.log)("dropping signal message for non-existent connection", {
1684
- message
1791
+ const offerMessage = {
1792
+ author,
1793
+ recipient,
1794
+ ...message,
1795
+ data: {
1796
+ offer: message.data.offer
1797
+ }
1798
+ };
1799
+ const answer = await this._onOffer(offerMessage);
1800
+ answer.offerMessageId = message.messageId;
1801
+ try {
1802
+ await this._sendReliableMessage({
1803
+ author: recipient,
1804
+ recipient: author,
1805
+ message: {
1806
+ topic: message.topic,
1807
+ sessionId: message.sessionId,
1808
+ data: {
1809
+ answer
1810
+ }
1811
+ }
1812
+ });
1813
+ } catch (err) {
1814
+ import_log4.log.warn("error sending answer", {
1815
+ err
1685
1816
  }, {
1686
- F: __dxlog_file3,
1687
- L: 332,
1817
+ F: __dxlog_file4,
1818
+ L: 174,
1688
1819
  S: this,
1689
1820
  C: (f, a) => f(...a)
1690
1821
  });
1691
- return;
1692
1822
  }
1693
- await this.connection.signal(message);
1694
1823
  }
1695
- async destroy() {
1696
- await this._ctx.dispose();
1697
- (0, import_log3.log)("Destroying peer", {
1698
- peerId: this.id,
1699
- topic: this.topic
1700
- }, {
1701
- F: __dxlog_file3,
1702
- L: 342,
1824
+ async _handleSignal({ author, recipient, message }) {
1825
+ (0, import_invariant3.invariant)(message.messageId, void 0, {
1826
+ F: __dxlog_file4,
1827
+ L: 187,
1703
1828
  S: this,
1704
- C: (f, a) => f(...a)
1829
+ A: [
1830
+ "message.messageId",
1831
+ ""
1832
+ ]
1705
1833
  });
1706
- await this?.connection?.close();
1707
- }
1708
- };
1709
- _ts_decorate2([
1710
- import_async2.synchronized
1711
- ], Peer.prototype, "destroy", null);
1712
- var increaseInterval = (interval) => {
1713
- if (interval === 0) {
1714
- return 50;
1715
- } else if (interval < 500) {
1716
- return 500;
1717
- } else if (interval < 1e3) {
1718
- return 1e3;
1719
- } else if (interval < 5e3) {
1720
- return 5e3;
1834
+ (0, import_invariant3.invariant)(message.data.signal || message.data.signalBatch, "Invalid message", {
1835
+ F: __dxlog_file4,
1836
+ L: 188,
1837
+ S: this,
1838
+ A: [
1839
+ "message.data.signal || message.data.signalBatch",
1840
+ "'Invalid message'"
1841
+ ]
1842
+ });
1843
+ const signalMessage = {
1844
+ author,
1845
+ recipient,
1846
+ ...message,
1847
+ data: {
1848
+ signal: message.data.signal,
1849
+ signalBatch: message.data.signalBatch
1850
+ }
1851
+ };
1852
+ await this._onSignal(signalMessage);
1721
1853
  }
1722
- return 1e4;
1723
1854
  };
1724
1855
 
1725
1856
  // packages/core/mesh/network-manager/src/swarm/swarm.ts
@@ -1733,7 +1864,7 @@ function _ts_decorate3(decorators, target, key, desc) {
1733
1864
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1734
1865
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1735
1866
  }
1736
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts";
1867
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts";
1737
1868
  var INITIATION_DELAY = 100;
1738
1869
  var getClassName = (obj) => Object.getPrototypeOf(obj).constructor.name;
1739
1870
  var Swarm = class {
@@ -1751,28 +1882,28 @@ var Swarm = class {
1751
1882
  this._initiationDelay = _initiationDelay;
1752
1883
  this._ctx = new import_context4.Context();
1753
1884
  this._listeningHandle = void 0;
1754
- this._peers = new import_util2.ComplexMap(import_keys4.PublicKey.hash);
1755
- this._instanceId = import_keys4.PublicKey.random().toHex();
1756
- this.connectionAdded = new import_async3.Event();
1757
- this.disconnected = new import_async3.Event();
1758
- this.connected = new import_async3.Event();
1885
+ this._peers = new import_util3.ComplexMap(import_keys5.PublicKey.hash);
1886
+ this._instanceId = import_keys5.PublicKey.random().toHex();
1887
+ this.connectionAdded = new import_async4.Event();
1888
+ this.disconnected = new import_async4.Event();
1889
+ this.connected = new import_async4.Event();
1759
1890
  this.errors = new import_debug2.ErrorStream();
1760
- import_log4.log.trace("dxos.mesh.swarm.constructor", import_protocols3.trace.begin({
1891
+ import_log5.log.trace("dxos.mesh.swarm.constructor", import_protocols4.trace.begin({
1761
1892
  id: this._instanceId,
1762
1893
  data: {
1763
1894
  topic: this._topic.toHex(),
1764
1895
  peerId: this._ownPeerId.toHex()
1765
1896
  }
1766
1897
  }), {
1767
- F: __dxlog_file4,
1898
+ F: __dxlog_file5,
1768
1899
  L: 88,
1769
1900
  S: this,
1770
1901
  C: (f, a) => f(...a)
1771
1902
  });
1772
- (0, import_log4.log)("creating swarm", {
1903
+ (0, import_log5.log)("creating swarm", {
1773
1904
  peerId: _ownPeerId
1774
1905
  }, {
1775
- F: __dxlog_file4,
1906
+ F: __dxlog_file5,
1776
1907
  L: 92,
1777
1908
  S: this,
1778
1909
  C: (f, a) => f(...a)
@@ -1784,17 +1915,17 @@ var Swarm = class {
1784
1915
  onOffer: async (msg) => await this.onOffer(msg),
1785
1916
  topic: this._topic
1786
1917
  });
1787
- import_log4.log.trace("dxos.mesh.swarm.constructor", import_protocols3.trace.end({
1918
+ import_log5.log.trace("dxos.mesh.swarm.constructor", import_protocols4.trace.end({
1788
1919
  id: this._instanceId
1789
1920
  }), {
1790
- F: __dxlog_file4,
1921
+ F: __dxlog_file5,
1791
1922
  L: 101,
1792
1923
  S: this,
1793
1924
  C: (f, a) => f(...a)
1794
1925
  });
1795
1926
  }
1796
1927
  get connections() {
1797
- return Array.from(this._peers.values()).map((peer) => peer.connection).filter(import_util2.isNotNullOrUndefined);
1928
+ return Array.from(this._peers.values()).map((peer) => peer.connection).filter(import_util3.isNotNullOrUndefined);
1798
1929
  }
1799
1930
  get ownPeerId() {
1800
1931
  return this._ownPeerId;
@@ -1810,7 +1941,7 @@ var Swarm = class {
1810
1941
  }
1811
1942
  async open() {
1812
1943
  (0, import_invariant4.invariant)(!this._listeningHandle, void 0, {
1813
- F: __dxlog_file4,
1944
+ F: __dxlog_file5,
1814
1945
  L: 128,
1815
1946
  S: this,
1816
1947
  A: [
@@ -1822,10 +1953,10 @@ var Swarm = class {
1822
1953
  peerId: this._ownPeerId,
1823
1954
  payloadType: "dxos.mesh.swarm.SwarmMessage",
1824
1955
  onMessage: async (message) => {
1825
- await this._swarmMessenger.receiveMessage(message).catch((err) => import_log4.log.warn("Error while receiving message", {
1956
+ await this._swarmMessenger.receiveMessage(message).catch((err) => import_log5.log.warn("Error while receiving message", {
1826
1957
  err
1827
1958
  }, {
1828
- F: __dxlog_file4,
1959
+ F: __dxlog_file5,
1829
1960
  L: 135,
1830
1961
  S: this,
1831
1962
  C: (f, a) => f(...a)
@@ -1834,8 +1965,8 @@ var Swarm = class {
1834
1965
  });
1835
1966
  }
1836
1967
  async destroy() {
1837
- (0, import_log4.log)("destroying...", void 0, {
1838
- F: __dxlog_file4,
1968
+ (0, import_log5.log)("destroying...", void 0, {
1969
+ F: __dxlog_file5,
1839
1970
  L: 141,
1840
1971
  S: this,
1841
1972
  C: (f, a) => f(...a)
@@ -1845,8 +1976,8 @@ var Swarm = class {
1845
1976
  await this._ctx.dispose();
1846
1977
  await this._topology.destroy();
1847
1978
  await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key)));
1848
- (0, import_log4.log)("destroyed", void 0, {
1849
- F: __dxlog_file4,
1979
+ (0, import_log5.log)("destroyed", void 0, {
1980
+ F: __dxlog_file5,
1850
1981
  L: 148,
1851
1982
  S: this,
1852
1983
  C: (f, a) => f(...a)
@@ -1854,7 +1985,7 @@ var Swarm = class {
1854
1985
  }
1855
1986
  async setTopology(topology) {
1856
1987
  (0, import_invariant4.invariant)(!this._ctx.disposed, "Swarm is offline", {
1857
- F: __dxlog_file4,
1988
+ F: __dxlog_file5,
1858
1989
  L: 152,
1859
1990
  S: this,
1860
1991
  A: [
@@ -1865,11 +1996,11 @@ var Swarm = class {
1865
1996
  if (topology === this._topology) {
1866
1997
  return;
1867
1998
  }
1868
- (0, import_log4.log)("setting topology", {
1999
+ (0, import_log5.log)("setting topology", {
1869
2000
  previous: getClassName(this._topology),
1870
2001
  topology: getClassName(topology)
1871
2002
  }, {
1872
- F: __dxlog_file4,
2003
+ F: __dxlog_file5,
1873
2004
  L: 156,
1874
2005
  S: this,
1875
2006
  C: (f, a) => f(...a)
@@ -1880,17 +2011,17 @@ var Swarm = class {
1880
2011
  this._topology.update();
1881
2012
  }
1882
2013
  onSwarmEvent(swarmEvent) {
1883
- (0, import_log4.log)("swarm event", {
2014
+ (0, import_log5.log)("swarm event", {
1884
2015
  swarmEvent
1885
2016
  }, {
1886
- F: __dxlog_file4,
2017
+ F: __dxlog_file5,
1887
2018
  L: 169,
1888
2019
  S: this,
1889
2020
  C: (f, a) => f(...a)
1890
2021
  });
1891
2022
  if (this._ctx.disposed) {
1892
- (0, import_log4.log)("swarm event ignored for disposed swarm", void 0, {
1893
- F: __dxlog_file4,
2023
+ (0, import_log5.log)("swarm event ignored for disposed swarm", void 0, {
2024
+ F: __dxlog_file5,
1894
2025
  L: 172,
1895
2026
  S: this,
1896
2027
  C: (f, a) => f(...a)
@@ -1898,11 +2029,11 @@ var Swarm = class {
1898
2029
  return;
1899
2030
  }
1900
2031
  if (swarmEvent.peerAvailable) {
1901
- const peerId = import_keys4.PublicKey.from(swarmEvent.peerAvailable.peer);
1902
- (0, import_log4.log)("new peer", {
2032
+ const peerId = import_keys5.PublicKey.from(swarmEvent.peerAvailable.peer);
2033
+ (0, import_log5.log)("new peer", {
1903
2034
  peerId
1904
2035
  }, {
1905
- F: __dxlog_file4,
2036
+ F: __dxlog_file5,
1906
2037
  L: 178,
1907
2038
  S: this,
1908
2039
  C: (f, a) => f(...a)
@@ -1912,12 +2043,12 @@ var Swarm = class {
1912
2043
  peer.advertizing = true;
1913
2044
  }
1914
2045
  } else if (swarmEvent.peerLeft) {
1915
- const peer = this._peers.get(import_keys4.PublicKey.from(swarmEvent.peerLeft.peer));
2046
+ const peer = this._peers.get(import_keys5.PublicKey.from(swarmEvent.peerLeft.peer));
1916
2047
  if (peer) {
1917
2048
  peer.advertizing = false;
1918
2049
  if (peer.connection?.state !== ConnectionState.CONNECTED) {
1919
- void this._destroyPeer(peer.id).catch((err) => import_log4.log.catch(err, void 0, {
1920
- F: __dxlog_file4,
2050
+ void this._destroyPeer(peer.id).catch((err) => import_log5.log.catch(err, void 0, {
2051
+ F: __dxlog_file5,
1921
2052
  L: 189,
1922
2053
  S: this,
1923
2054
  C: (f, a) => f(...a)
@@ -1928,17 +2059,17 @@ var Swarm = class {
1928
2059
  this._topology.update();
1929
2060
  }
1930
2061
  async onOffer(message) {
1931
- (0, import_log4.log)("offer", {
2062
+ (0, import_log5.log)("offer", {
1932
2063
  message
1933
2064
  }, {
1934
- F: __dxlog_file4,
2065
+ F: __dxlog_file5,
1935
2066
  L: 199,
1936
2067
  S: this,
1937
2068
  C: (f, a) => f(...a)
1938
2069
  });
1939
2070
  if (this._ctx.disposed) {
1940
- (0, import_log4.log)("ignored for disposed swarm", void 0, {
1941
- F: __dxlog_file4,
2071
+ (0, import_log5.log)("ignored for disposed swarm", void 0, {
2072
+ F: __dxlog_file5,
1942
2073
  L: 201,
1943
2074
  S: this,
1944
2075
  C: (f, a) => f(...a)
@@ -1948,7 +2079,7 @@ var Swarm = class {
1948
2079
  };
1949
2080
  }
1950
2081
  (0, import_invariant4.invariant)(message.author, void 0, {
1951
- F: __dxlog_file4,
2082
+ F: __dxlog_file5,
1952
2083
  L: 206,
1953
2084
  S: this,
1954
2085
  A: [
@@ -1957,10 +2088,10 @@ var Swarm = class {
1957
2088
  ]
1958
2089
  });
1959
2090
  if (!message.recipient?.equals(this._ownPeerId)) {
1960
- (0, import_log4.log)("rejecting offer with incorrect peerId", {
2091
+ (0, import_log5.log)("rejecting offer with incorrect peerId", {
1961
2092
  message
1962
2093
  }, {
1963
- F: __dxlog_file4,
2094
+ F: __dxlog_file5,
1964
2095
  L: 208,
1965
2096
  S: this,
1966
2097
  C: (f, a) => f(...a)
@@ -1970,10 +2101,10 @@ var Swarm = class {
1970
2101
  };
1971
2102
  }
1972
2103
  if (!message.topic?.equals(this._topic)) {
1973
- (0, import_log4.log)("rejecting offer with incorrect topic", {
2104
+ (0, import_log5.log)("rejecting offer with incorrect topic", {
1974
2105
  message
1975
2106
  }, {
1976
- F: __dxlog_file4,
2107
+ F: __dxlog_file5,
1977
2108
  L: 212,
1978
2109
  S: this,
1979
2110
  C: (f, a) => f(...a)
@@ -1988,17 +2119,17 @@ var Swarm = class {
1988
2119
  return answer;
1989
2120
  }
1990
2121
  async onSignal(message) {
1991
- (0, import_log4.log)("signal", {
2122
+ (0, import_log5.log)("signal", {
1992
2123
  message
1993
2124
  }, {
1994
- F: __dxlog_file4,
2125
+ F: __dxlog_file5,
1995
2126
  L: 223,
1996
2127
  S: this,
1997
2128
  C: (f, a) => f(...a)
1998
2129
  });
1999
2130
  if (this._ctx.disposed) {
2000
- import_log4.log.info("ignored for offline swarm", void 0, {
2001
- F: __dxlog_file4,
2131
+ import_log5.log.info("ignored for offline swarm", void 0, {
2132
+ F: __dxlog_file5,
2002
2133
  L: 225,
2003
2134
  S: this,
2004
2135
  C: (f, a) => f(...a)
@@ -2006,7 +2137,7 @@ var Swarm = class {
2006
2137
  return;
2007
2138
  }
2008
2139
  (0, import_invariant4.invariant)(message.recipient?.equals(this._ownPeerId), `Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`, {
2009
- F: __dxlog_file4,
2140
+ F: __dxlog_file5,
2010
2141
  L: 228,
2011
2142
  S: this,
2012
2143
  A: [
@@ -2015,7 +2146,7 @@ var Swarm = class {
2015
2146
  ]
2016
2147
  });
2017
2148
  (0, import_invariant4.invariant)(message.topic?.equals(this._topic), void 0, {
2018
- F: __dxlog_file4,
2149
+ F: __dxlog_file5,
2019
2150
  L: 232,
2020
2151
  S: this,
2021
2152
  A: [
@@ -2024,7 +2155,7 @@ var Swarm = class {
2024
2155
  ]
2025
2156
  });
2026
2157
  (0, import_invariant4.invariant)(message.author, void 0, {
2027
- F: __dxlog_file4,
2158
+ F: __dxlog_file5,
2028
2159
  L: 233,
2029
2160
  S: this,
2030
2161
  A: [
@@ -2084,7 +2215,7 @@ var Swarm = class {
2084
2215
  }
2085
2216
  async _destroyPeer(peerId) {
2086
2217
  (0, import_invariant4.invariant)(this._peers.has(peerId), void 0, {
2087
- F: __dxlog_file4,
2218
+ F: __dxlog_file5,
2088
2219
  L: 303,
2089
2220
  S: this,
2090
2221
  A: [
@@ -2106,12 +2237,12 @@ var Swarm = class {
2106
2237
  if (this._ctx.disposed) {
2107
2238
  return;
2108
2239
  }
2109
- (0, import_async3.scheduleTask)(this._ctx, async () => {
2240
+ (0, import_async4.scheduleTask)(this._ctx, async () => {
2110
2241
  try {
2111
2242
  await this._initiateConnection(peer);
2112
2243
  } catch (err) {
2113
- (0, import_log4.log)("initiation error", err, {
2114
- F: __dxlog_file4,
2244
+ (0, import_log5.log)("initiation error", err, {
2245
+ F: __dxlog_file5,
2115
2246
  L: 329,
2116
2247
  S: this,
2117
2248
  C: (f, a) => f(...a)
@@ -2123,7 +2254,7 @@ var Swarm = class {
2123
2254
  if (this._ctx.disposed) {
2124
2255
  return;
2125
2256
  }
2126
- (0, import_async3.scheduleTask)(this._ctx, async () => {
2257
+ (0, import_async4.scheduleTask)(this._ctx, async () => {
2127
2258
  await this._closeConnection(peer);
2128
2259
  this._topology.update();
2129
2260
  });
@@ -2136,15 +2267,15 @@ var Swarm = class {
2136
2267
  async _initiateConnection(remoteId) {
2137
2268
  const ctx = this._ctx;
2138
2269
  if (remoteId.toHex() < this._ownPeerId.toHex()) {
2139
- (0, import_log4.log)("initiation delay", {
2270
+ (0, import_log5.log)("initiation delay", {
2140
2271
  remoteId
2141
2272
  }, {
2142
- F: __dxlog_file4,
2273
+ F: __dxlog_file5,
2143
2274
  L: 356,
2144
2275
  S: this,
2145
2276
  C: (f, a) => f(...a)
2146
2277
  });
2147
- await (0, import_async3.sleep)(this._initiationDelay);
2278
+ await (0, import_async4.sleep)(this._initiationDelay);
2148
2279
  }
2149
2280
  if (ctx.disposed) {
2150
2281
  return;
@@ -2153,20 +2284,20 @@ var Swarm = class {
2153
2284
  if (peer.connection) {
2154
2285
  return;
2155
2286
  }
2156
- (0, import_log4.log)("initiating connection...", {
2287
+ (0, import_log5.log)("initiating connection...", {
2157
2288
  remoteId
2158
2289
  }, {
2159
- F: __dxlog_file4,
2290
+ F: __dxlog_file5,
2160
2291
  L: 370,
2161
2292
  S: this,
2162
2293
  C: (f, a) => f(...a)
2163
2294
  });
2164
2295
  await peer.initiateConnection();
2165
2296
  this._topology.update();
2166
- (0, import_log4.log)("initiated", {
2297
+ (0, import_log5.log)("initiated", {
2167
2298
  remoteId
2168
2299
  }, {
2169
- F: __dxlog_file4,
2300
+ F: __dxlog_file5,
2170
2301
  L: 373,
2171
2302
  S: this,
2172
2303
  C: (f, a) => f(...a)
@@ -2181,44 +2312,43 @@ var Swarm = class {
2181
2312
  }
2182
2313
  };
2183
2314
  _ts_decorate3([
2184
- import_log4.logInfo
2315
+ import_log5.logInfo
2185
2316
  ], Swarm.prototype, "_instanceId", void 0);
2186
2317
  _ts_decorate3([
2187
- import_log4.logInfo
2318
+ import_log5.logInfo
2188
2319
  ], Swarm.prototype, "ownPeerId", null);
2189
2320
  _ts_decorate3([
2190
- import_log4.logInfo
2321
+ import_log5.logInfo
2191
2322
  ], Swarm.prototype, "topic", null);
2192
2323
  _ts_decorate3([
2193
- import_async3.synchronized
2324
+ import_async4.synchronized
2194
2325
  ], Swarm.prototype, "onSwarmEvent", null);
2195
2326
  _ts_decorate3([
2196
- import_async3.synchronized
2327
+ import_async4.synchronized
2197
2328
  ], Swarm.prototype, "onOffer", null);
2198
2329
  _ts_decorate3([
2199
- import_async3.synchronized
2330
+ import_async4.synchronized
2200
2331
  ], Swarm.prototype, "goOffline", null);
2201
2332
  _ts_decorate3([
2202
- import_async3.synchronized
2333
+ import_async4.synchronized
2203
2334
  ], Swarm.prototype, "goOnline", null);
2204
2335
 
2205
2336
  // packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts
2206
- var import_async4 = require("@dxos/async");
2207
- var import_keys5 = require("@dxos/keys");
2208
- var import_log5 = require("@dxos/log");
2209
- var import_util3 = require("@dxos/util");
2210
- var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
2337
+ var import_async5 = require("@dxos/async");
2338
+ var import_keys6 = require("@dxos/keys");
2339
+ var import_log6 = require("@dxos/log");
2340
+ var import_util4 = require("@dxos/util");
2341
+ var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
2211
2342
  var SwarmMapper = class {
2212
2343
  get peers() {
2213
2344
  return Array.from(this._peers.values());
2214
2345
  }
2215
- // prettier-ignore
2216
2346
  constructor(_swarm) {
2217
2347
  this._swarm = _swarm;
2218
- this._subscriptions = new import_async4.EventSubscriptions();
2219
- this._connectionSubscriptions = new import_util3.ComplexMap(import_keys5.PublicKey.hash);
2220
- this._peers = new import_util3.ComplexMap(import_keys5.PublicKey.hash);
2221
- this.mapUpdated = new import_async4.Event();
2348
+ this._subscriptions = new import_async5.EventSubscriptions();
2349
+ this._connectionSubscriptions = new import_util4.ComplexMap(import_keys6.PublicKey.hash);
2350
+ this._peers = new import_util4.ComplexMap(import_keys6.PublicKey.hash);
2351
+ this.mapUpdated = new import_async5.Event();
2222
2352
  this._subscriptions.add(_swarm.connectionAdded.on((connection) => {
2223
2353
  this._update();
2224
2354
  this._connectionSubscriptions.set(connection.remoteId, connection.stateChanged.on(() => {
@@ -2233,9 +2363,9 @@ var SwarmMapper = class {
2233
2363
  this._update();
2234
2364
  }
2235
2365
  _update() {
2236
- (0, import_log5.log)("updating swarm", void 0, {
2237
- F: __dxlog_file5,
2238
- L: 75,
2366
+ (0, import_log6.log)("updating swarm", void 0, {
2367
+ F: __dxlog_file6,
2368
+ L: 72,
2239
2369
  S: this,
2240
2370
  C: (f, a) => f(...a)
2241
2371
  });
@@ -2254,12 +2384,12 @@ var SwarmMapper = class {
2254
2384
  ]
2255
2385
  });
2256
2386
  }
2257
- (0, import_log5.log)("graph changed", {
2387
+ (0, import_log6.log)("graph changed", {
2258
2388
  directConnections: this._swarm.connections.length,
2259
2389
  totalPeersInSwarm: this._peers.size
2260
2390
  }, {
2261
- F: __dxlog_file5,
2262
- L: 116,
2391
+ F: __dxlog_file6,
2392
+ L: 113,
2263
2393
  S: this,
2264
2394
  C: (f, a) => f(...a)
2265
2395
  });
@@ -2273,23 +2403,23 @@ var SwarmMapper = class {
2273
2403
  };
2274
2404
 
2275
2405
  // packages/core/mesh/network-manager/src/swarm/connection-limiter.ts
2276
- var import_async5 = require("@dxos/async");
2406
+ var import_async6 = require("@dxos/async");
2277
2407
  var import_context5 = require("@dxos/context");
2278
- var import_errors3 = require("@dxos/errors");
2279
2408
  var import_invariant5 = require("@dxos/invariant");
2280
- var import_keys6 = require("@dxos/keys");
2281
- var import_log6 = require("@dxos/log");
2282
- var import_util4 = require("@dxos/util");
2283
- var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
2284
- var MAX_CONCURRENT_INITIATING_CONNECTIONS = 10;
2409
+ var import_keys7 = require("@dxos/keys");
2410
+ var import_log7 = require("@dxos/log");
2411
+ var import_protocols5 = require("@dxos/protocols");
2412
+ var import_util5 = require("@dxos/util");
2413
+ var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
2414
+ var MAX_CONCURRENT_INITIATING_CONNECTIONS = 50;
2285
2415
  var ConnectionLimiter = class {
2286
2416
  constructor({ maxConcurrentInitConnections = MAX_CONCURRENT_INITIATING_CONNECTIONS } = {}) {
2287
2417
  this._ctx = new import_context5.Context();
2288
2418
  /**
2289
2419
  * Queue of promises to resolve when initiating connections amount is below the limit.
2290
2420
  */
2291
- this._waitingPromises = new import_util4.ComplexMap(import_keys6.PublicKey.hash);
2292
- this.resolveWaitingPromises = new import_async5.DeferredTask(this._ctx, async () => {
2421
+ this._waitingPromises = new import_util5.ComplexMap(import_keys7.PublicKey.hash);
2422
+ this.resolveWaitingPromises = new import_async6.DeferredTask(this._ctx, async () => {
2293
2423
  Array.from(this._waitingPromises.values()).slice(0, this._maxConcurrentInitConnections).forEach(({ resolve }) => {
2294
2424
  resolve();
2295
2425
  });
@@ -2301,7 +2431,7 @@ var ConnectionLimiter = class {
2301
2431
  */
2302
2432
  async connecting(sessionId) {
2303
2433
  (0, import_invariant5.invariant)(!this._waitingPromises.has(sessionId), "Peer is already waiting for connection", {
2304
- F: __dxlog_file6,
2434
+ F: __dxlog_file7,
2305
2435
  L: 48,
2306
2436
  S: this,
2307
2437
  A: [
@@ -2309,10 +2439,10 @@ var ConnectionLimiter = class {
2309
2439
  "'Peer is already waiting for connection'"
2310
2440
  ]
2311
2441
  });
2312
- (0, import_log6.log)("waiting", {
2442
+ (0, import_log7.log)("waiting", {
2313
2443
  sessionId
2314
2444
  }, {
2315
- F: __dxlog_file6,
2445
+ F: __dxlog_file7,
2316
2446
  L: 49,
2317
2447
  S: this,
2318
2448
  C: (f, a) => f(...a)
@@ -2324,10 +2454,10 @@ var ConnectionLimiter = class {
2324
2454
  });
2325
2455
  this.resolveWaitingPromises.schedule();
2326
2456
  });
2327
- (0, import_log6.log)("allow", {
2457
+ (0, import_log7.log)("allow", {
2328
2458
  sessionId
2329
2459
  }, {
2330
- F: __dxlog_file6,
2460
+ F: __dxlog_file7,
2331
2461
  L: 57,
2332
2462
  S: this,
2333
2463
  C: (f, a) => f(...a)
@@ -2337,10 +2467,10 @@ var ConnectionLimiter = class {
2337
2467
  * Rejects promise returned by `connecting` method.
2338
2468
  */
2339
2469
  doneConnecting(sessionId) {
2340
- (0, import_log6.log)("done", {
2470
+ (0, import_log7.log)("done", {
2341
2471
  sessionId
2342
2472
  }, {
2343
- F: __dxlog_file6,
2473
+ F: __dxlog_file7,
2344
2474
  L: 64,
2345
2475
  S: this,
2346
2476
  C: (f, a) => f(...a)
@@ -2348,7 +2478,7 @@ var ConnectionLimiter = class {
2348
2478
  if (!this._waitingPromises.has(sessionId)) {
2349
2479
  return;
2350
2480
  }
2351
- this._waitingPromises.get(sessionId).reject(new import_errors3.CancelledError());
2481
+ this._waitingPromises.get(sessionId).reject(new import_protocols5.CancelledError());
2352
2482
  this._waitingPromises.delete(sessionId);
2353
2483
  this.resolveWaitingPromises.schedule();
2354
2484
  }
@@ -2368,8 +2498,8 @@ var ConnectionLog = class {
2368
2498
  /**
2369
2499
  * SwarmId => info
2370
2500
  */
2371
- this._swarms = new import_util5.ComplexMap(import_keys7.PublicKey.hash);
2372
- this.update = new import_async6.Event();
2501
+ this._swarms = new import_util6.ComplexMap(import_keys8.PublicKey.hash);
2502
+ this.update = new import_async7.Event();
2373
2503
  }
2374
2504
  getSwarmInfo(swarmId) {
2375
2505
  return this._swarms.get(swarmId) ?? (0, import_debug3.raise)(new Error(`Swarm not found: ${swarmId}`));
@@ -2379,13 +2509,13 @@ var ConnectionLog = class {
2379
2509
  }
2380
2510
  joinedSwarm(swarm) {
2381
2511
  const info = {
2382
- id: import_keys7.PublicKey.from(swarm._instanceId),
2512
+ id: import_keys8.PublicKey.from(swarm._instanceId),
2383
2513
  topic: swarm.topic,
2384
2514
  isActive: true,
2385
2515
  label: swarm.label,
2386
2516
  connections: []
2387
2517
  };
2388
- this._swarms.set(import_keys7.PublicKey.from(swarm._instanceId), info);
2518
+ this._swarms.set(import_keys8.PublicKey.from(swarm._instanceId), info);
2389
2519
  this.update.emit();
2390
2520
  swarm.connectionAdded.on((connection) => {
2391
2521
  const connectionInfo = {
@@ -2415,24 +2545,24 @@ var ConnectionLog = class {
2415
2545
  });
2416
2546
  }
2417
2547
  leftSwarm(swarm) {
2418
- this.getSwarmInfo(import_keys7.PublicKey.from(swarm._instanceId)).isActive = false;
2548
+ this.getSwarmInfo(import_keys8.PublicKey.from(swarm._instanceId)).isActive = false;
2419
2549
  this.update.emit();
2420
2550
  }
2421
2551
  };
2422
2552
 
2423
2553
  // 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";
2554
+ var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts";
2425
2555
  var NetworkManager = class {
2426
2556
  constructor({ transportFactory, signalManager, log: log1 }) {
2427
2557
  /**
2428
2558
  * @internal
2429
2559
  */
2430
- this._swarms = new import_util6.ComplexMap(import_keys8.PublicKey.hash);
2431
- this._mappers = new import_util6.ComplexMap(import_keys8.PublicKey.hash);
2560
+ this._swarms = new import_util7.ComplexMap(import_keys9.PublicKey.hash);
2561
+ this._mappers = new import_util7.ComplexMap(import_keys9.PublicKey.hash);
2432
2562
  this._connectionState = import_services.ConnectionState.ONLINE;
2433
- this.connectionStateChanged = new import_async7.Event();
2434
- this.topicsUpdated = new import_async7.Event();
2435
- this._instanceId = import_keys8.PublicKey.random().toHex();
2563
+ this.connectionStateChanged = new import_async8.Event();
2564
+ this.topicsUpdated = new import_async8.Event();
2565
+ this._instanceId = import_keys9.PublicKey.random().toHex();
2436
2566
  this._transportFactory = transportFactory;
2437
2567
  this._signalManager = signalManager;
2438
2568
  this._signalManager.swarmEvent.on(({ topic, swarmEvent: event }) => this._swarms.get(topic)?.onSwarmEvent(event));
@@ -2466,20 +2596,20 @@ var NetworkManager = class {
2466
2596
  return this._swarms.get(topic);
2467
2597
  }
2468
2598
  async open() {
2469
- import_log7.log.trace("dxos.mesh.network-manager.open", import_protocols4.trace.begin({
2599
+ import_log8.log.trace("dxos.mesh.network-manager.open", import_protocols6.trace.begin({
2470
2600
  id: this._instanceId
2471
2601
  }), {
2472
- F: __dxlog_file7,
2602
+ F: __dxlog_file8,
2473
2603
  L: 130,
2474
2604
  S: this,
2475
2605
  C: (f, a) => f(...a)
2476
2606
  });
2477
2607
  await this._messenger.open();
2478
2608
  await this._signalManager.open();
2479
- import_log7.log.trace("dxos.mesh.network-manager.open", import_protocols4.trace.end({
2609
+ import_log8.log.trace("dxos.mesh.network-manager.open", import_protocols6.trace.end({
2480
2610
  id: this._instanceId
2481
2611
  }), {
2482
- F: __dxlog_file7,
2612
+ F: __dxlog_file8,
2483
2613
  L: 133,
2484
2614
  S: this,
2485
2615
  C: (f, a) => f(...a)
@@ -2488,8 +2618,8 @@ var NetworkManager = class {
2488
2618
  async close() {
2489
2619
  for (const topic of this._swarms.keys()) {
2490
2620
  await this.leaveSwarm(topic).catch((err) => {
2491
- (0, import_log7.log)(err, void 0, {
2492
- F: __dxlog_file7,
2621
+ (0, import_log8.log)(err, void 0, {
2622
+ F: __dxlog_file8,
2493
2623
  L: 139,
2494
2624
  S: this,
2495
2625
  C: (f, a) => f(...a)
@@ -2503,8 +2633,8 @@ var NetworkManager = class {
2503
2633
  * Join the swarm.
2504
2634
  */
2505
2635
  async joinSwarm({ topic, peerId, topology, protocolProvider: protocol, label }) {
2506
- (0, import_invariant6.invariant)(import_keys8.PublicKey.isPublicKey(topic), void 0, {
2507
- F: __dxlog_file7,
2636
+ (0, import_invariant6.invariant)(import_keys9.PublicKey.isPublicKey(topic), void 0, {
2637
+ F: __dxlog_file8,
2508
2638
  L: 157,
2509
2639
  S: this,
2510
2640
  A: [
@@ -2512,8 +2642,8 @@ var NetworkManager = class {
2512
2642
  ""
2513
2643
  ]
2514
2644
  });
2515
- (0, import_invariant6.invariant)(import_keys8.PublicKey.isPublicKey(peerId), void 0, {
2516
- F: __dxlog_file7,
2645
+ (0, import_invariant6.invariant)(import_keys9.PublicKey.isPublicKey(peerId), void 0, {
2646
+ F: __dxlog_file8,
2517
2647
  L: 158,
2518
2648
  S: this,
2519
2649
  A: [
@@ -2522,7 +2652,7 @@ var NetworkManager = class {
2522
2652
  ]
2523
2653
  });
2524
2654
  (0, import_invariant6.invariant)(topology, void 0, {
2525
- F: __dxlog_file7,
2655
+ F: __dxlog_file8,
2526
2656
  L: 159,
2527
2657
  S: this,
2528
2658
  A: [
@@ -2531,7 +2661,7 @@ var NetworkManager = class {
2531
2661
  ]
2532
2662
  });
2533
2663
  (0, import_invariant6.invariant)(typeof protocol === "function", void 0, {
2534
- F: __dxlog_file7,
2664
+ F: __dxlog_file8,
2535
2665
  L: 160,
2536
2666
  S: this,
2537
2667
  A: [
@@ -2540,24 +2670,24 @@ var NetworkManager = class {
2540
2670
  ]
2541
2671
  });
2542
2672
  if (this._swarms.has(topic)) {
2543
- throw new Error(`Already connected to swarm: ${import_keys8.PublicKey.from(topic)}`);
2673
+ throw new Error(`Already connected to swarm: ${import_keys9.PublicKey.from(topic)}`);
2544
2674
  }
2545
- (0, import_log7.log)("joining", {
2546
- topic: import_keys8.PublicKey.from(topic),
2675
+ (0, import_log8.log)("joining", {
2676
+ topic: import_keys9.PublicKey.from(topic),
2547
2677
  peerId,
2548
2678
  topology: topology.toString()
2549
2679
  }, {
2550
- F: __dxlog_file7,
2680
+ F: __dxlog_file8,
2551
2681
  L: 165,
2552
2682
  S: this,
2553
2683
  C: (f, a) => f(...a)
2554
2684
  });
2555
2685
  const swarm = new Swarm(topic, peerId, topology, protocol, this._messenger, this._transportFactory, label, this._connectionLimiter);
2556
2686
  swarm.errors.handle((error) => {
2557
- (0, import_log7.log)("swarm error", {
2687
+ (0, import_log8.log)("swarm error", {
2558
2688
  error
2559
2689
  }, {
2560
- F: __dxlog_file7,
2690
+ F: __dxlog_file8,
2561
2691
  L: 178,
2562
2692
  S: this,
2563
2693
  C: (f, a) => f(...a)
@@ -2569,19 +2699,19 @@ var NetworkManager = class {
2569
2699
  this._signalConnection.join({
2570
2700
  topic,
2571
2701
  peerId
2572
- }).catch((error) => import_log7.log.catch(error, void 0, {
2573
- F: __dxlog_file7,
2702
+ }).catch((error) => import_log8.log.catch(error, void 0, {
2703
+ F: __dxlog_file8,
2574
2704
  L: 187,
2575
2705
  S: this,
2576
2706
  C: (f, a) => f(...a)
2577
2707
  }));
2578
2708
  this.topicsUpdated.emit();
2579
2709
  this._connectionLog?.joinedSwarm(swarm);
2580
- (0, import_log7.log)("joined", {
2581
- topic: import_keys8.PublicKey.from(topic),
2710
+ (0, import_log8.log)("joined", {
2711
+ topic: import_keys9.PublicKey.from(topic),
2582
2712
  count: this._swarms.size
2583
2713
  }, {
2584
- F: __dxlog_file7,
2714
+ F: __dxlog_file8,
2585
2715
  L: 191,
2586
2716
  S: this,
2587
2717
  C: (f, a) => f(...a)
@@ -2597,10 +2727,10 @@ var NetworkManager = class {
2597
2727
  if (!this._swarms.has(topic)) {
2598
2728
  return;
2599
2729
  }
2600
- (0, import_log7.log)("leaving", {
2601
- topic: import_keys8.PublicKey.from(topic)
2730
+ (0, import_log8.log)("leaving", {
2731
+ topic: import_keys9.PublicKey.from(topic)
2602
2732
  }, {
2603
- F: __dxlog_file7,
2733
+ F: __dxlog_file8,
2604
2734
  L: 207,
2605
2735
  S: this,
2606
2736
  C: (f, a) => f(...a)
@@ -2617,11 +2747,11 @@ var NetworkManager = class {
2617
2747
  await swarm.destroy();
2618
2748
  this._swarms.delete(topic);
2619
2749
  await this.topicsUpdated.emit();
2620
- (0, import_log7.log)("left", {
2621
- topic: import_keys8.PublicKey.from(topic),
2750
+ (0, import_log8.log)("left", {
2751
+ topic: import_keys9.PublicKey.from(topic),
2622
2752
  count: this._swarms.size
2623
2753
  }, {
2624
- F: __dxlog_file7,
2754
+ F: __dxlog_file8,
2625
2755
  L: 221,
2626
2756
  S: this,
2627
2757
  C: (f, a) => f(...a)
@@ -2657,14 +2787,14 @@ var NetworkManager = class {
2657
2787
 
2658
2788
  // packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts
2659
2789
  var import_invariant7 = require("@dxos/invariant");
2660
- var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
2790
+ var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
2661
2791
  var FullyConnectedTopology = class {
2662
2792
  toString() {
2663
2793
  return "FullyConnectedTopology";
2664
2794
  }
2665
2795
  init(controller) {
2666
2796
  (0, import_invariant7.invariant)(!this._controller, "Already initialized", {
2667
- F: __dxlog_file8,
2797
+ F: __dxlog_file9,
2668
2798
  L: 18,
2669
2799
  S: this,
2670
2800
  A: [
@@ -2676,7 +2806,7 @@ var FullyConnectedTopology = class {
2676
2806
  }
2677
2807
  update() {
2678
2808
  (0, import_invariant7.invariant)(this._controller, "Not initialized", {
2679
- F: __dxlog_file8,
2809
+ F: __dxlog_file9,
2680
2810
  L: 23,
2681
2811
  S: this,
2682
2812
  A: [
@@ -2699,20 +2829,20 @@ var FullyConnectedTopology = class {
2699
2829
  // packages/core/mesh/network-manager/src/topology/mmst-topology.ts
2700
2830
  var import_xor_distance = __toESM(require("xor-distance"));
2701
2831
  var import_invariant8 = require("@dxos/invariant");
2702
- var import_log8 = require("@dxos/log");
2832
+ var import_log9 = require("@dxos/log");
2703
2833
 
2704
2834
  // packages/core/mesh/network-manager/src/topology/star-topology.ts
2705
2835
  var import_invariant9 = require("@dxos/invariant");
2706
- var import_log9 = require("@dxos/log");
2836
+ var import_log10 = require("@dxos/log");
2707
2837
 
2708
2838
  // packages/core/mesh/network-manager/src/transport/memory-transport.ts
2709
2839
  var import_node_stream = require("node:stream");
2710
- var import_async8 = require("@dxos/async");
2840
+ var import_async9 = require("@dxos/async");
2711
2841
  var import_debug4 = require("@dxos/debug");
2712
2842
  var import_invariant10 = require("@dxos/invariant");
2713
- var import_keys9 = require("@dxos/keys");
2714
- var import_log10 = require("@dxos/log");
2715
- var import_util7 = require("@dxos/util");
2843
+ var import_keys10 = require("@dxos/keys");
2844
+ var import_log11 = require("@dxos/log");
2845
+ var import_util8 = require("@dxos/util");
2716
2846
  function _ts_decorate4(decorators, target, key, desc) {
2717
2847
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2718
2848
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -2723,7 +2853,7 @@ function _ts_decorate4(decorators, target, key, desc) {
2723
2853
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2724
2854
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2725
2855
  }
2726
- var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
2856
+ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
2727
2857
  var MEMORY_TRANSPORT_DELAY = 1;
2728
2858
  var createStreamDelay = (delay) => {
2729
2859
  return new import_node_stream.Transform({
@@ -2739,26 +2869,26 @@ var MemoryTransportFactory = {
2739
2869
  var MemoryTransport = class _MemoryTransport {
2740
2870
  static {
2741
2871
  // TODO(burdon): Remove static properties (inject context into constructor).
2742
- this._connections = new import_util7.ComplexMap(import_keys9.PublicKey.hash);
2872
+ this._connections = new import_util8.ComplexMap(import_keys10.PublicKey.hash);
2743
2873
  }
2744
2874
  constructor(options) {
2745
2875
  this.options = options;
2746
- this.closed = new import_async8.Event();
2747
- this.connected = new import_async8.Event();
2876
+ this.closed = new import_async9.Event();
2877
+ this.connected = new import_async9.Event();
2748
2878
  this.errors = new import_debug4.ErrorStream();
2749
- this._instanceId = import_keys9.PublicKey.random();
2750
- this._remote = new import_async8.Trigger();
2879
+ this._instanceId = import_keys10.PublicKey.random();
2880
+ this._remote = new import_async9.Trigger();
2751
2881
  this._outgoingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
2752
2882
  this._incomingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
2753
2883
  this._destroyed = false;
2754
- (0, import_log10.log)("creating", void 0, {
2755
- F: __dxlog_file9,
2884
+ (0, import_log11.log)("creating", void 0, {
2885
+ F: __dxlog_file10,
2756
2886
  L: 64,
2757
2887
  S: this,
2758
2888
  C: (f, a) => f(...a)
2759
2889
  });
2760
2890
  (0, import_invariant10.invariant)(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection", {
2761
- F: __dxlog_file9,
2891
+ F: __dxlog_file10,
2762
2892
  L: 66,
2763
2893
  S: this,
2764
2894
  A: [
@@ -2769,8 +2899,8 @@ var MemoryTransport = class _MemoryTransport {
2769
2899
  _MemoryTransport._connections.set(this._instanceId, this);
2770
2900
  if (this.options.initiator) {
2771
2901
  setTimeout(async () => {
2772
- (0, import_log10.log)("sending signal", void 0, {
2773
- F: __dxlog_file9,
2902
+ (0, import_log11.log)("sending signal", void 0, {
2903
+ F: __dxlog_file10,
2774
2904
  L: 73,
2775
2905
  S: this,
2776
2906
  C: (f, a) => f(...a)
@@ -2800,7 +2930,7 @@ var MemoryTransport = class _MemoryTransport {
2800
2930
  return;
2801
2931
  }
2802
2932
  (0, import_invariant10.invariant)(!this._remoteConnection._remoteConnection, `Remote already connected: ${this._remoteInstanceId}`, {
2803
- F: __dxlog_file9,
2933
+ F: __dxlog_file10,
2804
2934
  L: 99,
2805
2935
  S: this,
2806
2936
  A: [
@@ -2810,8 +2940,8 @@ var MemoryTransport = class _MemoryTransport {
2810
2940
  });
2811
2941
  this._remoteConnection._remoteConnection = this;
2812
2942
  this._remoteConnection._remoteInstanceId = this._instanceId;
2813
- (0, import_log10.log)("connected", void 0, {
2814
- F: __dxlog_file9,
2943
+ (0, import_log11.log)("connected", void 0, {
2944
+ F: __dxlog_file10,
2815
2945
  L: 103,
2816
2946
  S: this,
2817
2947
  C: (f, a) => f(...a)
@@ -2828,8 +2958,8 @@ var MemoryTransport = class _MemoryTransport {
2828
2958
  }
2829
2959
  }
2830
2960
  async destroy() {
2831
- (0, import_log10.log)("closing", void 0, {
2832
- F: __dxlog_file9,
2961
+ (0, import_log11.log)("closing", void 0, {
2962
+ F: __dxlog_file10,
2833
2963
  L: 124,
2834
2964
  S: this,
2835
2965
  C: (f, a) => f(...a)
@@ -2837,8 +2967,8 @@ var MemoryTransport = class _MemoryTransport {
2837
2967
  this._destroyed = true;
2838
2968
  _MemoryTransport._connections.delete(this._instanceId);
2839
2969
  if (this._remoteConnection) {
2840
- (0, import_log10.log)("closing", void 0, {
2841
- F: __dxlog_file9,
2970
+ (0, import_log11.log)("closing", void 0, {
2971
+ F: __dxlog_file10,
2842
2972
  L: 129,
2843
2973
  S: this,
2844
2974
  C: (f, a) => f(...a)
@@ -2850,26 +2980,26 @@ var MemoryTransport = class _MemoryTransport {
2850
2980
  this._remoteConnection.closed.emit();
2851
2981
  this._remoteConnection._remoteConnection = void 0;
2852
2982
  this._remoteConnection = void 0;
2853
- (0, import_log10.log)("closed", void 0, {
2854
- F: __dxlog_file9,
2983
+ (0, import_log11.log)("closed", void 0, {
2984
+ F: __dxlog_file10,
2855
2985
  L: 147,
2856
2986
  S: this,
2857
2987
  C: (f, a) => f(...a)
2858
2988
  });
2859
2989
  }
2860
2990
  this.closed.emit();
2861
- (0, import_log10.log)("closed", void 0, {
2862
- F: __dxlog_file9,
2991
+ (0, import_log11.log)("closed", void 0, {
2992
+ F: __dxlog_file10,
2863
2993
  L: 151,
2864
2994
  S: this,
2865
2995
  C: (f, a) => f(...a)
2866
2996
  });
2867
2997
  }
2868
2998
  signal({ payload }) {
2869
- (0, import_log10.log)("received signal", {
2999
+ (0, import_log11.log)("received signal", {
2870
3000
  payload
2871
3001
  }, {
2872
- F: __dxlog_file9,
3002
+ F: __dxlog_file10,
2873
3003
  L: 155,
2874
3004
  S: this,
2875
3005
  C: (f, a) => f(...a)
@@ -2879,16 +3009,16 @@ var MemoryTransport = class _MemoryTransport {
2879
3009
  }
2880
3010
  const transportId = payload.transportId;
2881
3011
  if (transportId) {
2882
- const remoteId = import_keys9.PublicKey.fromHex(transportId);
3012
+ const remoteId = import_keys10.PublicKey.fromHex(transportId);
2883
3013
  this._remote.wake(remoteId);
2884
3014
  }
2885
3015
  }
2886
3016
  };
2887
3017
  _ts_decorate4([
2888
- import_log10.logInfo
3018
+ import_log11.logInfo
2889
3019
  ], MemoryTransport.prototype, "_instanceId", void 0);
2890
3020
  _ts_decorate4([
2891
- import_log10.logInfo
3021
+ import_log11.logInfo
2892
3022
  ], MemoryTransport.prototype, "_remoteInstanceId", void 0);
2893
3023
 
2894
3024
  // packages/core/mesh/network-manager/src/transport/transport.ts
@@ -2904,12 +3034,11 @@ var TransportKind;
2904
3034
  // packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts
2905
3035
  var import_simple_peer = __toESM(require("simple-peer"));
2906
3036
  var import_tiny_invariant = __toESM(require("tiny-invariant"));
2907
- var import_async9 = require("@dxos/async");
3037
+ var import_async10 = require("@dxos/async");
2908
3038
  var import_debug5 = require("@dxos/debug");
2909
- var import_errors4 = require("@dxos/errors");
2910
- var import_keys10 = require("@dxos/keys");
2911
- var import_log11 = require("@dxos/log");
2912
- var import_protocols5 = require("@dxos/protocols");
3039
+ var import_keys11 = require("@dxos/keys");
3040
+ var import_log12 = require("@dxos/log");
3041
+ var import_protocols7 = require("@dxos/protocols");
2913
3042
 
2914
3043
  // packages/core/mesh/network-manager/src/transport/webrtc.ts
2915
3044
  var wrtc = null;
@@ -2919,26 +3048,26 @@ try {
2919
3048
  }
2920
3049
 
2921
3050
  // packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts
2922
- var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts";
3051
+ var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts";
2923
3052
  var SimplePeerTransport = class {
2924
3053
  constructor(params) {
2925
3054
  this.params = params;
2926
3055
  this._closed = false;
2927
- this.closed = new import_async9.Event();
2928
- this.connected = new import_async9.Event();
3056
+ this.closed = new import_async10.Event();
3057
+ this.connected = new import_async10.Event();
2929
3058
  this.errors = new import_debug5.ErrorStream();
2930
- this._instanceId = import_keys10.PublicKey.random().toHex();
2931
- import_log11.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols5.trace.begin({
3059
+ this._instanceId = import_keys11.PublicKey.random().toHex();
3060
+ import_log12.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols7.trace.begin({
2932
3061
  id: this._instanceId
2933
3062
  }), {
2934
- F: __dxlog_file10,
2935
- L: 41,
3063
+ F: __dxlog_file11,
3064
+ L: 40,
2936
3065
  S: this,
2937
3066
  C: (f, a) => f(...a)
2938
3067
  });
2939
- (0, import_log11.log)("created connection", params, {
2940
- F: __dxlog_file10,
2941
- L: 42,
3068
+ (0, import_log12.log)("created connection", params, {
3069
+ F: __dxlog_file11,
3070
+ L: 41,
2942
3071
  S: this,
2943
3072
  C: (f, a) => f(...a)
2944
3073
  });
@@ -2949,9 +3078,9 @@ var SimplePeerTransport = class {
2949
3078
  config: this.params.webrtcConfig
2950
3079
  });
2951
3080
  this._peer.on("signal", async (data) => {
2952
- (0, import_log11.log)("signal", data, {
2953
- F: __dxlog_file10,
2954
- L: 51,
3081
+ (0, import_log12.log)("signal", data, {
3082
+ F: __dxlog_file11,
3083
+ L: 50,
2955
3084
  S: this,
2956
3085
  C: (f, a) => f(...a)
2957
3086
  });
@@ -2962,9 +3091,9 @@ var SimplePeerTransport = class {
2962
3091
  });
2963
3092
  });
2964
3093
  this._peer.on("connect", () => {
2965
- (0, import_log11.log)("connected", void 0, {
2966
- F: __dxlog_file10,
2967
- L: 56,
3094
+ (0, import_log12.log)("connected", void 0, {
3095
+ F: __dxlog_file11,
3096
+ L: 55,
2968
3097
  S: this,
2969
3098
  C: (f, a) => f(...a)
2970
3099
  });
@@ -2972,9 +3101,9 @@ var SimplePeerTransport = class {
2972
3101
  this.connected.emit();
2973
3102
  });
2974
3103
  this._peer.on("close", async () => {
2975
- (0, import_log11.log)("closed", void 0, {
2976
- F: __dxlog_file10,
2977
- L: 62,
3104
+ (0, import_log12.log)("closed", void 0, {
3105
+ F: __dxlog_file11,
3106
+ L: 61,
2978
3107
  S: this,
2979
3108
  C: (f, a) => f(...a)
2980
3109
  });
@@ -2984,70 +3113,84 @@ var SimplePeerTransport = class {
2984
3113
  this._peer.on("error", async (err) => {
2985
3114
  if (typeof RTCError !== "undefined" && err instanceof RTCError) {
2986
3115
  if (err.errorDetail === "sctp-failure") {
2987
- this.errors.raise(new import_errors4.ConnectionResetError("sctp-failure from RTCError", err));
3116
+ this.errors.raise(new import_protocols7.ConnectionResetError("sctp-failure from RTCError", err));
2988
3117
  } else {
2989
- this.errors.raise(new import_errors4.UnknownProtocolError("unknown RTCError", err));
3118
+ this.errors.raise(new import_protocols7.UnknownProtocolError("unknown RTCError", err));
2990
3119
  }
2991
- } else if (err.name === "InvalidStateError") {
2992
- this.errors.raise(new import_errors4.ConnectionResetError("safari WebRTC error", err));
2993
3120
  } else if ("code" in err) {
3121
+ import_log12.log.info("simple-peer error", err, {
3122
+ F: __dxlog_file11,
3123
+ L: 77,
3124
+ S: this,
3125
+ C: (f, a) => f(...a)
3126
+ });
2994
3127
  switch (err.code) {
2995
3128
  case "ERR_WEBRTC_SUPPORT":
2996
- this.errors.raise(new import_errors4.ProtocolError("WebRTC not supported", err));
3129
+ this.errors.raise(new import_protocols7.ProtocolError("WebRTC not supported", err));
3130
+ break;
2997
3131
  case "ERR_ICE_CONNECTION_FAILURE":
2998
3132
  case "ERR_DATA_CHANNEL":
2999
3133
  case "ERR_CONNECTION_FAILURE":
3000
3134
  case "ERR_SIGNALING":
3001
- this.errors.raise(new import_errors4.ConnectivityError("unknown communication failure", err));
3135
+ this.errors.raise(new import_protocols7.ConnectivityError("unknown communication failure", err));
3136
+ break;
3002
3137
  case "ERR_CREATE_OFFER":
3003
3138
  case "ERR_CREATE_ANSWER":
3004
3139
  case "ERR_SET_LOCAL_DESCRIPTION":
3005
3140
  case "ERR_SET_REMOTE_DESCRIPTION":
3006
3141
  case "ERR_ADD_ICE_CANDIDATE":
3007
- this.errors.raise(new import_errors4.UnknownProtocolError("unknown simple-peer library failure", err));
3142
+ this.errors.raise(new import_protocols7.UnknownProtocolError("unknown simple-peer library failure", err));
3143
+ break;
3008
3144
  default:
3009
3145
  this.errors.raise(new Error("unknown simple-peer error"));
3146
+ break;
3010
3147
  }
3011
3148
  } else {
3149
+ import_log12.log.info("unknown peer connection error", err, {
3150
+ F: __dxlog_file11,
3151
+ L: 101,
3152
+ S: this,
3153
+ C: (f, a) => f(...a)
3154
+ });
3012
3155
  this.errors.raise(err);
3013
3156
  }
3014
3157
  try {
3015
- if (typeof this._peer?._pc.getStats === "function") {
3158
+ if (typeof this._peer?._pc?.getStats === "function") {
3016
3159
  this._peer._pc.getStats().then((stats) => {
3017
- import_log11.log.warn("report after webrtc error", {
3160
+ import_log12.log.warn("report after webrtc error", {
3018
3161
  config: this.params.webrtcConfig,
3019
3162
  stats
3020
3163
  }, {
3021
- F: __dxlog_file10,
3022
- L: 107,
3164
+ F: __dxlog_file11,
3165
+ L: 109,
3023
3166
  S: this,
3024
3167
  C: (f, a) => f(...a)
3025
3168
  });
3026
3169
  });
3027
3170
  }
3028
3171
  } catch (err2) {
3029
- import_log11.log.catch(err2, void 0, {
3030
- F: __dxlog_file10,
3031
- L: 114,
3172
+ import_log12.log.catch(err2, void 0, {
3173
+ F: __dxlog_file11,
3174
+ L: 116,
3032
3175
  S: this,
3033
3176
  C: (f, a) => f(...a)
3034
3177
  });
3035
3178
  }
3036
3179
  await this.destroy();
3037
3180
  });
3038
- import_log11.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols5.trace.end({
3181
+ import_log12.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols7.trace.end({
3039
3182
  id: this._instanceId
3040
3183
  }), {
3041
- F: __dxlog_file10,
3042
- L: 119,
3184
+ F: __dxlog_file11,
3185
+ L: 121,
3043
3186
  S: this,
3044
3187
  C: (f, a) => f(...a)
3045
3188
  });
3046
3189
  }
3047
3190
  async destroy() {
3048
- (0, import_log11.log)("closing...", void 0, {
3049
- F: __dxlog_file10,
3050
- L: 123,
3191
+ (0, import_log12.log)("closing...", void 0, {
3192
+ F: __dxlog_file11,
3193
+ L: 125,
3051
3194
  S: this,
3052
3195
  C: (f, a) => f(...a)
3053
3196
  });
@@ -3055,9 +3198,9 @@ var SimplePeerTransport = class {
3055
3198
  await this._disconnectStreams();
3056
3199
  this._peer.destroy();
3057
3200
  this.closed.emit();
3058
- (0, import_log11.log)("closed", void 0, {
3059
- F: __dxlog_file10,
3060
- L: 128,
3201
+ (0, import_log12.log)("closed", void 0, {
3202
+ F: __dxlog_file11,
3203
+ L: 130,
3061
3204
  S: this,
3062
3205
  C: (f, a) => f(...a)
3063
3206
  });
@@ -3084,16 +3227,15 @@ var createSimplePeerTransportFactory = (webrtcConfig) => ({
3084
3227
  var import_node_stream2 = require("node:stream");
3085
3228
  var import_codec_protobuf = require("@dxos/codec-protobuf");
3086
3229
  var import_invariant11 = require("@dxos/invariant");
3087
- var import_keys11 = require("@dxos/keys");
3088
- var import_log12 = require("@dxos/log");
3230
+ var import_keys12 = require("@dxos/keys");
3231
+ var import_log13 = require("@dxos/log");
3089
3232
  var import_bridge = require("@dxos/protocols/proto/dxos/mesh/bridge");
3090
- var import_util8 = require("@dxos/util");
3091
- var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport-service.ts";
3233
+ var import_util9 = require("@dxos/util");
3234
+ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport-service.ts";
3092
3235
  var SimplePeerTransportService = class {
3093
- // prettier-ignore
3094
3236
  constructor(_webrtcConfig) {
3095
3237
  this._webrtcConfig = _webrtcConfig;
3096
- this.transports = new import_util8.ComplexMap(import_keys11.PublicKey.hash);
3238
+ this.transports = new import_util9.ComplexMap(import_keys12.PublicKey.hash);
3097
3239
  }
3098
3240
  open(request) {
3099
3241
  const rpcStream = new import_codec_protobuf.Stream(({ ready, next, close }) => {
@@ -3160,7 +3302,8 @@ var SimplePeerTransportService = class {
3160
3302
  const transportState = {
3161
3303
  transport,
3162
3304
  stream: duplex,
3163
- writeCallbacks: []
3305
+ writeCallbacks: [],
3306
+ state: "OPEN"
3164
3307
  };
3165
3308
  ready();
3166
3309
  this.transports.set(request.proxyId, transportState);
@@ -3169,8 +3312,8 @@ var SimplePeerTransportService = class {
3169
3312
  }
3170
3313
  async sendSignal({ proxyId, signal }) {
3171
3314
  (0, import_invariant11.invariant)(this.transports.has(proxyId), void 0, {
3172
- F: __dxlog_file11,
3173
- L: 113,
3315
+ F: __dxlog_file12,
3316
+ L: 112,
3174
3317
  S: this,
3175
3318
  A: [
3176
3319
  "this.transports.has(proxyId)",
@@ -3180,9 +3323,17 @@ var SimplePeerTransportService = class {
3180
3323
  await this.transports.get(proxyId).transport.signal(signal);
3181
3324
  }
3182
3325
  async sendData({ proxyId, payload }) {
3326
+ if (this.transports.get(proxyId)?.state !== "OPEN") {
3327
+ import_log13.log.debug("transport is closed", void 0, {
3328
+ F: __dxlog_file12,
3329
+ L: 118,
3330
+ S: this,
3331
+ C: (f, a) => f(...a)
3332
+ });
3333
+ }
3183
3334
  (0, import_invariant11.invariant)(this.transports.has(proxyId), void 0, {
3184
- F: __dxlog_file11,
3185
- L: 118,
3335
+ F: __dxlog_file12,
3336
+ L: 120,
3186
3337
  S: this,
3187
3338
  A: [
3188
3339
  "this.transports.has(proxyId)",
@@ -3200,10 +3351,12 @@ var SimplePeerTransportService = class {
3200
3351
  async close({ proxyId }) {
3201
3352
  await this.transports.get(proxyId)?.transport.destroy();
3202
3353
  await this.transports.get(proxyId)?.stream.end();
3203
- this.transports.delete(proxyId);
3204
- (0, import_log12.log)("Closed.", void 0, {
3205
- F: __dxlog_file11,
3206
- L: 132,
3354
+ if (this.transports.get(proxyId)) {
3355
+ this.transports.get(proxyId).state = "CLOSED";
3356
+ }
3357
+ (0, import_log13.log)("Closed.", void 0, {
3358
+ F: __dxlog_file12,
3359
+ L: 136,
3207
3360
  S: this,
3208
3361
  C: (f, a) => f(...a)
3209
3362
  });
@@ -3212,24 +3365,23 @@ var SimplePeerTransportService = class {
3212
3365
 
3213
3366
  // packages/core/mesh/network-manager/src/transport/simplepeer-transport-proxy.ts
3214
3367
  var import_node_stream3 = require("node:stream");
3215
- var import_async10 = require("@dxos/async");
3368
+ var import_async11 = require("@dxos/async");
3216
3369
  var import_context6 = require("@dxos/context");
3217
3370
  var import_debug6 = require("@dxos/debug");
3218
- var import_errors5 = require("@dxos/errors");
3219
3371
  var import_invariant12 = require("@dxos/invariant");
3220
- var import_keys12 = require("@dxos/keys");
3221
- var import_log13 = require("@dxos/log");
3372
+ var import_keys13 = require("@dxos/keys");
3373
+ var import_log14 = require("@dxos/log");
3374
+ var import_protocols8 = require("@dxos/protocols");
3222
3375
  var import_bridge2 = require("@dxos/protocols/proto/dxos/mesh/bridge");
3223
- var import_util9 = require("@dxos/util");
3224
- var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport-proxy.ts";
3376
+ var import_util10 = require("@dxos/util");
3377
+ var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport-proxy.ts";
3225
3378
  var SimplePeerTransportProxy = class {
3226
- // prettier-ignore
3227
3379
  constructor(_params) {
3228
3380
  this._params = _params;
3229
- this._proxyId = import_keys12.PublicKey.random();
3381
+ this._proxyId = import_keys13.PublicKey.random();
3230
3382
  this._ctx = new import_context6.Context();
3231
- this.closed = new import_async10.Event();
3232
- this.connected = new import_async10.Event();
3383
+ this.closed = new import_async11.Event();
3384
+ this.connected = new import_async11.Event();
3233
3385
  this.errors = new import_debug6.ErrorStream();
3234
3386
  this._closed = false;
3235
3387
  this._serviceStream = this._params.bridgeService.open({
@@ -3238,9 +3390,9 @@ var SimplePeerTransportProxy = class {
3238
3390
  });
3239
3391
  this._serviceStream.waitUntilReady().then(() => {
3240
3392
  this._serviceStream.subscribe(async (event) => {
3241
- (0, import_log13.log)("SimplePeerTransportProxy: event", event, {
3242
- F: __dxlog_file12,
3243
- L: 58,
3393
+ (0, import_log14.log)("SimplePeerTransportProxy: event", event, {
3394
+ F: __dxlog_file13,
3395
+ L: 55,
3244
3396
  S: this,
3245
3397
  C: (f, a) => f(...a)
3246
3398
  });
@@ -3258,8 +3410,8 @@ var SimplePeerTransportProxy = class {
3258
3410
  proxyId: this._proxyId,
3259
3411
  payload: chunk
3260
3412
  }).then(() => callback(), (err) => {
3261
- import_log13.log.catch(err, void 0, {
3262
- F: __dxlog_file12,
3413
+ import_log14.log.catch(err, void 0, {
3414
+ F: __dxlog_file13,
3263
3415
  L: 76,
3264
3416
  S: this,
3265
3417
  C: (f, a) => f(...a)
@@ -3267,9 +3419,9 @@ var SimplePeerTransportProxy = class {
3267
3419
  });
3268
3420
  }
3269
3421
  }));
3270
- }, (error) => import_log13.log.catch(error, void 0, {
3271
- F: __dxlog_file12,
3272
- L: 82,
3422
+ }, (error) => import_log14.log.catch(error, void 0, {
3423
+ F: __dxlog_file13,
3424
+ L: 83,
3273
3425
  S: this,
3274
3426
  C: (f, a) => f(...a)
3275
3427
  }));
@@ -3290,7 +3442,7 @@ var SimplePeerTransportProxy = class {
3290
3442
  }
3291
3443
  }
3292
3444
  _handleData(dataEvent) {
3293
- this._params.stream.write((0, import_util9.arrayToBuffer)(dataEvent.payload));
3445
+ this._params.stream.write((0, import_util10.arrayToBuffer)(dataEvent.payload));
3294
3446
  }
3295
3447
  async _handleSignal(signalEvent) {
3296
3448
  await this._params.sendSignal(signalEvent.payload);
@@ -3313,9 +3465,9 @@ var SimplePeerTransportProxy = class {
3313
3465
  proxyId: this._proxyId
3314
3466
  });
3315
3467
  } catch (err) {
3316
- import_log13.log.catch(err, void 0, {
3317
- F: __dxlog_file12,
3318
- L: 133,
3468
+ import_log14.log.catch(err, void 0, {
3469
+ F: __dxlog_file13,
3470
+ L: 134,
3319
3471
  S: this,
3320
3472
  C: (f, a) => f(...a)
3321
3473
  });
@@ -3350,8 +3502,8 @@ var SimplePeerTransportProxyFactory = class {
3350
3502
  }
3351
3503
  createTransport(options) {
3352
3504
  (0, import_invariant12.invariant)(this._bridgeService, "SimplePeerTransportProxyFactory is not ready to open connections", {
3353
- F: __dxlog_file12,
3354
- L: 170,
3505
+ F: __dxlog_file13,
3506
+ L: 171,
3355
3507
  S: this,
3356
3508
  A: [
3357
3509
  "this._bridgeService",
@@ -3369,16 +3521,16 @@ var SimplePeerTransportProxyFactory = class {
3369
3521
  };
3370
3522
  var decodeError = (err) => {
3371
3523
  const message = typeof err === "string" ? err : err.message;
3372
- if (message.includes("ConnectionResetError")) {
3373
- return new import_errors5.ConnectionResetError(message);
3374
- } else if (message.includes("TimeoutError")) {
3375
- return new import_errors5.TimeoutError(message);
3376
- } else if (message.includes("ProtocolError")) {
3377
- return new import_errors5.ProtocolError(message);
3378
- } else if (message.includes("ConnectivityError")) {
3379
- return new import_errors5.ConnectivityError(message);
3380
- } else if (message.includes("UnknownProtocolError")) {
3381
- return new import_errors5.UnknownProtocolError(message);
3524
+ if (message.includes("CONNECTION_RESET")) {
3525
+ return new import_protocols8.ConnectionResetError(message);
3526
+ } else if (message.includes("TIMEOUT")) {
3527
+ return new import_protocols8.TimeoutError(message);
3528
+ } else if (message.includes("PROTOCOL_ERROR")) {
3529
+ return new import_protocols8.ProtocolError(message);
3530
+ } else if (message.includes("CONNECTIVITY_ERROR")) {
3531
+ return new import_protocols8.ConnectivityError(message);
3532
+ } else if (message.includes("UNKNOWN_PROTOCOL_ERROR")) {
3533
+ return new import_protocols8.UnknownProtocolError(message);
3382
3534
  } else {
3383
3535
  return typeof err === "string" ? new Error(err) : err;
3384
3536
  }
@@ -3389,9 +3541,9 @@ init_datachannel();
3389
3541
 
3390
3542
  // packages/core/mesh/network-manager/src/transport/libdatachannel-transport.ts
3391
3543
  var import_stream = require("stream");
3392
- var import_async11 = require("@dxos/async");
3544
+ var import_async12 = require("@dxos/async");
3393
3545
  var import_debug7 = require("@dxos/debug");
3394
- var import_log14 = require("@dxos/log");
3546
+ var import_log15 = require("@dxos/log");
3395
3547
  function _ts_decorate5(decorators, target, key, desc) {
3396
3548
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3397
3549
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -3402,7 +3554,7 @@ function _ts_decorate5(decorators, target, key, desc) {
3402
3554
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3403
3555
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3404
3556
  }
3405
- var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/libdatachannel-transport.ts";
3557
+ var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/libdatachannel-transport.ts";
3406
3558
  var DATACHANNEL_LABEL = "dxos.mesh.transport";
3407
3559
  var MAX_BUFFERED_AMOUNT = 64 * 1024;
3408
3560
  var MAX_MESSAGE_SIZE = 64 * 1024;
@@ -3410,11 +3562,11 @@ var LibDataChannelTransport = class {
3410
3562
  constructor(params) {
3411
3563
  this.params = params;
3412
3564
  this._closed = false;
3413
- this.closed = new import_async11.Event();
3565
+ this.closed = new import_async12.Event();
3414
3566
  this._connected = false;
3415
- this.connected = new import_async11.Event();
3567
+ this.connected = new import_async12.Event();
3416
3568
  this.errors = new import_debug7.ErrorStream();
3417
- this._readyForCandidates = new import_async11.Trigger();
3569
+ this._readyForCandidates = new import_async12.Trigger();
3418
3570
  this._writeCallback = null;
3419
3571
  this._peer = (async () => {
3420
3572
  const { RTCPeerConnection: PeerConnection2 } = await Promise.resolve().then(() => (init_datachannel(), datachannel_exports));
@@ -3423,32 +3575,32 @@ var LibDataChannelTransport = class {
3423
3575
  }
3424
3576
  const peer = new PeerConnection2(params.webrtcConfig);
3425
3577
  peer.onicecandidateerror = (event) => {
3426
- import_log14.log.error("peer.onicecandidateerror", {
3578
+ import_log15.log.error("peer.onicecandidateerror", {
3427
3579
  event
3428
3580
  }, {
3429
- F: __dxlog_file13,
3581
+ F: __dxlog_file14,
3430
3582
  L: 53,
3431
3583
  S: this,
3432
3584
  C: (f, a) => f(...a)
3433
3585
  });
3434
3586
  };
3435
3587
  peer.onconnectionstatechange = (event) => {
3436
- import_log14.log.debug("peer.onconnectionstatechange", {
3588
+ import_log15.log.debug("peer.onconnectionstatechange", {
3437
3589
  event,
3438
3590
  peerConnectionState: peer.connectionState,
3439
3591
  transportConnectionState: this._connected
3440
3592
  }, {
3441
- F: __dxlog_file13,
3593
+ F: __dxlog_file14,
3442
3594
  L: 57,
3443
3595
  S: this,
3444
3596
  C: (f, a) => f(...a)
3445
3597
  });
3446
3598
  };
3447
3599
  peer.onicecandidate = async (event) => {
3448
- import_log14.log.debug("peer.onicecandidate", {
3600
+ import_log15.log.debug("peer.onicecandidate", {
3449
3601
  event
3450
3602
  }, {
3451
- F: __dxlog_file13,
3603
+ F: __dxlog_file14,
3452
3604
  L: 66,
3453
3605
  S: this,
3454
3606
  C: (f, a) => f(...a)
@@ -3469,10 +3621,10 @@ var LibDataChannelTransport = class {
3469
3621
  }
3470
3622
  });
3471
3623
  } catch (err) {
3472
- import_log14.log.warn("signaling errror", {
3624
+ import_log15.log.warn("signaling errror", {
3473
3625
  err
3474
3626
  }, {
3475
- F: __dxlog_file13,
3627
+ F: __dxlog_file14,
3476
3628
  L: 83,
3477
3629
  S: this,
3478
3630
  C: (f, a) => f(...a)
@@ -3483,20 +3635,20 @@ var LibDataChannelTransport = class {
3483
3635
  if (params.initiator) {
3484
3636
  peer.createOffer().then(async (offer) => {
3485
3637
  if (peer.connectionState !== "connecting") {
3486
- import_log14.log.error("i am initiator but peer not in state connecting", {
3638
+ import_log15.log.error("i am initiator but peer not in state connecting", {
3487
3639
  peer
3488
3640
  }, {
3489
- F: __dxlog_file13,
3641
+ F: __dxlog_file14,
3490
3642
  L: 92,
3491
3643
  S: this,
3492
3644
  C: (f, a) => f(...a)
3493
3645
  });
3494
3646
  this.errors.raise(new Error("invalid state: peer is initiator, but other peer not in state connecting"));
3495
3647
  }
3496
- import_log14.log.debug(`im the initiator, creating offer, peer is in state ${peer.connectionState}`, {
3648
+ import_log15.log.debug(`im the initiator, creating offer, peer is in state ${peer.connectionState}`, {
3497
3649
  offer
3498
3650
  }, {
3499
- F: __dxlog_file13,
3651
+ F: __dxlog_file14,
3500
3652
  L: 95,
3501
3653
  S: this,
3502
3654
  C: (f, a) => f(...a)
@@ -3515,8 +3667,8 @@ var LibDataChannelTransport = class {
3515
3667
  this.errors.raise(err);
3516
3668
  });
3517
3669
  this.handleChannel(peer.createDataChannel(DATACHANNEL_LABEL));
3518
- import_log14.log.debug("created data channel", void 0, {
3519
- F: __dxlog_file13,
3670
+ import_log15.log.debug("created data channel", void 0, {
3671
+ F: __dxlog_file14,
3520
3672
  L: 104,
3521
3673
  S: this,
3522
3674
  C: (f, a) => f(...a)
@@ -3526,10 +3678,10 @@ var LibDataChannelTransport = class {
3526
3678
  };
3527
3679
  } else {
3528
3680
  peer.ondatachannel = (event) => {
3529
- import_log14.log.debug("peer.ondatachannel (non-initiator)", {
3681
+ import_log15.log.debug("peer.ondatachannel (non-initiator)", {
3530
3682
  event
3531
3683
  }, {
3532
- F: __dxlog_file13,
3684
+ F: __dxlog_file14,
3533
3685
  L: 110,
3534
3686
  S: this,
3535
3687
  C: (f, a) => f(...a)
@@ -3546,8 +3698,8 @@ var LibDataChannelTransport = class {
3546
3698
  handleChannel(dataChannel) {
3547
3699
  this._channel = dataChannel;
3548
3700
  this._channel.onopen = () => {
3549
- import_log14.log.debug("dataChannel.onopen", void 0, {
3550
- F: __dxlog_file13,
3701
+ import_log15.log.debug("dataChannel.onopen", void 0, {
3702
+ F: __dxlog_file14,
3551
3703
  L: 126,
3552
3704
  S: this,
3553
3705
  C: (f, a) => f(...a)
@@ -3562,8 +3714,8 @@ var LibDataChannelTransport = class {
3562
3714
  dataChannel.send(chunk);
3563
3715
  if (this._channel.bufferedAmount > MAX_BUFFERED_AMOUNT) {
3564
3716
  if (this._writeCallback !== null) {
3565
- import_log14.log.error("consumer trying to write before we're ready for more data", void 0, {
3566
- F: __dxlog_file13,
3717
+ import_log15.log.error("consumer trying to write before we're ready for more data", void 0, {
3718
+ F: __dxlog_file14,
3567
3719
  L: 139,
3568
3720
  S: this,
3569
3721
  C: (f, a) => f(...a)
@@ -3585,10 +3737,10 @@ var LibDataChannelTransport = class {
3585
3737
  await this._close();
3586
3738
  };
3587
3739
  this._channel.onclose = async (err) => {
3588
- import_log14.log.info("channel onclose", {
3740
+ import_log15.log.info("channel onclose", {
3589
3741
  err
3590
3742
  }, {
3591
- F: __dxlog_file13,
3743
+ F: __dxlog_file14,
3592
3744
  L: 159,
3593
3745
  S: this,
3594
3746
  C: (f, a) => f(...a)
@@ -3622,10 +3774,10 @@ var LibDataChannelTransport = class {
3622
3774
  switch (data.type) {
3623
3775
  case "offer": {
3624
3776
  if ((await this._peer).connectionState !== "new") {
3625
- import_log14.log.error("received offer but peer not in state new", {
3777
+ import_log15.log.error("received offer but peer not in state new", {
3626
3778
  peer
3627
3779
  }, {
3628
- F: __dxlog_file13,
3780
+ F: __dxlog_file14,
3629
3781
  L: 194,
3630
3782
  S: this,
3631
3783
  C: (f, a) => f(...a)
@@ -3650,10 +3802,10 @@ var LibDataChannelTransport = class {
3650
3802
  });
3651
3803
  this._readyForCandidates.wake();
3652
3804
  } catch (err) {
3653
- import_log14.log.error("can't handle offer from signalling server", {
3805
+ import_log15.log.error("can't handle offer from signalling server", {
3654
3806
  err
3655
3807
  }, {
3656
- F: __dxlog_file13,
3808
+ F: __dxlog_file14,
3657
3809
  L: 205,
3658
3810
  S: this,
3659
3811
  C: (f, a) => f(...a)
@@ -3670,10 +3822,10 @@ var LibDataChannelTransport = class {
3670
3822
  });
3671
3823
  this._readyForCandidates.wake();
3672
3824
  } catch (err) {
3673
- import_log14.log.error("can't handle answer from signalling server", {
3825
+ import_log15.log.error("can't handle answer from signalling server", {
3674
3826
  err
3675
3827
  }, {
3676
- F: __dxlog_file13,
3828
+ F: __dxlog_file14,
3677
3829
  L: 216,
3678
3830
  S: this,
3679
3831
  C: (f, a) => f(...a)
@@ -3688,11 +3840,11 @@ var LibDataChannelTransport = class {
3688
3840
  });
3689
3841
  break;
3690
3842
  default:
3691
- import_log14.log.error("unhandled signal type", {
3843
+ import_log15.log.error("unhandled signal type", {
3692
3844
  type: data.type,
3693
3845
  signal
3694
3846
  }, {
3695
- F: __dxlog_file13,
3847
+ F: __dxlog_file14,
3696
3848
  L: 227,
3697
3849
  S: this,
3698
3850
  C: (f, a) => f(...a)
@@ -3700,8 +3852,8 @@ var LibDataChannelTransport = class {
3700
3852
  this.errors.raise(new Error(`unhandled signal type ${data.type}`));
3701
3853
  }
3702
3854
  }).catch((err) => {
3703
- import_log14.log.catch(err, void 0, {
3704
- F: __dxlog_file13,
3855
+ import_log15.log.catch(err, void 0, {
3856
+ F: __dxlog_file14,
3705
3857
  L: 232,
3706
3858
  S: this,
3707
3859
  C: (f, a) => f(...a)
@@ -3717,7 +3869,7 @@ var LibDataChannelTransport = class {
3717
3869
  }
3718
3870
  };
3719
3871
  _ts_decorate5([
3720
- import_async11.synchronized
3872
+ import_async12.synchronized
3721
3873
  ], LibDataChannelTransport.prototype, "_close", null);
3722
3874
  var createLibDataChannelTransportFactory = (webrtcConfig) => ({
3723
3875
  createTransport: (params) => new LibDataChannelTransport({
@@ -3728,10 +3880,10 @@ var createLibDataChannelTransportFactory = (webrtcConfig) => ({
3728
3880
 
3729
3881
  // packages/core/mesh/network-manager/src/transport/tcp-transport.ts
3730
3882
  var import_node_net = require("node:net");
3731
- var import_async12 = require("@dxos/async");
3883
+ var import_async13 = require("@dxos/async");
3732
3884
  var import_debug8 = require("@dxos/debug");
3733
- var import_log15 = require("@dxos/log");
3734
- var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/tcp-transport.ts";
3885
+ var import_log16 = require("@dxos/log");
3886
+ var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/tcp-transport.ts";
3735
3887
  var TcpTransportFactory = {
3736
3888
  createTransport: (params) => new TcpTransport(params)
3737
3889
  };
@@ -3740,13 +3892,13 @@ var TcpTransport = class {
3740
3892
  this.options = options;
3741
3893
  this._server = void 0;
3742
3894
  this._socket = void 0;
3743
- this.closed = new import_async12.Event();
3744
- this.connected = new import_async12.Event();
3895
+ this.closed = new import_async13.Event();
3896
+ this.connected = new import_async13.Event();
3745
3897
  this.errors = new import_debug8.ErrorStream();
3746
3898
  this._destroyed = false;
3747
3899
  this._connected = false;
3748
- (0, import_log15.log)("creating", void 0, {
3749
- F: __dxlog_file14,
3900
+ (0, import_log16.log)("creating", void 0, {
3901
+ F: __dxlog_file15,
3750
3902
  L: 34,
3751
3903
  S: this,
3752
3904
  C: (f, a) => f(...a)
@@ -3755,8 +3907,8 @@ var TcpTransport = class {
3755
3907
  setTimeout(async () => {
3756
3908
  const { Server } = await import("node:net");
3757
3909
  this._server = new Server((socket) => {
3758
- (0, import_log15.log)("new connection", void 0, {
3759
- F: __dxlog_file14,
3910
+ (0, import_log16.log)("new connection", void 0, {
3911
+ F: __dxlog_file15,
3760
3912
  L: 42,
3761
3913
  S: this,
3762
3914
  C: (f, a) => f(...a)
@@ -3768,10 +3920,10 @@ var TcpTransport = class {
3768
3920
  });
3769
3921
  this._server.on("listening", () => {
3770
3922
  const { port: port2 } = this._server.address();
3771
- (0, import_log15.log)("listening", {
3923
+ (0, import_log16.log)("listening", {
3772
3924
  port: port2
3773
3925
  }, {
3774
- F: __dxlog_file14,
3926
+ F: __dxlog_file15,
3775
3927
  L: 51,
3776
3928
  S: this,
3777
3929
  C: (f, a) => f(...a)
@@ -3794,8 +3946,8 @@ var TcpTransport = class {
3794
3946
  }
3795
3947
  }
3796
3948
  async destroy() {
3797
- (0, import_log15.log)("closing", void 0, {
3798
- F: __dxlog_file14,
3949
+ (0, import_log16.log)("closing", void 0, {
3950
+ F: __dxlog_file15,
3799
3951
  L: 72,
3800
3952
  S: this,
3801
3953
  C: (f, a) => f(...a)
@@ -3805,10 +3957,10 @@ var TcpTransport = class {
3805
3957
  this._destroyed = true;
3806
3958
  }
3807
3959
  signal({ payload }) {
3808
- (0, import_log15.log)("received signal", {
3960
+ (0, import_log16.log)("received signal", {
3809
3961
  payload
3810
3962
  }, {
3811
- F: __dxlog_file14,
3963
+ F: __dxlog_file15,
3812
3964
  L: 80,
3813
3965
  S: this,
3814
3966
  C: (f, a) => f(...a)
@@ -3824,11 +3976,11 @@ var TcpTransport = class {
3824
3976
  });
3825
3977
  }
3826
3978
  _handleSocket(socket) {
3827
- (0, import_log15.log)("handling socket", {
3979
+ (0, import_log16.log)("handling socket", {
3828
3980
  remotePort: socket.remotePort,
3829
3981
  localPort: socket.localPort
3830
3982
  }, {
3831
- F: __dxlog_file14,
3983
+ F: __dxlog_file15,
3832
3984
  L: 91,
3833
3985
  S: this,
3834
3986
  C: (f, a) => f(...a)
@@ -3837,10 +3989,10 @@ var TcpTransport = class {
3837
3989
  this.connected.emit();
3838
3990
  this.options.stream.pipe(this._socket).pipe(this.options.stream);
3839
3991
  this._socket.on("connect", () => {
3840
- (0, import_log15.log)("connected to", {
3992
+ (0, import_log16.log)("connected to", {
3841
3993
  port: this._socket?.remotePort
3842
3994
  }, {
3843
- F: __dxlog_file14,
3995
+ F: __dxlog_file15,
3844
3996
  L: 97,
3845
3997
  S: this,
3846
3998
  C: (f, a) => f(...a)
@@ -3856,118 +4008,6 @@ var TcpTransport = class {
3856
4008
  }
3857
4009
  };
3858
4010
 
3859
- // packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts
3860
- var import_async13 = require("@dxos/async");
3861
- var import_keys13 = require("@dxos/keys");
3862
- var import_log16 = require("@dxos/log");
3863
- var import_teleport2 = require("@dxos/teleport");
3864
- var import_util10 = require("@dxos/util");
3865
-
3866
- // packages/core/mesh/network-manager/src/wire-protocol.ts
3867
- var import_teleport = require("@dxos/teleport");
3868
- var createTeleportProtocolFactory = (onConnection) => {
3869
- return (params) => {
3870
- const teleport = new import_teleport.Teleport(params);
3871
- return {
3872
- stream: teleport.stream,
3873
- open: async () => {
3874
- await teleport.open();
3875
- await onConnection(teleport);
3876
- },
3877
- close: async () => {
3878
- await teleport.close();
3879
- },
3880
- abort: async () => {
3881
- await teleport.abort();
3882
- }
3883
- };
3884
- };
3885
- };
3886
-
3887
- // packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts
3888
- var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts";
3889
- var TestWireProtocol = class {
3890
- constructor(peerId, _extensionFactory = () => []) {
3891
- this.peerId = peerId;
3892
- this._extensionFactory = _extensionFactory;
3893
- this.connections = new import_util10.ComplexMap(import_keys13.PublicKey.hash);
3894
- this.streamConnections = new import_util10.ComplexMap(import_keys13.PublicKey.hash);
3895
- this.connected = new import_async13.Event();
3896
- this.disconnected = new import_async13.Event();
3897
- this.otherConnections = new import_util10.ComplexMap(({ remotePeerId, extension }) => remotePeerId.toHex() + extension);
3898
- this.factory = createTeleportProtocolFactory(async (teleport) => {
3899
- (0, import_log16.log)("create", {
3900
- remotePeerId: teleport.remotePeerId
3901
- }, {
3902
- F: __dxlog_file15,
3903
- L: 38,
3904
- S: this,
3905
- C: (f, a) => f(...a)
3906
- });
3907
- const extension = new import_teleport2.TestExtension({
3908
- onClose: async () => {
3909
- this.connections.delete(teleport.remotePeerId);
3910
- this.disconnected.emit(teleport.remotePeerId);
3911
- }
3912
- });
3913
- this.connections.set(teleport.remotePeerId, extension);
3914
- teleport.addExtension("test", extension);
3915
- this.connected.emit(teleport.remotePeerId);
3916
- const streamExtension = new import_teleport2.TestExtensionWithStreams({
3917
- onClose: async () => {
3918
- this.streamConnections.delete(teleport.remotePeerId);
3919
- }
3920
- });
3921
- this.streamConnections.set(teleport.remotePeerId, streamExtension);
3922
- teleport.addExtension("test-stream", streamExtension);
3923
- for (const { name, extension: extension2 } of this._extensionFactory()) {
3924
- this.otherConnections.set({
3925
- remotePeerId: teleport.remotePeerId,
3926
- extension: name
3927
- }, extension2);
3928
- teleport.addExtension(name, extension2);
3929
- }
3930
- });
3931
- }
3932
- async waitForConnection(peerId) {
3933
- if (this.connections.has(peerId)) {
3934
- return this.connections.get(peerId);
3935
- }
3936
- (0, import_log16.log)("waitForConnection", {
3937
- peerId
3938
- }, {
3939
- F: __dxlog_file15,
3940
- L: 67,
3941
- S: this,
3942
- C: (f, a) => f(...a)
3943
- });
3944
- await (0, import_async13.asyncTimeout)(
3945
- this.connected.waitFor((connectedId) => connectedId.equals(peerId)),
3946
- // TODO(nf): Make this configurable.
3947
- 1e4
3948
- );
3949
- return this.connections.get(peerId);
3950
- }
3951
- async testConnection(peerId, message) {
3952
- const connection = await this.waitForConnection(peerId);
3953
- await connection.test(message);
3954
- }
3955
- async openStream(peerId, streamTag, streamLoadInterval, streamLoadChunkSize) {
3956
- if (!this.streamConnections.has(peerId)) {
3957
- throw new Error("Connection does not exist.");
3958
- }
3959
- const connection = this.streamConnections.get(peerId);
3960
- return connection.addNewStream(streamLoadInterval, streamLoadChunkSize, streamTag);
3961
- }
3962
- async closeStream(peerId, streamTag) {
3963
- if (!this.streamConnections.has(peerId)) {
3964
- throw new Error("Connection does not exist.");
3965
- }
3966
- const connection = this.streamConnections.get(peerId);
3967
- return connection.closeStream(streamTag);
3968
- }
3969
- };
3970
-
3971
4011
  // packages/core/mesh/network-manager/src/testing/test-builder.ts
3972
4012
  var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-builder.ts";
3973
4013
  var port = process.env.SIGNAL_PORT ?? 4e3;
@@ -4035,7 +4075,7 @@ var TestPeer = class {
4035
4075
  this._proxy = (0, import_rpc.createProtoRpcPeer)({
4036
4076
  port: proxyPort,
4037
4077
  requested: {
4038
- BridgeService: import_protocols6.schema.getService("dxos.mesh.bridge.BridgeService")
4078
+ BridgeService: import_protocols9.schema.getService("dxos.mesh.bridge.BridgeService")
4039
4079
  },
4040
4080
  noHandshake: true,
4041
4081
  encodingOptions: {
@@ -4045,7 +4085,7 @@ var TestPeer = class {
4045
4085
  this._service = (0, import_rpc.createProtoRpcPeer)({
4046
4086
  port: servicePort,
4047
4087
  exposed: {
4048
- BridgeService: import_protocols6.schema.getService("dxos.mesh.bridge.BridgeService")
4088
+ BridgeService: import_protocols9.schema.getService("dxos.mesh.bridge.BridgeService")
4049
4089
  },
4050
4090
  handlers: {
4051
4091
  BridgeService: new SimplePeerTransportService()