From 2974fa20bb6c1709fda539fe63f1ed11d713a36b Mon Sep 17 00:00:00 2001 From: Odysseas Gabrielides Date: Fri, 15 Jul 2022 00:13:47 +0300 Subject: [PATCH] feat(rpc): getnetworkinfo RPC enrichment response (#4913) * Enrich getnetworkinfo * Adjustements --- src/net.cpp | 3 +++ src/net.h | 3 +++ src/rpc/net.cpp | 12 +++++++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/net.cpp b/src/net.cpp index 9896121535..432a2a2741 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -3400,6 +3400,9 @@ size_t CConnman::GetNodeCount(NumConnections flags) if (pnode->fDisconnect) { continue; } + if ((flags & CONNECTIONS_VERIFIED) && pnode->GetVerifiedProRegTxHash().IsNull()) { + continue; + } if (flags & (pnode->fInbound ? CONNECTIONS_IN : CONNECTIONS_OUT)) { nNum++; } diff --git a/src/net.h b/src/net.h index fe81741c80..f90db84089 100644 --- a/src/net.h +++ b/src/net.h @@ -146,6 +146,9 @@ public: CONNECTIONS_IN = (1U << 0), CONNECTIONS_OUT = (1U << 1), CONNECTIONS_ALL = (CONNECTIONS_IN | CONNECTIONS_OUT), + CONNECTIONS_VERIFIED = (1U << 2), + CONNECTIONS_VERIFIED_IN = (CONNECTIONS_VERIFIED | CONNECTIONS_IN), + CONNECTIONS_VERIFIED_OUT = (CONNECTIONS_VERIFIED | CONNECTIONS_OUT), }; enum SocketEventsMode { diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index 848cc68b51..c9d0dbdee3 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -490,7 +490,12 @@ static UniValue getnetworkinfo(const JSONRPCRequest& request) }}, {RPCResult::Type::BOOL, "localrelay", "true if transaction relay is requested from peers"}, {RPCResult::Type::NUM, "timeoffset", "the time offset"}, - {RPCResult::Type::NUM, "connections", "the number of connections"}, + {RPCResult::Type::NUM, "connections", "the number of inbound and outbound connections"}, + {RPCResult::Type::NUM, "inboundconnections", "the number of inbound connections"}, + {RPCResult::Type::NUM, "outboundconnections", "the number of outbound connections"}, + {RPCResult::Type::NUM, "mnconnections", "the number of verified mn connections"}, + {RPCResult::Type::NUM, "inboundmnconnections", "the number of inbound verified mn connections"}, + {RPCResult::Type::NUM, "outboundmnconnections", "the number of outbound verified mn connections"}, {RPCResult::Type::BOOL, "networkactive", "whether p2p networking is enabled"}, {RPCResult::Type::STR, "socketevents", "the socket events mode, either kqueue, epoll, poll or select"}, {RPCResult::Type::ARR, "networks", "information per network", @@ -541,6 +546,11 @@ static UniValue getnetworkinfo(const JSONRPCRequest& request) if (node.connman) { obj.pushKV("networkactive", node.connman->GetNetworkActive()); obj.pushKV("connections", (int)node.connman->GetNodeCount(CConnman::CONNECTIONS_ALL)); + obj.pushKV("inboundconnections", (int)node.connman->GetNodeCount(CConnman::CONNECTIONS_IN)); + obj.pushKV("outboundconnections", (int)node.connman->GetNodeCount(CConnman::CONNECTIONS_OUT)); + obj.pushKV("mnconnections", (int)node.connman->GetNodeCount(CConnman::CONNECTIONS_VERIFIED)); + obj.pushKV("inboundmnconnections", (int)node.connman->GetNodeCount(CConnman::CONNECTIONS_VERIFIED_IN)); + obj.pushKV("outboundmnconnections", (int)node.connman->GetNodeCount(CConnman::CONNECTIONS_VERIFIED_OUT)); std::string strSocketEvents; switch (node.connman->GetSocketEventsMode()) { case CConnman::SOCKETEVENTS_SELECT: