mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-06 18:53:21 +01:00
Merge bitcoin/bitcoin#28464: net: improve max-connection limits code
df69b22f2edoc: improve documentation around connection limit maximums (Amiti Uttarwar)adc171edf4scripted-diff: Rename connection limit variables (Amiti Uttarwar)e9fd9c0225net: add m_max_inbound to connman (Amiti Uttarwar)c25e0e0555net, refactor: move calculations for connection type limits into connman (Amiti Uttarwar) Pull request description: This is joint work with amitiuttarwar. This has the first few commits of #28463. It is not strictly a prerequisite for that, but has changes that in our opinion make sense on their own. It improves the handling of maximum numbers for different connection types (that are set during init and don’t change after) by: * moving all calculations into one place, `CConnMan::Init()`. Before, they were dispersed between `Init`, `CConnman::Init` and other parts of `CConnman`, resulting in some duplicated test code. * removing the possibility of having a negative maximum of inbound connections, which is hard to argue about * renaming of variables and doc improvements ACKs for top commit: amitiuttarwar: co-author review ACKdf69b22f2enaumenkogs: ACKdf69b22f2eachow101: ACKdf69b22f2eTree-SHA512: 913d56136bc1df739978de50db67302f88bac2a9d34748ae96763288d97093e998fc0f94f9b6eff12867712d7e86225af6128f4170bf2b5b8ab76f024870a22c
This commit is contained in:
38
src/net.h
38
src/net.h
@@ -1045,11 +1045,7 @@ public:
|
||||
struct Options
|
||||
{
|
||||
ServiceFlags nLocalServices = NODE_NONE;
|
||||
int nMaxConnections = 0;
|
||||
int m_max_outbound_full_relay = 0;
|
||||
int m_max_outbound_block_relay = 0;
|
||||
int nMaxAddnode = 0;
|
||||
int nMaxFeeler = 0;
|
||||
int m_max_automatic_connections = 0;
|
||||
CClientUIInterface* uiInterface = nullptr;
|
||||
NetEventsInterface* m_msgproc = nullptr;
|
||||
BanMan* m_banman = nullptr;
|
||||
@@ -1076,13 +1072,12 @@ public:
|
||||
AssertLockNotHeld(m_total_bytes_sent_mutex);
|
||||
|
||||
nLocalServices = connOptions.nLocalServices;
|
||||
nMaxConnections = connOptions.nMaxConnections;
|
||||
m_max_outbound_full_relay = std::min(connOptions.m_max_outbound_full_relay, connOptions.nMaxConnections);
|
||||
m_max_outbound_block_relay = connOptions.m_max_outbound_block_relay;
|
||||
m_max_automatic_connections = connOptions.m_max_automatic_connections;
|
||||
m_max_outbound_full_relay = std::min(MAX_OUTBOUND_FULL_RELAY_CONNECTIONS, m_max_automatic_connections);
|
||||
m_max_outbound_block_relay = std::min(MAX_BLOCK_RELAY_ONLY_CONNECTIONS, m_max_automatic_connections - m_max_outbound_full_relay);
|
||||
m_max_automatic_outbound = m_max_outbound_full_relay + m_max_outbound_block_relay + m_max_feeler;
|
||||
m_max_inbound = std::max(0, m_max_automatic_connections - m_max_automatic_outbound);
|
||||
m_use_addrman_outgoing = connOptions.m_use_addrman_outgoing;
|
||||
nMaxAddnode = connOptions.nMaxAddnode;
|
||||
nMaxFeeler = connOptions.nMaxFeeler;
|
||||
m_max_outbound = m_max_outbound_full_relay + m_max_outbound_block_relay + nMaxFeeler;
|
||||
m_client_interface = connOptions.uiInterface;
|
||||
m_banman = connOptions.m_banman;
|
||||
m_msgproc = connOptions.m_msgproc;
|
||||
@@ -1466,7 +1461,18 @@ private:
|
||||
|
||||
std::unique_ptr<CSemaphore> semOutbound;
|
||||
std::unique_ptr<CSemaphore> semAddnode;
|
||||
int nMaxConnections;
|
||||
|
||||
/**
|
||||
* Maximum number of automatic connections permitted, excluding manual
|
||||
* connections but including inbounds. May be changed by the user and is
|
||||
* potentially limited by the operating system (number of file descriptors).
|
||||
*/
|
||||
int m_max_automatic_connections;
|
||||
|
||||
/*
|
||||
* Maximum number of peers by connection type. Might vary from defaults
|
||||
* based on -maxconnections init value.
|
||||
*/
|
||||
|
||||
// How many full-relay (tx, block, addr) outbound peers we want
|
||||
int m_max_outbound_full_relay;
|
||||
@@ -1475,9 +1481,11 @@ private:
|
||||
// We do not relay tx or addr messages with these peers
|
||||
int m_max_outbound_block_relay;
|
||||
|
||||
int nMaxAddnode;
|
||||
int nMaxFeeler;
|
||||
int m_max_outbound;
|
||||
int m_max_addnode{MAX_ADDNODE_CONNECTIONS};
|
||||
int m_max_feeler{MAX_FEELER_CONNECTIONS};
|
||||
int m_max_automatic_outbound;
|
||||
int m_max_inbound;
|
||||
|
||||
bool m_use_addrman_outgoing;
|
||||
CClientUIInterface* m_client_interface;
|
||||
NetEventsInterface* m_msgproc;
|
||||
|
||||
Reference in New Issue
Block a user