@dxos/network-manager 0.3.9-main.1d6fb54 → 0.3.9-main.320ebac
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-4HITD6WI.mjs → chunk-S2JHWVGQ.mjs} +237 -62
- package/dist/lib/browser/chunk-S2JHWVGQ.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/{chunk-6AD7QA4X.cjs → chunk-3SCPMSHV.cjs} +246 -61
- package/dist/lib/node/chunk-3SCPMSHV.cjs.map +7 -0
- package/dist/lib/node/{chunk-XE5JOIGD.cjs → chunk-DMWORJG3.cjs} +13 -4
- package/dist/lib/node/chunk-DMWORJG3.cjs.map +7 -0
- package/dist/lib/node/{datachannel-53JZPGFA.cjs → datachannel-ABYQKZRC.cjs} +9 -9
- package/dist/lib/node/{datachannel-53JZPGFA.cjs.map → datachannel-ABYQKZRC.cjs.map} +2 -2
- package/dist/lib/node/index.cjs +32 -32
- package/dist/lib/node/index.cjs.map +1 -1
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +19 -19
- package/dist/types/src/connection-log.d.ts.map +1 -1
- package/dist/types/src/swarm/connection.d.ts +4 -1
- package/dist/types/src/swarm/connection.d.ts.map +1 -1
- package/dist/types/src/transport/datachannel/rtc-peer-connection.d.ts +7 -0
- package/dist/types/src/transport/datachannel/rtc-peer-connection.d.ts.map +1 -1
- package/dist/types/src/transport/libdatachannel-transport.d.ts +3 -1
- package/dist/types/src/transport/libdatachannel-transport.d.ts.map +1 -1
- package/dist/types/src/transport/memory-transport.d.ts +3 -1
- package/dist/types/src/transport/memory-transport.d.ts.map +1 -1
- package/dist/types/src/transport/simplepeer-transport-proxy.d.ts +3 -1
- package/dist/types/src/transport/simplepeer-transport-proxy.d.ts.map +1 -1
- package/dist/types/src/transport/simplepeer-transport-service.d.ts +3 -1
- package/dist/types/src/transport/simplepeer-transport-service.d.ts.map +1 -1
- package/dist/types/src/transport/simplepeer-transport.d.ts +4 -1
- package/dist/types/src/transport/simplepeer-transport.d.ts.map +1 -1
- package/dist/types/src/transport/tcp-transport.browser.d.ts +3 -1
- package/dist/types/src/transport/tcp-transport.browser.d.ts.map +1 -1
- package/dist/types/src/transport/tcp-transport.d.ts +3 -1
- package/dist/types/src/transport/tcp-transport.d.ts.map +1 -1
- package/dist/types/src/transport/transport.d.ts +17 -0
- package/dist/types/src/transport/transport.d.ts.map +1 -1
- package/dist/types/src/wire-protocol.d.ts +1 -1
- package/dist/types/src/wire-protocol.d.ts.map +1 -1
- package/package.json +17 -17
- package/src/connection-log.ts +14 -1
- package/src/swarm/connection.ts +23 -4
- package/src/transport/datachannel/rtc-peer-connection.ts +13 -1
- package/src/transport/libdatachannel-transport.ts +37 -1
- package/src/transport/memory-transport.ts +14 -1
- package/src/transport/simplepeer-transport-proxy.ts +9 -1
- package/src/transport/simplepeer-transport-service.ts +14 -0
- package/src/transport/simplepeer-transport.ts +63 -2
- package/src/transport/tcp-transport.browser.ts +9 -1
- package/src/transport/tcp-transport.ts +19 -1
- package/src/transport/transport.ts +19 -0
- package/src/wire-protocol.ts +3 -3
- package/dist/lib/browser/chunk-4HITD6WI.mjs.map +0 -7
- package/dist/lib/node/chunk-6AD7QA4X.cjs.map +0 -7
- package/dist/lib/node/chunk-XE5JOIGD.cjs.map +0 -7
|
@@ -4,12 +4,12 @@ import {
|
|
|
4
4
|
} from "./chunk-YERMWDRB.mjs";
|
|
5
5
|
|
|
6
6
|
// packages/core/mesh/network-manager/src/swarm/connection.ts
|
|
7
|
-
import { DeferredTask, Event, sleep, scheduleTask, synchronized } from "@dxos/async";
|
|
7
|
+
import { DeferredTask, Event, sleep, scheduleTask, scheduleTaskInterval, synchronized } from "@dxos/async";
|
|
8
8
|
import { Context, cancelWithContext } from "@dxos/context";
|
|
9
9
|
import { ErrorStream } from "@dxos/debug";
|
|
10
10
|
import { invariant } from "@dxos/invariant";
|
|
11
11
|
import { PublicKey } from "@dxos/keys";
|
|
12
|
-
import { log } from "@dxos/log";
|
|
12
|
+
import { log, logInfo } from "@dxos/log";
|
|
13
13
|
import { CancelledError, ProtocolError, ConnectionResetError, ConnectivityError, TimeoutError, UnknownProtocolError, trace } from "@dxos/protocols";
|
|
14
14
|
function _ts_decorate(decorators, target, key, desc) {
|
|
15
15
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -24,6 +24,7 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
24
24
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts";
|
|
25
25
|
var STARTING_SIGNALLING_DELAY = 10;
|
|
26
26
|
var TRANSPORT_CONNECTION_TIMEOUT = 1e4;
|
|
27
|
+
var TRANSPORT_STATS_INTERVAL = 5e3;
|
|
27
28
|
var MAX_SIGNALLING_DELAY = 300;
|
|
28
29
|
var ConnectionState;
|
|
29
30
|
(function(ConnectionState5) {
|
|
@@ -86,6 +87,7 @@ var Connection = class {
|
|
|
86
87
|
this.stateChanged = new Event();
|
|
87
88
|
this.errors = new ErrorStream();
|
|
88
89
|
this._instanceId = PublicKey.random().toHex();
|
|
90
|
+
this.transportStats = new Event();
|
|
89
91
|
this._signalSendTask = new DeferredTask(this._ctx, async () => {
|
|
90
92
|
await this._flushSignalBuffer();
|
|
91
93
|
});
|
|
@@ -98,11 +100,14 @@ var Connection = class {
|
|
|
98
100
|
initiator: this.initiator
|
|
99
101
|
}, {
|
|
100
102
|
F: __dxlog_file,
|
|
101
|
-
L:
|
|
103
|
+
L: 134,
|
|
102
104
|
S: this,
|
|
103
105
|
C: (f, a) => f(...a)
|
|
104
106
|
});
|
|
105
107
|
}
|
|
108
|
+
get sessionIdString() {
|
|
109
|
+
return this.sessionId.truncate();
|
|
110
|
+
}
|
|
106
111
|
get state() {
|
|
107
112
|
return this._state;
|
|
108
113
|
}
|
|
@@ -118,7 +123,7 @@ var Connection = class {
|
|
|
118
123
|
async openConnection() {
|
|
119
124
|
invariant(this._state === ConnectionState.INITIAL, "Invalid state.", {
|
|
120
125
|
F: __dxlog_file,
|
|
121
|
-
L:
|
|
126
|
+
L: 164,
|
|
122
127
|
S: this,
|
|
123
128
|
A: [
|
|
124
129
|
"this._state === ConnectionState.INITIAL",
|
|
@@ -129,7 +134,7 @@ var Connection = class {
|
|
|
129
134
|
id: this._instanceId
|
|
130
135
|
}), {
|
|
131
136
|
F: __dxlog_file,
|
|
132
|
-
L:
|
|
137
|
+
L: 165,
|
|
133
138
|
S: this,
|
|
134
139
|
C: (f, a) => f(...a)
|
|
135
140
|
});
|
|
@@ -141,18 +146,18 @@ var Connection = class {
|
|
|
141
146
|
initiator: this.initiator
|
|
142
147
|
}, {
|
|
143
148
|
F: __dxlog_file,
|
|
144
|
-
L:
|
|
149
|
+
L: 166,
|
|
145
150
|
S: this,
|
|
146
151
|
C: (f, a) => f(...a)
|
|
147
152
|
});
|
|
148
153
|
this._changeState(ConnectionState.CONNECTING);
|
|
149
|
-
this._protocol.open().catch((err) => {
|
|
154
|
+
this._protocol.open(this.sessionId).catch((err) => {
|
|
150
155
|
this.errors.raise(err);
|
|
151
156
|
});
|
|
152
157
|
this._protocol.stream.on("close", () => {
|
|
153
158
|
log("protocol stream closed", void 0, {
|
|
154
159
|
F: __dxlog_file,
|
|
155
|
-
L:
|
|
160
|
+
L: 183,
|
|
156
161
|
S: this,
|
|
157
162
|
C: (f, a) => f(...a)
|
|
158
163
|
});
|
|
@@ -161,7 +166,7 @@ var Connection = class {
|
|
|
161
166
|
scheduleTask(this.connectedTimeoutContext, async () => {
|
|
162
167
|
log.info(`timeout waiting ${TRANSPORT_CONNECTION_TIMEOUT / 1e3}s for transport to connect, aborting`, void 0, {
|
|
163
168
|
F: __dxlog_file,
|
|
164
|
-
L:
|
|
169
|
+
L: 190,
|
|
165
170
|
S: this,
|
|
166
171
|
C: (f, a) => f(...a)
|
|
167
172
|
});
|
|
@@ -169,7 +174,7 @@ var Connection = class {
|
|
|
169
174
|
}, TRANSPORT_CONNECTION_TIMEOUT);
|
|
170
175
|
invariant(!this._transport, void 0, {
|
|
171
176
|
F: __dxlog_file,
|
|
172
|
-
L:
|
|
177
|
+
L: 198,
|
|
173
178
|
S: this,
|
|
174
179
|
A: [
|
|
175
180
|
"!this._transport",
|
|
@@ -179,18 +184,20 @@ var Connection = class {
|
|
|
179
184
|
this._transport = this._transportFactory.createTransport({
|
|
180
185
|
initiator: this.initiator,
|
|
181
186
|
stream: this._protocol.stream,
|
|
182
|
-
sendSignal: async (signal) => this._sendSignal(signal)
|
|
187
|
+
sendSignal: async (signal) => this._sendSignal(signal),
|
|
188
|
+
sessionId: this.sessionId
|
|
183
189
|
});
|
|
184
190
|
this._transport.connected.once(async () => {
|
|
185
191
|
this._changeState(ConnectionState.CONNECTED);
|
|
186
192
|
await this.connectedTimeoutContext.dispose();
|
|
187
193
|
this._callbacks?.onConnected?.();
|
|
194
|
+
scheduleTaskInterval(this._ctx, async () => this._emitTransportStats(), TRANSPORT_STATS_INTERVAL);
|
|
188
195
|
});
|
|
189
196
|
this._transport.closed.once(() => {
|
|
190
197
|
this._transport = void 0;
|
|
191
198
|
log("abort triggered by transport close", void 0, {
|
|
192
199
|
F: __dxlog_file,
|
|
193
|
-
L:
|
|
200
|
+
L: 216,
|
|
194
201
|
S: this,
|
|
195
202
|
C: (f, a) => f(...a)
|
|
196
203
|
});
|
|
@@ -201,7 +208,7 @@ var Connection = class {
|
|
|
201
208
|
err
|
|
202
209
|
}, {
|
|
203
210
|
F: __dxlog_file,
|
|
204
|
-
L:
|
|
211
|
+
L: 221,
|
|
205
212
|
S: this,
|
|
206
213
|
C: (f, a) => f(...a)
|
|
207
214
|
});
|
|
@@ -211,7 +218,7 @@ var Connection = class {
|
|
|
211
218
|
if (err instanceof ConnectionResetError) {
|
|
212
219
|
log.info("aborting due to transport ConnectionResetError", void 0, {
|
|
213
220
|
F: __dxlog_file,
|
|
214
|
-
L:
|
|
221
|
+
L: 228,
|
|
215
222
|
S: this,
|
|
216
223
|
C: (f, a) => f(...a)
|
|
217
224
|
});
|
|
@@ -219,7 +226,7 @@ var Connection = class {
|
|
|
219
226
|
} else if (err instanceof ConnectivityError) {
|
|
220
227
|
log.info("aborting due to transport ConnectivityError", void 0, {
|
|
221
228
|
F: __dxlog_file,
|
|
222
|
-
L:
|
|
229
|
+
L: 231,
|
|
223
230
|
S: this,
|
|
224
231
|
C: (f, a) => f(...a)
|
|
225
232
|
});
|
|
@@ -229,7 +236,7 @@ var Connection = class {
|
|
|
229
236
|
err
|
|
230
237
|
}, {
|
|
231
238
|
F: __dxlog_file,
|
|
232
|
-
L:
|
|
239
|
+
L: 234,
|
|
233
240
|
S: this,
|
|
234
241
|
C: (f, a) => f(...a)
|
|
235
242
|
});
|
|
@@ -247,7 +254,7 @@ var Connection = class {
|
|
|
247
254
|
id: this._instanceId
|
|
248
255
|
}), {
|
|
249
256
|
F: __dxlog_file,
|
|
250
|
-
L:
|
|
257
|
+
L: 250,
|
|
251
258
|
S: this,
|
|
252
259
|
C: (f, a) => f(...a)
|
|
253
260
|
});
|
|
@@ -257,14 +264,14 @@ var Connection = class {
|
|
|
257
264
|
err
|
|
258
265
|
}, {
|
|
259
266
|
F: __dxlog_file,
|
|
260
|
-
L:
|
|
267
|
+
L: 257,
|
|
261
268
|
S: this,
|
|
262
269
|
C: (f, a) => f(...a)
|
|
263
270
|
});
|
|
264
271
|
if (this._state === ConnectionState.CLOSED || this._state === ConnectionState.ABORTED) {
|
|
265
272
|
log(`abort ignored: already ${this._state}`, this.closeReason, {
|
|
266
273
|
F: __dxlog_file,
|
|
267
|
-
L:
|
|
274
|
+
L: 259,
|
|
268
275
|
S: this,
|
|
269
276
|
C: (f, a) => f(...a)
|
|
270
277
|
});
|
|
@@ -279,7 +286,7 @@ var Connection = class {
|
|
|
279
286
|
try {
|
|
280
287
|
log("aborting protocol... ", void 0, {
|
|
281
288
|
F: __dxlog_file,
|
|
282
|
-
L:
|
|
289
|
+
L: 273,
|
|
283
290
|
S: this,
|
|
284
291
|
C: (f, a) => f(...a)
|
|
285
292
|
});
|
|
@@ -287,7 +294,7 @@ var Connection = class {
|
|
|
287
294
|
} catch (err2) {
|
|
288
295
|
log.catch(err2, void 0, {
|
|
289
296
|
F: __dxlog_file,
|
|
290
|
-
L:
|
|
297
|
+
L: 276,
|
|
291
298
|
S: this,
|
|
292
299
|
C: (f, a) => f(...a)
|
|
293
300
|
});
|
|
@@ -297,7 +304,7 @@ var Connection = class {
|
|
|
297
304
|
} catch (err2) {
|
|
298
305
|
log.catch(err2, void 0, {
|
|
299
306
|
F: __dxlog_file,
|
|
300
|
-
L:
|
|
307
|
+
L: 283,
|
|
301
308
|
S: this,
|
|
302
309
|
C: (f, a) => f(...a)
|
|
303
310
|
});
|
|
@@ -307,7 +314,7 @@ var Connection = class {
|
|
|
307
314
|
} catch (err2) {
|
|
308
315
|
log.catch(err2, void 0, {
|
|
309
316
|
F: __dxlog_file,
|
|
310
|
-
L:
|
|
317
|
+
L: 289,
|
|
311
318
|
S: this,
|
|
312
319
|
C: (f, a) => f(...a)
|
|
313
320
|
});
|
|
@@ -331,7 +338,7 @@ var Connection = class {
|
|
|
331
338
|
peerId: this.ownId
|
|
332
339
|
}, {
|
|
333
340
|
F: __dxlog_file,
|
|
334
|
-
L:
|
|
341
|
+
L: 314,
|
|
335
342
|
S: this,
|
|
336
343
|
C: (f, a) => f(...a)
|
|
337
344
|
});
|
|
@@ -341,7 +348,7 @@ var Connection = class {
|
|
|
341
348
|
} catch (err2) {
|
|
342
349
|
log.catch(err2, void 0, {
|
|
343
350
|
F: __dxlog_file,
|
|
344
|
-
L:
|
|
351
|
+
L: 321,
|
|
345
352
|
S: this,
|
|
346
353
|
C: (f, a) => f(...a)
|
|
347
354
|
});
|
|
@@ -351,7 +358,7 @@ var Connection = class {
|
|
|
351
358
|
} catch (err2) {
|
|
352
359
|
log.catch(err2, void 0, {
|
|
353
360
|
F: __dxlog_file,
|
|
354
|
-
L:
|
|
361
|
+
L: 328,
|
|
355
362
|
S: this,
|
|
356
363
|
C: (f, a) => f(...a)
|
|
357
364
|
});
|
|
@@ -359,7 +366,7 @@ var Connection = class {
|
|
|
359
366
|
} else {
|
|
360
367
|
log.info(`graceful close requested when we were in ${lastState} state? aborting`, void 0, {
|
|
361
368
|
F: __dxlog_file,
|
|
362
|
-
L:
|
|
369
|
+
L: 331,
|
|
363
370
|
S: this,
|
|
364
371
|
C: (f, a) => f(...a)
|
|
365
372
|
});
|
|
@@ -368,7 +375,7 @@ var Connection = class {
|
|
|
368
375
|
} catch (err2) {
|
|
369
376
|
log.catch(err2, void 0, {
|
|
370
377
|
F: __dxlog_file,
|
|
371
|
-
L:
|
|
378
|
+
L: 335,
|
|
372
379
|
S: this,
|
|
373
380
|
C: (f, a) => f(...a)
|
|
374
381
|
});
|
|
@@ -378,7 +385,7 @@ var Connection = class {
|
|
|
378
385
|
} catch (err2) {
|
|
379
386
|
log.catch(err2, void 0, {
|
|
380
387
|
F: __dxlog_file,
|
|
381
|
-
L:
|
|
388
|
+
L: 340,
|
|
382
389
|
S: this,
|
|
383
390
|
C: (f, a) => f(...a)
|
|
384
391
|
});
|
|
@@ -388,7 +395,7 @@ var Connection = class {
|
|
|
388
395
|
peerId: this.ownId
|
|
389
396
|
}, {
|
|
390
397
|
F: __dxlog_file,
|
|
391
|
-
L:
|
|
398
|
+
L: 344,
|
|
392
399
|
S: this,
|
|
393
400
|
C: (f, a) => f(...a)
|
|
394
401
|
});
|
|
@@ -431,7 +438,7 @@ var Connection = class {
|
|
|
431
438
|
err
|
|
432
439
|
}, {
|
|
433
440
|
F: __dxlog_file,
|
|
434
|
-
L:
|
|
441
|
+
L: 382,
|
|
435
442
|
S: this,
|
|
436
443
|
C: (f, a) => f(...a)
|
|
437
444
|
});
|
|
@@ -444,7 +451,7 @@ var Connection = class {
|
|
|
444
451
|
async signal(msg) {
|
|
445
452
|
invariant(msg.sessionId, void 0, {
|
|
446
453
|
F: __dxlog_file,
|
|
447
|
-
L:
|
|
454
|
+
L: 391,
|
|
448
455
|
S: this,
|
|
449
456
|
A: [
|
|
450
457
|
"msg.sessionId",
|
|
@@ -454,7 +461,7 @@ var Connection = class {
|
|
|
454
461
|
if (!msg.sessionId.equals(this.sessionId)) {
|
|
455
462
|
log("dropping signal for incorrect session id", void 0, {
|
|
456
463
|
F: __dxlog_file,
|
|
457
|
-
L:
|
|
464
|
+
L: 393,
|
|
458
465
|
S: this,
|
|
459
466
|
C: (f, a) => f(...a)
|
|
460
467
|
});
|
|
@@ -462,7 +469,7 @@ var Connection = class {
|
|
|
462
469
|
}
|
|
463
470
|
invariant(msg.data.signal || msg.data.signalBatch, void 0, {
|
|
464
471
|
F: __dxlog_file,
|
|
465
|
-
L:
|
|
472
|
+
L: 396,
|
|
466
473
|
S: this,
|
|
467
474
|
A: [
|
|
468
475
|
"msg.data.signal || msg.data.signalBatch",
|
|
@@ -471,7 +478,7 @@ var Connection = class {
|
|
|
471
478
|
});
|
|
472
479
|
invariant(msg.author?.equals(this.remoteId), void 0, {
|
|
473
480
|
F: __dxlog_file,
|
|
474
|
-
L:
|
|
481
|
+
L: 397,
|
|
475
482
|
S: this,
|
|
476
483
|
A: [
|
|
477
484
|
"msg.author?.equals(this.remoteId)",
|
|
@@ -480,7 +487,7 @@ var Connection = class {
|
|
|
480
487
|
});
|
|
481
488
|
invariant(msg.recipient?.equals(this.ownId), void 0, {
|
|
482
489
|
F: __dxlog_file,
|
|
483
|
-
L:
|
|
490
|
+
L: 398,
|
|
484
491
|
S: this,
|
|
485
492
|
A: [
|
|
486
493
|
"msg.recipient?.equals(this.ownId)",
|
|
@@ -504,7 +511,7 @@ var Connection = class {
|
|
|
504
511
|
msg: msg.data
|
|
505
512
|
}, {
|
|
506
513
|
F: __dxlog_file,
|
|
507
|
-
L:
|
|
514
|
+
L: 407,
|
|
508
515
|
S: this,
|
|
509
516
|
C: (f, a) => f(...a)
|
|
510
517
|
});
|
|
@@ -512,7 +519,7 @@ var Connection = class {
|
|
|
512
519
|
} else {
|
|
513
520
|
invariant(this._transport, "Connection not ready to accept signals.", {
|
|
514
521
|
F: __dxlog_file,
|
|
515
|
-
L:
|
|
522
|
+
L: 410,
|
|
516
523
|
S: this,
|
|
517
524
|
A: [
|
|
518
525
|
"this._transport",
|
|
@@ -525,7 +532,7 @@ var Connection = class {
|
|
|
525
532
|
msg: msg.data
|
|
526
533
|
}, {
|
|
527
534
|
F: __dxlog_file,
|
|
528
|
-
L:
|
|
535
|
+
L: 411,
|
|
529
536
|
S: this,
|
|
530
537
|
C: (f, a) => f(...a)
|
|
531
538
|
});
|
|
@@ -543,13 +550,13 @@ var Connection = class {
|
|
|
543
550
|
peerId: this.ownId
|
|
544
551
|
}, {
|
|
545
552
|
F: __dxlog_file,
|
|
546
|
-
L:
|
|
553
|
+
L: 422,
|
|
547
554
|
S: this,
|
|
548
555
|
C: (f, a) => f(...a)
|
|
549
556
|
});
|
|
550
557
|
invariant(state !== this._state, "Already in this state.", {
|
|
551
558
|
F: __dxlog_file,
|
|
552
|
-
L:
|
|
559
|
+
L: 423,
|
|
553
560
|
S: this,
|
|
554
561
|
A: [
|
|
555
562
|
"state !== this._state",
|
|
@@ -559,7 +566,16 @@ var Connection = class {
|
|
|
559
566
|
this._state = state;
|
|
560
567
|
this.stateChanged.emit(state);
|
|
561
568
|
}
|
|
569
|
+
async _emitTransportStats() {
|
|
570
|
+
const stats = await this.transport?.getStats();
|
|
571
|
+
if (stats) {
|
|
572
|
+
this.transportStats.emit(stats);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
562
575
|
};
|
|
576
|
+
_ts_decorate([
|
|
577
|
+
logInfo
|
|
578
|
+
], Connection.prototype, "sessionIdString", null);
|
|
563
579
|
_ts_decorate([
|
|
564
580
|
synchronized
|
|
565
581
|
], Connection.prototype, "abort", null);
|
|
@@ -816,7 +832,7 @@ import { Context as Context4 } from "@dxos/context";
|
|
|
816
832
|
import { ErrorStream as ErrorStream2 } from "@dxos/debug";
|
|
817
833
|
import { invariant as invariant4 } from "@dxos/invariant";
|
|
818
834
|
import { PublicKey as PublicKey4 } from "@dxos/keys";
|
|
819
|
-
import { log as log4, logInfo } from "@dxos/log";
|
|
835
|
+
import { log as log4, logInfo as logInfo2 } from "@dxos/log";
|
|
820
836
|
import { trace as trace2 } from "@dxos/protocols";
|
|
821
837
|
import { ComplexMap as ComplexMap2, isNotNullOrUndefined } from "@dxos/util";
|
|
822
838
|
|
|
@@ -1780,13 +1796,13 @@ var Swarm = class {
|
|
|
1780
1796
|
}
|
|
1781
1797
|
};
|
|
1782
1798
|
_ts_decorate3([
|
|
1783
|
-
|
|
1799
|
+
logInfo2
|
|
1784
1800
|
], Swarm.prototype, "_instanceId", void 0);
|
|
1785
1801
|
_ts_decorate3([
|
|
1786
|
-
|
|
1802
|
+
logInfo2
|
|
1787
1803
|
], Swarm.prototype, "ownPeerId", null);
|
|
1788
1804
|
_ts_decorate3([
|
|
1789
|
-
|
|
1805
|
+
logInfo2
|
|
1790
1806
|
], Swarm.prototype, "topic", null);
|
|
1791
1807
|
_ts_decorate3([
|
|
1792
1808
|
synchronized3
|
|
@@ -2003,7 +2019,7 @@ var ConnectionLog = class {
|
|
|
2003
2019
|
};
|
|
2004
2020
|
info.connections.push(connectionInfo);
|
|
2005
2021
|
this.update.emit();
|
|
2006
|
-
connection.stateChanged.on((state) => {
|
|
2022
|
+
connection.stateChanged.on(async (state) => {
|
|
2007
2023
|
connectionInfo.state = state;
|
|
2008
2024
|
connectionInfo.closeReason = connection.closeReason;
|
|
2009
2025
|
connectionInfo.lastUpdate = /* @__PURE__ */ new Date();
|
|
@@ -2011,6 +2027,10 @@ var ConnectionLog = class {
|
|
|
2011
2027
|
type: EventType.CONNECTION_STATE_CHANGED,
|
|
2012
2028
|
newState: state
|
|
2013
2029
|
});
|
|
2030
|
+
if (state === ConnectionState.CONNECTED) {
|
|
2031
|
+
const details = await connection.transport?.getDetails();
|
|
2032
|
+
connectionInfo.transportDetails = details;
|
|
2033
|
+
}
|
|
2014
2034
|
this.update.emit();
|
|
2015
2035
|
});
|
|
2016
2036
|
connection.protocol?.stats?.on((stats) => {
|
|
@@ -2020,6 +2040,12 @@ var ConnectionLog = class {
|
|
|
2020
2040
|
connectionInfo.lastUpdate = /* @__PURE__ */ new Date();
|
|
2021
2041
|
this.update.emit();
|
|
2022
2042
|
});
|
|
2043
|
+
connection.transportStats?.on((stats) => {
|
|
2044
|
+
connectionInfo.transportBytesSent = stats.bytesSent;
|
|
2045
|
+
connectionInfo.transportBytesReceived = stats.bytesReceived;
|
|
2046
|
+
connectionInfo.transportPacketsSent = stats.packetsSent;
|
|
2047
|
+
connectionInfo.transportPacketsReceived = stats.packetsReceived;
|
|
2048
|
+
});
|
|
2023
2049
|
gcSwarm(info);
|
|
2024
2050
|
});
|
|
2025
2051
|
}
|
|
@@ -2530,7 +2556,7 @@ import { Event as Event7, Trigger } from "@dxos/async";
|
|
|
2530
2556
|
import { ErrorStream as ErrorStream3 } from "@dxos/debug";
|
|
2531
2557
|
import { invariant as invariant10 } from "@dxos/invariant";
|
|
2532
2558
|
import { PublicKey as PublicKey9 } from "@dxos/keys";
|
|
2533
|
-
import { log as log10, logInfo as
|
|
2559
|
+
import { log as log10, logInfo as logInfo3 } from "@dxos/log";
|
|
2534
2560
|
import { ComplexMap as ComplexMap7 } from "@dxos/util";
|
|
2535
2561
|
function _ts_decorate4(decorators, target, key, desc) {
|
|
2536
2562
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -2705,12 +2731,23 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2705
2731
|
this._remote.wake(remoteId);
|
|
2706
2732
|
}
|
|
2707
2733
|
}
|
|
2734
|
+
async getDetails() {
|
|
2735
|
+
return this._instanceId.toHex();
|
|
2736
|
+
}
|
|
2737
|
+
async getStats() {
|
|
2738
|
+
return {
|
|
2739
|
+
bytesSent: 0,
|
|
2740
|
+
bytesReceived: 0,
|
|
2741
|
+
packetsSent: 0,
|
|
2742
|
+
packetsReceived: 0
|
|
2743
|
+
};
|
|
2744
|
+
}
|
|
2708
2745
|
};
|
|
2709
2746
|
_ts_decorate4([
|
|
2710
|
-
|
|
2747
|
+
logInfo3
|
|
2711
2748
|
], MemoryTransport.prototype, "_instanceId", void 0);
|
|
2712
2749
|
_ts_decorate4([
|
|
2713
|
-
|
|
2750
|
+
logInfo3
|
|
2714
2751
|
], MemoryTransport.prototype, "_remoteInstanceId", void 0);
|
|
2715
2752
|
|
|
2716
2753
|
// packages/core/mesh/network-manager/src/transport/transport.ts
|
|
@@ -2862,7 +2899,7 @@ var SimplePeerTransport = class {
|
|
|
2862
2899
|
this._peer._pc.getStats().then((stats) => {
|
|
2863
2900
|
log11.info("report after webrtc error", {
|
|
2864
2901
|
config: this.params.webrtcConfig,
|
|
2865
|
-
stats
|
|
2902
|
+
stats: Object.fromEntries(stats.entries())
|
|
2866
2903
|
}, {
|
|
2867
2904
|
F: __dxlog_file12,
|
|
2868
2905
|
L: 113,
|
|
@@ -2885,15 +2922,68 @@ var SimplePeerTransport = class {
|
|
|
2885
2922
|
id: this._instanceId
|
|
2886
2923
|
}), {
|
|
2887
2924
|
F: __dxlog_file12,
|
|
2888
|
-
L:
|
|
2925
|
+
L: 126,
|
|
2889
2926
|
S: this,
|
|
2890
2927
|
C: (f, a) => f(...a)
|
|
2891
2928
|
});
|
|
2892
2929
|
}
|
|
2930
|
+
async getStats() {
|
|
2931
|
+
const stats = await this._getStats();
|
|
2932
|
+
if (!stats) {
|
|
2933
|
+
return {
|
|
2934
|
+
bytesSent: 0,
|
|
2935
|
+
bytesReceived: 0,
|
|
2936
|
+
packetsSent: 0,
|
|
2937
|
+
packetsReceived: 0,
|
|
2938
|
+
rawStats: {}
|
|
2939
|
+
};
|
|
2940
|
+
}
|
|
2941
|
+
return {
|
|
2942
|
+
bytesSent: stats.transport.bytesSent,
|
|
2943
|
+
bytesReceived: stats.transport.bytesReceived,
|
|
2944
|
+
packetsSent: stats.transport.messagesSent,
|
|
2945
|
+
packetsReceived: stats.transport.messagesReceived,
|
|
2946
|
+
rawStats: stats.raw
|
|
2947
|
+
};
|
|
2948
|
+
}
|
|
2949
|
+
async _getStats() {
|
|
2950
|
+
if (typeof this._peer?._pc?.getStats !== "function") {
|
|
2951
|
+
return null;
|
|
2952
|
+
}
|
|
2953
|
+
return await this._peer._pc.getStats().then((stats) => {
|
|
2954
|
+
const statsEntries = Array.from(stats.entries());
|
|
2955
|
+
const transport = statsEntries.filter((s) => s[1].type === "transport")[0][1];
|
|
2956
|
+
const candidatePair = statsEntries.filter((s) => s[0] === transport.selectedCandidatePairId);
|
|
2957
|
+
let selectedCandidatePair;
|
|
2958
|
+
let remoteCandidate;
|
|
2959
|
+
if (candidatePair.length > 0) {
|
|
2960
|
+
selectedCandidatePair = candidatePair[0][1];
|
|
2961
|
+
remoteCandidate = statsEntries.filter((s) => s[0] === selectedCandidatePair.remoteCandidateId)[0][1];
|
|
2962
|
+
}
|
|
2963
|
+
return {
|
|
2964
|
+
datachannel: statsEntries.filter((s) => s[1].type === "data-channel")[0][1],
|
|
2965
|
+
transport,
|
|
2966
|
+
selectedCandidatePair,
|
|
2967
|
+
remoteCandidate,
|
|
2968
|
+
raw: Object.fromEntries(stats.entries())
|
|
2969
|
+
};
|
|
2970
|
+
});
|
|
2971
|
+
}
|
|
2972
|
+
async getDetails() {
|
|
2973
|
+
const stats = await this._getStats();
|
|
2974
|
+
const rc = stats?.remoteCandidate;
|
|
2975
|
+
if (!rc) {
|
|
2976
|
+
return "unavailable";
|
|
2977
|
+
}
|
|
2978
|
+
if (rc.relay) {
|
|
2979
|
+
return `${rc.ip}:${rc.port}/${rc.protocol} relay for XXX ${rc.candidateType}`;
|
|
2980
|
+
}
|
|
2981
|
+
return `${rc.ip}:${rc.port}/${rc.protocol} ${rc.candidateType}`;
|
|
2982
|
+
}
|
|
2893
2983
|
async destroy() {
|
|
2894
2984
|
log11("closing...", void 0, {
|
|
2895
2985
|
F: __dxlog_file12,
|
|
2896
|
-
L:
|
|
2986
|
+
L: 189,
|
|
2897
2987
|
S: this,
|
|
2898
2988
|
C: (f, a) => f(...a)
|
|
2899
2989
|
});
|
|
@@ -2903,10 +2993,11 @@ var SimplePeerTransport = class {
|
|
|
2903
2993
|
this._closed = true;
|
|
2904
2994
|
this._disconnectStreams();
|
|
2905
2995
|
this._peer.destroy();
|
|
2996
|
+
this._closed = true;
|
|
2906
2997
|
this.closed.emit();
|
|
2907
2998
|
log11("closed", void 0, {
|
|
2908
2999
|
F: __dxlog_file12,
|
|
2909
|
-
L:
|
|
3000
|
+
L: 198,
|
|
2910
3001
|
S: this,
|
|
2911
3002
|
C: (f, a) => f(...a)
|
|
2912
3003
|
});
|
|
@@ -3021,7 +3112,7 @@ var SimplePeerTransportService = class {
|
|
|
3021
3112
|
async sendSignal({ proxyId, signal }) {
|
|
3022
3113
|
invariant12(this.transports.has(proxyId), void 0, {
|
|
3023
3114
|
F: __dxlog_file13,
|
|
3024
|
-
L:
|
|
3115
|
+
L: 116,
|
|
3025
3116
|
S: this,
|
|
3026
3117
|
A: [
|
|
3027
3118
|
"this.transports.has(proxyId)",
|
|
@@ -3030,18 +3121,46 @@ var SimplePeerTransportService = class {
|
|
|
3030
3121
|
});
|
|
3031
3122
|
await this.transports.get(proxyId).transport.signal(signal);
|
|
3032
3123
|
}
|
|
3124
|
+
async getDetails({ proxyId }) {
|
|
3125
|
+
invariant12(this.transports.has(proxyId), void 0, {
|
|
3126
|
+
F: __dxlog_file13,
|
|
3127
|
+
L: 121,
|
|
3128
|
+
S: this,
|
|
3129
|
+
A: [
|
|
3130
|
+
"this.transports.has(proxyId)",
|
|
3131
|
+
""
|
|
3132
|
+
]
|
|
3133
|
+
});
|
|
3134
|
+
return {
|
|
3135
|
+
details: await this.transports.get(proxyId).transport.getDetails()
|
|
3136
|
+
};
|
|
3137
|
+
}
|
|
3138
|
+
async getStats({ proxyId }) {
|
|
3139
|
+
invariant12(this.transports.has(proxyId), void 0, {
|
|
3140
|
+
F: __dxlog_file13,
|
|
3141
|
+
L: 126,
|
|
3142
|
+
S: this,
|
|
3143
|
+
A: [
|
|
3144
|
+
"this.transports.has(proxyId)",
|
|
3145
|
+
""
|
|
3146
|
+
]
|
|
3147
|
+
});
|
|
3148
|
+
return {
|
|
3149
|
+
stats: await this.transports.get(proxyId).transport.getStats()
|
|
3150
|
+
};
|
|
3151
|
+
}
|
|
3033
3152
|
async sendData({ proxyId, payload }) {
|
|
3034
3153
|
if (this.transports.get(proxyId)?.state !== "OPEN") {
|
|
3035
3154
|
log12.debug("transport is closed", void 0, {
|
|
3036
3155
|
F: __dxlog_file13,
|
|
3037
|
-
L:
|
|
3156
|
+
L: 132,
|
|
3038
3157
|
S: this,
|
|
3039
3158
|
C: (f, a) => f(...a)
|
|
3040
3159
|
});
|
|
3041
3160
|
}
|
|
3042
3161
|
invariant12(this.transports.has(proxyId), void 0, {
|
|
3043
3162
|
F: __dxlog_file13,
|
|
3044
|
-
L:
|
|
3163
|
+
L: 134,
|
|
3045
3164
|
S: this,
|
|
3046
3165
|
A: [
|
|
3047
3166
|
"this.transports.has(proxyId)",
|
|
@@ -3064,7 +3183,7 @@ var SimplePeerTransportService = class {
|
|
|
3064
3183
|
}
|
|
3065
3184
|
log12("Closed.", void 0, {
|
|
3066
3185
|
F: __dxlog_file13,
|
|
3067
|
-
L:
|
|
3186
|
+
L: 150,
|
|
3068
3187
|
S: this,
|
|
3069
3188
|
C: (f, a) => f(...a)
|
|
3070
3189
|
});
|
|
@@ -3203,6 +3322,16 @@ var SimplePeerTransportProxy = class {
|
|
|
3203
3322
|
signal
|
|
3204
3323
|
}).catch((err) => this.errors.raise(decodeError(err)));
|
|
3205
3324
|
}
|
|
3325
|
+
async getDetails() {
|
|
3326
|
+
return (await this._params.bridgeService.getDetails({
|
|
3327
|
+
proxyId: this._proxyId
|
|
3328
|
+
})).details;
|
|
3329
|
+
}
|
|
3330
|
+
async getStats() {
|
|
3331
|
+
return (await this._params.bridgeService.getStats({
|
|
3332
|
+
proxyId: this._proxyId
|
|
3333
|
+
})).stats;
|
|
3334
|
+
}
|
|
3206
3335
|
// TODO(burdon): Move open from constructor.
|
|
3207
3336
|
async destroy() {
|
|
3208
3337
|
await this._ctx.dispose();
|
|
@@ -3217,7 +3346,7 @@ var SimplePeerTransportProxy = class {
|
|
|
3217
3346
|
} catch (err) {
|
|
3218
3347
|
log13.catch(err, void 0, {
|
|
3219
3348
|
F: __dxlog_file14,
|
|
3220
|
-
L:
|
|
3349
|
+
L: 168,
|
|
3221
3350
|
S: this,
|
|
3222
3351
|
C: (f, a) => f(...a)
|
|
3223
3352
|
});
|
|
@@ -3253,7 +3382,7 @@ var SimplePeerTransportProxyFactory = class {
|
|
|
3253
3382
|
createTransport(options) {
|
|
3254
3383
|
invariant13(this._bridgeService, "SimplePeerTransportProxyFactory is not ready to open connections", {
|
|
3255
3384
|
F: __dxlog_file14,
|
|
3256
|
-
L:
|
|
3385
|
+
L: 205,
|
|
3257
3386
|
S: this,
|
|
3258
3387
|
A: [
|
|
3259
3388
|
"this._bridgeService",
|
|
@@ -3612,6 +3741,46 @@ var LibDataChannelTransport = class {
|
|
|
3612
3741
|
});
|
|
3613
3742
|
});
|
|
3614
3743
|
}
|
|
3744
|
+
async getDetails() {
|
|
3745
|
+
return this._peer.then(async (peer) => {
|
|
3746
|
+
const cp = await peer.getSelectedCandidatePair();
|
|
3747
|
+
if (!cp) {
|
|
3748
|
+
return "unavailable";
|
|
3749
|
+
}
|
|
3750
|
+
return `${cp.remote.address}:${cp.remote.port}/${cp.remote.transportType} ${cp.remote.type}`;
|
|
3751
|
+
}).catch((err) => {
|
|
3752
|
+
log14.catch(err, void 0, {
|
|
3753
|
+
F: __dxlog_file15,
|
|
3754
|
+
L: 250,
|
|
3755
|
+
S: this,
|
|
3756
|
+
C: (f, a) => f(...a)
|
|
3757
|
+
});
|
|
3758
|
+
return "unavailable";
|
|
3759
|
+
});
|
|
3760
|
+
}
|
|
3761
|
+
async getStats() {
|
|
3762
|
+
return this._peer.then((peer) => {
|
|
3763
|
+
return {
|
|
3764
|
+
bytesSent: peer.bytesSent(),
|
|
3765
|
+
bytesReceived: peer.bytesReceived(),
|
|
3766
|
+
packetsSent: 0,
|
|
3767
|
+
packetsReceived: 0
|
|
3768
|
+
};
|
|
3769
|
+
}).catch((err) => {
|
|
3770
|
+
log14.catch(err, void 0, {
|
|
3771
|
+
F: __dxlog_file15,
|
|
3772
|
+
L: 266,
|
|
3773
|
+
S: this,
|
|
3774
|
+
C: (f, a) => f(...a)
|
|
3775
|
+
});
|
|
3776
|
+
return {
|
|
3777
|
+
bytesSent: 0,
|
|
3778
|
+
bytesReceived: 0,
|
|
3779
|
+
packetsSent: 0,
|
|
3780
|
+
packetsReceived: 0
|
|
3781
|
+
};
|
|
3782
|
+
});
|
|
3783
|
+
}
|
|
3615
3784
|
// TODO(nf): add classmethod to call node-datachannel.cleanup() when all instances have been destroyed?
|
|
3616
3785
|
async destroy() {
|
|
3617
3786
|
await this._close();
|
|
@@ -3648,6 +3817,12 @@ var TcpTransport = class {
|
|
|
3648
3817
|
signal() {
|
|
3649
3818
|
throw new Error("Method not implemented.");
|
|
3650
3819
|
}
|
|
3820
|
+
async getStats() {
|
|
3821
|
+
throw new Error("Method not implemented.");
|
|
3822
|
+
}
|
|
3823
|
+
async getDetails() {
|
|
3824
|
+
throw new Error("Method not implemented.");
|
|
3825
|
+
}
|
|
3651
3826
|
};
|
|
3652
3827
|
|
|
3653
3828
|
// packages/core/mesh/network-manager/src/wire-protocol.ts
|
|
@@ -3657,8 +3832,8 @@ var createTeleportProtocolFactory = (onConnection) => {
|
|
|
3657
3832
|
const teleport = new Teleport(params);
|
|
3658
3833
|
return {
|
|
3659
3834
|
stream: teleport.stream,
|
|
3660
|
-
open: async () => {
|
|
3661
|
-
await teleport.open();
|
|
3835
|
+
open: async (sessionId) => {
|
|
3836
|
+
await teleport.open(sessionId);
|
|
3662
3837
|
await onConnection(teleport);
|
|
3663
3838
|
},
|
|
3664
3839
|
close: async () => {
|
|
@@ -3699,4 +3874,4 @@ export {
|
|
|
3699
3874
|
TcpTransport,
|
|
3700
3875
|
createTeleportProtocolFactory
|
|
3701
3876
|
};
|
|
3702
|
-
//# sourceMappingURL=chunk-
|
|
3877
|
+
//# sourceMappingURL=chunk-S2JHWVGQ.mjs.map
|