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

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 (58) hide show
  1. package/dist/lib/browser/{chunk-O2SMNRBC.mjs → chunk-3KLH55NB.mjs} +156 -94
  2. package/dist/lib/browser/chunk-3KLH55NB.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +5 -1
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/testing/index.mjs +9 -5
  6. package/dist/lib/browser/testing/index.mjs.map +3 -3
  7. package/dist/lib/node/index.cjs +632 -458
  8. package/dist/lib/node/index.cjs.map +4 -4
  9. package/dist/lib/node/meta.json +1 -1
  10. package/dist/lib/node/testing/index.cjs +1063 -889
  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 +3 -3
  16. package/dist/types/src/swarm/peer.d.ts.map +1 -1
  17. package/dist/types/src/swarm/swarm-mapper.d.ts.map +1 -1
  18. package/dist/types/src/swarm/swarm.d.ts +2 -2
  19. package/dist/types/src/swarm/swarm.d.ts.map +1 -1
  20. package/dist/types/src/testing/test-builder.d.ts +1 -1
  21. package/dist/types/src/testing/test-builder.d.ts.map +1 -1
  22. package/dist/types/src/tests/basic-test-suite.d.ts.map +1 -1
  23. package/dist/types/src/tests/tcp-transport.test.d.ts +2 -0
  24. package/dist/types/src/tests/tcp-transport.test.d.ts.map +1 -0
  25. package/dist/types/src/topology/star-topology.d.ts.map +1 -1
  26. package/dist/types/src/transport/index.d.ts +1 -0
  27. package/dist/types/src/transport/index.d.ts.map +1 -1
  28. package/dist/types/src/transport/simplepeer-transport-proxy.d.ts.map +1 -1
  29. package/dist/types/src/transport/simplepeer-transport-service.d.ts.map +1 -1
  30. package/dist/types/src/transport/simplepeer-transport.d.ts.map +1 -1
  31. package/dist/types/src/transport/tcp-transport.browser.d.ts +12 -0
  32. package/dist/types/src/transport/tcp-transport.browser.d.ts.map +1 -0
  33. package/dist/types/src/transport/tcp-transport.d.ts +23 -0
  34. package/dist/types/src/transport/tcp-transport.d.ts.map +1 -0
  35. package/dist/types/src/transport/transport.d.ts +2 -1
  36. package/dist/types/src/transport/transport.d.ts.map +1 -1
  37. package/package.json +18 -18
  38. package/src/swarm/connection-limiter.ts +2 -2
  39. package/src/swarm/connection.test.ts +1 -1
  40. package/src/swarm/connection.ts +9 -8
  41. package/src/swarm/peer.ts +8 -3
  42. package/src/swarm/swarm-mapper.ts +4 -7
  43. package/src/swarm/swarm.test.ts +3 -3
  44. package/src/swarm/swarm.ts +3 -3
  45. package/src/testing/test-builder.ts +6 -2
  46. package/src/tests/basic-test-suite.ts +1 -1
  47. package/src/tests/memory-transport.test.ts +2 -2
  48. package/src/tests/tcp-transport.test.ts +67 -0
  49. package/src/tests/webrtc-transport.test.ts +1 -1
  50. package/src/topology/star-topology.ts +1 -4
  51. package/src/transport/index.ts +1 -0
  52. package/src/transport/simplepeer-transport-proxy.ts +29 -28
  53. package/src/transport/simplepeer-transport-service.ts +9 -5
  54. package/src/transport/simplepeer-transport.ts +9 -7
  55. package/src/transport/tcp-transport.browser.ts +28 -0
  56. package/src/transport/tcp-transport.ts +107 -0
  57. package/src/transport/transport.ts +1 -0
  58. package/dist/lib/browser/chunk-O2SMNRBC.mjs.map +0 -7
@@ -7,11 +7,10 @@ import {
7
7
  import { DeferredTask, Event, sleep, synchronized } from "@dxos/async";
8
8
  import { Context, cancelWithContext } from "@dxos/context";
9
9
  import { ErrorStream } from "@dxos/debug";
10
- import { CancelledError, ProtocolError, ConnectionResetError, ConnectivityError, UnknownProtocolError } from "@dxos/errors";
11
10
  import { invariant } from "@dxos/invariant";
12
11
  import { PublicKey } from "@dxos/keys";
13
12
  import { log } from "@dxos/log";
14
- import { trace } from "@dxos/protocols";
13
+ import { CancelledError, ProtocolError, ConnectionResetError, ConnectivityError, UnknownProtocolError, trace } from "@dxos/protocols";
15
14
  function _ts_decorate(decorators, target, key, desc) {
16
15
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
17
16
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -198,7 +197,7 @@ var Connection = class {
198
197
  this.closeReason = err?.message;
199
198
  }
200
199
  if (err instanceof ConnectionResetError) {
201
- log("aborting due to transport ConnectionResetError", void 0, {
200
+ log.warn("aborting due to transport ConnectionResetError", void 0, {
202
201
  F: __dxlog_file,
203
202
  L: 197,
204
203
  S: this,
@@ -206,7 +205,7 @@ var Connection = class {
206
205
  });
207
206
  this.abort().catch((err2) => this.errors.raise(err2));
208
207
  } else if (err instanceof ConnectivityError) {
209
- log("aborting due to transport ConnectivityError", void 0, {
208
+ log.warn("aborting due to transport ConnectivityError", void 0, {
210
209
  F: __dxlog_file,
211
210
  L: 200,
212
211
  S: this,
@@ -214,7 +213,7 @@ var Connection = class {
214
213
  });
215
214
  this.abort().catch((err2) => this.errors.raise(err2));
216
215
  } else if (err instanceof UnknownProtocolError) {
217
- log("unsure what to do for UnknownProtocolError", {
216
+ log.warn("unsure what to do with UnknownProtocolError, will keep on truckin", {
218
217
  err
219
218
  }, {
220
219
  F: __dxlog_file,
@@ -245,14 +244,14 @@ var Connection = class {
245
244
  err
246
245
  }, {
247
246
  F: __dxlog_file,
248
- L: 224,
247
+ L: 225,
249
248
  S: this,
250
249
  C: (f, a) => f(...a)
251
250
  });
252
251
  if (this._state === ConnectionState.CLOSED || this._state === ConnectionState.ABORTED) {
253
252
  log(`abort ignored: already ${this._state}`, this.closeReason, {
254
253
  F: __dxlog_file,
255
- L: 226,
254
+ L: 227,
256
255
  S: this,
257
256
  C: (f, a) => f(...a)
258
257
  });
@@ -268,7 +267,7 @@ var Connection = class {
268
267
  proto: this._protocol
269
268
  }, {
270
269
  F: __dxlog_file,
271
- L: 239,
270
+ L: 240,
272
271
  S: this,
273
272
  C: (f, a) => f(...a)
274
273
  });
@@ -276,7 +275,7 @@ var Connection = class {
276
275
  } catch (err2) {
277
276
  log.catch(err2, void 0, {
278
277
  F: __dxlog_file,
279
- L: 242,
278
+ L: 243,
280
279
  S: this,
281
280
  C: (f, a) => f(...a)
282
281
  });
@@ -286,7 +285,7 @@ var Connection = class {
286
285
  } catch (err2) {
287
286
  log.catch(err2, void 0, {
288
287
  F: __dxlog_file,
289
- L: 249,
288
+ L: 250,
290
289
  S: this,
291
290
  C: (f, a) => f(...a)
292
291
  });
@@ -296,7 +295,7 @@ var Connection = class {
296
295
  } catch (err2) {
297
296
  log.catch(err2, void 0, {
298
297
  F: __dxlog_file,
299
- L: 255,
298
+ L: 256,
300
299
  S: this,
301
300
  C: (f, a) => f(...a)
302
301
  });
@@ -317,7 +316,7 @@ var Connection = class {
317
316
  peerId: this.ownId
318
317
  }, {
319
318
  F: __dxlog_file,
320
- L: 277,
319
+ L: 278,
321
320
  S: this,
322
321
  C: (f, a) => f(...a)
323
322
  });
@@ -327,7 +326,7 @@ var Connection = class {
327
326
  } catch (err2) {
328
327
  log.catch(err2, void 0, {
329
328
  F: __dxlog_file,
330
- L: 284,
329
+ L: 285,
331
330
  S: this,
332
331
  C: (f, a) => f(...a)
333
332
  });
@@ -337,7 +336,7 @@ var Connection = class {
337
336
  } catch (err2) {
338
337
  log.catch(err2, void 0, {
339
338
  F: __dxlog_file,
340
- L: 291,
339
+ L: 292,
341
340
  S: this,
342
341
  C: (f, a) => f(...a)
343
342
  });
@@ -347,7 +346,7 @@ var Connection = class {
347
346
  peerId: this.ownId
348
347
  }, {
349
348
  F: __dxlog_file,
350
- L: 295,
349
+ L: 296,
351
350
  S: this,
352
351
  C: (f, a) => f(...a)
353
352
  });
@@ -390,7 +389,7 @@ var Connection = class {
390
389
  err
391
390
  }, {
392
391
  F: __dxlog_file,
393
- L: 332,
392
+ L: 333,
394
393
  S: this,
395
394
  C: (f, a) => f(...a)
396
395
  });
@@ -403,7 +402,7 @@ var Connection = class {
403
402
  async signal(msg) {
404
403
  invariant(msg.sessionId, void 0, {
405
404
  F: __dxlog_file,
406
- L: 341,
405
+ L: 342,
407
406
  S: this,
408
407
  A: [
409
408
  "msg.sessionId",
@@ -413,7 +412,7 @@ var Connection = class {
413
412
  if (!msg.sessionId.equals(this.sessionId)) {
414
413
  log("dropping signal for incorrect session id", void 0, {
415
414
  F: __dxlog_file,
416
- L: 343,
415
+ L: 344,
417
416
  S: this,
418
417
  C: (f, a) => f(...a)
419
418
  });
@@ -421,7 +420,7 @@ var Connection = class {
421
420
  }
422
421
  invariant(msg.data.signal || msg.data.signalBatch, void 0, {
423
422
  F: __dxlog_file,
424
- L: 346,
423
+ L: 347,
425
424
  S: this,
426
425
  A: [
427
426
  "msg.data.signal || msg.data.signalBatch",
@@ -430,7 +429,7 @@ var Connection = class {
430
429
  });
431
430
  invariant(msg.author?.equals(this.remoteId), void 0, {
432
431
  F: __dxlog_file,
433
- L: 347,
432
+ L: 348,
434
433
  S: this,
435
434
  A: [
436
435
  "msg.author?.equals(this.remoteId)",
@@ -439,7 +438,7 @@ var Connection = class {
439
438
  });
440
439
  invariant(msg.recipient?.equals(this.ownId), void 0, {
441
440
  F: __dxlog_file,
442
- L: 348,
441
+ L: 349,
443
442
  S: this,
444
443
  A: [
445
444
  "msg.recipient?.equals(this.ownId)",
@@ -463,7 +462,7 @@ var Connection = class {
463
462
  msg: msg.data
464
463
  }, {
465
464
  F: __dxlog_file,
466
- L: 357,
465
+ L: 358,
467
466
  S: this,
468
467
  C: (f, a) => f(...a)
469
468
  });
@@ -471,7 +470,7 @@ var Connection = class {
471
470
  } else {
472
471
  invariant(this._transport, "Connection not ready to accept signals.", {
473
472
  F: __dxlog_file,
474
- L: 360,
473
+ L: 361,
475
474
  S: this,
476
475
  A: [
477
476
  "this._transport",
@@ -484,7 +483,7 @@ var Connection = class {
484
483
  msg: msg.data
485
484
  }, {
486
485
  F: __dxlog_file,
487
- L: 361,
486
+ L: 362,
488
487
  S: this,
489
488
  C: (f, a) => f(...a)
490
489
  });
@@ -502,13 +501,13 @@ var Connection = class {
502
501
  peerId: this.ownId
503
502
  }, {
504
503
  F: __dxlog_file,
505
- L: 372,
504
+ L: 373,
506
505
  S: this,
507
506
  C: (f, a) => f(...a)
508
507
  });
509
508
  invariant(state !== this._state, "Already in this state.", {
510
509
  F: __dxlog_file,
511
- L: 373,
510
+ L: 374,
512
511
  S: this,
513
512
  A: [
514
513
  "state !== this._state",
@@ -771,10 +770,10 @@ import { ComplexMap as ComplexMap2, isNotNullOrUndefined } from "@dxos/util";
771
770
  // packages/core/mesh/network-manager/src/swarm/peer.ts
772
771
  import { Event as Event2, scheduleTask, synchronized as synchronized2 } from "@dxos/async";
773
772
  import { Context as Context3 } from "@dxos/context";
774
- import { CancelledError as CancelledError2, SystemError, TimeoutError } from "@dxos/errors";
775
773
  import { invariant as invariant3 } from "@dxos/invariant";
776
774
  import { PublicKey as PublicKey3 } from "@dxos/keys";
777
775
  import { log as log3 } from "@dxos/log";
776
+ import { CancelledError as CancelledError2, SystemError, TimeoutError } from "@dxos/protocols";
778
777
  function _ts_decorate2(decorators, target, key, desc) {
779
778
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
780
779
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -815,6 +814,20 @@ var Peer = class {
815
814
  */
816
815
  async onOffer(message) {
817
816
  const remoteId = message.author;
817
+ if (this.connection && ![
818
+ ConnectionState.CREATED,
819
+ ConnectionState.INITIAL
820
+ ].includes(this.connection.state)) {
821
+ log3.info(`received offer when connection already in ${this.connection.state} state`, void 0, {
822
+ F: __dxlog_file3,
823
+ L: 112,
824
+ S: this,
825
+ C: (f, a) => f(...a)
826
+ });
827
+ return {
828
+ accept: false
829
+ };
830
+ }
818
831
  if (this.connection || this.initiating) {
819
832
  if (remoteId.toHex() < this.localPeerId.toHex()) {
820
833
  log3("close local connection", {
@@ -824,7 +837,7 @@ var Peer = class {
824
837
  sessionId: this.connection?.sessionId
825
838
  }, {
826
839
  F: __dxlog_file3,
827
- L: 117,
840
+ L: 121,
828
841
  S: this,
829
842
  C: (f, a) => f(...a)
830
843
  });
@@ -841,7 +854,7 @@ var Peer = class {
841
854
  if (!this.connection) {
842
855
  invariant3(message.sessionId, void 0, {
843
856
  F: __dxlog_file3,
844
- L: 137,
857
+ L: 141,
845
858
  S: this,
846
859
  A: [
847
860
  "message.sessionId",
@@ -862,7 +875,7 @@ var Peer = class {
862
875
  err
863
876
  }, {
864
877
  F: __dxlog_file3,
865
- L: 147,
878
+ L: 151,
866
879
  S: this,
867
880
  C: (f, a) => f(...a)
868
881
  });
@@ -884,7 +897,7 @@ var Peer = class {
884
897
  async initiateConnection() {
885
898
  invariant3(!this.initiating, "Initiation in progress.", {
886
899
  F: __dxlog_file3,
887
- L: 164,
900
+ L: 168,
888
901
  S: this,
889
902
  A: [
890
903
  "!this.initiating",
@@ -893,7 +906,7 @@ var Peer = class {
893
906
  });
894
907
  invariant3(!this.connection, "Already connected.", {
895
908
  F: __dxlog_file3,
896
- L: 165,
909
+ L: 169,
897
910
  S: this,
898
911
  A: [
899
912
  "!this.connection",
@@ -908,7 +921,7 @@ var Peer = class {
908
921
  sessionId
909
922
  }, {
910
923
  F: __dxlog_file3,
911
- L: 167,
924
+ L: 171,
912
925
  S: this,
913
926
  C: (f, a) => f(...a)
914
927
  });
@@ -933,14 +946,14 @@ var Peer = class {
933
946
  remoteId: this.id
934
947
  }, {
935
948
  F: __dxlog_file3,
936
- L: 183,
949
+ L: 187,
937
950
  S: this,
938
951
  C: (f, a) => f(...a)
939
952
  });
940
953
  if (connection.state !== ConnectionState.INITIAL) {
941
954
  log3("ignoring response", void 0, {
942
955
  F: __dxlog_file3,
943
- L: 185,
956
+ L: 189,
944
957
  S: this,
945
958
  C: (f, a) => f(...a)
946
959
  });
@@ -960,11 +973,17 @@ var Peer = class {
960
973
  remoteId: this.id
961
974
  }, {
962
975
  F: __dxlog_file3,
963
- L: 196,
976
+ L: 200,
964
977
  S: this,
965
978
  C: (f, a) => f(...a)
966
979
  });
967
980
  if (err instanceof TimeoutError) {
981
+ log3.warn("aborting connection due to signalling failure", void 0, {
982
+ F: __dxlog_file3,
983
+ L: 202,
984
+ S: this,
985
+ C: (f, a) => f(...a)
986
+ });
968
987
  await connection.abort(err);
969
988
  }
970
989
  await this.closeConnection(err);
@@ -986,13 +1005,13 @@ var Peer = class {
986
1005
  sessionId
987
1006
  }, {
988
1007
  F: __dxlog_file3,
989
- L: 213,
1008
+ L: 218,
990
1009
  S: this,
991
1010
  C: (f, a) => f(...a)
992
1011
  });
993
1012
  invariant3(!this.connection, "Already connected.", {
994
1013
  F: __dxlog_file3,
995
- L: 220,
1014
+ L: 225,
996
1015
  S: this,
997
1016
  A: [
998
1017
  "!this.connection",
@@ -1028,7 +1047,7 @@ var Peer = class {
1028
1047
  initiator
1029
1048
  }, {
1030
1049
  F: __dxlog_file3,
1031
- L: 239,
1050
+ L: 244,
1032
1051
  S: this,
1033
1052
  C: (f, a) => f(...a)
1034
1053
  });
@@ -1041,14 +1060,14 @@ var Peer = class {
1041
1060
  initiator
1042
1061
  }, {
1043
1062
  F: __dxlog_file3,
1044
- L: 248,
1063
+ L: 253,
1045
1064
  S: this,
1046
1065
  C: (f, a) => f(...a)
1047
1066
  });
1048
1067
  this._connectionLimiter.doneConnecting(sessionId);
1049
1068
  invariant3(this.connection === connection, "Connection mismatch (race condition).", {
1050
1069
  F: __dxlog_file3,
1051
- L: 253,
1070
+ L: 258,
1052
1071
  S: this,
1053
1072
  A: [
1054
1073
  "this.connection === connection",
@@ -1063,7 +1082,7 @@ var Peer = class {
1063
1082
  initiator
1064
1083
  }, {
1065
1084
  F: __dxlog_file3,
1066
- L: 255,
1085
+ L: 260,
1067
1086
  S: this,
1068
1087
  C: (f, a) => f(...a)
1069
1088
  });
@@ -1098,7 +1117,7 @@ var Peer = class {
1098
1117
  err
1099
1118
  }, {
1100
1119
  F: __dxlog_file3,
1101
- L: 295,
1120
+ L: 300,
1102
1121
  S: this,
1103
1122
  C: (f, a) => f(...a)
1104
1123
  });
@@ -1111,7 +1130,7 @@ var Peer = class {
1111
1130
  err
1112
1131
  }, {
1113
1132
  F: __dxlog_file3,
1114
- L: 296,
1133
+ L: 301,
1115
1134
  S: this,
1116
1135
  C: (f, a) => f(...a)
1117
1136
  });
@@ -1130,7 +1149,7 @@ var Peer = class {
1130
1149
  sessionId: connection.sessionId
1131
1150
  }, {
1132
1151
  F: __dxlog_file3,
1133
- L: 321,
1152
+ L: 326,
1134
1153
  S: this,
1135
1154
  C: (f, a) => f(...a)
1136
1155
  });
@@ -1140,7 +1159,7 @@ var Peer = class {
1140
1159
  sessionId: connection.sessionId
1141
1160
  }, {
1142
1161
  F: __dxlog_file3,
1143
- L: 327,
1162
+ L: 332,
1144
1163
  S: this,
1145
1164
  C: (f, a) => f(...a)
1146
1165
  });
@@ -1151,7 +1170,7 @@ var Peer = class {
1151
1170
  message
1152
1171
  }, {
1153
1172
  F: __dxlog_file3,
1154
- L: 332,
1173
+ L: 337,
1155
1174
  S: this,
1156
1175
  C: (f, a) => f(...a)
1157
1176
  });
@@ -1166,7 +1185,7 @@ var Peer = class {
1166
1185
  topic: this.topic
1167
1186
  }, {
1168
1187
  F: __dxlog_file3,
1169
- L: 342,
1188
+ L: 347,
1170
1189
  S: this,
1171
1190
  C: (f, a) => f(...a)
1172
1191
  });
@@ -1679,7 +1698,6 @@ var SwarmMapper = class {
1679
1698
  get peers() {
1680
1699
  return Array.from(this._peers.values());
1681
1700
  }
1682
- // prettier-ignore
1683
1701
  constructor(_swarm) {
1684
1702
  this._swarm = _swarm;
1685
1703
  this._subscriptions = new EventSubscriptions();
@@ -1702,7 +1720,7 @@ var SwarmMapper = class {
1702
1720
  _update() {
1703
1721
  log5("updating swarm", void 0, {
1704
1722
  F: __dxlog_file5,
1705
- L: 75,
1723
+ L: 72,
1706
1724
  S: this,
1707
1725
  C: (f, a) => f(...a)
1708
1726
  });
@@ -1726,7 +1744,7 @@ var SwarmMapper = class {
1726
1744
  totalPeersInSwarm: this._peers.size
1727
1745
  }, {
1728
1746
  F: __dxlog_file5,
1729
- L: 116,
1747
+ L: 113,
1730
1748
  S: this,
1731
1749
  C: (f, a) => f(...a)
1732
1750
  });
@@ -1742,13 +1760,13 @@ var SwarmMapper = class {
1742
1760
  // packages/core/mesh/network-manager/src/swarm/connection-limiter.ts
1743
1761
  import { DeferredTask as DeferredTask2 } from "@dxos/async";
1744
1762
  import { Context as Context5 } from "@dxos/context";
1745
- import { CancelledError as CancelledError3 } from "@dxos/errors";
1746
1763
  import { invariant as invariant5 } from "@dxos/invariant";
1747
1764
  import { PublicKey as PublicKey6 } from "@dxos/keys";
1748
1765
  import { log as log6 } from "@dxos/log";
1766
+ import { CancelledError as CancelledError3 } from "@dxos/protocols";
1749
1767
  import { ComplexMap as ComplexMap4 } from "@dxos/util";
1750
1768
  var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
1751
- var MAX_CONCURRENT_INITIATING_CONNECTIONS = 10;
1769
+ var MAX_CONCURRENT_INITIATING_CONNECTIONS = 50;
1752
1770
  var ConnectionLimiter = class {
1753
1771
  constructor({ maxConcurrentInitConnections = MAX_CONCURRENT_INITIATING_CONNECTIONS } = {}) {
1754
1772
  this._ctx = new Context5();
@@ -2290,7 +2308,6 @@ import { invariant as invariant9 } from "@dxos/invariant";
2290
2308
  import { log as log9 } from "@dxos/log";
2291
2309
  var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/star-topology.ts";
2292
2310
  var StarTopology = class {
2293
- // prettier-ignore
2294
2311
  constructor(_centralPeer) {
2295
2312
  this._centralPeer = _centralPeer;
2296
2313
  }
@@ -2300,7 +2317,7 @@ var StarTopology = class {
2300
2317
  init(controller) {
2301
2318
  invariant9(!this._controller, "Already initialized.", {
2302
2319
  F: __dxlog_file10,
2303
- L: 24,
2320
+ L: 21,
2304
2321
  S: this,
2305
2322
  A: [
2306
2323
  "!this._controller",
@@ -2312,7 +2329,7 @@ var StarTopology = class {
2312
2329
  update() {
2313
2330
  invariant9(this._controller, "Not initialized.", {
2314
2331
  F: __dxlog_file10,
2315
- L: 29,
2332
+ L: 26,
2316
2333
  S: this,
2317
2334
  A: [
2318
2335
  "this._controller",
@@ -2323,7 +2340,7 @@ var StarTopology = class {
2323
2340
  if (!ownPeerId.equals(this._centralPeer)) {
2324
2341
  log9("leaf peer dropping all connections apart from central peer.", void 0, {
2325
2342
  F: __dxlog_file10,
2326
- L: 32,
2343
+ L: 29,
2327
2344
  S: this,
2328
2345
  C: (f, a) => f(...a)
2329
2346
  });
@@ -2333,7 +2350,7 @@ var StarTopology = class {
2333
2350
  peer
2334
2351
  }, {
2335
2352
  F: __dxlog_file10,
2336
- L: 37,
2353
+ L: 34,
2337
2354
  S: this,
2338
2355
  C: (f, a) => f(...a)
2339
2356
  });
@@ -2347,7 +2364,7 @@ var StarTopology = class {
2347
2364
  peer
2348
2365
  }, {
2349
2366
  F: __dxlog_file10,
2350
- L: 46,
2367
+ L: 43,
2351
2368
  S: this,
2352
2369
  C: (f, a) => f(...a)
2353
2370
  });
@@ -2358,7 +2375,7 @@ var StarTopology = class {
2358
2375
  async onOffer(peer) {
2359
2376
  invariant9(this._controller, "Not initialized.", {
2360
2377
  F: __dxlog_file10,
2361
- L: 53,
2378
+ L: 50,
2362
2379
  S: this,
2363
2380
  A: [
2364
2381
  "this._controller",
@@ -2372,7 +2389,7 @@ var StarTopology = class {
2372
2389
  isSelfCentral: ownPeerId.equals(this._centralPeer)
2373
2390
  }, {
2374
2391
  F: __dxlog_file10,
2375
- L: 55,
2392
+ L: 52,
2376
2393
  S: this,
2377
2394
  C: (f, a) => f(...a)
2378
2395
  });
@@ -2575,6 +2592,7 @@ var TransportKind;
2575
2592
  TransportKind2["LIBDATACHANNEL"] = "LIBDATACHANNEL";
2576
2593
  TransportKind2["SIMPLE_PEER_PROXY"] = "SIMPLE_PEER_PROXY";
2577
2594
  TransportKind2["MEMORY"] = "MEMORY";
2595
+ TransportKind2["TCP"] = "TCP";
2578
2596
  })(TransportKind || (TransportKind = {}));
2579
2597
 
2580
2598
  // packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts
@@ -2582,10 +2600,9 @@ import SimplePeerConstructor from "simple-peer";
2582
2600
  import invariant11 from "tiny-invariant";
2583
2601
  import { Event as Event8 } from "@dxos/async";
2584
2602
  import { ErrorStream as ErrorStream4, raise as raise2 } from "@dxos/debug";
2585
- import { ConnectionResetError as ConnectionResetError2, ConnectivityError as ConnectivityError2, ProtocolError as ProtocolError2, UnknownProtocolError as UnknownProtocolError2 } from "@dxos/errors";
2586
2603
  import { PublicKey as PublicKey10 } from "@dxos/keys";
2587
2604
  import { log as log11 } from "@dxos/log";
2588
- import { trace as trace4 } from "@dxos/protocols";
2605
+ import { ConnectionResetError as ConnectionResetError2, ConnectivityError as ConnectivityError2, ProtocolError as ProtocolError2, UnknownProtocolError as UnknownProtocolError2, trace as trace4 } from "@dxos/protocols";
2589
2606
 
2590
2607
  // packages/core/mesh/network-manager/src/transport/webrtc.ts
2591
2608
  var wrtc = null;
@@ -2608,13 +2625,13 @@ var SimplePeerTransport = class {
2608
2625
  id: this._instanceId
2609
2626
  }), {
2610
2627
  F: __dxlog_file12,
2611
- L: 41,
2628
+ L: 40,
2612
2629
  S: this,
2613
2630
  C: (f, a) => f(...a)
2614
2631
  });
2615
2632
  log11("created connection", params, {
2616
2633
  F: __dxlog_file12,
2617
- L: 42,
2634
+ L: 41,
2618
2635
  S: this,
2619
2636
  C: (f, a) => f(...a)
2620
2637
  });
@@ -2627,7 +2644,7 @@ var SimplePeerTransport = class {
2627
2644
  this._peer.on("signal", async (data) => {
2628
2645
  log11("signal", data, {
2629
2646
  F: __dxlog_file12,
2630
- L: 51,
2647
+ L: 50,
2631
2648
  S: this,
2632
2649
  C: (f, a) => f(...a)
2633
2650
  });
@@ -2640,7 +2657,7 @@ var SimplePeerTransport = class {
2640
2657
  this._peer.on("connect", () => {
2641
2658
  log11("connected", void 0, {
2642
2659
  F: __dxlog_file12,
2643
- L: 56,
2660
+ L: 55,
2644
2661
  S: this,
2645
2662
  C: (f, a) => f(...a)
2646
2663
  });
@@ -2650,7 +2667,7 @@ var SimplePeerTransport = class {
2650
2667
  this._peer.on("close", async () => {
2651
2668
  log11("closed", void 0, {
2652
2669
  F: __dxlog_file12,
2653
- L: 62,
2670
+ L: 61,
2654
2671
  S: this,
2655
2672
  C: (f, a) => f(...a)
2656
2673
  });
@@ -2664,38 +2681,52 @@ var SimplePeerTransport = class {
2664
2681
  } else {
2665
2682
  this.errors.raise(new UnknownProtocolError2("unknown RTCError", err));
2666
2683
  }
2667
- } else if (err.name === "InvalidStateError") {
2668
- this.errors.raise(new ConnectionResetError2("safari WebRTC error", err));
2669
2684
  } else if ("code" in err) {
2685
+ log11.info("simple-peer error", err, {
2686
+ F: __dxlog_file12,
2687
+ L: 77,
2688
+ S: this,
2689
+ C: (f, a) => f(...a)
2690
+ });
2670
2691
  switch (err.code) {
2671
2692
  case "ERR_WEBRTC_SUPPORT":
2672
2693
  this.errors.raise(new ProtocolError2("WebRTC not supported", err));
2694
+ break;
2673
2695
  case "ERR_ICE_CONNECTION_FAILURE":
2674
2696
  case "ERR_DATA_CHANNEL":
2675
2697
  case "ERR_CONNECTION_FAILURE":
2676
2698
  case "ERR_SIGNALING":
2677
2699
  this.errors.raise(new ConnectivityError2("unknown communication failure", err));
2700
+ break;
2678
2701
  case "ERR_CREATE_OFFER":
2679
2702
  case "ERR_CREATE_ANSWER":
2680
2703
  case "ERR_SET_LOCAL_DESCRIPTION":
2681
2704
  case "ERR_SET_REMOTE_DESCRIPTION":
2682
2705
  case "ERR_ADD_ICE_CANDIDATE":
2683
2706
  this.errors.raise(new UnknownProtocolError2("unknown simple-peer library failure", err));
2707
+ break;
2684
2708
  default:
2685
2709
  this.errors.raise(new Error("unknown simple-peer error"));
2710
+ break;
2686
2711
  }
2687
2712
  } else {
2713
+ log11.info("unknown peer connection error", err, {
2714
+ F: __dxlog_file12,
2715
+ L: 101,
2716
+ S: this,
2717
+ C: (f, a) => f(...a)
2718
+ });
2688
2719
  this.errors.raise(err);
2689
2720
  }
2690
2721
  try {
2691
- if (typeof this._peer?._pc.getStats === "function") {
2722
+ if (typeof this._peer?._pc?.getStats === "function") {
2692
2723
  this._peer._pc.getStats().then((stats) => {
2693
2724
  log11.warn("report after webrtc error", {
2694
2725
  config: this.params.webrtcConfig,
2695
2726
  stats
2696
2727
  }, {
2697
2728
  F: __dxlog_file12,
2698
- L: 107,
2729
+ L: 109,
2699
2730
  S: this,
2700
2731
  C: (f, a) => f(...a)
2701
2732
  });
@@ -2704,7 +2735,7 @@ var SimplePeerTransport = class {
2704
2735
  } catch (err2) {
2705
2736
  log11.catch(err2, void 0, {
2706
2737
  F: __dxlog_file12,
2707
- L: 114,
2738
+ L: 116,
2708
2739
  S: this,
2709
2740
  C: (f, a) => f(...a)
2710
2741
  });
@@ -2715,7 +2746,7 @@ var SimplePeerTransport = class {
2715
2746
  id: this._instanceId
2716
2747
  }), {
2717
2748
  F: __dxlog_file12,
2718
- L: 119,
2749
+ L: 121,
2719
2750
  S: this,
2720
2751
  C: (f, a) => f(...a)
2721
2752
  });
@@ -2723,7 +2754,7 @@ var SimplePeerTransport = class {
2723
2754
  async destroy() {
2724
2755
  log11("closing...", void 0, {
2725
2756
  F: __dxlog_file12,
2726
- L: 123,
2757
+ L: 125,
2727
2758
  S: this,
2728
2759
  C: (f, a) => f(...a)
2729
2760
  });
@@ -2733,7 +2764,7 @@ var SimplePeerTransport = class {
2733
2764
  this.closed.emit();
2734
2765
  log11("closed", void 0, {
2735
2766
  F: __dxlog_file12,
2736
- L: 128,
2767
+ L: 130,
2737
2768
  S: this,
2738
2769
  C: (f, a) => f(...a)
2739
2770
  });
@@ -2766,7 +2797,6 @@ import { ConnectionState as ConnectionState3 } from "@dxos/protocols/proto/dxos/
2766
2797
  import { ComplexMap as ComplexMap8 } from "@dxos/util";
2767
2798
  var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport-service.ts";
2768
2799
  var SimplePeerTransportService = class {
2769
- // prettier-ignore
2770
2800
  constructor(_webrtcConfig) {
2771
2801
  this._webrtcConfig = _webrtcConfig;
2772
2802
  this.transports = new ComplexMap8(PublicKey11.hash);
@@ -2836,7 +2866,8 @@ var SimplePeerTransportService = class {
2836
2866
  const transportState = {
2837
2867
  transport,
2838
2868
  stream: duplex,
2839
- writeCallbacks: []
2869
+ writeCallbacks: [],
2870
+ state: "OPEN"
2840
2871
  };
2841
2872
  ready();
2842
2873
  this.transports.set(request.proxyId, transportState);
@@ -2846,7 +2877,7 @@ var SimplePeerTransportService = class {
2846
2877
  async sendSignal({ proxyId, signal }) {
2847
2878
  invariant12(this.transports.has(proxyId), void 0, {
2848
2879
  F: __dxlog_file13,
2849
- L: 113,
2880
+ L: 112,
2850
2881
  S: this,
2851
2882
  A: [
2852
2883
  "this.transports.has(proxyId)",
@@ -2856,9 +2887,17 @@ var SimplePeerTransportService = class {
2856
2887
  await this.transports.get(proxyId).transport.signal(signal);
2857
2888
  }
2858
2889
  async sendData({ proxyId, payload }) {
2890
+ if (this.transports.get(proxyId)?.state !== "OPEN") {
2891
+ log12.debug("transport is closed", void 0, {
2892
+ F: __dxlog_file13,
2893
+ L: 118,
2894
+ S: this,
2895
+ C: (f, a) => f(...a)
2896
+ });
2897
+ }
2859
2898
  invariant12(this.transports.has(proxyId), void 0, {
2860
2899
  F: __dxlog_file13,
2861
- L: 118,
2900
+ L: 120,
2862
2901
  S: this,
2863
2902
  A: [
2864
2903
  "this.transports.has(proxyId)",
@@ -2876,10 +2915,12 @@ var SimplePeerTransportService = class {
2876
2915
  async close({ proxyId }) {
2877
2916
  await this.transports.get(proxyId)?.transport.destroy();
2878
2917
  await this.transports.get(proxyId)?.stream.end();
2879
- this.transports.delete(proxyId);
2918
+ if (this.transports.get(proxyId)) {
2919
+ this.transports.get(proxyId).state = "CLOSED";
2920
+ }
2880
2921
  log12("Closed.", void 0, {
2881
2922
  F: __dxlog_file13,
2882
- L: 132,
2923
+ L: 136,
2883
2924
  S: this,
2884
2925
  C: (f, a) => f(...a)
2885
2926
  });
@@ -2891,15 +2932,14 @@ import { Writable } from "@dxos/node-std/stream";
2891
2932
  import { Event as Event9 } from "@dxos/async";
2892
2933
  import { Context as Context6 } from "@dxos/context";
2893
2934
  import { ErrorStream as ErrorStream5 } from "@dxos/debug";
2894
- import { ConnectionResetError as ConnectionResetError3, TimeoutError as TimeoutError2, ProtocolError as ProtocolError3, ConnectivityError as ConnectivityError3, UnknownProtocolError as UnknownProtocolError3 } from "@dxos/errors";
2895
2935
  import { invariant as invariant13 } from "@dxos/invariant";
2896
2936
  import { PublicKey as PublicKey12 } from "@dxos/keys";
2897
2937
  import { log as log13 } from "@dxos/log";
2938
+ import { ConnectionResetError as ConnectionResetError3, TimeoutError as TimeoutError2, ProtocolError as ProtocolError3, ConnectivityError as ConnectivityError3, UnknownProtocolError as UnknownProtocolError3 } from "@dxos/protocols";
2898
2939
  import { ConnectionState as ConnectionState4 } from "@dxos/protocols/proto/dxos/mesh/bridge";
2899
2940
  import { arrayToBuffer } from "@dxos/util";
2900
2941
  var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport-proxy.ts";
2901
2942
  var SimplePeerTransportProxy = class {
2902
- // prettier-ignore
2903
2943
  constructor(_params) {
2904
2944
  this._params = _params;
2905
2945
  this._proxyId = PublicKey12.random();
@@ -2916,7 +2956,7 @@ var SimplePeerTransportProxy = class {
2916
2956
  this._serviceStream.subscribe(async (event) => {
2917
2957
  log13("SimplePeerTransportProxy: event", event, {
2918
2958
  F: __dxlog_file14,
2919
- L: 58,
2959
+ L: 55,
2920
2960
  S: this,
2921
2961
  C: (f, a) => f(...a)
2922
2962
  });
@@ -2945,7 +2985,7 @@ var SimplePeerTransportProxy = class {
2945
2985
  }));
2946
2986
  }, (error) => log13.catch(error, void 0, {
2947
2987
  F: __dxlog_file14,
2948
- L: 82,
2988
+ L: 83,
2949
2989
  S: this,
2950
2990
  C: (f, a) => f(...a)
2951
2991
  }));
@@ -2991,7 +3031,7 @@ var SimplePeerTransportProxy = class {
2991
3031
  } catch (err) {
2992
3032
  log13.catch(err, void 0, {
2993
3033
  F: __dxlog_file14,
2994
- L: 133,
3034
+ L: 134,
2995
3035
  S: this,
2996
3036
  C: (f, a) => f(...a)
2997
3037
  });
@@ -3027,7 +3067,7 @@ var SimplePeerTransportProxyFactory = class {
3027
3067
  createTransport(options) {
3028
3068
  invariant13(this._bridgeService, "SimplePeerTransportProxyFactory is not ready to open connections", {
3029
3069
  F: __dxlog_file14,
3030
- L: 170,
3070
+ L: 171,
3031
3071
  S: this,
3032
3072
  A: [
3033
3073
  "this._bridgeService",
@@ -3045,15 +3085,15 @@ var SimplePeerTransportProxyFactory = class {
3045
3085
  };
3046
3086
  var decodeError = (err) => {
3047
3087
  const message = typeof err === "string" ? err : err.message;
3048
- if (message.includes("ConnectionResetError")) {
3088
+ if (message.includes("CONNECTION_RESET")) {
3049
3089
  return new ConnectionResetError3(message);
3050
- } else if (message.includes("TimeoutError")) {
3090
+ } else if (message.includes("TIMEOUT")) {
3051
3091
  return new TimeoutError2(message);
3052
- } else if (message.includes("ProtocolError")) {
3092
+ } else if (message.includes("PROTOCOL_ERROR")) {
3053
3093
  return new ProtocolError3(message);
3054
- } else if (message.includes("ConnectivityError")) {
3094
+ } else if (message.includes("CONNECTIVITY_ERROR")) {
3055
3095
  return new ConnectivityError3(message);
3056
- } else if (message.includes("UnknownProtocolError")) {
3096
+ } else if (message.includes("UNKNOWN_PROTOCOL_ERROR")) {
3057
3097
  return new UnknownProtocolError3(message);
3058
3098
  } else {
3059
3099
  return typeof err === "string" ? new Error(err) : err;
@@ -3399,6 +3439,26 @@ var createLibDataChannelTransportFactory = (webrtcConfig) => ({
3399
3439
  })
3400
3440
  });
3401
3441
 
3442
+ // packages/core/mesh/network-manager/src/transport/tcp-transport.browser.ts
3443
+ import { Event as Event11 } from "@dxos/async";
3444
+ import { ErrorStream as ErrorStream7 } from "@dxos/debug";
3445
+ var TcpTransportFactory = {
3446
+ createTransport: () => new TcpTransport()
3447
+ };
3448
+ var TcpTransport = class {
3449
+ constructor() {
3450
+ this.closed = new Event11();
3451
+ this.connected = new Event11();
3452
+ this.errors = new ErrorStream7();
3453
+ }
3454
+ async destroy() {
3455
+ throw new Error("Method not implemented.");
3456
+ }
3457
+ signal() {
3458
+ throw new Error("Method not implemented.");
3459
+ }
3460
+ };
3461
+
3402
3462
  // packages/core/mesh/network-manager/src/wire-protocol.ts
3403
3463
  import { Teleport } from "@dxos/teleport";
3404
3464
  var createTeleportProtocolFactory = (onConnection) => {
@@ -3444,6 +3504,8 @@ export {
3444
3504
  SimplePeerTransportProxyFactory,
3445
3505
  LibDataChannelTransport,
3446
3506
  createLibDataChannelTransportFactory,
3507
+ TcpTransportFactory,
3508
+ TcpTransport,
3447
3509
  createTeleportProtocolFactory
3448
3510
  };
3449
- //# sourceMappingURL=chunk-O2SMNRBC.mjs.map
3511
+ //# sourceMappingURL=chunk-3KLH55NB.mjs.map