mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-18 22:35:39 +01:00
net, rpc: Enable AddrFetch connections for functional testing
Co-authored-by: Amiti Uttarwar <amiti@uttarwar.org>
This commit is contained in:
21
src/net.cpp
21
src/net.cpp
@@ -1166,16 +1166,29 @@ void CConnman::CreateNodeFromAcceptedSocket(SOCKET hSocket,
|
||||
|
||||
bool CConnman::AddConnection(const std::string& address, ConnectionType conn_type)
|
||||
{
|
||||
if (conn_type != ConnectionType::OUTBOUND_FULL_RELAY && conn_type != ConnectionType::BLOCK_RELAY) return false;
|
||||
|
||||
const int max_connections = conn_type == ConnectionType::OUTBOUND_FULL_RELAY ? m_max_outbound_full_relay : m_max_outbound_block_relay;
|
||||
std::optional<int> max_connections;
|
||||
switch (conn_type) {
|
||||
case ConnectionType::INBOUND:
|
||||
case ConnectionType::MANUAL:
|
||||
case ConnectionType::FEELER:
|
||||
return false;
|
||||
case ConnectionType::OUTBOUND_FULL_RELAY:
|
||||
max_connections = m_max_outbound_full_relay;
|
||||
break;
|
||||
case ConnectionType::BLOCK_RELAY:
|
||||
max_connections = m_max_outbound_block_relay;
|
||||
break;
|
||||
// no limit for ADDR_FETCH because -seednode has no limit either
|
||||
case ConnectionType::ADDR_FETCH:
|
||||
break;
|
||||
} // no default case, so the compiler can warn about missing cases
|
||||
|
||||
// Count existing connections
|
||||
int existing_connections = WITH_LOCK(cs_vNodes,
|
||||
return std::count_if(vNodes.begin(), vNodes.end(), [conn_type](CNode* node) { return node->m_conn_type == conn_type; }););
|
||||
|
||||
// Max connections of specified type already exist
|
||||
if (existing_connections >= max_connections) return false;
|
||||
if (max_connections != std::nullopt && existing_connections >= max_connections) return false;
|
||||
|
||||
// Max total outbound connections already exist
|
||||
CSemaphoreGrant grant(*semOutbound, true);
|
||||
|
||||
Reference in New Issue
Block a user