summaryrefslogtreecommitdiff
path: root/trackerlogic.c
diff options
context:
space:
mode:
authorerdgeist <>2007-10-19 21:56:59 +0000
committererdgeist <>2007-10-19 21:56:59 +0000
commit41019c79d802e9bc6c1d70e573b6f31f50765ad7 (patch)
treea3a2bf78c07705ea7e0f1fa5f9214b415a43c013 /trackerlogic.c
parentd5876ebb6b7f238411fc6dcab8d9637650c8727f (diff)
Introducing multiscrape
Diffstat (limited to 'trackerlogic.c')
-rw-r--r--trackerlogic.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/trackerlogic.c b/trackerlogic.c
index 765a845..00aec1f 100644
--- a/trackerlogic.c
+++ b/trackerlogic.c
@@ -411,23 +411,30 @@ size_t return_udp_scrape_for_torrent( ot_hash *hash, char *reply ) {
411} 411}
412 412
413/* Fetches scrape info for a specific torrent */ 413/* Fetches scrape info for a specific torrent */
414size_t return_tcp_scrape_for_torrent( ot_hash *hash, char *reply ) { 414size_t return_tcp_scrape_for_torrent( ot_hash *hash_list, int amount, char *reply ) {
415 char *r = reply; 415 char *r = reply;
416 int exactmatch, i; 416 int exactmatch, i, j;
417 size_t peers = 0, seeds = 0;
418 ot_vector *torrents_list = &all_torrents[*hash[0]];
419 ot_torrent *torrent = binary_search( hash, torrents_list->data, torrents_list->size, sizeof( ot_torrent ), OT_HASH_COMPARE_SIZE, &exactmatch );
420 417
421 if( !exactmatch ) return sprintf( r, "d5:filesdee" ); 418 r += sprintf( r, "d5:filesd" );
422 419
423 for( i=0; i<OT_POOLS_COUNT; ++i ) { 420 for( i=0; i<amount; ++i ) {
424 peers += torrent->peer_list->peers[i].size; 421 ot_hash *hash = hash_list + i;
425 seeds += torrent->peer_list->seed_count[i]; 422 ot_vector *torrents_list = &all_torrents[*hash[0]];
426 } 423 ot_torrent *torrent = binary_search( hash, torrents_list->data, torrents_list->size, sizeof( ot_torrent ), OT_HASH_COMPARE_SIZE, &exactmatch );
424 size_t peers = 0, seeds = 0;
427 425
428 memmove( r, "d5:filesd20:", 12 ); memmove( r+12, hash, 20 ); 426 if( !exactmatch ) continue;
429 r += sprintf( r+32, "d8:completei%zde10:downloadedi%zde10:incompletei%zdeeee", seeds, torrent->peer_list->downloaded, peers-seeds ) + 32; 427
428 for( j=0; j<OT_POOLS_COUNT; ++j ) {
429 peers += torrent->peer_list->peers[j].size;
430 seeds += torrent->peer_list->seed_count[j];
431 }
432
433 memmove( r, "20:", 3 ); memmove( r+3, hash, 20 );
434 r += sprintf( r+23, "d8:completei%zde10:downloadedi%zde10:incompletei%zdee", seeds, torrent->peer_list->downloaded, peers-seeds ) + 23;
435 }
430 436
437 *r++ = 'e'; *r++ = 'e';
431 return r - reply; 438 return r - reply;
432} 439}
433 440