summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorerdgeist <>2007-07-22 16:17:26 +0000
committererdgeist <>2007-07-22 16:17:26 +0000
commitafe966b64418c01e7ea09bb31c720365b0c4f395 (patch)
treea7613c25c71fa9d7d7d95b5492170b4b818015e7
parentc0b00c0bf5b9414f93c76bb6daef9c01e2b49628 (diff)
some subnet stats... still ugly and untested.
-rw-r--r--opentracker.c5
-rw-r--r--trackerlogic.c53
-rw-r--r--trackerlogic.h3
3 files changed, 60 insertions, 1 deletions
diff --git a/opentracker.c b/opentracker.c
index b13dc11..ff1c1c6 100644
--- a/opentracker.c
+++ b/opentracker.c
@@ -274,6 +274,8 @@ static void httpresponse( const int64 s, char *data ) {
274 mode = STATS_TCP; 274 mode = STATS_TCP;
275 else if( !byte_diff(data,4,"udp4")) 275 else if( !byte_diff(data,4,"udp4"))
276 mode = STATS_UDP; 276 mode = STATS_UDP;
277 else if( !byte_diff(data,4,"s24s"))
278 mode = STATS_SLASH24S;
277 else 279 else
278 HTTPERROR_400_PARAM; 280 HTTPERROR_400_PARAM;
279 } 281 }
@@ -304,6 +306,9 @@ static void httpresponse( const int64 s, char *data ) {
304 /* Enough for http header + whole scrape string */ 306 /* Enough for http header + whole scrape string */
305 if( !( reply_size = return_stats_for_tracker( SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, mode ) ) ) HTTPERROR_500; 307 if( !( reply_size = return_stats_for_tracker( SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, mode ) ) ) HTTPERROR_500;
306 break; 308 break;
309 case STATS_SLASH24S:
310 if( !( reply_size = return_stats_for_slash24s( SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, 25, 64 ) ) ) HTTPERROR_500;
311 break;
307 } 312 }
308 break; 313 break;
309 314
diff --git a/trackerlogic.c b/trackerlogic.c
index 98fcef9..ee49eb7 100644
--- a/trackerlogic.c
+++ b/trackerlogic.c
@@ -634,6 +634,59 @@ size_t return_stats_for_tracker( char *reply, int mode ) {
634 return r - reply; 634 return r - reply;
635} 635}
636 636
637size_t return_stats_for_slash24s( char *reply, size_t amount, ot_dword thresh ) {
638 ot_word *count = malloc( 0x1000000 * sizeof(ot_word) );
639 ot_dword slash24s[amount*2]; /* first dword amount, second dword subnet */
640 size_t i, j, k, l;
641 char *r = reply;
642
643 if( !count )
644 return 0;
645
646 byte_zero( count, 0x1000000 * sizeof(ot_word) );
647 byte_zero( slash24s, amount * 2 * sizeof(ot_dword) );
648
649 r += sprintf( r, "Stats for all /24s with more than %d announced torrents:\n\n", ((int)thresh) );
650
651 for( i=0; i<256; ++i ) {
652 ot_vector *torrents_list = &all_torrents[i];
653 for( j=0; j<torrents_list->size; ++j ) {
654 ot_peerlist *peer_list = ( ((ot_torrent*)(torrents_list->data))[j] ).peer_list;
655 for( k=0; k<OT_POOLS_COUNT; ++k ) {
656 ot_peer *peers = peer_list->peers[k].data;
657 size_t numpeers = peer_list->peers[k].size;
658 for( l=0; l<numpeers; ++l )
659 if( ++count[ (*(ot_dword*)(peers+l))>>8 ] == 65335 )
660 count[ (*(ot_dword*)(peers+l))>>8 ] = 65334;
661 }
662 }
663 }
664
665 for( i=0; i<0x1000000; ++i )
666 if( count[i] >= thresh ) {
667 /* This subnet seems to announce more torrents than the last in our list */
668 int insert_pos = amount - 1;
669 while( ( insert_pos >= 0 ) && ( count[i] > slash24s[ 2 * insert_pos ] ) )
670 --insert_pos;
671 ++insert_pos;
672 memmove( slash24s + 2 * ( insert_pos + 1 ), slash24s + 2 * ( insert_pos ), 2 * sizeof( ot_dword ) * ( amount - insert_pos - 1 ) );
673 slash24s[ 2 * insert_pos ] = count[i];
674 slash24s[ 2 * insert_pos + 1 ] = i;
675 if( slash24s[ 2 * amount - 2 ] > thresh )
676 thresh = slash24s[ 2 * amount - 2 ];
677 }
678
679 free( count );
680
681 for( i=0; i < amount; ++i )
682 if( slash24s[ 2*i ] >= thresh ) {
683 unsigned long ip = slash24s[ 2*i +1 ];
684 r += sprintf( r, "% 10ld %d.%d.%d/24\n", (long)slash24s[ 2*i ], (int)(ip >> 16), (int)(255 & ( ip >> 8 )), (int)(ip & 255) );
685 }
686
687 return r - reply;
688}
689
637void remove_peer_from_torrent( ot_hash *hash, ot_peer *peer ) { 690void remove_peer_from_torrent( ot_hash *hash, ot_peer *peer ) {
638 int exactmatch, i; 691 int exactmatch, i;
639 ot_vector *torrents_list = &all_torrents[*hash[0]]; 692 ot_vector *torrents_list = &all_torrents[*hash[0]];
diff --git a/trackerlogic.h b/trackerlogic.h
index eb4d4f6..3b2d883 100644
--- a/trackerlogic.h
+++ b/trackerlogic.h
@@ -84,7 +84,7 @@ typedef struct {
84int init_logic( const char * const serverdir ); 84int init_logic( const char * const serverdir );
85void deinit_logic( void ); 85void deinit_logic( void );
86 86
87enum { STATS_MRTG, STATS_TOP5, STATS_DMEM, STATS_TCP, STATS_UDP, SYNC_IN, SYNC_OUT }; 87enum { STATS_MRTG, STATS_TOP5, STATS_DMEM, STATS_TCP, STATS_UDP, STATS_SLASH24S, SYNC_IN, SYNC_OUT };
88 88
89ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer, int from_changeset ); 89ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer, int from_changeset );
90int add_changeset_to_tracker( ot_byte *data, size_t len ); 90int add_changeset_to_tracker( ot_byte *data, size_t len );
@@ -93,6 +93,7 @@ size_t return_fullscrape_for_tracker( char **reply );
93size_t return_tcp_scrape_for_torrent( ot_hash *hash, char *reply ); 93size_t return_tcp_scrape_for_torrent( ot_hash *hash, char *reply );
94size_t return_udp_scrape_for_torrent( ot_hash *hash, char *reply ); 94size_t return_udp_scrape_for_torrent( ot_hash *hash, char *reply );
95size_t return_stats_for_tracker( char *reply, int mode ); 95size_t return_stats_for_tracker( char *reply, int mode );
96size_t return_stats_for_slash24s( char *reply, size_t amount, ot_dword thresh );
96size_t return_memstat_for_tracker( char **reply ); 97size_t return_memstat_for_tracker( char **reply );
97size_t return_changeset_for_tracker( char **reply ); 98size_t return_changeset_for_tracker( char **reply );
98void clean_all_torrents( void ); 99void clean_all_torrents( void );