16 : m_client_interface(client_interface), m_ban_db(
std::move(ban_file)), m_default_ban_time(default_ban_time)
31 LogPrintf(
"Invalid or missing banlist.dat; recreating\n");
81 for (
const auto&
it : m_banned) {
85 if (current_time < ban_entry.
nBanUntil && sub_net.
Match(net_addr)) {
96 banmap_t::iterator i = m_banned.find(sub_net);
97 if (i != m_banned.end()) {
109 Ban(sub_net, ban_time_offset, since_unix_epoch);
122 int64_t normalized_ban_time_offset = ban_time_offset;
123 bool normalized_since_unix_epoch = since_unix_epoch;
124 if (ban_time_offset <= 0) {
126 normalized_since_unix_epoch =
false;
128 ban_entry.
nBanUntil = (normalized_since_unix_epoch ? 0 :
GetTime()) + normalized_ban_time_offset;
132 if (m_banned[sub_net].nBanUntil < ban_entry.
nBanUntil) {
133 m_banned[sub_net] = ban_entry;
147 return Unban(sub_net);
154 if (m_banned.erase(sub_net) == 0)
return false;
180 bool notify_ui =
false;
183 banmap_t::iterator
it = m_banned.begin();
184 while (it != m_banned.end()) {
188 m_banned.erase(it++);
void Ban(const CNetAddr &net_addr, int64_t ban_time_offset=0, bool since_unix_epoch=false)
void Discourage(const CNetAddr &net_addr)
#define LogPrint(category,...)
int64_t GetTimeMillis()
Returns the system time (not mockable)
static void LogPrintf(const char *fmt, const Args &...args)
void SetBanned(const banmap_t &banmap)
CClientUIInterface * m_client_interface
std::string ToString() const
void SetBannedSetDirty(bool dirty=true)
set the "dirty" flag for the banlist
bool Match(const CNetAddr &addr) const
Signals for UI communication.
bool IsDiscouraged(const CNetAddr &net_addr)
Return whether net_addr is discouraged.
void SweepBanned()
clean unused entries (if bantime has expired)
bilingual_str _(const char *psz)
Translation function.
RecursiveMutex m_cs_banned
bool Write(const banmap_t &banSet)
void GetBanned(banmap_t &banmap)
const int64_t m_default_ban_time
bool Read(banmap_t &banSet)
bool Unban(const CNetAddr &net_addr)
BanMan(fs::path ban_file, CClientUIInterface *client_interface, int64_t default_ban_time)
std::map< CSubNet, CBanEntry > banmap_t
bool IsBanned(const CNetAddr &net_addr)
Return whether net_addr is banned.
std::vector< unsigned char > GetAddrBytes() const
int64_t GetTime()
Return system time (or mocked time, if set)