18 : m_client_interface(client_interface), m_ban_db(
std::move(ban_file)), m_default_ban_time(default_ban_time)
35 const auto start{SteadyClock::now()};
39 LogPrint(
BCLog::NET,
"Loaded %d banned node addresses/subnets %dms\n", m_banned.size(),
40 Ticks<std::chrono::milliseconds>(SteadyClock::now() - start));
42 LogPrintf(
"Recreating the banlist database\n");
50 static Mutex dump_mutex;
62 const auto start{SteadyClock::now()};
67 LogPrint(
BCLog::NET,
"Flushed %d banned node addresses/subnets to disk %dms\n", banmap.size(),
68 Ticks<std::chrono::milliseconds>(SteadyClock::now() - start));
92 for (
const auto& it : m_banned) {
96 if (current_time < ban_entry.
nBanUntil && sub_net.
Match(net_addr)) {
107 banmap_t::iterator i = m_banned.find(sub_net);
108 if (i != m_banned.end()) {
110 if (current_time < ban_entry.
nBanUntil) {
120 Ban(sub_net, ban_time_offset, since_unix_epoch);
133 int64_t normalized_ban_time_offset = ban_time_offset;
134 bool normalized_since_unix_epoch = since_unix_epoch;
135 if (ban_time_offset <= 0) {
137 normalized_since_unix_epoch =
false;
139 ban_entry.
nBanUntil = (normalized_since_unix_epoch ? 0 :
GetTime()) + normalized_ban_time_offset;
143 if (m_banned[sub_net].nBanUntil < ban_entry.
nBanUntil) {
144 m_banned[sub_net] = ban_entry;
158 return Unban(sub_net);
165 if (m_banned.erase(sub_net) == 0)
return false;
186 bool notify_ui =
false;
187 banmap_t::iterator it = m_banned.begin();
188 while (it != m_banned.end()) {
192 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,...)
CClientUIInterface * m_client_interface
void SetBannedSetDirty(bool dirty=true)
set the "dirty" flag for the banlist
Signals for UI communication.
bool IsDiscouraged(const CNetAddr &net_addr)
Return whether net_addr is discouraged.
bilingual_str _(const char *psz)
Translation function.
void LoadBanlist() EXCLUSIVE_LOCKS_REQUIRED(!m_cs_banned)
RecursiveMutex m_cs_banned
bool Write(const banmap_t &banSet)
void GetBanned(banmap_t &banmap)
bool Match(const CNetAddr &addr) const
const int64_t m_default_ban_time
bool Read(banmap_t &banSet)
Read the banlist from disk.
std::string ToString() const
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.
void SweepBanned() EXCLUSIVE_LOCKS_REQUIRED(m_cs_banned)
clean unused entries (if bantime has expired)
int64_t GetTime()
DEPRECATED, see GetTime.
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
std::vector< unsigned char > GetAddrBytes() const