autobee 2.1.2 → 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.
Files changed (2) hide show
  1. package/index.js +56 -0
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autobee",
3
- "version": "2.1.2",
3
+ "version": "2.2.0",
4
4
  "description": "Bee based autobase",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Holepunch Inc.",