Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/net.cpp
Show First 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | static UniValue ping(const Config &config, const JSONRPCRequest &request) { | ||||
// 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_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( | throw std::runtime_error( | ||||
"getpeerinfo\n" | "getpeerinfo\n" | ||||
"\nReturns data about each connected network node as a json array " | "\nReturns data about each connected network node as a json array " | ||||
"of objects.\n" | "of objects.\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"[\n" | "[\n" | ||||
" {\n" | " {\n" | ||||
" \"id\": n, (numeric) Peer index\n" | " \"id\": n, (numeric) Peer index\n" | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() != 0) { | ||||
" ...\n" | " ...\n" | ||||
" }\n" | " }\n" | ||||
" }\n" | " }\n" | ||||
" ,...\n" | " ,...\n" | ||||
"]\n" | "]\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("getpeerinfo", "") + | HelpExampleCli("getpeerinfo", "") + | ||||
HelpExampleRpc("getpeerinfo", "")); | HelpExampleRpc("getpeerinfo", "")); | ||||
} | |||||
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<CNodeStats> vstats; | std::vector<CNodeStats> vstats; | ||||
g_connman->GetNodeStats(vstats); | g_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.push_back(Pair("id", stats.nodeid)); | obj.push_back(Pair("id", stats.nodeid)); | ||||
obj.push_back(Pair("addr", stats.addrName)); | obj.push_back(Pair("addr", stats.addrName)); | ||||
if (!(stats.addrLocal.empty())) | if (!(stats.addrLocal.empty())) { | ||||
obj.push_back(Pair("addrlocal", stats.addrLocal)); | obj.push_back(Pair("addrlocal", stats.addrLocal)); | ||||
} | |||||
obj.push_back(Pair("services", strprintf("%016x", stats.nServices))); | obj.push_back(Pair("services", strprintf("%016x", stats.nServices))); | ||||
obj.push_back(Pair("relaytxes", stats.fRelayTxes)); | obj.push_back(Pair("relaytxes", stats.fRelayTxes)); | ||||
obj.push_back(Pair("lastsend", stats.nLastSend)); | obj.push_back(Pair("lastsend", stats.nLastSend)); | ||||
obj.push_back(Pair("lastrecv", stats.nLastRecv)); | obj.push_back(Pair("lastrecv", stats.nLastRecv)); | ||||
obj.push_back(Pair("bytessent", stats.nSendBytes)); | obj.push_back(Pair("bytessent", stats.nSendBytes)); | ||||
obj.push_back(Pair("bytesrecv", stats.nRecvBytes)); | obj.push_back(Pair("bytesrecv", stats.nRecvBytes)); | ||||
obj.push_back(Pair("conntime", stats.nTimeConnected)); | obj.push_back(Pair("conntime", stats.nTimeConnected)); | ||||
obj.push_back(Pair("timeoffset", stats.nTimeOffset)); | obj.push_back(Pair("timeoffset", stats.nTimeOffset)); | ||||
if (stats.dPingTime > 0.0) | if (stats.dPingTime > 0.0) { | ||||
obj.push_back(Pair("pingtime", stats.dPingTime)); | obj.push_back(Pair("pingtime", stats.dPingTime)); | ||||
if (stats.dMinPing < std::numeric_limits<int64_t>::max() / 1e6) | } | ||||
if (stats.dMinPing < std::numeric_limits<int64_t>::max() / 1e6) { | |||||
obj.push_back(Pair("minping", stats.dMinPing)); | obj.push_back(Pair("minping", stats.dMinPing)); | ||||
if (stats.dPingWait > 0.0) | } | ||||
if (stats.dPingWait > 0.0) { | |||||
obj.push_back(Pair("pingwait", stats.dPingWait)); | obj.push_back(Pair("pingwait", stats.dPingWait)); | ||||
} | |||||
obj.push_back(Pair("version", stats.nVersion)); | obj.push_back(Pair("version", stats.nVersion)); | ||||
// Use the sanitized form of subver here, to avoid tricksy remote peers | // Use the sanitized form of subver here, to avoid tricksy remote peers | ||||
// from corrupting or modifying the JSON output by putting special | // from corrupting or modifying the JSON output by putting special | ||||
// characters in their ver message. | // characters in their ver message. | ||||
obj.push_back(Pair("subver", stats.cleanSubVer)); | obj.push_back(Pair("subver", stats.cleanSubVer)); | ||||
obj.push_back(Pair("inbound", stats.fInbound)); | obj.push_back(Pair("inbound", stats.fInbound)); | ||||
obj.push_back(Pair("addnode", stats.fAddnode)); | obj.push_back(Pair("addnode", stats.fAddnode)); | ||||
obj.push_back(Pair("startingheight", stats.nStartingHeight)); | obj.push_back(Pair("startingheight", stats.nStartingHeight)); | ||||
if (fStateStats) { | if (fStateStats) { | ||||
obj.push_back(Pair("banscore", statestats.nMisbehavior)); | obj.push_back(Pair("banscore", statestats.nMisbehavior)); | ||||
obj.push_back(Pair("synced_headers", statestats.nSyncHeight)); | obj.push_back(Pair("synced_headers", statestats.nSyncHeight)); | ||||
obj.push_back(Pair("synced_blocks", statestats.nCommonHeight)); | obj.push_back(Pair("synced_blocks", statestats.nCommonHeight)); | ||||
UniValue heights(UniValue::VARR); | UniValue heights(UniValue::VARR); | ||||
for (int height : statestats.vHeightInFlight) { | for (int height : statestats.vHeightInFlight) { | ||||
heights.push_back(height); | heights.push_back(height); | ||||
} | } | ||||
obj.push_back(Pair("inflight", heights)); | obj.push_back(Pair("inflight", heights)); | ||||
} | } | ||||
obj.push_back(Pair("whitelisted", stats.fWhitelisted)); | obj.push_back(Pair("whitelisted", stats.fWhitelisted)); | ||||
obj.push_back(Pair("cashmagic", stats.fUsesCashMagic)); | |||||
UniValue sendPerMsgCmd(UniValue::VOBJ); | UniValue sendPerMsgCmd(UniValue::VOBJ); | ||||
for (const mapMsgCmdSize::value_type &i : stats.mapSendBytesPerMsgCmd) { | for (const mapMsgCmdSize::value_type &i : stats.mapSendBytesPerMsgCmd) { | ||||
if (i.second > 0) sendPerMsgCmd.push_back(Pair(i.first, i.second)); | if (i.second > 0) { | ||||
sendPerMsgCmd.push_back(Pair(i.first, i.second)); | |||||
} | |||||
} | } | ||||
obj.push_back(Pair("bytessent_per_msg", sendPerMsgCmd)); | obj.push_back(Pair("bytessent_per_msg", sendPerMsgCmd)); | ||||
UniValue recvPerMsgCmd(UniValue::VOBJ); | UniValue recvPerMsgCmd(UniValue::VOBJ); | ||||
for (const mapMsgCmdSize::value_type &i : stats.mapRecvBytesPerMsgCmd) { | for (const mapMsgCmdSize::value_type &i : stats.mapRecvBytesPerMsgCmd) { | ||||
if (i.second > 0) recvPerMsgCmd.push_back(Pair(i.first, i.second)); | if (i.second > 0) { | ||||
recvPerMsgCmd.push_back(Pair(i.first, i.second)); | |||||
} | |||||
} | } | ||||
obj.push_back(Pair("bytesrecv_per_msg", recvPerMsgCmd)); | obj.push_back(Pair("bytesrecv_per_msg", recvPerMsgCmd)); | ||||
ret.push_back(obj); | ret.push_back(obj); | ||||
} | } | ||||
return ret; | return ret; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 548 Lines • Show Last 20 Lines |