Changeset View
Changeset View
Standalone View
Standalone View
src/banman.cpp
Show First 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | void BanMan::ClearBanned() { | ||||
} | } | ||||
// store banlist to disk | // store banlist to disk | ||||
DumpBanlist(); | DumpBanlist(); | ||||
if (m_client_interface) { | if (m_client_interface) { | ||||
m_client_interface->BannedListChanged(); | m_client_interface->BannedListChanged(); | ||||
} | } | ||||
} | } | ||||
int BanMan::IsBannedLevel(CNetAddr net_addr) { | |||||
// Returns the most severe level of banning that applies to this address. | |||||
// 0 - Not banned | |||||
// 1 - Automatic misbehavior ban | |||||
// 2 - Any other ban | |||||
int level = 0; | |||||
auto current_time = GetTime(); | |||||
LOCK(m_cs_banned); | |||||
for (const auto &it : m_banned) { | |||||
CSubNet sub_net = it.first; | |||||
CBanEntry ban_entry = it.second; | |||||
if (current_time < ban_entry.nBanUntil && sub_net.Match(net_addr)) { | |||||
if (ban_entry.banReason != BanReasonNodeMisbehaving) { | |||||
return 2; | |||||
} | |||||
level = 1; | |||||
} | |||||
} | |||||
return level; | |||||
} | |||||
bool BanMan::IsBanned(CNetAddr net_addr) { | bool BanMan::IsBanned(CNetAddr net_addr) { | ||||
auto current_time = GetTime(); | |||||
LOCK(m_cs_banned); | LOCK(m_cs_banned); | ||||
for (const auto &it : m_banned) { | for (const auto &it : m_banned) { | ||||
CSubNet sub_net = it.first; | CSubNet sub_net = it.first; | ||||
CBanEntry ban_entry = it.second; | CBanEntry ban_entry = it.second; | ||||
if (sub_net.Match(net_addr) && GetTime() < ban_entry.nBanUntil) { | if (current_time < ban_entry.nBanUntil && sub_net.Match(net_addr)) { | ||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
bool BanMan::IsBanned(CSubNet sub_net) { | bool BanMan::IsBanned(CSubNet sub_net) { | ||||
auto current_time = GetTime(); | |||||
LOCK(m_cs_banned); | LOCK(m_cs_banned); | ||||
banmap_t::iterator i = m_banned.find(sub_net); | banmap_t::iterator i = m_banned.find(sub_net); | ||||
if (i != m_banned.end()) { | if (i != m_banned.end()) { | ||||
CBanEntry ban_entry = (*i).second; | CBanEntry ban_entry = (*i).second; | ||||
if (GetTime() < ban_entry.nBanUntil) { | if (current_time < ban_entry.nBanUntil) { | ||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
void BanMan::Ban(const CNetAddr &net_addr, const BanReason &ban_reason, | void BanMan::Ban(const CNetAddr &net_addr, const BanReason &ban_reason, | ||||
int64_t ban_time_offset, bool since_unix_epoch) { | int64_t ban_time_offset, bool since_unix_epoch) { | ||||
▲ Show 20 Lines • Show All 110 Lines • Show Last 20 Lines |