@dxos/network-manager 0.1.32-next.77d513e → 0.1.33

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.
@@ -38,9 +38,9 @@ __export(testing_exports, {
38
38
  module.exports = __toCommonJS(testing_exports);
39
39
 
40
40
  // packages/core/mesh/network-manager/src/testing/test-builder.ts
41
- var import_keys11 = require("@dxos/keys");
41
+ var import_keys13 = require("@dxos/keys");
42
42
  var import_messaging2 = require("@dxos/messaging");
43
- var import_protocols2 = require("@dxos/protocols");
43
+ var import_protocols6 = require("@dxos/protocols");
44
44
  var import_services2 = require("@dxos/protocols/proto/dxos/client/services");
45
45
  var import_rpc = require("@dxos/rpc");
46
46
  var import_util9 = require("@dxos/util");
@@ -48,23 +48,26 @@ var import_util9 = require("@dxos/util");
48
48
  // packages/core/mesh/network-manager/src/network-manager.ts
49
49
  var import_node_assert5 = __toESM(require("node:assert"));
50
50
  var import_async6 = require("@dxos/async");
51
- var import_keys6 = require("@dxos/keys");
51
+ var import_keys7 = require("@dxos/keys");
52
52
  var import_log6 = require("@dxos/log");
53
53
  var import_messaging = require("@dxos/messaging");
54
+ var import_protocols4 = require("@dxos/protocols");
54
55
  var import_services = require("@dxos/protocols/proto/dxos/client/services");
55
56
  var import_util5 = require("@dxos/util");
56
57
 
57
58
  // packages/core/mesh/network-manager/src/connection-log.ts
58
59
  var import_async5 = require("@dxos/async");
59
60
  var import_debug3 = require("@dxos/debug");
60
- var import_keys5 = require("@dxos/keys");
61
+ var import_keys6 = require("@dxos/keys");
61
62
  var import_util4 = require("@dxos/util");
62
63
 
63
64
  // packages/core/mesh/network-manager/src/swarm/connection.ts
64
65
  var import_node_assert = __toESM(require("node:assert"));
65
66
  var import_async = require("@dxos/async");
66
67
  var import_debug = require("@dxos/debug");
68
+ var import_keys = require("@dxos/keys");
67
69
  var import_log = require("@dxos/log");
70
+ var import_protocols = require("@dxos/protocols");
68
71
  var __decorate = function(decorators, target, key, desc) {
69
72
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
70
73
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -123,6 +126,10 @@ var Connection = class {
123
126
  this._bufferedSignals = [];
124
127
  this.stateChanged = new import_async.Event();
125
128
  this.errors = new import_debug.ErrorStream();
129
+ this._instanceId = import_keys.PublicKey.random().toHex();
130
+ this._performance = {
131
+ signalsSent: 0
132
+ };
126
133
  }
127
134
  get state() {
128
135
  return this._state;
@@ -140,13 +147,22 @@ var Connection = class {
140
147
  openConnection() {
141
148
  (0, import_node_assert.default)(this._state === ConnectionState.INITIAL, "Invalid state.");
142
149
  this._changeState(ConnectionState.CONNECTING);
150
+ import_log.log.trace("dxos.mesh.connection", import_protocols.trace.begin({
151
+ id: this._instanceId,
152
+ parentId: this._traceParent
153
+ }), {
154
+ file: "connection.ts",
155
+ line: 97,
156
+ scope: this,
157
+ callSite: (f, a) => f(...a)
158
+ });
143
159
  this._protocol.initialize().catch((err) => {
144
160
  this.errors.raise(err);
145
161
  });
146
162
  this._protocol.stream.on("close", () => {
147
163
  (0, import_log.log)("protocol stream closed", {}, {
148
164
  file: "connection.ts",
149
- line: 98,
165
+ line: 106,
150
166
  scope: this,
151
167
  callSite: (f, a) => f(...a)
152
168
  });
@@ -157,6 +173,7 @@ var Connection = class {
157
173
  initiator: this.initiator,
158
174
  stream: this._protocol.stream,
159
175
  sendSignal: async (signal) => {
176
+ this._performance.signalsSent++;
160
177
  await this._signalMessaging.signal({
161
178
  author: this.ownId,
162
179
  recipient: this.remoteId,
@@ -195,7 +212,7 @@ var Connection = class {
195
212
  peerId: this.ownId
196
213
  }, {
197
214
  file: "connection.ts",
198
- line: 148,
215
+ line: 156,
199
216
  scope: this,
200
217
  callSite: (f, a) => f(...a)
201
218
  });
@@ -204,7 +221,7 @@ var Connection = class {
204
221
  } catch (err) {
205
222
  import_log.log.catch(err, {}, {
206
223
  file: "connection.ts",
207
- line: 154,
224
+ line: 162,
208
225
  scope: this,
209
226
  callSite: (f, a) => f(...a)
210
227
  });
@@ -214,7 +231,7 @@ var Connection = class {
214
231
  } catch (err1) {
215
232
  import_log.log.catch(err1, {}, {
216
233
  file: "connection.ts",
217
- line: 161,
234
+ line: 169,
218
235
  scope: this,
219
236
  callSite: (f, a) => f(...a)
220
237
  });
@@ -223,11 +240,23 @@ var Connection = class {
223
240
  peerId: this.ownId
224
241
  }, {
225
242
  file: "connection.ts",
226
- line: 164,
243
+ line: 172,
227
244
  scope: this,
228
245
  callSite: (f, a) => f(...a)
229
246
  });
230
247
  this._changeState(ConnectionState.CLOSED);
248
+ import_log.log.trace("dxos.mesh.connection", import_protocols.trace.end({
249
+ id: this._instanceId,
250
+ status: "ok",
251
+ data: {
252
+ performance: this._performance
253
+ }
254
+ }), {
255
+ file: "connection.ts",
256
+ line: 174,
257
+ scope: this,
258
+ callSite: (f, a) => f(...a)
259
+ });
231
260
  }
232
261
  async signal(msg) {
233
262
  var _a, _b;
@@ -235,7 +264,7 @@ var Connection = class {
235
264
  if (!msg.sessionId.equals(this.sessionId)) {
236
265
  (0, import_log.log)("dropping signal for incorrect session id", {}, {
237
266
  file: "connection.ts",
238
- line: 171,
267
+ line: 183,
239
268
  scope: this,
240
269
  callSite: (f, a) => f(...a)
241
270
  });
@@ -251,7 +280,7 @@ var Connection = class {
251
280
  msg: msg.data
252
281
  }, {
253
282
  file: "connection.ts",
254
- line: 179,
283
+ line: 191,
255
284
  scope: this,
256
285
  callSite: (f, a) => f(...a)
257
286
  });
@@ -265,7 +294,7 @@ var Connection = class {
265
294
  msg: msg.data
266
295
  }, {
267
296
  file: "connection.ts",
268
- line: 185,
297
+ line: 197,
269
298
  scope: this,
270
299
  callSite: (f, a) => f(...a)
271
300
  });
@@ -278,7 +307,7 @@ var Connection = class {
278
307
  peerId: this.ownId
279
308
  }, {
280
309
  file: "connection.ts",
281
- line: 190,
310
+ line: 202,
282
311
  scope: this,
283
312
  callSite: (f, a) => f(...a)
284
313
  });
@@ -296,15 +325,16 @@ var import_node_assert4 = __toESM(require("node:assert"));
296
325
  var import_async3 = require("@dxos/async");
297
326
  var import_context = require("@dxos/context");
298
327
  var import_debug2 = require("@dxos/debug");
299
- var import_keys3 = require("@dxos/keys");
328
+ var import_keys4 = require("@dxos/keys");
300
329
  var import_log4 = require("@dxos/log");
330
+ var import_protocols3 = require("@dxos/protocols");
301
331
  var import_util2 = require("@dxos/util");
302
332
 
303
333
  // packages/core/mesh/network-manager/src/signal/message-router.ts
304
334
  var import_node_assert2 = __toESM(require("node:assert"));
305
- var import_keys = require("@dxos/keys");
335
+ var import_keys2 = require("@dxos/keys");
306
336
  var import_log2 = require("@dxos/log");
307
- var import_protocols = require("@dxos/protocols");
337
+ var import_protocols2 = require("@dxos/protocols");
308
338
  var import_util = require("@dxos/util");
309
339
  var MessageRouter = class {
310
340
  constructor({ sendMessage, onSignal, onOffer, topic }) {
@@ -319,7 +349,7 @@ var MessageRouter = class {
319
349
  if (payload.type_url !== "dxos.mesh.swarm.SwarmMessage") {
320
350
  return;
321
351
  }
322
- const message = import_protocols.schema.getCodecForType("dxos.mesh.swarm.SwarmMessage").decode(payload.value);
352
+ const message = import_protocols2.schema.getCodecForType("dxos.mesh.swarm.SwarmMessage").decode(payload.value);
323
353
  if (!this._topic.equals(message.topic)) {
324
354
  return;
325
355
  }
@@ -361,7 +391,7 @@ var MessageRouter = class {
361
391
  async offer(message) {
362
392
  const networkMessage = {
363
393
  ...message,
364
- messageId: import_keys.PublicKey.random()
394
+ messageId: import_keys2.PublicKey.random()
365
395
  };
366
396
  return new Promise((resolve, reject) => {
367
397
  this._offerRecords.set(networkMessage.messageId, {
@@ -380,7 +410,7 @@ var MessageRouter = class {
380
410
  const networkMessage = {
381
411
  ...message,
382
412
  // Setting unique message_id if it not specified yet.
383
- messageId: (_a = message.messageId) != null ? _a : import_keys.PublicKey.random()
413
+ messageId: (_a = message.messageId) != null ? _a : import_keys2.PublicKey.random()
384
414
  };
385
415
  (0, import_log2.log)("sending", {
386
416
  from: author,
@@ -404,7 +434,7 @@ var MessageRouter = class {
404
434
  recipient,
405
435
  payload: {
406
436
  type_url: "dxos.mesh.swarm.SwarmMessage",
407
- value: import_protocols.schema.getCodecForType("dxos.mesh.swarm.SwarmMessage").encode(message)
437
+ value: import_protocols2.schema.getCodecForType("dxos.mesh.swarm.SwarmMessage").encode(message)
408
438
  }
409
439
  });
410
440
  }
@@ -468,7 +498,7 @@ var MessageRouter = class {
468
498
  // packages/core/mesh/network-manager/src/swarm/peer.ts
469
499
  var import_node_assert3 = __toESM(require("node:assert"));
470
500
  var import_async2 = require("@dxos/async");
471
- var import_keys2 = require("@dxos/keys");
501
+ var import_keys3 = require("@dxos/keys");
472
502
  var import_log3 = require("@dxos/log");
473
503
  var __decorate2 = function(decorators, target, key, desc) {
474
504
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -505,7 +535,7 @@ var Peer = class {
505
535
  peerId: this.localPeerId
506
536
  }, {
507
537
  file: "peer.ts",
508
- line: 84,
538
+ line: 86,
509
539
  scope: this,
510
540
  callSite: (f, a) => f(...a)
511
541
  });
@@ -532,7 +562,7 @@ var Peer = class {
532
562
  err
533
563
  }, {
534
564
  file: "peer.ts",
535
- line: 108,
565
+ line: 110,
536
566
  scope: this,
537
567
  callSite: (f, a) => f(...a)
538
568
  });
@@ -553,7 +583,7 @@ var Peer = class {
553
583
  async initiateConnection() {
554
584
  (0, import_node_assert3.default)(!this.initiating, "Initiation in progress.");
555
585
  (0, import_node_assert3.default)(!this.connection, "Already connected.");
556
- const sessionId = import_keys2.PublicKey.random();
586
+ const sessionId = import_keys3.PublicKey.random();
557
587
  (0, import_log3.log)("initiating...", {
558
588
  id: this.id,
559
589
  topic: this.topic,
@@ -561,7 +591,7 @@ var Peer = class {
561
591
  sessionId
562
592
  }, {
563
593
  file: "peer.ts",
564
- line: 126,
594
+ line: 128,
565
595
  scope: this,
566
596
  callSite: (f, a) => f(...a)
567
597
  });
@@ -584,14 +614,14 @@ var Peer = class {
584
614
  remoteId: this.id
585
615
  }, {
586
616
  file: "peer.ts",
587
- line: 138,
617
+ line: 140,
588
618
  scope: this,
589
619
  callSite: (f, a) => f(...a)
590
620
  });
591
621
  if (connection.state !== ConnectionState.INITIAL) {
592
622
  (0, import_log3.log)("ignoring response", {}, {
593
623
  file: "peer.ts",
594
- line: 140,
624
+ line: 142,
595
625
  scope: this,
596
626
  callSite: (f, a) => f(...a)
597
627
  });
@@ -611,7 +641,7 @@ var Peer = class {
611
641
  err
612
642
  }, {
613
643
  file: "peer.ts",
614
- line: 151,
644
+ line: 153,
615
645
  scope: this,
616
646
  callSite: (f, a) => f(...a)
617
647
  });
@@ -634,7 +664,7 @@ var Peer = class {
634
664
  sessionId
635
665
  }, {
636
666
  file: "peer.ts",
637
- line: 165,
667
+ line: 167,
638
668
  scope: this,
639
669
  callSite: (f, a) => f(...a)
640
670
  });
@@ -655,6 +685,7 @@ var Peer = class {
655
685
  }),
656
686
  this._transportFactory
657
687
  );
688
+ connection._traceParent = this._traceParent;
658
689
  this._callbacks.onInitiated(connection);
659
690
  connection.stateChanged.on((state) => {
660
691
  switch (state) {
@@ -670,7 +701,7 @@ var Peer = class {
670
701
  initiator
671
702
  }, {
672
703
  file: "peer.ts",
673
- line: 194,
704
+ line: 197,
674
705
  scope: this,
675
706
  callSite: (f, a) => f(...a)
676
707
  });
@@ -690,7 +721,7 @@ var Peer = class {
690
721
  err
691
722
  }, {
692
723
  file: "peer.ts",
693
- line: 204,
724
+ line: 207,
694
725
  scope: this,
695
726
  callSite: (f, a) => f(...a)
696
727
  });
@@ -709,7 +740,7 @@ var Peer = class {
709
740
  sessionId: connection.sessionId
710
741
  }, {
711
742
  file: "peer.ts",
712
- line: 220,
743
+ line: 223,
713
744
  scope: this,
714
745
  callSite: (f, a) => f(...a)
715
746
  });
@@ -719,7 +750,7 @@ var Peer = class {
719
750
  sessionId: connection.sessionId
720
751
  }, {
721
752
  file: "peer.ts",
722
- line: 226,
753
+ line: 229,
723
754
  scope: this,
724
755
  callSite: (f, a) => f(...a)
725
756
  });
@@ -730,7 +761,7 @@ var Peer = class {
730
761
  message
731
762
  }, {
732
763
  file: "peer.ts",
733
- line: 231,
764
+ line: 234,
734
765
  scope: this,
735
766
  callSite: (f, a) => f(...a)
736
767
  });
@@ -745,7 +776,7 @@ var Peer = class {
745
776
  topic: this.topic
746
777
  }, {
747
778
  file: "peer.ts",
748
- line: 239,
779
+ line: 242,
749
780
  scope: this,
750
781
  callSite: (f, a) => f(...a)
751
782
  });
@@ -780,18 +811,18 @@ var Swarm = class {
780
811
  this._messenger = _messenger;
781
812
  this._transportFactory = _transportFactory;
782
813
  this._label = _label;
783
- this._peers = new import_util2.ComplexMap(import_keys3.PublicKey.hash);
814
+ this._peers = new import_util2.ComplexMap(import_keys4.PublicKey.hash);
784
815
  this._ctx = new import_context.Context();
785
816
  this.connectionAdded = new import_async3.Event();
786
817
  this.disconnected = new import_async3.Event();
787
818
  this.connected = new import_async3.Event();
788
819
  this.errors = new import_debug2.ErrorStream();
789
- this.instanceId = import_keys3.PublicKey.random();
820
+ this._instanceId = import_keys4.PublicKey.random().toHex();
790
821
  (0, import_log4.log)("creating swarm", {
791
822
  peerId: _ownPeerId
792
823
  }, {
793
824
  file: "swarm.ts",
794
- line: 83,
825
+ line: 84,
795
826
  scope: this,
796
827
  callSite: (f, a) => f(...a)
797
828
  });
@@ -808,10 +839,22 @@ var Swarm = class {
808
839
  onMessage: async (message) => await this._swarmMessenger.receiveMessage(message)
809
840
  }).catch((error) => import_log4.log.catch(error, {}, {
810
841
  file: "swarm.ts",
811
- line: 99,
842
+ line: 100,
812
843
  scope: this,
813
844
  callSite: (f, a) => f(...a)
814
845
  }));
846
+ import_log4.log.trace("dxos.mesh.swarm", import_protocols3.trace.begin({
847
+ id: this._instanceId,
848
+ data: {
849
+ topic: this._topic.toHex(),
850
+ peerId: this._ownPeerId.toHex()
851
+ }
852
+ }), {
853
+ file: "swarm.ts",
854
+ line: 102,
855
+ scope: this,
856
+ callSite: (f, a) => f(...a)
857
+ });
815
858
  }
816
859
  get connections() {
817
860
  return Array.from(this._peers.values()).map((peer) => peer.connection).filter(import_util2.isNotNullOrUndefined);
@@ -832,7 +875,7 @@ var Swarm = class {
832
875
  async destroy() {
833
876
  (0, import_log4.log)("destroying...", {}, {
834
877
  file: "swarm.ts",
835
- line: 127,
878
+ line: 133,
836
879
  scope: this,
837
880
  callSite: (f, a) => f(...a)
838
881
  });
@@ -841,7 +884,15 @@ var Swarm = class {
841
884
  await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key)));
842
885
  (0, import_log4.log)("destroyed", {}, {
843
886
  file: "swarm.ts",
844
- line: 131,
887
+ line: 137,
888
+ scope: this,
889
+ callSite: (f, a) => f(...a)
890
+ });
891
+ import_log4.log.trace("dxos.mesh.swarm", import_protocols3.trace.end({
892
+ id: this._instanceId
893
+ }), {
894
+ file: "swarm.ts",
895
+ line: 138,
845
896
  scope: this,
846
897
  callSite: (f, a) => f(...a)
847
898
  });
@@ -856,7 +907,7 @@ var Swarm = class {
856
907
  topology: getClassName(topology)
857
908
  }, {
858
909
  file: "swarm.ts",
859
- line: 139,
910
+ line: 146,
860
911
  scope: this,
861
912
  callSite: (f, a) => f(...a)
862
913
  });
@@ -871,26 +922,26 @@ var Swarm = class {
871
922
  swarmEvent
872
923
  }, {
873
924
  file: "swarm.ts",
874
- line: 152,
925
+ line: 159,
875
926
  scope: this,
876
927
  callSite: (f, a) => f(...a)
877
928
  });
878
929
  if (this._ctx.disposed) {
879
930
  (0, import_log4.log)("swarm event ignored for disposed swarm", {}, {
880
931
  file: "swarm.ts",
881
- line: 155,
932
+ line: 162,
882
933
  scope: this,
883
934
  callSite: (f, a) => f(...a)
884
935
  });
885
936
  return;
886
937
  }
887
938
  if (swarmEvent.peerAvailable) {
888
- const peerId = import_keys3.PublicKey.from(swarmEvent.peerAvailable.peer);
939
+ const peerId = import_keys4.PublicKey.from(swarmEvent.peerAvailable.peer);
889
940
  (0, import_log4.log)("new peer", {
890
941
  peerId
891
942
  }, {
892
943
  file: "swarm.ts",
893
- line: 161,
944
+ line: 168,
894
945
  scope: this,
895
946
  callSite: (f, a) => f(...a)
896
947
  });
@@ -899,13 +950,13 @@ var Swarm = class {
899
950
  peer.advertizing = true;
900
951
  }
901
952
  } else if (swarmEvent.peerLeft) {
902
- const peer1 = this._peers.get(import_keys3.PublicKey.from(swarmEvent.peerLeft.peer));
953
+ const peer1 = this._peers.get(import_keys4.PublicKey.from(swarmEvent.peerLeft.peer));
903
954
  if (peer1) {
904
955
  peer1.advertizing = false;
905
956
  if (((_a = peer1.connection) == null ? void 0 : _a.state) !== ConnectionState.CONNECTED) {
906
957
  void this._destroyPeer(peer1.id).catch((err) => import_log4.log.catch(err, {}, {
907
958
  file: "swarm.ts",
908
- line: 172,
959
+ line: 179,
909
960
  scope: this,
910
961
  callSite: (f, a) => f(...a)
911
962
  }));
@@ -920,14 +971,14 @@ var Swarm = class {
920
971
  message
921
972
  }, {
922
973
  file: "swarm.ts",
923
- line: 182,
974
+ line: 189,
924
975
  scope: this,
925
976
  callSite: (f, a) => f(...a)
926
977
  });
927
978
  if (this._ctx.disposed) {
928
979
  (0, import_log4.log)("ignored for disposed swarm", {}, {
929
980
  file: "swarm.ts",
930
- line: 184,
981
+ line: 191,
931
982
  scope: this,
932
983
  callSite: (f, a) => f(...a)
933
984
  });
@@ -941,7 +992,7 @@ var Swarm = class {
941
992
  message
942
993
  }, {
943
994
  file: "swarm.ts",
944
- line: 191,
995
+ line: 198,
945
996
  scope: this,
946
997
  callSite: (f, a) => f(...a)
947
998
  });
@@ -954,7 +1005,7 @@ var Swarm = class {
954
1005
  message
955
1006
  }, {
956
1007
  file: "swarm.ts",
957
- line: 195,
1008
+ line: 202,
958
1009
  scope: this,
959
1010
  callSite: (f, a) => f(...a)
960
1011
  });
@@ -973,14 +1024,14 @@ var Swarm = class {
973
1024
  message
974
1025
  }, {
975
1026
  file: "swarm.ts",
976
- line: 207,
1027
+ line: 214,
977
1028
  scope: this,
978
1029
  callSite: (f, a) => f(...a)
979
1030
  });
980
1031
  if (this._ctx.disposed) {
981
1032
  import_log4.log.info("ignored for offline swarm", {}, {
982
1033
  file: "swarm.ts",
983
- line: 209,
1034
+ line: 216,
984
1035
  scope: this,
985
1036
  callSite: (f, a) => f(...a)
986
1037
  });
@@ -1032,6 +1083,7 @@ var Swarm = class {
1032
1083
  return this._topology.onOffer(remoteId);
1033
1084
  }
1034
1085
  });
1086
+ peer._traceParent = this._instanceId;
1035
1087
  this._peers.set(peerId, peer);
1036
1088
  }
1037
1089
  return peer;
@@ -1058,7 +1110,7 @@ var Swarm = class {
1058
1110
  } catch (err) {
1059
1111
  import_log4.log.warn("initiation error", err, {
1060
1112
  file: "swarm.ts",
1061
- line: 309,
1113
+ line: 317,
1062
1114
  scope: this,
1063
1115
  callSite: (f, a) => f(...a)
1064
1116
  });
@@ -1086,7 +1138,7 @@ var Swarm = class {
1086
1138
  remoteId
1087
1139
  }, {
1088
1140
  file: "swarm.ts",
1089
- line: 336,
1141
+ line: 344,
1090
1142
  scope: this,
1091
1143
  callSite: (f, a) => f(...a)
1092
1144
  });
@@ -1103,7 +1155,7 @@ var Swarm = class {
1103
1155
  remoteId
1104
1156
  }, {
1105
1157
  file: "swarm.ts",
1106
- line: 350,
1158
+ line: 358,
1107
1159
  scope: this,
1108
1160
  callSite: (f, a) => f(...a)
1109
1161
  });
@@ -1113,7 +1165,7 @@ var Swarm = class {
1113
1165
  remoteId
1114
1166
  }, {
1115
1167
  file: "swarm.ts",
1116
- line: 353,
1168
+ line: 361,
1117
1169
  scope: this,
1118
1170
  callSite: (f, a) => f(...a)
1119
1171
  });
@@ -1128,7 +1180,7 @@ var Swarm = class {
1128
1180
  };
1129
1181
  __decorate3([
1130
1182
  import_log4.logInfo
1131
- ], Swarm.prototype, "instanceId", void 0);
1183
+ ], Swarm.prototype, "_instanceId", void 0);
1132
1184
  __decorate3([
1133
1185
  import_log4.logInfo
1134
1186
  ], Swarm.prototype, "ownPeerId", null);
@@ -1153,7 +1205,7 @@ __decorate3([
1153
1205
 
1154
1206
  // packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts
1155
1207
  var import_async4 = require("@dxos/async");
1156
- var import_keys4 = require("@dxos/keys");
1208
+ var import_keys5 = require("@dxos/keys");
1157
1209
  var import_log5 = require("@dxos/log");
1158
1210
  var import_util3 = require("@dxos/util");
1159
1211
  var SwarmMapper = class {
@@ -1164,8 +1216,8 @@ var SwarmMapper = class {
1164
1216
  constructor(_swarm) {
1165
1217
  this._swarm = _swarm;
1166
1218
  this._subscriptions = new import_async4.EventSubscriptions();
1167
- this._connectionSubscriptions = new import_util3.ComplexMap(import_keys4.PublicKey.hash);
1168
- this._peers = new import_util3.ComplexMap(import_keys4.PublicKey.hash);
1219
+ this._connectionSubscriptions = new import_util3.ComplexMap(import_keys5.PublicKey.hash);
1220
+ this._peers = new import_util3.ComplexMap(import_keys5.PublicKey.hash);
1169
1221
  this.mapUpdated = new import_async4.Event();
1170
1222
  this._subscriptions.add(_swarm.connectionAdded.on((connection) => {
1171
1223
  this._update();
@@ -1235,7 +1287,7 @@ var ConnectionLog = class {
1235
1287
  /**
1236
1288
  * SwarmId => info
1237
1289
  */
1238
- this._swarms = new import_util4.ComplexMap(import_keys5.PublicKey.hash);
1290
+ this._swarms = new import_util4.ComplexMap(import_keys6.PublicKey.hash);
1239
1291
  this.update = new import_async5.Event();
1240
1292
  }
1241
1293
  getSwarmInfo(swarmId) {
@@ -1247,13 +1299,13 @@ var ConnectionLog = class {
1247
1299
  }
1248
1300
  joinedSwarm(swarm) {
1249
1301
  const info = {
1250
- id: swarm.instanceId,
1302
+ id: import_keys6.PublicKey.from(swarm._instanceId),
1251
1303
  topic: swarm.topic,
1252
1304
  isActive: true,
1253
1305
  label: swarm.label,
1254
1306
  connections: []
1255
1307
  };
1256
- this._swarms.set(swarm.instanceId, info);
1308
+ this._swarms.set(import_keys6.PublicKey.from(swarm._instanceId), info);
1257
1309
  this.update.emit();
1258
1310
  swarm.connectionAdded.on((connection) => {
1259
1311
  const connectionInfo = {
@@ -1277,7 +1329,7 @@ var ConnectionLog = class {
1277
1329
  });
1278
1330
  }
1279
1331
  leftSwarm(swarm) {
1280
- this.getSwarmInfo(swarm.instanceId).isActive = false;
1332
+ this.getSwarmInfo(import_keys6.PublicKey.from(swarm._instanceId)).isActive = false;
1281
1333
  this.update.emit();
1282
1334
  }
1283
1335
  };
@@ -1285,11 +1337,12 @@ var ConnectionLog = class {
1285
1337
  // packages/core/mesh/network-manager/src/network-manager.ts
1286
1338
  var NetworkManager = class {
1287
1339
  constructor({ transportFactory, signalManager, log: log14 }) {
1288
- this._swarms = new import_util5.ComplexMap(import_keys6.PublicKey.hash);
1289
- this._mappers = new import_util5.ComplexMap(import_keys6.PublicKey.hash);
1340
+ this._swarms = new import_util5.ComplexMap(import_keys7.PublicKey.hash);
1341
+ this._mappers = new import_util5.ComplexMap(import_keys7.PublicKey.hash);
1290
1342
  this._connectionState = import_services.ConnectionState.ONLINE;
1291
1343
  this.connectionStateChanged = new import_async6.Event();
1292
1344
  this.topicsUpdated = new import_async6.Event();
1345
+ this._instanceId = import_keys7.PublicKey.random().toHex();
1293
1346
  this._transportFactory = transportFactory;
1294
1347
  this._signalManager = signalManager;
1295
1348
  this._signalManager.swarmEvent.on(({ topic, swarmEvent: event }) => {
@@ -1299,6 +1352,7 @@ var NetworkManager = class {
1299
1352
  this._messenger = new import_messaging.Messenger({
1300
1353
  signalManager: this._signalManager
1301
1354
  });
1355
+ this._messenger._traceParent = this._instanceId;
1302
1356
  this._signalConnection = {
1303
1357
  join: (opts) => this._signalManager.join(opts),
1304
1358
  leave: (opts) => this._signalManager.leave(opts)
@@ -1329,6 +1383,14 @@ var NetworkManager = class {
1329
1383
  return this._swarms.get(topic);
1330
1384
  }
1331
1385
  async open() {
1386
+ import_log6.log.trace("dxos.mesh.network-manager", import_protocols4.trace.begin({
1387
+ id: this._instanceId
1388
+ }), {
1389
+ file: "network-manager.ts",
1390
+ line: 133,
1391
+ scope: this,
1392
+ callSite: (f, a) => f(...a)
1393
+ });
1332
1394
  await this._messenger.open();
1333
1395
  await this._signalManager.open();
1334
1396
  }
@@ -1337,7 +1399,7 @@ var NetworkManager = class {
1337
1399
  await this.leaveSwarm(topic).catch((err) => {
1338
1400
  (0, import_log6.log)(err, {}, {
1339
1401
  file: "network-manager.ts",
1340
- line: 136,
1402
+ line: 141,
1341
1403
  scope: this,
1342
1404
  callSite: (f, a) => f(...a)
1343
1405
  });
@@ -1345,26 +1407,34 @@ var NetworkManager = class {
1345
1407
  }
1346
1408
  await this._messenger.close();
1347
1409
  await this._signalManager.close();
1410
+ import_log6.log.trace("dxos.mesh.network-manager", import_protocols4.trace.end({
1411
+ id: this._instanceId
1412
+ }), {
1413
+ file: "network-manager.ts",
1414
+ line: 147,
1415
+ scope: this,
1416
+ callSite: (f, a) => f(...a)
1417
+ });
1348
1418
  }
1349
1419
  /**
1350
1420
  * Join the swarm.
1351
1421
  */
1352
1422
  async joinSwarm({ topic, peerId, topology, protocolProvider: protocol, label }) {
1353
1423
  var _a;
1354
- (0, import_node_assert5.default)(import_keys6.PublicKey.isPublicKey(topic));
1355
- (0, import_node_assert5.default)(import_keys6.PublicKey.isPublicKey(peerId));
1424
+ (0, import_node_assert5.default)(import_keys7.PublicKey.isPublicKey(topic));
1425
+ (0, import_node_assert5.default)(import_keys7.PublicKey.isPublicKey(peerId));
1356
1426
  (0, import_node_assert5.default)(topology);
1357
1427
  (0, import_node_assert5.default)(typeof protocol === "function");
1358
1428
  if (this._swarms.has(topic)) {
1359
- throw new Error(`Already connected to swarm: ${import_keys6.PublicKey.from(topic)}`);
1429
+ throw new Error(`Already connected to swarm: ${import_keys7.PublicKey.from(topic)}`);
1360
1430
  }
1361
1431
  (0, import_log6.log)("joining", {
1362
- topic: import_keys6.PublicKey.from(topic),
1432
+ topic: import_keys7.PublicKey.from(topic),
1363
1433
  peerId,
1364
1434
  topology: topology.toString()
1365
1435
  }, {
1366
1436
  file: "network-manager.ts",
1367
- line: 162,
1437
+ line: 168,
1368
1438
  scope: this,
1369
1439
  callSite: (f, a) => f(...a)
1370
1440
  });
@@ -1374,7 +1444,7 @@ var NetworkManager = class {
1374
1444
  error
1375
1445
  }, {
1376
1446
  file: "network-manager.ts",
1377
- line: 165,
1447
+ line: 171,
1378
1448
  scope: this,
1379
1449
  callSite: (f, a) => f(...a)
1380
1450
  });
@@ -1385,7 +1455,7 @@ var NetworkManager = class {
1385
1455
  peerId
1386
1456
  }).catch((error) => import_log6.log.catch(error, {}, {
1387
1457
  file: "network-manager.ts",
1388
- line: 169,
1458
+ line: 175,
1389
1459
  scope: this,
1390
1460
  callSite: (f, a) => f(...a)
1391
1461
  }));
@@ -1393,11 +1463,11 @@ var NetworkManager = class {
1393
1463
  this.topicsUpdated.emit();
1394
1464
  (_a = this._connectionLog) == null ? void 0 : _a.joinedSwarm(swarm);
1395
1465
  (0, import_log6.log)("joined", {
1396
- topic: import_keys6.PublicKey.from(topic),
1466
+ topic: import_keys7.PublicKey.from(topic),
1397
1467
  count: this._swarms.size
1398
1468
  }, {
1399
1469
  file: "network-manager.ts",
1400
- line: 174,
1470
+ line: 180,
1401
1471
  scope: this,
1402
1472
  callSite: (f, a) => f(...a)
1403
1473
  });
@@ -1412,20 +1482,20 @@ var NetworkManager = class {
1412
1482
  var _a;
1413
1483
  if (!this._swarms.has(topic)) {
1414
1484
  import_log6.log.warn("swarm not open", {
1415
- topic: import_keys6.PublicKey.from(topic).truncate()
1485
+ topic: import_keys7.PublicKey.from(topic).truncate()
1416
1486
  }, {
1417
1487
  file: "network-manager.ts",
1418
- line: 186,
1488
+ line: 192,
1419
1489
  scope: this,
1420
1490
  callSite: (f, a) => f(...a)
1421
1491
  });
1422
1492
  return;
1423
1493
  }
1424
1494
  (0, import_log6.log)("leaving", {
1425
- topic: import_keys6.PublicKey.from(topic)
1495
+ topic: import_keys7.PublicKey.from(topic)
1426
1496
  }, {
1427
1497
  file: "network-manager.ts",
1428
- line: 190,
1498
+ line: 196,
1429
1499
  scope: this,
1430
1500
  callSite: (f, a) => f(...a)
1431
1501
  });
@@ -1442,11 +1512,11 @@ var NetworkManager = class {
1442
1512
  this._swarms.delete(topic);
1443
1513
  await this.topicsUpdated.emit();
1444
1514
  (0, import_log6.log)("left", {
1445
- topic: import_keys6.PublicKey.from(topic),
1515
+ topic: import_keys7.PublicKey.from(topic),
1446
1516
  count: this._swarms.size
1447
1517
  }, {
1448
1518
  file: "network-manager.ts",
1449
- line: 204,
1519
+ line: 210,
1450
1520
  scope: this,
1451
1521
  callSite: (f, a) => f(...a)
1452
1522
  });
@@ -1515,7 +1585,7 @@ var import_node_assert7 = __toESM(require("node:assert"));
1515
1585
  var import_node_stream = require("node:stream");
1516
1586
  var import_async7 = require("@dxos/async");
1517
1587
  var import_debug4 = require("@dxos/debug");
1518
- var import_keys7 = require("@dxos/keys");
1588
+ var import_keys8 = require("@dxos/keys");
1519
1589
  var import_log9 = require("@dxos/log");
1520
1590
  var import_util6 = require("@dxos/util");
1521
1591
  var __decorate4 = function(decorators, target, key, desc) {
@@ -1551,7 +1621,7 @@ var _MemoryTransport = class {
1551
1621
  this._outgoingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
1552
1622
  this._incomingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
1553
1623
  this._destroyed = false;
1554
- this._instanceId = import_keys7.PublicKey.random();
1624
+ this._instanceId = import_keys8.PublicKey.random();
1555
1625
  (0, import_log9.log)("creating", {}, {
1556
1626
  file: "memory-transport.ts",
1557
1627
  line: 64,
@@ -1660,14 +1730,14 @@ var _MemoryTransport = class {
1660
1730
  }
1661
1731
  const transportId = payload.transportId;
1662
1732
  if (transportId) {
1663
- const remoteId = import_keys7.PublicKey.fromHex(transportId);
1733
+ const remoteId = import_keys8.PublicKey.fromHex(transportId);
1664
1734
  this._remote.wake(remoteId);
1665
1735
  }
1666
1736
  }
1667
1737
  };
1668
1738
  var MemoryTransport = _MemoryTransport;
1669
1739
  // TODO(burdon): Remove static properties (inject context into constructor).
1670
- MemoryTransport._connections = new import_util6.ComplexMap(import_keys7.PublicKey.hash);
1740
+ MemoryTransport._connections = new import_util6.ComplexMap(import_keys8.PublicKey.hash);
1671
1741
  __decorate4([
1672
1742
  import_log9.logInfo
1673
1743
  ], MemoryTransport.prototype, "_instanceId", void 0);
@@ -1680,7 +1750,9 @@ var import_node_assert8 = __toESM(require("node:assert"));
1680
1750
  var import_simple_peer = __toESM(require("simple-peer"));
1681
1751
  var import_async8 = require("@dxos/async");
1682
1752
  var import_debug5 = require("@dxos/debug");
1753
+ var import_keys9 = require("@dxos/keys");
1683
1754
  var import_log10 = require("@dxos/log");
1755
+ var import_protocols5 = require("@dxos/protocols");
1684
1756
 
1685
1757
  // packages/core/mesh/network-manager/src/transport/webrtc.ts
1686
1758
  var wrtc = null;
@@ -1698,9 +1770,22 @@ var WebRTCTransport = class {
1698
1770
  this.closed = new import_async8.Event();
1699
1771
  this.connected = new import_async8.Event();
1700
1772
  this.errors = new import_debug5.ErrorStream();
1773
+ this._instanceId = import_keys9.PublicKey.random().toHex();
1774
+ this._performance = {
1775
+ bytesSent: 0,
1776
+ bytesReceived: 0
1777
+ };
1778
+ import_log10.log.trace("dxos.mesh.webrtc-transport", import_protocols5.trace.begin({
1779
+ id: this._instanceId
1780
+ }), {
1781
+ file: "webrtc-transport.ts",
1782
+ line: 43,
1783
+ scope: this,
1784
+ callSite: (f, a) => f(...a)
1785
+ });
1701
1786
  (0, import_log10.log)("created connection", params, {
1702
1787
  file: "webrtc-transport.ts",
1703
- line: 35,
1788
+ line: 44,
1704
1789
  scope: this,
1705
1790
  callSite: (f, a) => f(...a)
1706
1791
  });
@@ -1712,7 +1797,7 @@ var WebRTCTransport = class {
1712
1797
  this._peer.on("signal", async (data) => {
1713
1798
  (0, import_log10.log)("signal", data, {
1714
1799
  file: "webrtc-transport.ts",
1715
- line: 43,
1800
+ line: 52,
1716
1801
  scope: this,
1717
1802
  callSite: (f, a) => f(...a)
1718
1803
  });
@@ -1725,7 +1810,7 @@ var WebRTCTransport = class {
1725
1810
  this._peer.on("connect", () => {
1726
1811
  (0, import_log10.log)("connected", {}, {
1727
1812
  file: "webrtc-transport.ts",
1728
- line: 48,
1813
+ line: 57,
1729
1814
  scope: this,
1730
1815
  callSite: (f, a) => f(...a)
1731
1816
  });
@@ -1735,7 +1820,7 @@ var WebRTCTransport = class {
1735
1820
  this._peer.on("close", async () => {
1736
1821
  (0, import_log10.log)("closed", {}, {
1737
1822
  file: "webrtc-transport.ts",
1738
- line: 54,
1823
+ line: 63,
1739
1824
  scope: this,
1740
1825
  callSite: (f, a) => f(...a)
1741
1826
  });
@@ -1753,7 +1838,7 @@ var WebRTCTransport = class {
1753
1838
  stats
1754
1839
  }, {
1755
1840
  file: "webrtc-transport.ts",
1756
- line: 66,
1841
+ line: 75,
1757
1842
  scope: this,
1758
1843
  callSite: (f, a) => f(...a)
1759
1844
  });
@@ -1767,7 +1852,7 @@ var WebRTCTransport = class {
1767
1852
  async destroy() {
1768
1853
  (0, import_log10.log)("closing...", {}, {
1769
1854
  file: "webrtc-transport.ts",
1770
- line: 79,
1855
+ line: 88,
1771
1856
  scope: this,
1772
1857
  callSite: (f, a) => f(...a)
1773
1858
  });
@@ -1777,7 +1862,18 @@ var WebRTCTransport = class {
1777
1862
  this.closed.emit();
1778
1863
  (0, import_log10.log)("closed", {}, {
1779
1864
  file: "webrtc-transport.ts",
1780
- line: 84,
1865
+ line: 93,
1866
+ scope: this,
1867
+ callSite: (f, a) => f(...a)
1868
+ });
1869
+ import_log10.log.trace("dxos.mesh.webrtc-transport", import_protocols5.trace.end({
1870
+ id: this._instanceId,
1871
+ data: {
1872
+ performance: this._performance
1873
+ }
1874
+ }), {
1875
+ file: "webrtc-transport.ts",
1876
+ line: 94,
1781
1877
  scope: this,
1782
1878
  callSite: (f, a) => f(...a)
1783
1879
  });
@@ -1799,7 +1895,7 @@ var WebRTCTransport = class {
1799
1895
  var import_node_assert9 = __toESM(require("node:assert"));
1800
1896
  var import_node_stream2 = require("node:stream");
1801
1897
  var import_codec_protobuf = require("@dxos/codec-protobuf");
1802
- var import_keys8 = require("@dxos/keys");
1898
+ var import_keys10 = require("@dxos/keys");
1803
1899
  var import_log11 = require("@dxos/log");
1804
1900
  var import_bridge = require("@dxos/protocols/proto/dxos/mesh/bridge");
1805
1901
  var import_util7 = require("@dxos/util");
@@ -1807,7 +1903,7 @@ var WebRTCTransportService = class {
1807
1903
  // prettier-ignore
1808
1904
  constructor(_webrtcConfig) {
1809
1905
  this._webrtcConfig = _webrtcConfig;
1810
- this.transports = new import_util7.ComplexMap(import_keys8.PublicKey.hash);
1906
+ this.transports = new import_util7.ComplexMap(import_keys10.PublicKey.hash);
1811
1907
  }
1812
1908
  open(request) {
1813
1909
  const rpcStream = new import_codec_protobuf.Stream(({ ready, next, close }) => {
@@ -1898,14 +1994,14 @@ var import_node_assert10 = __toESM(require("node:assert"));
1898
1994
  var import_async9 = require("@dxos/async");
1899
1995
  var import_context2 = require("@dxos/context");
1900
1996
  var import_debug6 = require("@dxos/debug");
1901
- var import_keys9 = require("@dxos/keys");
1997
+ var import_keys11 = require("@dxos/keys");
1902
1998
  var import_log12 = require("@dxos/log");
1903
1999
  var import_bridge2 = require("@dxos/protocols/proto/dxos/mesh/bridge");
1904
2000
  var WebRTCTransportProxy = class {
1905
2001
  // prettier-ignore
1906
2002
  constructor(_params) {
1907
2003
  this._params = _params;
1908
- this._proxyId = import_keys9.PublicKey.random();
2004
+ this._proxyId = import_keys11.PublicKey.random();
1909
2005
  this._ctx = new import_context2.Context();
1910
2006
  this.closed = new import_async9.Event();
1911
2007
  this._closed = false;
@@ -2045,7 +2141,7 @@ var WebRTCTransportProxyFactory = class {
2045
2141
 
2046
2142
  // packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts
2047
2143
  var import_async10 = require("@dxos/async");
2048
- var import_keys10 = require("@dxos/keys");
2144
+ var import_keys12 = require("@dxos/keys");
2049
2145
  var import_log13 = require("@dxos/log");
2050
2146
  var import_teleport2 = require("@dxos/teleport");
2051
2147
  var import_util8 = require("@dxos/util");
@@ -2072,7 +2168,7 @@ var createTeleportProtocolFactory = (onConnection) => {
2072
2168
  var TestWireProtocol = class {
2073
2169
  constructor(peerId) {
2074
2170
  this.peerId = peerId;
2075
- this.connections = new import_util8.ComplexMap(import_keys10.PublicKey.hash);
2171
+ this.connections = new import_util8.ComplexMap(import_keys12.PublicKey.hash);
2076
2172
  this.connected = new import_async10.Event();
2077
2173
  this.disconnected = new import_async10.Event();
2078
2174
  this.factory = createTeleportProtocolFactory(async (teleport) => {
@@ -2136,8 +2232,8 @@ var TestBuilder = class {
2136
2232
  var TestPeer = class {
2137
2233
  constructor(testBuilder) {
2138
2234
  this.testBuilder = testBuilder;
2139
- this.peerId = import_keys11.PublicKey.random();
2140
- this._swarms = new import_util9.ComplexMap(import_keys11.PublicKey.hash);
2235
+ this.peerId = import_keys13.PublicKey.random();
2236
+ this._swarms = new import_util9.ComplexMap(import_keys13.PublicKey.hash);
2141
2237
  this._networkManager = this.createNetworkManager();
2142
2238
  }
2143
2239
  // TODO(burdon): Move to TestBuilder.
@@ -2149,7 +2245,7 @@ var TestPeer = class {
2149
2245
  this._proxy = (0, import_rpc.createProtoRpcPeer)({
2150
2246
  port: proxyPort,
2151
2247
  requested: {
2152
- BridgeService: import_protocols2.schema.getService("dxos.mesh.bridge.BridgeService")
2248
+ BridgeService: import_protocols6.schema.getService("dxos.mesh.bridge.BridgeService")
2153
2249
  },
2154
2250
  noHandshake: true,
2155
2251
  encodingOptions: {
@@ -2159,7 +2255,7 @@ var TestPeer = class {
2159
2255
  this._service = (0, import_rpc.createProtoRpcPeer)({
2160
2256
  port: servicePort,
2161
2257
  exposed: {
2162
- BridgeService: import_protocols2.schema.getService("dxos.mesh.bridge.BridgeService")
2258
+ BridgeService: import_protocols6.schema.getService("dxos.mesh.bridge.BridgeService")
2163
2259
  },
2164
2260
  handlers: {
2165
2261
  BridgeService: new WebRTCTransportService()