@@ -957,6 +957,15 @@ void ProtectNoBanConnections(std::vector<NodeEvictionCandidate>& eviction_candid
957
957
eviction_candidates.end ());
958
958
}
959
959
960
+ void ProtectOutboundConnections (std::vector<NodeEvictionCandidate>& eviction_candidates)
961
+ {
962
+ eviction_candidates.erase (std::remove_if (eviction_candidates.begin (), eviction_candidates.end (),
963
+ [](NodeEvictionCandidate const & n) {
964
+ return n.m_conn_type != ConnectionType::INBOUND;
965
+ }),
966
+ eviction_candidates.end ());
967
+ }
968
+
960
969
void ProtectEvictionCandidatesByRatio (std::vector<NodeEvictionCandidate>& eviction_candidates)
961
970
{
962
971
// Protect the half of the remaining nodes which have been connected the longest.
@@ -1036,6 +1045,8 @@ void ProtectEvictionCandidatesByRatio(std::vector<NodeEvictionCandidate>& evicti
1036
1045
1037
1046
ProtectNoBanConnections (vEvictionCandidates);
1038
1047
1048
+ ProtectOutboundConnections (vEvictionCandidates);
1049
+
1039
1050
// Deterministically select 4 peers to protect by netgroup.
1040
1051
// An attacker cannot predict which netgroups will be protected
1041
1052
EraseLastKElements (vEvictionCandidates, CompareNetGroupKeyed, 4 );
@@ -1107,8 +1118,6 @@ bool CConnman::AttemptToEvictConnection()
1107
1118
1108
1119
LOCK (m_nodes_mutex);
1109
1120
for (const CNode* node : m_nodes) {
1110
- if (!node->IsInboundConn ())
1111
- continue ;
1112
1121
if (node->fDisconnect )
1113
1122
continue ;
1114
1123
NodeEvictionCandidate candidate{
@@ -1125,6 +1134,7 @@ bool CConnman::AttemptToEvictConnection()
1125
1134
Desig (m_is_local) node->addr .IsLocal (),
1126
1135
Desig (m_network) node->ConnectedThroughNetwork (),
1127
1136
Desig (m_noban) node->HasPermission (NetPermissionFlags::NoBan),
1137
+ Desig (m_conn_type) node->m_conn_type ,
1128
1138
};
1129
1139
vEvictionCandidates.push_back (candidate);
1130
1140
}
0 commit comments