setban: rewrite to UniValue, allow absolute bantime

This commit is contained in:
Jonas Schnelli
2015-06-12 18:31:47 +02:00
parent 3de24d7647
commit 4e36e9bcc7
6 changed files with 46 additions and 25 deletions

View File

@@ -484,15 +484,15 @@ bool CNode::IsBanned(CSubNet subnet)
return fResult;
}
void CNode::Ban(const CNetAddr& addr, int64_t bantimeoffset) {
void CNode::Ban(const CNetAddr& addr, int64_t bantimeoffset, bool sinceUnixEpoch) {
CSubNet subNet(addr.ToString()+(addr.IsIPv4() ? "/32" : "/128"));
Ban(subNet, bantimeoffset);
Ban(subNet, bantimeoffset, sinceUnixEpoch);
}
void CNode::Ban(const CSubNet& subNet, int64_t bantimeoffset) {
void CNode::Ban(const CSubNet& subNet, int64_t bantimeoffset, bool sinceUnixEpoch) {
int64_t banTime = GetTime()+GetArg("-bantime", 60*60*24); // Default 24-hour ban
if (bantimeoffset > 0)
banTime = GetTime()+bantimeoffset;
banTime = (sinceUnixEpoch ? 0 : GetTime() )+bantimeoffset;
LOCK(cs_setBanned);
if (setBanned[subNet] < banTime)