hypercore 10.37.25 → 10.37.26
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 +18 -4
- package/package.json +1 -1
package/lib/replicator.js
CHANGED
|
@@ -38,6 +38,8 @@ const DEFAULT_SEGMENT_SIZE = 256 * 1024 * 8 // 256 KiB in bits
|
|
|
38
38
|
const NOT_DOWNLOADING_SLACK = 20000 + (Math.random() * 20000) | 0
|
|
39
39
|
const MAX_PEERS_UPGRADE = 3
|
|
40
40
|
|
|
41
|
+
const MAX_RANGES = 64
|
|
42
|
+
|
|
41
43
|
const PRIORITY = {
|
|
42
44
|
NORMAL: 0,
|
|
43
45
|
HIGH: 1,
|
|
@@ -1623,11 +1625,18 @@ module.exports = class Replicator {
|
|
|
1623
1625
|
|
|
1624
1626
|
const ref = r.attach(session)
|
|
1625
1627
|
|
|
1626
|
-
this._ranges.push(r)
|
|
1627
|
-
|
|
1628
1628
|
// Trigger this to see if this is already resolved...
|
|
1629
1629
|
// Also auto compresses the range based on local bitfield
|
|
1630
|
-
this.
|
|
1630
|
+
clampRange(this.core, r)
|
|
1631
|
+
|
|
1632
|
+
this._ranges.push(r)
|
|
1633
|
+
|
|
1634
|
+
if (r.end !== -1 && r.start >= r.end) {
|
|
1635
|
+
this._resolveRangeRequest(r, this._ranges.length - 1)
|
|
1636
|
+
return ref
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1639
|
+
this.updateAll()
|
|
1631
1640
|
|
|
1632
1641
|
return ref
|
|
1633
1642
|
}
|
|
@@ -1899,13 +1908,16 @@ module.exports = class Replicator {
|
|
|
1899
1908
|
async _updateNonPrimary (updateAll) {
|
|
1900
1909
|
// Check if running, if so skip it and the running one will issue another update for us (debounce)
|
|
1901
1910
|
while (++this._updatesPending === 1) {
|
|
1902
|
-
|
|
1911
|
+
let len = Math.min(MAX_RANGES, this._ranges.length)
|
|
1912
|
+
|
|
1913
|
+
for (let i = 0; i < len; i++) {
|
|
1903
1914
|
const r = this._ranges[i]
|
|
1904
1915
|
|
|
1905
1916
|
clampRange(this.core, r)
|
|
1906
1917
|
|
|
1907
1918
|
if (r.end !== -1 && r.start >= r.end) {
|
|
1908
1919
|
this._resolveRangeRequest(r, i--)
|
|
1920
|
+
if (len > this._ranges.length) len--
|
|
1909
1921
|
}
|
|
1910
1922
|
}
|
|
1911
1923
|
|
|
@@ -2187,11 +2199,13 @@ module.exports = class Replicator {
|
|
|
2187
2199
|
}
|
|
2188
2200
|
|
|
2189
2201
|
const ranges = new RandomIterator(this._ranges)
|
|
2202
|
+
let tried = 0
|
|
2190
2203
|
|
|
2191
2204
|
for (const r of ranges) {
|
|
2192
2205
|
if (peer._requestRange(r) === true) {
|
|
2193
2206
|
return true
|
|
2194
2207
|
}
|
|
2208
|
+
if (++tried >= MAX_RANGES) break
|
|
2195
2209
|
}
|
|
2196
2210
|
|
|
2197
2211
|
// Iterate from newest fork to oldest fork...
|