Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(test): tests use ipv6 by default, even with USE_IPV6 set to 0 #2468

Merged
merged 2 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions auto_tests/auto_test_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#define ABORT_ON_LOG_ERROR true
#endif

#ifndef USE_IPV6
#define USE_IPV6 1
#endif

Run_Auto_Options default_run_auto_options(void)
{
return (Run_Auto_Options) {
Expand Down Expand Up @@ -193,6 +197,7 @@ void reload(AutoTox *autotox)

struct Tox_Options *const options = tox_options_new(nullptr);
ck_assert(options != nullptr);
tox_options_set_ipv6_enabled(options, USE_IPV6);
tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE);
tox_options_set_savedata_data(options, autotox->save_state, autotox->save_size);
autotox->tox = tox_new_log(options, nullptr, &autotox->index);
Expand All @@ -214,6 +219,8 @@ static void initialise_autotox(struct Tox_Options *options, AutoTox *autotox, ui
struct Tox_Options *default_opts = tox_options_new(nullptr);
ck_assert(default_opts != nullptr);

tox_options_set_ipv6_enabled(default_opts, USE_IPV6);

if (options == nullptr) {
options = default_opts;
}
Expand Down Expand Up @@ -426,6 +433,7 @@ Tox *tox_new_log_lan(struct Tox_Options *options, Tox_Err_New *err, void *log_us

assert(log_options != nullptr);

tox_options_set_ipv6_enabled(log_options, USE_IPV6);
tox_options_set_local_discovery_enabled(log_options, lan_discovery);
// Use a higher start port for non-LAN-discovery tests so it's more likely for the LAN discovery
// test to get the default port 33445.
Expand Down
11 changes: 8 additions & 3 deletions auto_tests/file_streaming_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@
#include "auto_test_support.h"
#include "check_compat.h"

/* The Travis-CI container responds poorly to ::1 as a localhost address
* You're encouraged to -D FORCE_TESTS_IPV6 on a local test */
#ifdef FORCE_TESTS_IPV6
#ifndef USE_IPV6
#define USE_IPV6 1
#endif

#ifdef TOX_LOCALHOST
#undef TOX_LOCALHOST
#endif
#if USE_IPV6
#define TOX_LOCALHOST "::1"
#else
#define TOX_LOCALHOST "127.0.0.1"
Expand Down
11 changes: 8 additions & 3 deletions auto_tests/file_transfer_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@
#include "auto_test_support.h"
#include "check_compat.h"

/* The Travis-CI container responds poorly to ::1 as a localhost address
* You're encouraged to -D FORCE_TESTS_IPV6 on a local test */
#ifdef FORCE_TESTS_IPV6
#ifndef USE_IPV6
#define USE_IPV6 1
#endif

#ifdef TOX_LOCALHOST
#undef TOX_LOCALHOST
#endif
#if USE_IPV6
#define TOX_LOCALHOST "::1"
#else
#define TOX_LOCALHOST "127.0.0.1"
Expand Down
12 changes: 9 additions & 3 deletions auto_tests/save_load_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
#include "auto_test_support.h"
#include "check_compat.h"

/* The Travis-CI container responds poorly to ::1 as a localhost address
* You're encouraged to -D FORCE_TESTS_IPV6 on a local test */
#ifndef USE_IPV6
#define USE_IPV6 1
#endif

#ifdef TOX_LOCALHOST
#undef TOX_LOCALHOST
#endif
#ifdef FORCE_TESTS_IPV6
#if USE_IPV6
#define TOX_LOCALHOST "::1"
#else
#define TOX_LOCALHOST "127.0.0.1"
Expand Down Expand Up @@ -74,6 +76,7 @@ static void reload_tox(Tox **tox, struct Tox_Options *const in_opts, void *user_
}

struct Tox_Options *const options = (in_opts == nullptr) ? tox_options_new(nullptr) : in_opts;
tox_options_set_ipv6_enabled(options, USE_IPV6);

tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE);

Expand Down Expand Up @@ -138,19 +141,22 @@ static void test_few_clients(void)
time_t con_time = 0, cur_time = time(nullptr);

struct Tox_Options *opts1 = tox_options_new(nullptr);
tox_options_set_ipv6_enabled(opts1, USE_IPV6);
tox_options_set_tcp_port(opts1, TCP_RELAY_PORT);
Tox_Err_New t_n_error;
Tox *tox1 = tox_new_log(opts1, &t_n_error, &index[0]);
ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "Failed to create tox instance: %d", t_n_error);
tox_options_free(opts1);

struct Tox_Options *opts2 = tox_options_new(nullptr);
tox_options_set_ipv6_enabled(opts2, USE_IPV6);
tox_options_set_udp_enabled(opts2, false);
tox_options_set_local_discovery_enabled(opts2, false);
Tox *tox2 = tox_new_log(opts2, &t_n_error, &index[1]);
ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "Failed to create tox instance: %d", t_n_error);

struct Tox_Options *opts3 = tox_options_new(nullptr);
tox_options_set_ipv6_enabled(opts3, USE_IPV6);
tox_options_set_local_discovery_enabled(opts3, false);
Tox *tox3 = tox_new_log(opts3, &t_n_error, &index[2]);
ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "Failed to create tox instance: %d", t_n_error);
Expand Down
11 changes: 8 additions & 3 deletions auto_tests/tox_many_tcp_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@
#include "auto_test_support.h"
#include "check_compat.h"

/* The Travis-CI container responds poorly to ::1 as a localhost address
* You're encouraged to -D FORCE_TESTS_IPV6 on a local test */
#ifdef FORCE_TESTS_IPV6
#ifndef USE_IPV6
#define USE_IPV6 1
#endif

#ifdef TOX_LOCALHOST
#undef TOX_LOCALHOST
#endif
#if USE_IPV6
#define TOX_LOCALHOST "::1"
#else
#define TOX_LOCALHOST "127.0.0.1"
Expand Down
2 changes: 1 addition & 1 deletion other/bootstrap_daemon/docker/tox-bootstrapd.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5061f92a95ba45cfa49d78175fa8fb6e4d66a58d86634ea3fd3ae6d80cb0558a /usr/local/bin/tox-bootstrapd
ccaf7a29c16d97068952d872b8663e38cc3d958aff01baeafee04e0ac6f3ac98 /usr/local/bin/tox-bootstrapd
5 changes: 3 additions & 2 deletions toxcore/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -946,8 +946,9 @@
if (net_family_is_ipv4(net->family) && !net_family_is_ipv4(ipp_copy.ip.family)) {
// TODO(iphydf): Make this an error. Occasionally we try to send to an
// all-zero ip_port.
LOGGER_WARNING(net->log, "attempted to send message with network family %d (probably IPv6) on IPv4 socket",
ipp_copy.ip.family.value);
Ip_Ntoa ip_str;
LOGGER_WARNING(net->log, "attempted to send message with network family %d (probably IPv6) on IPv4 socket (%s)",
ipp_copy.ip.family.value, net_ip_ntoa(&ipp_copy.ip, &ip_str));

Check warning on line 951 in toxcore/network.c

View check run for this annotation

Codecov / codecov/patch

toxcore/network.c#L949-L951

Added lines #L949 - L951 were not covered by tests
return -1;
}

Expand Down
5 changes: 5 additions & 0 deletions toxcore/tox.c
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,11 @@
bool udp_success = tox->m->options.udp_disabled;

for (int32_t i = 0; i < count; ++i) {
if (!tox->m->options.ipv6enabled && net_family_is_ipv6(root[i].ip.family)) {
// We can't use ipv6 when it's disabled.
continue;

Check warning on line 1063 in toxcore/tox.c

View check run for this annotation

Codecov / codecov/patch

toxcore/tox.c#L1063

Added line #L1063 was not covered by tests
}

root[i].port = net_htons(port);

if (onion_add_bs_path_node(tox->m->onion_c, &root[i], public_key)) {
Expand Down
Loading