diff options
author | erdgeist <> | 2008-11-28 22:21:10 +0000 |
---|---|---|
committer | erdgeist <> | 2008-11-28 22:21:10 +0000 |
commit | 334c6e4bbb97a4c0656e1b07c3e6a565f68eae2b (patch) | |
tree | f84ad28c39b32d0906e32e8ba5e461ecdaed7799 /trackerlogic.h | |
parent | ff6c0339c13a6b42149ba91da14dbb824307cea7 (diff) |
The BIG refactoring [tm]. Too many changes to count them. If it doesn't suite you, revert to last version.
Diffstat (limited to 'trackerlogic.h')
-rw-r--r-- | trackerlogic.h | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/trackerlogic.h b/trackerlogic.h index 3d7bcb5..c2d071a 100644 --- a/trackerlogic.h +++ b/trackerlogic.h | |||
@@ -22,7 +22,7 @@ typedef time_t ot_time; | |||
22 | #define OT_CLIENT_REQUEST_VARIATION (60*6) | 22 | #define OT_CLIENT_REQUEST_VARIATION (60*6) |
23 | 23 | ||
24 | #define OT_TORRENT_TIMEOUT_HOURS 24 | 24 | #define OT_TORRENT_TIMEOUT_HOURS 24 |
25 | #define OT_TORRENT_TIMEOUT ((60*60*OT_TORRENT_TIMEOUT_HOURS)/OT_POOLS_TIMEOUT) | 25 | #define OT_TORRENT_TIMEOUT (60*OT_TORRENT_TIMEOUT_HOURS) |
26 | 26 | ||
27 | #define OT_CLIENT_REQUEST_INTERVAL_RANDOM ( OT_CLIENT_REQUEST_INTERVAL - OT_CLIENT_REQUEST_VARIATION/2 + (int)( random( ) % OT_CLIENT_REQUEST_VARIATION ) ) | 27 | #define OT_CLIENT_REQUEST_INTERVAL_RANDOM ( OT_CLIENT_REQUEST_INTERVAL - OT_CLIENT_REQUEST_VARIATION/2 + (int)( random( ) % OT_CLIENT_REQUEST_VARIATION ) ) |
28 | 28 | ||
@@ -34,15 +34,12 @@ typedef time_t ot_time; | |||
34 | #define OT_ADMINIP_MAX 64 | 34 | #define OT_ADMINIP_MAX 64 |
35 | #define OT_MAX_THREADS 16 | 35 | #define OT_MAX_THREADS 16 |
36 | 36 | ||
37 | /* This list points to 9 pools of peers each grouped in five-minute-intervals | 37 | #define OT_PEER_TIMEOUT 45 |
38 | thus achieving a timeout of 2700s or 45 minutes | ||
39 | These pools are sorted by its binary content */ | ||
40 | #define OT_POOLS_COUNT 9 | ||
41 | #define OT_POOLS_TIMEOUT (60*5) | ||
42 | 38 | ||
43 | /* From opentracker.c */ | 39 | /* From opentracker.c */ |
44 | extern time_t g_now; | 40 | extern time_t g_now_seconds; |
45 | #define NOW (g_now/OT_POOLS_TIMEOUT) | 41 | #define g_now_minutes (g_now_seconds/60) |
42 | |||
46 | extern uint32_t g_tracker_id; | 43 | extern uint32_t g_tracker_id; |
47 | typedef enum { FLAG_TCP, FLAG_UDP, FLAG_MCA } PROTO_FLAG; | 44 | typedef enum { FLAG_TCP, FLAG_UDP, FLAG_MCA } PROTO_FLAG; |
48 | 45 | ||
@@ -57,6 +54,7 @@ static const uint8_t PEER_FLAG_LEECHING = 0x00; | |||
57 | #define OT_SETIP( peer, ip ) memmove((peer),(ip),4); | 54 | #define OT_SETIP( peer, ip ) memmove((peer),(ip),4); |
58 | #define OT_SETPORT( peer, port ) memmove(((uint8_t*)peer)+4,(port),2); | 55 | #define OT_SETPORT( peer, port ) memmove(((uint8_t*)peer)+4,(port),2); |
59 | #define OT_FLAG(peer) (((uint8_t*)(peer))[6]) | 56 | #define OT_FLAG(peer) (((uint8_t*)(peer))[6]) |
57 | #define OT_PEERTIME(peer) (((uint8_t*)(peer))[7]) | ||
60 | 58 | ||
61 | #define OT_PEER_COMPARE_SIZE ((size_t)6) | 59 | #define OT_PEER_COMPARE_SIZE ((size_t)6) |
62 | #define OT_HASH_COMPARE_SIZE (sizeof(ot_hash)) | 60 | #define OT_HASH_COMPARE_SIZE (sizeof(ot_hash)) |
@@ -75,18 +73,18 @@ struct ot_peerlist { | |||
75 | size_t seed_count; | 73 | size_t seed_count; |
76 | size_t peer_count; | 74 | size_t peer_count; |
77 | size_t down_count; | 75 | size_t down_count; |
78 | size_t seed_counts[ OT_POOLS_COUNT ]; | 76 | /* normal peers vector or |
79 | ot_vector peers[ OT_POOLS_COUNT ]; | 77 | pointer to ot_vector[32] buckets if data != NULL and space == 0 |
80 | #ifdef WANT_SYNC_BATCH | 78 | */ |
81 | ot_vector changeset; | 79 | ot_vector peers; |
82 | #endif | ||
83 | }; | 80 | }; |
81 | #define OT_PEERLIST_HASBUCKETS(peer_list) ((peer_list) && ((peer_list)->peers.size > (peer_list)->peers.space)) | ||
84 | 82 | ||
85 | /* | 83 | /* |
86 | Exported functions | 84 | Exported functions |
87 | */ | 85 | */ |
88 | 86 | ||
89 | #if defined( WANT_SYNC_BATCH ) || defined( WANT_SYNC_LIVE ) | 87 | #ifdef WANT_SYNC_LIVE |
90 | #define WANT_SYNC | 88 | #define WANT_SYNC |
91 | #endif | 89 | #endif |
92 | 90 | ||
@@ -100,9 +98,11 @@ int trackerlogic_init( const char * const serverdir ); | |||
100 | void trackerlogic_deinit( void ); | 98 | void trackerlogic_deinit( void ); |
101 | void exerr( char * message ); | 99 | void exerr( char * message ); |
102 | 100 | ||
103 | ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer WANT_SYNC_PARAM( int from_changeset ) ); | 101 | /* add_peer_to_torrent does only release the torrent bucket if from_sync is set, |
102 | otherwise it is released in return_peers_for_torrent */ | ||
103 | size_t return_peers_for_torrent( ot_torrent *torrent, size_t amount, char *reply, PROTO_FLAG proto ); | ||
104 | ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer WANT_SYNC_PARAM( int from_sync ) ); | ||
104 | size_t remove_peer_from_torrent( ot_hash *hash, ot_peer *peer, char *reply, PROTO_FLAG proto ); | 105 | size_t remove_peer_from_torrent( ot_hash *hash, ot_peer *peer, char *reply, PROTO_FLAG proto ); |
105 | size_t return_peers_for_torrent( ot_hash *hash, size_t amount, char *reply, PROTO_FLAG proto ); | ||
106 | size_t return_tcp_scrape_for_torrent( ot_hash *hash, int amount, char *reply ); | 106 | size_t return_tcp_scrape_for_torrent( ot_hash *hash, int amount, char *reply ); |
107 | size_t return_udp_scrape_for_torrent( ot_hash *hash, char *reply ); | 107 | size_t return_udp_scrape_for_torrent( ot_hash *hash, char *reply ); |
108 | 108 | ||