Skip to content

Commit e035387

Browse files
codablockUdjinM6
authored andcommitted
Back off for 1m when connecting to quorum masternodes (#2975)
* Implement GetAddressInfo in CAddrMan * Back off for 1m when connecting to quorum masternodes
1 parent bfcfb70 commit e035387

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

src/addrman.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,23 @@ void CAddrMan::SetServices_(const CService& addr, ServiceFlags nServices)
533533
info.nServices = nServices;
534534
}
535535

536+
CAddrInfo CAddrMan::GetAddressInfo_(const CService& addr)
537+
{
538+
CAddrInfo* pinfo = Find(addr);
539+
540+
// if not found, bail out
541+
if (!pinfo)
542+
return CAddrInfo();
543+
544+
CAddrInfo& info = *pinfo;
545+
546+
// check whether we are talking about the exact same CService (including same port)
547+
if (info != addr)
548+
return CAddrInfo();
549+
550+
return *pinfo;
551+
}
552+
536553
int CAddrMan::RandomInt(int nMax){
537554
return GetRandInt(nMax);
538555
}

src/addrman.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,9 @@ class CAddrMan
265265
//! Update an entry's service bits.
266266
void SetServices_(const CService &addr, ServiceFlags nServices);
267267

268+
//! Get address info for address
269+
CAddrInfo GetAddressInfo_(const CService& addr);
270+
268271
public:
269272
/**
270273
* serialized format:
@@ -595,6 +598,18 @@ class CAddrMan
595598
Check();
596599
}
597600

601+
CAddrInfo GetAddressInfo(const CService& addr)
602+
{
603+
CAddrInfo addrRet;
604+
{
605+
LOCK(cs);
606+
Check();
607+
addrRet = GetAddressInfo_(addr);
608+
Check();
609+
}
610+
return addrRet;
611+
}
612+
598613
};
599614

600615
#endif // BITCOIN_ADDRMAN_H

src/net.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2072,6 +2072,8 @@ void CConnman::ThreadOpenMasternodeConnections()
20722072
if (interruptNet)
20732073
return;
20742074

2075+
int64_t nANow = GetAdjustedTime();
2076+
20752077
// NOTE: Process only one pending masternode at a time
20762078

20772079
CService addr;
@@ -2087,6 +2089,11 @@ void CConnman::ThreadOpenMasternodeConnections()
20872089
}
20882090
const auto& addr2 = dmn->pdmnState->addr;
20892091
if (!connectedNodes.count(addr2) && !IsMasternodeOrDisconnectRequested(addr2) && !connectedProRegTxHashes.count(proRegTxHash)) {
2092+
auto addrInfo = addrman.GetAddressInfo(addr2);
2093+
// back off trying connecting to an address if we already tried recently
2094+
if (addrInfo.IsValid() && nANow - addrInfo.nLastTry < 60) {
2095+
continue;
2096+
}
20902097
pending.emplace_back(addr2);
20912098
}
20922099
}

0 commit comments

Comments
 (0)