summaryrefslogtreecommitdiff
path: root/trackerlogic.h
diff options
context:
space:
mode:
Diffstat (limited to 'trackerlogic.h')
-rw-r--r--trackerlogic.h60
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 */
7typedef unsigned char ot_byte;
8typedef unsigned short ot_word;
9typedef unsigned long ot_dword;
10
11typedef unsigned long ot_time;
12typedef ot_byte ot_hash[20];
13typedef ot_byte ot_ip[ 4/*0*/ ];
14// tunables
15const unsigned long OT_TIMEOUT = 2700;
16const 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
28typedef 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;
38ot_byte PEER_FLAG_SEEDING = 0x80;
39ot_byte PEER_IP_LENGTH_MASK = 0x3f;
40
41typedef struct {
42 ot_hash hash;
43 ot_peer peer_list;
44 unsigned long peer_count;
45 unsigned long seed_count;
46} *ot_torrent;
47
48void *map_file( char *file_name );
49void 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//
55void *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