@dxos/network-manager 0.6.8-main.3be982f → 0.6.8-staging.63bcb81
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-ZT4NXID2.mjs → chunk-ZQ4OU7JZ.mjs} +289 -251
- package/dist/lib/browser/chunk-ZQ4OU7JZ.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +5 -2
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node/{chunk-DZJ3BJOK.cjs → chunk-IQBYIEAR.cjs} +294 -256
- package/dist/lib/node/chunk-IQBYIEAR.cjs.map +7 -0
- package/dist/lib/node/index.cjs +28 -28
- package/dist/lib/node/index.cjs.map +1 -1
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +22 -19
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/types/src/network-manager.d.ts +9 -6
- 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 +5 -4
- package/dist/types/src/signal/signal-messenger.d.ts.map +1 -1
- package/dist/types/src/signal/swarm-messenger.d.ts +4 -7
- package/dist/types/src/signal/swarm-messenger.d.ts.map +1 -1
- package/dist/types/src/swarm/connection.d.ts +4 -4
- package/dist/types/src/swarm/connection.d.ts.map +1 -1
- package/dist/types/src/swarm/peer.d.ts +5 -4
- package/dist/types/src/swarm/peer.d.ts.map +1 -1
- package/dist/types/src/swarm/swarm-mapper.d.ts.map +1 -1
- package/dist/types/src/swarm/swarm.d.ts +4 -4
- package/dist/types/src/swarm/swarm.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/package.json +19 -18
- package/src/connection-log.ts +1 -1
- package/src/network-manager.ts +27 -13
- package/src/signal/integration.test.ts +25 -19
- package/src/signal/signal-connection.ts +3 -2
- package/src/signal/signal-messenger.ts +5 -4
- package/src/signal/swarm-messenger.test.ts +21 -21
- package/src/signal/swarm-messenger.ts +11 -10
- package/src/swarm/connection.test.ts +19 -17
- package/src/swarm/connection.ts +16 -15
- package/src/swarm/peer.ts +41 -35
- package/src/swarm/swarm-mapper.ts +7 -6
- package/src/swarm/swarm.test.ts +36 -28
- package/src/swarm/swarm.ts +57 -53
- package/src/testing/test-builder.ts +1 -1
- package/src/tests/basic-test-suite.ts +8 -5
- package/src/tests/property-test-suite.ts +4 -1
- package/dist/lib/browser/chunk-ZT4NXID2.mjs.map +0 -7
- package/dist/lib/node/chunk-DZJ3BJOK.cjs.map +0 -7
|
@@ -49,10 +49,10 @@ var ConnectionState;
|
|
|
49
49
|
ConnectionState5["ABORTED"] = "ABORTED";
|
|
50
50
|
})(ConnectionState || (ConnectionState = {}));
|
|
51
51
|
var Connection = class {
|
|
52
|
-
constructor(topic,
|
|
52
|
+
constructor(topic, localInfo, remoteInfo, sessionId, initiator, _signalMessaging, _protocol, _transportFactory, _callbacks) {
|
|
53
53
|
this.topic = topic;
|
|
54
|
-
this.
|
|
55
|
-
this.
|
|
54
|
+
this.localInfo = localInfo;
|
|
55
|
+
this.remoteInfo = remoteInfo;
|
|
56
56
|
this.sessionId = sessionId;
|
|
57
57
|
this.initiator = initiator;
|
|
58
58
|
this._signalMessaging = _signalMessaging;
|
|
@@ -61,11 +61,11 @@ var Connection = class {
|
|
|
61
61
|
this._callbacks = _callbacks;
|
|
62
62
|
this._ctx = new Context(void 0, {
|
|
63
63
|
F: __dxlog_file,
|
|
64
|
-
L:
|
|
64
|
+
L: 101
|
|
65
65
|
});
|
|
66
66
|
this.connectedTimeoutContext = new Context(void 0, {
|
|
67
67
|
F: __dxlog_file,
|
|
68
|
-
L:
|
|
68
|
+
L: 102
|
|
69
69
|
});
|
|
70
70
|
this._protocolClosed = new Trigger();
|
|
71
71
|
this._transportClosed = new Trigger();
|
|
@@ -83,12 +83,12 @@ var Connection = class {
|
|
|
83
83
|
log.trace("dxos.mesh.connection.construct", {
|
|
84
84
|
sessionId: this.sessionId,
|
|
85
85
|
topic: this.topic,
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
localPeer: this.localInfo,
|
|
87
|
+
remotePeer: this.remoteInfo,
|
|
88
88
|
initiator: this.initiator
|
|
89
89
|
}, {
|
|
90
90
|
F: __dxlog_file,
|
|
91
|
-
L:
|
|
91
|
+
L: 138,
|
|
92
92
|
S: this,
|
|
93
93
|
C: (f, a) => f(...a)
|
|
94
94
|
});
|
|
@@ -111,7 +111,7 @@ var Connection = class {
|
|
|
111
111
|
async openConnection() {
|
|
112
112
|
invariant(this._state === "INITIAL", "Invalid state.", {
|
|
113
113
|
F: __dxlog_file,
|
|
114
|
-
L:
|
|
114
|
+
L: 168,
|
|
115
115
|
S: this,
|
|
116
116
|
A: [
|
|
117
117
|
"this._state === ConnectionState.INITIAL",
|
|
@@ -122,19 +122,19 @@ var Connection = class {
|
|
|
122
122
|
id: this._instanceId
|
|
123
123
|
}), {
|
|
124
124
|
F: __dxlog_file,
|
|
125
|
-
L:
|
|
125
|
+
L: 169,
|
|
126
126
|
S: this,
|
|
127
127
|
C: (f, a) => f(...a)
|
|
128
128
|
});
|
|
129
129
|
log.trace("dxos.mesh.connection.open", {
|
|
130
130
|
sessionId: this.sessionId,
|
|
131
131
|
topic: this.topic,
|
|
132
|
-
localPeerId: this.
|
|
133
|
-
remotePeerId: this.
|
|
132
|
+
localPeerId: this.localInfo,
|
|
133
|
+
remotePeerId: this.remoteInfo,
|
|
134
134
|
initiator: this.initiator
|
|
135
135
|
}, {
|
|
136
136
|
F: __dxlog_file,
|
|
137
|
-
L:
|
|
137
|
+
L: 170,
|
|
138
138
|
S: this,
|
|
139
139
|
C: (f, a) => f(...a)
|
|
140
140
|
});
|
|
@@ -145,7 +145,7 @@ var Connection = class {
|
|
|
145
145
|
this._protocol.stream.on("close", () => {
|
|
146
146
|
log("protocol stream closed", void 0, {
|
|
147
147
|
F: __dxlog_file,
|
|
148
|
-
L:
|
|
148
|
+
L: 187,
|
|
149
149
|
S: this,
|
|
150
150
|
C: (f, a) => f(...a)
|
|
151
151
|
});
|
|
@@ -155,7 +155,7 @@ var Connection = class {
|
|
|
155
155
|
scheduleTask(this.connectedTimeoutContext, async () => {
|
|
156
156
|
log.info(`timeout waiting ${TRANSPORT_CONNECTION_TIMEOUT / 1e3}s for transport to connect, aborting`, void 0, {
|
|
157
157
|
F: __dxlog_file,
|
|
158
|
-
L:
|
|
158
|
+
L: 195,
|
|
159
159
|
S: this,
|
|
160
160
|
C: (f, a) => f(...a)
|
|
161
161
|
});
|
|
@@ -163,7 +163,7 @@ var Connection = class {
|
|
|
163
163
|
}, TRANSPORT_CONNECTION_TIMEOUT);
|
|
164
164
|
invariant(!this._transport, void 0, {
|
|
165
165
|
F: __dxlog_file,
|
|
166
|
-
L:
|
|
166
|
+
L: 203,
|
|
167
167
|
S: this,
|
|
168
168
|
A: [
|
|
169
169
|
"!this._transport",
|
|
@@ -188,7 +188,7 @@ var Connection = class {
|
|
|
188
188
|
this._transportClosed.wake();
|
|
189
189
|
log("abort triggered by transport close", void 0, {
|
|
190
190
|
F: __dxlog_file,
|
|
191
|
-
L:
|
|
191
|
+
L: 224,
|
|
192
192
|
S: this,
|
|
193
193
|
C: (f, a) => f(...a)
|
|
194
194
|
});
|
|
@@ -199,7 +199,7 @@ var Connection = class {
|
|
|
199
199
|
err
|
|
200
200
|
}, {
|
|
201
201
|
F: __dxlog_file,
|
|
202
|
-
L:
|
|
202
|
+
L: 229,
|
|
203
203
|
S: this,
|
|
204
204
|
C: (f, a) => f(...a)
|
|
205
205
|
});
|
|
@@ -209,7 +209,7 @@ var Connection = class {
|
|
|
209
209
|
if (err instanceof ConnectionResetError) {
|
|
210
210
|
log.info("aborting due to transport ConnectionResetError", void 0, {
|
|
211
211
|
F: __dxlog_file,
|
|
212
|
-
L:
|
|
212
|
+
L: 236,
|
|
213
213
|
S: this,
|
|
214
214
|
C: (f, a) => f(...a)
|
|
215
215
|
});
|
|
@@ -217,7 +217,7 @@ var Connection = class {
|
|
|
217
217
|
} else if (err instanceof ConnectivityError) {
|
|
218
218
|
log.info("aborting due to transport ConnectivityError", void 0, {
|
|
219
219
|
F: __dxlog_file,
|
|
220
|
-
L:
|
|
220
|
+
L: 239,
|
|
221
221
|
S: this,
|
|
222
222
|
C: (f, a) => f(...a)
|
|
223
223
|
});
|
|
@@ -227,7 +227,7 @@ var Connection = class {
|
|
|
227
227
|
err
|
|
228
228
|
}, {
|
|
229
229
|
F: __dxlog_file,
|
|
230
|
-
L:
|
|
230
|
+
L: 242,
|
|
231
231
|
S: this,
|
|
232
232
|
C: (f, a) => f(...a)
|
|
233
233
|
});
|
|
@@ -245,7 +245,7 @@ var Connection = class {
|
|
|
245
245
|
id: this._instanceId
|
|
246
246
|
}), {
|
|
247
247
|
F: __dxlog_file,
|
|
248
|
-
L:
|
|
248
|
+
L: 258,
|
|
249
249
|
S: this,
|
|
250
250
|
C: (f, a) => f(...a)
|
|
251
251
|
});
|
|
@@ -255,14 +255,14 @@ var Connection = class {
|
|
|
255
255
|
err
|
|
256
256
|
}, {
|
|
257
257
|
F: __dxlog_file,
|
|
258
|
-
L:
|
|
258
|
+
L: 265,
|
|
259
259
|
S: this,
|
|
260
260
|
C: (f, a) => f(...a)
|
|
261
261
|
});
|
|
262
262
|
if (this._state === "CLOSED" || this._state === "ABORTED") {
|
|
263
263
|
log(`abort ignored: already ${this._state}`, this.closeReason, {
|
|
264
264
|
F: __dxlog_file,
|
|
265
|
-
L:
|
|
265
|
+
L: 267,
|
|
266
266
|
S: this,
|
|
267
267
|
C: (f, a) => f(...a)
|
|
268
268
|
});
|
|
@@ -281,7 +281,7 @@ var Connection = class {
|
|
|
281
281
|
} catch (err2) {
|
|
282
282
|
log.catch(err2, void 0, {
|
|
283
283
|
F: __dxlog_file,
|
|
284
|
-
L:
|
|
284
|
+
L: 283,
|
|
285
285
|
S: this,
|
|
286
286
|
C: (f, a) => f(...a)
|
|
287
287
|
});
|
|
@@ -291,7 +291,7 @@ var Connection = class {
|
|
|
291
291
|
} catch (err2) {
|
|
292
292
|
log.catch(err2, void 0, {
|
|
293
293
|
F: __dxlog_file,
|
|
294
|
-
L:
|
|
294
|
+
L: 290,
|
|
295
295
|
S: this,
|
|
296
296
|
C: (f, a) => f(...a)
|
|
297
297
|
});
|
|
@@ -301,7 +301,7 @@ var Connection = class {
|
|
|
301
301
|
} catch (err2) {
|
|
302
302
|
log.catch(err2, void 0, {
|
|
303
303
|
F: __dxlog_file,
|
|
304
|
-
L:
|
|
304
|
+
L: 296,
|
|
305
305
|
S: this,
|
|
306
306
|
C: (f, a) => f(...a)
|
|
307
307
|
});
|
|
@@ -322,10 +322,10 @@ var Connection = class {
|
|
|
322
322
|
await this.connectedTimeoutContext.dispose();
|
|
323
323
|
await this._ctx.dispose();
|
|
324
324
|
log("closing...", {
|
|
325
|
-
peerId: this.
|
|
325
|
+
peerId: this.localInfo
|
|
326
326
|
}, {
|
|
327
327
|
F: __dxlog_file,
|
|
328
|
-
L:
|
|
328
|
+
L: 321,
|
|
329
329
|
S: this,
|
|
330
330
|
C: (f, a) => f(...a)
|
|
331
331
|
});
|
|
@@ -333,7 +333,7 @@ var Connection = class {
|
|
|
333
333
|
if (lastState !== "CONNECTED") {
|
|
334
334
|
log(`graceful close requested when we were in ${lastState} state? aborting`, void 0, {
|
|
335
335
|
F: __dxlog_file,
|
|
336
|
-
L:
|
|
336
|
+
L: 325,
|
|
337
337
|
S: this,
|
|
338
338
|
C: (f, a) => f(...a)
|
|
339
339
|
});
|
|
@@ -346,7 +346,7 @@ var Connection = class {
|
|
|
346
346
|
} catch (err2) {
|
|
347
347
|
log.catch(err2, void 0, {
|
|
348
348
|
F: __dxlog_file,
|
|
349
|
-
L:
|
|
349
|
+
L: 331,
|
|
350
350
|
S: this,
|
|
351
351
|
C: (f, a) => f(...a)
|
|
352
352
|
});
|
|
@@ -356,16 +356,16 @@ var Connection = class {
|
|
|
356
356
|
} catch (err2) {
|
|
357
357
|
log.catch(err2, void 0, {
|
|
358
358
|
F: __dxlog_file,
|
|
359
|
-
L:
|
|
359
|
+
L: 337,
|
|
360
360
|
S: this,
|
|
361
361
|
C: (f, a) => f(...a)
|
|
362
362
|
});
|
|
363
363
|
}
|
|
364
364
|
log("closed", {
|
|
365
|
-
peerId: this.
|
|
365
|
+
peerId: this.localInfo
|
|
366
366
|
}, {
|
|
367
367
|
F: __dxlog_file,
|
|
368
|
-
L:
|
|
368
|
+
L: 340,
|
|
369
369
|
S: this,
|
|
370
370
|
C: (f, a) => f(...a)
|
|
371
371
|
});
|
|
@@ -375,7 +375,7 @@ var Connection = class {
|
|
|
375
375
|
async _closeProtocol(options) {
|
|
376
376
|
log("closing protocol", options, {
|
|
377
377
|
F: __dxlog_file,
|
|
378
|
-
L:
|
|
378
|
+
L: 346,
|
|
379
379
|
S: this,
|
|
380
380
|
C: (f, a) => f(...a)
|
|
381
381
|
});
|
|
@@ -385,7 +385,7 @@ var Connection = class {
|
|
|
385
385
|
]);
|
|
386
386
|
log("protocol closed", options, {
|
|
387
387
|
F: __dxlog_file,
|
|
388
|
-
L:
|
|
388
|
+
L: 348,
|
|
389
389
|
S: this,
|
|
390
390
|
C: (f, a) => f(...a)
|
|
391
391
|
});
|
|
@@ -393,7 +393,7 @@ var Connection = class {
|
|
|
393
393
|
async _closeTransport() {
|
|
394
394
|
log("closing transport", void 0, {
|
|
395
395
|
F: __dxlog_file,
|
|
396
|
-
L:
|
|
396
|
+
L: 352,
|
|
397
397
|
S: this,
|
|
398
398
|
C: (f, a) => f(...a)
|
|
399
399
|
});
|
|
@@ -403,7 +403,7 @@ var Connection = class {
|
|
|
403
403
|
]);
|
|
404
404
|
log("transport closed", void 0, {
|
|
405
405
|
F: __dxlog_file,
|
|
406
|
-
L:
|
|
406
|
+
L: 354,
|
|
407
407
|
S: this,
|
|
408
408
|
C: (f, a) => f(...a)
|
|
409
409
|
});
|
|
@@ -426,8 +426,8 @@ var Connection = class {
|
|
|
426
426
|
];
|
|
427
427
|
this._outgoingSignalBuffer.length = 0;
|
|
428
428
|
await this._signalMessaging.signal({
|
|
429
|
-
author: this.
|
|
430
|
-
recipient: this.
|
|
429
|
+
author: this.localInfo,
|
|
430
|
+
recipient: this.remoteInfo,
|
|
431
431
|
sessionId: this.sessionId,
|
|
432
432
|
topic: this.topic,
|
|
433
433
|
data: {
|
|
@@ -444,7 +444,7 @@ var Connection = class {
|
|
|
444
444
|
err
|
|
445
445
|
}, {
|
|
446
446
|
F: __dxlog_file,
|
|
447
|
-
L:
|
|
447
|
+
L: 394,
|
|
448
448
|
S: this,
|
|
449
449
|
C: (f, a) => f(...a)
|
|
450
450
|
});
|
|
@@ -457,7 +457,7 @@ var Connection = class {
|
|
|
457
457
|
async signal(msg) {
|
|
458
458
|
invariant(msg.sessionId, void 0, {
|
|
459
459
|
F: __dxlog_file,
|
|
460
|
-
L:
|
|
460
|
+
L: 403,
|
|
461
461
|
S: this,
|
|
462
462
|
A: [
|
|
463
463
|
"msg.sessionId",
|
|
@@ -467,7 +467,7 @@ var Connection = class {
|
|
|
467
467
|
if (!msg.sessionId.equals(this.sessionId)) {
|
|
468
468
|
log("dropping signal for incorrect session id", void 0, {
|
|
469
469
|
F: __dxlog_file,
|
|
470
|
-
L:
|
|
470
|
+
L: 405,
|
|
471
471
|
S: this,
|
|
472
472
|
C: (f, a) => f(...a)
|
|
473
473
|
});
|
|
@@ -475,28 +475,28 @@ var Connection = class {
|
|
|
475
475
|
}
|
|
476
476
|
invariant(msg.data.signal || msg.data.signalBatch, void 0, {
|
|
477
477
|
F: __dxlog_file,
|
|
478
|
-
L:
|
|
478
|
+
L: 408,
|
|
479
479
|
S: this,
|
|
480
480
|
A: [
|
|
481
481
|
"msg.data.signal || msg.data.signalBatch",
|
|
482
482
|
""
|
|
483
483
|
]
|
|
484
484
|
});
|
|
485
|
-
invariant(msg.author
|
|
485
|
+
invariant(msg.author.peerKey === this.remoteInfo.peerKey, void 0, {
|
|
486
486
|
F: __dxlog_file,
|
|
487
|
-
L:
|
|
487
|
+
L: 409,
|
|
488
488
|
S: this,
|
|
489
489
|
A: [
|
|
490
|
-
"msg.author
|
|
490
|
+
"msg.author.peerKey === this.remoteInfo.peerKey",
|
|
491
491
|
""
|
|
492
492
|
]
|
|
493
493
|
});
|
|
494
|
-
invariant(msg.recipient
|
|
494
|
+
invariant(msg.recipient.peerKey === this.localInfo.peerKey, void 0, {
|
|
495
495
|
F: __dxlog_file,
|
|
496
|
-
L:
|
|
496
|
+
L: 410,
|
|
497
497
|
S: this,
|
|
498
498
|
A: [
|
|
499
|
-
"msg.recipient
|
|
499
|
+
"msg.recipient.peerKey === this.localInfo.peerKey",
|
|
500
500
|
""
|
|
501
501
|
]
|
|
502
502
|
});
|
|
@@ -512,12 +512,12 @@ var Connection = class {
|
|
|
512
512
|
"INITIAL"
|
|
513
513
|
].includes(this.state)) {
|
|
514
514
|
log("buffered signal", {
|
|
515
|
-
peerId: this.
|
|
516
|
-
remoteId: this.
|
|
515
|
+
peerId: this.localInfo,
|
|
516
|
+
remoteId: this.remoteInfo,
|
|
517
517
|
msg: msg.data
|
|
518
518
|
}, {
|
|
519
519
|
F: __dxlog_file,
|
|
520
|
-
L:
|
|
520
|
+
L: 419,
|
|
521
521
|
S: this,
|
|
522
522
|
C: (f, a) => f(...a)
|
|
523
523
|
});
|
|
@@ -525,7 +525,7 @@ var Connection = class {
|
|
|
525
525
|
} else {
|
|
526
526
|
invariant(this._transport, "Connection not ready to accept signals.", {
|
|
527
527
|
F: __dxlog_file,
|
|
528
|
-
L:
|
|
528
|
+
L: 422,
|
|
529
529
|
S: this,
|
|
530
530
|
A: [
|
|
531
531
|
"this._transport",
|
|
@@ -533,12 +533,12 @@ var Connection = class {
|
|
|
533
533
|
]
|
|
534
534
|
});
|
|
535
535
|
log("received signal", {
|
|
536
|
-
peerId: this.
|
|
537
|
-
remoteId: this.
|
|
536
|
+
peerId: this.localInfo,
|
|
537
|
+
remoteId: this.remoteInfo,
|
|
538
538
|
msg: msg.data
|
|
539
539
|
}, {
|
|
540
540
|
F: __dxlog_file,
|
|
541
|
-
L:
|
|
541
|
+
L: 423,
|
|
542
542
|
S: this,
|
|
543
543
|
C: (f, a) => f(...a)
|
|
544
544
|
});
|
|
@@ -553,16 +553,16 @@ var Connection = class {
|
|
|
553
553
|
log("stateChanged", {
|
|
554
554
|
from: this._state,
|
|
555
555
|
to: state,
|
|
556
|
-
peerId: this.
|
|
556
|
+
peerId: this.localInfo
|
|
557
557
|
}, {
|
|
558
558
|
F: __dxlog_file,
|
|
559
|
-
L:
|
|
559
|
+
L: 434,
|
|
560
560
|
S: this,
|
|
561
561
|
C: (f, a) => f(...a)
|
|
562
562
|
});
|
|
563
563
|
invariant(state !== this._state, "Already in this state.", {
|
|
564
564
|
F: __dxlog_file,
|
|
565
|
-
L:
|
|
565
|
+
L: 435,
|
|
566
566
|
S: this,
|
|
567
567
|
A: [
|
|
568
568
|
"state !== this._state",
|
|
@@ -630,7 +630,7 @@ var SwarmMessenger = class {
|
|
|
630
630
|
constructor({ sendMessage, onSignal, onOffer, topic }) {
|
|
631
631
|
this._ctx = new Context2(void 0, {
|
|
632
632
|
F: __dxlog_file3,
|
|
633
|
-
L:
|
|
633
|
+
L: 34
|
|
634
634
|
});
|
|
635
635
|
this._offerRecords = new ComplexMap((key) => key.toHex());
|
|
636
636
|
this._sendMessage = sendMessage;
|
|
@@ -652,7 +652,7 @@ var SwarmMessenger = class {
|
|
|
652
652
|
msg: message
|
|
653
653
|
}, {
|
|
654
654
|
F: __dxlog_file3,
|
|
655
|
-
L:
|
|
655
|
+
L: 70,
|
|
656
656
|
S: this,
|
|
657
657
|
C: (f, a) => f(...a)
|
|
658
658
|
});
|
|
@@ -681,7 +681,7 @@ var SwarmMessenger = class {
|
|
|
681
681
|
message
|
|
682
682
|
}, {
|
|
683
683
|
F: __dxlog_file3,
|
|
684
|
-
L:
|
|
684
|
+
L: 81,
|
|
685
685
|
S: this,
|
|
686
686
|
C: (f, a) => f(...a)
|
|
687
687
|
});
|
|
@@ -690,7 +690,7 @@ var SwarmMessenger = class {
|
|
|
690
690
|
async signal(message) {
|
|
691
691
|
invariant2(message.data?.signal || message.data?.signalBatch, "Invalid message", {
|
|
692
692
|
F: __dxlog_file3,
|
|
693
|
-
L:
|
|
693
|
+
L: 86,
|
|
694
694
|
S: this,
|
|
695
695
|
A: [
|
|
696
696
|
"message.data?.signal || message.data?.signalBatch",
|
|
@@ -731,7 +731,7 @@ var SwarmMessenger = class {
|
|
|
731
731
|
msg: networkMessage
|
|
732
732
|
}, {
|
|
733
733
|
F: __dxlog_file3,
|
|
734
|
-
L:
|
|
734
|
+
L: 124,
|
|
735
735
|
S: this,
|
|
736
736
|
C: (f, a) => f(...a)
|
|
737
737
|
});
|
|
@@ -747,7 +747,7 @@ var SwarmMessenger = class {
|
|
|
747
747
|
async _resolveAnswers(message) {
|
|
748
748
|
invariant2(message.data?.answer?.offerMessageId, "No offerMessageId", {
|
|
749
749
|
F: __dxlog_file3,
|
|
750
|
-
L:
|
|
750
|
+
L: 136,
|
|
751
751
|
S: this,
|
|
752
752
|
A: [
|
|
753
753
|
"message.data?.answer?.offerMessageId",
|
|
@@ -759,7 +759,7 @@ var SwarmMessenger = class {
|
|
|
759
759
|
this._offerRecords.delete(message.data.answer.offerMessageId);
|
|
760
760
|
invariant2(message.data?.answer, "No answer", {
|
|
761
761
|
F: __dxlog_file3,
|
|
762
|
-
L:
|
|
762
|
+
L: 140,
|
|
763
763
|
S: this,
|
|
764
764
|
A: [
|
|
765
765
|
"message.data?.answer",
|
|
@@ -770,7 +770,7 @@ var SwarmMessenger = class {
|
|
|
770
770
|
answer: message.data.answer
|
|
771
771
|
}, {
|
|
772
772
|
F: __dxlog_file3,
|
|
773
|
-
L:
|
|
773
|
+
L: 141,
|
|
774
774
|
S: this,
|
|
775
775
|
C: (f, a) => f(...a)
|
|
776
776
|
});
|
|
@@ -780,7 +780,7 @@ var SwarmMessenger = class {
|
|
|
780
780
|
async _handleOffer({ author, recipient, message }) {
|
|
781
781
|
invariant2(message.data.offer, "No offer", {
|
|
782
782
|
F: __dxlog_file3,
|
|
783
|
-
L:
|
|
783
|
+
L: 155,
|
|
784
784
|
S: this,
|
|
785
785
|
A: [
|
|
786
786
|
"message.data.offer",
|
|
@@ -815,7 +815,7 @@ var SwarmMessenger = class {
|
|
|
815
815
|
err
|
|
816
816
|
}, {
|
|
817
817
|
F: __dxlog_file3,
|
|
818
|
-
L:
|
|
818
|
+
L: 176,
|
|
819
819
|
S: this,
|
|
820
820
|
C: (f, a) => f(...a)
|
|
821
821
|
});
|
|
@@ -824,7 +824,7 @@ var SwarmMessenger = class {
|
|
|
824
824
|
err
|
|
825
825
|
}, {
|
|
826
826
|
F: __dxlog_file3,
|
|
827
|
-
L:
|
|
827
|
+
L: 178,
|
|
828
828
|
S: this,
|
|
829
829
|
C: (f, a) => f(...a)
|
|
830
830
|
});
|
|
@@ -834,7 +834,7 @@ var SwarmMessenger = class {
|
|
|
834
834
|
async _handleSignal({ author, recipient, message }) {
|
|
835
835
|
invariant2(message.messageId, void 0, {
|
|
836
836
|
F: __dxlog_file3,
|
|
837
|
-
L:
|
|
837
|
+
L: 192,
|
|
838
838
|
S: this,
|
|
839
839
|
A: [
|
|
840
840
|
"message.messageId",
|
|
@@ -843,7 +843,7 @@ var SwarmMessenger = class {
|
|
|
843
843
|
});
|
|
844
844
|
invariant2(message.data.signal || message.data.signalBatch, "Invalid message", {
|
|
845
845
|
F: __dxlog_file3,
|
|
846
|
-
L:
|
|
846
|
+
L: 193,
|
|
847
847
|
S: this,
|
|
848
848
|
A: [
|
|
849
849
|
"message.data.signal || message.data.signalBatch",
|
|
@@ -870,6 +870,7 @@ import { ErrorStream as ErrorStream2 } from "@dxos/debug";
|
|
|
870
870
|
import { invariant as invariant4 } from "@dxos/invariant";
|
|
871
871
|
import { PublicKey as PublicKey4 } from "@dxos/keys";
|
|
872
872
|
import { log as log5, logInfo as logInfo2 } from "@dxos/log";
|
|
873
|
+
import { PeerInfoHash } from "@dxos/messaging";
|
|
873
874
|
import { trace as trace2 } from "@dxos/protocols";
|
|
874
875
|
import { ComplexMap as ComplexMap2, isNotNullOrUndefined as isNotNullOrUndefined2 } from "@dxos/util";
|
|
875
876
|
|
|
@@ -898,10 +899,10 @@ var ConnectionDisplacedError = class extends SystemError {
|
|
|
898
899
|
};
|
|
899
900
|
var CONNECTION_COUNTS_STABLE_AFTER = 5e3;
|
|
900
901
|
var Peer = class {
|
|
901
|
-
constructor(
|
|
902
|
-
this.
|
|
902
|
+
constructor(remoteInfo, topic, localInfo, _signalMessaging, _protocolProvider, _transportFactory, _connectionLimiter, _callbacks) {
|
|
903
|
+
this.remoteInfo = remoteInfo;
|
|
903
904
|
this.topic = topic;
|
|
904
|
-
this.
|
|
905
|
+
this.localInfo = localInfo;
|
|
905
906
|
this._signalMessaging = _signalMessaging;
|
|
906
907
|
this._protocolProvider = _protocolProvider;
|
|
907
908
|
this._transportFactory = _transportFactory;
|
|
@@ -911,7 +912,7 @@ var Peer = class {
|
|
|
911
912
|
this.availableToConnect = true;
|
|
912
913
|
this._ctx = new Context3(void 0, {
|
|
913
914
|
F: __dxlog_file4,
|
|
914
|
-
L:
|
|
915
|
+
L: 80
|
|
915
916
|
});
|
|
916
917
|
this.advertizing = false;
|
|
917
918
|
this.initiating = false;
|
|
@@ -921,7 +922,7 @@ var Peer = class {
|
|
|
921
922
|
* Respond to remote offer.
|
|
922
923
|
*/
|
|
923
924
|
async onOffer(message) {
|
|
924
|
-
const
|
|
925
|
+
const remote = message.author;
|
|
925
926
|
if (this.connection && ![
|
|
926
927
|
ConnectionState.CREATED,
|
|
927
928
|
ConnectionState.INITIAL,
|
|
@@ -929,7 +930,7 @@ var Peer = class {
|
|
|
929
930
|
].includes(this.connection.state)) {
|
|
930
931
|
log4.info(`received offer when connection already in ${this.connection.state} state`, void 0, {
|
|
931
932
|
F: __dxlog_file4,
|
|
932
|
-
L:
|
|
933
|
+
L: 115,
|
|
933
934
|
S: this,
|
|
934
935
|
C: (f, a) => f(...a)
|
|
935
936
|
});
|
|
@@ -938,15 +939,15 @@ var Peer = class {
|
|
|
938
939
|
};
|
|
939
940
|
}
|
|
940
941
|
if (this.connection || this.initiating) {
|
|
941
|
-
if (
|
|
942
|
+
if (remote.peerKey < this.localInfo.peerKey) {
|
|
942
943
|
log4("close local connection", {
|
|
943
|
-
|
|
944
|
+
localPeer: this.localInfo,
|
|
944
945
|
topic: this.topic,
|
|
945
|
-
|
|
946
|
+
remotePeer: this.remoteInfo,
|
|
946
947
|
sessionId: this.connection?.sessionId
|
|
947
948
|
}, {
|
|
948
949
|
F: __dxlog_file4,
|
|
949
|
-
L:
|
|
950
|
+
L: 124,
|
|
950
951
|
S: this,
|
|
951
952
|
C: (f, a) => f(...a)
|
|
952
953
|
});
|
|
@@ -959,11 +960,11 @@ var Peer = class {
|
|
|
959
960
|
};
|
|
960
961
|
}
|
|
961
962
|
}
|
|
962
|
-
if (await this._callbacks.onOffer(
|
|
963
|
+
if (await this._callbacks.onOffer(remote)) {
|
|
963
964
|
if (!this.connection) {
|
|
964
965
|
invariant3(message.sessionId, void 0, {
|
|
965
966
|
F: __dxlog_file4,
|
|
966
|
-
L:
|
|
967
|
+
L: 144,
|
|
967
968
|
S: this,
|
|
968
969
|
A: [
|
|
969
970
|
"message.sessionId",
|
|
@@ -979,12 +980,12 @@ var Peer = class {
|
|
|
979
980
|
if (!(err instanceof CancelledError2)) {
|
|
980
981
|
log4.info("connection error", {
|
|
981
982
|
topic: this.topic,
|
|
982
|
-
peerId: this.
|
|
983
|
-
remoteId: this.
|
|
983
|
+
peerId: this.localInfo,
|
|
984
|
+
remoteId: this.remoteInfo,
|
|
984
985
|
err
|
|
985
986
|
}, {
|
|
986
987
|
F: __dxlog_file4,
|
|
987
|
-
L:
|
|
988
|
+
L: 154,
|
|
988
989
|
S: this,
|
|
989
990
|
C: (f, a) => f(...a)
|
|
990
991
|
});
|
|
@@ -1006,7 +1007,7 @@ var Peer = class {
|
|
|
1006
1007
|
async initiateConnection() {
|
|
1007
1008
|
invariant3(!this.initiating, "Initiation in progress.", {
|
|
1008
1009
|
F: __dxlog_file4,
|
|
1009
|
-
L:
|
|
1010
|
+
L: 171,
|
|
1010
1011
|
S: this,
|
|
1011
1012
|
A: [
|
|
1012
1013
|
"!this.initiating",
|
|
@@ -1015,7 +1016,7 @@ var Peer = class {
|
|
|
1015
1016
|
});
|
|
1016
1017
|
invariant3(!this.connection, "Already connected.", {
|
|
1017
1018
|
F: __dxlog_file4,
|
|
1018
|
-
L:
|
|
1019
|
+
L: 172,
|
|
1019
1020
|
S: this,
|
|
1020
1021
|
A: [
|
|
1021
1022
|
"!this.connection",
|
|
@@ -1024,13 +1025,13 @@ var Peer = class {
|
|
|
1024
1025
|
});
|
|
1025
1026
|
const sessionId = PublicKey3.random();
|
|
1026
1027
|
log4("initiating...", {
|
|
1027
|
-
|
|
1028
|
+
local: this.localInfo,
|
|
1028
1029
|
topic: this.topic,
|
|
1029
|
-
|
|
1030
|
+
remote: this.remoteInfo,
|
|
1030
1031
|
sessionId
|
|
1031
1032
|
}, {
|
|
1032
1033
|
F: __dxlog_file4,
|
|
1033
|
-
L:
|
|
1034
|
+
L: 174,
|
|
1034
1035
|
S: this,
|
|
1035
1036
|
C: (f, a) => f(...a)
|
|
1036
1037
|
});
|
|
@@ -1041,8 +1042,8 @@ var Peer = class {
|
|
|
1041
1042
|
await this._connectionLimiter.connecting(sessionId);
|
|
1042
1043
|
connection.initiate();
|
|
1043
1044
|
answer = await this._signalMessaging.offer({
|
|
1044
|
-
author: this.
|
|
1045
|
-
recipient: this.
|
|
1045
|
+
author: this.localInfo,
|
|
1046
|
+
recipient: this.remoteInfo,
|
|
1046
1047
|
sessionId,
|
|
1047
1048
|
topic: this.topic,
|
|
1048
1049
|
data: {
|
|
@@ -1052,18 +1053,18 @@ var Peer = class {
|
|
|
1052
1053
|
log4("received", {
|
|
1053
1054
|
answer,
|
|
1054
1055
|
topic: this.topic,
|
|
1055
|
-
|
|
1056
|
-
|
|
1056
|
+
local: this.localInfo,
|
|
1057
|
+
remote: this.remoteInfo
|
|
1057
1058
|
}, {
|
|
1058
1059
|
F: __dxlog_file4,
|
|
1059
|
-
L:
|
|
1060
|
+
L: 191,
|
|
1060
1061
|
S: this,
|
|
1061
1062
|
C: (f, a) => f(...a)
|
|
1062
1063
|
});
|
|
1063
1064
|
if (connection.state !== ConnectionState.INITIAL) {
|
|
1064
1065
|
log4("ignoring response", void 0, {
|
|
1065
1066
|
F: __dxlog_file4,
|
|
1066
|
-
L:
|
|
1067
|
+
L: 193,
|
|
1067
1068
|
S: this,
|
|
1068
1069
|
C: (f, a) => f(...a)
|
|
1069
1070
|
});
|
|
@@ -1073,11 +1074,11 @@ var Peer = class {
|
|
|
1073
1074
|
log4("initiation error: send offer", {
|
|
1074
1075
|
err,
|
|
1075
1076
|
topic: this.topic,
|
|
1076
|
-
|
|
1077
|
-
|
|
1077
|
+
local: this.localInfo,
|
|
1078
|
+
remote: this.remoteInfo
|
|
1078
1079
|
}, {
|
|
1079
1080
|
F: __dxlog_file4,
|
|
1080
|
-
L:
|
|
1081
|
+
L: 197,
|
|
1081
1082
|
S: this,
|
|
1082
1083
|
C: (f, a) => f(...a)
|
|
1083
1084
|
});
|
|
@@ -1095,11 +1096,11 @@ var Peer = class {
|
|
|
1095
1096
|
log4("initiation error: accept answer", {
|
|
1096
1097
|
err,
|
|
1097
1098
|
topic: this.topic,
|
|
1098
|
-
|
|
1099
|
-
|
|
1099
|
+
local: this.localInfo,
|
|
1100
|
+
remote: this.remoteInfo
|
|
1100
1101
|
}, {
|
|
1101
1102
|
F: __dxlog_file4,
|
|
1102
|
-
L:
|
|
1103
|
+
L: 210,
|
|
1103
1104
|
S: this,
|
|
1104
1105
|
C: (f, a) => f(...a)
|
|
1105
1106
|
});
|
|
@@ -1111,7 +1112,7 @@ var Peer = class {
|
|
|
1111
1112
|
try {
|
|
1112
1113
|
log4("opening connection as initiator", void 0, {
|
|
1113
1114
|
F: __dxlog_file4,
|
|
1114
|
-
L:
|
|
1115
|
+
L: 223,
|
|
1115
1116
|
S: this,
|
|
1116
1117
|
C: (f, a) => f(...a)
|
|
1117
1118
|
});
|
|
@@ -1121,11 +1122,11 @@ var Peer = class {
|
|
|
1121
1122
|
log4("initiation error: open connection", {
|
|
1122
1123
|
err,
|
|
1123
1124
|
topic: this.topic,
|
|
1124
|
-
|
|
1125
|
-
|
|
1125
|
+
local: this.localInfo,
|
|
1126
|
+
remote: this.remoteInfo
|
|
1126
1127
|
}, {
|
|
1127
1128
|
F: __dxlog_file4,
|
|
1128
|
-
L:
|
|
1129
|
+
L: 227,
|
|
1129
1130
|
S: this,
|
|
1130
1131
|
C: (f, a) => f(...a)
|
|
1131
1132
|
});
|
|
@@ -1133,7 +1134,7 @@ var Peer = class {
|
|
|
1133
1134
|
err
|
|
1134
1135
|
}, {
|
|
1135
1136
|
F: __dxlog_file4,
|
|
1136
|
-
L:
|
|
1137
|
+
L: 234,
|
|
1137
1138
|
S: this,
|
|
1138
1139
|
C: (f, a) => f(...a)
|
|
1139
1140
|
});
|
|
@@ -1150,19 +1151,19 @@ var Peer = class {
|
|
|
1150
1151
|
_createConnection(initiator, sessionId) {
|
|
1151
1152
|
log4("creating connection", {
|
|
1152
1153
|
topic: this.topic,
|
|
1153
|
-
peerId: this.
|
|
1154
|
-
remoteId: this.
|
|
1154
|
+
peerId: this.localInfo,
|
|
1155
|
+
remoteId: this.remoteInfo,
|
|
1155
1156
|
initiator,
|
|
1156
1157
|
sessionId
|
|
1157
1158
|
}, {
|
|
1158
1159
|
F: __dxlog_file4,
|
|
1159
|
-
L:
|
|
1160
|
+
L: 248,
|
|
1160
1161
|
S: this,
|
|
1161
1162
|
C: (f, a) => f(...a)
|
|
1162
1163
|
});
|
|
1163
1164
|
invariant3(!this.connection, "Already connected.", {
|
|
1164
1165
|
F: __dxlog_file4,
|
|
1165
|
-
L:
|
|
1166
|
+
L: 255,
|
|
1166
1167
|
S: this,
|
|
1167
1168
|
A: [
|
|
1168
1169
|
"!this.connection",
|
|
@@ -1171,16 +1172,16 @@ var Peer = class {
|
|
|
1171
1172
|
});
|
|
1172
1173
|
const connection = new Connection(
|
|
1173
1174
|
this.topic,
|
|
1174
|
-
this.
|
|
1175
|
-
this.
|
|
1175
|
+
this.localInfo,
|
|
1176
|
+
this.remoteInfo,
|
|
1176
1177
|
sessionId,
|
|
1177
1178
|
initiator,
|
|
1178
1179
|
this._signalMessaging,
|
|
1179
1180
|
// TODO(dmaretskyi): Init only when connection is established.
|
|
1180
1181
|
this._protocolProvider({
|
|
1181
1182
|
initiator,
|
|
1182
|
-
localPeerId: this.
|
|
1183
|
-
remotePeerId: this.
|
|
1183
|
+
localPeerId: PublicKey3.from(this.localInfo.peerKey),
|
|
1184
|
+
remotePeerId: PublicKey3.from(this.remoteInfo.peerKey),
|
|
1184
1185
|
topic: this.topic
|
|
1185
1186
|
}),
|
|
1186
1187
|
this._transportFactory,
|
|
@@ -1192,13 +1193,13 @@ var Peer = class {
|
|
|
1192
1193
|
this._connectionLimiter.doneConnecting(sessionId);
|
|
1193
1194
|
log4.trace("dxos.mesh.connection.connected", {
|
|
1194
1195
|
topic: this.topic,
|
|
1195
|
-
localPeerId: this.
|
|
1196
|
-
remotePeerId: this.
|
|
1196
|
+
localPeerId: this.localInfo,
|
|
1197
|
+
remotePeerId: this.remoteInfo,
|
|
1197
1198
|
sessionId,
|
|
1198
1199
|
initiator
|
|
1199
1200
|
}, {
|
|
1200
1201
|
F: __dxlog_file4,
|
|
1201
|
-
L:
|
|
1202
|
+
L: 279,
|
|
1202
1203
|
S: this,
|
|
1203
1204
|
C: (f, a) => f(...a)
|
|
1204
1205
|
});
|
|
@@ -1206,19 +1207,19 @@ var Peer = class {
|
|
|
1206
1207
|
onClosed: (err) => {
|
|
1207
1208
|
log4("connection closed", {
|
|
1208
1209
|
topic: this.topic,
|
|
1209
|
-
peerId: this.
|
|
1210
|
-
remoteId: this.
|
|
1210
|
+
peerId: this.localInfo,
|
|
1211
|
+
remoteId: this.remoteInfo,
|
|
1211
1212
|
initiator
|
|
1212
1213
|
}, {
|
|
1213
1214
|
F: __dxlog_file4,
|
|
1214
|
-
L:
|
|
1215
|
+
L: 288,
|
|
1215
1216
|
S: this,
|
|
1216
1217
|
C: (f, a) => f(...a)
|
|
1217
1218
|
});
|
|
1218
1219
|
this._connectionLimiter.doneConnecting(sessionId);
|
|
1219
1220
|
invariant3(this.connection === connection, "Connection mismatch (race condition).", {
|
|
1220
1221
|
F: __dxlog_file4,
|
|
1221
|
-
L:
|
|
1222
|
+
L: 293,
|
|
1222
1223
|
S: this,
|
|
1223
1224
|
A: [
|
|
1224
1225
|
"this.connection === connection",
|
|
@@ -1227,13 +1228,13 @@ var Peer = class {
|
|
|
1227
1228
|
});
|
|
1228
1229
|
log4.trace("dxos.mesh.connection.closed", {
|
|
1229
1230
|
topic: this.topic,
|
|
1230
|
-
localPeerId: this.
|
|
1231
|
-
remotePeerId: this.
|
|
1231
|
+
localPeerId: this.localInfo,
|
|
1232
|
+
remotePeerId: this.remoteInfo,
|
|
1232
1233
|
sessionId,
|
|
1233
1234
|
initiator
|
|
1234
1235
|
}, {
|
|
1235
1236
|
F: __dxlog_file4,
|
|
1236
|
-
L:
|
|
1237
|
+
L: 295,
|
|
1237
1238
|
S: this,
|
|
1238
1239
|
C: (f, a) => f(...a)
|
|
1239
1240
|
});
|
|
@@ -1262,26 +1263,26 @@ var Peer = class {
|
|
|
1262
1263
|
connection.errors.handle((err) => {
|
|
1263
1264
|
log4.info("connection error, closing", {
|
|
1264
1265
|
topic: this.topic,
|
|
1265
|
-
peerId: this.
|
|
1266
|
-
remoteId: this.
|
|
1266
|
+
peerId: this.localInfo,
|
|
1267
|
+
remoteId: this.remoteInfo,
|
|
1267
1268
|
initiator,
|
|
1268
1269
|
err
|
|
1269
1270
|
}, {
|
|
1270
1271
|
F: __dxlog_file4,
|
|
1271
|
-
L:
|
|
1272
|
+
L: 335,
|
|
1272
1273
|
S: this,
|
|
1273
1274
|
C: (f, a) => f(...a)
|
|
1274
1275
|
});
|
|
1275
1276
|
log4.trace("dxos.mesh.connection.error", {
|
|
1276
1277
|
topic: this.topic,
|
|
1277
|
-
localPeerId: this.
|
|
1278
|
-
remotePeerId: this.
|
|
1278
|
+
localPeerId: this.localInfo,
|
|
1279
|
+
remotePeerId: this.remoteInfo,
|
|
1279
1280
|
sessionId,
|
|
1280
1281
|
initiator,
|
|
1281
1282
|
err
|
|
1282
1283
|
}, {
|
|
1283
1284
|
F: __dxlog_file4,
|
|
1284
|
-
L:
|
|
1285
|
+
L: 342,
|
|
1285
1286
|
S: this,
|
|
1286
1287
|
C: (f, a) => f(...a)
|
|
1287
1288
|
});
|
|
@@ -1296,21 +1297,21 @@ var Peer = class {
|
|
|
1296
1297
|
}
|
|
1297
1298
|
const connection = this.connection;
|
|
1298
1299
|
log4("closing...", {
|
|
1299
|
-
peerId: this.
|
|
1300
|
+
peerId: this.remoteInfo,
|
|
1300
1301
|
sessionId: connection.sessionId
|
|
1301
1302
|
}, {
|
|
1302
1303
|
F: __dxlog_file4,
|
|
1303
|
-
L:
|
|
1304
|
+
L: 367,
|
|
1304
1305
|
S: this,
|
|
1305
1306
|
C: (f, a) => f(...a)
|
|
1306
1307
|
});
|
|
1307
1308
|
await connection.close(err);
|
|
1308
1309
|
log4("closed", {
|
|
1309
|
-
peerId: this.
|
|
1310
|
+
peerId: this.remoteInfo,
|
|
1310
1311
|
sessionId: connection.sessionId
|
|
1311
1312
|
}, {
|
|
1312
1313
|
F: __dxlog_file4,
|
|
1313
|
-
L:
|
|
1314
|
+
L: 373,
|
|
1314
1315
|
S: this,
|
|
1315
1316
|
C: (f, a) => f(...a)
|
|
1316
1317
|
});
|
|
@@ -1321,7 +1322,7 @@ var Peer = class {
|
|
|
1321
1322
|
message
|
|
1322
1323
|
}, {
|
|
1323
1324
|
F: __dxlog_file4,
|
|
1324
|
-
L:
|
|
1325
|
+
L: 378,
|
|
1325
1326
|
S: this,
|
|
1326
1327
|
C: (f, a) => f(...a)
|
|
1327
1328
|
});
|
|
@@ -1332,11 +1333,11 @@ var Peer = class {
|
|
|
1332
1333
|
async safeDestroy(reason) {
|
|
1333
1334
|
await this._ctx.dispose();
|
|
1334
1335
|
log4("Destroying peer", {
|
|
1335
|
-
peerId: this.
|
|
1336
|
+
peerId: this.remoteInfo,
|
|
1336
1337
|
topic: this.topic
|
|
1337
1338
|
}, {
|
|
1338
1339
|
F: __dxlog_file4,
|
|
1339
|
-
L:
|
|
1340
|
+
L: 388,
|
|
1340
1341
|
S: this,
|
|
1341
1342
|
C: (f, a) => f(...a)
|
|
1342
1343
|
});
|
|
@@ -1376,9 +1377,9 @@ var getClassName = (obj) => Object.getPrototypeOf(obj).constructor.name;
|
|
|
1376
1377
|
var Swarm = class {
|
|
1377
1378
|
// TODO(burdon): Swarm => Peer.create/destroy =< Connection.open/close
|
|
1378
1379
|
// TODO(burdon): Pass in object.
|
|
1379
|
-
constructor(_topic,
|
|
1380
|
+
constructor(_topic, _ownPeer, _topology, _protocolProvider, _messenger, _transportFactory, _label, _connectionLimiter, _initiationDelay = INITIATION_DELAY) {
|
|
1380
1381
|
this._topic = _topic;
|
|
1381
|
-
this.
|
|
1382
|
+
this._ownPeer = _ownPeer;
|
|
1382
1383
|
this._topology = _topology;
|
|
1383
1384
|
this._protocolProvider = _protocolProvider;
|
|
1384
1385
|
this._messenger = _messenger;
|
|
@@ -1388,10 +1389,10 @@ var Swarm = class {
|
|
|
1388
1389
|
this._initiationDelay = _initiationDelay;
|
|
1389
1390
|
this._ctx = new Context4(void 0, {
|
|
1390
1391
|
F: __dxlog_file5,
|
|
1391
|
-
L:
|
|
1392
|
+
L: 38
|
|
1392
1393
|
});
|
|
1393
1394
|
this._listeningHandle = void 0;
|
|
1394
|
-
this._peers = new ComplexMap2(
|
|
1395
|
+
this._peers = new ComplexMap2(PeerInfoHash);
|
|
1395
1396
|
this._instanceId = PublicKey4.random().toHex();
|
|
1396
1397
|
this.connectionAdded = new Event3();
|
|
1397
1398
|
this.disconnected = new Event3();
|
|
@@ -1401,19 +1402,19 @@ var Swarm = class {
|
|
|
1401
1402
|
id: this._instanceId,
|
|
1402
1403
|
data: {
|
|
1403
1404
|
topic: this._topic.toHex(),
|
|
1404
|
-
|
|
1405
|
+
peer: this._ownPeer
|
|
1405
1406
|
}
|
|
1406
1407
|
}), {
|
|
1407
1408
|
F: __dxlog_file5,
|
|
1408
|
-
L:
|
|
1409
|
+
L: 88,
|
|
1409
1410
|
S: this,
|
|
1410
1411
|
C: (f, a) => f(...a)
|
|
1411
1412
|
});
|
|
1412
1413
|
log5("creating swarm", {
|
|
1413
|
-
peerId:
|
|
1414
|
+
peerId: _ownPeer
|
|
1414
1415
|
}, {
|
|
1415
1416
|
F: __dxlog_file5,
|
|
1416
|
-
L:
|
|
1417
|
+
L: 92,
|
|
1417
1418
|
S: this,
|
|
1418
1419
|
C: (f, a) => f(...a)
|
|
1419
1420
|
});
|
|
@@ -1428,7 +1429,7 @@ var Swarm = class {
|
|
|
1428
1429
|
id: this._instanceId
|
|
1429
1430
|
}), {
|
|
1430
1431
|
F: __dxlog_file5,
|
|
1431
|
-
L:
|
|
1432
|
+
L: 101,
|
|
1432
1433
|
S: this,
|
|
1433
1434
|
C: (f, a) => f(...a)
|
|
1434
1435
|
});
|
|
@@ -1437,7 +1438,10 @@ var Swarm = class {
|
|
|
1437
1438
|
return Array.from(this._peers.values()).map((peer) => peer.connection).filter(isNotNullOrUndefined2);
|
|
1438
1439
|
}
|
|
1439
1440
|
get ownPeerId() {
|
|
1440
|
-
return this.
|
|
1441
|
+
return PublicKey4.from(this._ownPeer.peerKey);
|
|
1442
|
+
}
|
|
1443
|
+
get ownPeer() {
|
|
1444
|
+
return this._ownPeer;
|
|
1441
1445
|
}
|
|
1442
1446
|
/**
|
|
1443
1447
|
* Custom label assigned to this swarm. Used in devtools to display human-readable names for swarms.
|
|
@@ -1451,7 +1455,7 @@ var Swarm = class {
|
|
|
1451
1455
|
async open() {
|
|
1452
1456
|
invariant4(!this._listeningHandle, void 0, {
|
|
1453
1457
|
F: __dxlog_file5,
|
|
1454
|
-
L:
|
|
1458
|
+
L: 132,
|
|
1455
1459
|
S: this,
|
|
1456
1460
|
A: [
|
|
1457
1461
|
"!this._listeningHandle",
|
|
@@ -1459,14 +1463,14 @@ var Swarm = class {
|
|
|
1459
1463
|
]
|
|
1460
1464
|
});
|
|
1461
1465
|
this._listeningHandle = await this._messenger.listen({
|
|
1462
|
-
|
|
1466
|
+
peer: this._ownPeer,
|
|
1463
1467
|
payloadType: "dxos.mesh.swarm.SwarmMessage",
|
|
1464
1468
|
onMessage: async (message) => {
|
|
1465
1469
|
await this._swarmMessenger.receiveMessage(message).catch((err) => log5.info("Error while receiving message", {
|
|
1466
1470
|
err
|
|
1467
1471
|
}, {
|
|
1468
1472
|
F: __dxlog_file5,
|
|
1469
|
-
L:
|
|
1473
|
+
L: 140,
|
|
1470
1474
|
S: this,
|
|
1471
1475
|
C: (f, a) => f(...a)
|
|
1472
1476
|
}));
|
|
@@ -1476,7 +1480,7 @@ var Swarm = class {
|
|
|
1476
1480
|
async destroy() {
|
|
1477
1481
|
log5("destroying...", void 0, {
|
|
1478
1482
|
F: __dxlog_file5,
|
|
1479
|
-
L:
|
|
1483
|
+
L: 146,
|
|
1480
1484
|
S: this,
|
|
1481
1485
|
C: (f, a) => f(...a)
|
|
1482
1486
|
});
|
|
@@ -1487,7 +1491,7 @@ var Swarm = class {
|
|
|
1487
1491
|
await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key, "swarm destroyed")));
|
|
1488
1492
|
log5("destroyed", void 0, {
|
|
1489
1493
|
F: __dxlog_file5,
|
|
1490
|
-
L:
|
|
1494
|
+
L: 153,
|
|
1491
1495
|
S: this,
|
|
1492
1496
|
C: (f, a) => f(...a)
|
|
1493
1497
|
});
|
|
@@ -1495,7 +1499,7 @@ var Swarm = class {
|
|
|
1495
1499
|
async setTopology(topology) {
|
|
1496
1500
|
invariant4(!this._ctx.disposed, "Swarm is offline", {
|
|
1497
1501
|
F: __dxlog_file5,
|
|
1498
|
-
L:
|
|
1502
|
+
L: 157,
|
|
1499
1503
|
S: this,
|
|
1500
1504
|
A: [
|
|
1501
1505
|
"!this._ctx.disposed",
|
|
@@ -1510,7 +1514,7 @@ var Swarm = class {
|
|
|
1510
1514
|
topology: getClassName(topology)
|
|
1511
1515
|
}, {
|
|
1512
1516
|
F: __dxlog_file5,
|
|
1513
|
-
L:
|
|
1517
|
+
L: 161,
|
|
1514
1518
|
S: this,
|
|
1515
1519
|
C: (f, a) => f(...a)
|
|
1516
1520
|
});
|
|
@@ -1524,51 +1528,51 @@ var Swarm = class {
|
|
|
1524
1528
|
swarmEvent
|
|
1525
1529
|
}, {
|
|
1526
1530
|
F: __dxlog_file5,
|
|
1527
|
-
L:
|
|
1531
|
+
L: 174,
|
|
1528
1532
|
S: this,
|
|
1529
1533
|
C: (f, a) => f(...a)
|
|
1530
1534
|
});
|
|
1531
1535
|
if (this._ctx.disposed) {
|
|
1532
1536
|
log5("swarm event ignored for disposed swarm", void 0, {
|
|
1533
1537
|
F: __dxlog_file5,
|
|
1534
|
-
L:
|
|
1538
|
+
L: 177,
|
|
1535
1539
|
S: this,
|
|
1536
1540
|
C: (f, a) => f(...a)
|
|
1537
1541
|
});
|
|
1538
1542
|
return;
|
|
1539
1543
|
}
|
|
1540
1544
|
if (swarmEvent.peerAvailable) {
|
|
1541
|
-
const peerId =
|
|
1542
|
-
if (
|
|
1545
|
+
const peerId = swarmEvent.peerAvailable.peer.peerKey;
|
|
1546
|
+
if (peerId !== this._ownPeer.peerKey) {
|
|
1543
1547
|
log5("new peer", {
|
|
1544
1548
|
peerId
|
|
1545
1549
|
}, {
|
|
1546
1550
|
F: __dxlog_file5,
|
|
1547
|
-
L:
|
|
1551
|
+
L: 184,
|
|
1548
1552
|
S: this,
|
|
1549
1553
|
C: (f, a) => f(...a)
|
|
1550
1554
|
});
|
|
1551
|
-
const peer = this._getOrCreatePeer(
|
|
1555
|
+
const peer = this._getOrCreatePeer(swarmEvent.peerAvailable.peer);
|
|
1552
1556
|
peer.advertizing = true;
|
|
1553
1557
|
}
|
|
1554
1558
|
} else if (swarmEvent.peerLeft) {
|
|
1555
|
-
const peer = this._peers.get(
|
|
1559
|
+
const peer = this._peers.get(swarmEvent.peerLeft.peer);
|
|
1556
1560
|
if (peer) {
|
|
1557
1561
|
peer.advertizing = false;
|
|
1558
1562
|
if (peer.connection?.state !== ConnectionState.CONNECTED) {
|
|
1559
|
-
void this._destroyPeer(peer
|
|
1563
|
+
void this._destroyPeer(swarmEvent.peerLeft.peer, "peer left").catch((err) => log5.catch(err, void 0, {
|
|
1560
1564
|
F: __dxlog_file5,
|
|
1561
|
-
L:
|
|
1565
|
+
L: 194,
|
|
1562
1566
|
S: this,
|
|
1563
1567
|
C: (f, a) => f(...a)
|
|
1564
1568
|
}));
|
|
1565
1569
|
}
|
|
1566
1570
|
} else {
|
|
1567
1571
|
log5("received peerLeft but no peer found", {
|
|
1568
|
-
peer: swarmEvent.peerLeft.peer
|
|
1572
|
+
peer: swarmEvent.peerLeft.peer.peerKey
|
|
1569
1573
|
}, {
|
|
1570
1574
|
F: __dxlog_file5,
|
|
1571
|
-
L:
|
|
1575
|
+
L: 197,
|
|
1572
1576
|
S: this,
|
|
1573
1577
|
C: (f, a) => f(...a)
|
|
1574
1578
|
});
|
|
@@ -1581,14 +1585,14 @@ var Swarm = class {
|
|
|
1581
1585
|
message
|
|
1582
1586
|
}, {
|
|
1583
1587
|
F: __dxlog_file5,
|
|
1584
|
-
L:
|
|
1588
|
+
L: 206,
|
|
1585
1589
|
S: this,
|
|
1586
1590
|
C: (f, a) => f(...a)
|
|
1587
1591
|
});
|
|
1588
1592
|
if (this._ctx.disposed) {
|
|
1589
1593
|
log5("ignored for disposed swarm", void 0, {
|
|
1590
1594
|
F: __dxlog_file5,
|
|
1591
|
-
L:
|
|
1595
|
+
L: 208,
|
|
1592
1596
|
S: this,
|
|
1593
1597
|
C: (f, a) => f(...a)
|
|
1594
1598
|
});
|
|
@@ -1598,19 +1602,19 @@ var Swarm = class {
|
|
|
1598
1602
|
}
|
|
1599
1603
|
invariant4(message.author, void 0, {
|
|
1600
1604
|
F: __dxlog_file5,
|
|
1601
|
-
L:
|
|
1605
|
+
L: 213,
|
|
1602
1606
|
S: this,
|
|
1603
1607
|
A: [
|
|
1604
1608
|
"message.author",
|
|
1605
1609
|
""
|
|
1606
1610
|
]
|
|
1607
1611
|
});
|
|
1608
|
-
if (
|
|
1612
|
+
if (message.recipient.peerKey !== this._ownPeer.peerKey) {
|
|
1609
1613
|
log5("rejecting offer with incorrect peerId", {
|
|
1610
1614
|
message
|
|
1611
1615
|
}, {
|
|
1612
1616
|
F: __dxlog_file5,
|
|
1613
|
-
L:
|
|
1617
|
+
L: 215,
|
|
1614
1618
|
S: this,
|
|
1615
1619
|
C: (f, a) => f(...a)
|
|
1616
1620
|
});
|
|
@@ -1623,7 +1627,7 @@ var Swarm = class {
|
|
|
1623
1627
|
message
|
|
1624
1628
|
}, {
|
|
1625
1629
|
F: __dxlog_file5,
|
|
1626
|
-
L:
|
|
1630
|
+
L: 219,
|
|
1627
1631
|
S: this,
|
|
1628
1632
|
C: (f, a) => f(...a)
|
|
1629
1633
|
});
|
|
@@ -1641,31 +1645,31 @@ var Swarm = class {
|
|
|
1641
1645
|
message
|
|
1642
1646
|
}, {
|
|
1643
1647
|
F: __dxlog_file5,
|
|
1644
|
-
L:
|
|
1648
|
+
L: 230,
|
|
1645
1649
|
S: this,
|
|
1646
1650
|
C: (f, a) => f(...a)
|
|
1647
1651
|
});
|
|
1648
1652
|
if (this._ctx.disposed) {
|
|
1649
1653
|
log5.info("ignored for offline swarm", void 0, {
|
|
1650
1654
|
F: __dxlog_file5,
|
|
1651
|
-
L:
|
|
1655
|
+
L: 232,
|
|
1652
1656
|
S: this,
|
|
1653
1657
|
C: (f, a) => f(...a)
|
|
1654
1658
|
});
|
|
1655
1659
|
return;
|
|
1656
1660
|
}
|
|
1657
|
-
invariant4(message.recipient
|
|
1661
|
+
invariant4(message.recipient.peerKey === this._ownPeer.peerKey, `Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`, {
|
|
1658
1662
|
F: __dxlog_file5,
|
|
1659
|
-
L:
|
|
1663
|
+
L: 235,
|
|
1660
1664
|
S: this,
|
|
1661
1665
|
A: [
|
|
1662
|
-
"message.recipient
|
|
1666
|
+
"message.recipient.peerKey === this._ownPeer.peerKey",
|
|
1663
1667
|
"`Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`"
|
|
1664
1668
|
]
|
|
1665
1669
|
});
|
|
1666
1670
|
invariant4(message.topic?.equals(this._topic), void 0, {
|
|
1667
1671
|
F: __dxlog_file5,
|
|
1668
|
-
L:
|
|
1672
|
+
L: 239,
|
|
1669
1673
|
S: this,
|
|
1670
1674
|
A: [
|
|
1671
1675
|
"message.topic?.equals(this._topic)",
|
|
@@ -1674,7 +1678,7 @@ var Swarm = class {
|
|
|
1674
1678
|
});
|
|
1675
1679
|
invariant4(message.author, void 0, {
|
|
1676
1680
|
F: __dxlog_file5,
|
|
1677
|
-
L:
|
|
1681
|
+
L: 240,
|
|
1678
1682
|
S: this,
|
|
1679
1683
|
A: [
|
|
1680
1684
|
"message.author",
|
|
@@ -1695,77 +1699,86 @@ var Swarm = class {
|
|
|
1695
1699
|
async goOnline() {
|
|
1696
1700
|
this._ctx = new Context4(void 0, {
|
|
1697
1701
|
F: __dxlog_file5,
|
|
1698
|
-
L:
|
|
1702
|
+
L: 256
|
|
1699
1703
|
});
|
|
1700
1704
|
}
|
|
1701
|
-
_getOrCreatePeer(
|
|
1702
|
-
|
|
1705
|
+
_getOrCreatePeer(peerInfo) {
|
|
1706
|
+
invariant4(peerInfo.peerKey, "PeerInfo.peerKey is required", {
|
|
1707
|
+
F: __dxlog_file5,
|
|
1708
|
+
L: 260,
|
|
1709
|
+
S: this,
|
|
1710
|
+
A: [
|
|
1711
|
+
"peerInfo.peerKey",
|
|
1712
|
+
"'PeerInfo.peerKey is required'"
|
|
1713
|
+
]
|
|
1714
|
+
});
|
|
1715
|
+
let peer = this._peers.get(peerInfo);
|
|
1703
1716
|
if (!peer) {
|
|
1704
|
-
peer = new Peer(
|
|
1717
|
+
peer = new Peer(peerInfo, this._topic, this._ownPeer, this._swarmMessenger, this._protocolProvider, this._transportFactory, this._connectionLimiter, {
|
|
1705
1718
|
onInitiated: (connection) => {
|
|
1706
1719
|
this.connectionAdded.emit(connection);
|
|
1707
1720
|
},
|
|
1708
1721
|
onConnected: () => {
|
|
1709
|
-
this.connected.emit(
|
|
1722
|
+
this.connected.emit(peerInfo);
|
|
1710
1723
|
},
|
|
1711
1724
|
onDisconnected: async () => {
|
|
1712
1725
|
if (this._isUnregistered(peer)) {
|
|
1713
1726
|
return;
|
|
1714
1727
|
}
|
|
1715
1728
|
if (!peer.advertizing) {
|
|
1716
|
-
await this._destroyPeer(
|
|
1729
|
+
await this._destroyPeer(peerInfo, "peer disconnected");
|
|
1717
1730
|
}
|
|
1718
|
-
this.disconnected.emit(
|
|
1731
|
+
this.disconnected.emit(peerInfo);
|
|
1719
1732
|
this._topology.update();
|
|
1720
1733
|
},
|
|
1721
1734
|
onRejected: () => {
|
|
1722
1735
|
if (!this._isUnregistered(peer)) {
|
|
1723
1736
|
log5("peer rejected connection", {
|
|
1724
|
-
|
|
1737
|
+
peerInfo
|
|
1725
1738
|
}, {
|
|
1726
1739
|
F: __dxlog_file5,
|
|
1727
|
-
L:
|
|
1740
|
+
L: 293,
|
|
1728
1741
|
S: this,
|
|
1729
1742
|
C: (f, a) => f(...a)
|
|
1730
1743
|
});
|
|
1731
|
-
void this._destroyPeer(
|
|
1744
|
+
void this._destroyPeer(peerInfo, "peer rejected connection");
|
|
1732
1745
|
}
|
|
1733
1746
|
},
|
|
1734
1747
|
onAccepted: () => {
|
|
1735
1748
|
this._topology.update();
|
|
1736
1749
|
},
|
|
1737
1750
|
onOffer: (remoteId) => {
|
|
1738
|
-
return this._topology.onOffer(remoteId);
|
|
1751
|
+
return this._topology.onOffer(PublicKey4.from(remoteId.peerKey));
|
|
1739
1752
|
},
|
|
1740
1753
|
onPeerAvailable: () => {
|
|
1741
1754
|
this._topology.update();
|
|
1742
1755
|
}
|
|
1743
1756
|
});
|
|
1744
|
-
this._peers.set(
|
|
1757
|
+
this._peers.set(peerInfo, peer);
|
|
1745
1758
|
}
|
|
1746
1759
|
return peer;
|
|
1747
1760
|
}
|
|
1748
|
-
async _destroyPeer(
|
|
1749
|
-
const peer = this._peers.get(
|
|
1761
|
+
async _destroyPeer(peerInfo, reason) {
|
|
1762
|
+
const peer = this._peers.get(peerInfo);
|
|
1750
1763
|
invariant4(peer, void 0, {
|
|
1751
1764
|
F: __dxlog_file5,
|
|
1752
|
-
L:
|
|
1765
|
+
L: 316,
|
|
1753
1766
|
S: this,
|
|
1754
1767
|
A: [
|
|
1755
1768
|
"peer",
|
|
1756
1769
|
""
|
|
1757
1770
|
]
|
|
1758
1771
|
});
|
|
1759
|
-
this._peers.delete(
|
|
1772
|
+
this._peers.delete(peerInfo);
|
|
1760
1773
|
await peer.safeDestroy(new Error(reason));
|
|
1761
1774
|
}
|
|
1762
1775
|
_getSwarmController() {
|
|
1763
1776
|
return {
|
|
1764
1777
|
getState: () => ({
|
|
1765
|
-
ownPeerId: this.
|
|
1766
|
-
connected: Array.from(this._peers.
|
|
1767
|
-
candidates: Array.from(this._peers.
|
|
1768
|
-
allPeers: Array.from(this._peers.
|
|
1778
|
+
ownPeerId: PublicKey4.from(this._ownPeer.peerKey),
|
|
1779
|
+
connected: Array.from(this._peers.entries()).filter(([_, peer]) => peer.connection).map(([info]) => PublicKey4.from(info.peerKey)),
|
|
1780
|
+
candidates: Array.from(this._peers.entries()).filter(([_, peer]) => !peer.connection && peer.advertizing && peer.availableToConnect).map(([info]) => PublicKey4.from(info.peerKey)),
|
|
1781
|
+
allPeers: Array.from(this._peers.keys()).map((info) => PublicKey4.from(info.peerKey))
|
|
1769
1782
|
}),
|
|
1770
1783
|
connect: (peer) => {
|
|
1771
1784
|
if (this._ctx.disposed) {
|
|
@@ -1773,11 +1786,13 @@ var Swarm = class {
|
|
|
1773
1786
|
}
|
|
1774
1787
|
scheduleTask3(this._ctx, async () => {
|
|
1775
1788
|
try {
|
|
1776
|
-
await this._initiateConnection(
|
|
1789
|
+
await this._initiateConnection({
|
|
1790
|
+
peerKey: peer.toHex()
|
|
1791
|
+
});
|
|
1777
1792
|
} catch (err) {
|
|
1778
1793
|
log5("initiation error", err, {
|
|
1779
1794
|
F: __dxlog_file5,
|
|
1780
|
-
L:
|
|
1795
|
+
L: 343,
|
|
1781
1796
|
S: this,
|
|
1782
1797
|
C: (f, a) => f(...a)
|
|
1783
1798
|
});
|
|
@@ -1789,7 +1804,9 @@ var Swarm = class {
|
|
|
1789
1804
|
return;
|
|
1790
1805
|
}
|
|
1791
1806
|
scheduleTask3(this._ctx, async () => {
|
|
1792
|
-
await this._closeConnection(
|
|
1807
|
+
await this._closeConnection({
|
|
1808
|
+
peerKey: peer.toHex()
|
|
1809
|
+
});
|
|
1793
1810
|
this._topology.update();
|
|
1794
1811
|
});
|
|
1795
1812
|
}
|
|
@@ -1798,15 +1815,15 @@ var Swarm = class {
|
|
|
1798
1815
|
/**
|
|
1799
1816
|
* Creates a connection then sends message over signal network.
|
|
1800
1817
|
*/
|
|
1801
|
-
async _initiateConnection(
|
|
1818
|
+
async _initiateConnection(remotePeer) {
|
|
1802
1819
|
const ctx = this._ctx;
|
|
1803
|
-
const peer = this._getOrCreatePeer(
|
|
1804
|
-
if (
|
|
1820
|
+
const peer = this._getOrCreatePeer(remotePeer);
|
|
1821
|
+
if (remotePeer.peerKey < this._ownPeer.peerKey) {
|
|
1805
1822
|
log5("initiation delay", {
|
|
1806
|
-
|
|
1823
|
+
remotePeer
|
|
1807
1824
|
}, {
|
|
1808
1825
|
F: __dxlog_file5,
|
|
1809
|
-
L:
|
|
1826
|
+
L: 371,
|
|
1810
1827
|
S: this,
|
|
1811
1828
|
C: (f, a) => f(...a)
|
|
1812
1829
|
});
|
|
@@ -1822,33 +1839,33 @@ var Swarm = class {
|
|
|
1822
1839
|
return;
|
|
1823
1840
|
}
|
|
1824
1841
|
log5("initiating connection...", {
|
|
1825
|
-
|
|
1842
|
+
remotePeer
|
|
1826
1843
|
}, {
|
|
1827
1844
|
F: __dxlog_file5,
|
|
1828
|
-
L:
|
|
1845
|
+
L: 387,
|
|
1829
1846
|
S: this,
|
|
1830
1847
|
C: (f, a) => f(...a)
|
|
1831
1848
|
});
|
|
1832
1849
|
await peer.initiateConnection();
|
|
1833
1850
|
this._topology.update();
|
|
1834
1851
|
log5("initiated", {
|
|
1835
|
-
|
|
1852
|
+
remotePeer
|
|
1836
1853
|
}, {
|
|
1837
1854
|
F: __dxlog_file5,
|
|
1838
|
-
L:
|
|
1855
|
+
L: 390,
|
|
1839
1856
|
S: this,
|
|
1840
1857
|
C: (f, a) => f(...a)
|
|
1841
1858
|
});
|
|
1842
1859
|
}
|
|
1843
|
-
async _closeConnection(
|
|
1844
|
-
const peer = this._peers.get(
|
|
1860
|
+
async _closeConnection(peerInfo) {
|
|
1861
|
+
const peer = this._peers.get(peerInfo);
|
|
1845
1862
|
if (!peer) {
|
|
1846
1863
|
return;
|
|
1847
1864
|
}
|
|
1848
1865
|
await peer.closeConnection();
|
|
1849
1866
|
}
|
|
1850
1867
|
_isUnregistered(peer) {
|
|
1851
|
-
return !peer || this._peers.get(peer.
|
|
1868
|
+
return !peer || this._peers.get(peer.remoteInfo) !== peer;
|
|
1852
1869
|
}
|
|
1853
1870
|
};
|
|
1854
1871
|
_ts_decorate3([
|
|
@@ -1856,7 +1873,7 @@ _ts_decorate3([
|
|
|
1856
1873
|
], Swarm.prototype, "_instanceId", void 0);
|
|
1857
1874
|
_ts_decorate3([
|
|
1858
1875
|
logInfo2
|
|
1859
|
-
], Swarm.prototype, "
|
|
1876
|
+
], Swarm.prototype, "ownPeer", null);
|
|
1860
1877
|
_ts_decorate3([
|
|
1861
1878
|
logInfo2
|
|
1862
1879
|
], Swarm.prototype, "topic", null);
|
|
@@ -1877,6 +1894,7 @@ _ts_decorate3([
|
|
|
1877
1894
|
import { Event as Event4, EventSubscriptions } from "@dxos/async";
|
|
1878
1895
|
import { PublicKey as PublicKey5 } from "@dxos/keys";
|
|
1879
1896
|
import { log as log6 } from "@dxos/log";
|
|
1897
|
+
import { PeerInfoHash as PeerInfoHash2 } from "@dxos/messaging";
|
|
1880
1898
|
import { ComplexMap as ComplexMap3 } from "@dxos/util";
|
|
1881
1899
|
var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
|
|
1882
1900
|
var SwarmMapper = class {
|
|
@@ -1886,12 +1904,12 @@ var SwarmMapper = class {
|
|
|
1886
1904
|
constructor(_swarm) {
|
|
1887
1905
|
this._swarm = _swarm;
|
|
1888
1906
|
this._subscriptions = new EventSubscriptions();
|
|
1889
|
-
this._connectionSubscriptions = new ComplexMap3(
|
|
1890
|
-
this._peers = new ComplexMap3(
|
|
1907
|
+
this._connectionSubscriptions = new ComplexMap3(PeerInfoHash2);
|
|
1908
|
+
this._peers = new ComplexMap3(PeerInfoHash2);
|
|
1891
1909
|
this.mapUpdated = new Event4();
|
|
1892
1910
|
this._subscriptions.add(_swarm.connectionAdded.on((connection) => {
|
|
1893
1911
|
this._update();
|
|
1894
|
-
this._connectionSubscriptions.set(connection.
|
|
1912
|
+
this._connectionSubscriptions.set(connection.remoteInfo, connection.stateChanged.on(() => {
|
|
1895
1913
|
this._update();
|
|
1896
1914
|
}));
|
|
1897
1915
|
}));
|
|
@@ -1905,19 +1923,19 @@ var SwarmMapper = class {
|
|
|
1905
1923
|
_update() {
|
|
1906
1924
|
log6("updating swarm", void 0, {
|
|
1907
1925
|
F: __dxlog_file6,
|
|
1908
|
-
L:
|
|
1926
|
+
L: 73,
|
|
1909
1927
|
S: this,
|
|
1910
1928
|
C: (f, a) => f(...a)
|
|
1911
1929
|
});
|
|
1912
1930
|
this._peers.clear();
|
|
1913
|
-
this._peers.set(this._swarm.
|
|
1931
|
+
this._peers.set(this._swarm.ownPeer, {
|
|
1914
1932
|
id: this._swarm.ownPeerId,
|
|
1915
1933
|
state: "ME",
|
|
1916
1934
|
connections: []
|
|
1917
1935
|
});
|
|
1918
1936
|
for (const connection of this._swarm.connections) {
|
|
1919
|
-
this._peers.set(connection.
|
|
1920
|
-
id: connection.
|
|
1937
|
+
this._peers.set(connection.remoteInfo, {
|
|
1938
|
+
id: PublicKey5.from(connection.remoteInfo.peerKey),
|
|
1921
1939
|
state: connection.state,
|
|
1922
1940
|
connections: [
|
|
1923
1941
|
this._swarm.ownPeerId
|
|
@@ -1929,7 +1947,7 @@ var SwarmMapper = class {
|
|
|
1929
1947
|
totalPeersInSwarm: this._peers.size
|
|
1930
1948
|
}, {
|
|
1931
1949
|
F: __dxlog_file6,
|
|
1932
|
-
L:
|
|
1950
|
+
L: 114,
|
|
1933
1951
|
S: this,
|
|
1934
1952
|
C: (f, a) => f(...a)
|
|
1935
1953
|
});
|
|
@@ -2069,7 +2087,7 @@ var ConnectionLog = class {
|
|
|
2069
2087
|
const connectionInfo = {
|
|
2070
2088
|
state: ConnectionState.CREATED,
|
|
2071
2089
|
closeReason: connection.closeReason,
|
|
2072
|
-
remotePeerId: connection.
|
|
2090
|
+
remotePeerId: PublicKey7.from(connection.remoteInfo.peerKey),
|
|
2073
2091
|
sessionId: connection.sessionId,
|
|
2074
2092
|
transport: connection.transport && Object.getPrototypeOf(connection.transport).constructor.name,
|
|
2075
2093
|
protocolExtensions: [],
|
|
@@ -2140,19 +2158,20 @@ function _ts_decorate4(decorators, target, key, desc) {
|
|
|
2140
2158
|
}
|
|
2141
2159
|
var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts";
|
|
2142
2160
|
var SwarmNetworkManager = class {
|
|
2143
|
-
constructor({ transportFactory, signalManager,
|
|
2161
|
+
constructor({ transportFactory, signalManager, enableDevtoolsLogging, peerInfo }) {
|
|
2144
2162
|
/**
|
|
2145
2163
|
* @internal
|
|
2146
2164
|
*/
|
|
2147
2165
|
this._swarms = new ComplexMap6(PublicKey8.hash);
|
|
2148
2166
|
this._mappers = new ComplexMap6(PublicKey8.hash);
|
|
2149
2167
|
this._instanceId = PublicKey8.random().toHex();
|
|
2168
|
+
this._peerInfo = void 0;
|
|
2150
2169
|
this._connectionState = ConnectionState2.ONLINE;
|
|
2151
2170
|
this.connectionStateChanged = new Event6();
|
|
2152
2171
|
this.topicsUpdated = new Event6();
|
|
2153
2172
|
this._transportFactory = transportFactory;
|
|
2154
2173
|
this._signalManager = signalManager;
|
|
2155
|
-
this._signalManager.swarmEvent.on((
|
|
2174
|
+
this._signalManager.swarmEvent.on((event) => this._swarms.get(event.topic)?.onSwarmEvent(event));
|
|
2156
2175
|
this._messenger = new Messenger({
|
|
2157
2176
|
signalManager: this._signalManager
|
|
2158
2177
|
});
|
|
@@ -2160,8 +2179,9 @@ var SwarmNetworkManager = class {
|
|
|
2160
2179
|
join: (opts) => this._signalManager.join(opts),
|
|
2161
2180
|
leave: (opts) => this._signalManager.leave(opts)
|
|
2162
2181
|
};
|
|
2182
|
+
this._peerInfo = peerInfo;
|
|
2163
2183
|
this._connectionLimiter = new ConnectionLimiter();
|
|
2164
|
-
if (
|
|
2184
|
+
if (enableDevtoolsLogging) {
|
|
2165
2185
|
this._connectionLog = new ConnectionLog();
|
|
2166
2186
|
}
|
|
2167
2187
|
}
|
|
@@ -2182,12 +2202,15 @@ var SwarmNetworkManager = class {
|
|
|
2182
2202
|
getSwarm(topic) {
|
|
2183
2203
|
return this._swarms.get(topic);
|
|
2184
2204
|
}
|
|
2205
|
+
setPeerInfo(peerInfo) {
|
|
2206
|
+
this._peerInfo = peerInfo;
|
|
2207
|
+
}
|
|
2185
2208
|
async open() {
|
|
2186
2209
|
log8.trace("dxos.mesh.network-manager.open", trace3.begin({
|
|
2187
2210
|
id: this._instanceId
|
|
2188
2211
|
}), {
|
|
2189
2212
|
F: __dxlog_file8,
|
|
2190
|
-
L:
|
|
2213
|
+
L: 133,
|
|
2191
2214
|
S: this,
|
|
2192
2215
|
C: (f, a) => f(...a)
|
|
2193
2216
|
});
|
|
@@ -2197,7 +2220,7 @@ var SwarmNetworkManager = class {
|
|
|
2197
2220
|
id: this._instanceId
|
|
2198
2221
|
}), {
|
|
2199
2222
|
F: __dxlog_file8,
|
|
2200
|
-
L:
|
|
2223
|
+
L: 136,
|
|
2201
2224
|
S: this,
|
|
2202
2225
|
C: (f, a) => f(...a)
|
|
2203
2226
|
});
|
|
@@ -2207,7 +2230,7 @@ var SwarmNetworkManager = class {
|
|
|
2207
2230
|
await this.leaveSwarm(topic).catch((err) => {
|
|
2208
2231
|
log8(err, void 0, {
|
|
2209
2232
|
F: __dxlog_file8,
|
|
2210
|
-
L:
|
|
2233
|
+
L: 142,
|
|
2211
2234
|
S: this,
|
|
2212
2235
|
C: (f, a) => f(...a)
|
|
2213
2236
|
});
|
|
@@ -2219,28 +2242,43 @@ var SwarmNetworkManager = class {
|
|
|
2219
2242
|
/**
|
|
2220
2243
|
* Join the swarm.
|
|
2221
2244
|
*/
|
|
2222
|
-
async joinSwarm({ topic,
|
|
2245
|
+
async joinSwarm({ topic, peerInfo, topology, protocolProvider: protocol, label }) {
|
|
2223
2246
|
invariant6(PublicKey8.isPublicKey(topic), void 0, {
|
|
2224
2247
|
F: __dxlog_file8,
|
|
2225
|
-
L:
|
|
2248
|
+
L: 161,
|
|
2226
2249
|
S: this,
|
|
2227
2250
|
A: [
|
|
2228
2251
|
"PublicKey.isPublicKey(topic)",
|
|
2229
2252
|
""
|
|
2230
2253
|
]
|
|
2231
2254
|
});
|
|
2232
|
-
|
|
2255
|
+
if (!peerInfo) {
|
|
2256
|
+
peerInfo = {
|
|
2257
|
+
peerKey: this._peerInfo?.peerKey ?? PublicKey8.random().toHex(),
|
|
2258
|
+
identityKey: this._peerInfo?.identityKey ?? PublicKey8.random().toHex()
|
|
2259
|
+
};
|
|
2260
|
+
}
|
|
2261
|
+
invariant6(PublicKey8.from(peerInfo.peerKey), void 0, {
|
|
2233
2262
|
F: __dxlog_file8,
|
|
2234
|
-
L:
|
|
2263
|
+
L: 168,
|
|
2235
2264
|
S: this,
|
|
2236
2265
|
A: [
|
|
2237
|
-
"PublicKey.
|
|
2266
|
+
"PublicKey.from(peerInfo.peerKey)",
|
|
2267
|
+
""
|
|
2268
|
+
]
|
|
2269
|
+
});
|
|
2270
|
+
invariant6(PublicKey8.from(peerInfo.identityKey), void 0, {
|
|
2271
|
+
F: __dxlog_file8,
|
|
2272
|
+
L: 169,
|
|
2273
|
+
S: this,
|
|
2274
|
+
A: [
|
|
2275
|
+
"PublicKey.from(peerInfo.identityKey!)",
|
|
2238
2276
|
""
|
|
2239
2277
|
]
|
|
2240
2278
|
});
|
|
2241
2279
|
invariant6(topology, void 0, {
|
|
2242
2280
|
F: __dxlog_file8,
|
|
2243
|
-
L:
|
|
2281
|
+
L: 170,
|
|
2244
2282
|
S: this,
|
|
2245
2283
|
A: [
|
|
2246
2284
|
"topology",
|
|
@@ -2249,7 +2287,7 @@ var SwarmNetworkManager = class {
|
|
|
2249
2287
|
});
|
|
2250
2288
|
invariant6(typeof protocol === "function", void 0, {
|
|
2251
2289
|
F: __dxlog_file8,
|
|
2252
|
-
L:
|
|
2290
|
+
L: 171,
|
|
2253
2291
|
S: this,
|
|
2254
2292
|
A: [
|
|
2255
2293
|
"typeof protocol === 'function'",
|
|
@@ -2261,21 +2299,21 @@ var SwarmNetworkManager = class {
|
|
|
2261
2299
|
}
|
|
2262
2300
|
log8("joining", {
|
|
2263
2301
|
topic: PublicKey8.from(topic),
|
|
2264
|
-
|
|
2302
|
+
peerInfo,
|
|
2265
2303
|
topology: topology.toString()
|
|
2266
2304
|
}, {
|
|
2267
2305
|
F: __dxlog_file8,
|
|
2268
|
-
L:
|
|
2306
|
+
L: 176,
|
|
2269
2307
|
S: this,
|
|
2270
2308
|
C: (f, a) => f(...a)
|
|
2271
2309
|
});
|
|
2272
|
-
const swarm = new Swarm(topic,
|
|
2310
|
+
const swarm = new Swarm(topic, peerInfo, topology, protocol, this._messenger, this._transportFactory, label, this._connectionLimiter);
|
|
2273
2311
|
swarm.errors.handle((error) => {
|
|
2274
2312
|
log8("swarm error", {
|
|
2275
2313
|
error
|
|
2276
2314
|
}, {
|
|
2277
2315
|
F: __dxlog_file8,
|
|
2278
|
-
L:
|
|
2316
|
+
L: 189,
|
|
2279
2317
|
S: this,
|
|
2280
2318
|
C: (f, a) => f(...a)
|
|
2281
2319
|
});
|
|
@@ -2285,10 +2323,10 @@ var SwarmNetworkManager = class {
|
|
|
2285
2323
|
await swarm.open();
|
|
2286
2324
|
this._signalConnection.join({
|
|
2287
2325
|
topic,
|
|
2288
|
-
|
|
2326
|
+
peer: peerInfo
|
|
2289
2327
|
}).catch((error) => log8.catch(error, void 0, {
|
|
2290
2328
|
F: __dxlog_file8,
|
|
2291
|
-
L:
|
|
2329
|
+
L: 198,
|
|
2292
2330
|
S: this,
|
|
2293
2331
|
C: (f, a) => f(...a)
|
|
2294
2332
|
}));
|
|
@@ -2299,7 +2337,7 @@ var SwarmNetworkManager = class {
|
|
|
2299
2337
|
count: this._swarms.size
|
|
2300
2338
|
}, {
|
|
2301
2339
|
F: __dxlog_file8,
|
|
2302
|
-
L:
|
|
2340
|
+
L: 202,
|
|
2303
2341
|
S: this,
|
|
2304
2342
|
C: (f, a) => f(...a)
|
|
2305
2343
|
});
|
|
@@ -2318,14 +2356,14 @@ var SwarmNetworkManager = class {
|
|
|
2318
2356
|
topic: PublicKey8.from(topic)
|
|
2319
2357
|
}, {
|
|
2320
2358
|
F: __dxlog_file8,
|
|
2321
|
-
L:
|
|
2359
|
+
L: 219,
|
|
2322
2360
|
S: this,
|
|
2323
2361
|
C: (f, a) => f(...a)
|
|
2324
2362
|
});
|
|
2325
2363
|
const swarm = this._swarms.get(topic);
|
|
2326
2364
|
await this._signalConnection.leave({
|
|
2327
2365
|
topic,
|
|
2328
|
-
|
|
2366
|
+
peer: swarm.ownPeer
|
|
2329
2367
|
});
|
|
2330
2368
|
const map = this._mappers.get(topic);
|
|
2331
2369
|
map.destroy();
|
|
@@ -2339,7 +2377,7 @@ var SwarmNetworkManager = class {
|
|
|
2339
2377
|
count: this._swarms.size
|
|
2340
2378
|
}, {
|
|
2341
2379
|
F: __dxlog_file8,
|
|
2342
|
-
L:
|
|
2380
|
+
L: 233,
|
|
2343
2381
|
S: this,
|
|
2344
2382
|
C: (f, a) => f(...a)
|
|
2345
2383
|
});
|
|
@@ -4146,4 +4184,4 @@ export {
|
|
|
4146
4184
|
TcpTransport,
|
|
4147
4185
|
createTeleportProtocolFactory
|
|
4148
4186
|
};
|
|
4149
|
-
//# sourceMappingURL=chunk-
|
|
4187
|
+
//# sourceMappingURL=chunk-ZQ4OU7JZ.mjs.map
|