Some speedups and small fixes.

This commit is contained in:
irungentoo 2014-04-16 13:53:51 -04:00
parent 6578d930f8
commit de079d7cf7
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98
3 changed files with 28 additions and 9 deletions

View File

@ -110,7 +110,7 @@ void write_file(Tox *m, int friendnumber, uint8_t filenumber, uint8_t *data, uin
START_TEST(test_few_clients)
{
long long unsigned int cur_time = time(NULL);
long long unsigned int con_time, cur_time = time(NULL);
Tox *tox1 = tox_new(TOX_ENABLE_IPV6_DEFAULT);
Tox *tox2 = tox_new(TOX_ENABLE_IPV6_DEFAULT);
Tox *tox3 = tox_new(TOX_ENABLE_IPV6_DEFAULT);
@ -131,6 +131,7 @@ START_TEST(test_few_clients)
if (tox_isconnected(tox1) && tox_isconnected(tox2) && tox_isconnected(tox3) && off) {
printf("Toxes are online, took %llu seconds\n", time(NULL) - cur_time);
con_time = time(NULL);
off = 0;
}
@ -141,7 +142,7 @@ START_TEST(test_few_clients)
c_sleep(50);
}
printf("tox clients connected\n");
printf("tox clients connected took %llu seconds\n", time(NULL) - con_time);
to_compare = 974536;
tox_callback_friend_message(tox3, print_message, &to_compare);
tox_send_message(tox2, 0, (uint8_t *)"Install Gentoo", sizeof("Install Gentoo"));
@ -331,7 +332,7 @@ Suite *tox_suite(void)
Suite *s = suite_create("Tox");
DEFTESTCASE_SLOW(few_clients, 50);
DEFTESTCASE_SLOW(many_clients, 300);
DEFTESTCASE_SLOW(many_clients, 150);
return s;
}

View File

@ -286,7 +286,7 @@ static int client_add_to_list(Onion_Client *onion_c, uint32_t num, uint8_t *publ
list_nodes[index].is_stored = is_stored;
list_nodes[index].timestamp = unix_time();
list_nodes[index].last_pinged = unix_time();
list_nodes[index].last_pinged = 0;
list_nodes[index].path_used = set_path_timeouts(onion_c, num, source);
return 0;
}
@ -863,6 +863,11 @@ static void do_friend(Onion_Client *onion_c, uint16_t friendnum)
++count;
if (list_nodes[i].last_pinged == 0) {
list_nodes[i].last_pinged = unix_time();
continue;
}
if (is_timeout(list_nodes[i].last_pinged, ANNOUNCE_FRIEND)) {
if (client_send_announce_request(onion_c, friendnum + 1, list_nodes[i].ip_port, list_nodes[i].client_id, 0, ~0) == 0) {
list_nodes[i].last_pinged = unix_time();
@ -931,6 +936,13 @@ static void do_announce(Onion_Client *onion_c)
continue;
++count;
/* Don't announce ourselves the first time this is run to new peers */
if (list_nodes[i].last_pinged == 0) {
list_nodes[i].last_pinged = 1;
continue;
}
uint32_t interval = ANNOUNCE_INTERVAL_NOT_ANNOUNCED;
if (list_nodes[i].is_stored) {

View File

@ -38,10 +38,10 @@
#define PING_NUM_MAX 512
/* Maximum newly announced nodes to ping per TIME_TO_PING seconds. */
#define MAX_TO_PING 16
#define MAX_TO_PING 8
/* Ping newly announced nodes to ping per TIME_TO_PING seconds*/
#define TIME_TO_PING 5
#define TIME_TO_PING 3
typedef struct {
IP_Port ip_port;
@ -300,12 +300,18 @@ int add_to_ping(PING *ping, uint8_t *client_id, IP_Port ip_port)
ipport_copy(&ping->to_ping[i].ip_port, &ip_port);
return 0;
}
if (memcmp(ping->to_ping[i].client_id, client_id, CLIENT_ID_SIZE) == 0) {
return -1;
}
}
uint32_t r = rand();
for (i = 0; i < MAX_TO_PING; ++i) {
if (id_closest(ping->dht->self_public_key, ping->to_ping[i].client_id, client_id) == 2) {
memcpy(ping->to_ping[i].client_id, client_id, CLIENT_ID_SIZE);
ipport_copy(&ping->to_ping[i].ip_port, &ip_port);
if (id_closest(ping->dht->self_public_key, ping->to_ping[(i + r) % MAX_TO_PING].client_id, client_id) == 2) {
memcpy(ping->to_ping[(i + r) % MAX_TO_PING].client_id, client_id, CLIENT_ID_SIZE);
ipport_copy(&ping->to_ping[(i + r) % MAX_TO_PING].ip_port, &ip_port);
return 0;
}
}