@dxos/network-manager 0.6.9 → 0.6.10-main.48c066e

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.
@@ -26,8 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var chunk_IQBYIEAR_exports = {};
30
- __export(chunk_IQBYIEAR_exports, {
29
+ var chunk_FYVBSNF4_exports = {};
30
+ __export(chunk_FYVBSNF4_exports, {
31
31
  Connection: () => Connection,
32
32
  ConnectionLimiter: () => ConnectionLimiter,
33
33
  ConnectionLog: () => ConnectionLog,
@@ -56,7 +56,7 @@ __export(chunk_IQBYIEAR_exports, {
56
56
  createSimplePeerTransportFactory: () => createSimplePeerTransportFactory,
57
57
  createTeleportProtocolFactory: () => createTeleportProtocolFactory
58
58
  });
59
- module.exports = __toCommonJS(chunk_IQBYIEAR_exports);
59
+ module.exports = __toCommonJS(chunk_FYVBSNF4_exports);
60
60
  var import_async = require("@dxos/async");
61
61
  var import_context = require("@dxos/context");
62
62
  var import_debug = require("@dxos/debug");
@@ -72,6 +72,7 @@ var import_invariant2 = require("@dxos/invariant");
72
72
  var import_keys2 = require("@dxos/keys");
73
73
  var import_log3 = require("@dxos/log");
74
74
  var import_protocols2 = require("@dxos/protocols");
75
+ var import_proto = require("@dxos/protocols/proto");
75
76
  var import_util2 = require("@dxos/util");
76
77
  var import_async3 = require("@dxos/async");
77
78
  var import_context3 = require("@dxos/context");
@@ -113,7 +114,6 @@ var import_protocols6 = require("@dxos/protocols");
113
114
  var import_services = require("@dxos/protocols/proto/dxos/client/services");
114
115
  var import_util7 = require("@dxos/util");
115
116
  var import_invariant7 = require("@dxos/invariant");
116
- var import_xor_distance = __toESM(require("xor-distance"));
117
117
  var import_invariant8 = require("@dxos/invariant");
118
118
  var import_log9 = require("@dxos/log");
119
119
  var import_invariant9 = require("@dxos/invariant");
@@ -756,12 +756,12 @@ var createIceProvider = (iceProviders) => {
756
756
  };
757
757
  };
758
758
  var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
759
- var SwarmMessage = import_protocols2.schema.getCodecForType("dxos.mesh.swarm.SwarmMessage");
759
+ var SwarmMessage = import_proto.schema.getCodecForType("dxos.mesh.swarm.SwarmMessage");
760
760
  var SwarmMessenger = class {
761
761
  constructor({ sendMessage, onSignal, onOffer, topic }) {
762
762
  this._ctx = new import_context2.Context(void 0, {
763
763
  F: __dxlog_file3,
764
- L: 34
764
+ L: 35
765
765
  });
766
766
  this._offerRecords = new import_util2.ComplexMap((key) => key.toHex());
767
767
  this._sendMessage = sendMessage;
@@ -783,7 +783,7 @@ var SwarmMessenger = class {
783
783
  msg: message
784
784
  }, {
785
785
  F: __dxlog_file3,
786
- L: 70,
786
+ L: 71,
787
787
  S: this,
788
788
  C: (f, a) => f(...a)
789
789
  });
@@ -812,7 +812,7 @@ var SwarmMessenger = class {
812
812
  message
813
813
  }, {
814
814
  F: __dxlog_file3,
815
- L: 81,
815
+ L: 82,
816
816
  S: this,
817
817
  C: (f, a) => f(...a)
818
818
  });
@@ -821,7 +821,7 @@ var SwarmMessenger = class {
821
821
  async signal(message) {
822
822
  (0, import_invariant2.invariant)(message.data?.signal || message.data?.signalBatch, "Invalid message", {
823
823
  F: __dxlog_file3,
824
- L: 86,
824
+ L: 87,
825
825
  S: this,
826
826
  A: [
827
827
  "message.data?.signal || message.data?.signalBatch",
@@ -862,7 +862,7 @@ var SwarmMessenger = class {
862
862
  msg: networkMessage
863
863
  }, {
864
864
  F: __dxlog_file3,
865
- L: 124,
865
+ L: 125,
866
866
  S: this,
867
867
  C: (f, a) => f(...a)
868
868
  });
@@ -878,7 +878,7 @@ var SwarmMessenger = class {
878
878
  async _resolveAnswers(message) {
879
879
  (0, import_invariant2.invariant)(message.data?.answer?.offerMessageId, "No offerMessageId", {
880
880
  F: __dxlog_file3,
881
- L: 136,
881
+ L: 137,
882
882
  S: this,
883
883
  A: [
884
884
  "message.data?.answer?.offerMessageId",
@@ -890,7 +890,7 @@ var SwarmMessenger = class {
890
890
  this._offerRecords.delete(message.data.answer.offerMessageId);
891
891
  (0, import_invariant2.invariant)(message.data?.answer, "No answer", {
892
892
  F: __dxlog_file3,
893
- L: 140,
893
+ L: 141,
894
894
  S: this,
895
895
  A: [
896
896
  "message.data?.answer",
@@ -901,7 +901,7 @@ var SwarmMessenger = class {
901
901
  answer: message.data.answer
902
902
  }, {
903
903
  F: __dxlog_file3,
904
- L: 141,
904
+ L: 142,
905
905
  S: this,
906
906
  C: (f, a) => f(...a)
907
907
  });
@@ -911,7 +911,7 @@ var SwarmMessenger = class {
911
911
  async _handleOffer({ author, recipient, message }) {
912
912
  (0, import_invariant2.invariant)(message.data.offer, "No offer", {
913
913
  F: __dxlog_file3,
914
- L: 155,
914
+ L: 156,
915
915
  S: this,
916
916
  A: [
917
917
  "message.data.offer",
@@ -946,7 +946,7 @@ var SwarmMessenger = class {
946
946
  err
947
947
  }, {
948
948
  F: __dxlog_file3,
949
- L: 176,
949
+ L: 177,
950
950
  S: this,
951
951
  C: (f, a) => f(...a)
952
952
  });
@@ -955,7 +955,7 @@ var SwarmMessenger = class {
955
955
  err
956
956
  }, {
957
957
  F: __dxlog_file3,
958
- L: 178,
958
+ L: 179,
959
959
  S: this,
960
960
  C: (f, a) => f(...a)
961
961
  });
@@ -965,7 +965,7 @@ var SwarmMessenger = class {
965
965
  async _handleSignal({ author, recipient, message }) {
966
966
  (0, import_invariant2.invariant)(message.messageId, void 0, {
967
967
  F: __dxlog_file3,
968
- L: 192,
968
+ L: 193,
969
969
  S: this,
970
970
  A: [
971
971
  "message.messageId",
@@ -974,7 +974,7 @@ var SwarmMessenger = class {
974
974
  });
975
975
  (0, import_invariant2.invariant)(message.data.signal || message.data.signalBatch, "Invalid message", {
976
976
  F: __dxlog_file3,
977
- L: 193,
977
+ L: 194,
978
978
  S: this,
979
979
  A: [
980
980
  "message.data.signal || message.data.signalBatch",
@@ -2536,7 +2536,7 @@ var MMSTTopology = class {
2536
2536
  init(controller) {
2537
2537
  (0, import_invariant8.invariant)(!this._controller, "Already initialized", {
2538
2538
  F: __dxlog_file10,
2539
- L: 51,
2539
+ L: 49,
2540
2540
  S: this,
2541
2541
  A: [
2542
2542
  "!this._controller",
@@ -2548,7 +2548,7 @@ var MMSTTopology = class {
2548
2548
  update() {
2549
2549
  (0, import_invariant8.invariant)(this._controller, "Not initialized", {
2550
2550
  F: __dxlog_file10,
2551
- L: 56,
2551
+ L: 54,
2552
2552
  S: this,
2553
2553
  A: [
2554
2554
  "this._controller",
@@ -2559,7 +2559,7 @@ var MMSTTopology = class {
2559
2559
  if (this._sampleCollected || connected.length > this._maxPeers || candidates.length > 0) {
2560
2560
  (0, import_log9.log)("Running the algorithm.", void 0, {
2561
2561
  F: __dxlog_file10,
2562
- L: 60,
2562
+ L: 58,
2563
2563
  S: this,
2564
2564
  C: (f, a) => f(...a)
2565
2565
  });
@@ -2574,7 +2574,7 @@ var MMSTTopology = class {
2574
2574
  async onOffer(peer) {
2575
2575
  (0, import_invariant8.invariant)(this._controller, "Not initialized", {
2576
2576
  F: __dxlog_file10,
2577
- L: 72,
2577
+ L: 70,
2578
2578
  S: this,
2579
2579
  A: [
2580
2580
  "this._controller",
@@ -2585,7 +2585,7 @@ var MMSTTopology = class {
2585
2585
  const accept = connected.length < this._maxPeers;
2586
2586
  (0, import_log9.log)(`Offer ${peer} accept=${accept}`, void 0, {
2587
2587
  F: __dxlog_file10,
2588
- L: 75,
2588
+ L: 73,
2589
2589
  S: this,
2590
2590
  C: (f, a) => f(...a)
2591
2591
  });
@@ -2596,7 +2596,7 @@ var MMSTTopology = class {
2596
2596
  _runAlgorithm() {
2597
2597
  (0, import_invariant8.invariant)(this._controller, "Not initialized", {
2598
2598
  F: __dxlog_file10,
2599
- L: 84,
2599
+ L: 82,
2600
2600
  S: this,
2601
2601
  A: [
2602
2602
  "this._controller",
@@ -2607,14 +2607,14 @@ var MMSTTopology = class {
2607
2607
  if (connected.length > this._maxPeers) {
2608
2608
  (0, import_log9.log)(`disconnect ${connected.length - this._maxPeers} peers.`, void 0, {
2609
2609
  F: __dxlog_file10,
2610
- L: 90,
2610
+ L: 88,
2611
2611
  S: this,
2612
2612
  C: (f, a) => f(...a)
2613
2613
  });
2614
2614
  const sorted = sortByXorDistance(connected, ownPeerId).reverse().slice(0, this._maxPeers - connected.length);
2615
2615
  (0, import_invariant8.invariant)(sorted.length === 0, void 0, {
2616
2616
  F: __dxlog_file10,
2617
- L: 94,
2617
+ L: 92,
2618
2618
  S: this,
2619
2619
  A: [
2620
2620
  "sorted.length === 0",
@@ -2624,7 +2624,7 @@ var MMSTTopology = class {
2624
2624
  if (sorted.length > MAX_CHANGES_PER_UPDATE) {
2625
2625
  (0, import_log9.log)(`want to disconnect ${sorted.length} peers but limited to ${MAX_CHANGES_PER_UPDATE}`, void 0, {
2626
2626
  F: __dxlog_file10,
2627
- L: 97,
2627
+ L: 95,
2628
2628
  S: this,
2629
2629
  C: (f, a) => f(...a)
2630
2630
  });
@@ -2633,7 +2633,7 @@ var MMSTTopology = class {
2633
2633
  for (const peer of sorted.slice(0, MAX_CHANGES_PER_UPDATE)) {
2634
2634
  (0, import_log9.log)(`Disconnect ${peer}.`, void 0, {
2635
2635
  F: __dxlog_file10,
2636
- L: 102,
2636
+ L: 100,
2637
2637
  S: this,
2638
2638
  C: (f, a) => f(...a)
2639
2639
  });
@@ -2643,7 +2643,7 @@ var MMSTTopology = class {
2643
2643
  } else {
2644
2644
  (0, import_log9.log)("rate limited disconnect", void 0, {
2645
2645
  F: __dxlog_file10,
2646
- L: 107,
2646
+ L: 105,
2647
2647
  S: this,
2648
2648
  C: (f, a) => f(...a)
2649
2649
  });
@@ -2651,7 +2651,7 @@ var MMSTTopology = class {
2651
2651
  } else if (connected.length < this._originateConnections) {
2652
2652
  (0, import_log9.log)(`connect ${this._originateConnections - connected.length} peers.`, void 0, {
2653
2653
  F: __dxlog_file10,
2654
- L: 111,
2654
+ L: 109,
2655
2655
  S: this,
2656
2656
  C: (f, a) => f(...a)
2657
2657
  });
@@ -2660,7 +2660,7 @@ var MMSTTopology = class {
2660
2660
  if (sorted.length > MAX_CHANGES_PER_UPDATE) {
2661
2661
  (0, import_log9.log)(`want to connect ${sorted.length} peers but limited to ${MAX_CHANGES_PER_UPDATE}`, void 0, {
2662
2662
  F: __dxlog_file10,
2663
- L: 116,
2663
+ L: 114,
2664
2664
  S: this,
2665
2665
  C: (f, a) => f(...a)
2666
2666
  });
@@ -2669,7 +2669,7 @@ var MMSTTopology = class {
2669
2669
  for (const peer of sorted.slice(0, MAX_CHANGES_PER_UPDATE)) {
2670
2670
  (0, import_log9.log)(`Connect ${peer}.`, void 0, {
2671
2671
  F: __dxlog_file10,
2672
- L: 120,
2672
+ L: 118,
2673
2673
  S: this,
2674
2674
  C: (f, a) => f(...a)
2675
2675
  });
@@ -2679,7 +2679,7 @@ var MMSTTopology = class {
2679
2679
  } else {
2680
2680
  (0, import_log9.log)("rate limited connect", void 0, {
2681
2681
  F: __dxlog_file10,
2682
- L: 125,
2682
+ L: 123,
2683
2683
  S: this,
2684
2684
  C: (f, a) => f(...a)
2685
2685
  });
@@ -2690,7 +2690,40 @@ var MMSTTopology = class {
2690
2690
  return "MMSTTopology";
2691
2691
  }
2692
2692
  };
2693
- var sortByXorDistance = (keys, reference) => keys.sort((a, b) => import_xor_distance.default.gt((0, import_xor_distance.default)(a.asBuffer(), reference.asBuffer()), (0, import_xor_distance.default)(b.asBuffer(), reference.asBuffer())));
2693
+ var sortByXorDistance = (keys, reference) => {
2694
+ const sorted = keys.sort((a, b) => {
2695
+ return compareXor(distXor(a.asBuffer(), reference.asBuffer()), distXor(b.asBuffer(), reference.asBuffer()));
2696
+ });
2697
+ (0, import_log9.log)("Sorted keys", {
2698
+ keys,
2699
+ reference,
2700
+ sorted
2701
+ }, {
2702
+ F: __dxlog_file10,
2703
+ L: 137,
2704
+ S: void 0,
2705
+ C: (f, a) => f(...a)
2706
+ });
2707
+ return sorted;
2708
+ };
2709
+ var distXor = (a, b) => {
2710
+ const maxLength = Math.max(a.length, b.length);
2711
+ const result = Buffer.allocUnsafe(maxLength);
2712
+ for (let i = 0; i < maxLength; i++) {
2713
+ result[i] = (a[i] || 0) ^ (b[i] || 0);
2714
+ }
2715
+ return result;
2716
+ };
2717
+ var compareXor = (a, b) => {
2718
+ const maxLength = Math.max(a.length, b.length);
2719
+ for (let i = 0; i < maxLength; i++) {
2720
+ if ((a[i] || 0) === (b[i] || 0)) {
2721
+ continue;
2722
+ }
2723
+ return (a[i] || 0) < (b[i] || 0) ? -1 : 1;
2724
+ }
2725
+ return 0;
2726
+ };
2694
2727
  var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/star-topology.ts";
2695
2728
  var StarTopology = class {
2696
2729
  constructor(_centralPeer) {
@@ -4299,4 +4332,4 @@ var createTeleportProtocolFactory = (onConnection, defaultParams) => {
4299
4332
  createSimplePeerTransportFactory,
4300
4333
  createTeleportProtocolFactory
4301
4334
  });
4302
- //# sourceMappingURL=chunk-IQBYIEAR.cjs.map
4335
+ //# sourceMappingURL=chunk-FYVBSNF4.cjs.map