Don't disconnect masternode probes for a few seconds (#3449)

* Refactor CMasternodeUtils::ProcessMasternodeConnections to be more readable

* Don't disconnect masternode probes for a few seconds
This commit is contained in:
Alexander Block 2020-04-21 16:44:18 +02:00 committed by GitHub
parent 608aed3d85
commit 96faa8155e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -39,24 +39,31 @@ void CMasternodeUtils::ProcessMasternodeConnections(CConnman& connman)
}
connman.ForEachNode(CConnman::AllNodes, [&](CNode* pnode) {
if (!pnode->fInbound && pnode->fMasternode && !connman.IsMasternodeQuorumNode(pnode)) {
// we're only disconnecting fMasternode connections
if (!pnode->fMasternode) return;
// we're only disconnecting outbound connections
if (pnode->fInbound) return;
// we're not disconnecting LLMQ connections
if (connman.IsMasternodeQuorumNode(pnode)) return;
// we're not disconnecting masternode probes for at least a few seconds
if (pnode->fMasternodeProbe && GetSystemTimeInSeconds() - pnode->nTimeConnected < 5) return;
#ifdef ENABLE_WALLET
bool fFound = false;
for (const auto& dmn : vecDmns) {
if (pnode->addr == dmn->pdmnState->addr) {
fFound = true;
break;
}
bool fFound = false;
for (const auto& dmn : vecDmns) {
if (pnode->addr == dmn->pdmnState->addr) {
fFound = true;
break;
}
if (fFound) return; // do NOT disconnect mixing masternodes
#endif // ENABLE_WALLET
if (fLogIPs) {
LogPrintf("Closing Masternode connection: peer=%d, addr=%s\n", pnode->GetId(), pnode->addr.ToString());
} else {
LogPrintf("Closing Masternode connection: peer=%d\n", pnode->GetId());
}
pnode->fDisconnect = true;
}
if (fFound) return; // do NOT disconnect mixing masternodes
#endif // ENABLE_WALLET
if (fLogIPs) {
LogPrintf("Closing Masternode connection: peer=%d, addr=%s\n", pnode->GetId(), pnode->addr.ToString());
} else {
LogPrintf("Closing Masternode connection: peer=%d\n", pnode->GetId());
}
pnode->fDisconnect = true;
});
}