Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/net.cpp
Show First 20 Lines • Show All 918 Lines • ▼ Show 20 Lines | |||||
static UniValue getnodeaddresses(const Config &config, | static UniValue getnodeaddresses(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"getnodeaddresses", | "getnodeaddresses", | ||||
"Return known addresses which can potentially be used to find new " | "Return known addresses which can potentially be used to find new " | ||||
"nodes in the network\n", | "nodes in the network\n", | ||||
{ | { | ||||
{"count", RPCArg::Type::NUM, /* default */ "1", | {"count", RPCArg::Type::NUM, /* default */ "1", | ||||
"How many addresses to return. Limited to the smaller of " + | "The maximum number of addresses to return. Specify 0 to return " | ||||
ToString(ADDRMAN_GETADDR_MAX) + " or " + | "all known addresses."}, | ||||
ToString(ADDRMAN_GETADDR_MAX_PCT) + | |||||
"% of all known addresses."}, | |||||
}, | }, | ||||
RPCResult{ | RPCResult{ | ||||
RPCResult::Type::ARR, | RPCResult::Type::ARR, | ||||
"", | "", | ||||
"", | "", | ||||
{ | { | ||||
{RPCResult::Type::OBJ, | {RPCResult::Type::OBJ, | ||||
"", | "", | ||||
Show All 18 Lines | 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(); | ||||
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 = node.connman->GetAddresses(); | std::vector<CAddress> vAddr = | ||||
node.connman->GetAddresses(count, /* max_pct */ 0); | |||||
UniValue ret(UniValue::VARR); | UniValue ret(UniValue::VARR); | ||||
int address_return_count = std::min<int>(count, vAddr.size()); | for (const CAddress &addr : vAddr) { | ||||
for (int i = 0; i < address_return_count; ++i) { | |||||
UniValue obj(UniValue::VOBJ); | UniValue obj(UniValue::VOBJ); | ||||
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)); | ||||
obj.pushKV("address", addr.ToStringIP()); | obj.pushKV("address", addr.ToStringIP()); | ||||
obj.pushKV("port", addr.GetPort()); | obj.pushKV("port", addr.GetPort()); | ||||
ret.push_back(obj); | ret.push_back(obj); | ||||
} | } | ||||
return ret; | return ret; | ||||
} | } | ||||
Show All 26 Lines |