Browse Source

Full scrape moves to its own object

master
Dirk Engling 14 years ago
parent
commit
0bc163060e
  1. 41
      trackerlogic.c
  2. 3
      trackerlogic.h

41
trackerlogic.c

@ -226,47 +226,6 @@ void fix_mmapallocation( void *buf, size_t old_alloc, size_t new_alloc ) {
munmap( ((char*)buf) + new_pages * page_size, old_alloc - new_pages * page_size );
}
/* Fetch full scrape info for all torrents */
size_t return_fullscrape_for_tracker( char **reply ) {
size_t torrent_count = 0, j;
size_t allocated, replysize;
ot_vector *torrents_list;
int bucket;
char *r;
for( bucket=0; bucket<OT_BUCKET_COUNT; ++bucket ) {
ot_vector *torrents_list = mutex_bucket_lock( bucket );
torrent_count += torrents_list->size;
mutex_bucket_unlock( bucket );
}
/* one extra for pro- and epilogue */
allocated = 100*(1+torrent_count);
if( !( r = *reply = mmap( NULL, allocated, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0 ) ) ) return 0;
memmove( r, "d5:filesd", 9 ); r += 9;
for( bucket=0; bucket<OT_BUCKET_COUNT; ++bucket ) {
torrents_list = mutex_bucket_lock( bucket );
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;
if( peer_list->peer_count || peer_list->down_count ) {
*r++='2'; *r++='0'; *r++=':';
memmove( r, hash, 20 ); r+=20;
r += sprintf( r, "d8:completei%zde10:downloadedi%zde10:incompletei%zdee", peer_list->seed_count, peer_list->down_count, peer_list->peer_count-peer_list->seed_count );
}
}
mutex_bucket_unlock( bucket );
}
*r++='e'; *r++='e';
replysize = ( r - *reply );
fix_mmapallocation( *reply, allocated, replysize );
return replysize;
}
/* Fetches scrape info for a specific torrent */
size_t return_udp_scrape_for_torrent( ot_hash *hash, char *reply ) {
int exactmatch;

3
trackerlogic.h

@ -17,7 +17,6 @@ typedef uint16_t ot_word;
typedef uint32_t ot_dword;
typedef ot_byte ot_hash[20];
typedef ot_dword ot_ip;
typedef time_t ot_time;
/* Some tracker behaviour tunable */
@ -43,7 +42,6 @@ typedef time_t ot_time;
/* This list points to 9 pools of peers each grouped in five-minute-intervals
thus achieving a timeout of 2700s or 45 minutes
These pools are sorted by its binary content */
#define OT_POOLS_COUNT 9
#define OT_POOLS_TIMEOUT (60*5)
@ -105,7 +103,6 @@ void trackerlogic_deinit( void );
ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer WANT_TRACKER_SYNC_PARAM( int from_changeset ) );
size_t remove_peer_from_torrent( ot_hash *hash, ot_peer *peer, char *reply, int is_tcp );
size_t return_peers_for_torrent( ot_hash *hash, size_t amount, char *reply, int is_tcp );
size_t return_fullscrape_for_tracker( char **reply );
size_t return_tcp_scrape_for_torrent( ot_hash *hash, int amount, char *reply );
size_t return_udp_scrape_for_torrent( ot_hash *hash, char *reply );
void clean_all_torrents( void );

Loading…
Cancel
Save