File tree Expand file tree Collapse file tree 2 files changed +25
-7
lines changed Expand file tree Collapse file tree 2 files changed +25
-7
lines changed Original file line number Diff line number Diff line change @@ -458,16 +458,31 @@ bool CNode::IsBanned(CNetAddr ip)
458
458
return fResult ;
459
459
}
460
460
461
- bool CNode::Ban (const CNetAddr &addr) {
461
+ bool CNode::Ban (const CNetAddr &addr, int64_t bantimeoffset ) {
462
462
int64_t banTime = GetTime ()+GetArg (" -bantime" , 60 *60 *24 ); // Default 24-hour ban
463
- {
464
- LOCK (cs_setBanned);
465
- if (setBanned[addr] < banTime)
466
- setBanned[addr] = banTime;
467
- }
463
+ if (bantimeoffset > 0 )
464
+ banTime = GetTime ()+bantimeoffset;
465
+
466
+ LOCK (cs_setBanned);
467
+ if (setBanned[addr] < banTime)
468
+ setBanned[addr] = banTime;
469
+
468
470
return true ;
469
471
}
470
472
473
+ bool CNode::Unban (const CNetAddr &addr) {
474
+ LOCK (cs_setBanned);
475
+ if (setBanned.erase (addr))
476
+ return true ;
477
+ return false ;
478
+ }
479
+
480
+ void CNode::GetBanned (std::map<CNetAddr, int64_t > &banMap)
481
+ {
482
+ LOCK (cs_setBanned);
483
+ banMap = setBanned; // create a thread safe copy
484
+ }
485
+
471
486
472
487
std::vector<CSubNet> CNode::vWhitelistedRange;
473
488
CCriticalSection CNode::cs_vWhitelistedRange;
Original file line number Diff line number Diff line change @@ -606,7 +606,10 @@ class CNode
606
606
// new code.
607
607
static void ClearBanned (); // needed for unit testing
608
608
static bool IsBanned (CNetAddr ip);
609
- static bool Ban (const CNetAddr &ip);
609
+ static bool Ban (const CNetAddr &ip, int64_t bantimeoffset = 0 );
610
+ static bool Unban (const CNetAddr &ip);
611
+ static void GetBanned (std::map<CNetAddr, int64_t > &banmap);
612
+
610
613
void copyStats (CNodeStats &stats);
611
614
612
615
static bool IsWhitelistedRange (const CNetAddr &ip);
You can’t perform that action at this time.
0 commit comments