@dxos/network-manager 0.1.58-main.47053bc → 0.1.58-main.4cbb52d

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 (35) hide show
  1. package/dist/lib/browser/{chunk-O2SMNRBC.mjs → chunk-CNQ55TFQ.mjs} +18 -19
  2. package/dist/lib/browser/chunk-CNQ55TFQ.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +1 -1
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/testing/index.mjs +155 -22
  6. package/dist/lib/browser/testing/index.mjs.map +4 -4
  7. package/dist/lib/node/index.cjs +44 -45
  8. package/dist/lib/node/index.cjs.map +3 -3
  9. package/dist/lib/node/meta.json +1 -1
  10. package/dist/lib/node/testing/index.cjs +202 -70
  11. package/dist/lib/node/testing/index.cjs.map +4 -4
  12. package/dist/types/src/swarm/connection-limiter.d.ts +1 -1
  13. package/dist/types/src/swarm/connection-limiter.d.ts.map +1 -1
  14. package/dist/types/src/swarm/connection.d.ts.map +1 -1
  15. package/dist/types/src/swarm/peer.d.ts +1 -1
  16. package/dist/types/src/swarm/peer.d.ts.map +1 -1
  17. package/dist/types/src/testing/test-builder.d.ts.map +1 -1
  18. package/dist/types/src/tests/tcp-transport.test.d.ts +2 -0
  19. package/dist/types/src/tests/tcp-transport.test.d.ts.map +1 -0
  20. package/dist/types/src/transport/simplepeer-transport.d.ts.map +1 -1
  21. package/dist/types/src/transport/tcp-transport.d.ts +23 -0
  22. package/dist/types/src/transport/tcp-transport.d.ts.map +1 -0
  23. package/dist/types/src/transport/transport.d.ts +2 -1
  24. package/dist/types/src/transport/transport.d.ts.map +1 -1
  25. package/package.json +17 -18
  26. package/src/swarm/connection-limiter.ts +2 -2
  27. package/src/swarm/connection.ts +5 -5
  28. package/src/swarm/peer.ts +1 -1
  29. package/src/testing/test-builder.ts +5 -1
  30. package/src/tests/tcp-transport.test.ts +67 -0
  31. package/src/transport/simplepeer-transport-proxy.ts +4 -4
  32. package/src/transport/simplepeer-transport.ts +1 -2
  33. package/src/transport/tcp-transport.ts +107 -0
  34. package/src/transport/transport.ts +1 -0
  35. package/dist/lib/browser/chunk-O2SMNRBC.mjs.map +0 -7
@@ -513,9 +513,9 @@ module.exports = __toCommonJS(testing_exports);
513
513
 
514
514
  // packages/core/mesh/network-manager/src/testing/test-builder.ts
515
515
  var import_keys14 = require("@dxos/keys");
516
- var import_log16 = require("@dxos/log");
516
+ var import_log17 = require("@dxos/log");
517
517
  var import_messaging2 = require("@dxos/messaging");
518
- var import_protocols6 = require("@dxos/protocols");
518
+ var import_protocols9 = require("@dxos/protocols");
519
519
  var import_services2 = require("@dxos/protocols/proto/dxos/client/services");
520
520
  var import_rpc = require("@dxos/rpc");
521
521
  var import_util11 = require("@dxos/util");
@@ -526,7 +526,7 @@ var import_invariant6 = require("@dxos/invariant");
526
526
  var import_keys8 = require("@dxos/keys");
527
527
  var import_log7 = require("@dxos/log");
528
528
  var import_messaging = require("@dxos/messaging");
529
- var import_protocols4 = require("@dxos/protocols");
529
+ var import_protocols6 = require("@dxos/protocols");
530
530
  var import_services = require("@dxos/protocols/proto/dxos/client/services");
531
531
  var import_util6 = require("@dxos/util");
532
532
 
@@ -540,7 +540,6 @@ var import_util5 = require("@dxos/util");
540
540
  var import_async = require("@dxos/async");
541
541
  var import_context = require("@dxos/context");
542
542
  var import_debug = require("@dxos/debug");
543
- var import_errors = require("@dxos/errors");
544
543
  var import_invariant = require("@dxos/invariant");
545
544
  var import_keys = require("@dxos/keys");
546
545
  var import_log = require("@dxos/log");
@@ -688,7 +687,7 @@ var Connection = class {
688
687
  S: this,
689
688
  C: (f, a) => f(...a)
690
689
  });
691
- this.close(new import_errors.ProtocolError("protocol stream closed")).catch((err) => this.errors.raise(err));
690
+ this.close(new import_protocols.ProtocolError("protocol stream closed")).catch((err) => this.errors.raise(err));
692
691
  });
693
692
  (0, import_invariant.invariant)(!this._transport, void 0, {
694
693
  F: __dxlog_file,
@@ -730,7 +729,7 @@ var Connection = class {
730
729
  if (!this.closeReason) {
731
730
  this.closeReason = err?.message;
732
731
  }
733
- if (err instanceof import_errors.ConnectionResetError) {
732
+ if (err instanceof import_protocols.ConnectionResetError) {
734
733
  (0, import_log.log)("aborting due to transport ConnectionResetError", void 0, {
735
734
  F: __dxlog_file,
736
735
  L: 197,
@@ -738,7 +737,7 @@ var Connection = class {
738
737
  C: (f, a) => f(...a)
739
738
  });
740
739
  this.abort().catch((err2) => this.errors.raise(err2));
741
- } else if (err instanceof import_errors.ConnectivityError) {
740
+ } else if (err instanceof import_protocols.ConnectivityError) {
742
741
  (0, import_log.log)("aborting due to transport ConnectivityError", void 0, {
743
742
  F: __dxlog_file,
744
743
  L: 200,
@@ -746,7 +745,7 @@ var Connection = class {
746
745
  C: (f, a) => f(...a)
747
746
  });
748
747
  this.abort().catch((err2) => this.errors.raise(err2));
749
- } else if (err instanceof import_errors.UnknownProtocolError) {
748
+ } else if (err instanceof import_protocols.UnknownProtocolError) {
750
749
  (0, import_log.log)("unsure what to do for UnknownProtocolError", {
751
750
  err
752
751
  }, {
@@ -916,7 +915,7 @@ var Connection = class {
916
915
  }
917
916
  });
918
917
  } catch (err) {
919
- if (err instanceof import_errors.CancelledError) {
918
+ if (err instanceof import_protocols.CancelledError) {
920
919
  return;
921
920
  }
922
921
  import_log.log.warn("signal failed", {
@@ -1066,7 +1065,7 @@ var import_debug2 = require("@dxos/debug");
1066
1065
  var import_invariant4 = require("@dxos/invariant");
1067
1066
  var import_keys4 = require("@dxos/keys");
1068
1067
  var import_log4 = require("@dxos/log");
1069
- var import_protocols3 = require("@dxos/protocols");
1068
+ var import_protocols4 = require("@dxos/protocols");
1070
1069
  var import_util2 = require("@dxos/util");
1071
1070
 
1072
1071
  // packages/core/mesh/network-manager/src/signal/swarm-messenger.ts
@@ -1304,10 +1303,10 @@ var SwarmMessenger = class {
1304
1303
  // packages/core/mesh/network-manager/src/swarm/peer.ts
1305
1304
  var import_async2 = require("@dxos/async");
1306
1305
  var import_context3 = require("@dxos/context");
1307
- var import_errors2 = require("@dxos/errors");
1308
1306
  var import_invariant3 = require("@dxos/invariant");
1309
1307
  var import_keys3 = require("@dxos/keys");
1310
1308
  var import_log3 = require("@dxos/log");
1309
+ var import_protocols3 = require("@dxos/protocols");
1311
1310
  function _ts_decorate2(decorators, target, key, desc) {
1312
1311
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1313
1312
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -1319,7 +1318,7 @@ function _ts_decorate2(decorators, target, key, desc) {
1319
1318
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1320
1319
  }
1321
1320
  var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts";
1322
- var ConnectionDisplacedError = class extends import_errors2.SystemError {
1321
+ var ConnectionDisplacedError = class extends import_protocols3.SystemError {
1323
1322
  constructor() {
1324
1323
  super("Connection displaced by remote initiator.");
1325
1324
  }
@@ -1387,7 +1386,7 @@ var Peer = class {
1387
1386
  connection.initiate();
1388
1387
  await connection.openConnection();
1389
1388
  } catch (err) {
1390
- if (!(err instanceof import_errors2.CancelledError)) {
1389
+ if (!(err instanceof import_protocols3.CancelledError)) {
1391
1390
  import_log3.log.warn("connection error", {
1392
1391
  topic: this.topic,
1393
1392
  peerId: this.localPeerId,
@@ -1497,7 +1496,7 @@ var Peer = class {
1497
1496
  S: this,
1498
1497
  C: (f, a) => f(...a)
1499
1498
  });
1500
- if (err instanceof import_errors2.TimeoutError) {
1499
+ if (err instanceof import_protocols3.TimeoutError) {
1501
1500
  await connection.abort(err);
1502
1501
  }
1503
1502
  await this.closeConnection(err);
@@ -1757,7 +1756,7 @@ var Swarm = class {
1757
1756
  this.disconnected = new import_async3.Event();
1758
1757
  this.connected = new import_async3.Event();
1759
1758
  this.errors = new import_debug2.ErrorStream();
1760
- import_log4.log.trace("dxos.mesh.swarm.constructor", import_protocols3.trace.begin({
1759
+ import_log4.log.trace("dxos.mesh.swarm.constructor", import_protocols4.trace.begin({
1761
1760
  id: this._instanceId,
1762
1761
  data: {
1763
1762
  topic: this._topic.toHex(),
@@ -1784,7 +1783,7 @@ var Swarm = class {
1784
1783
  onOffer: async (msg) => await this.onOffer(msg),
1785
1784
  topic: this._topic
1786
1785
  });
1787
- import_log4.log.trace("dxos.mesh.swarm.constructor", import_protocols3.trace.end({
1786
+ import_log4.log.trace("dxos.mesh.swarm.constructor", import_protocols4.trace.end({
1788
1787
  id: this._instanceId
1789
1788
  }), {
1790
1789
  F: __dxlog_file4,
@@ -2275,13 +2274,13 @@ var SwarmMapper = class {
2275
2274
  // packages/core/mesh/network-manager/src/swarm/connection-limiter.ts
2276
2275
  var import_async5 = require("@dxos/async");
2277
2276
  var import_context5 = require("@dxos/context");
2278
- var import_errors3 = require("@dxos/errors");
2279
2277
  var import_invariant5 = require("@dxos/invariant");
2280
2278
  var import_keys6 = require("@dxos/keys");
2281
2279
  var import_log6 = require("@dxos/log");
2280
+ var import_protocols5 = require("@dxos/protocols");
2282
2281
  var import_util4 = require("@dxos/util");
2283
2282
  var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
2284
- var MAX_CONCURRENT_INITIATING_CONNECTIONS = 10;
2283
+ var MAX_CONCURRENT_INITIATING_CONNECTIONS = 50;
2285
2284
  var ConnectionLimiter = class {
2286
2285
  constructor({ maxConcurrentInitConnections = MAX_CONCURRENT_INITIATING_CONNECTIONS } = {}) {
2287
2286
  this._ctx = new import_context5.Context();
@@ -2348,7 +2347,7 @@ var ConnectionLimiter = class {
2348
2347
  if (!this._waitingPromises.has(sessionId)) {
2349
2348
  return;
2350
2349
  }
2351
- this._waitingPromises.get(sessionId).reject(new import_errors3.CancelledError());
2350
+ this._waitingPromises.get(sessionId).reject(new import_protocols5.CancelledError());
2352
2351
  this._waitingPromises.delete(sessionId);
2353
2352
  this.resolveWaitingPromises.schedule();
2354
2353
  }
@@ -2466,7 +2465,7 @@ var NetworkManager = class {
2466
2465
  return this._swarms.get(topic);
2467
2466
  }
2468
2467
  async open() {
2469
- import_log7.log.trace("dxos.mesh.network-manager.open", import_protocols4.trace.begin({
2468
+ import_log7.log.trace("dxos.mesh.network-manager.open", import_protocols6.trace.begin({
2470
2469
  id: this._instanceId
2471
2470
  }), {
2472
2471
  F: __dxlog_file7,
@@ -2476,7 +2475,7 @@ var NetworkManager = class {
2476
2475
  });
2477
2476
  await this._messenger.open();
2478
2477
  await this._signalManager.open();
2479
- import_log7.log.trace("dxos.mesh.network-manager.open", import_protocols4.trace.end({
2478
+ import_log7.log.trace("dxos.mesh.network-manager.open", import_protocols6.trace.end({
2480
2479
  id: this._instanceId
2481
2480
  }), {
2482
2481
  F: __dxlog_file7,
@@ -2898,6 +2897,7 @@ var TransportKind;
2898
2897
  TransportKind2["LIBDATACHANNEL"] = "LIBDATACHANNEL";
2899
2898
  TransportKind2["SIMPLE_PEER_PROXY"] = "SIMPLE_PEER_PROXY";
2900
2899
  TransportKind2["MEMORY"] = "MEMORY";
2900
+ TransportKind2["TCP"] = "TCP";
2901
2901
  })(TransportKind || (TransportKind = {}));
2902
2902
 
2903
2903
  // packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts
@@ -2905,10 +2905,9 @@ var import_simple_peer = __toESM(require("simple-peer"));
2905
2905
  var import_tiny_invariant = __toESM(require("tiny-invariant"));
2906
2906
  var import_async9 = require("@dxos/async");
2907
2907
  var import_debug5 = require("@dxos/debug");
2908
- var import_errors4 = require("@dxos/errors");
2909
2908
  var import_keys10 = require("@dxos/keys");
2910
2909
  var import_log11 = require("@dxos/log");
2911
- var import_protocols5 = require("@dxos/protocols");
2910
+ var import_protocols7 = require("@dxos/protocols");
2912
2911
 
2913
2912
  // packages/core/mesh/network-manager/src/transport/webrtc.ts
2914
2913
  var wrtc = null;
@@ -2927,17 +2926,17 @@ var SimplePeerTransport = class {
2927
2926
  this.connected = new import_async9.Event();
2928
2927
  this.errors = new import_debug5.ErrorStream();
2929
2928
  this._instanceId = import_keys10.PublicKey.random().toHex();
2930
- import_log11.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols5.trace.begin({
2929
+ import_log11.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols7.trace.begin({
2931
2930
  id: this._instanceId
2932
2931
  }), {
2933
2932
  F: __dxlog_file10,
2934
- L: 41,
2933
+ L: 40,
2935
2934
  S: this,
2936
2935
  C: (f, a) => f(...a)
2937
2936
  });
2938
2937
  (0, import_log11.log)("created connection", params, {
2939
2938
  F: __dxlog_file10,
2940
- L: 42,
2939
+ L: 41,
2941
2940
  S: this,
2942
2941
  C: (f, a) => f(...a)
2943
2942
  });
@@ -2950,7 +2949,7 @@ var SimplePeerTransport = class {
2950
2949
  this._peer.on("signal", async (data) => {
2951
2950
  (0, import_log11.log)("signal", data, {
2952
2951
  F: __dxlog_file10,
2953
- L: 51,
2952
+ L: 50,
2954
2953
  S: this,
2955
2954
  C: (f, a) => f(...a)
2956
2955
  });
@@ -2963,7 +2962,7 @@ var SimplePeerTransport = class {
2963
2962
  this._peer.on("connect", () => {
2964
2963
  (0, import_log11.log)("connected", void 0, {
2965
2964
  F: __dxlog_file10,
2966
- L: 56,
2965
+ L: 55,
2967
2966
  S: this,
2968
2967
  C: (f, a) => f(...a)
2969
2968
  });
@@ -2973,7 +2972,7 @@ var SimplePeerTransport = class {
2973
2972
  this._peer.on("close", async () => {
2974
2973
  (0, import_log11.log)("closed", void 0, {
2975
2974
  F: __dxlog_file10,
2976
- L: 62,
2975
+ L: 61,
2977
2976
  S: this,
2978
2977
  C: (f, a) => f(...a)
2979
2978
  });
@@ -2983,27 +2982,27 @@ var SimplePeerTransport = class {
2983
2982
  this._peer.on("error", async (err) => {
2984
2983
  if (typeof RTCError !== "undefined" && err instanceof RTCError) {
2985
2984
  if (err.errorDetail === "sctp-failure") {
2986
- this.errors.raise(new import_errors4.ConnectionResetError("sctp-failure from RTCError", err));
2985
+ this.errors.raise(new import_protocols7.ConnectionResetError("sctp-failure from RTCError", err));
2987
2986
  } else {
2988
- this.errors.raise(new import_errors4.UnknownProtocolError("unknown RTCError", err));
2987
+ this.errors.raise(new import_protocols7.UnknownProtocolError("unknown RTCError", err));
2989
2988
  }
2990
2989
  } else if (err.name === "InvalidStateError") {
2991
- this.errors.raise(new import_errors4.ConnectionResetError("safari WebRTC error", err));
2990
+ this.errors.raise(new import_protocols7.ConnectionResetError("safari WebRTC error", err));
2992
2991
  } else if ("code" in err) {
2993
2992
  switch (err.code) {
2994
2993
  case "ERR_WEBRTC_SUPPORT":
2995
- this.errors.raise(new import_errors4.ProtocolError("WebRTC not supported", err));
2994
+ this.errors.raise(new import_protocols7.ProtocolError("WebRTC not supported", err));
2996
2995
  case "ERR_ICE_CONNECTION_FAILURE":
2997
2996
  case "ERR_DATA_CHANNEL":
2998
2997
  case "ERR_CONNECTION_FAILURE":
2999
2998
  case "ERR_SIGNALING":
3000
- this.errors.raise(new import_errors4.ConnectivityError("unknown communication failure", err));
2999
+ this.errors.raise(new import_protocols7.ConnectivityError("unknown communication failure", err));
3001
3000
  case "ERR_CREATE_OFFER":
3002
3001
  case "ERR_CREATE_ANSWER":
3003
3002
  case "ERR_SET_LOCAL_DESCRIPTION":
3004
3003
  case "ERR_SET_REMOTE_DESCRIPTION":
3005
3004
  case "ERR_ADD_ICE_CANDIDATE":
3006
- this.errors.raise(new import_errors4.UnknownProtocolError("unknown simple-peer library failure", err));
3005
+ this.errors.raise(new import_protocols7.UnknownProtocolError("unknown simple-peer library failure", err));
3007
3006
  default:
3008
3007
  this.errors.raise(new Error("unknown simple-peer error"));
3009
3008
  }
@@ -3018,7 +3017,7 @@ var SimplePeerTransport = class {
3018
3017
  stats
3019
3018
  }, {
3020
3019
  F: __dxlog_file10,
3021
- L: 107,
3020
+ L: 106,
3022
3021
  S: this,
3023
3022
  C: (f, a) => f(...a)
3024
3023
  });
@@ -3027,18 +3026,18 @@ var SimplePeerTransport = class {
3027
3026
  } catch (err2) {
3028
3027
  import_log11.log.catch(err2, void 0, {
3029
3028
  F: __dxlog_file10,
3030
- L: 114,
3029
+ L: 113,
3031
3030
  S: this,
3032
3031
  C: (f, a) => f(...a)
3033
3032
  });
3034
3033
  }
3035
3034
  await this.destroy();
3036
3035
  });
3037
- import_log11.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols5.trace.end({
3036
+ import_log11.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols7.trace.end({
3038
3037
  id: this._instanceId
3039
3038
  }), {
3040
3039
  F: __dxlog_file10,
3041
- L: 119,
3040
+ L: 118,
3042
3041
  S: this,
3043
3042
  C: (f, a) => f(...a)
3044
3043
  });
@@ -3046,7 +3045,7 @@ var SimplePeerTransport = class {
3046
3045
  async destroy() {
3047
3046
  (0, import_log11.log)("closing...", void 0, {
3048
3047
  F: __dxlog_file10,
3049
- L: 123,
3048
+ L: 122,
3050
3049
  S: this,
3051
3050
  C: (f, a) => f(...a)
3052
3051
  });
@@ -3056,7 +3055,7 @@ var SimplePeerTransport = class {
3056
3055
  this.closed.emit();
3057
3056
  (0, import_log11.log)("closed", void 0, {
3058
3057
  F: __dxlog_file10,
3059
- L: 128,
3058
+ L: 127,
3060
3059
  S: this,
3061
3060
  C: (f, a) => f(...a)
3062
3061
  });
@@ -3214,10 +3213,10 @@ var import_node_stream3 = require("node:stream");
3214
3213
  var import_async10 = require("@dxos/async");
3215
3214
  var import_context6 = require("@dxos/context");
3216
3215
  var import_debug6 = require("@dxos/debug");
3217
- var import_errors5 = require("@dxos/errors");
3218
3216
  var import_invariant12 = require("@dxos/invariant");
3219
3217
  var import_keys12 = require("@dxos/keys");
3220
3218
  var import_log13 = require("@dxos/log");
3219
+ var import_protocols8 = require("@dxos/protocols");
3221
3220
  var import_bridge2 = require("@dxos/protocols/proto/dxos/mesh/bridge");
3222
3221
  var import_util9 = require("@dxos/util");
3223
3222
  var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport-proxy.ts";
@@ -3369,15 +3368,15 @@ var SimplePeerTransportProxyFactory = class {
3369
3368
  var decodeError = (err) => {
3370
3369
  const message = typeof err === "string" ? err : err.message;
3371
3370
  if (message.includes("ConnectionResetError")) {
3372
- return new import_errors5.ConnectionResetError(message);
3371
+ return new import_protocols8.ConnectionResetError(message);
3373
3372
  } else if (message.includes("TimeoutError")) {
3374
- return new import_errors5.TimeoutError(message);
3373
+ return new import_protocols8.TimeoutError(message);
3375
3374
  } else if (message.includes("ProtocolError")) {
3376
- return new import_errors5.ProtocolError(message);
3375
+ return new import_protocols8.ProtocolError(message);
3377
3376
  } else if (message.includes("ConnectivityError")) {
3378
- return new import_errors5.ConnectivityError(message);
3377
+ return new import_protocols8.ConnectivityError(message);
3379
3378
  } else if (message.includes("UnknownProtocolError")) {
3380
- return new import_errors5.UnknownProtocolError(message);
3379
+ return new import_protocols8.UnknownProtocolError(message);
3381
3380
  } else {
3382
3381
  return typeof err === "string" ? new Error(err) : err;
3383
3382
  }
@@ -3725,10 +3724,140 @@ var createLibDataChannelTransportFactory = (webrtcConfig) => ({
3725
3724
  })
3726
3725
  });
3727
3726
 
3728
- // packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts
3727
+ // packages/core/mesh/network-manager/src/transport/tcp-transport.ts
3728
+ var import_node_net = require("node:net");
3729
3729
  var import_async12 = require("@dxos/async");
3730
- var import_keys13 = require("@dxos/keys");
3730
+ var import_debug8 = require("@dxos/debug");
3731
3731
  var import_log15 = require("@dxos/log");
3732
+ var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/tcp-transport.ts";
3733
+ var TcpTransportFactory = {
3734
+ createTransport: (params) => new TcpTransport(params)
3735
+ };
3736
+ var TcpTransport = class {
3737
+ constructor(options) {
3738
+ this.options = options;
3739
+ this._server = void 0;
3740
+ this._socket = void 0;
3741
+ this.closed = new import_async12.Event();
3742
+ this.connected = new import_async12.Event();
3743
+ this.errors = new import_debug8.ErrorStream();
3744
+ this._destroyed = false;
3745
+ this._connected = false;
3746
+ (0, import_log15.log)("creating", void 0, {
3747
+ F: __dxlog_file14,
3748
+ L: 34,
3749
+ S: this,
3750
+ C: (f, a) => f(...a)
3751
+ });
3752
+ if (this.options.initiator) {
3753
+ setTimeout(async () => {
3754
+ const { Server } = await import("node:net");
3755
+ this._server = new Server((socket) => {
3756
+ (0, import_log15.log)("new connection", void 0, {
3757
+ F: __dxlog_file14,
3758
+ L: 42,
3759
+ S: this,
3760
+ C: (f, a) => f(...a)
3761
+ });
3762
+ if (this._connected) {
3763
+ socket.destroy();
3764
+ }
3765
+ this._handleSocket(socket);
3766
+ });
3767
+ this._server.on("listening", () => {
3768
+ const { port: port2 } = this._server.address();
3769
+ (0, import_log15.log)("listening", {
3770
+ port: port2
3771
+ }, {
3772
+ F: __dxlog_file14,
3773
+ L: 51,
3774
+ S: this,
3775
+ C: (f, a) => f(...a)
3776
+ });
3777
+ void this.options.sendSignal({
3778
+ payload: {
3779
+ port: port2
3780
+ }
3781
+ }).catch((err) => {
3782
+ if (!this._destroyed) {
3783
+ this.errors.raise(err);
3784
+ }
3785
+ });
3786
+ });
3787
+ this._server.on("error", (err) => {
3788
+ this.errors.raise(err);
3789
+ });
3790
+ this._server.listen(0);
3791
+ });
3792
+ }
3793
+ }
3794
+ async destroy() {
3795
+ (0, import_log15.log)("closing", void 0, {
3796
+ F: __dxlog_file14,
3797
+ L: 72,
3798
+ S: this,
3799
+ C: (f, a) => f(...a)
3800
+ });
3801
+ this._socket?.destroy();
3802
+ this._server?.close();
3803
+ this._destroyed = true;
3804
+ }
3805
+ signal({ payload }) {
3806
+ (0, import_log15.log)("received signal", {
3807
+ payload
3808
+ }, {
3809
+ F: __dxlog_file14,
3810
+ L: 80,
3811
+ S: this,
3812
+ C: (f, a) => f(...a)
3813
+ });
3814
+ if (this.options.initiator || this._connected) {
3815
+ return;
3816
+ }
3817
+ const socket = new import_node_net.Socket();
3818
+ this._handleSocket(socket);
3819
+ socket.connect({
3820
+ port: payload.port,
3821
+ host: "localhost"
3822
+ });
3823
+ }
3824
+ _handleSocket(socket) {
3825
+ (0, import_log15.log)("handling socket", {
3826
+ remotePort: socket.remotePort,
3827
+ localPort: socket.localPort
3828
+ }, {
3829
+ F: __dxlog_file14,
3830
+ L: 91,
3831
+ S: this,
3832
+ C: (f, a) => f(...a)
3833
+ });
3834
+ this._socket = socket;
3835
+ this.connected.emit();
3836
+ this.options.stream.pipe(this._socket).pipe(this.options.stream);
3837
+ this._socket.on("connect", () => {
3838
+ (0, import_log15.log)("connected to", {
3839
+ port: this._socket?.remotePort
3840
+ }, {
3841
+ F: __dxlog_file14,
3842
+ L: 97,
3843
+ S: this,
3844
+ C: (f, a) => f(...a)
3845
+ });
3846
+ this._connected = true;
3847
+ });
3848
+ this._socket.on("error", (err) => {
3849
+ this.errors.raise(err);
3850
+ });
3851
+ this._socket.on("close", () => {
3852
+ this.closed.emit();
3853
+ });
3854
+ }
3855
+ };
3856
+
3857
+ // packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts
3858
+ var import_async13 = require("@dxos/async");
3859
+ var import_keys13 = require("@dxos/keys");
3860
+ var import_log16 = require("@dxos/log");
3732
3861
  var import_teleport2 = require("@dxos/teleport");
3733
3862
  var import_util10 = require("@dxos/util");
3734
3863
 
@@ -3754,21 +3883,21 @@ var createTeleportProtocolFactory = (onConnection) => {
3754
3883
  };
3755
3884
 
3756
3885
  // packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts
3757
- var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts";
3886
+ var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts";
3758
3887
  var TestWireProtocol = class {
3759
3888
  constructor(peerId, _extensionFactory = () => []) {
3760
3889
  this.peerId = peerId;
3761
3890
  this._extensionFactory = _extensionFactory;
3762
3891
  this.connections = new import_util10.ComplexMap(import_keys13.PublicKey.hash);
3763
3892
  this.streamConnections = new import_util10.ComplexMap(import_keys13.PublicKey.hash);
3764
- this.connected = new import_async12.Event();
3765
- this.disconnected = new import_async12.Event();
3893
+ this.connected = new import_async13.Event();
3894
+ this.disconnected = new import_async13.Event();
3766
3895
  this.otherConnections = new import_util10.ComplexMap(({ remotePeerId, extension }) => remotePeerId.toHex() + extension);
3767
3896
  this.factory = createTeleportProtocolFactory(async (teleport) => {
3768
- (0, import_log15.log)("create", {
3897
+ (0, import_log16.log)("create", {
3769
3898
  remotePeerId: teleport.remotePeerId
3770
3899
  }, {
3771
- F: __dxlog_file14,
3900
+ F: __dxlog_file15,
3772
3901
  L: 38,
3773
3902
  S: this,
3774
3903
  C: (f, a) => f(...a)
@@ -3802,15 +3931,15 @@ var TestWireProtocol = class {
3802
3931
  if (this.connections.has(peerId)) {
3803
3932
  return this.connections.get(peerId);
3804
3933
  }
3805
- (0, import_log15.log)("waitForConnection", {
3934
+ (0, import_log16.log)("waitForConnection", {
3806
3935
  peerId
3807
3936
  }, {
3808
- F: __dxlog_file14,
3937
+ F: __dxlog_file15,
3809
3938
  L: 67,
3810
3939
  S: this,
3811
3940
  C: (f, a) => f(...a)
3812
3941
  });
3813
- await (0, import_async12.asyncTimeout)(
3942
+ await (0, import_async13.asyncTimeout)(
3814
3943
  this.connected.waitFor((connectedId) => connectedId.equals(peerId)),
3815
3944
  // TODO(nf): Make this configurable.
3816
3945
  1e4
@@ -3838,7 +3967,7 @@ var TestWireProtocol = class {
3838
3967
  };
3839
3968
 
3840
3969
  // packages/core/mesh/network-manager/src/testing/test-builder.ts
3841
- var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-builder.ts";
3970
+ var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-builder.ts";
3842
3971
  var port = process.env.SIGNAL_PORT ?? 4e3;
3843
3972
  var TEST_SIGNAL_HOSTS = [
3844
3973
  {
@@ -3880,15 +4009,18 @@ var TestPeer = class {
3880
4009
  createNetworkManager(transport) {
3881
4010
  let transportFactory;
3882
4011
  if (this.testBuilder.options.signalHosts) {
3883
- import_log16.log.info(`using ${transport} transport with signal server.`, void 0, {
3884
- F: __dxlog_file15,
3885
- L: 104,
4012
+ import_log17.log.info(`using ${transport} transport with signal server.`, void 0, {
4013
+ F: __dxlog_file16,
4014
+ L: 105,
3886
4015
  S: this,
3887
4016
  C: (f, a) => f(...a)
3888
4017
  });
3889
4018
  switch (transport) {
3890
4019
  case TransportKind.MEMORY:
3891
4020
  throw new Error("Memory transport not supported with signal server.");
4021
+ case TransportKind.TCP:
4022
+ transportFactory = TcpTransportFactory;
4023
+ break;
3892
4024
  case TransportKind.SIMPLE_PEER:
3893
4025
  transportFactory = createSimplePeerTransportFactory();
3894
4026
  break;
@@ -3901,7 +4033,7 @@ var TestPeer = class {
3901
4033
  this._proxy = (0, import_rpc.createProtoRpcPeer)({
3902
4034
  port: proxyPort,
3903
4035
  requested: {
3904
- BridgeService: import_protocols6.schema.getService("dxos.mesh.bridge.BridgeService")
4036
+ BridgeService: import_protocols9.schema.getService("dxos.mesh.bridge.BridgeService")
3905
4037
  },
3906
4038
  noHandshake: true,
3907
4039
  encodingOptions: {
@@ -3911,7 +4043,7 @@ var TestPeer = class {
3911
4043
  this._service = (0, import_rpc.createProtoRpcPeer)({
3912
4044
  port: servicePort,
3913
4045
  exposed: {
3914
- BridgeService: import_protocols6.schema.getService("dxos.mesh.bridge.BridgeService")
4046
+ BridgeService: import_protocols9.schema.getService("dxos.mesh.bridge.BridgeService")
3915
4047
  },
3916
4048
  handlers: {
3917
4049
  BridgeService: new SimplePeerTransportService()
@@ -3928,17 +4060,17 @@ var TestPeer = class {
3928
4060
  throw new Error(`Unsupported transport: ${transport}`);
3929
4061
  }
3930
4062
  } else {
3931
- if (transport !== TransportKind.MEMORY) {
3932
- import_log16.log.warn(`specified transport ${transport} but no signalling configured, using memory transport instead`, void 0, {
3933
- F: __dxlog_file15,
3934
- L: 150,
4063
+ if (transport !== TransportKind.MEMORY && transport !== TransportKind.TCP) {
4064
+ import_log17.log.warn(`specified transport ${transport} but no signalling configured, using memory transport instead`, void 0, {
4065
+ F: __dxlog_file16,
4066
+ L: 154,
3935
4067
  S: this,
3936
4068
  C: (f, a) => f(...a)
3937
4069
  });
3938
4070
  }
3939
- import_log16.log.info(`using ${transport} transport without signal server.`, void 0, {
3940
- F: __dxlog_file15,
3941
- L: 152,
4071
+ import_log17.log.info(`using ${transport} transport without signal server.`, void 0, {
4072
+ F: __dxlog_file16,
4073
+ L: 156,
3942
4074
  S: this,
3943
4075
  C: (f, a) => f(...a)
3944
4076
  });