Browse Source

Rudimentary stats

dynamic-accesslists
erdgeist 18 years ago
parent
commit
ade8268970
  1. 7
      opentracker.c
  2. 22
      trackerlogic.c
  3. 1
      trackerlogic.h

7
opentracker.c

@ -127,6 +127,13 @@ e400: @@ -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;

22
trackerlogic.c

@ -310,6 +310,28 @@ size_t return_scrape_for_torrent( ot_hash *hash, char *reply ) { @@ -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]];

1
trackerlogic.h

@ -82,6 +82,7 @@ extern int g_check_blacklist; @@ -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 );

Loading…
Cancel
Save