@@ -1703,18 +1703,19 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
1703
1703
//
1704
1704
CAddress addrConnect;
1705
1705
1706
- // Only connect out to one peer per network group (/16 for IPv4).
1706
+ // Only connect out to one peer per ipv4/ipv6 network group (/16 for IPv4).
1707
1707
int nOutboundFullRelay = 0 ;
1708
1708
int nOutboundBlockRelay = 0 ;
1709
- std::set<std::vector<unsigned char > > setConnected;
1709
+ int outbound_privacy_network_peers = 0 ;
1710
+ std::set<std::vector<unsigned char >> setConnected; // netgroups of our ipv4/ipv6 outbound peers
1710
1711
1711
1712
{
1712
1713
LOCK (m_nodes_mutex);
1713
1714
for (const CNode* pnode : m_nodes) {
1714
1715
if (pnode->IsFullOutboundConn ()) nOutboundFullRelay++;
1715
1716
if (pnode->IsBlockOnlyConn ()) nOutboundBlockRelay++;
1716
1717
1717
- // Make sure our persistent outbound slots belong to different netgroups.
1718
+ // Make sure our persistent outbound slots to ipv4/ipv6 peers belong to different netgroups.
1718
1719
switch (pnode->m_conn_type ) {
1719
1720
// We currently don't take inbound connections into account. Since they are
1720
1721
// free to make, an attacker could make them to prevent us from connecting to
@@ -1728,7 +1729,19 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
1728
1729
case ConnectionType::MANUAL:
1729
1730
case ConnectionType::OUTBOUND_FULL_RELAY:
1730
1731
case ConnectionType::BLOCK_RELAY:
1731
- setConnected.insert (m_netgroupman.GetGroup (pnode->addr ));
1732
+ CAddress address{pnode->addr };
1733
+ if (address.IsTor () || address.IsI2P () || address.IsCJDNS ()) {
1734
+ // Since our addrman-groups for these networks are
1735
+ // random, without relation to the route we
1736
+ // take to connect to these peers or to the
1737
+ // difficulty in obtaining addresses with diverse
1738
+ // groups, we don't worry about diversity with
1739
+ // respect to our addrman groups when connecting to
1740
+ // these networks.
1741
+ ++outbound_privacy_network_peers;
1742
+ } else {
1743
+ setConnected.insert (m_netgroupman.GetGroup (address));
1744
+ }
1732
1745
} // no default case, so the compiler can warn about missing cases
1733
1746
}
1734
1747
}
@@ -1886,8 +1899,11 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
1886
1899
}
1887
1900
LogPrint (BCLog::NET, " Making feeler connection to %s\n " , addrConnect.ToStringAddrPort ());
1888
1901
}
1889
-
1890
- OpenNetworkConnection (addrConnect, (int )setConnected.size () >= std::min (nMaxConnections - 1 , 2 ), &grant, nullptr , conn_type);
1902
+ // Record addrman failure attempts when node has at least 2 persistent outbound connections to peers with
1903
+ // different netgroups in ipv4/ipv6 networks + all peers in Tor/I2P/CJDNS networks.
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);
1891
1907
}
1892
1908
}
1893
1909
}
0 commit comments