Skip to content

Commit

Permalink
Skip required services and port checks when outgoing connections is a…
Browse files Browse the repository at this point in the history
… 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>
  • Loading branch information
codablock committed Apr 10, 2019
1 parent 2f84406 commit 27b2cd2
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit 27b2cd2

Please sign in to comment.