hypercore 11.11.2 → 11.12.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 +14 -3
  2. package/package.json +1 -1
package/lib/replicator.js CHANGED
@@ -235,10 +235,11 @@ class InflightTracker {
235
235
  constructor () {
236
236
  this._requests = []
237
237
  this._free = []
238
+ this._active = 0
238
239
  }
239
240
 
240
241
  get idle () {
241
- return this._requests.length === this._free.length
242
+ return this._active === 0
242
243
  }
243
244
 
244
245
  * [Symbol.iterator] () {
@@ -251,6 +252,7 @@ class InflightTracker {
251
252
  const id = this._free.length ? this._free.pop() : this._requests.push(null)
252
253
  req.id = id
253
254
  this._requests[id - 1] = req
255
+ this._active++
254
256
  return req
255
257
  }
256
258
 
@@ -260,6 +262,7 @@ class InflightTracker {
260
262
 
261
263
  remove (id, roundtrip) {
262
264
  if (id > this._requests.length) return
265
+ if (this._requests[id - 1]) this._active--
263
266
  this._requests[id - 1] = null
264
267
  if (roundtrip === true) this._free.push(id)
265
268
  }
@@ -402,7 +405,9 @@ class Peer {
402
405
  wireBitfield: { tx: 0, rx: 0 },
403
406
  wireRange: { tx: 0, rx: 0 },
404
407
  wireExtension: { tx: 0, rx: 0 },
405
- hotswaps: 0
408
+ hotswaps: 0,
409
+ invalidData: 0,
410
+ invalidRequests: 0
406
411
  }
407
412
 
408
413
  this.receiverQueue = new ReceiverQueue()
@@ -725,6 +730,8 @@ class Peer {
725
730
  return new ProofRequest(msg, proof, block, manifest)
726
731
  } catch (err) {
727
732
  batch.destroy()
733
+ this.stats.invalidRequests++
734
+ this.replicator.stats.invalidRequests++
728
735
  throw err
729
736
  }
730
737
  }
@@ -1496,7 +1503,9 @@ module.exports = class Replicator {
1496
1503
  wireBitfield: { tx: 0, rx: 0 },
1497
1504
  wireRange: { tx: 0, rx: 0 },
1498
1505
  wireExtension: { tx: 0, rx: 0 },
1499
- hotswaps: 0
1506
+ hotswaps: 0,
1507
+ invalidData: 0,
1508
+ invalidRequests: 0
1500
1509
  }
1501
1510
 
1502
1511
  this._attached = new Set()
@@ -2541,6 +2550,8 @@ module.exports = class Replicator {
2541
2550
  _oninvalid (err, req, res, from) {
2542
2551
  const sessions = this.core.monitors
2543
2552
 
2553
+ this.stats.invalidData++
2554
+ from.stats.invalidData++
2544
2555
  for (let i = 0; i < sessions.length; i++) {
2545
2556
  sessions[i].emit('verification-error', err, req, res, from)
2546
2557
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "11.11.2",
3
+ "version": "11.12.1",
4
4
  "description": "Hypercore is a secure, distributed append-only log",
5
5
  "main": "index.js",
6
6
  "scripts": {