diff --git a/demo/main.c b/demo/main.c index 2ef491a..165320b 100644 --- a/demo/main.c +++ b/demo/main.c @@ -61,7 +61,14 @@ int main(int argc, char *argv[]) { if(strcmp(in, "/exit") == 0 || strcmp(in, "/quit") == 0) run = 0; else if(strcmp(in, "/stats") == 0) - printf("%s", NeoComm_get_node_stats()); + { + struct stats statistics = NeoComm_get_node_stats(); + printf("Good: %u\nDubious: %u\nCached: %u\nIncoming: %u\n", + statistics.good, + statistics.dubious, + statistics.cached, + statistics.incoming); + } else if(strcmp(in, "/num_nodes") == 0) printf("%u", NeoComm_count_connected_nodes()); else if(strcmp(in, "/help") == 0) diff --git a/include/neocomm.h b/include/neocomm.h index 26053ef..4af3dde 100644 --- a/include/neocomm.h +++ b/include/neocomm.h @@ -49,6 +49,16 @@ struct message { struct user from; ///< Info on the peer who sent the message. }; +/** + * @brief Structure with information on the status of the node's connection. + */ +struct stats { + unsigned int good, + dubious, + cached, + incoming; +}; + /** * @brief Status of a sent message. */ @@ -110,7 +120,7 @@ int NeoComm_export_nodes(const char *node_file); * * @return A text description of the local node's status. */ -const char *NeoComm_get_node_stats(); +struct stats NeoComm_get_node_stats(); /** * @brief Get the number of nodes connected. diff --git a/src/node.cpp b/src/node.cpp index e94d807..9862127 100644 --- a/src/node.cpp +++ b/src/node.cpp @@ -117,20 +117,14 @@ 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( +struct stats NeoComm_get_node_stats() { + struct stats statistics; + 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"); + &statistics.good, + &statistics.dubious, + &statistics.cached, + &statistics.incoming); - return stats.c_str(); + return statistics; }