diff options
Diffstat (limited to 'trackerlogic.h')
-rw-r--r-- | trackerlogic.h | 55 |
1 files changed, 31 insertions, 24 deletions
diff --git a/trackerlogic.h b/trackerlogic.h index ad18cba..73f5d16 100644 --- a/trackerlogic.h +++ b/trackerlogic.h | |||
@@ -2,6 +2,7 @@ | |||
2 | #define __TRACKERLOGIC_H__ | 2 | #define __TRACKERLOGIC_H__ |
3 | 3 | ||
4 | #include <sys/types.h> | 4 | #include <sys/types.h> |
5 | #include <sys/time.h> | ||
5 | 6 | ||
6 | /* Should be called BYTE, WORD, DWORD - but some OSs already have that and there's no #iftypedef */ | 7 | /* Should be called BYTE, WORD, DWORD - but some OSs already have that and there's no #iftypedef */ |
7 | /* They mark memory used as data instead of integer or human readable string - | 8 | /* They mark memory used as data instead of integer or human readable string - |
@@ -10,15 +11,9 @@ typedef unsigned char ot_byte; | |||
10 | typedef unsigned short ot_word; | 11 | typedef unsigned short ot_word; |
11 | typedef unsigned long ot_dword; | 12 | typedef unsigned long ot_dword; |
12 | 13 | ||
13 | typedef unsigned long ot_time; | ||
14 | typedef ot_byte ot_hash[20]; | 14 | typedef ot_byte ot_hash[20]; |
15 | typedef ot_byte ot_ip[ 4/*0*/ ]; | 15 | typedef ot_dword ot_ip; |
16 | // tunables | 16 | typedef time_t ot_time; |
17 | static const unsigned long OT_TIMEOUT = 2700; | ||
18 | static const unsigned long OT_HUGE_FILESIZE = 1024*1024*256; // Thats 256MB per file, enough for 204800 peers of 128 bytes | ||
19 | |||
20 | // We will not service v6, yes | ||
21 | #define OT_COMPACT_ONLY | ||
22 | 17 | ||
23 | #define MEMMOVE memmove | 18 | #define MEMMOVE memmove |
24 | #define BZERO bzero | 19 | #define BZERO bzero |
@@ -27,28 +22,41 @@ static const unsigned long OT_HUGE_FILESIZE = 1024*1024*256; // Thats 256MB p | |||
27 | #define BINARY_FIND binary_search | 22 | #define BINARY_FIND binary_search |
28 | #define NOW time(NULL) | 23 | #define NOW time(NULL) |
29 | 24 | ||
25 | // We maintain a list of 256 pointers to sorted list of ot_torrent structs | ||
26 | // Sort key is, of course, its hash | ||
27 | |||
28 | // This list points to 9 pools of peers each grouped in five-minute-intervals | ||
29 | // thus achieving a timeout of 2700s or 45 minutes | ||
30 | // These pools are sorted by its binary content | ||
31 | |||
32 | #define OT_POOLS_COUNT 9 | ||
33 | #define OT_POOLS_TIMEOUT 300 | ||
34 | |||
35 | typedef struct ot_vector { | ||
36 | void *data; | ||
37 | size_t size; | ||
38 | size_t space; | ||
39 | } *ot_vector; | ||
40 | |||
30 | typedef struct ot_peer { | 41 | typedef struct ot_peer { |
31 | #ifndef OT_COMPACT_ONLY | 42 | ot_ip ip; |
32 | ot_hash id; | 43 | ot_dword port_flags; |
33 | ot_hash key; | ||
34 | #endif | ||
35 | ot_ip ip; | ||
36 | ot_word port; | ||
37 | ot_time death; | ||
38 | ot_byte flags; | ||
39 | } *ot_peer; | 44 | } *ot_peer; |
40 | static const ot_byte PEER_FLAG_SEEDING = 0x80; | 45 | static const ot_byte PEER_FLAG_SEEDING = 0x80; |
41 | static const ot_byte PEER_IP_LENGTH_MASK = 0x3f; | ||
42 | 46 | ||
43 | typedef struct { | 47 | typedef struct ot_peerlist { |
48 | ot_time base; | ||
49 | unsigned long seed_count[ OT_POOLS_COUNT ]; | ||
50 | struct ot_vector peers[ OT_POOLS_COUNT ]; | ||
51 | } *ot_peerlist; | ||
52 | |||
53 | typedef struct ot_torrent { | ||
44 | ot_hash hash; | 54 | ot_hash hash; |
45 | ot_peer peer_list; | 55 | ot_peerlist peer_list; |
46 | unsigned long peer_count; | ||
47 | unsigned long seed_count; | ||
48 | } *ot_torrent; | 56 | } *ot_torrent; |
49 | 57 | ||
50 | void *map_file( char *file_name ); | 58 | void *map_file( char *file_name, size_t map_size ); |
51 | void unmap_file( char *file_name, void *map, unsigned long real_size ); | 59 | void unmap_file( char *file_name, void *map, size_t mapped_size, unsigned long real_size ); |
52 | 60 | ||
53 | // This behaves quite like bsearch but allows to find | 61 | // This behaves quite like bsearch but allows to find |
54 | // the insertion point for inserts after unsuccessful searches | 62 | // the insertion point for inserts after unsuccessful searches |
@@ -68,6 +76,5 @@ void deinit_logic( ); | |||
68 | 76 | ||
69 | ot_torrent add_peer_to_torrent( ot_hash *hash, ot_peer peer ); | 77 | ot_torrent add_peer_to_torrent( ot_hash *hash, ot_peer peer ); |
70 | size_t return_peers_for_torrent( ot_torrent torrent, unsigned long amount, char *reply ); | 78 | size_t return_peers_for_torrent( ot_torrent torrent, unsigned long amount, char *reply ); |
71 | void heal_torrent( ot_torrent torrent ); | ||
72 | 79 | ||
73 | #endif | 80 | #endif |