Browse Source

Merge #10564: Return early in IsBanned.

bf376eacc Return early in IsBanned. (Gregory Maxwell)

Tree-SHA512: d8ed4aaf9a7523b00effa4ac17cec3be1ec1f5c5ce64d89833fbc8f3d73d13b022043354fbcf2682b2af05070d115e1fc0cc0b122197e9ddee5959c3fb9dd16d
0.15
Pieter Wuille 8 years ago
parent
commit
8d9f45ea6a
No known key found for this signature in database
GPG Key ID: A636E97631F767E0
  1. 16
      src/net.cpp

16
src/net.cpp

@ -469,35 +469,31 @@ void CConnman::ClearBanned()
bool CConnman::IsBanned(CNetAddr ip) bool CConnman::IsBanned(CNetAddr ip)
{ {
bool fResult = false;
{
LOCK(cs_setBanned); LOCK(cs_setBanned);
for (banmap_t::iterator it = setBanned.begin(); it != setBanned.end(); it++) for (banmap_t::iterator it = setBanned.begin(); it != setBanned.end(); it++)
{ {
CSubNet subNet = (*it).first; CSubNet subNet = (*it).first;
CBanEntry banEntry = (*it).second; CBanEntry banEntry = (*it).second;
if(subNet.Match(ip) && GetTime() < banEntry.nBanUntil) if (subNet.Match(ip) && GetTime() < banEntry.nBanUntil) {
fResult = true; return true;
} }
} }
return fResult; return false;
} }
bool CConnman::IsBanned(CSubNet subnet) bool CConnman::IsBanned(CSubNet subnet)
{ {
bool fResult = false;
{
LOCK(cs_setBanned); LOCK(cs_setBanned);
banmap_t::iterator i = setBanned.find(subnet); banmap_t::iterator i = setBanned.find(subnet);
if (i != setBanned.end()) if (i != setBanned.end())
{ {
CBanEntry banEntry = (*i).second; CBanEntry banEntry = (*i).second;
if (GetTime() < banEntry.nBanUntil) if (GetTime() < banEntry.nBanUntil) {
fResult = true; return true;
} }
} }
return fResult; return false;
} }
void CConnman::Ban(const CNetAddr& addr, const BanReason &banReason, int64_t bantimeoffset, bool sinceUnixEpoch) { void CConnman::Ban(const CNetAddr& addr, const BanReason &banReason, int64_t bantimeoffset, bool sinceUnixEpoch) {

Loading…
Cancel
Save