Skip to content

Commit e4e3b44

Browse files
committed
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.
1 parent 829becd commit e4e3b44

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/net.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2692,6 +2692,8 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect, Spa
26922692

26932693
const auto current_time{NodeClock::now()};
26942694
int nTries = 0;
2695+
const auto reachable_nets{g_reachable_nets.All()};
2696+
26952697
while (!interruptNet)
26962698
{
26972699
if (anchor && !m_anchors.empty()) {
@@ -2723,7 +2725,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect, Spa
27232725
if (!addr.IsValid()) {
27242726
// No tried table collisions. Select a new table address
27252727
// for our feeler.
2726-
std::tie(addr, addr_last_try) = addrman.Select(true);
2728+
std::tie(addr, addr_last_try) = addrman.Select(true, reachable_nets);
27272729
} else if (AlreadyConnectedToAddress(addr)) {
27282730
// If test-before-evict logic would have us connect to a
27292731
// peer that we're already connected to, just mark that
@@ -2732,18 +2734,16 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect, Spa
27322734
// a currently-connected peer.
27332735
addrman.Good(addr);
27342736
// Select a new table address for our feeler instead.
2735-
std::tie(addr, addr_last_try) = addrman.Select(true);
2737+
std::tie(addr, addr_last_try) = addrman.Select(true, reachable_nets);
27362738
}
27372739
} else {
27382740
// Not a feeler
27392741
// If preferred_net has a value set, pick an extra outbound
27402742
// peer from that network. The eviction logic in net_processing
27412743
// ensures that a peer from another network will be evicted.
2742-
std::unordered_set<Network> preferred_nets;
2743-
if (preferred_net.has_value()) {
2744-
preferred_nets = {*preferred_net};
2745-
}
2746-
std::tie(addr, addr_last_try) = addrman.Select(false, preferred_nets);
2744+
std::tie(addr, addr_last_try) = preferred_net.has_value()
2745+
? addrman.Select(false, {*preferred_net})
2746+
: addrman.Select(false, reachable_nets);
27472747
}
27482748

27492749
// Require outbound IPv4/IPv6 connections, other than feelers, to be to distinct network groups

0 commit comments

Comments
 (0)