Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/net.cpp
Show First 20 Lines • Show All 229 Lines • ▼ Show 20 Lines | for (const CNodeStats &stats : vstats) { | ||||
ret.push_back(obj); | ret.push_back(obj); | ||||
} | } | ||||
return ret; | return ret; | ||||
} | } | ||||
static UniValue addnode(const Config &config, const JSONRPCRequest &request) { | static UniValue addnode(const Config &config, const JSONRPCRequest &request) { | ||||
std::string strCommand; | std::string strCommand; | ||||
if (request.params.size() == 2) { | if (!request.params[1].isNull()) { | ||||
strCommand = request.params[1].get_str(); | strCommand = request.params[1].get_str(); | ||||
} | } | ||||
if (request.fHelp || request.params.size() != 2 || | if (request.fHelp || request.params.size() != 2 || | ||||
(strCommand != "onetry" && strCommand != "add" && | (strCommand != "onetry" && strCommand != "add" && | ||||
strCommand != "remove")) { | strCommand != "remove")) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"addnode \"node\" \"add|remove|onetry\"\n" | "addnode \"node\" \"add|remove|onetry\"\n" | ||||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | static UniValue disconnectnode(const Config &config, | ||||
if (!g_connman) { | if (!g_connman) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_CLIENT_P2P_DISABLED, | RPC_CLIENT_P2P_DISABLED, | ||||
"Error: Peer-to-peer functionality missing or disabled"); | "Error: Peer-to-peer functionality missing or disabled"); | ||||
} | } | ||||
bool success; | bool success; | ||||
const UniValue &address_arg = request.params[0]; | const UniValue &address_arg = request.params[0]; | ||||
const UniValue &id_arg = | const UniValue &id_arg = request.params[1]; | ||||
request.params.size() < 2 ? NullUniValue : request.params[1]; | |||||
if (!address_arg.isNull() && id_arg.isNull()) { | if (!address_arg.isNull() && id_arg.isNull()) { | ||||
/* handle disconnect-by-address */ | /* handle disconnect-by-address */ | ||||
success = g_connman->DisconnectNode(address_arg.get_str()); | success = g_connman->DisconnectNode(address_arg.get_str()); | ||||
} else if (!id_arg.isNull() && | } else if (!id_arg.isNull() && | ||||
(address_arg.isNull() || | (address_arg.isNull() || | ||||
(address_arg.isStr() && address_arg.get_str().empty()))) { | (address_arg.isStr() && address_arg.get_str().empty()))) { | ||||
/* handle disconnect-by-id */ | /* handle disconnect-by-id */ | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | static UniValue getaddednodeinfo(const Config &config, | ||||
if (!g_connman) { | if (!g_connman) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_CLIENT_P2P_DISABLED, | RPC_CLIENT_P2P_DISABLED, | ||||
"Error: Peer-to-peer functionality missing or disabled"); | "Error: Peer-to-peer functionality missing or disabled"); | ||||
} | } | ||||
std::vector<AddedNodeInfo> vInfo = g_connman->GetAddedNodeInfo(); | std::vector<AddedNodeInfo> vInfo = g_connman->GetAddedNodeInfo(); | ||||
if (request.params.size() == 1 && !request.params[0].isNull()) { | if (!request.params[0].isNull()) { | ||||
bool found = false; | bool found = false; | ||||
for (const AddedNodeInfo &info : vInfo) { | for (const AddedNodeInfo &info : vInfo) { | ||||
if (info.strAddedNode == request.params[0].get_str()) { | if (info.strAddedNode == request.params[0].get_str()) { | ||||
vInfo.assign(1, info); | vInfo.assign(1, info); | ||||
found = true; | found = true; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 208 Lines • ▼ Show 20 Lines | static UniValue getnetworkinfo(const Config &config, | ||||
} | } | ||||
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; | std::string strCommand; | ||||
if (request.params.size() >= 2) { | if (!request.params[1].isNull()) { | ||||
strCommand = request.params[1].get_str(); | strCommand = request.params[1].get_str(); | ||||
} | } | ||||
if (request.fHelp || request.params.size() < 2 || | if (request.fHelp || request.params.size() < 2 || | ||||
(strCommand != "add" && strCommand != "remove")) { | (strCommand != "add" && strCommand != "remove")) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"setban \"subnet\" \"add|remove\" (bantime) (absolute)\n" | "setban \"subnet\" \"add|remove\" (bantime) (absolute)\n" | ||||
"\nAttempts to add or remove a IP/Subnet from the banned list.\n" | "\nAttempts to add or remove a IP/Subnet from the banned list.\n" | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | if (strCommand == "add") { | ||||
if (isSubnet ? g_connman->IsBanned(subNet) | if (isSubnet ? g_connman->IsBanned(subNet) | ||||
: g_connman->IsBanned(netAddr)) { | : g_connman->IsBanned(netAddr)) { | ||||
throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, | throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, | ||||
"Error: IP/Subnet already banned"); | "Error: IP/Subnet already banned"); | ||||
} | } | ||||
// Use standard bantime if not specified. | // Use standard bantime if not specified. | ||||
int64_t banTime = 0; | int64_t banTime = 0; | ||||
if (request.params.size() >= 3 && !request.params[2].isNull()) { | if (!request.params[2].isNull()) { | ||||
banTime = request.params[2].get_int64(); | banTime = request.params[2].get_int64(); | ||||
} | } | ||||
bool absolute = false; | bool absolute = false; | ||||
if (request.params.size() == 4 && request.params[3].isTrue()) { | if (request.params[3].isTrue()) { | ||||
absolute = true; | absolute = true; | ||||
} | } | ||||
isSubnet | isSubnet | ||||
? g_connman->Ban(subNet, BanReasonManuallyAdded, banTime, absolute) | ? g_connman->Ban(subNet, BanReasonManuallyAdded, banTime, absolute) | ||||
: g_connman->Ban(netAddr, BanReasonManuallyAdded, banTime, | : g_connman->Ban(netAddr, BanReasonManuallyAdded, banTime, | ||||
absolute); | absolute); | ||||
} else if (strCommand == "remove") { | } else if (strCommand == "remove") { | ||||
▲ Show 20 Lines • Show All 111 Lines • Show Last 20 Lines |