diff --git a/src/net.cpp b/src/net.cpp index 24cd1f881..66604b1a5 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -604,6 +604,7 @@ void DumpBanlist() if (bandb.Write(banmap)) { SetBannedSetDirty(false); } + fprintf(stderr,"%s: Dumping banlist with %lu items\n", __func__, banmap.size()); LogPrint("net", "Flushed %d banned node ips/subnets to banlist.dat %dms\n", banmap.size(), GetTimeMillis() - nStart); @@ -617,7 +618,6 @@ void CNode::ClearBanned() setBannedIsDirty = true; } DumpBanlist(); //store banlist to disk - // uiInterface.BannedListChanged(); } @@ -631,8 +631,10 @@ bool CNode::IsBanned(CNetAddr ip) CSubNet subNet = (*it).first; CBanEntry banEntry = (*it).second; - if(subNet.Match(ip) && GetTime() < banEntry.nBanUntil) + if(subNet.Match(ip) && GetTime() < banEntry.nBanUntil) { + fprintf(stderr,"%s: found banned subnet %s\n", __func__, subNet.ToString().c_str()); fResult = true; + } } } return fResult; @@ -664,25 +666,29 @@ void CNode::Ban(const CSubNet& subNet, const BanReason &banReason, int64_t banti if (bantimeoffset > 0) banEntry.nBanUntil = (sinceUnixEpoch ? 0 : GetTime() )+bantimeoffset; + fprintf(stderr, "%s: banning %s until %ld with bantimeoffset=%ld sinceUnixEpoch=%d\n", __func__, subNet.ToString().c_str(), banEntry.nBanUntil, bantimeoffset, sinceUnixEpoch); { LOCK(cs_setBanned); if (setBanned[subNet].nBanUntil < banEntry.nBanUntil) { setBanned[subNet] = banEntry; setBannedIsDirty = true; - } - else + } else { return; + } } - // uiInterface.BannedListChanged(); { LOCK(cs_vNodes); for (CNode* pnode : vNodes) { if (subNet.Match(static_cast(pnode->addr))) + fprintf(stderr, "%s: disconnecting from banned node %s\n", __func__, pnode->addr.ToString().c_str() ); pnode->fDisconnect = true; } } - if(banReason == BanReasonManuallyAdded) + + if(banReason == BanReasonManuallyAdded) { + fprintf(stderr,"%s: dumping banlist after manual ban\n", __func__); DumpBanlist(); //store banlist to disk immediately if user requested ban + } } bool CNode::Unban(const CNetAddr &addr) { @@ -697,7 +703,6 @@ bool CNode::Unban(const CSubNet &subNet) { return false; setBannedIsDirty = true; } - // uiInterface.BannedListChanged(); DumpBanlist(); //store banlist to disk immediately return true; } @@ -720,6 +725,7 @@ void SetBanned(const banmap_t &banMap) void SweepBanned() { int64_t now = GetTime(); + //fprintf(stderr,"%s: Sweeping banlist\n", __func__); LOCK(cs_setBanned); banmap_t::iterator it = setBanned.begin(); @@ -732,9 +738,9 @@ void SweepBanned() setBanned.erase(it++); setBannedIsDirty = true; LogPrint("net", "%s: Removed banned node ip/subnet from banlist.dat: %s\n", __func__, subNet.ToString()); - } - else + } else { ++it; + } } } diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index 8a4e96113..8b686a6fd 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -633,7 +633,7 @@ UniValue setban(const UniValue& params, bool fHelp, const CPubKey& mypk) if (isSubnet ? CNode::IsBanned(subNet) : CNode::IsBanned(netAddr)) throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, "Error: IP/Subnet already banned"); - int64_t banTime = 0; //use standard bantime if not specified + int64_t banTime = 60*60*24; //use standard bantime if not specified if (params.size() >= 3 && !params[2].isNull()) banTime = params[2].get_int64(); @@ -641,14 +641,14 @@ UniValue setban(const UniValue& params, bool fHelp, const CPubKey& mypk) if (params.size() == 4 && params[3].isTrue()) absolute = true; + fprintf(stderr,"%s: adding manual ban for %s with banTime=%ld absolute=%d isSubnet=%d\n", __func__, isSubnet ? subNet.ToString().c_str() : netAddr.ToString().c_str(), banTime, absolute, isSubnet); isSubnet ? CNode::Ban(subNet, BanReasonManuallyAdded, banTime, absolute) : CNode::Ban(netAddr, BanReasonManuallyAdded, banTime, absolute); //disconnect possible nodes - while(CNode *bannedNode = (isSubnet ? FindNode(subNet) : FindNode(netAddr))) + while(CNode *bannedNode = (isSubnet ? FindNode(subNet) : FindNode(netAddr))) { bannedNode->fDisconnect = true; - } - else if(strCommand == "remove") - { + } + } else if(strCommand == "remove") { if (!( isSubnet ? CNode::Unban(subNet) : CNode::Unban(netAddr) )) throw JSONRPCError(RPC_MISC_ERROR, "Error: Unban failed"); }