aboutsummaryrefslogtreecommitdiff
path: root/src/net.cpp
diff options
context:
space:
mode:
authorPatrick Strateman <patrick.strateman@gmail.com>2015-08-20 16:47:49 -0700
committerPatrick Strateman <patrick.strateman@gmail.com>2015-08-22 15:38:24 -0700
commitdf239374224e6585d5b6ba37a39282d0fc647173 (patch)
tree55d7c556f35241f91699566427c024575962ca26 /src/net.cpp
parenta8f6e45249e815414cc99e7b594a8a7ab7ab9247 (diff)
downloadbitcoin-df239374224e6585d5b6ba37a39282d0fc647173.tar.xz
Add comments to AttemptToEvictConnection
Diffstat (limited to 'src/net.cpp')
-rw-r--r--src/net.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/net.cpp b/src/net.cpp
index 9cfb9d71db..d8d2783c4b 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -836,13 +836,20 @@ static bool AttemptToEvictConnection(bool fPreferNewConnection) {
}
// 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;
std::sort(vEvictionCandidates.begin(), vEvictionCandidates.end(), comparerNetGroupKeyed);
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);
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);
vEvictionCandidates.erase(vEvictionCandidates.end() - std::min(64, static_cast<int>(vEvictionCandidates.size())), vEvictionCandidates.end());