diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-02-05 16:11:49 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-02-08 14:57:34 +0000 |
commit | 8a0e98bab8a4bccd11adc0e2c838910ed1b6d794 (patch) | |
tree | 09e6cab043b303a26829521914d8b5d1e15df846 | |
parent | 36ba80aacb2a582854f0e5e3ed0d69ca63db52ea (diff) |
Fix LAN discovery on FreeBSD.
Also, add an auto-test for bootstrap and for LAN discovery.
Bootstrap is never tested otherwise, and LAN discovery is a prerequisite
for everything else. Having these two tests lets us rule out or identify
LAN discovery as a possible cause for test failures.
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | auto_tests/bootstrap_test.c | 34 | ||||
-rw-r--r-- | auto_tests/lan_discovery_test.c | 31 | ||||
-rw-r--r-- | auto_tests/monolith_test.cpp | 17 | ||||
-rw-r--r-- | other/fun/bootstrap_node_info.py | 4 | ||||
-rw-r--r-- | toxcore/LAN_discovery.c | 38 |
6 files changed, 108 insertions, 18 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 70c234d5..9705dcf4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt | |||
@@ -530,10 +530,12 @@ if(BUILD_TOXAV AND CHECK_FOUND) | |||
530 | endif() | 530 | endif() |
531 | 531 | ||
532 | auto_test(TCP) | 532 | auto_test(TCP) |
533 | auto_test(bootstrap) | ||
533 | auto_test(conference) | 534 | auto_test(conference) |
534 | auto_test(crypto MSVC_DONT_BUILD) | 535 | auto_test(crypto MSVC_DONT_BUILD) |
535 | auto_test(dht MSVC_DONT_BUILD) | 536 | auto_test(dht MSVC_DONT_BUILD) |
536 | auto_test(encryptsave) | 537 | auto_test(encryptsave) |
538 | auto_test(lan_discovery) | ||
537 | auto_test(messenger MSVC_DONT_BUILD) | 539 | auto_test(messenger MSVC_DONT_BUILD) |
538 | auto_test(network) | 540 | auto_test(network) |
539 | auto_test(onion) | 541 | auto_test(onion) |
diff --git a/auto_tests/bootstrap_test.c b/auto_tests/bootstrap_test.c new file mode 100644 index 00000000..488bd48e --- /dev/null +++ b/auto_tests/bootstrap_test.c | |||
@@ -0,0 +1,34 @@ | |||
1 | #ifndef _XOPEN_SOURCE | ||
2 | #define _XOPEN_SOURCE 600 | ||
3 | #endif | ||
4 | |||
5 | #include "helpers.h" | ||
6 | |||
7 | static uint8_t const key[] = { | ||
8 | 0xF4, 0x04, 0xAB, 0xAA, 0x1C, 0x99, 0xA9, 0xD3, | ||
9 | 0x7D, 0x61, 0xAB, 0x54, 0x89, 0x8F, 0x56, 0x79, | ||
10 | 0x3E, 0x1D, 0xEF, 0x8B, 0xD4, 0x6B, 0x10, 0x38, | ||
11 | 0xB9, 0xD8, 0x22, 0xE8, 0x46, 0x0F, 0xAB, 0x67, | ||
12 | }; | ||
13 | |||
14 | int main(void) | ||
15 | { | ||
16 | Tox *tox = tox_new_log(nullptr, nullptr, nullptr); | ||
17 | |||
18 | tox_bootstrap(tox, "node.tox.biribiri.org", 33445, key, nullptr); | ||
19 | |||
20 | printf("Waiting for connection"); | ||
21 | |||
22 | while (tox_self_get_connection_status(tox) == TOX_CONNECTION_NONE) { | ||
23 | printf("."); | ||
24 | fflush(stdout); | ||
25 | |||
26 | tox_iterate(tox, nullptr); | ||
27 | c_sleep(1000); | ||
28 | } | ||
29 | |||
30 | printf("Connection: %d\n", tox_self_get_connection_status(tox)); | ||
31 | |||
32 | tox_kill(tox); | ||
33 | return 0; | ||
34 | } | ||
diff --git a/auto_tests/lan_discovery_test.c b/auto_tests/lan_discovery_test.c new file mode 100644 index 00000000..6918c232 --- /dev/null +++ b/auto_tests/lan_discovery_test.c | |||
@@ -0,0 +1,31 @@ | |||
1 | #ifndef _XOPEN_SOURCE | ||
2 | #define _XOPEN_SOURCE 600 | ||
3 | #endif | ||
4 | |||
5 | #include "helpers.h" | ||
6 | |||
7 | int main(void) | ||
8 | { | ||
9 | Tox *tox1 = tox_new_log(nullptr, nullptr, nullptr); | ||
10 | Tox *tox2 = tox_new_log(nullptr, nullptr, nullptr); | ||
11 | |||
12 | printf("Waiting for LAN discovery"); | ||
13 | |||
14 | while (tox_self_get_connection_status(tox1) == TOX_CONNECTION_NONE || | ||
15 | tox_self_get_connection_status(tox2) == TOX_CONNECTION_NONE) { | ||
16 | printf("."); | ||
17 | fflush(stdout); | ||
18 | |||
19 | tox_iterate(tox1, nullptr); | ||
20 | tox_iterate(tox2, nullptr); | ||
21 | c_sleep(1000); | ||
22 | } | ||
23 | |||
24 | printf(" %d <-> %d\n", | ||
25 | tox_self_get_connection_status(tox1), | ||
26 | tox_self_get_connection_status(tox2)); | ||
27 | |||
28 | tox_kill(tox2); | ||
29 | tox_kill(tox1); | ||
30 | return 0; | ||
31 | } | ||
diff --git a/auto_tests/monolith_test.cpp b/auto_tests/monolith_test.cpp index 088b4e01..b1e13448 100644 --- a/auto_tests/monolith_test.cpp +++ b/auto_tests/monolith_test.cpp | |||
@@ -1,6 +1,13 @@ | |||
1 | /* Auto Tests: One instance. | 1 | /* Nop-test, just to make sure our code compiles as C++. |
2 | */ | 2 | */ |
3 | 3 | ||
4 | #ifdef __FreeBSD__ | ||
5 | // Include this here, because _XOPEN_SOURCE hides symbols we need. | ||
6 | // | ||
7 | // https://lists.freebsd.org/pipermail/freebsd-standards/2004-March/000474.html. | ||
8 | #include <net/if.h> | ||
9 | #endif | ||
10 | |||
4 | #define _DARWIN_C_SOURCE | 11 | #define _DARWIN_C_SOURCE |
5 | #define _XOPEN_SOURCE 600 | 12 | #define _XOPEN_SOURCE 600 |
6 | 13 | ||
@@ -21,6 +28,10 @@ namespace TCP_test | |||
21 | { | 28 | { |
22 | #include "TCP_test.c" | 29 | #include "TCP_test.c" |
23 | } | 30 | } |
31 | namespace bootstrap_test | ||
32 | { | ||
33 | #include "bootstrap_test.c" | ||
34 | } | ||
24 | namespace conference_test | 35 | namespace conference_test |
25 | { | 36 | { |
26 | #include "conference_test.c" | 37 | #include "conference_test.c" |
@@ -41,6 +52,10 @@ namespace file_saving_test | |||
41 | { | 52 | { |
42 | #include "file_saving_test.c" | 53 | #include "file_saving_test.c" |
43 | } | 54 | } |
55 | namespace lan_discovery_test | ||
56 | { | ||
57 | #include "lan_discovery_test.c" | ||
58 | } | ||
44 | namespace messenger_test | 59 | namespace messenger_test |
45 | { | 60 | { |
46 | #include "messenger_test.c" | 61 | #include "messenger_test.c" |
diff --git a/other/fun/bootstrap_node_info.py b/other/fun/bootstrap_node_info.py index 17349334..ffda41e3 100644 --- a/other/fun/bootstrap_node_info.py +++ b/other/fun/bootstrap_node_info.py | |||
@@ -32,7 +32,7 @@ def printHelp(): | |||
32 | print("Usage: " + sys.argv[0] + " <ipv4|ipv6> <ip/hostname> <port>") | 32 | print("Usage: " + sys.argv[0] + " <ipv4|ipv6> <ip/hostname> <port>") |
33 | print(" Example: " + sys.argv[0] + " ipv4 192.210.149.121 33445") | 33 | print(" Example: " + sys.argv[0] + " ipv4 192.210.149.121 33445") |
34 | print(" Example: " + sys.argv[0] + " ipv4 23.226.230.47 33445") | 34 | print(" Example: " + sys.argv[0] + " ipv4 23.226.230.47 33445") |
35 | print(" Example: " + sys.argv[0] + " ipv4 biribiri.org 33445") | 35 | print(" Example: " + sys.argv[0] + " ipv4 node.tox.biribiri.org 33445") |
36 | print(" Example: " + sys.argv[0] + " ipv4 cerberus.zodiaclabs.org 33445") | 36 | print(" Example: " + sys.argv[0] + " ipv4 cerberus.zodiaclabs.org 33445") |
37 | print(" Example: " + sys.argv[0] + " ipv6 2604:180:1::3ded:b280 33445") | 37 | print(" Example: " + sys.argv[0] + " ipv6 2604:180:1::3ded:b280 33445") |
38 | print("") | 38 | print("") |
@@ -95,4 +95,4 @@ version = int.from_bytes(data[PACKET_ID_LENGTH:PACKET_ID_LENGTH + VERSION_LENGTH | |||
95 | motd = data[PACKET_ID_LENGTH + VERSION_LENGTH:].decode("utf-8") | 95 | motd = data[PACKET_ID_LENGTH + VERSION_LENGTH:].decode("utf-8") |
96 | print("Version: " + str(version)) | 96 | print("Version: " + str(version)) |
97 | print("MOTD: " + motd) | 97 | print("MOTD: " + motd) |
98 | sys.exit(0) \ No newline at end of file | 98 | sys.exit(0) |
diff --git a/toxcore/LAN_discovery.c b/toxcore/LAN_discovery.c index 742b91ab..cb10b0aa 100644 --- a/toxcore/LAN_discovery.c +++ b/toxcore/LAN_discovery.c | |||
@@ -29,12 +29,6 @@ | |||
29 | 29 | ||
30 | #include "util.h" | 30 | #include "util.h" |
31 | 31 | ||
32 | /* Used for get_broadcast(). */ | ||
33 | #ifdef __linux | ||
34 | #include <linux/netdevice.h> | ||
35 | #include <sys/ioctl.h> | ||
36 | #endif | ||
37 | |||
38 | #define MAX_INTERFACES 16 | 32 | #define MAX_INTERFACES 16 |
39 | 33 | ||
40 | 34 | ||
@@ -112,7 +106,17 @@ static void fetch_broadcast_info(uint16_t port) | |||
112 | } | 106 | } |
113 | } | 107 | } |
114 | 108 | ||
115 | #elif defined(__linux__) | 109 | #elif defined(__linux__) || defined(__FreeBSD__) |
110 | |||
111 | #ifdef __linux__ | ||
112 | #include <linux/netdevice.h> | ||
113 | #endif | ||
114 | |||
115 | #ifdef __FreeBSD__ | ||
116 | #include <net/if.h> | ||
117 | #endif | ||
118 | |||
119 | #include <sys/ioctl.h> | ||
116 | 120 | ||
117 | static void fetch_broadcast_info(uint16_t port) | 121 | static void fetch_broadcast_info(uint16_t port) |
118 | { | 122 | { |
@@ -121,9 +125,9 @@ static void fetch_broadcast_info(uint16_t port) | |||
121 | * Definitely won't work like this on Windows... | 125 | * Definitely won't work like this on Windows... |
122 | */ | 126 | */ |
123 | broadcast_count = 0; | 127 | broadcast_count = 0; |
124 | Socket sock = 0; | 128 | const Socket sock = net_socket(TOX_AF_INET, TOX_SOCK_STREAM, 0); |
125 | 129 | ||
126 | if ((sock = net_socket(TOX_AF_INET, TOX_SOCK_STREAM, 0)) < 0) { | 130 | if (sock < 0) { |
127 | return; | 131 | return; |
128 | } | 132 | } |
129 | 133 | ||
@@ -217,9 +221,7 @@ static uint32_t send_broadcasts(Networking_Core *net, uint16_t port, const uint8 | |||
217 | return 0; | 221 | return 0; |
218 | } | 222 | } |
219 | 223 | ||
220 | int i; | 224 | for (int i = 0; i < broadcast_count; i++) { |
221 | |||
222 | for (i = 0; i < broadcast_count; i++) { | ||
223 | sendpacket(net, broadcast_ip_ports[i], data, length); | 225 | sendpacket(net, broadcast_ip_ports[i], data, length); |
224 | } | 226 | } |
225 | 227 | ||
@@ -346,17 +348,23 @@ static int handle_LANdiscovery(void *object, IP_Port source, const uint8_t *pack | |||
346 | { | 348 | { |
347 | DHT *dht = (DHT *)object; | 349 | DHT *dht = (DHT *)object; |
348 | 350 | ||
351 | char ip_str[IP_NTOA_LEN] = { 0 }; | ||
352 | ip_ntoa(&source.ip, ip_str, sizeof(ip_str)); | ||
353 | |||
354 | // TODO(iphydf): Add logging for this case. | ||
355 | // Why should we reject discovery packets from outside the LAN? | ||
356 | #if 0 | ||
357 | |||
349 | if (ip_is_lan(source.ip) == -1) { | 358 | if (ip_is_lan(source.ip) == -1) { |
350 | return 1; | 359 | return 1; |
351 | } | 360 | } |
352 | 361 | ||
362 | #endif | ||
363 | |||
353 | if (length != CRYPTO_PUBLIC_KEY_SIZE + 1) { | 364 | if (length != CRYPTO_PUBLIC_KEY_SIZE + 1) { |
354 | return 1; | 365 | return 1; |
355 | } | 366 | } |
356 | 367 | ||
357 | char ip_str[IP_NTOA_LEN] = { 0 }; | ||
358 | ip_ntoa(&source.ip, ip_str, sizeof(ip_str)); | ||
359 | |||
360 | DHT_bootstrap(dht, source, packet + 1); | 368 | DHT_bootstrap(dht, source, packet + 1); |
361 | return 0; | 369 | return 0; |
362 | } | 370 | } |