@@ -948,6 +948,15 @@ static void EraseLastKElements(
948
948
elements.erase (std::remove_if (elements.end () - eraseSize, elements.end (), predicate), elements.end ());
949
949
}
950
950
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
+
951
960
void ProtectEvictionCandidatesByRatio (std::vector<NodeEvictionCandidate>& eviction_candidates)
952
961
{
953
962
// Protect the half of the remaining nodes which have been connected the longest.
@@ -1025,6 +1034,8 @@ void ProtectEvictionCandidatesByRatio(std::vector<NodeEvictionCandidate>& evicti
1025
1034
{
1026
1035
// Protect connections with certain characteristics
1027
1036
1037
+ ProtectNoBanConnections (vEvictionCandidates);
1038
+
1028
1039
// Deterministically select 4 peers to protect by netgroup.
1029
1040
// An attacker cannot predict which netgroups will be protected
1030
1041
EraseLastKElements (vEvictionCandidates, CompareNetGroupKeyed, 4 );
@@ -1096,8 +1107,6 @@ bool CConnman::AttemptToEvictConnection()
1096
1107
1097
1108
LOCK (m_nodes_mutex);
1098
1109
for (const CNode* node : m_nodes) {
1099
- if (node->HasPermission (NetPermissionFlags::NoBan))
1100
- continue ;
1101
1110
if (!node->IsInboundConn ())
1102
1111
continue ;
1103
1112
if (node->fDisconnect )
@@ -1115,6 +1124,7 @@ bool CConnman::AttemptToEvictConnection()
1115
1124
Desig (prefer_evict) node->m_prefer_evict ,
1116
1125
Desig (m_is_local) node->addr .IsLocal (),
1117
1126
Desig (m_network) node->ConnectedThroughNetwork (),
1127
+ Desig (m_noban) node->HasPermission (NetPermissionFlags::NoBan),
1118
1128
};
1119
1129
vEvictionCandidates.push_back (candidate);
1120
1130
}
0 commit comments