@dxos/teleport 0.3.4 → 0.3.5-main.1429e83
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-J3RZ6SXA.mjs → chunk-VXXLKKBF.mjs} +350 -184
- package/dist/lib/browser/chunk-VXXLKKBF.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +2 -2
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +1 -1
- package/dist/lib/node/index.cjs +350 -184
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +347 -181
- 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/framer.d.ts.map +1 -1
- package/dist/types/src/muxing/muxer.d.ts +5 -6
- 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 +64 -49
- package/src/muxing/framer.ts +7 -0
- package/src/muxing/muxer.test.ts +1 -1
- package/src/muxing/muxer.ts +98 -37
- package/src/muxing/rpc-port.ts +1 -1
- package/src/teleport.ts +8 -5
- package/dist/lib/browser/chunk-J3RZ6SXA.mjs.map +0 -7
package/dist/lib/node/index.cjs
CHANGED
|
@@ -48,7 +48,8 @@ module.exports = __toCommonJS(src_exports);
|
|
|
48
48
|
var import_node_stream = require("node:stream");
|
|
49
49
|
var import_async = require("@dxos/async");
|
|
50
50
|
var import_invariant = require("@dxos/invariant");
|
|
51
|
-
var
|
|
51
|
+
var import_log = require("@dxos/log");
|
|
52
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/muxing/framer.ts";
|
|
52
53
|
var FRAME_LENGTH_SIZE = 2;
|
|
53
54
|
var Framer = class {
|
|
54
55
|
constructor() {
|
|
@@ -70,7 +71,7 @@ var Framer = class {
|
|
|
70
71
|
write: (chunk, encoding, callback) => {
|
|
71
72
|
(0, import_invariant.invariant)(!this._subscribeCb, "Internal Framer bug. Concurrent writes detected.", {
|
|
72
73
|
F: __dxlog_file,
|
|
73
|
-
L:
|
|
74
|
+
L: 40,
|
|
74
75
|
S: this,
|
|
75
76
|
A: [
|
|
76
77
|
"!this._subscribeCb",
|
|
@@ -114,7 +115,7 @@ var Framer = class {
|
|
|
114
115
|
subscribe: (callback) => {
|
|
115
116
|
(0, import_invariant.invariant)(!this._messageCb, "Rpc port already has a message listener.", {
|
|
116
117
|
F: __dxlog_file,
|
|
117
|
-
L:
|
|
118
|
+
L: 79,
|
|
118
119
|
S: this,
|
|
119
120
|
A: [
|
|
120
121
|
"!this._messageCb",
|
|
@@ -168,6 +169,22 @@ var Framer = class {
|
|
|
168
169
|
}
|
|
169
170
|
}
|
|
170
171
|
destroy() {
|
|
172
|
+
if (this._stream.readableLength > 0) {
|
|
173
|
+
import_log.log.warn("framer destroyed while there are still read bytes in the buffer.", void 0, {
|
|
174
|
+
F: __dxlog_file,
|
|
175
|
+
L: 140,
|
|
176
|
+
S: this,
|
|
177
|
+
C: (f, a) => f(...a)
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
if (this._stream.writableLength > 0) {
|
|
181
|
+
import_log.log.warn("framer destroyed while there are still write bytes in the buffer.", void 0, {
|
|
182
|
+
F: __dxlog_file,
|
|
183
|
+
L: 143,
|
|
184
|
+
S: this,
|
|
185
|
+
C: (f, a) => f(...a)
|
|
186
|
+
});
|
|
187
|
+
}
|
|
171
188
|
this._stream.destroy();
|
|
172
189
|
}
|
|
173
190
|
};
|
|
@@ -198,15 +215,16 @@ var import_node_stream2 = require("node:stream");
|
|
|
198
215
|
var import_async3 = require("@dxos/async");
|
|
199
216
|
var import_context = require("@dxos/context");
|
|
200
217
|
var import_debug = require("@dxos/debug");
|
|
201
|
-
var
|
|
202
|
-
var
|
|
218
|
+
var import_invariant3 = require("@dxos/invariant");
|
|
219
|
+
var import_log3 = require("@dxos/log");
|
|
203
220
|
var import_protocols = require("@dxos/protocols");
|
|
204
221
|
|
|
205
222
|
// packages/core/mesh/teleport/src/muxing/balancer.ts
|
|
206
223
|
var varint = __toESM(require("varint"));
|
|
207
224
|
var import_async2 = require("@dxos/async");
|
|
208
|
-
var
|
|
209
|
-
var
|
|
225
|
+
var import_invariant2 = require("@dxos/invariant");
|
|
226
|
+
var import_log2 = require("@dxos/log");
|
|
227
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/muxing/balancer.ts";
|
|
210
228
|
var MAX_CHUNK_SIZE = 8192;
|
|
211
229
|
var Balancer = class {
|
|
212
230
|
constructor(_sysChannelId) {
|
|
@@ -216,6 +234,7 @@ var Balancer = class {
|
|
|
216
234
|
this._framer = new Framer();
|
|
217
235
|
this._sendBuffers = /* @__PURE__ */ new Map();
|
|
218
236
|
this._receiveBuffers = /* @__PURE__ */ new Map();
|
|
237
|
+
this._sending = false;
|
|
219
238
|
this.incomingData = new import_async2.Event();
|
|
220
239
|
this.stream = this._framer.stream;
|
|
221
240
|
this._channels.push(_sysChannelId);
|
|
@@ -234,39 +253,23 @@ var Balancer = class {
|
|
|
234
253
|
this._channels.push(channel);
|
|
235
254
|
}
|
|
236
255
|
pushData(data, trigger, channelId) {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}
|
|
249
|
-
chunks.forEach((chunk, index) => {
|
|
250
|
-
const msg = encodeChunk({
|
|
251
|
-
chunk,
|
|
252
|
-
channelId,
|
|
253
|
-
dataLength: index === 0 ? data.length : void 0
|
|
254
|
-
});
|
|
255
|
-
sendBuffer.push({
|
|
256
|
-
msg,
|
|
257
|
-
trigger: index === chunks.length - 1 ? trigger : void 0
|
|
258
|
-
});
|
|
259
|
-
});
|
|
260
|
-
if (noCalls) {
|
|
261
|
-
this._sendChunk().catch((err) => import_log.log.catch(err, void 0, {
|
|
256
|
+
this._enqueueChunk(data, trigger, channelId);
|
|
257
|
+
this._sendChunks().catch((err) => import_log2.log.catch(err, void 0, {
|
|
258
|
+
F: __dxlog_file2,
|
|
259
|
+
L: 75,
|
|
260
|
+
S: this,
|
|
261
|
+
C: (f, a) => f(...a)
|
|
262
|
+
}));
|
|
263
|
+
}
|
|
264
|
+
destroy() {
|
|
265
|
+
if (this._sendBuffers.size !== 0) {
|
|
266
|
+
import_log2.log.warn("destroying balancer with pending calls", void 0, {
|
|
262
267
|
F: __dxlog_file2,
|
|
263
|
-
L:
|
|
268
|
+
L: 80,
|
|
264
269
|
S: this,
|
|
265
270
|
C: (f, a) => f(...a)
|
|
266
|
-
})
|
|
271
|
+
});
|
|
267
272
|
}
|
|
268
|
-
}
|
|
269
|
-
destroy() {
|
|
270
273
|
this._sendBuffers.clear();
|
|
271
274
|
this._framer.destroy();
|
|
272
275
|
}
|
|
@@ -303,36 +306,99 @@ var Balancer = class {
|
|
|
303
306
|
this._lastCallerIndex = (this._lastCallerIndex + 1) % this._channels.length;
|
|
304
307
|
return this._channels[index];
|
|
305
308
|
}
|
|
309
|
+
_enqueueChunk(data, trigger, channelId) {
|
|
310
|
+
if (!this._channels.includes(channelId)) {
|
|
311
|
+
throw new Error(`Unknown channel ${channelId}`);
|
|
312
|
+
}
|
|
313
|
+
if (!this._sendBuffers.has(channelId)) {
|
|
314
|
+
this._sendBuffers.set(channelId, []);
|
|
315
|
+
}
|
|
316
|
+
const sendBuffer = this._sendBuffers.get(channelId);
|
|
317
|
+
const chunks = [];
|
|
318
|
+
for (let idx = 0; idx < data.length; idx += MAX_CHUNK_SIZE) {
|
|
319
|
+
chunks.push(data.subarray(idx, idx + MAX_CHUNK_SIZE));
|
|
320
|
+
}
|
|
321
|
+
chunks.forEach((chunk, index) => {
|
|
322
|
+
const msg = encodeChunk({
|
|
323
|
+
chunk,
|
|
324
|
+
channelId,
|
|
325
|
+
dataLength: index === 0 ? data.length : void 0
|
|
326
|
+
});
|
|
327
|
+
sendBuffer.push({
|
|
328
|
+
msg,
|
|
329
|
+
trigger: index === chunks.length - 1 ? trigger : void 0
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
// get the next chunk or null if there are no chunks remaining
|
|
306
334
|
_getNextChunk() {
|
|
307
335
|
let chunk;
|
|
308
|
-
while (
|
|
336
|
+
while (this._sendBuffers.size > 0) {
|
|
309
337
|
const channelId = this._getNextCallerId();
|
|
310
338
|
const sendBuffer = this._sendBuffers.get(channelId);
|
|
311
339
|
if (!sendBuffer) {
|
|
312
340
|
continue;
|
|
313
341
|
}
|
|
314
342
|
chunk = sendBuffer.shift();
|
|
343
|
+
if (!chunk) {
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
315
346
|
if (sendBuffer.length === 0) {
|
|
316
347
|
this._sendBuffers.delete(channelId);
|
|
317
348
|
}
|
|
349
|
+
return chunk;
|
|
318
350
|
}
|
|
319
|
-
return
|
|
351
|
+
return null;
|
|
320
352
|
}
|
|
321
|
-
async
|
|
322
|
-
if (this.
|
|
353
|
+
async _sendChunks() {
|
|
354
|
+
if (this._sending) {
|
|
323
355
|
return;
|
|
324
356
|
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
357
|
+
this._sending = true;
|
|
358
|
+
let chunk;
|
|
359
|
+
chunk = this._getNextChunk();
|
|
360
|
+
while (chunk) {
|
|
361
|
+
if (!this._framer.writable) {
|
|
362
|
+
(0, import_log2.log)("PAUSE for drain", void 0, {
|
|
363
|
+
F: __dxlog_file2,
|
|
364
|
+
L: 179,
|
|
365
|
+
S: this,
|
|
366
|
+
C: (f, a) => f(...a)
|
|
367
|
+
});
|
|
368
|
+
await this._framer.drain.waitForCount(1);
|
|
369
|
+
(0, import_log2.log)("RESUME for drain", void 0, {
|
|
370
|
+
F: __dxlog_file2,
|
|
371
|
+
L: 181,
|
|
372
|
+
S: this,
|
|
373
|
+
C: (f, a) => f(...a)
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
try {
|
|
377
|
+
await this._framer.port.send(chunk.msg);
|
|
378
|
+
chunk.trigger?.wake();
|
|
379
|
+
} catch (err) {
|
|
380
|
+
(0, import_log2.log)("Error sending chunk", {
|
|
381
|
+
err
|
|
382
|
+
}, {
|
|
383
|
+
F: __dxlog_file2,
|
|
384
|
+
L: 187,
|
|
385
|
+
S: this,
|
|
386
|
+
C: (f, a) => f(...a)
|
|
387
|
+
});
|
|
388
|
+
chunk.trigger?.throw(err);
|
|
389
|
+
}
|
|
390
|
+
chunk = this._getNextChunk();
|
|
334
391
|
}
|
|
335
|
-
|
|
392
|
+
(0, import_invariant2.invariant)(this._sendBuffers.size === 0, "sendBuffers not empty", {
|
|
393
|
+
F: __dxlog_file2,
|
|
394
|
+
L: 192,
|
|
395
|
+
S: this,
|
|
396
|
+
A: [
|
|
397
|
+
"this._sendBuffers.size === 0",
|
|
398
|
+
"'sendBuffers not empty'"
|
|
399
|
+
]
|
|
400
|
+
});
|
|
401
|
+
this._sending = false;
|
|
336
402
|
}
|
|
337
403
|
};
|
|
338
404
|
var encodeChunk = ({ channelId, dataLength, chunk }) => {
|
|
@@ -363,11 +429,14 @@ var decodeChunk = (data, withLength) => {
|
|
|
363
429
|
};
|
|
364
430
|
|
|
365
431
|
// packages/core/mesh/teleport/src/muxing/muxer.ts
|
|
366
|
-
var __dxlog_file3 = "/
|
|
432
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/muxing/muxer.ts";
|
|
367
433
|
var Command = import_protocols.schema.getCodecForType("dxos.mesh.muxer.Command");
|
|
434
|
+
var DEFAULT_SEND_COMMAND_TIMEOUT = 6e4;
|
|
435
|
+
var DESTROY_COMMAND_SEND_TIMEOUT = 5e3;
|
|
368
436
|
var STATS_INTERVAL = 1e3;
|
|
369
437
|
var MAX_SAFE_FRAME_SIZE = 1e6;
|
|
370
438
|
var SYSTEM_CHANNEL_ID = 0;
|
|
439
|
+
var GRACEFUL_CLOSE_TIMEOUT = 3e3;
|
|
371
440
|
var Muxer = class {
|
|
372
441
|
constructor() {
|
|
373
442
|
this._balancer = new Balancer(SYSTEM_CHANNEL_ID);
|
|
@@ -375,17 +444,17 @@ var Muxer = class {
|
|
|
375
444
|
this._channelsByTag = /* @__PURE__ */ new Map();
|
|
376
445
|
this._ctx = new import_context.Context();
|
|
377
446
|
this._nextId = 1;
|
|
378
|
-
this.
|
|
447
|
+
this._closing = false;
|
|
379
448
|
this._destroying = false;
|
|
449
|
+
this._disposed = false;
|
|
380
450
|
this._lastStats = void 0;
|
|
381
451
|
this._lastChannelStats = /* @__PURE__ */ new Map();
|
|
382
|
-
this.
|
|
452
|
+
this.afterClosed = new import_async3.Event();
|
|
383
453
|
this.statsUpdated = new import_async3.Event();
|
|
384
454
|
this.stream = this._balancer.stream;
|
|
385
455
|
this._balancer.incomingData.on(async (msg) => {
|
|
386
456
|
await this._handleCommand(Command.decode(msg));
|
|
387
457
|
});
|
|
388
|
-
(0, import_async3.scheduleTaskInterval)(this._ctx, async () => this._emitStats(), STATS_INTERVAL);
|
|
389
458
|
}
|
|
390
459
|
/**
|
|
391
460
|
* Creates a duplex Node.js-style stream.
|
|
@@ -398,9 +467,9 @@ var Muxer = class {
|
|
|
398
467
|
tag,
|
|
399
468
|
contentType: opts.contentType
|
|
400
469
|
});
|
|
401
|
-
(0,
|
|
470
|
+
(0, import_invariant3.invariant)(!channel.push, `Channel already open: ${tag}`, {
|
|
402
471
|
F: __dxlog_file3,
|
|
403
|
-
L:
|
|
472
|
+
L: 140,
|
|
404
473
|
S: this,
|
|
405
474
|
A: [
|
|
406
475
|
"!channel.push",
|
|
@@ -446,9 +515,9 @@ var Muxer = class {
|
|
|
446
515
|
tag,
|
|
447
516
|
contentType: opts.contentType
|
|
448
517
|
});
|
|
449
|
-
(0,
|
|
518
|
+
(0, import_invariant3.invariant)(!channel.push, `Channel already open: ${tag}`, {
|
|
450
519
|
F: __dxlog_file3,
|
|
451
|
-
L:
|
|
520
|
+
L: 192,
|
|
452
521
|
S: this,
|
|
453
522
|
A: [
|
|
454
523
|
"!channel.push",
|
|
@@ -466,13 +535,13 @@ var Muxer = class {
|
|
|
466
535
|
}
|
|
467
536
|
};
|
|
468
537
|
const port = {
|
|
469
|
-
send: async (data) => {
|
|
470
|
-
await this._sendData(channel, data);
|
|
538
|
+
send: async (data, timeout) => {
|
|
539
|
+
await this._sendData(channel, data, timeout);
|
|
471
540
|
},
|
|
472
541
|
subscribe: (cb) => {
|
|
473
|
-
(0,
|
|
542
|
+
(0, import_invariant3.invariant)(!callback, "Only one subscriber is allowed", {
|
|
474
543
|
F: __dxlog_file3,
|
|
475
|
-
L:
|
|
544
|
+
L: 214,
|
|
476
545
|
S: this,
|
|
477
546
|
A: [
|
|
478
547
|
"!callback",
|
|
@@ -500,61 +569,153 @@ var Muxer = class {
|
|
|
500
569
|
}
|
|
501
570
|
return port;
|
|
502
571
|
}
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
*/
|
|
506
|
-
async destroy(err) {
|
|
572
|
+
// initiate graceful close
|
|
573
|
+
async close(err) {
|
|
507
574
|
if (this._destroying) {
|
|
575
|
+
(0, import_log3.log)("already destroying, ignoring graceful close request", void 0, {
|
|
576
|
+
F: __dxlog_file3,
|
|
577
|
+
L: 247,
|
|
578
|
+
S: this,
|
|
579
|
+
C: (f, a) => f(...a)
|
|
580
|
+
});
|
|
508
581
|
return;
|
|
509
582
|
}
|
|
510
|
-
this.
|
|
511
|
-
|
|
512
|
-
|
|
583
|
+
if (this._closing) {
|
|
584
|
+
(0, import_log3.log)("already closing, ignoring graceful close request", void 0, {
|
|
585
|
+
F: __dxlog_file3,
|
|
586
|
+
L: 251,
|
|
587
|
+
S: this,
|
|
588
|
+
C: (f, a) => f(...a)
|
|
589
|
+
});
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
this._closing = true;
|
|
593
|
+
await this._sendCommand({
|
|
594
|
+
close: {
|
|
513
595
|
error: err?.message
|
|
514
596
|
}
|
|
515
|
-
}, SYSTEM_CHANNEL_ID).
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
597
|
+
}, SYSTEM_CHANNEL_ID, DESTROY_COMMAND_SEND_TIMEOUT).catch(async (err2) => {
|
|
598
|
+
(0, import_log3.log)("error sending close command", {
|
|
599
|
+
err: err2
|
|
600
|
+
}, {
|
|
601
|
+
F: __dxlog_file3,
|
|
602
|
+
L: 266,
|
|
603
|
+
S: this,
|
|
604
|
+
C: (f, a) => f(...a)
|
|
605
|
+
});
|
|
606
|
+
await this.dispose(err2);
|
|
519
607
|
});
|
|
608
|
+
await Promise.race([
|
|
609
|
+
new Promise((_resolve, reject) => {
|
|
610
|
+
setTimeout(() => {
|
|
611
|
+
reject(new import_protocols.TimeoutError("gracefully closing muxer"));
|
|
612
|
+
}, GRACEFUL_CLOSE_TIMEOUT);
|
|
613
|
+
}),
|
|
614
|
+
(async () => {
|
|
615
|
+
await this.dispose(err);
|
|
616
|
+
})()
|
|
617
|
+
]);
|
|
618
|
+
}
|
|
619
|
+
// force close without confirmation
|
|
620
|
+
async destroy(err) {
|
|
621
|
+
if (this._destroying) {
|
|
622
|
+
(0, import_log3.log)("already destroying, ignoring destroy request", void 0, {
|
|
623
|
+
F: __dxlog_file3,
|
|
624
|
+
L: 287,
|
|
625
|
+
S: this,
|
|
626
|
+
C: (f, a) => f(...a)
|
|
627
|
+
});
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
630
|
+
this._destroying = true;
|
|
520
631
|
void this._ctx.dispose();
|
|
632
|
+
if (this._closing) {
|
|
633
|
+
(0, import_log3.log)("destroy cancelling graceful close", void 0, {
|
|
634
|
+
F: __dxlog_file3,
|
|
635
|
+
L: 293,
|
|
636
|
+
S: this,
|
|
637
|
+
C: (f, a) => f(...a)
|
|
638
|
+
});
|
|
639
|
+
this._closing = false;
|
|
640
|
+
} else {
|
|
641
|
+
await this._sendCommand({
|
|
642
|
+
close: {
|
|
643
|
+
error: err?.message
|
|
644
|
+
}
|
|
645
|
+
}, SYSTEM_CHANNEL_ID).catch(async (err2) => {
|
|
646
|
+
(0, import_log3.log)("error sending courtesy close command", {
|
|
647
|
+
err: err2
|
|
648
|
+
}, {
|
|
649
|
+
F: __dxlog_file3,
|
|
650
|
+
L: 306,
|
|
651
|
+
S: this,
|
|
652
|
+
C: (f, a) => f(...a)
|
|
653
|
+
});
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
this.dispose(err).catch((err2) => {
|
|
657
|
+
(0, import_log3.log)("error disposing after destroy", {
|
|
658
|
+
err: err2
|
|
659
|
+
}, {
|
|
660
|
+
F: __dxlog_file3,
|
|
661
|
+
L: 311,
|
|
662
|
+
S: this,
|
|
663
|
+
C: (f, a) => f(...a)
|
|
664
|
+
});
|
|
665
|
+
});
|
|
521
666
|
}
|
|
522
|
-
|
|
523
|
-
|
|
667
|
+
// complete the termination, graceful or otherwise
|
|
668
|
+
async dispose(err) {
|
|
669
|
+
if (this._disposed) {
|
|
670
|
+
(0, import_log3.log)("already destroyed, ignoring dispose request", void 0, {
|
|
671
|
+
F: __dxlog_file3,
|
|
672
|
+
L: 319,
|
|
673
|
+
S: this,
|
|
674
|
+
C: (f, a) => f(...a)
|
|
675
|
+
});
|
|
524
676
|
return;
|
|
525
677
|
}
|
|
526
|
-
this.
|
|
527
|
-
this._balancer.destroy();
|
|
678
|
+
void this._ctx.dispose();
|
|
679
|
+
await this._balancer.destroy();
|
|
528
680
|
for (const channel of this._channelsByTag.values()) {
|
|
529
681
|
channel.destroy?.(err);
|
|
530
682
|
}
|
|
531
|
-
this.
|
|
683
|
+
this._disposed = true;
|
|
684
|
+
this.afterClosed.emit(err);
|
|
532
685
|
this._channelsByLocalId.clear();
|
|
533
686
|
this._channelsByTag.clear();
|
|
534
687
|
}
|
|
535
688
|
async _handleCommand(cmd) {
|
|
536
|
-
(
|
|
537
|
-
|
|
538
|
-
}, {
|
|
539
|
-
F: __dxlog_file3,
|
|
540
|
-
L: 286,
|
|
541
|
-
S: this,
|
|
542
|
-
C: (f, a) => f(...a)
|
|
543
|
-
});
|
|
544
|
-
if (this._destroyed || this._destroying) {
|
|
545
|
-
if (cmd.destroy) {
|
|
546
|
-
return;
|
|
547
|
-
}
|
|
548
|
-
import_log2.log.warn("Received command after destroy", {
|
|
689
|
+
if (this._disposed) {
|
|
690
|
+
import_log3.log.warn("Received command after destroy", {
|
|
549
691
|
cmd
|
|
550
692
|
}, {
|
|
551
693
|
F: __dxlog_file3,
|
|
552
|
-
L:
|
|
694
|
+
L: 341,
|
|
553
695
|
S: this,
|
|
554
696
|
C: (f, a) => f(...a)
|
|
555
697
|
});
|
|
556
698
|
return;
|
|
557
699
|
}
|
|
700
|
+
if (cmd.close) {
|
|
701
|
+
if (!this._closing) {
|
|
702
|
+
(0, import_log3.log)("received peer close, initiating my own graceful close", void 0, {
|
|
703
|
+
F: __dxlog_file3,
|
|
704
|
+
L: 347,
|
|
705
|
+
S: this,
|
|
706
|
+
C: (f, a) => f(...a)
|
|
707
|
+
});
|
|
708
|
+
await this.close();
|
|
709
|
+
} else {
|
|
710
|
+
(0, import_log3.log)("received close from peer, already closing", void 0, {
|
|
711
|
+
F: __dxlog_file3,
|
|
712
|
+
L: 350,
|
|
713
|
+
S: this,
|
|
714
|
+
C: (f, a) => f(...a)
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
return;
|
|
718
|
+
}
|
|
558
719
|
if (cmd.openChannel) {
|
|
559
720
|
const channel = this._getOrCreateStream({
|
|
560
721
|
tag: cmd.openChannel.tag,
|
|
@@ -573,31 +734,34 @@ var Muxer = class {
|
|
|
573
734
|
} else if (cmd.data) {
|
|
574
735
|
const stream = this._channelsByLocalId.get(cmd.data.channelId) ?? (0, import_debug.failUndefined)();
|
|
575
736
|
if (!stream.push) {
|
|
576
|
-
|
|
737
|
+
import_log3.log.warn("Received data for channel before it was opened", {
|
|
577
738
|
tag: stream.tag
|
|
578
739
|
}, {
|
|
579
740
|
F: __dxlog_file3,
|
|
580
|
-
L:
|
|
741
|
+
L: 379,
|
|
581
742
|
S: this,
|
|
582
743
|
C: (f, a) => f(...a)
|
|
583
744
|
});
|
|
584
745
|
return;
|
|
585
746
|
}
|
|
586
747
|
stream.push(cmd.data.data);
|
|
587
|
-
} else if (cmd.destroy) {
|
|
588
|
-
this._dispose();
|
|
589
748
|
}
|
|
590
749
|
}
|
|
591
|
-
async _sendCommand(cmd, channelId = -1) {
|
|
750
|
+
async _sendCommand(cmd, channelId = -1, timeout = DEFAULT_SEND_COMMAND_TIMEOUT) {
|
|
592
751
|
try {
|
|
593
752
|
const trigger = new import_async3.Trigger();
|
|
594
753
|
this._balancer.pushData(Command.encode(cmd), trigger, channelId);
|
|
595
|
-
await trigger.wait(
|
|
754
|
+
await trigger.wait({
|
|
755
|
+
timeout
|
|
756
|
+
});
|
|
596
757
|
} catch (err) {
|
|
597
758
|
await this.destroy(err);
|
|
598
759
|
}
|
|
599
760
|
}
|
|
600
761
|
_getOrCreateStream(params) {
|
|
762
|
+
if (this._channelsByTag.size === 0) {
|
|
763
|
+
(0, import_async3.scheduleTaskInterval)(this._ctx, async () => this._emitStats(), STATS_INTERVAL);
|
|
764
|
+
}
|
|
601
765
|
let channel = this._channelsByTag.get(params.tag);
|
|
602
766
|
if (!channel) {
|
|
603
767
|
channel = {
|
|
@@ -619,14 +783,14 @@ var Muxer = class {
|
|
|
619
783
|
}
|
|
620
784
|
return channel;
|
|
621
785
|
}
|
|
622
|
-
async _sendData(channel, data) {
|
|
786
|
+
async _sendData(channel, data, timeout) {
|
|
623
787
|
if (data.length > MAX_SAFE_FRAME_SIZE) {
|
|
624
|
-
|
|
788
|
+
import_log3.log.warn("frame size exceeds maximum safe value", {
|
|
625
789
|
size: data.length,
|
|
626
790
|
threshold: MAX_SAFE_FRAME_SIZE
|
|
627
791
|
}, {
|
|
628
792
|
F: __dxlog_file3,
|
|
629
|
-
L:
|
|
793
|
+
L: 425,
|
|
630
794
|
S: this,
|
|
631
795
|
C: (f, a) => f(...a)
|
|
632
796
|
});
|
|
@@ -641,7 +805,7 @@ var Muxer = class {
|
|
|
641
805
|
channelId: channel.remoteId,
|
|
642
806
|
data
|
|
643
807
|
}
|
|
644
|
-
}, channel.id);
|
|
808
|
+
}, channel.id, timeout);
|
|
645
809
|
}
|
|
646
810
|
_destroyChannel(channel, err) {
|
|
647
811
|
if (channel.destroy) {
|
|
@@ -651,7 +815,7 @@ var Muxer = class {
|
|
|
651
815
|
this._channelsByTag.delete(channel.tag);
|
|
652
816
|
}
|
|
653
817
|
async _emitStats() {
|
|
654
|
-
if (this.
|
|
818
|
+
if (this._disposed || this._destroying) {
|
|
655
819
|
this._lastStats = void 0;
|
|
656
820
|
this._lastChannelStats.clear();
|
|
657
821
|
return;
|
|
@@ -696,9 +860,9 @@ var Muxer = class {
|
|
|
696
860
|
var import_async4 = require("@dxos/async");
|
|
697
861
|
var import_context2 = require("@dxos/context");
|
|
698
862
|
var import_debug2 = require("@dxos/debug");
|
|
699
|
-
var
|
|
863
|
+
var import_invariant4 = require("@dxos/invariant");
|
|
700
864
|
var import_keys = require("@dxos/keys");
|
|
701
|
-
var
|
|
865
|
+
var import_log4 = require("@dxos/log");
|
|
702
866
|
var import_protocols2 = require("@dxos/protocols");
|
|
703
867
|
var import_rpc = require("@dxos/rpc");
|
|
704
868
|
var import_util = require("@dxos/util");
|
|
@@ -712,15 +876,17 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
712
876
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
713
877
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
714
878
|
}
|
|
715
|
-
var __dxlog_file4 = "/
|
|
879
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/teleport.ts";
|
|
880
|
+
var CONTROL_HEARTBEAT_INTERVAL = 1e4;
|
|
881
|
+
var CONTROL_HEARTBEAT_TIMEOUT = 6e4;
|
|
716
882
|
var Teleport = class {
|
|
717
883
|
constructor({ initiator, localPeerId, remotePeerId }) {
|
|
718
884
|
this._ctx = new import_context2.Context({
|
|
719
885
|
onError: (err) => {
|
|
720
886
|
void this.destroy(err).catch(() => {
|
|
721
|
-
|
|
887
|
+
import_log4.log.error("Error during destroy", err, {
|
|
722
888
|
F: __dxlog_file4,
|
|
723
|
-
L:
|
|
889
|
+
L: 47,
|
|
724
890
|
S: this,
|
|
725
891
|
C: (f, a) => f(...a)
|
|
726
892
|
});
|
|
@@ -729,21 +895,21 @@ var Teleport = class {
|
|
|
729
895
|
});
|
|
730
896
|
this._muxer = new Muxer();
|
|
731
897
|
this._control = new ControlExtension({
|
|
732
|
-
heartbeatInterval:
|
|
733
|
-
heartbeatTimeout:
|
|
898
|
+
heartbeatInterval: CONTROL_HEARTBEAT_INTERVAL,
|
|
899
|
+
heartbeatTimeout: CONTROL_HEARTBEAT_TIMEOUT,
|
|
734
900
|
onTimeout: () => {
|
|
735
901
|
if (this._destroying || this._aborting) {
|
|
736
902
|
return;
|
|
737
903
|
}
|
|
738
|
-
(0,
|
|
904
|
+
(0, import_log4.log)("abort teleport due to onTimeout in ControlExtension", void 0, {
|
|
739
905
|
F: __dxlog_file4,
|
|
740
|
-
L:
|
|
906
|
+
L: 62,
|
|
741
907
|
S: this,
|
|
742
908
|
C: (f, a) => f(...a)
|
|
743
909
|
});
|
|
744
|
-
this.
|
|
910
|
+
this.abort(new import_protocols2.TimeoutError("control extension")).catch((err) => import_log4.log.catch(err, void 0, {
|
|
745
911
|
F: __dxlog_file4,
|
|
746
|
-
L:
|
|
912
|
+
L: 63,
|
|
747
913
|
S: this,
|
|
748
914
|
C: (f, a) => f(...a)
|
|
749
915
|
}));
|
|
@@ -754,27 +920,27 @@ var Teleport = class {
|
|
|
754
920
|
this._open = false;
|
|
755
921
|
this._destroying = false;
|
|
756
922
|
this._aborting = false;
|
|
757
|
-
(0,
|
|
923
|
+
(0, import_invariant4.invariant)(typeof initiator === "boolean", void 0, {
|
|
758
924
|
F: __dxlog_file4,
|
|
759
|
-
L:
|
|
925
|
+
L: 75,
|
|
760
926
|
S: this,
|
|
761
927
|
A: [
|
|
762
928
|
"typeof initiator === 'boolean'",
|
|
763
929
|
""
|
|
764
930
|
]
|
|
765
931
|
});
|
|
766
|
-
(0,
|
|
932
|
+
(0, import_invariant4.invariant)(import_keys.PublicKey.isPublicKey(localPeerId), void 0, {
|
|
767
933
|
F: __dxlog_file4,
|
|
768
|
-
L:
|
|
934
|
+
L: 76,
|
|
769
935
|
S: this,
|
|
770
936
|
A: [
|
|
771
937
|
"PublicKey.isPublicKey(localPeerId)",
|
|
772
938
|
""
|
|
773
939
|
]
|
|
774
940
|
});
|
|
775
|
-
(0,
|
|
941
|
+
(0, import_invariant4.invariant)(import_keys.PublicKey.isPublicKey(remotePeerId), void 0, {
|
|
776
942
|
F: __dxlog_file4,
|
|
777
|
-
L:
|
|
943
|
+
L: 77,
|
|
778
944
|
S: this,
|
|
779
945
|
A: [
|
|
780
946
|
"PublicKey.isPublicKey(remotePeerId)",
|
|
@@ -785,17 +951,17 @@ var Teleport = class {
|
|
|
785
951
|
this.localPeerId = localPeerId;
|
|
786
952
|
this.remotePeerId = remotePeerId;
|
|
787
953
|
this._control.onExtensionRegistered.set(async (name) => {
|
|
788
|
-
(0,
|
|
954
|
+
(0, import_log4.log)("remote extension", {
|
|
789
955
|
name
|
|
790
956
|
}, {
|
|
791
957
|
F: __dxlog_file4,
|
|
792
|
-
L:
|
|
958
|
+
L: 83,
|
|
793
959
|
S: this,
|
|
794
960
|
C: (f, a) => f(...a)
|
|
795
961
|
});
|
|
796
|
-
(0,
|
|
962
|
+
(0, import_invariant4.invariant)(!this._remoteExtensions.has(name), "Remote extension already exists", {
|
|
797
963
|
F: __dxlog_file4,
|
|
798
|
-
L:
|
|
964
|
+
L: 84,
|
|
799
965
|
S: this,
|
|
800
966
|
A: [
|
|
801
967
|
"!this._remoteExtensions.has(name)",
|
|
@@ -814,9 +980,9 @@ var Teleport = class {
|
|
|
814
980
|
{
|
|
815
981
|
this._muxer.stream.on("close", async () => {
|
|
816
982
|
if (this._destroying || this._aborting) {
|
|
817
|
-
(0,
|
|
983
|
+
(0, import_log4.log)("destroy teleport due to muxer stream close, skipping due to already destroying/aborting", void 0, {
|
|
818
984
|
F: __dxlog_file4,
|
|
819
|
-
L:
|
|
985
|
+
L: 100,
|
|
820
986
|
S: this,
|
|
821
987
|
C: (f, a) => f(...a)
|
|
822
988
|
});
|
|
@@ -829,7 +995,7 @@ var Teleport = class {
|
|
|
829
995
|
});
|
|
830
996
|
}
|
|
831
997
|
this._muxer.statsUpdated.on((stats) => {
|
|
832
|
-
|
|
998
|
+
import_log4.log.trace("dxos.mesh.teleport.stats", {
|
|
833
999
|
localPeerId,
|
|
834
1000
|
remotePeerId,
|
|
835
1001
|
bytesSent: stats.bytesSent,
|
|
@@ -839,7 +1005,7 @@ var Teleport = class {
|
|
|
839
1005
|
channels: stats.channels
|
|
840
1006
|
}, {
|
|
841
1007
|
F: __dxlog_file4,
|
|
842
|
-
L:
|
|
1008
|
+
L: 113,
|
|
843
1009
|
S: this,
|
|
844
1010
|
C: (f, a) => f(...a)
|
|
845
1011
|
});
|
|
@@ -875,9 +1041,9 @@ var Teleport = class {
|
|
|
875
1041
|
try {
|
|
876
1042
|
await extension.onAbort(err);
|
|
877
1043
|
} catch (err2) {
|
|
878
|
-
|
|
1044
|
+
import_log4.log.catch(err2, void 0, {
|
|
879
1045
|
F: __dxlog_file4,
|
|
880
|
-
L:
|
|
1046
|
+
L: 166,
|
|
881
1047
|
S: this,
|
|
882
1048
|
C: (f, a) => f(...a)
|
|
883
1049
|
});
|
|
@@ -898,25 +1064,25 @@ var Teleport = class {
|
|
|
898
1064
|
try {
|
|
899
1065
|
await extension.onClose(err);
|
|
900
1066
|
} catch (err2) {
|
|
901
|
-
|
|
1067
|
+
import_log4.log.catch(err2, void 0, {
|
|
902
1068
|
F: __dxlog_file4,
|
|
903
|
-
L:
|
|
1069
|
+
L: 190,
|
|
904
1070
|
S: this,
|
|
905
1071
|
C: (f, a) => f(...a)
|
|
906
1072
|
});
|
|
907
1073
|
}
|
|
908
1074
|
}
|
|
909
|
-
await this._muxer.
|
|
1075
|
+
await this._muxer.close();
|
|
910
1076
|
}
|
|
911
1077
|
addExtension(name, extension) {
|
|
912
1078
|
if (!this._open) {
|
|
913
1079
|
throw new Error("Not open");
|
|
914
1080
|
}
|
|
915
|
-
(0,
|
|
1081
|
+
(0, import_log4.log)("addExtension", {
|
|
916
1082
|
name
|
|
917
1083
|
}, {
|
|
918
1084
|
F: __dxlog_file4,
|
|
919
|
-
L:
|
|
1085
|
+
L: 202,
|
|
920
1086
|
S: this,
|
|
921
1087
|
C: (f, a) => f(...a)
|
|
922
1088
|
});
|
|
@@ -938,18 +1104,18 @@ var Teleport = class {
|
|
|
938
1104
|
}
|
|
939
1105
|
}
|
|
940
1106
|
_setExtension(extensionName, extension) {
|
|
941
|
-
(0,
|
|
1107
|
+
(0, import_invariant4.invariant)(!extensionName.includes("/"), "Invalid extension name", {
|
|
942
1108
|
F: __dxlog_file4,
|
|
943
|
-
L:
|
|
1109
|
+
L: 226,
|
|
944
1110
|
S: this,
|
|
945
1111
|
A: [
|
|
946
1112
|
"!extensionName.includes('/')",
|
|
947
1113
|
"'Invalid extension name'"
|
|
948
1114
|
]
|
|
949
1115
|
});
|
|
950
|
-
(0,
|
|
1116
|
+
(0, import_invariant4.invariant)(!this._extensions.has(extensionName), "Extension already exists", {
|
|
951
1117
|
F: __dxlog_file4,
|
|
952
|
-
L:
|
|
1118
|
+
L: 227,
|
|
953
1119
|
S: this,
|
|
954
1120
|
A: [
|
|
955
1121
|
"!this._extensions.has(extensionName)",
|
|
@@ -959,11 +1125,11 @@ var Teleport = class {
|
|
|
959
1125
|
this._extensions.set(extensionName, extension);
|
|
960
1126
|
}
|
|
961
1127
|
async _openExtension(extensionName) {
|
|
962
|
-
(0,
|
|
1128
|
+
(0, import_log4.log)("open extension", {
|
|
963
1129
|
extensionName
|
|
964
1130
|
}, {
|
|
965
1131
|
F: __dxlog_file4,
|
|
966
|
-
L:
|
|
1132
|
+
L: 232,
|
|
967
1133
|
S: this,
|
|
968
1134
|
C: (f, a) => f(...a)
|
|
969
1135
|
});
|
|
@@ -973,9 +1139,9 @@ var Teleport = class {
|
|
|
973
1139
|
localPeerId: this.localPeerId,
|
|
974
1140
|
remotePeerId: this.remotePeerId,
|
|
975
1141
|
createPort: async (channelName, opts) => {
|
|
976
|
-
(0,
|
|
1142
|
+
(0, import_invariant4.invariant)(!channelName.includes("/"), "Invalid channel name", {
|
|
977
1143
|
F: __dxlog_file4,
|
|
978
|
-
L:
|
|
1144
|
+
L: 240,
|
|
979
1145
|
S: this,
|
|
980
1146
|
A: [
|
|
981
1147
|
"!channelName.includes('/')",
|
|
@@ -985,9 +1151,9 @@ var Teleport = class {
|
|
|
985
1151
|
return this._muxer.createPort(`${extensionName}/${channelName}`, opts);
|
|
986
1152
|
},
|
|
987
1153
|
createStream: async (channelName, opts) => {
|
|
988
|
-
(0,
|
|
1154
|
+
(0, import_invariant4.invariant)(!channelName.includes("/"), "Invalid channel name", {
|
|
989
1155
|
F: __dxlog_file4,
|
|
990
|
-
L:
|
|
1156
|
+
L: 244,
|
|
991
1157
|
S: this,
|
|
992
1158
|
A: [
|
|
993
1159
|
"!channelName.includes('/')",
|
|
@@ -1003,11 +1169,11 @@ var Teleport = class {
|
|
|
1003
1169
|
}
|
|
1004
1170
|
};
|
|
1005
1171
|
await extension.onOpen(context);
|
|
1006
|
-
(0,
|
|
1172
|
+
(0, import_log4.log)("extension opened", {
|
|
1007
1173
|
extensionName
|
|
1008
1174
|
}, {
|
|
1009
1175
|
F: __dxlog_file4,
|
|
1010
|
-
L:
|
|
1176
|
+
L: 255,
|
|
1011
1177
|
S: this,
|
|
1012
1178
|
C: (f, a) => f(...a)
|
|
1013
1179
|
});
|
|
@@ -1077,10 +1243,10 @@ var ControlExtension = class {
|
|
|
1077
1243
|
|
|
1078
1244
|
// packages/core/mesh/teleport/src/testing/test-builder.ts
|
|
1079
1245
|
var import_node_stream3 = require("node:stream");
|
|
1080
|
-
var
|
|
1246
|
+
var import_invariant5 = require("@dxos/invariant");
|
|
1081
1247
|
var import_keys2 = require("@dxos/keys");
|
|
1082
|
-
var
|
|
1083
|
-
var __dxlog_file5 = "/
|
|
1248
|
+
var import_log5 = require("@dxos/log");
|
|
1249
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/testing/test-builder.ts";
|
|
1084
1250
|
var TestBuilder = class {
|
|
1085
1251
|
constructor() {
|
|
1086
1252
|
this._peers = /* @__PURE__ */ new Set();
|
|
@@ -1099,7 +1265,7 @@ var TestBuilder = class {
|
|
|
1099
1265
|
await Promise.all(Array.from(this._peers).map((agent) => agent.destroy()));
|
|
1100
1266
|
}
|
|
1101
1267
|
async connect(peer1, peer2) {
|
|
1102
|
-
(0,
|
|
1268
|
+
(0, import_invariant5.invariant)(peer1 !== peer2, void 0, {
|
|
1103
1269
|
F: __dxlog_file5,
|
|
1104
1270
|
L: 37,
|
|
1105
1271
|
S: this,
|
|
@@ -1108,7 +1274,7 @@ var TestBuilder = class {
|
|
|
1108
1274
|
""
|
|
1109
1275
|
]
|
|
1110
1276
|
});
|
|
1111
|
-
(0,
|
|
1277
|
+
(0, import_invariant5.invariant)(this._peers.has(peer1), void 0, {
|
|
1112
1278
|
F: __dxlog_file5,
|
|
1113
1279
|
L: 38,
|
|
1114
1280
|
S: this,
|
|
@@ -1117,7 +1283,7 @@ var TestBuilder = class {
|
|
|
1117
1283
|
""
|
|
1118
1284
|
]
|
|
1119
1285
|
});
|
|
1120
|
-
(0,
|
|
1286
|
+
(0, import_invariant5.invariant)(this._peers.has(peer1), void 0, {
|
|
1121
1287
|
F: __dxlog_file5,
|
|
1122
1288
|
L: 39,
|
|
1123
1289
|
S: this,
|
|
@@ -1145,7 +1311,7 @@ var TestBuilder = class {
|
|
|
1145
1311
|
];
|
|
1146
1312
|
}
|
|
1147
1313
|
async disconnect(peer1, peer2) {
|
|
1148
|
-
(0,
|
|
1314
|
+
(0, import_invariant5.invariant)(peer1 !== peer2, void 0, {
|
|
1149
1315
|
F: __dxlog_file5,
|
|
1150
1316
|
L: 51,
|
|
1151
1317
|
S: this,
|
|
@@ -1154,7 +1320,7 @@ var TestBuilder = class {
|
|
|
1154
1320
|
""
|
|
1155
1321
|
]
|
|
1156
1322
|
});
|
|
1157
|
-
(0,
|
|
1323
|
+
(0, import_invariant5.invariant)(this._peers.has(peer1), void 0, {
|
|
1158
1324
|
F: __dxlog_file5,
|
|
1159
1325
|
L: 52,
|
|
1160
1326
|
S: this,
|
|
@@ -1163,7 +1329,7 @@ var TestBuilder = class {
|
|
|
1163
1329
|
""
|
|
1164
1330
|
]
|
|
1165
1331
|
});
|
|
1166
|
-
(0,
|
|
1332
|
+
(0, import_invariant5.invariant)(this._peers.has(peer1), void 0, {
|
|
1167
1333
|
F: __dxlog_file5,
|
|
1168
1334
|
L: 53,
|
|
1169
1335
|
S: this,
|
|
@@ -1174,7 +1340,7 @@ var TestBuilder = class {
|
|
|
1174
1340
|
});
|
|
1175
1341
|
const connection1 = Array.from(peer1.connections).find((connection) => connection.remotePeerId.equals(peer2.peerId));
|
|
1176
1342
|
const connection2 = Array.from(peer2.connections).find((connection) => connection.remotePeerId.equals(peer1.peerId));
|
|
1177
|
-
(0,
|
|
1343
|
+
(0, import_invariant5.invariant)(connection1, void 0, {
|
|
1178
1344
|
F: __dxlog_file5,
|
|
1179
1345
|
L: 62,
|
|
1180
1346
|
S: this,
|
|
@@ -1183,7 +1349,7 @@ var TestBuilder = class {
|
|
|
1183
1349
|
""
|
|
1184
1350
|
]
|
|
1185
1351
|
});
|
|
1186
|
-
(0,
|
|
1352
|
+
(0, import_invariant5.invariant)(connection2, void 0, {
|
|
1187
1353
|
F: __dxlog_file5,
|
|
1188
1354
|
L: 63,
|
|
1189
1355
|
S: this,
|
|
@@ -1213,7 +1379,7 @@ var TestPeer = class {
|
|
|
1213
1379
|
return connection;
|
|
1214
1380
|
}
|
|
1215
1381
|
async openConnection(connection) {
|
|
1216
|
-
(0,
|
|
1382
|
+
(0, import_invariant5.invariant)(this.connections.has(connection), void 0, {
|
|
1217
1383
|
F: __dxlog_file5,
|
|
1218
1384
|
L: 84,
|
|
1219
1385
|
S: this,
|
|
@@ -1226,7 +1392,7 @@ var TestPeer = class {
|
|
|
1226
1392
|
await this.onOpen(connection);
|
|
1227
1393
|
}
|
|
1228
1394
|
async closeConnection(connection) {
|
|
1229
|
-
(0,
|
|
1395
|
+
(0, import_invariant5.invariant)(this.connections.has(connection), void 0, {
|
|
1230
1396
|
F: __dxlog_file5,
|
|
1231
1397
|
L: 90,
|
|
1232
1398
|
S: this,
|
|
@@ -1248,7 +1414,7 @@ var TestPeer = class {
|
|
|
1248
1414
|
var pipeStreams = (stream1, stream2) => {
|
|
1249
1415
|
(0, import_node_stream3.pipeline)(stream1, stream2, (err) => {
|
|
1250
1416
|
if (err && err.code !== "ERR_STREAM_PREMATURE_CLOSE") {
|
|
1251
|
-
|
|
1417
|
+
import_log5.log.catch(err, void 0, {
|
|
1252
1418
|
F: __dxlog_file5,
|
|
1253
1419
|
L: 106,
|
|
1254
1420
|
S: void 0,
|
|
@@ -1258,7 +1424,7 @@ var pipeStreams = (stream1, stream2) => {
|
|
|
1258
1424
|
});
|
|
1259
1425
|
(0, import_node_stream3.pipeline)(stream2, stream1, (err) => {
|
|
1260
1426
|
if (err && err.code !== "ERR_STREAM_PREMATURE_CLOSE") {
|
|
1261
|
-
|
|
1427
|
+
import_log5.log.catch(err, void 0, {
|
|
1262
1428
|
F: __dxlog_file5,
|
|
1263
1429
|
L: 111,
|
|
1264
1430
|
S: void 0,
|
|
@@ -1282,11 +1448,11 @@ var TestConnection = class {
|
|
|
1282
1448
|
|
|
1283
1449
|
// packages/core/mesh/teleport/src/testing/test-extension.ts
|
|
1284
1450
|
var import_async5 = require("@dxos/async");
|
|
1285
|
-
var
|
|
1286
|
-
var
|
|
1451
|
+
var import_invariant6 = require("@dxos/invariant");
|
|
1452
|
+
var import_log6 = require("@dxos/log");
|
|
1287
1453
|
var import_protocols3 = require("@dxos/protocols");
|
|
1288
1454
|
var import_rpc2 = require("@dxos/rpc");
|
|
1289
|
-
var __dxlog_file6 = "/
|
|
1455
|
+
var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/testing/test-extension.ts";
|
|
1290
1456
|
var TestExtension = class {
|
|
1291
1457
|
constructor(callbacks = {}) {
|
|
1292
1458
|
this.callbacks = callbacks;
|
|
@@ -1298,7 +1464,7 @@ var TestExtension = class {
|
|
|
1298
1464
|
return this.extensionContext?.remotePeerId;
|
|
1299
1465
|
}
|
|
1300
1466
|
async onOpen(context) {
|
|
1301
|
-
(0,
|
|
1467
|
+
(0, import_log6.log)("onOpen", {
|
|
1302
1468
|
localPeerId: context.localPeerId,
|
|
1303
1469
|
remotePeerId: context.remotePeerId
|
|
1304
1470
|
}, {
|
|
@@ -1336,7 +1502,7 @@ var TestExtension = class {
|
|
|
1336
1502
|
this.open.wake();
|
|
1337
1503
|
}
|
|
1338
1504
|
async onClose(err) {
|
|
1339
|
-
(0,
|
|
1505
|
+
(0, import_log6.log)("onClose", {
|
|
1340
1506
|
err
|
|
1341
1507
|
}, {
|
|
1342
1508
|
F: __dxlog_file6,
|
|
@@ -1349,7 +1515,7 @@ var TestExtension = class {
|
|
|
1349
1515
|
await this._rpc?.close();
|
|
1350
1516
|
}
|
|
1351
1517
|
async onAbort(err) {
|
|
1352
|
-
(0,
|
|
1518
|
+
(0, import_log6.log)("onAbort", {
|
|
1353
1519
|
err
|
|
1354
1520
|
}, {
|
|
1355
1521
|
F: __dxlog_file6,
|
|
@@ -1368,7 +1534,7 @@ var TestExtension = class {
|
|
|
1368
1534
|
const res = await (0, import_async5.asyncTimeout)(this._rpc.rpc.TestService.testCall({
|
|
1369
1535
|
data: message
|
|
1370
1536
|
}), 1500);
|
|
1371
|
-
(0,
|
|
1537
|
+
(0, import_invariant6.invariant)(res.data === message, void 0, {
|
|
1372
1538
|
F: __dxlog_file6,
|
|
1373
1539
|
L: 84,
|
|
1374
1540
|
S: this,
|
|
@@ -1389,11 +1555,11 @@ var TestExtension = class {
|
|
|
1389
1555
|
// packages/core/mesh/teleport/src/testing/test-extension-with-streams.ts
|
|
1390
1556
|
var import_node_crypto = require("node:crypto");
|
|
1391
1557
|
var import_async6 = require("@dxos/async");
|
|
1392
|
-
var
|
|
1393
|
-
var
|
|
1558
|
+
var import_invariant7 = require("@dxos/invariant");
|
|
1559
|
+
var import_log7 = require("@dxos/log");
|
|
1394
1560
|
var import_protocols4 = require("@dxos/protocols");
|
|
1395
1561
|
var import_rpc3 = require("@dxos/rpc");
|
|
1396
|
-
var __dxlog_file7 = "/
|
|
1562
|
+
var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/testing/test-extension-with-streams.ts";
|
|
1397
1563
|
var TestExtensionWithStreams = class {
|
|
1398
1564
|
constructor(callbacks = {}) {
|
|
1399
1565
|
this.callbacks = callbacks;
|
|
@@ -1406,7 +1572,7 @@ var TestExtensionWithStreams = class {
|
|
|
1406
1572
|
return this.extensionContext?.remotePeerId;
|
|
1407
1573
|
}
|
|
1408
1574
|
async _openStream(streamTag, interval = 5, chunkSize = 2048) {
|
|
1409
|
-
(0,
|
|
1575
|
+
(0, import_invariant7.invariant)(!this._streams.has(streamTag), `Stream already exists: ${streamTag}`, {
|
|
1410
1576
|
F: __dxlog_file7,
|
|
1411
1577
|
L: 39,
|
|
1412
1578
|
S: this,
|
|
@@ -1455,7 +1621,7 @@ var TestExtensionWithStreams = class {
|
|
|
1455
1621
|
});
|
|
1456
1622
|
streamEntry.reportingTimer = setInterval(() => {
|
|
1457
1623
|
const { bytesSent, bytesReceived, sendErrors, receiveErrors } = streamEntry;
|
|
1458
|
-
|
|
1624
|
+
import_log7.log.trace("dxos.test.stream-stats", {
|
|
1459
1625
|
streamTag,
|
|
1460
1626
|
bytesSent,
|
|
1461
1627
|
bytesReceived,
|
|
@@ -1472,7 +1638,7 @@ var TestExtensionWithStreams = class {
|
|
|
1472
1638
|
}, 100);
|
|
1473
1639
|
}
|
|
1474
1640
|
_closeStream(streamTag) {
|
|
1475
|
-
(0,
|
|
1641
|
+
(0, import_invariant7.invariant)(this._streams.has(streamTag), `Stream does not exist: ${streamTag}`, {
|
|
1476
1642
|
F: __dxlog_file7,
|
|
1477
1643
|
L: 106,
|
|
1478
1644
|
S: this,
|
|
@@ -1496,7 +1662,7 @@ var TestExtensionWithStreams = class {
|
|
|
1496
1662
|
};
|
|
1497
1663
|
}
|
|
1498
1664
|
async onOpen(context) {
|
|
1499
|
-
(0,
|
|
1665
|
+
(0, import_log7.log)("onOpen", {
|
|
1500
1666
|
localPeerId: context.localPeerId,
|
|
1501
1667
|
remotePeerId: context.remotePeerId
|
|
1502
1668
|
}, {
|
|
@@ -1546,7 +1712,7 @@ var TestExtensionWithStreams = class {
|
|
|
1546
1712
|
this.open.wake();
|
|
1547
1713
|
}
|
|
1548
1714
|
async onClose(err) {
|
|
1549
|
-
(0,
|
|
1715
|
+
(0, import_log7.log)("onClose", {
|
|
1550
1716
|
err
|
|
1551
1717
|
}, {
|
|
1552
1718
|
F: __dxlog_file7,
|
|
@@ -1557,7 +1723,7 @@ var TestExtensionWithStreams = class {
|
|
|
1557
1723
|
await this.callbacks.onClose?.();
|
|
1558
1724
|
this.closed.wake();
|
|
1559
1725
|
for (const [streamTag, stream] of Object.entries(this._streams)) {
|
|
1560
|
-
(0,
|
|
1726
|
+
(0, import_log7.log)("closing stream", {
|
|
1561
1727
|
streamTag
|
|
1562
1728
|
}, {
|
|
1563
1729
|
F: __dxlog_file7,
|
|
@@ -1571,7 +1737,7 @@ var TestExtensionWithStreams = class {
|
|
|
1571
1737
|
await this._rpc?.close();
|
|
1572
1738
|
}
|
|
1573
1739
|
async onAbort(err) {
|
|
1574
|
-
(0,
|
|
1740
|
+
(0, import_log7.log)("onAbort", {
|
|
1575
1741
|
err
|
|
1576
1742
|
}, {
|
|
1577
1743
|
F: __dxlog_file7,
|
|
@@ -1595,7 +1761,7 @@ var TestExtensionWithStreams = class {
|
|
|
1595
1761
|
streamLoadInterval,
|
|
1596
1762
|
streamLoadChunkSize
|
|
1597
1763
|
});
|
|
1598
|
-
(0,
|
|
1764
|
+
(0, import_invariant7.invariant)(data === streamTag, void 0, {
|
|
1599
1765
|
F: __dxlog_file7,
|
|
1600
1766
|
L: 207,
|
|
1601
1767
|
S: this,
|
|
@@ -1614,7 +1780,7 @@ var TestExtensionWithStreams = class {
|
|
|
1614
1780
|
const { data, bytesSent, bytesReceived, sendErrors, receiveErrors, runningTime } = await this._rpc.rpc.TestServiceWithStreams.closeTestStream({
|
|
1615
1781
|
data: streamTag
|
|
1616
1782
|
});
|
|
1617
|
-
(0,
|
|
1783
|
+
(0, import_invariant7.invariant)(data === streamTag, void 0, {
|
|
1618
1784
|
F: __dxlog_file7,
|
|
1619
1785
|
L: 220,
|
|
1620
1786
|
S: this,
|
|
@@ -1647,9 +1813,9 @@ var TestExtensionWithStreams = class {
|
|
|
1647
1813
|
};
|
|
1648
1814
|
|
|
1649
1815
|
// packages/core/mesh/teleport/src/rpc-extension.ts
|
|
1650
|
-
var
|
|
1816
|
+
var import_invariant8 = require("@dxos/invariant");
|
|
1651
1817
|
var import_rpc4 = require("@dxos/rpc");
|
|
1652
|
-
var __dxlog_file8 = "/
|
|
1818
|
+
var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/rpc-extension.ts";
|
|
1653
1819
|
var RpcExtension = class {
|
|
1654
1820
|
constructor(_rpcParams) {
|
|
1655
1821
|
this._rpcParams = _rpcParams;
|
|
@@ -1665,7 +1831,7 @@ var RpcExtension = class {
|
|
|
1665
1831
|
return this._extensionContext.remotePeerId;
|
|
1666
1832
|
}
|
|
1667
1833
|
get rpc() {
|
|
1668
|
-
(0,
|
|
1834
|
+
(0, import_invariant8.invariant)(this._rpc, void 0, {
|
|
1669
1835
|
F: __dxlog_file8,
|
|
1670
1836
|
L: 32,
|
|
1671
1837
|
S: this,
|