@dxos/network-manager 0.1.56-next.a63ce79 → 0.1.56
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.
- package/dist/lib/browser/{chunk-5TRIVLI6.mjs → chunk-BYYPWP6O.mjs} +105 -89
- package/dist/lib/browser/chunk-BYYPWP6O.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +19 -9
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node/index.cjs +104 -88
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +120 -94
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/types/src/connection-log.d.ts.map +1 -1
- package/dist/types/src/signal/swarm-messenger.d.ts +1 -1
- package/dist/types/src/signal/swarm-messenger.d.ts.map +1 -1
- package/dist/types/src/swarm/connection-limiter.d.ts +1 -1
- package/dist/types/src/swarm/connection-limiter.d.ts.map +1 -1
- package/dist/types/src/swarm/connection.d.ts +2 -1
- package/dist/types/src/swarm/connection.d.ts.map +1 -1
- package/dist/types/src/swarm/peer.d.ts +1 -1
- package/dist/types/src/swarm/peer.d.ts.map +1 -1
- package/dist/types/src/swarm/swarm.d.ts.map +1 -1
- package/dist/types/src/testing/test-builder.d.ts +4 -3
- package/dist/types/src/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/testing/test-wire-protocol.d.ts +13 -2
- package/dist/types/src/testing/test-wire-protocol.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc-transport-proxy.d.ts +1 -1
- package/dist/types/src/transport/webrtc-transport-proxy.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc-transport.d.ts +3 -3
- package/dist/types/src/transport/webrtc-transport.d.ts.map +1 -1
- package/package.json +18 -18
- package/src/connection-log.ts +2 -0
- package/src/signal/swarm-messenger.ts +2 -2
- package/src/swarm/connection-limiter.ts +1 -1
- package/src/swarm/connection.ts +12 -3
- package/src/swarm/peer.ts +8 -6
- package/src/swarm/swarm.ts +5 -5
- package/src/testing/test-builder.ts +9 -5
- package/src/testing/test-wire-protocol.ts +22 -2
- package/src/tests/memory-transport.test.ts +1 -1
- package/src/transport/webrtc-transport-proxy.ts +4 -4
- package/src/transport/webrtc-transport.ts +20 -6
- package/dist/lib/browser/chunk-5TRIVLI6.mjs.map +0 -7
package/dist/lib/node/index.cjs
CHANGED
|
@@ -79,7 +79,7 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
79
79
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
80
80
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
81
81
|
}
|
|
82
|
-
var __dxlog_file = "/
|
|
82
|
+
var __dxlog_file = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/connection.ts";
|
|
83
83
|
var STARTING_SIGNALLING_DELAY = 10;
|
|
84
84
|
var MAX_SIGNALLING_DELAY = 300;
|
|
85
85
|
var ConnectionState;
|
|
@@ -145,7 +145,7 @@ var Connection = class {
|
|
|
145
145
|
initiator: this.initiator
|
|
146
146
|
}, {
|
|
147
147
|
F: __dxlog_file,
|
|
148
|
-
L:
|
|
148
|
+
L: 96,
|
|
149
149
|
S: this,
|
|
150
150
|
C: (f, a) => f(...a)
|
|
151
151
|
});
|
|
@@ -165,7 +165,7 @@ var Connection = class {
|
|
|
165
165
|
async openConnection() {
|
|
166
166
|
(0, import_invariant.invariant)(this._state === ConnectionState.INITIAL, "Invalid state.", {
|
|
167
167
|
F: __dxlog_file,
|
|
168
|
-
L:
|
|
168
|
+
L: 121,
|
|
169
169
|
S: this,
|
|
170
170
|
A: [
|
|
171
171
|
"this._state === ConnectionState.INITIAL",
|
|
@@ -176,7 +176,7 @@ var Connection = class {
|
|
|
176
176
|
id: this._instanceId
|
|
177
177
|
}), {
|
|
178
178
|
F: __dxlog_file,
|
|
179
|
-
L:
|
|
179
|
+
L: 122,
|
|
180
180
|
S: this,
|
|
181
181
|
C: (f, a) => f(...a)
|
|
182
182
|
});
|
|
@@ -188,7 +188,7 @@ var Connection = class {
|
|
|
188
188
|
initiator: this.initiator
|
|
189
189
|
}, {
|
|
190
190
|
F: __dxlog_file,
|
|
191
|
-
L:
|
|
191
|
+
L: 123,
|
|
192
192
|
S: this,
|
|
193
193
|
C: (f, a) => f(...a)
|
|
194
194
|
});
|
|
@@ -199,7 +199,7 @@ var Connection = class {
|
|
|
199
199
|
this._protocol.stream.on("close", () => {
|
|
200
200
|
(0, import_log.log)("protocol stream closed", void 0, {
|
|
201
201
|
F: __dxlog_file,
|
|
202
|
-
L:
|
|
202
|
+
L: 140,
|
|
203
203
|
S: this,
|
|
204
204
|
C: (f, a) => f(...a)
|
|
205
205
|
});
|
|
@@ -207,7 +207,7 @@ var Connection = class {
|
|
|
207
207
|
});
|
|
208
208
|
(0, import_invariant.invariant)(!this._transport, void 0, {
|
|
209
209
|
F: __dxlog_file,
|
|
210
|
-
L:
|
|
210
|
+
L: 144,
|
|
211
211
|
S: this,
|
|
212
212
|
A: [
|
|
213
213
|
"!this._transport",
|
|
@@ -227,6 +227,9 @@ var Connection = class {
|
|
|
227
227
|
this.close().catch((err) => this.errors.raise(err));
|
|
228
228
|
});
|
|
229
229
|
this._transport.errors.handle((err) => {
|
|
230
|
+
if (!this.closeReason) {
|
|
231
|
+
this.closeReason = err?.message;
|
|
232
|
+
}
|
|
230
233
|
if (this._state !== ConnectionState.CLOSED && this._state !== ConnectionState.CLOSING) {
|
|
231
234
|
this.errors.raise(err);
|
|
232
235
|
}
|
|
@@ -239,12 +242,15 @@ var Connection = class {
|
|
|
239
242
|
id: this._instanceId
|
|
240
243
|
}), {
|
|
241
244
|
F: __dxlog_file,
|
|
242
|
-
L:
|
|
245
|
+
L: 176,
|
|
243
246
|
S: this,
|
|
244
247
|
C: (f, a) => f(...a)
|
|
245
248
|
});
|
|
246
249
|
}
|
|
247
|
-
async close() {
|
|
250
|
+
async close(err) {
|
|
251
|
+
if (!this.closeReason) {
|
|
252
|
+
this.closeReason = err?.message;
|
|
253
|
+
}
|
|
248
254
|
if (this._state === ConnectionState.CLOSED) {
|
|
249
255
|
return;
|
|
250
256
|
}
|
|
@@ -254,26 +260,26 @@ var Connection = class {
|
|
|
254
260
|
peerId: this.ownId
|
|
255
261
|
}, {
|
|
256
262
|
F: __dxlog_file,
|
|
257
|
-
L:
|
|
263
|
+
L: 191,
|
|
258
264
|
S: this,
|
|
259
265
|
C: (f, a) => f(...a)
|
|
260
266
|
});
|
|
261
267
|
try {
|
|
262
268
|
await this._protocol.destroy();
|
|
263
|
-
} catch (
|
|
264
|
-
import_log.log.catch(
|
|
269
|
+
} catch (err2) {
|
|
270
|
+
import_log.log.catch(err2, void 0, {
|
|
265
271
|
F: __dxlog_file,
|
|
266
|
-
L:
|
|
272
|
+
L: 197,
|
|
267
273
|
S: this,
|
|
268
274
|
C: (f, a) => f(...a)
|
|
269
275
|
});
|
|
270
276
|
}
|
|
271
277
|
try {
|
|
272
278
|
await this._transport?.destroy();
|
|
273
|
-
} catch (
|
|
274
|
-
import_log.log.catch(
|
|
279
|
+
} catch (err2) {
|
|
280
|
+
import_log.log.catch(err2, void 0, {
|
|
275
281
|
F: __dxlog_file,
|
|
276
|
-
L:
|
|
282
|
+
L: 204,
|
|
277
283
|
S: this,
|
|
278
284
|
C: (f, a) => f(...a)
|
|
279
285
|
});
|
|
@@ -282,7 +288,7 @@ var Connection = class {
|
|
|
282
288
|
peerId: this.ownId
|
|
283
289
|
}, {
|
|
284
290
|
F: __dxlog_file,
|
|
285
|
-
L:
|
|
291
|
+
L: 207,
|
|
286
292
|
S: this,
|
|
287
293
|
C: (f, a) => f(...a)
|
|
288
294
|
});
|
|
@@ -297,8 +303,10 @@ var Connection = class {
|
|
|
297
303
|
return;
|
|
298
304
|
}
|
|
299
305
|
try {
|
|
300
|
-
|
|
301
|
-
|
|
306
|
+
if (process.env.NODE_ENV !== "test") {
|
|
307
|
+
await (0, import_context.cancelWithContext)(this._ctx, (0, import_async.sleep)(this._signallingDelay));
|
|
308
|
+
this._signallingDelay = Math.min(this._signallingDelay * 2, MAX_SIGNALLING_DELAY);
|
|
309
|
+
}
|
|
302
310
|
const signals = [
|
|
303
311
|
...this._outgoingSignalBuffer
|
|
304
312
|
];
|
|
@@ -322,7 +330,7 @@ var Connection = class {
|
|
|
322
330
|
err
|
|
323
331
|
}, {
|
|
324
332
|
F: __dxlog_file,
|
|
325
|
-
L:
|
|
333
|
+
L: 243,
|
|
326
334
|
S: this,
|
|
327
335
|
C: (f, a) => f(...a)
|
|
328
336
|
});
|
|
@@ -335,7 +343,7 @@ var Connection = class {
|
|
|
335
343
|
async signal(msg) {
|
|
336
344
|
(0, import_invariant.invariant)(msg.sessionId, void 0, {
|
|
337
345
|
F: __dxlog_file,
|
|
338
|
-
L:
|
|
346
|
+
L: 252,
|
|
339
347
|
S: this,
|
|
340
348
|
A: [
|
|
341
349
|
"msg.sessionId",
|
|
@@ -345,7 +353,7 @@ var Connection = class {
|
|
|
345
353
|
if (!msg.sessionId.equals(this.sessionId)) {
|
|
346
354
|
(0, import_log.log)("dropping signal for incorrect session id", void 0, {
|
|
347
355
|
F: __dxlog_file,
|
|
348
|
-
L:
|
|
356
|
+
L: 254,
|
|
349
357
|
S: this,
|
|
350
358
|
C: (f, a) => f(...a)
|
|
351
359
|
});
|
|
@@ -353,7 +361,7 @@ var Connection = class {
|
|
|
353
361
|
}
|
|
354
362
|
(0, import_invariant.invariant)(msg.data.signal || msg.data.signalBatch, void 0, {
|
|
355
363
|
F: __dxlog_file,
|
|
356
|
-
L:
|
|
364
|
+
L: 257,
|
|
357
365
|
S: this,
|
|
358
366
|
A: [
|
|
359
367
|
"msg.data.signal || msg.data.signalBatch",
|
|
@@ -362,7 +370,7 @@ var Connection = class {
|
|
|
362
370
|
});
|
|
363
371
|
(0, import_invariant.invariant)(msg.author?.equals(this.remoteId), void 0, {
|
|
364
372
|
F: __dxlog_file,
|
|
365
|
-
L:
|
|
373
|
+
L: 258,
|
|
366
374
|
S: this,
|
|
367
375
|
A: [
|
|
368
376
|
"msg.author?.equals(this.remoteId)",
|
|
@@ -371,7 +379,7 @@ var Connection = class {
|
|
|
371
379
|
});
|
|
372
380
|
(0, import_invariant.invariant)(msg.recipient?.equals(this.ownId), void 0, {
|
|
373
381
|
F: __dxlog_file,
|
|
374
|
-
L:
|
|
382
|
+
L: 259,
|
|
375
383
|
S: this,
|
|
376
384
|
A: [
|
|
377
385
|
"msg.recipient?.equals(this.ownId)",
|
|
@@ -392,7 +400,7 @@ var Connection = class {
|
|
|
392
400
|
msg: msg.data
|
|
393
401
|
}, {
|
|
394
402
|
F: __dxlog_file,
|
|
395
|
-
L:
|
|
403
|
+
L: 268,
|
|
396
404
|
S: this,
|
|
397
405
|
C: (f, a) => f(...a)
|
|
398
406
|
});
|
|
@@ -400,7 +408,7 @@ var Connection = class {
|
|
|
400
408
|
} else {
|
|
401
409
|
(0, import_invariant.invariant)(this._transport, "Connection not ready to accept signals.", {
|
|
402
410
|
F: __dxlog_file,
|
|
403
|
-
L:
|
|
411
|
+
L: 271,
|
|
404
412
|
S: this,
|
|
405
413
|
A: [
|
|
406
414
|
"this._transport",
|
|
@@ -413,7 +421,7 @@ var Connection = class {
|
|
|
413
421
|
msg: msg.data
|
|
414
422
|
}, {
|
|
415
423
|
F: __dxlog_file,
|
|
416
|
-
L:
|
|
424
|
+
L: 272,
|
|
417
425
|
S: this,
|
|
418
426
|
C: (f, a) => f(...a)
|
|
419
427
|
});
|
|
@@ -428,13 +436,13 @@ var Connection = class {
|
|
|
428
436
|
peerId: this.ownId
|
|
429
437
|
}, {
|
|
430
438
|
F: __dxlog_file,
|
|
431
|
-
L:
|
|
439
|
+
L: 279,
|
|
432
440
|
S: this,
|
|
433
441
|
C: (f, a) => f(...a)
|
|
434
442
|
});
|
|
435
443
|
(0, import_invariant.invariant)(state !== this._state, "Already in this state.", {
|
|
436
444
|
F: __dxlog_file,
|
|
437
|
-
L:
|
|
445
|
+
L: 280,
|
|
438
446
|
S: this,
|
|
439
447
|
A: [
|
|
440
448
|
"state !== this._state",
|
|
@@ -466,7 +474,7 @@ var import_keys2 = require("@dxos/keys");
|
|
|
466
474
|
var import_log2 = require("@dxos/log");
|
|
467
475
|
var import_protocols2 = require("@dxos/protocols");
|
|
468
476
|
var import_util = require("@dxos/util");
|
|
469
|
-
var __dxlog_file2 = "/
|
|
477
|
+
var __dxlog_file2 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
|
|
470
478
|
var SwarmMessage = import_protocols2.schema.getCodecForType("dxos.mesh.swarm.SwarmMessage");
|
|
471
479
|
var SwarmMessenger = class {
|
|
472
480
|
constructor({ sendMessage, onSignal, onOffer, topic }) {
|
|
@@ -708,9 +716,10 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
708
716
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
709
717
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
710
718
|
}
|
|
711
|
-
var __dxlog_file3 = "/
|
|
719
|
+
var __dxlog_file3 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/peer.ts";
|
|
712
720
|
var CONNECTION_COUNTS_STABLE_AFTER = 5e3;
|
|
713
721
|
var Peer = class {
|
|
722
|
+
// TODO(burdon): Convert to map?
|
|
714
723
|
constructor(id, topic, localPeerId, _signalMessaging, _protocolProvider, _transportFactory, _connectionLimiter, _callbacks) {
|
|
715
724
|
this.id = id;
|
|
716
725
|
this.topic = topic;
|
|
@@ -740,12 +749,12 @@ var Peer = class {
|
|
|
740
749
|
sessionId: this.connection?.sessionId
|
|
741
750
|
}, {
|
|
742
751
|
F: __dxlog_file3,
|
|
743
|
-
L:
|
|
752
|
+
L: 108,
|
|
744
753
|
S: this,
|
|
745
754
|
C: (f, a) => f(...a)
|
|
746
755
|
});
|
|
747
756
|
if (this.connection) {
|
|
748
|
-
await this.closeConnection();
|
|
757
|
+
await this.closeConnection(new Error("Connection displaced by remote initiator."));
|
|
749
758
|
}
|
|
750
759
|
} else {
|
|
751
760
|
return {
|
|
@@ -757,7 +766,7 @@ var Peer = class {
|
|
|
757
766
|
if (!this.connection) {
|
|
758
767
|
(0, import_invariant3.invariant)(message.sessionId, void 0, {
|
|
759
768
|
F: __dxlog_file3,
|
|
760
|
-
L:
|
|
769
|
+
L: 128,
|
|
761
770
|
S: this,
|
|
762
771
|
A: [
|
|
763
772
|
"message.sessionId",
|
|
@@ -777,12 +786,12 @@ var Peer = class {
|
|
|
777
786
|
err
|
|
778
787
|
}, {
|
|
779
788
|
F: __dxlog_file3,
|
|
780
|
-
L:
|
|
789
|
+
L: 136,
|
|
781
790
|
S: this,
|
|
782
791
|
C: (f, a) => f(...a)
|
|
783
792
|
});
|
|
784
793
|
}
|
|
785
|
-
await this.closeConnection();
|
|
794
|
+
await this.closeConnection(err);
|
|
786
795
|
}
|
|
787
796
|
return {
|
|
788
797
|
accept: true
|
|
@@ -799,7 +808,7 @@ var Peer = class {
|
|
|
799
808
|
async initiateConnection() {
|
|
800
809
|
(0, import_invariant3.invariant)(!this.initiating, "Initiation in progress.", {
|
|
801
810
|
F: __dxlog_file3,
|
|
802
|
-
L:
|
|
811
|
+
L: 153,
|
|
803
812
|
S: this,
|
|
804
813
|
A: [
|
|
805
814
|
"!this.initiating",
|
|
@@ -808,7 +817,7 @@ var Peer = class {
|
|
|
808
817
|
});
|
|
809
818
|
(0, import_invariant3.invariant)(!this.connection, "Already connected.", {
|
|
810
819
|
F: __dxlog_file3,
|
|
811
|
-
L:
|
|
820
|
+
L: 154,
|
|
812
821
|
S: this,
|
|
813
822
|
A: [
|
|
814
823
|
"!this.connection",
|
|
@@ -823,7 +832,7 @@ var Peer = class {
|
|
|
823
832
|
sessionId
|
|
824
833
|
}, {
|
|
825
834
|
F: __dxlog_file3,
|
|
826
|
-
L:
|
|
835
|
+
L: 156,
|
|
827
836
|
S: this,
|
|
828
837
|
C: (f, a) => f(...a)
|
|
829
838
|
});
|
|
@@ -847,14 +856,14 @@ var Peer = class {
|
|
|
847
856
|
remoteId: this.id
|
|
848
857
|
}, {
|
|
849
858
|
F: __dxlog_file3,
|
|
850
|
-
L:
|
|
859
|
+
L: 171,
|
|
851
860
|
S: this,
|
|
852
861
|
C: (f, a) => f(...a)
|
|
853
862
|
});
|
|
854
863
|
if (connection.state !== ConnectionState.INITIAL) {
|
|
855
864
|
(0, import_log3.log)("ignoring response", void 0, {
|
|
856
865
|
F: __dxlog_file3,
|
|
857
|
-
L:
|
|
866
|
+
L: 173,
|
|
858
867
|
S: this,
|
|
859
868
|
C: (f, a) => f(...a)
|
|
860
869
|
});
|
|
@@ -874,11 +883,11 @@ var Peer = class {
|
|
|
874
883
|
remoteId: this.id
|
|
875
884
|
}, {
|
|
876
885
|
F: __dxlog_file3,
|
|
877
|
-
L:
|
|
886
|
+
L: 184,
|
|
878
887
|
S: this,
|
|
879
888
|
C: (f, a) => f(...a)
|
|
880
889
|
});
|
|
881
|
-
await this.closeConnection();
|
|
890
|
+
await this.closeConnection(err);
|
|
882
891
|
throw err;
|
|
883
892
|
} finally {
|
|
884
893
|
this.initiating = false;
|
|
@@ -897,13 +906,13 @@ var Peer = class {
|
|
|
897
906
|
sessionId
|
|
898
907
|
}, {
|
|
899
908
|
F: __dxlog_file3,
|
|
900
|
-
L:
|
|
909
|
+
L: 198,
|
|
901
910
|
S: this,
|
|
902
911
|
C: (f, a) => f(...a)
|
|
903
912
|
});
|
|
904
913
|
(0, import_invariant3.invariant)(!this.connection, "Already connected.", {
|
|
905
914
|
F: __dxlog_file3,
|
|
906
|
-
L:
|
|
915
|
+
L: 205,
|
|
907
916
|
S: this,
|
|
908
917
|
A: [
|
|
909
918
|
"!this.connection",
|
|
@@ -944,7 +953,7 @@ var Peer = class {
|
|
|
944
953
|
initiator
|
|
945
954
|
}, {
|
|
946
955
|
F: __dxlog_file3,
|
|
947
|
-
L:
|
|
956
|
+
L: 231,
|
|
948
957
|
S: this,
|
|
949
958
|
C: (f, a) => f(...a)
|
|
950
959
|
});
|
|
@@ -958,13 +967,13 @@ var Peer = class {
|
|
|
958
967
|
initiator
|
|
959
968
|
}, {
|
|
960
969
|
F: __dxlog_file3,
|
|
961
|
-
L:
|
|
970
|
+
L: 242,
|
|
962
971
|
S: this,
|
|
963
972
|
C: (f, a) => f(...a)
|
|
964
973
|
});
|
|
965
974
|
(0, import_invariant3.invariant)(this.connection === connection, "Connection mismatch (race condition).", {
|
|
966
975
|
F: __dxlog_file3,
|
|
967
|
-
L:
|
|
976
|
+
L: 243,
|
|
968
977
|
S: this,
|
|
969
978
|
A: [
|
|
970
979
|
"this.connection === connection",
|
|
@@ -979,7 +988,7 @@ var Peer = class {
|
|
|
979
988
|
initiator
|
|
980
989
|
}, {
|
|
981
990
|
F: __dxlog_file3,
|
|
982
|
-
L:
|
|
991
|
+
L: 245,
|
|
983
992
|
S: this,
|
|
984
993
|
C: (f, a) => f(...a)
|
|
985
994
|
});
|
|
@@ -1009,7 +1018,7 @@ var Peer = class {
|
|
|
1009
1018
|
err
|
|
1010
1019
|
}, {
|
|
1011
1020
|
F: __dxlog_file3,
|
|
1012
|
-
L:
|
|
1021
|
+
L: 279,
|
|
1013
1022
|
S: this,
|
|
1014
1023
|
C: (f, a) => f(...a)
|
|
1015
1024
|
});
|
|
@@ -1022,16 +1031,16 @@ var Peer = class {
|
|
|
1022
1031
|
err
|
|
1023
1032
|
}, {
|
|
1024
1033
|
F: __dxlog_file3,
|
|
1025
|
-
L:
|
|
1034
|
+
L: 280,
|
|
1026
1035
|
S: this,
|
|
1027
1036
|
C: (f, a) => f(...a)
|
|
1028
1037
|
});
|
|
1029
|
-
void this.closeConnection();
|
|
1038
|
+
void this.closeConnection(err);
|
|
1030
1039
|
});
|
|
1031
1040
|
this.connection = connection;
|
|
1032
1041
|
return connection;
|
|
1033
1042
|
}
|
|
1034
|
-
async closeConnection() {
|
|
1043
|
+
async closeConnection(err) {
|
|
1035
1044
|
if (!this.connection) {
|
|
1036
1045
|
return;
|
|
1037
1046
|
}
|
|
@@ -1041,17 +1050,17 @@ var Peer = class {
|
|
|
1041
1050
|
sessionId: connection.sessionId
|
|
1042
1051
|
}, {
|
|
1043
1052
|
F: __dxlog_file3,
|
|
1044
|
-
L:
|
|
1053
|
+
L: 303,
|
|
1045
1054
|
S: this,
|
|
1046
1055
|
C: (f, a) => f(...a)
|
|
1047
1056
|
});
|
|
1048
|
-
await connection.close();
|
|
1057
|
+
await connection.close(err);
|
|
1049
1058
|
(0, import_log3.log)("closed", {
|
|
1050
1059
|
peerId: this.id,
|
|
1051
1060
|
sessionId: connection.sessionId
|
|
1052
1061
|
}, {
|
|
1053
1062
|
F: __dxlog_file3,
|
|
1054
|
-
L:
|
|
1063
|
+
L: 309,
|
|
1055
1064
|
S: this,
|
|
1056
1065
|
C: (f, a) => f(...a)
|
|
1057
1066
|
});
|
|
@@ -1062,7 +1071,7 @@ var Peer = class {
|
|
|
1062
1071
|
message
|
|
1063
1072
|
}, {
|
|
1064
1073
|
F: __dxlog_file3,
|
|
1065
|
-
L:
|
|
1074
|
+
L: 314,
|
|
1066
1075
|
S: this,
|
|
1067
1076
|
C: (f, a) => f(...a)
|
|
1068
1077
|
});
|
|
@@ -1077,7 +1086,7 @@ var Peer = class {
|
|
|
1077
1086
|
topic: this.topic
|
|
1078
1087
|
}, {
|
|
1079
1088
|
F: __dxlog_file3,
|
|
1080
|
-
L:
|
|
1089
|
+
L: 324,
|
|
1081
1090
|
S: this,
|
|
1082
1091
|
C: (f, a) => f(...a)
|
|
1083
1092
|
});
|
|
@@ -1111,7 +1120,7 @@ function _ts_decorate3(decorators, target, key, desc) {
|
|
|
1111
1120
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1112
1121
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1113
1122
|
}
|
|
1114
|
-
var __dxlog_file4 = "/
|
|
1123
|
+
var __dxlog_file4 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/swarm.ts";
|
|
1115
1124
|
var INITIATION_DELAY = 100;
|
|
1116
1125
|
var getClassName = (obj) => Object.getPrototypeOf(obj).constructor.name;
|
|
1117
1126
|
var Swarm = class {
|
|
@@ -1126,9 +1135,9 @@ var Swarm = class {
|
|
|
1126
1135
|
this._transportFactory = _transportFactory;
|
|
1127
1136
|
this._label = _label;
|
|
1128
1137
|
this._connectionLimiter = _connectionLimiter;
|
|
1129
|
-
this._peers = new import_util2.ComplexMap(import_keys4.PublicKey.hash);
|
|
1130
1138
|
this._ctx = new import_context4.Context();
|
|
1131
1139
|
this._listeningHandle = void 0;
|
|
1140
|
+
this._peers = new import_util2.ComplexMap(import_keys4.PublicKey.hash);
|
|
1132
1141
|
this._instanceId = import_keys4.PublicKey.random().toHex();
|
|
1133
1142
|
this.connectionAdded = new import_async3.Event();
|
|
1134
1143
|
this.disconnected = new import_async3.Event();
|
|
@@ -1584,7 +1593,7 @@ var import_async4 = require("@dxos/async");
|
|
|
1584
1593
|
var import_keys5 = require("@dxos/keys");
|
|
1585
1594
|
var import_log5 = require("@dxos/log");
|
|
1586
1595
|
var import_util3 = require("@dxos/util");
|
|
1587
|
-
var __dxlog_file5 = "/
|
|
1596
|
+
var __dxlog_file5 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
|
|
1588
1597
|
var SwarmMapper = class {
|
|
1589
1598
|
get peers() {
|
|
1590
1599
|
return Array.from(this._peers.values());
|
|
@@ -1657,8 +1666,8 @@ var import_invariant5 = require("@dxos/invariant");
|
|
|
1657
1666
|
var import_keys6 = require("@dxos/keys");
|
|
1658
1667
|
var import_log6 = require("@dxos/log");
|
|
1659
1668
|
var import_util4 = require("@dxos/util");
|
|
1660
|
-
var __dxlog_file6 = "/
|
|
1661
|
-
var MAX_CONCURRENT_INITIATING_CONNECTIONS =
|
|
1669
|
+
var __dxlog_file6 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
|
|
1670
|
+
var MAX_CONCURRENT_INITIATING_CONNECTIONS = 10;
|
|
1662
1671
|
var ConnectionLimiter = class {
|
|
1663
1672
|
constructor({ maxConcurrentInitConnections = MAX_CONCURRENT_INITIATING_CONNECTIONS } = {}) {
|
|
1664
1673
|
this._ctx = new import_context5.Context();
|
|
@@ -1767,6 +1776,7 @@ var ConnectionLog = class {
|
|
|
1767
1776
|
swarm.connectionAdded.on((connection) => {
|
|
1768
1777
|
const connectionInfo = {
|
|
1769
1778
|
state: ConnectionState.INITIAL,
|
|
1779
|
+
closeReason: connection.closeReason,
|
|
1770
1780
|
remotePeerId: connection.remoteId,
|
|
1771
1781
|
sessionId: connection.sessionId,
|
|
1772
1782
|
transport: connection.transport && Object.getPrototypeOf(connection.transport).constructor.name,
|
|
@@ -1777,6 +1787,7 @@ var ConnectionLog = class {
|
|
|
1777
1787
|
this.update.emit();
|
|
1778
1788
|
connection.stateChanged.on((state) => {
|
|
1779
1789
|
connectionInfo.state = state;
|
|
1790
|
+
connectionInfo.closeReason = connection.closeReason;
|
|
1780
1791
|
connectionInfo.events.push({
|
|
1781
1792
|
type: EventType.CONNECTION_STATE_CHANGED,
|
|
1782
1793
|
newState: state
|
|
@@ -1804,7 +1815,7 @@ var import_messaging = require("@dxos/messaging");
|
|
|
1804
1815
|
var import_protocols4 = require("@dxos/protocols");
|
|
1805
1816
|
var import_services = require("@dxos/protocols/proto/dxos/client/services");
|
|
1806
1817
|
var import_util6 = require("@dxos/util");
|
|
1807
|
-
var __dxlog_file7 = "/
|
|
1818
|
+
var __dxlog_file7 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/network-manager.ts";
|
|
1808
1819
|
var NetworkManager = class {
|
|
1809
1820
|
constructor({ transportFactory, signalManager, log: log1 }) {
|
|
1810
1821
|
/**
|
|
@@ -2040,7 +2051,7 @@ var NetworkManager = class {
|
|
|
2040
2051
|
|
|
2041
2052
|
// packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts
|
|
2042
2053
|
var import_invariant7 = require("@dxos/invariant");
|
|
2043
|
-
var __dxlog_file8 = "/
|
|
2054
|
+
var __dxlog_file8 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
|
|
2044
2055
|
var FullyConnectedTopology = class {
|
|
2045
2056
|
toString() {
|
|
2046
2057
|
return "FullyConnectedTopology";
|
|
@@ -2083,7 +2094,7 @@ var FullyConnectedTopology = class {
|
|
|
2083
2094
|
var import_xor_distance = __toESM(require("xor-distance"));
|
|
2084
2095
|
var import_invariant8 = require("@dxos/invariant");
|
|
2085
2096
|
var import_log8 = require("@dxos/log");
|
|
2086
|
-
var __dxlog_file9 = "/
|
|
2097
|
+
var __dxlog_file9 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/topology/mmst-topology.ts";
|
|
2087
2098
|
var MMSTTopology = class {
|
|
2088
2099
|
constructor({ originateConnections = 2, maxPeers = 4, sampleSize = 10 } = {}) {
|
|
2089
2100
|
this._sampleCollected = false;
|
|
@@ -2192,7 +2203,7 @@ var sortByXorDistance = (keys, reference) => keys.sort((a, b) => import_xor_dist
|
|
|
2192
2203
|
// packages/core/mesh/network-manager/src/topology/star-topology.ts
|
|
2193
2204
|
var import_invariant9 = require("@dxos/invariant");
|
|
2194
2205
|
var import_log9 = require("@dxos/log");
|
|
2195
|
-
var __dxlog_file10 = "/
|
|
2206
|
+
var __dxlog_file10 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/topology/star-topology.ts";
|
|
2196
2207
|
var StarTopology = class {
|
|
2197
2208
|
// prettier-ignore
|
|
2198
2209
|
constructor(_centralPeer) {
|
|
@@ -2304,7 +2315,7 @@ function _ts_decorate4(decorators, target, key, desc) {
|
|
|
2304
2315
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2305
2316
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2306
2317
|
}
|
|
2307
|
-
var __dxlog_file11 = "/
|
|
2318
|
+
var __dxlog_file11 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
|
|
2308
2319
|
var MEMORY_TRANSPORT_DELAY = 1;
|
|
2309
2320
|
var createStreamDelay = (delay) => {
|
|
2310
2321
|
return new import_node_stream.Transform({
|
|
@@ -2489,38 +2500,43 @@ try {
|
|
|
2489
2500
|
}
|
|
2490
2501
|
|
|
2491
2502
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport.ts
|
|
2492
|
-
var __dxlog_file12 = "/
|
|
2503
|
+
var __dxlog_file12 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/webrtc-transport.ts";
|
|
2493
2504
|
var WebRTCTransport = class {
|
|
2494
2505
|
constructor(params) {
|
|
2495
2506
|
this.params = params;
|
|
2507
|
+
this._instanceId = import_keys10.PublicKey.random().toHex();
|
|
2496
2508
|
this._closed = false;
|
|
2497
2509
|
this.closed = new import_async9.Event();
|
|
2498
2510
|
this.connected = new import_async9.Event();
|
|
2499
2511
|
this.errors = new import_debug5.ErrorStream();
|
|
2500
|
-
this._instanceId = import_keys10.PublicKey.random().toHex();
|
|
2501
2512
|
import_log11.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols5.trace.begin({
|
|
2502
2513
|
id: this._instanceId
|
|
2503
2514
|
}), {
|
|
2504
2515
|
F: __dxlog_file12,
|
|
2505
|
-
L:
|
|
2516
|
+
L: 44,
|
|
2506
2517
|
S: this,
|
|
2507
2518
|
C: (f, a) => f(...a)
|
|
2508
2519
|
});
|
|
2509
2520
|
(0, import_log11.log)("created connection", params, {
|
|
2510
2521
|
F: __dxlog_file12,
|
|
2511
|
-
L:
|
|
2522
|
+
L: 45,
|
|
2512
2523
|
S: this,
|
|
2513
2524
|
C: (f, a) => f(...a)
|
|
2514
2525
|
});
|
|
2515
2526
|
this._peer = new import_simple_peer.default({
|
|
2516
2527
|
initiator: this.params.initiator,
|
|
2517
|
-
|
|
2518
|
-
|
|
2528
|
+
config: this.params.webrtcConfig,
|
|
2529
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/createDataChannel
|
|
2530
|
+
channelConfig: {
|
|
2531
|
+
protocol: "dxos.mesh"
|
|
2532
|
+
},
|
|
2533
|
+
// Custom WebRTC implementation (for Node); otherwise get-browser-rtc.
|
|
2534
|
+
wrtc: import_simple_peer.default.WEBRTC_SUPPORT ? void 0 : wrtc ?? (0, import_debug5.raise)(new Error("wrtc not available"))
|
|
2519
2535
|
});
|
|
2520
2536
|
this._peer.on("signal", async (data) => {
|
|
2521
2537
|
(0, import_log11.log)("signal", data, {
|
|
2522
2538
|
F: __dxlog_file12,
|
|
2523
|
-
L:
|
|
2539
|
+
L: 62,
|
|
2524
2540
|
S: this,
|
|
2525
2541
|
C: (f, a) => f(...a)
|
|
2526
2542
|
});
|
|
@@ -2533,7 +2549,7 @@ var WebRTCTransport = class {
|
|
|
2533
2549
|
this._peer.on("connect", () => {
|
|
2534
2550
|
(0, import_log11.log)("connected", void 0, {
|
|
2535
2551
|
F: __dxlog_file12,
|
|
2536
|
-
L:
|
|
2552
|
+
L: 67,
|
|
2537
2553
|
S: this,
|
|
2538
2554
|
C: (f, a) => f(...a)
|
|
2539
2555
|
});
|
|
@@ -2543,7 +2559,7 @@ var WebRTCTransport = class {
|
|
|
2543
2559
|
this._peer.on("close", async () => {
|
|
2544
2560
|
(0, import_log11.log)("closed", void 0, {
|
|
2545
2561
|
F: __dxlog_file12,
|
|
2546
|
-
L:
|
|
2562
|
+
L: 73,
|
|
2547
2563
|
S: this,
|
|
2548
2564
|
C: (f, a) => f(...a)
|
|
2549
2565
|
});
|
|
@@ -2560,7 +2576,7 @@ var WebRTCTransport = class {
|
|
|
2560
2576
|
stats
|
|
2561
2577
|
}, {
|
|
2562
2578
|
F: __dxlog_file12,
|
|
2563
|
-
L:
|
|
2579
|
+
L: 85,
|
|
2564
2580
|
S: this,
|
|
2565
2581
|
C: (f, a) => f(...a)
|
|
2566
2582
|
});
|
|
@@ -2574,7 +2590,7 @@ var WebRTCTransport = class {
|
|
|
2574
2590
|
id: this._instanceId
|
|
2575
2591
|
}), {
|
|
2576
2592
|
F: __dxlog_file12,
|
|
2577
|
-
L:
|
|
2593
|
+
L: 95,
|
|
2578
2594
|
S: this,
|
|
2579
2595
|
C: (f, a) => f(...a)
|
|
2580
2596
|
});
|
|
@@ -2582,7 +2598,7 @@ var WebRTCTransport = class {
|
|
|
2582
2598
|
async destroy() {
|
|
2583
2599
|
(0, import_log11.log)("closing...", void 0, {
|
|
2584
2600
|
F: __dxlog_file12,
|
|
2585
|
-
L:
|
|
2601
|
+
L: 99,
|
|
2586
2602
|
S: this,
|
|
2587
2603
|
C: (f, a) => f(...a)
|
|
2588
2604
|
});
|
|
@@ -2592,7 +2608,7 @@ var WebRTCTransport = class {
|
|
|
2592
2608
|
this.closed.emit();
|
|
2593
2609
|
(0, import_log11.log)("closed", void 0, {
|
|
2594
2610
|
F: __dxlog_file12,
|
|
2595
|
-
L:
|
|
2611
|
+
L: 104,
|
|
2596
2612
|
S: this,
|
|
2597
2613
|
C: (f, a) => f(...a)
|
|
2598
2614
|
});
|
|
@@ -2603,7 +2619,7 @@ var WebRTCTransport = class {
|
|
|
2603
2619
|
}
|
|
2604
2620
|
(0, import_invariant11.invariant)(signal.payload.data, "Signal message must contain signal data.", {
|
|
2605
2621
|
F: __dxlog_file12,
|
|
2606
|
-
L:
|
|
2622
|
+
L: 112,
|
|
2607
2623
|
S: this,
|
|
2608
2624
|
A: [
|
|
2609
2625
|
"signal.payload.data",
|
|
@@ -2631,7 +2647,7 @@ var import_keys11 = require("@dxos/keys");
|
|
|
2631
2647
|
var import_log12 = require("@dxos/log");
|
|
2632
2648
|
var import_bridge = require("@dxos/protocols/proto/dxos/mesh/bridge");
|
|
2633
2649
|
var import_util8 = require("@dxos/util");
|
|
2634
|
-
var __dxlog_file13 = "/
|
|
2650
|
+
var __dxlog_file13 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/webrtc-transport-service.ts";
|
|
2635
2651
|
var WebRTCTransportService = class {
|
|
2636
2652
|
// prettier-ignore
|
|
2637
2653
|
constructor(_webrtcConfig) {
|
|
@@ -2763,7 +2779,7 @@ var import_keys12 = require("@dxos/keys");
|
|
|
2763
2779
|
var import_log13 = require("@dxos/log");
|
|
2764
2780
|
var import_bridge2 = require("@dxos/protocols/proto/dxos/mesh/bridge");
|
|
2765
2781
|
var import_util9 = require("@dxos/util");
|
|
2766
|
-
var __dxlog_file14 = "/
|
|
2782
|
+
var __dxlog_file14 = "/mnt/ramdisk/work/packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts";
|
|
2767
2783
|
var WebRTCTransportProxy = class {
|
|
2768
2784
|
// prettier-ignore
|
|
2769
2785
|
constructor(_params) {
|
|
@@ -2771,9 +2787,9 @@ var WebRTCTransportProxy = class {
|
|
|
2771
2787
|
this._proxyId = import_keys12.PublicKey.random();
|
|
2772
2788
|
this._ctx = new import_context6.Context();
|
|
2773
2789
|
this.closed = new import_async10.Event();
|
|
2774
|
-
this._closed = false;
|
|
2775
2790
|
this.connected = new import_async10.Event();
|
|
2776
2791
|
this.errors = new import_debug6.ErrorStream();
|
|
2792
|
+
this._closed = false;
|
|
2777
2793
|
this._serviceStream = this._params.bridgeService.open({
|
|
2778
2794
|
proxyId: this._proxyId,
|
|
2779
2795
|
initiator: this._params.initiator
|
|
@@ -2849,7 +2865,7 @@ var WebRTCTransportProxy = class {
|
|
|
2849
2865
|
if (this._closed) {
|
|
2850
2866
|
return;
|
|
2851
2867
|
}
|
|
2852
|
-
this._serviceStream.close();
|
|
2868
|
+
await this._serviceStream.close();
|
|
2853
2869
|
try {
|
|
2854
2870
|
await this._params.bridgeService.close({
|
|
2855
2871
|
proxyId: this._proxyId
|
|
@@ -2870,7 +2886,7 @@ var WebRTCTransportProxy = class {
|
|
|
2870
2886
|
*/
|
|
2871
2887
|
// TODO(burdon): Option on close method.
|
|
2872
2888
|
forceClose() {
|
|
2873
|
-
this._serviceStream.close();
|
|
2889
|
+
void this._serviceStream.close();
|
|
2874
2890
|
this.closed.emit();
|
|
2875
2891
|
this._closed = true;
|
|
2876
2892
|
}
|