@qvac/core 0.7.6 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,11 +9,11 @@ import ReadyResource from 'ready-resource';
9
9
  import { Files } from './files/index.js';
10
10
  import MeshDefinition from '../../spec/mesh/hyperdb/index.js';
11
11
  import { Router, encode } from '../../spec/mesh/hyperdispatch/index.js';
12
- import { syncChanges } from './sync/index.js';
12
+ import { syncChanges, syncSnapshot } from './sync/index.js';
13
13
  import { buildDefaultSeed, isOwnKickedRow, isOwnRevokedRow } from './helpers/index.js';
14
14
  import { raceResource } from '../race-resource.js';
15
- import { signDeviceAttestation, signWriterClaim } from './device-attestation.js';
16
- import { liveDeviceForWriter } from './contract/activity.js';
15
+ import { signDeviceAttestation, signWriterClaim, verifyWriterClaim } from './device-attestation.js';
16
+ import { devicesByWriterKey, liveDeviceForWriter } from './contract/activity.js';
17
17
  import { assertComputeRoute } from './contract/compute.js';
18
18
  import { MESH_NAME_ROW } from './contract/mesh-name.js';
19
19
  import { registerRoutes } from './contract/index.js';
@@ -67,7 +67,6 @@ export class Mesh extends ReadyResource {
67
67
  _writerSeed;
68
68
  _log;
69
69
  _blindPeerKeys;
70
- _blindPeeringOpts;
71
70
  _bootFrom;
72
71
  _wakeup;
73
72
  attachmentUrl;
@@ -78,6 +77,9 @@ export class Mesh extends ReadyResource {
78
77
  _deviceKeyPair;
79
78
  _encryptionKey;
80
79
  _blindPeering = null;
80
+ _openedAt = 0;
81
+ _trustedDevice;
82
+ _joined = false;
81
83
  _orphanedBlobSweepStatus = { state: 'pending' };
82
84
  _bootInterrupted = false;
83
85
  _localWriterUploadedLength = 0;
@@ -137,7 +139,10 @@ export class Mesh extends ReadyResource {
137
139
  if (!peering?.blindPeers) {
138
140
  return [];
139
141
  }
140
- return [...peering.blindPeers.values()].map((bp) => ({
142
+ const own = new Set(this._blindPeerKeys.map((key) => b4a.toHex(key)));
143
+ return [...peering.blindPeers.values()]
144
+ .filter((bp) => own.has(b4a.toHex(bp.remotePublicKey)))
145
+ .map((bp) => ({
141
146
  key: b4a.toHex(bp.remotePublicKey).slice(0, 16),
142
147
  connected: bp.connected,
143
148
  connects: bp.connects,
@@ -229,8 +234,8 @@ export class Mesh extends ReadyResource {
229
234
  this._slowWriteMs = opts.slowWriteMs ?? SLOW_WRITE_MS;
230
235
  this._slowDrainMs = opts.slowDrainMs ?? SLOW_DRAIN_MS;
231
236
  this._blindPeerKeys = opts.blindPeerKeys ?? [];
232
- this._blindPeeringOpts = opts.blindPeeringOpts;
233
237
  this._bootFrom = opts.bootFrom;
238
+ this._trustedDevice = opts.trustedDevice ?? null;
234
239
  this._deviceId = opts.deviceId ?? null;
235
240
  this._wakeup = opts.wakeup;
236
241
  this.attachmentUrl = opts.attachmentUrl ?? null;
@@ -244,14 +249,23 @@ export class Mesh extends ReadyResource {
244
249
  registerRoutes(this.router, { compute: this._compute });
245
250
  }
246
251
  async _open() {
247
- this._log?.info(this._scope, 'opening');
252
+ this._openedAt = Date.now();
253
+ this._log?.info(this._scope, 'opening', {
254
+ creator: this._key === null,
255
+ compute: this._compute,
256
+ bootFrom: this._bootFrom?.length ?? null,
257
+ blindPeers: this._blindPeerKeys.length
258
+ });
248
259
  const namespace = this._store.namespace(this.discoveryKey);
249
260
  const blobCore = namespace.get({ name: 'qvac-blobs', encryptionKey: this._encryptionKey });
250
261
  const blobs = new Hyperblobs(blobCore);
251
262
  this._blobs = blobs;
252
263
  try {
253
264
  await raceResource(blobs.core, blobs.ready(), 'blobs');
254
- this._log?.info(this._scope, 'blob store opened');
265
+ this._log?.info(this._scope, 'blob store opened', {
266
+ blobs: blobs.core.length,
267
+ sinceOpenMs: this._sinceOpen()
268
+ });
255
269
  const writerKeyPair = await namespace.createKeyPair(this._writerSeed ?? 'local');
256
270
  const autobee = new Autobee(namespace, this._key, {
257
271
  open: this._autobeeOpen.bind(this),
@@ -274,8 +288,10 @@ export class Mesh extends ReadyResource {
274
288
  this.autobee.on('move-to', (to, from) => this._log?.info(this._scope, 'fast-forwarded onto a head', {
275
289
  from: from?.length ?? 0,
276
290
  to: to?.length ?? 0,
277
- fastForwards: this.autobee.stats.fastForwards
291
+ fastForwards: this.autobee.stats.fastForwards,
292
+ sinceOpenMs: this._sinceOpen()
278
293
  }));
294
+ this.autobee.on('move-to', () => void this._prefetchView().catch(noop));
279
295
  this.autobee.on('interrupt', (err) => this._log?.warn(this._scope, 'autobee interrupt', err));
280
296
  if (this._bootInterrupted) {
281
297
  void this.autobee.close().catch(noop);
@@ -294,39 +310,66 @@ export class Mesh extends ReadyResource {
294
310
  void this.refreshOurMember().catch((err) => this._log?.warn(this._scope, 'reading our member failed', err));
295
311
  this._log?.info(this._scope, 'autobee opened', {
296
312
  writable: this.autobee.writable,
297
- creator: this._key === null
313
+ creator: this._key === null,
314
+ ...this._lengths(),
315
+ fastForwards: this.autobee.stats.fastForwards,
316
+ writers: this.writerCount,
317
+ sinceOpenMs: this._sinceOpen()
298
318
  });
299
319
  void this._sweepOrphanedBlobs(this.blobs.core.length);
300
320
  this.files.start({ deviceId: this._deviceId });
301
321
  }
302
- startBlindPeering(dht, { suspended = false } = {}) {
322
+ startBlindPeering(peering) {
303
323
  if (this.closing || this._blindPeering || !this._autobee || !this._blobs) {
304
324
  return;
305
325
  }
306
- this._blindPeering = new BlindPeering(dht, this._store, {
307
- pick: 2,
308
- suspended,
309
- wakeup: this._wakeup,
310
- ...this._blindPeeringOpts
311
- });
312
- this._blindPeering.addAutobaseBackground(this._autobee, {
326
+ this._blindPeering = peering;
327
+ peering.addAutobaseBackground(this._autobee, {
313
328
  target: this._keyPair.publicKey,
314
- keys: this._blindPeerKeys
329
+ keys: this._blindPeerKeys,
330
+ pick: 2
315
331
  });
316
- this._blindPeering.addCoreBackground(this._blobs.core, {
332
+ peering.addCoreBackground(this._blobs.core, {
317
333
  target: this._keyPair.publicKey,
318
- keys: this._blindPeerKeys
334
+ keys: this._blindPeerKeys,
335
+ pick: 2
319
336
  });
320
- this._log?.info(this._scope, 'blind peering started');
337
+ this._log?.info(this._scope, 'blind peering started', { peers: this._blindPeerKeys.length });
321
338
  }
322
- async stopBlindPeering() {
323
- const peering = this._blindPeering;
324
- if (!peering) {
339
+ stopBlindPeering() {
340
+ if (!this._blindPeering) {
325
341
  return;
326
342
  }
327
343
  this._blindPeering = null;
328
- await peering.close();
329
- this._log?.info(this._scope, 'blind peering stopped');
344
+ this._log?.info(this._scope, 'blind peering stopped', { peers: this._blindPeerKeys.length });
345
+ }
346
+ get bootFrom() {
347
+ return this._bootFrom?.length ?? null;
348
+ }
349
+ get writerCount() {
350
+ let count = 0;
351
+ for (const _ of this.autobee.activeWriters) {
352
+ count++;
353
+ }
354
+ return count;
355
+ }
356
+ get uptimeMs() {
357
+ return this._openedAt ? this._sinceOpen() : 0;
358
+ }
359
+ blindPeersConnected() {
360
+ return this.blindPeerStats().filter((peer) => peer.connected).length;
361
+ }
362
+ _sinceOpen() {
363
+ return Date.now() - this._openedAt;
364
+ }
365
+ _lengths() {
366
+ return {
367
+ localLength: this.autobee.local.length,
368
+ systemLength: this.autobee.system.bee.head()?.length ?? 0,
369
+ viewLength: this.view.db.head()?.length ?? 0,
370
+ viewCore: viewCoreOf(this.view.db.head()),
371
+ flushes: this.autobee.system.flushes
372
+ };
330
373
  }
331
374
  async openBlobs(coreKey) {
332
375
  const core = this._store.get({ key: coreKey, encryptionKey: this._encryptionKey });
@@ -341,9 +384,13 @@ export class Mesh extends ReadyResource {
341
384
  }
342
385
  }
343
386
  async _close() {
344
- this._log?.info(this._scope, 'closing');
387
+ this._log?.info(this._scope, 'closing', {
388
+ sinceOpenMs: this._sinceOpen(),
389
+ ...this._lengths(),
390
+ ...this.autobee.stats
391
+ });
345
392
  await this._files?.close();
346
- await Promise.all([this.autobee.close(), this.blobs.close(), this._blindPeering?.close()]);
393
+ await Promise.all([this.autobee.close(), this.blobs.close()]);
347
394
  this._blindPeering = null;
348
395
  }
349
396
  async _sweepOrphanedBlobs(blobLength) {
@@ -489,8 +536,24 @@ export class Mesh extends ReadyResource {
489
536
  return this._birth.then(() => this._settleBirth());
490
537
  }
491
538
  async _settleBirth() {
539
+ const started = Date.now();
492
540
  await this.autobee.update();
493
541
  this.throwIfInterrupted();
542
+ const { applies, undos, drains, fastForwards } = this.autobee.stats;
543
+ this._log?.info(this._scope, 'joined', {
544
+ ms: Date.now() - started,
545
+ applies,
546
+ undos,
547
+ drains,
548
+ fastForwards,
549
+ ...this._lengths(),
550
+ sinceOpenMs: this._sinceOpen()
551
+ });
552
+ this._joined = true;
553
+ this.emit('joined');
554
+ }
555
+ get joined() {
556
+ return this._joined;
494
557
  }
495
558
  async _appendBirthOp(identity, device, { member, sharing = false } = {}) {
496
559
  if (this.autobee.local.length > 0)
@@ -568,14 +631,8 @@ export class Mesh extends ReadyResource {
568
631
  }
569
632
  async suspend() {
570
633
  await this._files?.suspend();
571
- if (this._blindPeering) {
572
- await this._blindPeering.suspend();
573
- }
574
634
  }
575
- async resume() {
576
- if (this._blindPeering) {
577
- await this._blindPeering.resume();
578
- }
635
+ resume() {
579
636
  this._files?.resume();
580
637
  }
581
638
  syncChatOrder = null;
@@ -611,7 +668,8 @@ export class Mesh extends ReadyResource {
611
668
  for await (const writer of target.db.find(LIVE_WRITERS_BY_MOST_RECENT, {
612
669
  reverse: true
613
670
  })) {
614
- if (await isOurTrustedWriter(snap, writer.writerKey, this._ourMemberId)) {
671
+ if ((await isOurTrustedWriter(snap, writer.writerKey, this._ourMemberId)) ||
672
+ (await this._vouchedByItsRow(target, reference, writer.writerKey))) {
615
673
  this._log?.debug(this._scope, 'vouching for a head', {
616
674
  writerKey: b4a.toHex(writer.writerKey).slice(0, 16),
617
675
  length: writer.length
@@ -626,6 +684,32 @@ export class Mesh extends ReadyResource {
626
684
  await snap.close();
627
685
  }
628
686
  }
687
+ async _vouchedByItsRow(target, reference, writerKey) {
688
+ if (!reference ||
689
+ !this._trustedDevice ||
690
+ (await devicesByWriterKey(reference.db, writerKey).one())) {
691
+ return false;
692
+ }
693
+ const device = await liveDeviceForWriter(target.db, writerKey);
694
+ if (!device?.deviceSignature) {
695
+ return false;
696
+ }
697
+ const binding = {
698
+ meshPublicKey: this.publicKey,
699
+ deviceId: device.id,
700
+ writerKey,
701
+ joinedAt: device.joinedAt
702
+ };
703
+ if (!verifyWriterClaim(device.deviceSignature, binding) ||
704
+ !(await this._trustedDevice(device.id))) {
705
+ return false;
706
+ }
707
+ this._log?.debug(this._scope, 'writer vouched by its row', {
708
+ writerKey: b4a.toHex(writerKey).slice(0, 16),
709
+ deviceId: b4a.toHex(device.id).slice(0, 16)
710
+ });
711
+ return true;
712
+ }
629
713
  _autobeeOpen(bee) {
630
714
  const db = HyperDB.bee2(bee, MeshDefinition, { autoUpdate: true });
631
715
  return { db };
@@ -634,7 +718,11 @@ export class Mesh extends ReadyResource {
634
718
  try {
635
719
  const counts = await Promise.all(WARMUP_COLLECTIONS.map((collection) => drain(view.db.find(collection))));
636
720
  const warmed = counts.reduce((total, count) => total + count, 0);
637
- this._log?.info(this._scope, 'warmed candidate view', { warmed });
721
+ this._log?.info(this._scope, 'warmed candidate view', {
722
+ warmed,
723
+ length: view.db.db.head()?.length ?? 0,
724
+ sinceOpenMs: this._sinceOpen()
725
+ });
638
726
  this.emit('warmup', { warmed });
639
727
  }
640
728
  catch (err) {
@@ -694,8 +782,17 @@ export class Mesh extends ReadyResource {
694
782
  }
695
783
  const shared = change.shared;
696
784
  const from = shared?.key ? { key: shared.key, length: shared.length } : change.from;
785
+ const started = Date.now();
697
786
  try {
698
- await syncChanges(this, view, from);
787
+ if (!from?.length) {
788
+ this._arrive();
789
+ }
790
+ else if (isIncremental(change)) {
791
+ await syncChanges(this, view, from);
792
+ }
793
+ else {
794
+ await syncSnapshot(this, view, from);
795
+ }
699
796
  if (this._admitted && !this.autobee.writable) {
700
797
  await this.checkOwnAdmission();
701
798
  }
@@ -703,6 +800,51 @@ export class Mesh extends ReadyResource {
703
800
  catch (err) {
704
801
  this._log?.warn(this._scope, 'change sync failed', err);
705
802
  }
803
+ this._log?.debug(this._scope, 'view synced', {
804
+ from: from?.length ?? 0,
805
+ to: change.to?.length ?? 0,
806
+ ms: Date.now() - started
807
+ });
808
+ }
809
+ _arrive() {
810
+ this._log?.info(this._scope, 'landed on the view', {
811
+ fastForwards: this.autobee.stats.fastForwards,
812
+ ...this._lengths(),
813
+ sinceOpenMs: this._sinceOpen()
814
+ });
815
+ this.emit('landed');
816
+ this.emit('indexing-dirty');
817
+ this.emit('agents-dirty');
818
+ this.emit('meshes-dirty', true);
819
+ void this._readLanding().catch((err) => {
820
+ if (!this.closing) {
821
+ this._log?.warn(this._scope, 'reading the landed view failed', err);
822
+ }
823
+ });
824
+ }
825
+ async _readLanding() {
826
+ const started = Date.now();
827
+ await Promise.all([this.refreshOurMember(), this.refreshMembership(), this.refreshName()]);
828
+ if (this.closing) {
829
+ return;
830
+ }
831
+ if (this._membership.unattested > 0) {
832
+ this.emit('unattested-device');
833
+ }
834
+ this.emit('membership-tallied');
835
+ this.emit('members-dirty');
836
+ this.emit('mesh-named');
837
+ this._log?.debug(this._scope, 'read the landed view', { ms: Date.now() - started });
838
+ }
839
+ async _prefetchView() {
840
+ const { context } = this.autobee.bee;
841
+ const cores = Array.from({ length: context.cores.length + 1 }, (_, i) => context.getCore(i));
842
+ const started = Date.now();
843
+ const fetched = await Promise.all(cores.map(prefetchCore));
844
+ const blocks = fetched.reduce((total, count) => total + count, 0);
845
+ if (blocks) {
846
+ this._log?.info(this._scope, 'prefetched the view', { blocks, ms: Date.now() - started });
847
+ }
706
848
  }
707
849
  async checkOwnAdmission() {
708
850
  if (this.autobee.writable) {
@@ -784,6 +926,30 @@ export class MeshBatch {
784
926
  }
785
927
  }
786
928
  function noop() { }
929
+ async function prefetchCore(core) {
930
+ await core.ready();
931
+ if (!core.length) {
932
+ await core.update({ wait: true });
933
+ }
934
+ const start = core.contiguousLength;
935
+ if (start >= core.length) {
936
+ return 0;
937
+ }
938
+ const range = core.download({ start, end: core.length });
939
+ try {
940
+ await range.done();
941
+ }
942
+ finally {
943
+ range.destroy();
944
+ }
945
+ return core.length - start;
946
+ }
947
+ function viewCoreOf(head) {
948
+ return isRecord(head) && b4a.isBuffer(head.key) ? b4a.toHex(head.key).slice(0, 8) : null;
949
+ }
950
+ function isIncremental(change) {
951
+ return isRecord(change) && change.incremental === true;
952
+ }
787
953
  function assertJoined(autobee, opts) {
788
954
  if (!opts?.optimistic && !autobee.writable)
789
955
  throw new Error(MESH_JOINING);
@@ -1,2 +1,3 @@
1
1
  import type { Mesh, MeshView, ViewHead } from '../mesh.ts';
2
2
  export declare function syncChanges(mesh: Mesh, view: MeshView, from: ViewHead): Promise<void>;
3
+ export declare function syncSnapshot(mesh: Mesh, view: MeshView, from: ViewHead): Promise<void>;
@@ -6,97 +6,166 @@ import { AGENTS, CHATS, CHUNKS, CHUNK_COUNTERS, DEVICES, KNOWLEDGE, KNOWLEDGE_AR
6
6
  export async function syncChanges(mesh, view, from) {
7
7
  if (mesh.closing)
8
8
  return;
9
- let indexingDirty = new Set();
10
- let unattestedDevice = false;
11
- let membershipMoved = false;
12
- let agentsDirty = false;
13
- let meshesChanged = false;
14
- const orderDirty = new Set();
15
- const purged = new Map();
16
- let nameChanged = false;
9
+ const pass = newPass();
17
10
  const snap = view.db.snapshot();
18
11
  const files = new FileChanges(snap, from);
19
12
  try {
20
- for await (const change of snap.changes({ from })) {
21
- if (mesh.closing)
22
- return;
23
- await files.add(change);
24
- if (change.type === 'delete') {
25
- continue;
26
- }
27
- if (changed(change, DEVICES)) {
28
- membershipMoved = true;
29
- unattestedDevice ||= !change.value.revoked && !change.value.memberId;
30
- syncOwnMember(mesh, change.value);
31
- syncDeviceRevocation(mesh, change.value);
32
- }
33
- else if (change.collection === MEMBERS) {
34
- membershipMoved = true;
35
- }
36
- else if (change.collection === AGENTS) {
37
- agentsDirty = true;
38
- }
39
- else if (changed(change, CHATS)) {
40
- orderDirty.add(change.value.id);
41
- syncChatTombstone(mesh, change.value);
42
- }
43
- else if (changed(change, CHUNK_COUNTERS)) {
44
- orderDirty.add(change.value.chatId);
45
- }
46
- else if (changed(change, CHUNKS)) {
47
- syncNotificationChunk(mesh, change.value);
48
- await mesh.files.syncAttachment(change.value);
49
- }
50
- else if (changed(change, KNOWLEDGE)) {
51
- await mesh.files.syncKnowledge(change.value);
52
- }
53
- else if (changed(change, KNOWLEDGE_ARTIFACTS)) {
54
- await mesh.files.syncArtifact(change.value);
55
- }
56
- else if (changed(change, PURGED_CHATS)) {
57
- purged.set(change.value.chatId, change.value.at);
58
- }
59
- else if (change.collection === '@qvac/joined-meshes' || change.collection === MESH_SEEDS) {
60
- meshesChanged = true;
61
- }
62
- else if (change.collection === MESH_NAMES) {
63
- nameChanged = true;
64
- }
65
- }
66
- indexingDirty = await files.ids();
13
+ try {
14
+ await walkChanges(mesh, { snap, from, files, pass });
15
+ }
16
+ catch (err) {
17
+ logger.warn('sync', 'change sync cut short', err);
18
+ pass.membershipMoved = pass.agentsDirty = pass.meshesChanged = pass.nameChanged = true;
19
+ }
20
+ pass.indexingDirty = await files.ids();
67
21
  }
68
22
  finally {
69
23
  await snap.close();
70
24
  }
71
- if (purged.size) {
72
- await mesh.fileIndex?.retireChats(purged);
73
- for (const chatId of purged.keys()) {
25
+ await settle(mesh, pass);
26
+ }
27
+ export async function syncSnapshot(mesh, view, from) {
28
+ if (mesh.closing)
29
+ return;
30
+ const pass = {
31
+ ...newPass(),
32
+ whole: true,
33
+ membershipMoved: true,
34
+ agentsDirty: true,
35
+ meshesChanged: true,
36
+ nameChanged: true
37
+ };
38
+ const snap = view.db.snapshot();
39
+ try {
40
+ await walkSnapshot(mesh, { snap, from, pass });
41
+ }
42
+ catch (err) {
43
+ logger.warn('sync', 'snapshot sync cut short', err);
44
+ }
45
+ finally {
46
+ await snap.close();
47
+ }
48
+ await settle(mesh, pass);
49
+ }
50
+ async function walkSnapshot(mesh, { snap, from, pass }) {
51
+ for await (const device of snap.find(DEVICES)) {
52
+ if (mesh.closing)
53
+ return;
54
+ syncDevice(mesh, pass, device);
55
+ }
56
+ for await (const chat of snap.find(CHATS)) {
57
+ if (mesh.closing)
58
+ return;
59
+ if (!chat.deletedAt)
60
+ continue;
61
+ const before = await snap.get(CHATS, { id: chat.id }, { checkout: from });
62
+ if (!before?.deletedAt) {
63
+ syncChatTombstone(mesh, chat);
64
+ }
65
+ }
66
+ for await (const row of snap.find(PURGED_CHATS)) {
67
+ pass.purged.set(row.chatId, row.at);
68
+ }
69
+ }
70
+ function newPass() {
71
+ return {
72
+ whole: false,
73
+ indexingDirty: new Set(),
74
+ orderDirty: new Set(),
75
+ purged: new Map(),
76
+ unattestedDevice: false,
77
+ membershipMoved: false,
78
+ agentsDirty: false,
79
+ meshesChanged: false,
80
+ nameChanged: false
81
+ };
82
+ }
83
+ function syncDevice(mesh, pass, device) {
84
+ pass.membershipMoved = true;
85
+ pass.unattestedDevice ||= !device.revoked && !device.memberId;
86
+ syncOwnMember(mesh, device);
87
+ syncDeviceRevocation(mesh, device);
88
+ }
89
+ async function settle(mesh, pass) {
90
+ if (mesh.closing)
91
+ return;
92
+ if (pass.purged.size) {
93
+ await mesh.fileIndex?.retireChats(pass.purged);
94
+ for (const chatId of pass.purged.keys()) {
74
95
  mesh.emit('chat-purged', chatId);
75
96
  }
76
97
  }
77
- if (indexingDirty.size) {
78
- mesh.emit('indexing-dirty', indexingDirty);
98
+ if (pass.whole) {
99
+ mesh.emit('indexing-dirty');
79
100
  }
80
- if (unattestedDevice) {
101
+ else if (pass.indexingDirty.size) {
102
+ mesh.emit('indexing-dirty', pass.indexingDirty);
103
+ }
104
+ if (pass.unattestedDevice) {
81
105
  mesh.emit('unattested-device');
82
106
  }
83
- if (membershipMoved) {
107
+ if (pass.membershipMoved) {
84
108
  await mesh.refreshMembership();
85
109
  mesh.emit('membership-tallied');
86
110
  mesh.emit('members-dirty');
87
111
  }
88
- if (agentsDirty) {
112
+ if (pass.agentsDirty) {
89
113
  mesh.emit('agents-dirty');
90
114
  }
91
- if (orderDirty.size && mesh.syncChatOrder) {
92
- await mesh.syncChatOrder(orderDirty);
115
+ if ((pass.whole || pass.orderDirty.size) && mesh.syncChatOrder) {
116
+ await mesh.syncChatOrder(pass.whole ? null : pass.orderDirty);
93
117
  }
94
- mesh.emit('meshes-dirty', meshesChanged);
95
- if (nameChanged) {
118
+ mesh.emit('meshes-dirty', pass.meshesChanged);
119
+ if (pass.nameChanged) {
96
120
  await mesh.refreshName();
97
121
  mesh.emit('mesh-named');
98
122
  }
99
123
  }
124
+ async function walkChanges(mesh, { snap, from, files, pass }) {
125
+ for await (const change of snap.changes({ from })) {
126
+ if (mesh.closing)
127
+ return;
128
+ await files.add(change);
129
+ if (change.type === 'delete') {
130
+ continue;
131
+ }
132
+ if (changed(change, DEVICES)) {
133
+ syncDevice(mesh, pass, change.value);
134
+ }
135
+ else if (change.collection === MEMBERS) {
136
+ pass.membershipMoved = true;
137
+ }
138
+ else if (change.collection === AGENTS) {
139
+ pass.agentsDirty = true;
140
+ }
141
+ else if (changed(change, CHATS)) {
142
+ pass.orderDirty.add(change.value.id);
143
+ syncChatTombstone(mesh, change.value);
144
+ }
145
+ else if (changed(change, CHUNK_COUNTERS)) {
146
+ pass.orderDirty.add(change.value.chatId);
147
+ }
148
+ else if (changed(change, CHUNKS)) {
149
+ syncNotificationChunk(mesh, change.value);
150
+ await mesh.files.syncAttachment(change.value);
151
+ }
152
+ else if (changed(change, KNOWLEDGE)) {
153
+ await mesh.files.syncKnowledge(change.value);
154
+ }
155
+ else if (changed(change, KNOWLEDGE_ARTIFACTS)) {
156
+ await mesh.files.syncArtifact(change.value);
157
+ }
158
+ else if (changed(change, PURGED_CHATS)) {
159
+ pass.purged.set(change.value.chatId, change.value.at);
160
+ }
161
+ else if (change.collection === '@qvac/joined-meshes' || change.collection === MESH_SEEDS) {
162
+ pass.meshesChanged = true;
163
+ }
164
+ else if (change.collection === MESH_NAMES) {
165
+ pass.nameChanged = true;
166
+ }
167
+ }
168
+ }
100
169
  function changed(change, collection) {
101
170
  return change.collection === collection;
102
171
  }
@@ -143,12 +143,12 @@ export declare class Core extends ReadyResource {
143
143
  private _minSupportedVersion;
144
144
  private readonly _otaConfigCore;
145
145
  private _otaConfig;
146
- private _configPeering;
146
+ private _blindPeering;
147
+ private _configPeered;
147
148
  private _blindPeeringOn;
148
149
  private readonly _blindPeeringListeners;
149
150
  private _recoveryCore;
150
151
  private _recoverySigner;
151
- private _recoveryPeering;
152
152
  private _localDevice;
153
153
  private readonly _blindPeerKeys;
154
154
  private readonly _blindPeeringOpts;
@@ -209,9 +209,6 @@ export declare class Core extends ReadyResource {
209
209
  private _identityPhrase;
210
210
  private _identityPublicKey;
211
211
  private _swarm;
212
- private _siblings;
213
- private readonly _seenPeers;
214
- private readonly _siblingLock;
215
212
  private readonly _onSwarmConnection;
216
213
  private _departures;
217
214
  private _fsDrives;
@@ -263,7 +260,7 @@ export declare class Core extends ReadyResource {
263
260
  private _openOtaConfig;
264
261
  private _logFloor;
265
262
  private _peerConfigCore;
266
- private _closeConfigPeering;
263
+ private _blindPeeringClient;
267
264
  private _closeOtaConfig;
268
265
  private _blockedByMinVersion;
269
266
  private _setUpgradeRequired;
@@ -299,6 +296,7 @@ export declare class Core extends ReadyResource {
299
296
  private _rerootRecovered;
300
297
  private _readRecovery;
301
298
  private _peerRecoveryCore;
299
+ private _closeBlindPeering;
302
300
  private _closeRecovery;
303
301
  private _joinBirthMember;
304
302
  private _knownBirthMember;
@@ -312,9 +310,6 @@ export declare class Core extends ReadyResource {
312
310
  private _stopBlindPeering;
313
311
  private _resumeBlindPeering;
314
312
  private _bringMeshOnline;
315
- private _dialSiblings;
316
- private _redialSiblings;
317
- private _siblingsToDial;
318
313
  private _advertiseDeviceProfile;
319
314
  private _advertiseAppVersion;
320
315
  private _retractInventory;
@@ -375,6 +370,7 @@ export declare class Core extends ReadyResource {
375
370
  private _wireMesh;
376
371
  private _adoptAccount;
377
372
  private _pooled;
373
+ private _isOurMemberDevice;
378
374
  private _accountMesh;
379
375
  private _meshIdOf;
380
376
  private _poolEntry;
@@ -442,7 +438,6 @@ export declare class Core extends ReadyResource {
442
438
  getMeshInvite(opts?: MeshInviteOptions): Promise<MeshInvite | null>;
443
439
  private _delegatePairing;
444
440
  previewMeshInvite(invite: string): MeshInvitePreview;
445
- private _leaveSiblings;
446
441
  private _closeSwarm;
447
442
  pushSkillSecret(request: SecretRequest): Promise<void>;
448
443
  private _storeHandedOffSecret;