Slightly increased number of peers to announce to.

Some test fixes.
This commit is contained in:
irungentoo 2015-12-01 20:11:53 -05:00
parent 516b6ab46c
commit f40a60575f
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98
3 changed files with 37 additions and 28 deletions

View File

@ -806,7 +806,7 @@ START_TEST(test_few_clients)
}
END_TEST
#define NUM_TOXES 66
#define NUM_TOXES 90
#define NUM_FRIENDS 50
START_TEST(test_many_clients)
@ -899,16 +899,17 @@ loop_top:
}
END_TEST
#define NUM_TOXES_TCP 40
#define TCP_RELAY_PORT 33448
START_TEST(test_many_clients_tcp)
{
long long unsigned int cur_time = time(NULL);
Tox *toxes[NUM_TOXES];
Tox *toxes[NUM_TOXES_TCP];
uint32_t i, j;
uint32_t to_comp = 974536;
for (i = 0; i < NUM_TOXES; ++i) {
for (i = 0; i < NUM_TOXES_TCP; ++i) {
struct Tox_Options opts;
tox_options_default(&opts);
@ -945,8 +946,8 @@ START_TEST(test_many_clients_tcp)
for (i = 0; i < NUM_FRIENDS; ++i) {
loop_top:
pairs[i].tox1 = rand() % NUM_TOXES;
pairs[i].tox2 = (pairs[i].tox1 + rand() % (NUM_TOXES - 1) + 1) % NUM_TOXES;
pairs[i].tox1 = rand() % NUM_TOXES_TCP;
pairs[i].tox2 = (pairs[i].tox1 + rand() % (NUM_TOXES_TCP - 1) + 1) % NUM_TOXES_TCP;
for (j = 0; j < i; ++j) {
if (pairs[j].tox2 == pairs[i].tox1 && pairs[j].tox1 == pairs[i].tox2)
@ -966,26 +967,27 @@ loop_top:
}
while (1) {
uint16_t counter = 0;
uint16_t counter = 0, cc = 0;
for (i = 0; i < NUM_TOXES; ++i) {
for (i = 0; i < NUM_TOXES_TCP; ++i) {
for (j = 0; j < tox_self_get_friend_list_size(toxes[i]); ++j)
if (tox_friend_get_connection_status(toxes[i], j, 0) == TOX_CONNECTION_TCP)
++counter;
}
if (counter == NUM_FRIENDS * 2) {
break;
}
for (i = 0; i < NUM_TOXES; ++i) {
for (i = 0; i < NUM_TOXES_TCP; ++i) {
tox_iterate(toxes[i]);
}
c_sleep(50);
}
for (i = 0; i < NUM_TOXES; ++i) {
for (i = 0; i < NUM_TOXES_TCP; ++i) {
tox_kill(toxes[i]);
}
@ -998,11 +1000,11 @@ END_TEST
START_TEST(test_many_clients_tcp_b)
{
long long unsigned int cur_time = time(NULL);
Tox *toxes[NUM_TOXES];
Tox *toxes[NUM_TOXES_TCP];
uint32_t i, j;
uint32_t to_comp = 974536;
for (i = 0; i < NUM_TOXES; ++i) {
for (i = 0; i < NUM_TOXES_TCP; ++i) {
struct Tox_Options opts;
tox_options_default(&opts);
@ -1040,8 +1042,8 @@ START_TEST(test_many_clients_tcp_b)
for (i = 0; i < NUM_FRIENDS; ++i) {
loop_top:
pairs[i].tox1 = rand() % NUM_TOXES;
pairs[i].tox2 = (pairs[i].tox1 + rand() % (NUM_TOXES - 1) + 1) % NUM_TOXES;
pairs[i].tox1 = rand() % NUM_TOXES_TCP;
pairs[i].tox2 = (pairs[i].tox1 + rand() % (NUM_TOXES_TCP - 1) + 1) % NUM_TOXES_TCP;
for (j = 0; j < i; ++j) {
if (pairs[j].tox2 == pairs[i].tox1 && pairs[j].tox1 == pairs[i].tox2)
@ -1063,7 +1065,7 @@ loop_top:
while (1) {
uint16_t counter = 0;
for (i = 0; i < NUM_TOXES; ++i) {
for (i = 0; i < NUM_TOXES_TCP; ++i) {
for (j = 0; j < tox_self_get_friend_list_size(toxes[i]); ++j)
if (tox_friend_get_connection_status(toxes[i], j, 0) == TOX_CONNECTION_TCP)
++counter;
@ -1073,14 +1075,14 @@ loop_top:
break;
}
for (i = 0; i < NUM_TOXES; ++i) {
for (i = 0; i < NUM_TOXES_TCP; ++i) {
tox_iterate(toxes[i]);
}
c_sleep(50);
}
for (i = 0; i < NUM_TOXES; ++i) {
for (i = 0; i < NUM_TOXES_TCP; ++i) {
tox_kill(toxes[i]);
}

View File

@ -477,10 +477,12 @@ static int client_add_to_list(Onion_Client *onion_c, uint32_t num, const uint8_t
Onion_Node *list_nodes = NULL;
uint8_t *reference_id = NULL;
unsigned int list_length;
if (num == 0) {
list_nodes = onion_c->clients_announce_list;
reference_id = onion_c->c->self_public_key;
list_length = MAX_ONION_CLIENTS_ANNOUNCE;
if (is_stored == 1 && memcmp(pingid_or_key, onion_c->temp_public_key, crypto_box_PUBLICKEYBYTES) != 0) {
is_stored = 0;
@ -492,10 +494,11 @@ static int client_add_to_list(Onion_Client *onion_c, uint32_t num, const uint8_t
list_nodes = onion_c->friends_list[num - 1].clients_list;
reference_id = onion_c->friends_list[num - 1].real_public_key;
list_length = MAX_ONION_CLIENTS;
}
memcpy(cmp_public_key, reference_id, crypto_box_PUBLICKEYBYTES);
qsort(list_nodes, MAX_ONION_CLIENTS, sizeof(Onion_Node), cmp_entry);
qsort(list_nodes, list_length, sizeof(Onion_Node), cmp_entry);
int index = -1, stored = 0;
unsigned int i;
@ -505,7 +508,7 @@ static int client_add_to_list(Onion_Client *onion_c, uint32_t num, const uint8_t
index = 0;
}
for (i = 0; i < MAX_ONION_CLIENTS; ++i) {
for (i = 0; i < list_length; ++i) {
if (memcmp(list_nodes[i].public_key, public_key, crypto_box_PUBLICKEYBYTES) == 0) {
index = i;
stored = 1;
@ -565,6 +568,7 @@ static int client_ping_nodes(Onion_Client *onion_c, uint32_t num, const Node_for
Onion_Node *list_nodes = NULL;
uint8_t *reference_id = NULL;
unsigned int list_length;
Last_Pinged *last_pinged = NULL;
uint8_t *last_pinged_index = NULL;
@ -572,11 +576,13 @@ static int client_ping_nodes(Onion_Client *onion_c, uint32_t num, const Node_for
if (num == 0) {
list_nodes = onion_c->clients_announce_list;
reference_id = onion_c->c->self_public_key;
list_length = MAX_ONION_CLIENTS_ANNOUNCE;
last_pinged = onion_c->last_pinged;
last_pinged_index = &onion_c->last_pinged_index;
} else {
list_nodes = onion_c->friends_list[num - 1].clients_list;
reference_id = onion_c->friends_list[num - 1].real_public_key;
list_length = MAX_ONION_CLIENTS;
last_pinged = onion_c->friends_list[num - 1].last_pinged;
last_pinged_index = &onion_c->friends_list[num - 1].last_pinged_index;
}
@ -593,13 +599,13 @@ static int client_ping_nodes(Onion_Client *onion_c, uint32_t num, const Node_for
if (is_timeout(list_nodes[0].timestamp, ONION_NODE_TIMEOUT)
|| id_closest(reference_id, list_nodes[0].public_key, nodes[i].public_key) == 2) {
/* check if node is already in list. */
for (j = 0; j < MAX_ONION_CLIENTS; ++j) {
for (j = 0; j < list_length; ++j) {
if (memcmp(list_nodes[j].public_key, nodes[i].public_key, crypto_box_PUBLICKEYBYTES) == 0) {
break;
}
}
if (j == MAX_ONION_CLIENTS && good_to_ping(last_pinged, last_pinged_index, nodes[i].public_key)) {
if (j == list_length && good_to_ping(last_pinged, last_pinged_index, nodes[i].public_key)) {
client_send_announce_request(onion_c, num, nodes[i].ip_port, nodes[i].public_key, NULL, ~0);
}
}
@ -1321,7 +1327,7 @@ static void do_announce(Onion_Client *onion_c)
unsigned int i, count = 0;
Onion_Node *list_nodes = onion_c->clients_announce_list;
for (i = 0; i < MAX_ONION_CLIENTS; ++i) {
for (i = 0; i < MAX_ONION_CLIENTS_ANNOUNCE; ++i) {
if (is_timeout(list_nodes[i].timestamp, ONION_NODE_TIMEOUT))
continue;
@ -1347,7 +1353,7 @@ static void do_announce(Onion_Client *onion_c)
}
}
if (count != MAX_ONION_CLIENTS) {
if (count != MAX_ONION_CLIENTS_ANNOUNCE) {
unsigned int num_nodes;
Node_format *path_nodes;
@ -1359,9 +1365,9 @@ static void do_announce(Onion_Client *onion_c)
path_nodes = onion_c->path_nodes;
}
if (count < (uint32_t)rand() % MAX_ONION_CLIENTS) {
if (count < (uint32_t)rand() % MAX_ONION_CLIENTS_ANNOUNCE) {
if (num_nodes != 0) {
for (i = 0; i < (MAX_ONION_CLIENTS / 2); ++i) {
for (i = 0; i < (MAX_ONION_CLIENTS_ANNOUNCE / 2); ++i) {
unsigned int num = rand() % num_nodes;
client_send_announce_request(onion_c, 0, path_nodes[num].ip_port, path_nodes[num].public_key, 0, ~0);
}
@ -1383,7 +1389,7 @@ static int onion_isconnected(const Onion_Client *onion_c)
if (onion_c->path_nodes_index == 0)
return 0;
for (i = 0; i < MAX_ONION_CLIENTS; ++i) {
for (i = 0; i < MAX_ONION_CLIENTS_ANNOUNCE; ++i) {
if (!is_timeout(onion_c->clients_announce_list[i].timestamp, ONION_NODE_TIMEOUT)) {
++num;
@ -1395,8 +1401,8 @@ static int onion_isconnected(const Onion_Client *onion_c)
unsigned int pnodes = onion_c->path_nodes_index;
if (pnodes > MAX_ONION_CLIENTS) {
pnodes = MAX_ONION_CLIENTS;
if (pnodes > MAX_ONION_CLIENTS_ANNOUNCE) {
pnodes = MAX_ONION_CLIENTS_ANNOUNCE;
}
/* Consider ourselves online if we are announced to half or more nodes

View File

@ -29,6 +29,7 @@
#include "ping_array.h"
#define MAX_ONION_CLIENTS 8
#define MAX_ONION_CLIENTS_ANNOUNCE 12 /* Number of nodes to announce ourselves to. */
#define ONION_NODE_PING_INTERVAL 15
#define ONION_NODE_TIMEOUT (ONION_NODE_PING_INTERVAL * 3)
@ -130,7 +131,7 @@ typedef struct {
Onion_Friend *friends_list;
uint16_t num_friends;
Onion_Node clients_announce_list[MAX_ONION_CLIENTS];
Onion_Node clients_announce_list[MAX_ONION_CLIENTS_ANNOUNCE];
Onion_Client_Paths onion_paths_self;
Onion_Client_Paths onion_paths_friends;