@qvac/core 1.0.0-rc.2 → 1.0.0-rc.5
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 +238 -12
- package/dist-lib/index.d.ts +3 -1
- package/dist-lib/index.js +1 -0
- package/dist-lib/lib/api/approval-rules.d.ts +1 -1
- package/dist-lib/lib/api/approval-rules.js +5 -1
- package/dist-lib/lib/api/chunk-delta.d.ts +7 -2
- package/dist-lib/lib/api/chunk-delta.js +89 -7
- package/dist-lib/lib/api/chunks.js +14 -8
- package/dist-lib/lib/api/config.d.ts +10 -3
- package/dist-lib/lib/api/config.js +51 -6
- package/dist-lib/lib/api/custom-models.js +3 -5
- package/dist-lib/lib/api/devices.js +3 -1
- package/dist-lib/lib/api/files.d.ts +1 -1
- package/dist-lib/lib/api/files.js +65 -8
- package/dist-lib/lib/api/index.d.ts +12 -2
- package/dist-lib/lib/api/index.js +6 -1
- package/dist-lib/lib/api/instrument.js +12 -4
- package/dist-lib/lib/api/members.js +7 -13
- package/dist-lib/lib/api/mesh.d.ts +1 -3
- package/dist-lib/lib/api/mesh.js +2 -2
- package/dist-lib/lib/api/notifications.js +8 -4
- package/dist-lib/lib/api/projects.js +5 -1
- package/dist-lib/lib/api/rag.js +32 -19
- package/dist-lib/lib/api/served.js +2 -1
- package/dist-lib/lib/api/workspace.js +0 -1
- package/dist-lib/lib/assistant/harness.d.ts +8 -2
- package/dist-lib/lib/assistant/harness.js +17 -4
- package/dist-lib/lib/assistant/history.d.ts +1 -1
- package/dist-lib/lib/assistant/history.js +19 -13
- package/dist-lib/lib/assistant/message.d.ts +6 -1
- package/dist-lib/lib/assistant/message.js +22 -2
- package/dist-lib/lib/assistant/model-round.d.ts +5 -0
- package/dist-lib/lib/assistant/model-round.js +47 -19
- package/dist-lib/lib/assistant/pdf-budget.d.ts +10 -2
- package/dist-lib/lib/assistant/pdf-budget.js +10 -11
- package/dist-lib/lib/assistant/pdf-pages.d.ts +25 -0
- package/dist-lib/lib/assistant/pdf-pages.js +75 -0
- package/dist-lib/lib/assistant/round-host.js +5 -3
- package/dist-lib/lib/assistant-client.d.ts +2 -1
- package/dist-lib/lib/assistant-client.js +24 -6
- package/dist-lib/lib/assistant-tree.d.ts +2 -0
- package/dist-lib/lib/assistant-tree.js +8 -5
- package/dist-lib/lib/assistant.d.ts +21 -7
- package/dist-lib/lib/assistant.js +481 -244
- package/dist-lib/lib/client.js +10 -1
- package/dist-lib/lib/compaction.d.ts +3 -1
- package/dist-lib/lib/compaction.js +18 -4
- package/dist-lib/lib/constants.d.ts +3 -0
- package/dist-lib/lib/constants.js +3 -0
- package/dist-lib/lib/core/agent-copies.js +7 -1
- package/dist-lib/lib/core/agent.js +1 -0
- package/dist-lib/lib/core/approval-rules.d.ts +5 -1
- package/dist-lib/lib/core/approval-rules.js +16 -1
- package/dist-lib/lib/core/chat-activity.js +13 -16
- package/dist-lib/lib/core/chat-copy.js +1 -1
- package/dist-lib/lib/core/chat-fork.js +2 -1
- package/dist-lib/lib/core/chat-move.d.ts +4 -0
- package/dist-lib/lib/core/chat-move.js +42 -11
- package/dist-lib/lib/core/chat.d.ts +0 -1
- package/dist-lib/lib/core/chat.js +1 -1
- package/dist-lib/lib/core/chunk.d.ts +14 -3
- package/dist-lib/lib/core/chunk.js +116 -25
- package/dist-lib/lib/core/collections.d.ts +12 -1
- package/dist-lib/lib/core/collections.js +12 -1
- package/dist-lib/lib/core/config-value.d.ts +7 -0
- package/dist-lib/lib/core/config-value.js +15 -0
- package/dist-lib/lib/core/contract/activity.d.ts +3 -2
- package/dist-lib/lib/core/contract/activity.js +39 -21
- package/dist-lib/lib/core/contract/agent-join.js +15 -19
- package/dist-lib/lib/core/contract/agents.js +8 -7
- package/dist-lib/lib/core/contract/chat.d.ts +3 -0
- package/dist-lib/lib/core/contract/chat.js +12 -1
- package/dist-lib/lib/core/contract/chunks.js +16 -6
- package/dist-lib/lib/core/contract/devices.js +6 -4
- package/dist-lib/lib/core/contract/index.js +2 -1
- package/dist-lib/lib/core/contract/invites.js +12 -31
- package/dist-lib/lib/core/contract/joined-meshes.js +2 -1
- package/dist-lib/lib/core/contract/mesh-rules.js +4 -0
- package/dist-lib/lib/core/contract/model-requests.js +7 -6
- package/dist-lib/lib/core/contract/project-device-keys.js +15 -6
- package/dist-lib/lib/core/contract/project-host-keys.js +5 -4
- package/dist-lib/lib/core/contract/projects.js +12 -13
- package/dist-lib/lib/core/contract/public-seeds.js +5 -5
- package/dist-lib/lib/core/contract/roles.js +2 -1
- package/dist-lib/lib/core/contract/run-requests.d.ts +1 -1
- package/dist-lib/lib/core/contract/run-requests.js +19 -13
- package/dist-lib/lib/core/contract/shipped-rows.d.ts +2 -0
- package/dist-lib/lib/core/contract/shipped-rows.js +22 -0
- package/dist-lib/lib/core/contract/workspace.js +6 -12
- package/dist-lib/lib/core/contract/writers.js +20 -6
- package/dist-lib/lib/core/deleted-agent-runs.d.ts +7 -0
- package/dist-lib/lib/core/deleted-agent-runs.js +46 -0
- package/dist-lib/lib/core/devices.d.ts +2 -1
- package/dist-lib/lib/core/devices.js +4 -2
- package/dist-lib/lib/core/document-attachment.d.ts +6 -3
- package/dist-lib/lib/core/document-attachment.js +10 -5
- package/dist-lib/lib/core/files/attachments.js +3 -3
- package/dist-lib/lib/core/files/index.d.ts +8 -5
- package/dist-lib/lib/core/files/index.js +111 -18
- package/dist-lib/lib/core/files/processing/index.d.ts +1 -1
- package/dist-lib/lib/core/files/processing/index.js +8 -2
- package/dist-lib/lib/core/files/processing/source.d.ts +1 -0
- package/dist-lib/lib/core/files/processing/source.js +3 -0
- package/dist-lib/lib/core/files/processing/state.d.ts +1 -0
- package/dist-lib/lib/core/files/processing/state.js +7 -0
- package/dist-lib/lib/core/files/rag/build.d.ts +1 -0
- package/dist-lib/lib/core/files/rag/build.js +14 -1
- package/dist-lib/lib/core/files/rag/index.d.ts +1 -1
- package/dist-lib/lib/core/files/rag/index.js +1 -1
- package/dist-lib/lib/core/files/rag/produce.js +1 -0
- package/dist-lib/lib/core/files/rag/retrieval/full-text.d.ts +2 -0
- package/dist-lib/lib/core/files/rag/retrieval/full-text.js +7 -1
- package/dist-lib/lib/core/first-event.d.ts +6 -0
- package/dist-lib/lib/core/first-event.js +13 -0
- package/dist-lib/lib/core/invite.d.ts +2 -2
- package/dist-lib/lib/core/invite.js +5 -4
- package/dist-lib/lib/core/local/index.d.ts +16 -1
- package/dist-lib/lib/core/local/index.js +119 -10
- package/dist-lib/lib/core/mesh.d.ts +14 -3
- package/dist-lib/lib/core/mesh.js +127 -54
- package/dist-lib/lib/core/migrations/chat-chunks.d.ts +4 -0
- package/dist-lib/lib/core/migrations/chat-chunks.js +47 -0
- package/dist-lib/lib/core/migrations/file-index.d.ts +1 -1
- package/dist-lib/lib/core/migrations/file-index.js +6 -2
- package/dist-lib/lib/core/migrations/index.d.ts +2 -1
- package/dist-lib/lib/core/migrations/index.js +66 -9
- package/dist-lib/lib/core/notification.js +96 -23
- package/dist-lib/lib/core/pdf/figure.d.ts +22 -0
- package/dist-lib/lib/core/pdf/figure.js +64 -0
- package/dist-lib/lib/core/pdf/rasterize.d.ts +10 -1
- package/dist-lib/lib/core/pdf/rasterize.js +72 -22
- package/dist-lib/lib/core/peer-duplex.js +57 -5
- package/dist-lib/lib/core/public-mesh.js +8 -2
- package/dist-lib/lib/core/run-requests.js +2 -3
- package/dist-lib/lib/core/senders.d.ts +7 -6
- package/dist-lib/lib/core/senders.js +23 -30
- package/dist-lib/lib/core/shared-agents.d.ts +1 -0
- package/dist-lib/lib/core/shared-agents.js +47 -19
- package/dist-lib/lib/core/skill-secrets.d.ts +3 -2
- package/dist-lib/lib/core/skill-secrets.js +4 -1
- package/dist-lib/lib/core/sync/background.d.ts +3 -15
- package/dist-lib/lib/core/sync/background.js +25 -102
- package/dist-lib/lib/core/sync/devices.js +6 -3
- package/dist-lib/lib/core/sync/index.js +25 -3
- package/dist-lib/lib/core/sync-status.js +3 -3
- package/dist-lib/lib/core/vault-managed-skills.d.ts +18 -0
- package/dist-lib/lib/core/vault-managed-skills.js +105 -0
- package/dist-lib/lib/core.d.ts +66 -10
- package/dist-lib/lib/core.js +768 -179
- package/dist-lib/lib/credential-pusher.d.ts +11 -7
- package/dist-lib/lib/credential-pusher.js +40 -8
- package/dist-lib/lib/device-tree.d.ts +18 -0
- package/dist-lib/lib/device-tree.js +32 -0
- package/dist-lib/lib/doctor/redact.js +1 -1
- package/dist-lib/lib/errors.d.ts +12 -0
- package/dist-lib/lib/errors.js +12 -0
- package/dist-lib/lib/fs-drive-bridge.d.ts +7 -0
- package/dist-lib/lib/fs-drive-bridge.js +308 -30
- package/dist-lib/lib/integrations/setup-routes.js +7 -5
- package/dist-lib/lib/knowledge-search.d.ts +1 -1
- package/dist-lib/lib/knowledge-search.js +5 -46
- package/dist-lib/lib/kv-cache-retention.d.ts +35 -0
- package/dist-lib/lib/kv-cache-retention.js +98 -0
- package/dist-lib/lib/latest-frame.d.ts +10 -0
- package/dist-lib/lib/latest-frame.js +48 -0
- package/dist-lib/lib/mesh-scoped-engine.js +1 -0
- package/dist-lib/lib/model-download.d.ts +6 -1
- package/dist-lib/lib/model-download.js +32 -17
- package/dist-lib/lib/oauth/resolve.js +13 -5
- package/dist-lib/lib/reconnecting-watch.js +19 -11
- package/dist-lib/lib/run-notices.d.ts +2 -0
- package/dist-lib/lib/run-notices.js +5 -0
- package/dist-lib/lib/run-replay.d.ts +13 -1
- package/dist-lib/lib/run-replay.js +58 -21
- package/dist-lib/schema/build.js +66 -57
- package/dist-lib/schema/config.d.ts +1 -1
- package/dist-lib/schema/config.js +1 -1
- package/dist-lib/schema/content.js +2 -1
- package/dist-lib/schema/engine.js +70 -6
- package/dist-lib/schema/field-order.js +7 -1
- package/dist-lib/schema/indexes.d.ts +4 -0
- package/dist-lib/schema/indexes.js +18 -0
- package/dist-lib/schema/local.js +9 -2
- package/dist-lib/schema/qvac.js +116 -6
- package/dist-lib/spec/bind.js +15 -0
- package/dist-lib/spec/calls.js +5 -0
- package/dist-lib/spec/capabilities.d.ts +10 -0
- package/dist-lib/spec/config/hyperconf/index.js +1 -1
- package/dist-lib/spec/hrpc/hrpc.json +65 -0
- package/dist-lib/spec/hrpc/index.js +63 -3
- package/dist-lib/spec/hrpc/messages.js +1537 -1395
- package/dist-lib/spec/hyperschema/index.js +1537 -1395
- package/dist-lib/spec/hyperschema/schema.json +126 -1
- package/dist-lib/spec/hyperschema/types.d.ts +33 -1
- package/dist-lib/spec/local/hyperdb/messages.js +110 -54
- package/dist-lib/spec/local/hyperschema/index.js +56 -28
- package/dist-lib/spec/local/hyperschema/schema.json +55 -20
- package/dist-lib/spec/local/hyperschema/types.d.ts +8 -1
- package/dist-lib/spec/mesh/hyperdb/db.json +255 -51
- package/dist-lib/spec/mesh/hyperdb/index.js +1063 -404
- package/dist-lib/spec/mesh/hyperdb/messages.js +1673 -1202
- package/dist-lib/spec/mesh/hyperdispatch/dispatch.json +62 -56
- package/dist-lib/spec/mesh/hyperdispatch/index.js +156 -139
- package/dist-lib/spec/mesh/hyperdispatch/messages.js +809 -632
- package/dist-lib/spec/mesh/hyperschema/index.js +809 -632
- package/dist-lib/spec/mesh/hyperschema/schema.json +293 -174
- package/dist-lib/spec/mesh/hyperschema/types.d.ts +31 -1
- package/package.json +32 -26
- package/worker/assistant-sidecar.mjs +3 -0
- package/dist-lib/lib/core/files/processing/settle.d.ts +0 -13
- package/dist-lib/lib/core/files/processing/settle.js +0 -86
- package/dist-lib/lib/core/migrations/device-indexes.d.ts +0 -2
- package/dist-lib/lib/core/migrations/device-indexes.js +0 -7
package/dist-lib/lib/core.js
CHANGED
|
@@ -18,6 +18,7 @@ import { writeAutoDownloadModels } from './api/app-config.js';
|
|
|
18
18
|
import { requireOurAdmin, requireWorkspace } from './api/members.js';
|
|
19
19
|
import { projectName } from './api/projects.js';
|
|
20
20
|
import { createServedApi } from './api/served.js';
|
|
21
|
+
import { firstEvent } from './core/first-event.js';
|
|
21
22
|
import { departedMembers, isWorkspace, lastAdminAmongOthers, liveMemberIds, readMemberKey, upgradeMembers } from './core/contract/workspace.js';
|
|
22
23
|
import { readPublicSeed } from './core/contract/public-seeds.js';
|
|
23
24
|
import { openSealedToDevice, sealToDevice } from './core/device-seal.js';
|
|
@@ -31,6 +32,8 @@ import { ChatMoves } from './core/chat-move.js';
|
|
|
31
32
|
import { purgeCores } from './core/purge.js';
|
|
32
33
|
import { copyContent } from './core/chat-copy.js';
|
|
33
34
|
import { followAgentCopies, keepCopyChats } from './core/agent-copies.js';
|
|
35
|
+
import { cancelDeletedAgentRuns } from './core/deleted-agent-runs.js';
|
|
36
|
+
import { devicesOfMember } from './core/contract/activity.js';
|
|
34
37
|
import { followPickedAgents, followSharedAgents, liveSharedAgent, pickAgent, shareAgent, unpickAgent } from './core/shared-agents.js';
|
|
35
38
|
import { inRole, publicRoute } from './core/contract/roles.js';
|
|
36
39
|
import { freshPublicRecord, isOwnWorkspace, isPublicRecord, lostMint, onOwnSeed, leftPublicRecordKey, ownWorkspaceSeed, ownWorkspaces, publicMeshKey, publicRecordKey, publicSeed, servesAgents, servesChat, servesChunk } from './core/public-mesh.js';
|
|
@@ -58,18 +61,20 @@ import { countContents, migrateContents, withArchivedMesh } from './core/archive
|
|
|
58
61
|
import { isMobilePlatform } from '@qvac/harness/lib/models/model-catalog.ts';
|
|
59
62
|
import { storeSkillSecret, syncSkillSecrets } from './core/skill-secrets.js';
|
|
60
63
|
import { SKILL_SECRET_PREFIX } from './core/contract/skill-secrets.js';
|
|
64
|
+
import { discardQuarantinedSkills, prepareVaultManagedSkills, quarantinedSkillKeys, releaseQuarantinedSkills, validateVaultManagedSkill } from './core/vault-managed-skills.js';
|
|
61
65
|
import { attestDeviceProof, attestMemberClaim, chainTo, claimAttestation, delegationFits, openIdentity, pairingAnchorSeed } from './core/identity.js';
|
|
62
66
|
import { openRecoveryCore, publishRecovery, readRecovery, recoveryKeys } from './core/account-recovery.js';
|
|
63
67
|
import { claimOwnMembership, legacyNameStamp, namedAt, renameFoundedMember } from './core/membership.js';
|
|
64
68
|
import { runMigrations } from './core/migrations/index.js';
|
|
65
69
|
import { backfillFileIndex } from './core/migrations/file-index.js';
|
|
70
|
+
import { REINDEX_FROM_APP_VERSION, backfillChatChunks, floorExcludesBefore } from './core/migrations/chat-chunks.js';
|
|
66
71
|
import { advertiseDeviceVersion, retractInventory } from './core/devices.js';
|
|
67
72
|
import { DeviceControl } from './core/device-control.js';
|
|
68
73
|
import { forwardToDevices, servedToSiblings } from './api/device-routes.js';
|
|
69
74
|
import { OtaConfigReader, configCoreFor, resolveConfigChannel, vendoredMinSupportedVersion } from './core/ota-config.js';
|
|
70
75
|
import { updateRequired } from './core/min-version.js';
|
|
71
76
|
import { PendingDepartures, waitForDelivery } from './core/departures.js';
|
|
72
|
-
import { Mesh } from './core/mesh.js';
|
|
77
|
+
import { Mesh, SCHEMA_VERSION } from './core/mesh.js';
|
|
73
78
|
import { raceResource } from './race-resource.js';
|
|
74
79
|
import { createSystemInfoSampler } from './core/system-info.js';
|
|
75
80
|
import { projectSenders } from './core/senders.js';
|
|
@@ -84,16 +89,18 @@ const top = new Top();
|
|
|
84
89
|
const FILE_GC_INTERVAL_MS = 24 * 60 * 60 * 1000;
|
|
85
90
|
const SWARM_KEYPAIR_NAME = 'qvac-swarm-keypair';
|
|
86
91
|
const QVAC_CORE_NAMESPACE = 'qvac-core';
|
|
87
|
-
const HELD_AGENTS_PREFIX = 'skill-values.held-agents';
|
|
88
92
|
const MESH_ID = /^[0-9a-f]{64}$/;
|
|
89
93
|
export const DEVICE_UNKNOWN = 'This device has no device details: pass `device` when creating Core';
|
|
90
94
|
const RECOVERY_WAIT_MS = 30_000;
|
|
95
|
+
const WINNER_ADMISSION_WAIT_MS = 60_000;
|
|
91
96
|
const TOPIC_RETRY_MS = [1_000, 5_000, 15_000];
|
|
92
97
|
const MESH_DIED = 'the local database died';
|
|
93
98
|
const MESH_NOT_EMPTY = 'this mesh is not empty: everyone in it will see the newcomer arrive, and the newcomer replays the whole history of the mesh, including what earlier members wrote';
|
|
94
99
|
const INVITE_DHT_NODES_LIMIT = 3;
|
|
95
100
|
const INVITE_BLIND_PEERS_LIMIT = 3;
|
|
101
|
+
const INVITE_PUBLIC_HEADS_LIMIT = 3;
|
|
96
102
|
const DIAGNOSTICS_SAMPLE_MS = 2000;
|
|
103
|
+
const PUBLIC_FOLLOW_ATTEMPTS = 3;
|
|
97
104
|
export class Core extends ReadyResource {
|
|
98
105
|
_storagePath;
|
|
99
106
|
store;
|
|
@@ -109,6 +116,7 @@ export class Core extends ReadyResource {
|
|
|
109
116
|
_log;
|
|
110
117
|
_spec;
|
|
111
118
|
_bootstrapNodes;
|
|
119
|
+
_network;
|
|
112
120
|
_device;
|
|
113
121
|
_app;
|
|
114
122
|
_minSupportedVersion;
|
|
@@ -124,7 +132,6 @@ export class Core extends ReadyResource {
|
|
|
124
132
|
_blindPeerKeys;
|
|
125
133
|
_blindPeeringOpts;
|
|
126
134
|
_fileGc;
|
|
127
|
-
_syncPacing;
|
|
128
135
|
_autoDownloadModels;
|
|
129
136
|
_fileGcTimer = null;
|
|
130
137
|
_fileGcRun = null;
|
|
@@ -159,6 +166,7 @@ export class Core extends ReadyResource {
|
|
|
159
166
|
_meshTransitionLock = new ScopeLock();
|
|
160
167
|
_opening = new Map();
|
|
161
168
|
_retiring = new Map();
|
|
169
|
+
_tearingDown = new Map();
|
|
162
170
|
_debugBeforeMeshOpen;
|
|
163
171
|
_debugOnMeshOpened;
|
|
164
172
|
_skills;
|
|
@@ -201,6 +209,7 @@ export class Core extends ReadyResource {
|
|
|
201
209
|
_groupPassesDue = new WeakSet();
|
|
202
210
|
_purging = new Map();
|
|
203
211
|
_publicIds = new Map();
|
|
212
|
+
_publicBoots = new Map();
|
|
204
213
|
_meshNames = new Map();
|
|
205
214
|
_ownWorkspaceId = null;
|
|
206
215
|
_publicWriters = new WeakMap();
|
|
@@ -217,6 +226,8 @@ export class Core extends ReadyResource {
|
|
|
217
226
|
_projectKeySeals = new ScopeLock({ debounce: true });
|
|
218
227
|
_hosting = new ScopeLock({ debounce: true });
|
|
219
228
|
_skillSecrets = new ScopeLock({ debounce: true });
|
|
229
|
+
_vaultManagedSkills;
|
|
230
|
+
_quarantine = Promise.resolve([]);
|
|
220
231
|
_hostMeshes = new Set();
|
|
221
232
|
_hostJoins = new WeakMap();
|
|
222
233
|
_agentListeners = new Set();
|
|
@@ -227,8 +238,12 @@ export class Core extends ReadyResource {
|
|
|
227
238
|
_minting;
|
|
228
239
|
_backfill = Promise.resolve();
|
|
229
240
|
_leaving;
|
|
230
|
-
|
|
231
|
-
|
|
241
|
+
_kickedMeshes = new Set();
|
|
242
|
+
_kickCloses = new Map();
|
|
243
|
+
_retiredMeshes = new Set();
|
|
244
|
+
_retiredAccount = null;
|
|
245
|
+
_kickNotice = false;
|
|
246
|
+
_leaveChecks = null;
|
|
232
247
|
_peers;
|
|
233
248
|
_peerArrivedSuspended = false;
|
|
234
249
|
_statusListeners;
|
|
@@ -243,7 +258,7 @@ export class Core extends ReadyResource {
|
|
|
243
258
|
_systemInfo;
|
|
244
259
|
_statusError;
|
|
245
260
|
_upgradeRequired;
|
|
246
|
-
constructor(transport, { storagePath, store = undefined, swarm = undefined, wakeup = undefined, logger = null, spec = openLocalSpec, bootstrapNodes = undefined, device = undefined, app = undefined, minSupportedVersion = undefined, otaConfigCore = undefined, blindPeerKeys = undefined, blindPeeringOpts = undefined, fileGc = null, autoDownloadModels = undefined, meshSeed = undefined, meshKey = undefined, additionalNodes = undefined, listModels = undefined, deleteModel = undefined, clearKvCache = undefined, deleteChatKvCache = undefined, compactChat = undefined, modelCatalogWatch = undefined, retryModelDownload = undefined, transcribe = undefined, detectLanguage = undefined, previewModelSource = undefined, speak = undefined, speakStream = undefined, embedder = undefined, extractors = undefined, skills = undefined, skillCatalog = undefined, tools = undefined, hostsModelSource = false, vectorIndex = undefined, apiLifecycle = undefined,
|
|
261
|
+
constructor(transport, { storagePath, skillSecrets = undefined, store = undefined, swarm = undefined, wakeup = undefined, logger = null, spec = openLocalSpec, bootstrapNodes = undefined, device = undefined, app = undefined, minSupportedVersion = undefined, otaConfigCore = undefined, blindPeerKeys = undefined, blindPeeringOpts = undefined, fileGc = null, autoDownloadModels = undefined, meshSeed = undefined, meshKey = undefined, additionalNodes = undefined, listModels = undefined, deleteModel = undefined, clearKvCache = undefined, deleteChatKvCache = undefined, compactChat = undefined, modelCatalogWatch = undefined, retryModelDownload = undefined, transcribe = undefined, detectLanguage = undefined, previewModelSource = undefined, speak = undefined, speakStream = undefined, embedder = undefined, extractors = undefined, skills = undefined, skillCatalog = undefined, tools = undefined, hostsModelSource = false, vectorIndex = undefined, apiLifecycle = undefined, network = undefined }) {
|
|
247
262
|
super();
|
|
248
263
|
this._transport = transport;
|
|
249
264
|
this._apiLifecycle = apiLifecycle ?? {
|
|
@@ -269,6 +284,7 @@ export class Core extends ReadyResource {
|
|
|
269
284
|
this.state = QvacState.RESUME;
|
|
270
285
|
this._spec = spec;
|
|
271
286
|
this._bootstrapNodes = bootstrapNodes;
|
|
287
|
+
this._network = network;
|
|
272
288
|
this._device = device;
|
|
273
289
|
this._app = app;
|
|
274
290
|
this._minSupportedVersion = minSupportedVersion;
|
|
@@ -282,7 +298,6 @@ export class Core extends ReadyResource {
|
|
|
282
298
|
this._blindPeerKeys = blindPeerKeys;
|
|
283
299
|
this._blindPeeringOpts = blindPeeringOpts;
|
|
284
300
|
this._fileGc = fileGc;
|
|
285
|
-
this._syncPacing = { syncBatch, syncPauseMs };
|
|
286
301
|
this._autoDownloadModels = autoDownloadModels;
|
|
287
302
|
this._meshSeed = meshSeed;
|
|
288
303
|
this._meshKey = meshKey;
|
|
@@ -305,6 +320,7 @@ export class Core extends ReadyResource {
|
|
|
305
320
|
this._ragExtractors = extractors;
|
|
306
321
|
this._skills = skills ?? null;
|
|
307
322
|
this._skillCatalog = skillCatalog ?? null;
|
|
323
|
+
this._vaultManagedSkills = skillSecrets;
|
|
308
324
|
this._skillManagement = null;
|
|
309
325
|
this._tools = tools ?? null;
|
|
310
326
|
this._hostsModelSource = hostsModelSource;
|
|
@@ -344,8 +360,6 @@ export class Core extends ReadyResource {
|
|
|
344
360
|
this._servedToSiblings = null;
|
|
345
361
|
this._minting = false;
|
|
346
362
|
this._leaving = null;
|
|
347
|
-
this._kicked = false;
|
|
348
|
-
this._kickedPending = false;
|
|
349
363
|
this._peers = new Map();
|
|
350
364
|
this._statusListeners = new Set();
|
|
351
365
|
this._senderListeners = new Set();
|
|
@@ -384,6 +398,16 @@ export class Core extends ReadyResource {
|
|
|
384
398
|
return [...new Set(ids)].sort();
|
|
385
399
|
}
|
|
386
400
|
async _open() {
|
|
401
|
+
const { length: quarantined } = await this._offerQuarantined();
|
|
402
|
+
if (quarantined) {
|
|
403
|
+
this._log?.warn('lifecycle', 'skill values wait for the vault', { quarantined });
|
|
404
|
+
}
|
|
405
|
+
this._log?.info('lifecycle', 'core opening', {
|
|
406
|
+
app: this._app?.version ?? null,
|
|
407
|
+
build: this._app?.build ?? null,
|
|
408
|
+
channel: this._app?.channel ?? null,
|
|
409
|
+
schema: SCHEMA_VERSION
|
|
410
|
+
});
|
|
387
411
|
this._runBootOffline().catch(noop);
|
|
388
412
|
this._runBootOnline().catch(noop);
|
|
389
413
|
await this._offlineBoot.ready();
|
|
@@ -397,10 +421,17 @@ export class Core extends ReadyResource {
|
|
|
397
421
|
this._blindPeeringOn = (await this.local.get(BLIND_PEERING_OFF_KEY)) !== true;
|
|
398
422
|
this._localDevice = await this.local.ensureDevice(this._deviceKeyPair.publicKey, this._device);
|
|
399
423
|
await this.local.dropLeftMeshes();
|
|
400
|
-
await this._retireComputeMeshes();
|
|
401
424
|
for (const row of await this.local.meshNames()) {
|
|
402
425
|
this._meshNames.set(b4a.toHex(row.meshKey), row);
|
|
403
426
|
}
|
|
427
|
+
for (const row of await this.local.listMeshes()) {
|
|
428
|
+
if (row.kicked) {
|
|
429
|
+
this._kickedMeshes.add(b4a.toHex(row.key));
|
|
430
|
+
}
|
|
431
|
+
if (row.retiredUnder) {
|
|
432
|
+
this._retiredMeshes.add(b4a.toHex(row.key));
|
|
433
|
+
}
|
|
434
|
+
}
|
|
404
435
|
this._resumePurges().catch((err) => this._log?.warn(['p2p', 'mesh'], 'reading the interrupted purges failed', err));
|
|
405
436
|
if (this._autoDownloadModels !== undefined) {
|
|
406
437
|
await writeAutoDownloadModels(this.local, this._autoDownloadModels);
|
|
@@ -496,11 +527,18 @@ export class Core extends ReadyResource {
|
|
|
496
527
|
return workspaceId === this._ownWorkspaceId ? null : workspaceId;
|
|
497
528
|
},
|
|
498
529
|
pushSkillSecret: (request) => this.pushSkillSecret(request),
|
|
499
|
-
|
|
500
|
-
|
|
530
|
+
beforeConfigSet: (entry) => validateVaultManagedSkill(this._vaultManagedSkills, entry),
|
|
531
|
+
onConfigSet: async (entry) => {
|
|
532
|
+
if (entry.key.startsWith(SKILL_SECRET_PREFIX)) {
|
|
501
533
|
void this._followSkillSecrets();
|
|
534
|
+
await this._releaseQuarantined([entry]);
|
|
502
535
|
}
|
|
503
536
|
},
|
|
537
|
+
listQuarantinedSkills: async () => ({ keys: await quarantinedSkillKeys(this.local) }),
|
|
538
|
+
retryQuarantinedSkills: async () => ({ keys: await this._offerQuarantined() }),
|
|
539
|
+
discardQuarantinedSkills: async ({ keys }) => ({
|
|
540
|
+
keys: await this._discardQuarantined(keys)
|
|
541
|
+
}),
|
|
504
542
|
storageRoot: path.dirname(this._storagePath),
|
|
505
543
|
listModels: this._hostsModelSource || this._listModels
|
|
506
544
|
? async (request) => (await this._readModelList(request)) ?? { models: [] }
|
|
@@ -705,14 +743,6 @@ export class Core extends ReadyResource {
|
|
|
705
743
|
this._log?.error(['p2p', 'mesh'], 'mesh open failed', err);
|
|
706
744
|
}
|
|
707
745
|
}
|
|
708
|
-
async _retireComputeMeshes() {
|
|
709
|
-
for (const row of await this.local.listMeshes()) {
|
|
710
|
-
if (row.compute) {
|
|
711
|
-
await this._teardownMesh(row.key);
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
await this.local.deletePrefix(HELD_AGENTS_PREFIX);
|
|
715
|
-
}
|
|
716
746
|
async _runBootOnline() {
|
|
717
747
|
void this.onlineBoot.ready().catch(noop);
|
|
718
748
|
try {
|
|
@@ -889,6 +919,9 @@ export class Core extends ReadyResource {
|
|
|
889
919
|
if (withheld) {
|
|
890
920
|
void this._reopenMesh();
|
|
891
921
|
}
|
|
922
|
+
for (const { mesh } of this._meshes.values()) {
|
|
923
|
+
void this._backfillChatChunks(mesh);
|
|
924
|
+
}
|
|
892
925
|
return;
|
|
893
926
|
}
|
|
894
927
|
for (const { mesh } of [...this._meshes.values()]) {
|
|
@@ -1143,6 +1176,10 @@ export class Core extends ReadyResource {
|
|
|
1143
1176
|
bootstrap: this._bootstrapNodes,
|
|
1144
1177
|
relayThrough: this._bootstrapNodes ? undefined : () => BLIND_RELAY_KEYS
|
|
1145
1178
|
});
|
|
1179
|
+
const onConnection = this._network?.onConnection;
|
|
1180
|
+
if (onConnection) {
|
|
1181
|
+
this._swarm.on('connection', (conn) => onConnection(conn));
|
|
1182
|
+
}
|
|
1146
1183
|
this._swarm.on('connection', this._onSwarmConnection);
|
|
1147
1184
|
for (const conn of this._swarm.connections) {
|
|
1148
1185
|
if (isPeerConnection(conn)) {
|
|
@@ -1211,7 +1248,7 @@ export class Core extends ReadyResource {
|
|
|
1211
1248
|
this._joinProjectWhenListed(mesh, deviceId);
|
|
1212
1249
|
}
|
|
1213
1250
|
else {
|
|
1214
|
-
void this._appendJoinLater(mesh, () => this.
|
|
1251
|
+
void this._appendJoinLater(mesh, () => this._ownBirthMember(mesh, deviceId), sharing);
|
|
1215
1252
|
}
|
|
1216
1253
|
}
|
|
1217
1254
|
else {
|
|
@@ -1248,7 +1285,7 @@ export class Core extends ReadyResource {
|
|
|
1248
1285
|
attachmentUrl: (attachment) => this._linkAttachment(attachment, mesh),
|
|
1249
1286
|
fileIndex: this._fileIndexFor(() => mesh),
|
|
1250
1287
|
pendingUpdates: this._pendingUpdatesFor(() => mesh),
|
|
1251
|
-
|
|
1288
|
+
bootFrom: session.bootFrom
|
|
1252
1289
|
});
|
|
1253
1290
|
return mesh;
|
|
1254
1291
|
}
|
|
@@ -1578,6 +1615,20 @@ export class Core extends ReadyResource {
|
|
|
1578
1615
|
proof
|
|
1579
1616
|
};
|
|
1580
1617
|
}
|
|
1618
|
+
async _ownBirthMember(mesh, deviceId) {
|
|
1619
|
+
const account = this._accountMesh();
|
|
1620
|
+
while (account && account !== mesh && !account.ourMemberId) {
|
|
1621
|
+
if (this.closing || mesh.closing || account.closing) {
|
|
1622
|
+
return null;
|
|
1623
|
+
}
|
|
1624
|
+
await firstEvent([
|
|
1625
|
+
[account, 'membership'],
|
|
1626
|
+
[account, 'close'],
|
|
1627
|
+
[mesh, 'close']
|
|
1628
|
+
]);
|
|
1629
|
+
}
|
|
1630
|
+
return this._knownBirthMember(mesh, deviceId);
|
|
1631
|
+
}
|
|
1581
1632
|
async _knownBirthMember(mesh, deviceId, given) {
|
|
1582
1633
|
if (!this._localDevice || mesh.localLength > 0)
|
|
1583
1634
|
return null;
|
|
@@ -1696,6 +1747,11 @@ export class Core extends ReadyResource {
|
|
|
1696
1747
|
if (this._swarm) {
|
|
1697
1748
|
if (announce) {
|
|
1698
1749
|
this._swarm.join(mesh.discoveryKey, { server: true, client: true });
|
|
1750
|
+
this._network?.onMeshTopic?.({
|
|
1751
|
+
meshId: this._meshIdOf(mesh),
|
|
1752
|
+
topic: mesh.discoveryKey,
|
|
1753
|
+
swarm: this._swarm
|
|
1754
|
+
});
|
|
1699
1755
|
}
|
|
1700
1756
|
this._startBlindPeering(mesh);
|
|
1701
1757
|
if (this.suspended) {
|
|
@@ -1881,10 +1937,20 @@ export class Core extends ReadyResource {
|
|
|
1881
1937
|
}
|
|
1882
1938
|
}
|
|
1883
1939
|
async _knownMember(exclude) {
|
|
1884
|
-
|
|
1885
|
-
|
|
1940
|
+
const account = this._accountMesh();
|
|
1941
|
+
if (account && account !== exclude && account.ourMemberId) {
|
|
1942
|
+
const known = await this._memberIn(account).catch(noop);
|
|
1943
|
+
if (known) {
|
|
1944
|
+
return known;
|
|
1945
|
+
}
|
|
1946
|
+
}
|
|
1947
|
+
for (const { mesh } of this._meshes.values()) {
|
|
1948
|
+
if (mesh === exclude ||
|
|
1949
|
+
!mesh.ourMemberId ||
|
|
1950
|
+
this._isHidden(this._meshIdOf(mesh), mesh.workspaceKey)) {
|
|
1886
1951
|
continue;
|
|
1887
|
-
|
|
1952
|
+
}
|
|
1953
|
+
const known = await this._memberIn(mesh).catch(noop);
|
|
1888
1954
|
if (known) {
|
|
1889
1955
|
return known;
|
|
1890
1956
|
}
|
|
@@ -1943,22 +2009,21 @@ export class Core extends ReadyResource {
|
|
|
1943
2009
|
async _ensureNotRevoked(mesh) {
|
|
1944
2010
|
const wasAccount = this._isAccount(mesh);
|
|
1945
2011
|
try {
|
|
1946
|
-
|
|
2012
|
+
let revocation = await mesh.checkResumedRevocation();
|
|
2013
|
+
if (!revocation && (await mesh.checkResumedRefusal())) {
|
|
2014
|
+
revocation = 'kicked';
|
|
2015
|
+
}
|
|
1947
2016
|
if (!revocation || !this._isPooled(mesh)) {
|
|
1948
2017
|
return;
|
|
1949
2018
|
}
|
|
1950
|
-
if (
|
|
1951
|
-
|
|
1952
|
-
return;
|
|
1953
|
-
}
|
|
1954
|
-
this._log?.info(['p2p', 'mesh'], 'a sibling mesh kicked this device, closing it');
|
|
1955
|
-
await this._departKicked(mesh);
|
|
2019
|
+
if (revocation === 'kicked') {
|
|
2020
|
+
await this._reviewKick(mesh);
|
|
1956
2021
|
return;
|
|
1957
2022
|
}
|
|
1958
|
-
this.
|
|
1959
|
-
|
|
1960
|
-
this._kickedPending = true;
|
|
2023
|
+
if (!wasAccount || !this._isAccount(mesh)) {
|
|
2024
|
+
return;
|
|
1961
2025
|
}
|
|
2026
|
+
this._log?.info(['p2p', 'mesh'], 'resumed onto our own leave, replacing the account');
|
|
1962
2027
|
await this._replaceRevokedAccount(mesh);
|
|
1963
2028
|
}
|
|
1964
2029
|
catch (err) {
|
|
@@ -1997,7 +2062,17 @@ export class Core extends ReadyResource {
|
|
|
1997
2062
|
await this._retireMesh(mesh);
|
|
1998
2063
|
}
|
|
1999
2064
|
}
|
|
2000
|
-
|
|
2065
|
+
_teardownMesh(target, opts = {}) {
|
|
2066
|
+
const meshId = b4a.toHex(b4a.isBuffer(target) ? target : target.key);
|
|
2067
|
+
const teardown = this._tearDown(target, opts).finally(() => {
|
|
2068
|
+
if (this._tearingDown.get(meshId) === teardown) {
|
|
2069
|
+
this._tearingDown.delete(meshId);
|
|
2070
|
+
}
|
|
2071
|
+
});
|
|
2072
|
+
this._tearingDown.set(meshId, teardown);
|
|
2073
|
+
return teardown;
|
|
2074
|
+
}
|
|
2075
|
+
async _tearDown(target, { depart = false, purge = false }) {
|
|
2001
2076
|
const key = b4a.isBuffer(target) ? target : target.key;
|
|
2002
2077
|
const mesh = b4a.isBuffer(target) ? this._pooled(b4a.toHex(key)) : target;
|
|
2003
2078
|
if (mesh && depart) {
|
|
@@ -2013,6 +2088,7 @@ export class Core extends ReadyResource {
|
|
|
2013
2088
|
finally {
|
|
2014
2089
|
await this.local.dropMesh(key, { keepDeparture: true, cores });
|
|
2015
2090
|
this._meshNames.delete(b4a.toHex(key));
|
|
2091
|
+
this._kickedMeshes.delete(b4a.toHex(key));
|
|
2016
2092
|
this._notifyStatus();
|
|
2017
2093
|
}
|
|
2018
2094
|
if (cores) {
|
|
@@ -2050,27 +2126,217 @@ export class Core extends ReadyResource {
|
|
|
2050
2126
|
this._log?.warn(['p2p', 'mesh'], 'retiring the stalled mesh failed', retireErr);
|
|
2051
2127
|
});
|
|
2052
2128
|
}
|
|
2053
|
-
|
|
2054
|
-
|
|
2129
|
+
async _reviewKick(mesh) {
|
|
2130
|
+
const entry = this._meshes.get(this._meshIdOf(mesh));
|
|
2131
|
+
if (entry?.mesh !== mesh || !(await entry.kickLock.lock())) {
|
|
2055
2132
|
return;
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
this.
|
|
2133
|
+
}
|
|
2134
|
+
try {
|
|
2135
|
+
const kicked = await this._readKick(mesh).catch(noop);
|
|
2136
|
+
const id = this._meshIdOf(mesh);
|
|
2137
|
+
if (kicked === undefined || this.closing || !this._isPooled(mesh)) {
|
|
2138
|
+
return;
|
|
2139
|
+
}
|
|
2140
|
+
if (kicked && !this._kickedMeshes.has(id)) {
|
|
2141
|
+
await this._onKicked(mesh);
|
|
2142
|
+
}
|
|
2143
|
+
else if (!kicked && this._retiredAccount === id) {
|
|
2144
|
+
await this._onKickVoided(mesh);
|
|
2145
|
+
}
|
|
2146
|
+
}
|
|
2147
|
+
catch (err) {
|
|
2148
|
+
this._log?.warn(['p2p', 'mesh'], 'reviewing our kick failed', err);
|
|
2149
|
+
}
|
|
2150
|
+
finally {
|
|
2151
|
+
entry.kickLock.unlock();
|
|
2152
|
+
}
|
|
2153
|
+
}
|
|
2154
|
+
async _onKicked(mesh) {
|
|
2155
|
+
if (!(await this._kickOutlivesTransition(mesh))) {
|
|
2156
|
+
return;
|
|
2157
|
+
}
|
|
2158
|
+
const id = this._meshIdOf(mesh);
|
|
2159
|
+
this._log?.info(['p2p', 'mesh'], 'our writer was revoked (kicked)');
|
|
2160
|
+
this._kickedMeshes.add(id);
|
|
2161
|
+
if (this._isAccount(mesh)) {
|
|
2162
|
+
this._kickNotice = true;
|
|
2163
|
+
await this._retireKickedAccount(mesh);
|
|
2164
|
+
return;
|
|
2165
|
+
}
|
|
2166
|
+
const closing = this._noteKickedProject(mesh)
|
|
2167
|
+
.then(() => this._closeKicked(mesh))
|
|
2168
|
+
.catch((err) => this._log?.warn(['p2p', 'mesh'], 'closing a kicked mesh failed', err))
|
|
2169
|
+
.finally(() => this._kickCloses.delete(id));
|
|
2170
|
+
this._kickCloses.set(id, closing);
|
|
2171
|
+
this._notifyStatus();
|
|
2172
|
+
}
|
|
2173
|
+
async _kickOutlivesTransition(mesh) {
|
|
2174
|
+
if (!(await this._meshTransitionLock.lock())) {
|
|
2175
|
+
return false;
|
|
2176
|
+
}
|
|
2177
|
+
try {
|
|
2178
|
+
const kicked = await this._readKick(mesh).catch(noop);
|
|
2179
|
+
return kicked === true && !this.closing && this._isPooled(mesh);
|
|
2180
|
+
}
|
|
2181
|
+
finally {
|
|
2182
|
+
this._meshTransitionLock.unlock();
|
|
2183
|
+
}
|
|
2184
|
+
}
|
|
2185
|
+
async _onKickVoided(account) {
|
|
2186
|
+
this._log?.info(['p2p', 'mesh'], 'our kick was voided');
|
|
2187
|
+
this._kickedMeshes.delete(this._meshIdOf(account));
|
|
2188
|
+
this._kickNotice = false;
|
|
2189
|
+
this._notifyStatus();
|
|
2190
|
+
await this._restoreAccount(account);
|
|
2191
|
+
}
|
|
2192
|
+
async _readKick(mesh) {
|
|
2193
|
+
return (await mesh.readKicked()) || (await this._removedAsMember(mesh));
|
|
2194
|
+
}
|
|
2195
|
+
async _removedAsMember(mesh) {
|
|
2196
|
+
if (mesh.role !== 'workspace' || mesh.writable) {
|
|
2197
|
+
return false;
|
|
2198
|
+
}
|
|
2199
|
+
if ((await this.local.meshRecord(mesh.key))?.awaitingAdmission) {
|
|
2200
|
+
return false;
|
|
2201
|
+
}
|
|
2202
|
+
const account = this._accountMesh();
|
|
2203
|
+
const joined = await account?.view.get(JOINED_MESHES, { meshKey: mesh.key });
|
|
2204
|
+
const ours = account?.ourMemberId;
|
|
2205
|
+
if (!joined || joined.leftAt || !ours || !b4a.equals(joined.memberId, ours)) {
|
|
2206
|
+
return false;
|
|
2207
|
+
}
|
|
2208
|
+
const devices = await devicesOfMember(mesh.view, joined.memberId);
|
|
2209
|
+
return devices.length > 0 && devices.every((device) => device.revoked);
|
|
2210
|
+
}
|
|
2211
|
+
async _followKick(meshId, held) {
|
|
2212
|
+
if (this._kickedMeshes.has(meshId)) {
|
|
2213
|
+
return;
|
|
2214
|
+
}
|
|
2215
|
+
const key = b4a.from(meshId, 'hex');
|
|
2216
|
+
if (!held && !(await this.local.readMeshSession(key))) {
|
|
2217
|
+
return;
|
|
2218
|
+
}
|
|
2219
|
+
this._kickedMeshes.add(meshId);
|
|
2220
|
+
if (held) {
|
|
2221
|
+
await this._closeKicked(held);
|
|
2059
2222
|
return;
|
|
2060
2223
|
}
|
|
2061
|
-
this.
|
|
2062
|
-
this.
|
|
2063
|
-
|
|
2064
|
-
|
|
2224
|
+
await this.local.markKicked(key);
|
|
2225
|
+
for (const row of await this._projectRowsOf(key)) {
|
|
2226
|
+
this._kickedMeshes.add(b4a.toHex(row.key));
|
|
2227
|
+
await this.local.markKicked(row.key);
|
|
2228
|
+
}
|
|
2229
|
+
this._notifyStatus();
|
|
2230
|
+
}
|
|
2231
|
+
async _markJoinedKicked(meshKey) {
|
|
2232
|
+
const registry = await this._writableAccount();
|
|
2233
|
+
const joined = await registry?.view.get(JOINED_MESHES, { meshKey });
|
|
2234
|
+
if (!registry || !joined || joined.kicked || joined.leftAt) {
|
|
2235
|
+
return;
|
|
2236
|
+
}
|
|
2237
|
+
const joinedUnder = await this.local.joinedUnder(meshKey);
|
|
2238
|
+
if (joinedUnder !== null && joined.joinedAt > joinedUnder) {
|
|
2239
|
+
return;
|
|
2240
|
+
}
|
|
2241
|
+
await registry.dispatch('put-joined-mesh', { room: { ...joined, kicked: true } });
|
|
2242
|
+
}
|
|
2243
|
+
async _closeKicked(mesh) {
|
|
2244
|
+
if (await this._removedAsMember(mesh)) {
|
|
2245
|
+
await this._markJoinedKicked(mesh.key);
|
|
2246
|
+
}
|
|
2247
|
+
const projects = mesh.role === 'workspace' ? await this._projectRowsOf(mesh.key) : [];
|
|
2248
|
+
for (const row of [{ key: mesh.key }, ...projects]) {
|
|
2249
|
+
this._kickedMeshes.add(b4a.toHex(row.key));
|
|
2250
|
+
await this.local.markKicked(row.key);
|
|
2251
|
+
const pooled = this._pooled(b4a.toHex(row.key));
|
|
2252
|
+
if (pooled) {
|
|
2253
|
+
await this._retirePooledMesh(pooled);
|
|
2254
|
+
}
|
|
2255
|
+
}
|
|
2256
|
+
this._notifyStatus();
|
|
2257
|
+
const account = this._accountMesh();
|
|
2258
|
+
if (account && account !== mesh) {
|
|
2259
|
+
void this._followJoinedMeshes(account);
|
|
2260
|
+
}
|
|
2261
|
+
}
|
|
2262
|
+
async _projectRowsOf(workspaceKey) {
|
|
2263
|
+
return (await this.local.listMeshes()).filter((row) => row.workspaceKey && b4a.equals(row.workspaceKey, workspaceKey));
|
|
2264
|
+
}
|
|
2265
|
+
_isHidden(meshId, workspaceKey) {
|
|
2266
|
+
if (meshId === this._accountId) {
|
|
2267
|
+
return false;
|
|
2268
|
+
}
|
|
2269
|
+
if (this._kickedMeshes.has(meshId) || this._retiredMeshes.has(meshId)) {
|
|
2270
|
+
return true;
|
|
2271
|
+
}
|
|
2272
|
+
return !!workspaceKey && this._kickedMeshes.has(b4a.toHex(workspaceKey));
|
|
2273
|
+
}
|
|
2274
|
+
async _retireKickedAccount(account) {
|
|
2275
|
+
this._minting = true;
|
|
2276
|
+
this._notifyStatus();
|
|
2277
|
+
try {
|
|
2278
|
+
const retired = (await this.local.listMeshes()).filter((row) => !b4a.equals(row.key, account.key));
|
|
2279
|
+
for (const row of retired) {
|
|
2280
|
+
this._retiredMeshes.add(b4a.toHex(row.key));
|
|
2281
|
+
}
|
|
2282
|
+
await this.local.markRetired(retired.map((row) => row.key), account.key);
|
|
2283
|
+
this._retiredAccount = this._meshIdOf(account);
|
|
2284
|
+
await this._archiveMembership(account);
|
|
2285
|
+
await this._rotatePublicWriters(account);
|
|
2286
|
+
this._accountId = null;
|
|
2287
|
+
this._ownWorkspaceId = null;
|
|
2288
|
+
}
|
|
2289
|
+
finally {
|
|
2290
|
+
this._minting = false;
|
|
2291
|
+
}
|
|
2292
|
+
await this._requestFreshMesh();
|
|
2293
|
+
}
|
|
2294
|
+
async _restoreAccount(account) {
|
|
2295
|
+
if (this._minting) {
|
|
2296
|
+
await this._waitForMeshChange();
|
|
2297
|
+
}
|
|
2298
|
+
const fresh = this._accountMesh();
|
|
2299
|
+
if (this.closing ||
|
|
2300
|
+
!this._isPooled(account) ||
|
|
2301
|
+
this._retiredAccount !== this._meshIdOf(account)) {
|
|
2302
|
+
return;
|
|
2303
|
+
}
|
|
2304
|
+
this._retiredAccount = null;
|
|
2305
|
+
this._retiredMeshes.clear();
|
|
2306
|
+
await this.local.restoreMesh(account.key);
|
|
2307
|
+
await this._restorePublicWriters(account);
|
|
2308
|
+
await this._adoptAccount(account);
|
|
2309
|
+
if (fresh && fresh !== account) {
|
|
2310
|
+
await this._dropOwnMint(fresh);
|
|
2311
|
+
await this._teardownMesh(fresh, { purge: true });
|
|
2312
|
+
}
|
|
2313
|
+
}
|
|
2314
|
+
async _dropOwnMint(fresh) {
|
|
2315
|
+
const seed = ownWorkspaceSeed(fresh.seed);
|
|
2316
|
+
for (const row of await this.local.listMeshes()) {
|
|
2317
|
+
if (!b4a.equals(row.seed, seed)) {
|
|
2318
|
+
continue;
|
|
2319
|
+
}
|
|
2320
|
+
const id = b4a.toHex(row.key);
|
|
2321
|
+
const own = this._publicMesh(id);
|
|
2322
|
+
if (own) {
|
|
2323
|
+
await this._teardownMesh(own, { purge: true });
|
|
2324
|
+
}
|
|
2325
|
+
await this._teardownMesh(this._pooled(id) ?? (await this._openPooledMesh(id, 'leave')), {
|
|
2326
|
+
purge: true
|
|
2327
|
+
});
|
|
2328
|
+
}
|
|
2065
2329
|
}
|
|
2066
2330
|
async _replaceRevokedAccount(mesh) {
|
|
2067
2331
|
this._minting = true;
|
|
2068
2332
|
this._notifyStatus();
|
|
2069
2333
|
try {
|
|
2334
|
+
await this._leaveKicked(mesh);
|
|
2070
2335
|
await this._departAllBut(mesh);
|
|
2071
2336
|
if (this.closing) {
|
|
2072
2337
|
return;
|
|
2073
2338
|
}
|
|
2339
|
+
await this._leavePublicMesh(mesh);
|
|
2074
2340
|
await this._archiveMembership(mesh);
|
|
2075
2341
|
}
|
|
2076
2342
|
finally {
|
|
@@ -2078,21 +2344,56 @@ export class Core extends ReadyResource {
|
|
|
2078
2344
|
}
|
|
2079
2345
|
await this._requestFreshMesh();
|
|
2080
2346
|
}
|
|
2347
|
+
async _leaveKicked(mesh) {
|
|
2348
|
+
try {
|
|
2349
|
+
await mesh.dispatch('remove-writer', {
|
|
2350
|
+
writerKey: mesh.localWriterKey,
|
|
2351
|
+
deviceId: this._requireDeviceKeyPair().publicKey,
|
|
2352
|
+
revokedAt: Date.now()
|
|
2353
|
+
}, { optimistic: true });
|
|
2354
|
+
await this.local.recordDeparture(mesh.key, { creator: mesh.minted });
|
|
2355
|
+
}
|
|
2356
|
+
catch (err) {
|
|
2357
|
+
this._log?.warn(['p2p', 'mesh'], 'writing our own leave after a kick failed', err);
|
|
2358
|
+
}
|
|
2359
|
+
}
|
|
2081
2360
|
async _departKicked(mesh) {
|
|
2082
2361
|
const ours = mesh.ourMemberId;
|
|
2083
2362
|
if (ours && mesh.role === 'workspace' && !(await liveMember(mesh.view, ours))) {
|
|
2084
|
-
await this._releaseJoinedMesh(mesh.key);
|
|
2363
|
+
await this._releaseJoinedMesh(mesh.key, undefined, await this.local.joinedUnder(mesh.key));
|
|
2085
2364
|
}
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
const record = await this.local.meshRecord(mesh.key);
|
|
2089
|
-
const workspace = record?.workspaceKey ? this._pooled(b4a.toHex(record.workspaceKey)) : null;
|
|
2090
|
-
const row = await workspace?.view.get(PROJECTS, { id: mesh.key });
|
|
2091
|
-
this._kickedProjects.set(this._meshIdOf(mesh), row && listsMember(row, ours) ? workspace : null);
|
|
2092
|
-
purge = record?.role === 'project' && !!record.workspaceKey;
|
|
2365
|
+
if (mesh.role === 'workspace') {
|
|
2366
|
+
await this._departProjectsOf(mesh);
|
|
2093
2367
|
}
|
|
2368
|
+
await this._noteKickedProject(mesh);
|
|
2369
|
+
const record = await this.local.meshRecord(mesh.key);
|
|
2370
|
+
const purge = record?.role === 'project' && !!record.workspaceKey;
|
|
2094
2371
|
await this._departRevokedMesh(mesh, { purge });
|
|
2095
2372
|
}
|
|
2373
|
+
async _noteKickedProject(mesh) {
|
|
2374
|
+
const ours = mesh.ourMemberId;
|
|
2375
|
+
if (!ours || mesh.role !== 'project' || (await inProject(mesh.view, ours))) {
|
|
2376
|
+
return false;
|
|
2377
|
+
}
|
|
2378
|
+
const record = await this.local.meshRecord(mesh.key);
|
|
2379
|
+
const workspace = record?.workspaceKey ? this._pooled(b4a.toHex(record.workspaceKey)) : null;
|
|
2380
|
+
const row = await workspace?.view.get(PROJECTS, { id: mesh.key });
|
|
2381
|
+
this._kickedProjects.set(this._meshIdOf(mesh), row && listsMember(row, ours) ? workspace : null);
|
|
2382
|
+
return record?.role === 'project' && !!record.workspaceKey;
|
|
2383
|
+
}
|
|
2384
|
+
async _departProjectsOf(workspace) {
|
|
2385
|
+
for (const row of await this.local.listMeshes()) {
|
|
2386
|
+
const ofWorkspace = row.workspaceKey && b4a.equals(row.workspaceKey, workspace.key);
|
|
2387
|
+
if (this.closing || !ofWorkspace || recordedRole(row) !== 'project') {
|
|
2388
|
+
continue;
|
|
2389
|
+
}
|
|
2390
|
+
this._kickedProjects.set(b4a.toHex(row.key), null);
|
|
2391
|
+
const project = await this._heldMesh(row.key, 'leave');
|
|
2392
|
+
await (project
|
|
2393
|
+
? this._departRevokedMesh(project, { purge: true })
|
|
2394
|
+
: this._teardownMesh(row.key));
|
|
2395
|
+
}
|
|
2396
|
+
}
|
|
2096
2397
|
async _departRevokedMesh(mesh, opts = {}) {
|
|
2097
2398
|
const account = this._accountMesh();
|
|
2098
2399
|
if (this._isOwnPublic(mesh) && mesh.workspaceKey && account) {
|
|
@@ -2164,9 +2465,6 @@ export class Core extends ReadyResource {
|
|
|
2164
2465
|
if (!invite) {
|
|
2165
2466
|
throw new CoreError('INVITE_INVALID');
|
|
2166
2467
|
}
|
|
2167
|
-
if (invite.compute) {
|
|
2168
|
-
throw new CoreError('COMPUTE_MESH_RETIRED');
|
|
2169
|
-
}
|
|
2170
2468
|
await this._awaitMesh();
|
|
2171
2469
|
this._requireLocalDevice();
|
|
2172
2470
|
await this._meshTransitionLock.lock();
|
|
@@ -2178,8 +2476,24 @@ export class Core extends ReadyResource {
|
|
|
2178
2476
|
if (this._leaving || this._minting) {
|
|
2179
2477
|
throw new CoreError('MESH_TRANSITION_IN_PROGRESS');
|
|
2180
2478
|
}
|
|
2181
|
-
|
|
2182
|
-
|
|
2479
|
+
const meshId = b4a.toHex(invite.baseKey);
|
|
2480
|
+
await this._tearingDown.get(meshId)?.catch(noop);
|
|
2481
|
+
await this._opening.get(meshId)?.catch(noop);
|
|
2482
|
+
await this._kickCloses.get(meshId);
|
|
2483
|
+
const workspaceKey = this._pooled(meshId)?.workspaceKey;
|
|
2484
|
+
if (workspaceKey) {
|
|
2485
|
+
await this._kickCloses.get(b4a.toHex(workspaceKey));
|
|
2486
|
+
}
|
|
2487
|
+
let pooled = this._pooled(meshId);
|
|
2488
|
+
if (this._isHidden(meshId, pooled?.workspaceKey)) {
|
|
2489
|
+
if (pooled) {
|
|
2490
|
+
await this._teardownMesh(pooled, { depart: true, purge: true });
|
|
2491
|
+
}
|
|
2492
|
+
else {
|
|
2493
|
+
await this._dropKickedCopy(meshId);
|
|
2494
|
+
}
|
|
2495
|
+
pooled = null;
|
|
2496
|
+
}
|
|
2183
2497
|
if (pooled?.writable) {
|
|
2184
2498
|
if (!invite.memberInvite && !this._isAccount(pooled)) {
|
|
2185
2499
|
await this._adoptAccount(pooled);
|
|
@@ -2262,6 +2576,7 @@ export class Core extends ReadyResource {
|
|
|
2262
2576
|
if (retire) {
|
|
2263
2577
|
await this._retirePooledMesh(retire);
|
|
2264
2578
|
}
|
|
2579
|
+
await this._purging.get(meshId)?.catch(noop);
|
|
2265
2580
|
await this._runJoinMesh(invite, claim);
|
|
2266
2581
|
}
|
|
2267
2582
|
catch (error) {
|
|
@@ -2315,6 +2630,9 @@ export class Core extends ReadyResource {
|
|
|
2315
2630
|
for (const node of invite.additionalNodes ?? []) {
|
|
2316
2631
|
this._swarm?.dht.addNode(node);
|
|
2317
2632
|
}
|
|
2633
|
+
if (!invite.memberInvite) {
|
|
2634
|
+
this._publicBoots = new Map((invite.publicHeads ?? []).map(({ meshKey, head }) => [b4a.toHex(meshKey), head]));
|
|
2635
|
+
}
|
|
2318
2636
|
await this._departures?.park(invite.baseKey);
|
|
2319
2637
|
try {
|
|
2320
2638
|
await this._joinParkedMesh(invite, claim, { source, deviceId });
|
|
@@ -2332,9 +2650,9 @@ export class Core extends ReadyResource {
|
|
|
2332
2650
|
claim.reject(new CoreError('MESH_BELOW_FLOOR'));
|
|
2333
2651
|
}
|
|
2334
2652
|
}
|
|
2335
|
-
_candidateSession({ seed, baseKey, workspace }) {
|
|
2653
|
+
_candidateSession({ seed, baseKey, workspace, fastForward }) {
|
|
2336
2654
|
const role = workspace ? 'workspace' : undefined;
|
|
2337
|
-
return this.local.createCandidateSession(seed, baseKey, { role });
|
|
2655
|
+
return { ...this.local.createCandidateSession(seed, baseKey, { role }), bootFrom: fastForward };
|
|
2338
2656
|
}
|
|
2339
2657
|
async _joinCandidate(invite, source, deviceId) {
|
|
2340
2658
|
const session = this._candidateSession(invite);
|
|
@@ -2523,7 +2841,14 @@ export class Core extends ReadyResource {
|
|
|
2523
2841
|
}
|
|
2524
2842
|
const buckets = await this._groupBuckets(workspace);
|
|
2525
2843
|
const rows = await projectsByGroup(workspace.view);
|
|
2526
|
-
const
|
|
2844
|
+
const passes = await Promise.allSettled(buckets.map((bucket) => this._passGroup(workspace, ours, { bucket, row: rows.get(bucket.groupId) ?? null })));
|
|
2845
|
+
const settled = [];
|
|
2846
|
+
for (const pass of passes) {
|
|
2847
|
+
if (pass.status === 'rejected') {
|
|
2848
|
+
throw pass.reason;
|
|
2849
|
+
}
|
|
2850
|
+
settled.push(pass.value);
|
|
2851
|
+
}
|
|
2527
2852
|
if (settled.every((state) => state === 'done') && this._isPooled(workspace)) {
|
|
2528
2853
|
await this.local.set(upgradeCheckedKey(workspace.key), true);
|
|
2529
2854
|
}
|
|
@@ -2668,8 +2993,8 @@ export class Core extends ReadyResource {
|
|
|
2668
2993
|
await this._following.get(projectId);
|
|
2669
2994
|
}
|
|
2670
2995
|
const winner = this._pooled(projectId) ?? (await this._heldMesh(row.id));
|
|
2671
|
-
await winner?.waitForWritable();
|
|
2672
|
-
return winner;
|
|
2996
|
+
await winner?.waitForWritable(WINNER_ADMISSION_WAIT_MS);
|
|
2997
|
+
return winner?.writable ? winner : null;
|
|
2673
2998
|
}
|
|
2674
2999
|
async _copyGroup(workspace, project, { chats }) {
|
|
2675
3000
|
const deviceId = this._requireDeviceKeyPair().publicKey;
|
|
@@ -2695,7 +3020,7 @@ export class Core extends ReadyResource {
|
|
|
2695
3020
|
await workspace.dispatch('set-project-listing', { projectId: row.id, memberId });
|
|
2696
3021
|
}
|
|
2697
3022
|
}
|
|
2698
|
-
if (added.length > 0) {
|
|
3023
|
+
if (added.length > 0 && this._isPooled(workspace)) {
|
|
2699
3024
|
const listedMembers = [...listed, ...added.map((id) => b4a.toHex(id))];
|
|
2700
3025
|
await this.local.set(recordKey, { ...record, listedMembers });
|
|
2701
3026
|
}
|
|
@@ -2773,7 +3098,7 @@ export class Core extends ReadyResource {
|
|
|
2773
3098
|
const { shared, workspace = false } = opts;
|
|
2774
3099
|
const registry = opts.registry ?? (await this._writableAccount());
|
|
2775
3100
|
const ours = registry?.ourMemberId;
|
|
2776
|
-
if (!registry || !ours) {
|
|
3101
|
+
if (!registry || !ours || this._isHidden(b4a.toHex(meshKey))) {
|
|
2777
3102
|
return;
|
|
2778
3103
|
}
|
|
2779
3104
|
const now = Date.now();
|
|
@@ -2787,6 +3112,7 @@ export class Core extends ReadyResource {
|
|
|
2787
3112
|
workspace
|
|
2788
3113
|
}
|
|
2789
3114
|
});
|
|
3115
|
+
await this.local.markJoinedUnder(meshKey, now);
|
|
2790
3116
|
await this._backfillMeshSeeds(registry).catch((err) => {
|
|
2791
3117
|
this._log?.warn(['p2p', 'mesh'], 'writing the mesh seed failed; writable or settle retries', err);
|
|
2792
3118
|
});
|
|
@@ -2818,7 +3144,9 @@ export class Core extends ReadyResource {
|
|
|
2818
3144
|
const registered = new Set();
|
|
2819
3145
|
const now = Date.now();
|
|
2820
3146
|
for (const row of await this.local.listMeshes()) {
|
|
2821
|
-
if (b4a.equals(row.key, account.key) ||
|
|
3147
|
+
if (b4a.equals(row.key, account.key) ||
|
|
3148
|
+
row.workspaceKey ||
|
|
3149
|
+
this._isHidden(b4a.toHex(row.key))) {
|
|
2822
3150
|
continue;
|
|
2823
3151
|
}
|
|
2824
3152
|
const held = await account.view.get(JOINED_MESHES, { meshKey: row.key });
|
|
@@ -2833,9 +3161,10 @@ export class Core extends ReadyResource {
|
|
|
2833
3161
|
joinedAt: now,
|
|
2834
3162
|
shared: false,
|
|
2835
3163
|
sharedAt: 0,
|
|
2836
|
-
workspace: !!pooled && (await isWorkspace(pooled.view))
|
|
3164
|
+
workspace: row.role === 'workspace' || (!!pooled && (await isWorkspace(pooled.view)))
|
|
2837
3165
|
}
|
|
2838
3166
|
});
|
|
3167
|
+
await this.local.markJoinedUnder(row.key, now);
|
|
2839
3168
|
registered.add(b4a.toHex(row.key));
|
|
2840
3169
|
}
|
|
2841
3170
|
return registered;
|
|
@@ -2853,7 +3182,7 @@ export class Core extends ReadyResource {
|
|
|
2853
3182
|
const held = await account.view.get(MESH_SEEDS, { meshKey: mesh.key });
|
|
2854
3183
|
return !held || !b4a.equals(held.seed, mesh.seed);
|
|
2855
3184
|
}
|
|
2856
|
-
async _releaseJoinedMesh(meshKey, registry) {
|
|
3185
|
+
async _releaseJoinedMesh(meshKey, registry, joinedUnder) {
|
|
2857
3186
|
try {
|
|
2858
3187
|
const held = registry ? [registry] : [...this._meshes.values()].map((entry) => entry.mesh);
|
|
2859
3188
|
for (const mesh of held) {
|
|
@@ -2866,7 +3195,12 @@ export class Core extends ReadyResource {
|
|
|
2866
3195
|
continue;
|
|
2867
3196
|
}
|
|
2868
3197
|
await mesh.dispatch('put-joined-mesh', {
|
|
2869
|
-
room: {
|
|
3198
|
+
room: {
|
|
3199
|
+
meshKey,
|
|
3200
|
+
memberId: ours,
|
|
3201
|
+
joinedAt: joinedUnder ?? joined.joinedAt,
|
|
3202
|
+
leftAt: Date.now()
|
|
3203
|
+
}
|
|
2870
3204
|
});
|
|
2871
3205
|
return;
|
|
2872
3206
|
}
|
|
@@ -2906,13 +3240,12 @@ export class Core extends ReadyResource {
|
|
|
2906
3240
|
writerSeed: session.writerSeed,
|
|
2907
3241
|
logger: this._log,
|
|
2908
3242
|
blindPeerKeys: this._resolveBlindPeerKeys(invite.blindPeers),
|
|
2909
|
-
bootFrom:
|
|
3243
|
+
bootFrom: session.bootFrom,
|
|
2910
3244
|
trustedDevice: (deviceId) => this._isOurMemberDevice(deviceId),
|
|
2911
3245
|
wakeup: this._wakeup,
|
|
2912
3246
|
attachmentUrl: (attachment) => this._linkAttachment(attachment, candidate),
|
|
2913
3247
|
fileIndex: this._fileIndexFor(() => candidate),
|
|
2914
|
-
pendingUpdates: this._pendingUpdatesFor(() => candidate)
|
|
2915
|
-
...this._syncPacing
|
|
3248
|
+
pendingUpdates: this._pendingUpdatesFor(() => candidate)
|
|
2916
3249
|
});
|
|
2917
3250
|
this._candidateMesh = candidate;
|
|
2918
3251
|
if (this._swarm) {
|
|
@@ -3017,7 +3350,6 @@ export class Core extends ReadyResource {
|
|
|
3017
3350
|
this._onProjectWritable(mesh);
|
|
3018
3351
|
this._onSharedWritable(mesh);
|
|
3019
3352
|
if (this._isAccount(mesh)) {
|
|
3020
|
-
this._kicked = false;
|
|
3021
3353
|
void this._followPublicMesh(mesh);
|
|
3022
3354
|
void this._followSkillSecrets();
|
|
3023
3355
|
}
|
|
@@ -3065,7 +3397,7 @@ export class Core extends ReadyResource {
|
|
|
3065
3397
|
peer: () => this._notifyStatus()
|
|
3066
3398
|
};
|
|
3067
3399
|
entry.handlers = handlers;
|
|
3068
|
-
mesh.on('
|
|
3400
|
+
mesh.on('kick-dirty', () => this._reviewKick(mesh).catch((err) => this._log?.warn(['p2p', 'mesh'], 'reviewing a kick failed', err)));
|
|
3069
3401
|
mesh.on('unattested-device', () => void this._settleMembership(mesh));
|
|
3070
3402
|
if (mesh.writable) {
|
|
3071
3403
|
this._onMeshSeedDue(mesh);
|
|
@@ -3078,6 +3410,7 @@ export class Core extends ReadyResource {
|
|
|
3078
3410
|
}
|
|
3079
3411
|
});
|
|
3080
3412
|
mesh.on('members-dirty', () => void this._deviceControl.revalidate());
|
|
3413
|
+
mesh.on('members-dirty', () => void this._revokeInMeshes());
|
|
3081
3414
|
mesh.on('members-dirty', () => {
|
|
3082
3415
|
if (mesh.role !== 'workspace')
|
|
3083
3416
|
return;
|
|
@@ -3106,30 +3439,15 @@ export class Core extends ReadyResource {
|
|
|
3106
3439
|
if (!this._isAccount(mesh))
|
|
3107
3440
|
return;
|
|
3108
3441
|
void this._followAccountName(mesh);
|
|
3109
|
-
void this._revokeInMeshes();
|
|
3110
|
-
});
|
|
3111
|
-
mesh.on('meshes-dirty', (changed, groupsChanged = false) => {
|
|
3112
|
-
if (changed || entry.meshesPending) {
|
|
3113
|
-
void this._followJoinedMeshes(mesh);
|
|
3114
|
-
}
|
|
3115
|
-
if (changed && mesh.role === 'workspace') {
|
|
3116
|
-
void this._followProjects(mesh);
|
|
3117
|
-
void this._followHosting();
|
|
3118
|
-
}
|
|
3119
|
-
if (mesh.role === 'project') {
|
|
3120
|
-
void this._followUpgrade(mesh);
|
|
3121
|
-
}
|
|
3122
|
-
if ((changed || groupsChanged) && mesh.role === 'workspace') {
|
|
3123
|
-
this._followGroups(mesh);
|
|
3124
|
-
}
|
|
3125
|
-
if (this._isAccount(mesh) && (changed || !this._publicMesh())) {
|
|
3126
|
-
void this._followPublicMesh(mesh);
|
|
3127
|
-
}
|
|
3128
3442
|
});
|
|
3443
|
+
mesh.on('meshes-dirty', (changed, groupsChanged = false) => this._onMeshesDirty(entry, { changed, groupsChanged }));
|
|
3129
3444
|
mesh.on('joined', () => {
|
|
3130
3445
|
if (entry.meshesPending) {
|
|
3131
3446
|
void this._followJoinedMeshes(mesh);
|
|
3132
3447
|
}
|
|
3448
|
+
if (entry.publicPending) {
|
|
3449
|
+
void this._followPublicMesh(mesh);
|
|
3450
|
+
}
|
|
3133
3451
|
});
|
|
3134
3452
|
mesh.on('membership-tallied', () => this._notifyStatus());
|
|
3135
3453
|
mesh.on('mesh-named', () => {
|
|
@@ -3137,6 +3455,8 @@ export class Core extends ReadyResource {
|
|
|
3137
3455
|
this._notifyStatus();
|
|
3138
3456
|
});
|
|
3139
3457
|
mesh.on('membership', (membership) => {
|
|
3458
|
+
if (this._isHidden(this._meshIdOf(mesh), mesh.workspaceKey))
|
|
3459
|
+
return;
|
|
3140
3460
|
void this._recordMemberProof(mesh, membership);
|
|
3141
3461
|
void this._followJoinedMeshes(mesh);
|
|
3142
3462
|
if (mesh.role === 'workspace') {
|
|
@@ -3149,6 +3469,30 @@ export class Core extends ReadyResource {
|
|
|
3149
3469
|
this._listenMesh(mesh, handlers);
|
|
3150
3470
|
this._startMeshServices(entry);
|
|
3151
3471
|
this._startEntryIndexing(entry);
|
|
3472
|
+
this._onMeshesDirty(entry, { changed: true, groupsChanged: true });
|
|
3473
|
+
this._reviewKick(mesh).catch((err) => this._log?.warn(['p2p', 'mesh'], 'reviewing a kick failed', err));
|
|
3474
|
+
}
|
|
3475
|
+
_onMeshesDirty(entry, { changed, groupsChanged }) {
|
|
3476
|
+
const { mesh } = entry;
|
|
3477
|
+
if (this._isHidden(this._meshIdOf(mesh), mesh.workspaceKey)) {
|
|
3478
|
+
return;
|
|
3479
|
+
}
|
|
3480
|
+
if (changed || entry.meshesPending) {
|
|
3481
|
+
void this._followJoinedMeshes(mesh);
|
|
3482
|
+
}
|
|
3483
|
+
if (changed && mesh.role === 'workspace') {
|
|
3484
|
+
void this._followProjects(mesh);
|
|
3485
|
+
void this._followHosting();
|
|
3486
|
+
}
|
|
3487
|
+
if (mesh.role === 'project') {
|
|
3488
|
+
void this._followUpgrade(mesh);
|
|
3489
|
+
}
|
|
3490
|
+
if ((changed || groupsChanged) && mesh.role === 'workspace') {
|
|
3491
|
+
this._followGroups(mesh);
|
|
3492
|
+
}
|
|
3493
|
+
if (this._isAccount(mesh) && (changed || entry.publicPending || !this._publicMesh())) {
|
|
3494
|
+
void this._followPublicMesh(mesh);
|
|
3495
|
+
}
|
|
3152
3496
|
}
|
|
3153
3497
|
_listenMesh(mesh, handlers) {
|
|
3154
3498
|
mesh.autobee.on('writable', handlers.writable);
|
|
@@ -3179,13 +3523,16 @@ export class Core extends ReadyResource {
|
|
|
3179
3523
|
this._candidateMesh = null;
|
|
3180
3524
|
}
|
|
3181
3525
|
await this.local.setAccountMesh(this._requireDeviceKeyPair().publicKey, mesh.key);
|
|
3526
|
+
for (const key of await this.local.unretire(mesh.key)) {
|
|
3527
|
+
this._retiredMeshes.delete(b4a.toHex(key));
|
|
3528
|
+
}
|
|
3182
3529
|
this._wireMesh(this._poolEntry(mesh));
|
|
3183
3530
|
this._accountId = this._meshIdOf(mesh);
|
|
3184
3531
|
void this._deviceControl.revalidate();
|
|
3185
3532
|
this._statusError = null;
|
|
3186
3533
|
this._upgradeRequired = null;
|
|
3187
3534
|
if (mesh.writable) {
|
|
3188
|
-
this.
|
|
3535
|
+
void this.local.markAwaitingAdmission(mesh.key, { awaitingAdmission: false }).catch(noop);
|
|
3189
3536
|
}
|
|
3190
3537
|
this._notifyStatus();
|
|
3191
3538
|
void this._followPublicMesh(mesh);
|
|
@@ -3311,8 +3658,16 @@ export class Core extends ReadyResource {
|
|
|
3311
3658
|
return;
|
|
3312
3659
|
}
|
|
3313
3660
|
try {
|
|
3314
|
-
|
|
3315
|
-
|
|
3661
|
+
const current = this._accountMesh();
|
|
3662
|
+
for (let attempt = 1; !this.closing && current; attempt++) {
|
|
3663
|
+
const entry = this._meshes.get(this._meshIdOf(current));
|
|
3664
|
+
const settled = await this._settlePublicMeshes(current);
|
|
3665
|
+
if (entry) {
|
|
3666
|
+
entry.publicPending = !settled;
|
|
3667
|
+
}
|
|
3668
|
+
if (settled || attempt === PUBLIC_FOLLOW_ATTEMPTS) {
|
|
3669
|
+
break;
|
|
3670
|
+
}
|
|
3316
3671
|
}
|
|
3317
3672
|
}
|
|
3318
3673
|
catch (err) {
|
|
@@ -3330,20 +3685,28 @@ export class Core extends ReadyResource {
|
|
|
3330
3685
|
if (!ours) {
|
|
3331
3686
|
return keys;
|
|
3332
3687
|
}
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3688
|
+
const snap = account.view.snapshot();
|
|
3689
|
+
try {
|
|
3690
|
+
for await (const joined of snap.find(JOINED_MESHES)) {
|
|
3691
|
+
const { meshKey } = joined;
|
|
3692
|
+
const live = joined.workspace && !joined.leftAt && b4a.equals(joined.memberId, ours);
|
|
3693
|
+
if (live && (await snap.get(MESH_SEEDS, { meshKey }))) {
|
|
3694
|
+
keys.push(meshKey);
|
|
3695
|
+
}
|
|
3338
3696
|
}
|
|
3339
3697
|
}
|
|
3698
|
+
finally {
|
|
3699
|
+
await snap.close();
|
|
3700
|
+
}
|
|
3340
3701
|
return keys;
|
|
3341
3702
|
}
|
|
3342
3703
|
async _settlePublicMeshes(account) {
|
|
3704
|
+
let settled = true;
|
|
3343
3705
|
try {
|
|
3344
3706
|
await this._settleOwnWorkspace(account);
|
|
3345
3707
|
}
|
|
3346
3708
|
catch (err) {
|
|
3709
|
+
settled = false;
|
|
3347
3710
|
if (!this.closing) {
|
|
3348
3711
|
this._log?.warn(['p2p', 'mesh'], 'settling your own workspace failed', err);
|
|
3349
3712
|
}
|
|
@@ -3351,17 +3714,19 @@ export class Core extends ReadyResource {
|
|
|
3351
3714
|
const workspaces = await this._publicWorkspaces(account);
|
|
3352
3715
|
for (const workspaceKey of workspaces) {
|
|
3353
3716
|
if (this.closing || !this._isAccount(account))
|
|
3354
|
-
return;
|
|
3717
|
+
return settled;
|
|
3355
3718
|
try {
|
|
3356
3719
|
await this._settlePublicMesh(account, workspaceKey);
|
|
3357
3720
|
}
|
|
3358
3721
|
catch (err) {
|
|
3722
|
+
settled = false;
|
|
3359
3723
|
if (!this.closing) {
|
|
3360
3724
|
this._log?.warn(['p2p', 'mesh'], 'following a public mesh failed', err);
|
|
3361
3725
|
}
|
|
3362
3726
|
}
|
|
3363
3727
|
}
|
|
3364
3728
|
await this._retireLeftPublic(account, workspaces);
|
|
3729
|
+
return settled;
|
|
3365
3730
|
}
|
|
3366
3731
|
async _settleOwnWorkspace(account) {
|
|
3367
3732
|
const { own, lost } = await ownWorkspaces(account);
|
|
@@ -3371,6 +3736,9 @@ export class Core extends ReadyResource {
|
|
|
3371
3736
|
}
|
|
3372
3737
|
}
|
|
3373
3738
|
const mints = account.minted || !(await bornUnderRules(account.view));
|
|
3739
|
+
if (!this._isAccount(account)) {
|
|
3740
|
+
return;
|
|
3741
|
+
}
|
|
3374
3742
|
if (own || !mints) {
|
|
3375
3743
|
this._setOwnWorkspace(own ? b4a.toHex(own) : null);
|
|
3376
3744
|
return;
|
|
@@ -3379,8 +3747,12 @@ export class Core extends ReadyResource {
|
|
|
3379
3747
|
}
|
|
3380
3748
|
async _mintOwnWorkspace(account) {
|
|
3381
3749
|
const seed = ownWorkspaceSeed(account.seed);
|
|
3382
|
-
const recorded = (await this.local.listMeshes()).
|
|
3383
|
-
if (recorded
|
|
3750
|
+
const recorded = (await this.local.listMeshes()).find((row) => b4a.equals(row.seed, seed));
|
|
3751
|
+
if (recorded) {
|
|
3752
|
+
await this._openPooledMesh(b4a.toHex(recorded.key), 'follow');
|
|
3753
|
+
return;
|
|
3754
|
+
}
|
|
3755
|
+
if (!account.writable || !account.ourMemberId) {
|
|
3384
3756
|
return;
|
|
3385
3757
|
}
|
|
3386
3758
|
const workspace = { name: await this._defaultWorkspaceName(account) };
|
|
@@ -3588,11 +3960,17 @@ export class Core extends ReadyResource {
|
|
|
3588
3960
|
_savePublicRecord(account, workspaceKey, record) {
|
|
3589
3961
|
return this.local.set(publicRecordKey(account.key, workspaceKey), record);
|
|
3590
3962
|
}
|
|
3963
|
+
_takePublicBoot(meshId) {
|
|
3964
|
+
const head = this._publicBoots.get(meshId) ?? null;
|
|
3965
|
+
this._publicBoots.delete(meshId);
|
|
3966
|
+
return head;
|
|
3967
|
+
}
|
|
3591
3968
|
async _openPublicMesh(account, { workspaceKey, record, founder = null }) {
|
|
3592
3969
|
const session = {
|
|
3593
3970
|
seed: publicSeed(account.seed, workspaceKey),
|
|
3594
3971
|
baseKey: record.key ? b4a.from(record.key, 'hex') : undefined,
|
|
3595
|
-
writerSeed: record.writerSeed
|
|
3972
|
+
writerSeed: record.writerSeed,
|
|
3973
|
+
bootFrom: record.key ? this._takePublicBoot(record.key) : null
|
|
3596
3974
|
};
|
|
3597
3975
|
const mesh = this._newMesh(session, 'public');
|
|
3598
3976
|
mesh.workspaceKey = workspaceKey;
|
|
@@ -3964,6 +4342,14 @@ export class Core extends ReadyResource {
|
|
|
3964
4342
|
this._leftPublic.add(held);
|
|
3965
4343
|
await this._announceDeparture(held);
|
|
3966
4344
|
}
|
|
4345
|
+
}
|
|
4346
|
+
await this._rotatePublicWriters(account);
|
|
4347
|
+
}
|
|
4348
|
+
async _dropKickedCopy(meshId) {
|
|
4349
|
+
await this._teardownMesh(await this._openPooledMesh(meshId, 'leave'), { purge: true });
|
|
4350
|
+
}
|
|
4351
|
+
async _rotatePublicWriters(account) {
|
|
4352
|
+
for (const workspaceKey of await this._publicWorkspaces(account)) {
|
|
3967
4353
|
const record = await this._publicRecord(account, workspaceKey);
|
|
3968
4354
|
if (record) {
|
|
3969
4355
|
await this.local.set(leftPublicRecordKey(account.key, workspaceKey), record);
|
|
@@ -3974,6 +4360,14 @@ export class Core extends ReadyResource {
|
|
|
3974
4360
|
}
|
|
3975
4361
|
}
|
|
3976
4362
|
}
|
|
4363
|
+
async _restorePublicWriters(account) {
|
|
4364
|
+
for (const workspaceKey of await this._publicWorkspaces(account)) {
|
|
4365
|
+
const left = await this.local.get(leftPublicRecordKey(account.key, workspaceKey));
|
|
4366
|
+
if (isPublicRecord(left)) {
|
|
4367
|
+
await this._savePublicRecord(account, workspaceKey, left);
|
|
4368
|
+
}
|
|
4369
|
+
}
|
|
4370
|
+
}
|
|
3977
4371
|
_pooled(meshKey) {
|
|
3978
4372
|
if (meshKey === null)
|
|
3979
4373
|
return null;
|
|
@@ -4007,7 +4401,9 @@ export class Core extends ReadyResource {
|
|
|
4007
4401
|
vectorIndex: null,
|
|
4008
4402
|
memberLock: new ScopeLock({ debounce: true }),
|
|
4009
4403
|
followLock: new ScopeLock({ debounce: true }),
|
|
4010
|
-
|
|
4404
|
+
kickLock: new ScopeLock({ debounce: true }),
|
|
4405
|
+
meshesPending: false,
|
|
4406
|
+
publicPending: false
|
|
4011
4407
|
};
|
|
4012
4408
|
this._meshes.set(key, entry);
|
|
4013
4409
|
mesh.on('peer-add', () => this._onMeshPeer(mesh));
|
|
@@ -4085,9 +4481,15 @@ export class Core extends ReadyResource {
|
|
|
4085
4481
|
if (await this.local.files.backfilled(mesh.key)) {
|
|
4086
4482
|
return;
|
|
4087
4483
|
}
|
|
4088
|
-
|
|
4484
|
+
const started = Date.now();
|
|
4485
|
+
const chunks = await backfillFileIndex(mesh);
|
|
4089
4486
|
if (!mesh.closing) {
|
|
4090
4487
|
await this.local.files.markBackfilled(mesh.key);
|
|
4488
|
+
this._log?.info(['files'], 'recorded the files the mesh already held', {
|
|
4489
|
+
mesh: b4a.toHex(mesh.key).slice(0, 8),
|
|
4490
|
+
chunks,
|
|
4491
|
+
ms: Date.now() - started
|
|
4492
|
+
});
|
|
4091
4493
|
}
|
|
4092
4494
|
}
|
|
4093
4495
|
catch (err) {
|
|
@@ -4119,6 +4521,27 @@ export class Core extends ReadyResource {
|
|
|
4119
4521
|
})
|
|
4120
4522
|
.catch(failed);
|
|
4121
4523
|
}
|
|
4524
|
+
async _backfillChatChunks(mesh) {
|
|
4525
|
+
if (!floorExcludesBefore(this._minSupportedVersion, REINDEX_FROM_APP_VERSION)) {
|
|
4526
|
+
return;
|
|
4527
|
+
}
|
|
4528
|
+
try {
|
|
4529
|
+
await mesh.waitForWritable();
|
|
4530
|
+
await mesh.autobee.update();
|
|
4531
|
+
const started = Date.now();
|
|
4532
|
+
const copied = await backfillChatChunks(mesh);
|
|
4533
|
+
this._log?.info(['p2p', 'mesh'], 'copied chats into chat-chunks', {
|
|
4534
|
+
mesh: b4a.toHex(mesh.key).slice(0, 8),
|
|
4535
|
+
copied,
|
|
4536
|
+
ms: Date.now() - started
|
|
4537
|
+
});
|
|
4538
|
+
}
|
|
4539
|
+
catch (err) {
|
|
4540
|
+
if (!mesh.closing) {
|
|
4541
|
+
this._log?.warn(['p2p', 'mesh'], 'copying chats into chat-chunks failed', err);
|
|
4542
|
+
}
|
|
4543
|
+
}
|
|
4544
|
+
}
|
|
4122
4545
|
_servedFile(mesh, coreKey, blockOffset) {
|
|
4123
4546
|
this.local.files
|
|
4124
4547
|
.touch({ meshKey: mesh.key, coreKey, blockOffset })
|
|
@@ -4189,6 +4612,9 @@ export class Core extends ReadyResource {
|
|
|
4189
4612
|
if (entry?.mesh === mesh) {
|
|
4190
4613
|
this._unwireMesh(entry);
|
|
4191
4614
|
this._meshes.delete(key);
|
|
4615
|
+
if (this._retiredMeshes.delete(key)) {
|
|
4616
|
+
this._notifyStatus();
|
|
4617
|
+
}
|
|
4192
4618
|
wasAccount = this._accountId === key;
|
|
4193
4619
|
}
|
|
4194
4620
|
if (this._candidateMesh === mesh) {
|
|
@@ -4280,6 +4706,25 @@ export class Core extends ReadyResource {
|
|
|
4280
4706
|
};
|
|
4281
4707
|
mesh.on('chat-purged', () => void reclaim());
|
|
4282
4708
|
mesh.on('landed', () => void reclaim());
|
|
4709
|
+
let canceling = Promise.resolve();
|
|
4710
|
+
const cancelRuns = (landed) => {
|
|
4711
|
+
canceling = canceling
|
|
4712
|
+
.then(async () => {
|
|
4713
|
+
if (mesh.writable) {
|
|
4714
|
+
await cancelDeletedAgentRuns(mesh, deviceId, landed);
|
|
4715
|
+
}
|
|
4716
|
+
})
|
|
4717
|
+
.catch((error) => {
|
|
4718
|
+
if (!mesh.closing) {
|
|
4719
|
+
this._log?.warn(['p2p', 'mesh'], "canceling a deleted agent's runs failed", error);
|
|
4720
|
+
}
|
|
4721
|
+
});
|
|
4722
|
+
};
|
|
4723
|
+
const cancelAll = () => cancelRuns(null);
|
|
4724
|
+
mesh.on('runs-landed', cancelRuns);
|
|
4725
|
+
mesh.on('landed', cancelAll);
|
|
4726
|
+
mesh.autobee.on('writable', cancelAll);
|
|
4727
|
+
cancelAll();
|
|
4283
4728
|
const sweepLock = new ScopeLock({ debounce: true });
|
|
4284
4729
|
const sweep = async () => {
|
|
4285
4730
|
if (!(await sweepLock.lock()))
|
|
@@ -4297,6 +4742,7 @@ export class Core extends ReadyResource {
|
|
|
4297
4742
|
}
|
|
4298
4743
|
};
|
|
4299
4744
|
void this._indexMeshFiles(mesh).then(() => Promise.all([reclaim(), sweep()]));
|
|
4745
|
+
void this._backfillChatChunks(mesh);
|
|
4300
4746
|
mesh.autobee.on('move-to', () => void sweep());
|
|
4301
4747
|
}
|
|
4302
4748
|
async _discardCandidateMesh() {
|
|
@@ -4355,68 +4801,85 @@ export class Core extends ReadyResource {
|
|
|
4355
4801
|
}
|
|
4356
4802
|
}
|
|
4357
4803
|
}
|
|
4358
|
-
async leaveMesh(meshId) {
|
|
4804
|
+
async leaveMesh(meshId, { workspace = false } = {}) {
|
|
4359
4805
|
if (this.closing)
|
|
4360
4806
|
return;
|
|
4361
4807
|
if (!this.opened)
|
|
4362
4808
|
await this.ready();
|
|
4363
4809
|
if (this._leaving === meshId) {
|
|
4810
|
+
await this._leaveChecks;
|
|
4364
4811
|
return;
|
|
4365
4812
|
}
|
|
4366
4813
|
if (this._leaving || this._minting) {
|
|
4367
4814
|
throw new CoreError('MESH_TRANSITION_IN_PROGRESS');
|
|
4368
4815
|
}
|
|
4369
|
-
|
|
4816
|
+
this._leaving = meshId;
|
|
4817
|
+
const checks = this._checkLeave(meshId, workspace);
|
|
4818
|
+
this._leaveChecks = checks;
|
|
4819
|
+
try {
|
|
4820
|
+
const checked = await checks;
|
|
4821
|
+
if (checked.kicked) {
|
|
4822
|
+
await this._departKicked(checked.departing);
|
|
4823
|
+
}
|
|
4824
|
+
else {
|
|
4825
|
+
await this._leaveChecked(meshId, checked);
|
|
4826
|
+
}
|
|
4827
|
+
}
|
|
4828
|
+
finally {
|
|
4829
|
+
this._leaving = null;
|
|
4830
|
+
this._leaveChecks = null;
|
|
4831
|
+
this._notifyStatus();
|
|
4832
|
+
}
|
|
4833
|
+
}
|
|
4834
|
+
async _checkLeave(meshId, workspace) {
|
|
4835
|
+
const departing = await this._openPooledMesh(meshId, 'leave');
|
|
4836
|
+
if (workspace) {
|
|
4837
|
+
requireWorkspace(departing, meshId);
|
|
4838
|
+
}
|
|
4370
4839
|
const account = this._accountMesh();
|
|
4371
4840
|
if (account && isOwnWorkspace(account, departing)) {
|
|
4372
4841
|
throw new CoreError('OWN_WORKSPACE_LEAVE_REFUSED');
|
|
4373
4842
|
}
|
|
4374
|
-
const
|
|
4843
|
+
const kicked = this._kickedMeshes.has(meshId) && departing !== account;
|
|
4844
|
+
const member = departing.role === 'workspace' && !kicked ? await this._leavingMember(departing) : null;
|
|
4375
4845
|
const leavingAccount = await this._isStoredAccount(departing);
|
|
4846
|
+
return { departing, member, leavingAccount, kicked };
|
|
4847
|
+
}
|
|
4848
|
+
async _leaveChecked(meshId, { departing, member, leavingAccount }) {
|
|
4376
4849
|
this._log?.info(['p2p', 'mesh'], 'leaving a mesh', {
|
|
4377
4850
|
meshId: meshId.slice(0, 8),
|
|
4378
4851
|
account: leavingAccount
|
|
4379
4852
|
});
|
|
4380
|
-
this._leaving = meshId;
|
|
4381
4853
|
this._notifyStatus();
|
|
4382
|
-
|
|
4383
|
-
|
|
4384
|
-
|
|
4385
|
-
if (this.closing) {
|
|
4386
|
-
return;
|
|
4387
|
-
}
|
|
4388
|
-
}
|
|
4389
|
-
if (leavingAccount) {
|
|
4390
|
-
await this._leavePublicMesh(departing);
|
|
4391
|
-
}
|
|
4392
|
-
if (member) {
|
|
4393
|
-
await this._leaveAsMember(departing, member);
|
|
4394
|
-
}
|
|
4395
|
-
await this._recordDeparture(departing);
|
|
4396
|
-
await this._releaseJoinedMesh(departing.key);
|
|
4397
|
-
if (!leavingAccount) {
|
|
4398
|
-
await this._teardownMesh(departing);
|
|
4399
|
-
this._departures?.flush();
|
|
4854
|
+
if (leavingAccount) {
|
|
4855
|
+
await this._departAllBut(departing);
|
|
4856
|
+
if (this.closing) {
|
|
4400
4857
|
return;
|
|
4401
4858
|
}
|
|
4402
|
-
await this._archiveMembership(departing);
|
|
4403
|
-
const landed = this._waitForMeshChange();
|
|
4404
|
-
this._requestFreshMesh().catch(noop);
|
|
4405
|
-
const error = await landed;
|
|
4406
|
-
if (error) {
|
|
4407
|
-
throw error;
|
|
4408
|
-
}
|
|
4409
4859
|
}
|
|
4410
|
-
|
|
4411
|
-
this.
|
|
4412
|
-
|
|
4860
|
+
if (leavingAccount) {
|
|
4861
|
+
await this._leavePublicMesh(departing);
|
|
4862
|
+
}
|
|
4863
|
+
if (member) {
|
|
4864
|
+
await this._leaveAsMember(departing, member);
|
|
4865
|
+
}
|
|
4866
|
+
await this._recordDeparture(departing);
|
|
4867
|
+
await this._releaseJoinedMesh(departing.key);
|
|
4868
|
+
if (!leavingAccount) {
|
|
4869
|
+
await this._teardownMesh(departing);
|
|
4870
|
+
this._departures?.flush();
|
|
4871
|
+
return;
|
|
4872
|
+
}
|
|
4873
|
+
await this._archiveMembership(departing);
|
|
4874
|
+
const landed = this._waitForMeshChange();
|
|
4875
|
+
this._requestFreshMesh().catch(noop);
|
|
4876
|
+
const error = await landed;
|
|
4877
|
+
if (error) {
|
|
4878
|
+
throw error;
|
|
4413
4879
|
}
|
|
4414
4880
|
}
|
|
4415
|
-
|
|
4416
|
-
|
|
4417
|
-
await this.ready();
|
|
4418
|
-
requireWorkspace(await this._openPooledMesh(meshId), meshId);
|
|
4419
|
-
await this.leaveMesh(meshId);
|
|
4881
|
+
leaveWorkspace(meshId) {
|
|
4882
|
+
return this.leaveMesh(meshId, { workspace: true });
|
|
4420
4883
|
}
|
|
4421
4884
|
async _leavingMember(workspace) {
|
|
4422
4885
|
const ours = workspace.ourMemberId ?? (await workspace.refreshOurMember())?.memberId;
|
|
@@ -4446,13 +4909,13 @@ export class Core extends ReadyResource {
|
|
|
4446
4909
|
}
|
|
4447
4910
|
await workspace.dispatch('remove-member', { memberId: ours, revokedAt: Date.now() });
|
|
4448
4911
|
}
|
|
4449
|
-
async _heldMesh(key) {
|
|
4912
|
+
async _heldMesh(key, reason = 'route') {
|
|
4450
4913
|
const meshId = b4a.toHex(key);
|
|
4451
4914
|
const held = this._pooled(meshId);
|
|
4452
4915
|
if (held || !(await this.local.readMeshSession(key))) {
|
|
4453
4916
|
return held;
|
|
4454
4917
|
}
|
|
4455
|
-
return this._openPooledMesh(meshId);
|
|
4918
|
+
return this._openPooledMesh(meshId, reason);
|
|
4456
4919
|
}
|
|
4457
4920
|
async _cascadeRemovals(workspace) {
|
|
4458
4921
|
const ours = workspace.ourMemberId;
|
|
@@ -4509,8 +4972,11 @@ export class Core extends ReadyResource {
|
|
|
4509
4972
|
if (this.closing || !ours || !own || own.revoked || !account?.writable) {
|
|
4510
4973
|
return;
|
|
4511
4974
|
}
|
|
4512
|
-
const devices = await workspace.view
|
|
4513
|
-
const kicked = devices.filter((device) => device.revoked &&
|
|
4975
|
+
const devices = await devicesOfMember(workspace.view, ours);
|
|
4976
|
+
const kicked = devices.filter((device) => device.revoked &&
|
|
4977
|
+
!!device.revokedBy &&
|
|
4978
|
+
!(device.writerKey && b4a.equals(device.revokedBy, device.writerKey)) &&
|
|
4979
|
+
(device.revokedAt ?? 0) > own.joinedAt);
|
|
4514
4980
|
for (const device of kicked) {
|
|
4515
4981
|
const row = await account.view.get(DEVICES, { id: device.id });
|
|
4516
4982
|
const writerKey = row && !row.revoked ? row.writerKey : null;
|
|
@@ -4564,8 +5030,9 @@ export class Core extends ReadyResource {
|
|
|
4564
5030
|
const rows = await this.local.listMeshes();
|
|
4565
5031
|
const registry = accountKey ? this._pooled(b4a.toHex(accountKey)) : null;
|
|
4566
5032
|
const meshes = registry ? await this._ownMeshes(registry) : new Map();
|
|
5033
|
+
const shown = rows.filter((row) => !this._isHidden(b4a.toHex(row.key), row.workspaceKey));
|
|
4567
5034
|
return {
|
|
4568
|
-
meshes: await Promise.all(
|
|
5035
|
+
meshes: await Promise.all(shown.map((row) => this._meshEntry(row, accountKey, meshes)))
|
|
4569
5036
|
};
|
|
4570
5037
|
}
|
|
4571
5038
|
async listArchivedMeshes() {
|
|
@@ -4653,7 +5120,7 @@ export class Core extends ReadyResource {
|
|
|
4653
5120
|
return meshes;
|
|
4654
5121
|
}
|
|
4655
5122
|
for await (const joined of registry.view.find(JOINED_MESHES)) {
|
|
4656
|
-
if (!joined.leftAt && b4a.equals(joined.memberId, ours)) {
|
|
5123
|
+
if (!joined.leftAt && !joined.kicked && b4a.equals(joined.memberId, ours)) {
|
|
4657
5124
|
meshes.set(b4a.toHex(joined.meshKey), joined);
|
|
4658
5125
|
}
|
|
4659
5126
|
}
|
|
@@ -4741,10 +5208,7 @@ export class Core extends ReadyResource {
|
|
|
4741
5208
|
}
|
|
4742
5209
|
return `${member.name}'s Workspace`.slice(0, MAX_MESH_NAME_CHARS);
|
|
4743
5210
|
}
|
|
4744
|
-
async createMesh({ shared = false
|
|
4745
|
-
if (compute) {
|
|
4746
|
-
throw new CoreError('COMPUTE_MESH_RETIRED');
|
|
4747
|
-
}
|
|
5211
|
+
async createMesh({ shared = false } = {}) {
|
|
4748
5212
|
if (!this.opened)
|
|
4749
5213
|
await this.ready();
|
|
4750
5214
|
await this._meshTransitionLock.lock();
|
|
@@ -4999,6 +5463,9 @@ export class Core extends ReadyResource {
|
|
|
4999
5463
|
if (this._blockedByMinVersion()) {
|
|
5000
5464
|
throw new CoreError('MESH_BELOW_FLOOR');
|
|
5001
5465
|
}
|
|
5466
|
+
if (reason === 'leave') {
|
|
5467
|
+
await this._kickCloses.get(meshId);
|
|
5468
|
+
}
|
|
5002
5469
|
const pooled = this._pooled(meshId);
|
|
5003
5470
|
if (pooled && this._isForeign(pooled)) {
|
|
5004
5471
|
throw new CoreError('MESH_NOT_FOUND', [meshId]);
|
|
@@ -5009,7 +5476,7 @@ export class Core extends ReadyResource {
|
|
|
5009
5476
|
const retiring = this._retiring.get(meshId);
|
|
5010
5477
|
if (retiring) {
|
|
5011
5478
|
await retiring.catch(noop);
|
|
5012
|
-
return this._openPooledMesh(meshId);
|
|
5479
|
+
return this._openPooledMesh(meshId, reason);
|
|
5013
5480
|
}
|
|
5014
5481
|
const inflight = this._opening.get(meshId);
|
|
5015
5482
|
if (inflight) {
|
|
@@ -5030,7 +5497,7 @@ export class Core extends ReadyResource {
|
|
|
5030
5497
|
const started = Date.now();
|
|
5031
5498
|
const key = this._meshKeyOf(meshId);
|
|
5032
5499
|
const session = await this.local.readMeshSession(key);
|
|
5033
|
-
if (!session) {
|
|
5500
|
+
if (!session || (this._kickedMeshes.has(meshId) && reason !== 'leave')) {
|
|
5034
5501
|
throw new CoreError('MESH_NOT_FOUND', [meshId]);
|
|
5035
5502
|
}
|
|
5036
5503
|
const stored = await this._storedAccountKey();
|
|
@@ -5046,6 +5513,10 @@ export class Core extends ReadyResource {
|
|
|
5046
5513
|
void this._deviceControl.revalidate();
|
|
5047
5514
|
void this._followPublicMesh(mesh);
|
|
5048
5515
|
}
|
|
5516
|
+
for (const dirty of ['members-dirty', 'agents-dirty', 'skill-secrets-dirty', 'mesh-named']) {
|
|
5517
|
+
mesh.emit(dirty);
|
|
5518
|
+
}
|
|
5519
|
+
mesh.emit('meshes-dirty', true);
|
|
5049
5520
|
if (this._isAccount(mesh) && this._statusError?.startsWith(MESH_DIED)) {
|
|
5050
5521
|
this._statusError = null;
|
|
5051
5522
|
}
|
|
@@ -5345,7 +5816,7 @@ export class Core extends ReadyResource {
|
|
|
5345
5816
|
const workspace = mesh.role === 'workspace';
|
|
5346
5817
|
if (opts.memberInvite) {
|
|
5347
5818
|
if (!isOwnMesh) {
|
|
5348
|
-
throw new CoreError('MEMBER_INVITE_ACCOUNT_REFUSED');
|
|
5819
|
+
throw new CoreError(mesh.writable ? 'MEMBER_INVITE_ACCOUNT_REFUSED' : 'MESH_STILL_JOINING');
|
|
5349
5820
|
}
|
|
5350
5821
|
if (isOwnWorkspace(registry, mesh)) {
|
|
5351
5822
|
throw new CoreError('OWN_WORKSPACE_INVITE_REFUSED');
|
|
@@ -5366,9 +5837,7 @@ export class Core extends ReadyResource {
|
|
|
5366
5837
|
throw new CoreError('DEVICE_INVITE_MESH_REFUSED');
|
|
5367
5838
|
}
|
|
5368
5839
|
}
|
|
5369
|
-
const
|
|
5370
|
-
const info = await auto.system.getInfo();
|
|
5371
|
-
const head = info && info.view.length > 0 ? await auto.trusted.mostRecentTrusted(auto.view, null) : null;
|
|
5840
|
+
const head = await inviteHead(mesh);
|
|
5372
5841
|
const additionalNodes = this._swarm
|
|
5373
5842
|
? this._swarm.dht.toArray({ limit: INVITE_DHT_NODES_LIMIT })
|
|
5374
5843
|
: [];
|
|
@@ -5390,7 +5859,7 @@ export class Core extends ReadyResource {
|
|
|
5390
5859
|
return {
|
|
5391
5860
|
baseKey: mesh.key,
|
|
5392
5861
|
seed: mesh.seed,
|
|
5393
|
-
fastForward: head
|
|
5862
|
+
fastForward: head,
|
|
5394
5863
|
additionalNodes,
|
|
5395
5864
|
blindPeers: blindPeerRows.length
|
|
5396
5865
|
? blindPeerRows.map((row) => row.key)
|
|
@@ -5401,9 +5870,25 @@ export class Core extends ReadyResource {
|
|
|
5401
5870
|
deviceSeed: delegation?.deviceSeed,
|
|
5402
5871
|
deviceProof: delegation?.deviceProof,
|
|
5403
5872
|
workspace,
|
|
5404
|
-
workspaceName: opts.memberInvite ? mesh.name?.name || undefined : undefined
|
|
5873
|
+
workspaceName: opts.memberInvite ? mesh.name?.name || undefined : undefined,
|
|
5874
|
+
publicHeads: opts.memberInvite ? [] : await this._publicHeads()
|
|
5405
5875
|
};
|
|
5406
5876
|
}
|
|
5877
|
+
async _publicHeads() {
|
|
5878
|
+
const heads = [];
|
|
5879
|
+
const ids = new Set([this._publicIdOf(this._accountId), ...this._publicIds.values()]);
|
|
5880
|
+
for (const meshId of ids) {
|
|
5881
|
+
const mesh = this._pooled(meshId);
|
|
5882
|
+
const head = mesh && (await inviteHead(mesh));
|
|
5883
|
+
if (head) {
|
|
5884
|
+
heads.push({ meshKey: mesh.key, head });
|
|
5885
|
+
}
|
|
5886
|
+
if (heads.length === INVITE_PUBLIC_HEADS_LIMIT) {
|
|
5887
|
+
break;
|
|
5888
|
+
}
|
|
5889
|
+
}
|
|
5890
|
+
return heads;
|
|
5891
|
+
}
|
|
5407
5892
|
async _delegatePairing(account) {
|
|
5408
5893
|
const keyPair = this._requireDeviceKeyPair();
|
|
5409
5894
|
const own = await account.view.get(DEVICES, { id: keyPair.publicKey });
|
|
@@ -5477,12 +5962,33 @@ export class Core extends ReadyResource {
|
|
|
5477
5962
|
await this.ready();
|
|
5478
5963
|
await storeSkillSecret({
|
|
5479
5964
|
local: this.local,
|
|
5965
|
+
validate: (entry) => validateVaultManagedSkill(this._vaultManagedSkills, entry),
|
|
5480
5966
|
setupFields: (skillName) => this._setupFields(skillName),
|
|
5481
|
-
onstored: () =>
|
|
5967
|
+
onstored: async (entries) => {
|
|
5968
|
+
await this._releaseQuarantined(entries);
|
|
5969
|
+
await this._skillCatalog?.(null, null, { refresh: true });
|
|
5970
|
+
}
|
|
5482
5971
|
}, request);
|
|
5483
5972
|
await this._followSkillSecrets();
|
|
5484
5973
|
}
|
|
5974
|
+
_offerQuarantined() {
|
|
5975
|
+
const offer = () => prepareVaultManagedSkills(this._vaultManagedSkills, this.local, this._log);
|
|
5976
|
+
this._quarantine = this._quarantine.then(offer, offer);
|
|
5977
|
+
return this._quarantine;
|
|
5978
|
+
}
|
|
5979
|
+
_discardQuarantined(keys) {
|
|
5980
|
+
const discard = () => discardQuarantinedSkills(this.local, keys);
|
|
5981
|
+
this._quarantine = this._quarantine.then(discard, discard);
|
|
5982
|
+
return this._quarantine;
|
|
5983
|
+
}
|
|
5984
|
+
async _releaseQuarantined(entries) {
|
|
5985
|
+
if (this._vaultManagedSkills) {
|
|
5986
|
+
await releaseQuarantinedSkills(this.local, entries);
|
|
5987
|
+
}
|
|
5988
|
+
}
|
|
5485
5989
|
async _followSkillSecrets() {
|
|
5990
|
+
if (this._vaultManagedSkills)
|
|
5991
|
+
return;
|
|
5486
5992
|
if (!(await this._skillSecrets.lock()))
|
|
5487
5993
|
return;
|
|
5488
5994
|
try {
|
|
@@ -5501,7 +6007,18 @@ export class Core extends ReadyResource {
|
|
|
5501
6007
|
this._skillSecrets.unlock();
|
|
5502
6008
|
}
|
|
5503
6009
|
}
|
|
5504
|
-
|
|
6010
|
+
_followJoinedMeshes(memberMesh) {
|
|
6011
|
+
return this._followJoinedMeshesPass(memberMesh).catch((err) => {
|
|
6012
|
+
const entry = this._meshes.get(this._meshIdOf(memberMesh));
|
|
6013
|
+
if (entry?.mesh === memberMesh) {
|
|
6014
|
+
entry.meshesPending = true;
|
|
6015
|
+
}
|
|
6016
|
+
if (!this.closing) {
|
|
6017
|
+
this._log?.warn(['p2p', 'mesh'], 'following the joined meshes failed', err);
|
|
6018
|
+
}
|
|
6019
|
+
});
|
|
6020
|
+
}
|
|
6021
|
+
async _followJoinedMeshesPass(memberMesh) {
|
|
5505
6022
|
if (this.closing || !this._isPooled(memberMesh))
|
|
5506
6023
|
return;
|
|
5507
6024
|
const entry = this._meshes.get(this._meshIdOf(memberMesh));
|
|
@@ -5566,6 +6083,10 @@ export class Core extends ReadyResource {
|
|
|
5566
6083
|
if (await lostMint(memberMesh, joined.meshKey)) {
|
|
5567
6084
|
return;
|
|
5568
6085
|
}
|
|
6086
|
+
if (joined.kicked && !joined.leftAt) {
|
|
6087
|
+
await this._followKick(meshId, held);
|
|
6088
|
+
return;
|
|
6089
|
+
}
|
|
5569
6090
|
if (joined.leftAt) {
|
|
5570
6091
|
if (held) {
|
|
5571
6092
|
tally.left++;
|
|
@@ -5580,6 +6101,13 @@ export class Core extends ReadyResource {
|
|
|
5580
6101
|
tally.held++;
|
|
5581
6102
|
return;
|
|
5582
6103
|
}
|
|
6104
|
+
const joinedUnder = await this.local.joinedUnder(joined.meshKey);
|
|
6105
|
+
if (joinedUnder !== null && this._kickedMeshes.has(meshId)) {
|
|
6106
|
+
if (joined.joinedAt <= joinedUnder) {
|
|
6107
|
+
return;
|
|
6108
|
+
}
|
|
6109
|
+
await this._dropKickedCopy(meshId);
|
|
6110
|
+
}
|
|
5583
6111
|
if (await this.local.readMeshSession(joined.meshKey)) {
|
|
5584
6112
|
if (this._upgradeRequired !== 'halt' &&
|
|
5585
6113
|
(await this.local.awaitsAdmission(joined.meshKey))) {
|
|
@@ -5666,12 +6194,25 @@ export class Core extends ReadyResource {
|
|
|
5666
6194
|
deviceId: this._requireDeviceKeyPair().publicKey
|
|
5667
6195
|
});
|
|
5668
6196
|
await this.local.markAwaitingAdmission(meshKey, { awaitingAdmission: true });
|
|
6197
|
+
await this.local.markJoinedUnder(meshKey, joined.joinedAt);
|
|
6198
|
+
this._kickedMeshes.delete(b4a.toHex(meshKey));
|
|
5669
6199
|
await this._openPooledMesh(b4a.toHex(meshKey), 'follow');
|
|
5670
6200
|
return 'opened';
|
|
5671
6201
|
}
|
|
5672
6202
|
async _followProjects(workspace) {
|
|
5673
|
-
|
|
5674
|
-
|
|
6203
|
+
try {
|
|
6204
|
+
await this._passProjects(workspace);
|
|
6205
|
+
}
|
|
6206
|
+
catch (err) {
|
|
6207
|
+
if (!this.closing) {
|
|
6208
|
+
this._log?.warn(['p2p', 'mesh'], 'following the projects failed', err);
|
|
6209
|
+
}
|
|
6210
|
+
}
|
|
6211
|
+
}
|
|
6212
|
+
async _passProjects(workspace) {
|
|
6213
|
+
if (!this._mayFollowProjects(workspace) ||
|
|
6214
|
+
this._upgradeRequired ||
|
|
6215
|
+
this._blockedByMinVersion()) {
|
|
5675
6216
|
return;
|
|
5676
6217
|
}
|
|
5677
6218
|
if (!workspace.ourMemberId) {
|
|
@@ -5682,7 +6223,7 @@ export class Core extends ReadyResource {
|
|
|
5682
6223
|
return;
|
|
5683
6224
|
}
|
|
5684
6225
|
for await (const project of workspace.view.find(PROJECTS)) {
|
|
5685
|
-
if (
|
|
6226
|
+
if (!this._mayFollowProjects(workspace)) {
|
|
5686
6227
|
return;
|
|
5687
6228
|
}
|
|
5688
6229
|
const meshId = b4a.toHex(project.id);
|
|
@@ -5703,17 +6244,36 @@ export class Core extends ReadyResource {
|
|
|
5703
6244
|
continue;
|
|
5704
6245
|
}
|
|
5705
6246
|
const held = this._pooled(meshId);
|
|
5706
|
-
|
|
5707
|
-
await this._releaseHostMesh(meshId, { replaced: true });
|
|
5708
|
-
}
|
|
6247
|
+
const hosted = !!held && this._isForeign(held);
|
|
5709
6248
|
const kicked = this._kickedProjects.get(meshId) === workspace;
|
|
5710
|
-
if (kicked
|
|
6249
|
+
if (!hosted && !kicked && this._kickedMeshes.has(meshId)) {
|
|
6250
|
+
if (!this._following.has(meshId)) {
|
|
6251
|
+
await this._trackFollow(meshId, async () => {
|
|
6252
|
+
await this._dropKickedCopy(meshId);
|
|
6253
|
+
await this._openListedProject(workspace, project);
|
|
6254
|
+
});
|
|
6255
|
+
}
|
|
6256
|
+
continue;
|
|
6257
|
+
}
|
|
6258
|
+
if (this._following.has(meshId) || (!hosted && (held || kicked))) {
|
|
5711
6259
|
continue;
|
|
5712
6260
|
}
|
|
5713
|
-
await this._trackFollow(meshId, () =>
|
|
6261
|
+
await this._trackFollow(meshId, async () => {
|
|
6262
|
+
if (hosted) {
|
|
6263
|
+
await this._releaseHostMesh(meshId, { replaced: true });
|
|
6264
|
+
}
|
|
6265
|
+
if (!kicked) {
|
|
6266
|
+
await this._openListedProject(workspace, project);
|
|
6267
|
+
}
|
|
6268
|
+
});
|
|
5714
6269
|
}
|
|
5715
6270
|
void this._sealProjectKeys();
|
|
5716
6271
|
}
|
|
6272
|
+
_mayFollowProjects(workspace) {
|
|
6273
|
+
const leaving = this._leaving !== null &&
|
|
6274
|
+
(this._leaving === this._accountId || this._leaving === this._meshIdOf(workspace));
|
|
6275
|
+
return !this.closing && !this._minting && !leaving && this._isPooled(workspace);
|
|
6276
|
+
}
|
|
5717
6277
|
async _sealProjectKeys() {
|
|
5718
6278
|
if (!(await this._projectKeySeals.lock()))
|
|
5719
6279
|
return;
|
|
@@ -5806,6 +6366,9 @@ export class Core extends ReadyResource {
|
|
|
5806
6366
|
return row && openSealedToDevice(row.sealedSeed, device);
|
|
5807
6367
|
}
|
|
5808
6368
|
async _projectGone(projectId) {
|
|
6369
|
+
if (this._isHidden(projectId, this._pooled(projectId)?.workspaceKey)) {
|
|
6370
|
+
return true;
|
|
6371
|
+
}
|
|
5809
6372
|
return !(await this.local.readMeshSession(b4a.from(projectId, 'hex')));
|
|
5810
6373
|
}
|
|
5811
6374
|
async _isProjectOf(workspaceKey, key) {
|
|
@@ -5857,6 +6420,10 @@ export class Core extends ReadyResource {
|
|
|
5857
6420
|
if (await this._departing(key)) {
|
|
5858
6421
|
return;
|
|
5859
6422
|
}
|
|
6423
|
+
const meshId = b4a.toHex(key);
|
|
6424
|
+
if (this._opening.has(meshId) || this._pooled(meshId)) {
|
|
6425
|
+
return;
|
|
6426
|
+
}
|
|
5860
6427
|
const pending = await this.local.readPurge(key);
|
|
5861
6428
|
if (pending) {
|
|
5862
6429
|
await purgeCores(this.store, this.storage, pending.cores ?? []);
|
|
@@ -5897,7 +6464,7 @@ export class Core extends ReadyResource {
|
|
|
5897
6464
|
return;
|
|
5898
6465
|
}
|
|
5899
6466
|
const seed = await this._ownProjectSeed(workspace, id);
|
|
5900
|
-
if (!seed) {
|
|
6467
|
+
if (!seed || !this._mayFollowProjects(workspace)) {
|
|
5901
6468
|
return;
|
|
5902
6469
|
}
|
|
5903
6470
|
const session = this.local.createCandidateSession(seed, id, {
|
|
@@ -6082,7 +6649,7 @@ export class Core extends ReadyResource {
|
|
|
6082
6649
|
_meshPool() {
|
|
6083
6650
|
return (meshId, request = {}) => {
|
|
6084
6651
|
const pooled = this._pooled(meshId);
|
|
6085
|
-
if (pooled && this._isForeign(pooled)) {
|
|
6652
|
+
if ((pooled && this._isForeign(pooled)) || this._isHidden(meshId, pooled?.workspaceKey)) {
|
|
6086
6653
|
return null;
|
|
6087
6654
|
}
|
|
6088
6655
|
if (pooled && this._definesAgents(pooled, request)) {
|
|
@@ -6199,7 +6766,7 @@ export class Core extends ReadyResource {
|
|
|
6199
6766
|
close: (meshId) => this.closeMesh(meshId),
|
|
6200
6767
|
label: (meshId, label) => this.setMeshLabel(meshId, label),
|
|
6201
6768
|
name: (meshId, name) => this.setMeshName(meshId, name),
|
|
6202
|
-
createMesh: (
|
|
6769
|
+
createMesh: () => this.createMesh(),
|
|
6203
6770
|
createWorkspace: (opts) => this.createWorkspace(opts),
|
|
6204
6771
|
leaveWorkspace: (meshId) => this.leaveWorkspace(meshId),
|
|
6205
6772
|
createProject: (workspaceId, opts) => this.createProject(workspaceId, opts),
|
|
@@ -6641,6 +7208,17 @@ export class Core extends ReadyResource {
|
|
|
6641
7208
|
blindPeers: mesh.blindPeerStats()
|
|
6642
7209
|
};
|
|
6643
7210
|
}
|
|
7211
|
+
_meshProgress(mesh) {
|
|
7212
|
+
return {
|
|
7213
|
+
role: mesh.role,
|
|
7214
|
+
writable: mesh.writable,
|
|
7215
|
+
localLength: mesh.localLength,
|
|
7216
|
+
systemLength: mesh.autobee.system.bee.head()?.length ?? 0,
|
|
7217
|
+
viewLength: mesh.view.db.head()?.length ?? 0,
|
|
7218
|
+
fastForwards: mesh.autobee.stats.fastForwards,
|
|
7219
|
+
bootFrom: mesh.bootFrom
|
|
7220
|
+
};
|
|
7221
|
+
}
|
|
6644
7222
|
_diagnostics() {
|
|
6645
7223
|
const mesh = this._accountMesh();
|
|
6646
7224
|
const publicMesh = this._publicMesh();
|
|
@@ -6662,6 +7240,7 @@ export class Core extends ReadyResource {
|
|
|
6662
7240
|
state: this._statusState(),
|
|
6663
7241
|
mesh: mesh ? this._meshDiagnostics(mesh) : null,
|
|
6664
7242
|
publicMesh: publicMesh ? this._meshDiagnostics(publicMesh) : null,
|
|
7243
|
+
meshes: Object.fromEntries([...this._meshes].map(([id, { mesh }]) => [id, this._meshProgress(mesh)])),
|
|
6665
7244
|
network: dht
|
|
6666
7245
|
? {
|
|
6667
7246
|
online: dht.online ?? null,
|
|
@@ -6688,24 +7267,28 @@ export class Core extends ReadyResource {
|
|
|
6688
7267
|
state: this._statusState(),
|
|
6689
7268
|
peerCount: peerDeviceIds.length,
|
|
6690
7269
|
peerDeviceIds,
|
|
6691
|
-
kickedPending: this.
|
|
7270
|
+
kickedPending: this._kickNotice,
|
|
6692
7271
|
error: this._statusError ?? undefined,
|
|
6693
7272
|
blindPeersConnected: blindPeers.filter((peer) => peer.connected).length,
|
|
6694
7273
|
blindPeersTotal: blindPeers.length
|
|
6695
7274
|
};
|
|
6696
7275
|
}
|
|
6697
7276
|
acknowledgeKicked() {
|
|
6698
|
-
if (!this.
|
|
7277
|
+
if (!this._kickNotice)
|
|
6699
7278
|
return;
|
|
6700
|
-
this.
|
|
7279
|
+
this._kickNotice = false;
|
|
6701
7280
|
this._notifyStatus();
|
|
6702
7281
|
}
|
|
7282
|
+
_accountKicked() {
|
|
7283
|
+
const account = this._accountMesh();
|
|
7284
|
+
return !!account && this._kickedMeshes.has(this._meshIdOf(account));
|
|
7285
|
+
}
|
|
6703
7286
|
_statusState() {
|
|
6704
7287
|
if (this._statusError)
|
|
6705
7288
|
return 'error';
|
|
6706
7289
|
if (this.closing || this._leaving)
|
|
6707
7290
|
return 'leaving';
|
|
6708
|
-
if (this.
|
|
7291
|
+
if (this._accountKicked()) {
|
|
6709
7292
|
return 'kicked';
|
|
6710
7293
|
}
|
|
6711
7294
|
if (this._upgradeRequired) {
|
|
@@ -6774,6 +7357,12 @@ async function closeConfigReader(reader) {
|
|
|
6774
7357
|
await reader.core.close().catch(noop);
|
|
6775
7358
|
await reader.close().catch(noop);
|
|
6776
7359
|
}
|
|
7360
|
+
async function inviteHead(mesh) {
|
|
7361
|
+
const auto = mesh.autobee;
|
|
7362
|
+
const info = await auto.system.getInfo();
|
|
7363
|
+
const head = info && info.view.length > 0 ? await auto.trusted.mostRecentTrusted(auto.view, null) : null;
|
|
7364
|
+
return head ? { key: head.key, length: head.length } : null;
|
|
7365
|
+
}
|
|
6777
7366
|
async function recordedBlockIsLocal(core) {
|
|
6778
7367
|
await raceResource(core, core.ready(), 'config core');
|
|
6779
7368
|
const length = Number((await raceResource(core, core.getUserData('hyperconf'), 'config core')) || '0');
|