Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/net.cpp
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2019 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <rpc/server.h> | #include <rpc/server.h> | ||||
#include <banman.h> | #include <banman.h> | ||||
#include <chainparams.h> | #include <chainparams.h> | ||||
#include <clientversion.h> | #include <clientversion.h> | ||||
▲ Show 20 Lines • Show All 635 Lines • ▼ Show 20 Lines | UniValue localAddresses(UniValue::VARR); | ||||
} | } | ||||
} | } | ||||
obj.pushKV("localaddresses", localAddresses); | obj.pushKV("localaddresses", localAddresses); | ||||
obj.pushKV("warnings", GetWarnings("statusbar")); | obj.pushKV("warnings", GetWarnings("statusbar")); | ||||
return obj; | return obj; | ||||
} | } | ||||
static UniValue setban(const Config &config, const JSONRPCRequest &request) { | static UniValue setban(const Config &config, const JSONRPCRequest &request) { | ||||
std::string strCommand; | const RPCHelpMan help{ | ||||
if (!request.params[1].isNull()) { | |||||
strCommand = request.params[1].get_str(); | |||||
} | |||||
if (request.fHelp || request.params.size() < 2 || | |||||
(strCommand != "add" && strCommand != "remove")) { | |||||
throw std::runtime_error(RPCHelpMan{ | |||||
"setban", | "setban", | ||||
"\nAttempts to add or remove an IP/Subnet from the " | "\nAttempts to add or remove an IP/Subnet from the " | ||||
"banned list.\n", | "banned list.\n", | ||||
{ | { | ||||
{"subnet", RPCArg::Type::STR, RPCArg::Optional::NO, | {"subnet", RPCArg::Type::STR, RPCArg::Optional::NO, | ||||
"The IP/Subnet (see getpeerinfo for nodes IP) with an " | "The IP/Subnet (see getpeerinfo for nodes IP) with an optional " | ||||
"optional netmask (default is /32 = single IP)"}, | "netmask (default is /32 = single IP)"}, | ||||
{"command", RPCArg::Type::STR, RPCArg::Optional::NO, | {"command", RPCArg::Type::STR, RPCArg::Optional::NO, | ||||
"'add' to add an IP/Subnet to the list, 'remove' to " | "'add' to add an IP/Subnet to the list, 'remove' to remove an " | ||||
"remove an IP/Subnet from the list"}, | "IP/Subnet from the list"}, | ||||
{"bantime", RPCArg::Type::NUM, /* default */ "0", | {"bantime", RPCArg::Type::NUM, /* default */ "0", | ||||
"time in seconds how long (or until when if [absolute] is " | "time in seconds how long (or until when if [absolute] is set) " | ||||
"set) the IP is banned (0 or empty means using the default " | "the IP is banned (0 or empty means using the default time of 24h " | ||||
"time of 24h which can also be overwritten by the -bantime " | "which can also be overwritten by the -bantime startup argument)"}, | ||||
"startup argument)"}, | |||||
{"absolute", RPCArg::Type::BOOL, /* default */ "false", | {"absolute", RPCArg::Type::BOOL, /* default */ "false", | ||||
"If set, the bantime must be an absolute timestamp in seconds " | "If set, the bantime must be an absolute timestamp in seconds " | ||||
"since epoch (Jan 1 1970 GMT)"}, | "since epoch (Jan 1 1970 GMT)"}, | ||||
}, | }, | ||||
RPCResults{}, | RPCResults{}, | ||||
RPCExamples{ | RPCExamples{ | ||||
HelpExampleCli("setban", "\"192.168.0.6\" \"add\" 86400") + | HelpExampleCli("setban", "\"192.168.0.6\" \"add\" 86400") + | ||||
HelpExampleCli("setban", "\"192.168.0.0/24\" \"add\"") + | HelpExampleCli("setban", "\"192.168.0.0/24\" \"add\"") + | ||||
HelpExampleRpc("setban", "\"192.168.0.6\", \"add\", 86400")}, | HelpExampleRpc("setban", "\"192.168.0.6\", \"add\", 86400")}, | ||||
}; | |||||
std::string strCommand; | |||||
if (!request.params[1].isNull()) { | |||||
strCommand = request.params[1].get_str(); | |||||
} | } | ||||
.ToString()); | |||||
if (request.fHelp || !help.IsValidNumArgs(request.params.size()) || | |||||
(strCommand != "add" && strCommand != "remove")) { | |||||
throw std::runtime_error(help.ToString()); | |||||
} | } | ||||
if (!g_banman) { | if (!g_banman) { | ||||
throw JSONRPCError(RPC_DATABASE_ERROR, | throw JSONRPCError(RPC_DATABASE_ERROR, | ||||
"Error: Ban database not loaded"); | "Error: Ban database not loaded"); | ||||
} | } | ||||
CSubNet subNet; | CSubNet subNet; | ||||
CNetAddr netAddr; | CNetAddr netAddr; | ||||
bool isSubnet = false; | bool isSubnet = false; | ||||
▲ Show 20 Lines • Show All 235 Lines • Show Last 20 Lines |