mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-03 09:56:38 -05:00
net: add m_max_inbound to connman
Extract the logic for calculating & maintaining inbound connection limits to be a member within connman for consistency with other maximum connection limits. Note that we now limit m_max_inbound to 0 and don't call AttemptToEvictConnection() when we don't have any inbounds. Previously, nMaxInbound could become negative if the user ran with a low -maxconnections, which didn't break any logic but didn't make sense. Co-authored-by: Martin Zumsande <mzumsande@gmail.com>
This commit is contained in:
parent
c25e0e0555
commit
e9fd9c0225
2 changed files with 4 additions and 3 deletions
|
@ -1777,7 +1777,6 @@ void CConnman::CreateNodeFromAcceptedSocket(std::unique_ptr<Sock>&& sock,
|
|||
const CAddress& addr)
|
||||
{
|
||||
int nInbound = 0;
|
||||
int nMaxInbound = nMaxConnections - m_max_outbound;
|
||||
|
||||
AddWhitelistPermissionFlags(permission_flags, addr);
|
||||
if (NetPermissions::HasFlag(permission_flags, NetPermissionFlags::Implicit)) {
|
||||
|
@ -1823,13 +1822,13 @@ void CConnman::CreateNodeFromAcceptedSocket(std::unique_ptr<Sock>&& sock,
|
|||
|
||||
// Only accept connections from discouraged peers if our inbound slots aren't (almost) full.
|
||||
bool discouraged = m_banman && m_banman->IsDiscouraged(addr);
|
||||
if (!NetPermissions::HasFlag(permission_flags, NetPermissionFlags::NoBan) && nInbound + 1 >= nMaxInbound && discouraged)
|
||||
if (!NetPermissions::HasFlag(permission_flags, NetPermissionFlags::NoBan) && nInbound + 1 >= m_max_inbound && discouraged)
|
||||
{
|
||||
LogPrint(BCLog::NET, "connection from %s dropped (discouraged)\n", addr.ToStringAddrPort());
|
||||
return;
|
||||
}
|
||||
|
||||
if (nInbound >= nMaxInbound)
|
||||
if (nInbound >= m_max_inbound)
|
||||
{
|
||||
if (!AttemptToEvictConnection()) {
|
||||
// No connection to evict, disconnect the new connection
|
||||
|
|
|
@ -1088,6 +1088,7 @@ public:
|
|||
m_max_outbound_full_relay = std::min(MAX_OUTBOUND_FULL_RELAY_CONNECTIONS, nMaxConnections);
|
||||
m_max_outbound_block_relay = std::min(MAX_BLOCK_RELAY_ONLY_CONNECTIONS, nMaxConnections - m_max_outbound_full_relay);
|
||||
m_max_outbound = m_max_outbound_full_relay + m_max_outbound_block_relay + nMaxFeeler;
|
||||
m_max_inbound = std::max(0, nMaxConnections - m_max_outbound);
|
||||
m_use_addrman_outgoing = connOptions.m_use_addrman_outgoing;
|
||||
m_client_interface = connOptions.uiInterface;
|
||||
m_banman = connOptions.m_banman;
|
||||
|
@ -1485,6 +1486,7 @@ private:
|
|||
int nMaxAddnode{MAX_ADDNODE_CONNECTIONS};
|
||||
int nMaxFeeler{MAX_FEELER_CONNECTIONS};
|
||||
int m_max_outbound;
|
||||
int m_max_inbound;
|
||||
bool m_use_addrman_outgoing;
|
||||
CClientUIInterface* m_client_interface;
|
||||
NetEventsInterface* m_msgproc;
|
||||
|
|
Loading…
Add table
Reference in a new issue