@dxos/network-manager 0.3.9-main.b7e6a67 → 0.3.9-main.c2ac8a5
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-LA2ACGLR.mjs → chunk-Q5B7EFTV.mjs} +382 -103
- package/dist/lib/browser/chunk-Q5B7EFTV.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-XE5JOIGD.cjs → chunk-JDKM4UPJ.cjs} +21 -13
- package/dist/lib/node/chunk-JDKM4UPJ.cjs.map +7 -0
- package/dist/lib/node/{chunk-QWUG7JSH.cjs → chunk-YLQJ2ALQ.cjs} +384 -95
- package/dist/lib/node/chunk-YLQJ2ALQ.cjs.map +7 -0
- package/dist/lib/node/{datachannel-53JZPGFA.cjs → datachannel-3VTTIMR5.cjs} +9 -9
- package/dist/lib/node/{datachannel-53JZPGFA.cjs.map → datachannel-3VTTIMR5.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/topology/mmst-topology.d.ts +1 -0
- package/dist/types/src/topology/mmst-topology.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 +7 -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 +40 -6
- package/src/topology/mmst-topology.ts +35 -7
- package/src/transport/datachannel/rtc-peer-connection.ts +20 -12
- package/src/transport/libdatachannel-transport.test.ts +0 -4
- package/src/transport/libdatachannel-transport.ts +44 -4
- 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 +70 -4
- 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-LA2ACGLR.mjs.map +0 -7
- package/dist/lib/node/chunk-QWUG7JSH.cjs.map +0 -7
- package/dist/lib/node/chunk-XE5JOIGD.cjs.map +0 -7
|
@@ -4,13 +4,13 @@ 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";
|
|
13
|
-
import { CancelledError, ProtocolError, ConnectionResetError, ConnectivityError, UnknownProtocolError, trace } from "@dxos/protocols";
|
|
12
|
+
import { log, logInfo } from "@dxos/log";
|
|
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;
|
|
16
16
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -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,35 +146,35 @@ 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
|
});
|
|
159
164
|
this.close(new ProtocolError("protocol stream closed")).catch((err) => this.errors.raise(err));
|
|
160
165
|
});
|
|
161
166
|
scheduleTask(this.connectedTimeoutContext, async () => {
|
|
162
|
-
log.info(
|
|
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
|
});
|
|
168
|
-
await this.abort().catch((err) => this.errors.raise(err));
|
|
173
|
+
await this.abort(new TimeoutError(`${TRANSPORT_CONNECTION_TIMEOUT / 1e3}s for transport to connect`)).catch((err) => this.errors.raise(err));
|
|
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,34 @@ var Connection = class {
|
|
|
341
348
|
} catch (err2) {
|
|
342
349
|
log.catch(err2, void 0, {
|
|
343
350
|
F: __dxlog_file,
|
|
344
|
-
L:
|
|
351
|
+
L: 321,
|
|
352
|
+
S: this,
|
|
353
|
+
C: (f, a) => f(...a)
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
try {
|
|
357
|
+
await this._transport?.destroy();
|
|
358
|
+
} catch (err2) {
|
|
359
|
+
log.catch(err2, void 0, {
|
|
360
|
+
F: __dxlog_file,
|
|
361
|
+
L: 328,
|
|
362
|
+
S: this,
|
|
363
|
+
C: (f, a) => f(...a)
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
} else {
|
|
367
|
+
log.info(`graceful close requested when we were in ${lastState} state? aborting`, void 0, {
|
|
368
|
+
F: __dxlog_file,
|
|
369
|
+
L: 331,
|
|
370
|
+
S: this,
|
|
371
|
+
C: (f, a) => f(...a)
|
|
372
|
+
});
|
|
373
|
+
try {
|
|
374
|
+
await this._protocol.abort();
|
|
375
|
+
} catch (err2) {
|
|
376
|
+
log.catch(err2, void 0, {
|
|
377
|
+
F: __dxlog_file,
|
|
378
|
+
L: 335,
|
|
345
379
|
S: this,
|
|
346
380
|
C: (f, a) => f(...a)
|
|
347
381
|
});
|
|
@@ -351,7 +385,7 @@ var Connection = class {
|
|
|
351
385
|
} catch (err2) {
|
|
352
386
|
log.catch(err2, void 0, {
|
|
353
387
|
F: __dxlog_file,
|
|
354
|
-
L:
|
|
388
|
+
L: 340,
|
|
355
389
|
S: this,
|
|
356
390
|
C: (f, a) => f(...a)
|
|
357
391
|
});
|
|
@@ -361,7 +395,7 @@ var Connection = class {
|
|
|
361
395
|
peerId: this.ownId
|
|
362
396
|
}, {
|
|
363
397
|
F: __dxlog_file,
|
|
364
|
-
L:
|
|
398
|
+
L: 344,
|
|
365
399
|
S: this,
|
|
366
400
|
C: (f, a) => f(...a)
|
|
367
401
|
});
|
|
@@ -404,7 +438,7 @@ var Connection = class {
|
|
|
404
438
|
err
|
|
405
439
|
}, {
|
|
406
440
|
F: __dxlog_file,
|
|
407
|
-
L:
|
|
441
|
+
L: 382,
|
|
408
442
|
S: this,
|
|
409
443
|
C: (f, a) => f(...a)
|
|
410
444
|
});
|
|
@@ -417,7 +451,7 @@ var Connection = class {
|
|
|
417
451
|
async signal(msg) {
|
|
418
452
|
invariant(msg.sessionId, void 0, {
|
|
419
453
|
F: __dxlog_file,
|
|
420
|
-
L:
|
|
454
|
+
L: 391,
|
|
421
455
|
S: this,
|
|
422
456
|
A: [
|
|
423
457
|
"msg.sessionId",
|
|
@@ -427,7 +461,7 @@ var Connection = class {
|
|
|
427
461
|
if (!msg.sessionId.equals(this.sessionId)) {
|
|
428
462
|
log("dropping signal for incorrect session id", void 0, {
|
|
429
463
|
F: __dxlog_file,
|
|
430
|
-
L:
|
|
464
|
+
L: 393,
|
|
431
465
|
S: this,
|
|
432
466
|
C: (f, a) => f(...a)
|
|
433
467
|
});
|
|
@@ -435,7 +469,7 @@ var Connection = class {
|
|
|
435
469
|
}
|
|
436
470
|
invariant(msg.data.signal || msg.data.signalBatch, void 0, {
|
|
437
471
|
F: __dxlog_file,
|
|
438
|
-
L:
|
|
472
|
+
L: 396,
|
|
439
473
|
S: this,
|
|
440
474
|
A: [
|
|
441
475
|
"msg.data.signal || msg.data.signalBatch",
|
|
@@ -444,7 +478,7 @@ var Connection = class {
|
|
|
444
478
|
});
|
|
445
479
|
invariant(msg.author?.equals(this.remoteId), void 0, {
|
|
446
480
|
F: __dxlog_file,
|
|
447
|
-
L:
|
|
481
|
+
L: 397,
|
|
448
482
|
S: this,
|
|
449
483
|
A: [
|
|
450
484
|
"msg.author?.equals(this.remoteId)",
|
|
@@ -453,7 +487,7 @@ var Connection = class {
|
|
|
453
487
|
});
|
|
454
488
|
invariant(msg.recipient?.equals(this.ownId), void 0, {
|
|
455
489
|
F: __dxlog_file,
|
|
456
|
-
L:
|
|
490
|
+
L: 398,
|
|
457
491
|
S: this,
|
|
458
492
|
A: [
|
|
459
493
|
"msg.recipient?.equals(this.ownId)",
|
|
@@ -477,7 +511,7 @@ var Connection = class {
|
|
|
477
511
|
msg: msg.data
|
|
478
512
|
}, {
|
|
479
513
|
F: __dxlog_file,
|
|
480
|
-
L:
|
|
514
|
+
L: 407,
|
|
481
515
|
S: this,
|
|
482
516
|
C: (f, a) => f(...a)
|
|
483
517
|
});
|
|
@@ -485,7 +519,7 @@ var Connection = class {
|
|
|
485
519
|
} else {
|
|
486
520
|
invariant(this._transport, "Connection not ready to accept signals.", {
|
|
487
521
|
F: __dxlog_file,
|
|
488
|
-
L:
|
|
522
|
+
L: 410,
|
|
489
523
|
S: this,
|
|
490
524
|
A: [
|
|
491
525
|
"this._transport",
|
|
@@ -498,7 +532,7 @@ var Connection = class {
|
|
|
498
532
|
msg: msg.data
|
|
499
533
|
}, {
|
|
500
534
|
F: __dxlog_file,
|
|
501
|
-
L:
|
|
535
|
+
L: 411,
|
|
502
536
|
S: this,
|
|
503
537
|
C: (f, a) => f(...a)
|
|
504
538
|
});
|
|
@@ -516,13 +550,13 @@ var Connection = class {
|
|
|
516
550
|
peerId: this.ownId
|
|
517
551
|
}, {
|
|
518
552
|
F: __dxlog_file,
|
|
519
|
-
L:
|
|
553
|
+
L: 422,
|
|
520
554
|
S: this,
|
|
521
555
|
C: (f, a) => f(...a)
|
|
522
556
|
});
|
|
523
557
|
invariant(state !== this._state, "Already in this state.", {
|
|
524
558
|
F: __dxlog_file,
|
|
525
|
-
L:
|
|
559
|
+
L: 423,
|
|
526
560
|
S: this,
|
|
527
561
|
A: [
|
|
528
562
|
"state !== this._state",
|
|
@@ -532,7 +566,16 @@ var Connection = class {
|
|
|
532
566
|
this._state = state;
|
|
533
567
|
this.stateChanged.emit(state);
|
|
534
568
|
}
|
|
569
|
+
async _emitTransportStats() {
|
|
570
|
+
const stats = await this.transport?.getStats();
|
|
571
|
+
if (stats) {
|
|
572
|
+
this.transportStats.emit(stats);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
535
575
|
};
|
|
576
|
+
_ts_decorate([
|
|
577
|
+
logInfo
|
|
578
|
+
], Connection.prototype, "sessionIdString", null);
|
|
536
579
|
_ts_decorate([
|
|
537
580
|
synchronized
|
|
538
581
|
], Connection.prototype, "abort", null);
|
|
@@ -545,7 +588,7 @@ import { Context as Context2 } from "@dxos/context";
|
|
|
545
588
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
546
589
|
import { PublicKey as PublicKey2 } from "@dxos/keys";
|
|
547
590
|
import { log as log2 } from "@dxos/log";
|
|
548
|
-
import { schema, TimeoutError } from "@dxos/protocols";
|
|
591
|
+
import { schema, TimeoutError as TimeoutError2 } from "@dxos/protocols";
|
|
549
592
|
import { ComplexMap } from "@dxos/util";
|
|
550
593
|
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
|
|
551
594
|
var SwarmMessage = schema.getCodecForType("dxos.mesh.swarm.SwarmMessage");
|
|
@@ -730,7 +773,7 @@ var SwarmMessenger = class {
|
|
|
730
773
|
}
|
|
731
774
|
});
|
|
732
775
|
} catch (err) {
|
|
733
|
-
if (err instanceof
|
|
776
|
+
if (err instanceof TimeoutError2) {
|
|
734
777
|
log2.info("timeout sending answer to offer", {
|
|
735
778
|
err
|
|
736
779
|
}, {
|
|
@@ -789,7 +832,7 @@ import { Context as Context4 } from "@dxos/context";
|
|
|
789
832
|
import { ErrorStream as ErrorStream2 } from "@dxos/debug";
|
|
790
833
|
import { invariant as invariant4 } from "@dxos/invariant";
|
|
791
834
|
import { PublicKey as PublicKey4 } from "@dxos/keys";
|
|
792
|
-
import { log as log4, logInfo } from "@dxos/log";
|
|
835
|
+
import { log as log4, logInfo as logInfo2 } from "@dxos/log";
|
|
793
836
|
import { trace as trace2 } from "@dxos/protocols";
|
|
794
837
|
import { ComplexMap as ComplexMap2, isNotNullOrUndefined } from "@dxos/util";
|
|
795
838
|
|
|
@@ -1753,13 +1796,13 @@ var Swarm = class {
|
|
|
1753
1796
|
}
|
|
1754
1797
|
};
|
|
1755
1798
|
_ts_decorate3([
|
|
1756
|
-
|
|
1799
|
+
logInfo2
|
|
1757
1800
|
], Swarm.prototype, "_instanceId", void 0);
|
|
1758
1801
|
_ts_decorate3([
|
|
1759
|
-
|
|
1802
|
+
logInfo2
|
|
1760
1803
|
], Swarm.prototype, "ownPeerId", null);
|
|
1761
1804
|
_ts_decorate3([
|
|
1762
|
-
|
|
1805
|
+
logInfo2
|
|
1763
1806
|
], Swarm.prototype, "topic", null);
|
|
1764
1807
|
_ts_decorate3([
|
|
1765
1808
|
synchronized3
|
|
@@ -1976,7 +2019,7 @@ var ConnectionLog = class {
|
|
|
1976
2019
|
};
|
|
1977
2020
|
info.connections.push(connectionInfo);
|
|
1978
2021
|
this.update.emit();
|
|
1979
|
-
connection.stateChanged.on((state) => {
|
|
2022
|
+
connection.stateChanged.on(async (state) => {
|
|
1980
2023
|
connectionInfo.state = state;
|
|
1981
2024
|
connectionInfo.closeReason = connection.closeReason;
|
|
1982
2025
|
connectionInfo.lastUpdate = /* @__PURE__ */ new Date();
|
|
@@ -1984,6 +2027,10 @@ var ConnectionLog = class {
|
|
|
1984
2027
|
type: EventType.CONNECTION_STATE_CHANGED,
|
|
1985
2028
|
newState: state
|
|
1986
2029
|
});
|
|
2030
|
+
if (state === ConnectionState.CONNECTED) {
|
|
2031
|
+
const details = await connection.transport?.getDetails();
|
|
2032
|
+
connectionInfo.transportDetails = details;
|
|
2033
|
+
}
|
|
1987
2034
|
this.update.emit();
|
|
1988
2035
|
});
|
|
1989
2036
|
connection.protocol?.stats?.on((stats) => {
|
|
@@ -1993,6 +2040,12 @@ var ConnectionLog = class {
|
|
|
1993
2040
|
connectionInfo.lastUpdate = /* @__PURE__ */ new Date();
|
|
1994
2041
|
this.update.emit();
|
|
1995
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
|
+
});
|
|
1996
2049
|
gcSwarm(info);
|
|
1997
2050
|
});
|
|
1998
2051
|
}
|
|
@@ -2296,9 +2349,12 @@ import distance from "xor-distance";
|
|
|
2296
2349
|
import { invariant as invariant8 } from "@dxos/invariant";
|
|
2297
2350
|
import { log as log8 } from "@dxos/log";
|
|
2298
2351
|
var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/mmst-topology.ts";
|
|
2352
|
+
var MIN_UPDATE_INTERVAL = 1e3 * 10;
|
|
2353
|
+
var MAX_CHANGES_PER_UPDATE = 1;
|
|
2299
2354
|
var MMSTTopology = class {
|
|
2300
2355
|
constructor({ originateConnections = 2, maxPeers = 4, sampleSize = 10 } = {}) {
|
|
2301
2356
|
this._sampleCollected = false;
|
|
2357
|
+
this._lastAction = /* @__PURE__ */ new Date(0);
|
|
2302
2358
|
this._originateConnections = originateConnections;
|
|
2303
2359
|
this._maxPeers = maxPeers;
|
|
2304
2360
|
this._sampleSize = sampleSize;
|
|
@@ -2306,7 +2362,7 @@ var MMSTTopology = class {
|
|
|
2306
2362
|
init(controller) {
|
|
2307
2363
|
invariant8(!this._controller, "Already initialized", {
|
|
2308
2364
|
F: __dxlog_file9,
|
|
2309
|
-
L:
|
|
2365
|
+
L: 51,
|
|
2310
2366
|
S: this,
|
|
2311
2367
|
A: [
|
|
2312
2368
|
"!this._controller",
|
|
@@ -2318,7 +2374,7 @@ var MMSTTopology = class {
|
|
|
2318
2374
|
update() {
|
|
2319
2375
|
invariant8(this._controller, "Not initialized", {
|
|
2320
2376
|
F: __dxlog_file9,
|
|
2321
|
-
L:
|
|
2377
|
+
L: 56,
|
|
2322
2378
|
S: this,
|
|
2323
2379
|
A: [
|
|
2324
2380
|
"this._controller",
|
|
@@ -2327,9 +2383,9 @@ var MMSTTopology = class {
|
|
|
2327
2383
|
});
|
|
2328
2384
|
const { connected, candidates } = this._controller.getState();
|
|
2329
2385
|
if (this._sampleCollected || connected.length > this._maxPeers || candidates.length > 0) {
|
|
2330
|
-
log8("Running the algorithm.", void 0, {
|
|
2386
|
+
log8.info("Running the algorithm.", void 0, {
|
|
2331
2387
|
F: __dxlog_file9,
|
|
2332
|
-
L:
|
|
2388
|
+
L: 60,
|
|
2333
2389
|
S: this,
|
|
2334
2390
|
C: (f, a) => f(...a)
|
|
2335
2391
|
});
|
|
@@ -2340,7 +2396,7 @@ var MMSTTopology = class {
|
|
|
2340
2396
|
async onOffer(peer) {
|
|
2341
2397
|
invariant8(this._controller, "Not initialized", {
|
|
2342
2398
|
F: __dxlog_file9,
|
|
2343
|
-
L:
|
|
2399
|
+
L: 67,
|
|
2344
2400
|
S: this,
|
|
2345
2401
|
A: [
|
|
2346
2402
|
"this._controller",
|
|
@@ -2351,7 +2407,7 @@ var MMSTTopology = class {
|
|
|
2351
2407
|
const accept = connected.length < this._maxPeers;
|
|
2352
2408
|
log8(`Offer ${peer} accept=${accept}`, void 0, {
|
|
2353
2409
|
F: __dxlog_file9,
|
|
2354
|
-
L:
|
|
2410
|
+
L: 70,
|
|
2355
2411
|
S: this,
|
|
2356
2412
|
C: (f, a) => f(...a)
|
|
2357
2413
|
});
|
|
@@ -2362,7 +2418,7 @@ var MMSTTopology = class {
|
|
|
2362
2418
|
_runAlgorithm() {
|
|
2363
2419
|
invariant8(this._controller, "Not initialized", {
|
|
2364
2420
|
F: __dxlog_file9,
|
|
2365
|
-
L:
|
|
2421
|
+
L: 79,
|
|
2366
2422
|
S: this,
|
|
2367
2423
|
A: [
|
|
2368
2424
|
"this._controller",
|
|
@@ -2371,27 +2427,84 @@ var MMSTTopology = class {
|
|
|
2371
2427
|
});
|
|
2372
2428
|
const { connected, candidates, ownPeerId } = this._controller.getState();
|
|
2373
2429
|
if (connected.length > this._maxPeers) {
|
|
2430
|
+
log8.info(`disconnect ${connected.length - this._maxPeers} peers.`, void 0, {
|
|
2431
|
+
F: __dxlog_file9,
|
|
2432
|
+
L: 85,
|
|
2433
|
+
S: this,
|
|
2434
|
+
C: (f, a) => f(...a)
|
|
2435
|
+
});
|
|
2374
2436
|
const sorted = sortByXorDistance(connected, ownPeerId).reverse().slice(0, this._maxPeers - connected.length);
|
|
2375
|
-
|
|
2376
|
-
|
|
2437
|
+
invariant8(sorted.length === 0, void 0, {
|
|
2438
|
+
F: __dxlog_file9,
|
|
2439
|
+
L: 89,
|
|
2440
|
+
S: this,
|
|
2441
|
+
A: [
|
|
2442
|
+
"sorted.length === 0",
|
|
2443
|
+
""
|
|
2444
|
+
]
|
|
2445
|
+
});
|
|
2446
|
+
if (sorted.length > MAX_CHANGES_PER_UPDATE) {
|
|
2447
|
+
log8(`want to disconnect ${sorted.length} peers but limited to ${MAX_CHANGES_PER_UPDATE}`, void 0, {
|
|
2448
|
+
F: __dxlog_file9,
|
|
2449
|
+
L: 92,
|
|
2450
|
+
S: this,
|
|
2451
|
+
C: (f, a) => f(...a)
|
|
2452
|
+
});
|
|
2453
|
+
}
|
|
2454
|
+
if (Date.now() - this._lastAction.getTime() > MIN_UPDATE_INTERVAL) {
|
|
2455
|
+
for (const peer of sorted.slice(0, MAX_CHANGES_PER_UPDATE)) {
|
|
2456
|
+
log8.info(`Disconnect ${peer}.`, void 0, {
|
|
2457
|
+
F: __dxlog_file9,
|
|
2458
|
+
L: 97,
|
|
2459
|
+
S: this,
|
|
2460
|
+
C: (f, a) => f(...a)
|
|
2461
|
+
});
|
|
2462
|
+
this._controller.disconnect(peer);
|
|
2463
|
+
}
|
|
2464
|
+
this._lastAction = /* @__PURE__ */ new Date();
|
|
2465
|
+
} else {
|
|
2466
|
+
log8.info("rate limited discconnect", void 0, {
|
|
2377
2467
|
F: __dxlog_file9,
|
|
2378
|
-
L:
|
|
2468
|
+
L: 102,
|
|
2379
2469
|
S: this,
|
|
2380
2470
|
C: (f, a) => f(...a)
|
|
2381
2471
|
});
|
|
2382
|
-
this._controller.disconnect(peer);
|
|
2383
2472
|
}
|
|
2384
2473
|
} else if (connected.length < this._originateConnections) {
|
|
2474
|
+
log8.info(`connect ${this._originateConnections - connected.length} peers.`, void 0, {
|
|
2475
|
+
F: __dxlog_file9,
|
|
2476
|
+
L: 106,
|
|
2477
|
+
S: this,
|
|
2478
|
+
C: (f, a) => f(...a)
|
|
2479
|
+
});
|
|
2385
2480
|
const sample = candidates.sort(() => Math.random() - 0.5).slice(0, this._sampleSize);
|
|
2386
2481
|
const sorted = sortByXorDistance(sample, ownPeerId).slice(0, this._originateConnections - connected.length);
|
|
2387
|
-
|
|
2388
|
-
log8(`
|
|
2482
|
+
if (sorted.length > MAX_CHANGES_PER_UPDATE) {
|
|
2483
|
+
log8(`want to connect ${sorted.length} peers but limited to ${MAX_CHANGES_PER_UPDATE}`, void 0, {
|
|
2389
2484
|
F: __dxlog_file9,
|
|
2390
|
-
L:
|
|
2485
|
+
L: 111,
|
|
2486
|
+
S: this,
|
|
2487
|
+
C: (f, a) => f(...a)
|
|
2488
|
+
});
|
|
2489
|
+
}
|
|
2490
|
+
if (Date.now() - this._lastAction.getTime() > MIN_UPDATE_INTERVAL) {
|
|
2491
|
+
for (const peer of sorted.slice(0, MAX_CHANGES_PER_UPDATE)) {
|
|
2492
|
+
log8.info(`Connect ${peer}.`, void 0, {
|
|
2493
|
+
F: __dxlog_file9,
|
|
2494
|
+
L: 115,
|
|
2495
|
+
S: this,
|
|
2496
|
+
C: (f, a) => f(...a)
|
|
2497
|
+
});
|
|
2498
|
+
this._controller.connect(peer);
|
|
2499
|
+
}
|
|
2500
|
+
this._lastAction = /* @__PURE__ */ new Date();
|
|
2501
|
+
} else {
|
|
2502
|
+
log8.info("rate limited connect", void 0, {
|
|
2503
|
+
F: __dxlog_file9,
|
|
2504
|
+
L: 120,
|
|
2391
2505
|
S: this,
|
|
2392
2506
|
C: (f, a) => f(...a)
|
|
2393
2507
|
});
|
|
2394
|
-
this._controller.connect(peer);
|
|
2395
2508
|
}
|
|
2396
2509
|
}
|
|
2397
2510
|
}
|
|
@@ -2503,7 +2616,7 @@ import { Event as Event7, Trigger } from "@dxos/async";
|
|
|
2503
2616
|
import { ErrorStream as ErrorStream3 } from "@dxos/debug";
|
|
2504
2617
|
import { invariant as invariant10 } from "@dxos/invariant";
|
|
2505
2618
|
import { PublicKey as PublicKey9 } from "@dxos/keys";
|
|
2506
|
-
import { log as log10, logInfo as
|
|
2619
|
+
import { log as log10, logInfo as logInfo3 } from "@dxos/log";
|
|
2507
2620
|
import { ComplexMap as ComplexMap7 } from "@dxos/util";
|
|
2508
2621
|
function _ts_decorate4(decorators, target, key, desc) {
|
|
2509
2622
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -2678,12 +2791,23 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2678
2791
|
this._remote.wake(remoteId);
|
|
2679
2792
|
}
|
|
2680
2793
|
}
|
|
2794
|
+
async getDetails() {
|
|
2795
|
+
return this._instanceId.toHex();
|
|
2796
|
+
}
|
|
2797
|
+
async getStats() {
|
|
2798
|
+
return {
|
|
2799
|
+
bytesSent: 0,
|
|
2800
|
+
bytesReceived: 0,
|
|
2801
|
+
packetsSent: 0,
|
|
2802
|
+
packetsReceived: 0
|
|
2803
|
+
};
|
|
2804
|
+
}
|
|
2681
2805
|
};
|
|
2682
2806
|
_ts_decorate4([
|
|
2683
|
-
|
|
2807
|
+
logInfo3
|
|
2684
2808
|
], MemoryTransport.prototype, "_instanceId", void 0);
|
|
2685
2809
|
_ts_decorate4([
|
|
2686
|
-
|
|
2810
|
+
logInfo3
|
|
2687
2811
|
], MemoryTransport.prototype, "_remoteInstanceId", void 0);
|
|
2688
2812
|
|
|
2689
2813
|
// packages/core/mesh/network-manager/src/transport/transport.ts
|
|
@@ -2715,6 +2839,9 @@ try {
|
|
|
2715
2839
|
// packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts
|
|
2716
2840
|
var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts";
|
|
2717
2841
|
var SimplePeerTransport = class {
|
|
2842
|
+
/**
|
|
2843
|
+
* @params opts.config formatted as per https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/RTCPeerConnection
|
|
2844
|
+
*/
|
|
2718
2845
|
constructor(params) {
|
|
2719
2846
|
this.params = params;
|
|
2720
2847
|
this._closed = false;
|
|
@@ -2727,13 +2854,13 @@ var SimplePeerTransport = class {
|
|
|
2727
2854
|
id: this._instanceId
|
|
2728
2855
|
}), {
|
|
2729
2856
|
F: __dxlog_file12,
|
|
2730
|
-
L:
|
|
2857
|
+
L: 44,
|
|
2731
2858
|
S: this,
|
|
2732
2859
|
C: (f, a) => f(...a)
|
|
2733
2860
|
});
|
|
2734
2861
|
log11("created connection", params, {
|
|
2735
2862
|
F: __dxlog_file12,
|
|
2736
|
-
L:
|
|
2863
|
+
L: 45,
|
|
2737
2864
|
S: this,
|
|
2738
2865
|
C: (f, a) => f(...a)
|
|
2739
2866
|
});
|
|
@@ -2746,7 +2873,7 @@ var SimplePeerTransport = class {
|
|
|
2746
2873
|
this._peer.on("signal", async (data) => {
|
|
2747
2874
|
log11("signal", data, {
|
|
2748
2875
|
F: __dxlog_file12,
|
|
2749
|
-
L:
|
|
2876
|
+
L: 54,
|
|
2750
2877
|
S: this,
|
|
2751
2878
|
C: (f, a) => f(...a)
|
|
2752
2879
|
});
|
|
@@ -2759,7 +2886,7 @@ var SimplePeerTransport = class {
|
|
|
2759
2886
|
this._peer.on("connect", () => {
|
|
2760
2887
|
log11("connected", void 0, {
|
|
2761
2888
|
F: __dxlog_file12,
|
|
2762
|
-
L:
|
|
2889
|
+
L: 59,
|
|
2763
2890
|
S: this,
|
|
2764
2891
|
C: (f, a) => f(...a)
|
|
2765
2892
|
});
|
|
@@ -2770,7 +2897,7 @@ var SimplePeerTransport = class {
|
|
|
2770
2897
|
this._peer.on("close", async () => {
|
|
2771
2898
|
log11("closed", void 0, {
|
|
2772
2899
|
F: __dxlog_file12,
|
|
2773
|
-
L:
|
|
2900
|
+
L: 66,
|
|
2774
2901
|
S: this,
|
|
2775
2902
|
C: (f, a) => f(...a)
|
|
2776
2903
|
});
|
|
@@ -2781,12 +2908,20 @@ var SimplePeerTransport = class {
|
|
|
2781
2908
|
if (err.errorDetail === "sctp-failure") {
|
|
2782
2909
|
this.errors.raise(new ConnectionResetError2("sctp-failure from RTCError", err));
|
|
2783
2910
|
} else {
|
|
2911
|
+
log11.info("unknown RTCError", {
|
|
2912
|
+
err
|
|
2913
|
+
}, {
|
|
2914
|
+
F: __dxlog_file12,
|
|
2915
|
+
L: 77,
|
|
2916
|
+
S: this,
|
|
2917
|
+
C: (f, a) => f(...a)
|
|
2918
|
+
});
|
|
2784
2919
|
this.errors.raise(new UnknownProtocolError2("unknown RTCError", err));
|
|
2785
2920
|
}
|
|
2786
2921
|
} else if ("code" in err) {
|
|
2787
2922
|
log11.info("simple-peer error", err, {
|
|
2788
2923
|
F: __dxlog_file12,
|
|
2789
|
-
L:
|
|
2924
|
+
L: 82,
|
|
2790
2925
|
S: this,
|
|
2791
2926
|
C: (f, a) => f(...a)
|
|
2792
2927
|
});
|
|
@@ -2794,10 +2929,12 @@ var SimplePeerTransport = class {
|
|
|
2794
2929
|
case "ERR_WEBRTC_SUPPORT":
|
|
2795
2930
|
this.errors.raise(new ProtocolError2("WebRTC not supported", err));
|
|
2796
2931
|
break;
|
|
2932
|
+
case "ERR_SIGNALING":
|
|
2933
|
+
this.errors.raise(new ConnectivityError2("signaling failure", err));
|
|
2934
|
+
break;
|
|
2797
2935
|
case "ERR_ICE_CONNECTION_FAILURE":
|
|
2798
2936
|
case "ERR_DATA_CHANNEL":
|
|
2799
2937
|
case "ERR_CONNECTION_FAILURE":
|
|
2800
|
-
case "ERR_SIGNALING":
|
|
2801
2938
|
this.errors.raise(new ConnectivityError2("unknown communication failure", err));
|
|
2802
2939
|
break;
|
|
2803
2940
|
case "ERR_CREATE_OFFER":
|
|
@@ -2814,7 +2951,7 @@ var SimplePeerTransport = class {
|
|
|
2814
2951
|
} else {
|
|
2815
2952
|
log11.info("unknown peer connection error", err, {
|
|
2816
2953
|
F: __dxlog_file12,
|
|
2817
|
-
L:
|
|
2954
|
+
L: 108,
|
|
2818
2955
|
S: this,
|
|
2819
2956
|
C: (f, a) => f(...a)
|
|
2820
2957
|
});
|
|
@@ -2825,10 +2962,10 @@ var SimplePeerTransport = class {
|
|
|
2825
2962
|
this._peer._pc.getStats().then((stats) => {
|
|
2826
2963
|
log11.info("report after webrtc error", {
|
|
2827
2964
|
config: this.params.webrtcConfig,
|
|
2828
|
-
stats
|
|
2965
|
+
stats: Object.fromEntries(stats.entries())
|
|
2829
2966
|
}, {
|
|
2830
2967
|
F: __dxlog_file12,
|
|
2831
|
-
L:
|
|
2968
|
+
L: 116,
|
|
2832
2969
|
S: this,
|
|
2833
2970
|
C: (f, a) => f(...a)
|
|
2834
2971
|
});
|
|
@@ -2837,7 +2974,7 @@ var SimplePeerTransport = class {
|
|
|
2837
2974
|
} catch (err2) {
|
|
2838
2975
|
log11.catch(err2, void 0, {
|
|
2839
2976
|
F: __dxlog_file12,
|
|
2840
|
-
L:
|
|
2977
|
+
L: 123,
|
|
2841
2978
|
S: this,
|
|
2842
2979
|
C: (f, a) => f(...a)
|
|
2843
2980
|
});
|
|
@@ -2848,28 +2985,81 @@ var SimplePeerTransport = class {
|
|
|
2848
2985
|
id: this._instanceId
|
|
2849
2986
|
}), {
|
|
2850
2987
|
F: __dxlog_file12,
|
|
2851
|
-
L:
|
|
2988
|
+
L: 129,
|
|
2852
2989
|
S: this,
|
|
2853
2990
|
C: (f, a) => f(...a)
|
|
2854
2991
|
});
|
|
2855
2992
|
}
|
|
2993
|
+
async getStats() {
|
|
2994
|
+
const stats = await this._getStats();
|
|
2995
|
+
if (!stats) {
|
|
2996
|
+
return {
|
|
2997
|
+
bytesSent: 0,
|
|
2998
|
+
bytesReceived: 0,
|
|
2999
|
+
packetsSent: 0,
|
|
3000
|
+
packetsReceived: 0,
|
|
3001
|
+
rawStats: {}
|
|
3002
|
+
};
|
|
3003
|
+
}
|
|
3004
|
+
return {
|
|
3005
|
+
bytesSent: stats.transport.bytesSent,
|
|
3006
|
+
bytesReceived: stats.transport.bytesReceived,
|
|
3007
|
+
packetsSent: stats.transport.messagesSent,
|
|
3008
|
+
packetsReceived: stats.transport.messagesReceived,
|
|
3009
|
+
rawStats: stats.raw
|
|
3010
|
+
};
|
|
3011
|
+
}
|
|
3012
|
+
async _getStats() {
|
|
3013
|
+
if (typeof this._peer?._pc?.getStats !== "function") {
|
|
3014
|
+
return null;
|
|
3015
|
+
}
|
|
3016
|
+
return await this._peer._pc.getStats().then((stats) => {
|
|
3017
|
+
const statsEntries = Array.from(stats.entries());
|
|
3018
|
+
const transport = statsEntries.filter((s) => s[1].type === "transport")[0][1];
|
|
3019
|
+
const candidatePair = statsEntries.filter((s) => s[0] === transport.selectedCandidatePairId);
|
|
3020
|
+
let selectedCandidatePair;
|
|
3021
|
+
let remoteCandidate;
|
|
3022
|
+
if (candidatePair.length > 0) {
|
|
3023
|
+
selectedCandidatePair = candidatePair[0][1];
|
|
3024
|
+
remoteCandidate = statsEntries.filter((s) => s[0] === selectedCandidatePair.remoteCandidateId)[0][1];
|
|
3025
|
+
}
|
|
3026
|
+
return {
|
|
3027
|
+
datachannel: statsEntries.filter((s) => s[1].type === "data-channel")[0][1],
|
|
3028
|
+
transport,
|
|
3029
|
+
selectedCandidatePair,
|
|
3030
|
+
remoteCandidate,
|
|
3031
|
+
raw: Object.fromEntries(stats.entries())
|
|
3032
|
+
};
|
|
3033
|
+
});
|
|
3034
|
+
}
|
|
3035
|
+
async getDetails() {
|
|
3036
|
+
const stats = await this._getStats();
|
|
3037
|
+
const rc = stats?.remoteCandidate;
|
|
3038
|
+
if (!rc) {
|
|
3039
|
+
return "unavailable";
|
|
3040
|
+
}
|
|
3041
|
+
if (rc.candidateType === "relay") {
|
|
3042
|
+
return `${rc.ip}:${rc.port}/${rc.protocol} relay for ${rc.relatedAddress}:${rc.relatedPort}`;
|
|
3043
|
+
}
|
|
3044
|
+
return `${rc.ip}:${rc.port}/${rc.protocol} ${rc.candidateType}`;
|
|
3045
|
+
}
|
|
2856
3046
|
async destroy() {
|
|
2857
3047
|
log11("closing...", void 0, {
|
|
2858
3048
|
F: __dxlog_file12,
|
|
2859
|
-
L:
|
|
3049
|
+
L: 192,
|
|
2860
3050
|
S: this,
|
|
2861
3051
|
C: (f, a) => f(...a)
|
|
2862
3052
|
});
|
|
2863
3053
|
if (this._closed) {
|
|
2864
3054
|
return;
|
|
2865
3055
|
}
|
|
2866
|
-
this._closed = true;
|
|
2867
3056
|
this._disconnectStreams();
|
|
2868
3057
|
this._peer.destroy();
|
|
3058
|
+
this._closed = true;
|
|
2869
3059
|
this.closed.emit();
|
|
2870
3060
|
log11("closed", void 0, {
|
|
2871
3061
|
F: __dxlog_file12,
|
|
2872
|
-
L:
|
|
3062
|
+
L: 200,
|
|
2873
3063
|
S: this,
|
|
2874
3064
|
C: (f, a) => f(...a)
|
|
2875
3065
|
});
|
|
@@ -2984,7 +3174,7 @@ var SimplePeerTransportService = class {
|
|
|
2984
3174
|
async sendSignal({ proxyId, signal }) {
|
|
2985
3175
|
invariant12(this.transports.has(proxyId), void 0, {
|
|
2986
3176
|
F: __dxlog_file13,
|
|
2987
|
-
L:
|
|
3177
|
+
L: 116,
|
|
2988
3178
|
S: this,
|
|
2989
3179
|
A: [
|
|
2990
3180
|
"this.transports.has(proxyId)",
|
|
@@ -2993,18 +3183,46 @@ var SimplePeerTransportService = class {
|
|
|
2993
3183
|
});
|
|
2994
3184
|
await this.transports.get(proxyId).transport.signal(signal);
|
|
2995
3185
|
}
|
|
3186
|
+
async getDetails({ proxyId }) {
|
|
3187
|
+
invariant12(this.transports.has(proxyId), void 0, {
|
|
3188
|
+
F: __dxlog_file13,
|
|
3189
|
+
L: 121,
|
|
3190
|
+
S: this,
|
|
3191
|
+
A: [
|
|
3192
|
+
"this.transports.has(proxyId)",
|
|
3193
|
+
""
|
|
3194
|
+
]
|
|
3195
|
+
});
|
|
3196
|
+
return {
|
|
3197
|
+
details: await this.transports.get(proxyId).transport.getDetails()
|
|
3198
|
+
};
|
|
3199
|
+
}
|
|
3200
|
+
async getStats({ proxyId }) {
|
|
3201
|
+
invariant12(this.transports.has(proxyId), void 0, {
|
|
3202
|
+
F: __dxlog_file13,
|
|
3203
|
+
L: 126,
|
|
3204
|
+
S: this,
|
|
3205
|
+
A: [
|
|
3206
|
+
"this.transports.has(proxyId)",
|
|
3207
|
+
""
|
|
3208
|
+
]
|
|
3209
|
+
});
|
|
3210
|
+
return {
|
|
3211
|
+
stats: await this.transports.get(proxyId).transport.getStats()
|
|
3212
|
+
};
|
|
3213
|
+
}
|
|
2996
3214
|
async sendData({ proxyId, payload }) {
|
|
2997
3215
|
if (this.transports.get(proxyId)?.state !== "OPEN") {
|
|
2998
3216
|
log12.debug("transport is closed", void 0, {
|
|
2999
3217
|
F: __dxlog_file13,
|
|
3000
|
-
L:
|
|
3218
|
+
L: 132,
|
|
3001
3219
|
S: this,
|
|
3002
3220
|
C: (f, a) => f(...a)
|
|
3003
3221
|
});
|
|
3004
3222
|
}
|
|
3005
3223
|
invariant12(this.transports.has(proxyId), void 0, {
|
|
3006
3224
|
F: __dxlog_file13,
|
|
3007
|
-
L:
|
|
3225
|
+
L: 134,
|
|
3008
3226
|
S: this,
|
|
3009
3227
|
A: [
|
|
3010
3228
|
"this.transports.has(proxyId)",
|
|
@@ -3027,7 +3245,7 @@ var SimplePeerTransportService = class {
|
|
|
3027
3245
|
}
|
|
3028
3246
|
log12("Closed.", void 0, {
|
|
3029
3247
|
F: __dxlog_file13,
|
|
3030
|
-
L:
|
|
3248
|
+
L: 150,
|
|
3031
3249
|
S: this,
|
|
3032
3250
|
C: (f, a) => f(...a)
|
|
3033
3251
|
});
|
|
@@ -3042,7 +3260,7 @@ import { ErrorStream as ErrorStream5 } from "@dxos/debug";
|
|
|
3042
3260
|
import { invariant as invariant13 } from "@dxos/invariant";
|
|
3043
3261
|
import { PublicKey as PublicKey12 } from "@dxos/keys";
|
|
3044
3262
|
import { log as log13 } from "@dxos/log";
|
|
3045
|
-
import { ConnectionResetError as ConnectionResetError3, TimeoutError as
|
|
3263
|
+
import { ConnectionResetError as ConnectionResetError3, TimeoutError as TimeoutError3, ProtocolError as ProtocolError3, ConnectivityError as ConnectivityError3, UnknownProtocolError as UnknownProtocolError3 } from "@dxos/protocols";
|
|
3046
3264
|
import { ConnectionState as ConnectionState4 } from "@dxos/protocols/proto/dxos/mesh/bridge";
|
|
3047
3265
|
import { arrayToBuffer } from "@dxos/util";
|
|
3048
3266
|
var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport-proxy.ts";
|
|
@@ -3098,9 +3316,9 @@ var SimplePeerTransportProxy = class {
|
|
|
3098
3316
|
}
|
|
3099
3317
|
this._timeoutCount = 0;
|
|
3100
3318
|
}, (err) => {
|
|
3101
|
-
if (err instanceof
|
|
3319
|
+
if (err instanceof TimeoutError3 || err.constructor.name === "TimeoutError") {
|
|
3102
3320
|
if (this._timeoutCount++ > TIMEOUT_THRESHOLD) {
|
|
3103
|
-
throw new
|
|
3321
|
+
throw new TimeoutError3(`too many timeoutes (${this._timeoutCount} > ${TIMEOUT_THRESHOLD}`);
|
|
3104
3322
|
} else {
|
|
3105
3323
|
log13("timeout error, but still invoking callback", void 0, {
|
|
3106
3324
|
F: __dxlog_file14,
|
|
@@ -3166,6 +3384,16 @@ var SimplePeerTransportProxy = class {
|
|
|
3166
3384
|
signal
|
|
3167
3385
|
}).catch((err) => this.errors.raise(decodeError(err)));
|
|
3168
3386
|
}
|
|
3387
|
+
async getDetails() {
|
|
3388
|
+
return (await this._params.bridgeService.getDetails({
|
|
3389
|
+
proxyId: this._proxyId
|
|
3390
|
+
})).details;
|
|
3391
|
+
}
|
|
3392
|
+
async getStats() {
|
|
3393
|
+
return (await this._params.bridgeService.getStats({
|
|
3394
|
+
proxyId: this._proxyId
|
|
3395
|
+
})).stats;
|
|
3396
|
+
}
|
|
3169
3397
|
// TODO(burdon): Move open from constructor.
|
|
3170
3398
|
async destroy() {
|
|
3171
3399
|
await this._ctx.dispose();
|
|
@@ -3180,7 +3408,7 @@ var SimplePeerTransportProxy = class {
|
|
|
3180
3408
|
} catch (err) {
|
|
3181
3409
|
log13.catch(err, void 0, {
|
|
3182
3410
|
F: __dxlog_file14,
|
|
3183
|
-
L:
|
|
3411
|
+
L: 168,
|
|
3184
3412
|
S: this,
|
|
3185
3413
|
C: (f, a) => f(...a)
|
|
3186
3414
|
});
|
|
@@ -3216,7 +3444,7 @@ var SimplePeerTransportProxyFactory = class {
|
|
|
3216
3444
|
createTransport(options) {
|
|
3217
3445
|
invariant13(this._bridgeService, "SimplePeerTransportProxyFactory is not ready to open connections", {
|
|
3218
3446
|
F: __dxlog_file14,
|
|
3219
|
-
L:
|
|
3447
|
+
L: 205,
|
|
3220
3448
|
S: this,
|
|
3221
3449
|
A: [
|
|
3222
3450
|
"this._bridgeService",
|
|
@@ -3237,7 +3465,7 @@ var decodeError = (err) => {
|
|
|
3237
3465
|
if (message.includes("CONNECTION_RESET")) {
|
|
3238
3466
|
return new ConnectionResetError3(message);
|
|
3239
3467
|
} else if (message.includes("TIMEOUT")) {
|
|
3240
|
-
return new
|
|
3468
|
+
return new TimeoutError3(message);
|
|
3241
3469
|
} else if (message.includes("PROTOCOL_ERROR")) {
|
|
3242
3470
|
return new ProtocolError3(message);
|
|
3243
3471
|
} else if (message.includes("CONNECTIVITY_ERROR")) {
|
|
@@ -3417,16 +3645,21 @@ var LibDataChannelTransport = class {
|
|
|
3417
3645
|
const duplex = new Duplex2({
|
|
3418
3646
|
read: () => {
|
|
3419
3647
|
},
|
|
3420
|
-
write: (chunk, encoding, callback) => {
|
|
3648
|
+
write: async (chunk, encoding, callback) => {
|
|
3421
3649
|
if (chunk.length > MAX_MESSAGE_SIZE) {
|
|
3422
3650
|
this.errors.raise(new Error(`message too large: ${chunk.length} > ${MAX_MESSAGE_SIZE}`));
|
|
3423
3651
|
}
|
|
3424
|
-
|
|
3652
|
+
try {
|
|
3653
|
+
dataChannel.send(chunk);
|
|
3654
|
+
} catch (err) {
|
|
3655
|
+
this.errors.raise(err);
|
|
3656
|
+
await this._close();
|
|
3657
|
+
}
|
|
3425
3658
|
if (this._channel.bufferedAmount > MAX_BUFFERED_AMOUNT) {
|
|
3426
3659
|
if (this._writeCallback !== null) {
|
|
3427
3660
|
log14.error("consumer trying to write before we're ready for more data", void 0, {
|
|
3428
3661
|
F: __dxlog_file15,
|
|
3429
|
-
L:
|
|
3662
|
+
L: 143,
|
|
3430
3663
|
S: this,
|
|
3431
3664
|
C: (f, a) => f(...a)
|
|
3432
3665
|
});
|
|
@@ -3451,7 +3684,7 @@ var LibDataChannelTransport = class {
|
|
|
3451
3684
|
err
|
|
3452
3685
|
}, {
|
|
3453
3686
|
F: __dxlog_file15,
|
|
3454
|
-
L:
|
|
3687
|
+
L: 163,
|
|
3455
3688
|
S: this,
|
|
3456
3689
|
C: (f, a) => f(...a)
|
|
3457
3690
|
});
|
|
@@ -3488,7 +3721,7 @@ var LibDataChannelTransport = class {
|
|
|
3488
3721
|
peer
|
|
3489
3722
|
}, {
|
|
3490
3723
|
F: __dxlog_file15,
|
|
3491
|
-
L:
|
|
3724
|
+
L: 198,
|
|
3492
3725
|
S: this,
|
|
3493
3726
|
C: (f, a) => f(...a)
|
|
3494
3727
|
});
|
|
@@ -3516,7 +3749,7 @@ var LibDataChannelTransport = class {
|
|
|
3516
3749
|
err
|
|
3517
3750
|
}, {
|
|
3518
3751
|
F: __dxlog_file15,
|
|
3519
|
-
L:
|
|
3752
|
+
L: 209,
|
|
3520
3753
|
S: this,
|
|
3521
3754
|
C: (f, a) => f(...a)
|
|
3522
3755
|
});
|
|
@@ -3536,7 +3769,7 @@ var LibDataChannelTransport = class {
|
|
|
3536
3769
|
err
|
|
3537
3770
|
}, {
|
|
3538
3771
|
F: __dxlog_file15,
|
|
3539
|
-
L:
|
|
3772
|
+
L: 220,
|
|
3540
3773
|
S: this,
|
|
3541
3774
|
C: (f, a) => f(...a)
|
|
3542
3775
|
});
|
|
@@ -3555,7 +3788,7 @@ var LibDataChannelTransport = class {
|
|
|
3555
3788
|
signal
|
|
3556
3789
|
}, {
|
|
3557
3790
|
F: __dxlog_file15,
|
|
3558
|
-
L:
|
|
3791
|
+
L: 231,
|
|
3559
3792
|
S: this,
|
|
3560
3793
|
C: (f, a) => f(...a)
|
|
3561
3794
|
});
|
|
@@ -3564,12 +3797,52 @@ var LibDataChannelTransport = class {
|
|
|
3564
3797
|
}).catch((err) => {
|
|
3565
3798
|
log14.catch(err, void 0, {
|
|
3566
3799
|
F: __dxlog_file15,
|
|
3567
|
-
L:
|
|
3800
|
+
L: 236,
|
|
3568
3801
|
S: this,
|
|
3569
3802
|
C: (f, a) => f(...a)
|
|
3570
3803
|
});
|
|
3571
3804
|
});
|
|
3572
3805
|
}
|
|
3806
|
+
async getDetails() {
|
|
3807
|
+
return this._peer.then(async (peer) => {
|
|
3808
|
+
const cp = await peer.getSelectedCandidatePair();
|
|
3809
|
+
if (!cp) {
|
|
3810
|
+
return "unavailable";
|
|
3811
|
+
}
|
|
3812
|
+
return `${cp.remote.address}:${cp.remote.port}/${cp.remote.transportType} ${cp.remote.type}`;
|
|
3813
|
+
}).catch((err) => {
|
|
3814
|
+
log14.catch(err, void 0, {
|
|
3815
|
+
F: __dxlog_file15,
|
|
3816
|
+
L: 250,
|
|
3817
|
+
S: this,
|
|
3818
|
+
C: (f, a) => f(...a)
|
|
3819
|
+
});
|
|
3820
|
+
return "unavailable";
|
|
3821
|
+
});
|
|
3822
|
+
}
|
|
3823
|
+
async getStats() {
|
|
3824
|
+
return this._peer.then((peer) => {
|
|
3825
|
+
return {
|
|
3826
|
+
bytesSent: peer.bytesSent(),
|
|
3827
|
+
bytesReceived: peer.bytesReceived(),
|
|
3828
|
+
packetsSent: 0,
|
|
3829
|
+
packetsReceived: 0
|
|
3830
|
+
};
|
|
3831
|
+
}).catch((err) => {
|
|
3832
|
+
log14.catch(err, void 0, {
|
|
3833
|
+
F: __dxlog_file15,
|
|
3834
|
+
L: 266,
|
|
3835
|
+
S: this,
|
|
3836
|
+
C: (f, a) => f(...a)
|
|
3837
|
+
});
|
|
3838
|
+
return {
|
|
3839
|
+
bytesSent: 0,
|
|
3840
|
+
bytesReceived: 0,
|
|
3841
|
+
packetsSent: 0,
|
|
3842
|
+
packetsReceived: 0
|
|
3843
|
+
};
|
|
3844
|
+
});
|
|
3845
|
+
}
|
|
3573
3846
|
// TODO(nf): add classmethod to call node-datachannel.cleanup() when all instances have been destroyed?
|
|
3574
3847
|
async destroy() {
|
|
3575
3848
|
await this._close();
|
|
@@ -3606,6 +3879,12 @@ var TcpTransport = class {
|
|
|
3606
3879
|
signal() {
|
|
3607
3880
|
throw new Error("Method not implemented.");
|
|
3608
3881
|
}
|
|
3882
|
+
async getStats() {
|
|
3883
|
+
throw new Error("Method not implemented.");
|
|
3884
|
+
}
|
|
3885
|
+
async getDetails() {
|
|
3886
|
+
throw new Error("Method not implemented.");
|
|
3887
|
+
}
|
|
3609
3888
|
};
|
|
3610
3889
|
|
|
3611
3890
|
// packages/core/mesh/network-manager/src/wire-protocol.ts
|
|
@@ -3615,8 +3894,8 @@ var createTeleportProtocolFactory = (onConnection) => {
|
|
|
3615
3894
|
const teleport = new Teleport(params);
|
|
3616
3895
|
return {
|
|
3617
3896
|
stream: teleport.stream,
|
|
3618
|
-
open: async () => {
|
|
3619
|
-
await teleport.open();
|
|
3897
|
+
open: async (sessionId) => {
|
|
3898
|
+
await teleport.open(sessionId);
|
|
3620
3899
|
await onConnection(teleport);
|
|
3621
3900
|
},
|
|
3622
3901
|
close: async () => {
|
|
@@ -3657,4 +3936,4 @@ export {
|
|
|
3657
3936
|
TcpTransport,
|
|
3658
3937
|
createTeleportProtocolFactory
|
|
3659
3938
|
};
|
|
3660
|
-
//# sourceMappingURL=chunk-
|
|
3939
|
+
//# sourceMappingURL=chunk-Q5B7EFTV.mjs.map
|