summaryrefslogtreecommitdiff
path: root/ot_udp.c
diff options
context:
space:
mode:
Diffstat (limited to 'ot_udp.c')
-rw-r--r--ot_udp.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/ot_udp.c b/ot_udp.c
index 4e760bb..14210c3 100644
--- a/ot_udp.c
+++ b/ot_udp.c
@@ -30,7 +30,7 @@ static void udp_generate_rijndael_round_key(void) {
30 rijndaelKeySetupEnc128(g_rijndael_round_key, (uint8_t *)key); 30 rijndaelKeySetupEnc128(g_rijndael_round_key, (uint8_t *)key);
31 31
32 g_key_of_the_hour[0] = random_uint32(); 32 g_key_of_the_hour[0] = random_uint32();
33 g_hour_of_the_key = g_now_minutes; 33 g_hour_of_the_key = time_now_minutes();
34} 34}
35 35
36/* Generate current and previous connection id for ip */ 36/* Generate current and previous connection id for ip */
@@ -39,14 +39,14 @@ static void udp_make_connectionid(uint32_t connid[2], const ot_ip6 remoteip, int
39 int i; 39 int i;
40 uint32_t current_key_of_the_hour; 40 uint32_t current_key_of_the_hour;
41 41
42 if (g_now_minutes - g_hour_of_the_key >= 60) { 42 if (time_now_minutes() - g_hour_of_the_key >= 60) {
43 uint32_t old_key_of_the_hour = g_key_of_the_hour[0]; 43 uint32_t old_key_of_the_hour = g_key_of_the_hour[0];
44 uint32_t new_key_of_the_hour = random_uint32(); 44 uint32_t new_key_of_the_hour = random_uint32();
45 /* If in the meantime another thread has performed 45 /* If in the meantime another thread has performed
46 key rotation, do not overwrite their results */ 46 key rotation, do not overwrite their results */
47 if (g_now_minutes - g_hour_of_the_key >= 60) { 47 if (time_now_minutes() - g_hour_of_the_key >= 60) {
48 /* Upgrade en bloc */ 48 /* Upgrade en bloc */
49 g_hour_of_the_key = g_now_minutes; 49 g_hour_of_the_key = time_now_minutes();
50 g_key_of_the_hour[0] = new_key_of_the_hour; 50 g_key_of_the_hour[0] = new_key_of_the_hour;
51 g_key_of_the_hour[1] = old_key_of_the_hour; 51 g_key_of_the_hour[1] = old_key_of_the_hour;
52 } 52 }
@@ -77,8 +77,8 @@ int handle_udp6(int64_t serversocket, struct ot_workstruct *ws) {
77 return 0; 77 return 0;
78 byte_count = (size_t)result; 78 byte_count = (size_t)result;
79 79
80 stats_issue_event(EVENT_ACCEPT, FLAG_UDP, (uintptr_t)remoteip); 80 stats_issue_event(ws, EVENT_ACCEPT, FLAG_UDP, (uintptr_t)remoteip);
81 stats_issue_event(EVENT_READ, FLAG_UDP, byte_count); 81 stats_issue_event(ws, EVENT_READ, FLAG_UDP, byte_count);
82 82
83 /* Minimum udp tracker packet size, also catches error */ 83 /* Minimum udp tracker packet size, also catches error */
84 if (byte_count < 16) 84 if (byte_count < 16)
@@ -111,7 +111,7 @@ int handle_udp6(int64_t serversocket, struct ot_workstruct *ws) {
111 outpacket[1] = inpacket[3]; 111 outpacket[1] = inpacket[3];
112 memcpy(&outpacket[2], &err_idmiss[0], s); 112 memcpy(&outpacket[2], &err_idmiss[0], s);
113 socket_send(serversocket, ws->outbuf, 8 + s, remoteip, remoteport); 113 socket_send(serversocket, ws->outbuf, 8 + s, remoteip, remoteport);
114 stats_issue_event(EVENT_CONNID_MISSMATCH, FLAG_UDP, 8 + s); 114 stats_issue_event(ws, EVENT_CONNID_MISSMATCH, FLAG_UDP, 8 + s);
115 return 1; 115 return 1;
116 } 116 }
117 } 117 }
@@ -128,7 +128,7 @@ int handle_udp6(int64_t serversocket, struct ot_workstruct *ws) {
128 outpacket[3] = connid[1]; 128 outpacket[3] = connid[1];
129 129
130 socket_send(serversocket, ws->outbuf, 16, remoteip, remoteport); 130 socket_send(serversocket, ws->outbuf, 16, remoteip, remoteport);
131 stats_issue_event(EVENT_CONNECT, FLAG_UDP, 16); 131 stats_issue_event(ws, EVENT_CONNECT, FLAG_UDP, 16);
132 break; 132 break;
133 case 1: /* This is an announce action */ 133 case 1: /* This is an announce action */
134 /* Minimum udp announce packet size */ 134 /* Minimum udp announce packet size */
@@ -188,7 +188,7 @@ int handle_udp6(int64_t serversocket, struct ot_workstruct *ws) {
188 } 188 }
189 189
190 socket_send(serversocket, ws->outbuf, ws->reply_size, remoteip, remoteport); 190 socket_send(serversocket, ws->outbuf, ws->reply_size, remoteip, remoteport);
191 stats_issue_event(EVENT_ANNOUNCE, FLAG_UDP, ws->reply_size); 191 stats_issue_event(ws, EVENT_ANNOUNCE, FLAG_UDP, ws->reply_size);
192 break; 192 break;
193 193
194 case 2: /* This is a scrape action */ 194 case 2: /* This is a scrape action */
@@ -199,7 +199,7 @@ int handle_udp6(int64_t serversocket, struct ot_workstruct *ws) {
199 return_udp_scrape_for_torrent(*(ot_hash *)(((char *)inpacket) + 16 + 20 * scrape_count), ((char *)outpacket) + 8 + 12 * scrape_count); 199 return_udp_scrape_for_torrent(*(ot_hash *)(((char *)inpacket) + 16 + 20 * scrape_count), ((char *)outpacket) + 8 + 12 * scrape_count);
200 200
201 socket_send(serversocket, ws->outbuf, 8 + 12 * scrape_count, remoteip, remoteport); 201 socket_send(serversocket, ws->outbuf, 8 + 12 * scrape_count, remoteip, remoteport);
202 stats_issue_event(EVENT_SCRAPE, FLAG_UDP, scrape_count); 202 stats_issue_event(ws, EVENT_SCRAPE, FLAG_UDP, scrape_count);
203 break; 203 break;
204 } 204 }
205 return 1; 205 return 1;
@@ -210,6 +210,7 @@ static void *udp_worker(void *args) {
210 struct ot_workstruct ws; 210 struct ot_workstruct ws;
211 memset(&ws, 0, sizeof(ws)); 211 memset(&ws, 0, sizeof(ws));
212 212
213 stats_counters_register(&ws);
213 ws.inbuf = malloc(G_INBUF_SIZE); 214 ws.inbuf = malloc(G_INBUF_SIZE);
214 ws.outbuf = malloc(G_OUTBUF_SIZE); 215 ws.outbuf = malloc(G_OUTBUF_SIZE);
215#ifdef _DEBUG_HTTPERROR 216#ifdef _DEBUG_HTTPERROR
@@ -219,6 +220,8 @@ static void *udp_worker(void *args) {
219 while (g_opentracker_running) 220 while (g_opentracker_running)
220 handle_udp6(sock, &ws); 221 handle_udp6(sock, &ws);
221 222
223 stats_counters_retire(&ws);
224
222 free(ws.inbuf); 225 free(ws.inbuf);
223 free(ws.outbuf); 226 free(ws.outbuf);
224#ifdef _DEBUG_HTTPERROR 227#ifdef _DEBUG_HTTPERROR