hypercore 11.13.4 → 11.14.1

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 CHANGED
@@ -453,6 +453,11 @@ class Hypercore extends EventEmitter {
453
453
  return this.closing
454
454
  }
455
455
 
456
+ clearRequests (activeRequests, error) {
457
+ if (!activeRequests.length) return
458
+ if (this.core) this.core.replicator.clearRequests(activeRequests, error)
459
+ }
460
+
456
461
  async _close (error) {
457
462
  if (this.opened === false) {
458
463
  try {
package/lib/core.js CHANGED
@@ -49,7 +49,6 @@ module.exports = class Core {
49
49
  this.destroyed = false
50
50
  this.closed = false
51
51
 
52
- this._manifestFlushed = false
53
52
  this._bitfield = null
54
53
  this._verifies = null
55
54
  this._verifiesFlushed = null
@@ -264,6 +263,14 @@ module.exports = class Core {
264
263
  // to unslab
265
264
  if (header.manifest) {
266
265
  header.manifest = Verifier.createManifest(header.manifest)
266
+ const tx = storage.write()
267
+ tx.setAuth({
268
+ key: header.key,
269
+ discoveryKey: crypto.discoveryKey(header.key),
270
+ manifest: header.manifest,
271
+ keyPair: header.keyPair
272
+ })
273
+ await tx.flush()
267
274
  }
268
275
 
269
276
  const verifier = header.manifest ? new Verifier(header.key, header.manifest, { crypto, legacy }) : null
@@ -279,8 +286,6 @@ module.exports = class Core {
279
286
  if (this.discoveryKey === null) this.discoveryKey = crypto.discoveryKey(this.key)
280
287
  if (this.id === null) this.id = z32.encode(this.key)
281
288
  if (this.manifest === null) this.manifest = this.header.manifest
282
-
283
- this._manifestFlushed = !!header.manifest
284
289
  }
285
290
 
286
291
  async audit (opts) {
@@ -329,7 +334,6 @@ module.exports = class Core {
329
334
 
330
335
  this.compat = verifier.compat
331
336
  this.verifier = verifier
332
- this._manifestFlushed = false
333
337
 
334
338
  this.replicator.onupgrade()
335
339
  this.emitManifest()
package/lib/replicator.js CHANGED
@@ -382,6 +382,7 @@ class Peer {
382
382
  this.remoteSupportsSeeks = false
383
383
  this.inflightRange = inflightRange
384
384
  this.remoteSegmentsWanted = new Set()
385
+ this.fullyDownloadedSignaled = false
385
386
 
386
387
  this.paused = false
387
388
  this.removed = false
@@ -482,6 +483,7 @@ class Peer {
482
483
  }
483
484
 
484
485
  signalUpgrade () {
486
+ if (this.fullyDownloadedSignaled && !this.replicator.fullyDownloaded()) this.fullyDownloadedSignaled = false
485
487
  if (this._shouldUpdateCanUpgrade() === true) this._updateCanUpgradeAndSync()
486
488
  else this.sendSync()
487
489
  }
@@ -501,13 +503,20 @@ class Peer {
501
503
 
502
504
  if (start + LAST_BLOCKS < this.core.state.length && !this.remoteSegmentsWanted.has(i) && !drop && !contig) return
503
505
 
506
+ let force = false
504
507
  if (contig && !drop) {
505
508
  start = 0
506
509
  length = this.core.state.length
510
+
511
+ // Always send the broadcast when we switch from sparse to fully contiguous, so remote knows too
512
+ if (!this.fullyDownloadedSignaled) {
513
+ this.fullyDownloadedSignaled = true
514
+ force = true
515
+ }
507
516
  }
508
517
 
509
518
  // TODO: consider also adding early-returns on the drop===true case
510
- if (!drop) {
519
+ if (!force && !drop) {
511
520
  // No need to broadcast if the remote already has this range
512
521
 
513
522
  if (this._remoteContiguousLength >= start + length) return
@@ -2156,6 +2165,11 @@ module.exports = class Replicator {
2156
2165
  for (const peer of this.peers) peer._resetMissingBlock(index)
2157
2166
  }
2158
2167
 
2168
+ fullyDownloaded () {
2169
+ if (!this.core.state.length) return false
2170
+ return this.core.state.length === this.core.header.hints.contiguousLength
2171
+ }
2172
+
2159
2173
  _ondata (peer, req, data) {
2160
2174
  req.elapsed = Date.now() - req.timestamp
2161
2175
  if (data.block !== null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "11.13.4",
3
+ "version": "11.14.1",
4
4
  "description": "Hypercore is a secure, distributed append-only log",
5
5
  "main": "index.js",
6
6
  "scripts": {