Skip required services and port checks when outgoing connections is a MN (#2847)

* Skip required services and port checks when outgoing connections is a MN

* Only relax default port check when AllowMultiplePorts is true

Co-Authored-By: codablock <ablock84@gmail.com>
This commit is contained in:
Alexander Block 2019-04-10 18:14:20 +02:00 committed by GitHub
parent 2f8440696f
commit 27b2cd2cca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1875,12 +1875,16 @@ void CConnman::ThreadOpenConnections()
}
}
auto mnList = deterministicMNManager->GetListAtChainTip();
int64_t nANow = GetAdjustedTime();
int nTries = 0;
while (!interruptNet)
{
CAddrInfo addr = addrman.Select(fFeeler);
bool isMasternode = mnList.GetValidMNByService(addr) != nullptr;
// if we selected an invalid address, restart
if (!addr.IsValid() || setConnected.count(addr.GetGroup()))
break;
@ -1901,7 +1905,7 @@ void CConnman::ThreadOpenConnections()
continue;
// only connect to full nodes
if ((addr.nServices & REQUIRED_SERVICES) != REQUIRED_SERVICES)
if (!isMasternode && (addr.nServices & REQUIRED_SERVICES) != REQUIRED_SERVICES)
continue;
// only consider very recently tried nodes after 30 failed attempts
@ -1914,12 +1918,12 @@ void CConnman::ThreadOpenConnections()
nRequiredServices = REQUIRED_SERVICES;
}
if ((addr.nServices & nRequiredServices) != nRequiredServices) {
if (!isMasternode && (addr.nServices & nRequiredServices) != nRequiredServices) {
continue;
}
// do not allow non-default ports, unless after 50 invalid addresses selected already
if (addr.GetPort() != Params().GetDefaultPort() && addr.GetPort() != GetListenPort() && nTries < 50)
if ((!isMasternode || !Params().AllowMultiplePorts()) && addr.GetPort() != Params().GetDefaultPort() && addr.GetPort() != GetListenPort() && nTries < 50)
continue;
addrConnect = addr;