hypercore 10.30.4 → 10.30.5

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
@@ -391,7 +391,8 @@ module.exports = class Hypercore extends EventEmitter {
391
391
  eagerUpgrade: true,
392
392
  allowFork: opts.allowFork !== false,
393
393
  onpeerupdate: this._onpeerupdate.bind(this),
394
- onupload: this._onupload.bind(this)
394
+ onupload: this._onupload.bind(this),
395
+ oninvalid: this._oninvalid.bind(this)
395
396
  })
396
397
 
397
398
  this.replicator.findingPeers += this._findingPeers
@@ -624,6 +625,12 @@ module.exports = class Hypercore extends EventEmitter {
624
625
  }
625
626
  }
626
627
 
628
+ _oninvalid (err, req, res, from) {
629
+ for (let i = 0; i < this.sessions.length; i++) {
630
+ this.sessions[i].emit('verification-error', err, req, res, from)
631
+ }
632
+ }
633
+
627
634
  async _oncoreconflict (proof, from) {
628
635
  await this.replicator.onconflict(from)
629
636
 
package/lib/replicator.js CHANGED
@@ -636,11 +636,11 @@ class Peer {
636
636
  this.wireCancel.send({ request: id })
637
637
  }
638
638
 
639
- _checkIfConflict (err) {
639
+ _checkIfConflict () {
640
640
  this.paused = true
641
641
 
642
642
  const length = Math.min(this.core.tree.length, this.remoteLength)
643
- if (length === 0) throw err
643
+ if (length === 0) return // pause and ignore
644
644
 
645
645
  this.wireRequest.send({
646
646
  id: 0, // TODO: use an more explicit id for this eventually...
@@ -675,7 +675,14 @@ class Peer {
675
675
  this.replicator._removeInflight(req.id)
676
676
  }
677
677
 
678
- if (reorg === true) return this.replicator._onreorgdata(this, req, data)
678
+ try {
679
+ if (reorg === true) return await this.replicator._onreorgdata(this, req, data)
680
+ } catch (err) {
681
+ safetyCatch(err)
682
+ this.paused = true
683
+ this.replicator.oninvalid(err, req, data, this)
684
+ return
685
+ }
679
686
 
680
687
  this.dataProcessing++
681
688
 
@@ -690,9 +697,10 @@ class Peer {
690
697
 
691
698
  if (err.code !== 'INVALID_OPERATION') {
692
699
  // might be a fork, verify
693
- this._checkIfConflict(err)
700
+ this._checkIfConflict()
694
701
  }
695
702
  this.replicator._onnodata(this, req)
703
+ this.replicator.oninvalid(err, req, data, this)
696
704
  return
697
705
  } finally {
698
706
  this.dataProcessing--
@@ -1104,7 +1112,7 @@ class Peer {
1104
1112
  }
1105
1113
 
1106
1114
  module.exports = class Replicator {
1107
- constructor (core, key, { eagerUpgrade = true, allowFork = true, onpeerupdate = noop, onupload = noop } = {}) {
1115
+ constructor (core, key, { eagerUpgrade = true, allowFork = true, onpeerupdate = noop, onupload = noop, oninvalid = noop } = {}) {
1108
1116
  this.key = key
1109
1117
  this.discoveryKey = core.crypto.discoveryKey(key)
1110
1118
  this.core = core
@@ -1112,6 +1120,7 @@ module.exports = class Replicator {
1112
1120
  this.allowFork = allowFork
1113
1121
  this.onpeerupdate = onpeerupdate
1114
1122
  this.onupload = onupload
1123
+ this.oninvalid = oninvalid
1115
1124
  this.ondownloading = null // optional external hook for monitoring downloading status
1116
1125
  this.peers = []
1117
1126
  this.findingPeers = 0 // updateable from the outside
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "10.30.4",
3
+ "version": "10.30.5",
4
4
  "description": "Hypercore is a secure, distributed append-only log",
5
5
  "main": "index.js",
6
6
  "scripts": {