mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 21:12:48 +01:00
Prefer to disconnect peers in favor of whitelisted peers
This commit is contained in:
parent
2c701537c8
commit
b105ba398b
@ -818,7 +818,7 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool AttemptToEvictConnection() {
|
static bool AttemptToEvictConnection(bool fPreferNewConnection) {
|
||||||
std::vector<CNode*> vEvictionCandidates;
|
std::vector<CNode*> vEvictionCandidates;
|
||||||
{
|
{
|
||||||
LOCK(cs_vNodes);
|
LOCK(cs_vNodes);
|
||||||
@ -866,8 +866,11 @@ static bool AttemptToEvictConnection() {
|
|||||||
// Reduce to the CNetAddr with the most connections
|
// Reduce to the CNetAddr with the most connections
|
||||||
vEvictionCandidates = mapAddrCounts[naMostConnections];
|
vEvictionCandidates = mapAddrCounts[naMostConnections];
|
||||||
|
|
||||||
|
// Do not disconnect peers who have only 1 evictable connection
|
||||||
if (vEvictionCandidates.size() <= 1)
|
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
|
// Disconnect the most recent connection from the CNetAddr with the most connections
|
||||||
std::sort(vEvictionCandidates.begin(), vEvictionCandidates.end(), ReverseCompareNodeTimeConnected);
|
std::sort(vEvictionCandidates.begin(), vEvictionCandidates.end(), ReverseCompareNodeTimeConnected);
|
||||||
@ -920,7 +923,7 @@ static void AcceptConnection(const ListenSocket& hListenSocket) {
|
|||||||
|
|
||||||
if (nInbound >= nMaxInbound)
|
if (nInbound >= nMaxInbound)
|
||||||
{
|
{
|
||||||
if (!AttemptToEvictConnection()) {
|
if (!AttemptToEvictConnection(whitelisted)) {
|
||||||
// No connection to evict, disconnect the new connection
|
// No connection to evict, disconnect the new connection
|
||||||
LogPrint("net", "failed to find an eviction candidate - connection dropped (full)\n");
|
LogPrint("net", "failed to find an eviction candidate - connection dropped (full)\n");
|
||||||
CloseSocket(hSocket);
|
CloseSocket(hSocket);
|
||||||
|
Loading…
Reference in New Issue
Block a user