mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-02 09:46:52 -05:00
p2p: Introduce data struct to track connection counts by network
Connman uses this new map to keep a count of active OUTBOUND_FULL_RELAY and MANUAL connections. Unused until next commit. Co-authored-by: Martin Zumsande <mzumsande@gmail.com>
This commit is contained in:
parent
6a473373d4
commit
654d9bc276
3 changed files with 28 additions and 0 deletions
|
@ -1135,6 +1135,9 @@ void CConnman::DisconnectNodes()
|
|||
// close socket and cleanup
|
||||
pnode->CloseSocketDisconnect();
|
||||
|
||||
// update connection count by network
|
||||
if (pnode->IsManualOrFullOutboundConn()) --m_network_conn_counts[pnode->addr.GetNetwork()];
|
||||
|
||||
// hold in disconnected pool until all refs are released
|
||||
pnode->Release();
|
||||
m_nodes_disconnected.push_back(pnode);
|
||||
|
@ -2035,6 +2038,9 @@ void CConnman::OpenNetworkConnection(const CAddress& addrConnect, bool fCountFai
|
|||
{
|
||||
LOCK(m_nodes_mutex);
|
||||
m_nodes.push_back(pnode);
|
||||
|
||||
// update connection count by network
|
||||
if (pnode->IsManualOrFullOutboundConn()) ++m_network_conn_counts[pnode->addr.GetNetwork()];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
19
src/net.h
19
src/net.h
|
@ -465,6 +465,22 @@ public:
|
|||
return m_conn_type == ConnectionType::MANUAL;
|
||||
}
|
||||
|
||||
bool IsManualOrFullOutboundConn() const
|
||||
{
|
||||
switch (m_conn_type) {
|
||||
case ConnectionType::INBOUND:
|
||||
case ConnectionType::FEELER:
|
||||
case ConnectionType::BLOCK_RELAY:
|
||||
case ConnectionType::ADDR_FETCH:
|
||||
return false;
|
||||
case ConnectionType::OUTBOUND_FULL_RELAY:
|
||||
case ConnectionType::MANUAL:
|
||||
return true;
|
||||
} // no default case, so the compiler can warn about missing cases
|
||||
|
||||
assert(false);
|
||||
}
|
||||
|
||||
bool IsBlockOnlyConn() const {
|
||||
return m_conn_type == ConnectionType::BLOCK_RELAY;
|
||||
}
|
||||
|
@ -1048,6 +1064,9 @@ private:
|
|||
std::atomic<NodeId> nLastNodeId{0};
|
||||
unsigned int nPrevNodeCount{0};
|
||||
|
||||
// Stores number of full-tx connections (outbound and manual) per network
|
||||
std::array<unsigned int, Network::NET_MAX> m_network_conn_counts GUARDED_BY(m_nodes_mutex) = {};
|
||||
|
||||
/**
|
||||
* Cache responses to addr requests to minimize privacy leak.
|
||||
* Attack example: scraping addrs in real-time may allow an attacker
|
||||
|
|
|
@ -29,7 +29,10 @@ struct ConnmanTestMsg : public CConnman {
|
|||
{
|
||||
LOCK(m_nodes_mutex);
|
||||
m_nodes.push_back(&node);
|
||||
|
||||
if (node.IsManualOrFullOutboundConn()) ++m_network_conn_counts[node.addr.GetNetwork()];
|
||||
}
|
||||
|
||||
void ClearTestNodes()
|
||||
{
|
||||
LOCK(m_nodes_mutex);
|
||||
|
|
Loading…
Add table
Reference in a new issue