hypercore 11.11.1 → 11.12.0
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 +5 -0
- package/lib/merkle-tree.js +1 -2
- package/lib/replicator.js +13 -4
- package/lib/session-state.js +2 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -71,6 +71,7 @@ class Hypercore extends EventEmitter {
|
|
|
71
71
|
this.closed = false
|
|
72
72
|
this.weak = !!opts.weak
|
|
73
73
|
this.snapshotted = !!opts.snapshot
|
|
74
|
+
this.onseq = opts.onseq || null
|
|
74
75
|
this.onwait = opts.onwait || null
|
|
75
76
|
this.wait = opts.wait !== false
|
|
76
77
|
this.timeout = opts.timeout || 0
|
|
@@ -219,6 +220,7 @@ class Hypercore extends EventEmitter {
|
|
|
219
220
|
const wait = opts.wait === false ? false : this.wait
|
|
220
221
|
const writable = opts.writable === undefined ? !this._readonly : opts.writable === true
|
|
221
222
|
const onwait = opts.onwait === undefined ? this.onwait : opts.onwait
|
|
223
|
+
const onseq = opts.onseq === undefined ? this.onseq : opts.onseq
|
|
222
224
|
const timeout = opts.timeout === undefined ? this.timeout : opts.timeout
|
|
223
225
|
const weak = opts.weak === undefined ? this.weak : opts.weak
|
|
224
226
|
const Clz = opts.class || Hypercore
|
|
@@ -226,6 +228,7 @@ class Hypercore extends EventEmitter {
|
|
|
226
228
|
...opts,
|
|
227
229
|
wait,
|
|
228
230
|
onwait,
|
|
231
|
+
onseq,
|
|
229
232
|
timeout,
|
|
230
233
|
writable,
|
|
231
234
|
weak,
|
|
@@ -768,6 +771,8 @@ class Hypercore extends EventEmitter {
|
|
|
768
771
|
|
|
769
772
|
const encoding = (opts && opts.valueEncoding && c.from(opts.valueEncoding)) || this.valueEncoding
|
|
770
773
|
|
|
774
|
+
if (this.onseq !== null) this.onseq(index, this)
|
|
775
|
+
|
|
771
776
|
const req = this._get(index, opts)
|
|
772
777
|
|
|
773
778
|
let block = await req
|
package/lib/merkle-tree.js
CHANGED
|
@@ -1091,9 +1091,8 @@ function nodesToRoot (index, nodes, head) {
|
|
|
1091
1091
|
const ite = flat.iterator(index)
|
|
1092
1092
|
|
|
1093
1093
|
for (let i = 0; i < nodes; i++) {
|
|
1094
|
-
const index = ite.index
|
|
1095
1094
|
ite.parent()
|
|
1096
|
-
if (ite.contains(head))
|
|
1095
|
+
if (ite.contains(head)) throw INVALID_OPERATION('Nodes is out of bounds')
|
|
1097
1096
|
}
|
|
1098
1097
|
|
|
1099
1098
|
return ite.index
|
package/lib/replicator.js
CHANGED
|
@@ -402,7 +402,9 @@ class Peer {
|
|
|
402
402
|
wireBitfield: { tx: 0, rx: 0 },
|
|
403
403
|
wireRange: { tx: 0, rx: 0 },
|
|
404
404
|
wireExtension: { tx: 0, rx: 0 },
|
|
405
|
-
hotswaps: 0
|
|
405
|
+
hotswaps: 0,
|
|
406
|
+
invalidData: 0,
|
|
407
|
+
invalidRequests: 0
|
|
406
408
|
}
|
|
407
409
|
|
|
408
410
|
this.receiverQueue = new ReceiverQueue()
|
|
@@ -725,6 +727,8 @@ class Peer {
|
|
|
725
727
|
return new ProofRequest(msg, proof, block, manifest)
|
|
726
728
|
} catch (err) {
|
|
727
729
|
batch.destroy()
|
|
730
|
+
this.stats.invalidRequests++
|
|
731
|
+
this.replicator.stats.invalidRequests++
|
|
728
732
|
throw err
|
|
729
733
|
}
|
|
730
734
|
}
|
|
@@ -927,6 +931,7 @@ class Peer {
|
|
|
927
931
|
this._checkIfConflict()
|
|
928
932
|
}
|
|
929
933
|
|
|
934
|
+
this.paused = true
|
|
930
935
|
this.replicator._onnodata(this, req)
|
|
931
936
|
this.replicator._oninvalid(err, req, data, this)
|
|
932
937
|
return
|
|
@@ -1495,7 +1500,9 @@ module.exports = class Replicator {
|
|
|
1495
1500
|
wireBitfield: { tx: 0, rx: 0 },
|
|
1496
1501
|
wireRange: { tx: 0, rx: 0 },
|
|
1497
1502
|
wireExtension: { tx: 0, rx: 0 },
|
|
1498
|
-
hotswaps: 0
|
|
1503
|
+
hotswaps: 0,
|
|
1504
|
+
invalidData: 0,
|
|
1505
|
+
invalidRequests: 0
|
|
1499
1506
|
}
|
|
1500
1507
|
|
|
1501
1508
|
this._attached = new Set()
|
|
@@ -2281,7 +2288,7 @@ module.exports = class Replicator {
|
|
|
2281
2288
|
}
|
|
2282
2289
|
|
|
2283
2290
|
_updatePeer (peer) {
|
|
2284
|
-
if (!peer.isActive() || peer.inflight >= peer.getMaxInflight()) {
|
|
2291
|
+
if (!peer.isActive() || peer.inflight >= peer.getMaxInflight() || !peer.remoteUploading) {
|
|
2285
2292
|
return false
|
|
2286
2293
|
}
|
|
2287
2294
|
|
|
@@ -2313,7 +2320,7 @@ module.exports = class Replicator {
|
|
|
2313
2320
|
}
|
|
2314
2321
|
|
|
2315
2322
|
_updatePeerNonPrimary (peer) {
|
|
2316
|
-
if (!peer.isActive() || peer.inflight >= peer.getMaxInflight()) {
|
|
2323
|
+
if (!peer.isActive() || peer.inflight >= peer.getMaxInflight() || !peer.remoteUploading) {
|
|
2317
2324
|
return false
|
|
2318
2325
|
}
|
|
2319
2326
|
|
|
@@ -2540,6 +2547,8 @@ module.exports = class Replicator {
|
|
|
2540
2547
|
_oninvalid (err, req, res, from) {
|
|
2541
2548
|
const sessions = this.core.monitors
|
|
2542
2549
|
|
|
2550
|
+
this.stats.invalidData++
|
|
2551
|
+
from.stats.invalidData++
|
|
2543
2552
|
for (let i = 0; i < sessions.length; i++) {
|
|
2544
2553
|
sessions[i].emit('verification-error', err, req, res, from)
|
|
2545
2554
|
}
|
package/lib/session-state.js
CHANGED
|
@@ -483,7 +483,8 @@ module.exports = class SessionState {
|
|
|
483
483
|
}
|
|
484
484
|
}
|
|
485
485
|
|
|
486
|
-
tx.
|
|
486
|
+
if ((end - start) === 1) tx.deleteBlock(start)
|
|
487
|
+
else tx.deleteBlockRange(start, end)
|
|
487
488
|
|
|
488
489
|
const dependency = start < this.flushedLength() ? updateDependency(this, start, true) : null
|
|
489
490
|
|