summaryrefslogtreecommitdiff
path: root/trackerlogic.h
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2024-04-03 22:25:30 +0200
committerDirk Engling <erdgeist@erdgeist.org>2024-04-03 22:25:30 +0200
commit2afc4893bf802700a1decfff57673cefc861c7e7 (patch)
tree9a0817371ac05062dbcf25107fcf5a6481feccc0 /trackerlogic.h
parenteb8834f7783cb85ae825976425800cd4af711263 (diff)
Prepare opentracker for dual stack capabilities
Diffstat (limited to 'trackerlogic.h')
-rw-r--r--trackerlogic.h54
1 files changed, 32 insertions, 22 deletions
diff --git a/trackerlogic.h b/trackerlogic.h
index f43b4f1..24ef097 100644
--- a/trackerlogic.h
+++ b/trackerlogic.h
@@ -24,16 +24,12 @@ typedef time_t ot_time;
24typedef char ot_ip6[16]; 24typedef char ot_ip6[16];
25typedef struct { ot_ip6 address; int bits; } 25typedef struct { ot_ip6 address; int bits; }
26 ot_net; 26 ot_net;
27#ifdef WANT_V6
28#define OT_IP_SIZE 16
29#define PEERS_BENCODED "6:peers6"
30/* List of peers should fit in a single UDP packet (around 1200 bytes) */ 27/* List of peers should fit in a single UDP packet (around 1200 bytes) */
31#define OT_MAX_PEERS_UDP 66 28#define OT_MAX_PEERS_UDP6 66
32#else 29#define OT_MAX_PEERS_UDP4 200
33#define OT_IP_SIZE 4 30
34#define PEERS_BENCODED "5:peers" 31#define OT_IP_SIZE6 16
35#define OT_MAX_PEERS_UDP 200 32#define OT_IP_SIZE4 4
36#endif
37#define OT_PORT_SIZE 2 33#define OT_PORT_SIZE 2
38#define OT_FLAG_SIZE 1 34#define OT_FLAG_SIZE 1
39#define OT_TIME_SIZE 1 35#define OT_TIME_SIZE 1
@@ -61,6 +57,7 @@ typedef struct { ot_ip6 address; int bits; }
61#define OT_ADMINIP_MAX 64 57#define OT_ADMINIP_MAX 64
62#define OT_MAX_THREADS 64 58#define OT_MAX_THREADS 64
63 59
60/* Number of minutes after announce before peer is removed */
64#define OT_PEER_TIMEOUT 45 61#define OT_PEER_TIMEOUT 45
65 62
66/* We maintain a list of 1024 pointers to sorted list of ot_torrent structs 63/* We maintain a list of 1024 pointers to sorted list of ot_torrent structs
@@ -78,23 +75,35 @@ extern volatile int g_opentracker_running;
78extern uint32_t g_tracker_id; 75extern uint32_t g_tracker_id;
79typedef enum { FLAG_TCP, FLAG_UDP, FLAG_MCA, FLAG_SELFPIPE } PROTO_FLAG; 76typedef enum { FLAG_TCP, FLAG_UDP, FLAG_MCA, FLAG_SELFPIPE } PROTO_FLAG;
80 77
81#define OT_PEER_COMPARE_SIZE ((OT_IP_SIZE)+(OT_PORT_SIZE)) 78#define OT_PEER_COMPARE_SIZE6 ((OT_IP_SIZE6)+(OT_PORT_SIZE))
82#define OT_PEER_SIZE ((OT_TIME_SIZE)+(OT_FLAG_SIZE)+(OT_PEER_COMPARE_SIZE)) 79#define OT_PEER_COMPARE_SIZE4 ((OT_IP_SIZE4)+(OT_PORT_SIZE))
83typedef uint8_t ot_peer[OT_PEER_SIZE]; 80#define OT_PEER_COMPARE_SIZE_FROM_PEER_SIZE(PEER_SIZE) ((PEER_SIZE)-(OT_TIME_SIZE)-(OT_FLAG_SIZE))
81
82#define OT_PEER_SIZE6 ((OT_TIME_SIZE)+(OT_FLAG_SIZE)+(OT_PEER_COMPARE_SIZE6))
83#define OT_PEER_SIZE4 ((OT_TIME_SIZE)+(OT_FLAG_SIZE)+(OT_PEER_COMPARE_SIZE4))
84
85typedef uint8_t ot_peer[1];
86typedef uint8_t ot_peer6[OT_PEER_SIZE6];
87typedef uint8_t ot_peer4[OT_PEER_SIZE4];
84static const uint8_t PEER_FLAG_SEEDING = 0x80; 88static const uint8_t PEER_FLAG_SEEDING = 0x80;
85static const uint8_t PEER_FLAG_COMPLETED = 0x40; 89static const uint8_t PEER_FLAG_COMPLETED = 0x40;
86static const uint8_t PEER_FLAG_STOPPED = 0x20; 90static const uint8_t PEER_FLAG_STOPPED = 0x20;
87static const uint8_t PEER_FLAG_FROM_SYNC = 0x10; 91static const uint8_t PEER_FLAG_FROM_SYNC = 0x10;
88static const uint8_t PEER_FLAG_LEECHING = 0x00; 92static const uint8_t PEER_FLAG_LEECHING = 0x00;
89 93
90#ifdef WANT_V6 94/* Takes an ot_peer6 and returns the proper pointer to the peer and sets peer_size */
91#define OT_SETIP(peer,ip) memcpy((peer),(ip),(OT_IP_SIZE)) 95ot_peer *peer_from_peer6(ot_peer6 *peer, size_t *peer_size);
92#else 96size_t peer_size_from_peer6(ot_peer6 *peer);
93#define OT_SETIP(peer,ip) memcpy((peer),(((uint8_t*)ip)+12),(OT_IP_SIZE)) 97
94#endif 98/* New style */
95#define OT_SETPORT(peer,port) memcpy(((uint8_t*)(peer))+(OT_IP_SIZE),(port),2) 99#define OT_SETIP(peer,ip) memcpy((peer),(ip),OT_IP_SIZE6)
96#define OT_PEERFLAG(peer) (((uint8_t*)(peer))[(OT_IP_SIZE)+2]) 100#define OT_SETPORT(peer,port) memcpy(((uint8_t*)(peer))+(OT_IP_SIZE6),(port),2)
97#define OT_PEERTIME(peer) (((uint8_t*)(peer))[(OT_IP_SIZE)+3]) 101#define OT_PEERFLAG(peer) (((uint8_t*)(peer))[(OT_IP_SIZE6)+2])
102#define OT_PEERFLAG_D(peer,peersize) (((uint8_t*)(peer))[(peersize)-2])
103#define OT_PEERTIME(peer,peersize) (((uint8_t*)(peer))[(peersize)-1])
104
105#define PEERS_BENCODED6 "6:peers6"
106#define PEERS_BENCODED4 "5:peers"
98 107
99#define OT_HASH_COMPARE_SIZE (sizeof(ot_hash)) 108#define OT_HASH_COMPARE_SIZE (sizeof(ot_hash))
100 109
@@ -102,7 +111,8 @@ struct ot_peerlist;
102typedef struct ot_peerlist ot_peerlist; 111typedef struct ot_peerlist ot_peerlist;
103typedef struct { 112typedef struct {
104 ot_hash hash; 113 ot_hash hash;
105 ot_peerlist *peer_list; 114 ot_peerlist *peer_list6;
115 ot_peerlist *peer_list4;
106} ot_torrent; 116} ot_torrent;
107 117
108#include "ot_vector.h" 118#include "ot_vector.h"
@@ -131,7 +141,7 @@ struct ot_workstruct {
131#endif 141#endif
132 142
133 /* The peer currently in the working */ 143 /* The peer currently in the working */
134 ot_peer peer; 144 ot_peer6 peer; /* Can fit v6 and v4 peers */
135 145
136 /* Pointers into the request buffer */ 146 /* Pointers into the request buffer */
137 ot_hash *hash; 147 ot_hash *hash;