mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 13:03:17 +01:00
Merge #10441: net: only enforce expected services for half of outgoing connections
b6fbfc2
net: only enforce the services required to connect (Cory Fields)
Tree-SHA512: 88943bff63213a734f3c96c45760cadaeb9ba18287c8a20c279851ebaf058a334c969028fb2180f155508e3eea4b838147382e4f2b655e7a9aa098eadc81d53e
This commit is contained in:
parent
785d4d0ee5
commit
c716ee03f1
21
src/net.cpp
21
src/net.cpp
@ -1735,11 +1735,17 @@ void CConnman::ThreadOpenConnections()
|
|||||||
// Do this here so we don't have to critsect vNodes inside mapAddresses critsect.
|
// Do this here so we don't have to critsect vNodes inside mapAddresses critsect.
|
||||||
// This is only done for mainnet and testnet
|
// This is only done for mainnet and testnet
|
||||||
int nOutbound = 0;
|
int nOutbound = 0;
|
||||||
|
int nOutboundRelevant = 0;
|
||||||
std::set<std::vector<unsigned char> > setConnected;
|
std::set<std::vector<unsigned char> > setConnected;
|
||||||
if (!Params().AllowMultipleAddressesFromGroup()) {
|
if (!Params().AllowMultipleAddressesFromGroup()) {
|
||||||
LOCK(cs_vNodes);
|
LOCK(cs_vNodes);
|
||||||
BOOST_FOREACH(CNode* pnode, vNodes) {
|
BOOST_FOREACH(CNode* pnode, vNodes) {
|
||||||
if (!pnode->fInbound && !pnode->fAddnode && !pnode->fMasternode) {
|
if (!pnode->fInbound && !pnode->fAddnode && !pnode->fMasternode) {
|
||||||
|
|
||||||
|
// 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
|
// 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
|
// 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
|
// but inbound and addnode peers do not use our outbound slots. Inbound peers
|
||||||
@ -1803,14 +1809,27 @@ void CConnman::ThreadOpenConnections()
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
// only consider nodes missing relevant services after 40 failed attempts and only if less than half the outbound are up.
|
// 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;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// do not allow non-default ports, unless after 50 invalid addresses selected already
|
// do not allow non-default ports, unless after 50 invalid addresses selected already
|
||||||
if (addr.GetPort() != Params().GetDefaultPort() && nTries < 50)
|
if (addr.GetPort() != Params().GetDefaultPort() && nTries < 50)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
addrConnect = addr;
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user