Skip to content

Commit 91d6195

Browse files
committed
Simplify and clarify extra outbound peer counting
1 parent 86f2007 commit 91d6195

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ void Shutdown(NodeContext& node)
200200
// using the other before destroying them.
201201
if (node.peerman) UnregisterValidationInterface(node.peerman.get());
202202
// Follow the lock order requirements:
203-
// * CheckForStaleTipAndEvictPeers locks cs_main before indirectly calling GetExtraOutboundCount
203+
// * CheckForStaleTipAndEvictPeers locks cs_main before indirectly calling GetExtraFullOutboundCount
204204
// which locks cs_vNodes.
205205
// * ProcessMessage locks cs_main and g_cs_orphans before indirectly calling ForEachNode which
206206
// locks cs_vNodes.

src/net.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,18 +1827,18 @@ void CConnman::SetTryNewOutboundPeer(bool flag)
18271827
// Also exclude peers that haven't finished initial connection handshake yet
18281828
// (so that we don't decide we're over our desired connection limit, and then
18291829
// evict some peer that has finished the handshake)
1830-
int CConnman::GetExtraOutboundCount()
1830+
int CConnman::GetExtraFullOutboundCount()
18311831
{
1832-
int nOutbound = 0;
1832+
int full_outbound_peers = 0;
18331833
{
18341834
LOCK(cs_vNodes);
18351835
for (const CNode* pnode : vNodes) {
1836-
if (pnode->fSuccessfullyConnected && !pnode->fDisconnect && pnode->IsOutboundOrBlockRelayConn()) {
1837-
++nOutbound;
1836+
if (pnode->fSuccessfullyConnected && !pnode->fDisconnect && pnode->IsFullOutboundConn()) {
1837+
++full_outbound_peers;
18381838
}
18391839
}
18401840
}
1841-
return std::max(nOutbound - m_max_outbound_full_relay - m_max_outbound_block_relay, 0);
1841+
return std::max(full_outbound_peers - m_max_outbound_full_relay, 0);
18421842
}
18431843

18441844
void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)

src/net.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ class CConnman
336336
// return a value less than (num_outbound_connections - num_outbound_slots)
337337
// in cases where some outbound connections are not yet fully connected, or
338338
// not yet fully disconnected.
339-
int GetExtraOutboundCount();
339+
int GetExtraFullOutboundCount();
340340

341341
bool AddNode(const std::string& node);
342342
bool RemoveAddedNode(const std::string& node);

src/net_processing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3910,7 +3910,7 @@ void PeerManager::ConsiderEviction(CNode& pto, int64_t time_in_seconds)
39103910
void PeerManager::EvictExtraOutboundPeers(int64_t time_in_seconds)
39113911
{
39123912
// Check whether we have too many outbound peers
3913-
int extra_peers = m_connman.GetExtraOutboundCount();
3913+
int extra_peers = m_connman.GetExtraFullOutboundCount();
39143914
if (extra_peers > 0) {
39153915
// If we have more outbound peers than we target, disconnect one.
39163916
// Pick the outbound peer that least recently announced

src/test/fuzz/connman.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ void test_one_input(const std::vector<uint8_t>& buffer)
145145
}
146146
(void)connman.GetAddedNodeInfo();
147147
(void)connman.GetBestHeight();
148-
(void)connman.GetExtraOutboundCount();
148+
(void)connman.GetExtraFullOutboundCount();
149149
(void)connman.GetLocalServices();
150150
(void)connman.GetMaxOutboundTarget();
151151
(void)connman.GetMaxOutboundTimeframe();

0 commit comments

Comments
 (0)