Browse Source

Prefer to disconnect peers in favor of whitelisted peers

pull/4/head
Patrick Strateman 9 years ago
committed by Taylor Hornby
parent
commit
dd99be0f8c
  1. 9
      src/net.cpp

9
src/net.cpp

@ -713,7 +713,7 @@ public:
}
};
static bool AttemptToEvictConnection() {
static bool AttemptToEvictConnection(bool fPreferNewConnection) {
std::vector<CNode*> vEvictionCandidates;
{
LOCK(cs_vNodes);
@ -761,8 +761,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);
@ -815,7 +818,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);

Loading…
Cancel
Save