Skip to content

Commit 456af7a

Browse files
committed
Merge bitcoin/bitcoin#27467: p2p: skip netgroup diversity follow-up
11bb31c p2p: "skip netgroup diversity of new connections for tor/i2p/cjdns" follow-up (Jon Atack) Pull request description: In #27374 the role of the `setConnected` data structure in `CConnman::ThreadOpenConnections` changed from the set of outbound peer netgroups to those of outbound IPv4/6 peers only. In accordance with the changed semantics, this pull fixes a code comment regarding feeler connections and updates the naming of `setConnected` to `outbound_ipv46_peer_netgroups`. Addresses bitcoin/bitcoin#27374 (comment). ACKs for top commit: mzumsande: Code Review ACK 11bb31c vasild: ACK 11bb31c ryanofsky: Code review ACK 11bb31c Tree-SHA512: df9151a6cce53c279e549683a9f30fdc23d513dc664cfee1cf0eb8ec80b2848d32c80a92cc0a9f47d967f305864975ffb339fe0eaa80bc3bef1b28406419eb96
2 parents a36134f + 11bb31c commit 456af7a

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/net.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,7 +1703,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
17031703
int nOutboundFullRelay = 0;
17041704
int nOutboundBlockRelay = 0;
17051705
int outbound_privacy_network_peers = 0;
1706-
std::set<std::vector<unsigned char>> setConnected; // netgroups of our ipv4/ipv6 outbound peers
1706+
std::set<std::vector<unsigned char>> outbound_ipv46_peer_netgroups;
17071707

17081708
{
17091709
LOCK(m_nodes_mutex);
@@ -1725,7 +1725,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
17251725
case ConnectionType::MANUAL:
17261726
case ConnectionType::OUTBOUND_FULL_RELAY:
17271727
case ConnectionType::BLOCK_RELAY:
1728-
CAddress address{pnode->addr};
1728+
const CAddress address{pnode->addr};
17291729
if (address.IsTor() || address.IsI2P() || address.IsCJDNS()) {
17301730
// Since our addrman-groups for these networks are
17311731
// random, without relation to the route we
@@ -1736,7 +1736,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
17361736
// these networks.
17371737
++outbound_privacy_network_peers;
17381738
} else {
1739-
setConnected.insert(m_netgroupman.GetGroup(address));
1739+
outbound_ipv46_peer_netgroups.insert(m_netgroupman.GetGroup(address));
17401740
}
17411741
} // no default case, so the compiler can warn about missing cases
17421742
}
@@ -1811,7 +1811,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
18111811
m_anchors.pop_back();
18121812
if (!addr.IsValid() || IsLocal(addr) || !IsReachable(addr) ||
18131813
!HasAllDesirableServiceFlags(addr.nServices) ||
1814-
setConnected.count(m_netgroupman.GetGroup(addr))) continue;
1814+
outbound_ipv46_peer_netgroups.count(m_netgroupman.GetGroup(addr))) continue;
18151815
addrConnect = addr;
18161816
LogPrint(BCLog::NET, "Trying to make an anchor connection to %s\n", addrConnect.ToStringAddrPort());
18171817
break;
@@ -1851,8 +1851,8 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
18511851
std::tie(addr, addr_last_try) = addrman.Select();
18521852
}
18531853

1854-
// Require outbound connections, other than feelers, to be to distinct network groups
1855-
if (!fFeeler && setConnected.count(m_netgroupman.GetGroup(addr))) {
1854+
// Require outbound IPv4/IPv6 connections, other than feelers, to be to distinct network groups
1855+
if (!fFeeler && outbound_ipv46_peer_netgroups.count(m_netgroupman.GetGroup(addr))) {
18561856
break;
18571857
}
18581858

@@ -1898,8 +1898,9 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
18981898
// Record addrman failure attempts when node has at least 2 persistent outbound connections to peers with
18991899
// different netgroups in ipv4/ipv6 networks + all peers in Tor/I2P/CJDNS networks.
19001900
// Don't record addrman failure attempts when node is offline. This can be identified since all local
1901-
// network connections(if any) belong in the same netgroup and size of setConnected would only be 1.
1902-
OpenNetworkConnection(addrConnect, (int)setConnected.size() + outbound_privacy_network_peers >= std::min(nMaxConnections - 1, 2), &grant, nullptr, conn_type);
1901+
// network connections (if any) belong in the same netgroup, and the size of `outbound_ipv46_peer_netgroups` would only be 1.
1902+
const bool count_failures{((int)outbound_ipv46_peer_netgroups.size() + outbound_privacy_network_peers) >= std::min(nMaxConnections - 1, 2)};
1903+
OpenNetworkConnection(addrConnect, count_failures, &grant, /*strDest=*/nullptr, conn_type);
19031904
}
19041905
}
19051906
}

0 commit comments

Comments
 (0)