summaryrefslogtreecommitdiff
path: root/auto_tests/dht_test.c
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2018-02-27 01:07:46 +0000
committeriphydf <iphydf@users.noreply.github.com>2018-05-20 19:35:28 +0000
commit21675ce0d2581597b0e0a727ab4cf6cfb796a037 (patch)
treee1ac4ca63c5cc2b2dc78fcd5b20a8202eab98d9d /auto_tests/dht_test.c
parent4f6ab0708c85f3e3da7726f6caecc381c6d21370 (diff)
Finish @Diadlo's network Family abstraction.
The Family stuff in toxcore is a big mess. I'm sure I saw a bunch of bugs on the way, but I'm not verifying that code now, so the bugs stay.
Diffstat (limited to 'auto_tests/dht_test.c')
-rw-r--r--auto_tests/dht_test.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/auto_tests/dht_test.c b/auto_tests/dht_test.c
index 803dad76..17f4563b 100644
--- a/auto_tests/dht_test.c
+++ b/auto_tests/dht_test.c
@@ -31,10 +31,10 @@ static inline IP get_loopback()
31{ 31{
32 IP ip; 32 IP ip;
33#if USE_IPV6 33#if USE_IPV6
34 ip.family = TOX_AF_INET6; 34 ip.family = net_family_ipv6;
35 ip.ip.v6 = get_ip6_loopback(); 35 ip.ip.v6 = get_ip6_loopback();
36#else 36#else
37 ip.family = TOX_AF_INET; 37 ip.family = net_family_ipv4;
38 ip.ip.v4 = get_ip4_loopback(); 38 ip.ip.v4 = get_ip4_loopback();
39#endif 39#endif
40 return ip; 40 return ip;
@@ -113,7 +113,7 @@ static void test_addto_lists_update(DHT *dht,
113 int used, test, test1, test2, found; 113 int used, test, test1, test2, found;
114 IP_Port test_ipp; 114 IP_Port test_ipp;
115 uint8_t test_id[CRYPTO_PUBLIC_KEY_SIZE]; 115 uint8_t test_id[CRYPTO_PUBLIC_KEY_SIZE];
116 uint8_t ipv6 = ip_port->ip.family == TOX_AF_INET6 ? 1 : 0; 116 uint8_t ipv6 = net_family_is_ipv6(ip_port->ip.family) ? 1 : 0;
117 117
118 // check id update for existing ip_port 118 // check id update for existing ip_port
119 test = random_u32() % length; 119 test = random_u32() % length;
@@ -188,7 +188,7 @@ static void test_addto_lists_bad(DHT *dht,
188 int used, test1, test2, test3; 188 int used, test1, test2, test3;
189 uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE], test_id1[CRYPTO_PUBLIC_KEY_SIZE], test_id2[CRYPTO_PUBLIC_KEY_SIZE], 189 uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE], test_id1[CRYPTO_PUBLIC_KEY_SIZE], test_id2[CRYPTO_PUBLIC_KEY_SIZE],
190 test_id3[CRYPTO_PUBLIC_KEY_SIZE]; 190 test_id3[CRYPTO_PUBLIC_KEY_SIZE];
191 uint8_t ipv6 = ip_port->ip.family == TOX_AF_INET6 ? 1 : 0; 191 uint8_t ipv6 = net_family_is_ipv6(ip_port->ip.family) ? 1 : 0;
192 192
193 random_bytes(public_key, sizeof(public_key)); 193 random_bytes(public_key, sizeof(public_key));
194 mark_all_good(list, length, ipv6); 194 mark_all_good(list, length, ipv6);
@@ -232,7 +232,7 @@ static void test_addto_lists_possible_bad(DHT *dht,
232 int used, test1, test2, test3; 232 int used, test1, test2, test3;
233 uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE], test_id1[CRYPTO_PUBLIC_KEY_SIZE], test_id2[CRYPTO_PUBLIC_KEY_SIZE], 233 uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE], test_id1[CRYPTO_PUBLIC_KEY_SIZE], test_id2[CRYPTO_PUBLIC_KEY_SIZE],
234 test_id3[CRYPTO_PUBLIC_KEY_SIZE]; 234 test_id3[CRYPTO_PUBLIC_KEY_SIZE];
235 uint8_t ipv6 = ip_port->ip.family == TOX_AF_INET6 ? 1 : 0; 235 uint8_t ipv6 = net_family_is_ipv6(ip_port->ip.family) ? 1 : 0;
236 236
237 random_bytes(public_key, sizeof(public_key)); 237 random_bytes(public_key, sizeof(public_key));
238 mark_all_good(list, length, ipv6); 238 mark_all_good(list, length, ipv6);
@@ -294,7 +294,7 @@ static void test_addto_lists_good(DHT *dht,
294 const uint8_t *comp_client_id) 294 const uint8_t *comp_client_id)
295{ 295{
296 uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE]; 296 uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE];
297 uint8_t ipv6 = ip_port->ip.family == TOX_AF_INET6 ? 1 : 0; 297 uint8_t ipv6 = net_family_is_ipv6(ip_port->ip.family) ? 1 : 0;
298 298
299 mark_all_good(list, length, ipv6); 299 mark_all_good(list, length, ipv6);
300 300
@@ -547,7 +547,7 @@ static void test_list_main(void)
547 ck_assert_msg(count == 1, "Nodes in search don't know ip of friend. %u %u %u", i, j, count); 547 ck_assert_msg(count == 1, "Nodes in search don't know ip of friend. %u %u %u", i, j, count);
548 548
549 Node_format ln[MAX_SENT_NODES]; 549 Node_format ln[MAX_SENT_NODES];
550 int n = get_close_nodes(dhts[(l + j) % NUM_DHT], dhts[l]->self_public_key, ln, 0, 1, 0); 550 int n = get_close_nodes(dhts[(l + j) % NUM_DHT], dhts[l]->self_public_key, ln, net_family_unspec, 1, 0);
551 ck_assert_msg(n == MAX_SENT_NODES, "bad num close %u | %u %u", n, i, j); 551 ck_assert_msg(n == MAX_SENT_NODES, "bad num close %u | %u %u", n, i, j);
552 552
553 count = 0; 553 count = 0;
@@ -744,8 +744,8 @@ static void random_ip(IP_Port *ipp, int family)
744 uint8_t *port = (uint8_t *)&ipp->port; 744 uint8_t *port = (uint8_t *)&ipp->port;
745 random_bytes(port, sizeof(ipp->port)); 745 random_bytes(port, sizeof(ipp->port));
746 random_bytes(ip, size); 746 random_bytes(ip, size);
747 ipp->ip.family = family; 747 // TODO(iphydf): Pass the net_family variant to random_ip.
748 748 ipp->ip.family.value = family;
749} 749}
750 750
751#define PACKED_NODES_SIZE (SIZE_IPPORT + CRYPTO_PUBLIC_KEY_SIZE) 751#define PACKED_NODES_SIZE (SIZE_IPPORT + CRYPTO_PUBLIC_KEY_SIZE)