summaryrefslogtreecommitdiff
path: root/auto_tests/onion_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'auto_tests/onion_test.c')
-rw-r--r--auto_tests/onion_test.c41
1 files changed, 21 insertions, 20 deletions
diff --git a/auto_tests/onion_test.c b/auto_tests/onion_test.c
index 58fde2d6..dd5a1946 100644
--- a/auto_tests/onion_test.c
+++ b/auto_tests/onion_test.c
@@ -23,7 +23,7 @@
23#define c_sleep(x) usleep(1000*x) 23#define c_sleep(x) usleep(1000*x)
24#endif 24#endif
25 25
26void do_onion(Onion *onion) 26static void do_onion(Onion *onion)
27{ 27{
28 networking_poll(onion->net, NULL); 28 networking_poll(onion->net, NULL);
29 do_DHT(onion->dht); 29 do_DHT(onion->dht);
@@ -38,7 +38,7 @@ static int handle_test_1(void *object, IP_Port source, const uint8_t *packet, ui
38 return 1; 38 return 1;
39 } 39 }
40 40
41 if (send_onion_response(onion->net, source, (uint8_t *)"install gentoo", sizeof("install gentoo"), 41 if (send_onion_response(onion->net, source, (const uint8_t *)"install gentoo", sizeof("install gentoo"),
42 packet + sizeof("Install Gentoo")) == -1) { 42 packet + sizeof("Install Gentoo")) == -1) {
43 return 1; 43 return 1;
44 } 44 }
@@ -54,14 +54,14 @@ static int handle_test_2(void *object, IP_Port source, const uint8_t *packet, ui
54 return 1; 54 return 1;
55 } 55 }
56 56
57 if (memcmp(packet, (uint8_t *)"install gentoo", sizeof("install gentoo")) != 0) { 57 if (memcmp(packet, (const uint8_t *)"install gentoo", sizeof("install gentoo")) != 0) {
58 return 1; 58 return 1;
59 } 59 }
60 60
61 handled_test_2 = 1; 61 handled_test_2 = 1;
62 return 0; 62 return 0;
63} 63}
64/* 64#if 0
65void print_client_id(uint8_t *client_id, uint32_t length) 65void print_client_id(uint8_t *client_id, uint32_t length)
66{ 66{
67 uint32_t j; 67 uint32_t j;
@@ -69,13 +69,14 @@ void print_client_id(uint8_t *client_id, uint32_t length)
69 for (j = 0; j < length; j++) { 69 for (j = 0; j < length; j++) {
70 printf("%02hhX", client_id[j]); 70 printf("%02hhX", client_id[j]);
71 } 71 }
72
72 printf("\n"); 73 printf("\n");
73} 74}
74*/ 75#endif
75uint8_t sb_data[ONION_ANNOUNCE_SENDBACK_DATA_LENGTH]; 76static uint8_t sb_data[ONION_ANNOUNCE_SENDBACK_DATA_LENGTH];
76static int handled_test_3; 77static int handled_test_3;
77uint8_t test_3_pub_key[crypto_box_PUBLICKEYBYTES]; 78static uint8_t test_3_pub_key[crypto_box_PUBLICKEYBYTES];
78uint8_t test_3_ping_id[crypto_hash_sha256_BYTES]; 79static uint8_t test_3_ping_id[crypto_hash_sha256_BYTES];
79static int handle_test_3(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) 80static int handle_test_3(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata)
80{ 81{
81 Onion *onion = object; 82 Onion *onion = object;
@@ -106,7 +107,7 @@ static int handle_test_3(void *object, IP_Port source, const uint8_t *packet, ui
106 return 0; 107 return 0;
107} 108}
108 109
109uint8_t nonce[crypto_box_NONCEBYTES]; 110static uint8_t nonce[crypto_box_NONCEBYTES];
110static int handled_test_4; 111static int handled_test_4;
111static int handle_test_4(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) 112static int handle_test_4(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata)
112{ 113{
@@ -165,7 +166,7 @@ START_TEST(test_basic)
165 nodes[3] = n2; 166 nodes[3] = n2;
166 Onion_Path path; 167 Onion_Path path;
167 create_onion_path(onion1->dht, &path, nodes); 168 create_onion_path(onion1->dht, &path, nodes);
168 int ret = send_onion_packet(onion1->net, &path, nodes[3].ip_port, (uint8_t *)"Install Gentoo", 169 int ret = send_onion_packet(onion1->net, &path, nodes[3].ip_port, (const uint8_t *)"Install Gentoo",
169 sizeof("Install Gentoo")); 170 sizeof("Install Gentoo"));
170 ck_assert_msg(ret == 0, "Failed to create/send onion packet."); 171 ck_assert_msg(ret == 0, "Failed to create/send onion packet.");
171 172
@@ -227,7 +228,7 @@ START_TEST(test_basic)
227 new_nonce(nonce); 228 new_nonce(nonce);
228 ret = send_data_request(onion3->net, &path, nodes[3].ip_port, onion1->dht->self_public_key, 229 ret = send_data_request(onion3->net, &path, nodes[3].ip_port, onion1->dht->self_public_key,
229 onion1->dht->self_public_key, 230 onion1->dht->self_public_key,
230 nonce, (uint8_t *)"Install gentoo", sizeof("Install gentoo")); 231 nonce, (const uint8_t *)"Install gentoo", sizeof("Install gentoo"));
231 ck_assert_msg(ret == 0, "Failed to create/send onion data_request packet."); 232 ck_assert_msg(ret == 0, "Failed to create/send onion data_request packet.");
232 handled_test_4 = 0; 233 handled_test_4 = 0;
233 234
@@ -278,7 +279,7 @@ typedef struct {
278 Onion_Client *onion_c; 279 Onion_Client *onion_c;
279} Onions; 280} Onions;
280 281
281Onions *new_onions(uint16_t port) 282static Onions *new_onions(uint16_t port)
282{ 283{
283 IP ip; 284 IP ip;
284 ip_init(&ip, 1); 285 ip_init(&ip, 1);
@@ -297,14 +298,14 @@ Onions *new_onions(uint16_t port)
297 return NULL; 298 return NULL;
298} 299}
299 300
300void do_onions(Onions *on) 301static void do_onions(Onions *on)
301{ 302{
302 networking_poll(on->onion->net, NULL); 303 networking_poll(on->onion->net, NULL);
303 do_DHT(on->onion->dht); 304 do_DHT(on->onion->dht);
304 do_onion_client(on->onion_c); 305 do_onion_client(on->onion_c);
305} 306}
306 307
307void kill_onions(Onions *on) 308static void kill_onions(Onions *on)
308{ 309{
309 Networking_Core *net = on->onion->dht->net; 310 Networking_Core *net = on->onion->dht->net;
310 DHT *dht = on->onion->dht; 311 DHT *dht = on->onion->dht;
@@ -322,8 +323,8 @@ void kill_onions(Onions *on)
322#define NUM_FIRST 7 323#define NUM_FIRST 7
323#define NUM_LAST 37 324#define NUM_LAST 37
324 325
325_Bool first_ip, last_ip; 326static _Bool first_ip, last_ip;
326void dht_ip_callback(void *object, int32_t number, IP_Port ip_port) 327static void dht_ip_callback(void *object, int32_t number, IP_Port ip_port)
327{ 328{
328 if (NUM_FIRST == number) { 329 if (NUM_FIRST == number) {
329 first_ip = 1; 330 first_ip = 1;
@@ -338,9 +339,9 @@ void dht_ip_callback(void *object, int32_t number, IP_Port ip_port)
338 ck_abort_msg("Error."); 339 ck_abort_msg("Error.");
339} 340}
340 341
341_Bool first, last; 342static _Bool first, last;
342uint8_t first_dht_pk[crypto_box_PUBLICKEYBYTES]; 343static uint8_t first_dht_pk[crypto_box_PUBLICKEYBYTES];
343uint8_t last_dht_pk[crypto_box_PUBLICKEYBYTES]; 344static uint8_t last_dht_pk[crypto_box_PUBLICKEYBYTES];
344 345
345static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_public_key, void *userdata) 346static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_public_key, void *userdata)
346{ 347{
@@ -460,7 +461,7 @@ START_TEST(test_announce)
460} 461}
461END_TEST 462END_TEST
462 463
463Suite *onion_suite(void) 464static Suite *onion_suite(void)
464{ 465{
465 Suite *s = suite_create("Onion"); 466 Suite *s = suite_create("Onion");
466 467