Skip to content

Commit

Permalink
expose cnode info for RPC
Browse files Browse the repository at this point in the history
  • Loading branch information
amitiuttarwar committed Nov 9, 2023
1 parent 38bb1cb commit cd930ac
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3698,6 +3698,14 @@ uint32_t CConnman::GetMappedAS(const CNetAddr& addr) const
return m_netgroupman.GetMappedAS(addr);
}

void CConnman::GetNodeMemory(std::map<NodeId, size_t>& info) const
{
LOCK(m_nodes_mutex);
for (CNode* pnode : m_nodes) {
info[pnode->GetId()] = pnode->DynamicMemoryUsage();
}
}

void CConnman::GetNodeStats(std::vector<CNodeStats>& vstats) const
{
vstats.clear();
Expand Down Expand Up @@ -4003,6 +4011,24 @@ bool CConnman::ForNode(NodeId id, std::function<bool(CNode* pnode)> 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);
Expand Down
2 changes: 2 additions & 0 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,8 @@ class CConnman
size_t GetNodeCount(ConnectionDirection) const;
uint32_t GetMappedAS(const CNetAddr& addr) const;
void GetNodeStats(std::vector<CNodeStats>& vstats) const;
void GetNodeMemory(std::map<NodeId, size_t>& info) const;
std::string NodeToString(NodeId id) const;
bool DisconnectNode(const std::string& node);
bool DisconnectNode(const CSubNet& subnet);
bool DisconnectNode(const CNetAddr& addr);
Expand Down

0 comments on commit cd930ac

Please sign in to comment.