Changeset View
Changeset View
Standalone View
Standalone View
src/net.cpp
Show First 20 Lines • Show All 2,157 Lines • ▼ Show 20 Lines | while (!interruptNet) { | ||||
pnode->addr.GetGroup(addrman.m_asmap)); | pnode->addr.GetGroup(addrman.m_asmap)); | ||||
} // no default case, so the compiler can warn about missing | } // no default case, so the compiler can warn about missing | ||||
// cases | // cases | ||||
} | } | ||||
} | } | ||||
ConnectionType conn_type = ConnectionType::OUTBOUND_FULL_RELAY; | ConnectionType conn_type = ConnectionType::OUTBOUND_FULL_RELAY; | ||||
int64_t nTime = GetTimeMicros(); | int64_t nTime = GetTimeMicros(); | ||||
bool anchor = false; | |||||
bool fFeeler = false; | bool fFeeler = false; | ||||
// Determine what type of connection to open. Opening | // Determine what type of connection to open. Opening | ||||
// OUTBOUND_FULL_RELAY connections gets the highest priority until we | // BLOCK_RELAY connections to addresses from anchors.dat gets the | ||||
// highest priority. Then we open OUTBOUND_FULL_RELAY priority until we | |||||
// meet our full-relay capacity. Then we open BLOCK_RELAY connection | // meet our full-relay capacity. Then we open BLOCK_RELAY connection | ||||
// until we hit our block-relay-only peer limit. | // until we hit our block-relay-only peer limit. | ||||
// GetTryNewOutboundPeer() gets set when a stale tip is detected, so we | // GetTryNewOutboundPeer() gets set when a stale tip is detected, so we | ||||
// try opening an additional OUTBOUND_FULL_RELAY connection. If none of | // try opening an additional OUTBOUND_FULL_RELAY connection. If none of | ||||
// these conditions are met, check the nNextFeeler timer to decide if | // these conditions are met, check the nNextFeeler timer to decide if | ||||
// we should open a FEELER. | // we should open a FEELER. | ||||
if (nOutboundFullRelay < m_max_outbound_full_relay) { | if (!m_anchors.empty() && | ||||
(nOutboundBlockRelay < m_max_outbound_block_relay)) { | |||||
conn_type = ConnectionType::BLOCK_RELAY; | |||||
anchor = true; | |||||
} else if (nOutboundFullRelay < m_max_outbound_full_relay) { | |||||
// OUTBOUND_FULL_RELAY | // OUTBOUND_FULL_RELAY | ||||
} else if (nOutboundBlockRelay < m_max_outbound_block_relay) { | } else if (nOutboundBlockRelay < m_max_outbound_block_relay) { | ||||
conn_type = ConnectionType::BLOCK_RELAY; | conn_type = ConnectionType::BLOCK_RELAY; | ||||
} else if (GetTryNewOutboundPeer()) { | } else if (GetTryNewOutboundPeer()) { | ||||
// OUTBOUND_FULL_RELAY | // OUTBOUND_FULL_RELAY | ||||
} else if (nTime > nNextFeeler) { | } else if (nTime > nNextFeeler) { | ||||
nNextFeeler = PoissonNextSend(nTime, FEELER_INTERVAL); | nNextFeeler = PoissonNextSend(nTime, FEELER_INTERVAL); | ||||
conn_type = ConnectionType::FEELER; | conn_type = ConnectionType::FEELER; | ||||
fFeeler = true; | fFeeler = true; | ||||
} else { | } else { | ||||
// skip to next iteration of while loop | // skip to next iteration of while loop | ||||
continue; | continue; | ||||
} | } | ||||
addrman.ResolveCollisions(); | addrman.ResolveCollisions(); | ||||
int64_t nANow = GetAdjustedTime(); | int64_t nANow = GetAdjustedTime(); | ||||
int nTries = 0; | int nTries = 0; | ||||
while (!interruptNet) { | while (!interruptNet) { | ||||
if (anchor && !m_anchors.empty()) { | |||||
const CAddress addr = m_anchors.back(); | |||||
m_anchors.pop_back(); | |||||
if (!addr.IsValid() || IsLocal(addr) || !IsReachable(addr) || | |||||
!HasAllDesirableServiceFlags(addr.nServices) || | |||||
setConnected.count(addr.GetGroup(addrman.m_asmap))) { | |||||
continue; | |||||
} | |||||
addrConnect = addr; | |||||
LogPrint(BCLog::NET, | |||||
"Trying to make an anchor connection to %s\n", | |||||
addrConnect.ToString()); | |||||
break; | |||||
} | |||||
// If we didn't find an appropriate destination after trying 100 | // If we didn't find an appropriate destination after trying 100 | ||||
// addresses fetched from addrman, stop this loop, and let the outer | // addresses fetched from addrman, stop this loop, and let the outer | ||||
// loop run again (which sleeps, adds seed nodes, recalculates | // loop run again (which sleeps, adds seed nodes, recalculates | ||||
// already-connected network ranges, ...) before trying new addrman | // already-connected network ranges, ...) before trying new addrman | ||||
// addresses. | // addresses. | ||||
nTries++; | nTries++; | ||||
if (nTries > 100) { | if (nTries > 100) { | ||||
break; | break; | ||||
▲ Show 20 Lines • Show All 1,237 Lines • Show Last 20 Lines |