diff options
author | Patrick Strateman <patrick.strateman@gmail.com> | 2015-08-22 15:15:39 -0700 |
---|---|---|
committer | Patrick Strateman <patrick.strateman@gmail.com> | 2015-08-22 15:38:24 -0700 |
commit | dc81dd02a1d5f47ca45f74577e0696dfba6fa15c (patch) | |
tree | 5da7ab8cadd3c501d2ca8c74f0d53267ee184c20 /src/net.cpp | |
parent | 17f3533c8484f02732fff5cf004d251c0df50eb8 (diff) |
Return false early if vEvictionCandidates is empty
Diffstat (limited to 'src/net.cpp')
-rw-r--r-- | src/net.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/net.cpp b/src/net.cpp index 4d08f63e32..4f4c7b81c4 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -846,6 +846,8 @@ static bool AttemptToEvictConnection(bool fPreferNewConnection) { } } + if (vEvictionCandidates.empty()) return false; + // Protect connections with certain characteristics // Deterministically select 4 peers to protect by netgroup. @@ -854,18 +856,21 @@ static bool AttemptToEvictConnection(bool fPreferNewConnection) { std::sort(vEvictionCandidates.begin(), vEvictionCandidates.end(), comparerNetGroupKeyed); vEvictionCandidates.erase(vEvictionCandidates.end() - std::min(4, static_cast<int>(vEvictionCandidates.size())), vEvictionCandidates.end()); + if (vEvictionCandidates.empty()) return false; + // Protect the 8 nodes with the best ping times. // An attacker cannot manipulate this metric without physically moving nodes closer to the target. std::sort(vEvictionCandidates.begin(), vEvictionCandidates.end(), ReverseCompareNodeMinPingTime); vEvictionCandidates.erase(vEvictionCandidates.end() - std::min(8, static_cast<int>(vEvictionCandidates.size())), vEvictionCandidates.end()); + if (vEvictionCandidates.empty()) return false; + // Protect the 64 nodes which have been connected the longest. // This replicates the existing implicit behavior. std::sort(vEvictionCandidates.begin(), vEvictionCandidates.end(), ReverseCompareNodeTimeConnected); - vEvictionCandidates.erase(vEvictionCandidates.end() - std::min(static_cast<int>(vEvictionCandidates.size() / 2), static_cast<int>(vEvictionCandidates.size())), vEvictionCandidates.end()); + vEvictionCandidates.erase(vEvictionCandidates.end() - static_cast<int>(vEvictionCandidates.size() / 2), vEvictionCandidates.end()); - if (vEvictionCandidates.empty()) - return false; + if (vEvictionCandidates.empty()) return false; // Identify CNetAddr with the most connections CNetAddr naMostConnections; |