@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
@@ -545,7 +545,6 @@ var import_util5 = require("@dxos/util");
545
545
  var import_async = require("@dxos/async");
546
546
  var import_context = require("@dxos/context");
547
547
  var import_debug = require("@dxos/debug");
548
- var import_errors = require("@dxos/errors");
549
548
  var import_invariant = require("@dxos/invariant");
550
549
  var import_keys = require("@dxos/keys");
551
550
  var import_log = require("@dxos/log");
@@ -693,7 +692,7 @@ var Connection = class {
693
692
  S: this,
694
693
  C: (f, a) => f(...a)
695
694
  });
696
- this.close(new import_errors.ProtocolError("protocol stream closed")).catch((err) => this.errors.raise(err));
695
+ this.close(new import_protocols.ProtocolError("protocol stream closed")).catch((err) => this.errors.raise(err));
697
696
  });
698
697
  (0, import_invariant.invariant)(!this._transport, void 0, {
699
698
  F: __dxlog_file,
@@ -735,7 +734,7 @@ var Connection = class {
735
734
  if (!this.closeReason) {
736
735
  this.closeReason = err?.message;
737
736
  }
738
- if (err instanceof import_errors.ConnectionResetError) {
737
+ if (err instanceof import_protocols.ConnectionResetError) {
739
738
  (0, import_log.log)("aborting due to transport ConnectionResetError", void 0, {
740
739
  F: __dxlog_file,
741
740
  L: 197,
@@ -743,7 +742,7 @@ var Connection = class {
743
742
  C: (f, a) => f(...a)
744
743
  });
745
744
  this.abort().catch((err2) => this.errors.raise(err2));
746
- } else if (err instanceof import_errors.ConnectivityError) {
745
+ } else if (err instanceof import_protocols.ConnectivityError) {
747
746
  (0, import_log.log)("aborting due to transport ConnectivityError", void 0, {
748
747
  F: __dxlog_file,
749
748
  L: 200,
@@ -751,7 +750,7 @@ var Connection = class {
751
750
  C: (f, a) => f(...a)
752
751
  });
753
752
  this.abort().catch((err2) => this.errors.raise(err2));
754
- } else if (err instanceof import_errors.UnknownProtocolError) {
753
+ } else if (err instanceof import_protocols.UnknownProtocolError) {
755
754
  (0, import_log.log)("unsure what to do for UnknownProtocolError", {
756
755
  err
757
756
  }, {
@@ -921,7 +920,7 @@ var Connection = class {
921
920
  }
922
921
  });
923
922
  } catch (err) {
924
- if (err instanceof import_errors.CancelledError) {
923
+ if (err instanceof import_protocols.CancelledError) {
925
924
  return;
926
925
  }
927
926
  import_log.log.warn("signal failed", {
@@ -1071,7 +1070,7 @@ var import_debug2 = require("@dxos/debug");
1071
1070
  var import_invariant4 = require("@dxos/invariant");
1072
1071
  var import_keys4 = require("@dxos/keys");
1073
1072
  var import_log4 = require("@dxos/log");
1074
- var import_protocols3 = require("@dxos/protocols");
1073
+ var import_protocols4 = require("@dxos/protocols");
1075
1074
  var import_util2 = require("@dxos/util");
1076
1075
 
1077
1076
  // packages/core/mesh/network-manager/src/signal/swarm-messenger.ts
@@ -1309,10 +1308,10 @@ var SwarmMessenger = class {
1309
1308
  // packages/core/mesh/network-manager/src/swarm/peer.ts
1310
1309
  var import_async2 = require("@dxos/async");
1311
1310
  var import_context3 = require("@dxos/context");
1312
- var import_errors2 = require("@dxos/errors");
1313
1311
  var import_invariant3 = require("@dxos/invariant");
1314
1312
  var import_keys3 = require("@dxos/keys");
1315
1313
  var import_log3 = require("@dxos/log");
1314
+ var import_protocols3 = require("@dxos/protocols");
1316
1315
  function _ts_decorate2(decorators, target, key, desc) {
1317
1316
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1318
1317
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -1324,7 +1323,7 @@ function _ts_decorate2(decorators, target, key, desc) {
1324
1323
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1325
1324
  }
1326
1325
  var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts";
1327
- var ConnectionDisplacedError = class extends import_errors2.SystemError {
1326
+ var ConnectionDisplacedError = class extends import_protocols3.SystemError {
1328
1327
  constructor() {
1329
1328
  super("Connection displaced by remote initiator.");
1330
1329
  }
@@ -1392,7 +1391,7 @@ var Peer = class {
1392
1391
  connection.initiate();
1393
1392
  await connection.openConnection();
1394
1393
  } catch (err) {
1395
- if (!(err instanceof import_errors2.CancelledError)) {
1394
+ if (!(err instanceof import_protocols3.CancelledError)) {
1396
1395
  import_log3.log.warn("connection error", {
1397
1396
  topic: this.topic,
1398
1397
  peerId: this.localPeerId,
@@ -1502,7 +1501,7 @@ var Peer = class {
1502
1501
  S: this,
1503
1502
  C: (f, a) => f(...a)
1504
1503
  });
1505
- if (err instanceof import_errors2.TimeoutError) {
1504
+ if (err instanceof import_protocols3.TimeoutError) {
1506
1505
  await connection.abort(err);
1507
1506
  }
1508
1507
  await this.closeConnection(err);
@@ -1762,7 +1761,7 @@ var Swarm = class {
1762
1761
  this.disconnected = new import_async3.Event();
1763
1762
  this.connected = new import_async3.Event();
1764
1763
  this.errors = new import_debug2.ErrorStream();
1765
- import_log4.log.trace("dxos.mesh.swarm.constructor", import_protocols3.trace.begin({
1764
+ import_log4.log.trace("dxos.mesh.swarm.constructor", import_protocols4.trace.begin({
1766
1765
  id: this._instanceId,
1767
1766
  data: {
1768
1767
  topic: this._topic.toHex(),
@@ -1789,7 +1788,7 @@ var Swarm = class {
1789
1788
  onOffer: async (msg) => await this.onOffer(msg),
1790
1789
  topic: this._topic
1791
1790
  });
1792
- import_log4.log.trace("dxos.mesh.swarm.constructor", import_protocols3.trace.end({
1791
+ import_log4.log.trace("dxos.mesh.swarm.constructor", import_protocols4.trace.end({
1793
1792
  id: this._instanceId
1794
1793
  }), {
1795
1794
  F: __dxlog_file4,
@@ -2280,13 +2279,13 @@ var SwarmMapper = class {
2280
2279
  // packages/core/mesh/network-manager/src/swarm/connection-limiter.ts
2281
2280
  var import_async5 = require("@dxos/async");
2282
2281
  var import_context5 = require("@dxos/context");
2283
- var import_errors3 = require("@dxos/errors");
2284
2282
  var import_invariant5 = require("@dxos/invariant");
2285
2283
  var import_keys6 = require("@dxos/keys");
2286
2284
  var import_log6 = require("@dxos/log");
2285
+ var import_protocols5 = require("@dxos/protocols");
2287
2286
  var import_util4 = require("@dxos/util");
2288
2287
  var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
2289
- var MAX_CONCURRENT_INITIATING_CONNECTIONS = 10;
2288
+ var MAX_CONCURRENT_INITIATING_CONNECTIONS = 50;
2290
2289
  var ConnectionLimiter = class {
2291
2290
  constructor({ maxConcurrentInitConnections = MAX_CONCURRENT_INITIATING_CONNECTIONS } = {}) {
2292
2291
  this._ctx = new import_context5.Context();
@@ -2353,7 +2352,7 @@ var ConnectionLimiter = class {
2353
2352
  if (!this._waitingPromises.has(sessionId)) {
2354
2353
  return;
2355
2354
  }
2356
- this._waitingPromises.get(sessionId).reject(new import_errors3.CancelledError());
2355
+ this._waitingPromises.get(sessionId).reject(new import_protocols5.CancelledError());
2357
2356
  this._waitingPromises.delete(sessionId);
2358
2357
  this.resolveWaitingPromises.schedule();
2359
2358
  }
@@ -2431,7 +2430,7 @@ var import_invariant6 = require("@dxos/invariant");
2431
2430
  var import_keys8 = require("@dxos/keys");
2432
2431
  var import_log7 = require("@dxos/log");
2433
2432
  var import_messaging = require("@dxos/messaging");
2434
- var import_protocols4 = require("@dxos/protocols");
2433
+ var import_protocols6 = require("@dxos/protocols");
2435
2434
  var import_services = require("@dxos/protocols/proto/dxos/client/services");
2436
2435
  var import_util6 = require("@dxos/util");
2437
2436
  var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts";
@@ -2479,7 +2478,7 @@ var NetworkManager = class {
2479
2478
  return this._swarms.get(topic);
2480
2479
  }
2481
2480
  async open() {
2482
- import_log7.log.trace("dxos.mesh.network-manager.open", import_protocols4.trace.begin({
2481
+ import_log7.log.trace("dxos.mesh.network-manager.open", import_protocols6.trace.begin({
2483
2482
  id: this._instanceId
2484
2483
  }), {
2485
2484
  F: __dxlog_file7,
@@ -2489,7 +2488,7 @@ var NetworkManager = class {
2489
2488
  });
2490
2489
  await this._messenger.open();
2491
2490
  await this._signalManager.open();
2492
- import_log7.log.trace("dxos.mesh.network-manager.open", import_protocols4.trace.end({
2491
+ import_log7.log.trace("dxos.mesh.network-manager.open", import_protocols6.trace.end({
2493
2492
  id: this._instanceId
2494
2493
  }), {
2495
2494
  F: __dxlog_file7,
@@ -3109,6 +3108,7 @@ var TransportKind;
3109
3108
  TransportKind2["LIBDATACHANNEL"] = "LIBDATACHANNEL";
3110
3109
  TransportKind2["SIMPLE_PEER_PROXY"] = "SIMPLE_PEER_PROXY";
3111
3110
  TransportKind2["MEMORY"] = "MEMORY";
3111
+ TransportKind2["TCP"] = "TCP";
3112
3112
  })(TransportKind || (TransportKind = {}));
3113
3113
 
3114
3114
  // packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts
@@ -3116,10 +3116,9 @@ var import_simple_peer = __toESM(require("simple-peer"));
3116
3116
  var import_tiny_invariant = __toESM(require("tiny-invariant"));
3117
3117
  var import_async9 = require("@dxos/async");
3118
3118
  var import_debug5 = require("@dxos/debug");
3119
- var import_errors4 = require("@dxos/errors");
3120
3119
  var import_keys10 = require("@dxos/keys");
3121
3120
  var import_log11 = require("@dxos/log");
3122
- var import_protocols5 = require("@dxos/protocols");
3121
+ var import_protocols7 = require("@dxos/protocols");
3123
3122
 
3124
3123
  // packages/core/mesh/network-manager/src/transport/webrtc.ts
3125
3124
  var wrtc = null;
@@ -3138,17 +3137,17 @@ var SimplePeerTransport = class {
3138
3137
  this.connected = new import_async9.Event();
3139
3138
  this.errors = new import_debug5.ErrorStream();
3140
3139
  this._instanceId = import_keys10.PublicKey.random().toHex();
3141
- import_log11.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols5.trace.begin({
3140
+ import_log11.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols7.trace.begin({
3142
3141
  id: this._instanceId
3143
3142
  }), {
3144
3143
  F: __dxlog_file12,
3145
- L: 41,
3144
+ L: 40,
3146
3145
  S: this,
3147
3146
  C: (f, a) => f(...a)
3148
3147
  });
3149
3148
  (0, import_log11.log)("created connection", params, {
3150
3149
  F: __dxlog_file12,
3151
- L: 42,
3150
+ L: 41,
3152
3151
  S: this,
3153
3152
  C: (f, a) => f(...a)
3154
3153
  });
@@ -3161,7 +3160,7 @@ var SimplePeerTransport = class {
3161
3160
  this._peer.on("signal", async (data) => {
3162
3161
  (0, import_log11.log)("signal", data, {
3163
3162
  F: __dxlog_file12,
3164
- L: 51,
3163
+ L: 50,
3165
3164
  S: this,
3166
3165
  C: (f, a) => f(...a)
3167
3166
  });
@@ -3174,7 +3173,7 @@ var SimplePeerTransport = class {
3174
3173
  this._peer.on("connect", () => {
3175
3174
  (0, import_log11.log)("connected", void 0, {
3176
3175
  F: __dxlog_file12,
3177
- L: 56,
3176
+ L: 55,
3178
3177
  S: this,
3179
3178
  C: (f, a) => f(...a)
3180
3179
  });
@@ -3184,7 +3183,7 @@ var SimplePeerTransport = class {
3184
3183
  this._peer.on("close", async () => {
3185
3184
  (0, import_log11.log)("closed", void 0, {
3186
3185
  F: __dxlog_file12,
3187
- L: 62,
3186
+ L: 61,
3188
3187
  S: this,
3189
3188
  C: (f, a) => f(...a)
3190
3189
  });
@@ -3194,27 +3193,27 @@ var SimplePeerTransport = class {
3194
3193
  this._peer.on("error", async (err) => {
3195
3194
  if (typeof RTCError !== "undefined" && err instanceof RTCError) {
3196
3195
  if (err.errorDetail === "sctp-failure") {
3197
- this.errors.raise(new import_errors4.ConnectionResetError("sctp-failure from RTCError", err));
3196
+ this.errors.raise(new import_protocols7.ConnectionResetError("sctp-failure from RTCError", err));
3198
3197
  } else {
3199
- this.errors.raise(new import_errors4.UnknownProtocolError("unknown RTCError", err));
3198
+ this.errors.raise(new import_protocols7.UnknownProtocolError("unknown RTCError", err));
3200
3199
  }
3201
3200
  } else if (err.name === "InvalidStateError") {
3202
- this.errors.raise(new import_errors4.ConnectionResetError("safari WebRTC error", err));
3201
+ this.errors.raise(new import_protocols7.ConnectionResetError("safari WebRTC error", err));
3203
3202
  } else if ("code" in err) {
3204
3203
  switch (err.code) {
3205
3204
  case "ERR_WEBRTC_SUPPORT":
3206
- this.errors.raise(new import_errors4.ProtocolError("WebRTC not supported", err));
3205
+ this.errors.raise(new import_protocols7.ProtocolError("WebRTC not supported", err));
3207
3206
  case "ERR_ICE_CONNECTION_FAILURE":
3208
3207
  case "ERR_DATA_CHANNEL":
3209
3208
  case "ERR_CONNECTION_FAILURE":
3210
3209
  case "ERR_SIGNALING":
3211
- this.errors.raise(new import_errors4.ConnectivityError("unknown communication failure", err));
3210
+ this.errors.raise(new import_protocols7.ConnectivityError("unknown communication failure", err));
3212
3211
  case "ERR_CREATE_OFFER":
3213
3212
  case "ERR_CREATE_ANSWER":
3214
3213
  case "ERR_SET_LOCAL_DESCRIPTION":
3215
3214
  case "ERR_SET_REMOTE_DESCRIPTION":
3216
3215
  case "ERR_ADD_ICE_CANDIDATE":
3217
- this.errors.raise(new import_errors4.UnknownProtocolError("unknown simple-peer library failure", err));
3216
+ this.errors.raise(new import_protocols7.UnknownProtocolError("unknown simple-peer library failure", err));
3218
3217
  default:
3219
3218
  this.errors.raise(new Error("unknown simple-peer error"));
3220
3219
  }
@@ -3229,7 +3228,7 @@ var SimplePeerTransport = class {
3229
3228
  stats
3230
3229
  }, {
3231
3230
  F: __dxlog_file12,
3232
- L: 107,
3231
+ L: 106,
3233
3232
  S: this,
3234
3233
  C: (f, a) => f(...a)
3235
3234
  });
@@ -3238,18 +3237,18 @@ var SimplePeerTransport = class {
3238
3237
  } catch (err2) {
3239
3238
  import_log11.log.catch(err2, void 0, {
3240
3239
  F: __dxlog_file12,
3241
- L: 114,
3240
+ L: 113,
3242
3241
  S: this,
3243
3242
  C: (f, a) => f(...a)
3244
3243
  });
3245
3244
  }
3246
3245
  await this.destroy();
3247
3246
  });
3248
- import_log11.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols5.trace.end({
3247
+ import_log11.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols7.trace.end({
3249
3248
  id: this._instanceId
3250
3249
  }), {
3251
3250
  F: __dxlog_file12,
3252
- L: 119,
3251
+ L: 118,
3253
3252
  S: this,
3254
3253
  C: (f, a) => f(...a)
3255
3254
  });
@@ -3257,7 +3256,7 @@ var SimplePeerTransport = class {
3257
3256
  async destroy() {
3258
3257
  (0, import_log11.log)("closing...", void 0, {
3259
3258
  F: __dxlog_file12,
3260
- L: 123,
3259
+ L: 122,
3261
3260
  S: this,
3262
3261
  C: (f, a) => f(...a)
3263
3262
  });
@@ -3267,7 +3266,7 @@ var SimplePeerTransport = class {
3267
3266
  this.closed.emit();
3268
3267
  (0, import_log11.log)("closed", void 0, {
3269
3268
  F: __dxlog_file12,
3270
- L: 128,
3269
+ L: 127,
3271
3270
  S: this,
3272
3271
  C: (f, a) => f(...a)
3273
3272
  });
@@ -3425,10 +3424,10 @@ var import_node_stream3 = require("node:stream");
3425
3424
  var import_async10 = require("@dxos/async");
3426
3425
  var import_context6 = require("@dxos/context");
3427
3426
  var import_debug6 = require("@dxos/debug");
3428
- var import_errors5 = require("@dxos/errors");
3429
3427
  var import_invariant12 = require("@dxos/invariant");
3430
3428
  var import_keys12 = require("@dxos/keys");
3431
3429
  var import_log13 = require("@dxos/log");
3430
+ var import_protocols8 = require("@dxos/protocols");
3432
3431
  var import_bridge2 = require("@dxos/protocols/proto/dxos/mesh/bridge");
3433
3432
  var import_util9 = require("@dxos/util");
3434
3433
  var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport-proxy.ts";
@@ -3580,15 +3579,15 @@ var SimplePeerTransportProxyFactory = class {
3580
3579
  var decodeError = (err) => {
3581
3580
  const message = typeof err === "string" ? err : err.message;
3582
3581
  if (message.includes("ConnectionResetError")) {
3583
- return new import_errors5.ConnectionResetError(message);
3582
+ return new import_protocols8.ConnectionResetError(message);
3584
3583
  } else if (message.includes("TimeoutError")) {
3585
- return new import_errors5.TimeoutError(message);
3584
+ return new import_protocols8.TimeoutError(message);
3586
3585
  } else if (message.includes("ProtocolError")) {
3587
- return new import_errors5.ProtocolError(message);
3586
+ return new import_protocols8.ProtocolError(message);
3588
3587
  } else if (message.includes("ConnectivityError")) {
3589
- return new import_errors5.ConnectivityError(message);
3588
+ return new import_protocols8.ConnectivityError(message);
3590
3589
  } else if (message.includes("UnknownProtocolError")) {
3591
- return new import_errors5.UnknownProtocolError(message);
3590
+ return new import_protocols8.UnknownProtocolError(message);
3592
3591
  } else {
3593
3592
  return typeof err === "string" ? new Error(err) : err;
3594
3593
  }