summaryrefslogtreecommitdiff
path: root/ot_udp.c
diff options
context:
space:
mode:
Diffstat (limited to 'ot_udp.c')
-rw-r--r--ot_udp.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/ot_udp.c b/ot_udp.c
index 82aa8bd..02467e1 100644
--- a/ot_udp.c
+++ b/ot_udp.c
@@ -12,10 +12,10 @@
12 12
13/* Libowfat */ 13/* Libowfat */
14#include "io.h" 14#include "io.h"
15#include "ip6.h"
16#include "socket.h" 15#include "socket.h"
17 16
18/* Opentracker */ 17/* Opentracker */
18#include "ot_ip.h"
19#include "ot_random.h" 19#include "ot_random.h"
20#include "ot_rijndael.h" 20#include "ot_rijndael.h"
21#include "ot_stats.h" 21#include "ot_stats.h"
@@ -71,7 +71,7 @@ static void udp_make_connectionid(uint32_t connid[2], const ot_ip6 remoteip, int
71} 71}
72 72
73/* UDP implementation according to http://xbtt.sourceforge.net/udp_tracker_protocol.html */ 73/* UDP implementation according to http://xbtt.sourceforge.net/udp_tracker_protocol.html */
74int handle_udp6(int64 serversocket, struct ot_workstruct *ws) { 74int handle_udp6(int64_t serversocket, struct ot_workstruct *ws) {
75 ot_ip6 remoteip; 75 ot_ip6 remoteip;
76 uint32_t *inpacket = (uint32_t *)ws->inbuf; 76 uint32_t *inpacket = (uint32_t *)ws->inbuf;
77 uint32_t *outpacket = (uint32_t *)ws->outbuf; 77 uint32_t *outpacket = (uint32_t *)ws->outbuf;
@@ -81,9 +81,10 @@ int handle_udp6(int64 serversocket, struct ot_workstruct *ws) {
81 uint16_t port, remoteport; 81 uint16_t port, remoteport;
82 size_t byte_count, scrape_count; 82 size_t byte_count, scrape_count;
83 83
84 byte_count = socket_recv6(serversocket, ws->inbuf, G_INBUF_SIZE, remoteip, &remoteport, &scopeid); 84 ssize_t result = socket_recv6(serversocket, ws->inbuf, G_INBUF_SIZE, remoteip, &remoteport, &scopeid);
85 if (!byte_count) 85 if (result <= 0)
86 return 0; 86 return 0;
87 byte_count = (size_t)result;
87 88
88 stats_issue_event(EVENT_ACCEPT, FLAG_UDP, (uintptr_t)remoteip); 89 stats_issue_event(EVENT_ACCEPT, FLAG_UDP, (uintptr_t)remoteip);
89 stats_issue_event(EVENT_READ, FLAG_UDP, byte_count); 90 stats_issue_event(EVENT_READ, FLAG_UDP, byte_count);
@@ -176,7 +177,7 @@ int handle_udp6(int64 serversocket, struct ot_workstruct *ws) {
176 } else { 177 } else {
177 /* Limit amount of peers to OT_MAX_PEERS_UDP */ 178 /* Limit amount of peers to OT_MAX_PEERS_UDP */
178 uint32_t numwant = ntohl(inpacket[92 / 4]); 179 uint32_t numwant = ntohl(inpacket[92 / 4]);
179 size_t max_peers = ip6_isv4mapped(remoteip) ? OT_MAX_PEERS_UDP4 : OT_MAX_PEERS_UDP6; 180 size_t max_peers = ip_is_v4mapped(remoteip) ? OT_MAX_PEERS_UDP4 : OT_MAX_PEERS_UDP6;
180 if (numwant > max_peers) 181 if (numwant > max_peers)
181 numwant = max_peers; 182 numwant = max_peers;
182 183
@@ -203,7 +204,7 @@ int handle_udp6(int64 serversocket, struct ot_workstruct *ws) {
203} 204}
204 205
205static void *udp_worker(void *args) { 206static void *udp_worker(void *args) {
206 int64 sock = (int64)args; 207 int64_t sock = (int64_t)args;
207 struct ot_workstruct ws; 208 struct ot_workstruct ws;
208 memset(&ws, 0, sizeof(ws)); 209 memset(&ws, 0, sizeof(ws));
209 210
@@ -229,7 +230,7 @@ static void *udp_worker(void *args) {
229 return NULL; 230 return NULL;
230} 231}
231 232
232void udp_init(int64 sock, unsigned int worker_count) { 233void udp_init(int64_t sock, unsigned int worker_count) {
233 pthread_t thread_id; 234 pthread_t thread_id;
234 if (!g_rijndael_round_key[0]) 235 if (!g_rijndael_round_key[0])
235 udp_generate_rijndael_round_key(); 236 udp_generate_rijndael_round_key();