mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-05 14:06:27 -05:00
p2p: Try to connect to anchors once
This commit is contained in:
parent
5543c7ab28
commit
0a85e5a7bc
2 changed files with 21 additions and 3 deletions
20
src/net.cpp
20
src/net.cpp
|
@ -1930,10 +1930,12 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
|
||||||
|
|
||||||
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
|
||||||
|
@ -1941,7 +1943,10 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
|
||||||
// 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;
|
||||||
|
@ -1962,6 +1967,17 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
|
||||||
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 addresses fetched from addrman,
|
// If we didn't find an appropriate destination after trying 100 addresses fetched from addrman,
|
||||||
// stop this loop, and let the outer loop run again (which sleeps, adds seed nodes, recalculates
|
// stop this loop, and let the outer loop run again (which sleeps, adds seed nodes, recalculates
|
||||||
// already-connected network ranges, ...) before trying new addrman addresses.
|
// already-connected network ranges, ...) before trying new addrman addresses.
|
||||||
|
|
|
@ -174,7 +174,9 @@ enum class ConnectionType {
|
||||||
* attacks. By not relaying transactions or addresses, these connections
|
* attacks. By not relaying transactions or addresses, these connections
|
||||||
* are harder to detect by a third party, thus helping obfuscate the
|
* are harder to detect by a third party, thus helping obfuscate the
|
||||||
* network topology. We automatically attempt to open
|
* network topology. We automatically attempt to open
|
||||||
* MAX_BLOCK_RELAY_ONLY_CONNECTIONS using addresses from our AddrMan.
|
* MAX_BLOCK_RELAY_ONLY_ANCHORS using addresses from our anchors.dat. Then
|
||||||
|
* addresses from our AddrMan if MAX_BLOCK_RELAY_ONLY_CONNECTIONS
|
||||||
|
* isn't reached yet.
|
||||||
*/
|
*/
|
||||||
BLOCK_RELAY,
|
BLOCK_RELAY,
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue