net: make Ban/Unban/ClearBan functionality consistent

- Ban/Unban/ClearBan call uiInterface.BannedListChanged() as necessary
- Ban/Unban/ClearBan sync to disk if the operation is user-invoked
- Mark node for disconnection automatically when banning
- Lock cs_vNodes while setting disconnected
- Don't spin in a tight loop while setting disconnected
This commit is contained in:
Cory Fields
2016-04-18 17:02:43 -04:00
parent cca221fd21
commit 8b8f87714d
3 changed files with 33 additions and 26 deletions

View File

@@ -565,20 +565,12 @@ UniValue setban(const UniValue& params, bool fHelp)
absolute = true;
isSubnet ? CNode::Ban(subNet, BanReasonManuallyAdded, banTime, absolute) : CNode::Ban(netAddr, BanReasonManuallyAdded, banTime, absolute);
//disconnect possible nodes
while(CNode *bannedNode = (isSubnet ? FindNode(subNet) : FindNode(netAddr)))
bannedNode->fDisconnect = true;
}
else if(strCommand == "remove")
{
if (!( isSubnet ? CNode::Unban(subNet) : CNode::Unban(netAddr) ))
throw JSONRPCError(RPC_MISC_ERROR, "Error: Unban failed");
}
DumpBanlist(); //store banlist to disk
uiInterface.BannedListChanged();
return NullUniValue;
}
@@ -624,8 +616,6 @@ UniValue clearbanned(const UniValue& params, bool fHelp)
);
CNode::ClearBanned();
DumpBanlist(); //store banlist to disk
uiInterface.BannedListChanged();
return NullUniValue;
}