diff options
author | erdgeist <> | 2006-12-07 01:31:30 +0000 |
---|---|---|
committer | erdgeist <> | 2006-12-07 01:31:30 +0000 |
commit | e31f00dac1cd4d30c192d3287d3c726e3b2a0372 (patch) | |
tree | 51b18a20e81dbd3fe70278b238195533c3771fff /trackerlogic.h | |
parent | a364c3f010a35880b2cc08c70524fc24762f0995 (diff) |
Every cool project needs at least one header file
Diffstat (limited to 'trackerlogic.h')
-rw-r--r-- | trackerlogic.h | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/trackerlogic.h b/trackerlogic.h new file mode 100644 index 0000000..46efb57 --- /dev/null +++ b/trackerlogic.h | |||
@@ -0,0 +1,60 @@ | |||
1 | #ifndef __TRACKERLOGIC_H__ | ||
2 | #define __TRACKERLOGIC_H__ | ||
3 | |||
4 | /* Should be called BYTE, WORD, DWORD - but some OSs already have that and there's no #iftypedef */ | ||
5 | /* They mark memory used as data instead of integer or human readable string - | ||
6 | they should be cast before used as integer/text */ | ||
7 | typedef unsigned char ot_byte; | ||
8 | typedef unsigned short ot_word; | ||
9 | typedef unsigned long ot_dword; | ||
10 | |||
11 | typedef unsigned long ot_time; | ||
12 | typedef ot_byte ot_hash[20]; | ||
13 | typedef ot_byte ot_ip[ 4/*0*/ ]; | ||
14 | // tunables | ||
15 | const unsigned long OT_TIMEOUT = 2700; | ||
16 | const unsigned long OT_HUGE_FILESIZE = 1024*1024*256; // Thats 256MB per file, enough for 204800 peers of 128 bytes | ||
17 | |||
18 | // We will not service v6, yes | ||
19 | #define OT_COMPACT_ONLY | ||
20 | |||
21 | #define MEMMOVE memmove | ||
22 | #define BZERO bzero | ||
23 | #define FORMAT_FIXED_STRING sprintf | ||
24 | #define FORMAT_FORMAT_STRING sprintf | ||
25 | #define BINARY_FIND binary_search | ||
26 | #define NOW time(NULL) | ||
27 | |||
28 | typedef struct ot_peer { | ||
29 | #ifndef OT_COMPACT_ONLY | ||
30 | ot_hash id; | ||
31 | ot_hash key; | ||
32 | #endif | ||
33 | ot_ip ip; | ||
34 | ot_word port; | ||
35 | ot_time death; | ||
36 | ot_byte flags; | ||
37 | } *ot_peer; | ||
38 | ot_byte PEER_FLAG_SEEDING = 0x80; | ||
39 | ot_byte PEER_IP_LENGTH_MASK = 0x3f; | ||
40 | |||
41 | typedef struct { | ||
42 | ot_hash hash; | ||
43 | ot_peer peer_list; | ||
44 | unsigned long peer_count; | ||
45 | unsigned long seed_count; | ||
46 | } *ot_torrent; | ||
47 | |||
48 | void *map_file( char *file_name ); | ||
49 | void unmap_file( char *file_name, void *map, unsigned long real_size ); | ||
50 | |||
51 | // This behaves quite like bsearch but allows to find | ||
52 | // the insertion point for inserts after unsuccessful searches | ||
53 | // in this case exactmatch is 0 on exit | ||
54 | // | ||
55 | void *binary_search( const void *key, const void *base, | ||
56 | const unsigned long member_count, const unsigned long member_size, | ||
57 | int (*compar) (const void *, const void *), | ||
58 | int *exactmatch ); | ||
59 | |||
60 | #endif | ||