Skip to content

Commit aa82795

Browse files
committed
Add detailed network info to getnetworkinfo RPC
This commit adds per-network information to the getnetworkinfo RPC call: - Is the network limited? - Is the network reachable - Which proxy is used for this network, if any Inspired by #2575.
1 parent 075cf49 commit aa82795

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ std::string HelpMessage(HelpMessageMode mode)
248248
strUsage += " -maxreceivebuffer=<n> " + _("Maximum per-connection receive buffer, <n>*1000 bytes (default: 5000)") + "\n";
249249
strUsage += " -maxsendbuffer=<n> " + _("Maximum per-connection send buffer, <n>*1000 bytes (default: 1000)") + "\n";
250250
strUsage += " -onion=<ip:port> " + _("Use separate SOCKS5 proxy to reach peers via Tor hidden services (default: -proxy)") + "\n";
251-
strUsage += " -onlynet=<net> " + _("Only connect to nodes in network <net> (IPv4, IPv6 or Onion)") + "\n";
251+
strUsage += " -onlynet=<net> " + _("Only connect to nodes in network <net> (ipv4, ipv6 or onion)") + "\n";
252252
strUsage += " -permitbaremultisig " + _("Relay non-P2SH multisig (default: 1)") + "\n";
253253
strUsage += " -port=<port> " + _("Listen for connections on <port> (default: 8333 or testnet: 18333)") + "\n";
254254
strUsage += " -proxy=<ip:port> " + _("Connect through SOCKS5 proxy") + "\n";

src/rpcnet.cpp

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,26 @@ Value getnettotals(const Array& params, bool fHelp)
338338
return obj;
339339
}
340340

341+
static Array GetNetworksInfo()
342+
{
343+
Array networks;
344+
for(int n=0; n<NET_MAX; ++n)
345+
{
346+
enum Network network = static_cast<enum Network>(n);
347+
if(network == NET_UNROUTABLE)
348+
continue;
349+
proxyType proxy;
350+
Object obj;
351+
GetProxy(network, proxy);
352+
obj.push_back(Pair("name", GetNetworkName(network)));
353+
obj.push_back(Pair("limited", IsLimited(network)));
354+
obj.push_back(Pair("reachable", IsReachable(network)));
355+
obj.push_back(Pair("proxy", proxy.IsValid() ? proxy.ToStringIPPort() : string()));
356+
networks.push_back(obj);
357+
}
358+
return networks;
359+
}
360+
341361
Value getnetworkinfo(const Array& params, bool fHelp)
342362
{
343363
if (fHelp || params.size() != 0)
@@ -351,7 +371,13 @@ Value getnetworkinfo(const Array& params, bool fHelp)
351371
" \"localservices\": \"xxxxxxxxxxxxxxxx\", (string) the services we offer to the network\n"
352372
" \"timeoffset\": xxxxx, (numeric) the time offset\n"
353373
" \"connections\": xxxxx, (numeric) the number of connections\n"
354-
" \"proxy\": \"host:port\", (string, optional) the proxy used by the server\n"
374+
" \"networks\": [ (array) information per network\n"
375+
" \"name\": \"xxx\", (string) network (ipv4, ipv6 or onion)\n"
376+
" \"limited\": xxx, (boolean) is the network limited using -onlynet?\n"
377+
" \"reachable\": xxx, (boolean) is the network reachable?\n"
378+
" \"proxy\": \"host:port\" (string) the proxy that is used for this network, or empty if none\n"
379+
" },\n"
380+
" ],\n"
355381
" \"relayfee\": x.xxxx, (numeric) minimum relay fee for non-free transactions in btc/kb\n"
356382
" \"localaddresses\": [, (array) list of local addresses\n"
357383
" \"address\": \"xxxx\", (string) network address\n"
@@ -364,16 +390,13 @@ Value getnetworkinfo(const Array& params, bool fHelp)
364390
+ HelpExampleRpc("getnetworkinfo", "")
365391
);
366392

367-
proxyType proxy;
368-
GetProxy(NET_IPV4, proxy);
369-
370393
Object obj;
371394
obj.push_back(Pair("version", (int)CLIENT_VERSION));
372395
obj.push_back(Pair("protocolversion",(int)PROTOCOL_VERSION));
373396
obj.push_back(Pair("localservices", strprintf("%016x", nLocalServices)));
374397
obj.push_back(Pair("timeoffset", GetTimeOffset()));
375398
obj.push_back(Pair("connections", (int)vNodes.size()));
376-
obj.push_back(Pair("proxy", (proxy.IsValid() ? proxy.ToStringIPPort() : string())));
399+
obj.push_back(Pair("networks", GetNetworksInfo()));
377400
obj.push_back(Pair("relayfee", ValueFromAmount(::minRelayTxFee.GetFeePerK())));
378401
Array localAddresses;
379402
{

0 commit comments

Comments
 (0)