mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
net: call Select
with reachable networks in ThreadOpenConnections
Calling `Select` with reachable networks can avoid unecessary calls and avoid exceed the max number of tries.
This commit is contained in:
parent
829becd990
commit
e4e3b44e9c
1 changed files with 7 additions and 7 deletions
14
src/net.cpp
14
src/net.cpp
|
@ -2692,6 +2692,8 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect, Spa
|
||||||
|
|
||||||
const auto current_time{NodeClock::now()};
|
const auto current_time{NodeClock::now()};
|
||||||
int nTries = 0;
|
int nTries = 0;
|
||||||
|
const auto reachable_nets{g_reachable_nets.All()};
|
||||||
|
|
||||||
while (!interruptNet)
|
while (!interruptNet)
|
||||||
{
|
{
|
||||||
if (anchor && !m_anchors.empty()) {
|
if (anchor && !m_anchors.empty()) {
|
||||||
|
@ -2723,7 +2725,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect, Spa
|
||||||
if (!addr.IsValid()) {
|
if (!addr.IsValid()) {
|
||||||
// No tried table collisions. Select a new table address
|
// No tried table collisions. Select a new table address
|
||||||
// for our feeler.
|
// for our feeler.
|
||||||
std::tie(addr, addr_last_try) = addrman.Select(true);
|
std::tie(addr, addr_last_try) = addrman.Select(true, reachable_nets);
|
||||||
} else if (AlreadyConnectedToAddress(addr)) {
|
} else if (AlreadyConnectedToAddress(addr)) {
|
||||||
// If test-before-evict logic would have us connect to a
|
// If test-before-evict logic would have us connect to a
|
||||||
// peer that we're already connected to, just mark that
|
// peer that we're already connected to, just mark that
|
||||||
|
@ -2732,18 +2734,16 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect, Spa
|
||||||
// a currently-connected peer.
|
// a currently-connected peer.
|
||||||
addrman.Good(addr);
|
addrman.Good(addr);
|
||||||
// Select a new table address for our feeler instead.
|
// Select a new table address for our feeler instead.
|
||||||
std::tie(addr, addr_last_try) = addrman.Select(true);
|
std::tie(addr, addr_last_try) = addrman.Select(true, reachable_nets);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Not a feeler
|
// Not a feeler
|
||||||
// If preferred_net has a value set, pick an extra outbound
|
// If preferred_net has a value set, pick an extra outbound
|
||||||
// peer from that network. The eviction logic in net_processing
|
// peer from that network. The eviction logic in net_processing
|
||||||
// ensures that a peer from another network will be evicted.
|
// ensures that a peer from another network will be evicted.
|
||||||
std::unordered_set<Network> preferred_nets;
|
std::tie(addr, addr_last_try) = preferred_net.has_value()
|
||||||
if (preferred_net.has_value()) {
|
? addrman.Select(false, {*preferred_net})
|
||||||
preferred_nets = {*preferred_net};
|
: addrman.Select(false, reachable_nets);
|
||||||
}
|
|
||||||
std::tie(addr, addr_last_try) = addrman.Select(false, preferred_nets);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Require outbound IPv4/IPv6 connections, other than feelers, to be to distinct network groups
|
// Require outbound IPv4/IPv6 connections, other than feelers, to be to distinct network groups
|
||||||
|
|
Loading…
Add table
Reference in a new issue