aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSuhas Daftuar <sdaftuar@gmail.com>2020-09-01 16:32:09 -0400
committerSuhas Daftuar <sdaftuar@gmail.com>2020-12-10 08:41:57 -0500
commit91d61952a82af3e8887e8ae532ecc19d87fe9073 (patch)
tree7595a09515d4ec79e518b6536106967552fa6f29 /src
parent86f20071931b803b5f26ed8f685d98d4919fb7a7 (diff)
downloadbitcoin-91d61952a82af3e8887e8ae532ecc19d87fe9073.tar.xz
Simplify and clarify extra outbound peer counting
Diffstat (limited to 'src')
-rw-r--r--src/init.cpp2
-rw-r--r--src/net.cpp10
-rw-r--r--src/net.h2
-rw-r--r--src/net_processing.cpp2
-rw-r--r--src/test/fuzz/connman.cpp2
5 files changed, 9 insertions, 9 deletions
diff --git a/src/init.cpp b/src/init.cpp
index 5460c9b2b0..09be3d01fa 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -200,7 +200,7 @@ void Shutdown(NodeContext& node)
// using the other before destroying them.
if (node.peerman) UnregisterValidationInterface(node.peerman.get());
// 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.
// * ProcessMessage locks cs_main and g_cs_orphans before indirectly calling ForEachNode which
// locks cs_vNodes.
diff --git a/src/net.cpp b/src/net.cpp
index bbb85694e7..fe1baf97a3 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -1827,18 +1827,18 @@ void CConnman::SetTryNewOutboundPeer(bool flag)
// 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
// 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);
for (const CNode* pnode : vNodes) {
- if (pnode->fSuccessfullyConnected && !pnode->fDisconnect && pnode->IsOutboundOrBlockRelayConn()) {
- ++nOutbound;
+ if (pnode->fSuccessfullyConnected && !pnode->fDisconnect && pnode->IsFullOutboundConn()) {
+ ++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)
diff --git a/src/net.h b/src/net.h
index 504855c386..e959718fab 100644
--- a/src/net.h
+++ b/src/net.h
@@ -336,7 +336,7 @@ public:
// return a value less than (num_outbound_connections - num_outbound_slots)
// in cases where some outbound connections are not yet fully connected, or
// not yet fully disconnected.
- int GetExtraOutboundCount();
+ int GetExtraFullOutboundCount();
bool AddNode(const std::string& node);
bool RemoveAddedNode(const std::string& node);
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index cdddde8540..243ac6a34b 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -3910,7 +3910,7 @@ void PeerManager::ConsiderEviction(CNode& pto, int64_t time_in_seconds)
void PeerManager::EvictExtraOutboundPeers(int64_t time_in_seconds)
{
// 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 we have more outbound peers than we target, disconnect one.
// Pick the outbound peer that least recently announced
diff --git a/src/test/fuzz/connman.cpp b/src/test/fuzz/connman.cpp
index 6521c3f3b2..bb97f58cf2 100644
--- a/src/test/fuzz/connman.cpp
+++ b/src/test/fuzz/connman.cpp
@@ -145,7 +145,7 @@ void test_one_input(const std::vector<uint8_t>& buffer)
}
(void)connman.GetAddedNodeInfo();
(void)connman.GetBestHeight();
- (void)connman.GetExtraOutboundCount();
+ (void)connman.GetExtraFullOutboundCount();
(void)connman.GetLocalServices();
(void)connman.GetMaxOutboundTarget();
(void)connman.GetMaxOutboundTimeframe();