Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/net.cpp
Show All 35 Lines | if (request.fHelp || request.params.size() != 0) { | ||||
{}, | {}, | ||||
RPCResult{"n (numeric) The connection count\n"}, | RPCResult{"n (numeric) The connection count\n"}, | ||||
RPCExamples{HelpExampleCli("getconnectioncount", "") + | RPCExamples{HelpExampleCli("getconnectioncount", "") + | ||||
HelpExampleRpc("getconnectioncount", "")}, | HelpExampleRpc("getconnectioncount", "")}, | ||||
} | } | ||||
.ToString()); | .ToString()); | ||||
} | } | ||||
if (!g_connman) { | if (!g_rpc_node->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"); | ||||
} | } | ||||
return int(g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL)); | return int(g_rpc_node->connman->GetNodeCount(CConnman::CONNECTIONS_ALL)); | ||||
} | } | ||||
static UniValue ping(const Config &config, const JSONRPCRequest &request) { | static UniValue ping(const Config &config, const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 0) { | if (request.fHelp || request.params.size() != 0) { | ||||
throw std::runtime_error(RPCHelpMan{ | throw std::runtime_error(RPCHelpMan{ | ||||
"ping", | "ping", | ||||
"\nRequests that a ping be sent to all other nodes, to measure " | "\nRequests that a ping be sent to all other nodes, to measure " | ||||
"ping time.\n" | "ping time.\n" | ||||
"Results provided in getpeerinfo, pingtime and pingwait fields " | "Results provided in getpeerinfo, pingtime and pingwait fields " | ||||
"are decimal seconds.\n" | "are decimal seconds.\n" | ||||
"Ping command is handled in queue with all other commands, so " | "Ping command is handled in queue with all other commands, so " | ||||
"it measures processing backlog, not just network ping.\n", | "it measures processing backlog, not just network ping.\n", | ||||
{}, | {}, | ||||
RPCResults{}, | RPCResults{}, | ||||
RPCExamples{HelpExampleCli("ping", "") + | RPCExamples{HelpExampleCli("ping", "") + | ||||
HelpExampleRpc("ping", "")}, | HelpExampleRpc("ping", "")}, | ||||
} | } | ||||
.ToString()); | .ToString()); | ||||
} | } | ||||
if (!g_connman) { | if (!g_rpc_node->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"); | ||||
} | } | ||||
// Request that each node send a ping during next message processing pass | // Request that each node send a ping during next message processing pass | ||||
g_connman->ForEachNode([](CNode *pnode) { pnode->fPingQueued = true; }); | g_rpc_node->connman->ForEachNode( | ||||
[](CNode *pnode) { pnode->fPingQueued = true; }); | |||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
static UniValue getpeerinfo(const Config &config, | static UniValue getpeerinfo(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 0) { | if (request.fHelp || request.params.size() != 0) { | ||||
throw std::runtime_error(RPCHelpMan{ | throw std::runtime_error(RPCHelpMan{ | ||||
"getpeerinfo", | "getpeerinfo", | ||||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() != 0) { | ||||
" ,...\n" | " ,...\n" | ||||
"]\n"}, | "]\n"}, | ||||
RPCExamples{HelpExampleCli("getpeerinfo", "") + | RPCExamples{HelpExampleCli("getpeerinfo", "") + | ||||
HelpExampleRpc("getpeerinfo", "")}, | HelpExampleRpc("getpeerinfo", "")}, | ||||
} | } | ||||
.ToString()); | .ToString()); | ||||
} | } | ||||
if (!g_connman) { | if (!g_rpc_node->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<CNodeStats> vstats; | std::vector<CNodeStats> vstats; | ||||
g_connman->GetNodeStats(vstats); | g_rpc_node->connman->GetNodeStats(vstats); | ||||
UniValue ret(UniValue::VARR); | UniValue ret(UniValue::VARR); | ||||
for (const CNodeStats &stats : vstats) { | for (const CNodeStats &stats : vstats) { | ||||
UniValue obj(UniValue::VOBJ); | UniValue obj(UniValue::VOBJ); | ||||
CNodeStateStats statestats; | CNodeStateStats statestats; | ||||
bool fStateStats = GetNodeStateStats(stats.nodeid, statestats); | bool fStateStats = GetNodeStateStats(stats.nodeid, statestats); | ||||
obj.pushKV("id", stats.nodeid); | obj.pushKV("id", stats.nodeid); | ||||
▲ Show 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() != 2 || | ||||
RPCResults{}, | RPCResults{}, | ||||
RPCExamples{ | RPCExamples{ | ||||
HelpExampleCli("addnode", "\"192.168.0.6:8333\" \"onetry\"") + | HelpExampleCli("addnode", "\"192.168.0.6:8333\" \"onetry\"") + | ||||
HelpExampleRpc("addnode", "\"192.168.0.6:8333\", \"onetry\"")}, | HelpExampleRpc("addnode", "\"192.168.0.6:8333\", \"onetry\"")}, | ||||
} | } | ||||
.ToString()); | .ToString()); | ||||
} | } | ||||
if (!g_connman) { | if (!g_rpc_node->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::string strNode = request.params[0].get_str(); | std::string strNode = request.params[0].get_str(); | ||||
if (strCommand == "onetry") { | if (strCommand == "onetry") { | ||||
CAddress addr; | CAddress addr; | ||||
g_connman->OpenNetworkConnection(addr, false, nullptr, strNode.c_str(), | g_rpc_node->connman->OpenNetworkConnection( | ||||
false, false, true); | addr, false, nullptr, strNode.c_str(), false, false, true); | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if ((strCommand == "add") && (!g_connman->AddNode(strNode))) { | if ((strCommand == "add") && (!g_rpc_node->connman->AddNode(strNode))) { | ||||
throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, | throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, | ||||
"Error: Node already added"); | "Error: Node already added"); | ||||
} else if ((strCommand == "remove") && | } else if ((strCommand == "remove") && | ||||
(!g_connman->RemoveAddedNode(strNode))) { | (!g_rpc_node->connman->RemoveAddedNode(strNode))) { | ||||
throw JSONRPCError(RPC_CLIENT_NODE_NOT_ADDED, | throw JSONRPCError(RPC_CLIENT_NODE_NOT_ADDED, | ||||
"Error: Node has not been added."); | "Error: Node has not been added."); | ||||
} | } | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
static UniValue disconnectnode(const Config &config, | static UniValue disconnectnode(const Config &config, | ||||
Show All 20 Lines | if (request.fHelp || request.params.size() == 0 || | ||||
HelpExampleCli("disconnectnode", "\"192.168.0.6:8333\"") + | HelpExampleCli("disconnectnode", "\"192.168.0.6:8333\"") + | ||||
HelpExampleCli("disconnectnode", "\"\" 1") + | HelpExampleCli("disconnectnode", "\"\" 1") + | ||||
HelpExampleRpc("disconnectnode", "\"192.168.0.6:8333\"") + | HelpExampleRpc("disconnectnode", "\"192.168.0.6:8333\"") + | ||||
HelpExampleRpc("disconnectnode", "\"\", 1")}, | HelpExampleRpc("disconnectnode", "\"\", 1")}, | ||||
} | } | ||||
.ToString()); | .ToString()); | ||||
} | } | ||||
if (!g_connman) { | if (!g_rpc_node->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 = request.params[1]; | const UniValue &id_arg = 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_rpc_node->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 */ | ||||
NodeId nodeid = (NodeId)id_arg.get_int64(); | NodeId nodeid = (NodeId)id_arg.get_int64(); | ||||
success = g_connman->DisconnectNode(nodeid); | success = g_rpc_node->connman->DisconnectNode(nodeid); | ||||
} else { | } else { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_INVALID_PARAMS, | RPC_INVALID_PARAMS, | ||||
"Only one of address and nodeid should be provided."); | "Only one of address and nodeid should be provided."); | ||||
} | } | ||||
if (!success) { | if (!success) { | ||||
throw JSONRPCError(RPC_CLIENT_NODE_NOT_CONNECTED, | throw JSONRPCError(RPC_CLIENT_NODE_NOT_CONNECTED, | ||||
Show All 37 Lines | if (request.fHelp || request.params.size() > 1) { | ||||
"]\n"}, | "]\n"}, | ||||
RPCExamples{ | RPCExamples{ | ||||
HelpExampleCli("getaddednodeinfo", "\"192.168.0.201\"") + | HelpExampleCli("getaddednodeinfo", "\"192.168.0.201\"") + | ||||
HelpExampleRpc("getaddednodeinfo", "\"192.168.0.201\"")}, | HelpExampleRpc("getaddednodeinfo", "\"192.168.0.201\"")}, | ||||
} | } | ||||
.ToString()); | .ToString()); | ||||
} | } | ||||
if (!g_connman) { | if (!g_rpc_node->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_rpc_node->connman->GetAddedNodeInfo(); | ||||
if (!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 57 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() > 0) { | ||||
" }\n" | " }\n" | ||||
"}\n"}, | "}\n"}, | ||||
RPCExamples{HelpExampleCli("getnettotals", "") + | RPCExamples{HelpExampleCli("getnettotals", "") + | ||||
HelpExampleRpc("getnettotals", "")}, | HelpExampleRpc("getnettotals", "")}, | ||||
} | } | ||||
.ToString()); | .ToString()); | ||||
} | } | ||||
if (!g_connman) { | if (!g_rpc_node->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"); | ||||
} | } | ||||
UniValue obj(UniValue::VOBJ); | UniValue obj(UniValue::VOBJ); | ||||
obj.pushKV("totalbytesrecv", g_connman->GetTotalBytesRecv()); | obj.pushKV("totalbytesrecv", g_rpc_node->connman->GetTotalBytesRecv()); | ||||
obj.pushKV("totalbytessent", g_connman->GetTotalBytesSent()); | obj.pushKV("totalbytessent", g_rpc_node->connman->GetTotalBytesSent()); | ||||
obj.pushKV("timemillis", GetTimeMillis()); | obj.pushKV("timemillis", GetTimeMillis()); | ||||
UniValue outboundLimit(UniValue::VOBJ); | UniValue outboundLimit(UniValue::VOBJ); | ||||
outboundLimit.pushKV("timeframe", g_connman->GetMaxOutboundTimeframe()); | outboundLimit.pushKV("timeframe", | ||||
outboundLimit.pushKV("target", g_connman->GetMaxOutboundTarget()); | g_rpc_node->connman->GetMaxOutboundTimeframe()); | ||||
outboundLimit.pushKV("target", g_rpc_node->connman->GetMaxOutboundTarget()); | |||||
outboundLimit.pushKV("target_reached", | outboundLimit.pushKV("target_reached", | ||||
g_connman->OutboundTargetReached(false)); | g_rpc_node->connman->OutboundTargetReached(false)); | ||||
outboundLimit.pushKV("serve_historical_blocks", | outboundLimit.pushKV("serve_historical_blocks", | ||||
!g_connman->OutboundTargetReached(true)); | !g_rpc_node->connman->OutboundTargetReached(true)); | ||||
outboundLimit.pushKV("bytes_left_in_cycle", | outboundLimit.pushKV("bytes_left_in_cycle", | ||||
g_connman->GetOutboundTargetBytesLeft()); | g_rpc_node->connman->GetOutboundTargetBytesLeft()); | ||||
outboundLimit.pushKV("time_left_in_cycle", | outboundLimit.pushKV("time_left_in_cycle", | ||||
g_connman->GetMaxOutboundTimeLeftInCycle()); | g_rpc_node->connman->GetMaxOutboundTimeLeftInCycle()); | ||||
obj.pushKV("uploadtarget", outboundLimit); | obj.pushKV("uploadtarget", outboundLimit); | ||||
return obj; | return obj; | ||||
} | } | ||||
static UniValue GetNetworksInfo() { | static UniValue GetNetworksInfo() { | ||||
UniValue networks(UniValue::VARR); | UniValue networks(UniValue::VARR); | ||||
for (int n = 0; n < NET_MAX; ++n) { | for (int n = 0; n < NET_MAX; ++n) { | ||||
enum Network network = static_cast<enum Network>(n); | enum Network network = static_cast<enum Network>(n); | ||||
▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() != 0) { | ||||
.ToString()); | .ToString()); | ||||
} | } | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
UniValue obj(UniValue::VOBJ); | UniValue obj(UniValue::VOBJ); | ||||
obj.pushKV("version", CLIENT_VERSION); | obj.pushKV("version", CLIENT_VERSION); | ||||
obj.pushKV("subversion", userAgent(config)); | obj.pushKV("subversion", userAgent(config)); | ||||
obj.pushKV("protocolversion", PROTOCOL_VERSION); | obj.pushKV("protocolversion", PROTOCOL_VERSION); | ||||
if (g_connman) { | if (g_rpc_node->connman) { | ||||
obj.pushKV("localservices", | obj.pushKV("localservices", | ||||
strprintf("%016x", g_connman->GetLocalServices())); | strprintf("%016x", g_rpc_node->connman->GetLocalServices())); | ||||
} | } | ||||
obj.pushKV("localrelay", fRelayTxes); | obj.pushKV("localrelay", fRelayTxes); | ||||
obj.pushKV("timeoffset", GetTimeOffset()); | obj.pushKV("timeoffset", GetTimeOffset()); | ||||
if (g_connman) { | if (g_rpc_node->connman) { | ||||
obj.pushKV("networkactive", g_connman->GetNetworkActive()); | obj.pushKV("networkactive", g_rpc_node->connman->GetNetworkActive()); | ||||
obj.pushKV("connections", | obj.pushKV("connections", int(g_rpc_node->connman->GetNodeCount( | ||||
int(g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL))); | CConnman::CONNECTIONS_ALL))); | ||||
} | } | ||||
obj.pushKV("networks", GetNetworksInfo()); | obj.pushKV("networks", GetNetworksInfo()); | ||||
obj.pushKV("relayfee", ValueFromAmount(::minRelayTxFee.GetFeePerK())); | obj.pushKV("relayfee", ValueFromAmount(::minRelayTxFee.GetFeePerK())); | ||||
obj.pushKV("excessutxocharge", | obj.pushKV("excessutxocharge", | ||||
ValueFromAmount(config.GetExcessUTXOCharge())); | ValueFromAmount(config.GetExcessUTXOCharge())); | ||||
UniValue localAddresses(UniValue::VARR); | UniValue localAddresses(UniValue::VARR); | ||||
{ | { | ||||
LOCK(cs_mapLocalHost); | LOCK(cs_mapLocalHost); | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | if (!request.params[1].isNull()) { | ||||
strCommand = request.params[1].get_str(); | strCommand = request.params[1].get_str(); | ||||
} | } | ||||
if (request.fHelp || !help.IsValidNumArgs(request.params.size()) || | if (request.fHelp || !help.IsValidNumArgs(request.params.size()) || | ||||
(strCommand != "add" && strCommand != "remove")) { | (strCommand != "add" && strCommand != "remove")) { | ||||
throw std::runtime_error(help.ToString()); | throw std::runtime_error(help.ToString()); | ||||
} | } | ||||
if (!g_banman) { | if (!g_rpc_node->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 All 10 Lines | static UniValue setban(const Config &config, const JSONRPCRequest &request) { | ||||
} | } | ||||
if (!(isSubnet ? subNet.IsValid() : netAddr.IsValid())) { | if (!(isSubnet ? subNet.IsValid() : netAddr.IsValid())) { | ||||
throw JSONRPCError(RPC_CLIENT_INVALID_IP_OR_SUBNET, | throw JSONRPCError(RPC_CLIENT_INVALID_IP_OR_SUBNET, | ||||
"Error: Invalid IP/Subnet"); | "Error: Invalid IP/Subnet"); | ||||
} | } | ||||
if (strCommand == "add") { | if (strCommand == "add") { | ||||
if (isSubnet ? g_banman->IsBanned(subNet) | if (isSubnet ? g_rpc_node->banman->IsBanned(subNet) | ||||
: g_banman->IsBanned(netAddr)) { | : g_rpc_node->banman->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[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[3].isTrue()) { | if (request.params[3].isTrue()) { | ||||
absolute = true; | absolute = true; | ||||
} | } | ||||
if (isSubnet) { | if (isSubnet) { | ||||
g_banman->Ban(subNet, BanReasonManuallyAdded, banTime, absolute); | g_rpc_node->banman->Ban(subNet, BanReasonManuallyAdded, banTime, | ||||
if (g_connman) { | absolute); | ||||
g_connman->DisconnectNode(subNet); | if (g_rpc_node->connman) { | ||||
g_rpc_node->connman->DisconnectNode(subNet); | |||||
} | } | ||||
} else { | } else { | ||||
g_banman->Ban(netAddr, BanReasonManuallyAdded, banTime, absolute); | g_rpc_node->banman->Ban(netAddr, BanReasonManuallyAdded, banTime, | ||||
if (g_connman) { | absolute); | ||||
g_connman->DisconnectNode(netAddr); | if (g_rpc_node->connman) { | ||||
g_rpc_node->connman->DisconnectNode(netAddr); | |||||
} | } | ||||
} | } | ||||
} else if (strCommand == "remove") { | } else if (strCommand == "remove") { | ||||
if (!(isSubnet ? g_banman->Unban(subNet) : g_banman->Unban(netAddr))) { | if (!(isSubnet ? g_rpc_node->banman->Unban(subNet) | ||||
: g_rpc_node->banman->Unban(netAddr))) { | |||||
throw JSONRPCError(RPC_CLIENT_INVALID_IP_OR_SUBNET, | throw JSONRPCError(RPC_CLIENT_INVALID_IP_OR_SUBNET, | ||||
"Error: Unban failed. Requested address/subnet " | "Error: Unban failed. Requested address/subnet " | ||||
"was not previously banned."); | "was not previously banned."); | ||||
} | } | ||||
} | } | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
static UniValue listbanned(const Config &config, | static UniValue listbanned(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 0) { | if (request.fHelp || request.params.size() != 0) { | ||||
throw std::runtime_error(RPCHelpMan{ | throw std::runtime_error(RPCHelpMan{ | ||||
"listbanned", | "listbanned", | ||||
"\nList all banned IPs/Subnets.\n", | "\nList all banned IPs/Subnets.\n", | ||||
{}, | {}, | ||||
RPCResults{}, | RPCResults{}, | ||||
RPCExamples{HelpExampleCli("listbanned", "") + | RPCExamples{HelpExampleCli("listbanned", "") + | ||||
HelpExampleRpc("listbanned", "")}, | HelpExampleRpc("listbanned", "")}, | ||||
} | } | ||||
.ToString()); | .ToString()); | ||||
} | } | ||||
if (!g_banman) { | if (!g_rpc_node->banman) { | ||||
throw JSONRPCError(RPC_DATABASE_ERROR, | throw JSONRPCError(RPC_DATABASE_ERROR, | ||||
"Error: Ban database not loaded"); | "Error: Ban database not loaded"); | ||||
} | } | ||||
banmap_t banMap; | banmap_t banMap; | ||||
g_banman->GetBanned(banMap); | g_rpc_node->banman->GetBanned(banMap); | ||||
UniValue bannedAddresses(UniValue::VARR); | UniValue bannedAddresses(UniValue::VARR); | ||||
for (const auto &entry : banMap) { | for (const auto &entry : banMap) { | ||||
const CBanEntry &banEntry = entry.second; | const CBanEntry &banEntry = entry.second; | ||||
UniValue rec(UniValue::VOBJ); | UniValue rec(UniValue::VOBJ); | ||||
rec.pushKV("address", entry.first.ToString()); | rec.pushKV("address", entry.first.ToString()); | ||||
rec.pushKV("banned_until", banEntry.nBanUntil); | rec.pushKV("banned_until", banEntry.nBanUntil); | ||||
rec.pushKV("ban_created", banEntry.nCreateTime); | rec.pushKV("ban_created", banEntry.nCreateTime); | ||||
Show All 13 Lines | if (request.fHelp || request.params.size() != 0) { | ||||
"\nClear all banned IPs.\n", | "\nClear all banned IPs.\n", | ||||
{}, | {}, | ||||
RPCResults{}, | RPCResults{}, | ||||
RPCExamples{HelpExampleCli("clearbanned", "") + | RPCExamples{HelpExampleCli("clearbanned", "") + | ||||
HelpExampleRpc("clearbanned", "")}, | HelpExampleRpc("clearbanned", "")}, | ||||
} | } | ||||
.ToString()); | .ToString()); | ||||
} | } | ||||
if (!g_banman) { | if (!g_rpc_node->banman) { | ||||
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"); | ||||
} | } | ||||
g_banman->ClearBanned(); | g_rpc_node->banman->ClearBanned(); | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
static UniValue setnetworkactive(const Config &config, | static UniValue setnetworkactive(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 1) { | if (request.fHelp || request.params.size() != 1) { | ||||
throw std::runtime_error(RPCHelpMan{ | throw std::runtime_error(RPCHelpMan{ | ||||
"setnetworkactive", | "setnetworkactive", | ||||
"\nDisable/enable all p2p network activity.\n", | "\nDisable/enable all p2p network activity.\n", | ||||
{ | { | ||||
{"state", RPCArg::Type::BOOL, RPCArg::Optional::NO, | {"state", RPCArg::Type::BOOL, RPCArg::Optional::NO, | ||||
"true to enable networking, false to disable"}, | "true to enable networking, false to disable"}, | ||||
}, | }, | ||||
RPCResults{}, | RPCResults{}, | ||||
RPCExamples{""}, | RPCExamples{""}, | ||||
} | } | ||||
.ToString()); | .ToString()); | ||||
} | } | ||||
if (!g_connman) { | if (!g_rpc_node->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"); | ||||
} | } | ||||
g_connman->SetNetworkActive(request.params[0].get_bool()); | g_rpc_node->connman->SetNetworkActive(request.params[0].get_bool()); | ||||
return g_connman->GetNetworkActive(); | return g_rpc_node->connman->GetNetworkActive(); | ||||
} | } | ||||
static UniValue getnodeaddresses(const Config &config, | static UniValue getnodeaddresses(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() > 1) { | if (request.fHelp || request.params.size() > 1) { | ||||
throw std::runtime_error(RPCHelpMan{ | throw std::runtime_error(RPCHelpMan{ | ||||
"getnodeaddresses", | "getnodeaddresses", | ||||
"\nReturn known addresses which can potentially be used " | "\nReturn known addresses which can potentially be used " | ||||
Show All 20 Lines | if (request.fHelp || request.params.size() > 1) { | ||||
" }\n" | " }\n" | ||||
" ,....\n" | " ,....\n" | ||||
"]\n"}, | "]\n"}, | ||||
RPCExamples{HelpExampleCli("getnodeaddresses", "8") + | RPCExamples{HelpExampleCli("getnodeaddresses", "8") + | ||||
HelpExampleRpc("getnodeaddresses", "8")}, | HelpExampleRpc("getnodeaddresses", "8")}, | ||||
} | } | ||||
.ToString()); | .ToString()); | ||||
} | } | ||||
if (!g_connman) { | if (!g_rpc_node->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"); | ||||
} | } | ||||
int count = 1; | int count = 1; | ||||
if (!request.params[0].isNull()) { | if (!request.params[0].isNull()) { | ||||
count = request.params[0].get_int(); | count = request.params[0].get_int(); | ||||
if (count <= 0) { | if (count <= 0) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
"Address count out of range"); | "Address count out of range"); | ||||
} | } | ||||
} | } | ||||
// returns a shuffled list of CAddress | // returns a shuffled list of CAddress | ||||
std::vector<CAddress> vAddr = g_connman->GetAddresses(); | std::vector<CAddress> vAddr = g_rpc_node->connman->GetAddresses(); | ||||
UniValue ret(UniValue::VARR); | UniValue ret(UniValue::VARR); | ||||
int address_return_count = std::min<int>(count, vAddr.size()); | int address_return_count = std::min<int>(count, vAddr.size()); | ||||
for (int i = 0; i < address_return_count; ++i) { | for (int i = 0; i < address_return_count; ++i) { | ||||
UniValue obj(UniValue::VOBJ); | UniValue obj(UniValue::VOBJ); | ||||
const CAddress &addr = vAddr[i]; | const CAddress &addr = vAddr[i]; | ||||
obj.pushKV("time", int(addr.nTime)); | obj.pushKV("time", int(addr.nTime)); | ||||
obj.pushKV("services", uint64_t(addr.nServices)); | obj.pushKV("services", uint64_t(addr.nServices)); | ||||
Show All 32 Lines |