]> git.ipfire.org Git - thirdparty/opentracker.git/commitdiff
Rudimentary stats
authorerdgeist <>
Tue, 16 Jan 2007 02:59:39 +0000 (02:59 +0000)
committererdgeist <>
Tue, 16 Jan 2007 02:59:39 +0000 (02:59 +0000)
opentracker.c
trackerlogic.c
trackerlogic.h

index dfaafca00914a8086d14f8b35235f1fd2af58c8f..a2f0db2b5161024256b6da55dad58bffc359a719 100644 (file)
@@ -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;
index 901697dca3c6df2045a4955f2fdd32c768efcd3e..0c78e160836e94df281cb5b8d72107302743b4db 100644 (file)
@@ -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; j<torrents_list->size; ++j ) {
+      ot_peerlist *peer_list = (  ((ot_torrent*)(torrents_list->data))[j] ).peer_list;
+      for( k=0; k<OT_POOLS_COUNT; ++k ) {
+        peer_count += peer_list->peers[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]];
index 178f8db3fb9b6996bf81a8e67a4d8eb03b98c7b3..64953c67631593bd29d8cf79ae0622db396664c3 100644 (file)
@@ -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 );