diff options
author | erdgeist <> | 2008-12-08 02:23:21 +0000 |
---|---|---|
committer | erdgeist <> | 2008-12-08 02:23:21 +0000 |
commit | a9ab9b0c0dbd5de29d1aef9927cca92ac522d4cb (patch) | |
tree | 98356c754d090611d9b34dbf1f51b045b124d6f3 | |
parent | bca8bee62334de23fdb28ae5a8fa76b5d72089cb (diff) |
Make all torrents in their buckets sorted again.
-rw-r--r-- | ot_mutex.c | 4 | ||||
-rw-r--r-- | ot_vector.c | 12 | ||||
-rw-r--r-- | trackerlogic.h | 11 |
3 files changed, 15 insertions, 12 deletions
@@ -80,7 +80,7 @@ ot_vector *mutex_bucket_lock( int bucket ) { | |||
80 | } | 80 | } |
81 | 81 | ||
82 | ot_vector *mutex_bucket_lock_by_hash( ot_hash *hash ) { | 82 | ot_vector *mutex_bucket_lock_by_hash( ot_hash *hash ) { |
83 | int bucket = uint32_read( *hash ) % OT_BUCKET_COUNT; | 83 | int bucket = uint32_read_big( (char*)*hash ) >> OT_BUCKET_COUNT_SHIFT; |
84 | 84 | ||
85 | /* Can block */ | 85 | /* Can block */ |
86 | mutex_bucket_lock( bucket ); | 86 | mutex_bucket_lock( bucket ); |
@@ -95,7 +95,7 @@ void mutex_bucket_unlock( int bucket ) { | |||
95 | } | 95 | } |
96 | 96 | ||
97 | void mutex_bucket_unlock_by_hash( ot_hash *hash ) { | 97 | void mutex_bucket_unlock_by_hash( ot_hash *hash ) { |
98 | mutex_bucket_unlock( uint32_read( *hash ) % OT_BUCKET_COUNT ); | 98 | mutex_bucket_unlock( uint32_read_big( (char*)*hash ) >> OT_BUCKET_COUNT_SHIFT ); |
99 | } | 99 | } |
100 | 100 | ||
101 | /* TaskQueue Magic */ | 101 | /* TaskQueue Magic */ |
diff --git a/ot_vector.c b/ot_vector.c index 154d1c8..f92f7ac 100644 --- a/ot_vector.c +++ b/ot_vector.c | |||
@@ -17,8 +17,8 @@ | |||
17 | #include "uint16.h" | 17 | #include "uint16.h" |
18 | 18 | ||
19 | static int vector_compare_peer(const void *peer1, const void *peer2 ) { | 19 | static int vector_compare_peer(const void *peer1, const void *peer2 ) { |
20 | int32_t cmp = READ32(peer1,0) - READ32(peer2,0); | 20 | int32_t cmp = READ32(peer2,0) - READ32(peer1,0); |
21 | if (cmp == 0) cmp = READ16(peer1,4) - READ16(peer2,4); | 21 | if (cmp == 0) cmp = READ16(peer2,4) - READ16(peer1,4); |
22 | return cmp; | 22 | return cmp; |
23 | } | 23 | } |
24 | 24 | ||
@@ -36,10 +36,10 @@ void *binary_search( const void * const key, const void * base, const size_t mem | |||
36 | *exactmatch = 1; | 36 | *exactmatch = 1; |
37 | 37 | ||
38 | while( mc ) { | 38 | while( mc ) { |
39 | int32_t cmp = key_cache - READ32(lookat,0); | 39 | int32_t cmp = READ32(lookat,0) - key_cache; |
40 | if (cmp == 0) { | 40 | if (cmp == 0) { |
41 | for( offs = 4; cmp == 0 && offs < compare_size; offs += 4 ) | 41 | for( offs = 4; cmp == 0 && offs < compare_size; offs += 4 ) |
42 | cmp = READ32(key,offs) - READ32(lookat,offs); | 42 | cmp = READ32(lookat,offs) - READ32(key,offs); |
43 | if( cmp == 0 ) | 43 | if( cmp == 0 ) |
44 | return (void *)lookat; | 44 | return (void *)lookat; |
45 | } | 45 | } |
@@ -65,8 +65,8 @@ ot_peer *binary_search_peer( const ot_peer * const peer, const ot_peer * base, c | |||
65 | *exactmatch = 1; | 65 | *exactmatch = 1; |
66 | 66 | ||
67 | while( mc ) { | 67 | while( mc ) { |
68 | int32_t cmp = low - READ32(lookat,0); | 68 | int32_t cmp = READ32(lookat,0) - low; |
69 | if(cmp == 0) cmp = high - READ16(lookat,4); | 69 | if(cmp == 0) cmp = READ16(lookat,4) - high; |
70 | if(cmp == 0) return (ot_peer*)lookat; | 70 | if(cmp == 0) return (ot_peer*)lookat; |
71 | 71 | ||
72 | if (cmp < 0) { | 72 | if (cmp < 0) { |
diff --git a/trackerlogic.h b/trackerlogic.h index c7e2e97..75e98d2 100644 --- a/trackerlogic.h +++ b/trackerlogic.h | |||
@@ -38,16 +38,19 @@ typedef time_t ot_time; | |||
38 | /* If peers come back before 10 minutes, don't live sync them */ | 38 | /* If peers come back before 10 minutes, don't live sync them */ |
39 | #define OT_CLIENT_SYNC_RENEW_BOUNDARY 10 | 39 | #define OT_CLIENT_SYNC_RENEW_BOUNDARY 10 |
40 | 40 | ||
41 | /* We maintain a list of 1024 pointers to sorted list of ot_torrent structs | ||
42 | Sort key is, of course, its hash */ | ||
43 | #define OT_BUCKET_COUNT 1024 | ||
44 | |||
45 | /* Number of tracker admin ip addresses allowed */ | 41 | /* Number of tracker admin ip addresses allowed */ |
46 | #define OT_ADMINIP_MAX 64 | 42 | #define OT_ADMINIP_MAX 64 |
47 | #define OT_MAX_THREADS 16 | 43 | #define OT_MAX_THREADS 16 |
48 | 44 | ||
49 | #define OT_PEER_TIMEOUT 45 | 45 | #define OT_PEER_TIMEOUT 45 |
50 | 46 | ||
47 | /* We maintain a list of 1024 pointers to sorted list of ot_torrent structs | ||
48 | Sort key is, of course, its hash */ | ||
49 | #define OT_BUCKET_COUNT_BITS 10 | ||
50 | |||
51 | #define OT_BUCKET_COUNT (1<<OT_BUCKET_COUNT_BITS) | ||
52 | #define OT_BUCKET_COUNT_SHIFT (32-OT_BUCKET_COUNT_BITS) | ||
53 | |||
51 | /* From opentracker.c */ | 54 | /* From opentracker.c */ |
52 | extern time_t g_now_seconds; | 55 | extern time_t g_now_seconds; |
53 | extern volatile int g_opentracker_running; | 56 | extern volatile int g_opentracker_running; |