summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--opentracker.c7
-rw-r--r--trackerlogic.c32
-rw-r--r--trackerlogic.h3
3 files changed, 40 insertions, 2 deletions
diff --git a/opentracker.c b/opentracker.c
index 6200087..06ba0f0 100644
--- a/opentracker.c
+++ b/opentracker.c
@@ -241,11 +241,18 @@ static void httpresponse( const int64 s, char *data ) {
241 mode = STATS_MRTG; 241 mode = STATS_MRTG;
242 else if( !byte_diff(data,4,"top5")) 242 else if( !byte_diff(data,4,"top5"))
243 mode = STATS_TOP5; 243 mode = STATS_TOP5;
244 else if( !byte_diff(data,4,"dmem"))
245 mode = STATS_DMEM;
244 else 246 else
245 HTTPERROR_400_PARAM; 247 HTTPERROR_400_PARAM;
246 } 248 }
247 } 249 }
248 250
251 if( mode == STATS_DMEM ) {
252 if( !( reply_size = return_memstat_for_tracker( &reply ) ) ) HTTPERROR_500;
253 return sendmallocdata( s, reply, reply_size );
254 }
255
249 /* Enough for http header + whole scrape string */ 256 /* Enough for http header + whole scrape string */
250 if( !( reply_size = return_stats_for_tracker( SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, mode ) ) ) HTTPERROR_500; 257 if( !( reply_size = return_stats_for_tracker( SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, mode ) ) ) HTTPERROR_500;
251 258
diff --git a/trackerlogic.c b/trackerlogic.c
index f4c61d3..54f236f 100644
--- a/trackerlogic.c
+++ b/trackerlogic.c
@@ -24,7 +24,6 @@
24 24
25/* GLOBAL VARIABLES */ 25/* GLOBAL VARIABLES */
26static ot_vector all_torrents[256]; 26static ot_vector all_torrents[256];
27
28#ifdef WANT_CLOSED_TRACKER 27#ifdef WANT_CLOSED_TRACKER
29int g_closedtracker = 1; 28int g_closedtracker = 1;
30static ot_torrent* const OT_TORRENT_NOT_ON_WHITELIST = (ot_torrent*)1; 29static ot_torrent* const OT_TORRENT_NOT_ON_WHITELIST = (ot_torrent*)1;
@@ -329,6 +328,37 @@ size_t return_fullscrape_for_tracker( char **reply ) {
329 return r - *reply; 328 return r - *reply;
330} 329}
331 330
331size_t return_memstat_for_tracker( char **reply ) {
332 size_t torrent_count = 0, j;
333 int i, k;
334 char *r;
335 time_t time_now = NOW;
336
337 for( i=0; i<256; ++i ) {
338 ot_vector *torrents_list = &all_torrents[i];
339 torrent_count += torrents_list->size;
340 }
341
342 if( !( r = *reply = malloc( 256*32 + 64*torrent_count ) ) ) return 0;
343
344 for( i=0; i<256; ++i )
345 r += sprintf( r, "%02X: %08X %08X\n", i, (ot_dword)all_torrents[i].size, (ot_dword)all_torrents[i].space );
346
347 for( i=0; i<256; ++i ) {
348 ot_vector *torrents_list = &all_torrents[i];
349 for( j=0; j<torrents_list->size; ++j ) {
350 ot_peerlist *peer_list = ( ((ot_torrent*)(torrents_list->data))[j] ).peer_list;
351 ot_hash *hash =&( ((ot_torrent*)(torrents_list->data))[j] ).hash;
352 r += sprintf( r, "\n%s:\n", to_hex( (ot_byte*)hash ) );
353 clean_peerlist( time_now, peer_list );
354 for( k=0; k<OT_POOLS_COUNT; ++k )
355 r += sprintf( r, "\t%08X %08X\n", peer_list->peers[k].size, peer_list->peers[k].space );
356 }
357 }
358
359 return r - *reply;
360}
361
332/* Fetches scrape info for a specific torrent */ 362/* Fetches scrape info for a specific torrent */
333size_t return_scrape_for_torrent( ot_hash *hash, char *reply ) { 363size_t return_scrape_for_torrent( ot_hash *hash, char *reply ) {
334 char *r = reply; 364 char *r = reply;
diff --git a/trackerlogic.h b/trackerlogic.h
index 9a6f33c..c85c520 100644
--- a/trackerlogic.h
+++ b/trackerlogic.h
@@ -88,7 +88,7 @@ extern int g_closedtracker;
88extern int g_check_blacklist; 88extern int g_check_blacklist;
89#endif 89#endif
90 90
91enum { STATS_MRTG, STATS_TOP5 }; 91enum { STATS_MRTG, STATS_TOP5, STATS_DMEM };
92 92
93ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer ); 93ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer );
94size_t return_peers_for_torrent( ot_torrent *torrent, size_t amount, char *reply ); 94size_t return_peers_for_torrent( ot_torrent *torrent, size_t amount, char *reply );
@@ -96,6 +96,7 @@ size_t return_fullscrape_for_tracker( char **reply );
96size_t return_scrape_for_torrent( ot_hash *hash, char *reply ); 96size_t return_scrape_for_torrent( ot_hash *hash, char *reply );
97size_t return_sync_for_torrent( ot_hash *hash, char **reply ); 97size_t return_sync_for_torrent( ot_hash *hash, char **reply );
98size_t return_stats_for_tracker( char *reply, int mode ); 98size_t return_stats_for_tracker( char *reply, int mode );
99size_t return_memstat_for_tracker( char **reply );
99void remove_peer_from_torrent( ot_hash *hash, ot_peer *peer ); 100void remove_peer_from_torrent( ot_hash *hash, ot_peer *peer );
100 101
101#endif 102#endif