diff options
Diffstat (limited to 'src/interface')
-rw-r--r-- | src/interface/node.cpp | 26 | ||||
-rw-r--r-- | src/interface/node.h | 8 |
2 files changed, 34 insertions, 0 deletions
diff --git a/src/interface/node.cpp b/src/interface/node.cpp index 281164779d..1937fe9d9b 100644 --- a/src/interface/node.cpp +++ b/src/interface/node.cpp @@ -10,6 +10,7 @@ #include <interface/handler.h> #include <interface/wallet.h> #include <net.h> +#include <net_processing.h> #include <netaddress.h> #include <netbase.h> #include <primitives/block.h> @@ -79,6 +80,31 @@ class NodeImpl : public Node { return g_connman ? g_connman->GetNodeCount(flags) : 0; } + bool getNodesStats(NodesStats& stats) override + { + stats.clear(); + + if (g_connman) { + std::vector<CNodeStats> stats_temp; + g_connman->GetNodeStats(stats_temp); + + stats.reserve(stats_temp.size()); + for (auto& node_stats_temp : stats_temp) { + stats.emplace_back(std::move(node_stats_temp), false, CNodeStateStats()); + } + + // Try to retrieve the CNodeStateStats for each node. + TRY_LOCK(::cs_main, lockMain); + if (lockMain) { + for (auto& node_stats : stats) { + std::get<1>(node_stats) = + GetNodeStateStats(std::get<0>(node_stats).nodeid, std::get<2>(node_stats)); + } + } + return true; + } + return false; + } int64_t getTotalBytesRecv() override { return g_connman ? g_connman->GetTotalBytesRecv() : 0; } int64_t getTotalBytesSent() override { return g_connman ? g_connman->GetTotalBytesSent() : 0; } size_t getMempoolSize() override { return ::mempool.size(); } diff --git a/src/interface/node.h b/src/interface/node.h index 5275030ca1..6288487032 100644 --- a/src/interface/node.h +++ b/src/interface/node.h @@ -14,8 +14,12 @@ #include <stddef.h> #include <stdint.h> #include <string> +#include <tuple> +#include <vector> +class CNodeStats; class proxyType; +struct CNodeStateStats; namespace interface { @@ -79,6 +83,10 @@ public: //! Get number of connections. virtual size_t getNodeCount(CConnman::NumConnections flags) = 0; + //! Get stats for connected nodes. + using NodesStats = std::vector<std::tuple<CNodeStats, bool, CNodeStateStats>>; + virtual bool getNodesStats(NodesStats& stats) = 0; + //! Get total bytes recv. virtual int64_t getTotalBytesRecv() = 0; |