Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/net.cpp
Show First 20 Lines • Show All 779 Lines • ▼ Show 20 Lines | if (!g_connman) { | ||||
"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_connman->SetNetworkActive(request.params[0].get_bool()); | ||||
return g_connman->GetNetworkActive(); | return g_connman->GetNetworkActive(); | ||||
} | } | ||||
static UniValue getnodeaddresses(const Config &config, | |||||
const JSONRPCRequest &request) { | |||||
if (request.fHelp || request.params.size() > 1) { | |||||
throw std::runtime_error( | |||||
"getnodeaddresses ( count )\n" | |||||
"\nReturn known addresses which can potentially be used to find " | |||||
"new nodes in the network\n" | |||||
"\nArguments:\n" | |||||
"1. \"count\" (numeric, optional) How many addresses to return. " | |||||
"Limited to the smaller of " + | |||||
std::to_string(ADDRMAN_GETADDR_MAX) + " or " + | |||||
std::to_string(ADDRMAN_GETADDR_MAX_PCT) + | |||||
"% of all known addresses. (default = 1)\n" | |||||
"\nResult:\n" | |||||
"[\n" | |||||
" {\n" | |||||
" \"time\": ttt, (numeric) Timestamp in seconds " | |||||
"since epoch (Jan 1 1970 GMT) keeping track of when the node was " | |||||
"last seen\n" | |||||
" \"services\": n, (numeric) The services offered\n" | |||||
" \"address\": \"host\", (string) The address of the " | |||||
"node\n" | |||||
" \"port\": n (numeric) The port of the node\n" | |||||
" }\n" | |||||
" ,....\n" | |||||
"]\n" | |||||
"\nExamples:\n" + | |||||
HelpExampleCli("getnodeaddresses", "8") + | |||||
HelpExampleRpc("getnodeaddresses", "8")); | |||||
} | |||||
if (!g_connman) { | |||||
throw JSONRPCError( | |||||
RPC_CLIENT_P2P_DISABLED, | |||||
"Error: Peer-to-peer functionality missing or disabled"); | |||||
} | |||||
int count = 1; | |||||
if (!request.params[0].isNull()) { | |||||
count = request.params[0].get_int(); | |||||
if (count <= 0) { | |||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | |||||
"Address count out of range"); | |||||
} | |||||
} | |||||
// returns a shuffled list of CAddress | |||||
std::vector<CAddress> vAddr = g_connman->GetAddresses(); | |||||
UniValue ret(UniValue::VARR); | |||||
int address_return_count = std::min<int>(count, vAddr.size()); | |||||
for (int i = 0; i < address_return_count; ++i) { | |||||
UniValue obj(UniValue::VOBJ); | |||||
const CAddress &addr = vAddr[i]; | |||||
obj.pushKV("time", int(addr.nTime)); | |||||
obj.pushKV("services", uint64_t(addr.nServices)); | |||||
obj.pushKV("address", addr.ToStringIP()); | |||||
obj.pushKV("port", addr.GetPort()); | |||||
ret.push_back(obj); | |||||
} | |||||
return ret; | |||||
} | |||||
// clang-format off | // clang-format off | ||||
static const ContextFreeRPCCommand commands[] = { | static const ContextFreeRPCCommand commands[] = { | ||||
// category name actor (function) argNames | // category name actor (function) argNames | ||||
// ------------------- ------------------------ ---------------------- ---------- | // ------------------- ------------------------ ---------------------- ---------- | ||||
{ "network", "getconnectioncount", getconnectioncount, {} }, | { "network", "getconnectioncount", getconnectioncount, {} }, | ||||
{ "network", "ping", ping, {} }, | { "network", "ping", ping, {} }, | ||||
{ "network", "getpeerinfo", getpeerinfo, {} }, | { "network", "getpeerinfo", getpeerinfo, {} }, | ||||
{ "network", "addnode", addnode, {"node","command"} }, | { "network", "addnode", addnode, {"node","command"} }, | ||||
{ "network", "disconnectnode", disconnectnode, {"address", "nodeid"} }, | { "network", "disconnectnode", disconnectnode, {"address", "nodeid"} }, | ||||
{ "network", "getaddednodeinfo", getaddednodeinfo, {"node"} }, | { "network", "getaddednodeinfo", getaddednodeinfo, {"node"} }, | ||||
{ "network", "getnettotals", getnettotals, {} }, | { "network", "getnettotals", getnettotals, {} }, | ||||
{ "network", "getnetworkinfo", getnetworkinfo, {} }, | { "network", "getnetworkinfo", getnetworkinfo, {} }, | ||||
{ "network", "setban", setban, {"subnet", "command", "bantime", "absolute"} }, | { "network", "setban", setban, {"subnet", "command", "bantime", "absolute"} }, | ||||
{ "network", "listbanned", listbanned, {} }, | { "network", "listbanned", listbanned, {} }, | ||||
{ "network", "clearbanned", clearbanned, {} }, | { "network", "clearbanned", clearbanned, {} }, | ||||
{ "network", "setnetworkactive", setnetworkactive, {"state"} }, | { "network", "setnetworkactive", setnetworkactive, {"state"} }, | ||||
{ "network", "getnodeaddresses", getnodeaddresses, {"count"} }, | |||||
}; | }; | ||||
// clang-format on | // clang-format on | ||||
void RegisterNetRPCCommands(CRPCTable &t) { | void RegisterNetRPCCommands(CRPCTable &t) { | ||||
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) { | for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) { | ||||
t.appendCommand(commands[vcidx].name, &commands[vcidx]); | t.appendCommand(commands[vcidx].name, &commands[vcidx]); | ||||
} | } | ||||
} | } |