Skip to content

Commit e9fd9c0

Browse files
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>
1 parent c25e0e0 commit e9fd9c0

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/net.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,7 +1777,6 @@ void CConnman::CreateNodeFromAcceptedSocket(std::unique_ptr<Sock>&& sock,
17771777
const CAddress& addr)
17781778
{
17791779
int nInbound = 0;
1780-
int nMaxInbound = nMaxConnections - m_max_outbound;
17811780

17821781
AddWhitelistPermissionFlags(permission_flags, addr);
17831782
if (NetPermissions::HasFlag(permission_flags, NetPermissionFlags::Implicit)) {
@@ -1823,13 +1822,13 @@ void CConnman::CreateNodeFromAcceptedSocket(std::unique_ptr<Sock>&& sock,
18231822

18241823
// Only accept connections from discouraged peers if our inbound slots aren't (almost) full.
18251824
bool discouraged = m_banman && m_banman->IsDiscouraged(addr);
1826-
if (!NetPermissions::HasFlag(permission_flags, NetPermissionFlags::NoBan) && nInbound + 1 >= nMaxInbound && discouraged)
1825+
if (!NetPermissions::HasFlag(permission_flags, NetPermissionFlags::NoBan) && nInbound + 1 >= m_max_inbound && discouraged)
18271826
{
18281827
LogPrint(BCLog::NET, "connection from %s dropped (discouraged)\n", addr.ToStringAddrPort());
18291828
return;
18301829
}
18311830

1832-
if (nInbound >= nMaxInbound)
1831+
if (nInbound >= m_max_inbound)
18331832
{
18341833
if (!AttemptToEvictConnection()) {
18351834
// No connection to evict, disconnect the new connection

src/net.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,7 @@ class CConnman
10881088
m_max_outbound_full_relay = std::min(MAX_OUTBOUND_FULL_RELAY_CONNECTIONS, nMaxConnections);
10891089
m_max_outbound_block_relay = std::min(MAX_BLOCK_RELAY_ONLY_CONNECTIONS, nMaxConnections - m_max_outbound_full_relay);
10901090
m_max_outbound = m_max_outbound_full_relay + m_max_outbound_block_relay + nMaxFeeler;
1091+
m_max_inbound = std::max(0, nMaxConnections - m_max_outbound);
10911092
m_use_addrman_outgoing = connOptions.m_use_addrman_outgoing;
10921093
m_client_interface = connOptions.uiInterface;
10931094
m_banman = connOptions.m_banman;
@@ -1485,6 +1486,7 @@ class CConnman
14851486
int nMaxAddnode{MAX_ADDNODE_CONNECTIONS};
14861487
int nMaxFeeler{MAX_FEELER_CONNECTIONS};
14871488
int m_max_outbound;
1489+
int m_max_inbound;
14881490
bool m_use_addrman_outgoing;
14891491
CClientUIInterface* m_client_interface;
14901492
NetEventsInterface* m_msgproc;

0 commit comments

Comments
 (0)