|
|
|
@ -1693,6 +1693,36 @@ void CConnman::ProcessOneShot()
@@ -1693,6 +1693,36 @@ void CConnman::ProcessOneShot()
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool CConnman::GetTryNewOutboundPeer() |
|
|
|
|
{ |
|
|
|
|
return m_try_another_outbound_peer; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void CConnman::SetTryNewOutboundPeer(bool flag) |
|
|
|
|
{ |
|
|
|
|
m_try_another_outbound_peer = flag; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Return the number of peers we have over our outbound connection limit
|
|
|
|
|
// Exclude peers that are marked for disconnect, or are going to be
|
|
|
|
|
// disconnected soon (eg one-shots and feelers)
|
|
|
|
|
// 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 nOutbound = 0; |
|
|
|
|
{ |
|
|
|
|
LOCK(cs_vNodes); |
|
|
|
|
for (CNode* pnode : vNodes) { |
|
|
|
|
if (!pnode->fInbound && !pnode->m_manual_connection && !pnode->fFeeler && !pnode->fDisconnect && !pnode->fOneShot && pnode->fSuccessfullyConnected) { |
|
|
|
|
++nOutbound; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return std::max(nOutbound - nMaxOutbound, 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void CConnman::ThreadOpenConnections(const std::vector<std::string> connect) |
|
|
|
|
{ |
|
|
|
|
// Connect to specific addresses
|
|
|
|
@ -1781,7 +1811,8 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
@@ -1781,7 +1811,8 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
|
|
|
|
|
// * Only make a feeler connection once every few minutes.
|
|
|
|
|
//
|
|
|
|
|
bool fFeeler = false; |
|
|
|
|
if (nOutbound >= nMaxOutbound) { |
|
|
|
|
|
|
|
|
|
if (nOutbound >= nMaxOutbound && !GetTryNewOutboundPeer()) { |
|
|
|
|
int64_t nTime = GetTimeMicros(); // The current time right now (in microseconds).
|
|
|
|
|
if (nTime > nNextFeeler) { |
|
|
|
|
nNextFeeler = PoissonNextSend(nTime, FEELER_INTERVAL); |
|
|
|
@ -2204,6 +2235,7 @@ CConnman::CConnman(uint64_t nSeed0In, uint64_t nSeed1In) : nSeed0(nSeed0In), nSe
@@ -2204,6 +2235,7 @@ CConnman::CConnman(uint64_t nSeed0In, uint64_t nSeed1In) : nSeed0(nSeed0In), nSe
|
|
|
|
|
semOutbound = nullptr; |
|
|
|
|
semAddnode = nullptr; |
|
|
|
|
flagInterruptMsgProc = false; |
|
|
|
|
SetTryNewOutboundPeer(false); |
|
|
|
|
|
|
|
|
|
Options connOptions; |
|
|
|
|
Init(connOptions); |
|
|
|
|