hypercore 11.11.1 → 11.11.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/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
@@ -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)) return index
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
@@ -927,6 +927,7 @@ class Peer {
927
927
  this._checkIfConflict()
928
928
  }
929
929
 
930
+ this.paused = true
930
931
  this.replicator._onnodata(this, req)
931
932
  this.replicator._oninvalid(err, req, data, this)
932
933
  return
@@ -2281,7 +2282,7 @@ module.exports = class Replicator {
2281
2282
  }
2282
2283
 
2283
2284
  _updatePeer (peer) {
2284
- if (!peer.isActive() || peer.inflight >= peer.getMaxInflight()) {
2285
+ if (!peer.isActive() || peer.inflight >= peer.getMaxInflight() || !peer.remoteUploading) {
2285
2286
  return false
2286
2287
  }
2287
2288
 
@@ -2313,7 +2314,7 @@ module.exports = class Replicator {
2313
2314
  }
2314
2315
 
2315
2316
  _updatePeerNonPrimary (peer) {
2316
- if (!peer.isActive() || peer.inflight >= peer.getMaxInflight()) {
2317
+ if (!peer.isActive() || peer.inflight >= peer.getMaxInflight() || !peer.remoteUploading) {
2317
2318
  return false
2318
2319
  }
2319
2320
 
@@ -483,7 +483,8 @@ module.exports = class SessionState {
483
483
  }
484
484
  }
485
485
 
486
- tx.deleteBlockRange(start, end)
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "11.11.1",
3
+ "version": "11.11.2",
4
4
  "description": "Hypercore is a secure, distributed append-only log",
5
5
  "main": "index.js",
6
6
  "scripts": {