summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ot_stats.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/ot_stats.c b/ot_stats.c
index 23a3a37..e1bce7c 100644
--- a/ot_stats.c
+++ b/ot_stats.c
@@ -76,7 +76,7 @@ static stats_network_node *stats_network_counters_root = NULL;
76 76
77static int stat_increase_network_count( stats_network_node **node, int depth, uintptr_t ip ) { 77static int stat_increase_network_count( stats_network_node **node, int depth, uintptr_t ip ) {
78 uint8_t *_ip = (uint8_t*)ip; 78 uint8_t *_ip = (uint8_t*)ip;
79 int foo = _ip[++depth]; 79 int foo = _ip[depth];
80 80
81 if( !*node ) { 81 if( !*node ) {
82 *node = malloc( sizeof( stats_network_node ) ); 82 *node = malloc( sizeof( stats_network_node ) );
@@ -86,7 +86,7 @@ static int stat_increase_network_count( stats_network_node **node, int depth, ui
86 } 86 }
87 87
88 if( depth < STATS_NETWORK_NODE_MAXDEPTH ) 88 if( depth < STATS_NETWORK_NODE_MAXDEPTH )
89 return stat_increase_network_count( &(*node)->children[ foo ], depth, ip ); 89 return stat_increase_network_count( &(*node)->children[ foo ], depth+1, ip );
90 90
91 (*node)->counters[ foo ]++; 91 (*node)->counters[ foo ]++;
92 return 0; 92 return 0;
@@ -125,16 +125,11 @@ static void stats_get_highscore_networks( stats_network_node *node, int depth, o
125 125
126 if( !node ) return; 126 if( !node ) return;
127 127
128 if( !depth++ ) {
129 memset( scores, 0, sizeof( *scores ) * network_count );
130 memset( networks, 0, sizeof( *networks ) * network_count );
131 }
132
133 if( depth < STATS_NETWORK_NODE_MAXDEPTH ) { 128 if( depth < STATS_NETWORK_NODE_MAXDEPTH ) {
134 for( i=0; i<STATS_NETWORK_NODE_COUNT; ++i ) 129 for( i=0; i<STATS_NETWORK_NODE_COUNT; ++i )
135 if( node->children[i] ) { 130 if( node->children[i] ) {
136 _node_value[depth] = i; 131 _node_value[depth] = i;
137 stats_get_highscore_networks( node->children[i], depth, node_value, scores, networks, network_count ); 132 stats_get_highscore_networks( node->children[i], depth+1, node_value, scores, networks, network_count );
138 } 133 }
139 } else 134 } else
140 for( i=0; i<STATS_NETWORK_NODE_COUNT; ++i ) { 135 for( i=0; i<STATS_NETWORK_NODE_COUNT; ++i ) {
@@ -159,6 +154,9 @@ static size_t stats_return_busy_networks( char * reply ) {
159 int i; 154 int i;
160 char * r = reply; 155 char * r = reply;
161 156
157 memset( scores, 0, sizeof( *scores ) * 256 );
158 memset( networks, 0, sizeof( *networks ) * 256 );
159
162 stats_get_highscore_networks( stats_network_counters_root, 0, node_value, scores, networks, 256 ); 160 stats_get_highscore_networks( stats_network_counters_root, 0, node_value, scores, networks, 256 );
163 161
164 for( i=255; i>=0; --i) { 162 for( i=255; i>=0; --i) {