@dxos/teleport 0.8.3 → 0.8.4-main.1c7ec43d41
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-PKY5UWGF.mjs → neutral/chunk-LECANKBC.mjs} +251 -738
- package/dist/lib/neutral/chunk-LECANKBC.mjs.map +7 -0
- package/dist/lib/{browser → neutral}/index.mjs +12 -16
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/{browser → neutral}/testing/index.mjs +1 -1
- package/dist/types/src/control-extension.d.ts.map +1 -1
- package/dist/types/src/muxing/balancer.d.ts +1 -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/index.d.ts +1 -1
- package/dist/types/src/muxing/index.d.ts.map +1 -1
- package/dist/types/src/muxing/muxer.d.ts.map +1 -1
- package/dist/types/src/rpc-extension.d.ts +2 -2
- package/dist/types/src/rpc-extension.d.ts.map +1 -1
- package/dist/types/src/teleport.d.ts +2 -2
- package/dist/types/src/teleport.d.ts.map +1 -1
- package/dist/types/src/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/testing/test-extension-with-streams.d.ts.map +1 -1
- package/dist/types/src/testing/test-extension.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +21 -24
- package/src/control-extension.ts +2 -2
- package/src/muxing/balancer.test.ts +2 -2
- package/src/muxing/balancer.ts +1 -1
- package/src/muxing/framer.test.ts +1 -1
- package/src/muxing/index.ts +1 -1
- package/src/muxing/muxer.test.ts +3 -3
- package/src/muxing/muxer.ts +8 -4
- package/src/rpc-extension.ts +3 -3
- package/src/teleport.test.ts +1 -1
- package/src/teleport.ts +4 -4
- package/src/testing/test-extension-with-streams.ts +1 -1
- package/src/testing/test-extension.ts +2 -2
- package/dist/lib/browser/chunk-PKY5UWGF.mjs.map +0 -7
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/node/chunk-IL4CNIZ3.cjs +0 -2093
- package/dist/lib/node/chunk-IL4CNIZ3.cjs.map +0 -7
- package/dist/lib/node/index.cjs +0 -106
- package/dist/lib/node/index.cjs.map +0 -7
- package/dist/lib/node/meta.json +0 -1
- package/dist/lib/node/testing/index.cjs +0 -37
- package/dist/lib/node/testing/index.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-Z23CICUY.mjs +0 -2094
- package/dist/lib/node-esm/chunk-Z23CICUY.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -86
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/testing/index.mjs +0 -16
- package/dist/lib/node-esm/testing/index.mjs.map +0 -7
- /package/dist/lib/{browser → neutral}/testing/index.mjs.map +0 -0
|
@@ -25,9 +25,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
25
|
mod
|
|
26
26
|
));
|
|
27
27
|
|
|
28
|
-
// node_modules/.pnpm/varint@6.0.0/node_modules/varint/encode.js
|
|
28
|
+
// ../../../../node_modules/.pnpm/varint@6.0.0/node_modules/varint/encode.js
|
|
29
29
|
var require_encode = __commonJS({
|
|
30
|
-
"node_modules/.pnpm/varint@6.0.0/node_modules/varint/encode.js"(exports, module) {
|
|
30
|
+
"../../../../node_modules/.pnpm/varint@6.0.0/node_modules/varint/encode.js"(exports, module) {
|
|
31
31
|
module.exports = encode;
|
|
32
32
|
var MSB = 128;
|
|
33
33
|
var REST = 127;
|
|
@@ -56,9 +56,9 @@ var require_encode = __commonJS({
|
|
|
56
56
|
}
|
|
57
57
|
});
|
|
58
58
|
|
|
59
|
-
// node_modules/.pnpm/varint@6.0.0/node_modules/varint/decode.js
|
|
59
|
+
// ../../../../node_modules/.pnpm/varint@6.0.0/node_modules/varint/decode.js
|
|
60
60
|
var require_decode = __commonJS({
|
|
61
|
-
"node_modules/.pnpm/varint@6.0.0/node_modules/varint/decode.js"(exports, module) {
|
|
61
|
+
"../../../../node_modules/.pnpm/varint@6.0.0/node_modules/varint/decode.js"(exports, module) {
|
|
62
62
|
module.exports = read;
|
|
63
63
|
var MSB = 128;
|
|
64
64
|
var REST = 127;
|
|
@@ -79,9 +79,9 @@ var require_decode = __commonJS({
|
|
|
79
79
|
}
|
|
80
80
|
});
|
|
81
81
|
|
|
82
|
-
// node_modules/.pnpm/varint@6.0.0/node_modules/varint/length.js
|
|
82
|
+
// ../../../../node_modules/.pnpm/varint@6.0.0/node_modules/varint/length.js
|
|
83
83
|
var require_length = __commonJS({
|
|
84
|
-
"node_modules/.pnpm/varint@6.0.0/node_modules/varint/length.js"(exports, module) {
|
|
84
|
+
"../../../../node_modules/.pnpm/varint@6.0.0/node_modules/varint/length.js"(exports, module) {
|
|
85
85
|
var N1 = Math.pow(2, 7);
|
|
86
86
|
var N2 = Math.pow(2, 14);
|
|
87
87
|
var N3 = Math.pow(2, 21);
|
|
@@ -97,9 +97,9 @@ var require_length = __commonJS({
|
|
|
97
97
|
}
|
|
98
98
|
});
|
|
99
99
|
|
|
100
|
-
// node_modules/.pnpm/varint@6.0.0/node_modules/varint/index.js
|
|
100
|
+
// ../../../../node_modules/.pnpm/varint@6.0.0/node_modules/varint/index.js
|
|
101
101
|
var require_varint = __commonJS({
|
|
102
|
-
"node_modules/.pnpm/varint@6.0.0/node_modules/varint/index.js"(exports, module) {
|
|
102
|
+
"../../../../node_modules/.pnpm/varint@6.0.0/node_modules/varint/index.js"(exports, module) {
|
|
103
103
|
module.exports = {
|
|
104
104
|
encode: require_encode(),
|
|
105
105
|
decode: require_decode(),
|
|
@@ -108,15 +108,15 @@ var require_varint = __commonJS({
|
|
|
108
108
|
}
|
|
109
109
|
});
|
|
110
110
|
|
|
111
|
-
//
|
|
111
|
+
// src/testing/test-builder.ts
|
|
112
112
|
import { pipeline } from "@dxos/node-std/stream";
|
|
113
113
|
import { waitForCondition } from "@dxos/async";
|
|
114
114
|
import { invariant as invariant5 } from "@dxos/invariant";
|
|
115
115
|
import { PublicKey as PublicKey2 } from "@dxos/keys";
|
|
116
116
|
import { log as log6 } from "@dxos/log";
|
|
117
117
|
|
|
118
|
-
//
|
|
119
|
-
import { runInContextAsync,
|
|
118
|
+
// src/teleport.ts
|
|
119
|
+
import { runInContextAsync, scheduleTask, synchronized } from "@dxos/async";
|
|
120
120
|
import { Context as Context3 } from "@dxos/context";
|
|
121
121
|
import { failUndefined as failUndefined2 } from "@dxos/debug";
|
|
122
122
|
import { invariant as invariant4 } from "@dxos/invariant";
|
|
@@ -124,31 +124,33 @@ import { PublicKey } from "@dxos/keys";
|
|
|
124
124
|
import { log as log5, logInfo as logInfo2 } from "@dxos/log";
|
|
125
125
|
import { RpcClosedError as RpcClosedError2, TimeoutError as TimeoutError2 } from "@dxos/protocols";
|
|
126
126
|
|
|
127
|
-
//
|
|
128
|
-
import {
|
|
127
|
+
// src/control-extension.ts
|
|
128
|
+
import { TimeoutError as AsyncTimeoutError, asyncTimeout, scheduleTaskInterval } from "@dxos/async";
|
|
129
129
|
import { Context } from "@dxos/context";
|
|
130
130
|
import { log } from "@dxos/log";
|
|
131
131
|
import { RpcClosedError } from "@dxos/protocols";
|
|
132
132
|
import { schema } from "@dxos/protocols/proto";
|
|
133
133
|
import { createProtoRpcPeer } from "@dxos/rpc";
|
|
134
134
|
import { Callback } from "@dxos/util";
|
|
135
|
-
var __dxlog_file = "/
|
|
135
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/core/mesh/teleport/src/control-extension.ts";
|
|
136
136
|
var HEARTBEAT_RTT_WARN_THRESH = 1e4;
|
|
137
137
|
var DEBUG_PRINT_HEARTBEAT = false;
|
|
138
138
|
var ControlExtension = class {
|
|
139
|
+
opts;
|
|
140
|
+
localPeerId;
|
|
141
|
+
remotePeerId;
|
|
142
|
+
_ctx = new Context({
|
|
143
|
+
onError: (err) => {
|
|
144
|
+
this._extensionContext.close(err);
|
|
145
|
+
}
|
|
146
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 17 });
|
|
147
|
+
onExtensionRegistered = new Callback();
|
|
148
|
+
_extensionContext;
|
|
149
|
+
_rpc;
|
|
139
150
|
constructor(opts, localPeerId, remotePeerId) {
|
|
140
151
|
this.opts = opts;
|
|
141
152
|
this.localPeerId = localPeerId;
|
|
142
153
|
this.remotePeerId = remotePeerId;
|
|
143
|
-
this._ctx = new Context({
|
|
144
|
-
onError: (err) => {
|
|
145
|
-
this._extensionContext.close(err);
|
|
146
|
-
}
|
|
147
|
-
}, {
|
|
148
|
-
F: __dxlog_file,
|
|
149
|
-
L: 31
|
|
150
|
-
});
|
|
151
|
-
this.onExtensionRegistered = new Callback();
|
|
152
154
|
}
|
|
153
155
|
async registerExtension(name) {
|
|
154
156
|
await this._rpc.rpc.Control.registerExtension({
|
|
@@ -175,12 +177,7 @@ var ControlExtension = class {
|
|
|
175
177
|
ts: request.requestTimestamp,
|
|
176
178
|
localPeerId: this.localPeerId.truncate(),
|
|
177
179
|
remotePeerId: this.remotePeerId.truncate()
|
|
178
|
-
}, {
|
|
179
|
-
F: __dxlog_file,
|
|
180
|
-
L: 69,
|
|
181
|
-
S: this,
|
|
182
|
-
C: (f, a) => f(...a)
|
|
183
|
-
});
|
|
180
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 51, S: this });
|
|
184
181
|
}
|
|
185
182
|
return {
|
|
186
183
|
requestTimestamp: request.requestTimestamp
|
|
@@ -207,36 +204,21 @@ var ControlExtension = class {
|
|
|
207
204
|
rtt: now - resp.requestTimestamp.getTime(),
|
|
208
205
|
localPeerId: this.localPeerId.truncate(),
|
|
209
206
|
remotePeerId: this.remotePeerId.truncate()
|
|
210
|
-
}, {
|
|
211
|
-
F: __dxlog_file,
|
|
212
|
-
L: 107,
|
|
213
|
-
S: this,
|
|
214
|
-
C: (f, a) => f(...a)
|
|
215
|
-
});
|
|
207
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 79, S: this });
|
|
216
208
|
} else {
|
|
217
209
|
if (DEBUG_PRINT_HEARTBEAT) {
|
|
218
210
|
log("heartbeat RTT", {
|
|
219
211
|
rtt: now - resp.requestTimestamp.getTime(),
|
|
220
212
|
localPeerId: this.localPeerId.truncate(),
|
|
221
213
|
remotePeerId: this.remotePeerId.truncate()
|
|
222
|
-
}, {
|
|
223
|
-
F: __dxlog_file,
|
|
224
|
-
L: 114,
|
|
225
|
-
S: this,
|
|
226
|
-
C: (f, a) => f(...a)
|
|
227
|
-
});
|
|
214
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 86, S: this });
|
|
228
215
|
}
|
|
229
216
|
}
|
|
230
217
|
}
|
|
231
218
|
} catch (err) {
|
|
232
219
|
const now = Date.now();
|
|
233
220
|
if (err instanceof RpcClosedError) {
|
|
234
|
-
log("ignoring RpcClosedError in heartbeat", void 0, {
|
|
235
|
-
F: __dxlog_file,
|
|
236
|
-
L: 126,
|
|
237
|
-
S: this,
|
|
238
|
-
C: (f, a) => f(...a)
|
|
239
|
-
});
|
|
221
|
+
log("ignoring RpcClosedError in heartbeat", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 98, S: this });
|
|
240
222
|
this._extensionContext.close(err);
|
|
241
223
|
return;
|
|
242
224
|
}
|
|
@@ -244,23 +226,13 @@ var ControlExtension = class {
|
|
|
244
226
|
log("timeout waiting for heartbeat response", {
|
|
245
227
|
err,
|
|
246
228
|
delay: now - reqTS.getTime()
|
|
247
|
-
}, {
|
|
248
|
-
F: __dxlog_file,
|
|
249
|
-
L: 131,
|
|
250
|
-
S: this,
|
|
251
|
-
C: (f, a) => f(...a)
|
|
252
|
-
});
|
|
229
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 103, S: this });
|
|
253
230
|
this.opts.onTimeout(err);
|
|
254
231
|
} else {
|
|
255
232
|
log.info("other error waiting for heartbeat response", {
|
|
256
233
|
err,
|
|
257
234
|
delay: now - reqTS.getTime()
|
|
258
|
-
}, {
|
|
259
|
-
F: __dxlog_file,
|
|
260
|
-
L: 134,
|
|
261
|
-
S: this,
|
|
262
|
-
C: (f, a) => f(...a)
|
|
263
|
-
});
|
|
235
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 109, S: this });
|
|
264
236
|
this.opts.onTimeout(err);
|
|
265
237
|
}
|
|
266
238
|
}
|
|
@@ -276,92 +248,74 @@ var ControlExtension = class {
|
|
|
276
248
|
}
|
|
277
249
|
};
|
|
278
250
|
|
|
279
|
-
//
|
|
251
|
+
// src/muxing/framer.ts
|
|
280
252
|
import { Duplex } from "@dxos/node-std/stream";
|
|
281
253
|
import { Event } from "@dxos/async";
|
|
282
254
|
import { invariant } from "@dxos/invariant";
|
|
283
255
|
import { log as log2 } from "@dxos/log";
|
|
284
|
-
var __dxlog_file2 = "/
|
|
256
|
+
var __dxlog_file2 = "/__w/dxos/dxos/packages/core/mesh/teleport/src/muxing/framer.ts";
|
|
285
257
|
var FRAME_LENGTH_SIZE = 2;
|
|
286
258
|
var Framer = class {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
]);
|
|
319
|
-
} else {
|
|
320
|
-
this._buffer = chunk;
|
|
321
|
-
}
|
|
322
|
-
if (this._messageCb) {
|
|
259
|
+
// private readonly _tagBuffer = Buffer.alloc(4)
|
|
260
|
+
_messageCb = void 0;
|
|
261
|
+
_subscribeCb = void 0;
|
|
262
|
+
_buffer = void 0;
|
|
263
|
+
_sendCallbacks = [];
|
|
264
|
+
_bytesSent = 0;
|
|
265
|
+
_bytesReceived = 0;
|
|
266
|
+
_writable = true;
|
|
267
|
+
drain = new Event();
|
|
268
|
+
// TODO(egorgripasov): Consider using a Transform stream if it provides better backpressure handling.
|
|
269
|
+
_stream = new Duplex({
|
|
270
|
+
objectMode: false,
|
|
271
|
+
read: () => {
|
|
272
|
+
this._processResponseQueue();
|
|
273
|
+
},
|
|
274
|
+
write: (chunk, encoding, callback) => {
|
|
275
|
+
invariant(!this._subscribeCb, "Internal Framer bug. Concurrent writes detected.", { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 29, S: this, A: ["!this._subscribeCb", "'Internal Framer bug. Concurrent writes detected.'"] });
|
|
276
|
+
this._bytesReceived += chunk.length;
|
|
277
|
+
if (this._buffer && this._buffer.length > 0) {
|
|
278
|
+
this._buffer = Buffer.concat([
|
|
279
|
+
this._buffer,
|
|
280
|
+
chunk
|
|
281
|
+
]);
|
|
282
|
+
} else {
|
|
283
|
+
this._buffer = chunk;
|
|
284
|
+
}
|
|
285
|
+
if (this._messageCb) {
|
|
286
|
+
this._popFrames();
|
|
287
|
+
callback();
|
|
288
|
+
} else {
|
|
289
|
+
this._subscribeCb = () => {
|
|
323
290
|
this._popFrames();
|
|
291
|
+
this._subscribeCb = void 0;
|
|
324
292
|
callback();
|
|
325
|
-
} else {
|
|
326
|
-
this._subscribeCb = () => {
|
|
327
|
-
this._popFrames();
|
|
328
|
-
this._subscribeCb = void 0;
|
|
329
|
-
callback();
|
|
330
|
-
};
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
});
|
|
334
|
-
this.port = {
|
|
335
|
-
send: (message) => {
|
|
336
|
-
return new Promise((resolve) => {
|
|
337
|
-
const frame = encodeFrame(message);
|
|
338
|
-
this._bytesSent += frame.length;
|
|
339
|
-
this._writable = this._stream.push(frame);
|
|
340
|
-
if (!this._writable) {
|
|
341
|
-
this._sendCallbacks.push(resolve);
|
|
342
|
-
} else {
|
|
343
|
-
resolve();
|
|
344
|
-
}
|
|
345
|
-
});
|
|
346
|
-
},
|
|
347
|
-
subscribe: (callback) => {
|
|
348
|
-
invariant(!this._messageCb, "Rpc port already has a message listener.", {
|
|
349
|
-
F: __dxlog_file2,
|
|
350
|
-
L: 79,
|
|
351
|
-
S: this,
|
|
352
|
-
A: [
|
|
353
|
-
"!this._messageCb",
|
|
354
|
-
"'Rpc port already has a message listener.'"
|
|
355
|
-
]
|
|
356
|
-
});
|
|
357
|
-
this._messageCb = callback;
|
|
358
|
-
this._subscribeCb?.();
|
|
359
|
-
return () => {
|
|
360
|
-
this._messageCb = void 0;
|
|
361
293
|
};
|
|
362
294
|
}
|
|
363
|
-
}
|
|
364
|
-
}
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
port = {
|
|
298
|
+
send: (message) => {
|
|
299
|
+
return new Promise((resolve) => {
|
|
300
|
+
const frame = encodeFrame(message);
|
|
301
|
+
this._bytesSent += frame.length;
|
|
302
|
+
this._writable = this._stream.push(frame);
|
|
303
|
+
if (!this._writable) {
|
|
304
|
+
this._sendCallbacks.push(resolve);
|
|
305
|
+
} else {
|
|
306
|
+
resolve();
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
},
|
|
310
|
+
subscribe: (callback) => {
|
|
311
|
+
invariant(!this._messageCb, "Rpc port already has a message listener.", { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 67, S: this, A: ["!this._messageCb", "'Rpc port already has a message listener.'"] });
|
|
312
|
+
this._messageCb = callback;
|
|
313
|
+
this._subscribeCb?.();
|
|
314
|
+
return () => {
|
|
315
|
+
this._messageCb = void 0;
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
};
|
|
365
319
|
get stream() {
|
|
366
320
|
return this._stream;
|
|
367
321
|
}
|
|
@@ -402,20 +356,10 @@ var Framer = class {
|
|
|
402
356
|
}
|
|
403
357
|
destroy() {
|
|
404
358
|
if (this._stream.readableLength > 0) {
|
|
405
|
-
log2("framer destroyed while there are still read bytes in the buffer.", void 0, {
|
|
406
|
-
F: __dxlog_file2,
|
|
407
|
-
L: 140,
|
|
408
|
-
S: this,
|
|
409
|
-
C: (f, a) => f(...a)
|
|
410
|
-
});
|
|
359
|
+
log2("framer destroyed while there are still read bytes in the buffer.", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 118, S: this });
|
|
411
360
|
}
|
|
412
361
|
if (this._stream.writableLength > 0) {
|
|
413
|
-
log2.warn("framer destroyed while there are still write bytes in the buffer.", void 0, {
|
|
414
|
-
F: __dxlog_file2,
|
|
415
|
-
L: 143,
|
|
416
|
-
S: this,
|
|
417
|
-
C: (f, a) => f(...a)
|
|
418
|
-
});
|
|
362
|
+
log2.warn("framer destroyed while there are still write bytes in the buffer.", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 121, S: this });
|
|
419
363
|
}
|
|
420
364
|
this._stream.destroy();
|
|
421
365
|
}
|
|
@@ -442,9 +386,9 @@ var encodeFrame = (payload) => {
|
|
|
442
386
|
return frame;
|
|
443
387
|
};
|
|
444
388
|
|
|
445
|
-
//
|
|
389
|
+
// src/muxing/muxer.ts
|
|
446
390
|
import { Duplex as Duplex2 } from "@dxos/node-std/stream";
|
|
447
|
-
import {
|
|
391
|
+
import { Event as Event3, Trigger, asyncTimeout as asyncTimeout2, scheduleTaskInterval as scheduleTaskInterval2 } from "@dxos/async";
|
|
448
392
|
import { Context as Context2 } from "@dxos/context";
|
|
449
393
|
import { failUndefined } from "@dxos/debug";
|
|
450
394
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
@@ -452,24 +396,26 @@ import { log as log4, logInfo } from "@dxos/log";
|
|
|
452
396
|
import { TimeoutError } from "@dxos/protocols";
|
|
453
397
|
import { schema as schema2 } from "@dxos/protocols/proto";
|
|
454
398
|
|
|
455
|
-
//
|
|
399
|
+
// src/muxing/balancer.ts
|
|
456
400
|
var import_varint = __toESM(require_varint(), 1);
|
|
457
401
|
import { Event as Event2 } from "@dxos/async";
|
|
458
402
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
459
403
|
import { log as log3 } from "@dxos/log";
|
|
460
|
-
var __dxlog_file3 = "/
|
|
404
|
+
var __dxlog_file3 = "/__w/dxos/dxos/packages/core/mesh/teleport/src/muxing/balancer.ts";
|
|
461
405
|
var MAX_CHUNK_SIZE = 8192;
|
|
462
406
|
var Balancer = class {
|
|
407
|
+
_sysChannelId;
|
|
408
|
+
_lastCallerIndex = 0;
|
|
409
|
+
_channels = [];
|
|
410
|
+
_framer = new Framer();
|
|
411
|
+
// TODO(egorgripasov): Will cause a memory leak if channels do not appreciate the backpressure.
|
|
412
|
+
_sendBuffers = /* @__PURE__ */ new Map();
|
|
413
|
+
_receiveBuffers = /* @__PURE__ */ new Map();
|
|
414
|
+
_sending = false;
|
|
415
|
+
incomingData = new Event2();
|
|
416
|
+
stream = this._framer.stream;
|
|
463
417
|
constructor(_sysChannelId) {
|
|
464
418
|
this._sysChannelId = _sysChannelId;
|
|
465
|
-
this._lastCallerIndex = 0;
|
|
466
|
-
this._channels = [];
|
|
467
|
-
this._framer = new Framer();
|
|
468
|
-
this._sendBuffers = /* @__PURE__ */ new Map();
|
|
469
|
-
this._receiveBuffers = /* @__PURE__ */ new Map();
|
|
470
|
-
this._sending = false;
|
|
471
|
-
this.incomingData = new Event2();
|
|
472
|
-
this.stream = this._framer.stream;
|
|
473
419
|
this._channels.push(_sysChannelId);
|
|
474
420
|
this._framer.port.subscribe(this._processIncomingMessage.bind(this));
|
|
475
421
|
}
|
|
@@ -487,21 +433,11 @@ var Balancer = class {
|
|
|
487
433
|
}
|
|
488
434
|
pushData(data, trigger, channelId) {
|
|
489
435
|
this._enqueueChunk(data, trigger, channelId);
|
|
490
|
-
this._sendChunks().catch((err) => log3.catch(err, void 0, {
|
|
491
|
-
F: __dxlog_file3,
|
|
492
|
-
L: 75,
|
|
493
|
-
S: this,
|
|
494
|
-
C: (f, a) => f(...a)
|
|
495
|
-
}));
|
|
436
|
+
this._sendChunks().catch((err) => log3.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 46, S: this }));
|
|
496
437
|
}
|
|
497
438
|
destroy() {
|
|
498
439
|
if (this._sendBuffers.size !== 0) {
|
|
499
|
-
log3.info("destroying balancer with pending calls", void 0, {
|
|
500
|
-
F: __dxlog_file3,
|
|
501
|
-
L: 80,
|
|
502
|
-
S: this,
|
|
503
|
-
C: (f, a) => f(...a)
|
|
504
|
-
});
|
|
440
|
+
log3.info("destroying balancer with pending calls", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 50, S: this });
|
|
505
441
|
}
|
|
506
442
|
this._sendBuffers.clear();
|
|
507
443
|
this._framer.destroy();
|
|
@@ -592,19 +528,9 @@ var Balancer = class {
|
|
|
592
528
|
chunk = this._getNextChunk();
|
|
593
529
|
while (chunk) {
|
|
594
530
|
if (!this._framer.writable) {
|
|
595
|
-
log3("PAUSE for drain", void 0, {
|
|
596
|
-
F: __dxlog_file3,
|
|
597
|
-
L: 179,
|
|
598
|
-
S: this,
|
|
599
|
-
C: (f, a) => f(...a)
|
|
600
|
-
});
|
|
531
|
+
log3("PAUSE for drain", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 142, S: this });
|
|
601
532
|
await this._framer.drain.waitForCount(1);
|
|
602
|
-
log3("RESUME for drain", void 0, {
|
|
603
|
-
F: __dxlog_file3,
|
|
604
|
-
L: 181,
|
|
605
|
-
S: this,
|
|
606
|
-
C: (f, a) => f(...a)
|
|
607
|
-
});
|
|
533
|
+
log3("RESUME for drain", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 144, S: this });
|
|
608
534
|
}
|
|
609
535
|
try {
|
|
610
536
|
await this._framer.port.send(chunk.msg);
|
|
@@ -612,25 +538,12 @@ var Balancer = class {
|
|
|
612
538
|
} catch (err) {
|
|
613
539
|
log3("Error sending chunk", {
|
|
614
540
|
err
|
|
615
|
-
}, {
|
|
616
|
-
F: __dxlog_file3,
|
|
617
|
-
L: 187,
|
|
618
|
-
S: this,
|
|
619
|
-
C: (f, a) => f(...a)
|
|
620
|
-
});
|
|
541
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 150, S: this });
|
|
621
542
|
chunk.trigger?.throw(err);
|
|
622
543
|
}
|
|
623
544
|
chunk = this._getNextChunk();
|
|
624
545
|
}
|
|
625
|
-
invariant2(this._sendBuffers.size === 0, "sendBuffers not empty", {
|
|
626
|
-
F: __dxlog_file3,
|
|
627
|
-
L: 192,
|
|
628
|
-
S: this,
|
|
629
|
-
A: [
|
|
630
|
-
"this._sendBuffers.size === 0",
|
|
631
|
-
"'sendBuffers not empty'"
|
|
632
|
-
]
|
|
633
|
-
});
|
|
546
|
+
invariant2(this._sendBuffers.size === 0, "sendBuffers not empty", { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 157, S: this, A: ["this._sendBuffers.size === 0", "'sendBuffers not empty'"] });
|
|
634
547
|
this._sending = false;
|
|
635
548
|
}
|
|
636
549
|
};
|
|
@@ -661,14 +574,14 @@ var decodeChunk = (data, withLength) => {
|
|
|
661
574
|
};
|
|
662
575
|
};
|
|
663
576
|
|
|
664
|
-
//
|
|
577
|
+
// src/muxing/muxer.ts
|
|
578
|
+
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/mesh/teleport/src/muxing/muxer.ts";
|
|
665
579
|
function _ts_decorate(decorators, target, key, desc) {
|
|
666
580
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
667
581
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
668
582
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
669
583
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
670
584
|
}
|
|
671
|
-
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/muxing/muxer.ts";
|
|
672
585
|
var Command = schema2.getCodecForType("dxos.mesh.muxer.Command");
|
|
673
586
|
var DEFAULT_SEND_COMMAND_TIMEOUT = 6e4;
|
|
674
587
|
var DESTROY_COMMAND_SEND_TIMEOUT = 5e3;
|
|
@@ -677,23 +590,21 @@ var MAX_SAFE_FRAME_SIZE = 1e6;
|
|
|
677
590
|
var SYSTEM_CHANNEL_ID = 0;
|
|
678
591
|
var GRACEFUL_CLOSE_TIMEOUT = 3e3;
|
|
679
592
|
var Muxer = class {
|
|
593
|
+
_balancer = new Balancer(SYSTEM_CHANNEL_ID);
|
|
594
|
+
_channelsByLocalId = /* @__PURE__ */ new Map();
|
|
595
|
+
_channelsByTag = /* @__PURE__ */ new Map();
|
|
596
|
+
_ctx = new Context2(void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 39 });
|
|
597
|
+
_sessionId;
|
|
598
|
+
_nextId = 1;
|
|
599
|
+
_closing = false;
|
|
600
|
+
_destroying = false;
|
|
601
|
+
_disposed = false;
|
|
602
|
+
_lastStats = void 0;
|
|
603
|
+
_lastChannelStats = /* @__PURE__ */ new Map();
|
|
604
|
+
afterClosed = new Event3();
|
|
605
|
+
statsUpdated = new Event3();
|
|
606
|
+
stream = this._balancer.stream;
|
|
680
607
|
constructor() {
|
|
681
|
-
this._balancer = new Balancer(SYSTEM_CHANNEL_ID);
|
|
682
|
-
this._channelsByLocalId = /* @__PURE__ */ new Map();
|
|
683
|
-
this._channelsByTag = /* @__PURE__ */ new Map();
|
|
684
|
-
this._ctx = new Context2(void 0, {
|
|
685
|
-
F: __dxlog_file4,
|
|
686
|
-
L: 108
|
|
687
|
-
});
|
|
688
|
-
this._nextId = 1;
|
|
689
|
-
this._closing = false;
|
|
690
|
-
this._destroying = false;
|
|
691
|
-
this._disposed = false;
|
|
692
|
-
this._lastStats = void 0;
|
|
693
|
-
this._lastChannelStats = /* @__PURE__ */ new Map();
|
|
694
|
-
this.afterClosed = new Event3();
|
|
695
|
-
this.statsUpdated = new Event3();
|
|
696
|
-
this.stream = this._balancer.stream;
|
|
697
608
|
this._balancer.incomingData.on(async (msg) => {
|
|
698
609
|
await this._handleCommand(Command.decode(msg));
|
|
699
610
|
});
|
|
@@ -715,15 +626,7 @@ var Muxer = class {
|
|
|
715
626
|
tag,
|
|
716
627
|
contentType: opts.contentType
|
|
717
628
|
});
|
|
718
|
-
invariant3(!channel.push, `Channel already open: ${tag}`, {
|
|
719
|
-
F: __dxlog_file4,
|
|
720
|
-
L: 152,
|
|
721
|
-
S: this,
|
|
722
|
-
A: [
|
|
723
|
-
"!channel.push",
|
|
724
|
-
"`Channel already open: ${tag}`"
|
|
725
|
-
]
|
|
726
|
-
});
|
|
629
|
+
invariant3(!channel.push, `Channel already open: ${tag}`, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 72, S: this, A: ["!channel.push", "`Channel already open: ${tag}`"] });
|
|
727
630
|
const stream = new Duplex2({
|
|
728
631
|
write: (data, encoding, callback) => {
|
|
729
632
|
this._sendData(channel, data).then(() => callback()).catch(callback);
|
|
@@ -771,15 +674,7 @@ var Muxer = class {
|
|
|
771
674
|
tag,
|
|
772
675
|
contentType: opts.contentType
|
|
773
676
|
});
|
|
774
|
-
invariant3(!channel.push, `Channel already open: ${tag}`, {
|
|
775
|
-
F: __dxlog_file4,
|
|
776
|
-
L: 212,
|
|
777
|
-
S: this,
|
|
778
|
-
A: [
|
|
779
|
-
"!channel.push",
|
|
780
|
-
"`Channel already open: ${tag}`"
|
|
781
|
-
]
|
|
782
|
-
});
|
|
677
|
+
invariant3(!channel.push, `Channel already open: ${tag}`, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 121, S: this, A: ["!channel.push", "`Channel already open: ${tag}`"] });
|
|
783
678
|
let inboundBuffer = [];
|
|
784
679
|
let callback;
|
|
785
680
|
channel.push = (data) => {
|
|
@@ -795,15 +690,7 @@ var Muxer = class {
|
|
|
795
690
|
await this._sendData(channel, data, timeout);
|
|
796
691
|
},
|
|
797
692
|
subscribe: (cb) => {
|
|
798
|
-
invariant3(!callback, "Only one subscriber is allowed", {
|
|
799
|
-
F: __dxlog_file4,
|
|
800
|
-
L: 234,
|
|
801
|
-
S: this,
|
|
802
|
-
A: [
|
|
803
|
-
"!callback",
|
|
804
|
-
"'Only one subscriber is allowed'"
|
|
805
|
-
]
|
|
806
|
-
});
|
|
693
|
+
invariant3(!callback, "Only one subscriber is allowed", { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 140, S: this, A: ["!callback", "'Only one subscriber is allowed'"] });
|
|
807
694
|
callback = cb;
|
|
808
695
|
for (const data of inboundBuffer) {
|
|
809
696
|
cb(data);
|
|
@@ -828,21 +715,11 @@ var Muxer = class {
|
|
|
828
715
|
// initiate graceful close
|
|
829
716
|
async close(err) {
|
|
830
717
|
if (this._destroying) {
|
|
831
|
-
log4("already destroying, ignoring graceful close request", void 0, {
|
|
832
|
-
F: __dxlog_file4,
|
|
833
|
-
L: 267,
|
|
834
|
-
S: this,
|
|
835
|
-
C: (f, a) => f(...a)
|
|
836
|
-
});
|
|
718
|
+
log4("already destroying, ignoring graceful close request", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 166, S: this });
|
|
837
719
|
return;
|
|
838
720
|
}
|
|
839
721
|
if (this._closing) {
|
|
840
|
-
log4("already closing, ignoring graceful close request", void 0, {
|
|
841
|
-
F: __dxlog_file4,
|
|
842
|
-
L: 271,
|
|
843
|
-
S: this,
|
|
844
|
-
C: (f, a) => f(...a)
|
|
845
|
-
});
|
|
722
|
+
log4("already closing, ignoring graceful close request", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 170, S: this });
|
|
846
723
|
return;
|
|
847
724
|
}
|
|
848
725
|
this._closing = true;
|
|
@@ -853,36 +730,23 @@ var Muxer = class {
|
|
|
853
730
|
}, SYSTEM_CHANNEL_ID, DESTROY_COMMAND_SEND_TIMEOUT).catch(async (err2) => {
|
|
854
731
|
log4("error sending close command", {
|
|
855
732
|
err: err2
|
|
856
|
-
}, {
|
|
857
|
-
F: __dxlog_file4,
|
|
858
|
-
L: 286,
|
|
859
|
-
S: this,
|
|
860
|
-
C: (f, a) => f(...a)
|
|
861
|
-
});
|
|
733
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 179, S: this });
|
|
862
734
|
await this._dispose(err2);
|
|
863
735
|
});
|
|
864
|
-
await asyncTimeout2(this._dispose(err), GRACEFUL_CLOSE_TIMEOUT, new TimeoutError(
|
|
736
|
+
await asyncTimeout2(this._dispose(err), GRACEFUL_CLOSE_TIMEOUT, new TimeoutError({
|
|
737
|
+
message: "gracefully closing muxer"
|
|
738
|
+
}));
|
|
865
739
|
}
|
|
866
740
|
// force close without confirmation
|
|
867
741
|
async destroy(err) {
|
|
868
742
|
if (this._destroying) {
|
|
869
|
-
log4("already destroying, ignoring destroy request", void 0, {
|
|
870
|
-
F: __dxlog_file4,
|
|
871
|
-
L: 299,
|
|
872
|
-
S: this,
|
|
873
|
-
C: (f, a) => f(...a)
|
|
874
|
-
});
|
|
743
|
+
log4("already destroying, ignoring destroy request", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 192, S: this });
|
|
875
744
|
return;
|
|
876
745
|
}
|
|
877
746
|
this._destroying = true;
|
|
878
747
|
void this._ctx.dispose();
|
|
879
748
|
if (this._closing) {
|
|
880
|
-
log4("destroy cancelling graceful close", void 0, {
|
|
881
|
-
F: __dxlog_file4,
|
|
882
|
-
L: 305,
|
|
883
|
-
S: this,
|
|
884
|
-
C: (f, a) => f(...a)
|
|
885
|
-
});
|
|
749
|
+
log4("destroy cancelling graceful close", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 198, S: this });
|
|
886
750
|
this._closing = false;
|
|
887
751
|
} else {
|
|
888
752
|
await this._sendCommand({
|
|
@@ -892,34 +756,19 @@ var Muxer = class {
|
|
|
892
756
|
}, SYSTEM_CHANNEL_ID).catch(async (err2) => {
|
|
893
757
|
log4("error sending courtesy close command", {
|
|
894
758
|
err: err2
|
|
895
|
-
}, {
|
|
896
|
-
F: __dxlog_file4,
|
|
897
|
-
L: 318,
|
|
898
|
-
S: this,
|
|
899
|
-
C: (f, a) => f(...a)
|
|
900
|
-
});
|
|
759
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 207, S: this });
|
|
901
760
|
});
|
|
902
761
|
}
|
|
903
762
|
this._dispose(err).catch((err2) => {
|
|
904
763
|
log4("error disposing after destroy", {
|
|
905
764
|
err: err2
|
|
906
|
-
}, {
|
|
907
|
-
F: __dxlog_file4,
|
|
908
|
-
L: 323,
|
|
909
|
-
S: this,
|
|
910
|
-
C: (f, a) => f(...a)
|
|
911
|
-
});
|
|
765
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 213, S: this });
|
|
912
766
|
});
|
|
913
767
|
}
|
|
914
768
|
// complete the termination, graceful or otherwise
|
|
915
769
|
async _dispose(err) {
|
|
916
770
|
if (this._disposed) {
|
|
917
|
-
log4("already destroyed, ignoring dispose request", void 0, {
|
|
918
|
-
F: __dxlog_file4,
|
|
919
|
-
L: 331,
|
|
920
|
-
S: this,
|
|
921
|
-
C: (f, a) => f(...a)
|
|
922
|
-
});
|
|
771
|
+
log4("already destroyed, ignoring dispose request", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 221, S: this });
|
|
923
772
|
return;
|
|
924
773
|
}
|
|
925
774
|
void this._ctx.dispose();
|
|
@@ -937,30 +786,15 @@ var Muxer = class {
|
|
|
937
786
|
if (this._disposed) {
|
|
938
787
|
log4.warn("Received command after disposed", {
|
|
939
788
|
cmd
|
|
940
|
-
}, {
|
|
941
|
-
F: __dxlog_file4,
|
|
942
|
-
L: 354,
|
|
943
|
-
S: this,
|
|
944
|
-
C: (f, a) => f(...a)
|
|
945
|
-
});
|
|
789
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 238, S: this });
|
|
946
790
|
return;
|
|
947
791
|
}
|
|
948
792
|
if (cmd.close) {
|
|
949
793
|
if (!this._closing) {
|
|
950
|
-
log4("received peer close, initiating my own graceful close", void 0, {
|
|
951
|
-
F: __dxlog_file4,
|
|
952
|
-
L: 360,
|
|
953
|
-
S: this,
|
|
954
|
-
C: (f, a) => f(...a)
|
|
955
|
-
});
|
|
794
|
+
log4("received peer close, initiating my own graceful close", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 245, S: this });
|
|
956
795
|
await this.close(new Error("received peer close"));
|
|
957
796
|
} else {
|
|
958
|
-
log4("received close from peer, already closing", void 0, {
|
|
959
|
-
F: __dxlog_file4,
|
|
960
|
-
L: 363,
|
|
961
|
-
S: this,
|
|
962
|
-
C: (f, a) => f(...a)
|
|
963
|
-
});
|
|
797
|
+
log4("received close from peer, already closing", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 248, S: this });
|
|
964
798
|
}
|
|
965
799
|
return;
|
|
966
800
|
}
|
|
@@ -984,12 +818,7 @@ var Muxer = class {
|
|
|
984
818
|
if (!stream.push) {
|
|
985
819
|
log4.warn("Received data for channel before it was opened", {
|
|
986
820
|
tag: stream.tag
|
|
987
|
-
}, {
|
|
988
|
-
F: __dxlog_file4,
|
|
989
|
-
L: 392,
|
|
990
|
-
S: this,
|
|
991
|
-
C: (f, a) => f(...a)
|
|
992
|
-
});
|
|
821
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 271, S: this });
|
|
993
822
|
return;
|
|
994
823
|
}
|
|
995
824
|
stream.push(cmd.data.data);
|
|
@@ -1039,12 +868,7 @@ var Muxer = class {
|
|
|
1039
868
|
log4.warn("frame size exceeds maximum safe value", {
|
|
1040
869
|
size: data.length,
|
|
1041
870
|
threshold: MAX_SAFE_FRAME_SIZE
|
|
1042
|
-
}, {
|
|
1043
|
-
F: __dxlog_file4,
|
|
1044
|
-
L: 442,
|
|
1045
|
-
S: this,
|
|
1046
|
-
C: (f, a) => f(...a)
|
|
1047
|
-
});
|
|
871
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 321, S: this });
|
|
1048
872
|
}
|
|
1049
873
|
channel.stats.bytesSent += data.length;
|
|
1050
874
|
if (channel.remoteId === null) {
|
|
@@ -1062,12 +886,7 @@ var Muxer = class {
|
|
|
1062
886
|
if (err) {
|
|
1063
887
|
log4.warn("destroying channel with error", {
|
|
1064
888
|
err
|
|
1065
|
-
}, {
|
|
1066
|
-
F: __dxlog_file4,
|
|
1067
|
-
L: 465,
|
|
1068
|
-
S: this,
|
|
1069
|
-
C: (f, a) => f(...a)
|
|
1070
|
-
});
|
|
889
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 341, S: this });
|
|
1071
890
|
}
|
|
1072
891
|
if (channel.destroy) {
|
|
1073
892
|
channel.destroy(err);
|
|
@@ -1130,74 +949,45 @@ _ts_decorate([
|
|
|
1130
949
|
logInfo
|
|
1131
950
|
], Muxer.prototype, "sessionIdString", null);
|
|
1132
951
|
|
|
1133
|
-
//
|
|
952
|
+
// src/teleport.ts
|
|
953
|
+
var __dxlog_file5 = "/__w/dxos/dxos/packages/core/mesh/teleport/src/teleport.ts";
|
|
1134
954
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
1135
955
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1136
956
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1137
957
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1138
958
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1139
959
|
}
|
|
1140
|
-
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/teleport.ts";
|
|
1141
960
|
var CONTROL_HEARTBEAT_INTERVAL = 1e4;
|
|
1142
961
|
var CONTROL_HEARTBEAT_TIMEOUT = 6e4;
|
|
1143
962
|
var Teleport = class {
|
|
963
|
+
initiator;
|
|
964
|
+
localPeerId;
|
|
965
|
+
remotePeerId;
|
|
966
|
+
_sessionId;
|
|
967
|
+
_ctx = new Context3({
|
|
968
|
+
onError: (err) => {
|
|
969
|
+
log5.info("error in teleport context", {
|
|
970
|
+
err
|
|
971
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 30, S: this });
|
|
972
|
+
void this.destroy(err).catch(() => {
|
|
973
|
+
log5.error("Error during destroy", err, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 34, S: this });
|
|
974
|
+
});
|
|
975
|
+
}
|
|
976
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 28 });
|
|
977
|
+
_muxer = new Muxer();
|
|
978
|
+
_control;
|
|
979
|
+
_extensions = /* @__PURE__ */ new Map();
|
|
980
|
+
_remoteExtensions = /* @__PURE__ */ new Set();
|
|
981
|
+
_open = false;
|
|
982
|
+
_destroying = false;
|
|
983
|
+
_aborting = false;
|
|
984
|
+
get isOpen() {
|
|
985
|
+
return this._open;
|
|
986
|
+
}
|
|
1144
987
|
constructor({ initiator, localPeerId, remotePeerId, ...rest }) {
|
|
1145
|
-
this
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
err
|
|
1149
|
-
}, {
|
|
1150
|
-
F: __dxlog_file5,
|
|
1151
|
-
L: 40,
|
|
1152
|
-
S: this,
|
|
1153
|
-
C: (f, a) => f(...a)
|
|
1154
|
-
});
|
|
1155
|
-
void this.destroy(err).catch(() => {
|
|
1156
|
-
log5.error("Error during destroy", err, {
|
|
1157
|
-
F: __dxlog_file5,
|
|
1158
|
-
L: 42,
|
|
1159
|
-
S: this,
|
|
1160
|
-
C: (f, a) => f(...a)
|
|
1161
|
-
});
|
|
1162
|
-
});
|
|
1163
|
-
}
|
|
1164
|
-
}, {
|
|
1165
|
-
F: __dxlog_file5,
|
|
1166
|
-
L: 38
|
|
1167
|
-
});
|
|
1168
|
-
this._muxer = new Muxer();
|
|
1169
|
-
this._extensions = /* @__PURE__ */ new Map();
|
|
1170
|
-
this._remoteExtensions = /* @__PURE__ */ new Set();
|
|
1171
|
-
this._open = false;
|
|
1172
|
-
this._destroying = false;
|
|
1173
|
-
this._aborting = false;
|
|
1174
|
-
invariant4(typeof initiator === "boolean", void 0, {
|
|
1175
|
-
F: __dxlog_file5,
|
|
1176
|
-
L: 63,
|
|
1177
|
-
S: this,
|
|
1178
|
-
A: [
|
|
1179
|
-
"typeof initiator === 'boolean'",
|
|
1180
|
-
""
|
|
1181
|
-
]
|
|
1182
|
-
});
|
|
1183
|
-
invariant4(PublicKey.isPublicKey(localPeerId), void 0, {
|
|
1184
|
-
F: __dxlog_file5,
|
|
1185
|
-
L: 64,
|
|
1186
|
-
S: this,
|
|
1187
|
-
A: [
|
|
1188
|
-
"PublicKey.isPublicKey(localPeerId)",
|
|
1189
|
-
""
|
|
1190
|
-
]
|
|
1191
|
-
});
|
|
1192
|
-
invariant4(PublicKey.isPublicKey(remotePeerId), void 0, {
|
|
1193
|
-
F: __dxlog_file5,
|
|
1194
|
-
L: 65,
|
|
1195
|
-
S: this,
|
|
1196
|
-
A: [
|
|
1197
|
-
"PublicKey.isPublicKey(remotePeerId)",
|
|
1198
|
-
""
|
|
1199
|
-
]
|
|
1200
|
-
});
|
|
988
|
+
invariant4(typeof initiator === "boolean", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 49, S: this, A: ["typeof initiator === 'boolean'", ""] });
|
|
989
|
+
invariant4(PublicKey.isPublicKey(localPeerId), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 50, S: this, A: ["PublicKey.isPublicKey(localPeerId)", ""] });
|
|
990
|
+
invariant4(PublicKey.isPublicKey(remotePeerId), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 51, S: this, A: ["PublicKey.isPublicKey(remotePeerId)", ""] });
|
|
1201
991
|
this.initiator = initiator;
|
|
1202
992
|
this.localPeerId = localPeerId;
|
|
1203
993
|
this.remotePeerId = remotePeerId;
|
|
@@ -1208,38 +998,17 @@ var Teleport = class {
|
|
|
1208
998
|
if (this._destroying || this._aborting) {
|
|
1209
999
|
return;
|
|
1210
1000
|
}
|
|
1211
|
-
log5.info("abort teleport due to onTimeout in ControlExtension", void 0, {
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
C: (f, a) => f(...a)
|
|
1216
|
-
});
|
|
1217
|
-
this.abort(new TimeoutError2("control extension")).catch((err) => log5.catch(err, void 0, {
|
|
1218
|
-
F: __dxlog_file5,
|
|
1219
|
-
L: 79,
|
|
1220
|
-
S: this,
|
|
1221
|
-
C: (f, a) => f(...a)
|
|
1222
|
-
}));
|
|
1001
|
+
log5.info("abort teleport due to onTimeout in ControlExtension", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 62, S: this });
|
|
1002
|
+
this.abort(new TimeoutError2({
|
|
1003
|
+
message: "control extension"
|
|
1004
|
+
})).catch((err) => log5.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 65, S: this }));
|
|
1223
1005
|
}
|
|
1224
1006
|
}, this.localPeerId, this.remotePeerId);
|
|
1225
1007
|
this._control.onExtensionRegistered.set(async (name) => {
|
|
1226
1008
|
log5("remote extension", {
|
|
1227
1009
|
name
|
|
1228
|
-
}, {
|
|
1229
|
-
|
|
1230
|
-
L: 87,
|
|
1231
|
-
S: this,
|
|
1232
|
-
C: (f, a) => f(...a)
|
|
1233
|
-
});
|
|
1234
|
-
invariant4(!this._remoteExtensions.has(name), "Remote extension already exists", {
|
|
1235
|
-
F: __dxlog_file5,
|
|
1236
|
-
L: 88,
|
|
1237
|
-
S: this,
|
|
1238
|
-
A: [
|
|
1239
|
-
"!this._remoteExtensions.has(name)",
|
|
1240
|
-
"'Remote extension already exists'"
|
|
1241
|
-
]
|
|
1242
|
-
});
|
|
1010
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 69, S: this });
|
|
1011
|
+
invariant4(!this._remoteExtensions.has(name), "Remote extension already exists", { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 72, S: this, A: ["!this._remoteExtensions.has(name)", "'Remote extension already exists'"] });
|
|
1243
1012
|
this._remoteExtensions.add(name);
|
|
1244
1013
|
if (this._extensions.has(name)) {
|
|
1245
1014
|
try {
|
|
@@ -1252,12 +1021,7 @@ var Teleport = class {
|
|
|
1252
1021
|
{
|
|
1253
1022
|
this._muxer.stream.on("close", async () => {
|
|
1254
1023
|
if (this._destroying || this._aborting) {
|
|
1255
|
-
log5("destroy teleport due to muxer stream close, skipping due to already destroying/aborting", void 0, {
|
|
1256
|
-
F: __dxlog_file5,
|
|
1257
|
-
L: 104,
|
|
1258
|
-
S: this,
|
|
1259
|
-
C: (f, a) => f(...a)
|
|
1260
|
-
});
|
|
1024
|
+
log5("destroy teleport due to muxer stream close, skipping due to already destroying/aborting", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 86, S: this });
|
|
1261
1025
|
return;
|
|
1262
1026
|
}
|
|
1263
1027
|
await this.destroy();
|
|
@@ -1275,17 +1039,9 @@ var Teleport = class {
|
|
|
1275
1039
|
bytesReceived: stats.bytesReceived,
|
|
1276
1040
|
bytesReceivedRate: stats.bytesReceivedRate,
|
|
1277
1041
|
channels: stats.channels
|
|
1278
|
-
}, {
|
|
1279
|
-
F: __dxlog_file5,
|
|
1280
|
-
L: 117,
|
|
1281
|
-
S: this,
|
|
1282
|
-
C: (f, a) => f(...a)
|
|
1283
|
-
});
|
|
1042
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 97, S: this });
|
|
1284
1043
|
});
|
|
1285
1044
|
}
|
|
1286
|
-
get isOpen() {
|
|
1287
|
-
return this._open;
|
|
1288
|
-
}
|
|
1289
1045
|
get sessionIdString() {
|
|
1290
1046
|
return this._sessionId ? this._sessionId.truncate() : "none";
|
|
1291
1047
|
}
|
|
@@ -1300,12 +1056,7 @@ var Teleport = class {
|
|
|
1300
1056
|
*/
|
|
1301
1057
|
async open(sessionId = PublicKey.random()) {
|
|
1302
1058
|
this._sessionId = sessionId;
|
|
1303
|
-
log5("open", void 0, {
|
|
1304
|
-
F: __dxlog_file5,
|
|
1305
|
-
L: 151,
|
|
1306
|
-
S: this,
|
|
1307
|
-
C: (f, a) => f(...a)
|
|
1308
|
-
});
|
|
1059
|
+
log5("open", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 123, S: this });
|
|
1309
1060
|
this._setExtension("dxos.mesh.teleport.control", this._control);
|
|
1310
1061
|
await this._openExtension("dxos.mesh.teleport.control");
|
|
1311
1062
|
this._open = true;
|
|
@@ -1328,12 +1079,7 @@ var Teleport = class {
|
|
|
1328
1079
|
try {
|
|
1329
1080
|
await extension.onAbort(err);
|
|
1330
1081
|
} catch (err2) {
|
|
1331
|
-
log5.catch(err2, void 0, {
|
|
1332
|
-
F: __dxlog_file5,
|
|
1333
|
-
L: 181,
|
|
1334
|
-
S: this,
|
|
1335
|
-
C: (f, a) => f(...a)
|
|
1336
|
-
});
|
|
1082
|
+
log5.catch(err2, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 147, S: this });
|
|
1337
1083
|
}
|
|
1338
1084
|
}
|
|
1339
1085
|
await this._muxer.destroy(err);
|
|
@@ -1344,12 +1090,7 @@ var Teleport = class {
|
|
|
1344
1090
|
}
|
|
1345
1091
|
log5("destroying teleport...", {
|
|
1346
1092
|
extensionsCount: this._extensions.size
|
|
1347
|
-
}, {
|
|
1348
|
-
F: __dxlog_file5,
|
|
1349
|
-
L: 194,
|
|
1350
|
-
S: this,
|
|
1351
|
-
C: (f, a) => f(...a)
|
|
1352
|
-
});
|
|
1093
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 156, S: this });
|
|
1353
1094
|
this._destroying = true;
|
|
1354
1095
|
this._open = false;
|
|
1355
1096
|
if (this._ctx.disposed) {
|
|
@@ -1360,37 +1101,17 @@ var Teleport = class {
|
|
|
1360
1101
|
try {
|
|
1361
1102
|
log5("destroying extension", {
|
|
1362
1103
|
name: extension.constructor.name
|
|
1363
|
-
}, {
|
|
1364
|
-
F: __dxlog_file5,
|
|
1365
|
-
L: 206,
|
|
1366
|
-
S: this,
|
|
1367
|
-
C: (f, a) => f(...a)
|
|
1368
|
-
});
|
|
1104
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 167, S: this });
|
|
1369
1105
|
await extension.onClose(err);
|
|
1370
1106
|
log5("destroyed extension", {
|
|
1371
1107
|
name: extension.constructor.name
|
|
1372
|
-
}, {
|
|
1373
|
-
F: __dxlog_file5,
|
|
1374
|
-
L: 208,
|
|
1375
|
-
S: this,
|
|
1376
|
-
C: (f, a) => f(...a)
|
|
1377
|
-
});
|
|
1108
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 171, S: this });
|
|
1378
1109
|
} catch (err2) {
|
|
1379
|
-
log5.catch(err2, void 0, {
|
|
1380
|
-
F: __dxlog_file5,
|
|
1381
|
-
L: 210,
|
|
1382
|
-
S: this,
|
|
1383
|
-
C: (f, a) => f(...a)
|
|
1384
|
-
});
|
|
1110
|
+
log5.catch(err2, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 175, S: this });
|
|
1385
1111
|
}
|
|
1386
1112
|
}
|
|
1387
1113
|
await this._muxer.close();
|
|
1388
|
-
log5("teleport destroyed", void 0, {
|
|
1389
|
-
F: __dxlog_file5,
|
|
1390
|
-
L: 215,
|
|
1391
|
-
S: this,
|
|
1392
|
-
C: (f, a) => f(...a)
|
|
1393
|
-
});
|
|
1114
|
+
log5("teleport destroyed", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 179, S: this });
|
|
1394
1115
|
}
|
|
1395
1116
|
addExtension(name, extension) {
|
|
1396
1117
|
if (!this._open) {
|
|
@@ -1398,12 +1119,7 @@ var Teleport = class {
|
|
|
1398
1119
|
}
|
|
1399
1120
|
log5("addExtension", {
|
|
1400
1121
|
name
|
|
1401
|
-
}, {
|
|
1402
|
-
F: __dxlog_file5,
|
|
1403
|
-
L: 223,
|
|
1404
|
-
S: this,
|
|
1405
|
-
C: (f, a) => f(...a)
|
|
1406
|
-
});
|
|
1122
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 185, S: this });
|
|
1407
1123
|
this._setExtension(name, extension);
|
|
1408
1124
|
scheduleTask(this._ctx, async () => {
|
|
1409
1125
|
try {
|
|
@@ -1422,62 +1138,25 @@ var Teleport = class {
|
|
|
1422
1138
|
}
|
|
1423
1139
|
}
|
|
1424
1140
|
_setExtension(extensionName, extension) {
|
|
1425
|
-
invariant4(!extensionName.includes("/"), "Invalid extension name", {
|
|
1426
|
-
|
|
1427
|
-
L: 247,
|
|
1428
|
-
S: this,
|
|
1429
|
-
A: [
|
|
1430
|
-
"!extensionName.includes('/')",
|
|
1431
|
-
"'Invalid extension name'"
|
|
1432
|
-
]
|
|
1433
|
-
});
|
|
1434
|
-
invariant4(!this._extensions.has(extensionName), "Extension already exists", {
|
|
1435
|
-
F: __dxlog_file5,
|
|
1436
|
-
L: 248,
|
|
1437
|
-
S: this,
|
|
1438
|
-
A: [
|
|
1439
|
-
"!this._extensions.has(extensionName)",
|
|
1440
|
-
"'Extension already exists'"
|
|
1441
|
-
]
|
|
1442
|
-
});
|
|
1141
|
+
invariant4(!extensionName.includes("/"), "Invalid extension name", { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 208, S: this, A: ["!extensionName.includes('/')", "'Invalid extension name'"] });
|
|
1142
|
+
invariant4(!this._extensions.has(extensionName), "Extension already exists", { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 209, S: this, A: ["!this._extensions.has(extensionName)", "'Extension already exists'"] });
|
|
1443
1143
|
this._extensions.set(extensionName, extension);
|
|
1444
1144
|
}
|
|
1445
1145
|
async _openExtension(extensionName) {
|
|
1446
1146
|
log5("open extension", {
|
|
1447
1147
|
extensionName
|
|
1448
|
-
}, {
|
|
1449
|
-
F: __dxlog_file5,
|
|
1450
|
-
L: 253,
|
|
1451
|
-
S: this,
|
|
1452
|
-
C: (f, a) => f(...a)
|
|
1453
|
-
});
|
|
1148
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 213, S: this });
|
|
1454
1149
|
const extension = this._extensions.get(extensionName) ?? failUndefined2();
|
|
1455
1150
|
const context = {
|
|
1456
1151
|
initiator: this.initiator,
|
|
1457
1152
|
localPeerId: this.localPeerId,
|
|
1458
1153
|
remotePeerId: this.remotePeerId,
|
|
1459
1154
|
createPort: async (channelName, opts) => {
|
|
1460
|
-
invariant4(!channelName.includes("/"), "Invalid channel name", {
|
|
1461
|
-
F: __dxlog_file5,
|
|
1462
|
-
L: 261,
|
|
1463
|
-
S: this,
|
|
1464
|
-
A: [
|
|
1465
|
-
"!channelName.includes('/')",
|
|
1466
|
-
"'Invalid channel name'"
|
|
1467
|
-
]
|
|
1468
|
-
});
|
|
1155
|
+
invariant4(!channelName.includes("/"), "Invalid channel name", { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 222, S: this, A: ["!channelName.includes('/')", "'Invalid channel name'"] });
|
|
1469
1156
|
return this._muxer.createPort(`${extensionName}/${channelName}`, opts);
|
|
1470
1157
|
},
|
|
1471
1158
|
createStream: async (channelName, opts) => {
|
|
1472
|
-
invariant4(!channelName.includes("/"), "Invalid channel name", {
|
|
1473
|
-
F: __dxlog_file5,
|
|
1474
|
-
L: 265,
|
|
1475
|
-
S: this,
|
|
1476
|
-
A: [
|
|
1477
|
-
"!channelName.includes('/')",
|
|
1478
|
-
"'Invalid channel name'"
|
|
1479
|
-
]
|
|
1480
|
-
});
|
|
1159
|
+
invariant4(!channelName.includes("/"), "Invalid channel name", { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 226, S: this, A: ["!channelName.includes('/')", "'Invalid channel name'"] });
|
|
1481
1160
|
return this._muxer.createStream(`${extensionName}/${channelName}`, opts);
|
|
1482
1161
|
},
|
|
1483
1162
|
close: (err) => {
|
|
@@ -1489,12 +1168,7 @@ var Teleport = class {
|
|
|
1489
1168
|
await extension.onOpen(context);
|
|
1490
1169
|
log5("extension opened", {
|
|
1491
1170
|
extensionName
|
|
1492
|
-
}, {
|
|
1493
|
-
F: __dxlog_file5,
|
|
1494
|
-
L: 276,
|
|
1495
|
-
S: this,
|
|
1496
|
-
C: (f, a) => f(...a)
|
|
1497
|
-
});
|
|
1171
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 236, S: this });
|
|
1498
1172
|
}
|
|
1499
1173
|
};
|
|
1500
1174
|
_ts_decorate2([
|
|
@@ -1507,12 +1181,10 @@ _ts_decorate2([
|
|
|
1507
1181
|
synchronized
|
|
1508
1182
|
], Teleport.prototype, "destroy", null);
|
|
1509
1183
|
|
|
1510
|
-
//
|
|
1511
|
-
var __dxlog_file6 = "/
|
|
1184
|
+
// src/testing/test-builder.ts
|
|
1185
|
+
var __dxlog_file6 = "/__w/dxos/dxos/packages/core/mesh/teleport/src/testing/test-builder.ts";
|
|
1512
1186
|
var TestBuilder = class {
|
|
1513
|
-
|
|
1514
|
-
this._peers = /* @__PURE__ */ new Set();
|
|
1515
|
-
}
|
|
1187
|
+
_peers = /* @__PURE__ */ new Set();
|
|
1516
1188
|
createPeer(opts) {
|
|
1517
1189
|
const peer = opts.factory();
|
|
1518
1190
|
this._peers.add(peer);
|
|
@@ -1527,33 +1199,9 @@ var TestBuilder = class {
|
|
|
1527
1199
|
await Promise.all(Array.from(this._peers).map((agent) => agent.destroy()));
|
|
1528
1200
|
}
|
|
1529
1201
|
async connect(peer1, peer2) {
|
|
1530
|
-
invariant5(peer1 !== peer2, void 0, {
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
S: this,
|
|
1534
|
-
A: [
|
|
1535
|
-
"peer1 !== peer2",
|
|
1536
|
-
""
|
|
1537
|
-
]
|
|
1538
|
-
});
|
|
1539
|
-
invariant5(this._peers.has(peer1), void 0, {
|
|
1540
|
-
F: __dxlog_file6,
|
|
1541
|
-
L: 39,
|
|
1542
|
-
S: this,
|
|
1543
|
-
A: [
|
|
1544
|
-
"this._peers.has(peer1)",
|
|
1545
|
-
""
|
|
1546
|
-
]
|
|
1547
|
-
});
|
|
1548
|
-
invariant5(this._peers.has(peer1), void 0, {
|
|
1549
|
-
F: __dxlog_file6,
|
|
1550
|
-
L: 40,
|
|
1551
|
-
S: this,
|
|
1552
|
-
A: [
|
|
1553
|
-
"this._peers.has(peer1)",
|
|
1554
|
-
""
|
|
1555
|
-
]
|
|
1556
|
-
});
|
|
1202
|
+
invariant5(peer1 !== peer2, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 26, S: this, A: ["peer1 !== peer2", ""] });
|
|
1203
|
+
invariant5(this._peers.has(peer1), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 27, S: this, A: ["this._peers.has(peer1)", ""] });
|
|
1204
|
+
invariant5(this._peers.has(peer1), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 28, S: this, A: ["this._peers.has(peer1)", ""] });
|
|
1557
1205
|
const connection1 = peer1.createConnection({
|
|
1558
1206
|
initiator: true,
|
|
1559
1207
|
remotePeerId: peer2.peerId
|
|
@@ -1573,53 +1221,13 @@ var TestBuilder = class {
|
|
|
1573
1221
|
];
|
|
1574
1222
|
}
|
|
1575
1223
|
async disconnect(peer1, peer2) {
|
|
1576
|
-
invariant5(peer1 !== peer2, void 0, {
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
S: this,
|
|
1580
|
-
A: [
|
|
1581
|
-
"peer1 !== peer2",
|
|
1582
|
-
""
|
|
1583
|
-
]
|
|
1584
|
-
});
|
|
1585
|
-
invariant5(this._peers.has(peer1), void 0, {
|
|
1586
|
-
F: __dxlog_file6,
|
|
1587
|
-
L: 53,
|
|
1588
|
-
S: this,
|
|
1589
|
-
A: [
|
|
1590
|
-
"this._peers.has(peer1)",
|
|
1591
|
-
""
|
|
1592
|
-
]
|
|
1593
|
-
});
|
|
1594
|
-
invariant5(this._peers.has(peer1), void 0, {
|
|
1595
|
-
F: __dxlog_file6,
|
|
1596
|
-
L: 54,
|
|
1597
|
-
S: this,
|
|
1598
|
-
A: [
|
|
1599
|
-
"this._peers.has(peer1)",
|
|
1600
|
-
""
|
|
1601
|
-
]
|
|
1602
|
-
});
|
|
1224
|
+
invariant5(peer1 !== peer2, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 48, S: this, A: ["peer1 !== peer2", ""] });
|
|
1225
|
+
invariant5(this._peers.has(peer1), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 49, S: this, A: ["this._peers.has(peer1)", ""] });
|
|
1226
|
+
invariant5(this._peers.has(peer1), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 50, S: this, A: ["this._peers.has(peer1)", ""] });
|
|
1603
1227
|
const connection1 = Array.from(peer1.connections).find((connection) => connection.remotePeerId.equals(peer2.peerId));
|
|
1604
1228
|
const connection2 = Array.from(peer2.connections).find((connection) => connection.remotePeerId.equals(peer1.peerId));
|
|
1605
|
-
invariant5(connection1, void 0, {
|
|
1606
|
-
|
|
1607
|
-
L: 63,
|
|
1608
|
-
S: this,
|
|
1609
|
-
A: [
|
|
1610
|
-
"connection1",
|
|
1611
|
-
""
|
|
1612
|
-
]
|
|
1613
|
-
});
|
|
1614
|
-
invariant5(connection2, void 0, {
|
|
1615
|
-
F: __dxlog_file6,
|
|
1616
|
-
L: 64,
|
|
1617
|
-
S: this,
|
|
1618
|
-
A: [
|
|
1619
|
-
"connection2",
|
|
1620
|
-
""
|
|
1621
|
-
]
|
|
1622
|
-
});
|
|
1229
|
+
invariant5(connection1, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 53, S: this, A: ["connection1", ""] });
|
|
1230
|
+
invariant5(connection2, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 54, S: this, A: ["connection2", ""] });
|
|
1623
1231
|
await Promise.all([
|
|
1624
1232
|
peer1.closeConnection(connection1),
|
|
1625
1233
|
peer2.closeConnection(connection2)
|
|
@@ -1627,9 +1235,10 @@ var TestBuilder = class {
|
|
|
1627
1235
|
}
|
|
1628
1236
|
};
|
|
1629
1237
|
var TestPeer = class {
|
|
1238
|
+
peerId;
|
|
1239
|
+
connections = /* @__PURE__ */ new Set();
|
|
1630
1240
|
constructor(peerId = PublicKey2.random()) {
|
|
1631
1241
|
this.peerId = peerId;
|
|
1632
|
-
this.connections = /* @__PURE__ */ new Set();
|
|
1633
1242
|
}
|
|
1634
1243
|
async onOpen(connection) {
|
|
1635
1244
|
}
|
|
@@ -1641,28 +1250,12 @@ var TestPeer = class {
|
|
|
1641
1250
|
return connection;
|
|
1642
1251
|
}
|
|
1643
1252
|
async openConnection(connection) {
|
|
1644
|
-
invariant5(this.connections.has(connection), void 0, {
|
|
1645
|
-
F: __dxlog_file6,
|
|
1646
|
-
L: 85,
|
|
1647
|
-
S: this,
|
|
1648
|
-
A: [
|
|
1649
|
-
"this.connections.has(connection)",
|
|
1650
|
-
""
|
|
1651
|
-
]
|
|
1652
|
-
});
|
|
1253
|
+
invariant5(this.connections.has(connection), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 75, S: this, A: ["this.connections.has(connection)", ""] });
|
|
1653
1254
|
await connection.teleport.open(PublicKey2.random());
|
|
1654
1255
|
await this.onOpen(connection);
|
|
1655
1256
|
}
|
|
1656
1257
|
async closeConnection(connection) {
|
|
1657
|
-
invariant5(this.connections.has(connection), void 0, {
|
|
1658
|
-
F: __dxlog_file6,
|
|
1659
|
-
L: 91,
|
|
1660
|
-
S: this,
|
|
1661
|
-
A: [
|
|
1662
|
-
"this.connections.has(connection)",
|
|
1663
|
-
""
|
|
1664
|
-
]
|
|
1665
|
-
});
|
|
1258
|
+
invariant5(this.connections.has(connection), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 80, S: this, A: ["this.connections.has(connection)", ""] });
|
|
1666
1259
|
await this.onClose(connection);
|
|
1667
1260
|
await connection.teleport.close();
|
|
1668
1261
|
this.connections.delete(connection);
|
|
@@ -1676,26 +1269,20 @@ var TestPeer = class {
|
|
|
1676
1269
|
var pipeStreams = (stream1, stream2) => {
|
|
1677
1270
|
pipeline(stream1, stream2, (err) => {
|
|
1678
1271
|
if (err && err.code !== "ERR_STREAM_PREMATURE_CLOSE") {
|
|
1679
|
-
log6.catch(err, void 0, {
|
|
1680
|
-
F: __dxlog_file6,
|
|
1681
|
-
L: 107,
|
|
1682
|
-
S: void 0,
|
|
1683
|
-
C: (f, a) => f(...a)
|
|
1684
|
-
});
|
|
1272
|
+
log6.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 94, S: void 0 });
|
|
1685
1273
|
}
|
|
1686
1274
|
});
|
|
1687
1275
|
pipeline(stream2, stream1, (err) => {
|
|
1688
1276
|
if (err && err.code !== "ERR_STREAM_PREMATURE_CLOSE") {
|
|
1689
|
-
log6.catch(err, void 0, {
|
|
1690
|
-
F: __dxlog_file6,
|
|
1691
|
-
L: 112,
|
|
1692
|
-
S: void 0,
|
|
1693
|
-
C: (f, a) => f(...a)
|
|
1694
|
-
});
|
|
1277
|
+
log6.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 99, S: void 0 });
|
|
1695
1278
|
}
|
|
1696
1279
|
});
|
|
1697
1280
|
};
|
|
1698
1281
|
var TestConnection = class {
|
|
1282
|
+
localPeerId;
|
|
1283
|
+
remotePeerId;
|
|
1284
|
+
initiator;
|
|
1285
|
+
teleport;
|
|
1699
1286
|
constructor(localPeerId, remotePeerId, initiator) {
|
|
1700
1287
|
this.localPeerId = localPeerId;
|
|
1701
1288
|
this.remotePeerId = remotePeerId;
|
|
@@ -1713,19 +1300,22 @@ var TestConnection = class {
|
|
|
1713
1300
|
}
|
|
1714
1301
|
};
|
|
1715
1302
|
|
|
1716
|
-
//
|
|
1717
|
-
import {
|
|
1303
|
+
// src/testing/test-extension.ts
|
|
1304
|
+
import { Trigger as Trigger2, asyncTimeout as asyncTimeout3 } from "@dxos/async";
|
|
1718
1305
|
import { invariant as invariant6 } from "@dxos/invariant";
|
|
1719
1306
|
import { log as log7 } from "@dxos/log";
|
|
1720
1307
|
import { schema as schema3 } from "@dxos/protocols/proto";
|
|
1721
1308
|
import { createProtoRpcPeer as createProtoRpcPeer2 } from "@dxos/rpc";
|
|
1722
|
-
var __dxlog_file7 = "/
|
|
1309
|
+
var __dxlog_file7 = "/__w/dxos/dxos/packages/core/mesh/teleport/src/testing/test-extension.ts";
|
|
1723
1310
|
var TestExtension = class {
|
|
1311
|
+
callbacks;
|
|
1312
|
+
open = new Trigger2();
|
|
1313
|
+
closed = new Trigger2();
|
|
1314
|
+
aborted = new Trigger2();
|
|
1315
|
+
extensionContext;
|
|
1316
|
+
_rpc;
|
|
1724
1317
|
constructor(callbacks = {}) {
|
|
1725
1318
|
this.callbacks = callbacks;
|
|
1726
|
-
this.open = new Trigger2();
|
|
1727
|
-
this.closed = new Trigger2();
|
|
1728
|
-
this.aborted = new Trigger2();
|
|
1729
1319
|
}
|
|
1730
1320
|
get remotePeerId() {
|
|
1731
1321
|
return this.extensionContext?.remotePeerId;
|
|
@@ -1734,12 +1324,7 @@ var TestExtension = class {
|
|
|
1734
1324
|
log7("onOpen", {
|
|
1735
1325
|
localPeerId: context.localPeerId,
|
|
1736
1326
|
remotePeerId: context.remotePeerId
|
|
1737
|
-
}, {
|
|
1738
|
-
F: __dxlog_file7,
|
|
1739
|
-
L: 34,
|
|
1740
|
-
S: this,
|
|
1741
|
-
C: (f, a) => f(...a)
|
|
1742
|
-
});
|
|
1327
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 23, S: this });
|
|
1743
1328
|
this.extensionContext = context;
|
|
1744
1329
|
this._rpc = createProtoRpcPeer2({
|
|
1745
1330
|
port: await context.createPort("rpc", {
|
|
@@ -1771,12 +1356,7 @@ var TestExtension = class {
|
|
|
1771
1356
|
async onClose(err) {
|
|
1772
1357
|
log7("onClose", {
|
|
1773
1358
|
err
|
|
1774
|
-
}, {
|
|
1775
|
-
F: __dxlog_file7,
|
|
1776
|
-
L: 68,
|
|
1777
|
-
S: this,
|
|
1778
|
-
C: (f, a) => f(...a)
|
|
1779
|
-
});
|
|
1359
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 57, S: this });
|
|
1780
1360
|
await this.callbacks.onClose?.();
|
|
1781
1361
|
this.closed.wake();
|
|
1782
1362
|
await this._rpc?.close();
|
|
@@ -1784,12 +1364,7 @@ var TestExtension = class {
|
|
|
1784
1364
|
async onAbort(err) {
|
|
1785
1365
|
log7("onAbort", {
|
|
1786
1366
|
err
|
|
1787
|
-
}, {
|
|
1788
|
-
F: __dxlog_file7,
|
|
1789
|
-
L: 75,
|
|
1790
|
-
S: this,
|
|
1791
|
-
C: (f, a) => f(...a)
|
|
1792
|
-
});
|
|
1367
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 65, S: this });
|
|
1793
1368
|
await this.callbacks.onAbort?.();
|
|
1794
1369
|
this.aborted.wake();
|
|
1795
1370
|
await this._rpc?.abort();
|
|
@@ -1801,15 +1376,7 @@ var TestExtension = class {
|
|
|
1801
1376
|
const res = await asyncTimeout3(this._rpc.rpc.TestService.testCall({
|
|
1802
1377
|
data: message
|
|
1803
1378
|
}), 1500);
|
|
1804
|
-
invariant6(res.data === message, void 0, {
|
|
1805
|
-
F: __dxlog_file7,
|
|
1806
|
-
L: 84,
|
|
1807
|
-
S: this,
|
|
1808
|
-
A: [
|
|
1809
|
-
"res.data === message",
|
|
1810
|
-
""
|
|
1811
|
-
]
|
|
1812
|
-
});
|
|
1379
|
+
invariant6(res.data === message, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 79, S: this, A: ["res.data === message", ""] });
|
|
1813
1380
|
}
|
|
1814
1381
|
/**
|
|
1815
1382
|
* Force-close the connection.
|
|
@@ -1819,35 +1386,30 @@ var TestExtension = class {
|
|
|
1819
1386
|
}
|
|
1820
1387
|
};
|
|
1821
1388
|
|
|
1822
|
-
//
|
|
1389
|
+
// src/testing/test-extension-with-streams.ts
|
|
1823
1390
|
import { randomBytes } from "@dxos/node-std/crypto";
|
|
1824
1391
|
import { Trigger as Trigger3 } from "@dxos/async";
|
|
1825
1392
|
import { invariant as invariant7 } from "@dxos/invariant";
|
|
1826
1393
|
import { log as log8 } from "@dxos/log";
|
|
1827
1394
|
import { schema as schema4 } from "@dxos/protocols/proto";
|
|
1828
1395
|
import { createProtoRpcPeer as createProtoRpcPeer3 } from "@dxos/rpc";
|
|
1829
|
-
var __dxlog_file8 = "/
|
|
1396
|
+
var __dxlog_file8 = "/__w/dxos/dxos/packages/core/mesh/teleport/src/testing/test-extension-with-streams.ts";
|
|
1830
1397
|
var TestExtensionWithStreams = class {
|
|
1398
|
+
callbacks;
|
|
1399
|
+
open = new Trigger3();
|
|
1400
|
+
closed = new Trigger3();
|
|
1401
|
+
aborted = new Trigger3();
|
|
1402
|
+
_streams = /* @__PURE__ */ new Map();
|
|
1403
|
+
extensionContext;
|
|
1404
|
+
_rpc;
|
|
1831
1405
|
constructor(callbacks = {}) {
|
|
1832
1406
|
this.callbacks = callbacks;
|
|
1833
|
-
this.open = new Trigger3();
|
|
1834
|
-
this.closed = new Trigger3();
|
|
1835
|
-
this.aborted = new Trigger3();
|
|
1836
|
-
this._streams = /* @__PURE__ */ new Map();
|
|
1837
1407
|
}
|
|
1838
1408
|
get remotePeerId() {
|
|
1839
1409
|
return this.extensionContext?.remotePeerId;
|
|
1840
1410
|
}
|
|
1841
1411
|
async _openStream(streamTag, interval = 5, chunkSize = 2048) {
|
|
1842
|
-
invariant7(!this._streams.has(streamTag), `Stream already exists: ${streamTag}`, {
|
|
1843
|
-
F: __dxlog_file8,
|
|
1844
|
-
L: 39,
|
|
1845
|
-
S: this,
|
|
1846
|
-
A: [
|
|
1847
|
-
"!this._streams.has(streamTag)",
|
|
1848
|
-
"`Stream already exists: ${streamTag}`"
|
|
1849
|
-
]
|
|
1850
|
-
});
|
|
1412
|
+
invariant7(!this._streams.has(streamTag), `Stream already exists: ${streamTag}`, { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 25, S: this, A: ["!this._streams.has(streamTag)", "`Stream already exists: ${streamTag}`"] });
|
|
1851
1413
|
const networkStream = await this.extensionContext.createStream(streamTag, {
|
|
1852
1414
|
contentType: "application/x-test-stream"
|
|
1853
1415
|
});
|
|
@@ -1896,24 +1458,11 @@ var TestExtensionWithStreams = class {
|
|
|
1896
1458
|
receiveErrors,
|
|
1897
1459
|
from: this.extensionContext?.localPeerId,
|
|
1898
1460
|
to: this.extensionContext?.remotePeerId
|
|
1899
|
-
}, {
|
|
1900
|
-
F: __dxlog_file8,
|
|
1901
|
-
L: 93,
|
|
1902
|
-
S: this,
|
|
1903
|
-
C: (f, a) => f(...a)
|
|
1904
|
-
});
|
|
1461
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 67, S: this });
|
|
1905
1462
|
}, 100);
|
|
1906
1463
|
}
|
|
1907
1464
|
_closeStream(streamTag) {
|
|
1908
|
-
invariant7(this._streams.has(streamTag), `Stream does not exist: ${streamTag}`, {
|
|
1909
|
-
F: __dxlog_file8,
|
|
1910
|
-
L: 106,
|
|
1911
|
-
S: this,
|
|
1912
|
-
A: [
|
|
1913
|
-
"this._streams.has(streamTag)",
|
|
1914
|
-
"`Stream does not exist: ${streamTag}`"
|
|
1915
|
-
]
|
|
1916
|
-
});
|
|
1465
|
+
invariant7(this._streams.has(streamTag), `Stream does not exist: ${streamTag}`, { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 79, S: this, A: ["this._streams.has(streamTag)", "`Stream does not exist: ${streamTag}`"] });
|
|
1917
1466
|
const stream = this._streams.get(streamTag);
|
|
1918
1467
|
clearTimeout(stream.timer);
|
|
1919
1468
|
clearTimeout(stream.reportingTimer);
|
|
@@ -1932,12 +1481,7 @@ var TestExtensionWithStreams = class {
|
|
|
1932
1481
|
log8("onOpen", {
|
|
1933
1482
|
localPeerId: context.localPeerId,
|
|
1934
1483
|
remotePeerId: context.remotePeerId
|
|
1935
|
-
}, {
|
|
1936
|
-
F: __dxlog_file8,
|
|
1937
|
-
L: 128,
|
|
1938
|
-
S: this,
|
|
1939
|
-
C: (f, a) => f(...a)
|
|
1940
|
-
});
|
|
1484
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 95, S: this });
|
|
1941
1485
|
this.extensionContext = context;
|
|
1942
1486
|
this._rpc = createProtoRpcPeer3({
|
|
1943
1487
|
port: await context.createPort("rpc", {
|
|
@@ -1981,23 +1525,13 @@ var TestExtensionWithStreams = class {
|
|
|
1981
1525
|
async onClose(err) {
|
|
1982
1526
|
log8("onClose", {
|
|
1983
1527
|
err
|
|
1984
|
-
}, {
|
|
1985
|
-
F: __dxlog_file8,
|
|
1986
|
-
L: 179,
|
|
1987
|
-
S: this,
|
|
1988
|
-
C: (f, a) => f(...a)
|
|
1989
|
-
});
|
|
1528
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 140, S: this });
|
|
1990
1529
|
await this.callbacks.onClose?.();
|
|
1991
1530
|
this.closed.wake();
|
|
1992
1531
|
for (const [streamTag, stream] of Object.entries(this._streams)) {
|
|
1993
1532
|
log8("closing stream", {
|
|
1994
1533
|
streamTag
|
|
1995
|
-
}, {
|
|
1996
|
-
F: __dxlog_file8,
|
|
1997
|
-
L: 183,
|
|
1998
|
-
S: this,
|
|
1999
|
-
C: (f, a) => f(...a)
|
|
2000
|
-
});
|
|
1534
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 146, S: this });
|
|
2001
1535
|
clearTimeout(stream.interval);
|
|
2002
1536
|
stream.networkStream.destroy();
|
|
2003
1537
|
}
|
|
@@ -2006,12 +1540,7 @@ var TestExtensionWithStreams = class {
|
|
|
2006
1540
|
async onAbort(err) {
|
|
2007
1541
|
log8("onAbort", {
|
|
2008
1542
|
err
|
|
2009
|
-
}, {
|
|
2010
|
-
F: __dxlog_file8,
|
|
2011
|
-
L: 191,
|
|
2012
|
-
S: this,
|
|
2013
|
-
C: (f, a) => f(...a)
|
|
2014
|
-
});
|
|
1543
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 155, S: this });
|
|
2015
1544
|
await this.callbacks.onAbort?.();
|
|
2016
1545
|
this.aborted.wake();
|
|
2017
1546
|
await this._rpc?.abort();
|
|
@@ -2028,15 +1557,7 @@ var TestExtensionWithStreams = class {
|
|
|
2028
1557
|
streamLoadInterval,
|
|
2029
1558
|
streamLoadChunkSize
|
|
2030
1559
|
});
|
|
2031
|
-
invariant7(data === streamTag, void 0, {
|
|
2032
|
-
F: __dxlog_file8,
|
|
2033
|
-
L: 207,
|
|
2034
|
-
S: this,
|
|
2035
|
-
A: [
|
|
2036
|
-
"data === streamTag",
|
|
2037
|
-
""
|
|
2038
|
-
]
|
|
2039
|
-
});
|
|
1560
|
+
invariant7(data === streamTag, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 174, S: this, A: ["data === streamTag", ""] });
|
|
2040
1561
|
await this._openStream(streamTag, streamLoadInterval, streamLoadChunkSize);
|
|
2041
1562
|
return streamTag;
|
|
2042
1563
|
}
|
|
@@ -2047,15 +1568,7 @@ var TestExtensionWithStreams = class {
|
|
|
2047
1568
|
const { data, bytesSent, bytesReceived, sendErrors, receiveErrors, runningTime } = await this._rpc.rpc.TestServiceWithStreams.closeTestStream({
|
|
2048
1569
|
data: streamTag
|
|
2049
1570
|
});
|
|
2050
|
-
invariant7(data === streamTag, void 0, {
|
|
2051
|
-
F: __dxlog_file8,
|
|
2052
|
-
L: 220,
|
|
2053
|
-
S: this,
|
|
2054
|
-
A: [
|
|
2055
|
-
"data === streamTag",
|
|
2056
|
-
""
|
|
2057
|
-
]
|
|
2058
|
-
});
|
|
1571
|
+
invariant7(data === streamTag, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 185, S: this, A: ["data === streamTag", ""] });
|
|
2059
1572
|
const local = this._closeStream(streamTag);
|
|
2060
1573
|
return {
|
|
2061
1574
|
streamTag,
|
|
@@ -2091,4 +1604,4 @@ export {
|
|
|
2091
1604
|
TestExtension,
|
|
2092
1605
|
TestExtensionWithStreams
|
|
2093
1606
|
};
|
|
2094
|
-
//# sourceMappingURL=chunk-
|
|
1607
|
+
//# sourceMappingURL=chunk-LECANKBC.mjs.map
|