@@ -1721,11 +1721,17 @@ void CConnman::ThreadOpenConnections()
1721
1721
// Only connect out to one peer per network group (/16 for IPv4).
1722
1722
// Do this here so we don't have to critsect vNodes inside mapAddresses critsect.
1723
1723
int nOutbound = 0 ;
1724
+ int nOutboundRelevant = 0 ;
1724
1725
std::set<std::vector<unsigned char > > setConnected;
1725
1726
{
1726
1727
LOCK (cs_vNodes);
1727
1728
BOOST_FOREACH (CNode* pnode, vNodes) {
1728
1729
if (!pnode->fInbound && !pnode->fAddnode ) {
1730
+
1731
+ // Count the peers that have all relevant services
1732
+ if (pnode->fSuccessfullyConnected && !pnode->fFeeler && ((pnode->nServices & nRelevantServices) == nRelevantServices)) {
1733
+ nOutboundRelevant++;
1734
+ }
1729
1735
// Netgroups for inbound and addnode peers are not excluded because our goal here
1730
1736
// is to not use multiple of our limited outbound slots on a single netgroup
1731
1737
// but inbound and addnode peers do not use our outbound slots. Inbound peers
@@ -1789,14 +1795,27 @@ void CConnman::ThreadOpenConnections()
1789
1795
continue ;
1790
1796
1791
1797
// only consider nodes missing relevant services after 40 failed attempts and only if less than half the outbound are up.
1792
- if ((addr.nServices & nRelevantServices) != nRelevantServices && (nTries < 40 || nOutbound >= (nMaxOutbound >> 1 )))
1798
+ ServiceFlags nRequiredServices = nRelevantServices;
1799
+ if (nTries >= 40 && nOutbound < (nMaxOutbound >> 1 )) {
1800
+ nRequiredServices = REQUIRED_SERVICES;
1801
+ }
1802
+
1803
+ if ((addr.nServices & nRequiredServices) != nRequiredServices) {
1793
1804
continue ;
1805
+ }
1794
1806
1795
1807
// do not allow non-default ports, unless after 50 invalid addresses selected already
1796
1808
if (addr.GetPort () != Params ().GetDefaultPort () && nTries < 50 )
1797
1809
continue ;
1798
1810
1799
1811
addrConnect = addr;
1812
+
1813
+ // regardless of the services assumed to be available, only require the minimum if half or more outbound have relevant services
1814
+ if (nOutboundRelevant >= (nMaxOutbound >> 1 )) {
1815
+ addrConnect.nServices = REQUIRED_SERVICES;
1816
+ } else {
1817
+ addrConnect.nServices = nRequiredServices;
1818
+ }
1800
1819
break ;
1801
1820
}
1802
1821
0 commit comments