corestore 6.15.3 → 6.15.4

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 +14 -5
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -294,9 +294,16 @@ module.exports = class Corestore extends ReadyResource {
294
294
  if (core.closing) return // extra safety here as ready is a tick after open
295
295
  if (hasKeyPair) core.setKeyPair(keyPair)
296
296
  this._emitCore('core-open', core)
297
- for (const { stream } of this._replicationStreams) {
298
- core.replicate(stream, { session: true })
297
+
298
+ const ondownloading = () => {
299
+ for (const { stream } of this._replicationStreams) {
300
+ core.replicate(stream, { session: true })
301
+ }
299
302
  }
303
+ // when the replicator says we are downloading, answer the call
304
+ core.replicator.ondownloading = ondownloading
305
+ // trigger once if the condition is already true
306
+ if (core.replicator.downloading) ondownloading()
300
307
  }, () => {
301
308
  this.cores.delete(id)
302
309
  })
@@ -382,7 +389,7 @@ module.exports = class Corestore extends ReadyResource {
382
389
  const stream = Hypercore.createProtocolStream(isInitiator, {
383
390
  ...opts,
384
391
  ondiscoverykey: async discoveryKey => {
385
- const core = this.get({ _discoveryKey: discoveryKey })
392
+ const core = this.get({ _discoveryKey: discoveryKey, active: false })
386
393
 
387
394
  try {
388
395
  await core.ready()
@@ -390,14 +397,16 @@ module.exports = class Corestore extends ReadyResource {
390
397
  return
391
398
  }
392
399
 
393
- if (this.passive && !core.closing) core.replicate(stream, { session: true })
400
+ // remote is asking for the core so we HAVE to answer even if not downloading
401
+ if (!core.closing) core.replicate(stream, { session: true })
394
402
  await core.close()
395
403
  }
396
404
  })
397
405
 
398
406
  if (!this.passive) {
399
407
  for (const core of this.cores.values()) {
400
- if (!core.opened || core.closing) continue // If the core is not opened, it will be replicated in preload.
408
+ // If the core is not opened, it will be replicated in preload.
409
+ if (!core.opened || core.closing || !core.replicator.downloading) continue
401
410
  core.replicate(stream, { session: true })
402
411
  }
403
412
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "corestore",
3
- "version": "6.15.3",
3
+ "version": "6.15.4",
4
4
  "description": "A Hypercore factory that simplifies managing collections of cores.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -31,7 +31,7 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "b4a": "^1.6.4",
34
- "hypercore": "^10.24.10",
34
+ "hypercore": "^10.25.0",
35
35
  "hypercore-crypto": "^3.4.0",
36
36
  "hypercore-id-encoding": "^1.2.0",
37
37
  "read-write-mutexify": "^2.1.0",