summaryrefslogtreecommitdiff
path: root/trackerlogic.h
diff options
context:
space:
mode:
authorerdgeist <>2006-12-12 02:37:19 +0000
committererdgeist <>2006-12-12 02:37:19 +0000
commit31c20c515d96c7311aa3483287202a48dd39cefb (patch)
tree949d07b127bfb9b498989d1d839652d08a9c5fd6 /trackerlogic.h
parent0de82a8925e38e39f01a732ee22b27607b820d0b (diff)
This is a complete rewrite... assume nothing works.
Diffstat (limited to 'trackerlogic.h')
-rw-r--r--trackerlogic.h55
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;
10typedef unsigned short ot_word; 11typedef unsigned short ot_word;
11typedef unsigned long ot_dword; 12typedef unsigned long ot_dword;
12 13
13typedef unsigned long ot_time;
14typedef ot_byte ot_hash[20]; 14typedef ot_byte ot_hash[20];
15typedef ot_byte ot_ip[ 4/*0*/ ]; 15typedef ot_dword ot_ip;
16// tunables 16typedef time_t ot_time;
17static const unsigned long OT_TIMEOUT = 2700;
18static 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
35typedef struct ot_vector {
36 void *data;
37 size_t size;
38 size_t space;
39} *ot_vector;
40
30typedef struct ot_peer { 41typedef 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;
40static const ot_byte PEER_FLAG_SEEDING = 0x80; 45static const ot_byte PEER_FLAG_SEEDING = 0x80;
41static const ot_byte PEER_IP_LENGTH_MASK = 0x3f;
42 46
43typedef struct { 47typedef 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
53typedef 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
50void *map_file( char *file_name ); 58void *map_file( char *file_name, size_t map_size );
51void unmap_file( char *file_name, void *map, unsigned long real_size ); 59void 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
69ot_torrent add_peer_to_torrent( ot_hash *hash, ot_peer peer ); 77ot_torrent add_peer_to_torrent( ot_hash *hash, ot_peer peer );
70size_t return_peers_for_torrent( ot_torrent torrent, unsigned long amount, char *reply ); 78size_t return_peers_for_torrent( ot_torrent torrent, unsigned long amount, char *reply );
71void heal_torrent( ot_torrent torrent );
72 79
73#endif 80#endif