Make all torrents in their buckets sorted again.

master
Dirk Engling 15 years ago
parent 32edd0dff8
commit 343169385e

@ -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 ) {
}
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 */
@ -316,4 +316,4 @@ void mutex_deinit( ) {
byte_zero( all_torrents, sizeof( all_torrents ) );
}
const char *g_version_mutex_c = "$Source: /home/cvsroot/opentracker/ot_mutex.c,v $: $Revision: 1.14 $\n";
const char *g_version_mutex_c = "$Source: /home/cvsroot/opentracker/ot_mutex.c,v $: $Revision: 1.15 $\n";

@ -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
*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
*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) {
@ -299,4 +299,4 @@ void vector_fixup_peers( ot_vector * vector ) {
vector->data = realloc( vector->data, vector->space * sizeof( ot_peer ) );
}
const char *g_version_vector_c = "$Source: /home/cvsroot/opentracker/ot_vector.c,v $: $Revision: 1.11 $\n";
const char *g_version_vector_c = "$Source: /home/cvsroot/opentracker/ot_vector.c,v $: $Revision: 1.12 $\n";

@ -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