hypercore 11.34.0 → 11.34.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.
- package/lib/replicator.js +17 -3
- package/package.json +1 -1
package/lib/replicator.js
CHANGED
|
@@ -1749,6 +1749,17 @@ class Peer {
|
|
|
1749
1749
|
return false
|
|
1750
1750
|
}
|
|
1751
1751
|
|
|
1752
|
+
_addLastRangeBatch(r, start, end) {
|
|
1753
|
+
const { WANT_BATCH } = w
|
|
1754
|
+
|
|
1755
|
+
const next = this.core.bitfield.findLast(false, end - 1)
|
|
1756
|
+
if (next === -1 || next < start) return false
|
|
1757
|
+
|
|
1758
|
+
const b = (next - (next & (WANT_BATCH - 1))) / WANT_BATCH
|
|
1759
|
+
|
|
1760
|
+
return r.addBatch(b)
|
|
1761
|
+
}
|
|
1762
|
+
|
|
1752
1763
|
_populateRangeBatches(r) {
|
|
1753
1764
|
const { WANT_BATCH } = w
|
|
1754
1765
|
for (let i = r.batches.length - 1; i >= 0; i--) {
|
|
@@ -1764,10 +1775,13 @@ class Peer {
|
|
|
1764
1775
|
r.removeBatch(b)
|
|
1765
1776
|
}
|
|
1766
1777
|
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
if (end <= r.start) return
|
|
1778
|
+
const end = r.end === -1 ? this.core.state.length : r.end
|
|
1779
|
+
if (end <= r.start) return
|
|
1770
1780
|
|
|
1781
|
+
// always keep the last batch in the range selected
|
|
1782
|
+
if (r.batches.length < 3) this._addLastRangeBatch(r, r.start, end)
|
|
1783
|
+
|
|
1784
|
+
while (r.batches.length < 3) {
|
|
1771
1785
|
const len = end - r.start
|
|
1772
1786
|
const off = r.start + (r.linear ? 0 : Math.floor(Math.random() * len))
|
|
1773
1787
|
|