@dxos/network-manager 0.8.4-main.c4373fc → 0.8.4-main.c85a9c8dae
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-NRRQ4H6U.mjs → chunk-AQSYW43M.mjs} +803 -1339
- package/dist/lib/browser/chunk-AQSYW43M.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +342 -4
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +85 -113
- package/dist/lib/browser/testing/index.mjs.map +2 -2
- package/dist/lib/browser/transport/tcp/index.mjs +2 -48
- package/dist/lib/browser/transport/tcp/index.mjs.map +4 -4
- package/dist/lib/browser/transport/tcp/tcp-transport.browser.mjs +36 -0
- package/dist/lib/browser/transport/tcp/tcp-transport.browser.mjs.map +7 -0
- package/dist/lib/browser/transport/tcp/tcp-transport.mjs +160 -0
- package/dist/lib/browser/transport/tcp/tcp-transport.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-AX4TJ2DL.mjs → chunk-SCX3PZRE.mjs} +803 -1339
- package/dist/lib/node-esm/chunk-SCX3PZRE.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +342 -4
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +85 -113
- package/dist/lib/node-esm/testing/index.mjs.map +2 -2
- package/dist/lib/node-esm/transport/tcp/index.mjs +2 -177
- package/dist/lib/node-esm/transport/tcp/index.mjs.map +4 -4
- package/dist/lib/node-esm/transport/tcp/tcp-transport.browser.mjs +36 -0
- package/dist/lib/node-esm/transport/tcp/tcp-transport.browser.mjs.map +7 -0
- package/dist/lib/node-esm/transport/tcp/tcp-transport.mjs +160 -0
- package/dist/lib/node-esm/transport/tcp/tcp-transport.mjs.map +7 -0
- package/dist/types/src/swarm/connection.d.ts.map +1 -1
- package/dist/types/src/swarm/peer.d.ts.map +1 -1
- package/dist/types/src/transport/tcp/index.d.ts +1 -1
- package/dist/types/src/transport/tcp/index.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc/rtc-transport-proxy.d.ts.map +1 -1
- package/dist/types/src/wire-protocol.d.ts +5 -5
- package/dist/types/src/wire-protocol.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +33 -23
- package/src/swarm/connection.test.ts +2 -1
- package/src/swarm/connection.ts +7 -5
- package/src/swarm/peer.ts +2 -1
- package/src/swarm/swarm.test.ts +2 -1
- package/src/tests/webrtc-transport.test.ts +4 -2
- package/src/transport/tcp/index.ts +1 -1
- package/src/transport/webrtc/rtc-peer-connection.ts +1 -1
- package/src/transport/webrtc/rtc-transport-channel.ts +1 -1
- package/src/transport/webrtc/rtc-transport-proxy.test.ts +2 -1
- package/src/transport/webrtc/rtc-transport-proxy.ts +6 -4
- package/src/transport/webrtc/rtc-transport.test.ts +2 -1
- package/src/wire-protocol.ts +6 -6
- package/dist/lib/browser/chunk-NRRQ4H6U.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-AX4TJ2DL.mjs.map +0 -7
|
@@ -8,19 +8,6 @@ import { invariant } from "@dxos/invariant";
|
|
|
8
8
|
import { PublicKey } from "@dxos/keys";
|
|
9
9
|
import { log, logInfo } from "@dxos/log";
|
|
10
10
|
import { CancelledError, ConnectionResetError, ConnectivityError, ProtocolError, TimeoutError, trace } from "@dxos/protocols";
|
|
11
|
-
function _define_property(obj, key, value) {
|
|
12
|
-
if (key in obj) {
|
|
13
|
-
Object.defineProperty(obj, key, {
|
|
14
|
-
value,
|
|
15
|
-
enumerable: true,
|
|
16
|
-
configurable: true,
|
|
17
|
-
writable: true
|
|
18
|
-
});
|
|
19
|
-
} else {
|
|
20
|
-
obj[key] = value;
|
|
21
|
-
}
|
|
22
|
-
return obj;
|
|
23
|
-
}
|
|
24
11
|
function _ts_decorate(decorators, target, key, desc) {
|
|
25
12
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
26
13
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -44,6 +31,61 @@ var ConnectionState = /* @__PURE__ */ (function(ConnectionState5) {
|
|
|
44
31
|
return ConnectionState5;
|
|
45
32
|
})({});
|
|
46
33
|
var Connection = class {
|
|
34
|
+
topic;
|
|
35
|
+
localInfo;
|
|
36
|
+
remoteInfo;
|
|
37
|
+
sessionId;
|
|
38
|
+
initiator;
|
|
39
|
+
_signalMessaging;
|
|
40
|
+
_protocol;
|
|
41
|
+
_transportFactory;
|
|
42
|
+
_callbacks;
|
|
43
|
+
_ctx = new Context(void 0, {
|
|
44
|
+
F: __dxlog_file,
|
|
45
|
+
L: 100
|
|
46
|
+
});
|
|
47
|
+
connectedTimeoutContext = new Context(void 0, {
|
|
48
|
+
F: __dxlog_file,
|
|
49
|
+
L: 101
|
|
50
|
+
});
|
|
51
|
+
_protocolClosed = new Trigger();
|
|
52
|
+
_transportClosed = new Trigger();
|
|
53
|
+
_state = "CREATED";
|
|
54
|
+
_transport;
|
|
55
|
+
closeReason;
|
|
56
|
+
_incomingSignalBuffer = [];
|
|
57
|
+
_outgoingSignalBuffer = [];
|
|
58
|
+
stateChanged = new Event();
|
|
59
|
+
errors = new ErrorStream();
|
|
60
|
+
_instanceId = PublicKey.random().toHex();
|
|
61
|
+
transportStats = new Event();
|
|
62
|
+
_signalSendTask = new DeferredTask(this._ctx, async () => {
|
|
63
|
+
await this._flushSignalBuffer();
|
|
64
|
+
});
|
|
65
|
+
_signallingDelay = STARTING_SIGNALLING_DELAY;
|
|
66
|
+
constructor(topic, localInfo, remoteInfo, sessionId, initiator, _signalMessaging, _protocol, _transportFactory, _callbacks) {
|
|
67
|
+
this.topic = topic;
|
|
68
|
+
this.localInfo = localInfo;
|
|
69
|
+
this.remoteInfo = remoteInfo;
|
|
70
|
+
this.sessionId = sessionId;
|
|
71
|
+
this.initiator = initiator;
|
|
72
|
+
this._signalMessaging = _signalMessaging;
|
|
73
|
+
this._protocol = _protocol;
|
|
74
|
+
this._transportFactory = _transportFactory;
|
|
75
|
+
this._callbacks = _callbacks;
|
|
76
|
+
log.trace("dxos.mesh.connection.construct", {
|
|
77
|
+
sessionId: this.sessionId,
|
|
78
|
+
topic: this.topic,
|
|
79
|
+
localPeer: this.localInfo,
|
|
80
|
+
remotePeer: this.remoteInfo,
|
|
81
|
+
initiator: this.initiator
|
|
82
|
+
}, {
|
|
83
|
+
F: __dxlog_file,
|
|
84
|
+
L: 137,
|
|
85
|
+
S: this,
|
|
86
|
+
C: (f, a) => f(...a)
|
|
87
|
+
});
|
|
88
|
+
}
|
|
47
89
|
get sessionIdString() {
|
|
48
90
|
return this.sessionId.truncate();
|
|
49
91
|
}
|
|
@@ -102,21 +144,25 @@ var Connection = class {
|
|
|
102
144
|
});
|
|
103
145
|
this._protocolClosed.wake();
|
|
104
146
|
this.close({
|
|
105
|
-
error: new ProtocolError(
|
|
147
|
+
error: new ProtocolError({
|
|
148
|
+
message: "protocol stream closed"
|
|
149
|
+
})
|
|
106
150
|
}).catch((err) => this.errors.raise(err));
|
|
107
151
|
});
|
|
108
152
|
scheduleTask(this.connectedTimeoutContext, async () => {
|
|
109
153
|
log.info(`timeout waiting ${TRANSPORT_CONNECTION_TIMEOUT / 1e3}s for transport to connect, aborting`, void 0, {
|
|
110
154
|
F: __dxlog_file,
|
|
111
|
-
L:
|
|
155
|
+
L: 196,
|
|
112
156
|
S: this,
|
|
113
157
|
C: (f, a) => f(...a)
|
|
114
158
|
});
|
|
115
|
-
await this.abort(new TimeoutError(
|
|
159
|
+
await this.abort(new TimeoutError({
|
|
160
|
+
message: `${TRANSPORT_CONNECTION_TIMEOUT / 1e3}s for transport to connect`
|
|
161
|
+
})).catch((err) => this.errors.raise(err));
|
|
116
162
|
}, TRANSPORT_CONNECTION_TIMEOUT);
|
|
117
163
|
invariant(!this._transport, void 0, {
|
|
118
164
|
F: __dxlog_file,
|
|
119
|
-
L:
|
|
165
|
+
L: 204,
|
|
120
166
|
S: this,
|
|
121
167
|
A: [
|
|
122
168
|
"!this._transport",
|
|
@@ -143,7 +189,7 @@ var Connection = class {
|
|
|
143
189
|
this._transportClosed.wake();
|
|
144
190
|
log("abort triggered by transport close", void 0, {
|
|
145
191
|
F: __dxlog_file,
|
|
146
|
-
L:
|
|
192
|
+
L: 226,
|
|
147
193
|
S: this,
|
|
148
194
|
C: (f, a) => f(...a)
|
|
149
195
|
});
|
|
@@ -154,7 +200,7 @@ var Connection = class {
|
|
|
154
200
|
err
|
|
155
201
|
}, {
|
|
156
202
|
F: __dxlog_file,
|
|
157
|
-
L:
|
|
203
|
+
L: 231,
|
|
158
204
|
S: this,
|
|
159
205
|
C: (f, a) => f(...a)
|
|
160
206
|
});
|
|
@@ -164,7 +210,7 @@ var Connection = class {
|
|
|
164
210
|
if (err instanceof ConnectionResetError) {
|
|
165
211
|
log.info("aborting due to transport ConnectionResetError", void 0, {
|
|
166
212
|
F: __dxlog_file,
|
|
167
|
-
L:
|
|
213
|
+
L: 238,
|
|
168
214
|
S: this,
|
|
169
215
|
C: (f, a) => f(...a)
|
|
170
216
|
});
|
|
@@ -172,7 +218,7 @@ var Connection = class {
|
|
|
172
218
|
} else if (err instanceof ConnectivityError) {
|
|
173
219
|
log.info("aborting due to transport ConnectivityError", void 0, {
|
|
174
220
|
F: __dxlog_file,
|
|
175
|
-
L:
|
|
221
|
+
L: 241,
|
|
176
222
|
S: this,
|
|
177
223
|
C: (f, a) => f(...a)
|
|
178
224
|
});
|
|
@@ -192,7 +238,7 @@ var Connection = class {
|
|
|
192
238
|
id: this._instanceId
|
|
193
239
|
}), {
|
|
194
240
|
F: __dxlog_file,
|
|
195
|
-
L:
|
|
241
|
+
L: 260,
|
|
196
242
|
S: this,
|
|
197
243
|
C: (f, a) => f(...a)
|
|
198
244
|
});
|
|
@@ -202,14 +248,14 @@ var Connection = class {
|
|
|
202
248
|
err
|
|
203
249
|
}, {
|
|
204
250
|
F: __dxlog_file,
|
|
205
|
-
L:
|
|
251
|
+
L: 267,
|
|
206
252
|
S: this,
|
|
207
253
|
C: (f, a) => f(...a)
|
|
208
254
|
});
|
|
209
255
|
if (this._state === "CLOSED" || this._state === "ABORTED") {
|
|
210
256
|
log(`abort ignored: already ${this._state}`, this.closeReason, {
|
|
211
257
|
F: __dxlog_file,
|
|
212
|
-
L:
|
|
258
|
+
L: 269,
|
|
213
259
|
S: this,
|
|
214
260
|
C: (f, a) => f(...a)
|
|
215
261
|
});
|
|
@@ -226,7 +272,7 @@ var Connection = class {
|
|
|
226
272
|
err
|
|
227
273
|
}, {
|
|
228
274
|
F: __dxlog_file,
|
|
229
|
-
L:
|
|
275
|
+
L: 281,
|
|
230
276
|
S: this,
|
|
231
277
|
C: (f, a) => f(...a)
|
|
232
278
|
});
|
|
@@ -237,7 +283,7 @@ var Connection = class {
|
|
|
237
283
|
} catch (err2) {
|
|
238
284
|
log.catch(err2, void 0, {
|
|
239
285
|
F: __dxlog_file,
|
|
240
|
-
L:
|
|
286
|
+
L: 287,
|
|
241
287
|
S: this,
|
|
242
288
|
C: (f, a) => f(...a)
|
|
243
289
|
});
|
|
@@ -247,7 +293,7 @@ var Connection = class {
|
|
|
247
293
|
} catch (err2) {
|
|
248
294
|
log.catch(err2, void 0, {
|
|
249
295
|
F: __dxlog_file,
|
|
250
|
-
L:
|
|
296
|
+
L: 294,
|
|
251
297
|
S: this,
|
|
252
298
|
C: (f, a) => f(...a)
|
|
253
299
|
});
|
|
@@ -257,7 +303,7 @@ var Connection = class {
|
|
|
257
303
|
} catch (err2) {
|
|
258
304
|
log.catch(err2, void 0, {
|
|
259
305
|
F: __dxlog_file,
|
|
260
|
-
L:
|
|
306
|
+
L: 300,
|
|
261
307
|
S: this,
|
|
262
308
|
C: (f, a) => f(...a)
|
|
263
309
|
});
|
|
@@ -269,7 +315,7 @@ var Connection = class {
|
|
|
269
315
|
error
|
|
270
316
|
}, {
|
|
271
317
|
F: __dxlog_file,
|
|
272
|
-
L:
|
|
318
|
+
L: 307,
|
|
273
319
|
S: this,
|
|
274
320
|
C: (f, a) => f(...a)
|
|
275
321
|
});
|
|
@@ -284,7 +330,7 @@ var Connection = class {
|
|
|
284
330
|
error
|
|
285
331
|
}, {
|
|
286
332
|
F: __dxlog_file,
|
|
287
|
-
L:
|
|
333
|
+
L: 318,
|
|
288
334
|
S: this,
|
|
289
335
|
C: (f, a) => f(...a)
|
|
290
336
|
});
|
|
@@ -298,7 +344,7 @@ var Connection = class {
|
|
|
298
344
|
if (lastState !== "CONNECTED" || error != null) {
|
|
299
345
|
log(`graceful close requested when we were in ${lastState} state? aborting`, void 0, {
|
|
300
346
|
F: __dxlog_file,
|
|
301
|
-
L:
|
|
347
|
+
L: 329,
|
|
302
348
|
S: this,
|
|
303
349
|
C: (f, a) => f(...a)
|
|
304
350
|
});
|
|
@@ -310,7 +356,7 @@ var Connection = class {
|
|
|
310
356
|
error
|
|
311
357
|
}, {
|
|
312
358
|
F: __dxlog_file,
|
|
313
|
-
L:
|
|
359
|
+
L: 333,
|
|
314
360
|
S: this,
|
|
315
361
|
C: (f, a) => f(...a)
|
|
316
362
|
});
|
|
@@ -321,7 +367,7 @@ var Connection = class {
|
|
|
321
367
|
} catch (err) {
|
|
322
368
|
log.catch(err, void 0, {
|
|
323
369
|
F: __dxlog_file,
|
|
324
|
-
L:
|
|
370
|
+
L: 338,
|
|
325
371
|
S: this,
|
|
326
372
|
C: (f, a) => f(...a)
|
|
327
373
|
});
|
|
@@ -331,7 +377,7 @@ var Connection = class {
|
|
|
331
377
|
} catch (err) {
|
|
332
378
|
log.catch(err, void 0, {
|
|
333
379
|
F: __dxlog_file,
|
|
334
|
-
L:
|
|
380
|
+
L: 344,
|
|
335
381
|
S: this,
|
|
336
382
|
C: (f, a) => f(...a)
|
|
337
383
|
});
|
|
@@ -340,7 +386,7 @@ var Connection = class {
|
|
|
340
386
|
peerId: this.localInfo
|
|
341
387
|
}, {
|
|
342
388
|
F: __dxlog_file,
|
|
343
|
-
L:
|
|
389
|
+
L: 347,
|
|
344
390
|
S: this,
|
|
345
391
|
C: (f, a) => f(...a)
|
|
346
392
|
});
|
|
@@ -350,7 +396,7 @@ var Connection = class {
|
|
|
350
396
|
async _closeProtocol(options) {
|
|
351
397
|
log("closing protocol", options, {
|
|
352
398
|
F: __dxlog_file,
|
|
353
|
-
L:
|
|
399
|
+
L: 353,
|
|
354
400
|
S: this,
|
|
355
401
|
C: (f, a) => f(...a)
|
|
356
402
|
});
|
|
@@ -360,7 +406,7 @@ var Connection = class {
|
|
|
360
406
|
]);
|
|
361
407
|
log("protocol closed", options, {
|
|
362
408
|
F: __dxlog_file,
|
|
363
|
-
L:
|
|
409
|
+
L: 355,
|
|
364
410
|
S: this,
|
|
365
411
|
C: (f, a) => f(...a)
|
|
366
412
|
});
|
|
@@ -368,7 +414,7 @@ var Connection = class {
|
|
|
368
414
|
async _closeTransport() {
|
|
369
415
|
log("closing transport", void 0, {
|
|
370
416
|
F: __dxlog_file,
|
|
371
|
-
L:
|
|
417
|
+
L: 359,
|
|
372
418
|
S: this,
|
|
373
419
|
C: (f, a) => f(...a)
|
|
374
420
|
});
|
|
@@ -378,7 +424,7 @@ var Connection = class {
|
|
|
378
424
|
]);
|
|
379
425
|
log("transport closed", void 0, {
|
|
380
426
|
F: __dxlog_file,
|
|
381
|
-
L:
|
|
427
|
+
L: 361,
|
|
382
428
|
S: this,
|
|
383
429
|
C: (f, a) => f(...a)
|
|
384
430
|
});
|
|
@@ -419,12 +465,15 @@ var Connection = class {
|
|
|
419
465
|
err
|
|
420
466
|
}, {
|
|
421
467
|
F: __dxlog_file,
|
|
422
|
-
L:
|
|
468
|
+
L: 401,
|
|
423
469
|
S: this,
|
|
424
470
|
C: (f, a) => f(...a)
|
|
425
471
|
});
|
|
426
472
|
await this.close({
|
|
427
|
-
error: new ConnectivityError(
|
|
473
|
+
error: new ConnectivityError({
|
|
474
|
+
message: "signal message failed to deliver",
|
|
475
|
+
cause: err
|
|
476
|
+
})
|
|
428
477
|
});
|
|
429
478
|
}
|
|
430
479
|
}
|
|
@@ -434,7 +483,7 @@ var Connection = class {
|
|
|
434
483
|
async signal(msg) {
|
|
435
484
|
invariant(msg.sessionId, void 0, {
|
|
436
485
|
F: __dxlog_file,
|
|
437
|
-
L:
|
|
486
|
+
L: 410,
|
|
438
487
|
S: this,
|
|
439
488
|
A: [
|
|
440
489
|
"msg.sessionId",
|
|
@@ -444,7 +493,7 @@ var Connection = class {
|
|
|
444
493
|
if (!msg.sessionId.equals(this.sessionId)) {
|
|
445
494
|
log("dropping signal for incorrect session id", void 0, {
|
|
446
495
|
F: __dxlog_file,
|
|
447
|
-
L:
|
|
496
|
+
L: 412,
|
|
448
497
|
S: this,
|
|
449
498
|
C: (f, a) => f(...a)
|
|
450
499
|
});
|
|
@@ -452,7 +501,7 @@ var Connection = class {
|
|
|
452
501
|
}
|
|
453
502
|
invariant(msg.data.signal || msg.data.signalBatch, void 0, {
|
|
454
503
|
F: __dxlog_file,
|
|
455
|
-
L:
|
|
504
|
+
L: 415,
|
|
456
505
|
S: this,
|
|
457
506
|
A: [
|
|
458
507
|
"msg.data.signal || msg.data.signalBatch",
|
|
@@ -461,7 +510,7 @@ var Connection = class {
|
|
|
461
510
|
});
|
|
462
511
|
invariant(msg.author.peerKey === this.remoteInfo.peerKey, void 0, {
|
|
463
512
|
F: __dxlog_file,
|
|
464
|
-
L:
|
|
513
|
+
L: 416,
|
|
465
514
|
S: this,
|
|
466
515
|
A: [
|
|
467
516
|
"msg.author.peerKey === this.remoteInfo.peerKey",
|
|
@@ -470,7 +519,7 @@ var Connection = class {
|
|
|
470
519
|
});
|
|
471
520
|
invariant(msg.recipient.peerKey === this.localInfo.peerKey, void 0, {
|
|
472
521
|
F: __dxlog_file,
|
|
473
|
-
L:
|
|
522
|
+
L: 417,
|
|
474
523
|
S: this,
|
|
475
524
|
A: [
|
|
476
525
|
"msg.recipient.peerKey === this.localInfo.peerKey",
|
|
@@ -494,7 +543,7 @@ var Connection = class {
|
|
|
494
543
|
msg: msg.data
|
|
495
544
|
}, {
|
|
496
545
|
F: __dxlog_file,
|
|
497
|
-
L:
|
|
546
|
+
L: 426,
|
|
498
547
|
S: this,
|
|
499
548
|
C: (f, a) => f(...a)
|
|
500
549
|
});
|
|
@@ -502,7 +551,7 @@ var Connection = class {
|
|
|
502
551
|
} else {
|
|
503
552
|
invariant(this._transport, "Connection not ready to accept signals.", {
|
|
504
553
|
F: __dxlog_file,
|
|
505
|
-
L:
|
|
554
|
+
L: 429,
|
|
506
555
|
S: this,
|
|
507
556
|
A: [
|
|
508
557
|
"this._transport",
|
|
@@ -515,7 +564,7 @@ var Connection = class {
|
|
|
515
564
|
msg: msg.data
|
|
516
565
|
}, {
|
|
517
566
|
F: __dxlog_file,
|
|
518
|
-
L:
|
|
567
|
+
L: 430,
|
|
519
568
|
S: this,
|
|
520
569
|
C: (f, a) => f(...a)
|
|
521
570
|
});
|
|
@@ -533,13 +582,13 @@ var Connection = class {
|
|
|
533
582
|
peerId: this.localInfo
|
|
534
583
|
}, {
|
|
535
584
|
F: __dxlog_file,
|
|
536
|
-
L:
|
|
585
|
+
L: 441,
|
|
537
586
|
S: this,
|
|
538
587
|
C: (f, a) => f(...a)
|
|
539
588
|
});
|
|
540
589
|
invariant(state !== this._state, "Already in this state.", {
|
|
541
590
|
F: __dxlog_file,
|
|
542
|
-
L:
|
|
591
|
+
L: 442,
|
|
543
592
|
S: this,
|
|
544
593
|
A: [
|
|
545
594
|
"state !== this._state",
|
|
@@ -555,74 +604,6 @@ var Connection = class {
|
|
|
555
604
|
this.transportStats.emit(stats);
|
|
556
605
|
}
|
|
557
606
|
}
|
|
558
|
-
constructor(topic, localInfo, remoteInfo, sessionId, initiator, _signalMessaging, _protocol, _transportFactory, _callbacks) {
|
|
559
|
-
_define_property(this, "topic", void 0);
|
|
560
|
-
_define_property(this, "localInfo", void 0);
|
|
561
|
-
_define_property(this, "remoteInfo", void 0);
|
|
562
|
-
_define_property(this, "sessionId", void 0);
|
|
563
|
-
_define_property(this, "initiator", void 0);
|
|
564
|
-
_define_property(this, "_signalMessaging", void 0);
|
|
565
|
-
_define_property(this, "_protocol", void 0);
|
|
566
|
-
_define_property(this, "_transportFactory", void 0);
|
|
567
|
-
_define_property(this, "_callbacks", void 0);
|
|
568
|
-
_define_property(this, "_ctx", void 0);
|
|
569
|
-
_define_property(this, "connectedTimeoutContext", void 0);
|
|
570
|
-
_define_property(this, "_protocolClosed", void 0);
|
|
571
|
-
_define_property(this, "_transportClosed", void 0);
|
|
572
|
-
_define_property(this, "_state", void 0);
|
|
573
|
-
_define_property(this, "_transport", void 0);
|
|
574
|
-
_define_property(this, "closeReason", void 0);
|
|
575
|
-
_define_property(this, "_incomingSignalBuffer", void 0);
|
|
576
|
-
_define_property(this, "_outgoingSignalBuffer", void 0);
|
|
577
|
-
_define_property(this, "stateChanged", void 0);
|
|
578
|
-
_define_property(this, "errors", void 0);
|
|
579
|
-
_define_property(this, "_instanceId", void 0);
|
|
580
|
-
_define_property(this, "transportStats", void 0);
|
|
581
|
-
_define_property(this, "_signalSendTask", void 0);
|
|
582
|
-
_define_property(this, "_signallingDelay", void 0);
|
|
583
|
-
this.topic = topic;
|
|
584
|
-
this.localInfo = localInfo;
|
|
585
|
-
this.remoteInfo = remoteInfo;
|
|
586
|
-
this.sessionId = sessionId;
|
|
587
|
-
this.initiator = initiator;
|
|
588
|
-
this._signalMessaging = _signalMessaging;
|
|
589
|
-
this._protocol = _protocol;
|
|
590
|
-
this._transportFactory = _transportFactory;
|
|
591
|
-
this._callbacks = _callbacks;
|
|
592
|
-
this._ctx = new Context(void 0, {
|
|
593
|
-
F: __dxlog_file,
|
|
594
|
-
L: 100
|
|
595
|
-
});
|
|
596
|
-
this.connectedTimeoutContext = new Context(void 0, {
|
|
597
|
-
F: __dxlog_file,
|
|
598
|
-
L: 101
|
|
599
|
-
});
|
|
600
|
-
this._protocolClosed = new Trigger();
|
|
601
|
-
this._transportClosed = new Trigger();
|
|
602
|
-
this._state = "CREATED";
|
|
603
|
-
this._incomingSignalBuffer = [];
|
|
604
|
-
this._outgoingSignalBuffer = [];
|
|
605
|
-
this.stateChanged = new Event();
|
|
606
|
-
this.errors = new ErrorStream();
|
|
607
|
-
this._instanceId = PublicKey.random().toHex();
|
|
608
|
-
this.transportStats = new Event();
|
|
609
|
-
this._signalSendTask = new DeferredTask(this._ctx, async () => {
|
|
610
|
-
await this._flushSignalBuffer();
|
|
611
|
-
});
|
|
612
|
-
this._signallingDelay = STARTING_SIGNALLING_DELAY;
|
|
613
|
-
log.trace("dxos.mesh.connection.construct", {
|
|
614
|
-
sessionId: this.sessionId,
|
|
615
|
-
topic: this.topic,
|
|
616
|
-
localPeer: this.localInfo,
|
|
617
|
-
remotePeer: this.remoteInfo,
|
|
618
|
-
initiator: this.initiator
|
|
619
|
-
}, {
|
|
620
|
-
F: __dxlog_file,
|
|
621
|
-
L: 137,
|
|
622
|
-
S: this,
|
|
623
|
-
C: (f, a) => f(...a)
|
|
624
|
-
});
|
|
625
|
-
}
|
|
626
607
|
};
|
|
627
608
|
_ts_decorate([
|
|
628
609
|
logInfo
|
|
@@ -634,63 +615,32 @@ _ts_decorate([
|
|
|
634
615
|
synchronized
|
|
635
616
|
], Connection.prototype, "close", null);
|
|
636
617
|
|
|
637
|
-
// src/signal/ice.ts
|
|
638
|
-
import { asyncTimeout } from "@dxos/async";
|
|
639
|
-
import { log as log2 } from "@dxos/log";
|
|
640
|
-
import { isNonNullable } from "@dxos/util";
|
|
641
|
-
var __dxlog_file2 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/signal/ice.ts";
|
|
642
|
-
var createIceProvider = (iceProviders) => {
|
|
643
|
-
let cachedIceServers;
|
|
644
|
-
return {
|
|
645
|
-
getIceServers: async () => {
|
|
646
|
-
if (cachedIceServers) {
|
|
647
|
-
return cachedIceServers;
|
|
648
|
-
}
|
|
649
|
-
cachedIceServers = (await Promise.all(iceProviders.map(({ urls }) => asyncTimeout(fetch(urls, {
|
|
650
|
-
method: "GET"
|
|
651
|
-
}), 1e4).then((response) => response.json()).catch((err) => {
|
|
652
|
-
const isDev = typeof window !== "undefined" && window.location.href.includes("localhost");
|
|
653
|
-
if (!isDev) {
|
|
654
|
-
log2.error("Failed to fetch ICE servers from provider", {
|
|
655
|
-
urls,
|
|
656
|
-
err
|
|
657
|
-
}, {
|
|
658
|
-
F: __dxlog_file2,
|
|
659
|
-
L: 30,
|
|
660
|
-
S: void 0,
|
|
661
|
-
C: (f, a) => f(...a)
|
|
662
|
-
});
|
|
663
|
-
}
|
|
664
|
-
})))).filter(isNonNullable).map(({ iceServers }) => iceServers).flat();
|
|
665
|
-
return cachedIceServers;
|
|
666
|
-
}
|
|
667
|
-
};
|
|
668
|
-
};
|
|
669
|
-
|
|
670
618
|
// src/signal/swarm-messenger.ts
|
|
671
619
|
import { Context as Context2 } from "@dxos/context";
|
|
672
620
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
673
621
|
import { PublicKey as PublicKey2 } from "@dxos/keys";
|
|
674
|
-
import { log as
|
|
622
|
+
import { log as log2 } from "@dxos/log";
|
|
675
623
|
import { TimeoutError as TimeoutError2 } from "@dxos/protocols";
|
|
676
624
|
import { schema } from "@dxos/protocols/proto";
|
|
677
625
|
import { ComplexMap } from "@dxos/util";
|
|
678
|
-
|
|
679
|
-
if (key in obj) {
|
|
680
|
-
Object.defineProperty(obj, key, {
|
|
681
|
-
value,
|
|
682
|
-
enumerable: true,
|
|
683
|
-
configurable: true,
|
|
684
|
-
writable: true
|
|
685
|
-
});
|
|
686
|
-
} else {
|
|
687
|
-
obj[key] = value;
|
|
688
|
-
}
|
|
689
|
-
return obj;
|
|
690
|
-
}
|
|
691
|
-
var __dxlog_file3 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
|
|
626
|
+
var __dxlog_file2 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
|
|
692
627
|
var SwarmMessage = schema.getCodecForType("dxos.mesh.swarm.SwarmMessage");
|
|
693
628
|
var SwarmMessenger = class {
|
|
629
|
+
_ctx = new Context2(void 0, {
|
|
630
|
+
F: __dxlog_file2,
|
|
631
|
+
L: 35
|
|
632
|
+
});
|
|
633
|
+
_sendMessage;
|
|
634
|
+
_onSignal;
|
|
635
|
+
_onOffer;
|
|
636
|
+
_topic;
|
|
637
|
+
_offerRecords = new ComplexMap((key) => key.toHex());
|
|
638
|
+
constructor({ sendMessage, onSignal, onOffer, topic }) {
|
|
639
|
+
this._sendMessage = sendMessage;
|
|
640
|
+
this._onSignal = onSignal;
|
|
641
|
+
this._onOffer = onOffer;
|
|
642
|
+
this._topic = topic;
|
|
643
|
+
}
|
|
694
644
|
async receiveMessage({ author, recipient, payload }) {
|
|
695
645
|
if (payload.type_url !== "dxos.mesh.swarm.SwarmMessage") {
|
|
696
646
|
return;
|
|
@@ -699,12 +649,12 @@ var SwarmMessenger = class {
|
|
|
699
649
|
if (!this._topic.equals(message.topic)) {
|
|
700
650
|
return;
|
|
701
651
|
}
|
|
702
|
-
|
|
652
|
+
log2("received", {
|
|
703
653
|
from: author,
|
|
704
654
|
to: recipient,
|
|
705
655
|
msg: message
|
|
706
656
|
}, {
|
|
707
|
-
F:
|
|
657
|
+
F: __dxlog_file2,
|
|
708
658
|
L: 71,
|
|
709
659
|
S: this,
|
|
710
660
|
C: (f, a) => f(...a)
|
|
@@ -730,10 +680,10 @@ var SwarmMessenger = class {
|
|
|
730
680
|
message
|
|
731
681
|
});
|
|
732
682
|
} else {
|
|
733
|
-
|
|
683
|
+
log2.warn("unknown message", {
|
|
734
684
|
message
|
|
735
685
|
}, {
|
|
736
|
-
F:
|
|
686
|
+
F: __dxlog_file2,
|
|
737
687
|
L: 82,
|
|
738
688
|
S: this,
|
|
739
689
|
C: (f, a) => f(...a)
|
|
@@ -742,7 +692,7 @@ var SwarmMessenger = class {
|
|
|
742
692
|
}
|
|
743
693
|
async signal(message) {
|
|
744
694
|
invariant2(message.data?.signal || message.data?.signalBatch, "Invalid message", {
|
|
745
|
-
F:
|
|
695
|
+
F: __dxlog_file2,
|
|
746
696
|
L: 87,
|
|
747
697
|
S: this,
|
|
748
698
|
A: [
|
|
@@ -778,12 +728,12 @@ var SwarmMessenger = class {
|
|
|
778
728
|
// Setting unique message_id if it not specified yet.
|
|
779
729
|
messageId: message.messageId ?? PublicKey2.random()
|
|
780
730
|
};
|
|
781
|
-
|
|
731
|
+
log2("sending", {
|
|
782
732
|
from: author,
|
|
783
733
|
to: recipient,
|
|
784
734
|
msg: networkMessage
|
|
785
735
|
}, {
|
|
786
|
-
F:
|
|
736
|
+
F: __dxlog_file2,
|
|
787
737
|
L: 125,
|
|
788
738
|
S: this,
|
|
789
739
|
C: (f, a) => f(...a)
|
|
@@ -799,7 +749,7 @@ var SwarmMessenger = class {
|
|
|
799
749
|
}
|
|
800
750
|
async _resolveAnswers(message) {
|
|
801
751
|
invariant2(message.data?.answer?.offerMessageId, "No offerMessageId", {
|
|
802
|
-
F:
|
|
752
|
+
F: __dxlog_file2,
|
|
803
753
|
L: 137,
|
|
804
754
|
S: this,
|
|
805
755
|
A: [
|
|
@@ -811,7 +761,7 @@ var SwarmMessenger = class {
|
|
|
811
761
|
if (offerRecord) {
|
|
812
762
|
this._offerRecords.delete(message.data.answer.offerMessageId);
|
|
813
763
|
invariant2(message.data?.answer, "No answer", {
|
|
814
|
-
F:
|
|
764
|
+
F: __dxlog_file2,
|
|
815
765
|
L: 141,
|
|
816
766
|
S: this,
|
|
817
767
|
A: [
|
|
@@ -819,10 +769,10 @@ var SwarmMessenger = class {
|
|
|
819
769
|
"'No answer'"
|
|
820
770
|
]
|
|
821
771
|
});
|
|
822
|
-
|
|
772
|
+
log2("resolving", {
|
|
823
773
|
answer: message.data.answer
|
|
824
774
|
}, {
|
|
825
|
-
F:
|
|
775
|
+
F: __dxlog_file2,
|
|
826
776
|
L: 142,
|
|
827
777
|
S: this,
|
|
828
778
|
C: (f, a) => f(...a)
|
|
@@ -832,7 +782,7 @@ var SwarmMessenger = class {
|
|
|
832
782
|
}
|
|
833
783
|
async _handleOffer({ author, recipient, message }) {
|
|
834
784
|
invariant2(message.data.offer, "No offer", {
|
|
835
|
-
F:
|
|
785
|
+
F: __dxlog_file2,
|
|
836
786
|
L: 156,
|
|
837
787
|
S: this,
|
|
838
788
|
A: [
|
|
@@ -864,19 +814,19 @@ var SwarmMessenger = class {
|
|
|
864
814
|
});
|
|
865
815
|
} catch (err) {
|
|
866
816
|
if (err instanceof TimeoutError2) {
|
|
867
|
-
|
|
817
|
+
log2.info("timeout sending answer to offer", {
|
|
868
818
|
err
|
|
869
819
|
}, {
|
|
870
|
-
F:
|
|
820
|
+
F: __dxlog_file2,
|
|
871
821
|
L: 177,
|
|
872
822
|
S: this,
|
|
873
823
|
C: (f, a) => f(...a)
|
|
874
824
|
});
|
|
875
825
|
} else {
|
|
876
|
-
|
|
826
|
+
log2.info("error sending answer to offer", {
|
|
877
827
|
err
|
|
878
828
|
}, {
|
|
879
|
-
F:
|
|
829
|
+
F: __dxlog_file2,
|
|
880
830
|
L: 179,
|
|
881
831
|
S: this,
|
|
882
832
|
C: (f, a) => f(...a)
|
|
@@ -886,7 +836,7 @@ var SwarmMessenger = class {
|
|
|
886
836
|
}
|
|
887
837
|
async _handleSignal({ author, recipient, message }) {
|
|
888
838
|
invariant2(message.messageId, void 0, {
|
|
889
|
-
F:
|
|
839
|
+
F: __dxlog_file2,
|
|
890
840
|
L: 193,
|
|
891
841
|
S: this,
|
|
892
842
|
A: [
|
|
@@ -895,7 +845,7 @@ var SwarmMessenger = class {
|
|
|
895
845
|
]
|
|
896
846
|
});
|
|
897
847
|
invariant2(message.data.signal || message.data.signalBatch, "Invalid message", {
|
|
898
|
-
F:
|
|
848
|
+
F: __dxlog_file2,
|
|
899
849
|
L: 194,
|
|
900
850
|
S: this,
|
|
901
851
|
A: [
|
|
@@ -914,21 +864,6 @@ var SwarmMessenger = class {
|
|
|
914
864
|
};
|
|
915
865
|
await this._onSignal(signalMessage);
|
|
916
866
|
}
|
|
917
|
-
constructor({ sendMessage, onSignal, onOffer, topic }) {
|
|
918
|
-
_define_property2(this, "_ctx", new Context2(void 0, {
|
|
919
|
-
F: __dxlog_file3,
|
|
920
|
-
L: 35
|
|
921
|
-
}));
|
|
922
|
-
_define_property2(this, "_sendMessage", void 0);
|
|
923
|
-
_define_property2(this, "_onSignal", void 0);
|
|
924
|
-
_define_property2(this, "_onOffer", void 0);
|
|
925
|
-
_define_property2(this, "_topic", void 0);
|
|
926
|
-
_define_property2(this, "_offerRecords", new ComplexMap((key) => key.toHex()));
|
|
927
|
-
this._sendMessage = sendMessage;
|
|
928
|
-
this._onSignal = onSignal;
|
|
929
|
-
this._onOffer = onOffer;
|
|
930
|
-
this._topic = topic;
|
|
931
|
-
}
|
|
932
867
|
};
|
|
933
868
|
|
|
934
869
|
// src/swarm/swarm.ts
|
|
@@ -937,45 +872,70 @@ import { Context as Context4 } from "@dxos/context";
|
|
|
937
872
|
import { ErrorStream as ErrorStream2 } from "@dxos/debug";
|
|
938
873
|
import { invariant as invariant4 } from "@dxos/invariant";
|
|
939
874
|
import { PublicKey as PublicKey4 } from "@dxos/keys";
|
|
940
|
-
import { log as
|
|
875
|
+
import { log as log4, logInfo as logInfo2 } from "@dxos/log";
|
|
941
876
|
import { PeerInfoHash } from "@dxos/messaging";
|
|
942
877
|
import { trace as trace2 } from "@dxos/protocols";
|
|
943
|
-
import { ComplexMap as ComplexMap2, isNonNullable
|
|
878
|
+
import { ComplexMap as ComplexMap2, isNonNullable } from "@dxos/util";
|
|
944
879
|
|
|
945
880
|
// src/swarm/peer.ts
|
|
946
881
|
import { Event as Event2, scheduleTask as scheduleTask2, synchronized as synchronized2 } from "@dxos/async";
|
|
947
882
|
import { Context as Context3 } from "@dxos/context";
|
|
948
883
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
949
884
|
import { PublicKey as PublicKey3 } from "@dxos/keys";
|
|
950
|
-
import { log as
|
|
885
|
+
import { log as log3 } from "@dxos/log";
|
|
951
886
|
import { CancelledError as CancelledError2, SystemError } from "@dxos/protocols";
|
|
952
|
-
function _define_property3(obj, key, value) {
|
|
953
|
-
if (key in obj) {
|
|
954
|
-
Object.defineProperty(obj, key, {
|
|
955
|
-
value,
|
|
956
|
-
enumerable: true,
|
|
957
|
-
configurable: true,
|
|
958
|
-
writable: true
|
|
959
|
-
});
|
|
960
|
-
} else {
|
|
961
|
-
obj[key] = value;
|
|
962
|
-
}
|
|
963
|
-
return obj;
|
|
964
|
-
}
|
|
965
887
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
966
888
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
967
889
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
968
890
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
969
891
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
970
892
|
}
|
|
971
|
-
var
|
|
893
|
+
var __dxlog_file3 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts";
|
|
972
894
|
var ConnectionDisplacedError = class extends SystemError {
|
|
973
895
|
constructor() {
|
|
974
|
-
super(
|
|
896
|
+
super({
|
|
897
|
+
message: "Connection displaced by remote initiator."
|
|
898
|
+
});
|
|
975
899
|
}
|
|
976
900
|
};
|
|
977
901
|
var CONNECTION_COUNTS_STABLE_AFTER = 5e3;
|
|
978
902
|
var Peer = class {
|
|
903
|
+
remoteInfo;
|
|
904
|
+
topic;
|
|
905
|
+
localInfo;
|
|
906
|
+
_signalMessaging;
|
|
907
|
+
_protocolProvider;
|
|
908
|
+
_transportFactory;
|
|
909
|
+
_connectionLimiter;
|
|
910
|
+
_callbacks;
|
|
911
|
+
/**
|
|
912
|
+
* Will be available to connect after this time.
|
|
913
|
+
*/
|
|
914
|
+
_availableAfter = 0;
|
|
915
|
+
availableToConnect = true;
|
|
916
|
+
_lastConnectionTime;
|
|
917
|
+
_ctx = new Context3(void 0, {
|
|
918
|
+
F: __dxlog_file3,
|
|
919
|
+
L: 81
|
|
920
|
+
});
|
|
921
|
+
_connectionCtx;
|
|
922
|
+
connection;
|
|
923
|
+
/**
|
|
924
|
+
* Whether the peer is currently advertizing itself on the signal-network.
|
|
925
|
+
*/
|
|
926
|
+
advertizing = false;
|
|
927
|
+
initiating = false;
|
|
928
|
+
connectionDisplaced = new Event2();
|
|
929
|
+
constructor(remoteInfo, topic, localInfo, _signalMessaging, _protocolProvider, _transportFactory, _connectionLimiter, _callbacks) {
|
|
930
|
+
this.remoteInfo = remoteInfo;
|
|
931
|
+
this.topic = topic;
|
|
932
|
+
this.localInfo = localInfo;
|
|
933
|
+
this._signalMessaging = _signalMessaging;
|
|
934
|
+
this._protocolProvider = _protocolProvider;
|
|
935
|
+
this._transportFactory = _transportFactory;
|
|
936
|
+
this._connectionLimiter = _connectionLimiter;
|
|
937
|
+
this._callbacks = _callbacks;
|
|
938
|
+
}
|
|
979
939
|
/**
|
|
980
940
|
* Respond to remote offer.
|
|
981
941
|
*/
|
|
@@ -986,8 +946,8 @@ var Peer = class {
|
|
|
986
946
|
ConnectionState.INITIAL,
|
|
987
947
|
ConnectionState.CONNECTING
|
|
988
948
|
].includes(this.connection.state)) {
|
|
989
|
-
|
|
990
|
-
F:
|
|
949
|
+
log3.info(`received offer when connection already in ${this.connection.state} state`, void 0, {
|
|
950
|
+
F: __dxlog_file3,
|
|
991
951
|
L: 116,
|
|
992
952
|
S: this,
|
|
993
953
|
C: (f, a) => f(...a)
|
|
@@ -998,13 +958,13 @@ var Peer = class {
|
|
|
998
958
|
}
|
|
999
959
|
if (this.connection || this.initiating) {
|
|
1000
960
|
if (remote.peerKey < this.localInfo.peerKey) {
|
|
1001
|
-
|
|
961
|
+
log3("close local connection", {
|
|
1002
962
|
localPeer: this.localInfo,
|
|
1003
963
|
topic: this.topic,
|
|
1004
964
|
remotePeer: this.remoteInfo,
|
|
1005
965
|
sessionId: this.connection?.sessionId
|
|
1006
966
|
}, {
|
|
1007
|
-
F:
|
|
967
|
+
F: __dxlog_file3,
|
|
1008
968
|
L: 125,
|
|
1009
969
|
S: this,
|
|
1010
970
|
C: (f, a) => f(...a)
|
|
@@ -1021,7 +981,7 @@ var Peer = class {
|
|
|
1021
981
|
if (await this._callbacks.onOffer(remote)) {
|
|
1022
982
|
if (!this.connection) {
|
|
1023
983
|
invariant3(message.sessionId, void 0, {
|
|
1024
|
-
F:
|
|
984
|
+
F: __dxlog_file3,
|
|
1025
985
|
L: 145,
|
|
1026
986
|
S: this,
|
|
1027
987
|
A: [
|
|
@@ -1036,13 +996,13 @@ var Peer = class {
|
|
|
1036
996
|
await connection.openConnection();
|
|
1037
997
|
} catch (err) {
|
|
1038
998
|
if (!(err instanceof CancelledError2)) {
|
|
1039
|
-
|
|
999
|
+
log3.info("connection error", {
|
|
1040
1000
|
topic: this.topic,
|
|
1041
1001
|
peerId: this.localInfo,
|
|
1042
1002
|
remoteId: this.remoteInfo,
|
|
1043
1003
|
err
|
|
1044
1004
|
}, {
|
|
1045
|
-
F:
|
|
1005
|
+
F: __dxlog_file3,
|
|
1046
1006
|
L: 155,
|
|
1047
1007
|
S: this,
|
|
1048
1008
|
C: (f, a) => f(...a)
|
|
@@ -1064,8 +1024,8 @@ var Peer = class {
|
|
|
1064
1024
|
*/
|
|
1065
1025
|
async initiateConnection() {
|
|
1066
1026
|
invariant3(!this.initiating, "Initiation in progress.", {
|
|
1067
|
-
F:
|
|
1068
|
-
L:
|
|
1027
|
+
F: __dxlog_file3,
|
|
1028
|
+
L: 173,
|
|
1069
1029
|
S: this,
|
|
1070
1030
|
A: [
|
|
1071
1031
|
"!this.initiating",
|
|
@@ -1073,8 +1033,8 @@ var Peer = class {
|
|
|
1073
1033
|
]
|
|
1074
1034
|
});
|
|
1075
1035
|
invariant3(!this.connection, "Already connected.", {
|
|
1076
|
-
F:
|
|
1077
|
-
L:
|
|
1036
|
+
F: __dxlog_file3,
|
|
1037
|
+
L: 174,
|
|
1078
1038
|
S: this,
|
|
1079
1039
|
A: [
|
|
1080
1040
|
"!this.connection",
|
|
@@ -1082,14 +1042,14 @@ var Peer = class {
|
|
|
1082
1042
|
]
|
|
1083
1043
|
});
|
|
1084
1044
|
const sessionId = PublicKey3.random();
|
|
1085
|
-
|
|
1045
|
+
log3("initiating...", {
|
|
1086
1046
|
local: this.localInfo,
|
|
1087
1047
|
topic: this.topic,
|
|
1088
1048
|
remote: this.remoteInfo,
|
|
1089
1049
|
sessionId
|
|
1090
1050
|
}, {
|
|
1091
|
-
F:
|
|
1092
|
-
L:
|
|
1051
|
+
F: __dxlog_file3,
|
|
1052
|
+
L: 176,
|
|
1093
1053
|
S: this,
|
|
1094
1054
|
C: (f, a) => f(...a)
|
|
1095
1055
|
});
|
|
@@ -1108,35 +1068,35 @@ var Peer = class {
|
|
|
1108
1068
|
offer: {}
|
|
1109
1069
|
}
|
|
1110
1070
|
});
|
|
1111
|
-
|
|
1071
|
+
log3("received", {
|
|
1112
1072
|
answer,
|
|
1113
1073
|
topic: this.topic,
|
|
1114
1074
|
local: this.localInfo,
|
|
1115
1075
|
remote: this.remoteInfo
|
|
1116
1076
|
}, {
|
|
1117
|
-
F:
|
|
1118
|
-
L:
|
|
1077
|
+
F: __dxlog_file3,
|
|
1078
|
+
L: 193,
|
|
1119
1079
|
S: this,
|
|
1120
1080
|
C: (f, a) => f(...a)
|
|
1121
1081
|
});
|
|
1122
1082
|
if (connection.state !== ConnectionState.INITIAL) {
|
|
1123
|
-
|
|
1124
|
-
F:
|
|
1125
|
-
L:
|
|
1083
|
+
log3("ignoring response", void 0, {
|
|
1084
|
+
F: __dxlog_file3,
|
|
1085
|
+
L: 195,
|
|
1126
1086
|
S: this,
|
|
1127
1087
|
C: (f, a) => f(...a)
|
|
1128
1088
|
});
|
|
1129
1089
|
return;
|
|
1130
1090
|
}
|
|
1131
1091
|
} catch (err) {
|
|
1132
|
-
|
|
1092
|
+
log3("initiation error: send offer", {
|
|
1133
1093
|
err,
|
|
1134
1094
|
topic: this.topic,
|
|
1135
1095
|
local: this.localInfo,
|
|
1136
1096
|
remote: this.remoteInfo
|
|
1137
1097
|
}, {
|
|
1138
|
-
F:
|
|
1139
|
-
L:
|
|
1098
|
+
F: __dxlog_file3,
|
|
1099
|
+
L: 199,
|
|
1140
1100
|
S: this,
|
|
1141
1101
|
C: (f, a) => f(...a)
|
|
1142
1102
|
});
|
|
@@ -1151,14 +1111,14 @@ var Peer = class {
|
|
|
1151
1111
|
return;
|
|
1152
1112
|
}
|
|
1153
1113
|
} catch (err) {
|
|
1154
|
-
|
|
1114
|
+
log3("initiation error: accept answer", {
|
|
1155
1115
|
err,
|
|
1156
1116
|
topic: this.topic,
|
|
1157
1117
|
local: this.localInfo,
|
|
1158
1118
|
remote: this.remoteInfo
|
|
1159
1119
|
}, {
|
|
1160
|
-
F:
|
|
1161
|
-
L:
|
|
1120
|
+
F: __dxlog_file3,
|
|
1121
|
+
L: 212,
|
|
1162
1122
|
S: this,
|
|
1163
1123
|
C: (f, a) => f(...a)
|
|
1164
1124
|
});
|
|
@@ -1168,31 +1128,31 @@ var Peer = class {
|
|
|
1168
1128
|
this.initiating = false;
|
|
1169
1129
|
}
|
|
1170
1130
|
try {
|
|
1171
|
-
|
|
1172
|
-
F:
|
|
1173
|
-
L:
|
|
1131
|
+
log3("opening connection as initiator", void 0, {
|
|
1132
|
+
F: __dxlog_file3,
|
|
1133
|
+
L: 225,
|
|
1174
1134
|
S: this,
|
|
1175
1135
|
C: (f, a) => f(...a)
|
|
1176
1136
|
});
|
|
1177
1137
|
await connection.openConnection();
|
|
1178
1138
|
this._callbacks.onAccepted();
|
|
1179
1139
|
} catch (err) {
|
|
1180
|
-
|
|
1140
|
+
log3("initiation error: open connection", {
|
|
1181
1141
|
err,
|
|
1182
1142
|
topic: this.topic,
|
|
1183
1143
|
local: this.localInfo,
|
|
1184
1144
|
remote: this.remoteInfo
|
|
1185
1145
|
}, {
|
|
1186
|
-
F:
|
|
1187
|
-
L:
|
|
1146
|
+
F: __dxlog_file3,
|
|
1147
|
+
L: 229,
|
|
1188
1148
|
S: this,
|
|
1189
1149
|
C: (f, a) => f(...a)
|
|
1190
1150
|
});
|
|
1191
|
-
|
|
1151
|
+
log3.warn("closing connection due to unhandled error on openConnection", {
|
|
1192
1152
|
err
|
|
1193
1153
|
}, {
|
|
1194
|
-
F:
|
|
1195
|
-
L:
|
|
1154
|
+
F: __dxlog_file3,
|
|
1155
|
+
L: 236,
|
|
1196
1156
|
S: this,
|
|
1197
1157
|
C: (f, a) => f(...a)
|
|
1198
1158
|
});
|
|
@@ -1207,21 +1167,21 @@ var Peer = class {
|
|
|
1207
1167
|
* Either we're initiating a connection or creating one in response to an offer from the other peer.
|
|
1208
1168
|
*/
|
|
1209
1169
|
_createConnection(initiator, sessionId) {
|
|
1210
|
-
|
|
1170
|
+
log3("creating connection", {
|
|
1211
1171
|
topic: this.topic,
|
|
1212
1172
|
peerId: this.localInfo,
|
|
1213
1173
|
remoteId: this.remoteInfo,
|
|
1214
1174
|
initiator,
|
|
1215
1175
|
sessionId
|
|
1216
1176
|
}, {
|
|
1217
|
-
F:
|
|
1218
|
-
L:
|
|
1177
|
+
F: __dxlog_file3,
|
|
1178
|
+
L: 250,
|
|
1219
1179
|
S: this,
|
|
1220
1180
|
C: (f, a) => f(...a)
|
|
1221
1181
|
});
|
|
1222
1182
|
invariant3(!this.connection, "Already connected.", {
|
|
1223
|
-
F:
|
|
1224
|
-
L:
|
|
1183
|
+
F: __dxlog_file3,
|
|
1184
|
+
L: 257,
|
|
1225
1185
|
S: this,
|
|
1226
1186
|
A: [
|
|
1227
1187
|
"!this.connection",
|
|
@@ -1249,15 +1209,15 @@ var Peer = class {
|
|
|
1249
1209
|
this._lastConnectionTime = Date.now();
|
|
1250
1210
|
this._callbacks.onConnected();
|
|
1251
1211
|
this._connectionLimiter.doneConnecting(sessionId);
|
|
1252
|
-
|
|
1212
|
+
log3.trace("dxos.mesh.connection.connected", {
|
|
1253
1213
|
topic: this.topic,
|
|
1254
1214
|
localPeerId: this.localInfo,
|
|
1255
1215
|
remotePeerId: this.remoteInfo,
|
|
1256
1216
|
sessionId,
|
|
1257
1217
|
initiator
|
|
1258
1218
|
}, {
|
|
1259
|
-
F:
|
|
1260
|
-
L:
|
|
1219
|
+
F: __dxlog_file3,
|
|
1220
|
+
L: 281,
|
|
1261
1221
|
S: this,
|
|
1262
1222
|
C: (f, a) => f(...a)
|
|
1263
1223
|
});
|
|
@@ -1269,31 +1229,31 @@ var Peer = class {
|
|
|
1269
1229
|
remoteId: this.remoteInfo,
|
|
1270
1230
|
initiator
|
|
1271
1231
|
};
|
|
1272
|
-
|
|
1273
|
-
F:
|
|
1274
|
-
L:
|
|
1232
|
+
log3("connection closed", logMeta, {
|
|
1233
|
+
F: __dxlog_file3,
|
|
1234
|
+
L: 291,
|
|
1275
1235
|
S: this,
|
|
1276
1236
|
C: (f, a) => f(...a)
|
|
1277
1237
|
});
|
|
1278
1238
|
this._connectionLimiter.doneConnecting(sessionId);
|
|
1279
1239
|
invariant3(this.connection === connection, "Connection mismatch (race condition).", {
|
|
1280
|
-
F:
|
|
1281
|
-
L:
|
|
1240
|
+
F: __dxlog_file3,
|
|
1241
|
+
L: 296,
|
|
1282
1242
|
S: this,
|
|
1283
1243
|
A: [
|
|
1284
1244
|
"this.connection === connection",
|
|
1285
1245
|
"'Connection mismatch (race condition).'"
|
|
1286
1246
|
]
|
|
1287
1247
|
});
|
|
1288
|
-
|
|
1248
|
+
log3.trace("dxos.mesh.connection.closed", {
|
|
1289
1249
|
topic: this.topic,
|
|
1290
1250
|
localPeerId: this.localInfo,
|
|
1291
1251
|
remotePeerId: this.remoteInfo,
|
|
1292
1252
|
sessionId,
|
|
1293
1253
|
initiator
|
|
1294
1254
|
}, {
|
|
1295
|
-
F:
|
|
1296
|
-
L:
|
|
1255
|
+
F: __dxlog_file3,
|
|
1256
|
+
L: 298,
|
|
1297
1257
|
S: this,
|
|
1298
1258
|
C: (f, a) => f(...a)
|
|
1299
1259
|
});
|
|
@@ -1308,9 +1268,9 @@ var Peer = class {
|
|
|
1308
1268
|
}
|
|
1309
1269
|
this._callbacks.onDisconnected();
|
|
1310
1270
|
scheduleTask2(this._connectionCtx, () => {
|
|
1311
|
-
|
|
1312
|
-
F:
|
|
1313
|
-
L:
|
|
1271
|
+
log3("peer became available", logMeta, {
|
|
1272
|
+
F: __dxlog_file3,
|
|
1273
|
+
L: 322,
|
|
1314
1274
|
S: this,
|
|
1315
1275
|
C: (f, a) => f(...a)
|
|
1316
1276
|
});
|
|
@@ -1326,19 +1286,19 @@ var Peer = class {
|
|
|
1326
1286
|
void this._connectionCtx?.dispose();
|
|
1327
1287
|
this._connectionCtx = this._ctx.derive();
|
|
1328
1288
|
connection.errors.handle((err) => {
|
|
1329
|
-
|
|
1289
|
+
log3.info("connection error, closing", {
|
|
1330
1290
|
topic: this.topic,
|
|
1331
1291
|
peerId: this.localInfo,
|
|
1332
1292
|
remoteId: this.remoteInfo,
|
|
1333
1293
|
initiator,
|
|
1334
1294
|
err
|
|
1335
1295
|
}, {
|
|
1336
|
-
F:
|
|
1337
|
-
L:
|
|
1296
|
+
F: __dxlog_file3,
|
|
1297
|
+
L: 340,
|
|
1338
1298
|
S: this,
|
|
1339
1299
|
C: (f, a) => f(...a)
|
|
1340
1300
|
});
|
|
1341
|
-
|
|
1301
|
+
log3.trace("dxos.mesh.connection.error", {
|
|
1342
1302
|
topic: this.topic,
|
|
1343
1303
|
localPeerId: this.localInfo,
|
|
1344
1304
|
remotePeerId: this.remoteInfo,
|
|
@@ -1346,8 +1306,8 @@ var Peer = class {
|
|
|
1346
1306
|
initiator,
|
|
1347
1307
|
err
|
|
1348
1308
|
}, {
|
|
1349
|
-
F:
|
|
1350
|
-
L:
|
|
1309
|
+
F: __dxlog_file3,
|
|
1310
|
+
L: 347,
|
|
1351
1311
|
S: this,
|
|
1352
1312
|
C: (f, a) => f(...a)
|
|
1353
1313
|
});
|
|
@@ -1361,35 +1321,35 @@ var Peer = class {
|
|
|
1361
1321
|
return;
|
|
1362
1322
|
}
|
|
1363
1323
|
const connection = this.connection;
|
|
1364
|
-
|
|
1324
|
+
log3("closing...", {
|
|
1365
1325
|
peerId: this.remoteInfo,
|
|
1366
1326
|
sessionId: connection.sessionId
|
|
1367
1327
|
}, {
|
|
1368
|
-
F:
|
|
1369
|
-
L:
|
|
1328
|
+
F: __dxlog_file3,
|
|
1329
|
+
L: 372,
|
|
1370
1330
|
S: this,
|
|
1371
1331
|
C: (f, a) => f(...a)
|
|
1372
1332
|
});
|
|
1373
1333
|
await connection.close({
|
|
1374
1334
|
error: err
|
|
1375
1335
|
});
|
|
1376
|
-
|
|
1336
|
+
log3("closed", {
|
|
1377
1337
|
peerId: this.remoteInfo,
|
|
1378
1338
|
sessionId: connection.sessionId
|
|
1379
1339
|
}, {
|
|
1380
|
-
F:
|
|
1381
|
-
L:
|
|
1340
|
+
F: __dxlog_file3,
|
|
1341
|
+
L: 378,
|
|
1382
1342
|
S: this,
|
|
1383
1343
|
C: (f, a) => f(...a)
|
|
1384
1344
|
});
|
|
1385
1345
|
}
|
|
1386
1346
|
async onSignal(message) {
|
|
1387
1347
|
if (!this.connection) {
|
|
1388
|
-
|
|
1348
|
+
log3("dropping signal message for non-existent connection", {
|
|
1389
1349
|
message
|
|
1390
1350
|
}, {
|
|
1391
|
-
F:
|
|
1392
|
-
L:
|
|
1351
|
+
F: __dxlog_file3,
|
|
1352
|
+
L: 383,
|
|
1393
1353
|
S: this,
|
|
1394
1354
|
C: (f, a) => f(...a)
|
|
1395
1355
|
});
|
|
@@ -1399,12 +1359,12 @@ var Peer = class {
|
|
|
1399
1359
|
}
|
|
1400
1360
|
async safeDestroy(reason) {
|
|
1401
1361
|
await this._ctx.dispose();
|
|
1402
|
-
|
|
1362
|
+
log3("Destroying peer", {
|
|
1403
1363
|
peerId: this.remoteInfo,
|
|
1404
1364
|
topic: this.topic
|
|
1405
1365
|
}, {
|
|
1406
|
-
F:
|
|
1407
|
-
L:
|
|
1366
|
+
F: __dxlog_file3,
|
|
1367
|
+
L: 393,
|
|
1408
1368
|
S: this,
|
|
1409
1369
|
C: (f, a) => f(...a)
|
|
1410
1370
|
});
|
|
@@ -1412,42 +1372,6 @@ var Peer = class {
|
|
|
1412
1372
|
reason
|
|
1413
1373
|
});
|
|
1414
1374
|
}
|
|
1415
|
-
constructor(remoteInfo, topic, localInfo, _signalMessaging, _protocolProvider, _transportFactory, _connectionLimiter, _callbacks) {
|
|
1416
|
-
_define_property3(this, "remoteInfo", void 0);
|
|
1417
|
-
_define_property3(this, "topic", void 0);
|
|
1418
|
-
_define_property3(this, "localInfo", void 0);
|
|
1419
|
-
_define_property3(this, "_signalMessaging", void 0);
|
|
1420
|
-
_define_property3(this, "_protocolProvider", void 0);
|
|
1421
|
-
_define_property3(this, "_transportFactory", void 0);
|
|
1422
|
-
_define_property3(this, "_connectionLimiter", void 0);
|
|
1423
|
-
_define_property3(this, "_callbacks", void 0);
|
|
1424
|
-
_define_property3(this, "_availableAfter", void 0);
|
|
1425
|
-
_define_property3(this, "availableToConnect", void 0);
|
|
1426
|
-
_define_property3(this, "_lastConnectionTime", void 0);
|
|
1427
|
-
_define_property3(this, "_ctx", void 0);
|
|
1428
|
-
_define_property3(this, "_connectionCtx", void 0);
|
|
1429
|
-
_define_property3(this, "connection", void 0);
|
|
1430
|
-
_define_property3(this, "advertizing", void 0);
|
|
1431
|
-
_define_property3(this, "initiating", void 0);
|
|
1432
|
-
_define_property3(this, "connectionDisplaced", void 0);
|
|
1433
|
-
this.remoteInfo = remoteInfo;
|
|
1434
|
-
this.topic = topic;
|
|
1435
|
-
this.localInfo = localInfo;
|
|
1436
|
-
this._signalMessaging = _signalMessaging;
|
|
1437
|
-
this._protocolProvider = _protocolProvider;
|
|
1438
|
-
this._transportFactory = _transportFactory;
|
|
1439
|
-
this._connectionLimiter = _connectionLimiter;
|
|
1440
|
-
this._callbacks = _callbacks;
|
|
1441
|
-
this._availableAfter = 0;
|
|
1442
|
-
this.availableToConnect = true;
|
|
1443
|
-
this._ctx = new Context3(void 0, {
|
|
1444
|
-
F: __dxlog_file4,
|
|
1445
|
-
L: 81
|
|
1446
|
-
});
|
|
1447
|
-
this.advertizing = false;
|
|
1448
|
-
this.initiating = false;
|
|
1449
|
-
this.connectionDisplaced = new Event2();
|
|
1450
|
-
}
|
|
1451
1375
|
};
|
|
1452
1376
|
_ts_decorate2([
|
|
1453
1377
|
synchronized2
|
|
@@ -1466,65 +1390,140 @@ var increaseInterval = (interval) => {
|
|
|
1466
1390
|
};
|
|
1467
1391
|
|
|
1468
1392
|
// src/swarm/swarm.ts
|
|
1469
|
-
function _define_property4(obj, key, value) {
|
|
1470
|
-
if (key in obj) {
|
|
1471
|
-
Object.defineProperty(obj, key, {
|
|
1472
|
-
value,
|
|
1473
|
-
enumerable: true,
|
|
1474
|
-
configurable: true,
|
|
1475
|
-
writable: true
|
|
1476
|
-
});
|
|
1477
|
-
} else {
|
|
1478
|
-
obj[key] = value;
|
|
1479
|
-
}
|
|
1480
|
-
return obj;
|
|
1481
|
-
}
|
|
1482
1393
|
function _ts_decorate3(decorators, target, key, desc) {
|
|
1483
1394
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1484
1395
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1485
1396
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1486
1397
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1487
1398
|
}
|
|
1488
|
-
var
|
|
1399
|
+
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts";
|
|
1489
1400
|
var INITIATION_DELAY = 100;
|
|
1490
1401
|
var getClassName = (obj) => Object.getPrototypeOf(obj).constructor.name;
|
|
1491
1402
|
var Swarm = class {
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1403
|
+
_topic;
|
|
1404
|
+
_ownPeer;
|
|
1405
|
+
_topology;
|
|
1406
|
+
_protocolProvider;
|
|
1407
|
+
_messenger;
|
|
1408
|
+
_transportFactory;
|
|
1409
|
+
_label;
|
|
1410
|
+
_connectionLimiter;
|
|
1411
|
+
_initiationDelay;
|
|
1412
|
+
_swarmMessenger;
|
|
1413
|
+
_ctx = new Context4(void 0, {
|
|
1414
|
+
F: __dxlog_file4,
|
|
1415
|
+
L: 39
|
|
1416
|
+
});
|
|
1417
|
+
_listeningHandle = void 0;
|
|
1501
1418
|
/**
|
|
1502
|
-
*
|
|
1419
|
+
* PeerInfo -> Peer.
|
|
1420
|
+
* @internal
|
|
1503
1421
|
*/
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1422
|
+
_peers = new ComplexMap2(PeerInfoHash);
|
|
1423
|
+
/**
|
|
1424
|
+
* Unique id of the swarm, local to the current peer, generated when swarm is joined.
|
|
1425
|
+
*/
|
|
1426
|
+
_instanceId = PublicKey4.random().toHex();
|
|
1427
|
+
/**
|
|
1428
|
+
* New connection to a peer is started.
|
|
1429
|
+
* @internal
|
|
1430
|
+
*/
|
|
1431
|
+
connectionAdded = new Event3();
|
|
1432
|
+
/**
|
|
1433
|
+
* Connection to a peer is dropped.
|
|
1434
|
+
* @internal
|
|
1435
|
+
*/
|
|
1436
|
+
disconnected = new Event3();
|
|
1437
|
+
/**
|
|
1438
|
+
* Connection is established to a new peer.
|
|
1439
|
+
* @internal
|
|
1440
|
+
*/
|
|
1441
|
+
connected = new Event3();
|
|
1442
|
+
errors = new ErrorStream2();
|
|
1443
|
+
// TODO(burdon): Swarm => Peer.create/destroy =< Connection.open/close
|
|
1444
|
+
// TODO(burdon): Pass in object.
|
|
1445
|
+
constructor(_topic, _ownPeer, _topology, _protocolProvider, _messenger, _transportFactory, _label, _connectionLimiter, _initiationDelay = INITIATION_DELAY) {
|
|
1446
|
+
this._topic = _topic;
|
|
1447
|
+
this._ownPeer = _ownPeer;
|
|
1448
|
+
this._topology = _topology;
|
|
1449
|
+
this._protocolProvider = _protocolProvider;
|
|
1450
|
+
this._messenger = _messenger;
|
|
1451
|
+
this._transportFactory = _transportFactory;
|
|
1452
|
+
this._label = _label;
|
|
1453
|
+
this._connectionLimiter = _connectionLimiter;
|
|
1454
|
+
this._initiationDelay = _initiationDelay;
|
|
1455
|
+
log4.trace("dxos.mesh.swarm.constructor", trace2.begin({
|
|
1456
|
+
id: this._instanceId,
|
|
1457
|
+
data: {
|
|
1458
|
+
topic: this._topic.toHex(),
|
|
1459
|
+
peer: this._ownPeer
|
|
1460
|
+
}
|
|
1461
|
+
}), {
|
|
1462
|
+
F: __dxlog_file4,
|
|
1463
|
+
L: 89,
|
|
1514
1464
|
S: this,
|
|
1515
|
-
|
|
1516
|
-
"!this._listeningHandle",
|
|
1517
|
-
""
|
|
1518
|
-
]
|
|
1465
|
+
C: (f, a) => f(...a)
|
|
1519
1466
|
});
|
|
1520
|
-
|
|
1467
|
+
log4("creating swarm", {
|
|
1468
|
+
peerId: _ownPeer
|
|
1469
|
+
}, {
|
|
1470
|
+
F: __dxlog_file4,
|
|
1471
|
+
L: 93,
|
|
1472
|
+
S: this,
|
|
1473
|
+
C: (f, a) => f(...a)
|
|
1474
|
+
});
|
|
1475
|
+
_topology.init(this._getSwarmController());
|
|
1476
|
+
this._swarmMessenger = new SwarmMessenger({
|
|
1477
|
+
sendMessage: async (msg) => await this._messenger.sendMessage(msg),
|
|
1478
|
+
onSignal: async (msg) => await this.onSignal(msg),
|
|
1479
|
+
onOffer: async (msg) => await this.onOffer(msg),
|
|
1480
|
+
topic: this._topic
|
|
1481
|
+
});
|
|
1482
|
+
log4.trace("dxos.mesh.swarm.constructor", trace2.end({
|
|
1483
|
+
id: this._instanceId
|
|
1484
|
+
}), {
|
|
1485
|
+
F: __dxlog_file4,
|
|
1486
|
+
L: 102,
|
|
1487
|
+
S: this,
|
|
1488
|
+
C: (f, a) => f(...a)
|
|
1489
|
+
});
|
|
1490
|
+
}
|
|
1491
|
+
get connections() {
|
|
1492
|
+
return Array.from(this._peers.values()).map((peer) => peer.connection).filter(isNonNullable);
|
|
1493
|
+
}
|
|
1494
|
+
get ownPeerId() {
|
|
1495
|
+
return PublicKey4.from(this._ownPeer.peerKey);
|
|
1496
|
+
}
|
|
1497
|
+
get ownPeer() {
|
|
1498
|
+
return this._ownPeer;
|
|
1499
|
+
}
|
|
1500
|
+
/**
|
|
1501
|
+
* Custom label assigned to this swarm. Used in devtools to display human-readable names for swarms.
|
|
1502
|
+
*/
|
|
1503
|
+
get label() {
|
|
1504
|
+
return this._label;
|
|
1505
|
+
}
|
|
1506
|
+
get topic() {
|
|
1507
|
+
return this._topic;
|
|
1508
|
+
}
|
|
1509
|
+
async open() {
|
|
1510
|
+
invariant4(!this._listeningHandle, void 0, {
|
|
1511
|
+
F: __dxlog_file4,
|
|
1512
|
+
L: 133,
|
|
1513
|
+
S: this,
|
|
1514
|
+
A: [
|
|
1515
|
+
"!this._listeningHandle",
|
|
1516
|
+
""
|
|
1517
|
+
]
|
|
1518
|
+
});
|
|
1519
|
+
this._listeningHandle = await this._messenger.listen({
|
|
1521
1520
|
peer: this._ownPeer,
|
|
1522
1521
|
payloadType: "dxos.mesh.swarm.SwarmMessage",
|
|
1523
1522
|
onMessage: async (message) => {
|
|
1524
|
-
await this._swarmMessenger.receiveMessage(message).catch((err) =>
|
|
1523
|
+
await this._swarmMessenger.receiveMessage(message).catch((err) => log4.info("Error while receiving message", {
|
|
1525
1524
|
err
|
|
1526
1525
|
}, {
|
|
1527
|
-
F:
|
|
1526
|
+
F: __dxlog_file4,
|
|
1528
1527
|
L: 141,
|
|
1529
1528
|
S: this,
|
|
1530
1529
|
C: (f, a) => f(...a)
|
|
@@ -1533,8 +1532,8 @@ var Swarm = class {
|
|
|
1533
1532
|
});
|
|
1534
1533
|
}
|
|
1535
1534
|
async destroy() {
|
|
1536
|
-
|
|
1537
|
-
F:
|
|
1535
|
+
log4("destroying...", void 0, {
|
|
1536
|
+
F: __dxlog_file4,
|
|
1538
1537
|
L: 147,
|
|
1539
1538
|
S: this,
|
|
1540
1539
|
C: (f, a) => f(...a)
|
|
@@ -1544,8 +1543,8 @@ var Swarm = class {
|
|
|
1544
1543
|
await this._ctx.dispose();
|
|
1545
1544
|
await this._topology.destroy();
|
|
1546
1545
|
await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key, "swarm destroyed")));
|
|
1547
|
-
|
|
1548
|
-
F:
|
|
1546
|
+
log4("destroyed", void 0, {
|
|
1547
|
+
F: __dxlog_file4,
|
|
1549
1548
|
L: 154,
|
|
1550
1549
|
S: this,
|
|
1551
1550
|
C: (f, a) => f(...a)
|
|
@@ -1553,7 +1552,7 @@ var Swarm = class {
|
|
|
1553
1552
|
}
|
|
1554
1553
|
async setTopology(topology) {
|
|
1555
1554
|
invariant4(!this._ctx.disposed, "Swarm is offline", {
|
|
1556
|
-
F:
|
|
1555
|
+
F: __dxlog_file4,
|
|
1557
1556
|
L: 158,
|
|
1558
1557
|
S: this,
|
|
1559
1558
|
A: [
|
|
@@ -1564,11 +1563,11 @@ var Swarm = class {
|
|
|
1564
1563
|
if (topology === this._topology) {
|
|
1565
1564
|
return;
|
|
1566
1565
|
}
|
|
1567
|
-
|
|
1566
|
+
log4("setting topology", {
|
|
1568
1567
|
previous: getClassName(this._topology),
|
|
1569
1568
|
topology: getClassName(topology)
|
|
1570
1569
|
}, {
|
|
1571
|
-
F:
|
|
1570
|
+
F: __dxlog_file4,
|
|
1572
1571
|
L: 162,
|
|
1573
1572
|
S: this,
|
|
1574
1573
|
C: (f, a) => f(...a)
|
|
@@ -1579,17 +1578,17 @@ var Swarm = class {
|
|
|
1579
1578
|
this._topology.update();
|
|
1580
1579
|
}
|
|
1581
1580
|
async onSwarmEvent(swarmEvent) {
|
|
1582
|
-
|
|
1581
|
+
log4("swarm event", {
|
|
1583
1582
|
swarmEvent
|
|
1584
1583
|
}, {
|
|
1585
|
-
F:
|
|
1584
|
+
F: __dxlog_file4,
|
|
1586
1585
|
L: 175,
|
|
1587
1586
|
S: this,
|
|
1588
1587
|
C: (f, a) => f(...a)
|
|
1589
1588
|
});
|
|
1590
1589
|
if (this._ctx.disposed) {
|
|
1591
|
-
|
|
1592
|
-
F:
|
|
1590
|
+
log4("swarm event ignored for disposed swarm", void 0, {
|
|
1591
|
+
F: __dxlog_file4,
|
|
1593
1592
|
L: 178,
|
|
1594
1593
|
S: this,
|
|
1595
1594
|
C: (f, a) => f(...a)
|
|
@@ -1599,10 +1598,10 @@ var Swarm = class {
|
|
|
1599
1598
|
if (swarmEvent.peerAvailable) {
|
|
1600
1599
|
const peerId = swarmEvent.peerAvailable.peer.peerKey;
|
|
1601
1600
|
if (peerId !== this._ownPeer.peerKey) {
|
|
1602
|
-
|
|
1601
|
+
log4("new peer", {
|
|
1603
1602
|
peerId
|
|
1604
1603
|
}, {
|
|
1605
|
-
F:
|
|
1604
|
+
F: __dxlog_file4,
|
|
1606
1605
|
L: 185,
|
|
1607
1606
|
S: this,
|
|
1608
1607
|
C: (f, a) => f(...a)
|
|
@@ -1615,24 +1614,24 @@ var Swarm = class {
|
|
|
1615
1614
|
if (peer) {
|
|
1616
1615
|
peer.advertizing = false;
|
|
1617
1616
|
if (this._isConnectionEstablishmentInProgress(peer)) {
|
|
1618
|
-
|
|
1619
|
-
F:
|
|
1617
|
+
log4(`destroying peer, state: ${peer.connection?.state}`, void 0, {
|
|
1618
|
+
F: __dxlog_file4,
|
|
1620
1619
|
L: 196,
|
|
1621
1620
|
S: this,
|
|
1622
1621
|
C: (f, a) => f(...a)
|
|
1623
1622
|
});
|
|
1624
|
-
void this._destroyPeer(swarmEvent.peerLeft.peer, "peer left").catch((err) =>
|
|
1625
|
-
F:
|
|
1623
|
+
void this._destroyPeer(swarmEvent.peerLeft.peer, "peer left").catch((err) => log4.catch(err, void 0, {
|
|
1624
|
+
F: __dxlog_file4,
|
|
1626
1625
|
L: 197,
|
|
1627
1626
|
S: this,
|
|
1628
1627
|
C: (f, a) => f(...a)
|
|
1629
1628
|
}));
|
|
1630
1629
|
}
|
|
1631
1630
|
} else {
|
|
1632
|
-
|
|
1631
|
+
log4("received peerLeft but no peer found", {
|
|
1633
1632
|
peer: swarmEvent.peerLeft.peer.peerKey
|
|
1634
1633
|
}, {
|
|
1635
|
-
F:
|
|
1634
|
+
F: __dxlog_file4,
|
|
1636
1635
|
L: 200,
|
|
1637
1636
|
S: this,
|
|
1638
1637
|
C: (f, a) => f(...a)
|
|
@@ -1642,17 +1641,17 @@ var Swarm = class {
|
|
|
1642
1641
|
this._topology.update();
|
|
1643
1642
|
}
|
|
1644
1643
|
async onOffer(message) {
|
|
1645
|
-
|
|
1644
|
+
log4("offer", {
|
|
1646
1645
|
message
|
|
1647
1646
|
}, {
|
|
1648
|
-
F:
|
|
1647
|
+
F: __dxlog_file4,
|
|
1649
1648
|
L: 209,
|
|
1650
1649
|
S: this,
|
|
1651
1650
|
C: (f, a) => f(...a)
|
|
1652
1651
|
});
|
|
1653
1652
|
if (this._ctx.disposed) {
|
|
1654
|
-
|
|
1655
|
-
F:
|
|
1653
|
+
log4("ignored for disposed swarm", void 0, {
|
|
1654
|
+
F: __dxlog_file4,
|
|
1656
1655
|
L: 211,
|
|
1657
1656
|
S: this,
|
|
1658
1657
|
C: (f, a) => f(...a)
|
|
@@ -1662,7 +1661,7 @@ var Swarm = class {
|
|
|
1662
1661
|
};
|
|
1663
1662
|
}
|
|
1664
1663
|
invariant4(message.author, void 0, {
|
|
1665
|
-
F:
|
|
1664
|
+
F: __dxlog_file4,
|
|
1666
1665
|
L: 216,
|
|
1667
1666
|
S: this,
|
|
1668
1667
|
A: [
|
|
@@ -1671,10 +1670,10 @@ var Swarm = class {
|
|
|
1671
1670
|
]
|
|
1672
1671
|
});
|
|
1673
1672
|
if (message.recipient.peerKey !== this._ownPeer.peerKey) {
|
|
1674
|
-
|
|
1673
|
+
log4("rejecting offer with incorrect peerId", {
|
|
1675
1674
|
message
|
|
1676
1675
|
}, {
|
|
1677
|
-
F:
|
|
1676
|
+
F: __dxlog_file4,
|
|
1678
1677
|
L: 218,
|
|
1679
1678
|
S: this,
|
|
1680
1679
|
C: (f, a) => f(...a)
|
|
@@ -1684,10 +1683,10 @@ var Swarm = class {
|
|
|
1684
1683
|
};
|
|
1685
1684
|
}
|
|
1686
1685
|
if (!message.topic?.equals(this._topic)) {
|
|
1687
|
-
|
|
1686
|
+
log4("rejecting offer with incorrect topic", {
|
|
1688
1687
|
message
|
|
1689
1688
|
}, {
|
|
1690
|
-
F:
|
|
1689
|
+
F: __dxlog_file4,
|
|
1691
1690
|
L: 222,
|
|
1692
1691
|
S: this,
|
|
1693
1692
|
C: (f, a) => f(...a)
|
|
@@ -1712,17 +1711,17 @@ var Swarm = class {
|
|
|
1712
1711
|
return peer;
|
|
1713
1712
|
}
|
|
1714
1713
|
async onSignal(message) {
|
|
1715
|
-
|
|
1714
|
+
log4("signal", {
|
|
1716
1715
|
message
|
|
1717
1716
|
}, {
|
|
1718
|
-
F:
|
|
1717
|
+
F: __dxlog_file4,
|
|
1719
1718
|
L: 247,
|
|
1720
1719
|
S: this,
|
|
1721
1720
|
C: (f, a) => f(...a)
|
|
1722
1721
|
});
|
|
1723
1722
|
if (this._ctx.disposed) {
|
|
1724
|
-
|
|
1725
|
-
F:
|
|
1723
|
+
log4.info("ignored for offline swarm", void 0, {
|
|
1724
|
+
F: __dxlog_file4,
|
|
1726
1725
|
L: 249,
|
|
1727
1726
|
S: this,
|
|
1728
1727
|
C: (f, a) => f(...a)
|
|
@@ -1730,7 +1729,7 @@ var Swarm = class {
|
|
|
1730
1729
|
return;
|
|
1731
1730
|
}
|
|
1732
1731
|
invariant4(message.recipient.peerKey === this._ownPeer.peerKey, `Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`, {
|
|
1733
|
-
F:
|
|
1732
|
+
F: __dxlog_file4,
|
|
1734
1733
|
L: 252,
|
|
1735
1734
|
S: this,
|
|
1736
1735
|
A: [
|
|
@@ -1739,7 +1738,7 @@ var Swarm = class {
|
|
|
1739
1738
|
]
|
|
1740
1739
|
});
|
|
1741
1740
|
invariant4(message.topic?.equals(this._topic), void 0, {
|
|
1742
|
-
F:
|
|
1741
|
+
F: __dxlog_file4,
|
|
1743
1742
|
L: 256,
|
|
1744
1743
|
S: this,
|
|
1745
1744
|
A: [
|
|
@@ -1748,7 +1747,7 @@ var Swarm = class {
|
|
|
1748
1747
|
]
|
|
1749
1748
|
});
|
|
1750
1749
|
invariant4(message.author, void 0, {
|
|
1751
|
-
F:
|
|
1750
|
+
F: __dxlog_file4,
|
|
1752
1751
|
L: 257,
|
|
1753
1752
|
S: this,
|
|
1754
1753
|
A: [
|
|
@@ -1769,13 +1768,13 @@ var Swarm = class {
|
|
|
1769
1768
|
// For debug purposes
|
|
1770
1769
|
async goOnline() {
|
|
1771
1770
|
this._ctx = new Context4(void 0, {
|
|
1772
|
-
F:
|
|
1771
|
+
F: __dxlog_file4,
|
|
1773
1772
|
L: 273
|
|
1774
1773
|
});
|
|
1775
1774
|
}
|
|
1776
1775
|
_getOrCreatePeer(peerInfo) {
|
|
1777
1776
|
invariant4(peerInfo.peerKey, "PeerInfo.peerKey is required", {
|
|
1778
|
-
F:
|
|
1777
|
+
F: __dxlog_file4,
|
|
1779
1778
|
L: 277,
|
|
1780
1779
|
S: this,
|
|
1781
1780
|
A: [
|
|
@@ -1794,8 +1793,8 @@ var Swarm = class {
|
|
|
1794
1793
|
},
|
|
1795
1794
|
onDisconnected: async () => {
|
|
1796
1795
|
if (this._isUnregistered(peer)) {
|
|
1797
|
-
|
|
1798
|
-
F:
|
|
1796
|
+
log4.verbose("ignored onDisconnected for unregistered peer", void 0, {
|
|
1797
|
+
F: __dxlog_file4,
|
|
1799
1798
|
L: 297,
|
|
1800
1799
|
S: this,
|
|
1801
1800
|
C: (f, a) => f(...a)
|
|
@@ -1810,10 +1809,10 @@ var Swarm = class {
|
|
|
1810
1809
|
},
|
|
1811
1810
|
onRejected: () => {
|
|
1812
1811
|
if (!this._isUnregistered(peer)) {
|
|
1813
|
-
|
|
1812
|
+
log4("peer rejected connection", {
|
|
1814
1813
|
peerInfo
|
|
1815
1814
|
}, {
|
|
1816
|
-
F:
|
|
1815
|
+
F: __dxlog_file4,
|
|
1817
1816
|
L: 311,
|
|
1818
1817
|
S: this,
|
|
1819
1818
|
C: (f, a) => f(...a)
|
|
@@ -1836,18 +1835,18 @@ var Swarm = class {
|
|
|
1836
1835
|
return peer;
|
|
1837
1836
|
}
|
|
1838
1837
|
async _destroyPeer(peerInfo, reason) {
|
|
1839
|
-
|
|
1838
|
+
log4("destroy peer", {
|
|
1840
1839
|
peerKey: peerInfo.peerKey,
|
|
1841
1840
|
reason
|
|
1842
1841
|
}, {
|
|
1843
|
-
F:
|
|
1842
|
+
F: __dxlog_file4,
|
|
1844
1843
|
L: 333,
|
|
1845
1844
|
S: this,
|
|
1846
1845
|
C: (f, a) => f(...a)
|
|
1847
1846
|
});
|
|
1848
1847
|
const peer = this._peers.get(peerInfo);
|
|
1849
1848
|
invariant4(peer, void 0, {
|
|
1850
|
-
F:
|
|
1849
|
+
F: __dxlog_file4,
|
|
1851
1850
|
L: 335,
|
|
1852
1851
|
S: this,
|
|
1853
1852
|
A: [
|
|
@@ -1876,8 +1875,8 @@ var Swarm = class {
|
|
|
1876
1875
|
peerKey: peer.toHex()
|
|
1877
1876
|
});
|
|
1878
1877
|
} catch (err) {
|
|
1879
|
-
|
|
1880
|
-
F:
|
|
1878
|
+
log4("initiation error", err, {
|
|
1879
|
+
F: __dxlog_file4,
|
|
1881
1880
|
L: 362,
|
|
1882
1881
|
S: this,
|
|
1883
1882
|
C: (f, a) => f(...a)
|
|
@@ -1905,10 +1904,10 @@ var Swarm = class {
|
|
|
1905
1904
|
const ctx = this._ctx;
|
|
1906
1905
|
const peer = this._getOrCreatePeer(remotePeer);
|
|
1907
1906
|
if (remotePeer.peerKey < this._ownPeer.peerKey) {
|
|
1908
|
-
|
|
1907
|
+
log4("initiation delay", {
|
|
1909
1908
|
remotePeer
|
|
1910
1909
|
}, {
|
|
1911
|
-
F:
|
|
1910
|
+
F: __dxlog_file4,
|
|
1912
1911
|
L: 390,
|
|
1913
1912
|
S: this,
|
|
1914
1913
|
C: (f, a) => f(...a)
|
|
@@ -1924,20 +1923,20 @@ var Swarm = class {
|
|
|
1924
1923
|
if (peer.connection) {
|
|
1925
1924
|
return;
|
|
1926
1925
|
}
|
|
1927
|
-
|
|
1926
|
+
log4("initiating connection...", {
|
|
1928
1927
|
remotePeer
|
|
1929
1928
|
}, {
|
|
1930
|
-
F:
|
|
1929
|
+
F: __dxlog_file4,
|
|
1931
1930
|
L: 406,
|
|
1932
1931
|
S: this,
|
|
1933
1932
|
C: (f, a) => f(...a)
|
|
1934
1933
|
});
|
|
1935
1934
|
await peer.initiateConnection();
|
|
1936
1935
|
this._topology.update();
|
|
1937
|
-
|
|
1936
|
+
log4("initiated", {
|
|
1938
1937
|
remotePeer
|
|
1939
1938
|
}, {
|
|
1940
|
-
F:
|
|
1939
|
+
F: __dxlog_file4,
|
|
1941
1940
|
L: 409,
|
|
1942
1941
|
S: this,
|
|
1943
1942
|
C: (f, a) => f(...a)
|
|
@@ -1963,83 +1962,6 @@ var Swarm = class {
|
|
|
1963
1962
|
_isUnregistered(peer) {
|
|
1964
1963
|
return !peer || this._peers.get(peer.remoteInfo) !== peer;
|
|
1965
1964
|
}
|
|
1966
|
-
// TODO(burdon): Swarm => Peer.create/destroy =< Connection.open/close
|
|
1967
|
-
// TODO(burdon): Pass in object.
|
|
1968
|
-
constructor(_topic, _ownPeer, _topology, _protocolProvider, _messenger, _transportFactory, _label, _connectionLimiter, _initiationDelay = INITIATION_DELAY) {
|
|
1969
|
-
_define_property4(this, "_topic", void 0);
|
|
1970
|
-
_define_property4(this, "_ownPeer", void 0);
|
|
1971
|
-
_define_property4(this, "_topology", void 0);
|
|
1972
|
-
_define_property4(this, "_protocolProvider", void 0);
|
|
1973
|
-
_define_property4(this, "_messenger", void 0);
|
|
1974
|
-
_define_property4(this, "_transportFactory", void 0);
|
|
1975
|
-
_define_property4(this, "_label", void 0);
|
|
1976
|
-
_define_property4(this, "_connectionLimiter", void 0);
|
|
1977
|
-
_define_property4(this, "_initiationDelay", void 0);
|
|
1978
|
-
_define_property4(this, "_swarmMessenger", void 0);
|
|
1979
|
-
_define_property4(this, "_ctx", void 0);
|
|
1980
|
-
_define_property4(this, "_listeningHandle", void 0);
|
|
1981
|
-
_define_property4(this, "_peers", void 0);
|
|
1982
|
-
_define_property4(this, "_instanceId", void 0);
|
|
1983
|
-
_define_property4(this, "connectionAdded", void 0);
|
|
1984
|
-
_define_property4(this, "disconnected", void 0);
|
|
1985
|
-
_define_property4(this, "connected", void 0);
|
|
1986
|
-
_define_property4(this, "errors", void 0);
|
|
1987
|
-
this._topic = _topic;
|
|
1988
|
-
this._ownPeer = _ownPeer;
|
|
1989
|
-
this._topology = _topology;
|
|
1990
|
-
this._protocolProvider = _protocolProvider;
|
|
1991
|
-
this._messenger = _messenger;
|
|
1992
|
-
this._transportFactory = _transportFactory;
|
|
1993
|
-
this._label = _label;
|
|
1994
|
-
this._connectionLimiter = _connectionLimiter;
|
|
1995
|
-
this._initiationDelay = _initiationDelay;
|
|
1996
|
-
this._ctx = new Context4(void 0, {
|
|
1997
|
-
F: __dxlog_file5,
|
|
1998
|
-
L: 39
|
|
1999
|
-
});
|
|
2000
|
-
this._listeningHandle = void 0;
|
|
2001
|
-
this._peers = new ComplexMap2(PeerInfoHash);
|
|
2002
|
-
this._instanceId = PublicKey4.random().toHex();
|
|
2003
|
-
this.connectionAdded = new Event3();
|
|
2004
|
-
this.disconnected = new Event3();
|
|
2005
|
-
this.connected = new Event3();
|
|
2006
|
-
this.errors = new ErrorStream2();
|
|
2007
|
-
log5.trace("dxos.mesh.swarm.constructor", trace2.begin({
|
|
2008
|
-
id: this._instanceId,
|
|
2009
|
-
data: {
|
|
2010
|
-
topic: this._topic.toHex(),
|
|
2011
|
-
peer: this._ownPeer
|
|
2012
|
-
}
|
|
2013
|
-
}), {
|
|
2014
|
-
F: __dxlog_file5,
|
|
2015
|
-
L: 89,
|
|
2016
|
-
S: this,
|
|
2017
|
-
C: (f, a) => f(...a)
|
|
2018
|
-
});
|
|
2019
|
-
log5("creating swarm", {
|
|
2020
|
-
peerId: _ownPeer
|
|
2021
|
-
}, {
|
|
2022
|
-
F: __dxlog_file5,
|
|
2023
|
-
L: 93,
|
|
2024
|
-
S: this,
|
|
2025
|
-
C: (f, a) => f(...a)
|
|
2026
|
-
});
|
|
2027
|
-
_topology.init(this._getSwarmController());
|
|
2028
|
-
this._swarmMessenger = new SwarmMessenger({
|
|
2029
|
-
sendMessage: async (msg) => await this._messenger.sendMessage(msg),
|
|
2030
|
-
onSignal: async (msg) => await this.onSignal(msg),
|
|
2031
|
-
onOffer: async (msg) => await this.onOffer(msg),
|
|
2032
|
-
topic: this._topic
|
|
2033
|
-
});
|
|
2034
|
-
log5.trace("dxos.mesh.swarm.constructor", trace2.end({
|
|
2035
|
-
id: this._instanceId
|
|
2036
|
-
}), {
|
|
2037
|
-
F: __dxlog_file5,
|
|
2038
|
-
L: 102,
|
|
2039
|
-
S: this,
|
|
2040
|
-
C: (f, a) => f(...a)
|
|
2041
|
-
});
|
|
2042
|
-
}
|
|
2043
1965
|
};
|
|
2044
1966
|
_ts_decorate3([
|
|
2045
1967
|
logInfo2
|
|
@@ -2066,30 +1988,37 @@ _ts_decorate3([
|
|
|
2066
1988
|
// src/swarm/swarm-mapper.ts
|
|
2067
1989
|
import { Event as Event4, SubscriptionList } from "@dxos/async";
|
|
2068
1990
|
import { PublicKey as PublicKey5 } from "@dxos/keys";
|
|
2069
|
-
import { log as
|
|
1991
|
+
import { log as log5 } from "@dxos/log";
|
|
2070
1992
|
import { PeerInfoHash as PeerInfoHash2 } from "@dxos/messaging";
|
|
2071
1993
|
import { ComplexMap as ComplexMap3 } from "@dxos/util";
|
|
2072
|
-
|
|
2073
|
-
if (key in obj) {
|
|
2074
|
-
Object.defineProperty(obj, key, {
|
|
2075
|
-
value,
|
|
2076
|
-
enumerable: true,
|
|
2077
|
-
configurable: true,
|
|
2078
|
-
writable: true
|
|
2079
|
-
});
|
|
2080
|
-
} else {
|
|
2081
|
-
obj[key] = value;
|
|
2082
|
-
}
|
|
2083
|
-
return obj;
|
|
2084
|
-
}
|
|
2085
|
-
var __dxlog_file6 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
|
|
1994
|
+
var __dxlog_file5 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
|
|
2086
1995
|
var SwarmMapper = class {
|
|
1996
|
+
_swarm;
|
|
1997
|
+
_subscriptions = new SubscriptionList();
|
|
1998
|
+
_connectionSubscriptions = new ComplexMap3(PeerInfoHash2);
|
|
1999
|
+
_peers = new ComplexMap3(PeerInfoHash2);
|
|
2000
|
+
mapUpdated = new Event4();
|
|
2087
2001
|
get peers() {
|
|
2088
2002
|
return Array.from(this._peers.values());
|
|
2089
2003
|
}
|
|
2004
|
+
constructor(_swarm) {
|
|
2005
|
+
this._swarm = _swarm;
|
|
2006
|
+
this._subscriptions.add(_swarm.connectionAdded.on((connection) => {
|
|
2007
|
+
this._update();
|
|
2008
|
+
this._connectionSubscriptions.set(connection.remoteInfo, connection.stateChanged.on(() => {
|
|
2009
|
+
this._update();
|
|
2010
|
+
}));
|
|
2011
|
+
}));
|
|
2012
|
+
this._subscriptions.add(_swarm.disconnected.on((peerId) => {
|
|
2013
|
+
this._connectionSubscriptions.get(peerId)?.();
|
|
2014
|
+
this._connectionSubscriptions.delete(peerId);
|
|
2015
|
+
this._update();
|
|
2016
|
+
}));
|
|
2017
|
+
this._update();
|
|
2018
|
+
}
|
|
2090
2019
|
_update() {
|
|
2091
|
-
|
|
2092
|
-
F:
|
|
2020
|
+
log5("updating swarm", void 0, {
|
|
2021
|
+
F: __dxlog_file5,
|
|
2093
2022
|
L: 71,
|
|
2094
2023
|
S: this,
|
|
2095
2024
|
C: (f, a) => f(...a)
|
|
@@ -2109,11 +2038,11 @@ var SwarmMapper = class {
|
|
|
2109
2038
|
]
|
|
2110
2039
|
});
|
|
2111
2040
|
}
|
|
2112
|
-
|
|
2041
|
+
log5("graph changed", {
|
|
2113
2042
|
directConnections: this._swarm.connections.length,
|
|
2114
2043
|
totalPeersInSwarm: this._peers.size
|
|
2115
2044
|
}, {
|
|
2116
|
-
F:
|
|
2045
|
+
F: __dxlog_file5,
|
|
2117
2046
|
L: 112,
|
|
2118
2047
|
S: this,
|
|
2119
2048
|
C: (f, a) => f(...a)
|
|
@@ -2126,30 +2055,6 @@ var SwarmMapper = class {
|
|
|
2126
2055
|
this._connectionSubscriptions.clear();
|
|
2127
2056
|
this._subscriptions.clear();
|
|
2128
2057
|
}
|
|
2129
|
-
constructor(_swarm) {
|
|
2130
|
-
_define_property5(this, "_swarm", void 0);
|
|
2131
|
-
_define_property5(this, "_subscriptions", void 0);
|
|
2132
|
-
_define_property5(this, "_connectionSubscriptions", void 0);
|
|
2133
|
-
_define_property5(this, "_peers", void 0);
|
|
2134
|
-
_define_property5(this, "mapUpdated", void 0);
|
|
2135
|
-
this._swarm = _swarm;
|
|
2136
|
-
this._subscriptions = new SubscriptionList();
|
|
2137
|
-
this._connectionSubscriptions = new ComplexMap3(PeerInfoHash2);
|
|
2138
|
-
this._peers = new ComplexMap3(PeerInfoHash2);
|
|
2139
|
-
this.mapUpdated = new Event4();
|
|
2140
|
-
this._subscriptions.add(_swarm.connectionAdded.on((connection) => {
|
|
2141
|
-
this._update();
|
|
2142
|
-
this._connectionSubscriptions.set(connection.remoteInfo, connection.stateChanged.on(() => {
|
|
2143
|
-
this._update();
|
|
2144
|
-
}));
|
|
2145
|
-
}));
|
|
2146
|
-
this._subscriptions.add(_swarm.disconnected.on((peerId) => {
|
|
2147
|
-
this._connectionSubscriptions.get(peerId)?.();
|
|
2148
|
-
this._connectionSubscriptions.delete(peerId);
|
|
2149
|
-
this._update();
|
|
2150
|
-
}));
|
|
2151
|
-
this._update();
|
|
2152
|
-
}
|
|
2153
2058
|
};
|
|
2154
2059
|
|
|
2155
2060
|
// src/swarm/connection-limiter.ts
|
|
@@ -2157,31 +2062,35 @@ import { DeferredTask as DeferredTask2 } from "@dxos/async";
|
|
|
2157
2062
|
import { Context as Context5 } from "@dxos/context";
|
|
2158
2063
|
import { invariant as invariant5 } from "@dxos/invariant";
|
|
2159
2064
|
import { PublicKey as PublicKey6 } from "@dxos/keys";
|
|
2160
|
-
import { log as
|
|
2065
|
+
import { log as log6 } from "@dxos/log";
|
|
2161
2066
|
import { CancelledError as CancelledError3 } from "@dxos/protocols";
|
|
2162
2067
|
import { ComplexMap as ComplexMap4 } from "@dxos/util";
|
|
2163
|
-
|
|
2164
|
-
if (key in obj) {
|
|
2165
|
-
Object.defineProperty(obj, key, {
|
|
2166
|
-
value,
|
|
2167
|
-
enumerable: true,
|
|
2168
|
-
configurable: true,
|
|
2169
|
-
writable: true
|
|
2170
|
-
});
|
|
2171
|
-
} else {
|
|
2172
|
-
obj[key] = value;
|
|
2173
|
-
}
|
|
2174
|
-
return obj;
|
|
2175
|
-
}
|
|
2176
|
-
var __dxlog_file7 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
|
|
2068
|
+
var __dxlog_file6 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
|
|
2177
2069
|
var MAX_CONCURRENT_INITIATING_CONNECTIONS = 50;
|
|
2178
2070
|
var ConnectionLimiter = class {
|
|
2071
|
+
_ctx = new Context5(void 0, {
|
|
2072
|
+
F: __dxlog_file6,
|
|
2073
|
+
L: 23
|
|
2074
|
+
});
|
|
2075
|
+
_maxConcurrentInitConnections;
|
|
2076
|
+
/**
|
|
2077
|
+
* Queue of promises to resolve when initiating connections amount is below the limit.
|
|
2078
|
+
*/
|
|
2079
|
+
_waitingPromises = new ComplexMap4(PublicKey6.hash);
|
|
2080
|
+
resolveWaitingPromises = new DeferredTask2(this._ctx, async () => {
|
|
2081
|
+
Array.from(this._waitingPromises.values()).slice(0, this._maxConcurrentInitConnections).forEach(({ resolve }) => {
|
|
2082
|
+
resolve();
|
|
2083
|
+
});
|
|
2084
|
+
});
|
|
2085
|
+
constructor({ maxConcurrentInitConnections = MAX_CONCURRENT_INITIATING_CONNECTIONS } = {}) {
|
|
2086
|
+
this._maxConcurrentInitConnections = maxConcurrentInitConnections;
|
|
2087
|
+
}
|
|
2179
2088
|
/**
|
|
2180
2089
|
* @returns Promise that resolves in queue when connections amount with 'CONNECTING' state is below the limit.
|
|
2181
2090
|
*/
|
|
2182
2091
|
async connecting(sessionId) {
|
|
2183
2092
|
invariant5(!this._waitingPromises.has(sessionId), "Peer is already waiting for connection", {
|
|
2184
|
-
F:
|
|
2093
|
+
F: __dxlog_file6,
|
|
2185
2094
|
L: 48,
|
|
2186
2095
|
S: this,
|
|
2187
2096
|
A: [
|
|
@@ -2189,10 +2098,10 @@ var ConnectionLimiter = class {
|
|
|
2189
2098
|
"'Peer is already waiting for connection'"
|
|
2190
2099
|
]
|
|
2191
2100
|
});
|
|
2192
|
-
|
|
2101
|
+
log6("waiting", {
|
|
2193
2102
|
sessionId
|
|
2194
2103
|
}, {
|
|
2195
|
-
F:
|
|
2104
|
+
F: __dxlog_file6,
|
|
2196
2105
|
L: 49,
|
|
2197
2106
|
S: this,
|
|
2198
2107
|
C: (f, a) => f(...a)
|
|
@@ -2204,10 +2113,10 @@ var ConnectionLimiter = class {
|
|
|
2204
2113
|
});
|
|
2205
2114
|
this.resolveWaitingPromises.schedule();
|
|
2206
2115
|
});
|
|
2207
|
-
|
|
2116
|
+
log6("allow", {
|
|
2208
2117
|
sessionId
|
|
2209
2118
|
}, {
|
|
2210
|
-
F:
|
|
2119
|
+
F: __dxlog_file6,
|
|
2211
2120
|
L: 57,
|
|
2212
2121
|
S: this,
|
|
2213
2122
|
C: (f, a) => f(...a)
|
|
@@ -2217,10 +2126,10 @@ var ConnectionLimiter = class {
|
|
|
2217
2126
|
* Rejects promise returned by `connecting` method.
|
|
2218
2127
|
*/
|
|
2219
2128
|
doneConnecting(sessionId) {
|
|
2220
|
-
|
|
2129
|
+
log6("done", {
|
|
2221
2130
|
sessionId
|
|
2222
2131
|
}, {
|
|
2223
|
-
F:
|
|
2132
|
+
F: __dxlog_file6,
|
|
2224
2133
|
L: 64,
|
|
2225
2134
|
S: this,
|
|
2226
2135
|
C: (f, a) => f(...a)
|
|
@@ -2232,20 +2141,6 @@ var ConnectionLimiter = class {
|
|
|
2232
2141
|
this._waitingPromises.delete(sessionId);
|
|
2233
2142
|
this.resolveWaitingPromises.schedule();
|
|
2234
2143
|
}
|
|
2235
|
-
constructor({ maxConcurrentInitConnections = MAX_CONCURRENT_INITIATING_CONNECTIONS } = {}) {
|
|
2236
|
-
_define_property6(this, "_ctx", new Context5(void 0, {
|
|
2237
|
-
F: __dxlog_file7,
|
|
2238
|
-
L: 23
|
|
2239
|
-
}));
|
|
2240
|
-
_define_property6(this, "_maxConcurrentInitConnections", void 0);
|
|
2241
|
-
_define_property6(this, "_waitingPromises", new ComplexMap4(PublicKey6.hash));
|
|
2242
|
-
_define_property6(this, "resolveWaitingPromises", new DeferredTask2(this._ctx, async () => {
|
|
2243
|
-
Array.from(this._waitingPromises.values()).slice(0, this._maxConcurrentInitConnections).forEach(({ resolve }) => {
|
|
2244
|
-
resolve();
|
|
2245
|
-
});
|
|
2246
|
-
}));
|
|
2247
|
-
this._maxConcurrentInitConnections = maxConcurrentInitConnections;
|
|
2248
|
-
}
|
|
2249
2144
|
};
|
|
2250
2145
|
|
|
2251
2146
|
// src/connection-log.ts
|
|
@@ -2253,19 +2148,6 @@ import { Event as Event5 } from "@dxos/async";
|
|
|
2253
2148
|
import { raise } from "@dxos/debug";
|
|
2254
2149
|
import { PublicKey as PublicKey7 } from "@dxos/keys";
|
|
2255
2150
|
import { ComplexMap as ComplexMap5 } from "@dxos/util";
|
|
2256
|
-
function _define_property7(obj, key, value) {
|
|
2257
|
-
if (key in obj) {
|
|
2258
|
-
Object.defineProperty(obj, key, {
|
|
2259
|
-
value,
|
|
2260
|
-
enumerable: true,
|
|
2261
|
-
configurable: true,
|
|
2262
|
-
writable: true
|
|
2263
|
-
});
|
|
2264
|
-
} else {
|
|
2265
|
-
obj[key] = value;
|
|
2266
|
-
}
|
|
2267
|
-
return obj;
|
|
2268
|
-
}
|
|
2269
2151
|
var CONNECTION_GC_THRESHOLD = 1e3 * 60 * 15;
|
|
2270
2152
|
var EventType = /* @__PURE__ */ (function(EventType2) {
|
|
2271
2153
|
EventType2["CONNECTION_STATE_CHANGED"] = "CONNECTION_STATE_CHANGED";
|
|
@@ -2276,6 +2158,11 @@ var EventType = /* @__PURE__ */ (function(EventType2) {
|
|
|
2276
2158
|
return EventType2;
|
|
2277
2159
|
})({});
|
|
2278
2160
|
var ConnectionLog = class {
|
|
2161
|
+
/**
|
|
2162
|
+
* SwarmId => info
|
|
2163
|
+
*/
|
|
2164
|
+
_swarms = new ComplexMap5(PublicKey7.hash);
|
|
2165
|
+
update = new Event5();
|
|
2279
2166
|
getSwarmInfo(swarmId) {
|
|
2280
2167
|
return this._swarms.get(swarmId) ?? raise(new Error(`Swarm not found: ${swarmId}`));
|
|
2281
2168
|
}
|
|
@@ -2339,10 +2226,6 @@ var ConnectionLog = class {
|
|
|
2339
2226
|
this.getSwarmInfo(PublicKey7.from(swarm._instanceId)).isActive = false;
|
|
2340
2227
|
this.update.emit();
|
|
2341
2228
|
}
|
|
2342
|
-
constructor() {
|
|
2343
|
-
_define_property7(this, "_swarms", new ComplexMap5(PublicKey7.hash));
|
|
2344
|
-
_define_property7(this, "update", new Event5());
|
|
2345
|
-
}
|
|
2346
2229
|
};
|
|
2347
2230
|
var gcSwarm = (swarm) => {
|
|
2348
2231
|
swarm.connections = swarm.connections?.filter((connection) => {
|
|
@@ -2354,32 +2237,52 @@ var gcSwarm = (swarm) => {
|
|
|
2354
2237
|
import { Event as Event6, synchronized as synchronized4 } from "@dxos/async";
|
|
2355
2238
|
import { invariant as invariant6 } from "@dxos/invariant";
|
|
2356
2239
|
import { PublicKey as PublicKey8 } from "@dxos/keys";
|
|
2357
|
-
import { log as
|
|
2240
|
+
import { log as log7 } from "@dxos/log";
|
|
2358
2241
|
import { Messenger } from "@dxos/messaging";
|
|
2359
2242
|
import { trace as trace3 } from "@dxos/protocols";
|
|
2360
2243
|
import { ConnectionState as ConnectionState2 } from "@dxos/protocols/proto/dxos/client/services";
|
|
2361
2244
|
import { ComplexMap as ComplexMap6 } from "@dxos/util";
|
|
2362
|
-
function _define_property8(obj, key, value) {
|
|
2363
|
-
if (key in obj) {
|
|
2364
|
-
Object.defineProperty(obj, key, {
|
|
2365
|
-
value,
|
|
2366
|
-
enumerable: true,
|
|
2367
|
-
configurable: true,
|
|
2368
|
-
writable: true
|
|
2369
|
-
});
|
|
2370
|
-
} else {
|
|
2371
|
-
obj[key] = value;
|
|
2372
|
-
}
|
|
2373
|
-
return obj;
|
|
2374
|
-
}
|
|
2375
2245
|
function _ts_decorate4(decorators, target, key, desc) {
|
|
2376
2246
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2377
2247
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2378
2248
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2379
2249
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2380
2250
|
}
|
|
2381
|
-
var
|
|
2251
|
+
var __dxlog_file7 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts";
|
|
2382
2252
|
var SwarmNetworkManager = class {
|
|
2253
|
+
/**
|
|
2254
|
+
* @internal
|
|
2255
|
+
*/
|
|
2256
|
+
_swarms = new ComplexMap6(PublicKey8.hash);
|
|
2257
|
+
_mappers = new ComplexMap6(PublicKey8.hash);
|
|
2258
|
+
_transportFactory;
|
|
2259
|
+
_signalManager;
|
|
2260
|
+
_messenger;
|
|
2261
|
+
_signalConnection;
|
|
2262
|
+
_connectionLimiter;
|
|
2263
|
+
_connectionLog;
|
|
2264
|
+
_instanceId = PublicKey8.random().toHex();
|
|
2265
|
+
_peerInfo = void 0;
|
|
2266
|
+
_connectionState = ConnectionState2.ONLINE;
|
|
2267
|
+
connectionStateChanged = new Event6();
|
|
2268
|
+
topicsUpdated = new Event6();
|
|
2269
|
+
constructor({ transportFactory, signalManager, enableDevtoolsLogging, peerInfo }) {
|
|
2270
|
+
this._transportFactory = transportFactory;
|
|
2271
|
+
this._signalManager = signalManager;
|
|
2272
|
+
this._signalManager.swarmEvent.on((event) => this._swarms.get(event.topic)?.onSwarmEvent(event));
|
|
2273
|
+
this._messenger = new Messenger({
|
|
2274
|
+
signalManager: this._signalManager
|
|
2275
|
+
});
|
|
2276
|
+
this._signalConnection = {
|
|
2277
|
+
join: (opts) => this._signalManager.join(opts),
|
|
2278
|
+
leave: (opts) => this._signalManager.leave(opts)
|
|
2279
|
+
};
|
|
2280
|
+
this._peerInfo = peerInfo;
|
|
2281
|
+
this._connectionLimiter = new ConnectionLimiter();
|
|
2282
|
+
if (enableDevtoolsLogging) {
|
|
2283
|
+
this._connectionLog = new ConnectionLog();
|
|
2284
|
+
}
|
|
2285
|
+
}
|
|
2383
2286
|
// TODO(burdon): Remove access (Devtools only).
|
|
2384
2287
|
get connectionLog() {
|
|
2385
2288
|
return this._connectionLog;
|
|
@@ -2401,20 +2304,20 @@ var SwarmNetworkManager = class {
|
|
|
2401
2304
|
this._peerInfo = peerInfo;
|
|
2402
2305
|
}
|
|
2403
2306
|
async open() {
|
|
2404
|
-
|
|
2307
|
+
log7.trace("dxos.mesh.network-manager.open", trace3.begin({
|
|
2405
2308
|
id: this._instanceId
|
|
2406
2309
|
}), {
|
|
2407
|
-
F:
|
|
2310
|
+
F: __dxlog_file7,
|
|
2408
2311
|
L: 133,
|
|
2409
2312
|
S: this,
|
|
2410
2313
|
C: (f, a) => f(...a)
|
|
2411
2314
|
});
|
|
2412
2315
|
await this._messenger.open();
|
|
2413
2316
|
await this._signalManager.open();
|
|
2414
|
-
|
|
2317
|
+
log7.trace("dxos.mesh.network-manager.open", trace3.end({
|
|
2415
2318
|
id: this._instanceId
|
|
2416
2319
|
}), {
|
|
2417
|
-
F:
|
|
2320
|
+
F: __dxlog_file7,
|
|
2418
2321
|
L: 136,
|
|
2419
2322
|
S: this,
|
|
2420
2323
|
C: (f, a) => f(...a)
|
|
@@ -2423,8 +2326,8 @@ var SwarmNetworkManager = class {
|
|
|
2423
2326
|
async close() {
|
|
2424
2327
|
for (const topic of this._swarms.keys()) {
|
|
2425
2328
|
await this.leaveSwarm(topic).catch((err) => {
|
|
2426
|
-
|
|
2427
|
-
F:
|
|
2329
|
+
log7(err, void 0, {
|
|
2330
|
+
F: __dxlog_file7,
|
|
2428
2331
|
L: 142,
|
|
2429
2332
|
S: this,
|
|
2430
2333
|
C: (f, a) => f(...a)
|
|
@@ -2439,7 +2342,7 @@ var SwarmNetworkManager = class {
|
|
|
2439
2342
|
*/
|
|
2440
2343
|
async joinSwarm({ topic, topology, protocolProvider: protocol, label }) {
|
|
2441
2344
|
invariant6(PublicKey8.isPublicKey(topic), void 0, {
|
|
2442
|
-
F:
|
|
2345
|
+
F: __dxlog_file7,
|
|
2443
2346
|
L: 160,
|
|
2444
2347
|
S: this,
|
|
2445
2348
|
A: [
|
|
@@ -2448,7 +2351,7 @@ var SwarmNetworkManager = class {
|
|
|
2448
2351
|
]
|
|
2449
2352
|
});
|
|
2450
2353
|
invariant6(topology, void 0, {
|
|
2451
|
-
F:
|
|
2354
|
+
F: __dxlog_file7,
|
|
2452
2355
|
L: 161,
|
|
2453
2356
|
S: this,
|
|
2454
2357
|
A: [
|
|
@@ -2457,7 +2360,7 @@ var SwarmNetworkManager = class {
|
|
|
2457
2360
|
]
|
|
2458
2361
|
});
|
|
2459
2362
|
invariant6(this._peerInfo, void 0, {
|
|
2460
|
-
F:
|
|
2363
|
+
F: __dxlog_file7,
|
|
2461
2364
|
L: 162,
|
|
2462
2365
|
S: this,
|
|
2463
2366
|
A: [
|
|
@@ -2466,7 +2369,7 @@ var SwarmNetworkManager = class {
|
|
|
2466
2369
|
]
|
|
2467
2370
|
});
|
|
2468
2371
|
invariant6(typeof protocol === "function", void 0, {
|
|
2469
|
-
F:
|
|
2372
|
+
F: __dxlog_file7,
|
|
2470
2373
|
L: 163,
|
|
2471
2374
|
S: this,
|
|
2472
2375
|
A: [
|
|
@@ -2477,22 +2380,22 @@ var SwarmNetworkManager = class {
|
|
|
2477
2380
|
if (this._swarms.has(topic)) {
|
|
2478
2381
|
throw new Error(`Already connected to swarm: ${PublicKey8.from(topic)}`);
|
|
2479
2382
|
}
|
|
2480
|
-
|
|
2383
|
+
log7("joining", {
|
|
2481
2384
|
topic: PublicKey8.from(topic),
|
|
2482
2385
|
peerInfo: this._peerInfo,
|
|
2483
2386
|
topology: topology.toString()
|
|
2484
2387
|
}, {
|
|
2485
|
-
F:
|
|
2388
|
+
F: __dxlog_file7,
|
|
2486
2389
|
L: 168,
|
|
2487
2390
|
S: this,
|
|
2488
2391
|
C: (f, a) => f(...a)
|
|
2489
2392
|
});
|
|
2490
2393
|
const swarm = new Swarm(topic, this._peerInfo, topology, protocol, this._messenger, this._transportFactory, label, this._connectionLimiter);
|
|
2491
2394
|
swarm.errors.handle((error) => {
|
|
2492
|
-
|
|
2395
|
+
log7("swarm error", {
|
|
2493
2396
|
error
|
|
2494
2397
|
}, {
|
|
2495
|
-
F:
|
|
2398
|
+
F: __dxlog_file7,
|
|
2496
2399
|
L: 181,
|
|
2497
2400
|
S: this,
|
|
2498
2401
|
C: (f, a) => f(...a)
|
|
@@ -2504,19 +2407,19 @@ var SwarmNetworkManager = class {
|
|
|
2504
2407
|
this._signalConnection.join({
|
|
2505
2408
|
topic,
|
|
2506
2409
|
peer: this._peerInfo
|
|
2507
|
-
}).catch((error) =>
|
|
2508
|
-
F:
|
|
2410
|
+
}).catch((error) => log7.catch(error, void 0, {
|
|
2411
|
+
F: __dxlog_file7,
|
|
2509
2412
|
L: 190,
|
|
2510
2413
|
S: this,
|
|
2511
2414
|
C: (f, a) => f(...a)
|
|
2512
2415
|
}));
|
|
2513
2416
|
this.topicsUpdated.emit();
|
|
2514
2417
|
this._connectionLog?.joinedSwarm(swarm);
|
|
2515
|
-
|
|
2418
|
+
log7("joined", {
|
|
2516
2419
|
topic: PublicKey8.from(topic),
|
|
2517
2420
|
count: this._swarms.size
|
|
2518
2421
|
}, {
|
|
2519
|
-
F:
|
|
2422
|
+
F: __dxlog_file7,
|
|
2520
2423
|
L: 194,
|
|
2521
2424
|
S: this,
|
|
2522
2425
|
C: (f, a) => f(...a)
|
|
@@ -2532,10 +2435,10 @@ var SwarmNetworkManager = class {
|
|
|
2532
2435
|
if (!this._swarms.has(topic)) {
|
|
2533
2436
|
return;
|
|
2534
2437
|
}
|
|
2535
|
-
|
|
2438
|
+
log7("leaving", {
|
|
2536
2439
|
topic: PublicKey8.from(topic)
|
|
2537
2440
|
}, {
|
|
2538
|
-
F:
|
|
2441
|
+
F: __dxlog_file7,
|
|
2539
2442
|
L: 211,
|
|
2540
2443
|
S: this,
|
|
2541
2444
|
C: (f, a) => f(...a)
|
|
@@ -2552,11 +2455,11 @@ var SwarmNetworkManager = class {
|
|
|
2552
2455
|
await swarm.destroy();
|
|
2553
2456
|
this._swarms.delete(topic);
|
|
2554
2457
|
this.topicsUpdated.emit();
|
|
2555
|
-
|
|
2458
|
+
log7("left", {
|
|
2556
2459
|
topic: PublicKey8.from(topic),
|
|
2557
2460
|
count: this._swarms.size
|
|
2558
2461
|
}, {
|
|
2559
|
-
F:
|
|
2462
|
+
F: __dxlog_file7,
|
|
2560
2463
|
L: 225,
|
|
2561
2464
|
S: this,
|
|
2562
2465
|
C: (f, a) => f(...a)
|
|
@@ -2573,478 +2476,86 @@ var SwarmNetworkManager = class {
|
|
|
2573
2476
|
...this._swarms.values()
|
|
2574
2477
|
].map((swarm) => swarm.goOffline()));
|
|
2575
2478
|
await this._messenger.close();
|
|
2576
|
-
await this._signalManager.close();
|
|
2577
|
-
break;
|
|
2578
|
-
}
|
|
2579
|
-
case ConnectionState2.ONLINE: {
|
|
2580
|
-
this._connectionState = state;
|
|
2581
|
-
this._messenger.open();
|
|
2582
|
-
await Promise.all([
|
|
2583
|
-
...this._swarms.values()
|
|
2584
|
-
].map((swarm) => swarm.goOnline()));
|
|
2585
|
-
await this._signalManager.open();
|
|
2586
|
-
break;
|
|
2587
|
-
}
|
|
2588
|
-
}
|
|
2589
|
-
this.connectionStateChanged.emit(this._connectionState);
|
|
2590
|
-
}
|
|
2591
|
-
constructor({ transportFactory, signalManager, enableDevtoolsLogging, peerInfo }) {
|
|
2592
|
-
_define_property8(this, "_swarms", new ComplexMap6(PublicKey8.hash));
|
|
2593
|
-
_define_property8(this, "_mappers", new ComplexMap6(PublicKey8.hash));
|
|
2594
|
-
_define_property8(this, "_transportFactory", void 0);
|
|
2595
|
-
_define_property8(this, "_signalManager", void 0);
|
|
2596
|
-
_define_property8(this, "_messenger", void 0);
|
|
2597
|
-
_define_property8(this, "_signalConnection", void 0);
|
|
2598
|
-
_define_property8(this, "_connectionLimiter", void 0);
|
|
2599
|
-
_define_property8(this, "_connectionLog", void 0);
|
|
2600
|
-
_define_property8(this, "_instanceId", PublicKey8.random().toHex());
|
|
2601
|
-
_define_property8(this, "_peerInfo", void 0);
|
|
2602
|
-
_define_property8(this, "_connectionState", ConnectionState2.ONLINE);
|
|
2603
|
-
_define_property8(this, "connectionStateChanged", new Event6());
|
|
2604
|
-
_define_property8(this, "topicsUpdated", new Event6());
|
|
2605
|
-
this._transportFactory = transportFactory;
|
|
2606
|
-
this._signalManager = signalManager;
|
|
2607
|
-
this._signalManager.swarmEvent.on((event) => this._swarms.get(event.topic)?.onSwarmEvent(event));
|
|
2608
|
-
this._messenger = new Messenger({
|
|
2609
|
-
signalManager: this._signalManager
|
|
2610
|
-
});
|
|
2611
|
-
this._signalConnection = {
|
|
2612
|
-
join: (opts) => this._signalManager.join(opts),
|
|
2613
|
-
leave: (opts) => this._signalManager.leave(opts)
|
|
2614
|
-
};
|
|
2615
|
-
this._peerInfo = peerInfo;
|
|
2616
|
-
this._connectionLimiter = new ConnectionLimiter();
|
|
2617
|
-
if (enableDevtoolsLogging) {
|
|
2618
|
-
this._connectionLog = new ConnectionLog();
|
|
2619
|
-
}
|
|
2620
|
-
}
|
|
2621
|
-
};
|
|
2622
|
-
_ts_decorate4([
|
|
2623
|
-
synchronized4
|
|
2624
|
-
], SwarmNetworkManager.prototype, "joinSwarm", null);
|
|
2625
|
-
_ts_decorate4([
|
|
2626
|
-
synchronized4
|
|
2627
|
-
], SwarmNetworkManager.prototype, "leaveSwarm", null);
|
|
2628
|
-
|
|
2629
|
-
// src/topology/fully-connected-topology.ts
|
|
2630
|
-
import { invariant as invariant7 } from "@dxos/invariant";
|
|
2631
|
-
function _define_property9(obj, key, value) {
|
|
2632
|
-
if (key in obj) {
|
|
2633
|
-
Object.defineProperty(obj, key, {
|
|
2634
|
-
value,
|
|
2635
|
-
enumerable: true,
|
|
2636
|
-
configurable: true,
|
|
2637
|
-
writable: true
|
|
2638
|
-
});
|
|
2639
|
-
} else {
|
|
2640
|
-
obj[key] = value;
|
|
2641
|
-
}
|
|
2642
|
-
return obj;
|
|
2643
|
-
}
|
|
2644
|
-
var __dxlog_file9 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
|
|
2645
|
-
var FullyConnectedTopology = class {
|
|
2646
|
-
toString() {
|
|
2647
|
-
return "FullyConnectedTopology";
|
|
2648
|
-
}
|
|
2649
|
-
init(controller) {
|
|
2650
|
-
invariant7(!this._controller, "Already initialized", {
|
|
2651
|
-
F: __dxlog_file9,
|
|
2652
|
-
L: 18,
|
|
2653
|
-
S: this,
|
|
2654
|
-
A: [
|
|
2655
|
-
"!this._controller",
|
|
2656
|
-
"'Already initialized'"
|
|
2657
|
-
]
|
|
2658
|
-
});
|
|
2659
|
-
this._controller = controller;
|
|
2660
|
-
}
|
|
2661
|
-
update() {
|
|
2662
|
-
invariant7(this._controller, "Not initialized", {
|
|
2663
|
-
F: __dxlog_file9,
|
|
2664
|
-
L: 23,
|
|
2665
|
-
S: this,
|
|
2666
|
-
A: [
|
|
2667
|
-
"this._controller",
|
|
2668
|
-
"'Not initialized'"
|
|
2669
|
-
]
|
|
2670
|
-
});
|
|
2671
|
-
const { candidates: discovered } = this._controller.getState();
|
|
2672
|
-
for (const peer of discovered) {
|
|
2673
|
-
this._controller.connect(peer);
|
|
2674
|
-
}
|
|
2675
|
-
}
|
|
2676
|
-
async onOffer(peer) {
|
|
2677
|
-
return true;
|
|
2678
|
-
}
|
|
2679
|
-
async destroy() {
|
|
2680
|
-
}
|
|
2681
|
-
constructor() {
|
|
2682
|
-
_define_property9(this, "_controller", void 0);
|
|
2683
|
-
}
|
|
2684
|
-
};
|
|
2685
|
-
|
|
2686
|
-
// src/topology/mmst-topology.ts
|
|
2687
|
-
import { invariant as invariant8 } from "@dxos/invariant";
|
|
2688
|
-
import { log as log9 } from "@dxos/log";
|
|
2689
|
-
function _define_property10(obj, key, value) {
|
|
2690
|
-
if (key in obj) {
|
|
2691
|
-
Object.defineProperty(obj, key, {
|
|
2692
|
-
value,
|
|
2693
|
-
enumerable: true,
|
|
2694
|
-
configurable: true,
|
|
2695
|
-
writable: true
|
|
2696
|
-
});
|
|
2697
|
-
} else {
|
|
2698
|
-
obj[key] = value;
|
|
2699
|
-
}
|
|
2700
|
-
return obj;
|
|
2701
|
-
}
|
|
2702
|
-
var __dxlog_file10 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/topology/mmst-topology.ts";
|
|
2703
|
-
var MIN_UPDATE_INTERVAL = 1e3 * 10;
|
|
2704
|
-
var MAX_CHANGES_PER_UPDATE = 1;
|
|
2705
|
-
var MMSTTopology = class {
|
|
2706
|
-
init(controller) {
|
|
2707
|
-
invariant8(!this._controller, "Already initialized", {
|
|
2708
|
-
F: __dxlog_file10,
|
|
2709
|
-
L: 49,
|
|
2710
|
-
S: this,
|
|
2711
|
-
A: [
|
|
2712
|
-
"!this._controller",
|
|
2713
|
-
"'Already initialized'"
|
|
2714
|
-
]
|
|
2715
|
-
});
|
|
2716
|
-
this._controller = controller;
|
|
2717
|
-
}
|
|
2718
|
-
update() {
|
|
2719
|
-
invariant8(this._controller, "Not initialized", {
|
|
2720
|
-
F: __dxlog_file10,
|
|
2721
|
-
L: 54,
|
|
2722
|
-
S: this,
|
|
2723
|
-
A: [
|
|
2724
|
-
"this._controller",
|
|
2725
|
-
"'Not initialized'"
|
|
2726
|
-
]
|
|
2727
|
-
});
|
|
2728
|
-
const { connected, candidates } = this._controller.getState();
|
|
2729
|
-
if (this._sampleCollected || connected.length > this._maxPeers || candidates.length > 0) {
|
|
2730
|
-
log9("Running the algorithm.", void 0, {
|
|
2731
|
-
F: __dxlog_file10,
|
|
2732
|
-
L: 58,
|
|
2733
|
-
S: this,
|
|
2734
|
-
C: (f, a) => f(...a)
|
|
2735
|
-
});
|
|
2736
|
-
this._sampleCollected = true;
|
|
2737
|
-
this._runAlgorithm();
|
|
2738
|
-
}
|
|
2739
|
-
}
|
|
2740
|
-
forceUpdate() {
|
|
2741
|
-
this._lastAction = /* @__PURE__ */ new Date(0);
|
|
2742
|
-
this.update();
|
|
2743
|
-
}
|
|
2744
|
-
async onOffer(peer) {
|
|
2745
|
-
invariant8(this._controller, "Not initialized", {
|
|
2746
|
-
F: __dxlog_file10,
|
|
2747
|
-
L: 70,
|
|
2748
|
-
S: this,
|
|
2749
|
-
A: [
|
|
2750
|
-
"this._controller",
|
|
2751
|
-
"'Not initialized'"
|
|
2752
|
-
]
|
|
2753
|
-
});
|
|
2754
|
-
const { connected } = this._controller.getState();
|
|
2755
|
-
const accept = connected.length < this._maxPeers;
|
|
2756
|
-
log9(`Offer ${peer} accept=${accept}`, void 0, {
|
|
2757
|
-
F: __dxlog_file10,
|
|
2758
|
-
L: 73,
|
|
2759
|
-
S: this,
|
|
2760
|
-
C: (f, a) => f(...a)
|
|
2761
|
-
});
|
|
2762
|
-
return accept;
|
|
2763
|
-
}
|
|
2764
|
-
async destroy() {
|
|
2765
|
-
}
|
|
2766
|
-
_runAlgorithm() {
|
|
2767
|
-
invariant8(this._controller, "Not initialized", {
|
|
2768
|
-
F: __dxlog_file10,
|
|
2769
|
-
L: 82,
|
|
2770
|
-
S: this,
|
|
2771
|
-
A: [
|
|
2772
|
-
"this._controller",
|
|
2773
|
-
"'Not initialized'"
|
|
2774
|
-
]
|
|
2775
|
-
});
|
|
2776
|
-
const { connected, candidates, ownPeerId } = this._controller.getState();
|
|
2777
|
-
if (connected.length > this._maxPeers) {
|
|
2778
|
-
log9(`disconnect ${connected.length - this._maxPeers} peers.`, void 0, {
|
|
2779
|
-
F: __dxlog_file10,
|
|
2780
|
-
L: 88,
|
|
2781
|
-
S: this,
|
|
2782
|
-
C: (f, a) => f(...a)
|
|
2783
|
-
});
|
|
2784
|
-
const sorted = sortByXorDistance(connected, ownPeerId).reverse().slice(0, this._maxPeers - connected.length);
|
|
2785
|
-
invariant8(sorted.length === 0, void 0, {
|
|
2786
|
-
F: __dxlog_file10,
|
|
2787
|
-
L: 92,
|
|
2788
|
-
S: this,
|
|
2789
|
-
A: [
|
|
2790
|
-
"sorted.length === 0",
|
|
2791
|
-
""
|
|
2792
|
-
]
|
|
2793
|
-
});
|
|
2794
|
-
if (sorted.length > MAX_CHANGES_PER_UPDATE) {
|
|
2795
|
-
log9(`want to disconnect ${sorted.length} peers but limited to ${MAX_CHANGES_PER_UPDATE}`, void 0, {
|
|
2796
|
-
F: __dxlog_file10,
|
|
2797
|
-
L: 95,
|
|
2798
|
-
S: this,
|
|
2799
|
-
C: (f, a) => f(...a)
|
|
2800
|
-
});
|
|
2801
|
-
}
|
|
2802
|
-
if (Date.now() - this._lastAction.getTime() > MIN_UPDATE_INTERVAL) {
|
|
2803
|
-
for (const peer of sorted.slice(0, MAX_CHANGES_PER_UPDATE)) {
|
|
2804
|
-
log9(`Disconnect ${peer}.`, void 0, {
|
|
2805
|
-
F: __dxlog_file10,
|
|
2806
|
-
L: 100,
|
|
2807
|
-
S: this,
|
|
2808
|
-
C: (f, a) => f(...a)
|
|
2809
|
-
});
|
|
2810
|
-
this._controller.disconnect(peer);
|
|
2811
|
-
}
|
|
2812
|
-
this._lastAction = /* @__PURE__ */ new Date();
|
|
2813
|
-
} else {
|
|
2814
|
-
log9("rate limited disconnect", void 0, {
|
|
2815
|
-
F: __dxlog_file10,
|
|
2816
|
-
L: 105,
|
|
2817
|
-
S: this,
|
|
2818
|
-
C: (f, a) => f(...a)
|
|
2819
|
-
});
|
|
2820
|
-
}
|
|
2821
|
-
} else if (connected.length < this._originateConnections) {
|
|
2822
|
-
log9(`connect ${this._originateConnections - connected.length} peers.`, void 0, {
|
|
2823
|
-
F: __dxlog_file10,
|
|
2824
|
-
L: 109,
|
|
2825
|
-
S: this,
|
|
2826
|
-
C: (f, a) => f(...a)
|
|
2827
|
-
});
|
|
2828
|
-
const sample = candidates.sort(() => Math.random() - 0.5).slice(0, this._sampleSize);
|
|
2829
|
-
const sorted = sortByXorDistance(sample, ownPeerId).slice(0, this._originateConnections - connected.length);
|
|
2830
|
-
if (sorted.length > MAX_CHANGES_PER_UPDATE) {
|
|
2831
|
-
log9(`want to connect ${sorted.length} peers but limited to ${MAX_CHANGES_PER_UPDATE}`, void 0, {
|
|
2832
|
-
F: __dxlog_file10,
|
|
2833
|
-
L: 114,
|
|
2834
|
-
S: this,
|
|
2835
|
-
C: (f, a) => f(...a)
|
|
2836
|
-
});
|
|
2479
|
+
await this._signalManager.close();
|
|
2480
|
+
break;
|
|
2837
2481
|
}
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
this._controller.connect(peer);
|
|
2847
|
-
}
|
|
2848
|
-
this._lastAction = /* @__PURE__ */ new Date();
|
|
2849
|
-
} else {
|
|
2850
|
-
log9("rate limited connect", void 0, {
|
|
2851
|
-
F: __dxlog_file10,
|
|
2852
|
-
L: 123,
|
|
2853
|
-
S: this,
|
|
2854
|
-
C: (f, a) => f(...a)
|
|
2855
|
-
});
|
|
2482
|
+
case ConnectionState2.ONLINE: {
|
|
2483
|
+
this._connectionState = state;
|
|
2484
|
+
this._messenger.open();
|
|
2485
|
+
await Promise.all([
|
|
2486
|
+
...this._swarms.values()
|
|
2487
|
+
].map((swarm) => swarm.goOnline()));
|
|
2488
|
+
await this._signalManager.open();
|
|
2489
|
+
break;
|
|
2856
2490
|
}
|
|
2857
2491
|
}
|
|
2492
|
+
this.connectionStateChanged.emit(this._connectionState);
|
|
2858
2493
|
}
|
|
2859
|
-
toString() {
|
|
2860
|
-
return "MMSTTopology";
|
|
2861
|
-
}
|
|
2862
|
-
constructor({ originateConnections = 2, maxPeers = 4, sampleSize = 10 } = {}) {
|
|
2863
|
-
_define_property10(this, "_originateConnections", void 0);
|
|
2864
|
-
_define_property10(this, "_maxPeers", void 0);
|
|
2865
|
-
_define_property10(this, "_sampleSize", void 0);
|
|
2866
|
-
_define_property10(this, "_controller", void 0);
|
|
2867
|
-
_define_property10(this, "_sampleCollected", false);
|
|
2868
|
-
_define_property10(this, "_lastAction", /* @__PURE__ */ new Date(0));
|
|
2869
|
-
this._originateConnections = originateConnections;
|
|
2870
|
-
this._maxPeers = maxPeers;
|
|
2871
|
-
this._sampleSize = sampleSize;
|
|
2872
|
-
}
|
|
2873
|
-
};
|
|
2874
|
-
var sortByXorDistance = (keys, reference) => {
|
|
2875
|
-
const sorted = keys.sort((a, b) => {
|
|
2876
|
-
return compareXor(distXor(a.asBuffer(), reference.asBuffer()), distXor(b.asBuffer(), reference.asBuffer()));
|
|
2877
|
-
});
|
|
2878
|
-
log9("Sorted keys", {
|
|
2879
|
-
keys,
|
|
2880
|
-
reference,
|
|
2881
|
-
sorted
|
|
2882
|
-
}, {
|
|
2883
|
-
F: __dxlog_file10,
|
|
2884
|
-
L: 137,
|
|
2885
|
-
S: void 0,
|
|
2886
|
-
C: (f, a) => f(...a)
|
|
2887
|
-
});
|
|
2888
|
-
return sorted;
|
|
2889
|
-
};
|
|
2890
|
-
var distXor = (a, b) => {
|
|
2891
|
-
const maxLength = Math.max(a.length, b.length);
|
|
2892
|
-
const result = Buffer.allocUnsafe(maxLength);
|
|
2893
|
-
for (let i = 0; i < maxLength; i++) {
|
|
2894
|
-
result[i] = (a[i] || 0) ^ (b[i] || 0);
|
|
2895
|
-
}
|
|
2896
|
-
return result;
|
|
2897
|
-
};
|
|
2898
|
-
var compareXor = (a, b) => {
|
|
2899
|
-
const maxLength = Math.max(a.length, b.length);
|
|
2900
|
-
for (let i = 0; i < maxLength; i++) {
|
|
2901
|
-
if ((a[i] || 0) === (b[i] || 0)) {
|
|
2902
|
-
continue;
|
|
2903
|
-
}
|
|
2904
|
-
return (a[i] || 0) < (b[i] || 0) ? -1 : 1;
|
|
2905
|
-
}
|
|
2906
|
-
return 0;
|
|
2907
2494
|
};
|
|
2495
|
+
_ts_decorate4([
|
|
2496
|
+
synchronized4
|
|
2497
|
+
], SwarmNetworkManager.prototype, "joinSwarm", null);
|
|
2498
|
+
_ts_decorate4([
|
|
2499
|
+
synchronized4
|
|
2500
|
+
], SwarmNetworkManager.prototype, "leaveSwarm", null);
|
|
2908
2501
|
|
|
2909
|
-
// src/topology/
|
|
2910
|
-
import { invariant as
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
Object.defineProperty(obj, key, {
|
|
2915
|
-
value,
|
|
2916
|
-
enumerable: true,
|
|
2917
|
-
configurable: true,
|
|
2918
|
-
writable: true
|
|
2919
|
-
});
|
|
2920
|
-
} else {
|
|
2921
|
-
obj[key] = value;
|
|
2922
|
-
}
|
|
2923
|
-
return obj;
|
|
2924
|
-
}
|
|
2925
|
-
var __dxlog_file11 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/topology/star-topology.ts";
|
|
2926
|
-
var StarTopology = class {
|
|
2502
|
+
// src/topology/fully-connected-topology.ts
|
|
2503
|
+
import { invariant as invariant7 } from "@dxos/invariant";
|
|
2504
|
+
var __dxlog_file8 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
|
|
2505
|
+
var FullyConnectedTopology = class {
|
|
2506
|
+
_controller;
|
|
2927
2507
|
toString() {
|
|
2928
|
-
return
|
|
2508
|
+
return "FullyConnectedTopology";
|
|
2929
2509
|
}
|
|
2930
2510
|
init(controller) {
|
|
2931
|
-
|
|
2932
|
-
F:
|
|
2933
|
-
L:
|
|
2511
|
+
invariant7(!this._controller, "Already initialized", {
|
|
2512
|
+
F: __dxlog_file8,
|
|
2513
|
+
L: 18,
|
|
2934
2514
|
S: this,
|
|
2935
2515
|
A: [
|
|
2936
2516
|
"!this._controller",
|
|
2937
|
-
"'Already initialized
|
|
2517
|
+
"'Already initialized'"
|
|
2938
2518
|
]
|
|
2939
2519
|
});
|
|
2940
2520
|
this._controller = controller;
|
|
2941
2521
|
}
|
|
2942
2522
|
update() {
|
|
2943
|
-
|
|
2944
|
-
F:
|
|
2945
|
-
L:
|
|
2523
|
+
invariant7(this._controller, "Not initialized", {
|
|
2524
|
+
F: __dxlog_file8,
|
|
2525
|
+
L: 23,
|
|
2946
2526
|
S: this,
|
|
2947
2527
|
A: [
|
|
2948
2528
|
"this._controller",
|
|
2949
|
-
"'Not initialized
|
|
2529
|
+
"'Not initialized'"
|
|
2950
2530
|
]
|
|
2951
2531
|
});
|
|
2952
|
-
const { candidates
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
F: __dxlog_file11,
|
|
2956
|
-
L: 29,
|
|
2957
|
-
S: this,
|
|
2958
|
-
C: (f, a) => f(...a)
|
|
2959
|
-
});
|
|
2960
|
-
for (const peer of connected) {
|
|
2961
|
-
if (!peer.equals(this._centralPeer)) {
|
|
2962
|
-
log10("dropping connection", {
|
|
2963
|
-
peer
|
|
2964
|
-
}, {
|
|
2965
|
-
F: __dxlog_file11,
|
|
2966
|
-
L: 34,
|
|
2967
|
-
S: this,
|
|
2968
|
-
C: (f, a) => f(...a)
|
|
2969
|
-
});
|
|
2970
|
-
this._controller.disconnect(peer);
|
|
2971
|
-
}
|
|
2972
|
-
}
|
|
2973
|
-
}
|
|
2974
|
-
for (const peer of candidates) {
|
|
2975
|
-
if (peer.equals(this._centralPeer) || ownPeerId.equals(this._centralPeer)) {
|
|
2976
|
-
log10("connecting to peer", {
|
|
2977
|
-
peer
|
|
2978
|
-
}, {
|
|
2979
|
-
F: __dxlog_file11,
|
|
2980
|
-
L: 43,
|
|
2981
|
-
S: this,
|
|
2982
|
-
C: (f, a) => f(...a)
|
|
2983
|
-
});
|
|
2984
|
-
this._controller.connect(peer);
|
|
2985
|
-
}
|
|
2532
|
+
const { candidates: discovered } = this._controller.getState();
|
|
2533
|
+
for (const peer of discovered) {
|
|
2534
|
+
this._controller.connect(peer);
|
|
2986
2535
|
}
|
|
2987
2536
|
}
|
|
2988
2537
|
async onOffer(peer) {
|
|
2989
|
-
|
|
2990
|
-
F: __dxlog_file11,
|
|
2991
|
-
L: 50,
|
|
2992
|
-
S: this,
|
|
2993
|
-
A: [
|
|
2994
|
-
"this._controller",
|
|
2995
|
-
"'Not initialized.'"
|
|
2996
|
-
]
|
|
2997
|
-
});
|
|
2998
|
-
const { ownPeerId } = this._controller.getState();
|
|
2999
|
-
log10("offer", {
|
|
3000
|
-
peer,
|
|
3001
|
-
isCentral: peer.equals(this._centralPeer),
|
|
3002
|
-
isSelfCentral: ownPeerId.equals(this._centralPeer)
|
|
3003
|
-
}, {
|
|
3004
|
-
F: __dxlog_file11,
|
|
3005
|
-
L: 52,
|
|
3006
|
-
S: this,
|
|
3007
|
-
C: (f, a) => f(...a)
|
|
3008
|
-
});
|
|
3009
|
-
return ownPeerId.equals(this._centralPeer) || peer.equals(this._centralPeer);
|
|
2538
|
+
return true;
|
|
3010
2539
|
}
|
|
3011
2540
|
async destroy() {
|
|
3012
2541
|
}
|
|
3013
|
-
constructor(_centralPeer) {
|
|
3014
|
-
_define_property11(this, "_centralPeer", void 0);
|
|
3015
|
-
_define_property11(this, "_controller", void 0);
|
|
3016
|
-
this._centralPeer = _centralPeer;
|
|
3017
|
-
}
|
|
3018
2542
|
};
|
|
3019
2543
|
|
|
3020
2544
|
// src/transport/memory-transport.ts
|
|
3021
2545
|
import { Transform } from "@dxos/node-std/stream";
|
|
3022
2546
|
import { Event as Event7, Trigger as Trigger2 } from "@dxos/async";
|
|
3023
2547
|
import { ErrorStream as ErrorStream3 } from "@dxos/debug";
|
|
3024
|
-
import { invariant as
|
|
2548
|
+
import { invariant as invariant8 } from "@dxos/invariant";
|
|
3025
2549
|
import { PublicKey as PublicKey9 } from "@dxos/keys";
|
|
3026
|
-
import { log as
|
|
2550
|
+
import { log as log8, logInfo as logInfo3 } from "@dxos/log";
|
|
3027
2551
|
import { ComplexMap as ComplexMap7 } from "@dxos/util";
|
|
3028
|
-
function _define_property12(obj, key, value) {
|
|
3029
|
-
if (key in obj) {
|
|
3030
|
-
Object.defineProperty(obj, key, {
|
|
3031
|
-
value,
|
|
3032
|
-
enumerable: true,
|
|
3033
|
-
configurable: true,
|
|
3034
|
-
writable: true
|
|
3035
|
-
});
|
|
3036
|
-
} else {
|
|
3037
|
-
obj[key] = value;
|
|
3038
|
-
}
|
|
3039
|
-
return obj;
|
|
3040
|
-
}
|
|
3041
2552
|
function _ts_decorate5(decorators, target, key, desc) {
|
|
3042
2553
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3043
2554
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
3044
2555
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
3045
2556
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3046
2557
|
}
|
|
3047
|
-
var
|
|
2558
|
+
var __dxlog_file9 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
|
|
3048
2559
|
var MEMORY_TRANSPORT_DELAY = 1;
|
|
3049
2560
|
var createStreamDelay = (delay) => {
|
|
3050
2561
|
return new Transform({
|
|
@@ -3058,19 +2569,45 @@ var MemoryTransportFactory = {
|
|
|
3058
2569
|
createTransport: (options) => new MemoryTransport(options)
|
|
3059
2570
|
};
|
|
3060
2571
|
var MemoryTransport = class _MemoryTransport {
|
|
2572
|
+
_options;
|
|
2573
|
+
// TODO(burdon): Remove static properties (inject context into constructor).
|
|
2574
|
+
static _connections = new ComplexMap7(PublicKey9.hash);
|
|
2575
|
+
_instanceId = PublicKey9.random();
|
|
2576
|
+
_remote = new Trigger2();
|
|
2577
|
+
_outgoingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
2578
|
+
_incomingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
2579
|
+
_closed = false;
|
|
2580
|
+
_remoteInstanceId;
|
|
2581
|
+
_remoteConnection;
|
|
2582
|
+
closed = new Event7();
|
|
2583
|
+
connected = new Event7();
|
|
2584
|
+
errors = new ErrorStream3();
|
|
2585
|
+
constructor(_options) {
|
|
2586
|
+
this._options = _options;
|
|
2587
|
+
invariant8(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection", {
|
|
2588
|
+
F: __dxlog_file9,
|
|
2589
|
+
L: 64,
|
|
2590
|
+
S: this,
|
|
2591
|
+
A: [
|
|
2592
|
+
"!MemoryTransport._connections.has(this._instanceId)",
|
|
2593
|
+
"'Duplicate memory connection'"
|
|
2594
|
+
]
|
|
2595
|
+
});
|
|
2596
|
+
_MemoryTransport._connections.set(this._instanceId, this);
|
|
2597
|
+
}
|
|
3061
2598
|
get isOpen() {
|
|
3062
2599
|
return !this._closed;
|
|
3063
2600
|
}
|
|
3064
2601
|
async open() {
|
|
3065
|
-
|
|
3066
|
-
F:
|
|
2602
|
+
log8("opening...", void 0, {
|
|
2603
|
+
F: __dxlog_file9,
|
|
3067
2604
|
L: 74,
|
|
3068
2605
|
S: this,
|
|
3069
2606
|
C: (f, a) => f(...a)
|
|
3070
2607
|
});
|
|
3071
2608
|
if (this._options.initiator) {
|
|
3072
|
-
|
|
3073
|
-
F:
|
|
2609
|
+
log8("sending signal", void 0, {
|
|
2610
|
+
F: __dxlog_file9,
|
|
3074
2611
|
L: 78,
|
|
3075
2612
|
S: this,
|
|
3076
2613
|
C: (f, a) => f(...a)
|
|
@@ -3100,8 +2637,8 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
3100
2637
|
this.closed.emit();
|
|
3101
2638
|
return;
|
|
3102
2639
|
}
|
|
3103
|
-
|
|
3104
|
-
F:
|
|
2640
|
+
invariant8(!this._remoteConnection._remoteConnection, `Remote already connected: ${this._remoteInstanceId}`, {
|
|
2641
|
+
F: __dxlog_file9,
|
|
3105
2642
|
L: 104,
|
|
3106
2643
|
S: this,
|
|
3107
2644
|
A: [
|
|
@@ -3111,8 +2648,8 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
3111
2648
|
});
|
|
3112
2649
|
this._remoteConnection._remoteConnection = this;
|
|
3113
2650
|
this._remoteConnection._remoteInstanceId = this._instanceId;
|
|
3114
|
-
|
|
3115
|
-
F:
|
|
2651
|
+
log8("connected", void 0, {
|
|
2652
|
+
F: __dxlog_file9,
|
|
3116
2653
|
L: 108,
|
|
3117
2654
|
S: this,
|
|
3118
2655
|
C: (f, a) => f(...a)
|
|
@@ -3130,8 +2667,8 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
3130
2667
|
return this;
|
|
3131
2668
|
}
|
|
3132
2669
|
async close() {
|
|
3133
|
-
|
|
3134
|
-
F:
|
|
2670
|
+
log8("closing...", void 0, {
|
|
2671
|
+
F: __dxlog_file9,
|
|
3135
2672
|
L: 130,
|
|
3136
2673
|
S: this,
|
|
3137
2674
|
C: (f, a) => f(...a)
|
|
@@ -3151,8 +2688,8 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
3151
2688
|
this._remoteConnection = void 0;
|
|
3152
2689
|
}
|
|
3153
2690
|
this.closed.emit();
|
|
3154
|
-
|
|
3155
|
-
F:
|
|
2691
|
+
log8("closed", void 0, {
|
|
2692
|
+
F: __dxlog_file9,
|
|
3156
2693
|
L: 158,
|
|
3157
2694
|
S: this,
|
|
3158
2695
|
C: (f, a) => f(...a)
|
|
@@ -3160,10 +2697,10 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
3160
2697
|
return this;
|
|
3161
2698
|
}
|
|
3162
2699
|
async onSignal({ payload }) {
|
|
3163
|
-
|
|
2700
|
+
log8("received signal", {
|
|
3164
2701
|
payload
|
|
3165
2702
|
}, {
|
|
3166
|
-
F:
|
|
2703
|
+
F: __dxlog_file9,
|
|
3167
2704
|
L: 163,
|
|
3168
2705
|
S: this,
|
|
3169
2706
|
C: (f, a) => f(...a)
|
|
@@ -3188,40 +2725,7 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
3188
2725
|
packetsReceived: 0
|
|
3189
2726
|
};
|
|
3190
2727
|
}
|
|
3191
|
-
constructor(_options) {
|
|
3192
|
-
_define_property12(this, "_options", void 0);
|
|
3193
|
-
_define_property12(this, "_instanceId", void 0);
|
|
3194
|
-
_define_property12(this, "_remote", void 0);
|
|
3195
|
-
_define_property12(this, "_outgoingDelay", void 0);
|
|
3196
|
-
_define_property12(this, "_incomingDelay", void 0);
|
|
3197
|
-
_define_property12(this, "_closed", void 0);
|
|
3198
|
-
_define_property12(this, "_remoteInstanceId", void 0);
|
|
3199
|
-
_define_property12(this, "_remoteConnection", void 0);
|
|
3200
|
-
_define_property12(this, "closed", void 0);
|
|
3201
|
-
_define_property12(this, "connected", void 0);
|
|
3202
|
-
_define_property12(this, "errors", void 0);
|
|
3203
|
-
this._options = _options;
|
|
3204
|
-
this._instanceId = PublicKey9.random();
|
|
3205
|
-
this._remote = new Trigger2();
|
|
3206
|
-
this._outgoingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
3207
|
-
this._incomingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
3208
|
-
this._closed = false;
|
|
3209
|
-
this.closed = new Event7();
|
|
3210
|
-
this.connected = new Event7();
|
|
3211
|
-
this.errors = new ErrorStream3();
|
|
3212
|
-
invariant10(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection", {
|
|
3213
|
-
F: __dxlog_file12,
|
|
3214
|
-
L: 64,
|
|
3215
|
-
S: this,
|
|
3216
|
-
A: [
|
|
3217
|
-
"!MemoryTransport._connections.has(this._instanceId)",
|
|
3218
|
-
"'Duplicate memory connection'"
|
|
3219
|
-
]
|
|
3220
|
-
});
|
|
3221
|
-
_MemoryTransport._connections.set(this._instanceId, this);
|
|
3222
|
-
}
|
|
3223
2728
|
};
|
|
3224
|
-
_define_property12(MemoryTransport, "_connections", new ComplexMap7(PublicKey9.hash));
|
|
3225
2729
|
_ts_decorate5([
|
|
3226
2730
|
logInfo3
|
|
3227
2731
|
], MemoryTransport.prototype, "_instanceId", void 0);
|
|
@@ -3241,19 +2745,6 @@ var TransportKind = /* @__PURE__ */ (function(TransportKind2) {
|
|
|
3241
2745
|
|
|
3242
2746
|
// src/transport/webrtc/rtc-connection-factory.ts
|
|
3243
2747
|
import { Mutex } from "@dxos/async";
|
|
3244
|
-
function _define_property13(obj, key, value) {
|
|
3245
|
-
if (key in obj) {
|
|
3246
|
-
Object.defineProperty(obj, key, {
|
|
3247
|
-
value,
|
|
3248
|
-
enumerable: true,
|
|
3249
|
-
configurable: true,
|
|
3250
|
-
writable: true
|
|
3251
|
-
});
|
|
3252
|
-
} else {
|
|
3253
|
-
obj[key] = value;
|
|
3254
|
-
}
|
|
3255
|
-
return obj;
|
|
3256
|
-
}
|
|
3257
2748
|
var BrowserRtcConnectionFactory = class {
|
|
3258
2749
|
async initialize() {
|
|
3259
2750
|
}
|
|
@@ -3266,6 +2757,8 @@ var BrowserRtcConnectionFactory = class {
|
|
|
3266
2757
|
}
|
|
3267
2758
|
};
|
|
3268
2759
|
var NodeRtcConnectionFactory = class _NodeRtcConnectionFactory {
|
|
2760
|
+
static _createdConnections = 0;
|
|
2761
|
+
static _cleanupMutex = new Mutex();
|
|
3269
2762
|
// This should be inside the function to avoid triggering `eval` in the global scope.
|
|
3270
2763
|
// eslint-disable-next-line @typescript-eslint/no-implied-eval
|
|
3271
2764
|
// TODO(burdon): Do imports here?
|
|
@@ -3291,16 +2784,14 @@ var NodeRtcConnectionFactory = class _NodeRtcConnectionFactory {
|
|
|
3291
2784
|
}
|
|
3292
2785
|
}
|
|
3293
2786
|
};
|
|
3294
|
-
_define_property13(NodeRtcConnectionFactory, "_createdConnections", 0);
|
|
3295
|
-
_define_property13(NodeRtcConnectionFactory, "_cleanupMutex", new Mutex());
|
|
3296
2787
|
var getRtcConnectionFactory = () => {
|
|
3297
2788
|
return typeof globalThis.RTCPeerConnection === "undefined" ? new NodeRtcConnectionFactory() : new BrowserRtcConnectionFactory();
|
|
3298
2789
|
};
|
|
3299
2790
|
|
|
3300
2791
|
// src/transport/webrtc/rtc-peer-connection.ts
|
|
3301
2792
|
import { Mutex as Mutex2, Trigger as Trigger3, synchronized as synchronized5 } from "@dxos/async";
|
|
3302
|
-
import { invariant as
|
|
3303
|
-
import { log as
|
|
2793
|
+
import { invariant as invariant10 } from "@dxos/invariant";
|
|
2794
|
+
import { log as log10, logInfo as logInfo4 } from "@dxos/log";
|
|
3304
2795
|
import { ConnectivityError as ConnectivityError3 } from "@dxos/protocols";
|
|
3305
2796
|
import { trace as trace4 } from "@dxos/tracing";
|
|
3306
2797
|
|
|
@@ -3309,8 +2800,8 @@ import { Duplex } from "@dxos/node-std/stream";
|
|
|
3309
2800
|
import { Event as AsyncEvent } from "@dxos/async";
|
|
3310
2801
|
import { Resource } from "@dxos/context";
|
|
3311
2802
|
import { ErrorStream as ErrorStream4 } from "@dxos/debug";
|
|
3312
|
-
import { invariant as
|
|
3313
|
-
import { log as
|
|
2803
|
+
import { invariant as invariant9 } from "@dxos/invariant";
|
|
2804
|
+
import { log as log9 } from "@dxos/log";
|
|
3314
2805
|
import { ConnectivityError as ConnectivityError2 } from "@dxos/protocols";
|
|
3315
2806
|
|
|
3316
2807
|
// src/transport/webrtc/rtc-transport-stats.ts
|
|
@@ -3361,23 +2852,22 @@ var getRtcConnectionStats = async (connection, channelTopic) => {
|
|
|
3361
2852
|
};
|
|
3362
2853
|
|
|
3363
2854
|
// src/transport/webrtc/rtc-transport-channel.ts
|
|
3364
|
-
|
|
3365
|
-
if (key in obj) {
|
|
3366
|
-
Object.defineProperty(obj, key, {
|
|
3367
|
-
value,
|
|
3368
|
-
enumerable: true,
|
|
3369
|
-
configurable: true,
|
|
3370
|
-
writable: true
|
|
3371
|
-
});
|
|
3372
|
-
} else {
|
|
3373
|
-
obj[key] = value;
|
|
3374
|
-
}
|
|
3375
|
-
return obj;
|
|
3376
|
-
}
|
|
3377
|
-
var __dxlog_file13 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-channel.ts";
|
|
2855
|
+
var __dxlog_file10 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-channel.ts";
|
|
3378
2856
|
var MAX_MESSAGE_SIZE = 64 * 1024;
|
|
3379
2857
|
var MAX_BUFFERED_AMOUNT = 64 * 1024;
|
|
3380
2858
|
var RtcTransportChannel = class extends Resource {
|
|
2859
|
+
_connection;
|
|
2860
|
+
_options;
|
|
2861
|
+
closed = new AsyncEvent();
|
|
2862
|
+
connected = new AsyncEvent();
|
|
2863
|
+
errors = new ErrorStream4();
|
|
2864
|
+
_channel;
|
|
2865
|
+
_stream;
|
|
2866
|
+
_streamDataFlushedCallback = null;
|
|
2867
|
+
_isChannelCreationInProgress = false;
|
|
2868
|
+
constructor(_connection, _options) {
|
|
2869
|
+
super(), this._connection = _connection, this._options = _options;
|
|
2870
|
+
}
|
|
3381
2871
|
get isRtcChannelCreationInProgress() {
|
|
3382
2872
|
return this._isChannelCreationInProgress;
|
|
3383
2873
|
}
|
|
@@ -3387,8 +2877,8 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3387
2877
|
}
|
|
3388
2878
|
}
|
|
3389
2879
|
async _open() {
|
|
3390
|
-
|
|
3391
|
-
F:
|
|
2880
|
+
invariant9(!this._isChannelCreationInProgress, void 0, {
|
|
2881
|
+
F: __dxlog_file10,
|
|
3392
2882
|
L: 57,
|
|
3393
2883
|
S: this,
|
|
3394
2884
|
A: [
|
|
@@ -3406,13 +2896,15 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3406
2896
|
}
|
|
3407
2897
|
}).catch((err) => {
|
|
3408
2898
|
if (this.isOpen) {
|
|
3409
|
-
const error = err instanceof Error ? err : new ConnectivityError2(
|
|
2899
|
+
const error = err instanceof Error ? err : new ConnectivityError2({
|
|
2900
|
+
message: `Failed to create a channel: ${JSON.stringify(err?.message)}`
|
|
2901
|
+
});
|
|
3410
2902
|
this.errors.raise(error);
|
|
3411
2903
|
} else {
|
|
3412
|
-
|
|
2904
|
+
log9.verbose("connection establishment failed after transport was closed", {
|
|
3413
2905
|
err
|
|
3414
2906
|
}, {
|
|
3415
|
-
F:
|
|
2907
|
+
F: __dxlog_file10,
|
|
3416
2908
|
L: 77,
|
|
3417
2909
|
S: this,
|
|
3418
2910
|
C: (f, a) => f(...a)
|
|
@@ -3429,8 +2921,8 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3429
2921
|
this._stream = void 0;
|
|
3430
2922
|
}
|
|
3431
2923
|
this.closed.emit();
|
|
3432
|
-
|
|
3433
|
-
F:
|
|
2924
|
+
log9("closed", void 0, {
|
|
2925
|
+
F: __dxlog_file10,
|
|
3434
2926
|
L: 93,
|
|
3435
2927
|
S: this,
|
|
3436
2928
|
C: (f, a) => f(...a)
|
|
@@ -3440,10 +2932,10 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3440
2932
|
Object.assign(channel, {
|
|
3441
2933
|
onopen: () => {
|
|
3442
2934
|
if (!this.isOpen) {
|
|
3443
|
-
|
|
2935
|
+
log9.warn("channel opened in a closed transport", {
|
|
3444
2936
|
topic: this._options.topic
|
|
3445
2937
|
}, {
|
|
3446
|
-
F:
|
|
2938
|
+
F: __dxlog_file10,
|
|
3447
2939
|
L: 100,
|
|
3448
2940
|
S: this,
|
|
3449
2941
|
C: (f, a) => f(...a)
|
|
@@ -3451,8 +2943,8 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3451
2943
|
this._safeCloseChannel(channel);
|
|
3452
2944
|
return;
|
|
3453
2945
|
}
|
|
3454
|
-
|
|
3455
|
-
F:
|
|
2946
|
+
log9("onopen", void 0, {
|
|
2947
|
+
F: __dxlog_file10,
|
|
3456
2948
|
L: 105,
|
|
3457
2949
|
S: this,
|
|
3458
2950
|
C: (f, a) => f(...a)
|
|
@@ -3469,8 +2961,8 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3469
2961
|
this.connected.emit();
|
|
3470
2962
|
},
|
|
3471
2963
|
onclose: async () => {
|
|
3472
|
-
|
|
3473
|
-
F:
|
|
2964
|
+
log9("onclose", void 0, {
|
|
2965
|
+
F: __dxlog_file10,
|
|
3474
2966
|
L: 118,
|
|
3475
2967
|
S: this,
|
|
3476
2968
|
C: (f, a) => f(...a)
|
|
@@ -3479,8 +2971,8 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3479
2971
|
},
|
|
3480
2972
|
onmessage: async (event) => {
|
|
3481
2973
|
if (!this._stream) {
|
|
3482
|
-
|
|
3483
|
-
F:
|
|
2974
|
+
log9.warn("ignoring message on a closed channel", void 0, {
|
|
2975
|
+
F: __dxlog_file10,
|
|
3484
2976
|
L: 124,
|
|
3485
2977
|
S: this,
|
|
3486
2978
|
C: (f, a) => f(...a)
|
|
@@ -3510,8 +3002,8 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3510
3002
|
}
|
|
3511
3003
|
async _handleChannelWrite(chunk, callback) {
|
|
3512
3004
|
if (!this._channel) {
|
|
3513
|
-
|
|
3514
|
-
F:
|
|
3005
|
+
log9.warn("writing to a channel after a connection was closed", void 0, {
|
|
3006
|
+
F: __dxlog_file10,
|
|
3515
3007
|
L: 154,
|
|
3516
3008
|
S: this,
|
|
3517
3009
|
C: (f, a) => f(...a)
|
|
@@ -3533,8 +3025,8 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3533
3025
|
}
|
|
3534
3026
|
if (this._channel.bufferedAmount > MAX_BUFFERED_AMOUNT) {
|
|
3535
3027
|
if (this._streamDataFlushedCallback !== null) {
|
|
3536
|
-
|
|
3537
|
-
F:
|
|
3028
|
+
log9.error("consumer trying to write before we are ready for more data", void 0, {
|
|
3029
|
+
F: __dxlog_file10,
|
|
3538
3030
|
L: 175,
|
|
3539
3031
|
S: this,
|
|
3540
3032
|
C: (f, a) => f(...a)
|
|
@@ -3549,8 +3041,8 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3549
3041
|
try {
|
|
3550
3042
|
channel.close();
|
|
3551
3043
|
} catch (error) {
|
|
3552
|
-
|
|
3553
|
-
F:
|
|
3044
|
+
log9.catch(error, void 0, {
|
|
3045
|
+
F: __dxlog_file10,
|
|
3554
3046
|
L: 187,
|
|
3555
3047
|
S: this,
|
|
3556
3048
|
C: (f, a) => f(...a)
|
|
@@ -3566,9 +3058,6 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3566
3058
|
async getStats() {
|
|
3567
3059
|
return createRtcTransportStats(this._connection.currentConnection, this._options.topic);
|
|
3568
3060
|
}
|
|
3569
|
-
constructor(_connection, _options) {
|
|
3570
|
-
super(), _define_property14(this, "_connection", void 0), _define_property14(this, "_options", void 0), _define_property14(this, "closed", void 0), _define_property14(this, "connected", void 0), _define_property14(this, "errors", void 0), _define_property14(this, "_channel", void 0), _define_property14(this, "_stream", void 0), _define_property14(this, "_streamDataFlushedCallback", void 0), _define_property14(this, "_isChannelCreationInProgress", void 0), this._connection = _connection, this._options = _options, this.closed = new AsyncEvent(), this.connected = new AsyncEvent(), this.errors = new ErrorStream4(), this._streamDataFlushedCallback = null, this._isChannelCreationInProgress = false;
|
|
3571
|
-
}
|
|
3572
3061
|
};
|
|
3573
3062
|
|
|
3574
3063
|
// src/transport/webrtc/utils.ts
|
|
@@ -3598,27 +3087,37 @@ var deduplicatedSdpLines = (sdp) => {
|
|
|
3598
3087
|
};
|
|
3599
3088
|
|
|
3600
3089
|
// src/transport/webrtc/rtc-peer-connection.ts
|
|
3601
|
-
function _define_property15(obj, key, value) {
|
|
3602
|
-
if (key in obj) {
|
|
3603
|
-
Object.defineProperty(obj, key, {
|
|
3604
|
-
value,
|
|
3605
|
-
enumerable: true,
|
|
3606
|
-
configurable: true,
|
|
3607
|
-
writable: true
|
|
3608
|
-
});
|
|
3609
|
-
} else {
|
|
3610
|
-
obj[key] = value;
|
|
3611
|
-
}
|
|
3612
|
-
return obj;
|
|
3613
|
-
}
|
|
3614
3090
|
function _ts_decorate6(decorators, target, key, desc) {
|
|
3615
3091
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3616
3092
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
3617
3093
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
3618
3094
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3619
3095
|
}
|
|
3620
|
-
var
|
|
3096
|
+
var __dxlog_file11 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-peer-connection.ts";
|
|
3621
3097
|
var RtcPeerConnection = class {
|
|
3098
|
+
_factory;
|
|
3099
|
+
_options;
|
|
3100
|
+
// A peer who is not the initiator waits for another party to open a channel.
|
|
3101
|
+
_channelCreatedCallbacks = /* @__PURE__ */ new Map();
|
|
3102
|
+
// Channels indexed by topic.
|
|
3103
|
+
_transportChannels = /* @__PURE__ */ new Map();
|
|
3104
|
+
_dataChannels = /* @__PURE__ */ new Map();
|
|
3105
|
+
// A peer is ready to receive ICE candidates when local and remote description were set.
|
|
3106
|
+
_readyForCandidates = new Trigger3();
|
|
3107
|
+
_offerProcessingMutex = new Mutex2();
|
|
3108
|
+
/**
|
|
3109
|
+
* Can't use peer.connection.initiator, because if two connections to the same peer are created in
|
|
3110
|
+
* different swarms, we might be the initiator of the first one, but not of the other one.
|
|
3111
|
+
* Use a stable peer keypair property (key ordering) to decide who's acting as the initiator of
|
|
3112
|
+
* transport connection establishment and data channel creation.
|
|
3113
|
+
*/
|
|
3114
|
+
_initiator;
|
|
3115
|
+
_connection;
|
|
3116
|
+
constructor(_factory, _options) {
|
|
3117
|
+
this._factory = _factory;
|
|
3118
|
+
this._options = _options;
|
|
3119
|
+
this._initiator = chooseInitiatorPeer(_options.ownPeerKey, _options.remotePeerKey) === _options.ownPeerKey;
|
|
3120
|
+
}
|
|
3622
3121
|
get transportChannelCount() {
|
|
3623
3122
|
return this._transportChannels.size;
|
|
3624
3123
|
}
|
|
@@ -3642,8 +3141,8 @@ var RtcPeerConnection = class {
|
|
|
3642
3141
|
if (existingChannel) {
|
|
3643
3142
|
return existingChannel;
|
|
3644
3143
|
}
|
|
3645
|
-
|
|
3646
|
-
F:
|
|
3144
|
+
log10("waiting for initiator-peer to open a data channel", void 0, {
|
|
3145
|
+
F: __dxlog_file11,
|
|
3647
3146
|
L: 96,
|
|
3648
3147
|
S: this,
|
|
3649
3148
|
C: (f, a) => f(...a)
|
|
@@ -3671,10 +3170,10 @@ var RtcPeerConnection = class {
|
|
|
3671
3170
|
if (this._connection) {
|
|
3672
3171
|
return this._connection;
|
|
3673
3172
|
}
|
|
3674
|
-
|
|
3173
|
+
log10("initializing connection...", () => ({
|
|
3675
3174
|
remotePeer: this._options.remotePeerKey
|
|
3676
3175
|
}), {
|
|
3677
|
-
F:
|
|
3176
|
+
F: __dxlog_file11,
|
|
3678
3177
|
L: 121,
|
|
3679
3178
|
S: this,
|
|
3680
3179
|
C: (f, a) => f(...a)
|
|
@@ -3684,8 +3183,8 @@ var RtcPeerConnection = class {
|
|
|
3684
3183
|
const iceCandidateErrors = [];
|
|
3685
3184
|
Object.assign(connection, {
|
|
3686
3185
|
onnegotiationneeded: async () => {
|
|
3687
|
-
|
|
3688
|
-
F:
|
|
3186
|
+
invariant10(this._initiator, void 0, {
|
|
3187
|
+
F: __dxlog_file11,
|
|
3689
3188
|
L: 136,
|
|
3690
3189
|
S: this,
|
|
3691
3190
|
A: [
|
|
@@ -3697,8 +3196,8 @@ var RtcPeerConnection = class {
|
|
|
3697
3196
|
this._onConnectionCallbackAfterClose("onnegotiationneeded", connection);
|
|
3698
3197
|
return;
|
|
3699
3198
|
}
|
|
3700
|
-
|
|
3701
|
-
F:
|
|
3199
|
+
log10("onnegotiationneeded", void 0, {
|
|
3200
|
+
F: __dxlog_file11,
|
|
3702
3201
|
L: 143,
|
|
3703
3202
|
S: this,
|
|
3704
3203
|
C: (f, a) => f(...a)
|
|
@@ -3719,18 +3218,18 @@ var RtcPeerConnection = class {
|
|
|
3719
3218
|
return;
|
|
3720
3219
|
}
|
|
3721
3220
|
if (event.candidate) {
|
|
3722
|
-
|
|
3221
|
+
log10("onicecandidate", {
|
|
3723
3222
|
candidate: event.candidate.candidate
|
|
3724
3223
|
}, {
|
|
3725
|
-
F:
|
|
3224
|
+
F: __dxlog_file11,
|
|
3726
3225
|
L: 162,
|
|
3727
3226
|
S: this,
|
|
3728
3227
|
C: (f, a) => f(...a)
|
|
3729
3228
|
});
|
|
3730
3229
|
await this._sendIceCandidate(event.candidate);
|
|
3731
3230
|
} else {
|
|
3732
|
-
|
|
3733
|
-
F:
|
|
3231
|
+
log10("onicecandidate gathering complete", void 0, {
|
|
3232
|
+
F: __dxlog_file11,
|
|
3734
3233
|
L: 165,
|
|
3735
3234
|
S: this,
|
|
3736
3235
|
C: (f, a) => f(...a)
|
|
@@ -3755,10 +3254,10 @@ var RtcPeerConnection = class {
|
|
|
3755
3254
|
this._onConnectionCallbackAfterClose("oniceconnectionstatechange", connection);
|
|
3756
3255
|
return;
|
|
3757
3256
|
}
|
|
3758
|
-
|
|
3257
|
+
log10("oniceconnectionstatechange", {
|
|
3759
3258
|
state: connection.iceConnectionState
|
|
3760
3259
|
}, {
|
|
3761
|
-
F:
|
|
3260
|
+
F: __dxlog_file11,
|
|
3762
3261
|
L: 185,
|
|
3763
3262
|
S: this,
|
|
3764
3263
|
C: (f, a) => f(...a)
|
|
@@ -3777,10 +3276,10 @@ var RtcPeerConnection = class {
|
|
|
3777
3276
|
}
|
|
3778
3277
|
return;
|
|
3779
3278
|
}
|
|
3780
|
-
|
|
3279
|
+
log10("onconnectionstatechange", {
|
|
3781
3280
|
state: connection.connectionState
|
|
3782
3281
|
}, {
|
|
3783
|
-
F:
|
|
3282
|
+
F: __dxlog_file11,
|
|
3784
3283
|
L: 202,
|
|
3785
3284
|
S: this,
|
|
3786
3285
|
C: (f, a) => f(...a)
|
|
@@ -3790,10 +3289,10 @@ var RtcPeerConnection = class {
|
|
|
3790
3289
|
}
|
|
3791
3290
|
},
|
|
3792
3291
|
onsignalingstatechange: () => {
|
|
3793
|
-
|
|
3292
|
+
log10("onsignalingstatechange", {
|
|
3794
3293
|
state: connection.signalingState
|
|
3795
3294
|
}, {
|
|
3796
|
-
F:
|
|
3295
|
+
F: __dxlog_file11,
|
|
3797
3296
|
L: 209,
|
|
3798
3297
|
S: this,
|
|
3799
3298
|
C: (f, a) => f(...a)
|
|
@@ -3802,8 +3301,8 @@ var RtcPeerConnection = class {
|
|
|
3802
3301
|
// When channel is added to connection.
|
|
3803
3302
|
// https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/datachannel_event
|
|
3804
3303
|
ondatachannel: (event) => {
|
|
3805
|
-
|
|
3806
|
-
F:
|
|
3304
|
+
invariant10(!this._initiator, "Initiator is expected to create data channels.", {
|
|
3305
|
+
F: __dxlog_file11,
|
|
3807
3306
|
L: 215,
|
|
3808
3307
|
S: this,
|
|
3809
3308
|
A: [
|
|
@@ -3815,10 +3314,10 @@ var RtcPeerConnection = class {
|
|
|
3815
3314
|
this._onConnectionCallbackAfterClose("ondatachannel", connection);
|
|
3816
3315
|
return;
|
|
3817
3316
|
}
|
|
3818
|
-
|
|
3317
|
+
log10("ondatachannel", {
|
|
3819
3318
|
label: event.channel.label
|
|
3820
3319
|
}, {
|
|
3821
|
-
F:
|
|
3320
|
+
F: __dxlog_file11,
|
|
3822
3321
|
L: 222,
|
|
3823
3322
|
S: this,
|
|
3824
3323
|
C: (f, a) => f(...a)
|
|
@@ -3843,10 +3342,10 @@ var RtcPeerConnection = class {
|
|
|
3843
3342
|
}
|
|
3844
3343
|
_abortConnection(connection, error) {
|
|
3845
3344
|
if (connection !== this._connection) {
|
|
3846
|
-
|
|
3345
|
+
log10.error("attempted to abort an inactive connection", {
|
|
3847
3346
|
error
|
|
3848
3347
|
}, {
|
|
3849
|
-
F:
|
|
3348
|
+
F: __dxlog_file11,
|
|
3850
3349
|
L: 247,
|
|
3851
3350
|
S: this,
|
|
3852
3351
|
C: (f, a) => f(...a)
|
|
@@ -3864,18 +3363,18 @@ var RtcPeerConnection = class {
|
|
|
3864
3363
|
}
|
|
3865
3364
|
this._transportChannels.clear();
|
|
3866
3365
|
this._safeCloseConnection();
|
|
3867
|
-
|
|
3366
|
+
log10("connection aborted", {
|
|
3868
3367
|
reason: error.message
|
|
3869
3368
|
}, {
|
|
3870
|
-
F:
|
|
3369
|
+
F: __dxlog_file11,
|
|
3871
3370
|
L: 261,
|
|
3872
3371
|
S: this,
|
|
3873
3372
|
C: (f, a) => f(...a)
|
|
3874
3373
|
});
|
|
3875
3374
|
}
|
|
3876
3375
|
async _lockAndCloseConnection() {
|
|
3877
|
-
|
|
3878
|
-
F:
|
|
3376
|
+
invariant10(this._transportChannels.size === 0, void 0, {
|
|
3377
|
+
F: __dxlog_file11,
|
|
3879
3378
|
L: 266,
|
|
3880
3379
|
S: this,
|
|
3881
3380
|
A: [
|
|
@@ -3885,8 +3384,8 @@ var RtcPeerConnection = class {
|
|
|
3885
3384
|
});
|
|
3886
3385
|
if (this._connection) {
|
|
3887
3386
|
this._safeCloseConnection();
|
|
3888
|
-
|
|
3889
|
-
F:
|
|
3387
|
+
log10("connection closed", void 0, {
|
|
3388
|
+
F: __dxlog_file11,
|
|
3890
3389
|
L: 269,
|
|
3891
3390
|
S: this,
|
|
3892
3391
|
C: (f, a) => f(...a)
|
|
@@ -3896,10 +3395,10 @@ var RtcPeerConnection = class {
|
|
|
3896
3395
|
async onSignal(signal) {
|
|
3897
3396
|
const connection = this._connection;
|
|
3898
3397
|
if (!connection) {
|
|
3899
|
-
|
|
3398
|
+
log10.warn("a signal ignored because the connection was closed", {
|
|
3900
3399
|
type: signal.payload.data.type
|
|
3901
3400
|
}, {
|
|
3902
|
-
F:
|
|
3401
|
+
F: __dxlog_file11,
|
|
3903
3402
|
L: 277,
|
|
3904
3403
|
S: this,
|
|
3905
3404
|
C: (f, a) => f(...a)
|
|
@@ -3963,10 +3462,10 @@ var RtcPeerConnection = class {
|
|
|
3963
3462
|
this._abortConnection(connection, new Error(`Unknown signal type ${data.type}.`));
|
|
3964
3463
|
break;
|
|
3965
3464
|
}
|
|
3966
|
-
|
|
3465
|
+
log10("signal processed", {
|
|
3967
3466
|
type: data.type
|
|
3968
3467
|
}, {
|
|
3969
|
-
F:
|
|
3468
|
+
F: __dxlog_file11,
|
|
3970
3469
|
L: 336,
|
|
3971
3470
|
S: this,
|
|
3972
3471
|
C: (f, a) => f(...a)
|
|
@@ -3976,10 +3475,10 @@ var RtcPeerConnection = class {
|
|
|
3976
3475
|
try {
|
|
3977
3476
|
await this._readyForCandidates.wait();
|
|
3978
3477
|
if (connection === this._connection) {
|
|
3979
|
-
|
|
3478
|
+
log10("adding ice candidate", {
|
|
3980
3479
|
candidate
|
|
3981
3480
|
}, {
|
|
3982
|
-
F:
|
|
3481
|
+
F: __dxlog_file11,
|
|
3983
3482
|
L: 344,
|
|
3984
3483
|
S: this,
|
|
3985
3484
|
C: (f, a) => f(...a)
|
|
@@ -3987,8 +3486,8 @@ var RtcPeerConnection = class {
|
|
|
3987
3486
|
await connection.addIceCandidate(candidate);
|
|
3988
3487
|
}
|
|
3989
3488
|
} catch (err) {
|
|
3990
|
-
|
|
3991
|
-
F:
|
|
3489
|
+
log10.catch(err, void 0, {
|
|
3490
|
+
F: __dxlog_file11,
|
|
3992
3491
|
L: 348,
|
|
3993
3492
|
S: this,
|
|
3994
3493
|
C: (f, a) => f(...a)
|
|
@@ -3997,16 +3496,16 @@ var RtcPeerConnection = class {
|
|
|
3997
3496
|
}
|
|
3998
3497
|
_onSessionNegotiated(connection) {
|
|
3999
3498
|
if (connection === this._connection) {
|
|
4000
|
-
|
|
4001
|
-
F:
|
|
3499
|
+
log10("ready to process ice candidates", void 0, {
|
|
3500
|
+
F: __dxlog_file11,
|
|
4002
3501
|
L: 354,
|
|
4003
3502
|
S: this,
|
|
4004
3503
|
C: (f, a) => f(...a)
|
|
4005
3504
|
});
|
|
4006
3505
|
this._readyForCandidates.wake();
|
|
4007
3506
|
} else {
|
|
4008
|
-
|
|
4009
|
-
F:
|
|
3507
|
+
log10.warn("session was negotiated after connection became inactive", void 0, {
|
|
3508
|
+
F: __dxlog_file11,
|
|
4010
3509
|
L: 357,
|
|
4011
3510
|
S: this,
|
|
4012
3511
|
C: (f, a) => f(...a)
|
|
@@ -4014,11 +3513,11 @@ var RtcPeerConnection = class {
|
|
|
4014
3513
|
}
|
|
4015
3514
|
}
|
|
4016
3515
|
_onConnectionCallbackAfterClose(callback, connection) {
|
|
4017
|
-
|
|
3516
|
+
log10.warn("callback invoked after a connection was destroyed, this is probably a bug", {
|
|
4018
3517
|
callback,
|
|
4019
3518
|
state: connection.connectionState
|
|
4020
3519
|
}, {
|
|
4021
|
-
F:
|
|
3520
|
+
F: __dxlog_file11,
|
|
4022
3521
|
L: 362,
|
|
4023
3522
|
S: this,
|
|
4024
3523
|
C: (f, a) => f(...a)
|
|
@@ -4030,8 +3529,8 @@ var RtcPeerConnection = class {
|
|
|
4030
3529
|
try {
|
|
4031
3530
|
connection?.close();
|
|
4032
3531
|
} catch (err) {
|
|
4033
|
-
|
|
4034
|
-
F:
|
|
3532
|
+
log10.catch(err, void 0, {
|
|
3533
|
+
F: __dxlog_file11,
|
|
4035
3534
|
L: 374,
|
|
4036
3535
|
S: this,
|
|
4037
3536
|
C: (f, a) => f(...a)
|
|
@@ -4041,8 +3540,8 @@ var RtcPeerConnection = class {
|
|
|
4041
3540
|
this._connection = void 0;
|
|
4042
3541
|
this._dataChannels.clear();
|
|
4043
3542
|
this._readyForCandidates.wake();
|
|
4044
|
-
void this._factory.onConnectionDestroyed().catch((err) =>
|
|
4045
|
-
F:
|
|
3543
|
+
void this._factory.onConnectionDestroyed().catch((err) => log10.catch(err, void 0, {
|
|
3544
|
+
F: __dxlog_file11,
|
|
4046
3545
|
L: 380,
|
|
4047
3546
|
S: this,
|
|
4048
3547
|
C: (f, a) => f(...a)
|
|
@@ -4066,8 +3565,8 @@ var RtcPeerConnection = class {
|
|
|
4066
3565
|
];
|
|
4067
3566
|
}
|
|
4068
3567
|
} catch (error) {
|
|
4069
|
-
|
|
4070
|
-
F:
|
|
3568
|
+
log10.catch(error, void 0, {
|
|
3569
|
+
F: __dxlog_file11,
|
|
4071
3570
|
L: 396,
|
|
4072
3571
|
S: this,
|
|
4073
3572
|
C: (f, a) => f(...a)
|
|
@@ -4091,10 +3590,10 @@ var RtcPeerConnection = class {
|
|
|
4091
3590
|
}
|
|
4092
3591
|
});
|
|
4093
3592
|
} catch (err) {
|
|
4094
|
-
|
|
3593
|
+
log10.warn("signaling error", {
|
|
4095
3594
|
err
|
|
4096
3595
|
}, {
|
|
4097
|
-
F:
|
|
3596
|
+
F: __dxlog_file11,
|
|
4098
3597
|
L: 417,
|
|
4099
3598
|
S: this,
|
|
4100
3599
|
C: (f, a) => f(...a)
|
|
@@ -4142,25 +3641,6 @@ var RtcPeerConnection = class {
|
|
|
4142
3641
|
channels: this._transportChannels.size
|
|
4143
3642
|
};
|
|
4144
3643
|
}
|
|
4145
|
-
constructor(_factory, _options) {
|
|
4146
|
-
_define_property15(this, "_factory", void 0);
|
|
4147
|
-
_define_property15(this, "_options", void 0);
|
|
4148
|
-
_define_property15(this, "_channelCreatedCallbacks", void 0);
|
|
4149
|
-
_define_property15(this, "_transportChannels", void 0);
|
|
4150
|
-
_define_property15(this, "_dataChannels", void 0);
|
|
4151
|
-
_define_property15(this, "_readyForCandidates", void 0);
|
|
4152
|
-
_define_property15(this, "_offerProcessingMutex", void 0);
|
|
4153
|
-
_define_property15(this, "_initiator", void 0);
|
|
4154
|
-
_define_property15(this, "_connection", void 0);
|
|
4155
|
-
this._factory = _factory;
|
|
4156
|
-
this._options = _options;
|
|
4157
|
-
this._channelCreatedCallbacks = /* @__PURE__ */ new Map();
|
|
4158
|
-
this._transportChannels = /* @__PURE__ */ new Map();
|
|
4159
|
-
this._dataChannels = /* @__PURE__ */ new Map();
|
|
4160
|
-
this._readyForCandidates = new Trigger3();
|
|
4161
|
-
this._offerProcessingMutex = new Mutex2();
|
|
4162
|
-
this._initiator = chooseInitiatorPeer(_options.ownPeerKey, _options.remotePeerKey) === _options.ownPeerKey;
|
|
4163
|
-
}
|
|
4164
3644
|
};
|
|
4165
3645
|
_ts_decorate6([
|
|
4166
3646
|
synchronized5
|
|
@@ -4191,8 +3671,10 @@ var isRemoteDescriptionSet = (connection, data) => {
|
|
|
4191
3671
|
};
|
|
4192
3672
|
var createIceFailureError = (details) => {
|
|
4193
3673
|
const candidateErrors = details.map(({ url, errorCode, errorText }) => `${errorCode} ${url}: ${errorText}`);
|
|
4194
|
-
return new ConnectivityError3(
|
|
4195
|
-
|
|
3674
|
+
return new ConnectivityError3({
|
|
3675
|
+
message: `ICE failed:
|
|
3676
|
+
${candidateErrors.join("\n")}`
|
|
3677
|
+
});
|
|
4196
3678
|
};
|
|
4197
3679
|
|
|
4198
3680
|
// src/transport/webrtc/rtc-transport-factory.ts
|
|
@@ -4218,30 +3700,26 @@ import { Writable } from "@dxos/node-std/stream";
|
|
|
4218
3700
|
import { Event as Event8, scheduleTask as scheduleTask4 } from "@dxos/async";
|
|
4219
3701
|
import { Resource as Resource2 } from "@dxos/context";
|
|
4220
3702
|
import { ErrorStream as ErrorStream5 } from "@dxos/debug";
|
|
4221
|
-
import { invariant as
|
|
3703
|
+
import { invariant as invariant11 } from "@dxos/invariant";
|
|
4222
3704
|
import { PublicKey as PublicKey10 } from "@dxos/keys";
|
|
4223
|
-
import { log as
|
|
3705
|
+
import { log as log11 } from "@dxos/log";
|
|
4224
3706
|
import { ConnectionResetError as ConnectionResetError2, ConnectivityError as ConnectivityError4, TimeoutError as TimeoutError3 } from "@dxos/protocols";
|
|
4225
3707
|
import { ConnectionState as ConnectionState3 } from "@dxos/protocols/proto/dxos/mesh/bridge";
|
|
4226
3708
|
import { arrayToBuffer } from "@dxos/util";
|
|
4227
|
-
|
|
4228
|
-
if (key in obj) {
|
|
4229
|
-
Object.defineProperty(obj, key, {
|
|
4230
|
-
value,
|
|
4231
|
-
enumerable: true,
|
|
4232
|
-
configurable: true,
|
|
4233
|
-
writable: true
|
|
4234
|
-
});
|
|
4235
|
-
} else {
|
|
4236
|
-
obj[key] = value;
|
|
4237
|
-
}
|
|
4238
|
-
return obj;
|
|
4239
|
-
}
|
|
4240
|
-
var __dxlog_file15 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-proxy.ts";
|
|
3709
|
+
var __dxlog_file12 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-proxy.ts";
|
|
4241
3710
|
var RPC_TIMEOUT = 1e4;
|
|
4242
3711
|
var CLOSE_RPC_TIMEOUT = 3e3;
|
|
4243
3712
|
var RESP_MIN_THRESHOLD = 500;
|
|
4244
3713
|
var RtcTransportProxy = class extends Resource2 {
|
|
3714
|
+
_options;
|
|
3715
|
+
_proxyId = PublicKey10.random();
|
|
3716
|
+
closed = new Event8();
|
|
3717
|
+
connected = new Event8();
|
|
3718
|
+
errors = new ErrorStream5();
|
|
3719
|
+
_serviceStream;
|
|
3720
|
+
constructor(_options) {
|
|
3721
|
+
super(), this._options = _options;
|
|
3722
|
+
}
|
|
4245
3723
|
async _open() {
|
|
4246
3724
|
let stream;
|
|
4247
3725
|
try {
|
|
@@ -4261,8 +3739,8 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
4261
3739
|
this._serviceStream = stream;
|
|
4262
3740
|
stream.waitUntilReady().then(() => {
|
|
4263
3741
|
stream.subscribe(async (event) => {
|
|
4264
|
-
|
|
4265
|
-
F:
|
|
3742
|
+
log11("rtc transport proxy event", event, {
|
|
3743
|
+
F: __dxlog_file12,
|
|
4266
3744
|
L: 66,
|
|
4267
3745
|
S: this,
|
|
4268
3746
|
C: (f, a) => f(...a)
|
|
@@ -4275,10 +3753,10 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
4275
3753
|
await this._handleSignal(event.signal);
|
|
4276
3754
|
}
|
|
4277
3755
|
}, (err) => {
|
|
4278
|
-
|
|
3756
|
+
log11("rtc bridge stream closed", {
|
|
4279
3757
|
err
|
|
4280
3758
|
}, {
|
|
4281
|
-
F:
|
|
3759
|
+
F: __dxlog_file12,
|
|
4282
3760
|
L: 76,
|
|
4283
3761
|
S: this,
|
|
4284
3762
|
C: (f, a) => f(...a)
|
|
@@ -4299,8 +3777,8 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
4299
3777
|
timeout: RPC_TIMEOUT
|
|
4300
3778
|
}).then(() => {
|
|
4301
3779
|
if (Date.now() - sendStartMs > RESP_MIN_THRESHOLD) {
|
|
4302
|
-
|
|
4303
|
-
F:
|
|
3780
|
+
log11("slow response, delaying callback", void 0, {
|
|
3781
|
+
F: __dxlog_file12,
|
|
4304
3782
|
L: 93,
|
|
4305
3783
|
S: this,
|
|
4306
3784
|
C: (f, a) => f(...a)
|
|
@@ -4332,8 +3810,8 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
4332
3810
|
await this._serviceStream?.close();
|
|
4333
3811
|
this._serviceStream = void 0;
|
|
4334
3812
|
} catch (err) {
|
|
4335
|
-
|
|
4336
|
-
F:
|
|
3813
|
+
log11.catch(err, void 0, {
|
|
3814
|
+
F: __dxlog_file12,
|
|
4337
3815
|
L: 128,
|
|
4338
3816
|
S: this,
|
|
4339
3817
|
C: (f, a) => f(...a)
|
|
@@ -4346,8 +3824,8 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
4346
3824
|
timeout: CLOSE_RPC_TIMEOUT
|
|
4347
3825
|
});
|
|
4348
3826
|
} catch (err) {
|
|
4349
|
-
|
|
4350
|
-
F:
|
|
3827
|
+
log11.catch(err, void 0, {
|
|
3828
|
+
F: __dxlog_file12,
|
|
4351
3829
|
L: 134,
|
|
4352
3830
|
S: this,
|
|
4353
3831
|
C: (f, a) => f(...a)
|
|
@@ -4392,7 +3870,9 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
4392
3870
|
} catch (error) {
|
|
4393
3871
|
const type = signalEvent.payload.payload.data?.type;
|
|
4394
3872
|
if (type === "offer" || type === "answer") {
|
|
4395
|
-
this._raiseIfOpen(new ConnectivityError4(
|
|
3873
|
+
this._raiseIfOpen(new ConnectivityError4({
|
|
3874
|
+
message: `Session establishment failed: ${type} couldn't be sent.`
|
|
3875
|
+
}));
|
|
4396
3876
|
}
|
|
4397
3877
|
}
|
|
4398
3878
|
}
|
|
@@ -4430,11 +3910,11 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
4430
3910
|
if (this.isOpen) {
|
|
4431
3911
|
this.errors.raise(error);
|
|
4432
3912
|
} else {
|
|
4433
|
-
|
|
3913
|
+
log11.info("error swallowed because transport was closed", {
|
|
4434
3914
|
message: error.message
|
|
4435
3915
|
}, {
|
|
4436
|
-
F:
|
|
4437
|
-
L:
|
|
3916
|
+
F: __dxlog_file12,
|
|
3917
|
+
L: 217,
|
|
4438
3918
|
S: this,
|
|
4439
3919
|
C: (f, a) => f(...a)
|
|
4440
3920
|
});
|
|
@@ -4447,11 +3927,10 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
4447
3927
|
void this._serviceStream?.close();
|
|
4448
3928
|
this.closed.emit();
|
|
4449
3929
|
}
|
|
4450
|
-
constructor(_options) {
|
|
4451
|
-
super(), _define_property16(this, "_options", void 0), _define_property16(this, "_proxyId", void 0), _define_property16(this, "closed", void 0), _define_property16(this, "connected", void 0), _define_property16(this, "errors", void 0), _define_property16(this, "_serviceStream", void 0), this._options = _options, this._proxyId = PublicKey10.random(), this.closed = new Event8(), this.connected = new Event8(), this.errors = new ErrorStream5();
|
|
4452
|
-
}
|
|
4453
3930
|
};
|
|
4454
3931
|
var RtcTransportProxyFactory = class {
|
|
3932
|
+
_bridgeService;
|
|
3933
|
+
_connections = /* @__PURE__ */ new Set();
|
|
4455
3934
|
/**
|
|
4456
3935
|
* Sets the current BridgeService to be used to open connections.
|
|
4457
3936
|
* Calling this method will close any existing connections.
|
|
@@ -4464,9 +3943,9 @@ var RtcTransportProxyFactory = class {
|
|
|
4464
3943
|
return this;
|
|
4465
3944
|
}
|
|
4466
3945
|
createTransport(options) {
|
|
4467
|
-
|
|
4468
|
-
F:
|
|
4469
|
-
L:
|
|
3946
|
+
invariant11(this._bridgeService, "RtcTransportProxyFactory is not ready to open connections", {
|
|
3947
|
+
F: __dxlog_file12,
|
|
3948
|
+
L: 247,
|
|
4470
3949
|
S: this,
|
|
4471
3950
|
A: [
|
|
4472
3951
|
"this._bridgeService",
|
|
@@ -4483,19 +3962,21 @@ var RtcTransportProxyFactory = class {
|
|
|
4483
3962
|
});
|
|
4484
3963
|
return transport;
|
|
4485
3964
|
}
|
|
4486
|
-
constructor() {
|
|
4487
|
-
_define_property16(this, "_bridgeService", void 0);
|
|
4488
|
-
_define_property16(this, "_connections", /* @__PURE__ */ new Set());
|
|
4489
|
-
}
|
|
4490
3965
|
};
|
|
4491
3966
|
var decodeError = (err) => {
|
|
4492
3967
|
const message = typeof err === "string" ? err : err.message;
|
|
4493
3968
|
if (message.includes("CONNECTION_RESET")) {
|
|
4494
|
-
return new ConnectionResetError2(
|
|
3969
|
+
return new ConnectionResetError2({
|
|
3970
|
+
message
|
|
3971
|
+
});
|
|
4495
3972
|
} else if (message.includes("TIMEOUT")) {
|
|
4496
|
-
return new TimeoutError3(
|
|
3973
|
+
return new TimeoutError3({
|
|
3974
|
+
message
|
|
3975
|
+
});
|
|
4497
3976
|
} else if (message.includes("CONNECTIVITY_ERROR")) {
|
|
4498
|
-
return new ConnectivityError4(
|
|
3977
|
+
return new ConnectivityError4({
|
|
3978
|
+
message
|
|
3979
|
+
});
|
|
4499
3980
|
} else {
|
|
4500
3981
|
return typeof err === "string" ? new Error(err) : err;
|
|
4501
3982
|
}
|
|
@@ -4504,34 +3985,26 @@ var decodeError = (err) => {
|
|
|
4504
3985
|
// src/transport/webrtc/rtc-transport-service.ts
|
|
4505
3986
|
import { Duplex as Duplex2 } from "@dxos/node-std/stream";
|
|
4506
3987
|
import { Stream } from "@dxos/codec-protobuf/stream";
|
|
4507
|
-
import { invariant as
|
|
3988
|
+
import { invariant as invariant12 } from "@dxos/invariant";
|
|
4508
3989
|
import { PublicKey as PublicKey11 } from "@dxos/keys";
|
|
4509
|
-
import { log as
|
|
3990
|
+
import { log as log12 } from "@dxos/log";
|
|
4510
3991
|
import { ConnectionState as ConnectionState4 } from "@dxos/protocols/proto/dxos/mesh/bridge";
|
|
4511
3992
|
import { ComplexMap as ComplexMap8 } from "@dxos/util";
|
|
4512
|
-
|
|
4513
|
-
if (key in obj) {
|
|
4514
|
-
Object.defineProperty(obj, key, {
|
|
4515
|
-
value,
|
|
4516
|
-
enumerable: true,
|
|
4517
|
-
configurable: true,
|
|
4518
|
-
writable: true
|
|
4519
|
-
});
|
|
4520
|
-
} else {
|
|
4521
|
-
obj[key] = value;
|
|
4522
|
-
}
|
|
4523
|
-
return obj;
|
|
4524
|
-
}
|
|
4525
|
-
var __dxlog_file16 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-service.ts";
|
|
3993
|
+
var __dxlog_file13 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-service.ts";
|
|
4526
3994
|
var RtcTransportService = class {
|
|
3995
|
+
_transportFactory;
|
|
3996
|
+
_openTransports = new ComplexMap8(PublicKey11.hash);
|
|
3997
|
+
constructor(webrtcConfig, iceProvider, _transportFactory = createRtcTransportFactory(webrtcConfig, iceProvider)) {
|
|
3998
|
+
this._transportFactory = _transportFactory;
|
|
3999
|
+
}
|
|
4527
4000
|
hasOpenTransports() {
|
|
4528
4001
|
return this._openTransports.size > 0;
|
|
4529
4002
|
}
|
|
4530
4003
|
open(request) {
|
|
4531
4004
|
const existingTransport = this._openTransports.get(request.proxyId);
|
|
4532
4005
|
if (existingTransport) {
|
|
4533
|
-
|
|
4534
|
-
F:
|
|
4006
|
+
log12.error("requesting a new transport bridge for an existing proxy", void 0, {
|
|
4007
|
+
F: __dxlog_file13,
|
|
4535
4008
|
L: 54,
|
|
4536
4009
|
S: this,
|
|
4537
4010
|
C: (f, a) => f(...a)
|
|
@@ -4596,8 +4069,8 @@ var RtcTransportService = class {
|
|
|
4596
4069
|
close(err);
|
|
4597
4070
|
});
|
|
4598
4071
|
ready();
|
|
4599
|
-
|
|
4600
|
-
F:
|
|
4072
|
+
log12("stream ready", void 0, {
|
|
4073
|
+
F: __dxlog_file13,
|
|
4601
4074
|
L: 116,
|
|
4602
4075
|
S: this,
|
|
4603
4076
|
C: (f, a) => f(...a)
|
|
@@ -4607,8 +4080,8 @@ var RtcTransportService = class {
|
|
|
4607
4080
|
}
|
|
4608
4081
|
async sendSignal({ proxyId, signal }) {
|
|
4609
4082
|
const transport = this._openTransports.get(proxyId);
|
|
4610
|
-
|
|
4611
|
-
F:
|
|
4083
|
+
invariant12(transport, void 0, {
|
|
4084
|
+
F: __dxlog_file13,
|
|
4612
4085
|
L: 124,
|
|
4613
4086
|
S: this,
|
|
4614
4087
|
A: [
|
|
@@ -4620,8 +4093,8 @@ var RtcTransportService = class {
|
|
|
4620
4093
|
}
|
|
4621
4094
|
async getDetails({ proxyId }) {
|
|
4622
4095
|
const transport = this._openTransports.get(proxyId);
|
|
4623
|
-
|
|
4624
|
-
F:
|
|
4096
|
+
invariant12(transport, void 0, {
|
|
4097
|
+
F: __dxlog_file13,
|
|
4625
4098
|
L: 131,
|
|
4626
4099
|
S: this,
|
|
4627
4100
|
A: [
|
|
@@ -4635,8 +4108,8 @@ var RtcTransportService = class {
|
|
|
4635
4108
|
}
|
|
4636
4109
|
async getStats({ proxyId }) {
|
|
4637
4110
|
const transport = this._openTransports.get(proxyId);
|
|
4638
|
-
|
|
4639
|
-
F:
|
|
4111
|
+
invariant12(transport, void 0, {
|
|
4112
|
+
F: __dxlog_file13,
|
|
4640
4113
|
L: 138,
|
|
4641
4114
|
S: this,
|
|
4642
4115
|
A: [
|
|
@@ -4650,8 +4123,8 @@ var RtcTransportService = class {
|
|
|
4650
4123
|
}
|
|
4651
4124
|
async sendData({ proxyId, payload }) {
|
|
4652
4125
|
const transport = this._openTransports.get(proxyId);
|
|
4653
|
-
|
|
4654
|
-
F:
|
|
4126
|
+
invariant12(transport, void 0, {
|
|
4127
|
+
F: __dxlog_file13,
|
|
4655
4128
|
L: 145,
|
|
4656
4129
|
S: this,
|
|
4657
4130
|
A: [
|
|
@@ -4682,10 +4155,10 @@ var RtcTransportService = class {
|
|
|
4682
4155
|
try {
|
|
4683
4156
|
await transport.transport.close();
|
|
4684
4157
|
} catch (error) {
|
|
4685
|
-
|
|
4158
|
+
log12.warn("transport close error", {
|
|
4686
4159
|
message: error?.message
|
|
4687
4160
|
}, {
|
|
4688
|
-
F:
|
|
4161
|
+
F: __dxlog_file13,
|
|
4689
4162
|
L: 175,
|
|
4690
4163
|
S: this,
|
|
4691
4164
|
C: (f, a) => f(...a)
|
|
@@ -4694,28 +4167,22 @@ var RtcTransportService = class {
|
|
|
4694
4167
|
try {
|
|
4695
4168
|
transport.connectorStream.end();
|
|
4696
4169
|
} catch (error) {
|
|
4697
|
-
|
|
4170
|
+
log12.warn("connectorStream close error", {
|
|
4698
4171
|
message: error?.message
|
|
4699
4172
|
}, {
|
|
4700
|
-
F:
|
|
4173
|
+
F: __dxlog_file13,
|
|
4701
4174
|
L: 180,
|
|
4702
4175
|
S: this,
|
|
4703
4176
|
C: (f, a) => f(...a)
|
|
4704
4177
|
});
|
|
4705
4178
|
}
|
|
4706
|
-
|
|
4707
|
-
F:
|
|
4179
|
+
log12("closed", void 0, {
|
|
4180
|
+
F: __dxlog_file13,
|
|
4708
4181
|
L: 182,
|
|
4709
4182
|
S: this,
|
|
4710
4183
|
C: (f, a) => f(...a)
|
|
4711
4184
|
});
|
|
4712
4185
|
}
|
|
4713
|
-
constructor(webrtcConfig, iceProvider, _transportFactory = createRtcTransportFactory(webrtcConfig, iceProvider)) {
|
|
4714
|
-
_define_property17(this, "_transportFactory", void 0);
|
|
4715
|
-
_define_property17(this, "_openTransports", void 0);
|
|
4716
|
-
this._transportFactory = _transportFactory;
|
|
4717
|
-
this._openTransports = new ComplexMap8(PublicKey11.hash);
|
|
4718
|
-
}
|
|
4719
4186
|
};
|
|
4720
4187
|
var createStateUpdater = (next) => {
|
|
4721
4188
|
return (state, err) => {
|
|
@@ -4732,10 +4199,10 @@ var createStateUpdater = (next) => {
|
|
|
4732
4199
|
|
|
4733
4200
|
// src/wire-protocol.ts
|
|
4734
4201
|
import { Teleport } from "@dxos/teleport";
|
|
4735
|
-
var createTeleportProtocolFactory = (onConnection,
|
|
4202
|
+
var createTeleportProtocolFactory = (onConnection, defaultProps) => {
|
|
4736
4203
|
return (params) => {
|
|
4737
4204
|
const teleport = new Teleport({
|
|
4738
|
-
...
|
|
4205
|
+
...defaultProps,
|
|
4739
4206
|
...params
|
|
4740
4207
|
});
|
|
4741
4208
|
return {
|
|
@@ -4757,7 +4224,6 @@ var createTeleportProtocolFactory = (onConnection, defaultParams) => {
|
|
|
4757
4224
|
export {
|
|
4758
4225
|
ConnectionState,
|
|
4759
4226
|
Connection,
|
|
4760
|
-
createIceProvider,
|
|
4761
4227
|
SwarmMessenger,
|
|
4762
4228
|
Swarm,
|
|
4763
4229
|
SwarmMapper,
|
|
@@ -4767,8 +4233,6 @@ export {
|
|
|
4767
4233
|
ConnectionLog,
|
|
4768
4234
|
SwarmNetworkManager,
|
|
4769
4235
|
FullyConnectedTopology,
|
|
4770
|
-
MMSTTopology,
|
|
4771
|
-
StarTopology,
|
|
4772
4236
|
MemoryTransportFactory,
|
|
4773
4237
|
MemoryTransport,
|
|
4774
4238
|
TransportKind,
|
|
@@ -4778,4 +4242,4 @@ export {
|
|
|
4778
4242
|
RtcTransportService,
|
|
4779
4243
|
createTeleportProtocolFactory
|
|
4780
4244
|
};
|
|
4781
|
-
//# sourceMappingURL=chunk-
|
|
4245
|
+
//# sourceMappingURL=chunk-AQSYW43M.mjs.map
|