]> Git Repo - VerusCoin.git/blobdiff - src/rpcnet.cpp
setban: rewrite to UniValue, allow absolute bantime
[VerusCoin.git] / src / rpcnet.cpp
index 08e01689051af8080f25ae441f123241cf1d018a..19d6c61ca9a036d227bcab7dfe04aa2958ec108d 100644 (file)
@@ -467,7 +467,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)
@@ -475,12 +475,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\"")
@@ -508,10 +509,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)))
@@ -523,10 +528,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(
@@ -540,10 +545,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);
@@ -552,7 +557,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(
@@ -565,5 +570,5 @@ Value clearbanned(const Array& params, bool fHelp)
 
     CNode::ClearBanned();
 
-    return Value::null;
+    return NullUniValue;
 }
This page took 0.028476 seconds and 4 git commands to generate.