diff options
author | Cory Fields <cory-nospam-@coryfields.com> | 2017-05-24 17:00:27 -0400 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2017-06-01 13:26:12 +0200 |
commit | 9e3ad500780b284765654cff4144451c7fa5ef6b (patch) | |
tree | 8cee6ffb24c10de5464e63597665626adbe7a300 | |
parent | ff3f9a807d46772646740714f87c7e77d1271678 (diff) |
net: only enforce the services required to connectv0.14.2rc1
also once half of all outgoing nodes have our preferred flags, require only
minimal flags from the rest.
Github-Pull: #10441
Rebased-From: b6fbfc228236947eaea5c14dda299f5a01810e92
-rw-r--r-- | src/net.cpp | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/net.cpp b/src/net.cpp index 2fca994748..1752c7707a 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1722,11 +1722,17 @@ void CConnman::ThreadOpenConnections() // Only connect out to one peer per network group (/16 for IPv4). // Do this here so we don't have to critsect vNodes inside mapAddresses critsect. int nOutbound = 0; + int nOutboundRelevant = 0; std::set<std::vector<unsigned char> > setConnected; { LOCK(cs_vNodes); BOOST_FOREACH(CNode* pnode, vNodes) { if (!pnode->fInbound && !pnode->fAddnode) { + + // Count the peers that have all relevant services + if (pnode->fSuccessfullyConnected && !pnode->fFeeler && ((pnode->nServices & nRelevantServices) == nRelevantServices)) { + nOutboundRelevant++; + } // Netgroups for inbound and addnode peers are not excluded because our goal here // is to not use multiple of our limited outbound slots on a single netgroup // but inbound and addnode peers do not use our outbound slots. Inbound peers @@ -1790,14 +1796,27 @@ void CConnman::ThreadOpenConnections() continue; // only consider nodes missing relevant services after 40 failed attempts and only if less than half the outbound are up. - if ((addr.nServices & nRelevantServices) != nRelevantServices && (nTries < 40 || nOutbound >= (nMaxOutbound >> 1))) + ServiceFlags nRequiredServices = nRelevantServices; + if (nTries >= 40 && nOutbound < (nMaxOutbound >> 1)) { + nRequiredServices = REQUIRED_SERVICES; + } + + if ((addr.nServices & nRequiredServices) != nRequiredServices) { continue; + } // do not allow non-default ports, unless after 50 invalid addresses selected already if (addr.GetPort() != Params().GetDefaultPort() && nTries < 50) continue; addrConnect = addr; + + // regardless of the services assumed to be available, only require the minimum if half or more outbound have relevant services + if (nOutboundRelevant >= (nMaxOutbound >> 1)) { + addrConnect.nServices = REQUIRED_SERVICES; + } else { + addrConnect.nServices = nRequiredServices; + } break; } |