Changeset View
Changeset View
Standalone View
Standalone View
src/net.cpp
| Show First 20 Lines • Show All 1,905 Lines • ▼ Show 20 Lines | while (!interruptNet) { | ||||
| ConnectionType conn_type = ConnectionType::OUTBOUND_FULL_RELAY; | ConnectionType conn_type = ConnectionType::OUTBOUND_FULL_RELAY; | ||||
| auto now = GetTime<std::chrono::microseconds>(); | auto now = GetTime<std::chrono::microseconds>(); | ||||
| bool anchor = false; | 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 | ||||
| // BLOCK_RELAY connections to addresses from anchors.dat gets the | // BLOCK_RELAY connections to addresses from anchors.dat gets the | ||||
| // highest priority. Then we open AVALANCHE_OUTBOUND connection until we | // highest priority. Then we open AVALANCHE_OUTBOUND connections only | ||||
| // hit our avalanche outbound peer limit, which is 0 if avalanche is not | // until we hit our avalanche outbound peer limit (which is 0 if | ||||
| // enabled. We fallback after 50 retries to OUTBOUND_FULL_RELAY if the | // avalanche is not enabled) or we have a quorum established. | ||||
| // peer is not avalanche capable until we meet our full-relay capacity. | // We fallback after 20 retries to OUTBOUND_FULL_RELAY if the peer is | ||||
| // not avalanche capable until we meet our full-relay capacity. | |||||
| // After the quorum is established, we open 50% avalanche, 50% | |||||
| // full-relay outbound peers (randomly) if there are available slots | |||||
| // remaining. | |||||
| // Then we open BLOCK_RELAY connection until we hit our block-relay-only | // Then we open BLOCK_RELAY connection until we hit our block-relay-only | ||||
| // peer limit. | // 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 to see if it's time to try an extra | // these conditions are met, check to see if it's time to try an extra | ||||
| // block-relay-only peer (to confirm our tip is current, see below) or | // block-relay-only peer (to confirm our tip is current, see below) or | ||||
| // the next_feeler timer to decide if we should open a FEELER. | // the next_feeler timer to decide if we should open a FEELER. | ||||
| if (!m_anchors.empty() && | if (!m_anchors.empty() && | ||||
| (nOutboundBlockRelay < m_max_outbound_block_relay)) { | (nOutboundBlockRelay < m_max_outbound_block_relay)) { | ||||
| conn_type = ConnectionType::BLOCK_RELAY; | conn_type = ConnectionType::BLOCK_RELAY; | ||||
| anchor = true; | anchor = true; | ||||
| } else if (nOutboundAvalanche < m_max_avalanche_outbound && | |||||
| nOutboundFullRelay < m_max_outbound_full_relay) { | |||||
| // We have room for both avalanche and full-relay outbound peers. | |||||
| // We select: | |||||
| // - Avalanche while the quorum is not established yet | |||||
| // - 50% avalanche, 50% full-relay otherwise | |||||
| conn_type = !m_quorum_established | |||||
| ? ConnectionType::AVALANCHE_OUTBOUND | |||||
| : rng.randbool() ? ConnectionType::AVALANCHE_OUTBOUND | |||||
| : ConnectionType::OUTBOUND_FULL_RELAY; | |||||
| } else if (nOutboundAvalanche < m_max_avalanche_outbound) { | } else if (nOutboundAvalanche < m_max_avalanche_outbound) { | ||||
| conn_type = ConnectionType::AVALANCHE_OUTBOUND; | conn_type = ConnectionType::AVALANCHE_OUTBOUND; | ||||
| } else if (nOutboundFullRelay < m_max_outbound_full_relay) { | } 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 | ||||
| ▲ Show 20 Lines • Show All 1,371 Lines • Show Last 20 Lines | |||||