hypercore 10.37.22 → 10.37.23

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 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 || this._upgrade === null || this._upgrade.refs.length === 0) return
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 < this.peers.length; 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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "10.37.22",
3
+ "version": "10.37.23",
4
4
  "description": "Hypercore is a secure, distributed append-only log",
5
5
  "main": "index.js",
6
6
  "scripts": {