mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-03 20:35:17 +02:00
Merge bitcoin/bitcoin#29436: net: call Select with reachable networks in ThreadOpenConnections
e4e3b44e9cnet: call `Select` with reachable networks in `ThreadOpenConnections` (brunoerg)829becd990addrman: change `Select` to support multiple networks (brunoerg)f698636ec8net: add `All()` in `ReachableNets` (brunoerg) Pull request description: This PR changes addrman's `Select` to support multiple networks and change `ThreadOpenConnections` to call it with reachable networks. It can avoid unnecessary `Select` calls and avoid exceeding the max number of tries (100), especially when turning a clearnet + Tor/I2P/CJDNS node to Tor/I2P/CJDNS. Compared to #29330, this approach is "less aggresive". It does not add a new init flag and does not impact address relay. I did an experiment of calling `Select` without passing a network until it finds an address from a network that compose 20% ~ 25% of the addrman (limited to 100 tries).  ACKs for top commit: achow101: ACKe4e3b44e9cvasild: ACKe4e3b44e9cnaumenkogs: ACKe4e3b44e9cTree-SHA512: e8466b72b85bbc2ad8bfb14471eb27d2c50d4e84218f5ede2c15a6fa3653af61b488cde492dbd398f7502bd847e95bfee1abb7e01092daba2236d3ce3d6d2268
This commit is contained in:
10
src/net.cpp
10
src/net.cpp
@@ -2693,6 +2693,8 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect, Spa
|
||||
|
||||
const auto current_time{NodeClock::now()};
|
||||
int nTries = 0;
|
||||
const auto reachable_nets{g_reachable_nets.All()};
|
||||
|
||||
while (!interruptNet)
|
||||
{
|
||||
if (anchor && !m_anchors.empty()) {
|
||||
@@ -2724,7 +2726,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect, Spa
|
||||
if (!addr.IsValid()) {
|
||||
// No tried table collisions. Select a new table address
|
||||
// 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)) {
|
||||
// If test-before-evict logic would have us connect to a
|
||||
// peer that we're already connected to, just mark that
|
||||
@@ -2733,14 +2735,16 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect, Spa
|
||||
// a currently-connected peer.
|
||||
addrman.Good(addr);
|
||||
// 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 {
|
||||
// Not a feeler
|
||||
// If preferred_net has a value set, pick an extra outbound
|
||||
// peer from that network. The eviction logic in net_processing
|
||||
// ensures that a peer from another network will be evicted.
|
||||
std::tie(addr, addr_last_try) = addrman.Select(false, preferred_net);
|
||||
std::tie(addr, addr_last_try) = preferred_net.has_value()
|
||||
? addrman.Select(false, {*preferred_net})
|
||||
: addrman.Select(false, reachable_nets);
|
||||
}
|
||||
|
||||
// Require outbound IPv4/IPv6 connections, other than feelers, to be to distinct network groups
|
||||
|
||||
Reference in New Issue
Block a user