Back off for 1m when connecting to quorum masternodes (#2975)

* Implement GetAddressInfo in CAddrMan

* Back off for 1m when connecting to quorum masternodes
This commit is contained in:
Alexander Block 2019-06-21 11:24:14 +02:00
parent c1f756fd90
commit 49c37b82ae
3 changed files with 39 additions and 0 deletions

View File

@ -533,6 +533,23 @@ void CAddrMan::SetServices_(const CService& addr, ServiceFlags nServices)
info.nServices = nServices; info.nServices = nServices;
} }
CAddrInfo CAddrMan::GetAddressInfo_(const CService& addr)
{
CAddrInfo* pinfo = Find(addr);
// if not found, bail out
if (!pinfo)
return CAddrInfo();
CAddrInfo& info = *pinfo;
// check whether we are talking about the exact same CService (including same port)
if (info != addr)
return CAddrInfo();
return *pinfo;
}
int CAddrMan::RandomInt(int nMax){ int CAddrMan::RandomInt(int nMax){
return GetRandInt(nMax); return GetRandInt(nMax);
} }

View File

@ -265,6 +265,9 @@ protected:
//! Update an entry's service bits. //! Update an entry's service bits.
void SetServices_(const CService &addr, ServiceFlags nServices); void SetServices_(const CService &addr, ServiceFlags nServices);
//! Get address info for address
CAddrInfo GetAddressInfo_(const CService& addr);
public: public:
/** /**
* serialized format: * serialized format:
@ -593,6 +596,18 @@ public:
Check(); Check();
} }
CAddrInfo GetAddressInfo(const CService& addr)
{
CAddrInfo addrRet;
{
LOCK(cs);
Check();
addrRet = GetAddressInfo_(addr);
Check();
}
return addrRet;
}
}; };
#endif // BITCOIN_ADDRMAN_H #endif // BITCOIN_ADDRMAN_H

View File

@ -2070,6 +2070,8 @@ void CConnman::ThreadOpenMasternodeConnections()
if (interruptNet) if (interruptNet)
return; return;
int64_t nANow = GetAdjustedTime();
// NOTE: Process only one pending masternode at a time // NOTE: Process only one pending masternode at a time
CService addr; CService addr;
@ -2085,6 +2087,11 @@ void CConnman::ThreadOpenMasternodeConnections()
} }
const auto& addr2 = dmn->pdmnState->addr; const auto& addr2 = dmn->pdmnState->addr;
if (!connectedNodes.count(addr2) && !IsMasternodeOrDisconnectRequested(addr2) && !connectedProRegTxHashes.count(proRegTxHash)) { if (!connectedNodes.count(addr2) && !IsMasternodeOrDisconnectRequested(addr2) && !connectedProRegTxHashes.count(proRegTxHash)) {
auto addrInfo = addrman.GetAddressInfo(addr2);
// back off trying connecting to an address if we already tried recently
if (addrInfo.IsValid() && nANow - addrInfo.nLastTry < 60) {
continue;
}
pending.emplace_back(addr2); pending.emplace_back(addr2);
} }
} }