From cd930acbee8b2f76fc8045b33b41ea9b4a4df7e4 Mon Sep 17 00:00:00 2001 From: Amiti Uttarwar Date: Mon, 6 Nov 2023 12:19:04 -0800 Subject: [PATCH] expose cnode info for RPC --- src/net.cpp | 26 ++++++++++++++++++++++++++ src/net.h | 2 ++ 2 files changed, 28 insertions(+) diff --git a/src/net.cpp b/src/net.cpp index af3cd8fd35f022..792486269bf794 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -3698,6 +3698,14 @@ uint32_t CConnman::GetMappedAS(const CNetAddr& addr) const return m_netgroupman.GetMappedAS(addr); } +void CConnman::GetNodeMemory(std::map& info) const +{ + LOCK(m_nodes_mutex); + for (CNode* pnode : m_nodes) { + info[pnode->GetId()] = pnode->DynamicMemoryUsage(); + } +} + void CConnman::GetNodeStats(std::vector& vstats) const { vstats.clear(); @@ -4003,6 +4011,24 @@ bool CConnman::ForNode(NodeId id, std::function func) return found != nullptr && NodeFullyConnected(found) && func(found); } +std::string CConnman::NodeToString(NodeId id) const +{ + CNode* found = nullptr; + LOCK(m_nodes_mutex); + for (auto&& pnode : m_nodes) { + if(pnode->GetId() == id) { + found = pnode; + break; + } + } + + if (found != nullptr) { + return ConnectionTypeAsString(found->m_conn_type); + } else { + return ""; + } +} + CSipHasher CConnman::GetDeterministicRandomizer(uint64_t id) const { return CSipHasher(nSeed0, nSeed1).Write(id); diff --git a/src/net.h b/src/net.h index cd63a803dc0aba..708703e526846d 100644 --- a/src/net.h +++ b/src/net.h @@ -1235,6 +1235,8 @@ class CConnman size_t GetNodeCount(ConnectionDirection) const; uint32_t GetMappedAS(const CNetAddr& addr) const; void GetNodeStats(std::vector& vstats) const; + void GetNodeMemory(std::map& info) const; + std::string NodeToString(NodeId id) const; bool DisconnectNode(const std::string& node); bool DisconnectNode(const CSubNet& subnet); bool DisconnectNode(const CNetAddr& addr);