scripted-diff: batch-rename BanMan members
-BEGIN VERIFY SCRIPT- sed -i "s/clientInterface/m_client_interface/g" src/banman.h src/banman.cpp sed -i "s/setBannedIsDirty/m_is_dirty/g" src/banman.h src/banman.cpp sed -i "s/cs_setBanned/m_cs_banned/g" src/banman.h src/banman.cpp sed -i "s/setBanned/m_banned/g" src/banman.h src/banman.cpp -END VERIFY SCRIPT-
This commit is contained in:
parent
af3503d903
commit
84fc3fbd03
2 changed files with 41 additions and 41 deletions
|
@ -12,12 +12,12 @@
|
||||||
|
|
||||||
|
|
||||||
BanMan::BanMan(fs::path ban_file, CClientUIInterface* client_interface, int64_t default_ban_time)
|
BanMan::BanMan(fs::path ban_file, CClientUIInterface* client_interface, int64_t default_ban_time)
|
||||||
: clientInterface(client_interface), m_ban_db(std::move(ban_file)), m_default_ban_time(default_ban_time)
|
: m_client_interface(client_interface), m_ban_db(std::move(ban_file)), m_default_ban_time(default_ban_time)
|
||||||
{
|
{
|
||||||
if (clientInterface) clientInterface->InitMessage(_("Loading banlist..."));
|
if (m_client_interface) m_client_interface->InitMessage(_("Loading banlist..."));
|
||||||
|
|
||||||
int64_t nStart = GetTimeMillis();
|
int64_t nStart = GetTimeMillis();
|
||||||
setBannedIsDirty = false;
|
m_is_dirty = false;
|
||||||
banmap_t banmap;
|
banmap_t banmap;
|
||||||
if (m_ban_db.Read(banmap)) {
|
if (m_ban_db.Read(banmap)) {
|
||||||
SetBanned(banmap); // thread save setter
|
SetBanned(banmap); // thread save setter
|
||||||
|
@ -59,18 +59,18 @@ void BanMan::DumpBanlist()
|
||||||
void BanMan::ClearBanned()
|
void BanMan::ClearBanned()
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
LOCK(cs_setBanned);
|
LOCK(m_cs_banned);
|
||||||
setBanned.clear();
|
m_banned.clear();
|
||||||
setBannedIsDirty = true;
|
m_is_dirty = true;
|
||||||
}
|
}
|
||||||
DumpBanlist(); //store banlist to disk
|
DumpBanlist(); //store banlist to disk
|
||||||
if (clientInterface) clientInterface->BannedListChanged();
|
if (m_client_interface) m_client_interface->BannedListChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BanMan::IsBanned(CNetAddr netAddr)
|
bool BanMan::IsBanned(CNetAddr netAddr)
|
||||||
{
|
{
|
||||||
LOCK(cs_setBanned);
|
LOCK(m_cs_banned);
|
||||||
for (const auto& it : setBanned) {
|
for (const auto& it : m_banned) {
|
||||||
CSubNet subNet = it.first;
|
CSubNet subNet = it.first;
|
||||||
CBanEntry banEntry = it.second;
|
CBanEntry banEntry = it.second;
|
||||||
|
|
||||||
|
@ -83,9 +83,9 @@ bool BanMan::IsBanned(CNetAddr netAddr)
|
||||||
|
|
||||||
bool BanMan::IsBanned(CSubNet subNet)
|
bool BanMan::IsBanned(CSubNet subNet)
|
||||||
{
|
{
|
||||||
LOCK(cs_setBanned);
|
LOCK(m_cs_banned);
|
||||||
banmap_t::iterator i = setBanned.find(subNet);
|
banmap_t::iterator i = m_banned.find(subNet);
|
||||||
if (i != setBanned.end()) {
|
if (i != m_banned.end()) {
|
||||||
CBanEntry banEntry = (*i).second;
|
CBanEntry banEntry = (*i).second;
|
||||||
if (GetTime() < banEntry.nBanUntil) {
|
if (GetTime() < banEntry.nBanUntil) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -111,14 +111,14 @@ void BanMan::Ban(const CSubNet& subNet, const BanReason& banReason, int64_t bant
|
||||||
banEntry.nBanUntil = (sinceUnixEpoch ? 0 : GetTime()) + bantimeoffset;
|
banEntry.nBanUntil = (sinceUnixEpoch ? 0 : GetTime()) + bantimeoffset;
|
||||||
|
|
||||||
{
|
{
|
||||||
LOCK(cs_setBanned);
|
LOCK(m_cs_banned);
|
||||||
if (setBanned[subNet].nBanUntil < banEntry.nBanUntil) {
|
if (m_banned[subNet].nBanUntil < banEntry.nBanUntil) {
|
||||||
setBanned[subNet] = banEntry;
|
m_banned[subNet] = banEntry;
|
||||||
setBannedIsDirty = true;
|
m_is_dirty = true;
|
||||||
} else
|
} else
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (clientInterface) clientInterface->BannedListChanged();
|
if (m_client_interface) m_client_interface->BannedListChanged();
|
||||||
|
|
||||||
//store banlist to disk immediately if user requested ban
|
//store banlist to disk immediately if user requested ban
|
||||||
if (banReason == BanReasonManuallyAdded) DumpBanlist();
|
if (banReason == BanReasonManuallyAdded) DumpBanlist();
|
||||||
|
@ -133,28 +133,28 @@ bool BanMan::Unban(const CNetAddr& netAddr)
|
||||||
bool BanMan::Unban(const CSubNet& subNet)
|
bool BanMan::Unban(const CSubNet& subNet)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
LOCK(cs_setBanned);
|
LOCK(m_cs_banned);
|
||||||
if (setBanned.erase(subNet) == 0) return false;
|
if (m_banned.erase(subNet) == 0) return false;
|
||||||
setBannedIsDirty = true;
|
m_is_dirty = true;
|
||||||
}
|
}
|
||||||
if (clientInterface) clientInterface->BannedListChanged();
|
if (m_client_interface) m_client_interface->BannedListChanged();
|
||||||
DumpBanlist(); //store banlist to disk immediately
|
DumpBanlist(); //store banlist to disk immediately
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BanMan::GetBanned(banmap_t& banMap)
|
void BanMan::GetBanned(banmap_t& banMap)
|
||||||
{
|
{
|
||||||
LOCK(cs_setBanned);
|
LOCK(m_cs_banned);
|
||||||
// Sweep the banlist so expired bans are not returned
|
// Sweep the banlist so expired bans are not returned
|
||||||
SweepBanned();
|
SweepBanned();
|
||||||
banMap = setBanned; //create a thread safe copy
|
banMap = m_banned; //create a thread safe copy
|
||||||
}
|
}
|
||||||
|
|
||||||
void BanMan::SetBanned(const banmap_t& banMap)
|
void BanMan::SetBanned(const banmap_t& banMap)
|
||||||
{
|
{
|
||||||
LOCK(cs_setBanned);
|
LOCK(m_cs_banned);
|
||||||
setBanned = banMap;
|
m_banned = banMap;
|
||||||
setBannedIsDirty = true;
|
m_is_dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BanMan::SweepBanned()
|
void BanMan::SweepBanned()
|
||||||
|
@ -162,14 +162,14 @@ void BanMan::SweepBanned()
|
||||||
int64_t now = GetTime();
|
int64_t now = GetTime();
|
||||||
bool notifyUI = false;
|
bool notifyUI = false;
|
||||||
{
|
{
|
||||||
LOCK(cs_setBanned);
|
LOCK(m_cs_banned);
|
||||||
banmap_t::iterator it = setBanned.begin();
|
banmap_t::iterator it = m_banned.begin();
|
||||||
while (it != setBanned.end()) {
|
while (it != m_banned.end()) {
|
||||||
CSubNet subNet = (*it).first;
|
CSubNet subNet = (*it).first;
|
||||||
CBanEntry banEntry = (*it).second;
|
CBanEntry banEntry = (*it).second;
|
||||||
if (now > banEntry.nBanUntil) {
|
if (now > banEntry.nBanUntil) {
|
||||||
setBanned.erase(it++);
|
m_banned.erase(it++);
|
||||||
setBannedIsDirty = true;
|
m_is_dirty = true;
|
||||||
notifyUI = true;
|
notifyUI = true;
|
||||||
LogPrint(BCLog::NET, "%s: Removed banned node ip/subnet from banlist.dat: %s\n", __func__, subNet.ToString());
|
LogPrint(BCLog::NET, "%s: Removed banned node ip/subnet from banlist.dat: %s\n", __func__, subNet.ToString());
|
||||||
} else
|
} else
|
||||||
|
@ -177,19 +177,19 @@ void BanMan::SweepBanned()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// update UI
|
// update UI
|
||||||
if (notifyUI && clientInterface) {
|
if (notifyUI && m_client_interface) {
|
||||||
clientInterface->BannedListChanged();
|
m_client_interface->BannedListChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BanMan::BannedSetIsDirty()
|
bool BanMan::BannedSetIsDirty()
|
||||||
{
|
{
|
||||||
LOCK(cs_setBanned);
|
LOCK(m_cs_banned);
|
||||||
return setBannedIsDirty;
|
return m_is_dirty;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BanMan::SetBannedSetDirty(bool dirty)
|
void BanMan::SetBannedSetDirty(bool dirty)
|
||||||
{
|
{
|
||||||
LOCK(cs_setBanned); //reuse setBanned lock for the setBannedIsDirty flag
|
LOCK(m_cs_banned); //reuse m_banned lock for the m_is_dirty flag
|
||||||
setBannedIsDirty = dirty;
|
m_is_dirty = dirty;
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,10 +57,10 @@ private:
|
||||||
//!clean unused entries (if bantime has expired)
|
//!clean unused entries (if bantime has expired)
|
||||||
void SweepBanned();
|
void SweepBanned();
|
||||||
|
|
||||||
banmap_t setBanned;
|
banmap_t m_banned;
|
||||||
CCriticalSection cs_setBanned;
|
CCriticalSection m_cs_banned;
|
||||||
bool setBannedIsDirty;
|
bool m_is_dirty;
|
||||||
CClientUIInterface* clientInterface = nullptr;
|
CClientUIInterface* m_client_interface = nullptr;
|
||||||
CBanDB m_ban_db;
|
CBanDB m_ban_db;
|
||||||
int64_t m_default_ban_time;
|
int64_t m_default_ban_time;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue