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