hypercore 11.41.0 → 11.41.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.
Files changed (2) hide show
  1. package/lib/replicator.js +9 -22
  2. package/package.json +1 -1
package/lib/replicator.js CHANGED
@@ -67,7 +67,7 @@ class Attachable {
67
67
  constructor(replicator) {
68
68
  this.replicator = replicator
69
69
  this.resolved = false
70
- this.processing = false
70
+ this.processing = 0
71
71
  this.refs = []
72
72
  this.wants = null
73
73
  }
@@ -129,7 +129,7 @@ class Attachable {
129
129
  }
130
130
 
131
131
  gc() {
132
- if (this.refs.length > 0 || this.processing) return
132
+ if (this.refs.length > 0 || this.processing > 0) return
133
133
  this._unref()
134
134
 
135
135
  if (this.wants === null) return
@@ -163,8 +163,7 @@ class Attachable {
163
163
  }
164
164
 
165
165
  processed() {
166
- this.processing = false
167
- this.gc()
166
+ if (--this.processing === 0) this.gc()
168
167
  }
169
168
 
170
169
  _cancel(r, err) {
@@ -1257,7 +1256,7 @@ class Peer {
1257
1256
  }
1258
1257
 
1259
1258
  this.dataProcessing++
1260
- if (isBlockRequest(req)) this.replicator._markProcessing(req.block.index)
1259
+ const processing = isBlockRequest(req) ? this.replicator._markProcessing(req.block.index) : null
1261
1260
 
1262
1261
  try {
1263
1262
  if (!this.replicator._matchingRequest(req, data) || !(await this.core.verify(data, this))) {
@@ -1292,7 +1291,7 @@ class Peer {
1292
1291
  this.replicator._oninvaliddata(err, req, data, this)
1293
1292
  return
1294
1293
  } finally {
1295
- if (isBlockRequest(req)) this.replicator._markProcessed(req.block.index)
1294
+ if (processing !== null) processing.processed()
1296
1295
  this.dataProcessing--
1297
1296
  }
1298
1297
 
@@ -2829,22 +2828,10 @@ module.exports = class Replicator {
2829
2828
  }
2830
2829
 
2831
2830
  _markProcessing(index) {
2832
- const b = this._blocks.get(index)
2833
- if (b) {
2834
- b.processing = true
2835
- return
2836
- }
2837
-
2838
- const h = this._hashes.get(index)
2839
- if (h) h.processing = true
2840
- }
2841
-
2842
- _markProcessed(index) {
2843
- const b = this._blocks.get(index)
2844
- if (b) return b.processed()
2845
-
2846
- const h = this._hashes.get(index)
2847
- if (h) h.processed()
2831
+ const b = this._blocks.get(index) || this._hashes.get(index)
2832
+ if (!b) return null
2833
+ b.processing++
2834
+ return b
2848
2835
  }
2849
2836
 
2850
2837
  _markInflight(index) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "11.41.0",
3
+ "version": "11.41.1",
4
4
  "description": "Hypercore is a secure, distributed append-only log",
5
5
  "main": "index.js",
6
6
  "scripts": {