diff options
author | Jonas Schnelli <jonas.schnelli@include7.ch> | 2015-06-12 18:31:47 +0200 |
---|---|---|
committer | Jonas Schnelli <jonas.schnelli@include7.ch> | 2015-06-17 21:40:55 +0200 |
commit | 4e36e9bcc7d071bba4c45fd89c0cfd2e2361ffe3 (patch) | |
tree | 2703eacb4f5dd62e6d6bb95193412cbcbf0e8ad5 /src/rpcnet.cpp | |
parent | 3de24d7647db2b9167cee25549c3c603582e19e6 (diff) |
setban: rewrite to UniValue, allow absolute bantime
Diffstat (limited to 'src/rpcnet.cpp')
-rw-r--r-- | src/rpcnet.cpp | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/rpcnet.cpp b/src/rpcnet.cpp index 35ef92ecfd..97d5ccbff8 100644 --- a/src/rpcnet.cpp +++ b/src/rpcnet.cpp @@ -466,7 +466,7 @@ UniValue getnetworkinfo(const UniValue& params, bool fHelp) return obj; } -Value setban(const Array& params, bool fHelp) +UniValue setban(const UniValue& params, bool fHelp) { string strCommand; if (params.size() >= 2) @@ -474,12 +474,13 @@ Value setban(const Array& params, bool fHelp) if (fHelp || params.size() < 2 || (strCommand != "add" && strCommand != "remove")) throw runtime_error( - "setban \"ip(/netmask)\" \"add|remove\" (bantime)\n" + "setban \"ip(/netmask)\" \"add|remove\" (bantime) (absolute)\n" "\nAttempts add or remove a IP/Subnet from the banned list.\n" "\nArguments:\n" "1. \"ip(/netmask)\" (string, required) The IP/Subnet (see getpeerinfo for nodes ip) with a optional netmask (default is /32 = single ip)\n" "2. \"command\" (string, required) 'add' to add a IP/Subnet to the list, 'remove' to remove a IP/Subnet from the list\n" - "1. \"bantime\" (numeric, optional) time in seconds how long the ip is banned (0 or empty means using the default time of 24h which can also be overwritten by the -bantime startup argument)\n" + "3. \"bantime\" (numeric, optional) time in seconds how long (or until when if [absolute] is set) the ip is banned (0 or empty means using the default time of 24h which can also be overwritten by the -bantime startup argument)\n" + "4. \"absolute\" (boolean, optional) If set, the bantime must be a absolute timestamp in seconds since epoch (Jan 1 1970 GMT)\n" "\nExamples:\n" + HelpExampleCli("setban", "\"192.168.0.6\" \"add\" 86400") + HelpExampleCli("setban", "\"192.168.0.0/24\" \"add\"") @@ -507,10 +508,14 @@ Value setban(const Array& params, bool fHelp) throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, "Error: IP/Subnet already banned"); int64_t banTime = 0; //use standard bantime if not specified - if (params.size() == 3 && !params[2].is_null()) + if (params.size() >= 3 && !params[2].isNull()) banTime = params[2].get_int64(); - isSubnet ? CNode::Ban(subNet, banTime) : CNode::Ban(netAddr, banTime); + bool absolute = false; + if (params.size() == 4 && params[3].isTrue()) + absolute = true; + + isSubnet ? CNode::Ban(subNet, banTime, absolute) : CNode::Ban(netAddr, banTime, absolute); //disconnect possible nodes while(CNode *bannedNode = (isSubnet ? FindNode(subNet) : FindNode(netAddr))) @@ -522,10 +527,10 @@ Value setban(const Array& params, bool fHelp) throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, "Error: Unban failed"); } - return Value::null; + return NullUniValue; } -Value listbanned(const Array& params, bool fHelp) +UniValue listbanned(const UniValue& params, bool fHelp) { if (fHelp || params.size() != 0) throw runtime_error( @@ -539,10 +544,10 @@ Value listbanned(const Array& params, bool fHelp) std::map<CSubNet, int64_t> banMap; CNode::GetBanned(banMap); - Array bannedAddresses; + UniValue bannedAddresses(UniValue::VARR); for (std::map<CSubNet, int64_t>::iterator it = banMap.begin(); it != banMap.end(); it++) { - Object rec; + UniValue rec(UniValue::VOBJ); rec.push_back(Pair("address", (*it).first.ToString())); rec.push_back(Pair("banned_untill", (*it).second)); bannedAddresses.push_back(rec); @@ -551,7 +556,7 @@ Value listbanned(const Array& params, bool fHelp) return bannedAddresses; } -Value clearbanned(const Array& params, bool fHelp) +UniValue clearbanned(const UniValue& params, bool fHelp) { if (fHelp || params.size() != 0) throw runtime_error( @@ -564,5 +569,5 @@ Value clearbanned(const Array& params, bool fHelp) CNode::ClearBanned(); - return Value::null; + return NullUniValue; } |