Changeset View
Changeset View
Standalone View
Standalone View
src/net.cpp
Show First 20 Lines • Show All 1,912 Lines • ▼ Show 20 Lines | int nOutbound = 0; | ||||
for (const CNode *pnode : vNodes) { | for (const CNode *pnode : vNodes) { | ||||
if (!pnode->fInbound && !pnode->m_manual_connection && | if (!pnode->fInbound && !pnode->m_manual_connection && | ||||
!pnode->fFeeler && !pnode->fDisconnect && !pnode->fOneShot && | !pnode->fFeeler && !pnode->fDisconnect && !pnode->fOneShot && | ||||
pnode->fSuccessfullyConnected) { | pnode->fSuccessfullyConnected) { | ||||
++nOutbound; | ++nOutbound; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
LOCK(cs_maxOutboundPeers); | |||||
return std::max( | return std::max( | ||||
nOutbound - m_max_outbound_full_relay - m_max_outbound_block_relay, 0); | nOutbound - m_max_outbound_full_relay - m_max_outbound_block_relay, 0); | ||||
} | } | ||||
void CConnman::ThreadOpenConnections(const std::vector<std::string> connect) { | void CConnman::ThreadOpenConnections(const std::vector<std::string> connect) { | ||||
// Connect to specific addresses | // Connect to specific addresses | ||||
if (!connect.empty()) { | if (!connect.empty()) { | ||||
for (int64_t nLoop = 0;; nLoop++) { | for (int64_t nLoop = 0;; nLoop++) { | ||||
▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | while (!interruptNet) { | ||||
// * Choose a random address from new and attempt to connect to it if | // * Choose a random address from new and attempt to connect to it if | ||||
// we can connect successfully it is added to tried. | // we can connect successfully it is added to tried. | ||||
// * Start attempting feeler connections only after node finishes | // * Start attempting feeler connections only after node finishes | ||||
// making outbound connections. | // making outbound connections. | ||||
// * Only make a feeler connection once every few minutes. | // * Only make a feeler connection once every few minutes. | ||||
// | // | ||||
bool fFeeler = false; | bool fFeeler = false; | ||||
{ | |||||
LOCK(cs_maxOutboundPeers); | |||||
if (nOutboundFullRelay >= m_max_outbound_full_relay && | if (nOutboundFullRelay >= m_max_outbound_full_relay && | ||||
nOutboundBlockRelay >= m_max_outbound_block_relay && | nOutboundBlockRelay >= m_max_outbound_block_relay && | ||||
!GetTryNewOutboundPeer()) { | !GetTryNewOutboundPeer()) { | ||||
// The current time right now (in microseconds). | // The current time right now (in microseconds). | ||||
int64_t nTime = GetTimeMicros(); | int64_t nTime = GetTimeMicros(); | ||||
if (nTime > nNextFeeler) { | if (nTime > nNextFeeler) { | ||||
nNextFeeler = PoissonNextSend(nTime, FEELER_INTERVAL); | nNextFeeler = PoissonNextSend(nTime, FEELER_INTERVAL); | ||||
fFeeler = true; | fFeeler = true; | ||||
} else { | } else { | ||||
continue; | continue; | ||||
} | } | ||||
} | } | ||||
} | |||||
addrman.ResolveCollisions(); | addrman.ResolveCollisions(); | ||||
int64_t nANow = GetAdjustedTime(); | int64_t nANow = GetAdjustedTime(); | ||||
int nTries = 0; | int nTries = 0; | ||||
while (!interruptNet) { | while (!interruptNet) { | ||||
CAddrInfo addr = addrman.SelectTriedCollision(); | CAddrInfo addr = addrman.SelectTriedCollision(); | ||||
▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | while (!interruptNet) { | ||||
addrConnect.ToString()); | addrConnect.ToString()); | ||||
} | } | ||||
// Open this connection as block-relay-only if we're already at our | // Open this connection as block-relay-only if we're already at our | ||||
// full-relay capacity, but not yet at our block-relay peer limit. | // full-relay capacity, but not yet at our block-relay peer limit. | ||||
// (It should not be possible for fFeeler to be set if we're not | // (It should not be possible for fFeeler to be set if we're not | ||||
// also at our block-relay peer limit, but check against that as | // also at our block-relay peer limit, but check against that as | ||||
// well for sanity.) | // well for sanity.) | ||||
bool block_relay_only = | bool block_relay_only; | ||||
nOutboundBlockRelay < m_max_outbound_block_relay && !fFeeler && | { | ||||
nOutboundFullRelay >= m_max_outbound_full_relay; | LOCK(cs_maxOutboundPeers); | ||||
block_relay_only = | |||||
nOutboundBlockRelay < m_max_outbound_block_relay && | |||||
!fFeeler && nOutboundFullRelay >= m_max_outbound_full_relay; | |||||
} | |||||
OpenNetworkConnection( | OpenNetworkConnection( | ||||
addrConnect, | addrConnect, | ||||
int(setConnected.size()) >= std::min(nMaxConnections - 1, 2), | int(setConnected.size()) >= std::min(nMaxConnections - 1, 2), | ||||
&grant, nullptr, false, fFeeler, false, block_relay_only); | &grant, nullptr, false, fFeeler, false, block_relay_only); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,028 Lines • Show Last 20 Lines |