summaryrefslogtreecommitdiff
path: root/trackerlogic.h
diff options
context:
space:
mode:
Diffstat (limited to 'trackerlogic.h')
-rw-r--r--trackerlogic.h55
1 files changed, 28 insertions, 27 deletions
diff --git a/trackerlogic.h b/trackerlogic.h
index eb2906b..da8f822 100644
--- a/trackerlogic.h
+++ b/trackerlogic.h
@@ -11,17 +11,16 @@
11#include <time.h> 11#include <time.h>
12#include <stdint.h> 12#include <stdint.h>
13 13
14/* Libowfat */
15#include <uint16.h>
16#include <uint32.h>
17
18#define READ16(addr,offs) ((int16_t)uint16_read((offs)+(uint8_t*)(addr)))
19#define READ32(addr,offs) ((int32_t)uint32_read((offs)+(uint8_t*)(addr)))
20#define WRITE16(addr,offs,val) uint16_pack((offs)+(uint8_t*)(addr),(val))
21#define WRITE32(addr,offs,val) uint32_pack((offs)+(uint8_t*)(addr),(val))
22
23typedef uint8_t ot_hash[20]; 14typedef uint8_t ot_hash[20];
24typedef time_t ot_time; 15typedef time_t ot_time;
16typedef char ot_ip6[16];
17#ifdef WANT_V6
18#define OT_IP_SIZE 16
19#define PEERS6 "6"
20#else
21#define OT_IP_SIZE 4
22#define PEERS6 ""
23#endif
25 24
26/* Some tracker behaviour tunable */ 25/* Some tracker behaviour tunable */
27#define OT_CLIENT_TIMEOUT 30 26#define OT_CLIENT_TIMEOUT 30
@@ -60,7 +59,7 @@ extern uint32_t g_tracker_id;
60typedef enum { FLAG_TCP, FLAG_UDP, FLAG_MCA } PROTO_FLAG; 59typedef enum { FLAG_TCP, FLAG_UDP, FLAG_MCA } PROTO_FLAG;
61 60
62typedef struct { 61typedef struct {
63 uint8_t data[8]; 62 uint8_t data[OT_IP_SIZE+2+2];
64} ot_peer; 63} ot_peer;
65static const uint8_t PEER_FLAG_SEEDING = 0x80; 64static const uint8_t PEER_FLAG_SEEDING = 0x80;
66static const uint8_t PEER_FLAG_COMPLETED = 0x40; 65static const uint8_t PEER_FLAG_COMPLETED = 0x40;
@@ -68,12 +67,17 @@ static const uint8_t PEER_FLAG_STOPPED = 0x20;
68static const uint8_t PEER_FLAG_FROM_SYNC = 0x10; 67static const uint8_t PEER_FLAG_FROM_SYNC = 0x10;
69static const uint8_t PEER_FLAG_LEECHING = 0x00; 68static const uint8_t PEER_FLAG_LEECHING = 0x00;
70 69
71#define OT_SETIP(peer,ip) WRITE32((peer),0,READ32((ip),0)) 70#ifdef WANT_V6
72#define OT_SETPORT(peer,port) WRITE16((peer),4,READ16((port),0)) 71#define OT_SETIP(peer,ip) memcpy((peer),(ip),(OT_IP_SIZE))
73#define OT_PEERFLAG(peer) (((uint8_t*)(peer))[6]) 72#else
74#define OT_PEERTIME(peer) (((uint8_t*)(peer))[7]) 73#define OT_SETIP(peer,ip) memcpy((peer),(((uint8_t*)ip)+12),(OT_IP_SIZE))
74#endif
75#define OT_SETPORT(peer,port) memcpy(((uint8_t*)(peer))+(OT_IP_SIZE),(port),2)
76#define OT_PEERFLAG(peer) (((uint8_t*)(peer))[(OT_IP_SIZE)+2])
77#define OT_PEERTIME(peer) (((uint8_t*)(peer))[(OT_IP_SIZE)+3])
75 78
76#define OT_HASH_COMPARE_SIZE (sizeof(ot_hash)) 79#define OT_HASH_COMPARE_SIZE (sizeof(ot_hash))
80#define OT_PEER_COMPARE_SIZE ((OT_IP_SIZE)+2)
77 81
78struct ot_peerlist; 82struct ot_peerlist;
79typedef struct ot_peerlist ot_peerlist; 83typedef struct ot_peerlist ot_peerlist;
@@ -98,16 +102,13 @@ struct ot_peerlist {
98 102
99struct ot_workstruct { 103struct ot_workstruct {
100 /* Thread specific, static */ 104 /* Thread specific, static */
101#define THREAD_INBUF_SIZE 8192
102 char *inbuf; 105 char *inbuf;
103 size_t inbuf_size; 106#define G_INBUF_SIZE 8192
104#define THREAD_OUTBUF_SIZE 8192
105 char *outbuf; 107 char *outbuf;
106 size_t outbuf_size; 108#define G_OUTBUF_SIZE 8192
107#ifdef _DEBUG_HTTPERROR 109#ifdef _DEBUG_HTTPERROR
108#define THREAD_DEBUGBUF_SIZE 8192
109 char *debugbuf; 110 char *debugbuf;
110 size_t debugbuf_size; 111#define G_DEBUGBUF_SIZE 8192
111#endif 112#endif
112 113
113 /* HTTP specific, non static */ 114 /* HTTP specific, non static */
@@ -115,10 +116,6 @@ struct ot_workstruct {
115 ssize_t request_size; 116 ssize_t request_size;
116 char *reply; 117 char *reply;
117 ssize_t reply_size; 118 ssize_t reply_size;
118#ifdef _DEBUG_PEERID
119 char *peer_id;
120 ssize_t peer_id_size;
121#endif
122}; 119};
123 120
124/* 121/*
@@ -135,6 +132,10 @@ struct ot_workstruct {
135#define WANT_SYNC_PARAM( param ) 132#define WANT_SYNC_PARAM( param )
136#endif 133#endif
137 134
135#if defined WANT_V6 && defined WANT_LOG_NETWORKS
136#undef WANT_LOG_NETWORKS
137#endif
138
138void trackerlogic_init( ); 139void trackerlogic_init( );
139void trackerlogic_deinit( void ); 140void trackerlogic_deinit( void );
140void exerr( char * message ); 141void exerr( char * message );
@@ -142,10 +143,10 @@ void exerr( char * message );
142/* add_peer_to_torrent does only release the torrent bucket if from_sync is set, 143/* add_peer_to_torrent does only release the torrent bucket if from_sync is set,
143 otherwise it is released in return_peers_for_torrent */ 144 otherwise it is released in return_peers_for_torrent */
144#define add_peer_to_torrent(hash,peer,proto) add_peer_to_torrent_and_return_peers(hash,peer,proto,0,NULL) 145#define add_peer_to_torrent(hash,peer,proto) add_peer_to_torrent_and_return_peers(hash,peer,proto,0,NULL)
145size_t add_peer_to_torrent_and_return_peers( ot_hash *hash, ot_peer *peer, PROTO_FLAG proto, size_t amount, char * reply ); 146size_t add_peer_to_torrent_and_return_peers( ot_hash hash, ot_peer *peer, PROTO_FLAG proto, size_t amount, char * reply );
146size_t remove_peer_from_torrent( ot_hash *hash, ot_peer *peer, char *reply, PROTO_FLAG proto ); 147size_t remove_peer_from_torrent( ot_hash hash, ot_peer *peer, char *reply, PROTO_FLAG proto );
147size_t return_tcp_scrape_for_torrent( ot_hash *hash, int amount, char *reply ); 148size_t return_tcp_scrape_for_torrent( ot_hash *hash, int amount, char *reply );
148size_t return_udp_scrape_for_torrent( ot_hash *hash, char *reply ); 149size_t return_udp_scrape_for_torrent( ot_hash hash, char *reply );
149 150
150/* Helper, before it moves to its own object */ 151/* Helper, before it moves to its own object */
151void free_peerlist( ot_peerlist *peer_list ); 152void free_peerlist( ot_peerlist *peer_list );