aboutsummaryrefslogtreecommitdiff
path: root/src/net.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <[email protected]>2016-02-02 12:53:57 +0100
committerWladimir J. van der Laan <[email protected]>2016-02-02 12:54:24 +0100
commit3dc3149e63934f6ba9d030aec6dcfe839e592b9a (patch)
tree9ae090fbc4635e029786b2ee98564121bea4f610 /src/net.cpp
parentMerge #7451: Add link to bitcoin whitepaper (diff)
parentDecide eviction group ties based on time. (diff)
downloaddiscoin-3dc3149e63934f6ba9d030aec6dcfe839e592b9a.tar.xz
discoin-3dc3149e63934f6ba9d030aec6dcfe839e592b9a.zip
Merge #7453: [0.13] Missing patches from 0.12
1e05727 Decide eviction group ties based on time. (Gregory Maxwell) 1e9613a Do not absolutely protect local peers from eviction. (Gregory Maxwell) 5d74309 Get rid of inaccurate ScriptSigArgsExpected (Pieter Wuille)
Diffstat (limited to 'src/net.cpp')
-rw-r--r--src/net.cpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/net.cpp b/src/net.cpp
index 48e9e1015..14e22f6cb 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -899,8 +899,6 @@ static bool AttemptToEvictConnection(bool fPreferNewConnection) {
continue;
if (node->fDisconnect)
continue;
- if (node->addr.IsLocal())
- continue;
vEvictionCandidates.push_back(CNodeRef(node));
}
}
@@ -931,15 +929,20 @@ static bool AttemptToEvictConnection(bool fPreferNewConnection) {
if (vEvictionCandidates.empty()) return false;
- // Identify the network group with the most connections
+ // Identify the network group with the most connections and youngest member.
+ // (vEvictionCandidates is already sorted by reverse connect time)
std::vector<unsigned char> naMostConnections;
unsigned int nMostConnections = 0;
+ int64_t nMostConnectionsTime = 0;
std::map<std::vector<unsigned char>, std::vector<CNodeRef> > mapAddrCounts;
BOOST_FOREACH(const CNodeRef &node, vEvictionCandidates) {
mapAddrCounts[node->addr.GetGroup()].push_back(node);
+ int64_t grouptime = mapAddrCounts[node->addr.GetGroup()][0]->nTimeConnected;
+ size_t groupsize = mapAddrCounts[node->addr.GetGroup()].size();
- if (mapAddrCounts[node->addr.GetGroup()].size() > nMostConnections) {
- nMostConnections = mapAddrCounts[node->addr.GetGroup()].size();
+ if (groupsize > nMostConnections || (groupsize == nMostConnections && grouptime > nMostConnectionsTime)) {
+ nMostConnections = groupsize;
+ nMostConnectionsTime = grouptime;
naMostConnections = node->addr.GetGroup();
}
}
@@ -947,14 +950,13 @@ static bool AttemptToEvictConnection(bool fPreferNewConnection) {
// Reduce to the network group with the most connections
vEvictionCandidates = mapAddrCounts[naMostConnections];
- // Do not disconnect peers if there is only 1 connection from their network group
+ // Do not disconnect peers if there is only one unprotected connection from their network group.
if (vEvictionCandidates.size() <= 1)
// unless we prefer the new connection (for whitelisted peers)
if (!fPreferNewConnection)
return false;
- // Disconnect the most recent connection from the network group with the most connections
- std::sort(vEvictionCandidates.begin(), vEvictionCandidates.end(), ReverseCompareNodeTimeConnected);
+ // Disconnect from the network group with the most connections
vEvictionCandidates[0]->fDisconnect = true;
return true;