mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 06:58:57 +01:00
[net] Add connection type to NodeEvictionCandidate
This commit is contained in:
14
src/net.cpp
14
src/net.cpp
@@ -957,6 +957,15 @@ void ProtectNoBanConnections(std::vector<NodeEvictionCandidate>& eviction_candid
|
||||
eviction_candidates.end());
|
||||
}
|
||||
|
||||
void ProtectOutboundConnections(std::vector<NodeEvictionCandidate>& eviction_candidates)
|
||||
{
|
||||
eviction_candidates.erase(std::remove_if(eviction_candidates.begin(), eviction_candidates.end(),
|
||||
[](NodeEvictionCandidate const& n) {
|
||||
return n.m_conn_type != ConnectionType::INBOUND;
|
||||
}),
|
||||
eviction_candidates.end());
|
||||
}
|
||||
|
||||
void ProtectEvictionCandidatesByRatio(std::vector<NodeEvictionCandidate>& eviction_candidates)
|
||||
{
|
||||
// Protect the half of the remaining nodes which have been connected the longest.
|
||||
@@ -1036,6 +1045,8 @@ void ProtectEvictionCandidatesByRatio(std::vector<NodeEvictionCandidate>& evicti
|
||||
|
||||
ProtectNoBanConnections(vEvictionCandidates);
|
||||
|
||||
ProtectOutboundConnections(vEvictionCandidates);
|
||||
|
||||
// Deterministically select 4 peers to protect by netgroup.
|
||||
// An attacker cannot predict which netgroups will be protected
|
||||
EraseLastKElements(vEvictionCandidates, CompareNetGroupKeyed, 4);
|
||||
@@ -1107,8 +1118,6 @@ bool CConnman::AttemptToEvictConnection()
|
||||
|
||||
LOCK(m_nodes_mutex);
|
||||
for (const CNode* node : m_nodes) {
|
||||
if (!node->IsInboundConn())
|
||||
continue;
|
||||
if (node->fDisconnect)
|
||||
continue;
|
||||
NodeEvictionCandidate candidate{
|
||||
@@ -1125,6 +1134,7 @@ bool CConnman::AttemptToEvictConnection()
|
||||
Desig(m_is_local) node->addr.IsLocal(),
|
||||
Desig(m_network) node->ConnectedThroughNetwork(),
|
||||
Desig(m_noban) node->HasPermission(NetPermissionFlags::NoBan),
|
||||
Desig(m_conn_type) node->m_conn_type,
|
||||
};
|
||||
vEvictionCandidates.push_back(candidate);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user