diff options
author | Suhas Daftuar <sdaftuar@gmail.com> | 2017-10-23 13:36:15 -0400 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2017-11-02 15:18:56 -0400 |
commit | 49bf090185ad7f6aa4d86bae8aeedfcaf396771c (patch) | |
tree | 9fe4617e8f3d2b5d5535fd81f34cbadac361c061 /src/net.cpp | |
parent | bb83fe19026b4d86a6514e6f3ed5f4d71f1bc4bc (diff) |
net: Allow connecting to extra outbound peers
Github-Pull: #11560
Rebased-From: 2d4327db1973a354e9e4153de6958d49120fcde8
Diffstat (limited to 'src/net.cpp')
-rw-r--r-- | src/net.cpp | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/src/net.cpp b/src/net.cpp index a07b22bf5d..1687900ed7 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1670,6 +1670,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() { // Connect to specific addresses @@ -1764,7 +1794,8 @@ void CConnman::ThreadOpenConnections() // * 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); @@ -2207,6 +2238,7 @@ CConnman::CConnman(uint64_t nSeed0In, uint64_t nSeed1In) : nSeed0(nSeed0In), nSe semOutbound = nullptr; semAddnode = nullptr; flagInterruptMsgProc = false; + SetTryNewOutboundPeer(false); Options connOptions; Init(connOptions); |