Browse Source
[net] extend core functionallity for ban/unban/listban
pull/4/head
Jonas Schnelli
9 years ago
committed by
Jack Grigg
No known key found for this signature in database
GPG Key ID: 6A6914DAFBEA00DA
2 changed files with
25 additions and
7 deletions
-
src/net.cpp
-
src/net.h
|
|
@ -464,16 +464,31 @@ bool CNode::IsBanned(CNetAddr ip) |
|
|
|
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
|
|
|
|
{ |
|
|
|
LOCK(cs_setBanned); |
|
|
|
if (setBanned[addr] < banTime) |
|
|
|
setBanned[addr] = banTime; |
|
|
|
} |
|
|
|
if (bantimeoffset > 0) |
|
|
|
banTime = GetTime()+bantimeoffset; |
|
|
|
|
|
|
|
LOCK(cs_setBanned); |
|
|
|
if (setBanned[addr] < banTime) |
|
|
|
setBanned[addr] = banTime; |
|
|
|
|
|
|
|
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; |
|
|
|
CCriticalSection CNode::cs_vWhitelistedRange; |
|
|
|
|
|
@ -613,7 +613,10 @@ public: |
|
|
|
// new code.
|
|
|
|
static void ClearBanned(); // needed for unit testing
|
|
|
|
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); |
|
|
|
|
|
|
|
static bool IsWhitelistedRange(const CNetAddr &ip); |
|
|
|