@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
|
@@ -2,18 +2,18 @@ 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
|
-
import { log as
|
|
7
|
+
import { log as log5 } from "@dxos/log";
|
|
8
8
|
|
|
9
9
|
// packages/core/mesh/teleport/src/teleport.ts
|
|
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
|
-
import { log as
|
|
16
|
-
import { schema as schema2, RpcClosedError, TimeoutError } from "@dxos/protocols";
|
|
15
|
+
import { log as log4 } from "@dxos/log";
|
|
16
|
+
import { schema as schema2, RpcClosedError, TimeoutError as TimeoutError2 } from "@dxos/protocols";
|
|
17
17
|
import { createProtoRpcPeer } from "@dxos/rpc";
|
|
18
18
|
import { Callback } from "@dxos/util";
|
|
19
19
|
|
|
@@ -21,7 +21,8 @@ import { Callback } from "@dxos/util";
|
|
|
21
21
|
import { Duplex } from "@dxos/node-std/stream";
|
|
22
22
|
import { Event } from "@dxos/async";
|
|
23
23
|
import { invariant } from "@dxos/invariant";
|
|
24
|
-
|
|
24
|
+
import { log } from "@dxos/log";
|
|
25
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/muxing/framer.ts";
|
|
25
26
|
var FRAME_LENGTH_SIZE = 2;
|
|
26
27
|
var Framer = class {
|
|
27
28
|
constructor() {
|
|
@@ -43,7 +44,7 @@ var Framer = class {
|
|
|
43
44
|
write: (chunk, encoding, callback) => {
|
|
44
45
|
invariant(!this._subscribeCb, "Internal Framer bug. Concurrent writes detected.", {
|
|
45
46
|
F: __dxlog_file,
|
|
46
|
-
L:
|
|
47
|
+
L: 40,
|
|
47
48
|
S: this,
|
|
48
49
|
A: [
|
|
49
50
|
"!this._subscribeCb",
|
|
@@ -87,7 +88,7 @@ var Framer = class {
|
|
|
87
88
|
subscribe: (callback) => {
|
|
88
89
|
invariant(!this._messageCb, "Rpc port already has a message listener.", {
|
|
89
90
|
F: __dxlog_file,
|
|
90
|
-
L:
|
|
91
|
+
L: 79,
|
|
91
92
|
S: this,
|
|
92
93
|
A: [
|
|
93
94
|
"!this._messageCb",
|
|
@@ -141,6 +142,22 @@ var Framer = class {
|
|
|
141
142
|
}
|
|
142
143
|
}
|
|
143
144
|
destroy() {
|
|
145
|
+
if (this._stream.readableLength > 0) {
|
|
146
|
+
log.warn("framer destroyed while there are still read bytes in the buffer.", void 0, {
|
|
147
|
+
F: __dxlog_file,
|
|
148
|
+
L: 140,
|
|
149
|
+
S: this,
|
|
150
|
+
C: (f, a) => f(...a)
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
if (this._stream.writableLength > 0) {
|
|
154
|
+
log.warn("framer destroyed while there are still write bytes in the buffer.", void 0, {
|
|
155
|
+
F: __dxlog_file,
|
|
156
|
+
L: 143,
|
|
157
|
+
S: this,
|
|
158
|
+
C: (f, a) => f(...a)
|
|
159
|
+
});
|
|
160
|
+
}
|
|
144
161
|
this._stream.destroy();
|
|
145
162
|
}
|
|
146
163
|
};
|
|
@@ -171,15 +188,16 @@ import { Duplex as Duplex2 } from "@dxos/node-std/stream";
|
|
|
171
188
|
import { scheduleTaskInterval, Event as Event3, Trigger } from "@dxos/async";
|
|
172
189
|
import { Context } from "@dxos/context";
|
|
173
190
|
import { failUndefined } from "@dxos/debug";
|
|
174
|
-
import { invariant as
|
|
175
|
-
import { log as
|
|
176
|
-
import { schema } from "@dxos/protocols";
|
|
191
|
+
import { invariant as invariant3 } from "@dxos/invariant";
|
|
192
|
+
import { log as log3 } from "@dxos/log";
|
|
193
|
+
import { schema, TimeoutError } from "@dxos/protocols";
|
|
177
194
|
|
|
178
195
|
// packages/core/mesh/teleport/src/muxing/balancer.ts
|
|
179
196
|
import * as varint from "varint";
|
|
180
197
|
import { Event as Event2 } from "@dxos/async";
|
|
181
|
-
import {
|
|
182
|
-
|
|
198
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
199
|
+
import { log as log2 } from "@dxos/log";
|
|
200
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/muxing/balancer.ts";
|
|
183
201
|
var MAX_CHUNK_SIZE = 8192;
|
|
184
202
|
var Balancer = class {
|
|
185
203
|
constructor(_sysChannelId) {
|
|
@@ -189,6 +207,7 @@ var Balancer = class {
|
|
|
189
207
|
this._framer = new Framer();
|
|
190
208
|
this._sendBuffers = /* @__PURE__ */ new Map();
|
|
191
209
|
this._receiveBuffers = /* @__PURE__ */ new Map();
|
|
210
|
+
this._sending = false;
|
|
192
211
|
this.incomingData = new Event2();
|
|
193
212
|
this.stream = this._framer.stream;
|
|
194
213
|
this._channels.push(_sysChannelId);
|
|
@@ -207,39 +226,23 @@ var Balancer = class {
|
|
|
207
226
|
this._channels.push(channel);
|
|
208
227
|
}
|
|
209
228
|
pushData(data, trigger, channelId) {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
}
|
|
222
|
-
chunks.forEach((chunk, index) => {
|
|
223
|
-
const msg = encodeChunk({
|
|
224
|
-
chunk,
|
|
225
|
-
channelId,
|
|
226
|
-
dataLength: index === 0 ? data.length : void 0
|
|
227
|
-
});
|
|
228
|
-
sendBuffer.push({
|
|
229
|
-
msg,
|
|
230
|
-
trigger: index === chunks.length - 1 ? trigger : void 0
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
if (noCalls) {
|
|
234
|
-
this._sendChunk().catch((err) => log.catch(err, void 0, {
|
|
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
|
+
}));
|
|
236
|
+
}
|
|
237
|
+
destroy() {
|
|
238
|
+
if (this._sendBuffers.size !== 0) {
|
|
239
|
+
log2.warn("destroying balancer with pending calls", void 0, {
|
|
235
240
|
F: __dxlog_file2,
|
|
236
|
-
L:
|
|
241
|
+
L: 80,
|
|
237
242
|
S: this,
|
|
238
243
|
C: (f, a) => f(...a)
|
|
239
|
-
})
|
|
244
|
+
});
|
|
240
245
|
}
|
|
241
|
-
}
|
|
242
|
-
destroy() {
|
|
243
246
|
this._sendBuffers.clear();
|
|
244
247
|
this._framer.destroy();
|
|
245
248
|
}
|
|
@@ -276,36 +279,99 @@ var Balancer = class {
|
|
|
276
279
|
this._lastCallerIndex = (this._lastCallerIndex + 1) % this._channels.length;
|
|
277
280
|
return this._channels[index];
|
|
278
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
|
|
279
307
|
_getNextChunk() {
|
|
280
308
|
let chunk;
|
|
281
|
-
while (
|
|
309
|
+
while (this._sendBuffers.size > 0) {
|
|
282
310
|
const channelId = this._getNextCallerId();
|
|
283
311
|
const sendBuffer = this._sendBuffers.get(channelId);
|
|
284
312
|
if (!sendBuffer) {
|
|
285
313
|
continue;
|
|
286
314
|
}
|
|
287
315
|
chunk = sendBuffer.shift();
|
|
316
|
+
if (!chunk) {
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
288
319
|
if (sendBuffer.length === 0) {
|
|
289
320
|
this._sendBuffers.delete(channelId);
|
|
290
321
|
}
|
|
322
|
+
return chunk;
|
|
291
323
|
}
|
|
292
|
-
return
|
|
324
|
+
return null;
|
|
293
325
|
}
|
|
294
|
-
async
|
|
295
|
-
if (this.
|
|
326
|
+
async _sendChunks() {
|
|
327
|
+
if (this._sending) {
|
|
296
328
|
return;
|
|
297
329
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
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();
|
|
307
364
|
}
|
|
308
|
-
|
|
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;
|
|
309
375
|
}
|
|
310
376
|
};
|
|
311
377
|
var encodeChunk = ({ channelId, dataLength, chunk }) => {
|
|
@@ -336,11 +402,14 @@ var decodeChunk = (data, withLength) => {
|
|
|
336
402
|
};
|
|
337
403
|
|
|
338
404
|
// packages/core/mesh/teleport/src/muxing/muxer.ts
|
|
339
|
-
var __dxlog_file3 = "/
|
|
405
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/muxing/muxer.ts";
|
|
340
406
|
var Command = schema.getCodecForType("dxos.mesh.muxer.Command");
|
|
407
|
+
var DEFAULT_SEND_COMMAND_TIMEOUT = 6e4;
|
|
408
|
+
var DESTROY_COMMAND_SEND_TIMEOUT = 5e3;
|
|
341
409
|
var STATS_INTERVAL = 1e3;
|
|
342
410
|
var MAX_SAFE_FRAME_SIZE = 1e6;
|
|
343
411
|
var SYSTEM_CHANNEL_ID = 0;
|
|
412
|
+
var GRACEFUL_CLOSE_TIMEOUT = 3e3;
|
|
344
413
|
var Muxer = class {
|
|
345
414
|
constructor() {
|
|
346
415
|
this._balancer = new Balancer(SYSTEM_CHANNEL_ID);
|
|
@@ -348,17 +417,17 @@ var Muxer = class {
|
|
|
348
417
|
this._channelsByTag = /* @__PURE__ */ new Map();
|
|
349
418
|
this._ctx = new Context();
|
|
350
419
|
this._nextId = 1;
|
|
351
|
-
this.
|
|
420
|
+
this._closing = false;
|
|
352
421
|
this._destroying = false;
|
|
422
|
+
this._disposed = false;
|
|
353
423
|
this._lastStats = void 0;
|
|
354
424
|
this._lastChannelStats = /* @__PURE__ */ new Map();
|
|
355
|
-
this.
|
|
425
|
+
this.afterClosed = new Event3();
|
|
356
426
|
this.statsUpdated = new Event3();
|
|
357
427
|
this.stream = this._balancer.stream;
|
|
358
428
|
this._balancer.incomingData.on(async (msg) => {
|
|
359
429
|
await this._handleCommand(Command.decode(msg));
|
|
360
430
|
});
|
|
361
|
-
scheduleTaskInterval(this._ctx, async () => this._emitStats(), STATS_INTERVAL);
|
|
362
431
|
}
|
|
363
432
|
/**
|
|
364
433
|
* Creates a duplex Node.js-style stream.
|
|
@@ -371,9 +440,9 @@ var Muxer = class {
|
|
|
371
440
|
tag,
|
|
372
441
|
contentType: opts.contentType
|
|
373
442
|
});
|
|
374
|
-
|
|
443
|
+
invariant3(!channel.push, `Channel already open: ${tag}`, {
|
|
375
444
|
F: __dxlog_file3,
|
|
376
|
-
L:
|
|
445
|
+
L: 140,
|
|
377
446
|
S: this,
|
|
378
447
|
A: [
|
|
379
448
|
"!channel.push",
|
|
@@ -419,9 +488,9 @@ var Muxer = class {
|
|
|
419
488
|
tag,
|
|
420
489
|
contentType: opts.contentType
|
|
421
490
|
});
|
|
422
|
-
|
|
491
|
+
invariant3(!channel.push, `Channel already open: ${tag}`, {
|
|
423
492
|
F: __dxlog_file3,
|
|
424
|
-
L:
|
|
493
|
+
L: 192,
|
|
425
494
|
S: this,
|
|
426
495
|
A: [
|
|
427
496
|
"!channel.push",
|
|
@@ -439,13 +508,13 @@ var Muxer = class {
|
|
|
439
508
|
}
|
|
440
509
|
};
|
|
441
510
|
const port = {
|
|
442
|
-
send: async (data) => {
|
|
443
|
-
await this._sendData(channel, data);
|
|
511
|
+
send: async (data, timeout) => {
|
|
512
|
+
await this._sendData(channel, data, timeout);
|
|
444
513
|
},
|
|
445
514
|
subscribe: (cb) => {
|
|
446
|
-
|
|
515
|
+
invariant3(!callback, "Only one subscriber is allowed", {
|
|
447
516
|
F: __dxlog_file3,
|
|
448
|
-
L:
|
|
517
|
+
L: 214,
|
|
449
518
|
S: this,
|
|
450
519
|
A: [
|
|
451
520
|
"!callback",
|
|
@@ -473,61 +542,153 @@ var Muxer = class {
|
|
|
473
542
|
}
|
|
474
543
|
return port;
|
|
475
544
|
}
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
*/
|
|
479
|
-
async destroy(err) {
|
|
545
|
+
// initiate graceful close
|
|
546
|
+
async close(err) {
|
|
480
547
|
if (this._destroying) {
|
|
548
|
+
log3("already destroying, ignoring graceful close request", void 0, {
|
|
549
|
+
F: __dxlog_file3,
|
|
550
|
+
L: 247,
|
|
551
|
+
S: this,
|
|
552
|
+
C: (f, a) => f(...a)
|
|
553
|
+
});
|
|
481
554
|
return;
|
|
482
555
|
}
|
|
483
|
-
this.
|
|
484
|
-
|
|
485
|
-
|
|
556
|
+
if (this._closing) {
|
|
557
|
+
log3("already closing, ignoring graceful close request", void 0, {
|
|
558
|
+
F: __dxlog_file3,
|
|
559
|
+
L: 251,
|
|
560
|
+
S: this,
|
|
561
|
+
C: (f, a) => f(...a)
|
|
562
|
+
});
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
this._closing = true;
|
|
566
|
+
await this._sendCommand({
|
|
567
|
+
close: {
|
|
486
568
|
error: err?.message
|
|
487
569
|
}
|
|
488
|
-
}, SYSTEM_CHANNEL_ID).
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
570
|
+
}, SYSTEM_CHANNEL_ID, DESTROY_COMMAND_SEND_TIMEOUT).catch(async (err2) => {
|
|
571
|
+
log3("error sending close command", {
|
|
572
|
+
err: err2
|
|
573
|
+
}, {
|
|
574
|
+
F: __dxlog_file3,
|
|
575
|
+
L: 266,
|
|
576
|
+
S: this,
|
|
577
|
+
C: (f, a) => f(...a)
|
|
578
|
+
});
|
|
579
|
+
await this.dispose(err2);
|
|
492
580
|
});
|
|
581
|
+
await Promise.race([
|
|
582
|
+
new Promise((_resolve, reject) => {
|
|
583
|
+
setTimeout(() => {
|
|
584
|
+
reject(new TimeoutError("gracefully closing muxer"));
|
|
585
|
+
}, GRACEFUL_CLOSE_TIMEOUT);
|
|
586
|
+
}),
|
|
587
|
+
(async () => {
|
|
588
|
+
await this.dispose(err);
|
|
589
|
+
})()
|
|
590
|
+
]);
|
|
591
|
+
}
|
|
592
|
+
// force close without confirmation
|
|
593
|
+
async destroy(err) {
|
|
594
|
+
if (this._destroying) {
|
|
595
|
+
log3("already destroying, ignoring destroy request", void 0, {
|
|
596
|
+
F: __dxlog_file3,
|
|
597
|
+
L: 287,
|
|
598
|
+
S: this,
|
|
599
|
+
C: (f, a) => f(...a)
|
|
600
|
+
});
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
this._destroying = true;
|
|
493
604
|
void this._ctx.dispose();
|
|
605
|
+
if (this._closing) {
|
|
606
|
+
log3("destroy cancelling graceful close", void 0, {
|
|
607
|
+
F: __dxlog_file3,
|
|
608
|
+
L: 293,
|
|
609
|
+
S: this,
|
|
610
|
+
C: (f, a) => f(...a)
|
|
611
|
+
});
|
|
612
|
+
this._closing = false;
|
|
613
|
+
} else {
|
|
614
|
+
await this._sendCommand({
|
|
615
|
+
close: {
|
|
616
|
+
error: err?.message
|
|
617
|
+
}
|
|
618
|
+
}, SYSTEM_CHANNEL_ID).catch(async (err2) => {
|
|
619
|
+
log3("error sending courtesy close command", {
|
|
620
|
+
err: err2
|
|
621
|
+
}, {
|
|
622
|
+
F: __dxlog_file3,
|
|
623
|
+
L: 306,
|
|
624
|
+
S: this,
|
|
625
|
+
C: (f, a) => f(...a)
|
|
626
|
+
});
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
this.dispose(err).catch((err2) => {
|
|
630
|
+
log3("error disposing after destroy", {
|
|
631
|
+
err: err2
|
|
632
|
+
}, {
|
|
633
|
+
F: __dxlog_file3,
|
|
634
|
+
L: 311,
|
|
635
|
+
S: this,
|
|
636
|
+
C: (f, a) => f(...a)
|
|
637
|
+
});
|
|
638
|
+
});
|
|
494
639
|
}
|
|
495
|
-
|
|
496
|
-
|
|
640
|
+
// complete the termination, graceful or otherwise
|
|
641
|
+
async dispose(err) {
|
|
642
|
+
if (this._disposed) {
|
|
643
|
+
log3("already destroyed, ignoring dispose request", void 0, {
|
|
644
|
+
F: __dxlog_file3,
|
|
645
|
+
L: 319,
|
|
646
|
+
S: this,
|
|
647
|
+
C: (f, a) => f(...a)
|
|
648
|
+
});
|
|
497
649
|
return;
|
|
498
650
|
}
|
|
499
|
-
this.
|
|
500
|
-
this._balancer.destroy();
|
|
651
|
+
void this._ctx.dispose();
|
|
652
|
+
await this._balancer.destroy();
|
|
501
653
|
for (const channel of this._channelsByTag.values()) {
|
|
502
654
|
channel.destroy?.(err);
|
|
503
655
|
}
|
|
504
|
-
this.
|
|
656
|
+
this._disposed = true;
|
|
657
|
+
this.afterClosed.emit(err);
|
|
505
658
|
this._channelsByLocalId.clear();
|
|
506
659
|
this._channelsByTag.clear();
|
|
507
660
|
}
|
|
508
661
|
async _handleCommand(cmd) {
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
}, {
|
|
512
|
-
F: __dxlog_file3,
|
|
513
|
-
L: 286,
|
|
514
|
-
S: this,
|
|
515
|
-
C: (f, a) => f(...a)
|
|
516
|
-
});
|
|
517
|
-
if (this._destroyed || this._destroying) {
|
|
518
|
-
if (cmd.destroy) {
|
|
519
|
-
return;
|
|
520
|
-
}
|
|
521
|
-
log2.warn("Received command after destroy", {
|
|
662
|
+
if (this._disposed) {
|
|
663
|
+
log3.warn("Received command after destroy", {
|
|
522
664
|
cmd
|
|
523
665
|
}, {
|
|
524
666
|
F: __dxlog_file3,
|
|
525
|
-
L:
|
|
667
|
+
L: 341,
|
|
526
668
|
S: this,
|
|
527
669
|
C: (f, a) => f(...a)
|
|
528
670
|
});
|
|
529
671
|
return;
|
|
530
672
|
}
|
|
673
|
+
if (cmd.close) {
|
|
674
|
+
if (!this._closing) {
|
|
675
|
+
log3("received peer close, initiating my own graceful close", void 0, {
|
|
676
|
+
F: __dxlog_file3,
|
|
677
|
+
L: 347,
|
|
678
|
+
S: this,
|
|
679
|
+
C: (f, a) => f(...a)
|
|
680
|
+
});
|
|
681
|
+
await this.close();
|
|
682
|
+
} else {
|
|
683
|
+
log3("received close from peer, already closing", void 0, {
|
|
684
|
+
F: __dxlog_file3,
|
|
685
|
+
L: 350,
|
|
686
|
+
S: this,
|
|
687
|
+
C: (f, a) => f(...a)
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
531
692
|
if (cmd.openChannel) {
|
|
532
693
|
const channel = this._getOrCreateStream({
|
|
533
694
|
tag: cmd.openChannel.tag,
|
|
@@ -546,31 +707,34 @@ var Muxer = class {
|
|
|
546
707
|
} else if (cmd.data) {
|
|
547
708
|
const stream = this._channelsByLocalId.get(cmd.data.channelId) ?? failUndefined();
|
|
548
709
|
if (!stream.push) {
|
|
549
|
-
|
|
710
|
+
log3.warn("Received data for channel before it was opened", {
|
|
550
711
|
tag: stream.tag
|
|
551
712
|
}, {
|
|
552
713
|
F: __dxlog_file3,
|
|
553
|
-
L:
|
|
714
|
+
L: 379,
|
|
554
715
|
S: this,
|
|
555
716
|
C: (f, a) => f(...a)
|
|
556
717
|
});
|
|
557
718
|
return;
|
|
558
719
|
}
|
|
559
720
|
stream.push(cmd.data.data);
|
|
560
|
-
} else if (cmd.destroy) {
|
|
561
|
-
this._dispose();
|
|
562
721
|
}
|
|
563
722
|
}
|
|
564
|
-
async _sendCommand(cmd, channelId = -1) {
|
|
723
|
+
async _sendCommand(cmd, channelId = -1, timeout = DEFAULT_SEND_COMMAND_TIMEOUT) {
|
|
565
724
|
try {
|
|
566
725
|
const trigger = new Trigger();
|
|
567
726
|
this._balancer.pushData(Command.encode(cmd), trigger, channelId);
|
|
568
|
-
await trigger.wait(
|
|
727
|
+
await trigger.wait({
|
|
728
|
+
timeout
|
|
729
|
+
});
|
|
569
730
|
} catch (err) {
|
|
570
731
|
await this.destroy(err);
|
|
571
732
|
}
|
|
572
733
|
}
|
|
573
734
|
_getOrCreateStream(params) {
|
|
735
|
+
if (this._channelsByTag.size === 0) {
|
|
736
|
+
scheduleTaskInterval(this._ctx, async () => this._emitStats(), STATS_INTERVAL);
|
|
737
|
+
}
|
|
574
738
|
let channel = this._channelsByTag.get(params.tag);
|
|
575
739
|
if (!channel) {
|
|
576
740
|
channel = {
|
|
@@ -592,14 +756,14 @@ var Muxer = class {
|
|
|
592
756
|
}
|
|
593
757
|
return channel;
|
|
594
758
|
}
|
|
595
|
-
async _sendData(channel, data) {
|
|
759
|
+
async _sendData(channel, data, timeout) {
|
|
596
760
|
if (data.length > MAX_SAFE_FRAME_SIZE) {
|
|
597
|
-
|
|
761
|
+
log3.warn("frame size exceeds maximum safe value", {
|
|
598
762
|
size: data.length,
|
|
599
763
|
threshold: MAX_SAFE_FRAME_SIZE
|
|
600
764
|
}, {
|
|
601
765
|
F: __dxlog_file3,
|
|
602
|
-
L:
|
|
766
|
+
L: 425,
|
|
603
767
|
S: this,
|
|
604
768
|
C: (f, a) => f(...a)
|
|
605
769
|
});
|
|
@@ -614,7 +778,7 @@ var Muxer = class {
|
|
|
614
778
|
channelId: channel.remoteId,
|
|
615
779
|
data
|
|
616
780
|
}
|
|
617
|
-
}, channel.id);
|
|
781
|
+
}, channel.id, timeout);
|
|
618
782
|
}
|
|
619
783
|
_destroyChannel(channel, err) {
|
|
620
784
|
if (channel.destroy) {
|
|
@@ -624,7 +788,7 @@ var Muxer = class {
|
|
|
624
788
|
this._channelsByTag.delete(channel.tag);
|
|
625
789
|
}
|
|
626
790
|
async _emitStats() {
|
|
627
|
-
if (this.
|
|
791
|
+
if (this._disposed || this._destroying) {
|
|
628
792
|
this._lastStats = void 0;
|
|
629
793
|
this._lastChannelStats.clear();
|
|
630
794
|
return;
|
|
@@ -676,15 +840,17 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
676
840
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
677
841
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
678
842
|
}
|
|
679
|
-
var __dxlog_file4 = "/
|
|
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;
|
|
680
846
|
var Teleport = class {
|
|
681
847
|
constructor({ initiator, localPeerId, remotePeerId }) {
|
|
682
848
|
this._ctx = new Context2({
|
|
683
849
|
onError: (err) => {
|
|
684
850
|
void this.destroy(err).catch(() => {
|
|
685
|
-
|
|
851
|
+
log4.error("Error during destroy", err, {
|
|
686
852
|
F: __dxlog_file4,
|
|
687
|
-
L:
|
|
853
|
+
L: 47,
|
|
688
854
|
S: this,
|
|
689
855
|
C: (f, a) => f(...a)
|
|
690
856
|
});
|
|
@@ -693,21 +859,21 @@ var Teleport = class {
|
|
|
693
859
|
});
|
|
694
860
|
this._muxer = new Muxer();
|
|
695
861
|
this._control = new ControlExtension({
|
|
696
|
-
heartbeatInterval:
|
|
697
|
-
heartbeatTimeout:
|
|
862
|
+
heartbeatInterval: CONTROL_HEARTBEAT_INTERVAL,
|
|
863
|
+
heartbeatTimeout: CONTROL_HEARTBEAT_TIMEOUT,
|
|
698
864
|
onTimeout: () => {
|
|
699
865
|
if (this._destroying || this._aborting) {
|
|
700
866
|
return;
|
|
701
867
|
}
|
|
702
|
-
|
|
868
|
+
log4("abort teleport due to onTimeout in ControlExtension", void 0, {
|
|
703
869
|
F: __dxlog_file4,
|
|
704
|
-
L:
|
|
870
|
+
L: 62,
|
|
705
871
|
S: this,
|
|
706
872
|
C: (f, a) => f(...a)
|
|
707
873
|
});
|
|
708
|
-
this.
|
|
874
|
+
this.abort(new TimeoutError2("control extension")).catch((err) => log4.catch(err, void 0, {
|
|
709
875
|
F: __dxlog_file4,
|
|
710
|
-
L:
|
|
876
|
+
L: 63,
|
|
711
877
|
S: this,
|
|
712
878
|
C: (f, a) => f(...a)
|
|
713
879
|
}));
|
|
@@ -718,27 +884,27 @@ var Teleport = class {
|
|
|
718
884
|
this._open = false;
|
|
719
885
|
this._destroying = false;
|
|
720
886
|
this._aborting = false;
|
|
721
|
-
|
|
887
|
+
invariant4(typeof initiator === "boolean", void 0, {
|
|
722
888
|
F: __dxlog_file4,
|
|
723
|
-
L:
|
|
889
|
+
L: 75,
|
|
724
890
|
S: this,
|
|
725
891
|
A: [
|
|
726
892
|
"typeof initiator === 'boolean'",
|
|
727
893
|
""
|
|
728
894
|
]
|
|
729
895
|
});
|
|
730
|
-
|
|
896
|
+
invariant4(PublicKey.isPublicKey(localPeerId), void 0, {
|
|
731
897
|
F: __dxlog_file4,
|
|
732
|
-
L:
|
|
898
|
+
L: 76,
|
|
733
899
|
S: this,
|
|
734
900
|
A: [
|
|
735
901
|
"PublicKey.isPublicKey(localPeerId)",
|
|
736
902
|
""
|
|
737
903
|
]
|
|
738
904
|
});
|
|
739
|
-
|
|
905
|
+
invariant4(PublicKey.isPublicKey(remotePeerId), void 0, {
|
|
740
906
|
F: __dxlog_file4,
|
|
741
|
-
L:
|
|
907
|
+
L: 77,
|
|
742
908
|
S: this,
|
|
743
909
|
A: [
|
|
744
910
|
"PublicKey.isPublicKey(remotePeerId)",
|
|
@@ -749,17 +915,17 @@ var Teleport = class {
|
|
|
749
915
|
this.localPeerId = localPeerId;
|
|
750
916
|
this.remotePeerId = remotePeerId;
|
|
751
917
|
this._control.onExtensionRegistered.set(async (name) => {
|
|
752
|
-
|
|
918
|
+
log4("remote extension", {
|
|
753
919
|
name
|
|
754
920
|
}, {
|
|
755
921
|
F: __dxlog_file4,
|
|
756
|
-
L:
|
|
922
|
+
L: 83,
|
|
757
923
|
S: this,
|
|
758
924
|
C: (f, a) => f(...a)
|
|
759
925
|
});
|
|
760
|
-
|
|
926
|
+
invariant4(!this._remoteExtensions.has(name), "Remote extension already exists", {
|
|
761
927
|
F: __dxlog_file4,
|
|
762
|
-
L:
|
|
928
|
+
L: 84,
|
|
763
929
|
S: this,
|
|
764
930
|
A: [
|
|
765
931
|
"!this._remoteExtensions.has(name)",
|
|
@@ -778,9 +944,9 @@ var Teleport = class {
|
|
|
778
944
|
{
|
|
779
945
|
this._muxer.stream.on("close", async () => {
|
|
780
946
|
if (this._destroying || this._aborting) {
|
|
781
|
-
|
|
947
|
+
log4("destroy teleport due to muxer stream close, skipping due to already destroying/aborting", void 0, {
|
|
782
948
|
F: __dxlog_file4,
|
|
783
|
-
L:
|
|
949
|
+
L: 100,
|
|
784
950
|
S: this,
|
|
785
951
|
C: (f, a) => f(...a)
|
|
786
952
|
});
|
|
@@ -793,7 +959,7 @@ var Teleport = class {
|
|
|
793
959
|
});
|
|
794
960
|
}
|
|
795
961
|
this._muxer.statsUpdated.on((stats) => {
|
|
796
|
-
|
|
962
|
+
log4.trace("dxos.mesh.teleport.stats", {
|
|
797
963
|
localPeerId,
|
|
798
964
|
remotePeerId,
|
|
799
965
|
bytesSent: stats.bytesSent,
|
|
@@ -803,7 +969,7 @@ var Teleport = class {
|
|
|
803
969
|
channels: stats.channels
|
|
804
970
|
}, {
|
|
805
971
|
F: __dxlog_file4,
|
|
806
|
-
L:
|
|
972
|
+
L: 113,
|
|
807
973
|
S: this,
|
|
808
974
|
C: (f, a) => f(...a)
|
|
809
975
|
});
|
|
@@ -839,9 +1005,9 @@ var Teleport = class {
|
|
|
839
1005
|
try {
|
|
840
1006
|
await extension.onAbort(err);
|
|
841
1007
|
} catch (err2) {
|
|
842
|
-
|
|
1008
|
+
log4.catch(err2, void 0, {
|
|
843
1009
|
F: __dxlog_file4,
|
|
844
|
-
L:
|
|
1010
|
+
L: 166,
|
|
845
1011
|
S: this,
|
|
846
1012
|
C: (f, a) => f(...a)
|
|
847
1013
|
});
|
|
@@ -862,25 +1028,25 @@ var Teleport = class {
|
|
|
862
1028
|
try {
|
|
863
1029
|
await extension.onClose(err);
|
|
864
1030
|
} catch (err2) {
|
|
865
|
-
|
|
1031
|
+
log4.catch(err2, void 0, {
|
|
866
1032
|
F: __dxlog_file4,
|
|
867
|
-
L:
|
|
1033
|
+
L: 190,
|
|
868
1034
|
S: this,
|
|
869
1035
|
C: (f, a) => f(...a)
|
|
870
1036
|
});
|
|
871
1037
|
}
|
|
872
1038
|
}
|
|
873
|
-
await this._muxer.
|
|
1039
|
+
await this._muxer.close();
|
|
874
1040
|
}
|
|
875
1041
|
addExtension(name, extension) {
|
|
876
1042
|
if (!this._open) {
|
|
877
1043
|
throw new Error("Not open");
|
|
878
1044
|
}
|
|
879
|
-
|
|
1045
|
+
log4("addExtension", {
|
|
880
1046
|
name
|
|
881
1047
|
}, {
|
|
882
1048
|
F: __dxlog_file4,
|
|
883
|
-
L:
|
|
1049
|
+
L: 202,
|
|
884
1050
|
S: this,
|
|
885
1051
|
C: (f, a) => f(...a)
|
|
886
1052
|
});
|
|
@@ -902,18 +1068,18 @@ var Teleport = class {
|
|
|
902
1068
|
}
|
|
903
1069
|
}
|
|
904
1070
|
_setExtension(extensionName, extension) {
|
|
905
|
-
|
|
1071
|
+
invariant4(!extensionName.includes("/"), "Invalid extension name", {
|
|
906
1072
|
F: __dxlog_file4,
|
|
907
|
-
L:
|
|
1073
|
+
L: 226,
|
|
908
1074
|
S: this,
|
|
909
1075
|
A: [
|
|
910
1076
|
"!extensionName.includes('/')",
|
|
911
1077
|
"'Invalid extension name'"
|
|
912
1078
|
]
|
|
913
1079
|
});
|
|
914
|
-
|
|
1080
|
+
invariant4(!this._extensions.has(extensionName), "Extension already exists", {
|
|
915
1081
|
F: __dxlog_file4,
|
|
916
|
-
L:
|
|
1082
|
+
L: 227,
|
|
917
1083
|
S: this,
|
|
918
1084
|
A: [
|
|
919
1085
|
"!this._extensions.has(extensionName)",
|
|
@@ -923,11 +1089,11 @@ var Teleport = class {
|
|
|
923
1089
|
this._extensions.set(extensionName, extension);
|
|
924
1090
|
}
|
|
925
1091
|
async _openExtension(extensionName) {
|
|
926
|
-
|
|
1092
|
+
log4("open extension", {
|
|
927
1093
|
extensionName
|
|
928
1094
|
}, {
|
|
929
1095
|
F: __dxlog_file4,
|
|
930
|
-
L:
|
|
1096
|
+
L: 232,
|
|
931
1097
|
S: this,
|
|
932
1098
|
C: (f, a) => f(...a)
|
|
933
1099
|
});
|
|
@@ -937,9 +1103,9 @@ var Teleport = class {
|
|
|
937
1103
|
localPeerId: this.localPeerId,
|
|
938
1104
|
remotePeerId: this.remotePeerId,
|
|
939
1105
|
createPort: async (channelName, opts) => {
|
|
940
|
-
|
|
1106
|
+
invariant4(!channelName.includes("/"), "Invalid channel name", {
|
|
941
1107
|
F: __dxlog_file4,
|
|
942
|
-
L:
|
|
1108
|
+
L: 240,
|
|
943
1109
|
S: this,
|
|
944
1110
|
A: [
|
|
945
1111
|
"!channelName.includes('/')",
|
|
@@ -949,9 +1115,9 @@ var Teleport = class {
|
|
|
949
1115
|
return this._muxer.createPort(`${extensionName}/${channelName}`, opts);
|
|
950
1116
|
},
|
|
951
1117
|
createStream: async (channelName, opts) => {
|
|
952
|
-
|
|
1118
|
+
invariant4(!channelName.includes("/"), "Invalid channel name", {
|
|
953
1119
|
F: __dxlog_file4,
|
|
954
|
-
L:
|
|
1120
|
+
L: 244,
|
|
955
1121
|
S: this,
|
|
956
1122
|
A: [
|
|
957
1123
|
"!channelName.includes('/')",
|
|
@@ -967,11 +1133,11 @@ var Teleport = class {
|
|
|
967
1133
|
}
|
|
968
1134
|
};
|
|
969
1135
|
await extension.onOpen(context);
|
|
970
|
-
|
|
1136
|
+
log4("extension opened", {
|
|
971
1137
|
extensionName
|
|
972
1138
|
}, {
|
|
973
1139
|
F: __dxlog_file4,
|
|
974
|
-
L:
|
|
1140
|
+
L: 255,
|
|
975
1141
|
S: this,
|
|
976
1142
|
C: (f, a) => f(...a)
|
|
977
1143
|
});
|
|
@@ -1040,7 +1206,7 @@ var ControlExtension = class {
|
|
|
1040
1206
|
};
|
|
1041
1207
|
|
|
1042
1208
|
// packages/core/mesh/teleport/src/testing/test-builder.ts
|
|
1043
|
-
var __dxlog_file5 = "/
|
|
1209
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/testing/test-builder.ts";
|
|
1044
1210
|
var TestBuilder = class {
|
|
1045
1211
|
constructor() {
|
|
1046
1212
|
this._peers = /* @__PURE__ */ new Set();
|
|
@@ -1059,7 +1225,7 @@ var TestBuilder = class {
|
|
|
1059
1225
|
await Promise.all(Array.from(this._peers).map((agent) => agent.destroy()));
|
|
1060
1226
|
}
|
|
1061
1227
|
async connect(peer1, peer2) {
|
|
1062
|
-
|
|
1228
|
+
invariant5(peer1 !== peer2, void 0, {
|
|
1063
1229
|
F: __dxlog_file5,
|
|
1064
1230
|
L: 37,
|
|
1065
1231
|
S: this,
|
|
@@ -1068,7 +1234,7 @@ var TestBuilder = class {
|
|
|
1068
1234
|
""
|
|
1069
1235
|
]
|
|
1070
1236
|
});
|
|
1071
|
-
|
|
1237
|
+
invariant5(this._peers.has(peer1), void 0, {
|
|
1072
1238
|
F: __dxlog_file5,
|
|
1073
1239
|
L: 38,
|
|
1074
1240
|
S: this,
|
|
@@ -1077,7 +1243,7 @@ var TestBuilder = class {
|
|
|
1077
1243
|
""
|
|
1078
1244
|
]
|
|
1079
1245
|
});
|
|
1080
|
-
|
|
1246
|
+
invariant5(this._peers.has(peer1), void 0, {
|
|
1081
1247
|
F: __dxlog_file5,
|
|
1082
1248
|
L: 39,
|
|
1083
1249
|
S: this,
|
|
@@ -1105,7 +1271,7 @@ var TestBuilder = class {
|
|
|
1105
1271
|
];
|
|
1106
1272
|
}
|
|
1107
1273
|
async disconnect(peer1, peer2) {
|
|
1108
|
-
|
|
1274
|
+
invariant5(peer1 !== peer2, void 0, {
|
|
1109
1275
|
F: __dxlog_file5,
|
|
1110
1276
|
L: 51,
|
|
1111
1277
|
S: this,
|
|
@@ -1114,7 +1280,7 @@ var TestBuilder = class {
|
|
|
1114
1280
|
""
|
|
1115
1281
|
]
|
|
1116
1282
|
});
|
|
1117
|
-
|
|
1283
|
+
invariant5(this._peers.has(peer1), void 0, {
|
|
1118
1284
|
F: __dxlog_file5,
|
|
1119
1285
|
L: 52,
|
|
1120
1286
|
S: this,
|
|
@@ -1123,7 +1289,7 @@ var TestBuilder = class {
|
|
|
1123
1289
|
""
|
|
1124
1290
|
]
|
|
1125
1291
|
});
|
|
1126
|
-
|
|
1292
|
+
invariant5(this._peers.has(peer1), void 0, {
|
|
1127
1293
|
F: __dxlog_file5,
|
|
1128
1294
|
L: 53,
|
|
1129
1295
|
S: this,
|
|
@@ -1134,7 +1300,7 @@ var TestBuilder = class {
|
|
|
1134
1300
|
});
|
|
1135
1301
|
const connection1 = Array.from(peer1.connections).find((connection) => connection.remotePeerId.equals(peer2.peerId));
|
|
1136
1302
|
const connection2 = Array.from(peer2.connections).find((connection) => connection.remotePeerId.equals(peer1.peerId));
|
|
1137
|
-
|
|
1303
|
+
invariant5(connection1, void 0, {
|
|
1138
1304
|
F: __dxlog_file5,
|
|
1139
1305
|
L: 62,
|
|
1140
1306
|
S: this,
|
|
@@ -1143,7 +1309,7 @@ var TestBuilder = class {
|
|
|
1143
1309
|
""
|
|
1144
1310
|
]
|
|
1145
1311
|
});
|
|
1146
|
-
|
|
1312
|
+
invariant5(connection2, void 0, {
|
|
1147
1313
|
F: __dxlog_file5,
|
|
1148
1314
|
L: 63,
|
|
1149
1315
|
S: this,
|
|
@@ -1173,7 +1339,7 @@ var TestPeer = class {
|
|
|
1173
1339
|
return connection;
|
|
1174
1340
|
}
|
|
1175
1341
|
async openConnection(connection) {
|
|
1176
|
-
|
|
1342
|
+
invariant5(this.connections.has(connection), void 0, {
|
|
1177
1343
|
F: __dxlog_file5,
|
|
1178
1344
|
L: 84,
|
|
1179
1345
|
S: this,
|
|
@@ -1186,7 +1352,7 @@ var TestPeer = class {
|
|
|
1186
1352
|
await this.onOpen(connection);
|
|
1187
1353
|
}
|
|
1188
1354
|
async closeConnection(connection) {
|
|
1189
|
-
|
|
1355
|
+
invariant5(this.connections.has(connection), void 0, {
|
|
1190
1356
|
F: __dxlog_file5,
|
|
1191
1357
|
L: 90,
|
|
1192
1358
|
S: this,
|
|
@@ -1208,7 +1374,7 @@ var TestPeer = class {
|
|
|
1208
1374
|
var pipeStreams = (stream1, stream2) => {
|
|
1209
1375
|
pipeline(stream1, stream2, (err) => {
|
|
1210
1376
|
if (err && err.code !== "ERR_STREAM_PREMATURE_CLOSE") {
|
|
1211
|
-
|
|
1377
|
+
log5.catch(err, void 0, {
|
|
1212
1378
|
F: __dxlog_file5,
|
|
1213
1379
|
L: 106,
|
|
1214
1380
|
S: void 0,
|
|
@@ -1218,7 +1384,7 @@ var pipeStreams = (stream1, stream2) => {
|
|
|
1218
1384
|
});
|
|
1219
1385
|
pipeline(stream2, stream1, (err) => {
|
|
1220
1386
|
if (err && err.code !== "ERR_STREAM_PREMATURE_CLOSE") {
|
|
1221
|
-
|
|
1387
|
+
log5.catch(err, void 0, {
|
|
1222
1388
|
F: __dxlog_file5,
|
|
1223
1389
|
L: 111,
|
|
1224
1390
|
S: void 0,
|
|
@@ -1242,11 +1408,11 @@ var TestConnection = class {
|
|
|
1242
1408
|
|
|
1243
1409
|
// packages/core/mesh/teleport/src/testing/test-extension.ts
|
|
1244
1410
|
import { asyncTimeout as asyncTimeout2, Trigger as Trigger2 } from "@dxos/async";
|
|
1245
|
-
import { invariant as
|
|
1246
|
-
import { log as
|
|
1411
|
+
import { invariant as invariant6 } from "@dxos/invariant";
|
|
1412
|
+
import { log as log6 } from "@dxos/log";
|
|
1247
1413
|
import { schema as schema3 } from "@dxos/protocols";
|
|
1248
1414
|
import { createProtoRpcPeer as createProtoRpcPeer2 } from "@dxos/rpc";
|
|
1249
|
-
var __dxlog_file6 = "/
|
|
1415
|
+
var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/testing/test-extension.ts";
|
|
1250
1416
|
var TestExtension = class {
|
|
1251
1417
|
constructor(callbacks = {}) {
|
|
1252
1418
|
this.callbacks = callbacks;
|
|
@@ -1258,7 +1424,7 @@ var TestExtension = class {
|
|
|
1258
1424
|
return this.extensionContext?.remotePeerId;
|
|
1259
1425
|
}
|
|
1260
1426
|
async onOpen(context) {
|
|
1261
|
-
|
|
1427
|
+
log6("onOpen", {
|
|
1262
1428
|
localPeerId: context.localPeerId,
|
|
1263
1429
|
remotePeerId: context.remotePeerId
|
|
1264
1430
|
}, {
|
|
@@ -1296,7 +1462,7 @@ var TestExtension = class {
|
|
|
1296
1462
|
this.open.wake();
|
|
1297
1463
|
}
|
|
1298
1464
|
async onClose(err) {
|
|
1299
|
-
|
|
1465
|
+
log6("onClose", {
|
|
1300
1466
|
err
|
|
1301
1467
|
}, {
|
|
1302
1468
|
F: __dxlog_file6,
|
|
@@ -1309,7 +1475,7 @@ var TestExtension = class {
|
|
|
1309
1475
|
await this._rpc?.close();
|
|
1310
1476
|
}
|
|
1311
1477
|
async onAbort(err) {
|
|
1312
|
-
|
|
1478
|
+
log6("onAbort", {
|
|
1313
1479
|
err
|
|
1314
1480
|
}, {
|
|
1315
1481
|
F: __dxlog_file6,
|
|
@@ -1328,7 +1494,7 @@ var TestExtension = class {
|
|
|
1328
1494
|
const res = await asyncTimeout2(this._rpc.rpc.TestService.testCall({
|
|
1329
1495
|
data: message
|
|
1330
1496
|
}), 1500);
|
|
1331
|
-
|
|
1497
|
+
invariant6(res.data === message, void 0, {
|
|
1332
1498
|
F: __dxlog_file6,
|
|
1333
1499
|
L: 84,
|
|
1334
1500
|
S: this,
|
|
@@ -1349,11 +1515,11 @@ var TestExtension = class {
|
|
|
1349
1515
|
// packages/core/mesh/teleport/src/testing/test-extension-with-streams.ts
|
|
1350
1516
|
import { randomBytes } from "@dxos/node-std/crypto";
|
|
1351
1517
|
import { Trigger as Trigger3 } from "@dxos/async";
|
|
1352
|
-
import { invariant as
|
|
1353
|
-
import { log as
|
|
1518
|
+
import { invariant as invariant7 } from "@dxos/invariant";
|
|
1519
|
+
import { log as log7 } from "@dxos/log";
|
|
1354
1520
|
import { schema as schema4 } from "@dxos/protocols";
|
|
1355
1521
|
import { createProtoRpcPeer as createProtoRpcPeer3 } from "@dxos/rpc";
|
|
1356
|
-
var __dxlog_file7 = "/
|
|
1522
|
+
var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/testing/test-extension-with-streams.ts";
|
|
1357
1523
|
var TestExtensionWithStreams = class {
|
|
1358
1524
|
constructor(callbacks = {}) {
|
|
1359
1525
|
this.callbacks = callbacks;
|
|
@@ -1366,7 +1532,7 @@ var TestExtensionWithStreams = class {
|
|
|
1366
1532
|
return this.extensionContext?.remotePeerId;
|
|
1367
1533
|
}
|
|
1368
1534
|
async _openStream(streamTag, interval = 5, chunkSize = 2048) {
|
|
1369
|
-
|
|
1535
|
+
invariant7(!this._streams.has(streamTag), `Stream already exists: ${streamTag}`, {
|
|
1370
1536
|
F: __dxlog_file7,
|
|
1371
1537
|
L: 39,
|
|
1372
1538
|
S: this,
|
|
@@ -1415,7 +1581,7 @@ var TestExtensionWithStreams = class {
|
|
|
1415
1581
|
});
|
|
1416
1582
|
streamEntry.reportingTimer = setInterval(() => {
|
|
1417
1583
|
const { bytesSent, bytesReceived, sendErrors, receiveErrors } = streamEntry;
|
|
1418
|
-
|
|
1584
|
+
log7.trace("dxos.test.stream-stats", {
|
|
1419
1585
|
streamTag,
|
|
1420
1586
|
bytesSent,
|
|
1421
1587
|
bytesReceived,
|
|
@@ -1432,7 +1598,7 @@ var TestExtensionWithStreams = class {
|
|
|
1432
1598
|
}, 100);
|
|
1433
1599
|
}
|
|
1434
1600
|
_closeStream(streamTag) {
|
|
1435
|
-
|
|
1601
|
+
invariant7(this._streams.has(streamTag), `Stream does not exist: ${streamTag}`, {
|
|
1436
1602
|
F: __dxlog_file7,
|
|
1437
1603
|
L: 106,
|
|
1438
1604
|
S: this,
|
|
@@ -1456,7 +1622,7 @@ var TestExtensionWithStreams = class {
|
|
|
1456
1622
|
};
|
|
1457
1623
|
}
|
|
1458
1624
|
async onOpen(context) {
|
|
1459
|
-
|
|
1625
|
+
log7("onOpen", {
|
|
1460
1626
|
localPeerId: context.localPeerId,
|
|
1461
1627
|
remotePeerId: context.remotePeerId
|
|
1462
1628
|
}, {
|
|
@@ -1506,7 +1672,7 @@ var TestExtensionWithStreams = class {
|
|
|
1506
1672
|
this.open.wake();
|
|
1507
1673
|
}
|
|
1508
1674
|
async onClose(err) {
|
|
1509
|
-
|
|
1675
|
+
log7("onClose", {
|
|
1510
1676
|
err
|
|
1511
1677
|
}, {
|
|
1512
1678
|
F: __dxlog_file7,
|
|
@@ -1517,7 +1683,7 @@ var TestExtensionWithStreams = class {
|
|
|
1517
1683
|
await this.callbacks.onClose?.();
|
|
1518
1684
|
this.closed.wake();
|
|
1519
1685
|
for (const [streamTag, stream] of Object.entries(this._streams)) {
|
|
1520
|
-
|
|
1686
|
+
log7("closing stream", {
|
|
1521
1687
|
streamTag
|
|
1522
1688
|
}, {
|
|
1523
1689
|
F: __dxlog_file7,
|
|
@@ -1531,7 +1697,7 @@ var TestExtensionWithStreams = class {
|
|
|
1531
1697
|
await this._rpc?.close();
|
|
1532
1698
|
}
|
|
1533
1699
|
async onAbort(err) {
|
|
1534
|
-
|
|
1700
|
+
log7("onAbort", {
|
|
1535
1701
|
err
|
|
1536
1702
|
}, {
|
|
1537
1703
|
F: __dxlog_file7,
|
|
@@ -1555,7 +1721,7 @@ var TestExtensionWithStreams = class {
|
|
|
1555
1721
|
streamLoadInterval,
|
|
1556
1722
|
streamLoadChunkSize
|
|
1557
1723
|
});
|
|
1558
|
-
|
|
1724
|
+
invariant7(data === streamTag, void 0, {
|
|
1559
1725
|
F: __dxlog_file7,
|
|
1560
1726
|
L: 207,
|
|
1561
1727
|
S: this,
|
|
@@ -1574,7 +1740,7 @@ var TestExtensionWithStreams = class {
|
|
|
1574
1740
|
const { data, bytesSent, bytesReceived, sendErrors, receiveErrors, runningTime } = await this._rpc.rpc.TestServiceWithStreams.closeTestStream({
|
|
1575
1741
|
data: streamTag
|
|
1576
1742
|
});
|
|
1577
|
-
|
|
1743
|
+
invariant7(data === streamTag, void 0, {
|
|
1578
1744
|
F: __dxlog_file7,
|
|
1579
1745
|
L: 220,
|
|
1580
1746
|
S: this,
|
|
@@ -1618,4 +1784,4 @@ export {
|
|
|
1618
1784
|
TestExtension,
|
|
1619
1785
|
TestExtensionWithStreams
|
|
1620
1786
|
};
|
|
1621
|
-
//# sourceMappingURL=chunk-
|
|
1787
|
+
//# sourceMappingURL=chunk-VXXLKKBF.mjs.map
|