From 58340cef63167fba6b62d2e9fd3f5c196cf2d377 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com> Date: Fri, 1 Mar 2019 17:06:27 +0100 Subject: [PATCH 1/9] merge bitcoin#16787: Human readable network services --- src/rpc/net.cpp | 16 ++++++++++++++-- src/rpc/util.cpp | 17 +++++++++++++++++ src/rpc/util.h | 4 ++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index 93a2816bbd..b2e302aec5 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -90,6 +90,10 @@ static UniValue getpeerinfo(const JSONRPCRequest& request) " \"verified_pubkey_hash\": h, (hex) Only present when the peer is a masternode and successfully\n" " authenticated via MNAUTH. In this case, this field contains the\n" " hash of the masternode's operator public key\n" + " \"servicesnames\":[ (array) the services offered, in human-readable form\n" + " \"SERVICE_NAME\", (string) the service name if it is recognised\n" + " ...\n" + " ],\n" " \"relaytxes\":true|false, (boolean) Whether peer has asked us to relay transactions to it\n" " \"lastsend\": ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) of the last send\n" " \"lastrecv\": ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) of the last receive\n" @@ -162,6 +166,7 @@ static UniValue getpeerinfo(const JSONRPCRequest& request) if (!stats.verifiedPubKeyHash.IsNull()) { obj.pushKV("verified_pubkey_hash", stats.verifiedPubKeyHash.ToString()); } + obj.pushKV("servicesnames", GetServicesNames(stats.nServices)); obj.pushKV("relaytxes", stats.fRelayTxes); obj.pushKV("lastsend", stats.nLastSend); obj.pushKV("lastrecv", stats.nLastRecv); @@ -458,6 +463,10 @@ static UniValue getnetworkinfo(const JSONRPCRequest& request) " \"subversion\": \"/Dash Core:x.x.x.x/\", (string) the server subversion string\n" " \"protocolversion\": xxxxx, (numeric) the protocol version\n" " \"localservices\": \"xxxxxxxxxxxxxxxx\", (string) the services we offer to the network\n" + " \"localservicesnames\": [ (array) the services we offer to the network, in human-readable form\n" + " \"SERVICE_NAME\", (string) the service name\n" + " ...\n" + " ],\n" " \"localrelay\": true|false, (bool) true if transaction relay is requested from peers\n" " \"timeoffset\": xxxxx, (numeric) the time offset\n" " \"connections\": xxxxx, (numeric) the number of connections\n" @@ -496,8 +505,11 @@ static UniValue getnetworkinfo(const JSONRPCRequest& request) obj.pushKV("buildversion", FormatFullVersion()); obj.pushKV("subversion", strSubVersion); obj.pushKV("protocolversion",PROTOCOL_VERSION); - if(g_connman) - obj.pushKV("localservices", strprintf("%016x", g_connman->GetLocalServices())); + if (g_connman) { + ServiceFlags services = g_connman->GetLocalServices(); + obj.pushKV("localservices", strprintf("%016x", services)); + obj.pushKV("localservicesnames", GetServicesNames(services)); + } obj.pushKV("localrelay", g_relay_txes); obj.pushKV("timeoffset", GetTimeOffset()); if (g_connman) { diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp index 66707c0fa8..710962d211 100644 --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -224,3 +224,20 @@ UniValue JSONRPCTransactionError(TransactionError terr, const std::string& err_s } } +UniValue GetServicesNames(ServiceFlags services) +{ + UniValue servicesNames(UniValue::VARR); + + if (services & NODE_NETWORK) + servicesNames.push_back("NETWORK"); + if (services & NODE_GETUTXO) + servicesNames.push_back("GETUTXO"); + if (services & NODE_BLOOM) + servicesNames.push_back("BLOOM"); + if (services & NODE_XTHIN) + servicesNames.push_back("XTHIN"); + if (services & NODE_NETWORK_LIMITED) + servicesNames.push_back("NETWORK_LIMITED"); + + return servicesNames; +} diff --git a/src/rpc/util.h b/src/rpc/util.h index 6d2995becb..5e119d63f9 100644 --- a/src/rpc/util.h +++ b/src/rpc/util.h @@ -7,6 +7,7 @@ #include #include +#include #include #include