Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/net.cpp
Show All 34 Lines | RPCHelpMan{ | ||||
"Returns the number of connections to other nodes.\n", | "Returns the number of connections to other nodes.\n", | ||||
{}, | {}, | ||||
RPCResult{"n (numeric) The connection count\n"}, | RPCResult{"n (numeric) The connection count\n"}, | ||||
RPCExamples{HelpExampleCli("getconnectioncount", "") + | RPCExamples{HelpExampleCli("getconnectioncount", "") + | ||||
HelpExampleRpc("getconnectioncount", "")}, | HelpExampleRpc("getconnectioncount", "")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
if (!g_rpc_node->connman) { | NodeContext &node = EnsureNodeContext(request.context); | ||||
if (!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_rpc_node->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) { | ||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"ping", | "ping", | ||||
"Requests that a ping be sent to all other nodes, to measure ping " | "Requests that a ping be sent to all other nodes, to measure ping " | ||||
"time.\n" | "time.\n" | ||||
"Results provided in getpeerinfo, pingtime and pingwait fields are " | "Results provided in getpeerinfo, pingtime and pingwait fields are " | ||||
"decimal seconds.\n" | "decimal seconds.\n" | ||||
"Ping command is handled in queue with all other commands, so it " | "Ping command is handled in queue with all other commands, so it " | ||||
"measures processing backlog, not just network ping.\n", | "measures processing backlog, not just network ping.\n", | ||||
{}, | {}, | ||||
RPCResults{}, | RPCResults{}, | ||||
RPCExamples{HelpExampleCli("ping", "") + HelpExampleRpc("ping", "")}, | RPCExamples{HelpExampleCli("ping", "") + HelpExampleRpc("ping", "")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
if (!g_rpc_node->connman) { | NodeContext &node = EnsureNodeContext(request.context); | ||||
if (!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_rpc_node->connman->ForEachNode( | g_rpc_node->connman->ForEachNode( | ||||
[](CNode *pnode) { pnode->fPingQueued = true; }); | [](CNode *pnode) { pnode->fPingQueued = true; }); | ||||
▲ Show 20 Lines • Show All 96 Lines • ▼ Show 20 Lines | RPCHelpMan{ | ||||
" }\n" | " }\n" | ||||
" ,...\n" | " ,...\n" | ||||
"]\n"}, | "]\n"}, | ||||
RPCExamples{HelpExampleCli("getpeerinfo", "") + | RPCExamples{HelpExampleCli("getpeerinfo", "") + | ||||
HelpExampleRpc("getpeerinfo", "")}, | HelpExampleRpc("getpeerinfo", "")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
if (!g_rpc_node->connman) { | NodeContext &node = EnsureNodeContext(request.context); | ||||
if (!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_rpc_node->connman->GetNodeStats(vstats); | g_rpc_node->connman->GetNodeStats(vstats); | ||||
▲ Show 20 Lines • Show All 106 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_rpc_node->connman) { | NodeContext &node = EnsureNodeContext(request.context); | ||||
if (!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") { | ||||
Show All 35 Lines | RPCHelpMan{ | ||||
RPCResults{}, | RPCResults{}, | ||||
RPCExamples{HelpExampleCli("disconnectnode", "\"192.168.0.6:8333\"") + | RPCExamples{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")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
if (!g_rpc_node->connman) { | NodeContext &node = EnsureNodeContext(request.context); | ||||
if (!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]; | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | RPCHelpMan{ | ||||
" }\n" | " }\n" | ||||
" ,...\n" | " ,...\n" | ||||
"]\n"}, | "]\n"}, | ||||
RPCExamples{HelpExampleCli("getaddednodeinfo", "\"192.168.0.201\"") + | RPCExamples{HelpExampleCli("getaddednodeinfo", "\"192.168.0.201\"") + | ||||
HelpExampleRpc("getaddednodeinfo", "\"192.168.0.201\"")}, | HelpExampleRpc("getaddednodeinfo", "\"192.168.0.201\"")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
if (!g_rpc_node->connman) { | NodeContext &node = EnsureNodeContext(request.context); | ||||
if (!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_rpc_node->connman->GetAddedNodeInfo(); | std::vector<AddedNodeInfo> vInfo = g_rpc_node->connman->GetAddedNodeInfo(); | ||||
if (!request.params[0].isNull()) { | if (!request.params[0].isNull()) { | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | RPCHelpMan{ | ||||
"Seconds left in current time cycle\n" | "Seconds left in current time cycle\n" | ||||
" }\n" | " }\n" | ||||
"}\n"}, | "}\n"}, | ||||
RPCExamples{HelpExampleCli("getnettotals", "") + | RPCExamples{HelpExampleCli("getnettotals", "") + | ||||
HelpExampleRpc("getnettotals", "")}, | HelpExampleRpc("getnettotals", "")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
if (!g_rpc_node->connman) { | NodeContext &node = EnsureNodeContext(request.context); | ||||
if (!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_rpc_node->connman->GetTotalBytesRecv()); | obj.pushKV("totalbytesrecv", g_rpc_node->connman->GetTotalBytesRecv()); | ||||
obj.pushKV("totalbytessent", g_rpc_node->connman->GetTotalBytesSent()); | obj.pushKV("totalbytessent", g_rpc_node->connman->GetTotalBytesSent()); | ||||
▲ Show 20 Lines • Show All 110 Lines • ▼ Show 20 Lines | static UniValue getnetworkinfo(const Config &config, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
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_rpc_node->connman) { | NodeContext &node = EnsureNodeContext(request.context); | ||||
if (node.connman) { | |||||
ServiceFlags services = g_rpc_node->connman->GetLocalServices(); | ServiceFlags services = g_rpc_node->connman->GetLocalServices(); | ||||
obj.pushKV("localservices", strprintf("%016x", services)); | obj.pushKV("localservices", strprintf("%016x", services)); | ||||
obj.pushKV("localservicesnames", GetServicesNames(services)); | obj.pushKV("localservicesnames", GetServicesNames(services)); | ||||
} | } | ||||
obj.pushKV("localrelay", g_relay_txes); | obj.pushKV("localrelay", g_relay_txes); | ||||
obj.pushKV("timeoffset", GetTimeOffset()); | obj.pushKV("timeoffset", GetTimeOffset()); | ||||
if (g_rpc_node->connman) { | if (g_rpc_node->connman) { | ||||
obj.pushKV("networkactive", g_rpc_node->connman->GetNetworkActive()); | obj.pushKV("networkactive", g_rpc_node->connman->GetNetworkActive()); | ||||
▲ Show 20 Lines • Show All 52 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_rpc_node->banman) { | NodeContext &node = EnsureNodeContext(request.context); | ||||
if (!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 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | RPCHelpMan{ | ||||
"List all manually banned IPs/Subnets.\n", | "List all manually banned IPs/Subnets.\n", | ||||
{}, | {}, | ||||
RPCResults{}, | RPCResults{}, | ||||
RPCExamples{HelpExampleCli("listbanned", "") + | RPCExamples{HelpExampleCli("listbanned", "") + | ||||
HelpExampleRpc("listbanned", "")}, | HelpExampleRpc("listbanned", "")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
if (!g_rpc_node->banman) { | NodeContext &node = EnsureNodeContext(request.context); | ||||
if (!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_rpc_node->banman->GetBanned(banMap); | g_rpc_node->banman->GetBanned(banMap); | ||||
UniValue bannedAddresses(UniValue::VARR); | UniValue bannedAddresses(UniValue::VARR); | ||||
Show All 17 Lines | RPCHelpMan{ | ||||
"Clear all banned IPs.\n", | "Clear all banned IPs.\n", | ||||
{}, | {}, | ||||
RPCResults{}, | RPCResults{}, | ||||
RPCExamples{HelpExampleCli("clearbanned", "") + | RPCExamples{HelpExampleCli("clearbanned", "") + | ||||
HelpExampleRpc("clearbanned", "")}, | HelpExampleRpc("clearbanned", "")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
if (!g_rpc_node->banman) { | NodeContext &node = EnsureNodeContext(request.context); | ||||
if (!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_rpc_node->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) { | ||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"setnetworkactive", | "setnetworkactive", | ||||
"Disable/enable all p2p network activity.\n", | "Disable/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{""}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
if (!g_rpc_node->connman) { | NodeContext &node = EnsureNodeContext(request.context); | ||||
if (!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_rpc_node->connman->SetNetworkActive(request.params[0].get_bool()); | g_rpc_node->connman->SetNetworkActive(request.params[0].get_bool()); | ||||
return g_rpc_node->connman->GetNetworkActive(); | return g_rpc_node->connman->GetNetworkActive(); | ||||
Show All 25 Lines | RPCHelpMan{ | ||||
" }\n" | " }\n" | ||||
" ,....\n" | " ,....\n" | ||||
"]\n"}, | "]\n"}, | ||||
RPCExamples{HelpExampleCli("getnodeaddresses", "8") + | RPCExamples{HelpExampleCli("getnodeaddresses", "8") + | ||||
HelpExampleRpc("getnodeaddresses", "8")}, | HelpExampleRpc("getnodeaddresses", "8")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
if (!g_rpc_node->connman) { | NodeContext &node = EnsureNodeContext(request.context); | ||||
if (!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"); | ||||
} | } | ||||
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(); | ||||
▲ Show 20 Lines • Show All 47 Lines • Show Last 20 Lines |