mirror of
https://github.com/kvazar-network/kevacoin.git
synced 2025-01-12 16:17:53 +00:00
[net] extend core functionallity for ban/unban/listban
This commit is contained in:
parent
9849c663b1
commit
2252fb91cd
21
src/net.cpp
21
src/net.cpp
@ -458,16 +458,31 @@ bool CNode::IsBanned(CNetAddr ip)
|
|||||||
return fResult;
|
return fResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CNode::Ban(const CNetAddr &addr) {
|
bool CNode::Ban(const CNetAddr &addr, int64_t bantimeoffset) {
|
||||||
int64_t banTime = GetTime()+GetArg("-bantime", 60*60*24); // Default 24-hour ban
|
int64_t banTime = GetTime()+GetArg("-bantime", 60*60*24); // Default 24-hour ban
|
||||||
{
|
if (bantimeoffset > 0)
|
||||||
|
banTime = GetTime()+bantimeoffset;
|
||||||
|
|
||||||
LOCK(cs_setBanned);
|
LOCK(cs_setBanned);
|
||||||
if (setBanned[addr] < banTime)
|
if (setBanned[addr] < banTime)
|
||||||
setBanned[addr] = banTime;
|
setBanned[addr] = banTime;
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CNode::Unban(const CNetAddr &addr) {
|
||||||
|
LOCK(cs_setBanned);
|
||||||
|
if (setBanned.erase(addr))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CNode::GetBanned(std::map<CNetAddr, int64_t> &banMap)
|
||||||
|
{
|
||||||
|
LOCK(cs_setBanned);
|
||||||
|
banMap = setBanned; //create a thread safe copy
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::vector<CSubNet> CNode::vWhitelistedRange;
|
std::vector<CSubNet> CNode::vWhitelistedRange;
|
||||||
CCriticalSection CNode::cs_vWhitelistedRange;
|
CCriticalSection CNode::cs_vWhitelistedRange;
|
||||||
|
@ -606,7 +606,10 @@ public:
|
|||||||
// new code.
|
// new code.
|
||||||
static void ClearBanned(); // needed for unit testing
|
static void ClearBanned(); // needed for unit testing
|
||||||
static bool IsBanned(CNetAddr ip);
|
static bool IsBanned(CNetAddr ip);
|
||||||
static bool Ban(const CNetAddr &ip);
|
static bool Ban(const CNetAddr &ip, int64_t bantimeoffset = 0);
|
||||||
|
static bool Unban(const CNetAddr &ip);
|
||||||
|
static void GetBanned(std::map<CNetAddr, int64_t> &banmap);
|
||||||
|
|
||||||
void copyStats(CNodeStats &stats);
|
void copyStats(CNodeStats &stats);
|
||||||
|
|
||||||
static bool IsWhitelistedRange(const CNetAddr &ip);
|
static bool IsWhitelistedRange(const CNetAddr &ip);
|
||||||
|
Loading…
Reference in New Issue
Block a user