@@ -1693,6 +1693,36 @@ void CConnman::ProcessOneShot()
1693
1693
}
1694
1694
}
1695
1695
1696
+ bool CConnman::GetTryNewOutboundPeer ()
1697
+ {
1698
+ return m_try_another_outbound_peer;
1699
+ }
1700
+
1701
+ void CConnman::SetTryNewOutboundPeer (bool flag)
1702
+ {
1703
+ m_try_another_outbound_peer = flag;
1704
+ }
1705
+
1706
+ // Return the number of peers we have over our outbound connection limit
1707
+ // Exclude peers that are marked for disconnect, or are going to be
1708
+ // disconnected soon (eg one-shots and feelers)
1709
+ // Also exclude peers that haven't finished initial connection handshake yet
1710
+ // (so that we don't decide we're over our desired connection limit, and then
1711
+ // evict some peer that has finished the handshake)
1712
+ int CConnman::GetExtraOutboundCount ()
1713
+ {
1714
+ int nOutbound = 0 ;
1715
+ {
1716
+ LOCK (cs_vNodes);
1717
+ for (CNode* pnode : vNodes) {
1718
+ if (!pnode->fInbound && !pnode->m_manual_connection && !pnode->fFeeler && !pnode->fDisconnect && !pnode->fOneShot && pnode->fSuccessfullyConnected ) {
1719
+ ++nOutbound;
1720
+ }
1721
+ }
1722
+ }
1723
+ return std::max (nOutbound - nMaxOutbound, 0 );
1724
+ }
1725
+
1696
1726
void CConnman::ThreadOpenConnections (const std::vector<std::string> connect)
1697
1727
{
1698
1728
// Connect to specific addresses
@@ -1781,7 +1811,8 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
1781
1811
// * Only make a feeler connection once every few minutes.
1782
1812
//
1783
1813
bool fFeeler = false ;
1784
- if (nOutbound >= nMaxOutbound) {
1814
+
1815
+ if (nOutbound >= nMaxOutbound && !GetTryNewOutboundPeer ()) {
1785
1816
int64_t nTime = GetTimeMicros (); // The current time right now (in microseconds).
1786
1817
if (nTime > nNextFeeler) {
1787
1818
nNextFeeler = PoissonNextSend (nTime, FEELER_INTERVAL);
@@ -2204,6 +2235,7 @@ CConnman::CConnman(uint64_t nSeed0In, uint64_t nSeed1In) : nSeed0(nSeed0In), nSe
2204
2235
semOutbound = nullptr ;
2205
2236
semAddnode = nullptr ;
2206
2237
flagInterruptMsgProc = false ;
2238
+ SetTryNewOutboundPeer (false );
2207
2239
2208
2240
Options connOptions;
2209
2241
Init (connOptions);
0 commit comments