Skip to content

Commit 027de94

Browse files
committed
Use network group instead of CNetAddr in final pass to select node to disconnect
1 parent 000c18a commit 027de94

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/net.cpp

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

899899
if (vEvictionCandidates.empty()) return false;
900900

901-
// Identify CNetAddr with the most connections
902-
CNetAddr naMostConnections;
901+
// Identify the network group with the most connections
902+
std::vector<unsigned char> naMostConnections;
903903
unsigned int nMostConnections = 0;
904-
std::map<CNetAddr, std::vector<CNodeRef> > mapAddrCounts;
904+
std::map<std::vector<unsigned char>, std::vector<CNodeRef> > mapAddrCounts;
905905
BOOST_FOREACH(const CNodeRef &node, vEvictionCandidates) {
906-
mapAddrCounts[node->addr].push_back(node);
906+
mapAddrCounts[node->addr.GetGroup()].push_back(node);
907907

908-
if (mapAddrCounts[node->addr].size() > nMostConnections) {
909-
nMostConnections = mapAddrCounts[node->addr].size();
910-
naMostConnections = node->addr;
908+
if (mapAddrCounts[node->addr.GetGroup()].size() > nMostConnections) {
909+
nMostConnections = mapAddrCounts[node->addr.GetGroup()].size();
910+
naMostConnections = node->addr.GetGroup();
911911
}
912912
}
913913

914-
// Reduce to the CNetAddr with the most connections
914+
// Reduce to the network group with the most connections
915915
vEvictionCandidates = mapAddrCounts[naMostConnections];
916916

917-
// Do not disconnect peers who have only 1 evictable connection
917+
// Do not disconnect peers if there is only 1 connection from their network group
918918
if (vEvictionCandidates.size() <= 1)
919919
// unless we prefer the new connection (for whitelisted peers)
920920
if (!fPreferNewConnection)
921921
return false;
922922

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

0 commit comments

Comments
 (0)