Fixed statistics count.
This commit is contained in:
parent
fc94e08e31
commit
64fbe3ec9c
@ -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)
|
||||
|
@ -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.
|
||||
|
22
src/node.cpp
22
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user