mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-09 10:43:19 -05:00
Simplify and clarify extra outbound peer counting
This commit is contained in:
parent
86f2007193
commit
91d61952a8
5 changed files with 9 additions and 9 deletions
|
@ -200,7 +200,7 @@ void Shutdown(NodeContext& node)
|
||||||
// using the other before destroying them.
|
// using the other before destroying them.
|
||||||
if (node.peerman) UnregisterValidationInterface(node.peerman.get());
|
if (node.peerman) UnregisterValidationInterface(node.peerman.get());
|
||||||
// Follow the lock order requirements:
|
// Follow the lock order requirements:
|
||||||
// * CheckForStaleTipAndEvictPeers locks cs_main before indirectly calling GetExtraOutboundCount
|
// * CheckForStaleTipAndEvictPeers locks cs_main before indirectly calling GetExtraFullOutboundCount
|
||||||
// which locks cs_vNodes.
|
// which locks cs_vNodes.
|
||||||
// * ProcessMessage locks cs_main and g_cs_orphans before indirectly calling ForEachNode which
|
// * ProcessMessage locks cs_main and g_cs_orphans before indirectly calling ForEachNode which
|
||||||
// locks cs_vNodes.
|
// locks cs_vNodes.
|
||||||
|
|
10
src/net.cpp
10
src/net.cpp
|
@ -1827,18 +1827,18 @@ void CConnman::SetTryNewOutboundPeer(bool flag)
|
||||||
// Also exclude peers that haven't finished initial connection handshake yet
|
// Also exclude peers that haven't finished initial connection handshake yet
|
||||||
// (so that we don't decide we're over our desired connection limit, and then
|
// (so that we don't decide we're over our desired connection limit, and then
|
||||||
// evict some peer that has finished the handshake)
|
// evict some peer that has finished the handshake)
|
||||||
int CConnman::GetExtraOutboundCount()
|
int CConnman::GetExtraFullOutboundCount()
|
||||||
{
|
{
|
||||||
int nOutbound = 0;
|
int full_outbound_peers = 0;
|
||||||
{
|
{
|
||||||
LOCK(cs_vNodes);
|
LOCK(cs_vNodes);
|
||||||
for (const CNode* pnode : vNodes) {
|
for (const CNode* pnode : vNodes) {
|
||||||
if (pnode->fSuccessfullyConnected && !pnode->fDisconnect && pnode->IsOutboundOrBlockRelayConn()) {
|
if (pnode->fSuccessfullyConnected && !pnode->fDisconnect && pnode->IsFullOutboundConn()) {
|
||||||
++nOutbound;
|
++full_outbound_peers;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return std::max(nOutbound - m_max_outbound_full_relay - m_max_outbound_block_relay, 0);
|
return std::max(full_outbound_peers - m_max_outbound_full_relay, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
|
void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
|
||||||
|
|
|
@ -336,7 +336,7 @@ public:
|
||||||
// return a value less than (num_outbound_connections - num_outbound_slots)
|
// return a value less than (num_outbound_connections - num_outbound_slots)
|
||||||
// in cases where some outbound connections are not yet fully connected, or
|
// in cases where some outbound connections are not yet fully connected, or
|
||||||
// not yet fully disconnected.
|
// not yet fully disconnected.
|
||||||
int GetExtraOutboundCount();
|
int GetExtraFullOutboundCount();
|
||||||
|
|
||||||
bool AddNode(const std::string& node);
|
bool AddNode(const std::string& node);
|
||||||
bool RemoveAddedNode(const std::string& node);
|
bool RemoveAddedNode(const std::string& node);
|
||||||
|
|
|
@ -3910,7 +3910,7 @@ void PeerManager::ConsiderEviction(CNode& pto, int64_t time_in_seconds)
|
||||||
void PeerManager::EvictExtraOutboundPeers(int64_t time_in_seconds)
|
void PeerManager::EvictExtraOutboundPeers(int64_t time_in_seconds)
|
||||||
{
|
{
|
||||||
// Check whether we have too many outbound peers
|
// Check whether we have too many outbound peers
|
||||||
int extra_peers = m_connman.GetExtraOutboundCount();
|
int extra_peers = m_connman.GetExtraFullOutboundCount();
|
||||||
if (extra_peers > 0) {
|
if (extra_peers > 0) {
|
||||||
// If we have more outbound peers than we target, disconnect one.
|
// If we have more outbound peers than we target, disconnect one.
|
||||||
// Pick the outbound peer that least recently announced
|
// Pick the outbound peer that least recently announced
|
||||||
|
|
|
@ -145,7 +145,7 @@ void test_one_input(const std::vector<uint8_t>& buffer)
|
||||||
}
|
}
|
||||||
(void)connman.GetAddedNodeInfo();
|
(void)connman.GetAddedNodeInfo();
|
||||||
(void)connman.GetBestHeight();
|
(void)connman.GetBestHeight();
|
||||||
(void)connman.GetExtraOutboundCount();
|
(void)connman.GetExtraFullOutboundCount();
|
||||||
(void)connman.GetLocalServices();
|
(void)connman.GetLocalServices();
|
||||||
(void)connman.GetMaxOutboundTarget();
|
(void)connman.GetMaxOutboundTarget();
|
||||||
(void)connman.GetMaxOutboundTimeframe();
|
(void)connman.GetMaxOutboundTimeframe();
|
||||||
|
|
Loading…
Add table
Reference in a new issue