@dxos/teleport 0.1.56-main.f3d4052 → 0.1.56-next.a63ce79
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-GGVQ27WJ.mjs → chunk-57AKT4R2.mjs} +315 -101
- package/dist/lib/browser/chunk-57AKT4R2.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +13 -5
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +1 -1
- package/dist/lib/node/index.cjs +326 -104
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +314 -100
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/types/src/muxing/framer.d.ts.map +1 -1
- package/dist/types/src/muxing/muxer.d.ts.map +1 -1
- package/dist/types/src/rpc-extension.d.ts.map +1 -1
- package/dist/types/src/teleport.d.ts.map +1 -1
- package/dist/types/src/testing/test-extension-with-streams.d.ts.map +1 -1
- package/dist/types/src/testing/test-extension.d.ts.map +1 -1
- package/package.json +12 -12
- package/src/muxing/framer.ts +2 -1
- package/src/muxing/muxer.ts +5 -1
- package/src/rpc-extension.ts +1 -2
- package/src/teleport.ts +1 -1
- package/src/testing/test-builder.ts +1 -1
- package/src/testing/test-extension-with-streams.ts +5 -5
- package/src/testing/test-extension.ts +1 -2
- package/dist/lib/browser/chunk-GGVQ27WJ.mjs.map +0 -7
|
@@ -2,15 +2,15 @@ import "@dxos/node-std/globals";
|
|
|
2
2
|
|
|
3
3
|
// packages/core/mesh/teleport/src/testing/test-builder.ts
|
|
4
4
|
import { pipeline } from "@dxos/node-std/stream";
|
|
5
|
-
import invariant4 from "
|
|
5
|
+
import { invariant as invariant4 } from "@dxos/invariant";
|
|
6
6
|
import { PublicKey as PublicKey2 } from "@dxos/keys";
|
|
7
7
|
import { log as log4 } from "@dxos/log";
|
|
8
8
|
|
|
9
9
|
// packages/core/mesh/teleport/src/teleport.ts
|
|
10
|
-
import invariant3 from "tiny-invariant";
|
|
11
10
|
import { asyncTimeout, scheduleTaskInterval as scheduleTaskInterval2, runInContextAsync, synchronized, scheduleTask } from "@dxos/async";
|
|
12
11
|
import { Context as Context2 } from "@dxos/context";
|
|
13
12
|
import { failUndefined as failUndefined2 } from "@dxos/debug";
|
|
13
|
+
import { invariant as invariant3 } from "@dxos/invariant";
|
|
14
14
|
import { PublicKey } from "@dxos/keys";
|
|
15
15
|
import { log as log3 } from "@dxos/log";
|
|
16
16
|
import { schema as schema2, RpcClosedError } from "@dxos/protocols";
|
|
@@ -19,7 +19,8 @@ import { Callback } from "@dxos/util";
|
|
|
19
19
|
|
|
20
20
|
// packages/core/mesh/teleport/src/muxing/framer.ts
|
|
21
21
|
import { Duplex } from "@dxos/node-std/stream";
|
|
22
|
-
import invariant from "
|
|
22
|
+
import { invariant } from "@dxos/invariant";
|
|
23
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/muxing/framer.ts";
|
|
23
24
|
var FRAME_LENGTH_SIZE = 2;
|
|
24
25
|
var Framer = class {
|
|
25
26
|
constructor() {
|
|
@@ -32,7 +33,15 @@ var Framer = class {
|
|
|
32
33
|
this._processResponseQueue();
|
|
33
34
|
},
|
|
34
35
|
write: (chunk, encoding, callback) => {
|
|
35
|
-
invariant(!this._subscribeCb, "Internal Framer bug. Concurrent writes detected."
|
|
36
|
+
invariant(!this._subscribeCb, "Internal Framer bug. Concurrent writes detected.", {
|
|
37
|
+
F: __dxlog_file,
|
|
38
|
+
L: 34,
|
|
39
|
+
S: this,
|
|
40
|
+
A: [
|
|
41
|
+
"!this._subscribeCb",
|
|
42
|
+
"'Internal Framer bug. Concurrent writes detected.'"
|
|
43
|
+
]
|
|
44
|
+
});
|
|
36
45
|
this._bytesReceived += chunk.length;
|
|
37
46
|
if (this._buffer && this._buffer.length > 0) {
|
|
38
47
|
this._buffer = Buffer.concat([
|
|
@@ -68,10 +77,17 @@ var Framer = class {
|
|
|
68
77
|
});
|
|
69
78
|
},
|
|
70
79
|
subscribe: (callback) => {
|
|
71
|
-
|
|
72
|
-
|
|
80
|
+
invariant(!this._messageCb, "Rpc port already has a message listener.", {
|
|
81
|
+
F: __dxlog_file,
|
|
82
|
+
L: 73,
|
|
83
|
+
S: this,
|
|
84
|
+
A: [
|
|
85
|
+
"!this._messageCb",
|
|
86
|
+
"'Rpc port already has a message listener.'"
|
|
87
|
+
]
|
|
88
|
+
});
|
|
73
89
|
this._messageCb = callback;
|
|
74
|
-
|
|
90
|
+
this._subscribeCb?.();
|
|
75
91
|
return () => {
|
|
76
92
|
this._messageCb = void 0;
|
|
77
93
|
};
|
|
@@ -139,10 +155,10 @@ var encodeFrame = (payload) => {
|
|
|
139
155
|
|
|
140
156
|
// packages/core/mesh/teleport/src/muxing/muxer.ts
|
|
141
157
|
import { Duplex as Duplex2 } from "@dxos/node-std/stream";
|
|
142
|
-
import invariant2 from "tiny-invariant";
|
|
143
158
|
import { scheduleTaskInterval, Event as Event2, Trigger } from "@dxos/async";
|
|
144
159
|
import { Context } from "@dxos/context";
|
|
145
160
|
import { failUndefined } from "@dxos/debug";
|
|
161
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
146
162
|
import { log as log2 } from "@dxos/log";
|
|
147
163
|
import { schema } from "@dxos/protocols";
|
|
148
164
|
|
|
@@ -150,7 +166,7 @@ import { schema } from "@dxos/protocols";
|
|
|
150
166
|
import * as varint from "varint";
|
|
151
167
|
import { Event } from "@dxos/async";
|
|
152
168
|
import { log } from "@dxos/log";
|
|
153
|
-
var
|
|
169
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/muxing/balancer.ts";
|
|
154
170
|
var MAX_CHUNK_SIZE = 8192;
|
|
155
171
|
var Balancer = class {
|
|
156
172
|
constructor(_sysChannelId) {
|
|
@@ -200,7 +216,7 @@ var Balancer = class {
|
|
|
200
216
|
});
|
|
201
217
|
if (noCalls) {
|
|
202
218
|
this._sendChunks().catch((err) => log.catch(err, void 0, {
|
|
203
|
-
F:
|
|
219
|
+
F: __dxlog_file2,
|
|
204
220
|
L: 96,
|
|
205
221
|
S: this,
|
|
206
222
|
C: (f, a) => f(...a)
|
|
@@ -260,16 +276,15 @@ var Balancer = class {
|
|
|
260
276
|
return chunk;
|
|
261
277
|
}
|
|
262
278
|
async _sendChunks() {
|
|
263
|
-
var _a, _b;
|
|
264
279
|
if (this._sendBuffers.size === 0) {
|
|
265
280
|
return;
|
|
266
281
|
}
|
|
267
282
|
const chunk = this._getNextChunk();
|
|
268
283
|
try {
|
|
269
284
|
await this._framer.port.send(chunk.msg);
|
|
270
|
-
|
|
285
|
+
chunk.trigger?.wake();
|
|
271
286
|
} catch (err) {
|
|
272
|
-
|
|
287
|
+
chunk.trigger?.throw(err);
|
|
273
288
|
}
|
|
274
289
|
await this._sendChunks();
|
|
275
290
|
}
|
|
@@ -302,7 +317,7 @@ var decodeChunk = (data, withLength) => {
|
|
|
302
317
|
};
|
|
303
318
|
|
|
304
319
|
// packages/core/mesh/teleport/src/muxing/muxer.ts
|
|
305
|
-
var
|
|
320
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/muxing/muxer.ts";
|
|
306
321
|
var Command = schema.getCodecForType("dxos.mesh.muxer.Command");
|
|
307
322
|
var STATS_INTERVAL = 1e3;
|
|
308
323
|
var MAX_SAFE_FRAME_SIZE = 1e6;
|
|
@@ -335,7 +350,15 @@ var Muxer = class {
|
|
|
335
350
|
tag,
|
|
336
351
|
contentType: opts.contentType
|
|
337
352
|
});
|
|
338
|
-
invariant2(!channel.push, `Channel already open: ${tag}
|
|
353
|
+
invariant2(!channel.push, `Channel already open: ${tag}`, {
|
|
354
|
+
F: __dxlog_file3,
|
|
355
|
+
L: 91,
|
|
356
|
+
S: this,
|
|
357
|
+
A: [
|
|
358
|
+
"!channel.push",
|
|
359
|
+
"`Channel already open: ${tag}`"
|
|
360
|
+
]
|
|
361
|
+
});
|
|
339
362
|
const stream = new Duplex2({
|
|
340
363
|
write: (data, encoding, callback) => {
|
|
341
364
|
this._sendData(channel, data).then(() => callback()).catch(callback);
|
|
@@ -375,7 +398,15 @@ var Muxer = class {
|
|
|
375
398
|
tag,
|
|
376
399
|
contentType: opts.contentType
|
|
377
400
|
});
|
|
378
|
-
invariant2(!channel.push, `Channel already open: ${tag}
|
|
401
|
+
invariant2(!channel.push, `Channel already open: ${tag}`, {
|
|
402
|
+
F: __dxlog_file3,
|
|
403
|
+
L: 143,
|
|
404
|
+
S: this,
|
|
405
|
+
A: [
|
|
406
|
+
"!channel.push",
|
|
407
|
+
"`Channel already open: ${tag}`"
|
|
408
|
+
]
|
|
409
|
+
});
|
|
379
410
|
let inboundBuffer = [];
|
|
380
411
|
let callback;
|
|
381
412
|
channel.push = (data) => {
|
|
@@ -391,7 +422,15 @@ var Muxer = class {
|
|
|
391
422
|
await this._sendData(channel, data);
|
|
392
423
|
},
|
|
393
424
|
subscribe: (cb) => {
|
|
394
|
-
invariant2(!callback, "Only one subscriber is allowed"
|
|
425
|
+
invariant2(!callback, "Only one subscriber is allowed", {
|
|
426
|
+
F: __dxlog_file3,
|
|
427
|
+
L: 165,
|
|
428
|
+
S: this,
|
|
429
|
+
A: [
|
|
430
|
+
"!callback",
|
|
431
|
+
"'Only one subscriber is allowed'"
|
|
432
|
+
]
|
|
433
|
+
});
|
|
395
434
|
callback = cb;
|
|
396
435
|
for (const data of inboundBuffer) {
|
|
397
436
|
cb(data);
|
|
@@ -423,7 +462,7 @@ var Muxer = class {
|
|
|
423
462
|
this._destroying = true;
|
|
424
463
|
this._sendCommand({
|
|
425
464
|
destroy: {
|
|
426
|
-
error: err
|
|
465
|
+
error: err?.message
|
|
427
466
|
}
|
|
428
467
|
}, SYSTEM_CHANNEL_ID).then(() => {
|
|
429
468
|
this._dispose();
|
|
@@ -433,35 +472,36 @@ var Muxer = class {
|
|
|
433
472
|
void this._ctx.dispose();
|
|
434
473
|
}
|
|
435
474
|
_dispose(err) {
|
|
436
|
-
var _a;
|
|
437
475
|
if (this._destroyed) {
|
|
438
476
|
return;
|
|
439
477
|
}
|
|
440
478
|
this._destroyed = true;
|
|
441
479
|
this._balancer.destroy();
|
|
442
480
|
for (const channel of this._channelsByTag.values()) {
|
|
443
|
-
|
|
481
|
+
channel.destroy?.(err);
|
|
444
482
|
}
|
|
445
483
|
this.close.emit(err);
|
|
446
484
|
this._channelsByLocalId.clear();
|
|
447
485
|
this._channelsByTag.clear();
|
|
448
486
|
}
|
|
449
487
|
async _handleCommand(cmd) {
|
|
450
|
-
var _a;
|
|
451
488
|
log2("Received command", {
|
|
452
489
|
cmd
|
|
453
490
|
}, {
|
|
454
|
-
F:
|
|
491
|
+
F: __dxlog_file3,
|
|
455
492
|
L: 240,
|
|
456
493
|
S: this,
|
|
457
494
|
C: (f, a) => f(...a)
|
|
458
495
|
});
|
|
459
496
|
if (this._destroyed || this._destroying) {
|
|
497
|
+
if (cmd.destroy) {
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
460
500
|
log2.warn("Received command after destroy", {
|
|
461
501
|
cmd
|
|
462
502
|
}, {
|
|
463
|
-
F:
|
|
464
|
-
L:
|
|
503
|
+
F: __dxlog_file3,
|
|
504
|
+
L: 247,
|
|
465
505
|
S: this,
|
|
466
506
|
C: (f, a) => f(...a)
|
|
467
507
|
});
|
|
@@ -483,13 +523,13 @@ var Muxer = class {
|
|
|
483
523
|
}
|
|
484
524
|
channel.buffer = [];
|
|
485
525
|
} else if (cmd.data) {
|
|
486
|
-
const stream =
|
|
526
|
+
const stream = this._channelsByLocalId.get(cmd.data.channelId) ?? failUndefined();
|
|
487
527
|
if (!stream.push) {
|
|
488
528
|
log2.warn("Received data for channel before it was opened", {
|
|
489
529
|
tag: stream.tag
|
|
490
530
|
}, {
|
|
491
|
-
F:
|
|
492
|
-
L:
|
|
531
|
+
F: __dxlog_file3,
|
|
532
|
+
L: 274,
|
|
493
533
|
S: this,
|
|
494
534
|
C: (f, a) => f(...a)
|
|
495
535
|
});
|
|
@@ -537,8 +577,8 @@ var Muxer = class {
|
|
|
537
577
|
size: data.length,
|
|
538
578
|
threshold: MAX_SAFE_FRAME_SIZE
|
|
539
579
|
}, {
|
|
540
|
-
F:
|
|
541
|
-
L:
|
|
580
|
+
F: __dxlog_file3,
|
|
581
|
+
L: 318,
|
|
542
582
|
S: this,
|
|
543
583
|
C: (f, a) => f(...a)
|
|
544
584
|
});
|
|
@@ -593,14 +633,14 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
593
633
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
594
634
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
595
635
|
}
|
|
596
|
-
var
|
|
636
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/teleport.ts";
|
|
597
637
|
var Teleport = class {
|
|
598
638
|
constructor({ initiator, localPeerId, remotePeerId }) {
|
|
599
639
|
this._ctx = new Context2({
|
|
600
640
|
onError: (err) => {
|
|
601
641
|
void this.destroy(err).catch(() => {
|
|
602
642
|
log3.error("Error during destroy", err, {
|
|
603
|
-
F:
|
|
643
|
+
F: __dxlog_file4,
|
|
604
644
|
L: 34,
|
|
605
645
|
S: this,
|
|
606
646
|
C: (f, a) => f(...a)
|
|
@@ -614,7 +654,7 @@ var Teleport = class {
|
|
|
614
654
|
heartbeatTimeout: 1e4,
|
|
615
655
|
onTimeout: () => {
|
|
616
656
|
this.destroy(new Error("Connection timed out")).catch((err) => log3.catch(err, void 0, {
|
|
617
|
-
F:
|
|
657
|
+
F: __dxlog_file4,
|
|
618
658
|
L: 45,
|
|
619
659
|
S: this,
|
|
620
660
|
C: (f, a) => f(...a)
|
|
@@ -624,9 +664,33 @@ var Teleport = class {
|
|
|
624
664
|
this._extensions = /* @__PURE__ */ new Map();
|
|
625
665
|
this._remoteExtensions = /* @__PURE__ */ new Set();
|
|
626
666
|
this._open = false;
|
|
627
|
-
invariant3(typeof initiator === "boolean"
|
|
628
|
-
|
|
629
|
-
|
|
667
|
+
invariant3(typeof initiator === "boolean", void 0, {
|
|
668
|
+
F: __dxlog_file4,
|
|
669
|
+
L: 55,
|
|
670
|
+
S: this,
|
|
671
|
+
A: [
|
|
672
|
+
"typeof initiator === 'boolean'",
|
|
673
|
+
""
|
|
674
|
+
]
|
|
675
|
+
});
|
|
676
|
+
invariant3(PublicKey.isPublicKey(localPeerId), void 0, {
|
|
677
|
+
F: __dxlog_file4,
|
|
678
|
+
L: 56,
|
|
679
|
+
S: this,
|
|
680
|
+
A: [
|
|
681
|
+
"PublicKey.isPublicKey(localPeerId)",
|
|
682
|
+
""
|
|
683
|
+
]
|
|
684
|
+
});
|
|
685
|
+
invariant3(PublicKey.isPublicKey(remotePeerId), void 0, {
|
|
686
|
+
F: __dxlog_file4,
|
|
687
|
+
L: 57,
|
|
688
|
+
S: this,
|
|
689
|
+
A: [
|
|
690
|
+
"PublicKey.isPublicKey(remotePeerId)",
|
|
691
|
+
""
|
|
692
|
+
]
|
|
693
|
+
});
|
|
630
694
|
this.initiator = initiator;
|
|
631
695
|
this.localPeerId = localPeerId;
|
|
632
696
|
this.remotePeerId = remotePeerId;
|
|
@@ -634,12 +698,20 @@ var Teleport = class {
|
|
|
634
698
|
log3("remote extension", {
|
|
635
699
|
name
|
|
636
700
|
}, {
|
|
637
|
-
F:
|
|
701
|
+
F: __dxlog_file4,
|
|
638
702
|
L: 63,
|
|
639
703
|
S: this,
|
|
640
704
|
C: (f, a) => f(...a)
|
|
641
705
|
});
|
|
642
|
-
invariant3(!this._remoteExtensions.has(name), "Remote extension already exists"
|
|
706
|
+
invariant3(!this._remoteExtensions.has(name), "Remote extension already exists", {
|
|
707
|
+
F: __dxlog_file4,
|
|
708
|
+
L: 64,
|
|
709
|
+
S: this,
|
|
710
|
+
A: [
|
|
711
|
+
"!this._remoteExtensions.has(name)",
|
|
712
|
+
"'Remote extension already exists'"
|
|
713
|
+
]
|
|
714
|
+
});
|
|
643
715
|
this._remoteExtensions.add(name);
|
|
644
716
|
if (this._extensions.has(name)) {
|
|
645
717
|
try {
|
|
@@ -665,7 +737,7 @@ var Teleport = class {
|
|
|
665
737
|
bytesReceived: stats.bytesReceived,
|
|
666
738
|
channels: stats.channels
|
|
667
739
|
}, {
|
|
668
|
-
F:
|
|
740
|
+
F: __dxlog_file4,
|
|
669
741
|
L: 88,
|
|
670
742
|
S: this,
|
|
671
743
|
C: (f, a) => f(...a)
|
|
@@ -699,7 +771,7 @@ var Teleport = class {
|
|
|
699
771
|
await extension.onClose(err);
|
|
700
772
|
} catch (err2) {
|
|
701
773
|
log3.catch(err2, void 0, {
|
|
702
|
-
F:
|
|
774
|
+
F: __dxlog_file4,
|
|
703
775
|
L: 132,
|
|
704
776
|
S: this,
|
|
705
777
|
C: (f, a) => f(...a)
|
|
@@ -715,7 +787,7 @@ var Teleport = class {
|
|
|
715
787
|
log3("addExtension", {
|
|
716
788
|
name
|
|
717
789
|
}, {
|
|
718
|
-
F:
|
|
790
|
+
F: __dxlog_file4,
|
|
719
791
|
L: 144,
|
|
720
792
|
S: this,
|
|
721
793
|
C: (f, a) => f(...a)
|
|
@@ -738,31 +810,62 @@ var Teleport = class {
|
|
|
738
810
|
}
|
|
739
811
|
}
|
|
740
812
|
_setExtension(extensionName, extension) {
|
|
741
|
-
invariant3(!extensionName.includes("/"), "Invalid extension name"
|
|
742
|
-
|
|
813
|
+
invariant3(!extensionName.includes("/"), "Invalid extension name", {
|
|
814
|
+
F: __dxlog_file4,
|
|
815
|
+
L: 168,
|
|
816
|
+
S: this,
|
|
817
|
+
A: [
|
|
818
|
+
"!extensionName.includes('/')",
|
|
819
|
+
"'Invalid extension name'"
|
|
820
|
+
]
|
|
821
|
+
});
|
|
822
|
+
invariant3(!this._extensions.has(extensionName), "Extension already exists", {
|
|
823
|
+
F: __dxlog_file4,
|
|
824
|
+
L: 169,
|
|
825
|
+
S: this,
|
|
826
|
+
A: [
|
|
827
|
+
"!this._extensions.has(extensionName)",
|
|
828
|
+
"'Extension already exists'"
|
|
829
|
+
]
|
|
830
|
+
});
|
|
743
831
|
this._extensions.set(extensionName, extension);
|
|
744
832
|
}
|
|
745
833
|
async _openExtension(extensionName) {
|
|
746
|
-
var _a;
|
|
747
834
|
log3("open extension", {
|
|
748
835
|
extensionName
|
|
749
836
|
}, {
|
|
750
|
-
F:
|
|
837
|
+
F: __dxlog_file4,
|
|
751
838
|
L: 174,
|
|
752
839
|
S: this,
|
|
753
840
|
C: (f, a) => f(...a)
|
|
754
841
|
});
|
|
755
|
-
const extension =
|
|
842
|
+
const extension = this._extensions.get(extensionName) ?? failUndefined2();
|
|
756
843
|
const context = {
|
|
757
844
|
initiator: this.initiator,
|
|
758
845
|
localPeerId: this.localPeerId,
|
|
759
846
|
remotePeerId: this.remotePeerId,
|
|
760
847
|
createPort: async (channelName, opts) => {
|
|
761
|
-
invariant3(!channelName.includes("/"), "Invalid channel name"
|
|
848
|
+
invariant3(!channelName.includes("/"), "Invalid channel name", {
|
|
849
|
+
F: __dxlog_file4,
|
|
850
|
+
L: 182,
|
|
851
|
+
S: this,
|
|
852
|
+
A: [
|
|
853
|
+
"!channelName.includes('/')",
|
|
854
|
+
"'Invalid channel name'"
|
|
855
|
+
]
|
|
856
|
+
});
|
|
762
857
|
return this._muxer.createPort(`${extensionName}/${channelName}`, opts);
|
|
763
858
|
},
|
|
764
859
|
createStream: async (channelName, opts) => {
|
|
765
|
-
invariant3(!channelName.includes("/"), "Invalid channel name"
|
|
860
|
+
invariant3(!channelName.includes("/"), "Invalid channel name", {
|
|
861
|
+
F: __dxlog_file4,
|
|
862
|
+
L: 186,
|
|
863
|
+
S: this,
|
|
864
|
+
A: [
|
|
865
|
+
"!channelName.includes('/')",
|
|
866
|
+
"'Invalid channel name'"
|
|
867
|
+
]
|
|
868
|
+
});
|
|
766
869
|
return this._muxer.createStream(`${extensionName}/${channelName}`, opts);
|
|
767
870
|
},
|
|
768
871
|
close: (err) => {
|
|
@@ -775,7 +878,7 @@ var Teleport = class {
|
|
|
775
878
|
log3("extension opened", {
|
|
776
879
|
extensionName
|
|
777
880
|
}, {
|
|
778
|
-
F:
|
|
881
|
+
F: __dxlog_file4,
|
|
779
882
|
L: 197,
|
|
780
883
|
S: this,
|
|
781
884
|
C: (f, a) => f(...a)
|
|
@@ -838,7 +941,7 @@ var ControlExtension = class {
|
|
|
838
941
|
};
|
|
839
942
|
|
|
840
943
|
// packages/core/mesh/teleport/src/testing/test-builder.ts
|
|
841
|
-
var
|
|
944
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/testing/test-builder.ts";
|
|
842
945
|
var TestBuilder = class {
|
|
843
946
|
constructor() {
|
|
844
947
|
this._peers = /* @__PURE__ */ new Set();
|
|
@@ -857,9 +960,33 @@ var TestBuilder = class {
|
|
|
857
960
|
await Promise.all(Array.from(this._peers).map((agent) => agent.destroy()));
|
|
858
961
|
}
|
|
859
962
|
async connect(peer1, peer2) {
|
|
860
|
-
invariant4(peer1 !== peer2
|
|
861
|
-
|
|
862
|
-
|
|
963
|
+
invariant4(peer1 !== peer2, void 0, {
|
|
964
|
+
F: __dxlog_file5,
|
|
965
|
+
L: 37,
|
|
966
|
+
S: this,
|
|
967
|
+
A: [
|
|
968
|
+
"peer1 !== peer2",
|
|
969
|
+
""
|
|
970
|
+
]
|
|
971
|
+
});
|
|
972
|
+
invariant4(this._peers.has(peer1), void 0, {
|
|
973
|
+
F: __dxlog_file5,
|
|
974
|
+
L: 38,
|
|
975
|
+
S: this,
|
|
976
|
+
A: [
|
|
977
|
+
"this._peers.has(peer1)",
|
|
978
|
+
""
|
|
979
|
+
]
|
|
980
|
+
});
|
|
981
|
+
invariant4(this._peers.has(peer1), void 0, {
|
|
982
|
+
F: __dxlog_file5,
|
|
983
|
+
L: 39,
|
|
984
|
+
S: this,
|
|
985
|
+
A: [
|
|
986
|
+
"this._peers.has(peer1)",
|
|
987
|
+
""
|
|
988
|
+
]
|
|
989
|
+
});
|
|
863
990
|
const connection1 = peer1.createConnection({
|
|
864
991
|
initiator: true,
|
|
865
992
|
remotePeerId: peer2.peerId
|
|
@@ -879,13 +1006,53 @@ var TestBuilder = class {
|
|
|
879
1006
|
];
|
|
880
1007
|
}
|
|
881
1008
|
async disconnect(peer1, peer2) {
|
|
882
|
-
invariant4(peer1 !== peer2
|
|
883
|
-
|
|
884
|
-
|
|
1009
|
+
invariant4(peer1 !== peer2, void 0, {
|
|
1010
|
+
F: __dxlog_file5,
|
|
1011
|
+
L: 51,
|
|
1012
|
+
S: this,
|
|
1013
|
+
A: [
|
|
1014
|
+
"peer1 !== peer2",
|
|
1015
|
+
""
|
|
1016
|
+
]
|
|
1017
|
+
});
|
|
1018
|
+
invariant4(this._peers.has(peer1), void 0, {
|
|
1019
|
+
F: __dxlog_file5,
|
|
1020
|
+
L: 52,
|
|
1021
|
+
S: this,
|
|
1022
|
+
A: [
|
|
1023
|
+
"this._peers.has(peer1)",
|
|
1024
|
+
""
|
|
1025
|
+
]
|
|
1026
|
+
});
|
|
1027
|
+
invariant4(this._peers.has(peer1), void 0, {
|
|
1028
|
+
F: __dxlog_file5,
|
|
1029
|
+
L: 53,
|
|
1030
|
+
S: this,
|
|
1031
|
+
A: [
|
|
1032
|
+
"this._peers.has(peer1)",
|
|
1033
|
+
""
|
|
1034
|
+
]
|
|
1035
|
+
});
|
|
885
1036
|
const connection1 = Array.from(peer1.connections).find((connection) => connection.remotePeerId.equals(peer2.peerId));
|
|
886
1037
|
const connection2 = Array.from(peer2.connections).find((connection) => connection.remotePeerId.equals(peer1.peerId));
|
|
887
|
-
invariant4(connection1
|
|
888
|
-
|
|
1038
|
+
invariant4(connection1, void 0, {
|
|
1039
|
+
F: __dxlog_file5,
|
|
1040
|
+
L: 62,
|
|
1041
|
+
S: this,
|
|
1042
|
+
A: [
|
|
1043
|
+
"connection1",
|
|
1044
|
+
""
|
|
1045
|
+
]
|
|
1046
|
+
});
|
|
1047
|
+
invariant4(connection2, void 0, {
|
|
1048
|
+
F: __dxlog_file5,
|
|
1049
|
+
L: 63,
|
|
1050
|
+
S: this,
|
|
1051
|
+
A: [
|
|
1052
|
+
"connection2",
|
|
1053
|
+
""
|
|
1054
|
+
]
|
|
1055
|
+
});
|
|
889
1056
|
await Promise.all([
|
|
890
1057
|
peer1.closeConnection(connection1),
|
|
891
1058
|
peer2.closeConnection(connection2)
|
|
@@ -907,12 +1074,28 @@ var TestPeer = class {
|
|
|
907
1074
|
return connection;
|
|
908
1075
|
}
|
|
909
1076
|
async openConnection(connection) {
|
|
910
|
-
invariant4(this.connections.has(connection)
|
|
1077
|
+
invariant4(this.connections.has(connection), void 0, {
|
|
1078
|
+
F: __dxlog_file5,
|
|
1079
|
+
L: 84,
|
|
1080
|
+
S: this,
|
|
1081
|
+
A: [
|
|
1082
|
+
"this.connections.has(connection)",
|
|
1083
|
+
""
|
|
1084
|
+
]
|
|
1085
|
+
});
|
|
911
1086
|
await connection.teleport.open();
|
|
912
1087
|
await this.onOpen(connection);
|
|
913
1088
|
}
|
|
914
1089
|
async closeConnection(connection) {
|
|
915
|
-
invariant4(this.connections.has(connection)
|
|
1090
|
+
invariant4(this.connections.has(connection), void 0, {
|
|
1091
|
+
F: __dxlog_file5,
|
|
1092
|
+
L: 90,
|
|
1093
|
+
S: this,
|
|
1094
|
+
A: [
|
|
1095
|
+
"this.connections.has(connection)",
|
|
1096
|
+
""
|
|
1097
|
+
]
|
|
1098
|
+
});
|
|
916
1099
|
await this.onClose(connection);
|
|
917
1100
|
await connection.teleport.close();
|
|
918
1101
|
this.connections.delete(connection);
|
|
@@ -927,7 +1110,7 @@ var pipeStreams = (stream1, stream2) => {
|
|
|
927
1110
|
pipeline(stream1, stream2, (err) => {
|
|
928
1111
|
if (err && err.code !== "ERR_STREAM_PREMATURE_CLOSE") {
|
|
929
1112
|
log4.catch(err, void 0, {
|
|
930
|
-
F:
|
|
1113
|
+
F: __dxlog_file5,
|
|
931
1114
|
L: 106,
|
|
932
1115
|
S: void 0,
|
|
933
1116
|
C: (f, a) => f(...a)
|
|
@@ -937,7 +1120,7 @@ var pipeStreams = (stream1, stream2) => {
|
|
|
937
1120
|
pipeline(stream2, stream1, (err) => {
|
|
938
1121
|
if (err && err.code !== "ERR_STREAM_PREMATURE_CLOSE") {
|
|
939
1122
|
log4.catch(err, void 0, {
|
|
940
|
-
F:
|
|
1123
|
+
F: __dxlog_file5,
|
|
941
1124
|
L: 111,
|
|
942
1125
|
S: void 0,
|
|
943
1126
|
C: (f, a) => f(...a)
|
|
@@ -959,12 +1142,12 @@ var TestConnection = class {
|
|
|
959
1142
|
};
|
|
960
1143
|
|
|
961
1144
|
// packages/core/mesh/teleport/src/testing/test-extension.ts
|
|
962
|
-
import invariant5 from "tiny-invariant";
|
|
963
1145
|
import { asyncTimeout as asyncTimeout2, Trigger as Trigger2 } from "@dxos/async";
|
|
1146
|
+
import { invariant as invariant5 } from "@dxos/invariant";
|
|
964
1147
|
import { log as log5 } from "@dxos/log";
|
|
965
1148
|
import { schema as schema3 } from "@dxos/protocols";
|
|
966
1149
|
import { createProtoRpcPeer as createProtoRpcPeer2 } from "@dxos/rpc";
|
|
967
|
-
var
|
|
1150
|
+
var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/testing/test-extension.ts";
|
|
968
1151
|
var TestExtension = class {
|
|
969
1152
|
constructor(callbacks = {}) {
|
|
970
1153
|
this.callbacks = callbacks;
|
|
@@ -972,17 +1155,15 @@ var TestExtension = class {
|
|
|
972
1155
|
this.closed = new Trigger2();
|
|
973
1156
|
}
|
|
974
1157
|
get remotePeerId() {
|
|
975
|
-
|
|
976
|
-
return (_a = this.extensionContext) == null ? void 0 : _a.remotePeerId;
|
|
1158
|
+
return this.extensionContext?.remotePeerId;
|
|
977
1159
|
}
|
|
978
1160
|
async onOpen(context) {
|
|
979
|
-
var _a, _b;
|
|
980
1161
|
log5("onOpen", {
|
|
981
1162
|
localPeerId: context.localPeerId,
|
|
982
1163
|
remotePeerId: context.remotePeerId
|
|
983
1164
|
}, {
|
|
984
|
-
F:
|
|
985
|
-
L:
|
|
1165
|
+
F: __dxlog_file6,
|
|
1166
|
+
L: 32,
|
|
986
1167
|
S: this,
|
|
987
1168
|
C: (f, a) => f(...a)
|
|
988
1169
|
});
|
|
@@ -1011,22 +1192,21 @@ var TestExtension = class {
|
|
|
1011
1192
|
timeout: 2e3
|
|
1012
1193
|
});
|
|
1013
1194
|
await this._rpc.open();
|
|
1014
|
-
await
|
|
1195
|
+
await this.callbacks.onOpen?.();
|
|
1015
1196
|
this.open.wake();
|
|
1016
1197
|
}
|
|
1017
1198
|
async onClose(err) {
|
|
1018
|
-
var _a, _b, _c;
|
|
1019
1199
|
log5("onClose", {
|
|
1020
1200
|
err
|
|
1021
1201
|
}, {
|
|
1022
|
-
F:
|
|
1023
|
-
L:
|
|
1202
|
+
F: __dxlog_file6,
|
|
1203
|
+
L: 66,
|
|
1024
1204
|
S: this,
|
|
1025
1205
|
C: (f, a) => f(...a)
|
|
1026
1206
|
});
|
|
1027
|
-
await
|
|
1207
|
+
await this.callbacks.onClose?.();
|
|
1028
1208
|
this.closed.wake();
|
|
1029
|
-
await
|
|
1209
|
+
await this._rpc?.close();
|
|
1030
1210
|
}
|
|
1031
1211
|
async test(message = "test") {
|
|
1032
1212
|
await this.open.wait({
|
|
@@ -1035,25 +1215,32 @@ var TestExtension = class {
|
|
|
1035
1215
|
const res = await asyncTimeout2(this._rpc.rpc.TestService.testCall({
|
|
1036
1216
|
data: message
|
|
1037
1217
|
}), 1500);
|
|
1038
|
-
invariant5(res.data === message
|
|
1218
|
+
invariant5(res.data === message, void 0, {
|
|
1219
|
+
F: __dxlog_file6,
|
|
1220
|
+
L: 75,
|
|
1221
|
+
S: this,
|
|
1222
|
+
A: [
|
|
1223
|
+
"res.data === message",
|
|
1224
|
+
""
|
|
1225
|
+
]
|
|
1226
|
+
});
|
|
1039
1227
|
}
|
|
1040
1228
|
/**
|
|
1041
1229
|
* Force-close the connection.
|
|
1042
1230
|
*/
|
|
1043
1231
|
async closeConnection(err) {
|
|
1044
|
-
|
|
1045
|
-
(_a = this.extensionContext) == null ? void 0 : _a.close(err);
|
|
1232
|
+
this.extensionContext?.close(err);
|
|
1046
1233
|
}
|
|
1047
1234
|
};
|
|
1048
1235
|
|
|
1049
1236
|
// packages/core/mesh/teleport/src/testing/test-extension-with-streams.ts
|
|
1050
|
-
import assert from "@dxos/node-std/assert";
|
|
1051
1237
|
import { randomBytes } from "@dxos/node-std/crypto";
|
|
1052
1238
|
import { Trigger as Trigger3 } from "@dxos/async";
|
|
1239
|
+
import { invariant as invariant6 } from "@dxos/invariant";
|
|
1053
1240
|
import { log as log6 } from "@dxos/log";
|
|
1054
1241
|
import { schema as schema4 } from "@dxos/protocols";
|
|
1055
1242
|
import { createProtoRpcPeer as createProtoRpcPeer3 } from "@dxos/rpc";
|
|
1056
|
-
var
|
|
1243
|
+
var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/testing/test-extension-with-streams.ts";
|
|
1057
1244
|
var TestExtensionWithStreams = class {
|
|
1058
1245
|
constructor(callbacks = {}) {
|
|
1059
1246
|
this.callbacks = callbacks;
|
|
@@ -1062,11 +1249,18 @@ var TestExtensionWithStreams = class {
|
|
|
1062
1249
|
this._streams = /* @__PURE__ */ new Map();
|
|
1063
1250
|
}
|
|
1064
1251
|
get remotePeerId() {
|
|
1065
|
-
|
|
1066
|
-
return (_a = this.extensionContext) == null ? void 0 : _a.remotePeerId;
|
|
1252
|
+
return this.extensionContext?.remotePeerId;
|
|
1067
1253
|
}
|
|
1068
1254
|
async _openStream(streamTag, interval = 5, chunkSize = 2048) {
|
|
1069
|
-
|
|
1255
|
+
invariant6(!this._streams.has(streamTag), `Stream already exists: ${streamTag}`, {
|
|
1256
|
+
F: __dxlog_file7,
|
|
1257
|
+
L: 37,
|
|
1258
|
+
S: this,
|
|
1259
|
+
A: [
|
|
1260
|
+
"!this._streams.has(streamTag)",
|
|
1261
|
+
"`Stream already exists: ${streamTag}`"
|
|
1262
|
+
]
|
|
1263
|
+
});
|
|
1070
1264
|
const networkStream = await this.extensionContext.createStream(streamTag, {
|
|
1071
1265
|
contentType: "application/x-test-stream"
|
|
1072
1266
|
});
|
|
@@ -1106,7 +1300,6 @@ var TestExtensionWithStreams = class {
|
|
|
1106
1300
|
networkStream.removeAllListeners();
|
|
1107
1301
|
});
|
|
1108
1302
|
streamEntry.reportingTimer = setInterval(() => {
|
|
1109
|
-
var _a, _b;
|
|
1110
1303
|
const { bytesSent, bytesReceived, sendErrors, receiveErrors } = streamEntry;
|
|
1111
1304
|
log6.trace("dxos.test.stream-stats", {
|
|
1112
1305
|
streamTag,
|
|
@@ -1114,10 +1307,10 @@ var TestExtensionWithStreams = class {
|
|
|
1114
1307
|
bytesReceived,
|
|
1115
1308
|
sendErrors,
|
|
1116
1309
|
receiveErrors,
|
|
1117
|
-
from:
|
|
1118
|
-
to:
|
|
1310
|
+
from: this.extensionContext?.localPeerId,
|
|
1311
|
+
to: this.extensionContext?.remotePeerId
|
|
1119
1312
|
}, {
|
|
1120
|
-
F:
|
|
1313
|
+
F: __dxlog_file7,
|
|
1121
1314
|
L: 91,
|
|
1122
1315
|
S: this,
|
|
1123
1316
|
C: (f, a) => f(...a)
|
|
@@ -1125,7 +1318,15 @@ var TestExtensionWithStreams = class {
|
|
|
1125
1318
|
}, 100);
|
|
1126
1319
|
}
|
|
1127
1320
|
_closeStream(streamTag) {
|
|
1128
|
-
|
|
1321
|
+
invariant6(this._streams.has(streamTag), `Stream does not exist: ${streamTag}`, {
|
|
1322
|
+
F: __dxlog_file7,
|
|
1323
|
+
L: 104,
|
|
1324
|
+
S: this,
|
|
1325
|
+
A: [
|
|
1326
|
+
"this._streams.has(streamTag)",
|
|
1327
|
+
"`Stream does not exist: ${streamTag}`"
|
|
1328
|
+
]
|
|
1329
|
+
});
|
|
1129
1330
|
const stream = this._streams.get(streamTag);
|
|
1130
1331
|
clearTimeout(stream.timer);
|
|
1131
1332
|
clearTimeout(stream.reportingTimer);
|
|
@@ -1137,16 +1338,15 @@ var TestExtensionWithStreams = class {
|
|
|
1137
1338
|
bytesReceived,
|
|
1138
1339
|
sendErrors,
|
|
1139
1340
|
receiveErrors,
|
|
1140
|
-
runningTime: Date.now() - (startTimestamp
|
|
1341
|
+
runningTime: Date.now() - (startTimestamp ?? 0)
|
|
1141
1342
|
};
|
|
1142
1343
|
}
|
|
1143
1344
|
async onOpen(context) {
|
|
1144
|
-
var _a, _b;
|
|
1145
1345
|
log6("onOpen", {
|
|
1146
1346
|
localPeerId: context.localPeerId,
|
|
1147
1347
|
remotePeerId: context.remotePeerId
|
|
1148
1348
|
}, {
|
|
1149
|
-
F:
|
|
1349
|
+
F: __dxlog_file7,
|
|
1150
1350
|
L: 126,
|
|
1151
1351
|
S: this,
|
|
1152
1352
|
C: (f, a) => f(...a)
|
|
@@ -1188,26 +1388,25 @@ var TestExtensionWithStreams = class {
|
|
|
1188
1388
|
timeout: 2e3
|
|
1189
1389
|
});
|
|
1190
1390
|
await this._rpc.open();
|
|
1191
|
-
await
|
|
1391
|
+
await this.callbacks.onOpen?.();
|
|
1192
1392
|
this.open.wake();
|
|
1193
1393
|
}
|
|
1194
1394
|
async onClose(err) {
|
|
1195
|
-
var _a, _b, _c;
|
|
1196
1395
|
log6("onClose", {
|
|
1197
1396
|
err
|
|
1198
1397
|
}, {
|
|
1199
|
-
F:
|
|
1398
|
+
F: __dxlog_file7,
|
|
1200
1399
|
L: 177,
|
|
1201
1400
|
S: this,
|
|
1202
1401
|
C: (f, a) => f(...a)
|
|
1203
1402
|
});
|
|
1204
|
-
await
|
|
1403
|
+
await this.callbacks.onClose?.();
|
|
1205
1404
|
this.closed.wake();
|
|
1206
1405
|
for (const [streamTag, stream] of Object.entries(this._streams)) {
|
|
1207
1406
|
log6("closing stream", {
|
|
1208
1407
|
streamTag
|
|
1209
1408
|
}, {
|
|
1210
|
-
F:
|
|
1409
|
+
F: __dxlog_file7,
|
|
1211
1410
|
L: 181,
|
|
1212
1411
|
S: this,
|
|
1213
1412
|
C: (f, a) => f(...a)
|
|
@@ -1215,7 +1414,7 @@ var TestExtensionWithStreams = class {
|
|
|
1215
1414
|
clearTimeout(stream.interval);
|
|
1216
1415
|
stream.networkStream.destroy();
|
|
1217
1416
|
}
|
|
1218
|
-
await
|
|
1417
|
+
await this._rpc?.close();
|
|
1219
1418
|
}
|
|
1220
1419
|
async addNewStream(streamLoadInterval, streamLoadChunkSize, streamTag) {
|
|
1221
1420
|
await this.open.wait({
|
|
@@ -1229,7 +1428,15 @@ var TestExtensionWithStreams = class {
|
|
|
1229
1428
|
streamLoadInterval,
|
|
1230
1429
|
streamLoadChunkSize
|
|
1231
1430
|
});
|
|
1232
|
-
|
|
1431
|
+
invariant6(data === streamTag, void 0, {
|
|
1432
|
+
F: __dxlog_file7,
|
|
1433
|
+
L: 198,
|
|
1434
|
+
S: this,
|
|
1435
|
+
A: [
|
|
1436
|
+
"data === streamTag",
|
|
1437
|
+
""
|
|
1438
|
+
]
|
|
1439
|
+
});
|
|
1233
1440
|
await this._openStream(streamTag, streamLoadInterval, streamLoadChunkSize);
|
|
1234
1441
|
return streamTag;
|
|
1235
1442
|
}
|
|
@@ -1240,7 +1447,15 @@ var TestExtensionWithStreams = class {
|
|
|
1240
1447
|
const { data, bytesSent, bytesReceived, sendErrors, receiveErrors, runningTime } = await this._rpc.rpc.TestServiceWithStreams.closeTestStream({
|
|
1241
1448
|
data: streamTag
|
|
1242
1449
|
});
|
|
1243
|
-
|
|
1450
|
+
invariant6(data === streamTag, void 0, {
|
|
1451
|
+
F: __dxlog_file7,
|
|
1452
|
+
L: 211,
|
|
1453
|
+
S: this,
|
|
1454
|
+
A: [
|
|
1455
|
+
"data === streamTag",
|
|
1456
|
+
""
|
|
1457
|
+
]
|
|
1458
|
+
});
|
|
1244
1459
|
const local = this._closeStream(streamTag);
|
|
1245
1460
|
return {
|
|
1246
1461
|
streamTag,
|
|
@@ -1260,8 +1475,7 @@ var TestExtensionWithStreams = class {
|
|
|
1260
1475
|
* Force-close the connection.
|
|
1261
1476
|
*/
|
|
1262
1477
|
async closeConnection(err) {
|
|
1263
|
-
|
|
1264
|
-
(_a = this.extensionContext) == null ? void 0 : _a.close(err);
|
|
1478
|
+
this.extensionContext?.close(err);
|
|
1265
1479
|
}
|
|
1266
1480
|
};
|
|
1267
1481
|
|
|
@@ -1277,4 +1491,4 @@ export {
|
|
|
1277
1491
|
TestExtension,
|
|
1278
1492
|
TestExtensionWithStreams
|
|
1279
1493
|
};
|
|
1280
|
-
//# sourceMappingURL=chunk-
|
|
1494
|
+
//# sourceMappingURL=chunk-57AKT4R2.mjs.map
|