Skip to content

Commit

Permalink
RPC hook up for peer dynamic infols
Browse files Browse the repository at this point in the history
  • Loading branch information
amitiuttarwar committed Oct 10, 2023
1 parent bab10ae commit d93dbc9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
6 changes: 6 additions & 0 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ class PeerManagerImpl final : public PeerManager
std::optional<std::string> FetchBlock(NodeId peer_id, const CBlockIndex& block_index) override
EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
size_t GetPeerMemory(NodeId nodeid) const override;
bool IgnoresIncomingTxs() override { return m_opts.ignore_incoming_txs; }
void SendPings() override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
void RelayTransaction(const uint256& txid, const uint256& wtxid) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
Expand Down Expand Up @@ -1597,6 +1598,11 @@ PeerRef PeerManagerImpl::RemovePeer(NodeId id)
return ret;
}

size_t PeerManagerImpl::GetPeerMemory(NodeId nodeid) const
{
return 0;
}

bool PeerManagerImpl::GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const
{
{
Expand Down
2 changes: 2 additions & 0 deletions src/net_processing.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class PeerManager : public CValidationInterface, public NetEventsInterface
/** Get statistics from node state */
virtual bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const = 0;

virtual size_t GetPeerMemory(NodeId nodeid) const = 0;

/** Whether this node ignores txs received over p2p. */
virtual bool IgnoresIncomingTxs() = 0;

Expand Down
30 changes: 11 additions & 19 deletions src/rpc/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ static RPCHelpMan getpeermemoryinfo()
{
{
{RPCResult::Type::NUM, "id", "Peer id"},
{RPCResult::Type::NUM, "memory", "the result of GetDynamicMemoryUsage for that node"},
{RPCResult::Type::NUM, "dynamic-cnode-memory", "the result of CNode::DynamicMemoryUsage"},
{RPCResult::Type::NUM, "dynamic-peer-memory", "the result of PeerManagerImpl::DynamicMemoryUsage"},
}},
}},
},
Expand All @@ -116,31 +117,22 @@ static RPCHelpMan getpeermemoryinfo()
{
NodeContext& node = EnsureAnyNodeContext(request.context);
const CConnman& connman = EnsureConnman(node);
//const PeerManager& peerman = EnsurePeerman(node);
const PeerManager& peerman = EnsurePeerman(node);

//std::vector<CNodeStats> vstats;
//connman.GetNodeStats(vstats);
UniValue ret(UniValue::VARR);

// map of node id -> memory usage
std::map<int64_t, size_t> info;
// call DynamicMemoryUsage on all CNode objects
connman.GetNodeMemory(info);
for (const auto& [node_id, node_memory] : info) {
UniValue obj(UniValue::VOBJ);
obj.pushKV("id", node_id);
obj.pushKV("dynamic-cnode-memory", node_memory);

UniValue ret(UniValue::VARR);

//for (const CNodeStats& stats : vstats) {
//UniValue obj(UniValue::VOBJ);
//CNodeStateStats statestats;
//obj.pushKV("id", stats.nodeid);
//obj.pushKV("addr", stats.m_addr_name);
//obj.pushKV("addr_relay_enabled", statestats.m_addr_relay_enabled);

//ret.push_back(obj);
//}
auto peer_memory = peerman.GetPeerMemory(node_id);
obj.pushKV("dynamic-peer-memory", peer_memory);

for (const auto& vals : info) {
UniValue obj(UniValue::VOBJ);
obj.pushKV("id", vals.first);
obj.pushKV("memory", vals.second);
ret.push_back(obj);
}

Expand Down

0 comments on commit d93dbc9

Please sign in to comment.