Skip to content

Commit

Permalink
Return false early if vEvictionCandidates is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
pstratem committed Aug 22, 2015
1 parent 17f3533 commit dc81dd0
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand Down

0 comments on commit dc81dd0

Please sign in to comment.