p2p: "skip netgroup diversity of new connections for tor/i2p/cjdns" follow-up

In PR 27374, the semantics of the `setConnected` data structure in
CConnman::ThreadOpenConnections changed from the set of outbound peer
netgroups to those of outbound IPv4/6 peers only.

This commit updates a code comment in this regard about feeler connections and
updates the naming of `setConnected` to `outbound_ipv46_peer_netgroups` to
reflect its new role.
This commit is contained in:
Jon Atack
2023-04-14 11:01:43 -07:00
parent b5585ba5f9
commit 11bb31c1c4

View File

@@ -1707,7 +1707,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
int nOutboundFullRelay = 0; int nOutboundFullRelay = 0;
int nOutboundBlockRelay = 0; int nOutboundBlockRelay = 0;
int outbound_privacy_network_peers = 0; int outbound_privacy_network_peers = 0;
std::set<std::vector<unsigned char>> setConnected; // netgroups of our ipv4/ipv6 outbound peers std::set<std::vector<unsigned char>> outbound_ipv46_peer_netgroups;
{ {
LOCK(m_nodes_mutex); LOCK(m_nodes_mutex);
@@ -1729,7 +1729,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
case ConnectionType::MANUAL: case ConnectionType::MANUAL:
case ConnectionType::OUTBOUND_FULL_RELAY: case ConnectionType::OUTBOUND_FULL_RELAY:
case ConnectionType::BLOCK_RELAY: case ConnectionType::BLOCK_RELAY:
CAddress address{pnode->addr}; const CAddress address{pnode->addr};
if (address.IsTor() || address.IsI2P() || address.IsCJDNS()) { if (address.IsTor() || address.IsI2P() || address.IsCJDNS()) {
// Since our addrman-groups for these networks are // Since our addrman-groups for these networks are
// random, without relation to the route we // random, without relation to the route we
@@ -1740,7 +1740,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
// these networks. // these networks.
++outbound_privacy_network_peers; ++outbound_privacy_network_peers;
} else { } else {
setConnected.insert(m_netgroupman.GetGroup(address)); outbound_ipv46_peer_netgroups.insert(m_netgroupman.GetGroup(address));
} }
} // no default case, so the compiler can warn about missing cases } // no default case, so the compiler can warn about missing cases
} }
@@ -1815,7 +1815,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
m_anchors.pop_back(); m_anchors.pop_back();
if (!addr.IsValid() || IsLocal(addr) || !IsReachable(addr) || if (!addr.IsValid() || IsLocal(addr) || !IsReachable(addr) ||
!HasAllDesirableServiceFlags(addr.nServices) || !HasAllDesirableServiceFlags(addr.nServices) ||
setConnected.count(m_netgroupman.GetGroup(addr))) continue; outbound_ipv46_peer_netgroups.count(m_netgroupman.GetGroup(addr))) continue;
addrConnect = addr; addrConnect = addr;
LogPrint(BCLog::NET, "Trying to make an anchor connection to %s\n", addrConnect.ToStringAddrPort()); LogPrint(BCLog::NET, "Trying to make an anchor connection to %s\n", addrConnect.ToStringAddrPort());
break; break;
@@ -1855,8 +1855,8 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
std::tie(addr, addr_last_try) = addrman.Select(); std::tie(addr, addr_last_try) = addrman.Select();
} }
// Require outbound connections, other than feelers, to be to distinct network groups // Require outbound IPv4/IPv6 connections, other than feelers, to be to distinct network groups
if (!fFeeler && setConnected.count(m_netgroupman.GetGroup(addr))) { if (!fFeeler && outbound_ipv46_peer_netgroups.count(m_netgroupman.GetGroup(addr))) {
break; break;
} }
@@ -1902,8 +1902,9 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
// Record addrman failure attempts when node has at least 2 persistent outbound connections to peers with // Record addrman failure attempts when node has at least 2 persistent outbound connections to peers with
// different netgroups in ipv4/ipv6 networks + all peers in Tor/I2P/CJDNS networks. // different netgroups in ipv4/ipv6 networks + all peers in Tor/I2P/CJDNS networks.
// Don't record addrman failure attempts when node is offline. This can be identified since all local // Don't record addrman failure attempts when node is offline. This can be identified since all local
// network connections(if any) belong in the same netgroup and size of setConnected would only be 1. // network connections (if any) belong in the same netgroup, and the size of `outbound_ipv46_peer_netgroups` would only be 1.
OpenNetworkConnection(addrConnect, (int)setConnected.size() + outbound_privacy_network_peers >= std::min(nMaxConnections - 1, 2), &grant, nullptr, conn_type); const bool count_failures{((int)outbound_ipv46_peer_netgroups.size() + outbound_privacy_network_peers) >= std::min(nMaxConnections - 1, 2)};
OpenNetworkConnection(addrConnect, count_failures, &grant, /*strDest=*/nullptr, conn_type);
} }
} }
} }