diff --git a/include/neocomm.h b/include/neocomm.h index f205ac7..26053ef 100644 --- a/include/neocomm.h +++ b/include/neocomm.h @@ -112,6 +112,13 @@ int NeoComm_export_nodes(const char *node_file); */ const char *NeoComm_get_node_stats(); +/** + * @brief Get the number of nodes connected. + * + * @return A number of the known nodes. + */ +unsigned int NeoComm_count_connected_nodes(); + /** * @brief Join a channel. * diff --git a/src/node.cpp b/src/node.cpp index c5de95d..e94d807 100644 --- a/src/node.cpp +++ b/src/node.cpp @@ -113,6 +113,24 @@ int NeoComm_export_nodes(const char *node_file) { return 1; } -const char *NeoComm_get_node_stats() { - return node.getNodesStats(AF_UNSPEC).toString().c_str(); +unsigned int NeoComm_count_connected_nodes() { + return node.getNodesStats(AF_UNSPEC).getKnownNodes(); +} + +const char *NeoComm_get_node_stats() { + unsigned int good, dubious, cached, incoming, total; + total = node.getNodesStats( + AF_UNSPEC, + &good, + &dubious, + &cached, + &incoming); + std::string stats; + stats += "Good: " + good + std::string("\n"); + stats += "Dubious: " + dubious + std::string("\n"); + stats += "Cached: " + cached + std::string("\n"); + stats += "Incoming: " + incoming + std::string("\n"); + stats += "Total: " + total + std::string("\n"); + + return stats.c_str(); }