autobee 2.1.1 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +60 -3
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -166,11 +166,11 @@ module.exports = class Autobee extends ReadyResource {
|
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
get isIndexer() {
|
|
169
|
-
return this.writers.localWriter.isIndexer
|
|
169
|
+
return this.writers ? this.writers.localWriter.isIndexer : false
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
get writable() {
|
|
173
|
-
return this.writers.writable
|
|
173
|
+
return this.writers ? this.writers.writable : false
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
// autobase compat
|
|
@@ -265,6 +265,62 @@ module.exports = class Autobee extends ReadyResource {
|
|
|
265
265
|
return w.views()
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
+
// the cores a mirror should pin: our writer core, our views when we are
|
|
269
|
+
// trusted, and (with wait) the most recent trusted head so a mirror that
|
|
270
|
+
// forgets to add one still pins a valid entrypoint
|
|
271
|
+
async cores({ wait = true, local = true, all = false } = {}) {
|
|
272
|
+
if (!this._bootGuard.opened) await this._bootGuard.ready()
|
|
273
|
+
|
|
274
|
+
const result = { key: this.key, views: null, writers: [] }
|
|
275
|
+
const views = new Map()
|
|
276
|
+
|
|
277
|
+
if (local) {
|
|
278
|
+
result.writers.push(this.local.key)
|
|
279
|
+
|
|
280
|
+
if (await this.trusted.isTrusted(this.local.key, this.view)) {
|
|
281
|
+
const localViews = await this.writers.localWriter.views()
|
|
282
|
+
for (const { key } of localViews) {
|
|
283
|
+
views.set(b4a.toString(key, 'hex'), key)
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
if (wait) {
|
|
289
|
+
const head = await this.trusted.mostRecentTrusted(this.view, null)
|
|
290
|
+
|
|
291
|
+
if (head && (!local || !b4a.equals(head.key, this.local.key))) {
|
|
292
|
+
const oplog = await this._resolveOplogHint(head.key, head.length)
|
|
293
|
+
if (oplog && oplog.op.views) {
|
|
294
|
+
const skey = oplog.op.views.system.key
|
|
295
|
+
const vkey = oplog.op.views.view.key
|
|
296
|
+
|
|
297
|
+
views.set(b4a.toString(skey, 'hex'), skey)
|
|
298
|
+
views.set(b4a.toString(vkey, 'hex'), vkey)
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
result.writers.push(head.key)
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
if (all) {
|
|
305
|
+
const [viewCores, systemCores] = await Promise.all([
|
|
306
|
+
this.bee.cores({ local: false }),
|
|
307
|
+
this.system.bee.cores({ local: false })
|
|
308
|
+
])
|
|
309
|
+
|
|
310
|
+
for (const key of viewCores) {
|
|
311
|
+
views.set(b4a.toString(key, 'hex'), key)
|
|
312
|
+
}
|
|
313
|
+
for (const key of systemCores) {
|
|
314
|
+
views.set(b4a.toString(key, 'hex'), key)
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
result.views = [...views.values()]
|
|
320
|
+
|
|
321
|
+
return result
|
|
322
|
+
}
|
|
323
|
+
|
|
268
324
|
static getViewEncryption(bootstrap, encryptionKey, name) {
|
|
269
325
|
return AutobeeEncryption.getViewEncryption(bootstrap, encryptionKey, name)
|
|
270
326
|
}
|
|
@@ -347,7 +403,8 @@ module.exports = class Autobee extends ReadyResource {
|
|
|
347
403
|
|
|
348
404
|
openCore(key) {
|
|
349
405
|
const encryption = this.encryptionKey ? new WriterEncryption(this) : null
|
|
350
|
-
|
|
406
|
+
const group = this.wakeupCapability ? this.wakeupCapability.discoveryKey : null
|
|
407
|
+
return this.store.get({ key, encryption, group })
|
|
351
408
|
}
|
|
352
409
|
|
|
353
410
|
_getEncryptionProvider(view) {
|