diff options
Diffstat (limited to 'trackerlogic.h')
| -rw-r--r-- | trackerlogic.h | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/trackerlogic.h b/trackerlogic.h index 96b59f3..fd8f48a 100644 --- a/trackerlogic.h +++ b/trackerlogic.h | |||
| @@ -20,6 +20,16 @@ typedef ot_byte ot_hash[20]; | |||
| 20 | typedef ot_dword ot_ip; | 20 | typedef ot_dword ot_ip; |
| 21 | typedef time_t ot_time; | 21 | typedef time_t ot_time; |
| 22 | 22 | ||
| 23 | #define OT_VECTOR_MIN_MEMBERS 4 | ||
| 24 | #define OT_VECTOR_GROW_RATIO 8 | ||
| 25 | #define OT_VECTOR_SHRINK_THRESH 6 | ||
| 26 | #define OT_VECTOR_SHRINK_RATIO 4 | ||
| 27 | typedef struct { | ||
| 28 | void *data; | ||
| 29 | size_t size; | ||
| 30 | size_t space; | ||
| 31 | } ot_vector; | ||
| 32 | |||
| 23 | /* Some tracker behaviour tunable */ | 33 | /* Some tracker behaviour tunable */ |
| 24 | #define OT_CLIENT_TIMEOUT 30 | 34 | #define OT_CLIENT_TIMEOUT 30 |
| 25 | #define OT_CLIENT_TIMEOUT_CHECKINTERVAL 10 | 35 | #define OT_CLIENT_TIMEOUT_CHECKINTERVAL 10 |
| @@ -32,8 +42,13 @@ typedef time_t ot_time; | |||
| 32 | 42 | ||
| 33 | #define OT_CLIENT_REQUEST_INTERVAL_RANDOM ( OT_CLIENT_REQUEST_INTERVAL - OT_CLIENT_REQUEST_VARIATION/2 + (int)( random( ) % OT_CLIENT_REQUEST_VARIATION ) ) | 43 | #define OT_CLIENT_REQUEST_INTERVAL_RANDOM ( OT_CLIENT_REQUEST_INTERVAL - OT_CLIENT_REQUEST_VARIATION/2 + (int)( random( ) % OT_CLIENT_REQUEST_VARIATION ) ) |
| 34 | 44 | ||
| 35 | /* We maintain a list of 256 pointers to sorted list of ot_torrent structs | 45 | /* We maintain a list of 4096 pointers to sorted list of ot_torrent structs |
| 36 | Sort key is, of course, its hash */ | 46 | Sort key is, of course, its hash */ |
| 47 | #define OT_BUCKET_COUNT 1024 | ||
| 48 | static inline ot_vector *hash_to_bucket( ot_vector *vectors, ot_hash *hash ) { | ||
| 49 | unsigned char *local_hash = hash[0]; | ||
| 50 | return vectors + ( ( local_hash[0] << 2 ) | ( local_hash[1] >> 6 ) ); | ||
| 51 | } | ||
| 37 | 52 | ||
| 38 | /* This list points to 9 pools of peers each grouped in five-minute-intervals | 53 | /* This list points to 9 pools of peers each grouped in five-minute-intervals |
| 39 | thus achieving a timeout of 2700s or 45 minutes | 54 | thus achieving a timeout of 2700s or 45 minutes |
| @@ -45,16 +60,6 @@ typedef time_t ot_time; | |||
| 45 | extern time_t g_now; | 60 | extern time_t g_now; |
| 46 | #define NOW (g_now/OT_POOLS_TIMEOUT) | 61 | #define NOW (g_now/OT_POOLS_TIMEOUT) |
| 47 | 62 | ||
| 48 | #define OT_VECTOR_MIN_MEMBERS 4 | ||
| 49 | #define OT_VECTOR_GROW_RATIO 8 | ||
| 50 | #define OT_VECTOR_SHRINK_THRESH 6 | ||
| 51 | #define OT_VECTOR_SHRINK_RATIO 4 | ||
| 52 | typedef struct { | ||
| 53 | void *data; | ||
| 54 | size_t size; | ||
| 55 | size_t space; | ||
| 56 | } ot_vector; | ||
| 57 | |||
| 58 | typedef struct { | 63 | typedef struct { |
| 59 | ot_byte data[8]; | 64 | ot_byte data[8]; |
| 60 | } ot_peer; | 65 | } ot_peer; |
| @@ -71,8 +76,10 @@ static const ot_byte PEER_FLAG_STOPPED = 0x20; | |||
| 71 | 76 | ||
| 72 | typedef struct { | 77 | typedef struct { |
| 73 | ot_time base; | 78 | ot_time base; |
| 74 | size_t seed_count[ OT_POOLS_COUNT ]; | 79 | size_t seed_count; |
| 75 | size_t downloaded; | 80 | size_t peer_count; |
| 81 | size_t down_count; | ||
| 82 | size_t seed_counts[ OT_POOLS_COUNT ]; | ||
| 76 | ot_vector peers[ OT_POOLS_COUNT ]; | 83 | ot_vector peers[ OT_POOLS_COUNT ]; |
| 77 | } ot_peerlist; | 84 | } ot_peerlist; |
| 78 | 85 | ||
| @@ -100,9 +107,12 @@ size_t return_stats_for_tracker( char *reply, int mode ); | |||
| 100 | size_t return_stats_for_slash24s( char *reply, size_t amount, ot_dword thresh ); | 107 | size_t return_stats_for_slash24s( char *reply, size_t amount, ot_dword thresh ); |
| 101 | size_t return_stats_for_slash24s_old( char *reply, size_t amount, ot_dword thresh ); | 108 | size_t return_stats_for_slash24s_old( char *reply, size_t amount, ot_dword thresh ); |
| 102 | size_t return_memstat_for_tracker( char **reply ); | 109 | size_t return_memstat_for_tracker( char **reply ); |
| 110 | void clean_all_torrents( void ); | ||
| 111 | |||
| 112 | #ifdef WANT_TRACKER_SYNC | ||
| 103 | size_t return_changeset_for_tracker( char **reply ); | 113 | size_t return_changeset_for_tracker( char **reply ); |
| 104 | int add_changeset_to_tracker( ot_byte *data, size_t len ); | 114 | int add_changeset_to_tracker( ot_byte *data, size_t len ); |
| 105 | void clean_all_torrents( void ); | 115 | #endif |
| 106 | 116 | ||
| 107 | #if defined ( WANT_BLACKLISTING ) || defined ( WANT_CLOSED_TRACKER ) | 117 | #if defined ( WANT_BLACKLISTING ) || defined ( WANT_CLOSED_TRACKER ) |
| 108 | int accesslist_addentry( ot_hash *hash ); | 118 | int accesslist_addentry( ot_hash *hash ); |
