@dxos/network-manager 0.1.17 → 0.1.19

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 (60) hide show
  1. package/dist/lib/browser/index.mjs +221 -352
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/browser/testing/index.mjs +222 -410
  5. package/dist/lib/browser/testing/index.mjs.map +4 -4
  6. package/dist/lib/node/index.cjs +222 -357
  7. package/dist/lib/node/index.cjs.map +4 -4
  8. package/dist/lib/node/meta.json +1 -1
  9. package/dist/lib/node/testing/index.cjs +222 -413
  10. package/dist/lib/node/testing/index.cjs.map +4 -4
  11. package/dist/types/src/index.d.ts +0 -1
  12. package/dist/types/src/index.d.ts.map +1 -1
  13. package/dist/types/src/network-manager.d.ts +1 -5
  14. package/dist/types/src/network-manager.d.ts.map +1 -1
  15. package/dist/types/src/swarm/connection.d.ts +4 -0
  16. package/dist/types/src/swarm/connection.d.ts.map +1 -1
  17. package/dist/types/src/swarm/peer.d.ts.map +1 -1
  18. package/dist/types/src/swarm/swarm-mapper.d.ts +1 -3
  19. package/dist/types/src/swarm/swarm-mapper.d.ts.map +1 -1
  20. package/dist/types/src/testing/index.d.ts +0 -1
  21. package/dist/types/src/testing/index.d.ts.map +1 -1
  22. package/dist/types/src/testing/test-builder.d.ts +2 -2
  23. package/dist/types/src/testing/test-builder.d.ts.map +1 -1
  24. package/dist/types/src/testing/test-wire-protocol.d.ts +14 -0
  25. package/dist/types/src/testing/test-wire-protocol.d.ts.map +1 -0
  26. package/dist/types/src/tests/basic-test-suite.d.ts.map +1 -1
  27. package/dist/types/src/tests/property-test-suite.d.ts.map +1 -1
  28. package/dist/types/src/tests/utils.d.ts.map +1 -1
  29. package/dist/types/src/transport/memory-transport.d.ts +3 -3
  30. package/dist/types/src/transport/memory-transport.d.ts.map +1 -1
  31. package/dist/types/src/wire-protocol.d.ts +0 -10
  32. package/dist/types/src/wire-protocol.d.ts.map +1 -1
  33. package/package.json +16 -18
  34. package/src/connection-log.ts +26 -26
  35. package/src/index.ts +0 -1
  36. package/src/network-manager.ts +1 -8
  37. package/src/swarm/connection.ts +12 -1
  38. package/src/swarm/peer.ts +1 -3
  39. package/src/swarm/swarm-mapper.ts +29 -31
  40. package/src/swarm/swarm.test.ts +12 -34
  41. package/src/testing/index.ts +0 -1
  42. package/src/testing/test-builder.ts +4 -7
  43. package/src/testing/test-wire-protocol.ts +44 -0
  44. package/src/tests/basic-test-suite.ts +13 -53
  45. package/src/tests/property-test-suite.ts +13 -15
  46. package/src/tests/utils.ts +10 -37
  47. package/src/transport/memory-transport.test.ts +13 -52
  48. package/src/transport/memory-transport.ts +37 -29
  49. package/src/transport/webrtc-transport-proxy.test.ts +13 -73
  50. package/src/transport/webrtc-transport.test.ts +7 -38
  51. package/src/wire-protocol.ts +0 -24
  52. package/dist/types/src/protocol-factory.d.ts +0 -36
  53. package/dist/types/src/protocol-factory.d.ts.map +0 -1
  54. package/dist/types/src/testing/test-protocol.d.ts +0 -52
  55. package/dist/types/src/testing/test-protocol.d.ts.map +0 -1
  56. package/dist/types/src/tests/presence.test.d.ts +0 -2
  57. package/dist/types/src/tests/presence.test.d.ts.map +0 -1
  58. package/src/protocol-factory.ts +0 -88
  59. package/src/testing/test-protocol.ts +0 -166
  60. package/src/tests/presence.test.ts +0 -80
@@ -8,11 +8,11 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
8
8
  });
9
9
 
10
10
  // packages/core/mesh/network-manager/src/testing/test-builder.ts
11
- import { PublicKey as PublicKey12 } from "@dxos/keys";
11
+ import { PublicKey as PublicKey11 } from "@dxos/keys";
12
12
  import { MemorySignalManager, MemorySignalManagerContext, WebsocketSignalManager } from "@dxos/messaging";
13
13
  import { schema as schema2 } from "@dxos/protocols";
14
14
  import { createLinkedPorts, createProtoRpcPeer } from "@dxos/rpc";
15
- import { ComplexMap as ComplexMap8 } from "@dxos/util";
15
+ import { ComplexMap as ComplexMap9 } from "@dxos/util";
16
16
 
17
17
  // packages/core/mesh/network-manager/src/network-manager.ts
18
18
  import assert5 from "@dxos/node-std/assert";
@@ -48,6 +48,7 @@ var ConnectionState;
48
48
  ConnectionState4["INITIAL"] = "INITIAL";
49
49
  ConnectionState4["CONNECTING"] = "CONNECTING";
50
50
  ConnectionState4["CONNECTED"] = "CONNECTED";
51
+ ConnectionState4["CLOSING"] = "CLOSING";
51
52
  ConnectionState4["CLOSED"] = "CLOSED";
52
53
  })(ConnectionState || (ConnectionState = {}));
53
54
  var Connection = class {
@@ -103,7 +104,11 @@ var Connection = class {
103
104
  this._transport = void 0;
104
105
  this.close().catch((err) => this.errors.raise(err));
105
106
  });
106
- this._transport.errors.pipeTo(this.errors);
107
+ this._transport.errors.handle((err) => {
108
+ if (this._state !== ConnectionState.CLOSED && this._state !== ConnectionState.CLOSING) {
109
+ this.errors.raise(err);
110
+ }
111
+ });
107
112
  for (const signal of this._bufferedSignals) {
108
113
  void this._transport.signal(signal);
109
114
  }
@@ -114,11 +119,12 @@ var Connection = class {
114
119
  if (this._state === ConnectionState.CLOSED) {
115
120
  return;
116
121
  }
122
+ this._changeState(ConnectionState.CLOSING);
117
123
  log("closing...", {
118
124
  peerId: this.ownId
119
125
  }, {
120
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts",
121
- line: 131,
126
+ file: "connection.ts",
127
+ line: 142,
122
128
  scope: this,
123
129
  callSite: (f, a) => f(...a)
124
130
  });
@@ -126,8 +132,8 @@ var Connection = class {
126
132
  await this._protocol.destroy();
127
133
  } catch (err) {
128
134
  log.catch(err, {}, {
129
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts",
130
- line: 137,
135
+ file: "connection.ts",
136
+ line: 148,
131
137
  scope: this,
132
138
  callSite: (f, a) => f(...a)
133
139
  });
@@ -136,8 +142,8 @@ var Connection = class {
136
142
  await ((_a = this._transport) == null ? void 0 : _a.destroy());
137
143
  } catch (err1) {
138
144
  log.catch(err1, {}, {
139
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts",
140
- line: 144,
145
+ file: "connection.ts",
146
+ line: 155,
141
147
  scope: this,
142
148
  callSite: (f, a) => f(...a)
143
149
  });
@@ -145,8 +151,8 @@ var Connection = class {
145
151
  log("closed", {
146
152
  peerId: this.ownId
147
153
  }, {
148
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts",
149
- line: 147,
154
+ file: "connection.ts",
155
+ line: 158,
150
156
  scope: this,
151
157
  callSite: (f, a) => f(...a)
152
158
  });
@@ -157,8 +163,8 @@ var Connection = class {
157
163
  assert(msg.sessionId);
158
164
  if (!msg.sessionId.equals(this.sessionId)) {
159
165
  log("dropping signal for incorrect session id", {}, {
160
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts",
161
- line: 154,
166
+ file: "connection.ts",
167
+ line: 165,
162
168
  scope: this,
163
169
  callSite: (f, a) => f(...a)
164
170
  });
@@ -173,8 +179,8 @@ var Connection = class {
173
179
  remoteId: this.remoteId,
174
180
  msg: msg.data
175
181
  }, {
176
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts",
177
- line: 162,
182
+ file: "connection.ts",
183
+ line: 173,
178
184
  scope: this,
179
185
  callSite: (f, a) => f(...a)
180
186
  });
@@ -187,8 +193,8 @@ var Connection = class {
187
193
  remoteId: this.remoteId,
188
194
  msg: msg.data
189
195
  }, {
190
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts",
191
- line: 168,
196
+ file: "connection.ts",
197
+ line: 179,
192
198
  scope: this,
193
199
  callSite: (f, a) => f(...a)
194
200
  });
@@ -241,7 +247,7 @@ var MessageRouter = class {
241
247
  to: recipient,
242
248
  msg: message
243
249
  }, {
244
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/signal/message-router.ts",
250
+ file: "message-router.ts",
245
251
  line: 67,
246
252
  scope: this,
247
253
  callSite: (f, a) => f(...a)
@@ -299,7 +305,7 @@ var MessageRouter = class {
299
305
  to: recipient,
300
306
  msg: networkMessage
301
307
  }, {
302
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/signal/message-router.ts",
308
+ file: "message-router.ts",
303
309
  line: 117,
304
310
  scope: this,
305
311
  callSite: (f, a) => f(...a)
@@ -330,7 +336,7 @@ var MessageRouter = class {
330
336
  log2("resolving", {
331
337
  answer: message.data.answer
332
338
  }, {
333
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/signal/message-router.ts",
339
+ file: "message-router.ts",
334
340
  line: 146,
335
341
  scope: this,
336
342
  callSite: (f, a) => f(...a)
@@ -413,7 +419,7 @@ var Peer = class {
413
419
  topic: this.topic,
414
420
  peerId: this.localPeerId
415
421
  }, {
416
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
422
+ file: "peer.ts",
417
423
  line: 83,
418
424
  scope: this,
419
425
  callSite: (f, a) => f(...a)
@@ -440,7 +446,7 @@ var Peer = class {
440
446
  remoteId: this.id,
441
447
  err
442
448
  }, {
443
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
449
+ file: "peer.ts",
444
450
  line: 107,
445
451
  scope: this,
446
452
  callSite: (f, a) => f(...a)
@@ -466,7 +472,7 @@ var Peer = class {
466
472
  peerId: this.id,
467
473
  sessionId
468
474
  }, {
469
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
475
+ file: "peer.ts",
470
476
  line: 125,
471
477
  scope: this,
472
478
  callSite: (f, a) => f(...a)
@@ -489,14 +495,14 @@ var Peer = class {
489
495
  ownId: this.localPeerId,
490
496
  remoteId: this.id
491
497
  }, {
492
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
498
+ file: "peer.ts",
493
499
  line: 137,
494
500
  scope: this,
495
501
  callSite: (f, a) => f(...a)
496
502
  });
497
503
  if (connection.state !== ConnectionState.INITIAL) {
498
504
  log3("ignoring response", {}, {
499
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
505
+ file: "peer.ts",
500
506
  line: 139,
501
507
  scope: this,
502
508
  callSite: (f, a) => f(...a)
@@ -516,7 +522,7 @@ var Peer = class {
516
522
  remoteId: this.id,
517
523
  err
518
524
  }, {
519
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
525
+ file: "peer.ts",
520
526
  line: 150,
521
527
  scope: this,
522
528
  callSite: (f, a) => f(...a)
@@ -535,7 +541,7 @@ var Peer = class {
535
541
  initiator,
536
542
  sessionId
537
543
  }, {
538
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
544
+ file: "peer.ts",
539
545
  line: 164,
540
546
  scope: this,
541
547
  callSite: (f, a) => f(...a)
@@ -570,7 +576,7 @@ var Peer = class {
570
576
  remoteId: this.id,
571
577
  initiator
572
578
  }, {
573
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
579
+ file: "peer.ts",
574
580
  line: 193,
575
581
  scope: this,
576
582
  callSite: (f, a) => f(...a)
@@ -590,19 +596,12 @@ var Peer = class {
590
596
  initiator,
591
597
  err
592
598
  }, {
593
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
599
+ file: "peer.ts",
594
600
  line: 203,
595
601
  scope: this,
596
602
  callSite: (f, a) => f(...a)
597
603
  });
598
- void this.closeConnection().catch(() => {
599
- log3.catch(err, {}, {
600
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
601
- line: 207,
602
- scope: this,
603
- callSite: (f, a) => f(...a)
604
- });
605
- });
604
+ void this.closeConnection();
606
605
  });
607
606
  this.connection = connection;
608
607
  return connection;
@@ -616,8 +615,8 @@ var Peer = class {
616
615
  peerId: this.id,
617
616
  sessionId: connection.sessionId
618
617
  }, {
619
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
620
- line: 221,
618
+ file: "peer.ts",
619
+ line: 219,
621
620
  scope: this,
622
621
  callSite: (f, a) => f(...a)
623
622
  });
@@ -626,8 +625,8 @@ var Peer = class {
626
625
  peerId: this.id,
627
626
  sessionId: connection.sessionId
628
627
  }, {
629
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
630
- line: 227,
628
+ file: "peer.ts",
629
+ line: 225,
631
630
  scope: this,
632
631
  callSite: (f, a) => f(...a)
633
632
  });
@@ -637,8 +636,8 @@ var Peer = class {
637
636
  log3("dropping signal message for non-existent connection", {
638
637
  message
639
638
  }, {
640
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
641
- line: 232,
639
+ file: "peer.ts",
640
+ line: 230,
642
641
  scope: this,
643
642
  callSite: (f, a) => f(...a)
644
643
  });
@@ -652,8 +651,8 @@ var Peer = class {
652
651
  peerId: this.id,
653
652
  topic: this.topic
654
653
  }, {
655
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
656
- line: 240,
654
+ file: "peer.ts",
655
+ line: 238,
657
656
  scope: this,
658
657
  callSite: (f, a) => f(...a)
659
658
  });
@@ -696,7 +695,7 @@ var Swarm = class {
696
695
  log4("creating swarm", {
697
696
  peerId: _ownPeerId
698
697
  }, {
699
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts",
698
+ file: "swarm.ts",
700
699
  line: 80,
701
700
  scope: this,
702
701
  callSite: (f, a) => f(...a)
@@ -713,7 +712,7 @@ var Swarm = class {
713
712
  payloadType: "dxos.mesh.swarm.SwarmMessage",
714
713
  onMessage: async (message) => await this._swarmMessenger.receiveMessage(message)
715
714
  }).catch((error) => log4.catch(error, {}, {
716
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts",
715
+ file: "swarm.ts",
717
716
  line: 96,
718
717
  scope: this,
719
718
  callSite: (f, a) => f(...a)
@@ -733,7 +732,7 @@ var Swarm = class {
733
732
  }
734
733
  async destroy() {
735
734
  log4("destroying...", {}, {
736
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts",
735
+ file: "swarm.ts",
737
736
  line: 124,
738
737
  scope: this,
739
738
  callSite: (f, a) => f(...a)
@@ -742,7 +741,7 @@ var Swarm = class {
742
741
  await this._topology.destroy();
743
742
  await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key)));
744
743
  log4("destroyed", {}, {
745
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts",
744
+ file: "swarm.ts",
746
745
  line: 128,
747
746
  scope: this,
748
747
  callSite: (f, a) => f(...a)
@@ -756,7 +755,7 @@ var Swarm = class {
756
755
  previous: getClassName(this._topology),
757
756
  topology: getClassName(topology)
758
757
  }, {
759
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts",
758
+ file: "swarm.ts",
760
759
  line: 135,
761
760
  scope: this,
762
761
  callSite: (f, a) => f(...a)
@@ -808,14 +807,14 @@ var Swarm = class {
808
807
  log4("swarm event", {
809
808
  swarmEvent
810
809
  }, {
811
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts",
810
+ file: "swarm.ts",
812
811
  line: 199,
813
812
  scope: this,
814
813
  callSite: (f, a) => f(...a)
815
814
  });
816
815
  if (this._ctx.disposed) {
817
816
  log4.warn("ignored for destroyed swarm", {}, {
818
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts",
817
+ file: "swarm.ts",
819
818
  line: 201,
820
819
  scope: this,
821
820
  callSite: (f, a) => f(...a)
@@ -827,7 +826,7 @@ var Swarm = class {
827
826
  log4("new peer", {
828
827
  peerId
829
828
  }, {
830
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts",
829
+ file: "swarm.ts",
831
830
  line: 207,
832
831
  scope: this,
833
832
  callSite: (f, a) => f(...a)
@@ -852,14 +851,14 @@ var Swarm = class {
852
851
  log4("offer", {
853
852
  message
854
853
  }, {
855
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts",
854
+ file: "swarm.ts",
856
855
  line: 226,
857
856
  scope: this,
858
857
  callSite: (f, a) => f(...a)
859
858
  });
860
859
  if (this._ctx.disposed) {
861
860
  log4.info("ignored for destroyed swarm", {}, {
862
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts",
861
+ file: "swarm.ts",
863
862
  line: 228,
864
863
  scope: this,
865
864
  callSite: (f, a) => f(...a)
@@ -873,7 +872,7 @@ var Swarm = class {
873
872
  log4("rejecting offer with incorrect peerId", {
874
873
  message
875
874
  }, {
876
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts",
875
+ file: "swarm.ts",
877
876
  line: 235,
878
877
  scope: this,
879
878
  callSite: (f, a) => f(...a)
@@ -886,7 +885,7 @@ var Swarm = class {
886
885
  log4("rejecting offer with incorrect topic", {
887
886
  message
888
887
  }, {
889
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts",
888
+ file: "swarm.ts",
890
889
  line: 239,
891
890
  scope: this,
892
891
  callSite: (f, a) => f(...a)
@@ -905,14 +904,14 @@ var Swarm = class {
905
904
  log4("signal", {
906
905
  message
907
906
  }, {
908
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts",
907
+ file: "swarm.ts",
909
908
  line: 250,
910
909
  scope: this,
911
910
  callSite: (f, a) => f(...a)
912
911
  });
913
912
  if (this._ctx.disposed) {
914
913
  log4.info("ignored for destroyed swarm", {}, {
915
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts",
914
+ file: "swarm.ts",
916
915
  line: 252,
917
916
  scope: this,
918
917
  callSite: (f, a) => f(...a)
@@ -941,7 +940,7 @@ var Swarm = class {
941
940
  await this._initiateConnection(peer);
942
941
  } catch (err) {
943
942
  log4.warn("initiation error", err, {
944
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts",
943
+ file: "swarm.ts",
945
944
  line: 287,
946
945
  scope: this,
947
946
  callSite: (f, a) => f(...a)
@@ -965,7 +964,7 @@ var Swarm = class {
965
964
  log4("initiation delay", {
966
965
  remoteId
967
966
  }, {
968
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts",
967
+ file: "swarm.ts",
969
968
  line: 312,
970
969
  scope: this,
971
970
  callSite: (f, a) => f(...a)
@@ -982,7 +981,7 @@ var Swarm = class {
982
981
  log4("initiating connection...", {
983
982
  remoteId
984
983
  }, {
985
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts",
984
+ file: "swarm.ts",
986
985
  line: 326,
987
986
  scope: this,
988
987
  callSite: (f, a) => f(...a)
@@ -992,7 +991,7 @@ var Swarm = class {
992
991
  log4("initiated", {
993
992
  remoteId
994
993
  }, {
995
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts",
994
+ file: "swarm.ts",
996
995
  line: 329,
997
996
  scope: this,
998
997
  callSite: (f, a) => f(...a)
@@ -1025,9 +1024,8 @@ var SwarmMapper = class {
1025
1024
  get peers() {
1026
1025
  return Array.from(this._peers.values());
1027
1026
  }
1028
- constructor(_swarm, _presence) {
1027
+ constructor(_swarm) {
1029
1028
  this._swarm = _swarm;
1030
- this._presence = _presence;
1031
1029
  this._subscriptions = new EventSubscriptions();
1032
1030
  this._connectionSubscriptions = new ComplexMap3(PublicKey4.hash);
1033
1031
  this._peers = new ComplexMap3(PublicKey4.hash);
@@ -1044,17 +1042,12 @@ var SwarmMapper = class {
1044
1042
  this._connectionSubscriptions.delete(peerId);
1045
1043
  this._update();
1046
1044
  }));
1047
- if (_presence) {
1048
- this._subscriptions.add(_presence.graphUpdated.on(() => {
1049
- this._update();
1050
- }));
1051
- }
1052
1045
  this._update();
1053
1046
  }
1054
1047
  _update() {
1055
1048
  log5("updating swarm", {}, {
1056
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts",
1057
- line: 77,
1049
+ file: "swarm-mapper.ts",
1050
+ line: 75,
1058
1051
  scope: this,
1059
1052
  callSite: (f, a) => f(...a)
1060
1053
  });
@@ -1073,32 +1066,12 @@ var SwarmMapper = class {
1073
1066
  ]
1074
1067
  });
1075
1068
  }
1076
- if (this._presence) {
1077
- this._presence.graph.forEachNode((node) => {
1078
- const id = PublicKey4.fromHex(node.id);
1079
- if (this._peers.has(id)) {
1080
- return;
1081
- }
1082
- this._peers.set(id, {
1083
- id,
1084
- state: "INDIRECTLY_CONNECTED",
1085
- connections: []
1086
- });
1087
- });
1088
- this._presence.graph.forEachLink((link) => {
1089
- const from = PublicKey4.from(link.fromId);
1090
- const to = PublicKey4.from(link.toId);
1091
- if (!from.equals(this._swarm.ownPeerId) && !to.equals(this._swarm.ownPeerId)) {
1092
- this._peers.get(from).connections.push(to);
1093
- }
1094
- });
1095
- }
1096
1069
  log5("graph changed", {
1097
1070
  directConnections: this._swarm.connections.length,
1098
1071
  totalPeersInSwarm: this._peers.size
1099
1072
  }, {
1100
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts",
1101
- line: 118,
1073
+ file: "swarm-mapper.ts",
1074
+ line: 116,
1102
1075
  scope: this,
1103
1076
  callSite: (f, a) => f(...a)
1104
1077
  });
@@ -1142,13 +1115,12 @@ var ConnectionLog = class {
1142
1115
  this._swarms.set(swarm.instanceId, info);
1143
1116
  this.update.emit();
1144
1117
  swarm.connectionAdded.on((connection) => {
1145
- var _a, _b, _c, _d, _e;
1146
1118
  const connectionInfo = {
1147
1119
  state: ConnectionState.INITIAL,
1148
1120
  remotePeerId: connection.remoteId,
1149
1121
  sessionId: connection.sessionId,
1150
1122
  transport: connection.transport && Object.getPrototypeOf(connection.transport).constructor.name,
1151
- protocolExtensions: (_a = connection.protocol.protocol) == null ? void 0 : _a.extensionNames,
1123
+ protocolExtensions: [],
1152
1124
  events: []
1153
1125
  };
1154
1126
  info.connections.push(connectionInfo);
@@ -1161,32 +1133,6 @@ var ConnectionLog = class {
1161
1133
  });
1162
1134
  this.update.emit();
1163
1135
  });
1164
- (_b = connection.protocol.protocol) == null ? void 0 : _b.error.on((error) => {
1165
- var _a2;
1166
- connectionInfo.events.push({
1167
- type: EventType.PROTOCOL_ERROR,
1168
- error: (_a2 = error.stack) != null ? _a2 : error.message
1169
- });
1170
- this.update.emit();
1171
- });
1172
- (_c = connection.protocol.protocol) == null ? void 0 : _c.extensionsInitialized.on(() => {
1173
- connectionInfo.events.push({
1174
- type: EventType.PROTOCOL_EXTENSIONS_INITIALIZED
1175
- });
1176
- this.update.emit();
1177
- });
1178
- (_d = connection.protocol.protocol) == null ? void 0 : _d.extensionsHandshake.on(() => {
1179
- connectionInfo.events.push({
1180
- type: EventType.PROTOCOL_EXTENSIONS_HANDSHAKE
1181
- });
1182
- this.update.emit();
1183
- });
1184
- (_e = connection.protocol.protocol) == null ? void 0 : _e.handshake.on(() => {
1185
- connectionInfo.events.push({
1186
- type: EventType.PROTOCOL_HANDSHAKE
1187
- });
1188
- this.update.emit();
1189
- });
1190
1136
  });
1191
1137
  }
1192
1138
  swarmLeft(swarm) {
@@ -1197,7 +1143,7 @@ var ConnectionLog = class {
1197
1143
 
1198
1144
  // packages/core/mesh/network-manager/src/network-manager.ts
1199
1145
  var NetworkManager = class {
1200
- constructor({ transportFactory, signalManager, log: log15 }) {
1146
+ constructor({ transportFactory, signalManager, log: log14 }) {
1201
1147
  this._swarms = new ComplexMap5(PublicKey6.hash);
1202
1148
  this._mappers = new ComplexMap5(PublicKey6.hash);
1203
1149
  this.topicsUpdated = new Event5();
@@ -1214,7 +1160,7 @@ var NetworkManager = class {
1214
1160
  join: (opts) => this._signalManager.join(opts),
1215
1161
  leave: (opts) => this._signalManager.leave(opts)
1216
1162
  };
1217
- if (log15) {
1163
+ if (log14) {
1218
1164
  this._connectionLog = new ConnectionLog();
1219
1165
  }
1220
1166
  }
@@ -1237,8 +1183,8 @@ var NetworkManager = class {
1237
1183
  for (const topic of this._swarms.keys()) {
1238
1184
  await this.leaveSwarm(topic).catch((err) => {
1239
1185
  log6(err, {}, {
1240
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts",
1241
- line: 128,
1186
+ file: "network-manager.ts",
1187
+ line: 122,
1242
1188
  scope: this,
1243
1189
  callSite: (f, a) => f(...a)
1244
1190
  });
@@ -1246,7 +1192,7 @@ var NetworkManager = class {
1246
1192
  }
1247
1193
  await this._signalManager.destroy();
1248
1194
  }
1249
- async joinSwarm({ topic, peerId, topology, protocolProvider: protocol, presence, label }) {
1195
+ async joinSwarm({ topic, peerId, topology, protocolProvider: protocol, label }) {
1250
1196
  var _a;
1251
1197
  assert5(PublicKey6.isPublicKey(topic));
1252
1198
  assert5(PublicKey6.isPublicKey(peerId));
@@ -1260,8 +1206,8 @@ var NetworkManager = class {
1260
1206
  peerId,
1261
1207
  topology: topology.toString()
1262
1208
  }, {
1263
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts",
1264
- line: 155,
1209
+ file: "network-manager.ts",
1210
+ line: 148,
1265
1211
  scope: this,
1266
1212
  callSite: (f, a) => f(...a)
1267
1213
  });
@@ -1270,8 +1216,8 @@ var NetworkManager = class {
1270
1216
  log6("swarm error", {
1271
1217
  error
1272
1218
  }, {
1273
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts",
1274
- line: 158,
1219
+ file: "network-manager.ts",
1220
+ line: 151,
1275
1221
  scope: this,
1276
1222
  callSite: (f, a) => f(...a)
1277
1223
  });
@@ -1281,20 +1227,20 @@ var NetworkManager = class {
1281
1227
  topic,
1282
1228
  peerId
1283
1229
  }).catch((error) => log6.catch(error, {}, {
1284
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts",
1285
- line: 162,
1230
+ file: "network-manager.ts",
1231
+ line: 155,
1286
1232
  scope: this,
1287
1233
  callSite: (f, a) => f(...a)
1288
1234
  }));
1289
- this._mappers.set(topic, new SwarmMapper(swarm, presence));
1235
+ this._mappers.set(topic, new SwarmMapper(swarm));
1290
1236
  this.topicsUpdated.emit();
1291
1237
  (_a = this._connectionLog) == null ? void 0 : _a.swarmJoined(swarm);
1292
1238
  log6("joined", {
1293
1239
  topic: PublicKey6.from(topic),
1294
1240
  count: this._swarms.size
1295
1241
  }, {
1296
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts",
1297
- line: 167,
1242
+ file: "network-manager.ts",
1243
+ line: 160,
1298
1244
  scope: this,
1299
1245
  callSite: (f, a) => f(...a)
1300
1246
  });
@@ -1308,8 +1254,8 @@ var NetworkManager = class {
1308
1254
  log6.warn("swarm not open", {
1309
1255
  topic: PublicKey6.from(topic)
1310
1256
  }, {
1311
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts",
1312
- line: 179,
1257
+ file: "network-manager.ts",
1258
+ line: 172,
1313
1259
  scope: this,
1314
1260
  callSite: (f, a) => f(...a)
1315
1261
  });
@@ -1318,8 +1264,8 @@ var NetworkManager = class {
1318
1264
  log6("leaving", {
1319
1265
  topic: PublicKey6.from(topic)
1320
1266
  }, {
1321
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts",
1322
- line: 183,
1267
+ file: "network-manager.ts",
1268
+ line: 176,
1323
1269
  scope: this,
1324
1270
  callSite: (f, a) => f(...a)
1325
1271
  });
@@ -1339,8 +1285,8 @@ var NetworkManager = class {
1339
1285
  topic: PublicKey6.from(topic),
1340
1286
  count: this._swarms.size
1341
1287
  }, {
1342
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts",
1343
- line: 197,
1288
+ file: "network-manager.ts",
1289
+ line: 190,
1344
1290
  scope: this,
1345
1291
  callSite: (f, a) => f(...a)
1346
1292
  });
@@ -1386,8 +1332,18 @@ import { Transform } from "@dxos/node-std/stream";
1386
1332
  import { Event as Event6, Trigger } from "@dxos/async";
1387
1333
  import { ErrorStream as ErrorStream3 } from "@dxos/debug";
1388
1334
  import { PublicKey as PublicKey7 } from "@dxos/keys";
1389
- import { log as log9 } from "@dxos/log";
1335
+ import { log as log9, logInfo as logInfo2 } from "@dxos/log";
1390
1336
  import { ComplexMap as ComplexMap6 } from "@dxos/util";
1337
+ var __decorate4 = function(decorators, target, key, desc) {
1338
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1339
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
1340
+ r = Reflect.decorate(decorators, target, key, desc);
1341
+ else
1342
+ for (var i = decorators.length - 1; i >= 0; i--)
1343
+ if (d = decorators[i])
1344
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1345
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1346
+ };
1391
1347
  var MEMORY_TRANSPORT_DELAY = 1;
1392
1348
  var createStreamDelay = (delay) => {
1393
1349
  return new Transform({
@@ -1407,34 +1363,30 @@ var _MemoryTransport = class {
1407
1363
  this.closed = new Event6();
1408
1364
  this.connected = new Event6();
1409
1365
  this.errors = new ErrorStream3();
1410
- this._id = PublicKey7.random();
1411
1366
  this._remote = new Trigger();
1412
1367
  this._outgoingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
1413
1368
  this._incomingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
1414
1369
  this._destroyed = false;
1415
- log9("creating", {
1416
- id: this._id
1417
- }, {
1418
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts",
1419
- line: 59,
1370
+ this._instanceId = PublicKey7.random();
1371
+ log9("creating", {}, {
1372
+ file: "memory-transport.ts",
1373
+ line: 64,
1420
1374
  scope: this,
1421
1375
  callSite: (f, a) => f(...a)
1422
1376
  });
1423
- assert9(!_MemoryTransport._connections.has(this._id), "Duplicate memory connection");
1424
- _MemoryTransport._connections.set(this._id, this);
1377
+ assert9(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection");
1378
+ _MemoryTransport._connections.set(this._instanceId, this);
1425
1379
  if (this.options.initiator) {
1426
1380
  setTimeout(async () => {
1427
- log9("sending signal", {
1428
- transportId: this._id
1429
- }, {
1430
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts",
1431
- line: 68,
1381
+ log9("sending signal", {}, {
1382
+ file: "memory-transport.ts",
1383
+ line: 73,
1432
1384
  scope: this,
1433
1385
  callSite: (f, a) => f(...a)
1434
1386
  });
1435
1387
  void this.options.sendSignal({
1436
1388
  payload: {
1437
- transportId: this._id.toHex()
1389
+ transportId: this._instanceId.toHex()
1438
1390
  }
1439
1391
  });
1440
1392
  });
@@ -1445,22 +1397,19 @@ var _MemoryTransport = class {
1445
1397
  if (this._destroyed) {
1446
1398
  return;
1447
1399
  }
1448
- this._remoteId = remoteId;
1449
- this._remoteConnection = _MemoryTransport._connections.get(this._remoteId);
1400
+ this._remoteInstanceId = remoteId;
1401
+ this._remoteConnection = _MemoryTransport._connections.get(this._remoteInstanceId);
1450
1402
  if (!this._remoteConnection) {
1451
1403
  this._destroyed = true;
1452
1404
  this.closed.emit();
1453
1405
  return;
1454
1406
  }
1455
- assert9(!this._remoteConnection._remoteConnection, new Error(`Remote already connected: ${this._remoteId}`));
1407
+ assert9(!this._remoteConnection._remoteConnection, new Error(`Remote already connected: ${this._remoteInstanceId}`));
1456
1408
  this._remoteConnection._remoteConnection = this;
1457
- this._remoteConnection._remoteId = this._id;
1458
- log9("connected", {
1459
- id: this._id,
1460
- remote: this._remoteId
1461
- }, {
1462
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts",
1463
- line: 94,
1409
+ this._remoteConnection._remoteInstanceId = this._instanceId;
1410
+ log9("connected", {}, {
1411
+ file: "memory-transport.ts",
1412
+ line: 102,
1464
1413
  scope: this,
1465
1414
  callSite: (f, a) => f(...a)
1466
1415
  });
@@ -1476,73 +1425,70 @@ var _MemoryTransport = class {
1476
1425
  }
1477
1426
  }
1478
1427
  async destroy() {
1479
- log9("closing", {
1480
- id: this._id
1481
- }, {
1482
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts",
1483
- line: 115,
1428
+ log9("closing", {}, {
1429
+ file: "memory-transport.ts",
1430
+ line: 123,
1484
1431
  scope: this,
1485
1432
  callSite: (f, a) => f(...a)
1486
1433
  });
1487
1434
  this._destroyed = true;
1488
- _MemoryTransport._connections.delete(this._id);
1435
+ _MemoryTransport._connections.delete(this._instanceId);
1489
1436
  if (this._remoteConnection) {
1490
- log9("closing", {
1491
- id: this._remoteId
1492
- }, {
1493
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts",
1494
- line: 120,
1437
+ log9("closing", {}, {
1438
+ file: "memory-transport.ts",
1439
+ line: 128,
1495
1440
  scope: this,
1496
1441
  callSite: (f, a) => f(...a)
1497
1442
  });
1498
1443
  this._remoteConnection._destroyed = true;
1499
- _MemoryTransport._connections.delete(this._remoteId);
1444
+ _MemoryTransport._connections.delete(this._remoteInstanceId);
1500
1445
  this._outgoingDelay.unpipe();
1501
1446
  this._incomingDelay.unpipe();
1502
1447
  this._remoteConnection.closed.emit();
1503
1448
  this._remoteConnection._remoteConnection = void 0;
1504
1449
  this._remoteConnection = void 0;
1505
- log9("closed", {
1506
- id: this._remoteId
1507
- }, {
1508
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts",
1509
- line: 138,
1450
+ log9("closed", {}, {
1451
+ file: "memory-transport.ts",
1452
+ line: 146,
1510
1453
  scope: this,
1511
1454
  callSite: (f, a) => f(...a)
1512
1455
  });
1513
1456
  }
1514
1457
  this.closed.emit();
1515
- log9("closed", {
1516
- id: this._id
1517
- }, {
1518
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts",
1519
- line: 142,
1458
+ log9("closed", {}, {
1459
+ file: "memory-transport.ts",
1460
+ line: 150,
1520
1461
  scope: this,
1521
1462
  callSite: (f, a) => f(...a)
1522
1463
  });
1523
1464
  }
1524
- signal(signal) {
1525
- const { payload: json } = signal;
1526
- if (json && json.transportId) {
1527
- const transportId = json.transportId;
1528
- if (transportId) {
1529
- const remoteId = PublicKey7.fromHex(transportId);
1530
- log9("received signal", {
1531
- id: this._id,
1532
- remoteId
1533
- }, {
1534
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts",
1535
- line: 152,
1536
- scope: this,
1537
- callSite: (f, a) => f(...a)
1538
- });
1539
- this._remote.wake(remoteId);
1540
- }
1465
+ signal({ payload }) {
1466
+ log9("received signal", {
1467
+ payload
1468
+ }, {
1469
+ file: "memory-transport.ts",
1470
+ line: 154,
1471
+ scope: this,
1472
+ callSite: (f, a) => f(...a)
1473
+ });
1474
+ if (!(payload == null ? void 0 : payload.transportId)) {
1475
+ return;
1476
+ }
1477
+ const transportId = payload.transportId;
1478
+ if (transportId) {
1479
+ const remoteId = PublicKey7.fromHex(transportId);
1480
+ this._remote.wake(remoteId);
1541
1481
  }
1542
1482
  }
1543
1483
  };
1544
1484
  var MemoryTransport = _MemoryTransport;
1545
1485
  MemoryTransport._connections = new ComplexMap6(PublicKey7.hash);
1486
+ __decorate4([
1487
+ logInfo2
1488
+ ], MemoryTransport.prototype, "_instanceId", void 0);
1489
+ __decorate4([
1490
+ logInfo2
1491
+ ], MemoryTransport.prototype, "_remoteInstanceId", void 0);
1546
1492
 
1547
1493
  // packages/core/mesh/network-manager/src/transport/webrtc-transport.ts
1548
1494
  import assert10 from "@dxos/node-std/assert";
@@ -1567,7 +1513,7 @@ var WebRTCTransport = class {
1567
1513
  this.connected = new Event7();
1568
1514
  this.errors = new ErrorStream4();
1569
1515
  log10("created connection", params, {
1570
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport.ts",
1516
+ file: "webrtc-transport.ts",
1571
1517
  line: 34,
1572
1518
  scope: this,
1573
1519
  callSite: (f, a) => f(...a)
@@ -1579,7 +1525,7 @@ var WebRTCTransport = class {
1579
1525
  });
1580
1526
  this._peer.on("signal", async (data) => {
1581
1527
  log10("signal", data, {
1582
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport.ts",
1528
+ file: "webrtc-transport.ts",
1583
1529
  line: 42,
1584
1530
  scope: this,
1585
1531
  callSite: (f, a) => f(...a)
@@ -1592,7 +1538,7 @@ var WebRTCTransport = class {
1592
1538
  });
1593
1539
  this._peer.on("connect", () => {
1594
1540
  log10("connected", {}, {
1595
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport.ts",
1541
+ file: "webrtc-transport.ts",
1596
1542
  line: 47,
1597
1543
  scope: this,
1598
1544
  callSite: (f, a) => f(...a)
@@ -1602,7 +1548,7 @@ var WebRTCTransport = class {
1602
1548
  });
1603
1549
  this._peer.on("close", async () => {
1604
1550
  log10("closed", {}, {
1605
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport.ts",
1551
+ file: "webrtc-transport.ts",
1606
1552
  line: 53,
1607
1553
  scope: this,
1608
1554
  callSite: (f, a) => f(...a)
@@ -1617,7 +1563,7 @@ var WebRTCTransport = class {
1617
1563
  }
1618
1564
  async destroy() {
1619
1565
  log10("closing...", {}, {
1620
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport.ts",
1566
+ file: "webrtc-transport.ts",
1621
1567
  line: 65,
1622
1568
  scope: this,
1623
1569
  callSite: (f, a) => f(...a)
@@ -1626,7 +1572,7 @@ var WebRTCTransport = class {
1626
1572
  this._peer.destroy();
1627
1573
  this.closed.emit();
1628
1574
  log10("closed", {}, {
1629
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport.ts",
1575
+ file: "webrtc-transport.ts",
1630
1576
  line: 69,
1631
1577
  scope: this,
1632
1578
  callSite: (f, a) => f(...a)
@@ -1732,7 +1678,7 @@ var WebRTCTransportService = class {
1732
1678
  await ((_b = this.transports.get(proxyId)) == null ? void 0 : _b.stream.end());
1733
1679
  this.transports.delete(proxyId);
1734
1680
  log11("Closed.", {}, {
1735
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-service.ts",
1681
+ file: "webrtc-transport-service.ts",
1736
1682
  line: 108,
1737
1683
  scope: this,
1738
1684
  callSite: (f, a) => f(...a)
@@ -1762,7 +1708,7 @@ var WebRTCTransportProxy = class {
1762
1708
  this._serviceStream.waitUntilReady().then(() => {
1763
1709
  this._serviceStream.subscribe(async (event) => {
1764
1710
  log12("WebRTCTransportProxy: event", event, {
1765
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts",
1711
+ file: "webrtc-transport-proxy.ts",
1766
1712
  line: 46,
1767
1713
  scope: this,
1768
1714
  callSite: (f, a) => f(...a)
@@ -1783,7 +1729,7 @@ var WebRTCTransportProxy = class {
1783
1729
  });
1784
1730
  } catch (err) {
1785
1731
  log12.catch(err, {}, {
1786
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts",
1732
+ file: "webrtc-transport-proxy.ts",
1787
1733
  line: 63,
1788
1734
  scope: this,
1789
1735
  callSite: (f, a) => f(...a)
@@ -1791,7 +1737,7 @@ var WebRTCTransportProxy = class {
1791
1737
  }
1792
1738
  });
1793
1739
  }, (error) => log12.catch(error, {}, {
1794
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts",
1740
+ file: "webrtc-transport-proxy.ts",
1795
1741
  line: 67,
1796
1742
  scope: this,
1797
1743
  callSite: (f, a) => f(...a)
@@ -1835,7 +1781,7 @@ var WebRTCTransportProxy = class {
1835
1781
  });
1836
1782
  } catch (err) {
1837
1783
  log12.catch(err, {}, {
1838
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts",
1784
+ file: "webrtc-transport-proxy.ts",
1839
1785
  line: 117,
1840
1786
  scope: this,
1841
1787
  callSite: (f, a) => f(...a)
@@ -1873,205 +1819,74 @@ var WebRTCTransportProxyFactory = class {
1873
1819
  }
1874
1820
  };
1875
1821
 
1876
- // packages/core/mesh/network-manager/src/wire-protocol.ts
1877
- import { discoveryKey } from "@dxos/crypto";
1878
- import { Teleport } from "@dxos/teleport";
1879
- var adaptProtocolProvider = (factory) => ({ initiator, localPeerId, remotePeerId, topic }) => {
1880
- const protocol = factory({
1881
- channel: discoveryKey(topic),
1882
- initiator
1883
- });
1884
- return {
1885
- initialize: () => protocol.open(),
1886
- destroy: () => protocol.close(),
1887
- stream: protocol.stream,
1888
- protocol
1889
- };
1890
- };
1891
-
1892
- // packages/core/mesh/network-manager/src/testing/test-protocol.ts
1893
- import assert14 from "@dxos/node-std/assert";
1894
- import { EventEmitter } from "@dxos/node-std/events";
1895
- import { PublicKey as PublicKey11 } from "@dxos/keys";
1896
- import { log as log14 } from "@dxos/log";
1897
- import { Extension } from "@dxos/mesh-protocol";
1898
-
1899
- // packages/core/mesh/network-manager/src/protocol-factory.ts
1900
- import assert13 from "@dxos/node-std/assert";
1901
- import { discoveryKey as discoveryKey2 } from "@dxos/crypto";
1822
+ // packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts
1823
+ import { Event as Event9 } from "@dxos/async";
1902
1824
  import { PublicKey as PublicKey10 } from "@dxos/keys";
1903
1825
  import { log as log13 } from "@dxos/log";
1904
- import { Protocol } from "@dxos/mesh-protocol";
1905
- var protocolFactory = ({ session = {}, plugins = [], getTopics }) => {
1906
- assert13(getTopics);
1907
- return ({ channel, initiator }) => {
1908
- log13("creating protocol", {}, {
1909
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/protocol-factory.ts",
1910
- line: 41,
1911
- scope: void 0,
1912
- callSite: (f, a) => f(...a)
1913
- });
1914
- const protocol = new Protocol({
1915
- streamOptions: {
1916
- live: true
1917
- },
1918
- discoveryToPublicKey: (dk) => {
1919
- const publicKey = getTopics().find((topic) => discoveryKey2(topic).equals(dk));
1920
- if (publicKey) {
1921
- protocol.setContext({
1922
- topic: PublicKey10.stringify(publicKey)
1923
- });
1924
- }
1925
- assert13(publicKey, "PublicKey not found in discovery.");
1926
- return publicKey;
1826
+ import { TestExtension } from "@dxos/teleport";
1827
+ import { ComplexMap as ComplexMap8 } from "@dxos/util";
1828
+
1829
+ // packages/core/mesh/network-manager/src/wire-protocol.ts
1830
+ import { Teleport } from "@dxos/teleport";
1831
+ var createTeleportProtocolFactory = (onConnection) => {
1832
+ return (params) => {
1833
+ const teleport = new Teleport(params);
1834
+ return {
1835
+ stream: teleport.stream,
1836
+ initialize: async () => {
1837
+ await teleport.open();
1838
+ await onConnection(teleport);
1927
1839
  },
1928
- initiator,
1929
- userSession: session,
1930
- discoveryKey: channel
1931
- });
1932
- protocol.setExtensions(plugins.map((plugin) => plugin.createExtension())).init();
1933
- return protocol;
1840
+ destroy: async () => {
1841
+ await teleport.close();
1842
+ }
1843
+ };
1934
1844
  };
1935
1845
  };
1936
1846
 
1937
- // packages/core/mesh/network-manager/src/testing/test-protocol.ts
1938
- var EXTENSION_NAME = "test";
1939
- var getPeerId = (protocol) => {
1940
- var _a;
1941
- const { peerId } = (_a = protocol.getSession()) != null ? _a : {};
1942
- if (!peerId) {
1943
- return void 0;
1944
- }
1945
- return PublicKey11.bufferize(peerId);
1946
- };
1947
- var testProtocolProvider = (topic, peerId, protocolPlugin) => {
1948
- log14("creating protocol-factory", {
1949
- topic: PublicKey11.from(topic),
1950
- peerId
1951
- }, {
1952
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-protocol.ts",
1953
- line: 34,
1954
- scope: void 0,
1955
- callSite: (f, a) => f(...a)
1956
- });
1957
- return protocolFactory({
1958
- getTopics: () => [
1959
- topic
1960
- ],
1961
- session: {
1962
- peerId: peerId.toHex()
1963
- },
1964
- plugins: [
1965
- protocolPlugin
1966
- ]
1967
- });
1968
- };
1969
- var TestProtocolPlugin = class extends EventEmitter {
1970
- constructor(peerId, uppercase = false) {
1971
- super();
1972
- this._peers = /* @__PURE__ */ new Map();
1973
- this.initCalled = false;
1974
- assert14(Buffer.isBuffer(peerId));
1975
- this._peerId = peerId;
1976
- this._uppercase = uppercase;
1977
- }
1978
- get peerId() {
1979
- return this._peerId;
1980
- }
1981
- get peers() {
1982
- return Array.from(this._peers.values());
1983
- }
1984
- createExtension() {
1985
- log14("creating extension", {
1986
- peerId: PublicKey11.from(this.peerId)
1987
- }, {
1988
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-protocol.ts",
1989
- line: 92,
1990
- scope: this,
1991
- callSite: (f, a) => f(...a)
1992
- });
1993
- return new Extension(EXTENSION_NAME, {
1994
- binary: true
1995
- }).setInitHandler(this._init.bind(this)).setMessageHandler(this._receive.bind(this)).setHandshakeHandler(this._onPeerConnect.bind(this)).setCloseHandler(this._onPeerDisconnect.bind(this));
1996
- }
1997
- async _init(protocol) {
1998
- this.initCalled = true;
1999
- }
2000
- async send(peerId, payload) {
2001
- assert14(Buffer.isBuffer(peerId));
2002
- const peerIdStr = PublicKey11.stringify(peerId);
2003
- const peer = this._peers.get(peerIdStr);
2004
- if (!peer) {
2005
- throw new Error(`peer not found: ${PublicKey11.from(peerId).truncate()}`);
2006
- }
2007
- const extension = peer.getExtension(EXTENSION_NAME);
2008
- const encoded = Buffer.from(payload);
2009
- log14("sending", {
2010
- peerId: PublicKey11.from(peerId),
2011
- payload
2012
- }, {
2013
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-protocol.ts",
2014
- line: 124,
2015
- scope: this,
2016
- callSite: (f, a) => f(...a)
2017
- });
2018
- return await extension.send(encoded, {
2019
- oneway: true
1847
+ // packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts
1848
+ var TestWireProtocol = class {
1849
+ constructor(peerId) {
1850
+ this.peerId = peerId;
1851
+ this.connections = new ComplexMap8(PublicKey10.hash);
1852
+ this.connected = new Event9();
1853
+ this.factory = createTeleportProtocolFactory(async (teleport) => {
1854
+ log13("create", {
1855
+ remotePeerId: teleport.remotePeerId
1856
+ }, {
1857
+ file: "test-wire-protocol.ts",
1858
+ line: 20,
1859
+ scope: this,
1860
+ callSite: (f, a) => f(...a)
1861
+ });
1862
+ const extension = new TestExtension({
1863
+ onClose: async () => {
1864
+ this.connections.delete(teleport.remotePeerId);
1865
+ }
1866
+ });
1867
+ this.connections.set(teleport.remotePeerId, extension);
1868
+ teleport.addExtension("test", extension);
1869
+ this.connected.emit(teleport.remotePeerId);
2020
1870
  });
2021
1871
  }
2022
- async _receive(protocol, data) {
2023
- const peerId = getPeerId(protocol);
2024
- assert14(peerId !== void 0);
2025
- let payload = data.data.toString();
2026
- if (this._uppercase) {
2027
- payload = payload.toUpperCase();
1872
+ async waitForConnection(peerId) {
1873
+ if (this.connections.has(peerId)) {
1874
+ return this.connections.get(peerId);
2028
1875
  }
2029
- log14("received", {
2030
- peerId: PublicKey11.from(peerId),
2031
- payload
1876
+ log13("waitForConnection", {
1877
+ peerId
2032
1878
  }, {
2033
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-protocol.ts",
2034
- line: 136,
1879
+ file: "test-wire-protocol.ts",
1880
+ line: 35,
2035
1881
  scope: this,
2036
1882
  callSite: (f, a) => f(...a)
2037
1883
  });
2038
- this.emit("receive", protocol, payload);
1884
+ await this.connected.waitFor((connectedId) => connectedId.equals(peerId));
1885
+ return this.connections.get(peerId);
2039
1886
  }
2040
- async _onPeerConnect(protocol) {
2041
- log14("connecting", {
2042
- id: PublicKey11.from(protocol.id)
2043
- }, {
2044
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-protocol.ts",
2045
- line: 141,
2046
- scope: this,
2047
- callSite: (f, a) => f(...a)
2048
- });
2049
- const peerId = getPeerId(protocol);
2050
- if (peerId === void 0) {
2051
- return;
2052
- }
2053
- const peerIdStr = PublicKey11.stringify(peerId);
2054
- if (this._peers.has(peerIdStr)) {
2055
- return;
2056
- }
2057
- this._peers.set(peerIdStr, protocol);
2058
- this.emit("connect", protocol);
2059
- }
2060
- async _onPeerDisconnect(protocol) {
2061
- log14("disconnecting", {
2062
- id: PublicKey11.from(protocol.id)
2063
- }, {
2064
- file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-protocol.ts",
2065
- line: 157,
2066
- scope: this,
2067
- callSite: (f, a) => f(...a)
2068
- });
2069
- const peerId = getPeerId(protocol);
2070
- if (peerId === void 0) {
2071
- return;
2072
- }
2073
- this._peers.delete(PublicKey11.stringify(peerId));
2074
- this.emit("disconnect", peerId);
1887
+ async testConnection(peerId) {
1888
+ const connection = await this.waitForConnection(peerId);
1889
+ await connection.test();
2075
1890
  }
2076
1891
  };
2077
1892
 
@@ -2095,8 +1910,8 @@ var TestBuilder = class {
2095
1910
  var TestPeer = class {
2096
1911
  constructor(testBuilder) {
2097
1912
  this.testBuilder = testBuilder;
2098
- this.peerId = PublicKey12.random();
2099
- this._swarms = new ComplexMap8(PublicKey12.hash);
1913
+ this.peerId = PublicKey11.random();
1914
+ this._swarms = new ComplexMap9(PublicKey11.hash);
2100
1915
  this._networkManager = this.createNetworkManager();
2101
1916
  }
2102
1917
  createNetworkManager() {
@@ -2169,13 +1984,13 @@ var TestSwarmConnection = class {
2169
1984
  constructor(peer, topic) {
2170
1985
  this.peer = peer;
2171
1986
  this.topic = topic;
2172
- this.plugin = new TestProtocolPlugin(this.peer.peerId.asBuffer());
1987
+ this.protocol = new TestWireProtocol(this.peer.peerId);
2173
1988
  }
2174
1989
  async join(topology = new FullyConnectedTopology()) {
2175
1990
  await this.peer._networkManager.joinSwarm({
2176
1991
  topic: this.topic,
2177
1992
  peerId: this.peer.peerId,
2178
- protocolProvider: adaptProtocolProvider(testProtocolProvider(this.topic.asBuffer(), this.peer.peerId, this.plugin)),
1993
+ protocolProvider: this.protocol.factory,
2179
1994
  topology
2180
1995
  });
2181
1996
  return this;
@@ -2189,9 +2004,6 @@ export {
2189
2004
  TEST_SIGNAL_URL,
2190
2005
  TestBuilder,
2191
2006
  TestPeer,
2192
- TestProtocolPlugin,
2193
- TestSwarmConnection,
2194
- getPeerId,
2195
- testProtocolProvider
2007
+ TestSwarmConnection
2196
2008
  };
2197
2009
  //# sourceMappingURL=index.mjs.map