autobee 2.0.0-rc.32 → 2.0.0-rc.34
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/index.js +5 -0
- package/lib/writers.js +24 -56
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -461,6 +461,11 @@ module.exports = class Autobee extends ReadyResource {
|
|
|
461
461
|
for (const head of this.system.heads) {
|
|
462
462
|
await this.writers.add(head.key)
|
|
463
463
|
}
|
|
464
|
+
|
|
465
|
+
if (!this.system.heads.length) {
|
|
466
|
+
await this.writers.add(this.bootstrap.key)
|
|
467
|
+
}
|
|
468
|
+
|
|
464
469
|
await this._bump()
|
|
465
470
|
}
|
|
466
471
|
|
package/lib/writers.js
CHANGED
|
@@ -28,8 +28,6 @@ class ActiveWriters {
|
|
|
28
28
|
|
|
29
29
|
this.localWriter = new Writer(this, auto.system, true, local, b4a.toString(local.key, 'hex'))
|
|
30
30
|
this.localWriter.attach()
|
|
31
|
-
|
|
32
|
-
this._bootstrap()
|
|
33
31
|
}
|
|
34
32
|
|
|
35
33
|
get size() {
|
|
@@ -208,6 +206,7 @@ class ActiveWriters {
|
|
|
208
206
|
const encryption = this.auto.encryptionKey ? new WriterEncryption(this.auto) : null
|
|
209
207
|
|
|
210
208
|
const core = this.auto.store.get({
|
|
209
|
+
active: false,
|
|
211
210
|
key,
|
|
212
211
|
encryption,
|
|
213
212
|
group: local || !this.auto.wakeupCapability ? null : this.auto.wakeupCapability.discoveryKey
|
|
@@ -251,29 +250,6 @@ class ActiveWriters {
|
|
|
251
250
|
w.decouple()
|
|
252
251
|
if (w !== this.localWriter) await w.close()
|
|
253
252
|
}
|
|
254
|
-
|
|
255
|
-
_bootstrap() {
|
|
256
|
-
const bootstrap = this.auto.bootstrap
|
|
257
|
-
|
|
258
|
-
bootstrap.setEncryption(this.auto._getEncryptionProvider())
|
|
259
|
-
bootstrap.setActive(true)
|
|
260
|
-
|
|
261
|
-
const id = b4a.toString(bootstrap.key, 'hex')
|
|
262
|
-
let w = this.active.get(id)
|
|
263
|
-
if (w) {
|
|
264
|
-
w.isHead = true
|
|
265
|
-
w.couple() // couple if we weren't ready first time
|
|
266
|
-
return
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
const session = bootstrap.session()
|
|
270
|
-
session.setEncryption(this.auto._getEncryptionProvider())
|
|
271
|
-
|
|
272
|
-
w = new Writer(this, this.auto.system, false, session, id)
|
|
273
|
-
w.isHead = true // the root of the autobase, never gc'd
|
|
274
|
-
w.attach()
|
|
275
|
-
w.couple()
|
|
276
|
-
}
|
|
277
253
|
}
|
|
278
254
|
|
|
279
255
|
class Writer {
|
|
@@ -305,8 +281,6 @@ class Writer {
|
|
|
305
281
|
|
|
306
282
|
if (!local) this.core.on('append', this._onchangeBound)
|
|
307
283
|
if (!local) this.core.on('download', this._onchangeBound)
|
|
308
|
-
|
|
309
|
-
this.couple()
|
|
310
284
|
}
|
|
311
285
|
|
|
312
286
|
get isIndexer() {
|
|
@@ -314,6 +288,10 @@ class Writer {
|
|
|
314
288
|
}
|
|
315
289
|
|
|
316
290
|
isSystemHead() {
|
|
291
|
+
if (this.system.heads.length === 0) {
|
|
292
|
+
return b4a.equals(this.core.key, this.writers.auto.key)
|
|
293
|
+
}
|
|
294
|
+
|
|
317
295
|
return this.system.isHead(this.core.key)
|
|
318
296
|
}
|
|
319
297
|
|
|
@@ -403,26 +381,7 @@ class Writer {
|
|
|
403
381
|
this.waiting = null
|
|
404
382
|
}
|
|
405
383
|
|
|
406
|
-
const isHead = this.isSystemHead()
|
|
407
|
-
|
|
408
|
-
if (isHead && !this.isHead) {
|
|
409
|
-
this.isHead = true
|
|
410
|
-
this.couple()
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
if (!isHead && this.isHead) {
|
|
414
|
-
this.isHead = false
|
|
415
|
-
this.decouple()
|
|
416
|
-
}
|
|
417
|
-
|
|
418
384
|
const length = await this.update()
|
|
419
|
-
const active = length < this.core.length || length < this.hintedLength
|
|
420
|
-
|
|
421
|
-
if (this.isHead || active) {
|
|
422
|
-
this.core.setActive(true)
|
|
423
|
-
} else {
|
|
424
|
-
this.core.setActive(false)
|
|
425
|
-
}
|
|
426
385
|
|
|
427
386
|
// don't drop any local nodes left in buffer, or work a peer told us about
|
|
428
387
|
if (length < this.core.length || length < this.hintedLength || this.appending) {
|
|
@@ -474,12 +433,24 @@ class Writer {
|
|
|
474
433
|
|
|
475
434
|
async update() {
|
|
476
435
|
const info = await this.system.get(this.core.key)
|
|
436
|
+
const length = info ? info.length : 0
|
|
477
437
|
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
if (
|
|
481
|
-
|
|
482
|
-
|
|
438
|
+
const isHead = this.isSystemHead()
|
|
439
|
+
|
|
440
|
+
if (isHead) {
|
|
441
|
+
this.isHead = true
|
|
442
|
+
this.couple()
|
|
443
|
+
} else {
|
|
444
|
+
this.isHead = false
|
|
445
|
+
this.decouple()
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
const active = length < this.core.length || length < this.hintedLength
|
|
449
|
+
|
|
450
|
+
if (this.isHead || active) {
|
|
451
|
+
this.core.setActive(true)
|
|
452
|
+
} else {
|
|
453
|
+
this.core.setActive(false)
|
|
483
454
|
}
|
|
484
455
|
|
|
485
456
|
if (!info) {
|
|
@@ -495,7 +466,7 @@ class Writer {
|
|
|
495
466
|
this.writers._updateLocalState()
|
|
496
467
|
}
|
|
497
468
|
|
|
498
|
-
return
|
|
469
|
+
return length
|
|
499
470
|
}
|
|
500
471
|
|
|
501
472
|
next() {
|
|
@@ -720,6 +691,7 @@ class Writer {
|
|
|
720
691
|
head.views = views
|
|
721
692
|
|
|
722
693
|
head.trusted = trusted ? [{ key: trusted.key, length: trusted.length }] : null
|
|
694
|
+
this.writers.auto.emit('appending', this.pending)
|
|
723
695
|
|
|
724
696
|
const buffers = []
|
|
725
697
|
for (let i = 0; i < this.processed; i++) {
|
|
@@ -789,7 +761,3 @@ function finalizeNodeBatch(batch) {
|
|
|
789
761
|
}
|
|
790
762
|
|
|
791
763
|
function noop() {}
|
|
792
|
-
|
|
793
|
-
function isAnchor(core) {
|
|
794
|
-
return !!(core.manifest && core.manifest.signers.length === 0 && core.length === 1)
|
|
795
|
-
}
|