Skip to content

Commit

Permalink
add connection type to RPC
Browse files Browse the repository at this point in the history
  • Loading branch information
amitiuttarwar committed Oct 11, 2023
1 parent aa752b1 commit 1273b6d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
18 changes: 18 additions & 0 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3911,6 +3911,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
1 change: 1 addition & 0 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,7 @@ class CConnman
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
10 changes: 6 additions & 4 deletions src/rpc/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ static RPCHelpMan getpeermemoryinfo()
{
{
{RPCResult::Type::NUM, "id", "Peer id"},
{RPCResult::Type::NUM, "dynamic-cnode-memory", "the result of CNode::DynamicMemoryUsage"},
{RPCResult::Type::NUM, "dynamic-peer-memory", "the result of PeerManagerImpl::DynamicMemoryUsage"},
{RPCResult::Type::NUM, "dynamic_cnode_memory", "the result of CNode::DynamicMemoryUsage"},
{RPCResult::Type::NUM, "dynamic_peer_memory", "the result of PeerManagerImpl::DynamicMemoryUsage"},
{RPCResult::Type::STR, "connection_type", "Type of connection: \n" + Join(CONNECTION_TYPE_DOC, ",\n") + ".\n"},
}},
}},
},
Expand All @@ -135,11 +136,12 @@ static RPCHelpMan getpeermemoryinfo()
for (const auto& [node_id, node_memory] : info) {
UniValue obj(UniValue::VOBJ);
obj.pushKV("id", node_id);
obj.pushKV("dynamic-cnode-memory", node_memory);
obj.pushKV("dynamic_cnode_memory", node_memory);

auto peer_memory = peerman.GetPeerMemory(node_id);
obj.pushKV("dynamic-peer-memory", peer_memory);
obj.pushKV("dynamic_peer_memory", peer_memory);

obj.pushKV("connection_type", connman.NodeToString(node_id));
ret.push_back(obj);
}

Expand Down

0 comments on commit 1273b6d

Please sign in to comment.