diff options
author | erdgeist <> | 2009-01-13 22:41:17 +0000 |
---|---|---|
committer | erdgeist <> | 2009-01-13 22:41:17 +0000 |
commit | 131211b4daf83b7c594337f4e7c71e4711094d71 (patch) | |
tree | 63dc942c426103c01d61aa15959a81df91f2d4e1 /ot_stats.c | |
parent | 779d6c235ff8fe5284fd10dc82a9b99e7fa38d06 (diff) |
V6
Diffstat (limited to 'ot_stats.c')
-rw-r--r-- | ot_stats.c | 34 |
1 files changed, 22 insertions, 12 deletions
@@ -12,10 +12,12 @@ | |||
12 | #include <stdio.h> | 12 | #include <stdio.h> |
13 | #include <string.h> | 13 | #include <string.h> |
14 | #include <pthread.h> | 14 | #include <pthread.h> |
15 | #include <unistd.h> | ||
15 | 16 | ||
16 | /* Libowfat */ | 17 | /* Libowfat */ |
17 | #include "byte.h" | 18 | #include "byte.h" |
18 | #include "io.h" | 19 | #include "io.h" |
20 | #include "ip6.h" | ||
19 | 21 | ||
20 | /* Opentracker */ | 22 | /* Opentracker */ |
21 | #include "trackerlogic.h" | 23 | #include "trackerlogic.h" |
@@ -132,8 +134,8 @@ static void stats_get_highscore_networks( stats_network_node *node, int depth, u | |||
132 | while( (j<network_count) && (node->counters[i]>scores[j] ) ) ++j; | 134 | while( (j<network_count) && (node->counters[i]>scores[j] ) ) ++j; |
133 | --j; | 135 | --j; |
134 | 136 | ||
135 | memmove( scores, scores + 1, j * sizeof( *scores ) ); | 137 | memcpy( scores, scores + 1, j * sizeof( *scores ) ); |
136 | memmove( networks, networks + 1, j * sizeof( *networks ) ); | 138 | memcpy( networks, networks + 1, j * sizeof( *networks ) ); |
137 | scores[ j ] = node->counters[ i ]; | 139 | scores[ j ] = node->counters[ i ]; |
138 | networks[ j ] = node_value | ( i << ( 32 - depth * STATS_NETWORK_NODE_BITWIDTH ) ); | 140 | networks[ j ] = node_value | ( i << ( 32 - depth * STATS_NETWORK_NODE_BITWIDTH ) ); |
139 | } | 141 | } |
@@ -176,13 +178,13 @@ size_t stats_top10_txt( char * reply ) { | |||
176 | ot_peerlist *peer_list = ( ((ot_torrent*)(torrents_list->data))[j] ).peer_list; | 178 | ot_peerlist *peer_list = ( ((ot_torrent*)(torrents_list->data))[j] ).peer_list; |
177 | int idx = 9; while( (idx >= 0) && ( peer_list->peer_count > top10c[idx].val ) ) --idx; | 179 | int idx = 9; while( (idx >= 0) && ( peer_list->peer_count > top10c[idx].val ) ) --idx; |
178 | if ( idx++ != 9 ) { | 180 | if ( idx++ != 9 ) { |
179 | memmove( top10c + idx + 1, top10c + idx, ( 9 - idx ) * sizeof( ot_record ) ); | 181 | memcpy( top10c + idx + 1, top10c + idx, ( 9 - idx ) * sizeof( ot_record ) ); |
180 | top10c[idx].val = peer_list->peer_count; | 182 | top10c[idx].val = peer_list->peer_count; |
181 | top10c[idx].torrent = (ot_torrent*)(torrents_list->data) + j; | 183 | top10c[idx].torrent = (ot_torrent*)(torrents_list->data) + j; |
182 | } | 184 | } |
183 | idx = 9; while( (idx >= 0) && ( peer_list->seed_count > top10s[idx].val ) ) --idx; | 185 | idx = 9; while( (idx >= 0) && ( peer_list->seed_count > top10s[idx].val ) ) --idx; |
184 | if ( idx++ != 9 ) { | 186 | if ( idx++ != 9 ) { |
185 | memmove( top10s + idx + 1, top10s + idx, ( 9 - idx ) * sizeof( ot_record ) ); | 187 | memcpy( top10s + idx + 1, top10s + idx, ( 9 - idx ) * sizeof( ot_record ) ); |
186 | top10s[idx].val = peer_list->seed_count; | 188 | top10s[idx].val = peer_list->seed_count; |
187 | top10s[idx].torrent = (ot_torrent*)(torrents_list->data) + j; | 189 | top10s[idx].torrent = (ot_torrent*)(torrents_list->data) + j; |
188 | } | 190 | } |
@@ -269,7 +271,7 @@ static size_t stats_slash24s_txt( char * reply, size_t amount, uint32_t thresh ) | |||
269 | while( ( insert_pos >= 0 ) && ( count[j] > slash24s[ 2 * insert_pos ] ) ) | 271 | while( ( insert_pos >= 0 ) && ( count[j] > slash24s[ 2 * insert_pos ] ) ) |
270 | --insert_pos; | 272 | --insert_pos; |
271 | ++insert_pos; | 273 | ++insert_pos; |
272 | memmove( slash24s + 2 * ( insert_pos + 1 ), slash24s + 2 * ( insert_pos ), 2 * sizeof( uint32_t ) * ( amount - insert_pos - 1 ) ); | 274 | memcpy( slash24s + 2 * ( insert_pos + 1 ), slash24s + 2 * ( insert_pos ), 2 * sizeof( uint32_t ) * ( amount - insert_pos - 1 ) ); |
273 | slash24s[ 2 * insert_pos ] = count[j]; | 275 | slash24s[ 2 * insert_pos ] = count[j]; |
274 | slash24s[ 2 * insert_pos + 1 ] = ( i << NUM_TOPBITS ) + j; | 276 | slash24s[ 2 * insert_pos + 1 ] = ( i << NUM_TOPBITS ) + j; |
275 | if( slash24s[ 2 * amount - 2 ] > thresh ) | 277 | if( slash24s[ 2 * amount - 2 ] > thresh ) |
@@ -537,7 +539,7 @@ static void stats_make( int *iovec_entries, struct iovec **iovector, ot_tasktype | |||
537 | iovec_fixlast( iovec_entries, iovector, r ); | 539 | iovec_fixlast( iovec_entries, iovector, r ); |
538 | } | 540 | } |
539 | 541 | ||
540 | void stats_issue_event( ot_status_event event, PROTO_FLAG proto, uint32_t event_data ) { | 542 | void stats_issue_event( ot_status_event event, PROTO_FLAG proto, uintptr_t event_data ) { |
541 | switch( event ) { | 543 | switch( event ) { |
542 | case EVENT_ACCEPT: | 544 | case EVENT_ACCEPT: |
543 | if( proto == FLAG_TCP ) ot_overall_tcp_connections++; else ot_overall_udp_connections++; | 545 | if( proto == FLAG_TCP ) ot_overall_tcp_connections++; else ot_overall_udp_connections++; |
@@ -559,16 +561,24 @@ void stats_issue_event( ot_status_event event, PROTO_FLAG proto, uint32_t event_ | |||
559 | break; | 561 | break; |
560 | case EVENT_FULLSCRAPE_REQUEST: | 562 | case EVENT_FULLSCRAPE_REQUEST: |
561 | { | 563 | { |
562 | uint8_t ip[4]; *(uint32_t*)ip = (uint32_t)proto; /* ugly hack to transfer ip to stats */ | 564 | ot_ip6 *ip = (ot_ip6*)event_data; /* ugly hack to transfer ip to stats */ |
563 | LOG_TO_STDERR( "[%08d] scrp: %d.%d.%d.%d - FULL SCRAPE\n", (unsigned int)(g_now_seconds - ot_start_time)/60, ip[0], ip[1], ip[2], ip[3] ); | 565 | char _debug[512]; |
564 | ot_full_scrape_request_count++; | 566 | int off = snprintf( _debug, sizeof(_debug), "[%08d] scrp: ", (unsigned int)(g_now_seconds - ot_start_time)/60 ); |
567 | off += fmt_ip6( _debug+off, *ip ); | ||
568 | off += snprintf( _debug, sizeof(_debug)-off, " - FULL SCRAPE\n" ); | ||
569 | write( 2, _debug, off ); | ||
570 | ot_full_scrape_request_count++; | ||
565 | } | 571 | } |
566 | break; | 572 | break; |
567 | case EVENT_FULLSCRAPE_REQUEST_GZIP: | 573 | case EVENT_FULLSCRAPE_REQUEST_GZIP: |
568 | { | 574 | { |
569 | uint8_t ip[4]; *(uint32_t*)ip = (uint32_t)proto; /* ugly hack to transfer ip to stats */ | 575 | ot_ip6 *ip = (ot_ip6*)event_data; /* ugly hack to transfer ip to stats */ |
570 | LOG_TO_STDERR( "[%08d] scrp: %d.%d.%d.%d - FULL SCRAPE GZIP\n", (unsigned int)(g_now_seconds - ot_start_time)/60, ip[0], ip[1], ip[2], ip[3] ); | 576 | char _debug[512]; |
571 | ot_full_scrape_request_count++; | 577 | int off = snprintf( _debug, sizeof(_debug), "[%08d] scrp: ", (unsigned int)(g_now_seconds - ot_start_time)/60 ); |
578 | off += fmt_ip6(_debug+off, *ip ); | ||
579 | off += snprintf( _debug, sizeof(_debug)-off, " - FULL SCRAPE\n" ); | ||
580 | write( 2, _debug, off ); | ||
581 | ot_full_scrape_request_count++; | ||
572 | } | 582 | } |
573 | break; | 583 | break; |
574 | case EVENT_FAILED: | 584 | case EVENT_FAILED: |