diff options
author | erdgeist <> | 2007-11-06 11:58:32 +0000 |
---|---|---|
committer | erdgeist <> | 2007-11-06 11:58:32 +0000 |
commit | 8900cc0dd980cb08a0af957a1d0dd849bf3c2ac6 (patch) | |
tree | 70aeed1dbaceea343e6ebd000d46df025bae21fc /trackerlogic.h | |
parent | 5749f1d8fe80cbb84d66a265bcf9bafe159985ab (diff) |
No one can get access to buckets now without locking them. Also split up the trackerlogic.c-monster in functional sub-units. HEADS UP: this code is untested and not considered stable.
Diffstat (limited to 'trackerlogic.h')
-rw-r--r-- | trackerlogic.h | 48 |
1 files changed, 20 insertions, 28 deletions
diff --git a/trackerlogic.h b/trackerlogic.h index 5b03012..fd80f92 100644 --- a/trackerlogic.h +++ b/trackerlogic.h | |||
@@ -1,8 +1,8 @@ | |||
1 | /* This software was written by Dirk Engling <erdgeist@erdgeist.org> | 1 | /* This software was written by Dirk Engling <erdgeist@erdgeist.org> |
2 | It is considered beerware. Prost. Skol. Cheers or whatever. */ | 2 | It is considered beerware. Prost. Skol. Cheers or whatever. */ |
3 | 3 | ||
4 | #ifndef __TRACKERLOGIC_H__ | 4 | #ifndef __OT_TRACKERLOGIC_H__ |
5 | #define __TRACKERLOGIC_H__ | 5 | #define __OT_TRACKERLOGIC_H__ |
6 | 6 | ||
7 | #include <sys/types.h> | 7 | #include <sys/types.h> |
8 | #include <sys/time.h> | 8 | #include <sys/time.h> |
@@ -20,16 +20,6 @@ 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 | |||
33 | /* Some tracker behaviour tunable */ | 23 | /* Some tracker behaviour tunable */ |
34 | #define OT_CLIENT_TIMEOUT 30 | 24 | #define OT_CLIENT_TIMEOUT 30 |
35 | #define OT_CLIENT_TIMEOUT_CHECKINTERVAL 10 | 25 | #define OT_CLIENT_TIMEOUT_CHECKINTERVAL 10 |
@@ -42,6 +32,10 @@ typedef struct { | |||
42 | 32 | ||
43 | #define OT_CLIENT_REQUEST_INTERVAL_RANDOM ( OT_CLIENT_REQUEST_INTERVAL - OT_CLIENT_REQUEST_VARIATION/2 + (int)( random( ) % OT_CLIENT_REQUEST_VARIATION ) ) | 33 | #define OT_CLIENT_REQUEST_INTERVAL_RANDOM ( OT_CLIENT_REQUEST_INTERVAL - OT_CLIENT_REQUEST_VARIATION/2 + (int)( random( ) % OT_CLIENT_REQUEST_VARIATION ) ) |
44 | 34 | ||
35 | /* We maintain a list of 1024 pointers to sorted list of ot_torrent structs | ||
36 | Sort key is, of course, its hash */ | ||
37 | #define OT_BUCKET_COUNT 1024 | ||
38 | |||
45 | /* Number of tracker admin ip addresses allowed */ | 39 | /* Number of tracker admin ip addresses allowed */ |
46 | #define OT_ADMINIP_MAX 64 | 40 | #define OT_ADMINIP_MAX 64 |
47 | #define OT_MAX_THREADS 16 | 41 | #define OT_MAX_THREADS 16 |
@@ -70,7 +64,16 @@ static const ot_byte PEER_FLAG_STOPPED = 0x20; | |||
70 | #define OT_PEER_COMPARE_SIZE ((size_t)6) | 64 | #define OT_PEER_COMPARE_SIZE ((size_t)6) |
71 | #define OT_HASH_COMPARE_SIZE (sizeof(ot_hash)) | 65 | #define OT_HASH_COMPARE_SIZE (sizeof(ot_hash)) |
72 | 66 | ||
67 | struct ot_peerlist; | ||
68 | typedef struct ot_peerlist ot_peerlist; | ||
73 | typedef struct { | 69 | typedef struct { |
70 | ot_hash hash; | ||
71 | ot_peerlist *peer_list; | ||
72 | } ot_torrent; | ||
73 | |||
74 | #include "ot_vector.h" | ||
75 | |||
76 | struct ot_peerlist { | ||
74 | ot_time base; | 77 | ot_time base; |
75 | size_t seed_count; | 78 | size_t seed_count; |
76 | size_t peer_count; | 79 | size_t peer_count; |
@@ -80,12 +83,7 @@ typedef struct { | |||
80 | #ifdef WANT_TRACKER_SYNC | 83 | #ifdef WANT_TRACKER_SYNC |
81 | ot_vector changeset; | 84 | ot_vector changeset; |
82 | #endif | 85 | #endif |
83 | } ot_peerlist; | 86 | }; |
84 | |||
85 | typedef struct { | ||
86 | ot_hash hash; | ||
87 | ot_peerlist *peer_list; | ||
88 | } ot_torrent; | ||
89 | 87 | ||
90 | /* | 88 | /* |
91 | Exported functions | 89 | Exported functions |
@@ -100,27 +98,21 @@ typedef struct { | |||
100 | int trackerlogic_init( const char * const serverdir ); | 98 | int trackerlogic_init( const char * const serverdir ); |
101 | void trackerlogic_deinit( void ); | 99 | void trackerlogic_deinit( void ); |
102 | 100 | ||
103 | enum { STATS_CONNS, STATS_PEERS, STATS_TOP5, STATS_DMEM, STATS_TCP, STATS_UDP, STATS_SLASH24S, SYNC_IN, SYNC_OUT, STATS_FULLSCRAPE }; | ||
104 | |||
105 | ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer WANT_TRACKER_SYNC_PARAM( int from_changeset ) ); | 101 | ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer WANT_TRACKER_SYNC_PARAM( int from_changeset ) ); |
106 | size_t remove_peer_from_torrent( ot_hash *hash, ot_peer *peer, char *reply, int is_tcp ); | 102 | size_t remove_peer_from_torrent( ot_hash *hash, ot_peer *peer, char *reply, int is_tcp ); |
107 | size_t return_peers_for_torrent( ot_hash *hash, size_t amount, char *reply, int is_tcp ); | 103 | size_t return_peers_for_torrent( ot_hash *hash, size_t amount, char *reply, int is_tcp ); |
108 | size_t return_fullscrape_for_tracker( char **reply ); | 104 | size_t return_fullscrape_for_tracker( char **reply ); |
109 | size_t return_tcp_scrape_for_torrent( ot_hash *hash, int amount, char *reply ); | 105 | size_t return_tcp_scrape_for_torrent( ot_hash *hash, int amount, char *reply ); |
110 | size_t return_udp_scrape_for_torrent( ot_hash *hash, char *reply ); | 106 | size_t return_udp_scrape_for_torrent( ot_hash *hash, char *reply ); |
111 | size_t return_stats_for_tracker( char *reply, int mode ); | ||
112 | size_t return_stats_for_slash24s( char *reply, size_t amount, ot_dword thresh ); | ||
113 | size_t return_memstat_for_tracker( char **reply ); | ||
114 | void clean_all_torrents( void ); | 107 | void clean_all_torrents( void ); |
115 | 108 | ||
116 | #ifdef WANT_TRACKER_SYNC | ||
117 | size_t return_changeset_for_tracker( char **reply ); | ||
118 | int add_changeset_to_tracker( ot_byte *data, size_t len ); | ||
119 | #endif | ||
120 | |||
121 | #if defined ( WANT_BLACKLISTING ) || defined ( WANT_CLOSED_TRACKER ) | 109 | #if defined ( WANT_BLACKLISTING ) || defined ( WANT_CLOSED_TRACKER ) |
122 | int accesslist_addentry( ot_hash *hash ); | 110 | int accesslist_addentry( ot_hash *hash ); |
123 | void accesslist_reset( void ); | 111 | void accesslist_reset( void ); |
124 | #endif | 112 | #endif |
125 | 113 | ||
114 | /* Helper, before it moves to its own object */ | ||
115 | void fix_mmapallocation( void *buf, size_t old_alloc, size_t new_alloc ); | ||
116 | void free_peerlist( ot_peerlist *peer_list ); | ||
117 | |||
126 | #endif | 118 | #endif |