16 : m_client_interface(client_interface),
17 m_ban_db(
std::move(ban_file), chainparams),
18 m_default_ban_time(default_ban_time) {
31 LogPrintf(
"Recreating the banlist database\n");
60 "Flushed %d banned node addresses/subnets to disk %dms\n",
67 m_discouraged.reset();
86 for (
const auto &it : m_banned) {
90 if (current_time < ban_entry.
nBanUntil && sub_net.
Match(net_addr)) {
100 banmap_t::iterator i = m_banned.find(sub_net);
101 if (i != m_banned.end()) {
103 if (current_time < ban_entry.
nBanUntil) {
111 bool since_unix_epoch) {
113 Ban(sub_net, ban_time_offset, since_unix_epoch);
122 bool since_unix_epoch) {
125 int64_t normalized_ban_time_offset = ban_time_offset;
126 bool normalized_since_unix_epoch = since_unix_epoch;
127 if (ban_time_offset <= 0) {
129 normalized_since_unix_epoch =
false;
132 normalized_ban_time_offset;
136 if (m_banned[sub_net].nBanUntil < ban_entry.
nBanUntil) {
137 m_banned[sub_net] = ban_entry;
153 return Unban(sub_net);
159 if (m_banned.erase(sub_net) == 0) {
183 bool notify_ui =
false;
186 banmap_t::iterator it = m_banned.begin();
187 while (it != m_banned.end()) {
191 m_banned.erase(it++);
void Discourage(const CNetAddr &net_addr)
void Ban(const CNetAddr &net_addr, int64_t ban_time_offset=0, bool since_unix_epoch=false)
const int64_t m_default_ban_time
void GetBanned(banmap_t &banmap)
bool IsBanned(const CNetAddr &net_addr)
Return whether net_addr is banned.
RecursiveMutex m_cs_banned
CClientUIInterface * m_client_interface
bool Unban(const CNetAddr &net_addr)
BanMan(fs::path ban_file, const CChainParams &chainparams, CClientUIInterface *client_interface, int64_t default_ban_time)
void SetBannedSetDirty(bool dirty=true)
set the "dirty" flag for the banlist
void SweepBanned()
clean unused entries (if bantime has expired)
bool IsDiscouraged(const CNetAddr &net_addr)
Return whether net_addr is discouraged.
bool Write(const banmap_t &banSet)
bool Read(banmap_t &banSet, bool &dirty)
Read the banlist from disk.
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Signals for UI communication.
std::vector< uint8_t > GetAddrBytes() const
std::string ToString() const
bool Match(const CNetAddr &addr) const
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
#define LogPrint(category,...)
Implement std::hash so RCUPtr can be used as a key for maps or sets.
std::map< CSubNet, CBanEntry > banmap_t
int64_t GetTimeMillis()
Returns the system time (not mockable)
int64_t GetTime()
DEPRECATED Use either ClockType::now() or Now<TimePointType>() if a cast is needed.
bilingual_str _(const char *psz)
Translation function.