|
|
@ -836,13 +836,20 @@ static bool AttemptToEvictConnection(bool fPreferNewConnection) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Protect connections with certain characteristics
|
|
|
|
// Protect connections with certain characteristics
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Deterministically select 4 peers to protect by netgroup.
|
|
|
|
|
|
|
|
// An attacker cannot predict which netgroups will be protected.
|
|
|
|
static CompareNetGroupKeyed comparerNetGroupKeyed; |
|
|
|
static CompareNetGroupKeyed comparerNetGroupKeyed; |
|
|
|
std::sort(vEvictionCandidates.begin(), vEvictionCandidates.end(), comparerNetGroupKeyed); |
|
|
|
std::sort(vEvictionCandidates.begin(), vEvictionCandidates.end(), comparerNetGroupKeyed); |
|
|
|
vEvictionCandidates.erase(vEvictionCandidates.end() - std::min(4, static_cast<int>(vEvictionCandidates.size())), vEvictionCandidates.end()); |
|
|
|
vEvictionCandidates.erase(vEvictionCandidates.end() - std::min(4, static_cast<int>(vEvictionCandidates.size())), vEvictionCandidates.end()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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); |
|
|
|
std::sort(vEvictionCandidates.begin(), vEvictionCandidates.end(), ReverseCompareNodeMinPingTime); |
|
|
|
vEvictionCandidates.erase(vEvictionCandidates.end() - std::min(8, static_cast<int>(vEvictionCandidates.size())), vEvictionCandidates.end()); |
|
|
|
vEvictionCandidates.erase(vEvictionCandidates.end() - std::min(8, static_cast<int>(vEvictionCandidates.size())), vEvictionCandidates.end()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Protect the 64 nodes which have been connected the longest.
|
|
|
|
|
|
|
|
// This replicates the existing implicit behavior.
|
|
|
|
std::sort(vEvictionCandidates.begin(), vEvictionCandidates.end(), ReverseCompareNodeTimeConnected); |
|
|
|
std::sort(vEvictionCandidates.begin(), vEvictionCandidates.end(), ReverseCompareNodeTimeConnected); |
|
|
|
vEvictionCandidates.erase(vEvictionCandidates.end() - std::min(64, static_cast<int>(vEvictionCandidates.size())), vEvictionCandidates.end()); |
|
|
|
vEvictionCandidates.erase(vEvictionCandidates.end() - std::min(64, static_cast<int>(vEvictionCandidates.size())), vEvictionCandidates.end()); |
|
|
|
|
|
|
|
|
|
|
|