corestore 6.15.1 → 6.15.2
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 +4 -11
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -277,6 +277,7 @@ module.exports = class Corestore extends ReadyResource {
|
|
|
277
277
|
const core = new Hypercore(p => this.storage(storageRoot + '/' + p), {
|
|
278
278
|
_preready: this._preready.bind(this),
|
|
279
279
|
autoClose: true,
|
|
280
|
+
active: false,
|
|
280
281
|
encryptionKey: opts.encryptionKey || null,
|
|
281
282
|
userData,
|
|
282
283
|
manifest,
|
|
@@ -311,7 +312,7 @@ module.exports = class Corestore extends ReadyResource {
|
|
|
311
312
|
}
|
|
312
313
|
|
|
313
314
|
async createKeyPair (name, namespace = this._namespace) {
|
|
314
|
-
if (!this.
|
|
315
|
+
if (!this.opened) await this.ready()
|
|
315
316
|
|
|
316
317
|
const keyPair = {
|
|
317
318
|
publicKey: b4a.allocUnsafe(sodium.crypto_sign_PUBLICKEYBYTES),
|
|
@@ -342,7 +343,7 @@ module.exports = class Corestore extends ReadyResource {
|
|
|
342
343
|
...opts,
|
|
343
344
|
name: null,
|
|
344
345
|
preload: async () => {
|
|
345
|
-
if (!this.
|
|
346
|
+
if (!this.opened) await this.ready()
|
|
346
347
|
|
|
347
348
|
const keys = await this._generateKeys(opts)
|
|
348
349
|
|
|
@@ -359,26 +360,18 @@ module.exports = class Corestore extends ReadyResource {
|
|
|
359
360
|
this._findingPeers.push(core.findingPeers())
|
|
360
361
|
}
|
|
361
362
|
|
|
362
|
-
const updateReplication = () => {
|
|
363
|
-
if (core.replicator !== null) {
|
|
364
|
-
// if the only session left is the internal session + replication sessions, tell the replicator so it can gc
|
|
365
|
-
core.replicator.setDownloading(core.replicator.sessions + 1 !== core.sessions.length)
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
|
|
369
363
|
const gc = () => {
|
|
370
364
|
// technically better to also clear _findingPeers if we added it,
|
|
371
365
|
// but the lifecycle for those are pretty short so prob not worth the complexity
|
|
372
366
|
// as _decFindingPeers clear them all.
|
|
373
367
|
this._sessions.delete(core)
|
|
374
|
-
updateReplication()
|
|
375
368
|
|
|
376
369
|
if (!rw) return
|
|
377
370
|
rw.write.unlock()
|
|
378
371
|
if (!rw.write.locked) this._locks.delete(id)
|
|
379
372
|
}
|
|
380
373
|
|
|
381
|
-
core.ready().
|
|
374
|
+
core.ready().catch(gc)
|
|
382
375
|
core.once('close', gc)
|
|
383
376
|
|
|
384
377
|
return core
|