Browse Source

Make all torrents in their buckets sorted again.

dynamic-accesslists
erdgeist 16 years ago
parent
commit
a9ab9b0c0d
  1. 4
      ot_mutex.c
  2. 12
      ot_vector.c
  3. 11
      trackerlogic.h

4
ot_mutex.c

@ -80,7 +80,7 @@ ot_vector *mutex_bucket_lock( int bucket ) { @@ -80,7 +80,7 @@ ot_vector *mutex_bucket_lock( int bucket ) {
}
ot_vector *mutex_bucket_lock_by_hash( ot_hash *hash ) {
int bucket = uint32_read( *hash ) % OT_BUCKET_COUNT;
int bucket = uint32_read_big( (char*)*hash ) >> OT_BUCKET_COUNT_SHIFT;
/* Can block */
mutex_bucket_lock( bucket );
@ -95,7 +95,7 @@ void mutex_bucket_unlock( int bucket ) { @@ -95,7 +95,7 @@ void mutex_bucket_unlock( int bucket ) {
}
void mutex_bucket_unlock_by_hash( ot_hash *hash ) {
mutex_bucket_unlock( uint32_read( *hash ) % OT_BUCKET_COUNT );
mutex_bucket_unlock( uint32_read_big( (char*)*hash ) >> OT_BUCKET_COUNT_SHIFT );
}
/* TaskQueue Magic */

12
ot_vector.c

@ -17,8 +17,8 @@ @@ -17,8 +17,8 @@
#include "uint16.h"
static int vector_compare_peer(const void *peer1, const void *peer2 ) {
int32_t cmp = READ32(peer1,0) - READ32(peer2,0);
if (cmp == 0) cmp = READ16(peer1,4) - READ16(peer2,4);
int32_t cmp = READ32(peer2,0) - READ32(peer1,0);
if (cmp == 0) cmp = READ16(peer2,4) - READ16(peer1,4);
return cmp;
}
@ -36,10 +36,10 @@ void *binary_search( const void * const key, const void * base, const size_t mem @@ -36,10 +36,10 @@ void *binary_search( const void * const key, const void * base, const size_t mem
*exactmatch = 1;
while( mc ) {
int32_t cmp = key_cache - READ32(lookat,0);
int32_t cmp = READ32(lookat,0) - key_cache;
if (cmp == 0) {
for( offs = 4; cmp == 0 && offs < compare_size; offs += 4 )
cmp = READ32(key,offs) - READ32(lookat,offs);
cmp = READ32(lookat,offs) - READ32(key,offs);
if( cmp == 0 )
return (void *)lookat;
}
@ -65,8 +65,8 @@ ot_peer *binary_search_peer( const ot_peer * const peer, const ot_peer * base, c @@ -65,8 +65,8 @@ ot_peer *binary_search_peer( const ot_peer * const peer, const ot_peer * base, c
*exactmatch = 1;
while( mc ) {
int32_t cmp = low - READ32(lookat,0);
if(cmp == 0) cmp = high - READ16(lookat,4);
int32_t cmp = READ32(lookat,0) - low;
if(cmp == 0) cmp = READ16(lookat,4) - high;
if(cmp == 0) return (ot_peer*)lookat;
if (cmp < 0) {

11
trackerlogic.h

@ -38,16 +38,19 @@ typedef time_t ot_time; @@ -38,16 +38,19 @@ typedef time_t ot_time;
/* If peers come back before 10 minutes, don't live sync them */
#define OT_CLIENT_SYNC_RENEW_BOUNDARY 10
/* We maintain a list of 1024 pointers to sorted list of ot_torrent structs
Sort key is, of course, its hash */
#define OT_BUCKET_COUNT 1024
/* Number of tracker admin ip addresses allowed */
#define OT_ADMINIP_MAX 64
#define OT_MAX_THREADS 16
#define OT_PEER_TIMEOUT 45
/* We maintain a list of 1024 pointers to sorted list of ot_torrent structs
Sort key is, of course, its hash */
#define OT_BUCKET_COUNT_BITS 10
#define OT_BUCKET_COUNT (1<<OT_BUCKET_COUNT_BITS)
#define OT_BUCKET_COUNT_SHIFT (32-OT_BUCKET_COUNT_BITS)
/* From opentracker.c */
extern time_t g_now_seconds;
extern volatile int g_opentracker_running;

Loading…
Cancel
Save