diff options
author | Amiti Uttarwar <amiti@uttarwar.org> | 2023-08-31 13:41:30 -0700 |
---|---|---|
committer | Martin Zumsande <mzumsande@gmail.com> | 2023-10-03 13:52:47 -0400 |
commit | e9fd9c0225527ec7727d2a7ccbdf028784aadc6c (patch) | |
tree | 7259d80bc5389a3d39f32ea668257f18a0a2717c /src/net.cpp | |
parent | c25e0e05550426f29d79571368d90f63fb472b02 (diff) |
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>
Diffstat (limited to 'src/net.cpp')
-rw-r--r-- | src/net.cpp | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/src/net.cpp b/src/net.cpp index 13f4430424..565e54875b 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -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 |