@dxos/teleport 0.1.55-main.ff36828 → 0.1.55
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-HCC6HY7F.mjs → chunk-WUEX3RV3.mjs} +280 -144
- package/dist/lib/browser/chunk-WUEX3RV3.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +1 -1
- package/dist/lib/node/index.cjs +295 -159
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +295 -159
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/types/src/muxing/balancer.d.ts +22 -8
- package/dist/types/src/muxing/balancer.d.ts.map +1 -1
- package/dist/types/src/muxing/balancer.test.d.ts +2 -0
- package/dist/types/src/muxing/balancer.test.d.ts.map +1 -0
- package/dist/types/src/muxing/framer.d.ts +5 -2
- package/dist/types/src/muxing/framer.d.ts.map +1 -1
- package/dist/types/src/muxing/muxer.d.ts +8 -4
- package/dist/types/src/muxing/muxer.d.ts.map +1 -1
- package/dist/types/src/teleport.d.ts +2 -3
- package/dist/types/src/teleport.d.ts.map +1 -1
- package/dist/types/src/testing/test-extension-with-streams.d.ts.map +1 -1
- package/package.json +11 -11
- package/src/muxing/balancer.test.ts +50 -0
- package/src/muxing/balancer.ts +127 -34
- package/src/muxing/framer.test.ts +1 -15
- package/src/muxing/framer.ts +43 -35
- package/src/muxing/muxer.ts +29 -16
- package/src/teleport.ts +22 -14
- package/src/testing/test-extension-with-streams.ts +16 -0
- package/dist/lib/browser/chunk-HCC6HY7F.mjs.map +0 -7
|
@@ -4,7 +4,7 @@ import "@dxos/node-std/globals";
|
|
|
4
4
|
import { pipeline } from "@dxos/node-std/stream";
|
|
5
5
|
import invariant4 from "tiny-invariant";
|
|
6
6
|
import { PublicKey as PublicKey2 } from "@dxos/keys";
|
|
7
|
-
import { log as
|
|
7
|
+
import { log as log4 } from "@dxos/log";
|
|
8
8
|
|
|
9
9
|
// packages/core/mesh/teleport/src/teleport.ts
|
|
10
10
|
import invariant3 from "tiny-invariant";
|
|
@@ -12,7 +12,7 @@ import { asyncTimeout, scheduleTaskInterval as scheduleTaskInterval2, runInConte
|
|
|
12
12
|
import { Context as Context2 } from "@dxos/context";
|
|
13
13
|
import { failUndefined as failUndefined2 } from "@dxos/debug";
|
|
14
14
|
import { PublicKey } from "@dxos/keys";
|
|
15
|
-
import { log as
|
|
15
|
+
import { log as log3 } from "@dxos/log";
|
|
16
16
|
import { schema as schema2, RpcClosedError } from "@dxos/protocols";
|
|
17
17
|
import { createProtoRpcPeer } from "@dxos/rpc";
|
|
18
18
|
import { Callback } from "@dxos/util";
|
|
@@ -20,16 +20,20 @@ import { Callback } from "@dxos/util";
|
|
|
20
20
|
// packages/core/mesh/teleport/src/muxing/framer.ts
|
|
21
21
|
import { Duplex } from "@dxos/node-std/stream";
|
|
22
22
|
import invariant from "tiny-invariant";
|
|
23
|
-
|
|
23
|
+
var FRAME_LENGTH_SIZE = 2;
|
|
24
24
|
var Framer = class {
|
|
25
25
|
constructor() {
|
|
26
|
-
this.
|
|
26
|
+
this._sendCallbacks = [];
|
|
27
|
+
this._bytesSent = 0;
|
|
28
|
+
this._bytesReceived = 0;
|
|
27
29
|
this._stream = new Duplex({
|
|
28
30
|
objectMode: false,
|
|
29
31
|
read: () => {
|
|
32
|
+
this._processResponseQueue();
|
|
30
33
|
},
|
|
31
34
|
write: (chunk, encoding, callback) => {
|
|
32
35
|
invariant(!this._subscribeCb, "Internal Framer bug. Concurrent writes detected.");
|
|
36
|
+
this._bytesReceived += chunk.length;
|
|
33
37
|
if (this._buffer && this._buffer.length > 0) {
|
|
34
38
|
this._buffer = Buffer.concat([
|
|
35
39
|
this._buffer,
|
|
@@ -53,11 +57,13 @@ var Framer = class {
|
|
|
53
57
|
this.port = {
|
|
54
58
|
send: (message) => {
|
|
55
59
|
return new Promise((resolve) => {
|
|
56
|
-
const
|
|
60
|
+
const frame = encodeFrame(message);
|
|
61
|
+
this._bytesSent += frame.length;
|
|
62
|
+
const canContinue = this._stream.push(frame);
|
|
57
63
|
if (!canContinue) {
|
|
58
|
-
this.
|
|
64
|
+
this._sendCallbacks.push(resolve);
|
|
59
65
|
} else {
|
|
60
|
-
|
|
66
|
+
resolve();
|
|
61
67
|
}
|
|
62
68
|
});
|
|
63
69
|
},
|
|
@@ -71,14 +77,19 @@ var Framer = class {
|
|
|
71
77
|
};
|
|
72
78
|
}
|
|
73
79
|
};
|
|
74
|
-
this.stream.on("drain", this._processResponseQueue.bind(this));
|
|
75
80
|
}
|
|
76
81
|
get stream() {
|
|
77
82
|
return this._stream;
|
|
78
83
|
}
|
|
84
|
+
get bytesSent() {
|
|
85
|
+
return this._bytesSent;
|
|
86
|
+
}
|
|
87
|
+
get bytesReceived() {
|
|
88
|
+
return this._bytesReceived;
|
|
89
|
+
}
|
|
79
90
|
_processResponseQueue() {
|
|
80
|
-
const responseQueue = this.
|
|
81
|
-
this.
|
|
91
|
+
const responseQueue = this._sendCallbacks;
|
|
92
|
+
this._sendCallbacks = [];
|
|
82
93
|
responseQueue.forEach((cb) => cb());
|
|
83
94
|
}
|
|
84
95
|
/**
|
|
@@ -101,139 +112,214 @@ var Framer = class {
|
|
|
101
112
|
}
|
|
102
113
|
}
|
|
103
114
|
destroy() {
|
|
104
|
-
this._stream.removeAllListeners("drain");
|
|
105
115
|
this._stream.destroy();
|
|
106
116
|
}
|
|
107
117
|
};
|
|
108
118
|
var decodeFrame = (buffer, offset) => {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return void 0;
|
|
123
|
-
} else {
|
|
124
|
-
throw err;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
119
|
+
if (buffer.length < offset + FRAME_LENGTH_SIZE) {
|
|
120
|
+
return void 0;
|
|
121
|
+
}
|
|
122
|
+
const frameLength = buffer.readUInt16BE(offset);
|
|
123
|
+
const bytesConsumed = FRAME_LENGTH_SIZE + frameLength;
|
|
124
|
+
if (buffer.length < offset + bytesConsumed) {
|
|
125
|
+
return void 0;
|
|
126
|
+
}
|
|
127
|
+
const payload = buffer.subarray(offset + FRAME_LENGTH_SIZE, offset + bytesConsumed);
|
|
128
|
+
return {
|
|
129
|
+
payload,
|
|
130
|
+
bytesConsumed
|
|
131
|
+
};
|
|
127
132
|
};
|
|
128
133
|
var encodeFrame = (payload) => {
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
frame.set(payload, tagLength);
|
|
134
|
+
const frame = Buffer.allocUnsafe(FRAME_LENGTH_SIZE + payload.length);
|
|
135
|
+
frame.writeUInt16BE(payload.length, 0);
|
|
136
|
+
frame.set(payload, FRAME_LENGTH_SIZE);
|
|
133
137
|
return frame;
|
|
134
138
|
};
|
|
135
139
|
|
|
136
140
|
// packages/core/mesh/teleport/src/muxing/muxer.ts
|
|
137
141
|
import { Duplex as Duplex2 } from "@dxos/node-std/stream";
|
|
138
142
|
import invariant2 from "tiny-invariant";
|
|
139
|
-
import { scheduleTaskInterval, Event, Trigger } from "@dxos/async";
|
|
143
|
+
import { scheduleTaskInterval, Event as Event2, Trigger } from "@dxos/async";
|
|
140
144
|
import { Context } from "@dxos/context";
|
|
141
145
|
import { failUndefined } from "@dxos/debug";
|
|
142
|
-
import { log } from "@dxos/log";
|
|
146
|
+
import { log as log2 } from "@dxos/log";
|
|
143
147
|
import { schema } from "@dxos/protocols";
|
|
144
148
|
|
|
145
149
|
// packages/core/mesh/teleport/src/muxing/balancer.ts
|
|
150
|
+
import * as varint from "varint";
|
|
151
|
+
import { Event } from "@dxos/async";
|
|
152
|
+
import { log } from "@dxos/log";
|
|
153
|
+
var __dxlog_file = "/mnt/ramdisk/work/packages/core/mesh/teleport/src/muxing/balancer.ts";
|
|
154
|
+
var MAX_CHUNK_SIZE = 8192;
|
|
146
155
|
var Balancer = class {
|
|
147
|
-
constructor(
|
|
148
|
-
this._port = _port;
|
|
156
|
+
constructor(_sysChannelId) {
|
|
149
157
|
this._sysChannelId = _sysChannelId;
|
|
150
158
|
this._lastCallerIndex = 0;
|
|
151
159
|
this._channels = [];
|
|
152
|
-
this.
|
|
160
|
+
this._framer = new Framer();
|
|
161
|
+
this._sendBuffers = /* @__PURE__ */ new Map();
|
|
162
|
+
this._receiveBuffers = /* @__PURE__ */ new Map();
|
|
163
|
+
this.incomingData = new Event();
|
|
164
|
+
this.stream = this._framer.stream;
|
|
153
165
|
this._channels.push(_sysChannelId);
|
|
166
|
+
this._framer.port.subscribe(this._processIncomingMessage.bind(this));
|
|
167
|
+
}
|
|
168
|
+
get bytesSent() {
|
|
169
|
+
return this._framer.bytesSent;
|
|
170
|
+
}
|
|
171
|
+
get bytesReceived() {
|
|
172
|
+
return this._framer.bytesReceived;
|
|
154
173
|
}
|
|
155
174
|
addChannel(channel) {
|
|
156
175
|
this._channels.push(channel);
|
|
157
176
|
}
|
|
158
|
-
|
|
159
|
-
const noCalls = this.
|
|
177
|
+
pushData(data, trigger, channelId) {
|
|
178
|
+
const noCalls = this._sendBuffers.size === 0;
|
|
160
179
|
if (!this._channels.includes(channelId)) {
|
|
161
180
|
throw new Error(`Unknown channel ${channelId}`);
|
|
162
181
|
}
|
|
163
|
-
if (!this.
|
|
164
|
-
this.
|
|
182
|
+
if (!this._sendBuffers.has(channelId)) {
|
|
183
|
+
this._sendBuffers.set(channelId, []);
|
|
165
184
|
}
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
185
|
+
const sendBuffer = this._sendBuffers.get(channelId);
|
|
186
|
+
const chunks = [];
|
|
187
|
+
for (let idx = 0; idx < data.length; idx += MAX_CHUNK_SIZE) {
|
|
188
|
+
chunks.push(data.subarray(idx, idx + MAX_CHUNK_SIZE));
|
|
189
|
+
}
|
|
190
|
+
chunks.forEach((chunk, index) => {
|
|
191
|
+
const msg = encodeChunk({
|
|
192
|
+
chunk,
|
|
193
|
+
channelId,
|
|
194
|
+
dataLength: index === 0 ? data.length : void 0
|
|
195
|
+
});
|
|
196
|
+
sendBuffer.push({
|
|
197
|
+
msg,
|
|
198
|
+
trigger: index === chunks.length - 1 ? trigger : void 0
|
|
199
|
+
});
|
|
170
200
|
});
|
|
171
201
|
if (noCalls) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
202
|
+
this._sendChunks().catch((err) => log.catch(err, void 0, {
|
|
203
|
+
F: __dxlog_file,
|
|
204
|
+
L: 96,
|
|
205
|
+
S: this,
|
|
206
|
+
C: (f, a) => f(...a)
|
|
207
|
+
}));
|
|
175
208
|
}
|
|
176
209
|
}
|
|
177
210
|
destroy() {
|
|
178
|
-
this.
|
|
211
|
+
this._sendBuffers.clear();
|
|
212
|
+
this._framer.destroy();
|
|
213
|
+
}
|
|
214
|
+
_processIncomingMessage(msg) {
|
|
215
|
+
const { channelId, dataLength, chunk } = decodeChunk(msg, (channelId2) => !this._receiveBuffers.has(channelId2));
|
|
216
|
+
if (!this._receiveBuffers.has(channelId)) {
|
|
217
|
+
if (chunk.length < dataLength) {
|
|
218
|
+
this._receiveBuffers.set(channelId, {
|
|
219
|
+
buffer: Buffer.from(chunk),
|
|
220
|
+
msgLength: dataLength
|
|
221
|
+
});
|
|
222
|
+
} else {
|
|
223
|
+
this.incomingData.emit(chunk);
|
|
224
|
+
}
|
|
225
|
+
} else {
|
|
226
|
+
const channelBuffer = this._receiveBuffers.get(channelId);
|
|
227
|
+
channelBuffer.buffer = Buffer.concat([
|
|
228
|
+
channelBuffer.buffer,
|
|
229
|
+
chunk
|
|
230
|
+
]);
|
|
231
|
+
if (channelBuffer.buffer.length < channelBuffer.msgLength) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
const msg2 = channelBuffer.buffer;
|
|
235
|
+
this._receiveBuffers.delete(channelId);
|
|
236
|
+
this.incomingData.emit(msg2);
|
|
237
|
+
}
|
|
179
238
|
}
|
|
180
239
|
_getNextCallerId() {
|
|
181
|
-
if (this.
|
|
240
|
+
if (this._sendBuffers.has(this._sysChannelId)) {
|
|
182
241
|
return this._sysChannelId;
|
|
183
242
|
}
|
|
184
243
|
const index = this._lastCallerIndex;
|
|
185
244
|
this._lastCallerIndex = (this._lastCallerIndex + 1) % this._channels.length;
|
|
186
245
|
return this._channels[index];
|
|
187
246
|
}
|
|
188
|
-
|
|
189
|
-
let
|
|
190
|
-
while (!
|
|
247
|
+
_getNextChunk() {
|
|
248
|
+
let chunk;
|
|
249
|
+
while (!chunk) {
|
|
191
250
|
const channelId = this._getNextCallerId();
|
|
192
|
-
const
|
|
193
|
-
if (!
|
|
251
|
+
const sendBuffer = this._sendBuffers.get(channelId);
|
|
252
|
+
if (!sendBuffer) {
|
|
194
253
|
continue;
|
|
195
254
|
}
|
|
196
|
-
|
|
197
|
-
if (
|
|
198
|
-
this.
|
|
255
|
+
chunk = sendBuffer.shift();
|
|
256
|
+
if (sendBuffer.length === 0) {
|
|
257
|
+
this._sendBuffers.delete(channelId);
|
|
199
258
|
}
|
|
200
259
|
}
|
|
201
|
-
return
|
|
260
|
+
return chunk;
|
|
202
261
|
}
|
|
203
|
-
async
|
|
204
|
-
|
|
262
|
+
async _sendChunks() {
|
|
263
|
+
var _a, _b;
|
|
264
|
+
if (this._sendBuffers.size === 0) {
|
|
205
265
|
return;
|
|
206
266
|
}
|
|
207
|
-
const
|
|
267
|
+
const chunk = this._getNextChunk();
|
|
208
268
|
try {
|
|
209
|
-
await this.
|
|
210
|
-
|
|
269
|
+
await this._framer.port.send(chunk.msg);
|
|
270
|
+
(_a = chunk.trigger) == null ? void 0 : _a.wake();
|
|
211
271
|
} catch (err) {
|
|
212
|
-
|
|
272
|
+
(_b = chunk.trigger) == null ? void 0 : _b.throw(err);
|
|
213
273
|
}
|
|
214
|
-
await this.
|
|
274
|
+
await this._sendChunks();
|
|
215
275
|
}
|
|
216
276
|
};
|
|
277
|
+
var encodeChunk = ({ channelId, dataLength, chunk }) => {
|
|
278
|
+
const channelTagLength = varint.encodingLength(channelId);
|
|
279
|
+
const dataLengthLength = dataLength ? varint.encodingLength(dataLength) : 0;
|
|
280
|
+
const message = Buffer.allocUnsafe(channelTagLength + dataLengthLength + chunk.length);
|
|
281
|
+
varint.encode(channelId, message);
|
|
282
|
+
if (dataLength) {
|
|
283
|
+
varint.encode(dataLength, message, channelTagLength);
|
|
284
|
+
}
|
|
285
|
+
message.set(chunk, channelTagLength + dataLengthLength);
|
|
286
|
+
return message;
|
|
287
|
+
};
|
|
288
|
+
var decodeChunk = (data, withLength) => {
|
|
289
|
+
const channelId = varint.decode(data);
|
|
290
|
+
let dataLength;
|
|
291
|
+
let offset = varint.decode.bytes;
|
|
292
|
+
if (withLength(channelId)) {
|
|
293
|
+
dataLength = varint.decode(data, offset);
|
|
294
|
+
offset += varint.decode.bytes;
|
|
295
|
+
}
|
|
296
|
+
const chunk = data.subarray(offset);
|
|
297
|
+
return {
|
|
298
|
+
channelId,
|
|
299
|
+
dataLength,
|
|
300
|
+
chunk
|
|
301
|
+
};
|
|
302
|
+
};
|
|
217
303
|
|
|
218
304
|
// packages/core/mesh/teleport/src/muxing/muxer.ts
|
|
219
|
-
var
|
|
305
|
+
var __dxlog_file2 = "/mnt/ramdisk/work/packages/core/mesh/teleport/src/muxing/muxer.ts";
|
|
220
306
|
var Command = schema.getCodecForType("dxos.mesh.muxer.Command");
|
|
221
307
|
var STATS_INTERVAL = 1e3;
|
|
222
|
-
var
|
|
308
|
+
var MAX_SAFE_FRAME_SIZE = 1e6;
|
|
309
|
+
var SYSTEM_CHANNEL_ID = 0;
|
|
223
310
|
var Muxer = class {
|
|
224
311
|
constructor() {
|
|
225
|
-
this.
|
|
226
|
-
this._balancer = new Balancer(this._framer.port, SYSTEM_CHANNEL_ID);
|
|
227
|
-
this.stream = this._framer.stream;
|
|
312
|
+
this._balancer = new Balancer(SYSTEM_CHANNEL_ID);
|
|
228
313
|
this._channelsByLocalId = /* @__PURE__ */ new Map();
|
|
229
314
|
this._channelsByTag = /* @__PURE__ */ new Map();
|
|
230
|
-
this.
|
|
315
|
+
this._ctx = new Context();
|
|
316
|
+
this._nextId = 1;
|
|
231
317
|
this._destroyed = false;
|
|
232
318
|
this._destroying = false;
|
|
233
|
-
this.close = new
|
|
234
|
-
this.statsUpdated = new
|
|
235
|
-
this.
|
|
236
|
-
this.
|
|
319
|
+
this.close = new Event2();
|
|
320
|
+
this.statsUpdated = new Event2();
|
|
321
|
+
this.stream = this._balancer.stream;
|
|
322
|
+
this._balancer.incomingData.on(async (msg) => {
|
|
237
323
|
await this._handleCommand(Command.decode(msg));
|
|
238
324
|
});
|
|
239
325
|
scheduleTaskInterval(this._ctx, async () => this._emitStats(), STATS_INTERVAL);
|
|
@@ -353,7 +439,6 @@ var Muxer = class {
|
|
|
353
439
|
}
|
|
354
440
|
this._destroyed = true;
|
|
355
441
|
this._balancer.destroy();
|
|
356
|
-
this._framer.destroy();
|
|
357
442
|
for (const channel of this._channelsByTag.values()) {
|
|
358
443
|
(_a = channel.destroy) == null ? void 0 : _a.call(channel, err);
|
|
359
444
|
}
|
|
@@ -363,20 +448,20 @@ var Muxer = class {
|
|
|
363
448
|
}
|
|
364
449
|
async _handleCommand(cmd) {
|
|
365
450
|
var _a;
|
|
366
|
-
|
|
451
|
+
log2("Received command", {
|
|
367
452
|
cmd
|
|
368
453
|
}, {
|
|
369
|
-
F:
|
|
370
|
-
L:
|
|
454
|
+
F: __dxlog_file2,
|
|
455
|
+
L: 240,
|
|
371
456
|
S: this,
|
|
372
457
|
C: (f, a) => f(...a)
|
|
373
458
|
});
|
|
374
459
|
if (this._destroyed || this._destroying) {
|
|
375
|
-
|
|
460
|
+
log2.warn("Received command after destroy", {
|
|
376
461
|
cmd
|
|
377
462
|
}, {
|
|
378
|
-
F:
|
|
379
|
-
L:
|
|
463
|
+
F: __dxlog_file2,
|
|
464
|
+
L: 243,
|
|
380
465
|
S: this,
|
|
381
466
|
C: (f, a) => f(...a)
|
|
382
467
|
});
|
|
@@ -400,11 +485,11 @@ var Muxer = class {
|
|
|
400
485
|
} else if (cmd.data) {
|
|
401
486
|
const stream = (_a = this._channelsByLocalId.get(cmd.data.channelId)) != null ? _a : failUndefined();
|
|
402
487
|
if (!stream.push) {
|
|
403
|
-
|
|
488
|
+
log2.warn("Received data for channel before it was opened", {
|
|
404
489
|
tag: stream.tag
|
|
405
490
|
}, {
|
|
406
|
-
F:
|
|
407
|
-
L:
|
|
491
|
+
F: __dxlog_file2,
|
|
492
|
+
L: 270,
|
|
408
493
|
S: this,
|
|
409
494
|
C: (f, a) => f(...a)
|
|
410
495
|
});
|
|
@@ -418,7 +503,7 @@ var Muxer = class {
|
|
|
418
503
|
async _sendCommand(cmd, channelId = -1) {
|
|
419
504
|
try {
|
|
420
505
|
const trigger = new Trigger();
|
|
421
|
-
this._balancer.
|
|
506
|
+
this._balancer.pushData(Command.encode(cmd), trigger, channelId);
|
|
422
507
|
await trigger.wait();
|
|
423
508
|
} catch (err) {
|
|
424
509
|
this.destroy(err);
|
|
@@ -447,6 +532,17 @@ var Muxer = class {
|
|
|
447
532
|
return channel;
|
|
448
533
|
}
|
|
449
534
|
async _sendData(channel, data) {
|
|
535
|
+
if (data.length > MAX_SAFE_FRAME_SIZE) {
|
|
536
|
+
log2.warn("frame size exceeds maximum safe value", {
|
|
537
|
+
size: data.length,
|
|
538
|
+
threshold: MAX_SAFE_FRAME_SIZE
|
|
539
|
+
}, {
|
|
540
|
+
F: __dxlog_file2,
|
|
541
|
+
L: 314,
|
|
542
|
+
S: this,
|
|
543
|
+
C: (f, a) => f(...a)
|
|
544
|
+
});
|
|
545
|
+
}
|
|
450
546
|
channel.stats.bytesSent += data.length;
|
|
451
547
|
if (channel.remoteId === null) {
|
|
452
548
|
channel.buffer.push(data);
|
|
@@ -470,12 +566,19 @@ var Muxer = class {
|
|
|
470
566
|
if (this._destroyed || this._destroying) {
|
|
471
567
|
return;
|
|
472
568
|
}
|
|
473
|
-
this.
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
569
|
+
const bytesSent = this._balancer.bytesSent;
|
|
570
|
+
const bytesReceived = this._balancer.bytesReceived;
|
|
571
|
+
this.statsUpdated.emit({
|
|
572
|
+
channels: Array.from(this._channelsByTag.values()).map((channel) => ({
|
|
573
|
+
id: channel.id,
|
|
574
|
+
tag: channel.tag,
|
|
575
|
+
contentType: channel.contentType,
|
|
576
|
+
bytesSent: channel.stats.bytesSent,
|
|
577
|
+
bytesReceived: channel.stats.bytesReceived
|
|
578
|
+
})),
|
|
579
|
+
bytesSent,
|
|
580
|
+
bytesReceived
|
|
581
|
+
});
|
|
479
582
|
}
|
|
480
583
|
};
|
|
481
584
|
|
|
@@ -490,15 +593,15 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
490
593
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
491
594
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
492
595
|
}
|
|
493
|
-
var
|
|
596
|
+
var __dxlog_file3 = "/mnt/ramdisk/work/packages/core/mesh/teleport/src/teleport.ts";
|
|
494
597
|
var Teleport = class {
|
|
495
598
|
constructor({ initiator, localPeerId, remotePeerId }) {
|
|
496
599
|
this._ctx = new Context2({
|
|
497
600
|
onError: (err) => {
|
|
498
601
|
void this.destroy(err).catch(() => {
|
|
499
|
-
|
|
500
|
-
F:
|
|
501
|
-
L:
|
|
602
|
+
log3.error("Error during destroy", err, {
|
|
603
|
+
F: __dxlog_file3,
|
|
604
|
+
L: 34,
|
|
502
605
|
S: this,
|
|
503
606
|
C: (f, a) => f(...a)
|
|
504
607
|
});
|
|
@@ -510,9 +613,9 @@ var Teleport = class {
|
|
|
510
613
|
heartbeatInterval: 1e4,
|
|
511
614
|
heartbeatTimeout: 1e4,
|
|
512
615
|
onTimeout: () => {
|
|
513
|
-
this.destroy(new Error("Connection timed out")).catch((err) =>
|
|
514
|
-
F:
|
|
515
|
-
L:
|
|
616
|
+
this.destroy(new Error("Connection timed out")).catch((err) => log3.catch(err, void 0, {
|
|
617
|
+
F: __dxlog_file3,
|
|
618
|
+
L: 45,
|
|
516
619
|
S: this,
|
|
517
620
|
C: (f, a) => f(...a)
|
|
518
621
|
}));
|
|
@@ -528,11 +631,11 @@ var Teleport = class {
|
|
|
528
631
|
this.localPeerId = localPeerId;
|
|
529
632
|
this.remotePeerId = remotePeerId;
|
|
530
633
|
this._control.onExtensionRegistered.set(async (name) => {
|
|
531
|
-
|
|
634
|
+
log3("remote extension", {
|
|
532
635
|
name
|
|
533
636
|
}, {
|
|
534
|
-
F:
|
|
535
|
-
L:
|
|
637
|
+
F: __dxlog_file3,
|
|
638
|
+
L: 63,
|
|
536
639
|
S: this,
|
|
537
640
|
C: (f, a) => f(...a)
|
|
538
641
|
});
|
|
@@ -554,6 +657,20 @@ var Teleport = class {
|
|
|
554
657
|
await this.destroy(err);
|
|
555
658
|
});
|
|
556
659
|
}
|
|
660
|
+
this._muxer.statsUpdated.on((stats) => {
|
|
661
|
+
log3.trace("dxos.mesh.teleport.stats", {
|
|
662
|
+
localPeerId,
|
|
663
|
+
remotePeerId,
|
|
664
|
+
bytesSent: stats.bytesSent,
|
|
665
|
+
bytesReceived: stats.bytesReceived,
|
|
666
|
+
channels: stats.channels
|
|
667
|
+
}, {
|
|
668
|
+
F: __dxlog_file3,
|
|
669
|
+
L: 88,
|
|
670
|
+
S: this,
|
|
671
|
+
C: (f, a) => f(...a)
|
|
672
|
+
});
|
|
673
|
+
});
|
|
557
674
|
}
|
|
558
675
|
get stream() {
|
|
559
676
|
return this._muxer.stream;
|
|
@@ -581,9 +698,9 @@ var Teleport = class {
|
|
|
581
698
|
try {
|
|
582
699
|
await extension.onClose(err);
|
|
583
700
|
} catch (err2) {
|
|
584
|
-
|
|
585
|
-
F:
|
|
586
|
-
L:
|
|
701
|
+
log3.catch(err2, void 0, {
|
|
702
|
+
F: __dxlog_file3,
|
|
703
|
+
L: 132,
|
|
587
704
|
S: this,
|
|
588
705
|
C: (f, a) => f(...a)
|
|
589
706
|
});
|
|
@@ -595,11 +712,11 @@ var Teleport = class {
|
|
|
595
712
|
if (!this._open) {
|
|
596
713
|
throw new Error("Not open");
|
|
597
714
|
}
|
|
598
|
-
|
|
715
|
+
log3("addExtension", {
|
|
599
716
|
name
|
|
600
717
|
}, {
|
|
601
|
-
F:
|
|
602
|
-
L:
|
|
718
|
+
F: __dxlog_file3,
|
|
719
|
+
L: 144,
|
|
603
720
|
S: this,
|
|
604
721
|
C: (f, a) => f(...a)
|
|
605
722
|
});
|
|
@@ -627,11 +744,11 @@ var Teleport = class {
|
|
|
627
744
|
}
|
|
628
745
|
async _openExtension(extensionName) {
|
|
629
746
|
var _a;
|
|
630
|
-
|
|
747
|
+
log3("open extension", {
|
|
631
748
|
extensionName
|
|
632
749
|
}, {
|
|
633
|
-
F:
|
|
634
|
-
L:
|
|
750
|
+
F: __dxlog_file3,
|
|
751
|
+
L: 174,
|
|
635
752
|
S: this,
|
|
636
753
|
C: (f, a) => f(...a)
|
|
637
754
|
});
|
|
@@ -655,11 +772,11 @@ var Teleport = class {
|
|
|
655
772
|
}
|
|
656
773
|
};
|
|
657
774
|
await extension.onOpen(context);
|
|
658
|
-
|
|
775
|
+
log3("extension opened", {
|
|
659
776
|
extensionName
|
|
660
777
|
}, {
|
|
661
|
-
F:
|
|
662
|
-
L:
|
|
778
|
+
F: __dxlog_file3,
|
|
779
|
+
L: 197,
|
|
663
780
|
S: this,
|
|
664
781
|
C: (f, a) => f(...a)
|
|
665
782
|
});
|
|
@@ -678,6 +795,11 @@ var ControlExtension = class {
|
|
|
678
795
|
});
|
|
679
796
|
this.onExtensionRegistered = new Callback();
|
|
680
797
|
}
|
|
798
|
+
async registerExtension(name) {
|
|
799
|
+
await this._rpc.rpc.Control.registerExtension({
|
|
800
|
+
name
|
|
801
|
+
});
|
|
802
|
+
}
|
|
681
803
|
async onOpen(extensionContext) {
|
|
682
804
|
this._extensionContext = extensionContext;
|
|
683
805
|
this._rpc = createProtoRpcPeer({
|
|
@@ -713,15 +835,10 @@ var ControlExtension = class {
|
|
|
713
835
|
await this._ctx.dispose();
|
|
714
836
|
await this._rpc.close();
|
|
715
837
|
}
|
|
716
|
-
async registerExtension(name) {
|
|
717
|
-
await this._rpc.rpc.Control.registerExtension({
|
|
718
|
-
name
|
|
719
|
-
});
|
|
720
|
-
}
|
|
721
838
|
};
|
|
722
839
|
|
|
723
840
|
// packages/core/mesh/teleport/src/testing/test-builder.ts
|
|
724
|
-
var
|
|
841
|
+
var __dxlog_file4 = "/mnt/ramdisk/work/packages/core/mesh/teleport/src/testing/test-builder.ts";
|
|
725
842
|
var TestBuilder = class {
|
|
726
843
|
constructor() {
|
|
727
844
|
this._peers = /* @__PURE__ */ new Set();
|
|
@@ -809,8 +926,8 @@ var TestPeer = class {
|
|
|
809
926
|
var pipeStreams = (stream1, stream2) => {
|
|
810
927
|
pipeline(stream1, stream2, (err) => {
|
|
811
928
|
if (err && err.code !== "ERR_STREAM_PREMATURE_CLOSE") {
|
|
812
|
-
|
|
813
|
-
F:
|
|
929
|
+
log4.catch(err, void 0, {
|
|
930
|
+
F: __dxlog_file4,
|
|
814
931
|
L: 106,
|
|
815
932
|
S: void 0,
|
|
816
933
|
C: (f, a) => f(...a)
|
|
@@ -819,8 +936,8 @@ var pipeStreams = (stream1, stream2) => {
|
|
|
819
936
|
});
|
|
820
937
|
pipeline(stream2, stream1, (err) => {
|
|
821
938
|
if (err && err.code !== "ERR_STREAM_PREMATURE_CLOSE") {
|
|
822
|
-
|
|
823
|
-
F:
|
|
939
|
+
log4.catch(err, void 0, {
|
|
940
|
+
F: __dxlog_file4,
|
|
824
941
|
L: 111,
|
|
825
942
|
S: void 0,
|
|
826
943
|
C: (f, a) => f(...a)
|
|
@@ -844,10 +961,10 @@ var TestConnection = class {
|
|
|
844
961
|
// packages/core/mesh/teleport/src/testing/test-extension.ts
|
|
845
962
|
import invariant5 from "tiny-invariant";
|
|
846
963
|
import { asyncTimeout as asyncTimeout2, Trigger as Trigger2 } from "@dxos/async";
|
|
847
|
-
import { log as
|
|
964
|
+
import { log as log5 } from "@dxos/log";
|
|
848
965
|
import { schema as schema3 } from "@dxos/protocols";
|
|
849
966
|
import { createProtoRpcPeer as createProtoRpcPeer2 } from "@dxos/rpc";
|
|
850
|
-
var
|
|
967
|
+
var __dxlog_file5 = "/mnt/ramdisk/work/packages/core/mesh/teleport/src/testing/test-extension.ts";
|
|
851
968
|
var TestExtension = class {
|
|
852
969
|
constructor(callbacks = {}) {
|
|
853
970
|
this.callbacks = callbacks;
|
|
@@ -860,11 +977,11 @@ var TestExtension = class {
|
|
|
860
977
|
}
|
|
861
978
|
async onOpen(context) {
|
|
862
979
|
var _a, _b;
|
|
863
|
-
|
|
980
|
+
log5("onOpen", {
|
|
864
981
|
localPeerId: context.localPeerId,
|
|
865
982
|
remotePeerId: context.remotePeerId
|
|
866
983
|
}, {
|
|
867
|
-
F:
|
|
984
|
+
F: __dxlog_file5,
|
|
868
985
|
L: 33,
|
|
869
986
|
S: this,
|
|
870
987
|
C: (f, a) => f(...a)
|
|
@@ -899,10 +1016,10 @@ var TestExtension = class {
|
|
|
899
1016
|
}
|
|
900
1017
|
async onClose(err) {
|
|
901
1018
|
var _a, _b, _c;
|
|
902
|
-
|
|
1019
|
+
log5("onClose", {
|
|
903
1020
|
err
|
|
904
1021
|
}, {
|
|
905
|
-
F:
|
|
1022
|
+
F: __dxlog_file5,
|
|
906
1023
|
L: 67,
|
|
907
1024
|
S: this,
|
|
908
1025
|
C: (f, a) => f(...a)
|
|
@@ -933,10 +1050,10 @@ var TestExtension = class {
|
|
|
933
1050
|
import assert from "@dxos/node-std/assert";
|
|
934
1051
|
import { randomBytes } from "@dxos/node-std/crypto";
|
|
935
1052
|
import { Trigger as Trigger3 } from "@dxos/async";
|
|
936
|
-
import { log as
|
|
1053
|
+
import { log as log6 } from "@dxos/log";
|
|
937
1054
|
import { schema as schema4 } from "@dxos/protocols";
|
|
938
1055
|
import { createProtoRpcPeer as createProtoRpcPeer3 } from "@dxos/rpc";
|
|
939
|
-
var
|
|
1056
|
+
var __dxlog_file6 = "/mnt/ramdisk/work/packages/core/mesh/teleport/src/testing/test-extension-with-streams.ts";
|
|
940
1057
|
var TestExtensionWithStreams = class {
|
|
941
1058
|
constructor(callbacks = {}) {
|
|
942
1059
|
this.callbacks = callbacks;
|
|
@@ -988,11 +1105,30 @@ var TestExtensionWithStreams = class {
|
|
|
988
1105
|
networkStream.on("close", () => {
|
|
989
1106
|
networkStream.removeAllListeners();
|
|
990
1107
|
});
|
|
1108
|
+
streamEntry.reportingTimer = setInterval(() => {
|
|
1109
|
+
var _a, _b;
|
|
1110
|
+
const { bytesSent, bytesReceived, sendErrors, receiveErrors } = streamEntry;
|
|
1111
|
+
log6.trace("dxos.test.stream-stats", {
|
|
1112
|
+
streamTag,
|
|
1113
|
+
bytesSent,
|
|
1114
|
+
bytesReceived,
|
|
1115
|
+
sendErrors,
|
|
1116
|
+
receiveErrors,
|
|
1117
|
+
from: (_a = this.extensionContext) == null ? void 0 : _a.localPeerId,
|
|
1118
|
+
to: (_b = this.extensionContext) == null ? void 0 : _b.remotePeerId
|
|
1119
|
+
}, {
|
|
1120
|
+
F: __dxlog_file6,
|
|
1121
|
+
L: 91,
|
|
1122
|
+
S: this,
|
|
1123
|
+
C: (f, a) => f(...a)
|
|
1124
|
+
});
|
|
1125
|
+
}, 100);
|
|
991
1126
|
}
|
|
992
1127
|
_closeStream(streamTag) {
|
|
993
1128
|
assert(this._streams.has(streamTag), `Stream does not exist: ${streamTag}`);
|
|
994
1129
|
const stream = this._streams.get(streamTag);
|
|
995
1130
|
clearTimeout(stream.timer);
|
|
1131
|
+
clearTimeout(stream.reportingTimer);
|
|
996
1132
|
const { bytesSent, bytesReceived, sendErrors, receiveErrors, startTimestamp } = stream;
|
|
997
1133
|
stream.networkStream.destroy();
|
|
998
1134
|
this._streams.delete(streamTag);
|
|
@@ -1006,12 +1142,12 @@ var TestExtensionWithStreams = class {
|
|
|
1006
1142
|
}
|
|
1007
1143
|
async onOpen(context) {
|
|
1008
1144
|
var _a, _b;
|
|
1009
|
-
|
|
1145
|
+
log6("onOpen", {
|
|
1010
1146
|
localPeerId: context.localPeerId,
|
|
1011
1147
|
remotePeerId: context.remotePeerId
|
|
1012
1148
|
}, {
|
|
1013
|
-
F:
|
|
1014
|
-
L:
|
|
1149
|
+
F: __dxlog_file6,
|
|
1150
|
+
L: 126,
|
|
1015
1151
|
S: this,
|
|
1016
1152
|
C: (f, a) => f(...a)
|
|
1017
1153
|
});
|
|
@@ -1057,22 +1193,22 @@ var TestExtensionWithStreams = class {
|
|
|
1057
1193
|
}
|
|
1058
1194
|
async onClose(err) {
|
|
1059
1195
|
var _a, _b, _c;
|
|
1060
|
-
|
|
1196
|
+
log6("onClose", {
|
|
1061
1197
|
err
|
|
1062
1198
|
}, {
|
|
1063
|
-
F:
|
|
1064
|
-
L:
|
|
1199
|
+
F: __dxlog_file6,
|
|
1200
|
+
L: 177,
|
|
1065
1201
|
S: this,
|
|
1066
1202
|
C: (f, a) => f(...a)
|
|
1067
1203
|
});
|
|
1068
1204
|
await ((_b = (_a = this.callbacks).onClose) == null ? void 0 : _b.call(_a));
|
|
1069
1205
|
this.closed.wake();
|
|
1070
1206
|
for (const [streamTag, stream] of Object.entries(this._streams)) {
|
|
1071
|
-
|
|
1207
|
+
log6("closing stream", {
|
|
1072
1208
|
streamTag
|
|
1073
1209
|
}, {
|
|
1074
|
-
F:
|
|
1075
|
-
L:
|
|
1210
|
+
F: __dxlog_file6,
|
|
1211
|
+
L: 181,
|
|
1076
1212
|
S: this,
|
|
1077
1213
|
C: (f, a) => f(...a)
|
|
1078
1214
|
});
|
|
@@ -1141,4 +1277,4 @@ export {
|
|
|
1141
1277
|
TestExtension,
|
|
1142
1278
|
TestExtensionWithStreams
|
|
1143
1279
|
};
|
|
1144
|
-
//# sourceMappingURL=chunk-
|
|
1280
|
+
//# sourceMappingURL=chunk-WUEX3RV3.mjs.map
|