hypercore 10.37.22 → 10.37.24
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 +12 -4
- package/package.json +1 -1
package/lib/replicator.js
CHANGED
|
@@ -37,6 +37,7 @@ const DEFAULT_MAX_INFLIGHT = [16, 512]
|
|
|
37
37
|
const SCALE_LATENCY = 50
|
|
38
38
|
const DEFAULT_SEGMENT_SIZE = 256 * 1024 * 8 // 256 KiB in bits
|
|
39
39
|
const NOT_DOWNLOADING_SLACK = 20000 + (Math.random() * 20000) | 0
|
|
40
|
+
const MAX_PEERS_UPGRADE = 3
|
|
40
41
|
|
|
41
42
|
const PRIORITY = {
|
|
42
43
|
NORMAL: 0,
|
|
@@ -1667,12 +1668,15 @@ module.exports = class Replicator {
|
|
|
1667
1668
|
// instead its more efficient to only call it when the conditions in here change - ie on sync/add/remove peer
|
|
1668
1669
|
// Do this when we have more tests.
|
|
1669
1670
|
_checkUpgradeIfAvailable () {
|
|
1670
|
-
if (this._ifAvailable > 0
|
|
1671
|
+
if (this._ifAvailable > 0 && this.peers.length < MAX_PEERS_UPGRADE) return
|
|
1672
|
+
if (this._upgrade === null || this._upgrade.refs.length === 0) return
|
|
1671
1673
|
if (this._hadPeers === false && this.findingPeers > 0) return
|
|
1672
1674
|
|
|
1675
|
+
const maxPeers = Math.min(this.peers.length, MAX_PEERS_UPGRADE)
|
|
1676
|
+
|
|
1673
1677
|
// check if a peer can upgrade us
|
|
1674
1678
|
|
|
1675
|
-
for (let i = 0; i <
|
|
1679
|
+
for (let i = 0; i < maxPeers; i++) {
|
|
1676
1680
|
const peer = this.peers[i]
|
|
1677
1681
|
|
|
1678
1682
|
if (peer.remoteSynced === false) return
|
|
@@ -1699,6 +1703,9 @@ module.exports = class Replicator {
|
|
|
1699
1703
|
if (r.inflight.length > 0) return
|
|
1700
1704
|
}
|
|
1701
1705
|
|
|
1706
|
+
// if something is inflight, wait for that first
|
|
1707
|
+
if (this._upgrade.inflight.length > 0) return
|
|
1708
|
+
|
|
1702
1709
|
// nothing to do, indicate no update avail
|
|
1703
1710
|
|
|
1704
1711
|
const u = this._upgrade
|
|
@@ -2320,9 +2327,10 @@ module.exports = class Replicator {
|
|
|
2320
2327
|
clearTimeout(this._downloadingTimer)
|
|
2321
2328
|
this._downloadingTimer = null
|
|
2322
2329
|
}
|
|
2323
|
-
|
|
2330
|
+
while (this.peers.length) {
|
|
2331
|
+
const peer = this.peers[this.peers.length - 1]
|
|
2324
2332
|
this.detachFrom(peer.protomux)
|
|
2325
|
-
peer.channel.close()
|
|
2333
|
+
peer.channel.close() // peer is removed from array in onclose
|
|
2326
2334
|
}
|
|
2327
2335
|
for (const protomux of this._attached) {
|
|
2328
2336
|
this.detachFrom(protomux)
|