aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPatrick Strateman <patrick.strateman@gmail.com>2015-08-13 17:22:35 -0700
committerPatrick Strateman <patrick.strateman@gmail.com>2015-08-22 15:38:24 -0700
commitb105ba398b20789eb482e45f26ae1761800b81be (patch)
tree117cca0214e0f9ab7a6cf757755475b1bc53e6f9 /src
parent2c701537c8fc7f4cfb0163ec1f49662120e61eb7 (diff)
downloadbitcoin-b105ba398b20789eb482e45f26ae1761800b81be.tar.xz
Prefer to disconnect peers in favor of whitelisted peers
Diffstat (limited to 'src')
-rw-r--r--src/net.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/net.cpp b/src/net.cpp
index 0fab0f82af..77dde99445 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -818,7 +818,7 @@ public:
}
};
-static bool AttemptToEvictConnection() {
+static bool AttemptToEvictConnection(bool fPreferNewConnection) {
std::vector<CNode*> vEvictionCandidates;
{
LOCK(cs_vNodes);
@@ -866,8 +866,11 @@ static bool AttemptToEvictConnection() {
// Reduce to the CNetAddr with the most connections
vEvictionCandidates = mapAddrCounts[naMostConnections];
+ // Do not disconnect peers who have only 1 evictable connection
if (vEvictionCandidates.size() <= 1)
- return false;
+ // unless we prefer the new connection (for whitelisted peers)
+ if (!fPreferNewConnection)
+ return false;
// Disconnect the most recent connection from the CNetAddr with the most connections
std::sort(vEvictionCandidates.begin(), vEvictionCandidates.end(), ReverseCompareNodeTimeConnected);
@@ -920,7 +923,7 @@ static void AcceptConnection(const ListenSocket& hListenSocket) {
if (nInbound >= nMaxInbound)
{
- if (!AttemptToEvictConnection()) {
+ if (!AttemptToEvictConnection(whitelisted)) {
// No connection to evict, disconnect the new connection
LogPrint("net", "failed to find an eviction candidate - connection dropped (full)\n");
CloseSocket(hSocket);