mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-08-04 05:54:48 +02:00
net: nodes with ForceInbound permission force eviction
Github-Pull: #27600 Rebased-From: 8bc203073a0b8b7e1a6851bcf3f1688e54b10a73
This commit is contained in:
parent
ef1953b138
commit
a128693bf2
@ -1665,7 +1665,7 @@ std::pair<size_t, bool> CConnman::SocketSendData(CNode& node) const
|
||||
* to forge. In order to partition a node the attacker must be
|
||||
* simultaneously better at all of them than honest peers.
|
||||
*/
|
||||
bool CConnman::AttemptToEvictConnection()
|
||||
bool CConnman::AttemptToEvictConnection(bool force)
|
||||
{
|
||||
std::vector<NodeEvictionCandidate> vEvictionCandidates;
|
||||
{
|
||||
@ -1693,7 +1693,7 @@ bool CConnman::AttemptToEvictConnection()
|
||||
vEvictionCandidates.push_back(candidate);
|
||||
}
|
||||
}
|
||||
const std::optional<NodeId> node_id_to_evict = SelectNodeToEvict(std::move(vEvictionCandidates));
|
||||
const std::optional<NodeId> node_id_to_evict = SelectNodeToEvict(std::move(vEvictionCandidates), force);
|
||||
if (!node_id_to_evict) {
|
||||
return false;
|
||||
}
|
||||
@ -1788,7 +1788,9 @@ void CConnman::CreateNodeFromAcceptedSocket(std::unique_ptr<Sock>&& sock,
|
||||
|
||||
if (nInbound >= m_max_inbound)
|
||||
{
|
||||
if (!AttemptToEvictConnection()) {
|
||||
// If the inbound connection attempt is granted ForceInbound permission, try a little harder
|
||||
// to make room by evicting a peer we may not have otherwise evicted.
|
||||
if (!AttemptToEvictConnection(NetPermissions::HasFlag(permission_flags, NetPermissionFlags::ForceInbound))) {
|
||||
// No connection to evict, disconnect the new connection
|
||||
LogPrint(BCLog::NET, "failed to find an eviction candidate - connection dropped (full)\n");
|
||||
return;
|
||||
|
@ -1339,7 +1339,14 @@ private:
|
||||
*/
|
||||
bool AlreadyConnectedToAddress(const CAddress& addr);
|
||||
|
||||
bool AttemptToEvictConnection();
|
||||
/**
|
||||
* Attempt to disconnect a connected peer.
|
||||
* Used to make room for new inbound connections, returns true if successful.
|
||||
* @param[in] force Try to evict a random inbound ban-able peer if
|
||||
* all connections are otherwise protected.
|
||||
*/
|
||||
bool AttemptToEvictConnection(bool force);
|
||||
|
||||
CNode* ConnectNode(CAddress addrConnect, const char *pszDest, bool fCountFailure, ConnectionType conn_type, bool use_v2transport) EXCLUSIVE_LOCKS_REQUIRED(!m_unused_i2p_sessions_mutex);
|
||||
void AddWhitelistPermissionFlags(NetPermissionFlags& flags, const CNetAddr &addr, const std::vector<NetWhitelistPermissions>& ranges) const;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user