From eec51a872c9b08bef1fcd006a8402dfcbf50889e Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Thu, 12 Mar 2009 18:47:02 +0000 Subject: [PATCH] Re-implement logging busy networks to handle v6 API. Implement a state dump for later reparsing. --- ot_fullscrape.c | 9 +++++-- ot_http.c | 2 +- ot_mutex.h | 1 + ot_stats.c | 63 +++++++++++++++++++++++++++++-------------------- 4 files changed, 47 insertions(+), 28 deletions(-) diff --git a/ot_fullscrape.c b/ot_fullscrape.c index 4cd0a44..d284bd4 100644 --- a/ot_fullscrape.c +++ b/ot_fullscrape.c @@ -162,14 +162,13 @@ static void fullscrape_make( int *iovec_entries, struct iovec **iovector, ot_tas switch( mode & TASK_TASK_MASK ) { case TASK_FULLSCRAPE: default: - /* push hash as bencoded string */ *r++='2'; *r++='0'; *r++=':'; memcpy( r, hash, sizeof(ot_hash) ); r += sizeof(ot_hash); /* push rest of the scrape string */ r += sprintf( r, "d8:completei%zde10:downloadedi%zde10:incompletei%zdee", peer_list->seed_count, peer_list->down_count, peer_list->peer_count-peer_list->seed_count ); - break; + break; case TASK_FULLSCRAPE_TPB_ASCII: to_hex( r, *hash ); r+= 2 * sizeof(ot_hash); r += sprintf( r, ":%zd:%zd\n", peer_list->seed_count, peer_list->peer_count-peer_list->seed_count ); @@ -184,6 +183,12 @@ static void fullscrape_make( int *iovec_entries, struct iovec **iovector, ot_tas r += fmt_urlencoded( r, (char *)*hash, 20 ); r += sprintf( r, ":%zd:%zd\n", peer_list->seed_count, peer_list->peer_count-peer_list->seed_count ); break; + case TASK_FULLSCRAPE_TRACKERSTATE: + memcpy( r, *hash, sizeof(ot_hash) ); r += sizeof(ot_hash); + uint64_pack_big( r, (uint64_t)peer_list->down_count ); + uint64_pack_big( r + 8, (uint64_t)peer_list->base ); + r += 16; + break; } #ifdef WANT_COMPRESSION_GZIP diff --git a/ot_http.c b/ot_http.c index c184c0e..aee9d3c 100644 --- a/ot_http.c +++ b/ot_http.c @@ -165,7 +165,7 @@ static const ot_keywords keywords_mode[] = { "busy", TASK_STATS_BUSY_NETWORKS }, { "torr", TASK_STATS_TORRENTS }, { "fscr", TASK_STATS_FULLSCRAPE }, { "s24s", TASK_STATS_SLASH24S }, { "tpbs", TASK_STATS_TPB }, { "herr", TASK_STATS_HTTPERRORS }, { "top10", TASK_STATS_TOP10 }, { "renew", TASK_STATS_RENEW }, { "syncs", TASK_STATS_SYNCS }, { "version", TASK_STATS_VERSION }, - { "everything", TASK_STATS_EVERYTHING }, { NULL, -3 } }; + { "everything", TASK_STATS_EVERYTHING }, { "statedump", TASK_FULLSCRAPE_TPB_URLENCODED }, { NULL, -3 } }; static const ot_keywords keywords_format[] = { { "bin", TASK_FULLSCRAPE_TPB_BINARY }, { "ben", TASK_FULLSCRAPE }, { "url", TASK_FULLSCRAPE_TPB_URLENCODED }, { "txt", TASK_FULLSCRAPE_TPB_ASCII }, { NULL, -3 } }; diff --git a/ot_mutex.h b/ot_mutex.h index 5bde9e4..6240bbb 100644 --- a/ot_mutex.h +++ b/ot_mutex.h @@ -43,6 +43,7 @@ typedef enum { TASK_FULLSCRAPE_TPB_BINARY = 0x0201, TASK_FULLSCRAPE_TPB_ASCII = 0x0202, TASK_FULLSCRAPE_TPB_URLENCODED = 0x0203, + TASK_FULLSCRAPE_TRACKERSTATE = 0x0204, TASK_DMEM = 0x0300, diff --git a/ot_stats.c b/ot_stats.c index 9ce985f..23a3a37 100644 --- a/ot_stats.c +++ b/ot_stats.c @@ -57,11 +57,15 @@ static time_t ot_start_time; #ifdef WANT_LOG_NETWORKS #define STATS_NETWORK_NODE_BITWIDTH 8 -#define STATS_NETWORK_NODE_MAXDEPTH 16 - -#define STATS_NETWORK_NODE_BITMASK ((1<counters[i]>>=shift); return rest; } - + for( i=0; ichildren[i]; int rest_val; - + if( !*childnode ) continue; - + rest += rest_val = stats_shift_down_network_count( childnode, depth, shift ); - + if( rest_val ) continue; - + free( (*node)->children[i] ); (*node)->children[i] = NULL; } - + return rest; } -static void stats_get_highscore_networks( stats_network_node *node, int depth, uint32_t node_value, int *scores, uint32_t *networks, int network_count ) { +static void stats_get_highscore_networks( stats_network_node *node, int depth, ot_ip6 node_value, int *scores, ot_ip6 *networks, int network_count ) { + uint8_t *_node_value = (uint8_t*)node_value; int i; if( !node ) return; @@ -127,34 +132,41 @@ static void stats_get_highscore_networks( stats_network_node *node, int depth, u if( depth < STATS_NETWORK_NODE_MAXDEPTH ) { for( i=0; ichildren[i] ) - stats_get_highscore_networks( node->children[i], depth, node_value | ( i << ( 32 - depth * STATS_NETWORK_NODE_BITWIDTH ) ), scores, networks, network_count ); + if( node->children[i] ) { + _node_value[depth] = i; + stats_get_highscore_networks( node->children[i], depth, node_value, scores, networks, network_count ); + } } else for( i=0; icounters[i] <= scores[0] ) continue; - + + _node_value[depth] = i; while( (jcounters[i]>scores[j] ) ) ++j; --j; memcpy( scores, scores + 1, j * sizeof( *scores ) ); memcpy( networks, networks + 1, j * sizeof( *networks ) ); scores[ j ] = node->counters[ i ]; - networks[ j ] = node_value | ( i << ( 32 - depth * STATS_NETWORK_NODE_BITWIDTH ) ); + memcpy( networks + j, _node_value, sizeof( *networks ) ); } } static size_t stats_return_busy_networks( char * reply ) { - uint32_t networks[16]; - int scores[16]; + ot_ip6 networks[256]; + ot_ip6 node_value; + int scores[256]; int i; char * r = reply; + + stats_get_highscore_networks( stats_network_counters_root, 0, node_value, scores, networks, 256 ); - stats_get_highscore_networks( stats_network_counters_root, 0, 0, scores, networks, 16 ); - - for( i=15; i>=0; --i) - r += sprintf( r, "%08i: %d.%d.%d.0/24\n", scores[i], (networks[i]>>24)&0xff, (networks[i]>>16)&0xff, (networks[i]>>8)&0xff ); - + for( i=255; i>=0; --i) { + r += sprintf( r, "%08i: ", scores[i] ); + r += fmt_ip6c( r, networks[i] ); + *r++ = '\n'; + } + return r - reply; } @@ -442,6 +454,7 @@ static size_t stats_return_everything( char * reply ) { iterate_all_torrents( torrent_statter, (uintptr_t)&stats ); + r += sprintf( r, "" ); r += sprintf( r, "\n" ); r += stats_return_tracker_version( r ); r += sprintf( r, "\n" ); r += sprintf( r, "\n" ); r += sprintf( r, " %llu\n", (unsigned long long)(time( NULL ) - ot_start_time) );