@dxos/teleport 0.3.5-main.d85c645 → 0.3.5-main.d8a95f3
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-PWWDYMDW.mjs → chunk-VXXLKKBF.mjs} +180 -131
- package/dist/lib/browser/chunk-VXXLKKBF.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 +1 -1
- package/dist/lib/node/index.cjs +181 -132
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +179 -130
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/types/src/muxing/balancer.d.ts +3 -1
- package/dist/types/src/muxing/balancer.d.ts.map +1 -1
- package/dist/types/src/muxing/muxer.d.ts +2 -2
- package/dist/types/src/muxing/muxer.d.ts.map +1 -1
- package/dist/types/src/muxing/rpc-port.d.ts +1 -1
- package/dist/types/src/muxing/rpc-port.d.ts.map +1 -1
- package/dist/types/src/teleport.d.ts.map +1 -1
- package/package.json +12 -12
- package/src/muxing/balancer.ts +61 -49
- package/src/muxing/muxer.ts +20 -13
- package/src/muxing/rpc-port.ts +1 -1
- package/src/teleport.ts +7 -4
- package/dist/lib/browser/chunk-PWWDYMDW.mjs.map +0 -7
|
@@ -2,7 +2,7 @@ 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 { invariant as
|
|
5
|
+
import { invariant as invariant5 } from "@dxos/invariant";
|
|
6
6
|
import { PublicKey as PublicKey2 } from "@dxos/keys";
|
|
7
7
|
import { log as log5 } from "@dxos/log";
|
|
8
8
|
|
|
@@ -10,7 +10,7 @@ import { log as log5 } from "@dxos/log";
|
|
|
10
10
|
import { asyncTimeout, scheduleTaskInterval as scheduleTaskInterval2, runInContextAsync, synchronized, scheduleTask } from "@dxos/async";
|
|
11
11
|
import { Context as Context2 } from "@dxos/context";
|
|
12
12
|
import { failUndefined as failUndefined2 } from "@dxos/debug";
|
|
13
|
-
import { invariant as
|
|
13
|
+
import { invariant as invariant4 } from "@dxos/invariant";
|
|
14
14
|
import { PublicKey } from "@dxos/keys";
|
|
15
15
|
import { log as log4 } from "@dxos/log";
|
|
16
16
|
import { schema as schema2, RpcClosedError, TimeoutError as TimeoutError2 } from "@dxos/protocols";
|
|
@@ -188,13 +188,14 @@ import { Duplex as Duplex2 } from "@dxos/node-std/stream";
|
|
|
188
188
|
import { scheduleTaskInterval, Event as Event3, Trigger } from "@dxos/async";
|
|
189
189
|
import { Context } from "@dxos/context";
|
|
190
190
|
import { failUndefined } from "@dxos/debug";
|
|
191
|
-
import { invariant as
|
|
191
|
+
import { invariant as invariant3 } from "@dxos/invariant";
|
|
192
192
|
import { log as log3 } from "@dxos/log";
|
|
193
193
|
import { schema, TimeoutError } from "@dxos/protocols";
|
|
194
194
|
|
|
195
195
|
// packages/core/mesh/teleport/src/muxing/balancer.ts
|
|
196
196
|
import * as varint from "varint";
|
|
197
197
|
import { Event as Event2 } from "@dxos/async";
|
|
198
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
198
199
|
import { log as log2 } from "@dxos/log";
|
|
199
200
|
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/muxing/balancer.ts";
|
|
200
201
|
var MAX_CHUNK_SIZE = 8192;
|
|
@@ -206,6 +207,7 @@ var Balancer = class {
|
|
|
206
207
|
this._framer = new Framer();
|
|
207
208
|
this._sendBuffers = /* @__PURE__ */ new Map();
|
|
208
209
|
this._receiveBuffers = /* @__PURE__ */ new Map();
|
|
210
|
+
this._sending = false;
|
|
209
211
|
this.incomingData = new Event2();
|
|
210
212
|
this.stream = this._framer.stream;
|
|
211
213
|
this._channels.push(_sysChannelId);
|
|
@@ -224,43 +226,19 @@ var Balancer = class {
|
|
|
224
226
|
this._channels.push(channel);
|
|
225
227
|
}
|
|
226
228
|
pushData(data, trigger, channelId) {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
}
|
|
234
|
-
const sendBuffer = this._sendBuffers.get(channelId);
|
|
235
|
-
const chunks = [];
|
|
236
|
-
for (let idx = 0; idx < data.length; idx += MAX_CHUNK_SIZE) {
|
|
237
|
-
chunks.push(data.subarray(idx, idx + MAX_CHUNK_SIZE));
|
|
238
|
-
}
|
|
239
|
-
chunks.forEach((chunk, index) => {
|
|
240
|
-
const msg = encodeChunk({
|
|
241
|
-
chunk,
|
|
242
|
-
channelId,
|
|
243
|
-
dataLength: index === 0 ? data.length : void 0
|
|
244
|
-
});
|
|
245
|
-
sendBuffer.push({
|
|
246
|
-
msg,
|
|
247
|
-
trigger: index === chunks.length - 1 ? trigger : void 0
|
|
248
|
-
});
|
|
249
|
-
});
|
|
250
|
-
if (noCalls) {
|
|
251
|
-
this._sendChunk().catch((err) => log2.catch(err, void 0, {
|
|
252
|
-
F: __dxlog_file2,
|
|
253
|
-
L: 100,
|
|
254
|
-
S: this,
|
|
255
|
-
C: (f, a) => f(...a)
|
|
256
|
-
}));
|
|
257
|
-
}
|
|
229
|
+
this._enqueueChunk(data, trigger, channelId);
|
|
230
|
+
this._sendChunks().catch((err) => log2.catch(err, void 0, {
|
|
231
|
+
F: __dxlog_file2,
|
|
232
|
+
L: 75,
|
|
233
|
+
S: this,
|
|
234
|
+
C: (f, a) => f(...a)
|
|
235
|
+
}));
|
|
258
236
|
}
|
|
259
237
|
destroy() {
|
|
260
238
|
if (this._sendBuffers.size !== 0) {
|
|
261
239
|
log2.warn("destroying balancer with pending calls", void 0, {
|
|
262
240
|
F: __dxlog_file2,
|
|
263
|
-
L:
|
|
241
|
+
L: 80,
|
|
264
242
|
S: this,
|
|
265
243
|
C: (f, a) => f(...a)
|
|
266
244
|
});
|
|
@@ -301,36 +279,99 @@ var Balancer = class {
|
|
|
301
279
|
this._lastCallerIndex = (this._lastCallerIndex + 1) % this._channels.length;
|
|
302
280
|
return this._channels[index];
|
|
303
281
|
}
|
|
282
|
+
_enqueueChunk(data, trigger, channelId) {
|
|
283
|
+
if (!this._channels.includes(channelId)) {
|
|
284
|
+
throw new Error(`Unknown channel ${channelId}`);
|
|
285
|
+
}
|
|
286
|
+
if (!this._sendBuffers.has(channelId)) {
|
|
287
|
+
this._sendBuffers.set(channelId, []);
|
|
288
|
+
}
|
|
289
|
+
const sendBuffer = this._sendBuffers.get(channelId);
|
|
290
|
+
const chunks = [];
|
|
291
|
+
for (let idx = 0; idx < data.length; idx += MAX_CHUNK_SIZE) {
|
|
292
|
+
chunks.push(data.subarray(idx, idx + MAX_CHUNK_SIZE));
|
|
293
|
+
}
|
|
294
|
+
chunks.forEach((chunk, index) => {
|
|
295
|
+
const msg = encodeChunk({
|
|
296
|
+
chunk,
|
|
297
|
+
channelId,
|
|
298
|
+
dataLength: index === 0 ? data.length : void 0
|
|
299
|
+
});
|
|
300
|
+
sendBuffer.push({
|
|
301
|
+
msg,
|
|
302
|
+
trigger: index === chunks.length - 1 ? trigger : void 0
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
// get the next chunk or null if there are no chunks remaining
|
|
304
307
|
_getNextChunk() {
|
|
305
308
|
let chunk;
|
|
306
|
-
while (
|
|
309
|
+
while (this._sendBuffers.size > 0) {
|
|
307
310
|
const channelId = this._getNextCallerId();
|
|
308
311
|
const sendBuffer = this._sendBuffers.get(channelId);
|
|
309
312
|
if (!sendBuffer) {
|
|
310
313
|
continue;
|
|
311
314
|
}
|
|
312
315
|
chunk = sendBuffer.shift();
|
|
316
|
+
if (!chunk) {
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
313
319
|
if (sendBuffer.length === 0) {
|
|
314
320
|
this._sendBuffers.delete(channelId);
|
|
315
321
|
}
|
|
322
|
+
return chunk;
|
|
316
323
|
}
|
|
317
|
-
return
|
|
324
|
+
return null;
|
|
318
325
|
}
|
|
319
|
-
async
|
|
320
|
-
if (this.
|
|
326
|
+
async _sendChunks() {
|
|
327
|
+
if (this._sending) {
|
|
321
328
|
return;
|
|
322
329
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
330
|
+
this._sending = true;
|
|
331
|
+
let chunk;
|
|
332
|
+
chunk = this._getNextChunk();
|
|
333
|
+
while (chunk) {
|
|
334
|
+
if (!this._framer.writable) {
|
|
335
|
+
log2("PAUSE for drain", void 0, {
|
|
336
|
+
F: __dxlog_file2,
|
|
337
|
+
L: 179,
|
|
338
|
+
S: this,
|
|
339
|
+
C: (f, a) => f(...a)
|
|
340
|
+
});
|
|
341
|
+
await this._framer.drain.waitForCount(1);
|
|
342
|
+
log2("RESUME for drain", void 0, {
|
|
343
|
+
F: __dxlog_file2,
|
|
344
|
+
L: 181,
|
|
345
|
+
S: this,
|
|
346
|
+
C: (f, a) => f(...a)
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
try {
|
|
350
|
+
await this._framer.port.send(chunk.msg);
|
|
351
|
+
chunk.trigger?.wake();
|
|
352
|
+
} catch (err) {
|
|
353
|
+
log2("Error sending chunk", {
|
|
354
|
+
err
|
|
355
|
+
}, {
|
|
356
|
+
F: __dxlog_file2,
|
|
357
|
+
L: 187,
|
|
358
|
+
S: this,
|
|
359
|
+
C: (f, a) => f(...a)
|
|
360
|
+
});
|
|
361
|
+
chunk.trigger?.throw(err);
|
|
362
|
+
}
|
|
363
|
+
chunk = this._getNextChunk();
|
|
332
364
|
}
|
|
333
|
-
|
|
365
|
+
invariant2(this._sendBuffers.size === 0, "sendBuffers not empty", {
|
|
366
|
+
F: __dxlog_file2,
|
|
367
|
+
L: 192,
|
|
368
|
+
S: this,
|
|
369
|
+
A: [
|
|
370
|
+
"this._sendBuffers.size === 0",
|
|
371
|
+
"'sendBuffers not empty'"
|
|
372
|
+
]
|
|
373
|
+
});
|
|
374
|
+
this._sending = false;
|
|
334
375
|
}
|
|
335
376
|
};
|
|
336
377
|
var encodeChunk = ({ channelId, dataLength, chunk }) => {
|
|
@@ -363,6 +404,8 @@ var decodeChunk = (data, withLength) => {
|
|
|
363
404
|
// packages/core/mesh/teleport/src/muxing/muxer.ts
|
|
364
405
|
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/muxing/muxer.ts";
|
|
365
406
|
var Command = schema.getCodecForType("dxos.mesh.muxer.Command");
|
|
407
|
+
var DEFAULT_SEND_COMMAND_TIMEOUT = 6e4;
|
|
408
|
+
var DESTROY_COMMAND_SEND_TIMEOUT = 5e3;
|
|
366
409
|
var STATS_INTERVAL = 1e3;
|
|
367
410
|
var MAX_SAFE_FRAME_SIZE = 1e6;
|
|
368
411
|
var SYSTEM_CHANNEL_ID = 0;
|
|
@@ -374,9 +417,9 @@ var Muxer = class {
|
|
|
374
417
|
this._channelsByTag = /* @__PURE__ */ new Map();
|
|
375
418
|
this._ctx = new Context();
|
|
376
419
|
this._nextId = 1;
|
|
377
|
-
this._destroyed = false;
|
|
378
|
-
this._destroying = false;
|
|
379
420
|
this._closing = false;
|
|
421
|
+
this._destroying = false;
|
|
422
|
+
this._disposed = false;
|
|
380
423
|
this._lastStats = void 0;
|
|
381
424
|
this._lastChannelStats = /* @__PURE__ */ new Map();
|
|
382
425
|
this.afterClosed = new Event3();
|
|
@@ -385,7 +428,6 @@ var Muxer = class {
|
|
|
385
428
|
this._balancer.incomingData.on(async (msg) => {
|
|
386
429
|
await this._handleCommand(Command.decode(msg));
|
|
387
430
|
});
|
|
388
|
-
scheduleTaskInterval(this._ctx, async () => this._emitStats(), STATS_INTERVAL);
|
|
389
431
|
}
|
|
390
432
|
/**
|
|
391
433
|
* Creates a duplex Node.js-style stream.
|
|
@@ -398,9 +440,9 @@ var Muxer = class {
|
|
|
398
440
|
tag,
|
|
399
441
|
contentType: opts.contentType
|
|
400
442
|
});
|
|
401
|
-
|
|
443
|
+
invariant3(!channel.push, `Channel already open: ${tag}`, {
|
|
402
444
|
F: __dxlog_file3,
|
|
403
|
-
L:
|
|
445
|
+
L: 140,
|
|
404
446
|
S: this,
|
|
405
447
|
A: [
|
|
406
448
|
"!channel.push",
|
|
@@ -446,9 +488,9 @@ var Muxer = class {
|
|
|
446
488
|
tag,
|
|
447
489
|
contentType: opts.contentType
|
|
448
490
|
});
|
|
449
|
-
|
|
491
|
+
invariant3(!channel.push, `Channel already open: ${tag}`, {
|
|
450
492
|
F: __dxlog_file3,
|
|
451
|
-
L:
|
|
493
|
+
L: 192,
|
|
452
494
|
S: this,
|
|
453
495
|
A: [
|
|
454
496
|
"!channel.push",
|
|
@@ -466,13 +508,13 @@ var Muxer = class {
|
|
|
466
508
|
}
|
|
467
509
|
};
|
|
468
510
|
const port = {
|
|
469
|
-
send: async (data) => {
|
|
470
|
-
await this._sendData(channel, data);
|
|
511
|
+
send: async (data, timeout) => {
|
|
512
|
+
await this._sendData(channel, data, timeout);
|
|
471
513
|
},
|
|
472
514
|
subscribe: (cb) => {
|
|
473
|
-
|
|
515
|
+
invariant3(!callback, "Only one subscriber is allowed", {
|
|
474
516
|
F: __dxlog_file3,
|
|
475
|
-
L:
|
|
517
|
+
L: 214,
|
|
476
518
|
S: this,
|
|
477
519
|
A: [
|
|
478
520
|
"!callback",
|
|
@@ -505,7 +547,7 @@ var Muxer = class {
|
|
|
505
547
|
if (this._destroying) {
|
|
506
548
|
log3("already destroying, ignoring graceful close request", void 0, {
|
|
507
549
|
F: __dxlog_file3,
|
|
508
|
-
L:
|
|
550
|
+
L: 247,
|
|
509
551
|
S: this,
|
|
510
552
|
C: (f, a) => f(...a)
|
|
511
553
|
});
|
|
@@ -514,7 +556,7 @@ var Muxer = class {
|
|
|
514
556
|
if (this._closing) {
|
|
515
557
|
log3("already closing, ignoring graceful close request", void 0, {
|
|
516
558
|
F: __dxlog_file3,
|
|
517
|
-
L:
|
|
559
|
+
L: 251,
|
|
518
560
|
S: this,
|
|
519
561
|
C: (f, a) => f(...a)
|
|
520
562
|
});
|
|
@@ -525,12 +567,12 @@ var Muxer = class {
|
|
|
525
567
|
close: {
|
|
526
568
|
error: err?.message
|
|
527
569
|
}
|
|
528
|
-
}, SYSTEM_CHANNEL_ID).catch(async (err2) => {
|
|
570
|
+
}, SYSTEM_CHANNEL_ID, DESTROY_COMMAND_SEND_TIMEOUT).catch(async (err2) => {
|
|
529
571
|
log3("error sending close command", {
|
|
530
572
|
err: err2
|
|
531
573
|
}, {
|
|
532
574
|
F: __dxlog_file3,
|
|
533
|
-
L:
|
|
575
|
+
L: 266,
|
|
534
576
|
S: this,
|
|
535
577
|
C: (f, a) => f(...a)
|
|
536
578
|
});
|
|
@@ -552,7 +594,7 @@ var Muxer = class {
|
|
|
552
594
|
if (this._destroying) {
|
|
553
595
|
log3("already destroying, ignoring destroy request", void 0, {
|
|
554
596
|
F: __dxlog_file3,
|
|
555
|
-
L:
|
|
597
|
+
L: 287,
|
|
556
598
|
S: this,
|
|
557
599
|
C: (f, a) => f(...a)
|
|
558
600
|
});
|
|
@@ -563,7 +605,7 @@ var Muxer = class {
|
|
|
563
605
|
if (this._closing) {
|
|
564
606
|
log3("destroy cancelling graceful close", void 0, {
|
|
565
607
|
F: __dxlog_file3,
|
|
566
|
-
L:
|
|
608
|
+
L: 293,
|
|
567
609
|
S: this,
|
|
568
610
|
C: (f, a) => f(...a)
|
|
569
611
|
});
|
|
@@ -578,7 +620,7 @@ var Muxer = class {
|
|
|
578
620
|
err: err2
|
|
579
621
|
}, {
|
|
580
622
|
F: __dxlog_file3,
|
|
581
|
-
L:
|
|
623
|
+
L: 306,
|
|
582
624
|
S: this,
|
|
583
625
|
C: (f, a) => f(...a)
|
|
584
626
|
});
|
|
@@ -589,7 +631,7 @@ var Muxer = class {
|
|
|
589
631
|
err: err2
|
|
590
632
|
}, {
|
|
591
633
|
F: __dxlog_file3,
|
|
592
|
-
L:
|
|
634
|
+
L: 311,
|
|
593
635
|
S: this,
|
|
594
636
|
C: (f, a) => f(...a)
|
|
595
637
|
});
|
|
@@ -597,10 +639,10 @@ var Muxer = class {
|
|
|
597
639
|
}
|
|
598
640
|
// complete the termination, graceful or otherwise
|
|
599
641
|
async dispose(err) {
|
|
600
|
-
if (this.
|
|
642
|
+
if (this._disposed) {
|
|
601
643
|
log3("already destroyed, ignoring dispose request", void 0, {
|
|
602
644
|
F: __dxlog_file3,
|
|
603
|
-
L:
|
|
645
|
+
L: 319,
|
|
604
646
|
S: this,
|
|
605
647
|
C: (f, a) => f(...a)
|
|
606
648
|
});
|
|
@@ -611,18 +653,18 @@ var Muxer = class {
|
|
|
611
653
|
for (const channel of this._channelsByTag.values()) {
|
|
612
654
|
channel.destroy?.(err);
|
|
613
655
|
}
|
|
614
|
-
this.
|
|
656
|
+
this._disposed = true;
|
|
615
657
|
this.afterClosed.emit(err);
|
|
616
658
|
this._channelsByLocalId.clear();
|
|
617
659
|
this._channelsByTag.clear();
|
|
618
660
|
}
|
|
619
661
|
async _handleCommand(cmd) {
|
|
620
|
-
if (this.
|
|
662
|
+
if (this._disposed) {
|
|
621
663
|
log3.warn("Received command after destroy", {
|
|
622
664
|
cmd
|
|
623
665
|
}, {
|
|
624
666
|
F: __dxlog_file3,
|
|
625
|
-
L:
|
|
667
|
+
L: 341,
|
|
626
668
|
S: this,
|
|
627
669
|
C: (f, a) => f(...a)
|
|
628
670
|
});
|
|
@@ -632,7 +674,7 @@ var Muxer = class {
|
|
|
632
674
|
if (!this._closing) {
|
|
633
675
|
log3("received peer close, initiating my own graceful close", void 0, {
|
|
634
676
|
F: __dxlog_file3,
|
|
635
|
-
L:
|
|
677
|
+
L: 347,
|
|
636
678
|
S: this,
|
|
637
679
|
C: (f, a) => f(...a)
|
|
638
680
|
});
|
|
@@ -640,7 +682,7 @@ var Muxer = class {
|
|
|
640
682
|
} else {
|
|
641
683
|
log3("received close from peer, already closing", void 0, {
|
|
642
684
|
F: __dxlog_file3,
|
|
643
|
-
L:
|
|
685
|
+
L: 350,
|
|
644
686
|
S: this,
|
|
645
687
|
C: (f, a) => f(...a)
|
|
646
688
|
});
|
|
@@ -669,7 +711,7 @@ var Muxer = class {
|
|
|
669
711
|
tag: stream.tag
|
|
670
712
|
}, {
|
|
671
713
|
F: __dxlog_file3,
|
|
672
|
-
L:
|
|
714
|
+
L: 379,
|
|
673
715
|
S: this,
|
|
674
716
|
C: (f, a) => f(...a)
|
|
675
717
|
});
|
|
@@ -678,16 +720,21 @@ var Muxer = class {
|
|
|
678
720
|
stream.push(cmd.data.data);
|
|
679
721
|
}
|
|
680
722
|
}
|
|
681
|
-
async _sendCommand(cmd, channelId = -1) {
|
|
723
|
+
async _sendCommand(cmd, channelId = -1, timeout = DEFAULT_SEND_COMMAND_TIMEOUT) {
|
|
682
724
|
try {
|
|
683
725
|
const trigger = new Trigger();
|
|
684
726
|
this._balancer.pushData(Command.encode(cmd), trigger, channelId);
|
|
685
|
-
await trigger.wait(
|
|
727
|
+
await trigger.wait({
|
|
728
|
+
timeout
|
|
729
|
+
});
|
|
686
730
|
} catch (err) {
|
|
687
731
|
await this.destroy(err);
|
|
688
732
|
}
|
|
689
733
|
}
|
|
690
734
|
_getOrCreateStream(params) {
|
|
735
|
+
if (this._channelsByTag.size === 0) {
|
|
736
|
+
scheduleTaskInterval(this._ctx, async () => this._emitStats(), STATS_INTERVAL);
|
|
737
|
+
}
|
|
691
738
|
let channel = this._channelsByTag.get(params.tag);
|
|
692
739
|
if (!channel) {
|
|
693
740
|
channel = {
|
|
@@ -709,14 +756,14 @@ var Muxer = class {
|
|
|
709
756
|
}
|
|
710
757
|
return channel;
|
|
711
758
|
}
|
|
712
|
-
async _sendData(channel, data) {
|
|
759
|
+
async _sendData(channel, data, timeout) {
|
|
713
760
|
if (data.length > MAX_SAFE_FRAME_SIZE) {
|
|
714
761
|
log3.warn("frame size exceeds maximum safe value", {
|
|
715
762
|
size: data.length,
|
|
716
763
|
threshold: MAX_SAFE_FRAME_SIZE
|
|
717
764
|
}, {
|
|
718
765
|
F: __dxlog_file3,
|
|
719
|
-
L:
|
|
766
|
+
L: 425,
|
|
720
767
|
S: this,
|
|
721
768
|
C: (f, a) => f(...a)
|
|
722
769
|
});
|
|
@@ -731,7 +778,7 @@ var Muxer = class {
|
|
|
731
778
|
channelId: channel.remoteId,
|
|
732
779
|
data
|
|
733
780
|
}
|
|
734
|
-
}, channel.id);
|
|
781
|
+
}, channel.id, timeout);
|
|
735
782
|
}
|
|
736
783
|
_destroyChannel(channel, err) {
|
|
737
784
|
if (channel.destroy) {
|
|
@@ -741,7 +788,7 @@ var Muxer = class {
|
|
|
741
788
|
this._channelsByTag.delete(channel.tag);
|
|
742
789
|
}
|
|
743
790
|
async _emitStats() {
|
|
744
|
-
if (this.
|
|
791
|
+
if (this._disposed || this._destroying) {
|
|
745
792
|
this._lastStats = void 0;
|
|
746
793
|
this._lastChannelStats.clear();
|
|
747
794
|
return;
|
|
@@ -794,6 +841,8 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
794
841
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
795
842
|
}
|
|
796
843
|
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/teleport.ts";
|
|
844
|
+
var CONTROL_HEARTBEAT_INTERVAL = 1e4;
|
|
845
|
+
var CONTROL_HEARTBEAT_TIMEOUT = 6e4;
|
|
797
846
|
var Teleport = class {
|
|
798
847
|
constructor({ initiator, localPeerId, remotePeerId }) {
|
|
799
848
|
this._ctx = new Context2({
|
|
@@ -801,7 +850,7 @@ var Teleport = class {
|
|
|
801
850
|
void this.destroy(err).catch(() => {
|
|
802
851
|
log4.error("Error during destroy", err, {
|
|
803
852
|
F: __dxlog_file4,
|
|
804
|
-
L:
|
|
853
|
+
L: 47,
|
|
805
854
|
S: this,
|
|
806
855
|
C: (f, a) => f(...a)
|
|
807
856
|
});
|
|
@@ -810,21 +859,21 @@ var Teleport = class {
|
|
|
810
859
|
});
|
|
811
860
|
this._muxer = new Muxer();
|
|
812
861
|
this._control = new ControlExtension({
|
|
813
|
-
heartbeatInterval:
|
|
814
|
-
heartbeatTimeout:
|
|
862
|
+
heartbeatInterval: CONTROL_HEARTBEAT_INTERVAL,
|
|
863
|
+
heartbeatTimeout: CONTROL_HEARTBEAT_TIMEOUT,
|
|
815
864
|
onTimeout: () => {
|
|
816
865
|
if (this._destroying || this._aborting) {
|
|
817
866
|
return;
|
|
818
867
|
}
|
|
819
|
-
log4("
|
|
868
|
+
log4("abort teleport due to onTimeout in ControlExtension", void 0, {
|
|
820
869
|
F: __dxlog_file4,
|
|
821
|
-
L:
|
|
870
|
+
L: 62,
|
|
822
871
|
S: this,
|
|
823
872
|
C: (f, a) => f(...a)
|
|
824
873
|
});
|
|
825
|
-
this.
|
|
874
|
+
this.abort(new TimeoutError2("control extension")).catch((err) => log4.catch(err, void 0, {
|
|
826
875
|
F: __dxlog_file4,
|
|
827
|
-
L:
|
|
876
|
+
L: 63,
|
|
828
877
|
S: this,
|
|
829
878
|
C: (f, a) => f(...a)
|
|
830
879
|
}));
|
|
@@ -835,27 +884,27 @@ var Teleport = class {
|
|
|
835
884
|
this._open = false;
|
|
836
885
|
this._destroying = false;
|
|
837
886
|
this._aborting = false;
|
|
838
|
-
|
|
887
|
+
invariant4(typeof initiator === "boolean", void 0, {
|
|
839
888
|
F: __dxlog_file4,
|
|
840
|
-
L:
|
|
889
|
+
L: 75,
|
|
841
890
|
S: this,
|
|
842
891
|
A: [
|
|
843
892
|
"typeof initiator === 'boolean'",
|
|
844
893
|
""
|
|
845
894
|
]
|
|
846
895
|
});
|
|
847
|
-
|
|
896
|
+
invariant4(PublicKey.isPublicKey(localPeerId), void 0, {
|
|
848
897
|
F: __dxlog_file4,
|
|
849
|
-
L:
|
|
898
|
+
L: 76,
|
|
850
899
|
S: this,
|
|
851
900
|
A: [
|
|
852
901
|
"PublicKey.isPublicKey(localPeerId)",
|
|
853
902
|
""
|
|
854
903
|
]
|
|
855
904
|
});
|
|
856
|
-
|
|
905
|
+
invariant4(PublicKey.isPublicKey(remotePeerId), void 0, {
|
|
857
906
|
F: __dxlog_file4,
|
|
858
|
-
L:
|
|
907
|
+
L: 77,
|
|
859
908
|
S: this,
|
|
860
909
|
A: [
|
|
861
910
|
"PublicKey.isPublicKey(remotePeerId)",
|
|
@@ -870,13 +919,13 @@ var Teleport = class {
|
|
|
870
919
|
name
|
|
871
920
|
}, {
|
|
872
921
|
F: __dxlog_file4,
|
|
873
|
-
L:
|
|
922
|
+
L: 83,
|
|
874
923
|
S: this,
|
|
875
924
|
C: (f, a) => f(...a)
|
|
876
925
|
});
|
|
877
|
-
|
|
926
|
+
invariant4(!this._remoteExtensions.has(name), "Remote extension already exists", {
|
|
878
927
|
F: __dxlog_file4,
|
|
879
|
-
L:
|
|
928
|
+
L: 84,
|
|
880
929
|
S: this,
|
|
881
930
|
A: [
|
|
882
931
|
"!this._remoteExtensions.has(name)",
|
|
@@ -897,7 +946,7 @@ var Teleport = class {
|
|
|
897
946
|
if (this._destroying || this._aborting) {
|
|
898
947
|
log4("destroy teleport due to muxer stream close, skipping due to already destroying/aborting", void 0, {
|
|
899
948
|
F: __dxlog_file4,
|
|
900
|
-
L:
|
|
949
|
+
L: 100,
|
|
901
950
|
S: this,
|
|
902
951
|
C: (f, a) => f(...a)
|
|
903
952
|
});
|
|
@@ -920,7 +969,7 @@ var Teleport = class {
|
|
|
920
969
|
channels: stats.channels
|
|
921
970
|
}, {
|
|
922
971
|
F: __dxlog_file4,
|
|
923
|
-
L:
|
|
972
|
+
L: 113,
|
|
924
973
|
S: this,
|
|
925
974
|
C: (f, a) => f(...a)
|
|
926
975
|
});
|
|
@@ -958,7 +1007,7 @@ var Teleport = class {
|
|
|
958
1007
|
} catch (err2) {
|
|
959
1008
|
log4.catch(err2, void 0, {
|
|
960
1009
|
F: __dxlog_file4,
|
|
961
|
-
L:
|
|
1010
|
+
L: 166,
|
|
962
1011
|
S: this,
|
|
963
1012
|
C: (f, a) => f(...a)
|
|
964
1013
|
});
|
|
@@ -981,7 +1030,7 @@ var Teleport = class {
|
|
|
981
1030
|
} catch (err2) {
|
|
982
1031
|
log4.catch(err2, void 0, {
|
|
983
1032
|
F: __dxlog_file4,
|
|
984
|
-
L:
|
|
1033
|
+
L: 190,
|
|
985
1034
|
S: this,
|
|
986
1035
|
C: (f, a) => f(...a)
|
|
987
1036
|
});
|
|
@@ -997,7 +1046,7 @@ var Teleport = class {
|
|
|
997
1046
|
name
|
|
998
1047
|
}, {
|
|
999
1048
|
F: __dxlog_file4,
|
|
1000
|
-
L:
|
|
1049
|
+
L: 202,
|
|
1001
1050
|
S: this,
|
|
1002
1051
|
C: (f, a) => f(...a)
|
|
1003
1052
|
});
|
|
@@ -1019,18 +1068,18 @@ var Teleport = class {
|
|
|
1019
1068
|
}
|
|
1020
1069
|
}
|
|
1021
1070
|
_setExtension(extensionName, extension) {
|
|
1022
|
-
|
|
1071
|
+
invariant4(!extensionName.includes("/"), "Invalid extension name", {
|
|
1023
1072
|
F: __dxlog_file4,
|
|
1024
|
-
L:
|
|
1073
|
+
L: 226,
|
|
1025
1074
|
S: this,
|
|
1026
1075
|
A: [
|
|
1027
1076
|
"!extensionName.includes('/')",
|
|
1028
1077
|
"'Invalid extension name'"
|
|
1029
1078
|
]
|
|
1030
1079
|
});
|
|
1031
|
-
|
|
1080
|
+
invariant4(!this._extensions.has(extensionName), "Extension already exists", {
|
|
1032
1081
|
F: __dxlog_file4,
|
|
1033
|
-
L:
|
|
1082
|
+
L: 227,
|
|
1034
1083
|
S: this,
|
|
1035
1084
|
A: [
|
|
1036
1085
|
"!this._extensions.has(extensionName)",
|
|
@@ -1044,7 +1093,7 @@ var Teleport = class {
|
|
|
1044
1093
|
extensionName
|
|
1045
1094
|
}, {
|
|
1046
1095
|
F: __dxlog_file4,
|
|
1047
|
-
L:
|
|
1096
|
+
L: 232,
|
|
1048
1097
|
S: this,
|
|
1049
1098
|
C: (f, a) => f(...a)
|
|
1050
1099
|
});
|
|
@@ -1054,9 +1103,9 @@ var Teleport = class {
|
|
|
1054
1103
|
localPeerId: this.localPeerId,
|
|
1055
1104
|
remotePeerId: this.remotePeerId,
|
|
1056
1105
|
createPort: async (channelName, opts) => {
|
|
1057
|
-
|
|
1106
|
+
invariant4(!channelName.includes("/"), "Invalid channel name", {
|
|
1058
1107
|
F: __dxlog_file4,
|
|
1059
|
-
L:
|
|
1108
|
+
L: 240,
|
|
1060
1109
|
S: this,
|
|
1061
1110
|
A: [
|
|
1062
1111
|
"!channelName.includes('/')",
|
|
@@ -1066,9 +1115,9 @@ var Teleport = class {
|
|
|
1066
1115
|
return this._muxer.createPort(`${extensionName}/${channelName}`, opts);
|
|
1067
1116
|
},
|
|
1068
1117
|
createStream: async (channelName, opts) => {
|
|
1069
|
-
|
|
1118
|
+
invariant4(!channelName.includes("/"), "Invalid channel name", {
|
|
1070
1119
|
F: __dxlog_file4,
|
|
1071
|
-
L:
|
|
1120
|
+
L: 244,
|
|
1072
1121
|
S: this,
|
|
1073
1122
|
A: [
|
|
1074
1123
|
"!channelName.includes('/')",
|
|
@@ -1088,7 +1137,7 @@ var Teleport = class {
|
|
|
1088
1137
|
extensionName
|
|
1089
1138
|
}, {
|
|
1090
1139
|
F: __dxlog_file4,
|
|
1091
|
-
L:
|
|
1140
|
+
L: 255,
|
|
1092
1141
|
S: this,
|
|
1093
1142
|
C: (f, a) => f(...a)
|
|
1094
1143
|
});
|
|
@@ -1176,7 +1225,7 @@ var TestBuilder = class {
|
|
|
1176
1225
|
await Promise.all(Array.from(this._peers).map((agent) => agent.destroy()));
|
|
1177
1226
|
}
|
|
1178
1227
|
async connect(peer1, peer2) {
|
|
1179
|
-
|
|
1228
|
+
invariant5(peer1 !== peer2, void 0, {
|
|
1180
1229
|
F: __dxlog_file5,
|
|
1181
1230
|
L: 37,
|
|
1182
1231
|
S: this,
|
|
@@ -1185,7 +1234,7 @@ var TestBuilder = class {
|
|
|
1185
1234
|
""
|
|
1186
1235
|
]
|
|
1187
1236
|
});
|
|
1188
|
-
|
|
1237
|
+
invariant5(this._peers.has(peer1), void 0, {
|
|
1189
1238
|
F: __dxlog_file5,
|
|
1190
1239
|
L: 38,
|
|
1191
1240
|
S: this,
|
|
@@ -1194,7 +1243,7 @@ var TestBuilder = class {
|
|
|
1194
1243
|
""
|
|
1195
1244
|
]
|
|
1196
1245
|
});
|
|
1197
|
-
|
|
1246
|
+
invariant5(this._peers.has(peer1), void 0, {
|
|
1198
1247
|
F: __dxlog_file5,
|
|
1199
1248
|
L: 39,
|
|
1200
1249
|
S: this,
|
|
@@ -1222,7 +1271,7 @@ var TestBuilder = class {
|
|
|
1222
1271
|
];
|
|
1223
1272
|
}
|
|
1224
1273
|
async disconnect(peer1, peer2) {
|
|
1225
|
-
|
|
1274
|
+
invariant5(peer1 !== peer2, void 0, {
|
|
1226
1275
|
F: __dxlog_file5,
|
|
1227
1276
|
L: 51,
|
|
1228
1277
|
S: this,
|
|
@@ -1231,7 +1280,7 @@ var TestBuilder = class {
|
|
|
1231
1280
|
""
|
|
1232
1281
|
]
|
|
1233
1282
|
});
|
|
1234
|
-
|
|
1283
|
+
invariant5(this._peers.has(peer1), void 0, {
|
|
1235
1284
|
F: __dxlog_file5,
|
|
1236
1285
|
L: 52,
|
|
1237
1286
|
S: this,
|
|
@@ -1240,7 +1289,7 @@ var TestBuilder = class {
|
|
|
1240
1289
|
""
|
|
1241
1290
|
]
|
|
1242
1291
|
});
|
|
1243
|
-
|
|
1292
|
+
invariant5(this._peers.has(peer1), void 0, {
|
|
1244
1293
|
F: __dxlog_file5,
|
|
1245
1294
|
L: 53,
|
|
1246
1295
|
S: this,
|
|
@@ -1251,7 +1300,7 @@ var TestBuilder = class {
|
|
|
1251
1300
|
});
|
|
1252
1301
|
const connection1 = Array.from(peer1.connections).find((connection) => connection.remotePeerId.equals(peer2.peerId));
|
|
1253
1302
|
const connection2 = Array.from(peer2.connections).find((connection) => connection.remotePeerId.equals(peer1.peerId));
|
|
1254
|
-
|
|
1303
|
+
invariant5(connection1, void 0, {
|
|
1255
1304
|
F: __dxlog_file5,
|
|
1256
1305
|
L: 62,
|
|
1257
1306
|
S: this,
|
|
@@ -1260,7 +1309,7 @@ var TestBuilder = class {
|
|
|
1260
1309
|
""
|
|
1261
1310
|
]
|
|
1262
1311
|
});
|
|
1263
|
-
|
|
1312
|
+
invariant5(connection2, void 0, {
|
|
1264
1313
|
F: __dxlog_file5,
|
|
1265
1314
|
L: 63,
|
|
1266
1315
|
S: this,
|
|
@@ -1290,7 +1339,7 @@ var TestPeer = class {
|
|
|
1290
1339
|
return connection;
|
|
1291
1340
|
}
|
|
1292
1341
|
async openConnection(connection) {
|
|
1293
|
-
|
|
1342
|
+
invariant5(this.connections.has(connection), void 0, {
|
|
1294
1343
|
F: __dxlog_file5,
|
|
1295
1344
|
L: 84,
|
|
1296
1345
|
S: this,
|
|
@@ -1303,7 +1352,7 @@ var TestPeer = class {
|
|
|
1303
1352
|
await this.onOpen(connection);
|
|
1304
1353
|
}
|
|
1305
1354
|
async closeConnection(connection) {
|
|
1306
|
-
|
|
1355
|
+
invariant5(this.connections.has(connection), void 0, {
|
|
1307
1356
|
F: __dxlog_file5,
|
|
1308
1357
|
L: 90,
|
|
1309
1358
|
S: this,
|
|
@@ -1359,7 +1408,7 @@ var TestConnection = class {
|
|
|
1359
1408
|
|
|
1360
1409
|
// packages/core/mesh/teleport/src/testing/test-extension.ts
|
|
1361
1410
|
import { asyncTimeout as asyncTimeout2, Trigger as Trigger2 } from "@dxos/async";
|
|
1362
|
-
import { invariant as
|
|
1411
|
+
import { invariant as invariant6 } from "@dxos/invariant";
|
|
1363
1412
|
import { log as log6 } from "@dxos/log";
|
|
1364
1413
|
import { schema as schema3 } from "@dxos/protocols";
|
|
1365
1414
|
import { createProtoRpcPeer as createProtoRpcPeer2 } from "@dxos/rpc";
|
|
@@ -1445,7 +1494,7 @@ var TestExtension = class {
|
|
|
1445
1494
|
const res = await asyncTimeout2(this._rpc.rpc.TestService.testCall({
|
|
1446
1495
|
data: message
|
|
1447
1496
|
}), 1500);
|
|
1448
|
-
|
|
1497
|
+
invariant6(res.data === message, void 0, {
|
|
1449
1498
|
F: __dxlog_file6,
|
|
1450
1499
|
L: 84,
|
|
1451
1500
|
S: this,
|
|
@@ -1466,7 +1515,7 @@ var TestExtension = class {
|
|
|
1466
1515
|
// packages/core/mesh/teleport/src/testing/test-extension-with-streams.ts
|
|
1467
1516
|
import { randomBytes } from "@dxos/node-std/crypto";
|
|
1468
1517
|
import { Trigger as Trigger3 } from "@dxos/async";
|
|
1469
|
-
import { invariant as
|
|
1518
|
+
import { invariant as invariant7 } from "@dxos/invariant";
|
|
1470
1519
|
import { log as log7 } from "@dxos/log";
|
|
1471
1520
|
import { schema as schema4 } from "@dxos/protocols";
|
|
1472
1521
|
import { createProtoRpcPeer as createProtoRpcPeer3 } from "@dxos/rpc";
|
|
@@ -1483,7 +1532,7 @@ var TestExtensionWithStreams = class {
|
|
|
1483
1532
|
return this.extensionContext?.remotePeerId;
|
|
1484
1533
|
}
|
|
1485
1534
|
async _openStream(streamTag, interval = 5, chunkSize = 2048) {
|
|
1486
|
-
|
|
1535
|
+
invariant7(!this._streams.has(streamTag), `Stream already exists: ${streamTag}`, {
|
|
1487
1536
|
F: __dxlog_file7,
|
|
1488
1537
|
L: 39,
|
|
1489
1538
|
S: this,
|
|
@@ -1549,7 +1598,7 @@ var TestExtensionWithStreams = class {
|
|
|
1549
1598
|
}, 100);
|
|
1550
1599
|
}
|
|
1551
1600
|
_closeStream(streamTag) {
|
|
1552
|
-
|
|
1601
|
+
invariant7(this._streams.has(streamTag), `Stream does not exist: ${streamTag}`, {
|
|
1553
1602
|
F: __dxlog_file7,
|
|
1554
1603
|
L: 106,
|
|
1555
1604
|
S: this,
|
|
@@ -1672,7 +1721,7 @@ var TestExtensionWithStreams = class {
|
|
|
1672
1721
|
streamLoadInterval,
|
|
1673
1722
|
streamLoadChunkSize
|
|
1674
1723
|
});
|
|
1675
|
-
|
|
1724
|
+
invariant7(data === streamTag, void 0, {
|
|
1676
1725
|
F: __dxlog_file7,
|
|
1677
1726
|
L: 207,
|
|
1678
1727
|
S: this,
|
|
@@ -1691,7 +1740,7 @@ var TestExtensionWithStreams = class {
|
|
|
1691
1740
|
const { data, bytesSent, bytesReceived, sendErrors, receiveErrors, runningTime } = await this._rpc.rpc.TestServiceWithStreams.closeTestStream({
|
|
1692
1741
|
data: streamTag
|
|
1693
1742
|
});
|
|
1694
|
-
|
|
1743
|
+
invariant7(data === streamTag, void 0, {
|
|
1695
1744
|
F: __dxlog_file7,
|
|
1696
1745
|
L: 220,
|
|
1697
1746
|
S: this,
|
|
@@ -1735,4 +1784,4 @@ export {
|
|
|
1735
1784
|
TestExtension,
|
|
1736
1785
|
TestExtensionWithStreams
|
|
1737
1786
|
};
|
|
1738
|
-
//# sourceMappingURL=chunk-
|
|
1787
|
+
//# sourceMappingURL=chunk-VXXLKKBF.mjs.map
|