mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
96843fbae4
- Make sender send more data per iteration. - Make receiver iterate more often while receiving. Before this commit tox would send at maximum around 4MiB/s. With this patch sustained speeds of up to 100MiB/s were observed on a low-latency, high-bandwidth network. As a consequence of iterating more frequently the receiver's CPU usage is increased for the duration of the transfer. The data structures used to represent friends and file transfers cause the sender code use costly loops that do little real work. This patch makes this problem more visible: the sender uses more CPU while sending. Poor network conditions were simulated using the netem kernel facility: $ tc qdisc add dev lo root netem delay 100ms 50ms \ loss 1% duplicate 1% corrupt 1% reorder 25% 50% and no adverse behavior was encountered. Tests were conducted using toxic using both UDP and TCP.
100 lines
3.4 KiB
C
100 lines
3.4 KiB
C
/* Tests that we can set our name.
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <time.h>
|
|
|
|
#include "../testing/misc_tools.h"
|
|
#include "../toxcore/ccompat.h"
|
|
#include "../toxcore/tox.h"
|
|
#include "../toxcore/util.h"
|
|
#include "check_compat.h"
|
|
|
|
#define NICKNAME "Gentoo"
|
|
|
|
static void nickchange_callback(Tox *tox, uint32_t friendnumber, const uint8_t *string, size_t length, void *userdata)
|
|
{
|
|
ck_assert_msg(length == sizeof(NICKNAME), "Name length not correct: %d != %d", (uint16_t)length,
|
|
(uint16_t)sizeof(NICKNAME));
|
|
ck_assert_msg(memcmp(string, NICKNAME, sizeof(NICKNAME)) == 0, "Name not correct: %s", (const char *)string);
|
|
bool *nickname_updated = (bool *)userdata;
|
|
*nickname_updated = true;
|
|
}
|
|
|
|
static void test_set_name(void)
|
|
{
|
|
printf("initialising 2 toxes\n");
|
|
uint32_t index[] = { 1, 2 };
|
|
const time_t cur_time = time(nullptr);
|
|
Tox *const tox1 = tox_new_log(nullptr, nullptr, &index[0]);
|
|
Tox *const tox2 = tox_new_log(nullptr, nullptr, &index[1]);
|
|
|
|
ck_assert_msg(tox1 && tox2, "failed to create 2 tox instances");
|
|
|
|
printf("tox1 adds tox2 as friend, tox2 adds tox1\n");
|
|
uint8_t public_key[TOX_PUBLIC_KEY_SIZE];
|
|
tox_self_get_public_key(tox2, public_key);
|
|
tox_friend_add_norequest(tox1, public_key, nullptr);
|
|
tox_self_get_public_key(tox1, public_key);
|
|
tox_friend_add_norequest(tox2, public_key, nullptr);
|
|
|
|
printf("bootstrapping tox2 off tox1\n");
|
|
uint8_t dht_key[TOX_PUBLIC_KEY_SIZE];
|
|
tox_self_get_dht_id(tox1, dht_key);
|
|
const uint16_t dht_port = tox_self_get_udp_port(tox1, nullptr);
|
|
|
|
tox_bootstrap(tox2, "localhost", dht_port, dht_key, nullptr);
|
|
|
|
do {
|
|
tox_iterate(tox1, nullptr);
|
|
tox_iterate(tox2, nullptr);
|
|
c_sleep(ITERATION_INTERVAL);
|
|
} while (tox_self_get_connection_status(tox1) == TOX_CONNECTION_NONE ||
|
|
tox_self_get_connection_status(tox2) == TOX_CONNECTION_NONE);
|
|
|
|
printf("toxes are online, took %lu seconds\n", (unsigned long)(time(nullptr) - cur_time));
|
|
const time_t con_time = time(nullptr);
|
|
|
|
do {
|
|
tox_iterate(tox1, nullptr);
|
|
tox_iterate(tox2, nullptr);
|
|
c_sleep(ITERATION_INTERVAL);
|
|
} while (tox_friend_get_connection_status(tox1, 0, nullptr) != TOX_CONNECTION_UDP ||
|
|
tox_friend_get_connection_status(tox2, 0, nullptr) != TOX_CONNECTION_UDP);
|
|
|
|
printf("tox clients connected took %lu seconds\n", (unsigned long)(time(nullptr) - con_time));
|
|
|
|
tox_callback_friend_name(tox2, nickchange_callback);
|
|
Tox_Err_Set_Info err_n;
|
|
bool ret = tox_self_set_name(tox1, (const uint8_t *)NICKNAME, sizeof(NICKNAME), &err_n);
|
|
ck_assert_msg(ret && err_n == TOX_ERR_SET_INFO_OK, "tox_self_set_name failed because %d\n", err_n);
|
|
|
|
bool nickname_updated = false;
|
|
|
|
do {
|
|
tox_iterate(tox1, nullptr);
|
|
tox_iterate(tox2, &nickname_updated);
|
|
c_sleep(ITERATION_INTERVAL);
|
|
} while (!nickname_updated);
|
|
|
|
ck_assert_msg(tox_friend_get_name_size(tox2, 0, nullptr) == sizeof(NICKNAME), "Name length not correct");
|
|
uint8_t temp_name[sizeof(NICKNAME)];
|
|
tox_friend_get_name(tox2, 0, temp_name, nullptr);
|
|
ck_assert_msg(memcmp(temp_name, NICKNAME, sizeof(NICKNAME)) == 0, "Name not correct");
|
|
|
|
printf("test_set_name succeeded, took %lu seconds\n", (unsigned long)(time(nullptr) - cur_time));
|
|
|
|
tox_kill(tox1);
|
|
tox_kill(tox2);
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
setvbuf(stdout, nullptr, _IONBF, 0);
|
|
|
|
test_set_name();
|
|
return 0;
|
|
}
|