Changeset View
Changeset View
Standalone View
Standalone View
src/net.cpp
Show First 20 Lines • Show All 2,061 Lines • ▼ Show 20 Lines | while (!interruptNet) { | ||||
case ConnectionType::ADDR_FETCH: | case ConnectionType::ADDR_FETCH: | ||||
case ConnectionType::FEELER: | case ConnectionType::FEELER: | ||||
setConnected.insert( | setConnected.insert( | ||||
pnode->addr.GetGroup(addrman.m_asmap)); | pnode->addr.GetGroup(addrman.m_asmap)); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// Feeler Connections | ConnectionType conn_type = ConnectionType::OUTBOUND_FULL_RELAY; | ||||
// | int64_t nTime = GetTimeMicros(); | ||||
// Design goals: | |||||
// * Increase the number of connectable addresses in the tried table. | |||||
// | |||||
// Method: | |||||
// * Choose a random address from new and attempt to connect to it if | |||||
// we can connect successfully it is added to tried. | |||||
// * Start attempting feeler connections only after node finishes | |||||
// making outbound connections. | |||||
// * Only make a feeler connection once every few minutes. | |||||
// | |||||
bool fFeeler = false; | bool fFeeler = false; | ||||
if (nOutboundFullRelay >= m_max_outbound_full_relay && | // Determine what type of connection to open. Opening | ||||
nOutboundBlockRelay >= m_max_outbound_block_relay && | // OUTBOUND_FULL_RELAY connections gets the highest priority until we | ||||
!GetTryNewOutboundPeer()) { | // meet our full-relay capacity. Then we open BLOCK_RELAY connection | ||||
// The current time right now (in microseconds). | // until we hit our block-relay-only peer limit. | ||||
int64_t nTime = GetTimeMicros(); | // GetTryNewOutboundPeer() gets set when a stale tip is detected, so we | ||||
if (nTime > nNextFeeler) { | // try opening an additional OUTBOUND_FULL_RELAY connection. If none of | ||||
// these conditions are met, check the nNextFeeler timer to decide if | |||||
// we should open a FEELER. | |||||
if (nOutboundFullRelay < m_max_outbound_full_relay) { | |||||
// OUTBOUND_FULL_RELAY | |||||
} else if (nOutboundBlockRelay < m_max_outbound_block_relay) { | |||||
conn_type = ConnectionType::BLOCK_RELAY; | |||||
} else if (GetTryNewOutboundPeer()) { | |||||
// OUTBOUND_FULL_RELAY | |||||
} else if (nTime > nNextFeeler) { | |||||
nNextFeeler = PoissonNextSend(nTime, FEELER_INTERVAL); | nNextFeeler = PoissonNextSend(nTime, FEELER_INTERVAL); | ||||
conn_type = ConnectionType::FEELER; | |||||
fFeeler = true; | fFeeler = true; | ||||
} else { | } else { | ||||
// 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) { | ||||
CAddrInfo addr = addrman.SelectTriedCollision(); | CAddrInfo addr = addrman.SelectTriedCollision(); | ||||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | while (!interruptNet) { | ||||
if (!interruptNet.sleep_for( | if (!interruptNet.sleep_for( | ||||
std::chrono::milliseconds(randsleep))) { | std::chrono::milliseconds(randsleep))) { | ||||
return; | return; | ||||
} | } | ||||
LogPrint(BCLog::NET, "Making feeler connection to %s\n", | LogPrint(BCLog::NET, "Making feeler connection to %s\n", | ||||
addrConnect.ToString()); | addrConnect.ToString()); | ||||
} | } | ||||
ConnectionType conn_type; | |||||
// Determine what type of connection to open. If fFeeler is not | |||||
// set, open OUTBOUND connections until we meet our full-relay | |||||
// capacity. Then open BLOCK_RELAY connections until we hit our | |||||
// block-relay peer limit. Otherwise, default to opening an | |||||
// OUTBOUND connection. | |||||
if (fFeeler) { | |||||
conn_type = ConnectionType::FEELER; | |||||
} else if (nOutboundFullRelay < m_max_outbound_full_relay) { | |||||
conn_type = ConnectionType::OUTBOUND_FULL_RELAY; | |||||
} else if (nOutboundBlockRelay < m_max_outbound_block_relay) { | |||||
conn_type = ConnectionType::BLOCK_RELAY; | |||||
} else { | |||||
// GetTryNewOutboundPeer() is true | |||||
conn_type = ConnectionType::OUTBOUND_FULL_RELAY; | |||||
} | |||||
OpenNetworkConnection(addrConnect, | OpenNetworkConnection(addrConnect, | ||||
int(setConnected.size()) >= | int(setConnected.size()) >= | ||||
std::min(nMaxConnections - 1, 2), | std::min(nMaxConnections - 1, 2), | ||||
&grant, nullptr, conn_type); | &grant, nullptr, conn_type); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,027 Lines • Show Last 20 Lines |