From ade82689709441f64ec871709d7ce95b14cd729c Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Tue, 16 Jan 2007 02:59:39 +0000 Subject: Rudimentary stats --- opentracker.c | 7 +++++++ trackerlogic.c | 22 ++++++++++++++++++++++ trackerlogic.h | 1 + 3 files changed, 30 insertions(+) diff --git a/opentracker.c b/opentracker.c index dfaafca..a2f0db2 100644 --- a/opentracker.c +++ b/opentracker.c @@ -127,6 +127,13 @@ e400: while (*c=='/') ++c; switch( scan_urlencoded_query( &c, data = c, SCAN_PATH ) ) { + case 5: /* scrape ? */ + if (byte_diff(data,5,"stats")) + goto e404; + /* Enough for http header + whole scrape string */ + if( ( reply_size = return_stats_for_tracker( SUCCESS_HTTP_HEADER_LENGTH + static_reply ) ) <= 0 ) + goto e500; + break; case 6: /* scrape ? */ if (byte_diff(data,6,"scrape")) goto e404; diff --git a/trackerlogic.c b/trackerlogic.c index 901697d..0c78e16 100644 --- a/trackerlogic.c +++ b/trackerlogic.c @@ -310,6 +310,28 @@ size_t return_scrape_for_torrent( ot_hash *hash, char *reply ) { return r - reply; } +/* Fetches stats from tracker */ +size_t return_stats_for_tracker( char *reply ) { + int torrent_count = 0, peer_count = 0, seed_count = 0; + char *r = reply; + int i,j,k; + + for( i=0; i<256; ++i ) { + ot_vector *torrents_list = &all_torrents[i]; + torrent_count += torrents_list->size; + for( j=0; jsize; ++j ) { + ot_peerlist *peer_list = ( ((ot_torrent*)(torrents_list->data))[j] ).peer_list; + for( k=0; kpeers[k].size; + seed_count += peer_list->seed_count[k]; + } + } + } + r += sprintf( r, "%i\n%i\nopentracker serving %i torrents\nSomething else.", peer_count, seed_count, torrent_count ); + + return r - reply; +} + void remove_peer_from_torrent( ot_hash *hash, ot_peer *peer ) { int exactmatch, i; ot_vector *torrents_list = &all_torrents[*hash[0]]; diff --git a/trackerlogic.h b/trackerlogic.h index 178f8db..64953c6 100644 --- a/trackerlogic.h +++ b/trackerlogic.h @@ -82,6 +82,7 @@ extern int g_check_blacklist; ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer ); size_t return_peers_for_torrent( ot_torrent *torrent, unsigned int amount, char *reply ); size_t return_scrape_for_torrent( ot_hash *hash, char *reply ); +size_t return_stats_for_tracker( char *reply ); void remove_peer_from_torrent( ot_hash *hash, ot_peer *peer ); void cleanup_torrents( void ); -- cgit v1.2.3