@dxos/network-manager 0.8.4-main.f5c0578 → 0.8.4-main.fcfe5033a5
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-JUVDHWW4.mjs → chunk-Y2FDDNGM.mjs} +617 -990
- package/dist/lib/browser/chunk-Y2FDDNGM.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 +55 -53
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/browser/transport/tcp/index.mjs +2 -33
- 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-HUSU3OKQ.mjs → chunk-OU3FYVBA.mjs} +617 -990
- package/dist/lib/node-esm/chunk-OU3FYVBA.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 +55 -53
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/transport/tcp/index.mjs +2 -164
- 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/network-manager.d.ts +5 -4
- package/dist/types/src/network-manager.d.ts.map +1 -1
- package/dist/types/src/signal/signal-connection.d.ts +3 -2
- package/dist/types/src/signal/signal-connection.d.ts.map +1 -1
- package/dist/types/src/signal/signal-messenger.d.ts +3 -2
- package/dist/types/src/signal/signal-messenger.d.ts.map +1 -1
- package/dist/types/src/signal/swarm-messenger.d.ts +7 -7
- package/dist/types/src/signal/swarm-messenger.d.ts.map +1 -1
- package/dist/types/src/swarm/connection.d.ts +2 -1
- package/dist/types/src/swarm/connection.d.ts.map +1 -1
- package/dist/types/src/swarm/peer.d.ts +4 -3
- package/dist/types/src/swarm/peer.d.ts.map +1 -1
- package/dist/types/src/swarm/swarm.d.ts +3 -2
- package/dist/types/src/swarm/swarm.d.ts.map +1 -1
- package/dist/types/src/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/tests/basic-test-suite.d.ts.map +1 -1
- package/dist/types/src/tests/property-test-suite.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-peer-connection.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc/rtc-transport-channel.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc/rtc-transport-factory.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc/rtc-transport-proxy.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc/rtc-transport-service.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 -33
- package/src/network-manager.ts +19 -15
- package/src/signal/integration.node.test.ts +11 -10
- package/src/signal/signal-connection.ts +3 -2
- package/src/signal/signal-messenger.ts +3 -2
- package/src/signal/swarm-messenger.node.test.ts +25 -24
- package/src/signal/swarm-messenger.ts +65 -55
- package/src/swarm/connection.test.ts +8 -8
- package/src/swarm/connection.ts +12 -10
- package/src/swarm/peer.ts +7 -7
- package/src/swarm/swarm.test.ts +4 -4
- package/src/swarm/swarm.ts +9 -10
- package/src/testing/test-builder.ts +4 -4
- package/src/tests/basic-test-suite.ts +0 -1
- package/src/tests/memory-transport.test.ts +0 -2
- package/src/tests/property-test-suite.ts +4 -3
- package/src/tests/tcp-transport.node.test.ts +0 -2
- package/src/tests/webrtc-transport.test.ts +4 -3
- package/src/transport/tcp/index.ts +1 -1
- package/src/transport/webrtc/rtc-peer-connection.ts +1 -2
- package/src/transport/webrtc/rtc-transport-channel.test.ts +0 -2
- package/src/transport/webrtc/rtc-transport-channel.ts +1 -2
- package/src/transport/webrtc/rtc-transport-factory.ts +0 -1
- package/src/transport/webrtc/rtc-transport-proxy.test.ts +2 -3
- package/src/transport/webrtc/rtc-transport-proxy.ts +6 -4
- package/src/transport/webrtc/rtc-transport-service.ts +0 -1
- package/src/transport/webrtc/rtc-transport.test.ts +2 -2
- package/src/wire-protocol.ts +6 -6
- package/dist/lib/browser/chunk-JUVDHWW4.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-HUSU3OKQ.mjs.map +0 -7
|
@@ -19,7 +19,7 @@ var STARTING_SIGNALLING_DELAY = 10;
|
|
|
19
19
|
var TRANSPORT_CONNECTION_TIMEOUT = 1e4;
|
|
20
20
|
var TRANSPORT_STATS_INTERVAL = 5e3;
|
|
21
21
|
var MAX_SIGNALLING_DELAY = 300;
|
|
22
|
-
var ConnectionState = /* @__PURE__ */ function(ConnectionState5) {
|
|
22
|
+
var ConnectionState = /* @__PURE__ */ (function(ConnectionState5) {
|
|
23
23
|
ConnectionState5["CREATED"] = "CREATED";
|
|
24
24
|
ConnectionState5["INITIAL"] = "INITIAL";
|
|
25
25
|
ConnectionState5["CONNECTING"] = "CONNECTING";
|
|
@@ -29,7 +29,7 @@ var ConnectionState = /* @__PURE__ */ function(ConnectionState5) {
|
|
|
29
29
|
ConnectionState5["ABORTING"] = "ABORTING";
|
|
30
30
|
ConnectionState5["ABORTED"] = "ABORTED";
|
|
31
31
|
return ConnectionState5;
|
|
32
|
-
}({});
|
|
32
|
+
})({});
|
|
33
33
|
var Connection = class {
|
|
34
34
|
topic;
|
|
35
35
|
localInfo;
|
|
@@ -40,21 +40,29 @@ var Connection = class {
|
|
|
40
40
|
_protocol;
|
|
41
41
|
_transportFactory;
|
|
42
42
|
_callbacks;
|
|
43
|
-
_ctx
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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";
|
|
48
54
|
_transport;
|
|
49
55
|
closeReason;
|
|
50
|
-
_incomingSignalBuffer;
|
|
51
|
-
_outgoingSignalBuffer;
|
|
52
|
-
stateChanged;
|
|
53
|
-
errors;
|
|
54
|
-
_instanceId;
|
|
55
|
-
transportStats;
|
|
56
|
-
_signalSendTask
|
|
57
|
-
|
|
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(this._ctx);
|
|
64
|
+
});
|
|
65
|
+
_signallingDelay = STARTING_SIGNALLING_DELAY;
|
|
58
66
|
constructor(topic, localInfo, remoteInfo, sessionId, initiator, _signalMessaging, _protocol, _transportFactory, _callbacks) {
|
|
59
67
|
this.topic = topic;
|
|
60
68
|
this.localInfo = localInfo;
|
|
@@ -65,27 +73,6 @@ var Connection = class {
|
|
|
65
73
|
this._protocol = _protocol;
|
|
66
74
|
this._transportFactory = _transportFactory;
|
|
67
75
|
this._callbacks = _callbacks;
|
|
68
|
-
this._ctx = new Context(void 0, {
|
|
69
|
-
F: __dxlog_file,
|
|
70
|
-
L: 100
|
|
71
|
-
});
|
|
72
|
-
this.connectedTimeoutContext = new Context(void 0, {
|
|
73
|
-
F: __dxlog_file,
|
|
74
|
-
L: 101
|
|
75
|
-
});
|
|
76
|
-
this._protocolClosed = new Trigger();
|
|
77
|
-
this._transportClosed = new Trigger();
|
|
78
|
-
this._state = "CREATED";
|
|
79
|
-
this._incomingSignalBuffer = [];
|
|
80
|
-
this._outgoingSignalBuffer = [];
|
|
81
|
-
this.stateChanged = new Event();
|
|
82
|
-
this.errors = new ErrorStream();
|
|
83
|
-
this._instanceId = PublicKey.random().toHex();
|
|
84
|
-
this.transportStats = new Event();
|
|
85
|
-
this._signalSendTask = new DeferredTask(this._ctx, async () => {
|
|
86
|
-
await this._flushSignalBuffer();
|
|
87
|
-
});
|
|
88
|
-
this._signallingDelay = STARTING_SIGNALLING_DELAY;
|
|
89
76
|
log.trace("dxos.mesh.connection.construct", {
|
|
90
77
|
sessionId: this.sessionId,
|
|
91
78
|
topic: this.topic,
|
|
@@ -157,21 +144,25 @@ var Connection = class {
|
|
|
157
144
|
});
|
|
158
145
|
this._protocolClosed.wake();
|
|
159
146
|
this.close({
|
|
160
|
-
error: new ProtocolError(
|
|
147
|
+
error: new ProtocolError({
|
|
148
|
+
message: "protocol stream closed"
|
|
149
|
+
})
|
|
161
150
|
}).catch((err) => this.errors.raise(err));
|
|
162
151
|
});
|
|
163
152
|
scheduleTask(this.connectedTimeoutContext, async () => {
|
|
164
153
|
log.info(`timeout waiting ${TRANSPORT_CONNECTION_TIMEOUT / 1e3}s for transport to connect, aborting`, void 0, {
|
|
165
154
|
F: __dxlog_file,
|
|
166
|
-
L:
|
|
155
|
+
L: 196,
|
|
167
156
|
S: this,
|
|
168
157
|
C: (f, a) => f(...a)
|
|
169
158
|
});
|
|
170
|
-
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));
|
|
171
162
|
}, TRANSPORT_CONNECTION_TIMEOUT);
|
|
172
163
|
invariant(!this._transport, void 0, {
|
|
173
164
|
F: __dxlog_file,
|
|
174
|
-
L:
|
|
165
|
+
L: 204,
|
|
175
166
|
S: this,
|
|
176
167
|
A: [
|
|
177
168
|
"!this._transport",
|
|
@@ -198,7 +189,7 @@ var Connection = class {
|
|
|
198
189
|
this._transportClosed.wake();
|
|
199
190
|
log("abort triggered by transport close", void 0, {
|
|
200
191
|
F: __dxlog_file,
|
|
201
|
-
L:
|
|
192
|
+
L: 226,
|
|
202
193
|
S: this,
|
|
203
194
|
C: (f, a) => f(...a)
|
|
204
195
|
});
|
|
@@ -209,7 +200,7 @@ var Connection = class {
|
|
|
209
200
|
err
|
|
210
201
|
}, {
|
|
211
202
|
F: __dxlog_file,
|
|
212
|
-
L:
|
|
203
|
+
L: 231,
|
|
213
204
|
S: this,
|
|
214
205
|
C: (f, a) => f(...a)
|
|
215
206
|
});
|
|
@@ -219,7 +210,7 @@ var Connection = class {
|
|
|
219
210
|
if (err instanceof ConnectionResetError) {
|
|
220
211
|
log.info("aborting due to transport ConnectionResetError", void 0, {
|
|
221
212
|
F: __dxlog_file,
|
|
222
|
-
L:
|
|
213
|
+
L: 238,
|
|
223
214
|
S: this,
|
|
224
215
|
C: (f, a) => f(...a)
|
|
225
216
|
});
|
|
@@ -227,7 +218,7 @@ var Connection = class {
|
|
|
227
218
|
} else if (err instanceof ConnectivityError) {
|
|
228
219
|
log.info("aborting due to transport ConnectivityError", void 0, {
|
|
229
220
|
F: __dxlog_file,
|
|
230
|
-
L:
|
|
221
|
+
L: 241,
|
|
231
222
|
S: this,
|
|
232
223
|
C: (f, a) => f(...a)
|
|
233
224
|
});
|
|
@@ -247,7 +238,7 @@ var Connection = class {
|
|
|
247
238
|
id: this._instanceId
|
|
248
239
|
}), {
|
|
249
240
|
F: __dxlog_file,
|
|
250
|
-
L:
|
|
241
|
+
L: 260,
|
|
251
242
|
S: this,
|
|
252
243
|
C: (f, a) => f(...a)
|
|
253
244
|
});
|
|
@@ -257,14 +248,14 @@ var Connection = class {
|
|
|
257
248
|
err
|
|
258
249
|
}, {
|
|
259
250
|
F: __dxlog_file,
|
|
260
|
-
L:
|
|
251
|
+
L: 267,
|
|
261
252
|
S: this,
|
|
262
253
|
C: (f, a) => f(...a)
|
|
263
254
|
});
|
|
264
255
|
if (this._state === "CLOSED" || this._state === "ABORTED") {
|
|
265
256
|
log(`abort ignored: already ${this._state}`, this.closeReason, {
|
|
266
257
|
F: __dxlog_file,
|
|
267
|
-
L:
|
|
258
|
+
L: 269,
|
|
268
259
|
S: this,
|
|
269
260
|
C: (f, a) => f(...a)
|
|
270
261
|
});
|
|
@@ -281,7 +272,7 @@ var Connection = class {
|
|
|
281
272
|
err
|
|
282
273
|
}, {
|
|
283
274
|
F: __dxlog_file,
|
|
284
|
-
L:
|
|
275
|
+
L: 281,
|
|
285
276
|
S: this,
|
|
286
277
|
C: (f, a) => f(...a)
|
|
287
278
|
});
|
|
@@ -292,7 +283,7 @@ var Connection = class {
|
|
|
292
283
|
} catch (err2) {
|
|
293
284
|
log.catch(err2, void 0, {
|
|
294
285
|
F: __dxlog_file,
|
|
295
|
-
L:
|
|
286
|
+
L: 287,
|
|
296
287
|
S: this,
|
|
297
288
|
C: (f, a) => f(...a)
|
|
298
289
|
});
|
|
@@ -302,7 +293,7 @@ var Connection = class {
|
|
|
302
293
|
} catch (err2) {
|
|
303
294
|
log.catch(err2, void 0, {
|
|
304
295
|
F: __dxlog_file,
|
|
305
|
-
L:
|
|
296
|
+
L: 294,
|
|
306
297
|
S: this,
|
|
307
298
|
C: (f, a) => f(...a)
|
|
308
299
|
});
|
|
@@ -312,7 +303,7 @@ var Connection = class {
|
|
|
312
303
|
} catch (err2) {
|
|
313
304
|
log.catch(err2, void 0, {
|
|
314
305
|
F: __dxlog_file,
|
|
315
|
-
L:
|
|
306
|
+
L: 300,
|
|
316
307
|
S: this,
|
|
317
308
|
C: (f, a) => f(...a)
|
|
318
309
|
});
|
|
@@ -324,7 +315,7 @@ var Connection = class {
|
|
|
324
315
|
error
|
|
325
316
|
}, {
|
|
326
317
|
F: __dxlog_file,
|
|
327
|
-
L:
|
|
318
|
+
L: 307,
|
|
328
319
|
S: this,
|
|
329
320
|
C: (f, a) => f(...a)
|
|
330
321
|
});
|
|
@@ -339,7 +330,7 @@ var Connection = class {
|
|
|
339
330
|
error
|
|
340
331
|
}, {
|
|
341
332
|
F: __dxlog_file,
|
|
342
|
-
L:
|
|
333
|
+
L: 318,
|
|
343
334
|
S: this,
|
|
344
335
|
C: (f, a) => f(...a)
|
|
345
336
|
});
|
|
@@ -353,7 +344,7 @@ var Connection = class {
|
|
|
353
344
|
if (lastState !== "CONNECTED" || error != null) {
|
|
354
345
|
log(`graceful close requested when we were in ${lastState} state? aborting`, void 0, {
|
|
355
346
|
F: __dxlog_file,
|
|
356
|
-
L:
|
|
347
|
+
L: 329,
|
|
357
348
|
S: this,
|
|
358
349
|
C: (f, a) => f(...a)
|
|
359
350
|
});
|
|
@@ -365,7 +356,7 @@ var Connection = class {
|
|
|
365
356
|
error
|
|
366
357
|
}, {
|
|
367
358
|
F: __dxlog_file,
|
|
368
|
-
L:
|
|
359
|
+
L: 333,
|
|
369
360
|
S: this,
|
|
370
361
|
C: (f, a) => f(...a)
|
|
371
362
|
});
|
|
@@ -376,7 +367,7 @@ var Connection = class {
|
|
|
376
367
|
} catch (err) {
|
|
377
368
|
log.catch(err, void 0, {
|
|
378
369
|
F: __dxlog_file,
|
|
379
|
-
L:
|
|
370
|
+
L: 338,
|
|
380
371
|
S: this,
|
|
381
372
|
C: (f, a) => f(...a)
|
|
382
373
|
});
|
|
@@ -386,7 +377,7 @@ var Connection = class {
|
|
|
386
377
|
} catch (err) {
|
|
387
378
|
log.catch(err, void 0, {
|
|
388
379
|
F: __dxlog_file,
|
|
389
|
-
L:
|
|
380
|
+
L: 344,
|
|
390
381
|
S: this,
|
|
391
382
|
C: (f, a) => f(...a)
|
|
392
383
|
});
|
|
@@ -395,7 +386,7 @@ var Connection = class {
|
|
|
395
386
|
peerId: this.localInfo
|
|
396
387
|
}, {
|
|
397
388
|
F: __dxlog_file,
|
|
398
|
-
L:
|
|
389
|
+
L: 347,
|
|
399
390
|
S: this,
|
|
400
391
|
C: (f, a) => f(...a)
|
|
401
392
|
});
|
|
@@ -405,7 +396,7 @@ var Connection = class {
|
|
|
405
396
|
async _closeProtocol(options) {
|
|
406
397
|
log("closing protocol", options, {
|
|
407
398
|
F: __dxlog_file,
|
|
408
|
-
L:
|
|
399
|
+
L: 353,
|
|
409
400
|
S: this,
|
|
410
401
|
C: (f, a) => f(...a)
|
|
411
402
|
});
|
|
@@ -415,7 +406,7 @@ var Connection = class {
|
|
|
415
406
|
]);
|
|
416
407
|
log("protocol closed", options, {
|
|
417
408
|
F: __dxlog_file,
|
|
418
|
-
L:
|
|
409
|
+
L: 355,
|
|
419
410
|
S: this,
|
|
420
411
|
C: (f, a) => f(...a)
|
|
421
412
|
});
|
|
@@ -423,7 +414,7 @@ var Connection = class {
|
|
|
423
414
|
async _closeTransport() {
|
|
424
415
|
log("closing transport", void 0, {
|
|
425
416
|
F: __dxlog_file,
|
|
426
|
-
L:
|
|
417
|
+
L: 359,
|
|
427
418
|
S: this,
|
|
428
419
|
C: (f, a) => f(...a)
|
|
429
420
|
});
|
|
@@ -433,7 +424,7 @@ var Connection = class {
|
|
|
433
424
|
]);
|
|
434
425
|
log("transport closed", void 0, {
|
|
435
426
|
F: __dxlog_file,
|
|
436
|
-
L:
|
|
427
|
+
L: 361,
|
|
437
428
|
S: this,
|
|
438
429
|
C: (f, a) => f(...a)
|
|
439
430
|
});
|
|
@@ -442,20 +433,20 @@ var Connection = class {
|
|
|
442
433
|
this._outgoingSignalBuffer.push(signal);
|
|
443
434
|
this._signalSendTask.schedule();
|
|
444
435
|
}
|
|
445
|
-
async _flushSignalBuffer() {
|
|
436
|
+
async _flushSignalBuffer(ctx) {
|
|
446
437
|
if (this._outgoingSignalBuffer.length === 0) {
|
|
447
438
|
return;
|
|
448
439
|
}
|
|
449
440
|
try {
|
|
450
441
|
if (true) {
|
|
451
|
-
await cancelWithContext(
|
|
442
|
+
await cancelWithContext(ctx, sleep(this._signallingDelay));
|
|
452
443
|
this._signallingDelay = Math.min(this._signallingDelay * 2, MAX_SIGNALLING_DELAY);
|
|
453
444
|
}
|
|
454
445
|
const signals = [
|
|
455
446
|
...this._outgoingSignalBuffer
|
|
456
447
|
];
|
|
457
448
|
this._outgoingSignalBuffer.length = 0;
|
|
458
|
-
await this._signalMessaging.signal({
|
|
449
|
+
await this._signalMessaging.signal(ctx, {
|
|
459
450
|
author: this.localInfo,
|
|
460
451
|
recipient: this.remoteInfo,
|
|
461
452
|
sessionId: this.sessionId,
|
|
@@ -474,22 +465,25 @@ var Connection = class {
|
|
|
474
465
|
err
|
|
475
466
|
}, {
|
|
476
467
|
F: __dxlog_file,
|
|
477
|
-
L:
|
|
468
|
+
L: 401,
|
|
478
469
|
S: this,
|
|
479
470
|
C: (f, a) => f(...a)
|
|
480
471
|
});
|
|
481
472
|
await this.close({
|
|
482
|
-
error: new ConnectivityError(
|
|
473
|
+
error: new ConnectivityError({
|
|
474
|
+
message: "signal message failed to deliver",
|
|
475
|
+
cause: err
|
|
476
|
+
})
|
|
483
477
|
});
|
|
484
478
|
}
|
|
485
479
|
}
|
|
486
480
|
/**
|
|
487
481
|
* Receive a signal from the remote peer.
|
|
488
482
|
*/
|
|
489
|
-
async signal(msg) {
|
|
483
|
+
async signal(_ctx, msg) {
|
|
490
484
|
invariant(msg.sessionId, void 0, {
|
|
491
485
|
F: __dxlog_file,
|
|
492
|
-
L:
|
|
486
|
+
L: 410,
|
|
493
487
|
S: this,
|
|
494
488
|
A: [
|
|
495
489
|
"msg.sessionId",
|
|
@@ -499,7 +493,7 @@ var Connection = class {
|
|
|
499
493
|
if (!msg.sessionId.equals(this.sessionId)) {
|
|
500
494
|
log("dropping signal for incorrect session id", void 0, {
|
|
501
495
|
F: __dxlog_file,
|
|
502
|
-
L:
|
|
496
|
+
L: 412,
|
|
503
497
|
S: this,
|
|
504
498
|
C: (f, a) => f(...a)
|
|
505
499
|
});
|
|
@@ -507,7 +501,7 @@ var Connection = class {
|
|
|
507
501
|
}
|
|
508
502
|
invariant(msg.data.signal || msg.data.signalBatch, void 0, {
|
|
509
503
|
F: __dxlog_file,
|
|
510
|
-
L:
|
|
504
|
+
L: 415,
|
|
511
505
|
S: this,
|
|
512
506
|
A: [
|
|
513
507
|
"msg.data.signal || msg.data.signalBatch",
|
|
@@ -516,7 +510,7 @@ var Connection = class {
|
|
|
516
510
|
});
|
|
517
511
|
invariant(msg.author.peerKey === this.remoteInfo.peerKey, void 0, {
|
|
518
512
|
F: __dxlog_file,
|
|
519
|
-
L:
|
|
513
|
+
L: 416,
|
|
520
514
|
S: this,
|
|
521
515
|
A: [
|
|
522
516
|
"msg.author.peerKey === this.remoteInfo.peerKey",
|
|
@@ -525,7 +519,7 @@ var Connection = class {
|
|
|
525
519
|
});
|
|
526
520
|
invariant(msg.recipient.peerKey === this.localInfo.peerKey, void 0, {
|
|
527
521
|
F: __dxlog_file,
|
|
528
|
-
L:
|
|
522
|
+
L: 417,
|
|
529
523
|
S: this,
|
|
530
524
|
A: [
|
|
531
525
|
"msg.recipient.peerKey === this.localInfo.peerKey",
|
|
@@ -549,7 +543,7 @@ var Connection = class {
|
|
|
549
543
|
msg: msg.data
|
|
550
544
|
}, {
|
|
551
545
|
F: __dxlog_file,
|
|
552
|
-
L:
|
|
546
|
+
L: 426,
|
|
553
547
|
S: this,
|
|
554
548
|
C: (f, a) => f(...a)
|
|
555
549
|
});
|
|
@@ -557,7 +551,7 @@ var Connection = class {
|
|
|
557
551
|
} else {
|
|
558
552
|
invariant(this._transport, "Connection not ready to accept signals.", {
|
|
559
553
|
F: __dxlog_file,
|
|
560
|
-
L:
|
|
554
|
+
L: 429,
|
|
561
555
|
S: this,
|
|
562
556
|
A: [
|
|
563
557
|
"this._transport",
|
|
@@ -570,7 +564,7 @@ var Connection = class {
|
|
|
570
564
|
msg: msg.data
|
|
571
565
|
}, {
|
|
572
566
|
F: __dxlog_file,
|
|
573
|
-
L:
|
|
567
|
+
L: 430,
|
|
574
568
|
S: this,
|
|
575
569
|
C: (f, a) => f(...a)
|
|
576
570
|
});
|
|
@@ -588,13 +582,13 @@ var Connection = class {
|
|
|
588
582
|
peerId: this.localInfo
|
|
589
583
|
}, {
|
|
590
584
|
F: __dxlog_file,
|
|
591
|
-
L:
|
|
585
|
+
L: 441,
|
|
592
586
|
S: this,
|
|
593
587
|
C: (f, a) => f(...a)
|
|
594
588
|
});
|
|
595
589
|
invariant(state !== this._state, "Already in this state.", {
|
|
596
590
|
F: __dxlog_file,
|
|
597
|
-
L:
|
|
591
|
+
L: 442,
|
|
598
592
|
S: this,
|
|
599
593
|
A: [
|
|
600
594
|
"state !== this._state",
|
|
@@ -621,54 +615,16 @@ _ts_decorate([
|
|
|
621
615
|
synchronized
|
|
622
616
|
], Connection.prototype, "close", null);
|
|
623
617
|
|
|
624
|
-
// src/signal/ice.ts
|
|
625
|
-
import { asyncTimeout } from "@dxos/async";
|
|
626
|
-
import { log as log2 } from "@dxos/log";
|
|
627
|
-
import { isNonNullable } from "@dxos/util";
|
|
628
|
-
var __dxlog_file2 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/signal/ice.ts";
|
|
629
|
-
var createIceProvider = (iceProviders) => {
|
|
630
|
-
let cachedIceServers;
|
|
631
|
-
return {
|
|
632
|
-
getIceServers: async () => {
|
|
633
|
-
if (cachedIceServers) {
|
|
634
|
-
return cachedIceServers;
|
|
635
|
-
}
|
|
636
|
-
cachedIceServers = (await Promise.all(iceProviders.map(({ urls }) => asyncTimeout(fetch(urls, {
|
|
637
|
-
method: "GET"
|
|
638
|
-
}), 1e4).then((response) => response.json()).catch((err) => {
|
|
639
|
-
const isDev = typeof window !== "undefined" && window.location.href.includes("localhost");
|
|
640
|
-
if (!isDev) {
|
|
641
|
-
log2.error("Failed to fetch ICE servers from provider", {
|
|
642
|
-
urls,
|
|
643
|
-
err
|
|
644
|
-
}, {
|
|
645
|
-
F: __dxlog_file2,
|
|
646
|
-
L: 30,
|
|
647
|
-
S: void 0,
|
|
648
|
-
C: (f, a) => f(...a)
|
|
649
|
-
});
|
|
650
|
-
}
|
|
651
|
-
})))).filter(isNonNullable).map(({ iceServers }) => iceServers).flat();
|
|
652
|
-
return cachedIceServers;
|
|
653
|
-
}
|
|
654
|
-
};
|
|
655
|
-
};
|
|
656
|
-
|
|
657
618
|
// src/signal/swarm-messenger.ts
|
|
658
|
-
import { Context as Context2 } from "@dxos/context";
|
|
659
619
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
660
620
|
import { PublicKey as PublicKey2 } from "@dxos/keys";
|
|
661
|
-
import { log as
|
|
621
|
+
import { log as log2 } from "@dxos/log";
|
|
662
622
|
import { TimeoutError as TimeoutError2 } from "@dxos/protocols";
|
|
663
623
|
import { schema } from "@dxos/protocols/proto";
|
|
664
624
|
import { ComplexMap } from "@dxos/util";
|
|
665
|
-
var
|
|
625
|
+
var __dxlog_file2 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
|
|
666
626
|
var SwarmMessage = schema.getCodecForType("dxos.mesh.swarm.SwarmMessage");
|
|
667
627
|
var SwarmMessenger = class {
|
|
668
|
-
_ctx = new Context2(void 0, {
|
|
669
|
-
F: __dxlog_file3,
|
|
670
|
-
L: 35
|
|
671
|
-
});
|
|
672
628
|
_sendMessage;
|
|
673
629
|
_onSignal;
|
|
674
630
|
_onOffer;
|
|
@@ -680,7 +636,7 @@ var SwarmMessenger = class {
|
|
|
680
636
|
this._onOffer = onOffer;
|
|
681
637
|
this._topic = topic;
|
|
682
638
|
}
|
|
683
|
-
async receiveMessage({ author, recipient, payload }) {
|
|
639
|
+
async receiveMessage(ctx, { author, recipient, payload }) {
|
|
684
640
|
if (payload.type_url !== "dxos.mesh.swarm.SwarmMessage") {
|
|
685
641
|
return;
|
|
686
642
|
}
|
|
@@ -688,18 +644,18 @@ var SwarmMessenger = class {
|
|
|
688
644
|
if (!this._topic.equals(message.topic)) {
|
|
689
645
|
return;
|
|
690
646
|
}
|
|
691
|
-
|
|
647
|
+
log2("received", {
|
|
692
648
|
from: author,
|
|
693
649
|
to: recipient,
|
|
694
650
|
msg: message
|
|
695
651
|
}, {
|
|
696
|
-
F:
|
|
697
|
-
L:
|
|
652
|
+
F: __dxlog_file2,
|
|
653
|
+
L: 72,
|
|
698
654
|
S: this,
|
|
699
655
|
C: (f, a) => f(...a)
|
|
700
656
|
});
|
|
701
657
|
if (message.data?.offer) {
|
|
702
|
-
await this._handleOffer({
|
|
658
|
+
await this._handleOffer(ctx, {
|
|
703
659
|
author,
|
|
704
660
|
recipient,
|
|
705
661
|
message
|
|
@@ -707,45 +663,45 @@ var SwarmMessenger = class {
|
|
|
707
663
|
} else if (message.data?.answer) {
|
|
708
664
|
await this._resolveAnswers(message);
|
|
709
665
|
} else if (message.data?.signal) {
|
|
710
|
-
await this._handleSignal({
|
|
666
|
+
await this._handleSignal(ctx, {
|
|
711
667
|
author,
|
|
712
668
|
recipient,
|
|
713
669
|
message
|
|
714
670
|
});
|
|
715
671
|
} else if (message.data?.signalBatch) {
|
|
716
|
-
await this._handleSignal({
|
|
672
|
+
await this._handleSignal(ctx, {
|
|
717
673
|
author,
|
|
718
674
|
recipient,
|
|
719
675
|
message
|
|
720
676
|
});
|
|
721
677
|
} else {
|
|
722
|
-
|
|
678
|
+
log2.warn("unknown message", {
|
|
723
679
|
message
|
|
724
680
|
}, {
|
|
725
|
-
F:
|
|
726
|
-
L:
|
|
681
|
+
F: __dxlog_file2,
|
|
682
|
+
L: 83,
|
|
727
683
|
S: this,
|
|
728
684
|
C: (f, a) => f(...a)
|
|
729
685
|
});
|
|
730
686
|
}
|
|
731
687
|
}
|
|
732
|
-
async signal(message) {
|
|
688
|
+
async signal(ctx, message) {
|
|
733
689
|
invariant2(message.data?.signal || message.data?.signalBatch, "Invalid message", {
|
|
734
|
-
F:
|
|
735
|
-
L:
|
|
690
|
+
F: __dxlog_file2,
|
|
691
|
+
L: 88,
|
|
736
692
|
S: this,
|
|
737
693
|
A: [
|
|
738
694
|
"message.data?.signal || message.data?.signalBatch",
|
|
739
695
|
"'Invalid message'"
|
|
740
696
|
]
|
|
741
697
|
});
|
|
742
|
-
await this._sendReliableMessage({
|
|
698
|
+
await this._sendReliableMessage(ctx, {
|
|
743
699
|
author: message.author,
|
|
744
700
|
recipient: message.recipient,
|
|
745
701
|
message
|
|
746
702
|
});
|
|
747
703
|
}
|
|
748
|
-
async offer(message) {
|
|
704
|
+
async offer(ctx, message) {
|
|
749
705
|
const networkMessage = {
|
|
750
706
|
...message,
|
|
751
707
|
messageId: PublicKey2.random()
|
|
@@ -754,30 +710,30 @@ var SwarmMessenger = class {
|
|
|
754
710
|
this._offerRecords.set(networkMessage.messageId, {
|
|
755
711
|
resolve
|
|
756
712
|
});
|
|
757
|
-
this._sendReliableMessage({
|
|
713
|
+
this._sendReliableMessage(ctx, {
|
|
758
714
|
author: message.author,
|
|
759
715
|
recipient: message.recipient,
|
|
760
716
|
message: networkMessage
|
|
761
717
|
}).catch((err) => reject(err));
|
|
762
718
|
});
|
|
763
719
|
}
|
|
764
|
-
async _sendReliableMessage({ author, recipient, message }) {
|
|
720
|
+
async _sendReliableMessage(ctx, { author, recipient, message }) {
|
|
765
721
|
const networkMessage = {
|
|
766
722
|
...message,
|
|
767
723
|
// Setting unique message_id if it not specified yet.
|
|
768
724
|
messageId: message.messageId ?? PublicKey2.random()
|
|
769
725
|
};
|
|
770
|
-
|
|
726
|
+
log2("sending", {
|
|
771
727
|
from: author,
|
|
772
728
|
to: recipient,
|
|
773
729
|
msg: networkMessage
|
|
774
730
|
}, {
|
|
775
|
-
F:
|
|
776
|
-
L:
|
|
731
|
+
F: __dxlog_file2,
|
|
732
|
+
L: 129,
|
|
777
733
|
S: this,
|
|
778
734
|
C: (f, a) => f(...a)
|
|
779
735
|
});
|
|
780
|
-
await this._sendMessage({
|
|
736
|
+
await this._sendMessage(ctx, {
|
|
781
737
|
author,
|
|
782
738
|
recipient,
|
|
783
739
|
payload: {
|
|
@@ -788,8 +744,8 @@ var SwarmMessenger = class {
|
|
|
788
744
|
}
|
|
789
745
|
async _resolveAnswers(message) {
|
|
790
746
|
invariant2(message.data?.answer?.offerMessageId, "No offerMessageId", {
|
|
791
|
-
F:
|
|
792
|
-
L:
|
|
747
|
+
F: __dxlog_file2,
|
|
748
|
+
L: 141,
|
|
793
749
|
S: this,
|
|
794
750
|
A: [
|
|
795
751
|
"message.data?.answer?.offerMessageId",
|
|
@@ -800,29 +756,29 @@ var SwarmMessenger = class {
|
|
|
800
756
|
if (offerRecord) {
|
|
801
757
|
this._offerRecords.delete(message.data.answer.offerMessageId);
|
|
802
758
|
invariant2(message.data?.answer, "No answer", {
|
|
803
|
-
F:
|
|
804
|
-
L:
|
|
759
|
+
F: __dxlog_file2,
|
|
760
|
+
L: 145,
|
|
805
761
|
S: this,
|
|
806
762
|
A: [
|
|
807
763
|
"message.data?.answer",
|
|
808
764
|
"'No answer'"
|
|
809
765
|
]
|
|
810
766
|
});
|
|
811
|
-
|
|
767
|
+
log2("resolving", {
|
|
812
768
|
answer: message.data.answer
|
|
813
769
|
}, {
|
|
814
|
-
F:
|
|
815
|
-
L:
|
|
770
|
+
F: __dxlog_file2,
|
|
771
|
+
L: 146,
|
|
816
772
|
S: this,
|
|
817
773
|
C: (f, a) => f(...a)
|
|
818
774
|
});
|
|
819
775
|
offerRecord.resolve(message.data.answer);
|
|
820
776
|
}
|
|
821
777
|
}
|
|
822
|
-
async _handleOffer({ author, recipient, message }) {
|
|
778
|
+
async _handleOffer(ctx, { author, recipient, message }) {
|
|
823
779
|
invariant2(message.data.offer, "No offer", {
|
|
824
|
-
F:
|
|
825
|
-
L:
|
|
780
|
+
F: __dxlog_file2,
|
|
781
|
+
L: 163,
|
|
826
782
|
S: this,
|
|
827
783
|
A: [
|
|
828
784
|
"message.data.offer",
|
|
@@ -837,10 +793,10 @@ var SwarmMessenger = class {
|
|
|
837
793
|
offer: message.data.offer
|
|
838
794
|
}
|
|
839
795
|
};
|
|
840
|
-
const answer = await this._onOffer(offerMessage);
|
|
796
|
+
const answer = await this._onOffer(ctx, offerMessage);
|
|
841
797
|
answer.offerMessageId = message.messageId;
|
|
842
798
|
try {
|
|
843
|
-
await this._sendReliableMessage({
|
|
799
|
+
await this._sendReliableMessage(ctx, {
|
|
844
800
|
author: recipient,
|
|
845
801
|
recipient: author,
|
|
846
802
|
message: {
|
|
@@ -853,30 +809,30 @@ var SwarmMessenger = class {
|
|
|
853
809
|
});
|
|
854
810
|
} catch (err) {
|
|
855
811
|
if (err instanceof TimeoutError2) {
|
|
856
|
-
|
|
812
|
+
log2.info("timeout sending answer to offer", {
|
|
857
813
|
err
|
|
858
814
|
}, {
|
|
859
|
-
F:
|
|
860
|
-
L:
|
|
815
|
+
F: __dxlog_file2,
|
|
816
|
+
L: 184,
|
|
861
817
|
S: this,
|
|
862
818
|
C: (f, a) => f(...a)
|
|
863
819
|
});
|
|
864
820
|
} else {
|
|
865
|
-
|
|
821
|
+
log2.info("error sending answer to offer", {
|
|
866
822
|
err
|
|
867
823
|
}, {
|
|
868
|
-
F:
|
|
869
|
-
L:
|
|
824
|
+
F: __dxlog_file2,
|
|
825
|
+
L: 186,
|
|
870
826
|
S: this,
|
|
871
827
|
C: (f, a) => f(...a)
|
|
872
828
|
});
|
|
873
829
|
}
|
|
874
830
|
}
|
|
875
831
|
}
|
|
876
|
-
async _handleSignal({ author, recipient, message }) {
|
|
832
|
+
async _handleSignal(ctx, { author, recipient, message }) {
|
|
877
833
|
invariant2(message.messageId, void 0, {
|
|
878
|
-
F:
|
|
879
|
-
L:
|
|
834
|
+
F: __dxlog_file2,
|
|
835
|
+
L: 203,
|
|
880
836
|
S: this,
|
|
881
837
|
A: [
|
|
882
838
|
"message.messageId",
|
|
@@ -884,8 +840,8 @@ var SwarmMessenger = class {
|
|
|
884
840
|
]
|
|
885
841
|
});
|
|
886
842
|
invariant2(message.data.signal || message.data.signalBatch, "Invalid message", {
|
|
887
|
-
F:
|
|
888
|
-
L:
|
|
843
|
+
F: __dxlog_file2,
|
|
844
|
+
L: 204,
|
|
889
845
|
S: this,
|
|
890
846
|
A: [
|
|
891
847
|
"message.data.signal || message.data.signalBatch",
|
|
@@ -901,27 +857,27 @@ var SwarmMessenger = class {
|
|
|
901
857
|
signalBatch: message.data.signalBatch
|
|
902
858
|
}
|
|
903
859
|
};
|
|
904
|
-
await this._onSignal(signalMessage);
|
|
860
|
+
await this._onSignal(ctx, signalMessage);
|
|
905
861
|
}
|
|
906
862
|
};
|
|
907
863
|
|
|
908
864
|
// src/swarm/swarm.ts
|
|
909
865
|
import { Event as Event3, scheduleTask as scheduleTask3, sleep as sleep2, synchronized as synchronized3 } from "@dxos/async";
|
|
910
|
-
import { Context as
|
|
866
|
+
import { Context as Context3 } from "@dxos/context";
|
|
911
867
|
import { ErrorStream as ErrorStream2 } from "@dxos/debug";
|
|
912
868
|
import { invariant as invariant4 } from "@dxos/invariant";
|
|
913
869
|
import { PublicKey as PublicKey4 } from "@dxos/keys";
|
|
914
|
-
import { log as
|
|
870
|
+
import { log as log4, logInfo as logInfo2 } from "@dxos/log";
|
|
915
871
|
import { PeerInfoHash } from "@dxos/messaging";
|
|
916
872
|
import { trace as trace2 } from "@dxos/protocols";
|
|
917
|
-
import { ComplexMap as ComplexMap2, isNonNullable
|
|
873
|
+
import { ComplexMap as ComplexMap2, isNonNullable } from "@dxos/util";
|
|
918
874
|
|
|
919
875
|
// src/swarm/peer.ts
|
|
920
876
|
import { Event as Event2, scheduleTask as scheduleTask2, synchronized as synchronized2 } from "@dxos/async";
|
|
921
|
-
import { Context as
|
|
877
|
+
import { Context as Context2 } from "@dxos/context";
|
|
922
878
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
923
879
|
import { PublicKey as PublicKey3 } from "@dxos/keys";
|
|
924
|
-
import { log as
|
|
880
|
+
import { log as log3 } from "@dxos/log";
|
|
925
881
|
import { CancelledError as CancelledError2, SystemError } from "@dxos/protocols";
|
|
926
882
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
927
883
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -929,10 +885,12 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
929
885
|
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;
|
|
930
886
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
931
887
|
}
|
|
932
|
-
var
|
|
888
|
+
var __dxlog_file3 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts";
|
|
933
889
|
var ConnectionDisplacedError = class extends SystemError {
|
|
934
890
|
constructor() {
|
|
935
|
-
super(
|
|
891
|
+
super({
|
|
892
|
+
message: "Connection displaced by remote initiator."
|
|
893
|
+
});
|
|
936
894
|
}
|
|
937
895
|
};
|
|
938
896
|
var CONNECTION_COUNTS_STABLE_AFTER = 5e3;
|
|
@@ -948,18 +906,21 @@ var Peer = class {
|
|
|
948
906
|
/**
|
|
949
907
|
* Will be available to connect after this time.
|
|
950
908
|
*/
|
|
951
|
-
_availableAfter;
|
|
952
|
-
availableToConnect;
|
|
909
|
+
_availableAfter = 0;
|
|
910
|
+
availableToConnect = true;
|
|
953
911
|
_lastConnectionTime;
|
|
954
|
-
_ctx
|
|
912
|
+
_ctx = new Context2(void 0, {
|
|
913
|
+
F: __dxlog_file3,
|
|
914
|
+
L: 80
|
|
915
|
+
});
|
|
955
916
|
_connectionCtx;
|
|
956
917
|
connection;
|
|
957
918
|
/**
|
|
958
919
|
* Whether the peer is currently advertizing itself on the signal-network.
|
|
959
920
|
*/
|
|
960
|
-
advertizing;
|
|
961
|
-
initiating;
|
|
962
|
-
connectionDisplaced;
|
|
921
|
+
advertizing = false;
|
|
922
|
+
initiating = false;
|
|
923
|
+
connectionDisplaced = new Event2();
|
|
963
924
|
constructor(remoteInfo, topic, localInfo, _signalMessaging, _protocolProvider, _transportFactory, _connectionLimiter, _callbacks) {
|
|
964
925
|
this.remoteInfo = remoteInfo;
|
|
965
926
|
this.topic = topic;
|
|
@@ -969,29 +930,20 @@ var Peer = class {
|
|
|
969
930
|
this._transportFactory = _transportFactory;
|
|
970
931
|
this._connectionLimiter = _connectionLimiter;
|
|
971
932
|
this._callbacks = _callbacks;
|
|
972
|
-
this._availableAfter = 0;
|
|
973
|
-
this.availableToConnect = true;
|
|
974
|
-
this._ctx = new Context3(void 0, {
|
|
975
|
-
F: __dxlog_file4,
|
|
976
|
-
L: 81
|
|
977
|
-
});
|
|
978
|
-
this.advertizing = false;
|
|
979
|
-
this.initiating = false;
|
|
980
|
-
this.connectionDisplaced = new Event2();
|
|
981
933
|
}
|
|
982
934
|
/**
|
|
983
935
|
* Respond to remote offer.
|
|
984
936
|
*/
|
|
985
|
-
async onOffer(message) {
|
|
937
|
+
async onOffer(_ctx, message) {
|
|
986
938
|
const remote = message.author;
|
|
987
939
|
if (this.connection && ![
|
|
988
940
|
ConnectionState.CREATED,
|
|
989
941
|
ConnectionState.INITIAL,
|
|
990
942
|
ConnectionState.CONNECTING
|
|
991
943
|
].includes(this.connection.state)) {
|
|
992
|
-
|
|
993
|
-
F:
|
|
994
|
-
L:
|
|
944
|
+
log3.info(`received offer when connection already in ${this.connection.state} state`, void 0, {
|
|
945
|
+
F: __dxlog_file3,
|
|
946
|
+
L: 115,
|
|
995
947
|
S: this,
|
|
996
948
|
C: (f, a) => f(...a)
|
|
997
949
|
});
|
|
@@ -1001,14 +953,14 @@ var Peer = class {
|
|
|
1001
953
|
}
|
|
1002
954
|
if (this.connection || this.initiating) {
|
|
1003
955
|
if (remote.peerKey < this.localInfo.peerKey) {
|
|
1004
|
-
|
|
956
|
+
log3("close local connection", {
|
|
1005
957
|
localPeer: this.localInfo,
|
|
1006
958
|
topic: this.topic,
|
|
1007
959
|
remotePeer: this.remoteInfo,
|
|
1008
960
|
sessionId: this.connection?.sessionId
|
|
1009
961
|
}, {
|
|
1010
|
-
F:
|
|
1011
|
-
L:
|
|
962
|
+
F: __dxlog_file3,
|
|
963
|
+
L: 124,
|
|
1012
964
|
S: this,
|
|
1013
965
|
C: (f, a) => f(...a)
|
|
1014
966
|
});
|
|
@@ -1024,8 +976,8 @@ var Peer = class {
|
|
|
1024
976
|
if (await this._callbacks.onOffer(remote)) {
|
|
1025
977
|
if (!this.connection) {
|
|
1026
978
|
invariant3(message.sessionId, void 0, {
|
|
1027
|
-
F:
|
|
1028
|
-
L:
|
|
979
|
+
F: __dxlog_file3,
|
|
980
|
+
L: 144,
|
|
1029
981
|
S: this,
|
|
1030
982
|
A: [
|
|
1031
983
|
"message.sessionId",
|
|
@@ -1039,14 +991,14 @@ var Peer = class {
|
|
|
1039
991
|
await connection.openConnection();
|
|
1040
992
|
} catch (err) {
|
|
1041
993
|
if (!(err instanceof CancelledError2)) {
|
|
1042
|
-
|
|
994
|
+
log3.info("connection error", {
|
|
1043
995
|
topic: this.topic,
|
|
1044
996
|
peerId: this.localInfo,
|
|
1045
997
|
remoteId: this.remoteInfo,
|
|
1046
998
|
err
|
|
1047
999
|
}, {
|
|
1048
|
-
F:
|
|
1049
|
-
L:
|
|
1000
|
+
F: __dxlog_file3,
|
|
1001
|
+
L: 154,
|
|
1050
1002
|
S: this,
|
|
1051
1003
|
C: (f, a) => f(...a)
|
|
1052
1004
|
});
|
|
@@ -1065,9 +1017,9 @@ var Peer = class {
|
|
|
1065
1017
|
/**
|
|
1066
1018
|
* Initiate a connection to the remote peer.
|
|
1067
1019
|
*/
|
|
1068
|
-
async initiateConnection() {
|
|
1020
|
+
async initiateConnection(ctx) {
|
|
1069
1021
|
invariant3(!this.initiating, "Initiation in progress.", {
|
|
1070
|
-
F:
|
|
1022
|
+
F: __dxlog_file3,
|
|
1071
1023
|
L: 172,
|
|
1072
1024
|
S: this,
|
|
1073
1025
|
A: [
|
|
@@ -1076,7 +1028,7 @@ var Peer = class {
|
|
|
1076
1028
|
]
|
|
1077
1029
|
});
|
|
1078
1030
|
invariant3(!this.connection, "Already connected.", {
|
|
1079
|
-
F:
|
|
1031
|
+
F: __dxlog_file3,
|
|
1080
1032
|
L: 173,
|
|
1081
1033
|
S: this,
|
|
1082
1034
|
A: [
|
|
@@ -1085,13 +1037,13 @@ var Peer = class {
|
|
|
1085
1037
|
]
|
|
1086
1038
|
});
|
|
1087
1039
|
const sessionId = PublicKey3.random();
|
|
1088
|
-
|
|
1040
|
+
log3("initiating...", {
|
|
1089
1041
|
local: this.localInfo,
|
|
1090
1042
|
topic: this.topic,
|
|
1091
1043
|
remote: this.remoteInfo,
|
|
1092
1044
|
sessionId
|
|
1093
1045
|
}, {
|
|
1094
|
-
F:
|
|
1046
|
+
F: __dxlog_file3,
|
|
1095
1047
|
L: 175,
|
|
1096
1048
|
S: this,
|
|
1097
1049
|
C: (f, a) => f(...a)
|
|
@@ -1102,7 +1054,7 @@ var Peer = class {
|
|
|
1102
1054
|
try {
|
|
1103
1055
|
await this._connectionLimiter.connecting(sessionId);
|
|
1104
1056
|
connection.initiate();
|
|
1105
|
-
answer = await this._signalMessaging.offer({
|
|
1057
|
+
answer = await this._signalMessaging.offer(ctx, {
|
|
1106
1058
|
author: this.localInfo,
|
|
1107
1059
|
recipient: this.remoteInfo,
|
|
1108
1060
|
sessionId,
|
|
@@ -1111,20 +1063,20 @@ var Peer = class {
|
|
|
1111
1063
|
offer: {}
|
|
1112
1064
|
}
|
|
1113
1065
|
});
|
|
1114
|
-
|
|
1066
|
+
log3("received", {
|
|
1115
1067
|
answer,
|
|
1116
1068
|
topic: this.topic,
|
|
1117
1069
|
local: this.localInfo,
|
|
1118
1070
|
remote: this.remoteInfo
|
|
1119
1071
|
}, {
|
|
1120
|
-
F:
|
|
1072
|
+
F: __dxlog_file3,
|
|
1121
1073
|
L: 192,
|
|
1122
1074
|
S: this,
|
|
1123
1075
|
C: (f, a) => f(...a)
|
|
1124
1076
|
});
|
|
1125
1077
|
if (connection.state !== ConnectionState.INITIAL) {
|
|
1126
|
-
|
|
1127
|
-
F:
|
|
1078
|
+
log3("ignoring response", void 0, {
|
|
1079
|
+
F: __dxlog_file3,
|
|
1128
1080
|
L: 194,
|
|
1129
1081
|
S: this,
|
|
1130
1082
|
C: (f, a) => f(...a)
|
|
@@ -1132,13 +1084,13 @@ var Peer = class {
|
|
|
1132
1084
|
return;
|
|
1133
1085
|
}
|
|
1134
1086
|
} catch (err) {
|
|
1135
|
-
|
|
1087
|
+
log3("initiation error: send offer", {
|
|
1136
1088
|
err,
|
|
1137
1089
|
topic: this.topic,
|
|
1138
1090
|
local: this.localInfo,
|
|
1139
1091
|
remote: this.remoteInfo
|
|
1140
1092
|
}, {
|
|
1141
|
-
F:
|
|
1093
|
+
F: __dxlog_file3,
|
|
1142
1094
|
L: 198,
|
|
1143
1095
|
S: this,
|
|
1144
1096
|
C: (f, a) => f(...a)
|
|
@@ -1154,13 +1106,13 @@ var Peer = class {
|
|
|
1154
1106
|
return;
|
|
1155
1107
|
}
|
|
1156
1108
|
} catch (err) {
|
|
1157
|
-
|
|
1109
|
+
log3("initiation error: accept answer", {
|
|
1158
1110
|
err,
|
|
1159
1111
|
topic: this.topic,
|
|
1160
1112
|
local: this.localInfo,
|
|
1161
1113
|
remote: this.remoteInfo
|
|
1162
1114
|
}, {
|
|
1163
|
-
F:
|
|
1115
|
+
F: __dxlog_file3,
|
|
1164
1116
|
L: 211,
|
|
1165
1117
|
S: this,
|
|
1166
1118
|
C: (f, a) => f(...a)
|
|
@@ -1171,8 +1123,8 @@ var Peer = class {
|
|
|
1171
1123
|
this.initiating = false;
|
|
1172
1124
|
}
|
|
1173
1125
|
try {
|
|
1174
|
-
|
|
1175
|
-
F:
|
|
1126
|
+
log3("opening connection as initiator", void 0, {
|
|
1127
|
+
F: __dxlog_file3,
|
|
1176
1128
|
L: 224,
|
|
1177
1129
|
S: this,
|
|
1178
1130
|
C: (f, a) => f(...a)
|
|
@@ -1180,21 +1132,21 @@ var Peer = class {
|
|
|
1180
1132
|
await connection.openConnection();
|
|
1181
1133
|
this._callbacks.onAccepted();
|
|
1182
1134
|
} catch (err) {
|
|
1183
|
-
|
|
1135
|
+
log3("initiation error: open connection", {
|
|
1184
1136
|
err,
|
|
1185
1137
|
topic: this.topic,
|
|
1186
1138
|
local: this.localInfo,
|
|
1187
1139
|
remote: this.remoteInfo
|
|
1188
1140
|
}, {
|
|
1189
|
-
F:
|
|
1141
|
+
F: __dxlog_file3,
|
|
1190
1142
|
L: 228,
|
|
1191
1143
|
S: this,
|
|
1192
1144
|
C: (f, a) => f(...a)
|
|
1193
1145
|
});
|
|
1194
|
-
|
|
1146
|
+
log3.warn("closing connection due to unhandled error on openConnection", {
|
|
1195
1147
|
err
|
|
1196
1148
|
}, {
|
|
1197
|
-
F:
|
|
1149
|
+
F: __dxlog_file3,
|
|
1198
1150
|
L: 235,
|
|
1199
1151
|
S: this,
|
|
1200
1152
|
C: (f, a) => f(...a)
|
|
@@ -1210,20 +1162,20 @@ var Peer = class {
|
|
|
1210
1162
|
* Either we're initiating a connection or creating one in response to an offer from the other peer.
|
|
1211
1163
|
*/
|
|
1212
1164
|
_createConnection(initiator, sessionId) {
|
|
1213
|
-
|
|
1165
|
+
log3("creating connection", {
|
|
1214
1166
|
topic: this.topic,
|
|
1215
1167
|
peerId: this.localInfo,
|
|
1216
1168
|
remoteId: this.remoteInfo,
|
|
1217
1169
|
initiator,
|
|
1218
1170
|
sessionId
|
|
1219
1171
|
}, {
|
|
1220
|
-
F:
|
|
1172
|
+
F: __dxlog_file3,
|
|
1221
1173
|
L: 249,
|
|
1222
1174
|
S: this,
|
|
1223
1175
|
C: (f, a) => f(...a)
|
|
1224
1176
|
});
|
|
1225
1177
|
invariant3(!this.connection, "Already connected.", {
|
|
1226
|
-
F:
|
|
1178
|
+
F: __dxlog_file3,
|
|
1227
1179
|
L: 256,
|
|
1228
1180
|
S: this,
|
|
1229
1181
|
A: [
|
|
@@ -1252,14 +1204,14 @@ var Peer = class {
|
|
|
1252
1204
|
this._lastConnectionTime = Date.now();
|
|
1253
1205
|
this._callbacks.onConnected();
|
|
1254
1206
|
this._connectionLimiter.doneConnecting(sessionId);
|
|
1255
|
-
|
|
1207
|
+
log3.trace("dxos.mesh.connection.connected", {
|
|
1256
1208
|
topic: this.topic,
|
|
1257
1209
|
localPeerId: this.localInfo,
|
|
1258
1210
|
remotePeerId: this.remoteInfo,
|
|
1259
1211
|
sessionId,
|
|
1260
1212
|
initiator
|
|
1261
1213
|
}, {
|
|
1262
|
-
F:
|
|
1214
|
+
F: __dxlog_file3,
|
|
1263
1215
|
L: 280,
|
|
1264
1216
|
S: this,
|
|
1265
1217
|
C: (f, a) => f(...a)
|
|
@@ -1272,15 +1224,15 @@ var Peer = class {
|
|
|
1272
1224
|
remoteId: this.remoteInfo,
|
|
1273
1225
|
initiator
|
|
1274
1226
|
};
|
|
1275
|
-
|
|
1276
|
-
F:
|
|
1227
|
+
log3("connection closed", logMeta, {
|
|
1228
|
+
F: __dxlog_file3,
|
|
1277
1229
|
L: 290,
|
|
1278
1230
|
S: this,
|
|
1279
1231
|
C: (f, a) => f(...a)
|
|
1280
1232
|
});
|
|
1281
1233
|
this._connectionLimiter.doneConnecting(sessionId);
|
|
1282
1234
|
invariant3(this.connection === connection, "Connection mismatch (race condition).", {
|
|
1283
|
-
F:
|
|
1235
|
+
F: __dxlog_file3,
|
|
1284
1236
|
L: 295,
|
|
1285
1237
|
S: this,
|
|
1286
1238
|
A: [
|
|
@@ -1288,14 +1240,14 @@ var Peer = class {
|
|
|
1288
1240
|
"'Connection mismatch (race condition).'"
|
|
1289
1241
|
]
|
|
1290
1242
|
});
|
|
1291
|
-
|
|
1243
|
+
log3.trace("dxos.mesh.connection.closed", {
|
|
1292
1244
|
topic: this.topic,
|
|
1293
1245
|
localPeerId: this.localInfo,
|
|
1294
1246
|
remotePeerId: this.remoteInfo,
|
|
1295
1247
|
sessionId,
|
|
1296
1248
|
initiator
|
|
1297
1249
|
}, {
|
|
1298
|
-
F:
|
|
1250
|
+
F: __dxlog_file3,
|
|
1299
1251
|
L: 297,
|
|
1300
1252
|
S: this,
|
|
1301
1253
|
C: (f, a) => f(...a)
|
|
@@ -1311,8 +1263,8 @@ var Peer = class {
|
|
|
1311
1263
|
}
|
|
1312
1264
|
this._callbacks.onDisconnected();
|
|
1313
1265
|
scheduleTask2(this._connectionCtx, () => {
|
|
1314
|
-
|
|
1315
|
-
F:
|
|
1266
|
+
log3("peer became available", logMeta, {
|
|
1267
|
+
F: __dxlog_file3,
|
|
1316
1268
|
L: 321,
|
|
1317
1269
|
S: this,
|
|
1318
1270
|
C: (f, a) => f(...a)
|
|
@@ -1329,19 +1281,19 @@ var Peer = class {
|
|
|
1329
1281
|
void this._connectionCtx?.dispose();
|
|
1330
1282
|
this._connectionCtx = this._ctx.derive();
|
|
1331
1283
|
connection.errors.handle((err) => {
|
|
1332
|
-
|
|
1284
|
+
log3.info("connection error, closing", {
|
|
1333
1285
|
topic: this.topic,
|
|
1334
1286
|
peerId: this.localInfo,
|
|
1335
1287
|
remoteId: this.remoteInfo,
|
|
1336
1288
|
initiator,
|
|
1337
1289
|
err
|
|
1338
1290
|
}, {
|
|
1339
|
-
F:
|
|
1291
|
+
F: __dxlog_file3,
|
|
1340
1292
|
L: 339,
|
|
1341
1293
|
S: this,
|
|
1342
1294
|
C: (f, a) => f(...a)
|
|
1343
1295
|
});
|
|
1344
|
-
|
|
1296
|
+
log3.trace("dxos.mesh.connection.error", {
|
|
1345
1297
|
topic: this.topic,
|
|
1346
1298
|
localPeerId: this.localInfo,
|
|
1347
1299
|
remotePeerId: this.remoteInfo,
|
|
@@ -1349,7 +1301,7 @@ var Peer = class {
|
|
|
1349
1301
|
initiator,
|
|
1350
1302
|
err
|
|
1351
1303
|
}, {
|
|
1352
|
-
F:
|
|
1304
|
+
F: __dxlog_file3,
|
|
1353
1305
|
L: 346,
|
|
1354
1306
|
S: this,
|
|
1355
1307
|
C: (f, a) => f(...a)
|
|
@@ -1364,11 +1316,11 @@ var Peer = class {
|
|
|
1364
1316
|
return;
|
|
1365
1317
|
}
|
|
1366
1318
|
const connection = this.connection;
|
|
1367
|
-
|
|
1319
|
+
log3("closing...", {
|
|
1368
1320
|
peerId: this.remoteInfo,
|
|
1369
1321
|
sessionId: connection.sessionId
|
|
1370
1322
|
}, {
|
|
1371
|
-
F:
|
|
1323
|
+
F: __dxlog_file3,
|
|
1372
1324
|
L: 371,
|
|
1373
1325
|
S: this,
|
|
1374
1326
|
C: (f, a) => f(...a)
|
|
@@ -1376,37 +1328,37 @@ var Peer = class {
|
|
|
1376
1328
|
await connection.close({
|
|
1377
1329
|
error: err
|
|
1378
1330
|
});
|
|
1379
|
-
|
|
1331
|
+
log3("closed", {
|
|
1380
1332
|
peerId: this.remoteInfo,
|
|
1381
1333
|
sessionId: connection.sessionId
|
|
1382
1334
|
}, {
|
|
1383
|
-
F:
|
|
1335
|
+
F: __dxlog_file3,
|
|
1384
1336
|
L: 377,
|
|
1385
1337
|
S: this,
|
|
1386
1338
|
C: (f, a) => f(...a)
|
|
1387
1339
|
});
|
|
1388
1340
|
}
|
|
1389
|
-
async onSignal(message) {
|
|
1341
|
+
async onSignal(ctx, message) {
|
|
1390
1342
|
if (!this.connection) {
|
|
1391
|
-
|
|
1343
|
+
log3("dropping signal message for non-existent connection", {
|
|
1392
1344
|
message
|
|
1393
1345
|
}, {
|
|
1394
|
-
F:
|
|
1346
|
+
F: __dxlog_file3,
|
|
1395
1347
|
L: 382,
|
|
1396
1348
|
S: this,
|
|
1397
1349
|
C: (f, a) => f(...a)
|
|
1398
1350
|
});
|
|
1399
1351
|
return;
|
|
1400
1352
|
}
|
|
1401
|
-
await this.connection.signal(message);
|
|
1353
|
+
await this.connection.signal(ctx, message);
|
|
1402
1354
|
}
|
|
1403
1355
|
async safeDestroy(reason) {
|
|
1404
1356
|
await this._ctx.dispose();
|
|
1405
|
-
|
|
1357
|
+
log3("Destroying peer", {
|
|
1406
1358
|
peerId: this.remoteInfo,
|
|
1407
1359
|
topic: this.topic
|
|
1408
1360
|
}, {
|
|
1409
|
-
F:
|
|
1361
|
+
F: __dxlog_file3,
|
|
1410
1362
|
L: 392,
|
|
1411
1363
|
S: this,
|
|
1412
1364
|
C: (f, a) => f(...a)
|
|
@@ -1439,7 +1391,7 @@ function _ts_decorate3(decorators, target, key, desc) {
|
|
|
1439
1391
|
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;
|
|
1440
1392
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1441
1393
|
}
|
|
1442
|
-
var
|
|
1394
|
+
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts";
|
|
1443
1395
|
var INITIATION_DELAY = 100;
|
|
1444
1396
|
var getClassName = (obj) => Object.getPrototypeOf(obj).constructor.name;
|
|
1445
1397
|
var Swarm = class {
|
|
@@ -1453,33 +1405,36 @@ var Swarm = class {
|
|
|
1453
1405
|
_connectionLimiter;
|
|
1454
1406
|
_initiationDelay;
|
|
1455
1407
|
_swarmMessenger;
|
|
1456
|
-
_ctx
|
|
1457
|
-
|
|
1408
|
+
_ctx = new Context3(void 0, {
|
|
1409
|
+
F: __dxlog_file4,
|
|
1410
|
+
L: 38
|
|
1411
|
+
});
|
|
1412
|
+
_listeningHandle = void 0;
|
|
1458
1413
|
/**
|
|
1459
1414
|
* PeerInfo -> Peer.
|
|
1460
1415
|
* @internal
|
|
1461
1416
|
*/
|
|
1462
|
-
_peers;
|
|
1417
|
+
_peers = new ComplexMap2(PeerInfoHash);
|
|
1463
1418
|
/**
|
|
1464
1419
|
* Unique id of the swarm, local to the current peer, generated when swarm is joined.
|
|
1465
1420
|
*/
|
|
1466
|
-
_instanceId;
|
|
1421
|
+
_instanceId = PublicKey4.random().toHex();
|
|
1467
1422
|
/**
|
|
1468
1423
|
* New connection to a peer is started.
|
|
1469
1424
|
* @internal
|
|
1470
1425
|
*/
|
|
1471
|
-
connectionAdded;
|
|
1426
|
+
connectionAdded = new Event3();
|
|
1472
1427
|
/**
|
|
1473
1428
|
* Connection to a peer is dropped.
|
|
1474
1429
|
* @internal
|
|
1475
1430
|
*/
|
|
1476
|
-
disconnected;
|
|
1431
|
+
disconnected = new Event3();
|
|
1477
1432
|
/**
|
|
1478
1433
|
* Connection is established to a new peer.
|
|
1479
1434
|
* @internal
|
|
1480
1435
|
*/
|
|
1481
|
-
connected;
|
|
1482
|
-
errors;
|
|
1436
|
+
connected = new Event3();
|
|
1437
|
+
errors = new ErrorStream2();
|
|
1483
1438
|
// TODO(burdon): Swarm => Peer.create/destroy =< Connection.open/close
|
|
1484
1439
|
// TODO(burdon): Pass in object.
|
|
1485
1440
|
constructor(_topic, _ownPeer, _topology, _protocolProvider, _messenger, _transportFactory, _label, _connectionLimiter, _initiationDelay = INITIATION_DELAY) {
|
|
@@ -1492,55 +1447,44 @@ var Swarm = class {
|
|
|
1492
1447
|
this._label = _label;
|
|
1493
1448
|
this._connectionLimiter = _connectionLimiter;
|
|
1494
1449
|
this._initiationDelay = _initiationDelay;
|
|
1495
|
-
|
|
1496
|
-
F: __dxlog_file5,
|
|
1497
|
-
L: 39
|
|
1498
|
-
});
|
|
1499
|
-
this._listeningHandle = void 0;
|
|
1500
|
-
this._peers = new ComplexMap2(PeerInfoHash);
|
|
1501
|
-
this._instanceId = PublicKey4.random().toHex();
|
|
1502
|
-
this.connectionAdded = new Event3();
|
|
1503
|
-
this.disconnected = new Event3();
|
|
1504
|
-
this.connected = new Event3();
|
|
1505
|
-
this.errors = new ErrorStream2();
|
|
1506
|
-
log5.trace("dxos.mesh.swarm.constructor", trace2.begin({
|
|
1450
|
+
log4.trace("dxos.mesh.swarm.constructor", trace2.begin({
|
|
1507
1451
|
id: this._instanceId,
|
|
1508
1452
|
data: {
|
|
1509
1453
|
topic: this._topic.toHex(),
|
|
1510
1454
|
peer: this._ownPeer
|
|
1511
1455
|
}
|
|
1512
1456
|
}), {
|
|
1513
|
-
F:
|
|
1514
|
-
L:
|
|
1457
|
+
F: __dxlog_file4,
|
|
1458
|
+
L: 88,
|
|
1515
1459
|
S: this,
|
|
1516
1460
|
C: (f, a) => f(...a)
|
|
1517
1461
|
});
|
|
1518
|
-
|
|
1462
|
+
log4("creating swarm", {
|
|
1519
1463
|
peerId: _ownPeer
|
|
1520
1464
|
}, {
|
|
1521
|
-
F:
|
|
1522
|
-
L:
|
|
1465
|
+
F: __dxlog_file4,
|
|
1466
|
+
L: 92,
|
|
1523
1467
|
S: this,
|
|
1524
1468
|
C: (f, a) => f(...a)
|
|
1525
1469
|
});
|
|
1526
1470
|
_topology.init(this._getSwarmController());
|
|
1527
1471
|
this._swarmMessenger = new SwarmMessenger({
|
|
1528
|
-
sendMessage: async (msg) => await this._messenger.sendMessage(msg),
|
|
1529
|
-
onSignal: async (msg) => await this.onSignal(msg),
|
|
1530
|
-
onOffer: async (msg) => await this.onOffer(msg),
|
|
1472
|
+
sendMessage: async (ctx, msg) => await this._messenger.sendMessage(ctx, msg),
|
|
1473
|
+
onSignal: async (ctx, msg) => await this.onSignal(ctx, msg),
|
|
1474
|
+
onOffer: async (ctx, msg) => await this.onOffer(ctx, msg),
|
|
1531
1475
|
topic: this._topic
|
|
1532
1476
|
});
|
|
1533
|
-
|
|
1477
|
+
log4.trace("dxos.mesh.swarm.constructor", trace2.end({
|
|
1534
1478
|
id: this._instanceId
|
|
1535
1479
|
}), {
|
|
1536
|
-
F:
|
|
1537
|
-
L:
|
|
1480
|
+
F: __dxlog_file4,
|
|
1481
|
+
L: 101,
|
|
1538
1482
|
S: this,
|
|
1539
1483
|
C: (f, a) => f(...a)
|
|
1540
1484
|
});
|
|
1541
1485
|
}
|
|
1542
1486
|
get connections() {
|
|
1543
|
-
return Array.from(this._peers.values()).map((peer) => peer.connection).filter(
|
|
1487
|
+
return Array.from(this._peers.values()).map((peer) => peer.connection).filter(isNonNullable);
|
|
1544
1488
|
}
|
|
1545
1489
|
get ownPeerId() {
|
|
1546
1490
|
return PublicKey4.from(this._ownPeer.peerKey);
|
|
@@ -1559,8 +1503,8 @@ var Swarm = class {
|
|
|
1559
1503
|
}
|
|
1560
1504
|
async open() {
|
|
1561
1505
|
invariant4(!this._listeningHandle, void 0, {
|
|
1562
|
-
F:
|
|
1563
|
-
L:
|
|
1506
|
+
F: __dxlog_file4,
|
|
1507
|
+
L: 132,
|
|
1564
1508
|
S: this,
|
|
1565
1509
|
A: [
|
|
1566
1510
|
"!this._listeningHandle",
|
|
@@ -1571,11 +1515,11 @@ var Swarm = class {
|
|
|
1571
1515
|
peer: this._ownPeer,
|
|
1572
1516
|
payloadType: "dxos.mesh.swarm.SwarmMessage",
|
|
1573
1517
|
onMessage: async (message) => {
|
|
1574
|
-
await this._swarmMessenger.receiveMessage(message).catch((err) =>
|
|
1518
|
+
await this._swarmMessenger.receiveMessage(this._ctx, message).catch((err) => log4.info("Error while receiving message", {
|
|
1575
1519
|
err
|
|
1576
1520
|
}, {
|
|
1577
|
-
F:
|
|
1578
|
-
L:
|
|
1521
|
+
F: __dxlog_file4,
|
|
1522
|
+
L: 140,
|
|
1579
1523
|
S: this,
|
|
1580
1524
|
C: (f, a) => f(...a)
|
|
1581
1525
|
}));
|
|
@@ -1583,9 +1527,9 @@ var Swarm = class {
|
|
|
1583
1527
|
});
|
|
1584
1528
|
}
|
|
1585
1529
|
async destroy() {
|
|
1586
|
-
|
|
1587
|
-
F:
|
|
1588
|
-
L:
|
|
1530
|
+
log4("destroying...", void 0, {
|
|
1531
|
+
F: __dxlog_file4,
|
|
1532
|
+
L: 146,
|
|
1589
1533
|
S: this,
|
|
1590
1534
|
C: (f, a) => f(...a)
|
|
1591
1535
|
});
|
|
@@ -1594,17 +1538,17 @@ var Swarm = class {
|
|
|
1594
1538
|
await this._ctx.dispose();
|
|
1595
1539
|
await this._topology.destroy();
|
|
1596
1540
|
await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key, "swarm destroyed")));
|
|
1597
|
-
|
|
1598
|
-
F:
|
|
1599
|
-
L:
|
|
1541
|
+
log4("destroyed", void 0, {
|
|
1542
|
+
F: __dxlog_file4,
|
|
1543
|
+
L: 153,
|
|
1600
1544
|
S: this,
|
|
1601
1545
|
C: (f, a) => f(...a)
|
|
1602
1546
|
});
|
|
1603
1547
|
}
|
|
1604
1548
|
async setTopology(topology) {
|
|
1605
1549
|
invariant4(!this._ctx.disposed, "Swarm is offline", {
|
|
1606
|
-
F:
|
|
1607
|
-
L:
|
|
1550
|
+
F: __dxlog_file4,
|
|
1551
|
+
L: 157,
|
|
1608
1552
|
S: this,
|
|
1609
1553
|
A: [
|
|
1610
1554
|
"!this._ctx.disposed",
|
|
@@ -1614,12 +1558,12 @@ var Swarm = class {
|
|
|
1614
1558
|
if (topology === this._topology) {
|
|
1615
1559
|
return;
|
|
1616
1560
|
}
|
|
1617
|
-
|
|
1561
|
+
log4("setting topology", {
|
|
1618
1562
|
previous: getClassName(this._topology),
|
|
1619
1563
|
topology: getClassName(topology)
|
|
1620
1564
|
}, {
|
|
1621
|
-
F:
|
|
1622
|
-
L:
|
|
1565
|
+
F: __dxlog_file4,
|
|
1566
|
+
L: 161,
|
|
1623
1567
|
S: this,
|
|
1624
1568
|
C: (f, a) => f(...a)
|
|
1625
1569
|
});
|
|
@@ -1629,18 +1573,18 @@ var Swarm = class {
|
|
|
1629
1573
|
this._topology.update();
|
|
1630
1574
|
}
|
|
1631
1575
|
async onSwarmEvent(swarmEvent) {
|
|
1632
|
-
|
|
1576
|
+
log4("swarm event", {
|
|
1633
1577
|
swarmEvent
|
|
1634
1578
|
}, {
|
|
1635
|
-
F:
|
|
1636
|
-
L:
|
|
1579
|
+
F: __dxlog_file4,
|
|
1580
|
+
L: 174,
|
|
1637
1581
|
S: this,
|
|
1638
1582
|
C: (f, a) => f(...a)
|
|
1639
1583
|
});
|
|
1640
1584
|
if (this._ctx.disposed) {
|
|
1641
|
-
|
|
1642
|
-
F:
|
|
1643
|
-
L:
|
|
1585
|
+
log4("swarm event ignored for disposed swarm", void 0, {
|
|
1586
|
+
F: __dxlog_file4,
|
|
1587
|
+
L: 177,
|
|
1644
1588
|
S: this,
|
|
1645
1589
|
C: (f, a) => f(...a)
|
|
1646
1590
|
});
|
|
@@ -1649,11 +1593,11 @@ var Swarm = class {
|
|
|
1649
1593
|
if (swarmEvent.peerAvailable) {
|
|
1650
1594
|
const peerId = swarmEvent.peerAvailable.peer.peerKey;
|
|
1651
1595
|
if (peerId !== this._ownPeer.peerKey) {
|
|
1652
|
-
|
|
1596
|
+
log4("new peer", {
|
|
1653
1597
|
peerId
|
|
1654
1598
|
}, {
|
|
1655
|
-
F:
|
|
1656
|
-
L:
|
|
1599
|
+
F: __dxlog_file4,
|
|
1600
|
+
L: 184,
|
|
1657
1601
|
S: this,
|
|
1658
1602
|
C: (f, a) => f(...a)
|
|
1659
1603
|
});
|
|
@@ -1665,25 +1609,25 @@ var Swarm = class {
|
|
|
1665
1609
|
if (peer) {
|
|
1666
1610
|
peer.advertizing = false;
|
|
1667
1611
|
if (this._isConnectionEstablishmentInProgress(peer)) {
|
|
1668
|
-
|
|
1669
|
-
F:
|
|
1670
|
-
L:
|
|
1612
|
+
log4(`destroying peer, state: ${peer.connection?.state}`, void 0, {
|
|
1613
|
+
F: __dxlog_file4,
|
|
1614
|
+
L: 195,
|
|
1671
1615
|
S: this,
|
|
1672
1616
|
C: (f, a) => f(...a)
|
|
1673
1617
|
});
|
|
1674
|
-
void this._destroyPeer(swarmEvent.peerLeft.peer, "peer left").catch((err) =>
|
|
1675
|
-
F:
|
|
1676
|
-
L:
|
|
1618
|
+
void this._destroyPeer(swarmEvent.peerLeft.peer, "peer left").catch((err) => log4.catch(err, void 0, {
|
|
1619
|
+
F: __dxlog_file4,
|
|
1620
|
+
L: 196,
|
|
1677
1621
|
S: this,
|
|
1678
1622
|
C: (f, a) => f(...a)
|
|
1679
1623
|
}));
|
|
1680
1624
|
}
|
|
1681
1625
|
} else {
|
|
1682
|
-
|
|
1626
|
+
log4("received peerLeft but no peer found", {
|
|
1683
1627
|
peer: swarmEvent.peerLeft.peer.peerKey
|
|
1684
1628
|
}, {
|
|
1685
|
-
F:
|
|
1686
|
-
L:
|
|
1629
|
+
F: __dxlog_file4,
|
|
1630
|
+
L: 199,
|
|
1687
1631
|
S: this,
|
|
1688
1632
|
C: (f, a) => f(...a)
|
|
1689
1633
|
});
|
|
@@ -1691,19 +1635,19 @@ var Swarm = class {
|
|
|
1691
1635
|
}
|
|
1692
1636
|
this._topology.update();
|
|
1693
1637
|
}
|
|
1694
|
-
async onOffer(message) {
|
|
1695
|
-
|
|
1638
|
+
async onOffer(ctx, message) {
|
|
1639
|
+
log4("offer", {
|
|
1696
1640
|
message
|
|
1697
1641
|
}, {
|
|
1698
|
-
F:
|
|
1699
|
-
L:
|
|
1642
|
+
F: __dxlog_file4,
|
|
1643
|
+
L: 208,
|
|
1700
1644
|
S: this,
|
|
1701
1645
|
C: (f, a) => f(...a)
|
|
1702
1646
|
});
|
|
1703
1647
|
if (this._ctx.disposed) {
|
|
1704
|
-
|
|
1705
|
-
F:
|
|
1706
|
-
L:
|
|
1648
|
+
log4("ignored for disposed swarm", void 0, {
|
|
1649
|
+
F: __dxlog_file4,
|
|
1650
|
+
L: 210,
|
|
1707
1651
|
S: this,
|
|
1708
1652
|
C: (f, a) => f(...a)
|
|
1709
1653
|
});
|
|
@@ -1712,8 +1656,8 @@ var Swarm = class {
|
|
|
1712
1656
|
};
|
|
1713
1657
|
}
|
|
1714
1658
|
invariant4(message.author, void 0, {
|
|
1715
|
-
F:
|
|
1716
|
-
L:
|
|
1659
|
+
F: __dxlog_file4,
|
|
1660
|
+
L: 215,
|
|
1717
1661
|
S: this,
|
|
1718
1662
|
A: [
|
|
1719
1663
|
"message.author",
|
|
@@ -1721,11 +1665,11 @@ var Swarm = class {
|
|
|
1721
1665
|
]
|
|
1722
1666
|
});
|
|
1723
1667
|
if (message.recipient.peerKey !== this._ownPeer.peerKey) {
|
|
1724
|
-
|
|
1668
|
+
log4("rejecting offer with incorrect peerId", {
|
|
1725
1669
|
message
|
|
1726
1670
|
}, {
|
|
1727
|
-
F:
|
|
1728
|
-
L:
|
|
1671
|
+
F: __dxlog_file4,
|
|
1672
|
+
L: 217,
|
|
1729
1673
|
S: this,
|
|
1730
1674
|
C: (f, a) => f(...a)
|
|
1731
1675
|
});
|
|
@@ -1734,11 +1678,11 @@ var Swarm = class {
|
|
|
1734
1678
|
};
|
|
1735
1679
|
}
|
|
1736
1680
|
if (!message.topic?.equals(this._topic)) {
|
|
1737
|
-
|
|
1681
|
+
log4("rejecting offer with incorrect topic", {
|
|
1738
1682
|
message
|
|
1739
1683
|
}, {
|
|
1740
|
-
F:
|
|
1741
|
-
L:
|
|
1684
|
+
F: __dxlog_file4,
|
|
1685
|
+
L: 221,
|
|
1742
1686
|
S: this,
|
|
1743
1687
|
C: (f, a) => f(...a)
|
|
1744
1688
|
});
|
|
@@ -1747,7 +1691,7 @@ var Swarm = class {
|
|
|
1747
1691
|
};
|
|
1748
1692
|
}
|
|
1749
1693
|
const peer = this._getOfferSenderPeer(message.author);
|
|
1750
|
-
const answer = await peer.onOffer(message);
|
|
1694
|
+
const answer = await peer.onOffer(ctx, message);
|
|
1751
1695
|
this._topology.update();
|
|
1752
1696
|
return answer;
|
|
1753
1697
|
}
|
|
@@ -1761,27 +1705,27 @@ var Swarm = class {
|
|
|
1761
1705
|
}
|
|
1762
1706
|
return peer;
|
|
1763
1707
|
}
|
|
1764
|
-
async onSignal(message) {
|
|
1765
|
-
|
|
1708
|
+
async onSignal(ctx, message) {
|
|
1709
|
+
log4("signal", {
|
|
1766
1710
|
message
|
|
1767
1711
|
}, {
|
|
1768
|
-
F:
|
|
1769
|
-
L:
|
|
1712
|
+
F: __dxlog_file4,
|
|
1713
|
+
L: 246,
|
|
1770
1714
|
S: this,
|
|
1771
1715
|
C: (f, a) => f(...a)
|
|
1772
1716
|
});
|
|
1773
1717
|
if (this._ctx.disposed) {
|
|
1774
|
-
|
|
1775
|
-
F:
|
|
1776
|
-
L:
|
|
1718
|
+
log4.info("ignored for offline swarm", void 0, {
|
|
1719
|
+
F: __dxlog_file4,
|
|
1720
|
+
L: 248,
|
|
1777
1721
|
S: this,
|
|
1778
1722
|
C: (f, a) => f(...a)
|
|
1779
1723
|
});
|
|
1780
1724
|
return;
|
|
1781
1725
|
}
|
|
1782
1726
|
invariant4(message.recipient.peerKey === this._ownPeer.peerKey, `Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`, {
|
|
1783
|
-
F:
|
|
1784
|
-
L:
|
|
1727
|
+
F: __dxlog_file4,
|
|
1728
|
+
L: 251,
|
|
1785
1729
|
S: this,
|
|
1786
1730
|
A: [
|
|
1787
1731
|
"message.recipient.peerKey === this._ownPeer.peerKey",
|
|
@@ -1789,8 +1733,8 @@ var Swarm = class {
|
|
|
1789
1733
|
]
|
|
1790
1734
|
});
|
|
1791
1735
|
invariant4(message.topic?.equals(this._topic), void 0, {
|
|
1792
|
-
F:
|
|
1793
|
-
L:
|
|
1736
|
+
F: __dxlog_file4,
|
|
1737
|
+
L: 255,
|
|
1794
1738
|
S: this,
|
|
1795
1739
|
A: [
|
|
1796
1740
|
"message.topic?.equals(this._topic)",
|
|
@@ -1798,8 +1742,8 @@ var Swarm = class {
|
|
|
1798
1742
|
]
|
|
1799
1743
|
});
|
|
1800
1744
|
invariant4(message.author, void 0, {
|
|
1801
|
-
F:
|
|
1802
|
-
L:
|
|
1745
|
+
F: __dxlog_file4,
|
|
1746
|
+
L: 256,
|
|
1803
1747
|
S: this,
|
|
1804
1748
|
A: [
|
|
1805
1749
|
"message.author",
|
|
@@ -1807,7 +1751,7 @@ var Swarm = class {
|
|
|
1807
1751
|
]
|
|
1808
1752
|
});
|
|
1809
1753
|
const peer = this._getOrCreatePeer(message.author);
|
|
1810
|
-
await peer.onSignal(message);
|
|
1754
|
+
await peer.onSignal(ctx, message);
|
|
1811
1755
|
}
|
|
1812
1756
|
// For debug purposes
|
|
1813
1757
|
async goOffline() {
|
|
@@ -1818,15 +1762,15 @@ var Swarm = class {
|
|
|
1818
1762
|
}
|
|
1819
1763
|
// For debug purposes
|
|
1820
1764
|
async goOnline() {
|
|
1821
|
-
this._ctx = new
|
|
1822
|
-
F:
|
|
1823
|
-
L:
|
|
1765
|
+
this._ctx = new Context3(void 0, {
|
|
1766
|
+
F: __dxlog_file4,
|
|
1767
|
+
L: 272
|
|
1824
1768
|
});
|
|
1825
1769
|
}
|
|
1826
1770
|
_getOrCreatePeer(peerInfo) {
|
|
1827
1771
|
invariant4(peerInfo.peerKey, "PeerInfo.peerKey is required", {
|
|
1828
|
-
F:
|
|
1829
|
-
L:
|
|
1772
|
+
F: __dxlog_file4,
|
|
1773
|
+
L: 276,
|
|
1830
1774
|
S: this,
|
|
1831
1775
|
A: [
|
|
1832
1776
|
"peerInfo.peerKey",
|
|
@@ -1844,9 +1788,9 @@ var Swarm = class {
|
|
|
1844
1788
|
},
|
|
1845
1789
|
onDisconnected: async () => {
|
|
1846
1790
|
if (this._isUnregistered(peer)) {
|
|
1847
|
-
|
|
1848
|
-
F:
|
|
1849
|
-
L:
|
|
1791
|
+
log4.verbose("ignored onDisconnected for unregistered peer", void 0, {
|
|
1792
|
+
F: __dxlog_file4,
|
|
1793
|
+
L: 296,
|
|
1850
1794
|
S: this,
|
|
1851
1795
|
C: (f, a) => f(...a)
|
|
1852
1796
|
});
|
|
@@ -1860,11 +1804,11 @@ var Swarm = class {
|
|
|
1860
1804
|
},
|
|
1861
1805
|
onRejected: () => {
|
|
1862
1806
|
if (!this._isUnregistered(peer)) {
|
|
1863
|
-
|
|
1807
|
+
log4("peer rejected connection", {
|
|
1864
1808
|
peerInfo
|
|
1865
1809
|
}, {
|
|
1866
|
-
F:
|
|
1867
|
-
L:
|
|
1810
|
+
F: __dxlog_file4,
|
|
1811
|
+
L: 310,
|
|
1868
1812
|
S: this,
|
|
1869
1813
|
C: (f, a) => f(...a)
|
|
1870
1814
|
});
|
|
@@ -1886,19 +1830,19 @@ var Swarm = class {
|
|
|
1886
1830
|
return peer;
|
|
1887
1831
|
}
|
|
1888
1832
|
async _destroyPeer(peerInfo, reason) {
|
|
1889
|
-
|
|
1833
|
+
log4("destroy peer", {
|
|
1890
1834
|
peerKey: peerInfo.peerKey,
|
|
1891
1835
|
reason
|
|
1892
1836
|
}, {
|
|
1893
|
-
F:
|
|
1894
|
-
L:
|
|
1837
|
+
F: __dxlog_file4,
|
|
1838
|
+
L: 332,
|
|
1895
1839
|
S: this,
|
|
1896
1840
|
C: (f, a) => f(...a)
|
|
1897
1841
|
});
|
|
1898
1842
|
const peer = this._peers.get(peerInfo);
|
|
1899
1843
|
invariant4(peer, void 0, {
|
|
1900
|
-
F:
|
|
1901
|
-
L:
|
|
1844
|
+
F: __dxlog_file4,
|
|
1845
|
+
L: 334,
|
|
1902
1846
|
S: this,
|
|
1903
1847
|
A: [
|
|
1904
1848
|
"peer",
|
|
@@ -1926,9 +1870,9 @@ var Swarm = class {
|
|
|
1926
1870
|
peerKey: peer.toHex()
|
|
1927
1871
|
});
|
|
1928
1872
|
} catch (err) {
|
|
1929
|
-
|
|
1930
|
-
F:
|
|
1931
|
-
L:
|
|
1873
|
+
log4("initiation error", err, {
|
|
1874
|
+
F: __dxlog_file4,
|
|
1875
|
+
L: 361,
|
|
1932
1876
|
S: this,
|
|
1933
1877
|
C: (f, a) => f(...a)
|
|
1934
1878
|
});
|
|
@@ -1955,11 +1899,11 @@ var Swarm = class {
|
|
|
1955
1899
|
const ctx = this._ctx;
|
|
1956
1900
|
const peer = this._getOrCreatePeer(remotePeer);
|
|
1957
1901
|
if (remotePeer.peerKey < this._ownPeer.peerKey) {
|
|
1958
|
-
|
|
1902
|
+
log4("initiation delay", {
|
|
1959
1903
|
remotePeer
|
|
1960
1904
|
}, {
|
|
1961
|
-
F:
|
|
1962
|
-
L:
|
|
1905
|
+
F: __dxlog_file4,
|
|
1906
|
+
L: 389,
|
|
1963
1907
|
S: this,
|
|
1964
1908
|
C: (f, a) => f(...a)
|
|
1965
1909
|
});
|
|
@@ -1974,21 +1918,21 @@ var Swarm = class {
|
|
|
1974
1918
|
if (peer.connection) {
|
|
1975
1919
|
return;
|
|
1976
1920
|
}
|
|
1977
|
-
|
|
1921
|
+
log4("initiating connection...", {
|
|
1978
1922
|
remotePeer
|
|
1979
1923
|
}, {
|
|
1980
|
-
F:
|
|
1981
|
-
L:
|
|
1924
|
+
F: __dxlog_file4,
|
|
1925
|
+
L: 405,
|
|
1982
1926
|
S: this,
|
|
1983
1927
|
C: (f, a) => f(...a)
|
|
1984
1928
|
});
|
|
1985
|
-
await peer.initiateConnection();
|
|
1929
|
+
await peer.initiateConnection(ctx);
|
|
1986
1930
|
this._topology.update();
|
|
1987
|
-
|
|
1931
|
+
log4("initiated", {
|
|
1988
1932
|
remotePeer
|
|
1989
1933
|
}, {
|
|
1990
|
-
F:
|
|
1991
|
-
L:
|
|
1934
|
+
F: __dxlog_file4,
|
|
1935
|
+
L: 408,
|
|
1992
1936
|
S: this,
|
|
1993
1937
|
C: (f, a) => f(...a)
|
|
1994
1938
|
});
|
|
@@ -2039,25 +1983,21 @@ _ts_decorate3([
|
|
|
2039
1983
|
// src/swarm/swarm-mapper.ts
|
|
2040
1984
|
import { Event as Event4, SubscriptionList } from "@dxos/async";
|
|
2041
1985
|
import { PublicKey as PublicKey5 } from "@dxos/keys";
|
|
2042
|
-
import { log as
|
|
1986
|
+
import { log as log5 } from "@dxos/log";
|
|
2043
1987
|
import { PeerInfoHash as PeerInfoHash2 } from "@dxos/messaging";
|
|
2044
1988
|
import { ComplexMap as ComplexMap3 } from "@dxos/util";
|
|
2045
|
-
var
|
|
1989
|
+
var __dxlog_file5 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
|
|
2046
1990
|
var SwarmMapper = class {
|
|
2047
1991
|
_swarm;
|
|
2048
|
-
_subscriptions;
|
|
2049
|
-
_connectionSubscriptions;
|
|
2050
|
-
_peers;
|
|
2051
|
-
mapUpdated;
|
|
1992
|
+
_subscriptions = new SubscriptionList();
|
|
1993
|
+
_connectionSubscriptions = new ComplexMap3(PeerInfoHash2);
|
|
1994
|
+
_peers = new ComplexMap3(PeerInfoHash2);
|
|
1995
|
+
mapUpdated = new Event4();
|
|
2052
1996
|
get peers() {
|
|
2053
1997
|
return Array.from(this._peers.values());
|
|
2054
1998
|
}
|
|
2055
1999
|
constructor(_swarm) {
|
|
2056
2000
|
this._swarm = _swarm;
|
|
2057
|
-
this._subscriptions = new SubscriptionList();
|
|
2058
|
-
this._connectionSubscriptions = new ComplexMap3(PeerInfoHash2);
|
|
2059
|
-
this._peers = new ComplexMap3(PeerInfoHash2);
|
|
2060
|
-
this.mapUpdated = new Event4();
|
|
2061
2001
|
this._subscriptions.add(_swarm.connectionAdded.on((connection) => {
|
|
2062
2002
|
this._update();
|
|
2063
2003
|
this._connectionSubscriptions.set(connection.remoteInfo, connection.stateChanged.on(() => {
|
|
@@ -2072,8 +2012,8 @@ var SwarmMapper = class {
|
|
|
2072
2012
|
this._update();
|
|
2073
2013
|
}
|
|
2074
2014
|
_update() {
|
|
2075
|
-
|
|
2076
|
-
F:
|
|
2015
|
+
log5("updating swarm", void 0, {
|
|
2016
|
+
F: __dxlog_file5,
|
|
2077
2017
|
L: 71,
|
|
2078
2018
|
S: this,
|
|
2079
2019
|
C: (f, a) => f(...a)
|
|
@@ -2093,11 +2033,11 @@ var SwarmMapper = class {
|
|
|
2093
2033
|
]
|
|
2094
2034
|
});
|
|
2095
2035
|
}
|
|
2096
|
-
|
|
2036
|
+
log5("graph changed", {
|
|
2097
2037
|
directConnections: this._swarm.connections.length,
|
|
2098
2038
|
totalPeersInSwarm: this._peers.size
|
|
2099
2039
|
}, {
|
|
2100
|
-
F:
|
|
2040
|
+
F: __dxlog_file5,
|
|
2101
2041
|
L: 112,
|
|
2102
2042
|
S: this,
|
|
2103
2043
|
C: (f, a) => f(...a)
|
|
@@ -2114,17 +2054,17 @@ var SwarmMapper = class {
|
|
|
2114
2054
|
|
|
2115
2055
|
// src/swarm/connection-limiter.ts
|
|
2116
2056
|
import { DeferredTask as DeferredTask2 } from "@dxos/async";
|
|
2117
|
-
import { Context as
|
|
2057
|
+
import { Context as Context4 } from "@dxos/context";
|
|
2118
2058
|
import { invariant as invariant5 } from "@dxos/invariant";
|
|
2119
2059
|
import { PublicKey as PublicKey6 } from "@dxos/keys";
|
|
2120
|
-
import { log as
|
|
2060
|
+
import { log as log6 } from "@dxos/log";
|
|
2121
2061
|
import { CancelledError as CancelledError3 } from "@dxos/protocols";
|
|
2122
2062
|
import { ComplexMap as ComplexMap4 } from "@dxos/util";
|
|
2123
|
-
var
|
|
2063
|
+
var __dxlog_file6 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
|
|
2124
2064
|
var MAX_CONCURRENT_INITIATING_CONNECTIONS = 50;
|
|
2125
2065
|
var ConnectionLimiter = class {
|
|
2126
|
-
_ctx = new
|
|
2127
|
-
F:
|
|
2066
|
+
_ctx = new Context4(void 0, {
|
|
2067
|
+
F: __dxlog_file6,
|
|
2128
2068
|
L: 23
|
|
2129
2069
|
});
|
|
2130
2070
|
_maxConcurrentInitConnections;
|
|
@@ -2145,7 +2085,7 @@ var ConnectionLimiter = class {
|
|
|
2145
2085
|
*/
|
|
2146
2086
|
async connecting(sessionId) {
|
|
2147
2087
|
invariant5(!this._waitingPromises.has(sessionId), "Peer is already waiting for connection", {
|
|
2148
|
-
F:
|
|
2088
|
+
F: __dxlog_file6,
|
|
2149
2089
|
L: 48,
|
|
2150
2090
|
S: this,
|
|
2151
2091
|
A: [
|
|
@@ -2153,10 +2093,10 @@ var ConnectionLimiter = class {
|
|
|
2153
2093
|
"'Peer is already waiting for connection'"
|
|
2154
2094
|
]
|
|
2155
2095
|
});
|
|
2156
|
-
|
|
2096
|
+
log6("waiting", {
|
|
2157
2097
|
sessionId
|
|
2158
2098
|
}, {
|
|
2159
|
-
F:
|
|
2099
|
+
F: __dxlog_file6,
|
|
2160
2100
|
L: 49,
|
|
2161
2101
|
S: this,
|
|
2162
2102
|
C: (f, a) => f(...a)
|
|
@@ -2168,10 +2108,10 @@ var ConnectionLimiter = class {
|
|
|
2168
2108
|
});
|
|
2169
2109
|
this.resolveWaitingPromises.schedule();
|
|
2170
2110
|
});
|
|
2171
|
-
|
|
2111
|
+
log6("allow", {
|
|
2172
2112
|
sessionId
|
|
2173
2113
|
}, {
|
|
2174
|
-
F:
|
|
2114
|
+
F: __dxlog_file6,
|
|
2175
2115
|
L: 57,
|
|
2176
2116
|
S: this,
|
|
2177
2117
|
C: (f, a) => f(...a)
|
|
@@ -2181,10 +2121,10 @@ var ConnectionLimiter = class {
|
|
|
2181
2121
|
* Rejects promise returned by `connecting` method.
|
|
2182
2122
|
*/
|
|
2183
2123
|
doneConnecting(sessionId) {
|
|
2184
|
-
|
|
2124
|
+
log6("done", {
|
|
2185
2125
|
sessionId
|
|
2186
2126
|
}, {
|
|
2187
|
-
F:
|
|
2127
|
+
F: __dxlog_file6,
|
|
2188
2128
|
L: 64,
|
|
2189
2129
|
S: this,
|
|
2190
2130
|
C: (f, a) => f(...a)
|
|
@@ -2204,14 +2144,14 @@ import { raise } from "@dxos/debug";
|
|
|
2204
2144
|
import { PublicKey as PublicKey7 } from "@dxos/keys";
|
|
2205
2145
|
import { ComplexMap as ComplexMap5 } from "@dxos/util";
|
|
2206
2146
|
var CONNECTION_GC_THRESHOLD = 1e3 * 60 * 15;
|
|
2207
|
-
var EventType = /* @__PURE__ */ function(EventType2) {
|
|
2147
|
+
var EventType = /* @__PURE__ */ (function(EventType2) {
|
|
2208
2148
|
EventType2["CONNECTION_STATE_CHANGED"] = "CONNECTION_STATE_CHANGED";
|
|
2209
2149
|
EventType2["PROTOCOL_ERROR"] = "PROTOCOL_ERROR";
|
|
2210
2150
|
EventType2["PROTOCOL_EXTENSIONS_INITIALIZED"] = "PROTOCOL_EXTENSIONS_INITIALIZED";
|
|
2211
2151
|
EventType2["PROTOCOL_EXTENSIONS_HANDSHAKE"] = "PROTOCOL_EXTENSIONS_HANDSHAKE";
|
|
2212
2152
|
EventType2["PROTOCOL_HANDSHAKE"] = "PROTOCOL_HANDSHAKE";
|
|
2213
2153
|
return EventType2;
|
|
2214
|
-
}({});
|
|
2154
|
+
})({});
|
|
2215
2155
|
var ConnectionLog = class {
|
|
2216
2156
|
/**
|
|
2217
2157
|
* SwarmId => info
|
|
@@ -2292,7 +2232,7 @@ var gcSwarm = (swarm) => {
|
|
|
2292
2232
|
import { Event as Event6, synchronized as synchronized4 } from "@dxos/async";
|
|
2293
2233
|
import { invariant as invariant6 } from "@dxos/invariant";
|
|
2294
2234
|
import { PublicKey as PublicKey8 } from "@dxos/keys";
|
|
2295
|
-
import { log as
|
|
2235
|
+
import { log as log7 } from "@dxos/log";
|
|
2296
2236
|
import { Messenger } from "@dxos/messaging";
|
|
2297
2237
|
import { trace as trace3 } from "@dxos/protocols";
|
|
2298
2238
|
import { ConnectionState as ConnectionState2 } from "@dxos/protocols/proto/dxos/client/services";
|
|
@@ -2303,7 +2243,7 @@ function _ts_decorate4(decorators, target, key, desc) {
|
|
|
2303
2243
|
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;
|
|
2304
2244
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2305
2245
|
}
|
|
2306
|
-
var
|
|
2246
|
+
var __dxlog_file7 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts";
|
|
2307
2247
|
var SwarmNetworkManager = class {
|
|
2308
2248
|
/**
|
|
2309
2249
|
* @internal
|
|
@@ -2329,8 +2269,8 @@ var SwarmNetworkManager = class {
|
|
|
2329
2269
|
signalManager: this._signalManager
|
|
2330
2270
|
});
|
|
2331
2271
|
this._signalConnection = {
|
|
2332
|
-
join: (opts) => this._signalManager.join(opts),
|
|
2333
|
-
leave: (opts) => this._signalManager.leave(opts)
|
|
2272
|
+
join: (ctx, opts) => this._signalManager.join(ctx, opts),
|
|
2273
|
+
leave: (ctx, opts) => this._signalManager.leave(ctx, opts)
|
|
2334
2274
|
};
|
|
2335
2275
|
this._peerInfo = peerInfo;
|
|
2336
2276
|
this._connectionLimiter = new ConnectionLimiter();
|
|
@@ -2359,31 +2299,31 @@ var SwarmNetworkManager = class {
|
|
|
2359
2299
|
this._peerInfo = peerInfo;
|
|
2360
2300
|
}
|
|
2361
2301
|
async open() {
|
|
2362
|
-
|
|
2302
|
+
log7.trace("dxos.mesh.network-manager.open", trace3.begin({
|
|
2363
2303
|
id: this._instanceId
|
|
2364
2304
|
}), {
|
|
2365
|
-
F:
|
|
2366
|
-
L:
|
|
2305
|
+
F: __dxlog_file7,
|
|
2306
|
+
L: 134,
|
|
2367
2307
|
S: this,
|
|
2368
2308
|
C: (f, a) => f(...a)
|
|
2369
2309
|
});
|
|
2370
2310
|
await this._messenger.open();
|
|
2371
2311
|
await this._signalManager.open();
|
|
2372
|
-
|
|
2312
|
+
log7.trace("dxos.mesh.network-manager.open", trace3.end({
|
|
2373
2313
|
id: this._instanceId
|
|
2374
2314
|
}), {
|
|
2375
|
-
F:
|
|
2376
|
-
L:
|
|
2315
|
+
F: __dxlog_file7,
|
|
2316
|
+
L: 137,
|
|
2377
2317
|
S: this,
|
|
2378
2318
|
C: (f, a) => f(...a)
|
|
2379
2319
|
});
|
|
2380
2320
|
}
|
|
2381
|
-
async close() {
|
|
2321
|
+
async close(ctx) {
|
|
2382
2322
|
for (const topic of this._swarms.keys()) {
|
|
2383
|
-
await this.leaveSwarm(topic).catch((err) => {
|
|
2384
|
-
|
|
2385
|
-
F:
|
|
2386
|
-
L:
|
|
2323
|
+
await this.leaveSwarm(ctx, topic).catch((err) => {
|
|
2324
|
+
log7(err, void 0, {
|
|
2325
|
+
F: __dxlog_file7,
|
|
2326
|
+
L: 143,
|
|
2387
2327
|
S: this,
|
|
2388
2328
|
C: (f, a) => f(...a)
|
|
2389
2329
|
});
|
|
@@ -2395,10 +2335,10 @@ var SwarmNetworkManager = class {
|
|
|
2395
2335
|
/**
|
|
2396
2336
|
* Join the swarm.
|
|
2397
2337
|
*/
|
|
2398
|
-
async joinSwarm({ topic, topology, protocolProvider: protocol, label }) {
|
|
2338
|
+
async joinSwarm(ctx, { topic, topology, protocolProvider: protocol, label }) {
|
|
2399
2339
|
invariant6(PublicKey8.isPublicKey(topic), void 0, {
|
|
2400
|
-
F:
|
|
2401
|
-
L:
|
|
2340
|
+
F: __dxlog_file7,
|
|
2341
|
+
L: 164,
|
|
2402
2342
|
S: this,
|
|
2403
2343
|
A: [
|
|
2404
2344
|
"PublicKey.isPublicKey(topic)",
|
|
@@ -2406,8 +2346,8 @@ var SwarmNetworkManager = class {
|
|
|
2406
2346
|
]
|
|
2407
2347
|
});
|
|
2408
2348
|
invariant6(topology, void 0, {
|
|
2409
|
-
F:
|
|
2410
|
-
L:
|
|
2349
|
+
F: __dxlog_file7,
|
|
2350
|
+
L: 165,
|
|
2411
2351
|
S: this,
|
|
2412
2352
|
A: [
|
|
2413
2353
|
"topology",
|
|
@@ -2415,8 +2355,8 @@ var SwarmNetworkManager = class {
|
|
|
2415
2355
|
]
|
|
2416
2356
|
});
|
|
2417
2357
|
invariant6(this._peerInfo, void 0, {
|
|
2418
|
-
F:
|
|
2419
|
-
L:
|
|
2358
|
+
F: __dxlog_file7,
|
|
2359
|
+
L: 166,
|
|
2420
2360
|
S: this,
|
|
2421
2361
|
A: [
|
|
2422
2362
|
"this._peerInfo",
|
|
@@ -2424,8 +2364,8 @@ var SwarmNetworkManager = class {
|
|
|
2424
2364
|
]
|
|
2425
2365
|
});
|
|
2426
2366
|
invariant6(typeof protocol === "function", void 0, {
|
|
2427
|
-
F:
|
|
2428
|
-
L:
|
|
2367
|
+
F: __dxlog_file7,
|
|
2368
|
+
L: 167,
|
|
2429
2369
|
S: this,
|
|
2430
2370
|
A: [
|
|
2431
2371
|
"typeof protocol === 'function'",
|
|
@@ -2435,23 +2375,23 @@ var SwarmNetworkManager = class {
|
|
|
2435
2375
|
if (this._swarms.has(topic)) {
|
|
2436
2376
|
throw new Error(`Already connected to swarm: ${PublicKey8.from(topic)}`);
|
|
2437
2377
|
}
|
|
2438
|
-
|
|
2378
|
+
log7("joining", {
|
|
2439
2379
|
topic: PublicKey8.from(topic),
|
|
2440
2380
|
peerInfo: this._peerInfo,
|
|
2441
2381
|
topology: topology.toString()
|
|
2442
2382
|
}, {
|
|
2443
|
-
F:
|
|
2444
|
-
L:
|
|
2383
|
+
F: __dxlog_file7,
|
|
2384
|
+
L: 172,
|
|
2445
2385
|
S: this,
|
|
2446
2386
|
C: (f, a) => f(...a)
|
|
2447
2387
|
});
|
|
2448
2388
|
const swarm = new Swarm(topic, this._peerInfo, topology, protocol, this._messenger, this._transportFactory, label, this._connectionLimiter);
|
|
2449
2389
|
swarm.errors.handle((error) => {
|
|
2450
|
-
|
|
2390
|
+
log7("swarm error", {
|
|
2451
2391
|
error
|
|
2452
2392
|
}, {
|
|
2453
|
-
F:
|
|
2454
|
-
L:
|
|
2393
|
+
F: __dxlog_file7,
|
|
2394
|
+
L: 185,
|
|
2455
2395
|
S: this,
|
|
2456
2396
|
C: (f, a) => f(...a)
|
|
2457
2397
|
});
|
|
@@ -2459,47 +2399,47 @@ var SwarmNetworkManager = class {
|
|
|
2459
2399
|
this._swarms.set(topic, swarm);
|
|
2460
2400
|
this._mappers.set(topic, new SwarmMapper(swarm));
|
|
2461
2401
|
await swarm.open();
|
|
2462
|
-
this._signalConnection.join({
|
|
2402
|
+
this._signalConnection.join(ctx, {
|
|
2463
2403
|
topic,
|
|
2464
2404
|
peer: this._peerInfo
|
|
2465
|
-
}).catch((error) =>
|
|
2466
|
-
F:
|
|
2467
|
-
L:
|
|
2405
|
+
}).catch((error) => log7.catch(error, void 0, {
|
|
2406
|
+
F: __dxlog_file7,
|
|
2407
|
+
L: 194,
|
|
2468
2408
|
S: this,
|
|
2469
2409
|
C: (f, a) => f(...a)
|
|
2470
2410
|
}));
|
|
2471
2411
|
this.topicsUpdated.emit();
|
|
2472
2412
|
this._connectionLog?.joinedSwarm(swarm);
|
|
2473
|
-
|
|
2413
|
+
log7("joined", {
|
|
2474
2414
|
topic: PublicKey8.from(topic),
|
|
2475
2415
|
count: this._swarms.size
|
|
2476
2416
|
}, {
|
|
2477
|
-
F:
|
|
2478
|
-
L:
|
|
2417
|
+
F: __dxlog_file7,
|
|
2418
|
+
L: 198,
|
|
2479
2419
|
S: this,
|
|
2480
2420
|
C: (f, a) => f(...a)
|
|
2481
2421
|
});
|
|
2482
2422
|
return {
|
|
2483
|
-
close: () => this.leaveSwarm(topic)
|
|
2423
|
+
close: (ctx2) => this.leaveSwarm(ctx2, topic)
|
|
2484
2424
|
};
|
|
2485
2425
|
}
|
|
2486
2426
|
/**
|
|
2487
2427
|
* Close the connection.
|
|
2488
2428
|
*/
|
|
2489
|
-
async leaveSwarm(topic) {
|
|
2429
|
+
async leaveSwarm(ctx, topic) {
|
|
2490
2430
|
if (!this._swarms.has(topic)) {
|
|
2491
2431
|
return;
|
|
2492
2432
|
}
|
|
2493
|
-
|
|
2433
|
+
log7("leaving", {
|
|
2494
2434
|
topic: PublicKey8.from(topic)
|
|
2495
2435
|
}, {
|
|
2496
|
-
F:
|
|
2497
|
-
L:
|
|
2436
|
+
F: __dxlog_file7,
|
|
2437
|
+
L: 215,
|
|
2498
2438
|
S: this,
|
|
2499
2439
|
C: (f, a) => f(...a)
|
|
2500
2440
|
});
|
|
2501
2441
|
const swarm = this._swarms.get(topic);
|
|
2502
|
-
await this._signalConnection.leave({
|
|
2442
|
+
await this._signalConnection.leave(ctx, {
|
|
2503
2443
|
topic,
|
|
2504
2444
|
peer: swarm.ownPeer
|
|
2505
2445
|
});
|
|
@@ -2510,12 +2450,12 @@ var SwarmNetworkManager = class {
|
|
|
2510
2450
|
await swarm.destroy();
|
|
2511
2451
|
this._swarms.delete(topic);
|
|
2512
2452
|
this.topicsUpdated.emit();
|
|
2513
|
-
|
|
2453
|
+
log7("left", {
|
|
2514
2454
|
topic: PublicKey8.from(topic),
|
|
2515
2455
|
count: this._swarms.size
|
|
2516
2456
|
}, {
|
|
2517
|
-
F:
|
|
2518
|
-
L:
|
|
2457
|
+
F: __dxlog_file7,
|
|
2458
|
+
L: 229,
|
|
2519
2459
|
S: this,
|
|
2520
2460
|
C: (f, a) => f(...a)
|
|
2521
2461
|
});
|
|
@@ -2556,7 +2496,7 @@ _ts_decorate4([
|
|
|
2556
2496
|
|
|
2557
2497
|
// src/topology/fully-connected-topology.ts
|
|
2558
2498
|
import { invariant as invariant7 } from "@dxos/invariant";
|
|
2559
|
-
var
|
|
2499
|
+
var __dxlog_file8 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
|
|
2560
2500
|
var FullyConnectedTopology = class {
|
|
2561
2501
|
_controller;
|
|
2562
2502
|
toString() {
|
|
@@ -2564,7 +2504,7 @@ var FullyConnectedTopology = class {
|
|
|
2564
2504
|
}
|
|
2565
2505
|
init(controller) {
|
|
2566
2506
|
invariant7(!this._controller, "Already initialized", {
|
|
2567
|
-
F:
|
|
2507
|
+
F: __dxlog_file8,
|
|
2568
2508
|
L: 18,
|
|
2569
2509
|
S: this,
|
|
2570
2510
|
A: [
|
|
@@ -2576,7 +2516,7 @@ var FullyConnectedTopology = class {
|
|
|
2576
2516
|
}
|
|
2577
2517
|
update() {
|
|
2578
2518
|
invariant7(this._controller, "Not initialized", {
|
|
2579
|
-
F:
|
|
2519
|
+
F: __dxlog_file8,
|
|
2580
2520
|
L: 23,
|
|
2581
2521
|
S: this,
|
|
2582
2522
|
A: [
|
|
@@ -2596,321 +2536,13 @@ var FullyConnectedTopology = class {
|
|
|
2596
2536
|
}
|
|
2597
2537
|
};
|
|
2598
2538
|
|
|
2599
|
-
// src/topology/mmst-topology.ts
|
|
2600
|
-
import { invariant as invariant8 } from "@dxos/invariant";
|
|
2601
|
-
import { log as log9 } from "@dxos/log";
|
|
2602
|
-
var __dxlog_file10 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/topology/mmst-topology.ts";
|
|
2603
|
-
var MIN_UPDATE_INTERVAL = 1e3 * 10;
|
|
2604
|
-
var MAX_CHANGES_PER_UPDATE = 1;
|
|
2605
|
-
var MMSTTopology = class {
|
|
2606
|
-
_originateConnections;
|
|
2607
|
-
_maxPeers;
|
|
2608
|
-
_sampleSize;
|
|
2609
|
-
_controller;
|
|
2610
|
-
_sampleCollected = false;
|
|
2611
|
-
_lastAction = /* @__PURE__ */ new Date(0);
|
|
2612
|
-
constructor({ originateConnections = 2, maxPeers = 4, sampleSize = 10 } = {}) {
|
|
2613
|
-
this._originateConnections = originateConnections;
|
|
2614
|
-
this._maxPeers = maxPeers;
|
|
2615
|
-
this._sampleSize = sampleSize;
|
|
2616
|
-
}
|
|
2617
|
-
init(controller) {
|
|
2618
|
-
invariant8(!this._controller, "Already initialized", {
|
|
2619
|
-
F: __dxlog_file10,
|
|
2620
|
-
L: 49,
|
|
2621
|
-
S: this,
|
|
2622
|
-
A: [
|
|
2623
|
-
"!this._controller",
|
|
2624
|
-
"'Already initialized'"
|
|
2625
|
-
]
|
|
2626
|
-
});
|
|
2627
|
-
this._controller = controller;
|
|
2628
|
-
}
|
|
2629
|
-
update() {
|
|
2630
|
-
invariant8(this._controller, "Not initialized", {
|
|
2631
|
-
F: __dxlog_file10,
|
|
2632
|
-
L: 54,
|
|
2633
|
-
S: this,
|
|
2634
|
-
A: [
|
|
2635
|
-
"this._controller",
|
|
2636
|
-
"'Not initialized'"
|
|
2637
|
-
]
|
|
2638
|
-
});
|
|
2639
|
-
const { connected, candidates } = this._controller.getState();
|
|
2640
|
-
if (this._sampleCollected || connected.length > this._maxPeers || candidates.length > 0) {
|
|
2641
|
-
log9("Running the algorithm.", void 0, {
|
|
2642
|
-
F: __dxlog_file10,
|
|
2643
|
-
L: 58,
|
|
2644
|
-
S: this,
|
|
2645
|
-
C: (f, a) => f(...a)
|
|
2646
|
-
});
|
|
2647
|
-
this._sampleCollected = true;
|
|
2648
|
-
this._runAlgorithm();
|
|
2649
|
-
}
|
|
2650
|
-
}
|
|
2651
|
-
forceUpdate() {
|
|
2652
|
-
this._lastAction = /* @__PURE__ */ new Date(0);
|
|
2653
|
-
this.update();
|
|
2654
|
-
}
|
|
2655
|
-
async onOffer(peer) {
|
|
2656
|
-
invariant8(this._controller, "Not initialized", {
|
|
2657
|
-
F: __dxlog_file10,
|
|
2658
|
-
L: 70,
|
|
2659
|
-
S: this,
|
|
2660
|
-
A: [
|
|
2661
|
-
"this._controller",
|
|
2662
|
-
"'Not initialized'"
|
|
2663
|
-
]
|
|
2664
|
-
});
|
|
2665
|
-
const { connected } = this._controller.getState();
|
|
2666
|
-
const accept = connected.length < this._maxPeers;
|
|
2667
|
-
log9(`Offer ${peer} accept=${accept}`, void 0, {
|
|
2668
|
-
F: __dxlog_file10,
|
|
2669
|
-
L: 73,
|
|
2670
|
-
S: this,
|
|
2671
|
-
C: (f, a) => f(...a)
|
|
2672
|
-
});
|
|
2673
|
-
return accept;
|
|
2674
|
-
}
|
|
2675
|
-
async destroy() {
|
|
2676
|
-
}
|
|
2677
|
-
_runAlgorithm() {
|
|
2678
|
-
invariant8(this._controller, "Not initialized", {
|
|
2679
|
-
F: __dxlog_file10,
|
|
2680
|
-
L: 82,
|
|
2681
|
-
S: this,
|
|
2682
|
-
A: [
|
|
2683
|
-
"this._controller",
|
|
2684
|
-
"'Not initialized'"
|
|
2685
|
-
]
|
|
2686
|
-
});
|
|
2687
|
-
const { connected, candidates, ownPeerId } = this._controller.getState();
|
|
2688
|
-
if (connected.length > this._maxPeers) {
|
|
2689
|
-
log9(`disconnect ${connected.length - this._maxPeers} peers.`, void 0, {
|
|
2690
|
-
F: __dxlog_file10,
|
|
2691
|
-
L: 88,
|
|
2692
|
-
S: this,
|
|
2693
|
-
C: (f, a) => f(...a)
|
|
2694
|
-
});
|
|
2695
|
-
const sorted = sortByXorDistance(connected, ownPeerId).reverse().slice(0, this._maxPeers - connected.length);
|
|
2696
|
-
invariant8(sorted.length === 0, void 0, {
|
|
2697
|
-
F: __dxlog_file10,
|
|
2698
|
-
L: 92,
|
|
2699
|
-
S: this,
|
|
2700
|
-
A: [
|
|
2701
|
-
"sorted.length === 0",
|
|
2702
|
-
""
|
|
2703
|
-
]
|
|
2704
|
-
});
|
|
2705
|
-
if (sorted.length > MAX_CHANGES_PER_UPDATE) {
|
|
2706
|
-
log9(`want to disconnect ${sorted.length} peers but limited to ${MAX_CHANGES_PER_UPDATE}`, void 0, {
|
|
2707
|
-
F: __dxlog_file10,
|
|
2708
|
-
L: 95,
|
|
2709
|
-
S: this,
|
|
2710
|
-
C: (f, a) => f(...a)
|
|
2711
|
-
});
|
|
2712
|
-
}
|
|
2713
|
-
if (Date.now() - this._lastAction.getTime() > MIN_UPDATE_INTERVAL) {
|
|
2714
|
-
for (const peer of sorted.slice(0, MAX_CHANGES_PER_UPDATE)) {
|
|
2715
|
-
log9(`Disconnect ${peer}.`, void 0, {
|
|
2716
|
-
F: __dxlog_file10,
|
|
2717
|
-
L: 100,
|
|
2718
|
-
S: this,
|
|
2719
|
-
C: (f, a) => f(...a)
|
|
2720
|
-
});
|
|
2721
|
-
this._controller.disconnect(peer);
|
|
2722
|
-
}
|
|
2723
|
-
this._lastAction = /* @__PURE__ */ new Date();
|
|
2724
|
-
} else {
|
|
2725
|
-
log9("rate limited disconnect", void 0, {
|
|
2726
|
-
F: __dxlog_file10,
|
|
2727
|
-
L: 105,
|
|
2728
|
-
S: this,
|
|
2729
|
-
C: (f, a) => f(...a)
|
|
2730
|
-
});
|
|
2731
|
-
}
|
|
2732
|
-
} else if (connected.length < this._originateConnections) {
|
|
2733
|
-
log9(`connect ${this._originateConnections - connected.length} peers.`, void 0, {
|
|
2734
|
-
F: __dxlog_file10,
|
|
2735
|
-
L: 109,
|
|
2736
|
-
S: this,
|
|
2737
|
-
C: (f, a) => f(...a)
|
|
2738
|
-
});
|
|
2739
|
-
const sample = candidates.sort(() => Math.random() - 0.5).slice(0, this._sampleSize);
|
|
2740
|
-
const sorted = sortByXorDistance(sample, ownPeerId).slice(0, this._originateConnections - connected.length);
|
|
2741
|
-
if (sorted.length > MAX_CHANGES_PER_UPDATE) {
|
|
2742
|
-
log9(`want to connect ${sorted.length} peers but limited to ${MAX_CHANGES_PER_UPDATE}`, void 0, {
|
|
2743
|
-
F: __dxlog_file10,
|
|
2744
|
-
L: 114,
|
|
2745
|
-
S: this,
|
|
2746
|
-
C: (f, a) => f(...a)
|
|
2747
|
-
});
|
|
2748
|
-
}
|
|
2749
|
-
if (Date.now() - this._lastAction.getTime() > MIN_UPDATE_INTERVAL) {
|
|
2750
|
-
for (const peer of sorted.slice(0, MAX_CHANGES_PER_UPDATE)) {
|
|
2751
|
-
log9(`Connect ${peer}.`, void 0, {
|
|
2752
|
-
F: __dxlog_file10,
|
|
2753
|
-
L: 118,
|
|
2754
|
-
S: this,
|
|
2755
|
-
C: (f, a) => f(...a)
|
|
2756
|
-
});
|
|
2757
|
-
this._controller.connect(peer);
|
|
2758
|
-
}
|
|
2759
|
-
this._lastAction = /* @__PURE__ */ new Date();
|
|
2760
|
-
} else {
|
|
2761
|
-
log9("rate limited connect", void 0, {
|
|
2762
|
-
F: __dxlog_file10,
|
|
2763
|
-
L: 123,
|
|
2764
|
-
S: this,
|
|
2765
|
-
C: (f, a) => f(...a)
|
|
2766
|
-
});
|
|
2767
|
-
}
|
|
2768
|
-
}
|
|
2769
|
-
}
|
|
2770
|
-
toString() {
|
|
2771
|
-
return "MMSTTopology";
|
|
2772
|
-
}
|
|
2773
|
-
};
|
|
2774
|
-
var sortByXorDistance = (keys, reference) => {
|
|
2775
|
-
const sorted = keys.sort((a, b) => {
|
|
2776
|
-
return compareXor(distXor(a.asBuffer(), reference.asBuffer()), distXor(b.asBuffer(), reference.asBuffer()));
|
|
2777
|
-
});
|
|
2778
|
-
log9("Sorted keys", {
|
|
2779
|
-
keys,
|
|
2780
|
-
reference,
|
|
2781
|
-
sorted
|
|
2782
|
-
}, {
|
|
2783
|
-
F: __dxlog_file10,
|
|
2784
|
-
L: 137,
|
|
2785
|
-
S: void 0,
|
|
2786
|
-
C: (f, a) => f(...a)
|
|
2787
|
-
});
|
|
2788
|
-
return sorted;
|
|
2789
|
-
};
|
|
2790
|
-
var distXor = (a, b) => {
|
|
2791
|
-
const maxLength = Math.max(a.length, b.length);
|
|
2792
|
-
const result = Buffer.allocUnsafe(maxLength);
|
|
2793
|
-
for (let i = 0; i < maxLength; i++) {
|
|
2794
|
-
result[i] = (a[i] || 0) ^ (b[i] || 0);
|
|
2795
|
-
}
|
|
2796
|
-
return result;
|
|
2797
|
-
};
|
|
2798
|
-
var compareXor = (a, b) => {
|
|
2799
|
-
const maxLength = Math.max(a.length, b.length);
|
|
2800
|
-
for (let i = 0; i < maxLength; i++) {
|
|
2801
|
-
if ((a[i] || 0) === (b[i] || 0)) {
|
|
2802
|
-
continue;
|
|
2803
|
-
}
|
|
2804
|
-
return (a[i] || 0) < (b[i] || 0) ? -1 : 1;
|
|
2805
|
-
}
|
|
2806
|
-
return 0;
|
|
2807
|
-
};
|
|
2808
|
-
|
|
2809
|
-
// src/topology/star-topology.ts
|
|
2810
|
-
import { invariant as invariant9 } from "@dxos/invariant";
|
|
2811
|
-
import { log as log10 } from "@dxos/log";
|
|
2812
|
-
var __dxlog_file11 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/topology/star-topology.ts";
|
|
2813
|
-
var StarTopology = class {
|
|
2814
|
-
_centralPeer;
|
|
2815
|
-
_controller;
|
|
2816
|
-
constructor(_centralPeer) {
|
|
2817
|
-
this._centralPeer = _centralPeer;
|
|
2818
|
-
}
|
|
2819
|
-
toString() {
|
|
2820
|
-
return `StarTopology(${this._centralPeer.truncate()})`;
|
|
2821
|
-
}
|
|
2822
|
-
init(controller) {
|
|
2823
|
-
invariant9(!this._controller, "Already initialized.", {
|
|
2824
|
-
F: __dxlog_file11,
|
|
2825
|
-
L: 21,
|
|
2826
|
-
S: this,
|
|
2827
|
-
A: [
|
|
2828
|
-
"!this._controller",
|
|
2829
|
-
"'Already initialized.'"
|
|
2830
|
-
]
|
|
2831
|
-
});
|
|
2832
|
-
this._controller = controller;
|
|
2833
|
-
}
|
|
2834
|
-
update() {
|
|
2835
|
-
invariant9(this._controller, "Not initialized.", {
|
|
2836
|
-
F: __dxlog_file11,
|
|
2837
|
-
L: 26,
|
|
2838
|
-
S: this,
|
|
2839
|
-
A: [
|
|
2840
|
-
"this._controller",
|
|
2841
|
-
"'Not initialized.'"
|
|
2842
|
-
]
|
|
2843
|
-
});
|
|
2844
|
-
const { candidates, connected, ownPeerId } = this._controller.getState();
|
|
2845
|
-
if (!ownPeerId.equals(this._centralPeer)) {
|
|
2846
|
-
log10("leaf peer dropping all connections apart from central peer.", void 0, {
|
|
2847
|
-
F: __dxlog_file11,
|
|
2848
|
-
L: 29,
|
|
2849
|
-
S: this,
|
|
2850
|
-
C: (f, a) => f(...a)
|
|
2851
|
-
});
|
|
2852
|
-
for (const peer of connected) {
|
|
2853
|
-
if (!peer.equals(this._centralPeer)) {
|
|
2854
|
-
log10("dropping connection", {
|
|
2855
|
-
peer
|
|
2856
|
-
}, {
|
|
2857
|
-
F: __dxlog_file11,
|
|
2858
|
-
L: 34,
|
|
2859
|
-
S: this,
|
|
2860
|
-
C: (f, a) => f(...a)
|
|
2861
|
-
});
|
|
2862
|
-
this._controller.disconnect(peer);
|
|
2863
|
-
}
|
|
2864
|
-
}
|
|
2865
|
-
}
|
|
2866
|
-
for (const peer of candidates) {
|
|
2867
|
-
if (peer.equals(this._centralPeer) || ownPeerId.equals(this._centralPeer)) {
|
|
2868
|
-
log10("connecting to peer", {
|
|
2869
|
-
peer
|
|
2870
|
-
}, {
|
|
2871
|
-
F: __dxlog_file11,
|
|
2872
|
-
L: 43,
|
|
2873
|
-
S: this,
|
|
2874
|
-
C: (f, a) => f(...a)
|
|
2875
|
-
});
|
|
2876
|
-
this._controller.connect(peer);
|
|
2877
|
-
}
|
|
2878
|
-
}
|
|
2879
|
-
}
|
|
2880
|
-
async onOffer(peer) {
|
|
2881
|
-
invariant9(this._controller, "Not initialized.", {
|
|
2882
|
-
F: __dxlog_file11,
|
|
2883
|
-
L: 50,
|
|
2884
|
-
S: this,
|
|
2885
|
-
A: [
|
|
2886
|
-
"this._controller",
|
|
2887
|
-
"'Not initialized.'"
|
|
2888
|
-
]
|
|
2889
|
-
});
|
|
2890
|
-
const { ownPeerId } = this._controller.getState();
|
|
2891
|
-
log10("offer", {
|
|
2892
|
-
peer,
|
|
2893
|
-
isCentral: peer.equals(this._centralPeer),
|
|
2894
|
-
isSelfCentral: ownPeerId.equals(this._centralPeer)
|
|
2895
|
-
}, {
|
|
2896
|
-
F: __dxlog_file11,
|
|
2897
|
-
L: 52,
|
|
2898
|
-
S: this,
|
|
2899
|
-
C: (f, a) => f(...a)
|
|
2900
|
-
});
|
|
2901
|
-
return ownPeerId.equals(this._centralPeer) || peer.equals(this._centralPeer);
|
|
2902
|
-
}
|
|
2903
|
-
async destroy() {
|
|
2904
|
-
}
|
|
2905
|
-
};
|
|
2906
|
-
|
|
2907
2539
|
// src/transport/memory-transport.ts
|
|
2908
2540
|
import { Transform } from "@dxos/node-std/stream";
|
|
2909
2541
|
import { Event as Event7, Trigger as Trigger2 } from "@dxos/async";
|
|
2910
2542
|
import { ErrorStream as ErrorStream3 } from "@dxos/debug";
|
|
2911
|
-
import { invariant as
|
|
2543
|
+
import { invariant as invariant8 } from "@dxos/invariant";
|
|
2912
2544
|
import { PublicKey as PublicKey9 } from "@dxos/keys";
|
|
2913
|
-
import { log as
|
|
2545
|
+
import { log as log8, logInfo as logInfo3 } from "@dxos/log";
|
|
2914
2546
|
import { ComplexMap as ComplexMap7 } from "@dxos/util";
|
|
2915
2547
|
function _ts_decorate5(decorators, target, key, desc) {
|
|
2916
2548
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -2918,7 +2550,7 @@ function _ts_decorate5(decorators, target, key, desc) {
|
|
|
2918
2550
|
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;
|
|
2919
2551
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2920
2552
|
}
|
|
2921
|
-
var
|
|
2553
|
+
var __dxlog_file9 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
|
|
2922
2554
|
var MEMORY_TRANSPORT_DELAY = 1;
|
|
2923
2555
|
var createStreamDelay = (delay) => {
|
|
2924
2556
|
return new Transform({
|
|
@@ -2935,28 +2567,20 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2935
2567
|
_options;
|
|
2936
2568
|
// TODO(burdon): Remove static properties (inject context into constructor).
|
|
2937
2569
|
static _connections = new ComplexMap7(PublicKey9.hash);
|
|
2938
|
-
_instanceId;
|
|
2939
|
-
_remote;
|
|
2940
|
-
_outgoingDelay;
|
|
2941
|
-
_incomingDelay;
|
|
2942
|
-
_closed;
|
|
2570
|
+
_instanceId = PublicKey9.random();
|
|
2571
|
+
_remote = new Trigger2();
|
|
2572
|
+
_outgoingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
2573
|
+
_incomingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
2574
|
+
_closed = false;
|
|
2943
2575
|
_remoteInstanceId;
|
|
2944
2576
|
_remoteConnection;
|
|
2945
|
-
closed;
|
|
2946
|
-
connected;
|
|
2947
|
-
errors;
|
|
2577
|
+
closed = new Event7();
|
|
2578
|
+
connected = new Event7();
|
|
2579
|
+
errors = new ErrorStream3();
|
|
2948
2580
|
constructor(_options) {
|
|
2949
2581
|
this._options = _options;
|
|
2950
|
-
this._instanceId
|
|
2951
|
-
|
|
2952
|
-
this._outgoingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
2953
|
-
this._incomingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
2954
|
-
this._closed = false;
|
|
2955
|
-
this.closed = new Event7();
|
|
2956
|
-
this.connected = new Event7();
|
|
2957
|
-
this.errors = new ErrorStream3();
|
|
2958
|
-
invariant10(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection", {
|
|
2959
|
-
F: __dxlog_file12,
|
|
2582
|
+
invariant8(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection", {
|
|
2583
|
+
F: __dxlog_file9,
|
|
2960
2584
|
L: 64,
|
|
2961
2585
|
S: this,
|
|
2962
2586
|
A: [
|
|
@@ -2970,15 +2594,15 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2970
2594
|
return !this._closed;
|
|
2971
2595
|
}
|
|
2972
2596
|
async open() {
|
|
2973
|
-
|
|
2974
|
-
F:
|
|
2597
|
+
log8("opening...", void 0, {
|
|
2598
|
+
F: __dxlog_file9,
|
|
2975
2599
|
L: 74,
|
|
2976
2600
|
S: this,
|
|
2977
2601
|
C: (f, a) => f(...a)
|
|
2978
2602
|
});
|
|
2979
2603
|
if (this._options.initiator) {
|
|
2980
|
-
|
|
2981
|
-
F:
|
|
2604
|
+
log8("sending signal", void 0, {
|
|
2605
|
+
F: __dxlog_file9,
|
|
2982
2606
|
L: 78,
|
|
2983
2607
|
S: this,
|
|
2984
2608
|
C: (f, a) => f(...a)
|
|
@@ -3008,8 +2632,8 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
3008
2632
|
this.closed.emit();
|
|
3009
2633
|
return;
|
|
3010
2634
|
}
|
|
3011
|
-
|
|
3012
|
-
F:
|
|
2635
|
+
invariant8(!this._remoteConnection._remoteConnection, `Remote already connected: ${this._remoteInstanceId}`, {
|
|
2636
|
+
F: __dxlog_file9,
|
|
3013
2637
|
L: 104,
|
|
3014
2638
|
S: this,
|
|
3015
2639
|
A: [
|
|
@@ -3019,8 +2643,8 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
3019
2643
|
});
|
|
3020
2644
|
this._remoteConnection._remoteConnection = this;
|
|
3021
2645
|
this._remoteConnection._remoteInstanceId = this._instanceId;
|
|
3022
|
-
|
|
3023
|
-
F:
|
|
2646
|
+
log8("connected", void 0, {
|
|
2647
|
+
F: __dxlog_file9,
|
|
3024
2648
|
L: 108,
|
|
3025
2649
|
S: this,
|
|
3026
2650
|
C: (f, a) => f(...a)
|
|
@@ -3038,8 +2662,8 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
3038
2662
|
return this;
|
|
3039
2663
|
}
|
|
3040
2664
|
async close() {
|
|
3041
|
-
|
|
3042
|
-
F:
|
|
2665
|
+
log8("closing...", void 0, {
|
|
2666
|
+
F: __dxlog_file9,
|
|
3043
2667
|
L: 130,
|
|
3044
2668
|
S: this,
|
|
3045
2669
|
C: (f, a) => f(...a)
|
|
@@ -3059,8 +2683,8 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
3059
2683
|
this._remoteConnection = void 0;
|
|
3060
2684
|
}
|
|
3061
2685
|
this.closed.emit();
|
|
3062
|
-
|
|
3063
|
-
F:
|
|
2686
|
+
log8("closed", void 0, {
|
|
2687
|
+
F: __dxlog_file9,
|
|
3064
2688
|
L: 158,
|
|
3065
2689
|
S: this,
|
|
3066
2690
|
C: (f, a) => f(...a)
|
|
@@ -3068,10 +2692,10 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
3068
2692
|
return this;
|
|
3069
2693
|
}
|
|
3070
2694
|
async onSignal({ payload }) {
|
|
3071
|
-
|
|
2695
|
+
log8("received signal", {
|
|
3072
2696
|
payload
|
|
3073
2697
|
}, {
|
|
3074
|
-
F:
|
|
2698
|
+
F: __dxlog_file9,
|
|
3075
2699
|
L: 163,
|
|
3076
2700
|
S: this,
|
|
3077
2701
|
C: (f, a) => f(...a)
|
|
@@ -3106,13 +2730,13 @@ _ts_decorate5([
|
|
|
3106
2730
|
var toError = (err) => err instanceof Error ? err : new Error(String(err));
|
|
3107
2731
|
|
|
3108
2732
|
// src/transport/transport.ts
|
|
3109
|
-
var TransportKind = /* @__PURE__ */ function(TransportKind2) {
|
|
2733
|
+
var TransportKind = /* @__PURE__ */ (function(TransportKind2) {
|
|
3110
2734
|
TransportKind2["WEB_RTC"] = "WEB-RTC";
|
|
3111
2735
|
TransportKind2["WEB_RTC_PROXY"] = "WEB-RTC_PROXY";
|
|
3112
2736
|
TransportKind2["MEMORY"] = "MEMORY";
|
|
3113
2737
|
TransportKind2["TCP"] = "TCP";
|
|
3114
2738
|
return TransportKind2;
|
|
3115
|
-
}({});
|
|
2739
|
+
})({});
|
|
3116
2740
|
|
|
3117
2741
|
// src/transport/webrtc/rtc-connection-factory.ts
|
|
3118
2742
|
import { Mutex } from "@dxos/async";
|
|
@@ -3161,8 +2785,8 @@ var getRtcConnectionFactory = () => {
|
|
|
3161
2785
|
|
|
3162
2786
|
// src/transport/webrtc/rtc-peer-connection.ts
|
|
3163
2787
|
import { Mutex as Mutex2, Trigger as Trigger3, synchronized as synchronized5 } from "@dxos/async";
|
|
3164
|
-
import { invariant as
|
|
3165
|
-
import { log as
|
|
2788
|
+
import { invariant as invariant10 } from "@dxos/invariant";
|
|
2789
|
+
import { log as log10, logInfo as logInfo4 } from "@dxos/log";
|
|
3166
2790
|
import { ConnectivityError as ConnectivityError3 } from "@dxos/protocols";
|
|
3167
2791
|
import { trace as trace4 } from "@dxos/tracing";
|
|
3168
2792
|
|
|
@@ -3171,8 +2795,8 @@ import { Duplex } from "@dxos/node-std/stream";
|
|
|
3171
2795
|
import { Event as AsyncEvent } from "@dxos/async";
|
|
3172
2796
|
import { Resource } from "@dxos/context";
|
|
3173
2797
|
import { ErrorStream as ErrorStream4 } from "@dxos/debug";
|
|
3174
|
-
import { invariant as
|
|
3175
|
-
import { log as
|
|
2798
|
+
import { invariant as invariant9 } from "@dxos/invariant";
|
|
2799
|
+
import { log as log9 } from "@dxos/log";
|
|
3176
2800
|
import { ConnectivityError as ConnectivityError2 } from "@dxos/protocols";
|
|
3177
2801
|
|
|
3178
2802
|
// src/transport/webrtc/rtc-transport-stats.ts
|
|
@@ -3223,21 +2847,21 @@ var getRtcConnectionStats = async (connection, channelTopic) => {
|
|
|
3223
2847
|
};
|
|
3224
2848
|
|
|
3225
2849
|
// src/transport/webrtc/rtc-transport-channel.ts
|
|
3226
|
-
var
|
|
2850
|
+
var __dxlog_file10 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-channel.ts";
|
|
3227
2851
|
var MAX_MESSAGE_SIZE = 64 * 1024;
|
|
3228
2852
|
var MAX_BUFFERED_AMOUNT = 64 * 1024;
|
|
3229
2853
|
var RtcTransportChannel = class extends Resource {
|
|
3230
2854
|
_connection;
|
|
3231
2855
|
_options;
|
|
3232
|
-
closed;
|
|
3233
|
-
connected;
|
|
3234
|
-
errors;
|
|
2856
|
+
closed = new AsyncEvent();
|
|
2857
|
+
connected = new AsyncEvent();
|
|
2858
|
+
errors = new ErrorStream4();
|
|
3235
2859
|
_channel;
|
|
3236
2860
|
_stream;
|
|
3237
|
-
_streamDataFlushedCallback;
|
|
3238
|
-
_isChannelCreationInProgress;
|
|
2861
|
+
_streamDataFlushedCallback = null;
|
|
2862
|
+
_isChannelCreationInProgress = false;
|
|
3239
2863
|
constructor(_connection, _options) {
|
|
3240
|
-
super(), this._connection = _connection, this._options = _options
|
|
2864
|
+
super(), this._connection = _connection, this._options = _options;
|
|
3241
2865
|
}
|
|
3242
2866
|
get isRtcChannelCreationInProgress() {
|
|
3243
2867
|
return this._isChannelCreationInProgress;
|
|
@@ -3248,9 +2872,9 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3248
2872
|
}
|
|
3249
2873
|
}
|
|
3250
2874
|
async _open() {
|
|
3251
|
-
|
|
3252
|
-
F:
|
|
3253
|
-
L:
|
|
2875
|
+
invariant9(!this._isChannelCreationInProgress, void 0, {
|
|
2876
|
+
F: __dxlog_file10,
|
|
2877
|
+
L: 56,
|
|
3254
2878
|
S: this,
|
|
3255
2879
|
A: [
|
|
3256
2880
|
"!this._isChannelCreationInProgress",
|
|
@@ -3267,14 +2891,16 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3267
2891
|
}
|
|
3268
2892
|
}).catch((err) => {
|
|
3269
2893
|
if (this.isOpen) {
|
|
3270
|
-
const error = err instanceof Error ? err : new ConnectivityError2(
|
|
2894
|
+
const error = err instanceof Error ? err : new ConnectivityError2({
|
|
2895
|
+
message: `Failed to create a channel: ${JSON.stringify(err?.message)}`
|
|
2896
|
+
});
|
|
3271
2897
|
this.errors.raise(error);
|
|
3272
2898
|
} else {
|
|
3273
|
-
|
|
2899
|
+
log9.verbose("connection establishment failed after transport was closed", {
|
|
3274
2900
|
err
|
|
3275
2901
|
}, {
|
|
3276
|
-
F:
|
|
3277
|
-
L:
|
|
2902
|
+
F: __dxlog_file10,
|
|
2903
|
+
L: 76,
|
|
3278
2904
|
S: this,
|
|
3279
2905
|
C: (f, a) => f(...a)
|
|
3280
2906
|
});
|
|
@@ -3290,9 +2916,9 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3290
2916
|
this._stream = void 0;
|
|
3291
2917
|
}
|
|
3292
2918
|
this.closed.emit();
|
|
3293
|
-
|
|
3294
|
-
F:
|
|
3295
|
-
L:
|
|
2919
|
+
log9("closed", void 0, {
|
|
2920
|
+
F: __dxlog_file10,
|
|
2921
|
+
L: 92,
|
|
3296
2922
|
S: this,
|
|
3297
2923
|
C: (f, a) => f(...a)
|
|
3298
2924
|
});
|
|
@@ -3301,20 +2927,20 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3301
2927
|
Object.assign(channel, {
|
|
3302
2928
|
onopen: () => {
|
|
3303
2929
|
if (!this.isOpen) {
|
|
3304
|
-
|
|
2930
|
+
log9.warn("channel opened in a closed transport", {
|
|
3305
2931
|
topic: this._options.topic
|
|
3306
2932
|
}, {
|
|
3307
|
-
F:
|
|
3308
|
-
L:
|
|
2933
|
+
F: __dxlog_file10,
|
|
2934
|
+
L: 99,
|
|
3309
2935
|
S: this,
|
|
3310
2936
|
C: (f, a) => f(...a)
|
|
3311
2937
|
});
|
|
3312
2938
|
this._safeCloseChannel(channel);
|
|
3313
2939
|
return;
|
|
3314
2940
|
}
|
|
3315
|
-
|
|
3316
|
-
F:
|
|
3317
|
-
L:
|
|
2941
|
+
log9("onopen", void 0, {
|
|
2942
|
+
F: __dxlog_file10,
|
|
2943
|
+
L: 104,
|
|
3318
2944
|
S: this,
|
|
3319
2945
|
C: (f, a) => f(...a)
|
|
3320
2946
|
});
|
|
@@ -3330,9 +2956,9 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3330
2956
|
this.connected.emit();
|
|
3331
2957
|
},
|
|
3332
2958
|
onclose: async () => {
|
|
3333
|
-
|
|
3334
|
-
F:
|
|
3335
|
-
L:
|
|
2959
|
+
log9("onclose", void 0, {
|
|
2960
|
+
F: __dxlog_file10,
|
|
2961
|
+
L: 117,
|
|
3336
2962
|
S: this,
|
|
3337
2963
|
C: (f, a) => f(...a)
|
|
3338
2964
|
});
|
|
@@ -3340,9 +2966,9 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3340
2966
|
},
|
|
3341
2967
|
onmessage: async (event) => {
|
|
3342
2968
|
if (!this._stream) {
|
|
3343
|
-
|
|
3344
|
-
F:
|
|
3345
|
-
L:
|
|
2969
|
+
log9.warn("ignoring message on a closed channel", void 0, {
|
|
2970
|
+
F: __dxlog_file10,
|
|
2971
|
+
L: 123,
|
|
3346
2972
|
S: this,
|
|
3347
2973
|
C: (f, a) => f(...a)
|
|
3348
2974
|
});
|
|
@@ -3371,9 +2997,9 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3371
2997
|
}
|
|
3372
2998
|
async _handleChannelWrite(chunk, callback) {
|
|
3373
2999
|
if (!this._channel) {
|
|
3374
|
-
|
|
3375
|
-
F:
|
|
3376
|
-
L:
|
|
3000
|
+
log9.warn("writing to a channel after a connection was closed", void 0, {
|
|
3001
|
+
F: __dxlog_file10,
|
|
3002
|
+
L: 153,
|
|
3377
3003
|
S: this,
|
|
3378
3004
|
C: (f, a) => f(...a)
|
|
3379
3005
|
});
|
|
@@ -3394,9 +3020,9 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3394
3020
|
}
|
|
3395
3021
|
if (this._channel.bufferedAmount > MAX_BUFFERED_AMOUNT) {
|
|
3396
3022
|
if (this._streamDataFlushedCallback !== null) {
|
|
3397
|
-
|
|
3398
|
-
F:
|
|
3399
|
-
L:
|
|
3023
|
+
log9.error("consumer trying to write before we are ready for more data", void 0, {
|
|
3024
|
+
F: __dxlog_file10,
|
|
3025
|
+
L: 174,
|
|
3400
3026
|
S: this,
|
|
3401
3027
|
C: (f, a) => f(...a)
|
|
3402
3028
|
});
|
|
@@ -3410,9 +3036,9 @@ var RtcTransportChannel = class extends Resource {
|
|
|
3410
3036
|
try {
|
|
3411
3037
|
channel.close();
|
|
3412
3038
|
} catch (error) {
|
|
3413
|
-
|
|
3414
|
-
F:
|
|
3415
|
-
L:
|
|
3039
|
+
log9.catch(error, void 0, {
|
|
3040
|
+
F: __dxlog_file10,
|
|
3041
|
+
L: 186,
|
|
3416
3042
|
S: this,
|
|
3417
3043
|
C: (f, a) => f(...a)
|
|
3418
3044
|
});
|
|
@@ -3462,18 +3088,18 @@ function _ts_decorate6(decorators, target, key, desc) {
|
|
|
3462
3088
|
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;
|
|
3463
3089
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3464
3090
|
}
|
|
3465
|
-
var
|
|
3091
|
+
var __dxlog_file11 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-peer-connection.ts";
|
|
3466
3092
|
var RtcPeerConnection = class {
|
|
3467
3093
|
_factory;
|
|
3468
3094
|
_options;
|
|
3469
3095
|
// A peer who is not the initiator waits for another party to open a channel.
|
|
3470
|
-
_channelCreatedCallbacks;
|
|
3096
|
+
_channelCreatedCallbacks = /* @__PURE__ */ new Map();
|
|
3471
3097
|
// Channels indexed by topic.
|
|
3472
|
-
_transportChannels;
|
|
3473
|
-
_dataChannels;
|
|
3098
|
+
_transportChannels = /* @__PURE__ */ new Map();
|
|
3099
|
+
_dataChannels = /* @__PURE__ */ new Map();
|
|
3474
3100
|
// A peer is ready to receive ICE candidates when local and remote description were set.
|
|
3475
|
-
_readyForCandidates;
|
|
3476
|
-
_offerProcessingMutex;
|
|
3101
|
+
_readyForCandidates = new Trigger3();
|
|
3102
|
+
_offerProcessingMutex = new Mutex2();
|
|
3477
3103
|
/**
|
|
3478
3104
|
* Can't use peer.connection.initiator, because if two connections to the same peer are created in
|
|
3479
3105
|
* different swarms, we might be the initiator of the first one, but not of the other one.
|
|
@@ -3485,11 +3111,6 @@ var RtcPeerConnection = class {
|
|
|
3485
3111
|
constructor(_factory, _options) {
|
|
3486
3112
|
this._factory = _factory;
|
|
3487
3113
|
this._options = _options;
|
|
3488
|
-
this._channelCreatedCallbacks = /* @__PURE__ */ new Map();
|
|
3489
|
-
this._transportChannels = /* @__PURE__ */ new Map();
|
|
3490
|
-
this._dataChannels = /* @__PURE__ */ new Map();
|
|
3491
|
-
this._readyForCandidates = new Trigger3();
|
|
3492
|
-
this._offerProcessingMutex = new Mutex2();
|
|
3493
3114
|
this._initiator = chooseInitiatorPeer(_options.ownPeerKey, _options.remotePeerKey) === _options.ownPeerKey;
|
|
3494
3115
|
}
|
|
3495
3116
|
get transportChannelCount() {
|
|
@@ -3515,9 +3136,9 @@ var RtcPeerConnection = class {
|
|
|
3515
3136
|
if (existingChannel) {
|
|
3516
3137
|
return existingChannel;
|
|
3517
3138
|
}
|
|
3518
|
-
|
|
3519
|
-
F:
|
|
3520
|
-
L:
|
|
3139
|
+
log10("waiting for initiator-peer to open a data channel", void 0, {
|
|
3140
|
+
F: __dxlog_file11,
|
|
3141
|
+
L: 95,
|
|
3521
3142
|
S: this,
|
|
3522
3143
|
C: (f, a) => f(...a)
|
|
3523
3144
|
});
|
|
@@ -3544,11 +3165,11 @@ var RtcPeerConnection = class {
|
|
|
3544
3165
|
if (this._connection) {
|
|
3545
3166
|
return this._connection;
|
|
3546
3167
|
}
|
|
3547
|
-
|
|
3168
|
+
log10("initializing connection...", () => ({
|
|
3548
3169
|
remotePeer: this._options.remotePeerKey
|
|
3549
3170
|
}), {
|
|
3550
|
-
F:
|
|
3551
|
-
L:
|
|
3171
|
+
F: __dxlog_file11,
|
|
3172
|
+
L: 120,
|
|
3552
3173
|
S: this,
|
|
3553
3174
|
C: (f, a) => f(...a)
|
|
3554
3175
|
});
|
|
@@ -3557,9 +3178,9 @@ var RtcPeerConnection = class {
|
|
|
3557
3178
|
const iceCandidateErrors = [];
|
|
3558
3179
|
Object.assign(connection, {
|
|
3559
3180
|
onnegotiationneeded: async () => {
|
|
3560
|
-
|
|
3561
|
-
F:
|
|
3562
|
-
L:
|
|
3181
|
+
invariant10(this._initiator, void 0, {
|
|
3182
|
+
F: __dxlog_file11,
|
|
3183
|
+
L: 135,
|
|
3563
3184
|
S: this,
|
|
3564
3185
|
A: [
|
|
3565
3186
|
"this._initiator",
|
|
@@ -3570,9 +3191,9 @@ var RtcPeerConnection = class {
|
|
|
3570
3191
|
this._onConnectionCallbackAfterClose("onnegotiationneeded", connection);
|
|
3571
3192
|
return;
|
|
3572
3193
|
}
|
|
3573
|
-
|
|
3574
|
-
F:
|
|
3575
|
-
L:
|
|
3194
|
+
log10("onnegotiationneeded", void 0, {
|
|
3195
|
+
F: __dxlog_file11,
|
|
3196
|
+
L: 142,
|
|
3576
3197
|
S: this,
|
|
3577
3198
|
C: (f, a) => f(...a)
|
|
3578
3199
|
});
|
|
@@ -3592,19 +3213,19 @@ var RtcPeerConnection = class {
|
|
|
3592
3213
|
return;
|
|
3593
3214
|
}
|
|
3594
3215
|
if (event.candidate) {
|
|
3595
|
-
|
|
3216
|
+
log10("onicecandidate", {
|
|
3596
3217
|
candidate: event.candidate.candidate
|
|
3597
3218
|
}, {
|
|
3598
|
-
F:
|
|
3599
|
-
L:
|
|
3219
|
+
F: __dxlog_file11,
|
|
3220
|
+
L: 161,
|
|
3600
3221
|
S: this,
|
|
3601
3222
|
C: (f, a) => f(...a)
|
|
3602
3223
|
});
|
|
3603
3224
|
await this._sendIceCandidate(event.candidate);
|
|
3604
3225
|
} else {
|
|
3605
|
-
|
|
3606
|
-
F:
|
|
3607
|
-
L:
|
|
3226
|
+
log10("onicecandidate gathering complete", void 0, {
|
|
3227
|
+
F: __dxlog_file11,
|
|
3228
|
+
L: 164,
|
|
3608
3229
|
S: this,
|
|
3609
3230
|
C: (f, a) => f(...a)
|
|
3610
3231
|
});
|
|
@@ -3628,11 +3249,11 @@ var RtcPeerConnection = class {
|
|
|
3628
3249
|
this._onConnectionCallbackAfterClose("oniceconnectionstatechange", connection);
|
|
3629
3250
|
return;
|
|
3630
3251
|
}
|
|
3631
|
-
|
|
3252
|
+
log10("oniceconnectionstatechange", {
|
|
3632
3253
|
state: connection.iceConnectionState
|
|
3633
3254
|
}, {
|
|
3634
|
-
F:
|
|
3635
|
-
L:
|
|
3255
|
+
F: __dxlog_file11,
|
|
3256
|
+
L: 184,
|
|
3636
3257
|
S: this,
|
|
3637
3258
|
C: (f, a) => f(...a)
|
|
3638
3259
|
});
|
|
@@ -3650,11 +3271,11 @@ var RtcPeerConnection = class {
|
|
|
3650
3271
|
}
|
|
3651
3272
|
return;
|
|
3652
3273
|
}
|
|
3653
|
-
|
|
3274
|
+
log10("onconnectionstatechange", {
|
|
3654
3275
|
state: connection.connectionState
|
|
3655
3276
|
}, {
|
|
3656
|
-
F:
|
|
3657
|
-
L:
|
|
3277
|
+
F: __dxlog_file11,
|
|
3278
|
+
L: 201,
|
|
3658
3279
|
S: this,
|
|
3659
3280
|
C: (f, a) => f(...a)
|
|
3660
3281
|
});
|
|
@@ -3663,11 +3284,11 @@ var RtcPeerConnection = class {
|
|
|
3663
3284
|
}
|
|
3664
3285
|
},
|
|
3665
3286
|
onsignalingstatechange: () => {
|
|
3666
|
-
|
|
3287
|
+
log10("onsignalingstatechange", {
|
|
3667
3288
|
state: connection.signalingState
|
|
3668
3289
|
}, {
|
|
3669
|
-
F:
|
|
3670
|
-
L:
|
|
3290
|
+
F: __dxlog_file11,
|
|
3291
|
+
L: 208,
|
|
3671
3292
|
S: this,
|
|
3672
3293
|
C: (f, a) => f(...a)
|
|
3673
3294
|
});
|
|
@@ -3675,9 +3296,9 @@ var RtcPeerConnection = class {
|
|
|
3675
3296
|
// When channel is added to connection.
|
|
3676
3297
|
// https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/datachannel_event
|
|
3677
3298
|
ondatachannel: (event) => {
|
|
3678
|
-
|
|
3679
|
-
F:
|
|
3680
|
-
L:
|
|
3299
|
+
invariant10(!this._initiator, "Initiator is expected to create data channels.", {
|
|
3300
|
+
F: __dxlog_file11,
|
|
3301
|
+
L: 214,
|
|
3681
3302
|
S: this,
|
|
3682
3303
|
A: [
|
|
3683
3304
|
"!this._initiator",
|
|
@@ -3688,11 +3309,11 @@ var RtcPeerConnection = class {
|
|
|
3688
3309
|
this._onConnectionCallbackAfterClose("ondatachannel", connection);
|
|
3689
3310
|
return;
|
|
3690
3311
|
}
|
|
3691
|
-
|
|
3312
|
+
log10("ondatachannel", {
|
|
3692
3313
|
label: event.channel.label
|
|
3693
3314
|
}, {
|
|
3694
|
-
F:
|
|
3695
|
-
L:
|
|
3315
|
+
F: __dxlog_file11,
|
|
3316
|
+
L: 221,
|
|
3696
3317
|
S: this,
|
|
3697
3318
|
C: (f, a) => f(...a)
|
|
3698
3319
|
});
|
|
@@ -3716,11 +3337,11 @@ var RtcPeerConnection = class {
|
|
|
3716
3337
|
}
|
|
3717
3338
|
_abortConnection(connection, error) {
|
|
3718
3339
|
if (connection !== this._connection) {
|
|
3719
|
-
|
|
3340
|
+
log10.error("attempted to abort an inactive connection", {
|
|
3720
3341
|
error
|
|
3721
3342
|
}, {
|
|
3722
|
-
F:
|
|
3723
|
-
L:
|
|
3343
|
+
F: __dxlog_file11,
|
|
3344
|
+
L: 246,
|
|
3724
3345
|
S: this,
|
|
3725
3346
|
C: (f, a) => f(...a)
|
|
3726
3347
|
});
|
|
@@ -3737,19 +3358,19 @@ var RtcPeerConnection = class {
|
|
|
3737
3358
|
}
|
|
3738
3359
|
this._transportChannels.clear();
|
|
3739
3360
|
this._safeCloseConnection();
|
|
3740
|
-
|
|
3361
|
+
log10("connection aborted", {
|
|
3741
3362
|
reason: error.message
|
|
3742
3363
|
}, {
|
|
3743
|
-
F:
|
|
3744
|
-
L:
|
|
3364
|
+
F: __dxlog_file11,
|
|
3365
|
+
L: 260,
|
|
3745
3366
|
S: this,
|
|
3746
3367
|
C: (f, a) => f(...a)
|
|
3747
3368
|
});
|
|
3748
3369
|
}
|
|
3749
3370
|
async _lockAndCloseConnection() {
|
|
3750
|
-
|
|
3751
|
-
F:
|
|
3752
|
-
L:
|
|
3371
|
+
invariant10(this._transportChannels.size === 0, void 0, {
|
|
3372
|
+
F: __dxlog_file11,
|
|
3373
|
+
L: 265,
|
|
3753
3374
|
S: this,
|
|
3754
3375
|
A: [
|
|
3755
3376
|
"this._transportChannels.size === 0",
|
|
@@ -3758,9 +3379,9 @@ var RtcPeerConnection = class {
|
|
|
3758
3379
|
});
|
|
3759
3380
|
if (this._connection) {
|
|
3760
3381
|
this._safeCloseConnection();
|
|
3761
|
-
|
|
3762
|
-
F:
|
|
3763
|
-
L:
|
|
3382
|
+
log10("connection closed", void 0, {
|
|
3383
|
+
F: __dxlog_file11,
|
|
3384
|
+
L: 268,
|
|
3764
3385
|
S: this,
|
|
3765
3386
|
C: (f, a) => f(...a)
|
|
3766
3387
|
});
|
|
@@ -3769,11 +3390,11 @@ var RtcPeerConnection = class {
|
|
|
3769
3390
|
async onSignal(signal) {
|
|
3770
3391
|
const connection = this._connection;
|
|
3771
3392
|
if (!connection) {
|
|
3772
|
-
|
|
3393
|
+
log10.warn("a signal ignored because the connection was closed", {
|
|
3773
3394
|
type: signal.payload.data.type
|
|
3774
3395
|
}, {
|
|
3775
|
-
F:
|
|
3776
|
-
L:
|
|
3396
|
+
F: __dxlog_file11,
|
|
3397
|
+
L: 276,
|
|
3777
3398
|
S: this,
|
|
3778
3399
|
C: (f, a) => f(...a)
|
|
3779
3400
|
});
|
|
@@ -3836,11 +3457,11 @@ var RtcPeerConnection = class {
|
|
|
3836
3457
|
this._abortConnection(connection, new Error(`Unknown signal type ${data.type}.`));
|
|
3837
3458
|
break;
|
|
3838
3459
|
}
|
|
3839
|
-
|
|
3460
|
+
log10("signal processed", {
|
|
3840
3461
|
type: data.type
|
|
3841
3462
|
}, {
|
|
3842
|
-
F:
|
|
3843
|
-
L:
|
|
3463
|
+
F: __dxlog_file11,
|
|
3464
|
+
L: 335,
|
|
3844
3465
|
S: this,
|
|
3845
3466
|
C: (f, a) => f(...a)
|
|
3846
3467
|
});
|
|
@@ -3849,20 +3470,20 @@ var RtcPeerConnection = class {
|
|
|
3849
3470
|
try {
|
|
3850
3471
|
await this._readyForCandidates.wait();
|
|
3851
3472
|
if (connection === this._connection) {
|
|
3852
|
-
|
|
3473
|
+
log10("adding ice candidate", {
|
|
3853
3474
|
candidate
|
|
3854
3475
|
}, {
|
|
3855
|
-
F:
|
|
3856
|
-
L:
|
|
3476
|
+
F: __dxlog_file11,
|
|
3477
|
+
L: 343,
|
|
3857
3478
|
S: this,
|
|
3858
3479
|
C: (f, a) => f(...a)
|
|
3859
3480
|
});
|
|
3860
3481
|
await connection.addIceCandidate(candidate);
|
|
3861
3482
|
}
|
|
3862
3483
|
} catch (err) {
|
|
3863
|
-
|
|
3864
|
-
F:
|
|
3865
|
-
L:
|
|
3484
|
+
log10.catch(err, void 0, {
|
|
3485
|
+
F: __dxlog_file11,
|
|
3486
|
+
L: 347,
|
|
3866
3487
|
S: this,
|
|
3867
3488
|
C: (f, a) => f(...a)
|
|
3868
3489
|
});
|
|
@@ -3870,29 +3491,29 @@ var RtcPeerConnection = class {
|
|
|
3870
3491
|
}
|
|
3871
3492
|
_onSessionNegotiated(connection) {
|
|
3872
3493
|
if (connection === this._connection) {
|
|
3873
|
-
|
|
3874
|
-
F:
|
|
3875
|
-
L:
|
|
3494
|
+
log10("ready to process ice candidates", void 0, {
|
|
3495
|
+
F: __dxlog_file11,
|
|
3496
|
+
L: 353,
|
|
3876
3497
|
S: this,
|
|
3877
3498
|
C: (f, a) => f(...a)
|
|
3878
3499
|
});
|
|
3879
3500
|
this._readyForCandidates.wake();
|
|
3880
3501
|
} else {
|
|
3881
|
-
|
|
3882
|
-
F:
|
|
3883
|
-
L:
|
|
3502
|
+
log10.warn("session was negotiated after connection became inactive", void 0, {
|
|
3503
|
+
F: __dxlog_file11,
|
|
3504
|
+
L: 356,
|
|
3884
3505
|
S: this,
|
|
3885
3506
|
C: (f, a) => f(...a)
|
|
3886
3507
|
});
|
|
3887
3508
|
}
|
|
3888
3509
|
}
|
|
3889
3510
|
_onConnectionCallbackAfterClose(callback, connection) {
|
|
3890
|
-
|
|
3511
|
+
log10.warn("callback invoked after a connection was destroyed, this is probably a bug", {
|
|
3891
3512
|
callback,
|
|
3892
3513
|
state: connection.connectionState
|
|
3893
3514
|
}, {
|
|
3894
|
-
F:
|
|
3895
|
-
L:
|
|
3515
|
+
F: __dxlog_file11,
|
|
3516
|
+
L: 361,
|
|
3896
3517
|
S: this,
|
|
3897
3518
|
C: (f, a) => f(...a)
|
|
3898
3519
|
});
|
|
@@ -3903,9 +3524,9 @@ var RtcPeerConnection = class {
|
|
|
3903
3524
|
try {
|
|
3904
3525
|
connection?.close();
|
|
3905
3526
|
} catch (err) {
|
|
3906
|
-
|
|
3907
|
-
F:
|
|
3908
|
-
L:
|
|
3527
|
+
log10.catch(err, void 0, {
|
|
3528
|
+
F: __dxlog_file11,
|
|
3529
|
+
L: 373,
|
|
3909
3530
|
S: this,
|
|
3910
3531
|
C: (f, a) => f(...a)
|
|
3911
3532
|
});
|
|
@@ -3914,9 +3535,9 @@ var RtcPeerConnection = class {
|
|
|
3914
3535
|
this._connection = void 0;
|
|
3915
3536
|
this._dataChannels.clear();
|
|
3916
3537
|
this._readyForCandidates.wake();
|
|
3917
|
-
void this._factory.onConnectionDestroyed().catch((err) =>
|
|
3918
|
-
F:
|
|
3919
|
-
L:
|
|
3538
|
+
void this._factory.onConnectionDestroyed().catch((err) => log10.catch(err, void 0, {
|
|
3539
|
+
F: __dxlog_file11,
|
|
3540
|
+
L: 379,
|
|
3920
3541
|
S: this,
|
|
3921
3542
|
C: (f, a) => f(...a)
|
|
3922
3543
|
}));
|
|
@@ -3939,9 +3560,9 @@ var RtcPeerConnection = class {
|
|
|
3939
3560
|
];
|
|
3940
3561
|
}
|
|
3941
3562
|
} catch (error) {
|
|
3942
|
-
|
|
3943
|
-
F:
|
|
3944
|
-
L:
|
|
3563
|
+
log10.catch(error, void 0, {
|
|
3564
|
+
F: __dxlog_file11,
|
|
3565
|
+
L: 395,
|
|
3945
3566
|
S: this,
|
|
3946
3567
|
C: (f, a) => f(...a)
|
|
3947
3568
|
});
|
|
@@ -3964,11 +3585,11 @@ var RtcPeerConnection = class {
|
|
|
3964
3585
|
}
|
|
3965
3586
|
});
|
|
3966
3587
|
} catch (err) {
|
|
3967
|
-
|
|
3588
|
+
log10.warn("signaling error", {
|
|
3968
3589
|
err
|
|
3969
3590
|
}, {
|
|
3970
|
-
F:
|
|
3971
|
-
L:
|
|
3591
|
+
F: __dxlog_file11,
|
|
3592
|
+
L: 416,
|
|
3972
3593
|
S: this,
|
|
3973
3594
|
C: (f, a) => f(...a)
|
|
3974
3595
|
});
|
|
@@ -4045,8 +3666,10 @@ var isRemoteDescriptionSet = (connection, data) => {
|
|
|
4045
3666
|
};
|
|
4046
3667
|
var createIceFailureError = (details) => {
|
|
4047
3668
|
const candidateErrors = details.map(({ url, errorCode, errorText }) => `${errorCode} ${url}: ${errorText}`);
|
|
4048
|
-
return new ConnectivityError3(
|
|
4049
|
-
|
|
3669
|
+
return new ConnectivityError3({
|
|
3670
|
+
message: `ICE failed:
|
|
3671
|
+
${candidateErrors.join("\n")}`
|
|
3672
|
+
});
|
|
4050
3673
|
};
|
|
4051
3674
|
|
|
4052
3675
|
// src/transport/webrtc/rtc-transport-factory.ts
|
|
@@ -4072,25 +3695,25 @@ import { Writable } from "@dxos/node-std/stream";
|
|
|
4072
3695
|
import { Event as Event8, scheduleTask as scheduleTask4 } from "@dxos/async";
|
|
4073
3696
|
import { Resource as Resource2 } from "@dxos/context";
|
|
4074
3697
|
import { ErrorStream as ErrorStream5 } from "@dxos/debug";
|
|
4075
|
-
import { invariant as
|
|
3698
|
+
import { invariant as invariant11 } from "@dxos/invariant";
|
|
4076
3699
|
import { PublicKey as PublicKey10 } from "@dxos/keys";
|
|
4077
|
-
import { log as
|
|
3700
|
+
import { log as log11 } from "@dxos/log";
|
|
4078
3701
|
import { ConnectionResetError as ConnectionResetError2, ConnectivityError as ConnectivityError4, TimeoutError as TimeoutError3 } from "@dxos/protocols";
|
|
4079
3702
|
import { ConnectionState as ConnectionState3 } from "@dxos/protocols/proto/dxos/mesh/bridge";
|
|
4080
3703
|
import { arrayToBuffer } from "@dxos/util";
|
|
4081
|
-
var
|
|
3704
|
+
var __dxlog_file12 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-proxy.ts";
|
|
4082
3705
|
var RPC_TIMEOUT = 1e4;
|
|
4083
3706
|
var CLOSE_RPC_TIMEOUT = 3e3;
|
|
4084
3707
|
var RESP_MIN_THRESHOLD = 500;
|
|
4085
3708
|
var RtcTransportProxy = class extends Resource2 {
|
|
4086
3709
|
_options;
|
|
4087
|
-
_proxyId;
|
|
4088
|
-
closed;
|
|
4089
|
-
connected;
|
|
4090
|
-
errors;
|
|
3710
|
+
_proxyId = PublicKey10.random();
|
|
3711
|
+
closed = new Event8();
|
|
3712
|
+
connected = new Event8();
|
|
3713
|
+
errors = new ErrorStream5();
|
|
4091
3714
|
_serviceStream;
|
|
4092
3715
|
constructor(_options) {
|
|
4093
|
-
super(), this._options = _options
|
|
3716
|
+
super(), this._options = _options;
|
|
4094
3717
|
}
|
|
4095
3718
|
async _open() {
|
|
4096
3719
|
let stream;
|
|
@@ -4111,8 +3734,8 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
4111
3734
|
this._serviceStream = stream;
|
|
4112
3735
|
stream.waitUntilReady().then(() => {
|
|
4113
3736
|
stream.subscribe(async (event) => {
|
|
4114
|
-
|
|
4115
|
-
F:
|
|
3737
|
+
log11("rtc transport proxy event", event, {
|
|
3738
|
+
F: __dxlog_file12,
|
|
4116
3739
|
L: 66,
|
|
4117
3740
|
S: this,
|
|
4118
3741
|
C: (f, a) => f(...a)
|
|
@@ -4125,10 +3748,10 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
4125
3748
|
await this._handleSignal(event.signal);
|
|
4126
3749
|
}
|
|
4127
3750
|
}, (err) => {
|
|
4128
|
-
|
|
3751
|
+
log11("rtc bridge stream closed", {
|
|
4129
3752
|
err
|
|
4130
3753
|
}, {
|
|
4131
|
-
F:
|
|
3754
|
+
F: __dxlog_file12,
|
|
4132
3755
|
L: 76,
|
|
4133
3756
|
S: this,
|
|
4134
3757
|
C: (f, a) => f(...a)
|
|
@@ -4149,8 +3772,8 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
4149
3772
|
timeout: RPC_TIMEOUT
|
|
4150
3773
|
}).then(() => {
|
|
4151
3774
|
if (Date.now() - sendStartMs > RESP_MIN_THRESHOLD) {
|
|
4152
|
-
|
|
4153
|
-
F:
|
|
3775
|
+
log11("slow response, delaying callback", void 0, {
|
|
3776
|
+
F: __dxlog_file12,
|
|
4154
3777
|
L: 93,
|
|
4155
3778
|
S: this,
|
|
4156
3779
|
C: (f, a) => f(...a)
|
|
@@ -4182,8 +3805,8 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
4182
3805
|
await this._serviceStream?.close();
|
|
4183
3806
|
this._serviceStream = void 0;
|
|
4184
3807
|
} catch (err) {
|
|
4185
|
-
|
|
4186
|
-
F:
|
|
3808
|
+
log11.catch(err, void 0, {
|
|
3809
|
+
F: __dxlog_file12,
|
|
4187
3810
|
L: 128,
|
|
4188
3811
|
S: this,
|
|
4189
3812
|
C: (f, a) => f(...a)
|
|
@@ -4196,8 +3819,8 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
4196
3819
|
timeout: CLOSE_RPC_TIMEOUT
|
|
4197
3820
|
});
|
|
4198
3821
|
} catch (err) {
|
|
4199
|
-
|
|
4200
|
-
F:
|
|
3822
|
+
log11.catch(err, void 0, {
|
|
3823
|
+
F: __dxlog_file12,
|
|
4201
3824
|
L: 134,
|
|
4202
3825
|
S: this,
|
|
4203
3826
|
C: (f, a) => f(...a)
|
|
@@ -4242,7 +3865,9 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
4242
3865
|
} catch (error) {
|
|
4243
3866
|
const type = signalEvent.payload.payload.data?.type;
|
|
4244
3867
|
if (type === "offer" || type === "answer") {
|
|
4245
|
-
this._raiseIfOpen(new ConnectivityError4(
|
|
3868
|
+
this._raiseIfOpen(new ConnectivityError4({
|
|
3869
|
+
message: `Session establishment failed: ${type} couldn't be sent.`
|
|
3870
|
+
}));
|
|
4246
3871
|
}
|
|
4247
3872
|
}
|
|
4248
3873
|
}
|
|
@@ -4280,11 +3905,11 @@ var RtcTransportProxy = class extends Resource2 {
|
|
|
4280
3905
|
if (this.isOpen) {
|
|
4281
3906
|
this.errors.raise(error);
|
|
4282
3907
|
} else {
|
|
4283
|
-
|
|
3908
|
+
log11.info("error swallowed because transport was closed", {
|
|
4284
3909
|
message: error.message
|
|
4285
3910
|
}, {
|
|
4286
|
-
F:
|
|
4287
|
-
L:
|
|
3911
|
+
F: __dxlog_file12,
|
|
3912
|
+
L: 217,
|
|
4288
3913
|
S: this,
|
|
4289
3914
|
C: (f, a) => f(...a)
|
|
4290
3915
|
});
|
|
@@ -4313,9 +3938,9 @@ var RtcTransportProxyFactory = class {
|
|
|
4313
3938
|
return this;
|
|
4314
3939
|
}
|
|
4315
3940
|
createTransport(options) {
|
|
4316
|
-
|
|
4317
|
-
F:
|
|
4318
|
-
L:
|
|
3941
|
+
invariant11(this._bridgeService, "RtcTransportProxyFactory is not ready to open connections", {
|
|
3942
|
+
F: __dxlog_file12,
|
|
3943
|
+
L: 247,
|
|
4319
3944
|
S: this,
|
|
4320
3945
|
A: [
|
|
4321
3946
|
"this._bridgeService",
|
|
@@ -4336,11 +3961,17 @@ var RtcTransportProxyFactory = class {
|
|
|
4336
3961
|
var decodeError = (err) => {
|
|
4337
3962
|
const message = typeof err === "string" ? err : err.message;
|
|
4338
3963
|
if (message.includes("CONNECTION_RESET")) {
|
|
4339
|
-
return new ConnectionResetError2(
|
|
3964
|
+
return new ConnectionResetError2({
|
|
3965
|
+
message
|
|
3966
|
+
});
|
|
4340
3967
|
} else if (message.includes("TIMEOUT")) {
|
|
4341
|
-
return new TimeoutError3(
|
|
3968
|
+
return new TimeoutError3({
|
|
3969
|
+
message
|
|
3970
|
+
});
|
|
4342
3971
|
} else if (message.includes("CONNECTIVITY_ERROR")) {
|
|
4343
|
-
return new ConnectivityError4(
|
|
3972
|
+
return new ConnectivityError4({
|
|
3973
|
+
message
|
|
3974
|
+
});
|
|
4344
3975
|
} else {
|
|
4345
3976
|
return typeof err === "string" ? new Error(err) : err;
|
|
4346
3977
|
}
|
|
@@ -4349,18 +3980,17 @@ var decodeError = (err) => {
|
|
|
4349
3980
|
// src/transport/webrtc/rtc-transport-service.ts
|
|
4350
3981
|
import { Duplex as Duplex2 } from "@dxos/node-std/stream";
|
|
4351
3982
|
import { Stream } from "@dxos/codec-protobuf/stream";
|
|
4352
|
-
import { invariant as
|
|
3983
|
+
import { invariant as invariant12 } from "@dxos/invariant";
|
|
4353
3984
|
import { PublicKey as PublicKey11 } from "@dxos/keys";
|
|
4354
|
-
import { log as
|
|
3985
|
+
import { log as log12 } from "@dxos/log";
|
|
4355
3986
|
import { ConnectionState as ConnectionState4 } from "@dxos/protocols/proto/dxos/mesh/bridge";
|
|
4356
3987
|
import { ComplexMap as ComplexMap8 } from "@dxos/util";
|
|
4357
|
-
var
|
|
3988
|
+
var __dxlog_file13 = "/__w/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc/rtc-transport-service.ts";
|
|
4358
3989
|
var RtcTransportService = class {
|
|
4359
3990
|
_transportFactory;
|
|
4360
|
-
_openTransports;
|
|
3991
|
+
_openTransports = new ComplexMap8(PublicKey11.hash);
|
|
4361
3992
|
constructor(webrtcConfig, iceProvider, _transportFactory = createRtcTransportFactory(webrtcConfig, iceProvider)) {
|
|
4362
3993
|
this._transportFactory = _transportFactory;
|
|
4363
|
-
this._openTransports = new ComplexMap8(PublicKey11.hash);
|
|
4364
3994
|
}
|
|
4365
3995
|
hasOpenTransports() {
|
|
4366
3996
|
return this._openTransports.size > 0;
|
|
@@ -4368,9 +3998,9 @@ var RtcTransportService = class {
|
|
|
4368
3998
|
open(request) {
|
|
4369
3999
|
const existingTransport = this._openTransports.get(request.proxyId);
|
|
4370
4000
|
if (existingTransport) {
|
|
4371
|
-
|
|
4372
|
-
F:
|
|
4373
|
-
L:
|
|
4001
|
+
log12.error("requesting a new transport bridge for an existing proxy", void 0, {
|
|
4002
|
+
F: __dxlog_file13,
|
|
4003
|
+
L: 53,
|
|
4374
4004
|
S: this,
|
|
4375
4005
|
C: (f, a) => f(...a)
|
|
4376
4006
|
});
|
|
@@ -4434,9 +4064,9 @@ var RtcTransportService = class {
|
|
|
4434
4064
|
close(err);
|
|
4435
4065
|
});
|
|
4436
4066
|
ready();
|
|
4437
|
-
|
|
4438
|
-
F:
|
|
4439
|
-
L:
|
|
4067
|
+
log12("stream ready", void 0, {
|
|
4068
|
+
F: __dxlog_file13,
|
|
4069
|
+
L: 115,
|
|
4440
4070
|
S: this,
|
|
4441
4071
|
C: (f, a) => f(...a)
|
|
4442
4072
|
});
|
|
@@ -4445,9 +4075,9 @@ var RtcTransportService = class {
|
|
|
4445
4075
|
}
|
|
4446
4076
|
async sendSignal({ proxyId, signal }) {
|
|
4447
4077
|
const transport = this._openTransports.get(proxyId);
|
|
4448
|
-
|
|
4449
|
-
F:
|
|
4450
|
-
L:
|
|
4078
|
+
invariant12(transport, void 0, {
|
|
4079
|
+
F: __dxlog_file13,
|
|
4080
|
+
L: 123,
|
|
4451
4081
|
S: this,
|
|
4452
4082
|
A: [
|
|
4453
4083
|
"transport",
|
|
@@ -4458,9 +4088,9 @@ var RtcTransportService = class {
|
|
|
4458
4088
|
}
|
|
4459
4089
|
async getDetails({ proxyId }) {
|
|
4460
4090
|
const transport = this._openTransports.get(proxyId);
|
|
4461
|
-
|
|
4462
|
-
F:
|
|
4463
|
-
L:
|
|
4091
|
+
invariant12(transport, void 0, {
|
|
4092
|
+
F: __dxlog_file13,
|
|
4093
|
+
L: 130,
|
|
4464
4094
|
S: this,
|
|
4465
4095
|
A: [
|
|
4466
4096
|
"transport",
|
|
@@ -4473,9 +4103,9 @@ var RtcTransportService = class {
|
|
|
4473
4103
|
}
|
|
4474
4104
|
async getStats({ proxyId }) {
|
|
4475
4105
|
const transport = this._openTransports.get(proxyId);
|
|
4476
|
-
|
|
4477
|
-
F:
|
|
4478
|
-
L:
|
|
4106
|
+
invariant12(transport, void 0, {
|
|
4107
|
+
F: __dxlog_file13,
|
|
4108
|
+
L: 137,
|
|
4479
4109
|
S: this,
|
|
4480
4110
|
A: [
|
|
4481
4111
|
"transport",
|
|
@@ -4488,9 +4118,9 @@ var RtcTransportService = class {
|
|
|
4488
4118
|
}
|
|
4489
4119
|
async sendData({ proxyId, payload }) {
|
|
4490
4120
|
const transport = this._openTransports.get(proxyId);
|
|
4491
|
-
|
|
4492
|
-
F:
|
|
4493
|
-
L:
|
|
4121
|
+
invariant12(transport, void 0, {
|
|
4122
|
+
F: __dxlog_file13,
|
|
4123
|
+
L: 144,
|
|
4494
4124
|
S: this,
|
|
4495
4125
|
A: [
|
|
4496
4126
|
"transport",
|
|
@@ -4520,11 +4150,11 @@ var RtcTransportService = class {
|
|
|
4520
4150
|
try {
|
|
4521
4151
|
await transport.transport.close();
|
|
4522
4152
|
} catch (error) {
|
|
4523
|
-
|
|
4153
|
+
log12.warn("transport close error", {
|
|
4524
4154
|
message: error?.message
|
|
4525
4155
|
}, {
|
|
4526
|
-
F:
|
|
4527
|
-
L:
|
|
4156
|
+
F: __dxlog_file13,
|
|
4157
|
+
L: 174,
|
|
4528
4158
|
S: this,
|
|
4529
4159
|
C: (f, a) => f(...a)
|
|
4530
4160
|
});
|
|
@@ -4532,18 +4162,18 @@ var RtcTransportService = class {
|
|
|
4532
4162
|
try {
|
|
4533
4163
|
transport.connectorStream.end();
|
|
4534
4164
|
} catch (error) {
|
|
4535
|
-
|
|
4165
|
+
log12.warn("connectorStream close error", {
|
|
4536
4166
|
message: error?.message
|
|
4537
4167
|
}, {
|
|
4538
|
-
F:
|
|
4539
|
-
L:
|
|
4168
|
+
F: __dxlog_file13,
|
|
4169
|
+
L: 179,
|
|
4540
4170
|
S: this,
|
|
4541
4171
|
C: (f, a) => f(...a)
|
|
4542
4172
|
});
|
|
4543
4173
|
}
|
|
4544
|
-
|
|
4545
|
-
F:
|
|
4546
|
-
L:
|
|
4174
|
+
log12("closed", void 0, {
|
|
4175
|
+
F: __dxlog_file13,
|
|
4176
|
+
L: 181,
|
|
4547
4177
|
S: this,
|
|
4548
4178
|
C: (f, a) => f(...a)
|
|
4549
4179
|
});
|
|
@@ -4564,10 +4194,10 @@ var createStateUpdater = (next) => {
|
|
|
4564
4194
|
|
|
4565
4195
|
// src/wire-protocol.ts
|
|
4566
4196
|
import { Teleport } from "@dxos/teleport";
|
|
4567
|
-
var createTeleportProtocolFactory = (onConnection,
|
|
4197
|
+
var createTeleportProtocolFactory = (onConnection, defaultProps) => {
|
|
4568
4198
|
return (params) => {
|
|
4569
4199
|
const teleport = new Teleport({
|
|
4570
|
-
...
|
|
4200
|
+
...defaultProps,
|
|
4571
4201
|
...params
|
|
4572
4202
|
});
|
|
4573
4203
|
return {
|
|
@@ -4589,7 +4219,6 @@ var createTeleportProtocolFactory = (onConnection, defaultParams) => {
|
|
|
4589
4219
|
export {
|
|
4590
4220
|
ConnectionState,
|
|
4591
4221
|
Connection,
|
|
4592
|
-
createIceProvider,
|
|
4593
4222
|
SwarmMessenger,
|
|
4594
4223
|
Swarm,
|
|
4595
4224
|
SwarmMapper,
|
|
@@ -4599,8 +4228,6 @@ export {
|
|
|
4599
4228
|
ConnectionLog,
|
|
4600
4229
|
SwarmNetworkManager,
|
|
4601
4230
|
FullyConnectedTopology,
|
|
4602
|
-
MMSTTopology,
|
|
4603
|
-
StarTopology,
|
|
4604
4231
|
MemoryTransportFactory,
|
|
4605
4232
|
MemoryTransport,
|
|
4606
4233
|
TransportKind,
|
|
@@ -4610,4 +4237,4 @@ export {
|
|
|
4610
4237
|
RtcTransportService,
|
|
4611
4238
|
createTeleportProtocolFactory
|
|
4612
4239
|
};
|
|
4613
|
-
//# sourceMappingURL=chunk-
|
|
4240
|
+
//# sourceMappingURL=chunk-Y2FDDNGM.mjs.map
|