summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorerdgeist <>2007-01-16 02:59:39 +0000
committererdgeist <>2007-01-16 02:59:39 +0000
commitade82689709441f64ec871709d7ce95b14cd729c (patch)
treefc30416e009b355556bdc9982707f45f5c97734a
parentec531730ababd42f01a5b30da0cabf5e5a9577f9 (diff)
Rudimentary stats
-rw-r--r--opentracker.c7
-rw-r--r--trackerlogic.c22
-rw-r--r--trackerlogic.h1
3 files changed, 30 insertions, 0 deletions
diff --git a/opentracker.c b/opentracker.c
index dfaafca..a2f0db2 100644
--- a/opentracker.c
+++ b/opentracker.c
@@ -127,6 +127,13 @@ e400:
127 while (*c=='/') ++c; 127 while (*c=='/') ++c;
128 128
129 switch( scan_urlencoded_query( &c, data = c, SCAN_PATH ) ) { 129 switch( scan_urlencoded_query( &c, data = c, SCAN_PATH ) ) {
130 case 5: /* scrape ? */
131 if (byte_diff(data,5,"stats"))
132 goto e404;
133 /* Enough for http header + whole scrape string */
134 if( ( reply_size = return_stats_for_tracker( SUCCESS_HTTP_HEADER_LENGTH + static_reply ) ) <= 0 )
135 goto e500;
136 break;
130 case 6: /* scrape ? */ 137 case 6: /* scrape ? */
131 if (byte_diff(data,6,"scrape")) 138 if (byte_diff(data,6,"scrape"))
132 goto e404; 139 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 ) {
310 return r - reply; 310 return r - reply;
311} 311}
312 312
313/* Fetches stats from tracker */
314size_t return_stats_for_tracker( char *reply ) {
315 int torrent_count = 0, peer_count = 0, seed_count = 0;
316 char *r = reply;
317 int i,j,k;
318
319 for( i=0; i<256; ++i ) {
320 ot_vector *torrents_list = &all_torrents[i];
321 torrent_count += torrents_list->size;
322 for( j=0; j<torrents_list->size; ++j ) {
323 ot_peerlist *peer_list = ( ((ot_torrent*)(torrents_list->data))[j] ).peer_list;
324 for( k=0; k<OT_POOLS_COUNT; ++k ) {
325 peer_count += peer_list->peers[k].size;
326 seed_count += peer_list->seed_count[k];
327 }
328 }
329 }
330 r += sprintf( r, "%i\n%i\nopentracker serving %i torrents\nSomething else.", peer_count, seed_count, torrent_count );
331
332 return r - reply;
333}
334
313void remove_peer_from_torrent( ot_hash *hash, ot_peer *peer ) { 335void remove_peer_from_torrent( ot_hash *hash, ot_peer *peer ) {
314 int exactmatch, i; 336 int exactmatch, i;
315 ot_vector *torrents_list = &all_torrents[*hash[0]]; 337 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;
82ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer ); 82ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer );
83size_t return_peers_for_torrent( ot_torrent *torrent, unsigned int amount, char *reply ); 83size_t return_peers_for_torrent( ot_torrent *torrent, unsigned int amount, char *reply );
84size_t return_scrape_for_torrent( ot_hash *hash, char *reply ); 84size_t return_scrape_for_torrent( ot_hash *hash, char *reply );
85size_t return_stats_for_tracker( char *reply );
85void remove_peer_from_torrent( ot_hash *hash, ot_peer *peer ); 86void remove_peer_from_torrent( ot_hash *hash, ot_peer *peer );
86void cleanup_torrents( void ); 87void cleanup_torrents( void );
87 88