@@ -957,6 +957,15 @@ void ProtectNoBanConnections(std::vector<NodeEvictionCandidate>& eviction_candid
957957 eviction_candidates.end ());
958958}
959959
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+
960969void ProtectEvictionCandidatesByRatio (std::vector<NodeEvictionCandidate>& eviction_candidates)
961970{
962971 // Protect the half of the remaining nodes which have been connected the longest.
@@ -1036,6 +1045,8 @@ void ProtectEvictionCandidatesByRatio(std::vector<NodeEvictionCandidate>& evicti
10361045
10371046 ProtectNoBanConnections (vEvictionCandidates);
10381047
1048+ ProtectOutboundConnections (vEvictionCandidates);
1049+
10391050 // Deterministically select 4 peers to protect by netgroup.
10401051 // An attacker cannot predict which netgroups will be protected
10411052 EraseLastKElements (vEvictionCandidates, CompareNetGroupKeyed, 4 );
@@ -1107,8 +1118,6 @@ bool CConnman::AttemptToEvictConnection()
11071118
11081119 LOCK (m_nodes_mutex);
11091120 for (const CNode* node : m_nodes) {
1110- if (!node->IsInboundConn ())
1111- continue ;
11121121 if (node->fDisconnect )
11131122 continue ;
11141123 NodeEvictionCandidate candidate{
@@ -1125,6 +1134,7 @@ bool CConnman::AttemptToEvictConnection()
11251134 Desig (m_is_local) node->addr .IsLocal (),
11261135 Desig (m_network) node->ConnectedThroughNetwork (),
11271136 Desig (m_noban) node->HasPermission (NetPermissionFlags::NoBan),
1137+ Desig (m_conn_type) node->m_conn_type ,
11281138 };
11291139 vEvictionCandidates.push_back (candidate);
11301140 }
0 commit comments