Browse Source

el cheapo vector debugging

master
Dirk Engling 15 years ago
parent
commit
b0eee67849
  1. 7
      opentracker.c
  2. 32
      trackerlogic.c
  3. 3
      trackerlogic.h

7
opentracker.c

@ -241,11 +241,18 @@ static void httpresponse( const int64 s, char *data ) {
mode = STATS_MRTG;
else if( !byte_diff(data,4,"top5"))
mode = STATS_TOP5;
else if( !byte_diff(data,4,"dmem"))
mode = STATS_DMEM;
else
HTTPERROR_400_PARAM;
}
}
if( mode == STATS_DMEM ) {
if( !( reply_size = return_memstat_for_tracker( &reply ) ) ) HTTPERROR_500;
return sendmallocdata( s, reply, reply_size );
}
/* Enough for http header + whole scrape string */
if( !( reply_size = return_stats_for_tracker( SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, mode ) ) ) HTTPERROR_500;

32
trackerlogic.c

@ -24,7 +24,6 @@
/* GLOBAL VARIABLES */
static ot_vector all_torrents[256];
#ifdef WANT_CLOSED_TRACKER
int g_closedtracker = 1;
static ot_torrent* const OT_TORRENT_NOT_ON_WHITELIST = (ot_torrent*)1;
@ -329,6 +328,37 @@ size_t return_fullscrape_for_tracker( char **reply ) {
return r - *reply;
}
size_t return_memstat_for_tracker( char **reply ) {
size_t torrent_count = 0, j;
int i, k;
char *r;
time_t time_now = NOW;
for( i=0; i<256; ++i ) {
ot_vector *torrents_list = &all_torrents[i];
torrent_count += torrents_list->size;
}
if( !( r = *reply = malloc( 256*32 + 64*torrent_count ) ) ) return 0;
for( i=0; i<256; ++i )
r += sprintf( r, "%02X: %08X %08X\n", i, (ot_dword)all_torrents[i].size, (ot_dword)all_torrents[i].space );
for( i=0; i<256; ++i ) {
ot_vector *torrents_list = &all_torrents[i];
for( j=0; j<torrents_list->size; ++j ) {
ot_peerlist *peer_list = ( ((ot_torrent*)(torrents_list->data))[j] ).peer_list;
ot_hash *hash =&( ((ot_torrent*)(torrents_list->data))[j] ).hash;
r += sprintf( r, "\n%s:\n", to_hex( (ot_byte*)hash ) );
clean_peerlist( time_now, peer_list );
for( k=0; k<OT_POOLS_COUNT; ++k )
r += sprintf( r, "\t%08X %08X\n", peer_list->peers[k].size, peer_list->peers[k].space );
}
}
return r - *reply;
}
/* Fetches scrape info for a specific torrent */
size_t return_scrape_for_torrent( ot_hash *hash, char *reply ) {
char *r = reply;

3
trackerlogic.h

@ -88,7 +88,7 @@ extern int g_closedtracker;
extern int g_check_blacklist;
#endif
enum { STATS_MRTG, STATS_TOP5 };
enum { STATS_MRTG, STATS_TOP5, STATS_DMEM };
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 );
@ -96,6 +96,7 @@ size_t return_fullscrape_for_tracker( char **reply );
size_t return_scrape_for_torrent( ot_hash *hash, char *reply );
size_t return_sync_for_torrent( ot_hash *hash, char **reply );
size_t return_stats_for_tracker( char *reply, int mode );
size_t return_memstat_for_tracker( char **reply );
void remove_peer_from_torrent( ot_hash *hash, ot_peer *peer );
#endif

Loading…
Cancel
Save