optimized IsBanned()

This commit is contained in:
jahway603
2022-07-13 01:04:03 -04:00
parent a3258de217
commit 9806119366

View File

@@ -547,8 +547,6 @@ void CNode::ClearBanned()
bool CNode::IsBanned(CNetAddr ip) bool CNode::IsBanned(CNetAddr ip)
{ {
bool fResult = false;
{
LOCK(cs_setBanned); LOCK(cs_setBanned);
for (std::map<CSubNet, int64_t>::iterator it = setBanned.begin(); it != setBanned.end(); it++) for (std::map<CSubNet, int64_t>::iterator it = setBanned.begin(); it != setBanned.end(); it++)
{ {
@@ -556,26 +554,22 @@ bool CNode::IsBanned(CNetAddr ip)
int64_t t = (*it).second; int64_t t = (*it).second;
if(subNet.Match(ip) && GetTime() < t) if(subNet.Match(ip) && GetTime() < t)
fResult = true; return true;
} }
} return false;
return fResult;
} }
bool CNode::IsBanned(CSubNet subnet) bool CNode::IsBanned(CSubNet subnet)
{ {
bool fResult = false;
{
LOCK(cs_setBanned); LOCK(cs_setBanned);
std::map<CSubNet, int64_t>::iterator i = setBanned.find(subnet); std::map<CSubNet, int64_t>::iterator i = setBanned.find(subnet);
if (i != setBanned.end()) if (i != setBanned.end())
{ {
int64_t t = (*i).second; int64_t t = (*i).second;
if (GetTime() < t) if (GetTime() < t)
fResult = true; return true;
} }
} return false;
return fResult;
} }
void CNode::Ban(const CNetAddr& addr, int64_t bantimeoffset, bool sinceUnixEpoch) { void CNode::Ban(const CNetAddr& addr, int64_t bantimeoffset, bool sinceUnixEpoch) {