@@ -948,6 +948,15 @@ static void EraseLastKElements(
948948 elements.erase (std::remove_if (elements.end () - eraseSize, elements.end (), predicate), elements.end ());
949949}
950950
951+ void ProtectNoBanConnections (std::vector<NodeEvictionCandidate>& eviction_candidates)
952+ {
953+ eviction_candidates.erase (std::remove_if (eviction_candidates.begin (), eviction_candidates.end (),
954+ [](NodeEvictionCandidate const & n) {
955+ return n.m_noban ;
956+ }),
957+ eviction_candidates.end ());
958+ }
959+
951960void ProtectEvictionCandidatesByRatio (std::vector<NodeEvictionCandidate>& eviction_candidates)
952961{
953962 // Protect the half of the remaining nodes which have been connected the longest.
@@ -1025,6 +1034,8 @@ void ProtectEvictionCandidatesByRatio(std::vector<NodeEvictionCandidate>& evicti
10251034{
10261035 // Protect connections with certain characteristics
10271036
1037+ ProtectNoBanConnections (vEvictionCandidates);
1038+
10281039 // Deterministically select 4 peers to protect by netgroup.
10291040 // An attacker cannot predict which netgroups will be protected
10301041 EraseLastKElements (vEvictionCandidates, CompareNetGroupKeyed, 4 );
@@ -1096,8 +1107,6 @@ bool CConnman::AttemptToEvictConnection()
10961107
10971108 LOCK (m_nodes_mutex);
10981109 for (const CNode* node : m_nodes) {
1099- if (node->HasPermission (NetPermissionFlags::NoBan))
1100- continue ;
11011110 if (!node->IsInboundConn ())
11021111 continue ;
11031112 if (node->fDisconnect )
@@ -1115,6 +1124,7 @@ bool CConnman::AttemptToEvictConnection()
11151124 Desig (prefer_evict) node->m_prefer_evict ,
11161125 Desig (m_is_local) node->addr .IsLocal (),
11171126 Desig (m_network) node->ConnectedThroughNetwork (),
1127+ Desig (m_noban) node->HasPermission (NetPermissionFlags::NoBan),
11181128 };
11191129 vEvictionCandidates.push_back (candidate);
11201130 }
0 commit comments