diff options
Diffstat (limited to 'trackerlogic.c')
-rw-r--r-- | trackerlogic.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/trackerlogic.c b/trackerlogic.c index 7d5c16b..2a79df2 100644 --- a/trackerlogic.c +++ b/trackerlogic.c | |||
@@ -133,9 +133,10 @@ static int vector_remove_torrent( ot_vector *vector, ot_hash *hash ) { | |||
133 | return 1; | 133 | return 1; |
134 | } | 134 | } |
135 | 135 | ||
136 | /* Returns 1, if torrent is gone, 0 otherwise */ | 136 | /* Returns 1, if torrent is gone, 0 otherwise |
137 | static int clean_peerlist( ot_peerlist *peer_list ) { | 137 | We expect NOW as a parameter since calling time() may be expensive*/ |
138 | int i, timedout = (int)( NOW - peer_list->base ); | 138 | static int clean_peerlist( time_t time_now, ot_peerlist *peer_list ) { |
139 | int i, timedout = (int)( time_now - peer_list->base ); | ||
139 | 140 | ||
140 | if( !timedout ) return 0; | 141 | if( !timedout ) return 0; |
141 | if( timedout > OT_POOLS_COUNT ) timedout = OT_POOLS_COUNT; | 142 | if( timedout > OT_POOLS_COUNT ) timedout = OT_POOLS_COUNT; |
@@ -189,7 +190,7 @@ ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer ) { | |||
189 | byte_zero( torrent->peer_list, sizeof( ot_peerlist )); | 190 | byte_zero( torrent->peer_list, sizeof( ot_peerlist )); |
190 | torrent->peer_list->base = NOW; | 191 | torrent->peer_list->base = NOW; |
191 | } else | 192 | } else |
192 | clean_peerlist( torrent->peer_list ); | 193 | clean_peerlist( NOW, torrent->peer_list ); |
193 | 194 | ||
194 | peer_pool = &torrent->peer_list->peers[0]; | 195 | peer_pool = &torrent->peer_list->peers[0]; |
195 | peer_dest = vector_find_or_insert( peer_pool, (void*)peer, sizeof( ot_peer ), OT_PEER_COMPARE_SIZE, &exactmatch ); | 196 | peer_dest = vector_find_or_insert( peer_pool, (void*)peer, sizeof( ot_peer ), OT_PEER_COMPARE_SIZE, &exactmatch ); |
@@ -297,7 +298,7 @@ size_t return_scrape_for_torrent( ot_hash *hash, char *reply ) { | |||
297 | ot_torrent *torrent = binary_search( hash, torrents_list->data, torrents_list->size, sizeof( ot_torrent ), OT_HASH_COMPARE_SIZE, &exactmatch ); | 298 | ot_torrent *torrent = binary_search( hash, torrents_list->data, torrents_list->size, sizeof( ot_torrent ), OT_HASH_COMPARE_SIZE, &exactmatch ); |
298 | 299 | ||
299 | if( !exactmatch ) return 0; | 300 | if( !exactmatch ) return 0; |
300 | clean_peerlist( torrent->peer_list ); | 301 | clean_peerlist( NOW, torrent->peer_list ); |
301 | 302 | ||
302 | for( i=0; i<OT_POOLS_COUNT; ++i ) { | 303 | for( i=0; i<OT_POOLS_COUNT; ++i ) { |
303 | peers += torrent->peer_list->peers[i].size; | 304 | peers += torrent->peer_list->peers[i].size; |
@@ -312,6 +313,7 @@ size_t return_scrape_for_torrent( ot_hash *hash, char *reply ) { | |||
312 | 313 | ||
313 | /* Fetches stats from tracker */ | 314 | /* Fetches stats from tracker */ |
314 | size_t return_stats_for_tracker( char *reply ) { | 315 | size_t return_stats_for_tracker( char *reply ) { |
316 | time_t time_now = NOW; | ||
315 | int torrent_count = 0, peer_count = 0, seed_count = 0; | 317 | int torrent_count = 0, peer_count = 0, seed_count = 0; |
316 | char *r = reply; | 318 | char *r = reply; |
317 | int i,j,k; | 319 | int i,j,k; |
@@ -321,7 +323,7 @@ size_t return_stats_for_tracker( char *reply ) { | |||
321 | torrent_count += torrents_list->size; | 323 | torrent_count += torrents_list->size; |
322 | for( j=0; j<torrents_list->size; ++j ) { | 324 | for( j=0; j<torrents_list->size; ++j ) { |
323 | ot_peerlist *peer_list = ( ((ot_torrent*)(torrents_list->data))[j] ).peer_list; | 325 | ot_peerlist *peer_list = ( ((ot_torrent*)(torrents_list->data))[j] ).peer_list; |
324 | clean_peerlist( peer_list ); | 326 | clean_peerlist( time_now, peer_list ); |
325 | for( k=0; k<OT_POOLS_COUNT; ++k ) { | 327 | for( k=0; k<OT_POOLS_COUNT; ++k ) { |
326 | peer_count += peer_list->peers[k].size; | 328 | peer_count += peer_list->peers[k].size; |
327 | seed_count += peer_list->seed_count[k]; | 329 | seed_count += peer_list->seed_count[k]; |
@@ -341,7 +343,7 @@ void remove_peer_from_torrent( ot_hash *hash, ot_peer *peer ) { | |||
341 | if( !exactmatch ) return; | 343 | if( !exactmatch ) return; |
342 | 344 | ||
343 | /* Maybe this does the job */ | 345 | /* Maybe this does the job */ |
344 | if( clean_peerlist( torrent->peer_list ) ) { | 346 | if( clean_peerlist( NOW, torrent->peer_list ) ) { |
345 | #ifdef WANT_CLOSED_TRACKER | 347 | #ifdef WANT_CLOSED_TRACKER |
346 | if( !g_closedtracker ) | 348 | if( !g_closedtracker ) |
347 | #endif | 349 | #endif |