mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
random_nodes_path should return slightly better paths.
Fixed test in network_test failing on some machines because of localhost ipv6 issues.
This commit is contained in:
parent
98043f4512
commit
00100ea335
|
@ -23,6 +23,7 @@ START_TEST(test_addr_resolv_localhost)
|
|||
#endif
|
||||
|
||||
const char localhost[] = "localhost";
|
||||
int localhost_split = 0;
|
||||
|
||||
IP ip;
|
||||
ip_init(&ip, 0);
|
||||
|
@ -39,6 +40,11 @@ START_TEST(test_addr_resolv_localhost)
|
|||
ip_init(&ip, 1);
|
||||
res = addr_resolve(localhost, &ip, NULL);
|
||||
|
||||
if (res < 1) {
|
||||
res = addr_resolve("ip6-localhost", &ip, NULL);
|
||||
localhost_split = 1;
|
||||
}
|
||||
|
||||
ck_assert_msg(res > 0, "Resolver failed: %u, %s (%x, %x)", errno, strerror(errno));
|
||||
|
||||
if (res > 0) {
|
||||
|
@ -46,20 +52,23 @@ START_TEST(test_addr_resolv_localhost)
|
|||
ck_assert_msg(!memcmp(&ip.ip6, &in6addr_loopback, sizeof(IP6)), "Expected ::1, got %s.", ip_ntoa(&ip));
|
||||
}
|
||||
|
||||
ip_init(&ip, 1);
|
||||
ip.family = AF_UNSPEC;
|
||||
IP extra;
|
||||
ip_reset(&extra);
|
||||
res = addr_resolve(localhost, &ip, &extra);
|
||||
if (!localhost_split) {
|
||||
ip_init(&ip, 1);
|
||||
ip.family = AF_UNSPEC;
|
||||
IP extra;
|
||||
ip_reset(&extra);
|
||||
res = addr_resolve(localhost, &ip, &extra);
|
||||
ck_assert_msg(res > 0, "Resolver failed: %u, %s (%x, %x)", errno, strerror(errno));
|
||||
|
||||
ck_assert_msg(res > 0, "Resolver failed: %u, %s (%x, %x)", errno, strerror(errno));
|
||||
if (res > 0) {
|
||||
ck_assert_msg(ip.family == AF_INET6, "Expected family AF_INET6, got %u.", ip.family);
|
||||
ck_assert_msg(!memcmp(&ip.ip6, &in6addr_loopback, sizeof(IP6)), "Expected ::1, got %s.", ip_ntoa(&ip));
|
||||
|
||||
if (res > 0) {
|
||||
ck_assert_msg(ip.family == AF_INET6, "Expected family AF_INET6, got %u.", ip.family);
|
||||
ck_assert_msg(!memcmp(&ip.ip6, &in6addr_loopback, sizeof(IP6)), "Expected ::1, got %s.", ip_ntoa(&ip));
|
||||
|
||||
ck_assert_msg(extra.family == AF_INET, "Expected family AF_INET, got %u.", extra.family);
|
||||
ck_assert_msg(extra.ip4.uint32 == htonl(0x7F000001), "Expected 127.0.0.1, got %s.", inet_ntoa(extra.ip4.in_addr));
|
||||
ck_assert_msg(extra.family == AF_INET, "Expected family AF_INET, got %u.", extra.family);
|
||||
ck_assert_msg(extra.ip4.uint32 == htonl(0x7F000001), "Expected 127.0.0.1, got %s.", inet_ntoa(extra.ip4.in_addr));
|
||||
}
|
||||
} else {
|
||||
printf("Localhost seems to be split in two.\n");
|
||||
}
|
||||
}
|
||||
END_TEST
|
||||
|
|
|
@ -2135,21 +2135,18 @@ uint16_t random_nodes_path(DHT *dht, Node_format *nodes, uint16_t max_num)
|
|||
if (max_num == 0)
|
||||
return 0;
|
||||
|
||||
if (dht->num_friends == 0)
|
||||
return 0;
|
||||
|
||||
uint16_t count = 0;
|
||||
Client_data *list = NULL;
|
||||
uint16_t list_size = 0;
|
||||
uint32_t i;
|
||||
|
||||
for (i = 0; i < max_num; ++i) {
|
||||
uint16_t rand_num = rand() % (dht->num_friends + 1);
|
||||
|
||||
if (rand_num == dht->num_friends) {
|
||||
list = dht->close_clientlist;
|
||||
list_size = LCLIENT_LIST;
|
||||
} else {
|
||||
list = dht->friends_list[rand_num].client_list;
|
||||
list_size = MAX_FRIEND_CLIENTS;
|
||||
}
|
||||
uint16_t rand_num = rand() % (dht->num_friends);
|
||||
list = dht->friends_list[rand_num].client_list;
|
||||
list_size = MAX_FRIEND_CLIENTS;
|
||||
|
||||
uint8_t LAN_ok = 1;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user