summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile21
-rw-r--r--ot_clean.h2
-rw-r--r--ot_http.h8
-rw-r--r--ot_iovec.c3
-rw-r--r--ot_stats.c8
-rw-r--r--ot_udp.c3
-rw-r--r--ot_udp.h2
-rw-r--r--ot_vector.h5
-rw-r--r--scan_urlencoded_query.c14
-rw-r--r--scan_urlencoded_query.h4
-rw-r--r--tests/t_scan_urlencoded_query.c9
-rw-r--r--tests/t_socket.c8
12 files changed, 38 insertions, 49 deletions
diff --git a/Makefile b/Makefile
index 2587b62..9a09e7b 100644
--- a/Makefile
+++ b/Makefile
@@ -87,26 +87,31 @@ CFLAGS_debug = $(CFLAGS) $(OPTS_debug) $(FEATURES)
87CFLAGS_proxy = $(CFLAGS_production) -DWANT_SYNC_LIVE 87CFLAGS_proxy = $(CFLAGS_production) -DWANT_SYNC_LIVE
88CFLAGS_proxy_debug = $(CFLAGS_debug) -DWANT_SYNC_LIVE 88CFLAGS_proxy_debug = $(CFLAGS_debug) -DWANT_SYNC_LIVE
89 89
90$(BINARY): $(OBJECTS) $(HEADERS) 90$(BINARY): $(OBJECTS)
91 $(CC) -o $@ $(OBJECTS) $(LDFLAGS) 91 $(CC) -o $@ $(OBJECTS) $(LDFLAGS)
92 $(STRIP) $@ 92 $(STRIP) $@
93$(BINARY).debug: $(OBJECTS_debug) $(HEADERS) 93$(BINARY).debug: $(OBJECTS_debug)
94 $(CC) -o $@ $(OBJECTS_debug) $(LDFLAGS) 94 $(CC) -o $@ $(OBJECTS_debug) $(LDFLAGS)
95proxy: $(OBJECTS_proxy) $(HEADERS) 95proxy: $(OBJECTS_proxy)
96 $(CC) -o $@ $(OBJECTS_proxy) $(CFLAGS_production) $(LDFLAGS) 96 $(CC) -o $@ $(OBJECTS_proxy) $(CFLAGS_production) $(LDFLAGS)
97proxy.debug: $(OBJECTS_proxy_debug) $(HEADERS) 97proxy.debug: $(OBJECTS_proxy_debug)
98 $(CC) -o $@ $(OBJECTS_proxy_debug) $(LDFLAGS) 98 $(CC) -o $@ $(OBJECTS_proxy_debug) $(LDFLAGS)
99 99
100.c.proxy.debug.o : $(HEADERS) 100$(OBJECTS): $(HEADERS)
101$(OBJECTS_debug): $(HEADERS)
102$(OBJECTS_proxy): $(HEADERS)
103$(OBJECTS_proxy_debug): $(HEADERS)
104
105.c.proxy.debug.o :
101 $(CC) -c -o $@ $(CFLAGS_proxy_debug) $(<:.proxy.debug.o=.c) 106 $(CC) -c -o $@ $(CFLAGS_proxy_debug) $(<:.proxy.debug.o=.c)
102 107
103.c.proxy.o : $(HEADERS) 108.c.proxy.o :
104 $(CC) -c -o $@ $(CFLAGS_proxy) $(<:.proxy.o=.c) 109 $(CC) -c -o $@ $(CFLAGS_proxy) $(<:.proxy.o=.c)
105 110
106.c.debug.o : $(HEADERS) 111.c.debug.o :
107 $(CC) -c -o $@ $(CFLAGS_debug) $(<:.debug.o=.c) 112 $(CC) -c -o $@ $(CFLAGS_debug) $(<:.debug.o=.c)
108 113
109.c.o : $(HEADERS) 114.c.o :
110 $(CC) -c -o $@ $(CFLAGS_production) $< 115 $(CC) -c -o $@ $(CFLAGS_production) $<
111 116
112# Unit tests. The modules under test are compiled straight into the test 117# Unit tests. The modules under test are compiled straight into the test
diff --git a/ot_clean.h b/ot_clean.h
index e8bcdc1..1484d82 100644
--- a/ot_clean.h
+++ b/ot_clean.h
@@ -6,6 +6,8 @@
6#ifndef OT_CLEAN_H__ 6#ifndef OT_CLEAN_H__
7#define OT_CLEAN_H__ 7#define OT_CLEAN_H__
8 8
9#include "trackerlogic.h"
10
9/* The amount of time a clean cycle should take */ 11/* The amount of time a clean cycle should take */
10#define OT_CLEAN_INTERVAL_MINUTES 2 12#define OT_CLEAN_INTERVAL_MINUTES 2
11 13
diff --git a/ot_http.h b/ot_http.h
index 004d710..965820f 100644
--- a/ot_http.h
+++ b/ot_http.h
@@ -6,7 +6,15 @@
6#ifndef OT_HTTP_H__ 6#ifndef OT_HTTP_H__
7#define OT_HTTP_H__ 7#define OT_HTTP_H__
8 8
9#include <stdint.h>
10#include <sys/types.h>
11#include <sys/uio.h>
12
13/* Libowfat */
14#include "iob.h"
15
9#include "ot_buf.h" 16#include "ot_buf.h"
17#include "trackerlogic.h"
10 18
11typedef enum { 19typedef enum {
12 STRUCT_HTTP_FLAG_WAITINGFORTASK = 1, 20 STRUCT_HTTP_FLAG_WAITINGFORTASK = 1,
diff --git a/ot_iovec.c b/ot_iovec.c
index bab19e3..cd5b9f9 100644
--- a/ot_iovec.c
+++ b/ot_iovec.c
@@ -20,6 +20,8 @@ void *iovec_increase(size_t *iovec_entries, struct iovec **iovector, size_t new_
20 if (!new_vec) 20 if (!new_vec)
21 return NULL; 21 return NULL;
22 22
23 *iovector = new_vec;
24
23 /* Only allocate after we have a place to store the pointer */ 25 /* Only allocate after we have a place to store the pointer */
24 new_data = malloc(new_alloc); 26 new_data = malloc(new_alloc);
25 if (!new_data) 27 if (!new_data)
@@ -28,7 +30,6 @@ void *iovec_increase(size_t *iovec_entries, struct iovec **iovector, size_t new_
28 new_vec[new_entries - 1].iov_base = new_data; 30 new_vec[new_entries - 1].iov_base = new_data;
29 new_vec[new_entries - 1].iov_len = new_alloc; 31 new_vec[new_entries - 1].iov_len = new_alloc;
30 32
31 *iovector = new_vec;
32 ++*iovec_entries; 33 ++*iovec_entries;
33 return new_data; 34 return new_data;
34} 35}
diff --git a/ot_stats.c b/ot_stats.c
index 7945f4e..f938e91 100644
--- a/ot_stats.c
+++ b/ot_stats.c
@@ -206,10 +206,6 @@ static size_t stats_return_busy_networks(char *reply, stats_network_node *tree,
206 r += sprintf(r, "%08zd: ", scores[i - 1]); 206 r += sprintf(r, "%08zd: ", scores[i - 1]);
207 // #ifdef WANT_V6 207 // #ifdef WANT_V6
208 r += ip_format(r, networks[i - 1]); 208 r += ip_format(r, networks[i - 1]);
209#if 0
210 // XXX
211 r += fmt_ip4( r, networks[i - 1]);
212#endif
213 *r++ = '\n'; 209 *r++ = '\n';
214 } 210 }
215 } 211 }
@@ -663,10 +659,6 @@ void stats_issue_event(ot_status_event event, PROTO_FLAG proto, uintptr_t event_
663 } 659 }
664 660
665 ip_readable[ip_format(ip_readable, (char *)&ws->peer)] = 0; 661 ip_readable[ip_format(ip_readable, (char *)&ws->peer)] = 0;
666#if 0
667 /* XXX */
668 ip_readable[ fmt_ip4( ip_readable, (char*)&ws->peer ) ] = 0;
669#endif
670 syslog(LOG_INFO, "time=%s event=completed info_hash=%s peer_id=%s ip=%s", timestring, hash_hex, peerid_hex, ip_readable); 662 syslog(LOG_INFO, "time=%s event=completed info_hash=%s peer_id=%s ip=%s", timestring, hash_hex, peerid_hex, ip_readable);
671 } 663 }
672#endif 664#endif
diff --git a/ot_udp.c b/ot_udp.c
index e80f4e7..dc8267c 100644
--- a/ot_udp.c
+++ b/ot_udp.c
@@ -22,9 +22,6 @@
22#include "ot_udp.h" 22#include "ot_udp.h"
23#include "trackerlogic.h" 23#include "trackerlogic.h"
24 24
25#if 0
26static const uint8_t g_static_connid[8] = { 0x23, 0x42, 0x05, 0x17, 0xde, 0x41, 0x50, 0xff };
27#endif
28static uint32_t g_rijndael_round_key[44] = {0}; 25static uint32_t g_rijndael_round_key[44] = {0};
29static volatile uint32_t g_key_of_the_hour[2] = {0}; 26static volatile uint32_t g_key_of_the_hour[2] = {0};
30static volatile ot_time g_hour_of_the_key; 27static volatile ot_time g_hour_of_the_key;
diff --git a/ot_udp.h b/ot_udp.h
index c670175..87d99a9 100644
--- a/ot_udp.h
+++ b/ot_udp.h
@@ -8,6 +8,8 @@
8 8
9#include <stdint.h> 9#include <stdint.h>
10 10
11#include "trackerlogic.h"
12
11void udp_init(int64_t sock, unsigned int worker_count); 13void udp_init(int64_t sock, unsigned int worker_count);
12void udp_kickoff(void); 14void udp_kickoff(void);
13int handle_udp6(int64_t serversocket, struct ot_workstruct *ws); 15int handle_udp6(int64_t serversocket, struct ot_workstruct *ws);
diff --git a/ot_vector.h b/ot_vector.h
index 2618363..fbc75f4 100644
--- a/ot_vector.h
+++ b/ot_vector.h
@@ -6,6 +6,8 @@
6#ifndef OT_VECTOR_H__ 6#ifndef OT_VECTOR_H__
7#define OT_VECTOR_H__ 7#define OT_VECTOR_H__
8 8
9#include <stddef.h>
10
9/* These defines control vectors behaviour */ 11/* These defines control vectors behaviour */
10#define OT_VECTOR_MIN_MEMBERS 2 12#define OT_VECTOR_MIN_MEMBERS 2
11#define OT_VECTOR_GROW_RATIO 2 13#define OT_VECTOR_GROW_RATIO 2
@@ -21,6 +23,9 @@ typedef struct {
21 size_t space; 23 size_t space;
22} ot_vector; 24} ot_vector;
23 25
26/* trackerlogic.h needs ot_vector, break circular dependency here */
27#include "trackerlogic.h"
28
24void *binary_search(const void *const key, const void *base, const size_t member_count, const size_t member_size, size_t compare_size, int *exactmatch); 29void *binary_search(const void *const key, const void *base, const size_t member_count, const size_t member_size, size_t compare_size, int *exactmatch);
25void *vector_find_or_insert(ot_vector *vector, void *key, size_t member_size, size_t compare_size, int *exactmatch); 30void *vector_find_or_insert(ot_vector *vector, void *key, size_t member_size, size_t compare_size, int *exactmatch);
26ot_peer *vector_find_or_insert_peer(ot_vector *vector, ot_peer const *peer, size_t peer_size, int *exactmatch); 31ot_peer *vector_find_or_insert_peer(ot_vector *vector, ot_peer const *peer, size_t peer_size, int *exactmatch);
diff --git a/scan_urlencoded_query.c b/scan_urlencoded_query.c
index cf0c5b1..4825a4a 100644
--- a/scan_urlencoded_query.c
+++ b/scan_urlencoded_query.c
@@ -170,16 +170,12 @@ size_t fmt_urlencoded(char *dest, const uint8_t *src, size_t len) {
170 170
171 /* strchr would find the terminator, so a zero byte never counts as safe */ 171 /* strchr would find the terminator, so a zero byte never counts as safe */
172 if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || (c && strchr(safe, c))) { 172 if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || (c && strchr(safe, c))) {
173 if (dest) 173 dest[written++] = (char)c;
174 dest[written] = (char)c;
175 ++written;
176 } else { 174 } else {
177 if (dest) { 175 dest[written] = '%';
178 dest[written] = '%'; 176 dest[written + 1] = hexdigit[c >> 4];
179 dest[written + 1] = hexdigit[c >> 4]; 177 dest[written + 2] = hexdigit[c & 15];
180 dest[written + 2] = hexdigit[c & 15]; 178 written += 3;
181 }
182 written += 3;
183 } 179 }
184 } 180 }
185 181
diff --git a/scan_urlencoded_query.h b/scan_urlencoded_query.h
index 6f12c03..d0929cf 100644
--- a/scan_urlencoded_query.h
+++ b/scan_urlencoded_query.h
@@ -55,9 +55,7 @@ void scan_urlencoded_skipvalue(char **string);
55ssize_t scan_fixed_int(char *data, size_t len, int *number); 55ssize_t scan_fixed_int(char *data, size_t len, int *number);
56 56
57/* The other direction: percent encode len bytes from src into dest and return 57/* The other direction: percent encode len bytes from src into dest and return
58 how many characters were written, or how many would be needed when dest is 58 how many characters were written. dest needs room for three times len. */
59 NULL. dest needs room for three times len.
60 */
61size_t fmt_urlencoded(char *dest, const uint8_t *src, size_t len); 59size_t fmt_urlencoded(char *dest, const uint8_t *src, size_t len);
62 60
63#endif 61#endif
diff --git a/tests/t_scan_urlencoded_query.c b/tests/t_scan_urlencoded_query.c
index 6fa34e0..f660ea3 100644
--- a/tests/t_scan_urlencoded_query.c
+++ b/tests/t_scan_urlencoded_query.c
@@ -295,14 +295,6 @@ static void case_fmt_hex_is_lower_case(void) {
295 CHECK_STR(dest, "%00%ab%ff"); 295 CHECK_STR(dest, "%00%ab%ff");
296} 296}
297 297
298static void case_fmt_length_only(void) {
299 const uint8_t src[] = {'a', 0xff, 'b'};
300
301 test_case("a null destination reports the length without writing");
302 CHECK_INT(fmt_urlencoded(NULL, src, sizeof(src)), 5);
303 CHECK_INT(fmt_urlencoded(NULL, src, 0), 0);
304}
305
306static void case_fmt_zero_length(void) { 298static void case_fmt_zero_length(void) {
307 char dest[4]; 299 char dest[4];
308 300
@@ -374,7 +366,6 @@ void test_scan_urlencoded_query(void) {
374 case_fmt_passes_safe_bytes(); 366 case_fmt_passes_safe_bytes();
375 case_fmt_escapes_the_rest(); 367 case_fmt_escapes_the_rest();
376 case_fmt_hex_is_lower_case(); 368 case_fmt_hex_is_lower_case();
377 case_fmt_length_only();
378 case_fmt_zero_length(); 369 case_fmt_zero_length();
379 case_fmt_worst_case_fits(); 370 case_fmt_worst_case_fits();
380 case_fmt_decoder_disagrees_on_dollar(); 371 case_fmt_decoder_disagrees_on_dollar();
diff --git a/tests/t_socket.c b/tests/t_socket.c
index cf7d291..bbc9e5e 100644
--- a/tests/t_socket.c
+++ b/tests/t_socket.c
@@ -58,14 +58,6 @@ static void bound_address(int s, char ip[16], uint16_t *port) {
58 } 58 }
59} 59}
60 60
61static uint16_t bound_port(int s) {
62 char ip[16];
63 uint16_t port;
64
65 bound_address(s, ip, &port);
66 return port;
67}
68
69static int is_nonblocking(int s) { 61static int is_nonblocking(int s) {
70 int flags = fcntl(s, F_GETFL, 0); 62 int flags = fcntl(s, F_GETFL, 0);
71 return flags != -1 && (flags & O_NONBLOCK) != 0; 63 return flags != -1 && (flags & O_NONBLOCK) != 0;