Skip to content

Commit fabf358

Browse files
Patrick StratemanFuzzbawls
authored andcommitted
Use network group instead of CNetAddr in final pass to select node to disconnect
1 parent 7f030fe commit fabf358

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

src/net.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,29 +1012,29 @@ static bool AttemptToEvictConnection(bool fPreferNewConnection) {
10121012

10131013
if (vEvictionCandidates.empty()) return false;
10141014

1015-
// Identify CNetAddr with the most connections
1016-
CNetAddr naMostConnections;
1015+
// Identify the network group with the most connections
1016+
std::vector<unsigned char> naMostConnections;
10171017
unsigned int nMostConnections = 0;
1018-
std::map<CNetAddr, std::vector<CNodeRef> > mapAddrCounts;
1018+
std::map<std::vector<unsigned char>, std::vector<CNodeRef> > mapAddrCounts;
10191019
for (const CNodeRef& node : vEvictionCandidates) {
1020-
mapAddrCounts[node->addr].push_back(node);
1020+
mapAddrCounts[node->addr.GetGroup()].push_back(node);
10211021

1022-
if (mapAddrCounts[node->addr].size() > nMostConnections) {
1023-
nMostConnections = mapAddrCounts[node->addr].size();
1024-
naMostConnections = node->addr;
1022+
if (mapAddrCounts[node->addr.GetGroup()].size() > nMostConnections) {
1023+
nMostConnections = mapAddrCounts[node->addr.GetGroup()].size();
1024+
naMostConnections = node->addr.GetGroup();
10251025
}
10261026
}
10271027

1028-
// Reduce to the CNetAddr with the most connections
1028+
// Reduce to the network group with the most connections
10291029
vEvictionCandidates = mapAddrCounts[naMostConnections];
10301030

1031-
// Do not disconnect peers who have only 1 evictable connection
1031+
// Do not disconnect peers if there is only 1 connection from their network group
10321032
if (vEvictionCandidates.size() <= 1)
10331033
// unless we prefer the new connection (for whitelisted peers)
10341034
if (!fPreferNewConnection)
10351035
return false;
10361036

1037-
// Disconnect the most recent connection from the CNetAddr with the most connections
1037+
// Disconnect the most recent connection from the network group with the most connections
10381038
std::sort(vEvictionCandidates.begin(), vEvictionCandidates.end(), ReverseCompareNodeTimeConnected);
10391039
vEvictionCandidates[0]->fDisconnect = true;
10401040

0 commit comments

Comments
 (0)