@qvac/core 0.7.5 → 0.8.0
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/CHANGELOG.md +79 -1
- package/dist-lib/lib/assistant/skill-encode.d.ts +1 -0
- package/dist-lib/lib/assistant/skill-encode.js +1 -0
- package/dist-lib/lib/core/blind-peers.d.ts +0 -3
- package/dist-lib/lib/core/chunk.d.ts +4 -0
- package/dist-lib/lib/core/contract/seed-defaults.js +2 -2
- package/dist-lib/lib/core/contract/writers.js +1 -1
- package/dist-lib/lib/core/departures.d.ts +5 -7
- package/dist-lib/lib/core/departures.js +14 -12
- package/dist-lib/lib/core/files/records/reclaim.js +1 -1
- package/dist-lib/lib/core/fs-drives.d.ts +2 -6
- package/dist-lib/lib/core/fs-drives.js +7 -30
- package/dist-lib/lib/core/mesh.d.ts +20 -7
- package/dist-lib/lib/core/mesh.js +205 -39
- package/dist-lib/lib/core/sync/index.d.ts +1 -0
- package/dist-lib/lib/core/sync/index.js +136 -67
- package/dist-lib/lib/core.d.ts +5 -10
- package/dist-lib/lib/core.js +156 -156
- package/dist-lib/schema/engine.js +5 -2
- package/dist-lib/spec/hrpc/messages.js +22 -6
- package/dist-lib/spec/hyperschema/index.js +22 -6
- package/dist-lib/spec/hyperschema/schema.json +15 -0
- package/dist-lib/spec/hyperschema/types.d.ts +3 -0
- package/package.json +1 -1
- package/tui/README.md +17 -13
- package/tui/app.mjs +234 -52
- package/tui/main.mjs +10 -3
package/dist-lib/lib/core.js
CHANGED
|
@@ -110,12 +110,12 @@ export class Core extends ReadyResource {
|
|
|
110
110
|
_minSupportedVersion;
|
|
111
111
|
_otaConfigCore;
|
|
112
112
|
_otaConfig = null;
|
|
113
|
-
|
|
113
|
+
_blindPeering = null;
|
|
114
|
+
_configPeered = false;
|
|
114
115
|
_blindPeeringOn = true;
|
|
115
116
|
_blindPeeringListeners = new Set();
|
|
116
117
|
_recoveryCore = null;
|
|
117
118
|
_recoverySigner = null;
|
|
118
|
-
_recoveryPeering = null;
|
|
119
119
|
_localDevice;
|
|
120
120
|
_blindPeerKeys;
|
|
121
121
|
_blindPeeringOpts;
|
|
@@ -176,9 +176,6 @@ export class Core extends ReadyResource {
|
|
|
176
176
|
_identityPhrase = null;
|
|
177
177
|
_identityPublicKey = null;
|
|
178
178
|
_swarm;
|
|
179
|
-
_siblings = new Map();
|
|
180
|
-
_seenPeers = new Set();
|
|
181
|
-
_siblingLock = new ScopeLock({ debounce: true });
|
|
182
179
|
_onSwarmConnection;
|
|
183
180
|
_departures = null;
|
|
184
181
|
_fsDrives = null;
|
|
@@ -386,15 +383,13 @@ export class Core extends ReadyResource {
|
|
|
386
383
|
deviceId: () => this._deviceKeyPair?.publicKey ?? null,
|
|
387
384
|
logger: this._log,
|
|
388
385
|
blindPeerKeys: this._resolveBlindPeerKeys(),
|
|
389
|
-
|
|
390
|
-
blindPeering: this._blindPeeringOn,
|
|
386
|
+
blindPeering: () => this._blindPeeringClient(),
|
|
391
387
|
wakeup: this._wakeup
|
|
392
388
|
});
|
|
393
389
|
this._fsDrives = createFsDriveHost(this.store, {
|
|
394
390
|
swarm,
|
|
395
391
|
blindPeerKeys: this._resolveBlindPeerKeys(),
|
|
396
|
-
|
|
397
|
-
blindPeering: this._blindPeeringOn
|
|
392
|
+
blindPeering: () => this._blindPeeringClient()
|
|
398
393
|
});
|
|
399
394
|
void sweepDriveStaging();
|
|
400
395
|
this._blobServer = new CoreBlobServer(this.store, (coreKey, blockOffset, meshKey) => this._meshForBlobCore(coreKey, blockOffset, meshKey), { onRead: (mesh, coreKey, blockOffset) => this._servedFile(mesh, coreKey, blockOffset) });
|
|
@@ -721,32 +716,33 @@ export class Core extends ReadyResource {
|
|
|
721
716
|
}
|
|
722
717
|
_peerConfigCore() {
|
|
723
718
|
const config = this._otaConfig;
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
this._configPeering ||
|
|
727
|
-
this._accountMesh() ||
|
|
728
|
-
!this._swarm) {
|
|
719
|
+
const peering = this._blindPeeringClient();
|
|
720
|
+
if (!config || !peering || this._configPeered) {
|
|
729
721
|
return;
|
|
730
722
|
}
|
|
731
723
|
const keys = this._resolveBlindPeerKeys();
|
|
732
724
|
if (keys.length === 0) {
|
|
733
725
|
return;
|
|
734
726
|
}
|
|
735
|
-
this.
|
|
736
|
-
|
|
727
|
+
this._configPeered = true;
|
|
728
|
+
peering.addCoreBackground(config.core, { keys, pick: keys.length });
|
|
729
|
+
this._log?.info(['p2p', 'config'], 'blind peering the config core');
|
|
730
|
+
}
|
|
731
|
+
_blindPeeringClient() {
|
|
732
|
+
if (!this._swarm || !this._blindPeeringOn || this.closing) {
|
|
733
|
+
return null;
|
|
734
|
+
}
|
|
735
|
+
if (this._blindPeering) {
|
|
736
|
+
return this._blindPeering;
|
|
737
|
+
}
|
|
738
|
+
const peering = new BlindPeering(this._swarm.dht, this.store, {
|
|
739
|
+
pick: 2,
|
|
737
740
|
suspended: this.suspended,
|
|
741
|
+
wakeup: this._wakeup,
|
|
738
742
|
...this._blindPeeringOpts
|
|
739
743
|
});
|
|
740
|
-
this.
|
|
741
|
-
|
|
742
|
-
}
|
|
743
|
-
async _closeConfigPeering() {
|
|
744
|
-
const peering = this._configPeering;
|
|
745
|
-
if (!peering) {
|
|
746
|
-
return;
|
|
747
|
-
}
|
|
748
|
-
this._configPeering = null;
|
|
749
|
-
await peering.close();
|
|
744
|
+
this._blindPeering = peering;
|
|
745
|
+
return peering;
|
|
750
746
|
}
|
|
751
747
|
async _closeOtaConfig() {
|
|
752
748
|
const config = this._otaConfig;
|
|
@@ -857,13 +853,7 @@ export class Core extends ReadyResource {
|
|
|
857
853
|
if (this._departures) {
|
|
858
854
|
await this._departures.suspend();
|
|
859
855
|
}
|
|
860
|
-
|
|
861
|
-
await this._configPeering.suspend();
|
|
862
|
-
}
|
|
863
|
-
if (this._recoveryPeering) {
|
|
864
|
-
await this._recoveryPeering.suspend();
|
|
865
|
-
}
|
|
866
|
-
await this._fsDrives?.suspend();
|
|
856
|
+
await this._blindPeering?.suspend();
|
|
867
857
|
if (this._swarm && this._ownsSwarm) {
|
|
868
858
|
await this._swarm.suspend();
|
|
869
859
|
}
|
|
@@ -899,13 +889,7 @@ export class Core extends ReadyResource {
|
|
|
899
889
|
if (this._swarm && this._ownsSwarm) {
|
|
900
890
|
await this._swarm.resume();
|
|
901
891
|
}
|
|
902
|
-
|
|
903
|
-
await this._configPeering.resume();
|
|
904
|
-
}
|
|
905
|
-
if (this._recoveryPeering) {
|
|
906
|
-
await this._recoveryPeering.resume();
|
|
907
|
-
}
|
|
908
|
-
await this._fsDrives?.resume();
|
|
892
|
+
await this._blindPeering?.resume();
|
|
909
893
|
for (const { mesh } of this._meshes.values()) {
|
|
910
894
|
await mesh.resume();
|
|
911
895
|
}
|
|
@@ -919,11 +903,6 @@ export class Core extends ReadyResource {
|
|
|
919
903
|
}
|
|
920
904
|
this._startFileGc();
|
|
921
905
|
if (this._swarm) {
|
|
922
|
-
for (const [id, key] of this._siblings) {
|
|
923
|
-
if (this._seenPeers.has(id)) {
|
|
924
|
-
this._swarm.joinPeer(key);
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
906
|
void this._refreshTopics(this._swarm).catch(noop);
|
|
928
907
|
}
|
|
929
908
|
void this._pushIdentityPhrase();
|
|
@@ -938,8 +917,7 @@ export class Core extends ReadyResource {
|
|
|
938
917
|
}
|
|
939
918
|
this._log?.info(['p2p', 'swarm'], 'topics refreshed after resume', {
|
|
940
919
|
topics,
|
|
941
|
-
peers: this.peerDeviceIds.length
|
|
942
|
-
siblings: this._siblings.size
|
|
920
|
+
peers: this.peerDeviceIds.length
|
|
943
921
|
});
|
|
944
922
|
}
|
|
945
923
|
_joinedTopics(swarm) {
|
|
@@ -991,7 +969,7 @@ export class Core extends ReadyResource {
|
|
|
991
969
|
await this._departures?.close();
|
|
992
970
|
this._departures = null;
|
|
993
971
|
await this._closeRecovery();
|
|
994
|
-
await this.
|
|
972
|
+
await this._closeBlindPeering();
|
|
995
973
|
await this._closeOtaConfig();
|
|
996
974
|
await this._fsDrives?.close();
|
|
997
975
|
this._fsDrives = null;
|
|
@@ -1086,7 +1064,7 @@ export class Core extends ReadyResource {
|
|
|
1086
1064
|
writerSeed: session.writerSeed,
|
|
1087
1065
|
logger: this._log,
|
|
1088
1066
|
blindPeerKeys: this._resolveBlindPeerKeys(blindPeerKeys),
|
|
1089
|
-
|
|
1067
|
+
trustedDevice: (deviceId) => this._isOurMemberDevice(deviceId),
|
|
1090
1068
|
wakeup: this._wakeup,
|
|
1091
1069
|
attachmentUrl: (attachment) => this._linkAttachment(attachment, mesh),
|
|
1092
1070
|
fileIndex: this._fileIndexFor(() => mesh)
|
|
@@ -1366,23 +1344,23 @@ export class Core extends ReadyResource {
|
|
|
1366
1344
|
if (keys.length === 0) {
|
|
1367
1345
|
return;
|
|
1368
1346
|
}
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
suspended: this.suspended,
|
|
1373
|
-
...this._blindPeeringOpts
|
|
1374
|
-
});
|
|
1347
|
+
const peering = this._blindPeeringClient();
|
|
1348
|
+
if (!peering) {
|
|
1349
|
+
return;
|
|
1375
1350
|
}
|
|
1376
|
-
|
|
1351
|
+
peering.addCoreBackground(core, { keys, pick: keys.length });
|
|
1377
1352
|
this._log?.info(['p2p', 'mesh'], 'blind peering an account recovery core');
|
|
1378
1353
|
}
|
|
1354
|
+
async _closeBlindPeering() {
|
|
1355
|
+
const peering = this._blindPeering;
|
|
1356
|
+
this._blindPeering = null;
|
|
1357
|
+
this._configPeered = false;
|
|
1358
|
+
await peering?.close();
|
|
1359
|
+
}
|
|
1379
1360
|
async _closeRecovery() {
|
|
1380
|
-
const peering = this._recoveryPeering;
|
|
1381
1361
|
const core = this._recoveryCore;
|
|
1382
|
-
this._recoveryPeering = null;
|
|
1383
1362
|
this._recoveryCore = null;
|
|
1384
1363
|
this._recoverySigner = null;
|
|
1385
|
-
await peering?.close();
|
|
1386
1364
|
await core?.close();
|
|
1387
1365
|
}
|
|
1388
1366
|
async _joinBirthMember(mesh, deviceId) {
|
|
@@ -1478,8 +1456,9 @@ export class Core extends ReadyResource {
|
|
|
1478
1456
|
}
|
|
1479
1457
|
}
|
|
1480
1458
|
_startBlindPeering(mesh) {
|
|
1481
|
-
|
|
1482
|
-
|
|
1459
|
+
const peering = this._blindPeeringClient();
|
|
1460
|
+
if (peering) {
|
|
1461
|
+
mesh.startBlindPeering(peering);
|
|
1483
1462
|
}
|
|
1484
1463
|
}
|
|
1485
1464
|
async setBlindPeering(enabled) {
|
|
@@ -1499,28 +1478,25 @@ export class Core extends ReadyResource {
|
|
|
1499
1478
|
return this._candidateMesh ? [...meshes, this._candidateMesh] : meshes;
|
|
1500
1479
|
}
|
|
1501
1480
|
async _stopBlindPeering() {
|
|
1502
|
-
const
|
|
1503
|
-
this.
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1481
|
+
const peering = this._blindPeering;
|
|
1482
|
+
this._blindPeering = null;
|
|
1483
|
+
this._configPeered = false;
|
|
1484
|
+
for (const mesh of this._peeredMeshes()) {
|
|
1485
|
+
mesh.stopBlindPeering();
|
|
1486
|
+
}
|
|
1487
|
+
this._departures?.stopBlindPeering();
|
|
1488
|
+
await peering?.close();
|
|
1489
|
+
this._notifyStatus();
|
|
1511
1490
|
}
|
|
1512
1491
|
async _resumeBlindPeering() {
|
|
1513
|
-
const
|
|
1514
|
-
|
|
1515
|
-
for (const mesh of this._peeredMeshes()) {
|
|
1516
|
-
mesh.startBlindPeering(this._swarm.dht, { suspended });
|
|
1517
|
-
}
|
|
1492
|
+
for (const mesh of this._peeredMeshes()) {
|
|
1493
|
+
this._startBlindPeering(mesh);
|
|
1518
1494
|
}
|
|
1519
1495
|
this._peerConfigCore();
|
|
1520
1496
|
if (this._recoveryCore) {
|
|
1521
1497
|
this._peerRecoveryCore(this._recoveryCore);
|
|
1522
1498
|
}
|
|
1523
|
-
this._departures?.startBlindPeering(
|
|
1499
|
+
this._departures?.startBlindPeering();
|
|
1524
1500
|
await this._fsDrives?.startBlindPeering();
|
|
1525
1501
|
}
|
|
1526
1502
|
_bringMeshOnline(mesh, opts = {}) {
|
|
@@ -1532,8 +1508,11 @@ export class Core extends ReadyResource {
|
|
|
1532
1508
|
if (this.suspended) {
|
|
1533
1509
|
void mesh.suspend().catch(noop);
|
|
1534
1510
|
}
|
|
1535
|
-
this._log?.info(['p2p', 'swarm'], 'announced and peering the mesh'
|
|
1536
|
-
|
|
1511
|
+
this._log?.info(['p2p', 'swarm'], 'announced and peering the mesh', {
|
|
1512
|
+
mesh: b4a.toHex(mesh.key).slice(0, 8),
|
|
1513
|
+
account: this._isAccount(mesh),
|
|
1514
|
+
blindPeers: mesh.blindPeerKeys.length
|
|
1515
|
+
});
|
|
1537
1516
|
}
|
|
1538
1517
|
if (!opts.new) {
|
|
1539
1518
|
void this._ensureNotRevoked(mesh);
|
|
@@ -1544,57 +1523,6 @@ export class Core extends ReadyResource {
|
|
|
1544
1523
|
void this._retractInventory(mesh, this._requireDeviceKeyPair().publicKey);
|
|
1545
1524
|
void this._settleMembership(mesh, { migrate: true });
|
|
1546
1525
|
}
|
|
1547
|
-
async _dialSiblings(mesh) {
|
|
1548
|
-
if (!this._isAccount(mesh) || !(await this._siblingLock.lock())) {
|
|
1549
|
-
return;
|
|
1550
|
-
}
|
|
1551
|
-
try {
|
|
1552
|
-
await this._redialSiblings(mesh);
|
|
1553
|
-
}
|
|
1554
|
-
finally {
|
|
1555
|
-
this._siblingLock.unlock();
|
|
1556
|
-
}
|
|
1557
|
-
}
|
|
1558
|
-
async _redialSiblings(mesh) {
|
|
1559
|
-
const swarm = this._swarm;
|
|
1560
|
-
if (!swarm || this.closing) {
|
|
1561
|
-
return;
|
|
1562
|
-
}
|
|
1563
|
-
const live = await this._siblingsToDial(mesh, swarm);
|
|
1564
|
-
if (!this._isAccount(mesh) || this.closing) {
|
|
1565
|
-
return;
|
|
1566
|
-
}
|
|
1567
|
-
let changed = false;
|
|
1568
|
-
for (const [id, key] of this._siblings) {
|
|
1569
|
-
if (live.has(id))
|
|
1570
|
-
continue;
|
|
1571
|
-
swarm.leavePeer(key);
|
|
1572
|
-
changed = true;
|
|
1573
|
-
}
|
|
1574
|
-
for (const [id, key] of live) {
|
|
1575
|
-
if (this._siblings.has(id))
|
|
1576
|
-
continue;
|
|
1577
|
-
swarm.joinPeer(key);
|
|
1578
|
-
changed = true;
|
|
1579
|
-
}
|
|
1580
|
-
this._siblings = live;
|
|
1581
|
-
if (changed) {
|
|
1582
|
-
this._log?.info(['p2p', 'swarm'], 'dialling sibling devices', { devices: live.size });
|
|
1583
|
-
}
|
|
1584
|
-
}
|
|
1585
|
-
async _siblingsToDial(mesh, swarm) {
|
|
1586
|
-
const self = this._requireDeviceKeyPair().publicKey;
|
|
1587
|
-
const hosts = new Set([...swarm.explicitPeers].map((peer) => b4a.toHex(peer.publicKey)));
|
|
1588
|
-
const live = new Map();
|
|
1589
|
-
for await (const device of mesh.view.find(DEVICES)) {
|
|
1590
|
-
const id = b4a.toHex(device.id);
|
|
1591
|
-
const theirs = hosts.has(id) && !this._siblings.has(id);
|
|
1592
|
-
if (!device.revoked && !theirs && !b4a.equals(device.id, self)) {
|
|
1593
|
-
live.set(id, device.id);
|
|
1594
|
-
}
|
|
1595
|
-
}
|
|
1596
|
-
return live;
|
|
1597
|
-
}
|
|
1598
1526
|
async _advertiseDeviceProfile(mesh, deviceId) {
|
|
1599
1527
|
const local = this._localDevice;
|
|
1600
1528
|
if (!local?.platform) {
|
|
@@ -2384,8 +2312,8 @@ export class Core extends ReadyResource {
|
|
|
2384
2312
|
writerSeed: session.writerSeed,
|
|
2385
2313
|
logger: this._log,
|
|
2386
2314
|
blindPeerKeys: this._resolveBlindPeerKeys(invite.blindPeers),
|
|
2387
|
-
blindPeeringOpts: this._blindPeeringOpts,
|
|
2388
2315
|
bootFrom: invite.fastForward,
|
|
2316
|
+
trustedDevice: (deviceId) => this._isOurMemberDevice(deviceId),
|
|
2389
2317
|
wakeup: this._wakeup,
|
|
2390
2318
|
attachmentUrl: (attachment) => this._linkAttachment(attachment, candidate),
|
|
2391
2319
|
fileIndex: this._fileIndexFor(() => candidate)
|
|
@@ -2499,7 +2427,8 @@ export class Core extends ReadyResource {
|
|
|
2499
2427
|
const handlers = {
|
|
2500
2428
|
writable: () => this._onMeshWritable(mesh),
|
|
2501
2429
|
dead: (err) => this._onMeshDead(mesh, err),
|
|
2502
|
-
stalled: (err) => this._onMeshStalled(mesh, err)
|
|
2430
|
+
stalled: (err) => this._onMeshStalled(mesh, err),
|
|
2431
|
+
peer: () => this._notifyStatus()
|
|
2503
2432
|
};
|
|
2504
2433
|
entry.handlers = handlers;
|
|
2505
2434
|
mesh.on('kicked', () => this._onKicked(mesh));
|
|
@@ -2512,7 +2441,6 @@ export class Core extends ReadyResource {
|
|
|
2512
2441
|
mesh.on('members-dirty', () => {
|
|
2513
2442
|
if (!this._isAccount(mesh))
|
|
2514
2443
|
return;
|
|
2515
|
-
void this._dialSiblings(mesh).catch(noop);
|
|
2516
2444
|
void this._followAccountName(mesh);
|
|
2517
2445
|
void this._revokeInMeshes();
|
|
2518
2446
|
});
|
|
@@ -2521,6 +2449,11 @@ export class Core extends ReadyResource {
|
|
|
2521
2449
|
void this._followJoinedMeshes(mesh);
|
|
2522
2450
|
}
|
|
2523
2451
|
});
|
|
2452
|
+
mesh.on('joined', () => {
|
|
2453
|
+
if (entry.meshesPending) {
|
|
2454
|
+
void this._followJoinedMeshes(mesh);
|
|
2455
|
+
}
|
|
2456
|
+
});
|
|
2524
2457
|
mesh.on('membership-tallied', () => this._notifyStatus());
|
|
2525
2458
|
mesh.on('mesh-named', () => this._notifyStatus());
|
|
2526
2459
|
mesh.on('membership', (membership) => {
|
|
@@ -2531,6 +2464,8 @@ export class Core extends ReadyResource {
|
|
|
2531
2464
|
mesh.autobee.on('error', handlers.dead);
|
|
2532
2465
|
mesh.autobee.on('close', handlers.dead);
|
|
2533
2466
|
mesh.autobee.on('interrupt', handlers.stalled);
|
|
2467
|
+
mesh.autobee.local.on('peer-add', handlers.peer);
|
|
2468
|
+
mesh.autobee.local.on('peer-remove', handlers.peer);
|
|
2534
2469
|
this._startMeshServices(entry);
|
|
2535
2470
|
this._startEntryIndexing(entry);
|
|
2536
2471
|
}
|
|
@@ -2542,10 +2477,8 @@ export class Core extends ReadyResource {
|
|
|
2542
2477
|
this._wireMesh(this._poolEntry(mesh));
|
|
2543
2478
|
this._accountId = this._meshIdOf(mesh);
|
|
2544
2479
|
void this._deviceControl.revalidate();
|
|
2545
|
-
void this._dialSiblings(mesh).catch(noop);
|
|
2546
2480
|
this._statusError = null;
|
|
2547
2481
|
this._upgradeRequired = null;
|
|
2548
|
-
void this._closeConfigPeering().catch(noop);
|
|
2549
2482
|
if (mesh.writable) {
|
|
2550
2483
|
this._kicked = false;
|
|
2551
2484
|
}
|
|
@@ -2556,6 +2489,15 @@ export class Core extends ReadyResource {
|
|
|
2556
2489
|
return null;
|
|
2557
2490
|
return this._meshes.get(meshKey)?.mesh ?? null;
|
|
2558
2491
|
}
|
|
2492
|
+
async _isOurMemberDevice(deviceId) {
|
|
2493
|
+
const account = this._accountMesh();
|
|
2494
|
+
const ours = account?.ourMemberId;
|
|
2495
|
+
if (!account || !ours || account.closing) {
|
|
2496
|
+
return false;
|
|
2497
|
+
}
|
|
2498
|
+
const row = await account.view.get(DEVICES, { id: deviceId });
|
|
2499
|
+
return !!row && !row.revoked && !!row.memberId && b4a.equals(row.memberId, ours);
|
|
2500
|
+
}
|
|
2559
2501
|
_accountMesh() {
|
|
2560
2502
|
return this._pooled(this._accountId);
|
|
2561
2503
|
}
|
|
@@ -2725,6 +2667,8 @@ export class Core extends ReadyResource {
|
|
|
2725
2667
|
entry.mesh.autobee.off('error', entry.handlers.dead);
|
|
2726
2668
|
entry.mesh.autobee.off('close', entry.handlers.dead);
|
|
2727
2669
|
entry.mesh.autobee.off('interrupt', entry.handlers.stalled);
|
|
2670
|
+
entry.mesh.autobee.local.off('peer-add', entry.handlers.peer);
|
|
2671
|
+
entry.mesh.autobee.local.off('peer-remove', entry.handlers.peer);
|
|
2728
2672
|
}
|
|
2729
2673
|
async _awaitMesh() {
|
|
2730
2674
|
if (this.closing)
|
|
@@ -2737,12 +2681,19 @@ export class Core extends ReadyResource {
|
|
|
2737
2681
|
const { mesh } = entry;
|
|
2738
2682
|
const deviceId = this._requireDeviceKeyPair().publicKey;
|
|
2739
2683
|
mesh.on('notification', (event) => this.emit('notification', event));
|
|
2740
|
-
const
|
|
2684
|
+
const build = () => rebuildChatOrder(mesh, this.local).catch((error) => this._log?.warn(['p2p', 'mesh'], 'building the chat order failed', error));
|
|
2685
|
+
let built = build();
|
|
2741
2686
|
mesh.chatOrderBuilt = built;
|
|
2742
2687
|
mesh.syncChatOrder = async (chatIds) => {
|
|
2743
2688
|
await built;
|
|
2744
|
-
await
|
|
2689
|
+
await (chatIds
|
|
2690
|
+
? refreshChatOrder(mesh, this.local, chatIds)
|
|
2691
|
+
: rebuildChatOrder(mesh, this.local));
|
|
2745
2692
|
};
|
|
2693
|
+
mesh.on('landed', () => {
|
|
2694
|
+
built = built.then(build);
|
|
2695
|
+
mesh.chatOrderBuilt = built;
|
|
2696
|
+
});
|
|
2746
2697
|
void mesh.refreshMembership().catch((error) => {
|
|
2747
2698
|
this._log?.warn(['p2p', 'mesh'], 'tallying membership failed', error);
|
|
2748
2699
|
});
|
|
@@ -3247,7 +3198,7 @@ export class Core extends ReadyResource {
|
|
|
3247
3198
|
}
|
|
3248
3199
|
this._notifyStatus();
|
|
3249
3200
|
}
|
|
3250
|
-
async _openPooledMesh(meshId) {
|
|
3201
|
+
async _openPooledMesh(meshId, reason = 'route') {
|
|
3251
3202
|
if (!this.opened)
|
|
3252
3203
|
await this.ready();
|
|
3253
3204
|
if (this.closing) {
|
|
@@ -3269,7 +3220,7 @@ export class Core extends ReadyResource {
|
|
|
3269
3220
|
if (inflight) {
|
|
3270
3221
|
return inflight;
|
|
3271
3222
|
}
|
|
3272
|
-
const opening = this._openRecordedMesh(meshId).finally(() => {
|
|
3223
|
+
const opening = this._openRecordedMesh(meshId, reason).finally(() => {
|
|
3273
3224
|
if (this._opening.get(meshId) === opening) {
|
|
3274
3225
|
this._opening.delete(meshId);
|
|
3275
3226
|
}
|
|
@@ -3277,10 +3228,11 @@ export class Core extends ReadyResource {
|
|
|
3277
3228
|
this._opening.set(meshId, opening);
|
|
3278
3229
|
return opening;
|
|
3279
3230
|
}
|
|
3280
|
-
async _openRecordedMesh(meshId) {
|
|
3231
|
+
async _openRecordedMesh(meshId, reason) {
|
|
3281
3232
|
if (this._debugBeforeMeshOpen) {
|
|
3282
3233
|
await this._debugBeforeMeshOpen(meshId);
|
|
3283
3234
|
}
|
|
3235
|
+
const started = Date.now();
|
|
3284
3236
|
const key = this._meshKeyOf(meshId);
|
|
3285
3237
|
const session = await this.local.readMeshSession(key);
|
|
3286
3238
|
if (!session) {
|
|
@@ -3307,6 +3259,14 @@ export class Core extends ReadyResource {
|
|
|
3307
3259
|
}
|
|
3308
3260
|
this._notifyStatus();
|
|
3309
3261
|
this._debugOnMeshOpened?.(mesh, meshId);
|
|
3262
|
+
this._log?.info(['p2p', 'mesh'], 'mesh opened', {
|
|
3263
|
+
mesh: meshId.slice(0, 8),
|
|
3264
|
+
reason,
|
|
3265
|
+
account: this._isAccount(mesh),
|
|
3266
|
+
writable: mesh.writable,
|
|
3267
|
+
localLength: mesh.localLength,
|
|
3268
|
+
ms: Date.now() - started
|
|
3269
|
+
});
|
|
3310
3270
|
return mesh;
|
|
3311
3271
|
}
|
|
3312
3272
|
async _meshEntry(row, accountKey, meshes) {
|
|
@@ -3642,12 +3602,6 @@ export class Core extends ReadyResource {
|
|
|
3642
3602
|
}
|
|
3643
3603
|
return { memberInvite: decoded.memberInvite ?? false, inviterName: decoded.inviterName };
|
|
3644
3604
|
}
|
|
3645
|
-
_leaveSiblings(swarm) {
|
|
3646
|
-
for (const key of this._siblings.values()) {
|
|
3647
|
-
swarm.leavePeer(key);
|
|
3648
|
-
}
|
|
3649
|
-
this._siblings.clear();
|
|
3650
|
-
}
|
|
3651
3605
|
async _closeSwarm() {
|
|
3652
3606
|
if (this._ownsWakeup) {
|
|
3653
3607
|
this._wakeup.destroy();
|
|
@@ -3668,7 +3622,6 @@ export class Core extends ReadyResource {
|
|
|
3668
3622
|
detach();
|
|
3669
3623
|
}
|
|
3670
3624
|
this._peers.clear();
|
|
3671
|
-
this._leaveSiblings(swarm);
|
|
3672
3625
|
await Promise.all([...this._meshes.values()].map(({ mesh }) => swarm.leave(mesh.discoveryKey)));
|
|
3673
3626
|
return;
|
|
3674
3627
|
}
|
|
@@ -3723,6 +3676,10 @@ export class Core extends ReadyResource {
|
|
|
3723
3676
|
if (entry?.mesh !== memberMesh) {
|
|
3724
3677
|
return;
|
|
3725
3678
|
}
|
|
3679
|
+
if (!memberMesh.joined) {
|
|
3680
|
+
entry.meshesPending = true;
|
|
3681
|
+
return;
|
|
3682
|
+
}
|
|
3726
3683
|
if (!memberMesh.ourMemberId) {
|
|
3727
3684
|
await memberMesh.refreshOurMember();
|
|
3728
3685
|
}
|
|
@@ -3734,14 +3691,29 @@ export class Core extends ReadyResource {
|
|
|
3734
3691
|
if (!(await entry.followLock.lock())) {
|
|
3735
3692
|
return;
|
|
3736
3693
|
}
|
|
3694
|
+
const tally = {
|
|
3695
|
+
rows: 0,
|
|
3696
|
+
opened: 0,
|
|
3697
|
+
readmitted: 0,
|
|
3698
|
+
held: 0,
|
|
3699
|
+
left: 0,
|
|
3700
|
+
noSeed: 0,
|
|
3701
|
+
skipped: 0
|
|
3702
|
+
};
|
|
3737
3703
|
try {
|
|
3738
|
-
entry.meshesPending = await this._followMeshRows(memberMesh, ours);
|
|
3704
|
+
entry.meshesPending = await this._followMeshRows(memberMesh, ours, tally);
|
|
3739
3705
|
}
|
|
3740
3706
|
finally {
|
|
3741
3707
|
entry.followLock.unlock();
|
|
3742
3708
|
}
|
|
3709
|
+
const level = tally.opened || tally.readmitted || tally.left ? 'info' : 'debug';
|
|
3710
|
+
this._log?.[level](['p2p', 'mesh'], 'followed the joined meshes', {
|
|
3711
|
+
mesh: b4a.toHex(memberMesh.key).slice(0, 8),
|
|
3712
|
+
...tally,
|
|
3713
|
+
pending: entry.meshesPending
|
|
3714
|
+
});
|
|
3743
3715
|
}
|
|
3744
|
-
async _followMeshRows(memberMesh, ours) {
|
|
3716
|
+
async _followMeshRows(memberMesh, ours, tally) {
|
|
3745
3717
|
let pending = false;
|
|
3746
3718
|
for await (const joined of memberMesh.view.find(JOINED_MESHES)) {
|
|
3747
3719
|
if (this.closing ||
|
|
@@ -3752,6 +3724,7 @@ export class Core extends ReadyResource {
|
|
|
3752
3724
|
if (!b4a.equals(joined.memberId, ours))
|
|
3753
3725
|
continue;
|
|
3754
3726
|
const meshId = b4a.toHex(joined.meshKey);
|
|
3727
|
+
tally.rows++;
|
|
3755
3728
|
if (this._following.has(meshId)) {
|
|
3756
3729
|
continue;
|
|
3757
3730
|
}
|
|
@@ -3759,6 +3732,7 @@ export class Core extends ReadyResource {
|
|
|
3759
3732
|
const failed = await this._trackFollow(meshId, async () => {
|
|
3760
3733
|
if (joined.leftAt) {
|
|
3761
3734
|
if (held) {
|
|
3735
|
+
tally.left++;
|
|
3762
3736
|
await this._retireLeftMesh(held);
|
|
3763
3737
|
}
|
|
3764
3738
|
else {
|
|
@@ -3767,16 +3741,27 @@ export class Core extends ReadyResource {
|
|
|
3767
3741
|
return;
|
|
3768
3742
|
}
|
|
3769
3743
|
if (held) {
|
|
3744
|
+
tally.held++;
|
|
3770
3745
|
return;
|
|
3771
3746
|
}
|
|
3772
3747
|
if (await this.local.readMeshSession(joined.meshKey)) {
|
|
3773
3748
|
if (this._upgradeRequired !== 'halt' &&
|
|
3774
3749
|
(await this.local.awaitsAdmission(joined.meshKey))) {
|
|
3775
|
-
|
|
3750
|
+
tally.readmitted++;
|
|
3751
|
+
await this._openPooledMesh(meshId, 'readmit');
|
|
3776
3752
|
}
|
|
3777
3753
|
return;
|
|
3778
3754
|
}
|
|
3779
|
-
await this._openFollowedMesh(memberMesh, joined);
|
|
3755
|
+
const outcome = await this._openFollowedMesh(memberMesh, joined);
|
|
3756
|
+
if (outcome === 'opened') {
|
|
3757
|
+
tally.opened++;
|
|
3758
|
+
}
|
|
3759
|
+
else if (outcome === 'no-seed') {
|
|
3760
|
+
tally.noSeed++;
|
|
3761
|
+
}
|
|
3762
|
+
else {
|
|
3763
|
+
tally.skipped++;
|
|
3764
|
+
}
|
|
3780
3765
|
});
|
|
3781
3766
|
if (failed && !joined.leftAt) {
|
|
3782
3767
|
pending = true;
|
|
@@ -3805,6 +3790,10 @@ export class Core extends ReadyResource {
|
|
|
3805
3790
|
if (this._leaving || this._minting)
|
|
3806
3791
|
return;
|
|
3807
3792
|
try {
|
|
3793
|
+
this._log?.info(['p2p', 'mesh'], 'retiring a mesh the member left', {
|
|
3794
|
+
mesh: b4a.toHex(mesh.key).slice(0, 8),
|
|
3795
|
+
account: this._isAccount(mesh)
|
|
3796
|
+
});
|
|
3808
3797
|
await this._recordDeparture(mesh);
|
|
3809
3798
|
if (this._isAccount(mesh)) {
|
|
3810
3799
|
await this._replaceRevokedAccount(mesh);
|
|
@@ -3826,19 +3815,23 @@ export class Core extends ReadyResource {
|
|
|
3826
3815
|
}
|
|
3827
3816
|
async _openFollowedMesh(memberMesh, joined) {
|
|
3828
3817
|
if (this._blockedByMinVersion() || this._upgradeRequired || !this._mayFollow(memberMesh)) {
|
|
3829
|
-
return;
|
|
3818
|
+
return 'skipped';
|
|
3830
3819
|
}
|
|
3831
3820
|
const { meshKey } = joined;
|
|
3832
3821
|
const held = await memberMesh.view.get(MESH_SEEDS, { meshKey });
|
|
3833
|
-
if (!held
|
|
3834
|
-
return;
|
|
3822
|
+
if (!held) {
|
|
3823
|
+
return 'no-seed';
|
|
3824
|
+
}
|
|
3825
|
+
if (this.closing) {
|
|
3826
|
+
return 'skipped';
|
|
3835
3827
|
}
|
|
3836
3828
|
const session = this.local.createCandidateSession(held.seed, meshKey);
|
|
3837
3829
|
await this.local.recordMesh(meshKey, session, {
|
|
3838
3830
|
deviceId: this._requireDeviceKeyPair().publicKey
|
|
3839
3831
|
});
|
|
3840
3832
|
await this.local.markAwaitingAdmission(meshKey, { awaitingAdmission: true });
|
|
3841
|
-
await this._openPooledMesh(b4a.toHex(meshKey));
|
|
3833
|
+
await this._openPooledMesh(b4a.toHex(meshKey), 'follow');
|
|
3834
|
+
return 'opened';
|
|
3842
3835
|
}
|
|
3843
3836
|
_mayFollow(memberMesh) {
|
|
3844
3837
|
const moving = this._joinCancellation ? this._joinCancellation.account : this._minting;
|
|
@@ -4127,7 +4120,6 @@ export class Core extends ReadyResource {
|
|
|
4127
4120
|
}
|
|
4128
4121
|
}
|
|
4129
4122
|
_trackPeerConnection(conn, detach) {
|
|
4130
|
-
this._seenPeers.add(b4a.toHex(conn.remotePublicKey));
|
|
4131
4123
|
const remove = () => {
|
|
4132
4124
|
if (this._peers.delete(conn)) {
|
|
4133
4125
|
this._onPeerChange();
|
|
@@ -4621,6 +4613,11 @@ export class Core extends ReadyResource {
|
|
|
4621
4613
|
viewLength: mesh.view.db.head()?.length ?? 0,
|
|
4622
4614
|
flushes: mesh.autobee.system.flushes,
|
|
4623
4615
|
fastForwards: mesh.autobee.stats.fastForwards,
|
|
4616
|
+
stats: { ...mesh.autobee.stats },
|
|
4617
|
+
writers: mesh.writerCount,
|
|
4618
|
+
bootFrom: mesh.bootFrom,
|
|
4619
|
+
uptimeMs: mesh.uptimeMs,
|
|
4620
|
+
blindPeersConnected: mesh.blindPeersConnected(),
|
|
4624
4621
|
member: this._memberDiagnostics(mesh),
|
|
4625
4622
|
orphanedBlobSweep: mesh.orphanedBlobSweepStatus,
|
|
4626
4623
|
blindPeering: this._blindPeeringOn,
|
|
@@ -4649,12 +4646,15 @@ export class Core extends ReadyResource {
|
|
|
4649
4646
|
}
|
|
4650
4647
|
_statusSnapshot() {
|
|
4651
4648
|
const peerDeviceIds = [...this.peerDeviceIds];
|
|
4649
|
+
const blindPeers = [...(this._blindPeering?.blindPeers.values() ?? [])];
|
|
4652
4650
|
return {
|
|
4653
4651
|
state: this._statusState(),
|
|
4654
4652
|
peerCount: peerDeviceIds.length,
|
|
4655
4653
|
peerDeviceIds,
|
|
4656
4654
|
kickedPending: this._kickedPending,
|
|
4657
|
-
error: this._statusError ?? undefined
|
|
4655
|
+
error: this._statusError ?? undefined,
|
|
4656
|
+
blindPeersConnected: blindPeers.filter((peer) => peer.connected).length,
|
|
4657
|
+
blindPeersTotal: blindPeers.length
|
|
4658
4658
|
};
|
|
4659
4659
|
}
|
|
4660
4660
|
acknowledgeKicked() {
|
|
@@ -939,7 +939,9 @@ export function registerEngineTypes(ns) {
|
|
|
939
939
|
{ name: 'peerCount', type: 'uint', required: true },
|
|
940
940
|
{ name: 'peerDeviceIds', type: 'string', array: true },
|
|
941
941
|
{ name: 'kickedPending', type: 'bool' },
|
|
942
|
-
{ name: 'error', type: 'string' }
|
|
942
|
+
{ name: 'error', type: 'string' },
|
|
943
|
+
{ name: 'blindPeersConnected', type: 'uint' },
|
|
944
|
+
{ name: 'blindPeersTotal', type: 'uint' }
|
|
943
945
|
]
|
|
944
946
|
});
|
|
945
947
|
ns.register({
|
|
@@ -1454,7 +1456,8 @@ export function registerEngineTypes(ns) {
|
|
|
1454
1456
|
{ name: 'status', type: 'string', required: true },
|
|
1455
1457
|
{ name: 'stub', type: 'bool' },
|
|
1456
1458
|
{ name: 'minCapabilityProfile', type: 'string' },
|
|
1457
|
-
{ name: 'emoji', type: 'string' }
|
|
1459
|
+
{ name: 'emoji', type: 'string' },
|
|
1460
|
+
{ name: 'displayName', type: 'string' }
|
|
1458
1461
|
]
|
|
1459
1462
|
});
|
|
1460
1463
|
ns.register({
|