From 5bb381e20a94f2cf0885a5ed4c91b1b5d9c76574 Mon Sep 17 00:00:00 2001 From: denis <> Date: Thu, 15 Mar 2007 23:14:14 +0000 Subject: [PATCH] new modes for udp4 and tcp4 stats --- opentracker.c | 36 ++++++++++++++++++++++++++++++------ trackerlogic.h | 2 +- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/opentracker.c b/opentracker.c index dcbecaf..29af881 100644 --- a/opentracker.c +++ b/opentracker.c @@ -246,18 +246,42 @@ static void httpresponse( const int64 s, char *data ) { mode = STATS_TOP5; else if( !byte_diff(data,4,"dmem")) mode = STATS_DMEM; + else if( !byte_diff(data,4,"tcp4")) + mode = STATS_TCP; + else if( !byte_diff(data,4,"udp4")) + mode = STATS_UDP; else HTTPERROR_400_PARAM; } } - if( mode == STATS_DMEM ) { - if( !( reply_size = return_memstat_for_tracker( &reply ) ) ) HTTPERROR_500; - return sendmallocdata( s, reply, reply_size ); - } + switch( mode) + { + case STATS_DMEM: + if( !( reply_size = return_memstat_for_tracker( &reply ) ) ) HTTPERROR_500; + return sendmallocdata( s, reply, reply_size ); + + case STATS_UDP: + t = time( NULL ) - ot_start_time; + reply_size = sprintf( static_outbuf + SUCCESS_HTTP_HEADER_LENGTH, + "%i\n%i\n%i seconds (%i hours)\nopentracker udp stats.", + ot_overall_connections, ot_overall_udp_successfulannounces, (int)t, (int)(t / 3600) ); + break; - /* Enough for http header + whole scrape string */ - if( !( reply_size = return_stats_for_tracker( SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, mode ) ) ) HTTPERROR_500; + case STATS_TCP: + t = time( NULL ) - ot_start_time; + reply_size = sprintf( static_outbuf + SUCCESS_HTTP_HEADER_LENGTH, + "%i\n%i\n%i seconds (%i hours)\nopentracker tcp stats.", + ot_overall_connections, ot_overall_tcp_successfulannounces, (int)t, (int)(t / 3600) ); + break; + + default: + case STATS_MRTG: + /* Enough for http header + whole scrape string */ + if( !( reply_size = return_stats_for_tracker( SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, mode ) ) ) HTTPERROR_500; + break; + } + break; case 6: /* scrape ? */ if( byte_diff( data, 6, "scrape") ) HTTPERROR_404; diff --git a/trackerlogic.h b/trackerlogic.h index 360dacb..59d256e 100644 --- a/trackerlogic.h +++ b/trackerlogic.h @@ -91,7 +91,7 @@ extern int g_closedtracker; extern int g_check_blacklist; #endif -enum { STATS_MRTG, STATS_TOP5, STATS_DMEM }; +enum { STATS_MRTG, STATS_TOP5, STATS_DMEM, STATS_TCP, STATS_UDP }; ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer ); size_t return_peers_for_torrent( ot_torrent *torrent, size_t amount, char *reply, int is_tcp );