From 65c3b2404560b976bfeff0db190c97d4b9487644 Mon Sep 17 00:00:00 2001 From: denis <> Date: Fri, 14 Dec 2007 22:01:14 +0000 Subject: add support for more stats: 1. stats for added and removed torrents 2. stats for start and stopped events from peers this should help to detect DoS attacks and is useful for profiling --- ot_http.c | 4 ++++ ot_mutex.h | 2 ++ ot_stats.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/ot_http.c b/ot_http.c index faf1aae..a377e84 100644 --- a/ot_http.c +++ b/ot_http.c @@ -251,6 +251,10 @@ static ssize_t http_handle_stats( const int64 client_socket, char *data, char *d mode = TASK_STATS_TPB; else if( !byte_diff(data,4,"herr")) mode = TASK_STATS_HTTPERRORS; + else if( !byte_diff(data,9,"startstop")) + mode = TASK_STATS_STARTSTOP; + else if( !byte_diff(data,10,"toraddrem")) + mode = TASK_STATS_TORADDREM; else HTTPERROR_400_PARAM; break; diff --git a/ot_mutex.h b/ot_mutex.h index 01ceefd..c098343 100644 --- a/ot_mutex.h +++ b/ot_mutex.h @@ -24,6 +24,8 @@ typedef enum { TASK_STATS_TPB = 0x0007, TASK_STATS_HTTPERRORS = 0x0008, TASK_STATS_TORRENTS = 0x0009, + TASK_STATS_STARTSTOP = 0x000a, + TASK_STATS_TORADDREM = 0x000b, TASK_STATS_SLASH24S = 0x0100, diff --git a/ot_stats.c b/ot_stats.c index 77910f5..d2b02fa 100644 --- a/ot_stats.c +++ b/ot_stats.c @@ -264,6 +264,48 @@ static size_t stats_peers_mrtg( char * reply ) { ); } +static size_t stats_startstop_mrtg( char * reply ) +{ + size_t torrent_count = 0; + int bucket; + + for( bucket=0; bucketsize; + mutex_bucket_unlock( bucket ); + } + + return sprintf( reply, "%zd\n%zd\nopentracker handling %zd torrents\nopentracker", + (size_t)0, + (size_t)0, + torrent_count + ); +} + +static size_t stats_toraddrem_mrtg( char * reply ) +{ + size_t peer_count = 0, j; + int bucket; + + for( bucket=0; bucketsize; ++j ) + { + ot_peerlist *peer_list = ( ((ot_torrent*)(torrents_list->data))[j] ).peer_list; + peer_count += peer_list->peer_count; + } + mutex_bucket_unlock( bucket ); + } + + return sprintf( reply, "%zd\n%zd\nopentracker handling %zd peers\nopentracker", + (size_t)0, + (size_t)0, + peer_count + ); +} + static size_t stats_torrents_mrtg( char * reply ) { size_t torrent_count = 0; @@ -305,6 +347,10 @@ size_t return_stats_for_tracker( char *reply, int mode, int format ) { return stats_peers_mrtg( reply ); case TASK_STATS_TORRENTS: return stats_torrents_mrtg( reply ); + case TASK_STATS_TORADDREM: + return stats_toraddrem_mrtg( reply ); + case TASK_STATS_STARTSTOP: + return stats_startstop_mrtg( reply ); case TASK_STATS_SLASH24S: return stats_slash24s_txt( reply, 25, 16 ); case TASK_STATS_TOP5: -- cgit v1.2.3