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:
irungentoo 2014-01-21 11:14:16 -05:00
parent 98043f4512
commit 00100ea335
2 changed files with 27 additions and 21 deletions

View File

@ -23,6 +23,7 @@ START_TEST(test_addr_resolv_localhost)
#endif #endif
const char localhost[] = "localhost"; const char localhost[] = "localhost";
int localhost_split = 0;
IP ip; IP ip;
ip_init(&ip, 0); ip_init(&ip, 0);
@ -39,6 +40,11 @@ START_TEST(test_addr_resolv_localhost)
ip_init(&ip, 1); ip_init(&ip, 1);
res = addr_resolve(localhost, &ip, NULL); 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)); ck_assert_msg(res > 0, "Resolver failed: %u, %s (%x, %x)", errno, strerror(errno));
if (res > 0) { if (res > 0) {
@ -46,12 +52,12 @@ START_TEST(test_addr_resolv_localhost)
ck_assert_msg(!memcmp(&ip.ip6, &in6addr_loopback, sizeof(IP6)), "Expected ::1, got %s.", ip_ntoa(&ip)); ck_assert_msg(!memcmp(&ip.ip6, &in6addr_loopback, sizeof(IP6)), "Expected ::1, got %s.", ip_ntoa(&ip));
} }
if (!localhost_split) {
ip_init(&ip, 1); ip_init(&ip, 1);
ip.family = AF_UNSPEC; ip.family = AF_UNSPEC;
IP extra; IP extra;
ip_reset(&extra); ip_reset(&extra);
res = addr_resolve(localhost, &ip, &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) { if (res > 0) {
@ -61,6 +67,9 @@ START_TEST(test_addr_resolv_localhost)
ck_assert_msg(extra.family == AF_INET, "Expected family AF_INET, got %u.", extra.family); 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.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 END_TEST

View File

@ -2135,21 +2135,18 @@ uint16_t random_nodes_path(DHT *dht, Node_format *nodes, uint16_t max_num)
if (max_num == 0) if (max_num == 0)
return 0; return 0;
if (dht->num_friends == 0)
return 0;
uint16_t count = 0; uint16_t count = 0;
Client_data *list = NULL; Client_data *list = NULL;
uint16_t list_size = 0; uint16_t list_size = 0;
uint32_t i; uint32_t i;
for (i = 0; i < max_num; ++i) { for (i = 0; i < max_num; ++i) {
uint16_t rand_num = rand() % (dht->num_friends + 1); uint16_t rand_num = rand() % (dht->num_friends);
if (rand_num == dht->num_friends) {
list = dht->close_clientlist;
list_size = LCLIENT_LIST;
} else {
list = dht->friends_list[rand_num].client_list; list = dht->friends_list[rand_num].client_list;
list_size = MAX_FRIEND_CLIENTS; list_size = MAX_FRIEND_CLIENTS;
}
uint8_t LAN_ok = 1; uint8_t LAN_ok = 1;