hypercore 10.36.0 → 10.36.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/README.md CHANGED
@@ -478,3 +478,11 @@ Emitted when a new connection has been established with a peer.
478
478
  #### `core.on('peer-remove')`
479
479
 
480
480
  Emitted when a peer's connection has been closed.
481
+
482
+ #### `core.on('upload', index, byteLength, peer)`
483
+
484
+ Emitted when a block is uploaded to a peer.
485
+
486
+ #### `core.on('download', index, byteLength, peer)`
487
+
488
+ Emitted when a block is downloaded from a peer.
package/index.js CHANGED
@@ -335,6 +335,10 @@ module.exports = class Hypercore extends EventEmitter {
335
335
  ensureEncryption(this, opts)
336
336
  }
337
337
 
338
+ if (opts.manifest && !this.core.header.manifest) {
339
+ await this.core.setManifest(opts.manifest)
340
+ }
341
+
338
342
  this.writable = this._isWritable()
339
343
 
340
344
  if (opts.valueEncoding) {
package/lib/core.js CHANGED
@@ -194,7 +194,21 @@ module.exports = class Core {
194
194
  return new this(header, compat, crypto, oplog, bigHeader, tree, blocks, bitfield, verifier, legacy, opts.onupdate || noop, opts.onconflict || noop)
195
195
  }
196
196
 
197
- setManifest (manifest, keyPair) {
197
+ async setManifest (manifest) {
198
+ await this._mutex.lock()
199
+
200
+ try {
201
+ if (manifest && this.header.manifest === null) {
202
+ if (!Verifier.isValidManifest(this.header.key, manifest)) throw INVALID_CHECKSUM('Manifest hash does not match')
203
+ this._setManifest(Verifier.createManifest(manifest), null)
204
+ await this._flushOplog()
205
+ }
206
+ } finally {
207
+ this._mutex.unlock()
208
+ }
209
+ }
210
+
211
+ _setManifest (manifest, keyPair) {
198
212
  if (!manifest && b4a.equals(keyPair.publicKey, this.header.key)) manifest = Verifier.defaultSignerManifest(this.header.key)
199
213
  if (!manifest) return
200
214
 
@@ -430,7 +444,7 @@ module.exports = class Core {
430
444
  await this._mutex.lock()
431
445
 
432
446
  // upsert compat manifest
433
- if (this.verifier === null && keyPair) this.setManifest(null, keyPair)
447
+ if (this.verifier === null && keyPair) this._setManifest(null, keyPair)
434
448
 
435
449
  try {
436
450
  const batch = await this.tree.truncate(length, fork)
@@ -549,7 +563,7 @@ module.exports = class Core {
549
563
 
550
564
  try {
551
565
  // upsert compat manifest
552
- if (this.verifier === null && keyPair) this.setManifest(null, keyPair)
566
+ if (this.verifier === null && keyPair) this._setManifest(null, keyPair)
553
567
 
554
568
  if (this.tree.fork !== batch.fork) return null
555
569
 
@@ -623,7 +637,7 @@ module.exports = class Core {
623
637
 
624
638
  try {
625
639
  // upsert compat manifest
626
- if (this.verifier === null && keyPair) this.setManifest(null, keyPair)
640
+ if (this.verifier === null && keyPair) this._setManifest(null, keyPair)
627
641
 
628
642
  if (preappend) await preappend(values)
629
643
 
@@ -790,7 +804,7 @@ module.exports = class Core {
790
804
  // if we got a manifest AND its strictly a non compat one, lets store it
791
805
  if (manifest && this.header.manifest === null) {
792
806
  if (!Verifier.isValidManifest(this.header.key, manifest)) throw INVALID_CHECKSUM('Manifest hash does not match')
793
- this.setManifest(manifest, null)
807
+ this._setManifest(manifest, null)
794
808
  }
795
809
 
796
810
  batch.commit()
package/lib/replicator.js CHANGED
@@ -1491,12 +1491,14 @@ module.exports = class Replicator {
1491
1491
  }
1492
1492
 
1493
1493
  clearRequests (session, err = null) {
1494
+ let cleared = false
1494
1495
  while (session.length > 0) {
1495
1496
  const ref = session[session.length - 1]
1496
1497
  ref.context.detach(ref, err)
1498
+ cleared = true
1497
1499
  }
1498
1500
 
1499
- this.updateAll()
1501
+ if (cleared) this.updateAll()
1500
1502
  }
1501
1503
 
1502
1504
  _addUpgradeMaybe () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "10.36.0",
3
+ "version": "10.36.2",
4
4
  "description": "Hypercore is a secure, distributed append-only log",
5
5
  "main": "index.js",
6
6
  "scripts": {