Merge commit 'a3126d581b6a872f0b8d5641f199fb233306e181'
This commit is contained in:
265
external/toxcore/c-toxcore/auto_tests/TCP_test.c
vendored
265
external/toxcore/c-toxcore/auto_tests/TCP_test.c
vendored
@ -34,20 +34,25 @@ static IP get_loopback(void)
|
||||
return ip;
|
||||
}
|
||||
|
||||
static void do_TCP_server_delay(TCP_Server *tcp_s, Mono_Time *mono_time, int delay)
|
||||
static void do_tcp_server_delay(TCP_Server *tcp_s, Mono_Time *mono_time, int delay)
|
||||
{
|
||||
c_sleep(delay);
|
||||
mono_time_update(mono_time);
|
||||
do_TCP_server(tcp_s, mono_time);
|
||||
do_tcp_server(tcp_s, mono_time);
|
||||
c_sleep(delay);
|
||||
}
|
||||
static uint16_t ports[NUM_PORTS] = {13215, 33445, 25643};
|
||||
|
||||
static void test_basic(void)
|
||||
{
|
||||
Mono_Time *mono_time = mono_time_new(nullptr, nullptr);
|
||||
const Random *rng = system_random();
|
||||
ck_assert(rng != nullptr);
|
||||
const Network *ns = system_network();
|
||||
ck_assert(ns != nullptr);
|
||||
const Memory *mem = system_memory();
|
||||
ck_assert(mem != nullptr);
|
||||
|
||||
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
|
||||
Logger *logger = logger_new();
|
||||
logger_callback_log(logger, print_debug_logger, nullptr, nullptr);
|
||||
|
||||
@ -55,8 +60,7 @@ static void test_basic(void)
|
||||
uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE];
|
||||
uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE];
|
||||
crypto_new_keypair(rng, self_public_key, self_secret_key);
|
||||
const Network *ns = system_network();
|
||||
TCP_Server *tcp_s = new_TCP_server(logger, rng, ns, USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr, nullptr);
|
||||
TCP_Server *tcp_s = new_tcp_server(logger, mem, rng, ns, USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr, nullptr);
|
||||
ck_assert_msg(tcp_s != nullptr, "Failed to create a TCP relay server.");
|
||||
ck_assert_msg(tcp_server_listen_count(tcp_s) == NUM_PORTS,
|
||||
"Failed to bind a TCP relay server to all %d attempted ports.", NUM_PORTS);
|
||||
@ -70,7 +74,7 @@ static void test_basic(void)
|
||||
for (uint8_t i = 0; i < NUM_PORTS; i++) {
|
||||
sock = net_socket(ns, net_family_ipv6(), TOX_SOCK_STREAM, TOX_PROTO_TCP);
|
||||
localhost.port = net_htons(ports[i]);
|
||||
bool ret = net_connect(logger, sock, &localhost);
|
||||
bool ret = net_connect(mem, logger, sock, &localhost);
|
||||
ck_assert_msg(ret, "Failed to connect to created TCP relay server on port %d (%d).", ports[i], errno);
|
||||
|
||||
// Leave open one connection for the next test.
|
||||
@ -110,14 +114,14 @@ static void test_basic(void)
|
||||
&localhost) == TCP_CLIENT_HANDSHAKE_SIZE - 1,
|
||||
"An attempt to send the initial handshake minus last byte failed.");
|
||||
|
||||
do_TCP_server_delay(tcp_s, mono_time, 50);
|
||||
do_tcp_server_delay(tcp_s, mono_time, 50);
|
||||
|
||||
ck_assert_msg(net_send(ns, logger, sock, handshake + (TCP_CLIENT_HANDSHAKE_SIZE - 1), 1, &localhost) == 1,
|
||||
"The attempt to send the last byte of handshake failed.");
|
||||
|
||||
free(handshake);
|
||||
|
||||
do_TCP_server_delay(tcp_s, mono_time, 50);
|
||||
do_tcp_server_delay(tcp_s, mono_time, 50);
|
||||
|
||||
// Receiving server response and decrypting it
|
||||
uint8_t response[TCP_SERVER_HANDSHAKE_SIZE];
|
||||
@ -157,7 +161,7 @@ static void test_basic(void)
|
||||
|
||||
c_sleep(50);
|
||||
mono_time_update(mono_time);
|
||||
do_TCP_server(tcp_s, mono_time);
|
||||
do_tcp_server(tcp_s, mono_time);
|
||||
}
|
||||
|
||||
// Receiving the second response and verifying its validity
|
||||
@ -181,33 +185,35 @@ static void test_basic(void)
|
||||
|
||||
// Closing connections.
|
||||
kill_sock(ns, sock);
|
||||
kill_TCP_server(tcp_s);
|
||||
kill_tcp_server(tcp_s);
|
||||
|
||||
logger_kill(logger);
|
||||
mono_time_free(mono_time);
|
||||
mono_time_free(mem, mono_time);
|
||||
}
|
||||
|
||||
struct sec_TCP_con {
|
||||
Socket sock;
|
||||
const Network *ns;
|
||||
const Memory *mem;
|
||||
uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE];
|
||||
uint8_t recv_nonce[CRYPTO_NONCE_SIZE];
|
||||
uint8_t sent_nonce[CRYPTO_NONCE_SIZE];
|
||||
uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE];
|
||||
};
|
||||
|
||||
static struct sec_TCP_con *new_TCP_con(const Logger *logger, const Random *rng, const Network *ns, TCP_Server *tcp_s, Mono_Time *mono_time)
|
||||
static struct sec_TCP_con *new_tcp_con(const Logger *logger, const Memory *mem, const Random *rng, const Network *ns, TCP_Server *tcp_s, Mono_Time *mono_time)
|
||||
{
|
||||
struct sec_TCP_con *sec_c = (struct sec_TCP_con *)malloc(sizeof(struct sec_TCP_con));
|
||||
ck_assert(sec_c != nullptr);
|
||||
sec_c->ns = ns;
|
||||
sec_c->mem = mem;
|
||||
Socket sock = net_socket(ns, net_family_ipv6(), TOX_SOCK_STREAM, TOX_PROTO_TCP);
|
||||
|
||||
IP_Port localhost;
|
||||
localhost.ip = get_loopback();
|
||||
localhost.port = net_htons(ports[random_u32(rng) % NUM_PORTS]);
|
||||
|
||||
bool ok = net_connect(logger, sock, &localhost);
|
||||
bool ok = net_connect(mem, logger, sock, &localhost);
|
||||
ck_assert_msg(ok, "Failed to connect to the test TCP relay server.");
|
||||
|
||||
uint8_t f_secret_key[CRYPTO_SECRET_KEY_SIZE];
|
||||
@ -231,12 +237,12 @@ static struct sec_TCP_con *new_TCP_con(const Logger *logger, const Random *rng,
|
||||
&localhost) == TCP_CLIENT_HANDSHAKE_SIZE - 1,
|
||||
"Failed to send the first portion of the handshake to the TCP relay server.");
|
||||
|
||||
do_TCP_server_delay(tcp_s, mono_time, 50);
|
||||
do_tcp_server_delay(tcp_s, mono_time, 50);
|
||||
|
||||
ck_assert_msg(net_send(ns, logger, sock, handshake + (TCP_CLIENT_HANDSHAKE_SIZE - 1), 1, &localhost) == 1,
|
||||
"Failed to send last byte of handshake.");
|
||||
|
||||
do_TCP_server_delay(tcp_s, mono_time, 50);
|
||||
do_tcp_server_delay(tcp_s, mono_time, 50);
|
||||
|
||||
uint8_t response[TCP_SERVER_HANDSHAKE_SIZE];
|
||||
uint8_t response_plain[TCP_HANDSHAKE_PLAIN_SIZE];
|
||||
@ -251,13 +257,13 @@ static struct sec_TCP_con *new_TCP_con(const Logger *logger, const Random *rng,
|
||||
return sec_c;
|
||||
}
|
||||
|
||||
static void kill_TCP_con(struct sec_TCP_con *con)
|
||||
static void kill_tcp_con(struct sec_TCP_con *con)
|
||||
{
|
||||
kill_sock(con->ns, con->sock);
|
||||
free(con);
|
||||
}
|
||||
|
||||
static int write_packet_TCP_test_connection(const Logger *logger, struct sec_TCP_con *con, const uint8_t *data,
|
||||
static int write_packet_tcp_test_connection(const Logger *logger, struct sec_TCP_con *con, const uint8_t *data,
|
||||
uint16_t length)
|
||||
{
|
||||
VLA(uint8_t, packet, sizeof(uint16_t) + length + CRYPTO_MAC_SIZE);
|
||||
@ -281,7 +287,7 @@ static int write_packet_TCP_test_connection(const Logger *logger, struct sec_TCP
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int read_packet_sec_TCP(const Logger *logger, struct sec_TCP_con *con, uint8_t *data, uint16_t length)
|
||||
static int read_packet_sec_tcp(const Logger *logger, struct sec_TCP_con *con, uint8_t *data, uint16_t length)
|
||||
{
|
||||
IP_Port localhost;
|
||||
localhost.ip = get_loopback();
|
||||
@ -297,44 +303,48 @@ static int read_packet_sec_TCP(const Logger *logger, struct sec_TCP_con *con, ui
|
||||
|
||||
static void test_some(void)
|
||||
{
|
||||
Mono_Time *mono_time = mono_time_new(nullptr, nullptr);
|
||||
const Random *rng = system_random();
|
||||
ck_assert(rng != nullptr);
|
||||
Logger *logger = logger_new();
|
||||
const Network *ns = system_network();
|
||||
ck_assert(ns != nullptr);
|
||||
const Memory *mem = system_memory();
|
||||
ck_assert(mem != nullptr);
|
||||
|
||||
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
|
||||
Logger *logger = logger_new();
|
||||
|
||||
uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE];
|
||||
uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE];
|
||||
crypto_new_keypair(rng, self_public_key, self_secret_key);
|
||||
TCP_Server *tcp_s = new_TCP_server(logger, rng, ns, USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr, nullptr);
|
||||
TCP_Server *tcp_s = new_tcp_server(logger, mem, rng, ns, USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr, nullptr);
|
||||
ck_assert_msg(tcp_s != nullptr, "Failed to create TCP relay server");
|
||||
ck_assert_msg(tcp_server_listen_count(tcp_s) == NUM_PORTS, "Failed to bind to all ports.");
|
||||
|
||||
struct sec_TCP_con *con1 = new_TCP_con(logger, rng, ns, tcp_s, mono_time);
|
||||
struct sec_TCP_con *con2 = new_TCP_con(logger, rng, ns, tcp_s, mono_time);
|
||||
struct sec_TCP_con *con3 = new_TCP_con(logger, rng, ns, tcp_s, mono_time);
|
||||
struct sec_TCP_con *con1 = new_tcp_con(logger, mem, rng, ns, tcp_s, mono_time);
|
||||
struct sec_TCP_con *con2 = new_tcp_con(logger, mem, rng, ns, tcp_s, mono_time);
|
||||
struct sec_TCP_con *con3 = new_tcp_con(logger, mem, rng, ns, tcp_s, mono_time);
|
||||
|
||||
uint8_t requ_p[1 + CRYPTO_PUBLIC_KEY_SIZE];
|
||||
requ_p[0] = TCP_PACKET_ROUTING_REQUEST;
|
||||
|
||||
// Sending wrong public keys to test server response.
|
||||
memcpy(requ_p + 1, con3->public_key, CRYPTO_PUBLIC_KEY_SIZE);
|
||||
write_packet_TCP_test_connection(logger, con1, requ_p, sizeof(requ_p));
|
||||
write_packet_tcp_test_connection(logger, con1, requ_p, sizeof(requ_p));
|
||||
memcpy(requ_p + 1, con1->public_key, CRYPTO_PUBLIC_KEY_SIZE);
|
||||
write_packet_TCP_test_connection(logger, con3, requ_p, sizeof(requ_p));
|
||||
write_packet_tcp_test_connection(logger, con3, requ_p, sizeof(requ_p));
|
||||
|
||||
do_TCP_server_delay(tcp_s, mono_time, 50);
|
||||
do_tcp_server_delay(tcp_s, mono_time, 50);
|
||||
|
||||
// Testing response from connection 1
|
||||
uint8_t data[2048];
|
||||
int len = read_packet_sec_TCP(logger, con1, data, 2 + 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE);
|
||||
int len = read_packet_sec_tcp(logger, con1, data, 2 + 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE);
|
||||
ck_assert_msg(len == 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE, "Wrong response packet length of %d.", len);
|
||||
ck_assert_msg(data[0] == TCP_PACKET_ROUTING_RESPONSE, "Wrong response packet id of %d.", data[0]);
|
||||
ck_assert_msg(data[1] == 16, "Server didn't refuse connection using wrong public key.");
|
||||
ck_assert_msg(pk_equal(data + 2, con3->public_key), "Key in response packet wrong.");
|
||||
|
||||
// Connection 3
|
||||
len = read_packet_sec_TCP(logger, con3, data, 2 + 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE);
|
||||
len = read_packet_sec_tcp(logger, con3, data, 2 + 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE);
|
||||
ck_assert_msg(len == 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE, "Wrong response packet length of %d.", len);
|
||||
ck_assert_msg(data[0] == TCP_PACKET_ROUTING_RESPONSE, "Wrong response packet id of %d.", data[0]);
|
||||
ck_assert_msg(data[1] == 16, "Server didn't refuse connection using wrong public key.");
|
||||
@ -342,67 +352,67 @@ static void test_some(void)
|
||||
|
||||
uint8_t test_packet[512] = {16, 17, 16, 86, 99, 127, 255, 189, 78}; // What is this packet????
|
||||
|
||||
write_packet_TCP_test_connection(logger, con3, test_packet, sizeof(test_packet));
|
||||
write_packet_TCP_test_connection(logger, con3, test_packet, sizeof(test_packet));
|
||||
write_packet_TCP_test_connection(logger, con3, test_packet, sizeof(test_packet));
|
||||
write_packet_tcp_test_connection(logger, con3, test_packet, sizeof(test_packet));
|
||||
write_packet_tcp_test_connection(logger, con3, test_packet, sizeof(test_packet));
|
||||
write_packet_tcp_test_connection(logger, con3, test_packet, sizeof(test_packet));
|
||||
|
||||
do_TCP_server_delay(tcp_s, mono_time, 50);
|
||||
do_tcp_server_delay(tcp_s, mono_time, 50);
|
||||
|
||||
len = read_packet_sec_TCP(logger, con1, data, 2 + 2 + CRYPTO_MAC_SIZE);
|
||||
len = read_packet_sec_tcp(logger, con1, data, 2 + 2 + CRYPTO_MAC_SIZE);
|
||||
ck_assert_msg(len == 2, "wrong len %d", len);
|
||||
ck_assert_msg(data[0] == TCP_PACKET_CONNECTION_NOTIFICATION, "wrong packet id %u", data[0]);
|
||||
ck_assert_msg(data[1] == 16, "wrong peer id %u", data[1]);
|
||||
len = read_packet_sec_TCP(logger, con3, data, 2 + 2 + CRYPTO_MAC_SIZE);
|
||||
len = read_packet_sec_tcp(logger, con3, data, 2 + 2 + CRYPTO_MAC_SIZE);
|
||||
ck_assert_msg(len == 2, "wrong len %d", len);
|
||||
ck_assert_msg(data[0] == TCP_PACKET_CONNECTION_NOTIFICATION, "wrong packet id %u", data[0]);
|
||||
ck_assert_msg(data[1] == 16, "wrong peer id %u", data[1]);
|
||||
len = read_packet_sec_TCP(logger, con1, data, 2 + sizeof(test_packet) + CRYPTO_MAC_SIZE);
|
||||
len = read_packet_sec_tcp(logger, con1, data, 2 + sizeof(test_packet) + CRYPTO_MAC_SIZE);
|
||||
ck_assert_msg(len == sizeof(test_packet), "wrong len %d", len);
|
||||
ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1],
|
||||
data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]);
|
||||
len = read_packet_sec_TCP(logger, con1, data, 2 + sizeof(test_packet) + CRYPTO_MAC_SIZE);
|
||||
len = read_packet_sec_tcp(logger, con1, data, 2 + sizeof(test_packet) + CRYPTO_MAC_SIZE);
|
||||
ck_assert_msg(len == sizeof(test_packet), "wrong len %d", len);
|
||||
ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1],
|
||||
data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]);
|
||||
len = read_packet_sec_TCP(logger, con1, data, 2 + sizeof(test_packet) + CRYPTO_MAC_SIZE);
|
||||
len = read_packet_sec_tcp(logger, con1, data, 2 + sizeof(test_packet) + CRYPTO_MAC_SIZE);
|
||||
ck_assert_msg(len == sizeof(test_packet), "wrong len %d", len);
|
||||
ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1],
|
||||
data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]);
|
||||
write_packet_TCP_test_connection(logger, con1, test_packet, sizeof(test_packet));
|
||||
write_packet_TCP_test_connection(logger, con1, test_packet, sizeof(test_packet));
|
||||
write_packet_TCP_test_connection(logger, con1, test_packet, sizeof(test_packet));
|
||||
do_TCP_server_delay(tcp_s, mono_time, 50);
|
||||
len = read_packet_sec_TCP(logger, con3, data, 2 + sizeof(test_packet) + CRYPTO_MAC_SIZE);
|
||||
write_packet_tcp_test_connection(logger, con1, test_packet, sizeof(test_packet));
|
||||
write_packet_tcp_test_connection(logger, con1, test_packet, sizeof(test_packet));
|
||||
write_packet_tcp_test_connection(logger, con1, test_packet, sizeof(test_packet));
|
||||
do_tcp_server_delay(tcp_s, mono_time, 50);
|
||||
len = read_packet_sec_tcp(logger, con3, data, 2 + sizeof(test_packet) + CRYPTO_MAC_SIZE);
|
||||
ck_assert_msg(len == sizeof(test_packet), "wrong len %d", len);
|
||||
ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1],
|
||||
data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]);
|
||||
len = read_packet_sec_TCP(logger, con3, data, 2 + sizeof(test_packet) + CRYPTO_MAC_SIZE);
|
||||
len = read_packet_sec_tcp(logger, con3, data, 2 + sizeof(test_packet) + CRYPTO_MAC_SIZE);
|
||||
ck_assert_msg(len == sizeof(test_packet), "wrong len %d", len);
|
||||
ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1],
|
||||
data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]);
|
||||
len = read_packet_sec_TCP(logger, con3, data, 2 + sizeof(test_packet) + CRYPTO_MAC_SIZE);
|
||||
len = read_packet_sec_tcp(logger, con3, data, 2 + sizeof(test_packet) + CRYPTO_MAC_SIZE);
|
||||
ck_assert_msg(len == sizeof(test_packet), "wrong len %d", len);
|
||||
ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1],
|
||||
data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]);
|
||||
|
||||
uint8_t ping_packet[1 + sizeof(uint64_t)] = {TCP_PACKET_PING, 8, 6, 9, 67};
|
||||
write_packet_TCP_test_connection(logger, con1, ping_packet, sizeof(ping_packet));
|
||||
write_packet_tcp_test_connection(logger, con1, ping_packet, sizeof(ping_packet));
|
||||
|
||||
do_TCP_server_delay(tcp_s, mono_time, 50);
|
||||
do_tcp_server_delay(tcp_s, mono_time, 50);
|
||||
|
||||
len = read_packet_sec_TCP(logger, con1, data, 2 + sizeof(ping_packet) + CRYPTO_MAC_SIZE);
|
||||
len = read_packet_sec_tcp(logger, con1, data, 2 + sizeof(ping_packet) + CRYPTO_MAC_SIZE);
|
||||
ck_assert_msg(len == sizeof(ping_packet), "wrong len %d", len);
|
||||
ck_assert_msg(data[0] == TCP_PACKET_PONG, "wrong packet id %u", data[0]);
|
||||
ck_assert_msg(memcmp(ping_packet + 1, data + 1, sizeof(uint64_t)) == 0, "wrong packet data");
|
||||
|
||||
// Kill off the connections
|
||||
kill_TCP_server(tcp_s);
|
||||
kill_TCP_con(con1);
|
||||
kill_TCP_con(con2);
|
||||
kill_TCP_con(con3);
|
||||
kill_tcp_server(tcp_s);
|
||||
kill_tcp_con(con1);
|
||||
kill_tcp_con(con2);
|
||||
kill_tcp_con(con3);
|
||||
|
||||
logger_kill(logger);
|
||||
mono_time_free(mono_time);
|
||||
mono_time_free(mem, mono_time);
|
||||
}
|
||||
|
||||
static int response_callback_good;
|
||||
@ -488,16 +498,20 @@ static int oob_data_callback(void *object, const uint8_t *public_key, const uint
|
||||
|
||||
static void test_client(void)
|
||||
{
|
||||
Mono_Time *mono_time = mono_time_new(nullptr, nullptr);
|
||||
const Random *rng = system_random();
|
||||
ck_assert(rng != nullptr);
|
||||
const Network *ns = system_network();
|
||||
ck_assert(ns != nullptr);
|
||||
const Memory *mem = system_memory();
|
||||
ck_assert(mem != nullptr);
|
||||
|
||||
Logger *logger = logger_new();
|
||||
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
|
||||
|
||||
uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE];
|
||||
uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE];
|
||||
crypto_new_keypair(rng, self_public_key, self_secret_key);
|
||||
const Network *ns = system_network();
|
||||
TCP_Server *tcp_s = new_TCP_server(logger, rng, ns, USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr, nullptr);
|
||||
TCP_Server *tcp_s = new_tcp_server(logger, mem, rng, ns, USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr, nullptr);
|
||||
ck_assert_msg(tcp_s != nullptr, "Failed to create a TCP relay server.");
|
||||
ck_assert_msg(tcp_server_listen_count(tcp_s) == NUM_PORTS, "Failed to bind the relay server to all ports.");
|
||||
|
||||
@ -509,9 +523,8 @@ static void test_client(void)
|
||||
ip_port_tcp_s.port = net_htons(ports[random_u32(rng) % NUM_PORTS]);
|
||||
ip_port_tcp_s.ip = get_loopback();
|
||||
|
||||
TCP_Client_Connection *conn = new_TCP_connection(logger, mono_time, rng, ns, &ip_port_tcp_s, self_public_key, f_public_key,
|
||||
f_secret_key, nullptr);
|
||||
do_TCP_connection(logger, mono_time, conn, nullptr);
|
||||
TCP_Client_Connection *conn = new_tcp_connection(logger, mem, mono_time, rng, ns, &ip_port_tcp_s, self_public_key, f_public_key, f_secret_key, nullptr);
|
||||
do_tcp_connection(logger, mono_time, conn, nullptr);
|
||||
c_sleep(50);
|
||||
|
||||
// The connection status should be unconfirmed here because we have finished
|
||||
@ -519,22 +532,22 @@ static void test_client(void)
|
||||
ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_UNCONFIRMED, "Wrong connection status. Expected: %d, is: %d.",
|
||||
TCP_CLIENT_UNCONFIRMED, tcp_con_status(conn));
|
||||
|
||||
do_TCP_server_delay(tcp_s, mono_time, 50); // Now let the server handle requests...
|
||||
do_tcp_server_delay(tcp_s, mono_time, 50); // Now let the server handle requests...
|
||||
|
||||
const uint8_t LOOP_SIZE = 3;
|
||||
const uint8_t loop_size = 3;
|
||||
|
||||
for (uint8_t i = 0; i < LOOP_SIZE; i++) {
|
||||
for (uint8_t i = 0; i < loop_size; i++) {
|
||||
mono_time_update(mono_time);
|
||||
do_TCP_connection(logger, mono_time, conn, nullptr); // Run the connection loop.
|
||||
do_tcp_connection(logger, mono_time, conn, nullptr); // Run the connection loop.
|
||||
|
||||
// The status of the connection should continue to be TCP_CLIENT_CONFIRMED after multiple subsequent do_TCP_connection() calls.
|
||||
// The status of the connection should continue to be TCP_CLIENT_CONFIRMED after multiple subsequent do_tcp_connection() calls.
|
||||
ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_CONFIRMED, "Wrong connection status. Expected: %d, is: %d",
|
||||
TCP_CLIENT_CONFIRMED, tcp_con_status(conn));
|
||||
|
||||
c_sleep(i == LOOP_SIZE - 1 ? 0 : 500); // Sleep for 500ms on all except third loop.
|
||||
c_sleep(i == loop_size - 1 ? 0 : 500); // Sleep for 500ms on all except third loop.
|
||||
}
|
||||
|
||||
do_TCP_server_delay(tcp_s, mono_time, 50);
|
||||
do_tcp_server_delay(tcp_s, mono_time, 50);
|
||||
|
||||
// And still after the server runs again.
|
||||
ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_CONFIRMED, "Wrong status. Expected: %d, is: %d", TCP_CLIENT_CONFIRMED,
|
||||
@ -544,7 +557,7 @@ static void test_client(void)
|
||||
uint8_t f2_secret_key[CRYPTO_SECRET_KEY_SIZE];
|
||||
crypto_new_keypair(rng, f2_public_key, f2_secret_key);
|
||||
ip_port_tcp_s.port = net_htons(ports[random_u32(rng) % NUM_PORTS]);
|
||||
TCP_Client_Connection *conn2 = new_TCP_connection(logger, mono_time, rng, ns, &ip_port_tcp_s, self_public_key, f2_public_key,
|
||||
TCP_Client_Connection *conn2 = new_tcp_connection(logger, mem, mono_time, rng, ns, &ip_port_tcp_s, self_public_key, f2_public_key,
|
||||
f2_secret_key, nullptr);
|
||||
|
||||
// The client should call this function (defined earlier) during the routing process.
|
||||
@ -559,13 +572,13 @@ static void test_client(void)
|
||||
// These integers will increment per successful callback.
|
||||
oob_data_callback_good = response_callback_good = status_callback_good = data_callback_good = 0;
|
||||
|
||||
do_TCP_connection(logger, mono_time, conn, nullptr);
|
||||
do_TCP_connection(logger, mono_time, conn2, nullptr);
|
||||
do_tcp_connection(logger, mono_time, conn, nullptr);
|
||||
do_tcp_connection(logger, mono_time, conn2, nullptr);
|
||||
|
||||
do_TCP_server_delay(tcp_s, mono_time, 50);
|
||||
do_tcp_server_delay(tcp_s, mono_time, 50);
|
||||
|
||||
do_TCP_connection(logger, mono_time, conn, nullptr);
|
||||
do_TCP_connection(logger, mono_time, conn2, nullptr);
|
||||
do_tcp_connection(logger, mono_time, conn, nullptr);
|
||||
do_tcp_connection(logger, mono_time, conn2, nullptr);
|
||||
c_sleep(50);
|
||||
|
||||
uint8_t data[5] = {1, 2, 3, 4, 5};
|
||||
@ -574,10 +587,10 @@ static void test_client(void)
|
||||
send_routing_request(logger, conn, f2_public_key);
|
||||
send_routing_request(logger, conn2, f_public_key);
|
||||
|
||||
do_TCP_server_delay(tcp_s, mono_time, 50);
|
||||
do_tcp_server_delay(tcp_s, mono_time, 50);
|
||||
|
||||
do_TCP_connection(logger, mono_time, conn, nullptr);
|
||||
do_TCP_connection(logger, mono_time, conn2, nullptr);
|
||||
do_tcp_connection(logger, mono_time, conn, nullptr);
|
||||
do_tcp_connection(logger, mono_time, conn2, nullptr);
|
||||
|
||||
// All callback methods save data should have run during the above network prodding.
|
||||
ck_assert_msg(oob_data_callback_good == 1, "OOB callback not called");
|
||||
@ -588,42 +601,46 @@ static void test_client(void)
|
||||
ck_assert_msg(status_callback_connection_id == response_callback_connection_id,
|
||||
"Status and response callback connection IDs are not equal.");
|
||||
|
||||
do_TCP_server_delay(tcp_s, mono_time, 50);
|
||||
do_tcp_server_delay(tcp_s, mono_time, 50);
|
||||
|
||||
ck_assert_msg(send_data(logger, conn2, 0, data, 5) == 1, "Failed a send_data() call.");
|
||||
|
||||
do_TCP_server_delay(tcp_s, mono_time, 50);
|
||||
do_tcp_server_delay(tcp_s, mono_time, 50);
|
||||
|
||||
do_TCP_connection(logger, mono_time, conn, nullptr);
|
||||
do_TCP_connection(logger, mono_time, conn2, nullptr);
|
||||
do_tcp_connection(logger, mono_time, conn, nullptr);
|
||||
do_tcp_connection(logger, mono_time, conn2, nullptr);
|
||||
ck_assert_msg(data_callback_good == 1, "Data callback was not called.");
|
||||
status_callback_good = 0;
|
||||
send_disconnect_request(logger, conn2, 0);
|
||||
|
||||
do_TCP_server_delay(tcp_s, mono_time, 50);
|
||||
do_tcp_server_delay(tcp_s, mono_time, 50);
|
||||
|
||||
do_TCP_connection(logger, mono_time, conn, nullptr);
|
||||
do_TCP_connection(logger, mono_time, conn2, nullptr);
|
||||
do_tcp_connection(logger, mono_time, conn, nullptr);
|
||||
do_tcp_connection(logger, mono_time, conn2, nullptr);
|
||||
ck_assert_msg(status_callback_good == 1, "Status callback not called");
|
||||
ck_assert_msg(status_callback_status == 1, "Wrong status callback status.");
|
||||
|
||||
// Kill off all connections and servers.
|
||||
kill_TCP_server(tcp_s);
|
||||
kill_TCP_connection(conn);
|
||||
kill_TCP_connection(conn2);
|
||||
kill_tcp_server(tcp_s);
|
||||
kill_tcp_connection(conn);
|
||||
kill_tcp_connection(conn2);
|
||||
|
||||
logger_kill(logger);
|
||||
mono_time_free(mono_time);
|
||||
mono_time_free(mem, mono_time);
|
||||
}
|
||||
|
||||
// Test how the client handles servers that don't respond.
|
||||
static void test_client_invalid(void)
|
||||
{
|
||||
Mono_Time *mono_time = mono_time_new(nullptr, nullptr);
|
||||
const Random *rng = system_random();
|
||||
ck_assert(rng != nullptr);
|
||||
Logger *logger = logger_new();
|
||||
const Network *ns = system_network();
|
||||
ck_assert(ns != nullptr);
|
||||
const Memory *mem = system_memory();
|
||||
ck_assert(mem != nullptr);
|
||||
|
||||
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
|
||||
Logger *logger = logger_new();
|
||||
|
||||
uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE];
|
||||
uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE];
|
||||
@ -636,12 +653,12 @@ static void test_client_invalid(void)
|
||||
|
||||
ip_port_tcp_s.port = net_htons(ports[random_u32(rng) % NUM_PORTS]);
|
||||
ip_port_tcp_s.ip = get_loopback();
|
||||
TCP_Client_Connection *conn = new_TCP_connection(logger, mono_time, rng, ns, &ip_port_tcp_s,
|
||||
TCP_Client_Connection *conn = new_tcp_connection(logger, mem, mono_time, rng, ns, &ip_port_tcp_s,
|
||||
self_public_key, f_public_key, f_secret_key, nullptr);
|
||||
|
||||
// Run the client's main loop but not the server.
|
||||
mono_time_update(mono_time);
|
||||
do_TCP_connection(logger, mono_time, conn, nullptr);
|
||||
do_tcp_connection(logger, mono_time, conn, nullptr);
|
||||
c_sleep(50);
|
||||
|
||||
// After 50ms of no response...
|
||||
@ -650,20 +667,20 @@ static void test_client_invalid(void)
|
||||
// After 5s...
|
||||
c_sleep(5000);
|
||||
mono_time_update(mono_time);
|
||||
do_TCP_connection(logger, mono_time, conn, nullptr);
|
||||
do_tcp_connection(logger, mono_time, conn, nullptr);
|
||||
ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_CONNECTING, "Wrong status. Expected: %d, is: %d.",
|
||||
TCP_CLIENT_CONNECTING, tcp_con_status(conn));
|
||||
// 11s... (Should wait for 10 before giving up.)
|
||||
c_sleep(6000);
|
||||
mono_time_update(mono_time);
|
||||
do_TCP_connection(logger, mono_time, conn, nullptr);
|
||||
do_tcp_connection(logger, mono_time, conn, nullptr);
|
||||
ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_DISCONNECTED, "Wrong status. Expected: %d, is: %d.",
|
||||
TCP_CLIENT_DISCONNECTED, tcp_con_status(conn));
|
||||
|
||||
kill_TCP_connection(conn);
|
||||
kill_tcp_connection(conn);
|
||||
|
||||
logger_kill(logger);
|
||||
mono_time_free(mono_time);
|
||||
mono_time_free(mem, mono_time);
|
||||
}
|
||||
|
||||
#include "../toxcore/TCP_connection.h"
|
||||
@ -694,27 +711,31 @@ static int tcp_data_callback(void *object, int id, const uint8_t *data, uint16_t
|
||||
|
||||
static void test_tcp_connection(void)
|
||||
{
|
||||
Mono_Time *mono_time = mono_time_new(nullptr, nullptr);
|
||||
Logger *logger = logger_new();
|
||||
const Random *rng = system_random();
|
||||
ck_assert(rng != nullptr);
|
||||
const Network *ns = system_network();
|
||||
ck_assert(ns != nullptr);
|
||||
const Memory *mem = system_memory();
|
||||
ck_assert(mem != nullptr);
|
||||
|
||||
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
|
||||
Logger *logger = logger_new();
|
||||
|
||||
tcp_data_callback_called = 0;
|
||||
uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE];
|
||||
uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE];
|
||||
crypto_new_keypair(rng, self_public_key, self_secret_key);
|
||||
TCP_Server *tcp_s = new_TCP_server(logger, rng, ns, USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr, nullptr);
|
||||
TCP_Server *tcp_s = new_tcp_server(logger, mem, rng, ns, USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr, nullptr);
|
||||
ck_assert_msg(pk_equal(tcp_server_public_key(tcp_s), self_public_key), "Wrong public key");
|
||||
|
||||
TCP_Proxy_Info proxy_info;
|
||||
proxy_info.proxy_type = TCP_PROXY_NONE;
|
||||
crypto_new_keypair(rng, self_public_key, self_secret_key);
|
||||
TCP_Connections *tc_1 = new_tcp_connections(logger, rng, ns, mono_time, self_secret_key, &proxy_info);
|
||||
TCP_Connections *tc_1 = new_tcp_connections(logger, mem, rng, ns, mono_time, self_secret_key, &proxy_info);
|
||||
ck_assert_msg(pk_equal(tcp_connections_public_key(tc_1), self_public_key), "Wrong public key");
|
||||
|
||||
crypto_new_keypair(rng, self_public_key, self_secret_key);
|
||||
TCP_Connections *tc_2 = new_tcp_connections(logger, rng, ns, mono_time, self_secret_key, &proxy_info);
|
||||
TCP_Connections *tc_2 = new_tcp_connections(logger, mem, rng, ns, mono_time, self_secret_key, &proxy_info);
|
||||
ck_assert_msg(pk_equal(tcp_connections_public_key(tc_2), self_public_key), "Wrong public key");
|
||||
|
||||
IP_Port ip_port_tcp_s;
|
||||
@ -736,17 +757,17 @@ static void test_tcp_connection(void)
|
||||
ck_assert_msg(new_tcp_connection_to(tc_2, tcp_connections_public_key(tc_1), 123) == -1,
|
||||
"Managed to read same connection\n");
|
||||
|
||||
do_TCP_server_delay(tcp_s, mono_time, 50);
|
||||
do_tcp_server_delay(tcp_s, mono_time, 50);
|
||||
|
||||
do_tcp_connections(logger, tc_1, nullptr);
|
||||
do_tcp_connections(logger, tc_2, nullptr);
|
||||
|
||||
do_TCP_server_delay(tcp_s, mono_time, 50);
|
||||
do_tcp_server_delay(tcp_s, mono_time, 50);
|
||||
|
||||
do_tcp_connections(logger, tc_1, nullptr);
|
||||
do_tcp_connections(logger, tc_2, nullptr);
|
||||
|
||||
do_TCP_server_delay(tcp_s, mono_time, 50);
|
||||
do_tcp_server_delay(tcp_s, mono_time, 50);
|
||||
|
||||
do_tcp_connections(logger, tc_1, nullptr);
|
||||
do_tcp_connections(logger, tc_2, nullptr);
|
||||
@ -755,7 +776,7 @@ static void test_tcp_connection(void)
|
||||
ck_assert_msg(ret == 0, "could not send packet.");
|
||||
set_packet_tcp_connection_callback(tc_2, &tcp_data_callback, (void *) 120397);
|
||||
|
||||
do_TCP_server_delay(tcp_s, mono_time, 50);
|
||||
do_tcp_server_delay(tcp_s, mono_time, 50);
|
||||
|
||||
do_tcp_connections(logger, tc_1, nullptr);
|
||||
do_tcp_connections(logger, tc_2, nullptr);
|
||||
@ -764,7 +785,7 @@ static void test_tcp_connection(void)
|
||||
ck_assert_msg(tcp_connection_to_online_tcp_relays(tc_1, 0) == 1, "Wrong number of connected relays");
|
||||
ck_assert_msg(kill_tcp_connection_to(tc_1, 0) == 0, "could not kill connection to\n");
|
||||
|
||||
do_TCP_server_delay(tcp_s, mono_time, 50);
|
||||
do_tcp_server_delay(tcp_s, mono_time, 50);
|
||||
|
||||
do_tcp_connections(logger, tc_1, nullptr);
|
||||
do_tcp_connections(logger, tc_2, nullptr);
|
||||
@ -772,12 +793,12 @@ static void test_tcp_connection(void)
|
||||
ck_assert_msg(send_packet_tcp_connection(tc_1, 0, (const uint8_t *)"Gentoo", 6) == -1, "could send packet.");
|
||||
ck_assert_msg(kill_tcp_connection_to(tc_2, 0) == 0, "could not kill connection to\n");
|
||||
|
||||
kill_TCP_server(tcp_s);
|
||||
kill_tcp_server(tcp_s);
|
||||
kill_tcp_connections(tc_1);
|
||||
kill_tcp_connections(tc_2);
|
||||
|
||||
logger_kill(logger);
|
||||
mono_time_free(mono_time);
|
||||
mono_time_free(mem, mono_time);
|
||||
}
|
||||
|
||||
static bool tcp_oobdata_callback_called;
|
||||
@ -803,11 +824,15 @@ static int tcp_oobdata_callback(void *object, const uint8_t *public_key, unsigne
|
||||
|
||||
static void test_tcp_connection2(void)
|
||||
{
|
||||
Mono_Time *mono_time = mono_time_new(nullptr, nullptr);
|
||||
Logger *logger = logger_new();
|
||||
const Random *rng = system_random();
|
||||
ck_assert(rng != nullptr);
|
||||
const Network *ns = system_network();
|
||||
ck_assert(ns != nullptr);
|
||||
const Memory *mem = system_memory();
|
||||
ck_assert(mem != nullptr);
|
||||
|
||||
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
|
||||
Logger *logger = logger_new();
|
||||
|
||||
tcp_oobdata_callback_called = 0;
|
||||
tcp_data_callback_called = 0;
|
||||
@ -815,17 +840,17 @@ static void test_tcp_connection2(void)
|
||||
uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE];
|
||||
uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE];
|
||||
crypto_new_keypair(rng, self_public_key, self_secret_key);
|
||||
TCP_Server *tcp_s = new_TCP_server(logger, rng, ns, USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr, nullptr);
|
||||
TCP_Server *tcp_s = new_tcp_server(logger, mem, rng, ns, USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr, nullptr);
|
||||
ck_assert_msg(pk_equal(tcp_server_public_key(tcp_s), self_public_key), "Wrong public key");
|
||||
|
||||
TCP_Proxy_Info proxy_info;
|
||||
proxy_info.proxy_type = TCP_PROXY_NONE;
|
||||
crypto_new_keypair(rng, self_public_key, self_secret_key);
|
||||
TCP_Connections *tc_1 = new_tcp_connections(logger, rng, ns, mono_time, self_secret_key, &proxy_info);
|
||||
TCP_Connections *tc_1 = new_tcp_connections(logger, mem, rng, ns, mono_time, self_secret_key, &proxy_info);
|
||||
ck_assert_msg(pk_equal(tcp_connections_public_key(tc_1), self_public_key), "Wrong public key");
|
||||
|
||||
crypto_new_keypair(rng, self_public_key, self_secret_key);
|
||||
TCP_Connections *tc_2 = new_tcp_connections(logger, rng, ns, mono_time, self_secret_key, &proxy_info);
|
||||
TCP_Connections *tc_2 = new_tcp_connections(logger, mem, rng, ns, mono_time, self_secret_key, &proxy_info);
|
||||
ck_assert_msg(pk_equal(tcp_connections_public_key(tc_2), self_public_key), "Wrong public key");
|
||||
|
||||
IP_Port ip_port_tcp_s;
|
||||
@ -841,17 +866,17 @@ static void test_tcp_connection2(void)
|
||||
ck_assert_msg(add_tcp_relay_global(tc_2, &ip_port_tcp_s, tcp_server_public_key(tcp_s)) == 0,
|
||||
"Could not add global relay");
|
||||
|
||||
do_TCP_server_delay(tcp_s, mono_time, 50);
|
||||
do_tcp_server_delay(tcp_s, mono_time, 50);
|
||||
|
||||
do_tcp_connections(logger, tc_1, nullptr);
|
||||
do_tcp_connections(logger, tc_2, nullptr);
|
||||
|
||||
do_TCP_server_delay(tcp_s, mono_time, 50);
|
||||
do_tcp_server_delay(tcp_s, mono_time, 50);
|
||||
|
||||
do_tcp_connections(logger, tc_1, nullptr);
|
||||
do_tcp_connections(logger, tc_2, nullptr);
|
||||
|
||||
do_TCP_server_delay(tcp_s, mono_time, 50);
|
||||
do_tcp_server_delay(tcp_s, mono_time, 50);
|
||||
|
||||
do_tcp_connections(logger, tc_1, nullptr);
|
||||
do_tcp_connections(logger, tc_2, nullptr);
|
||||
@ -861,14 +886,14 @@ static void test_tcp_connection2(void)
|
||||
set_oob_packet_tcp_connection_callback(tc_2, &tcp_oobdata_callback, tc_2);
|
||||
set_packet_tcp_connection_callback(tc_1, &tcp_data_callback, (void *) 120397);
|
||||
|
||||
do_TCP_server_delay(tcp_s, mono_time, 50);
|
||||
do_tcp_server_delay(tcp_s, mono_time, 50);
|
||||
|
||||
do_tcp_connections(logger, tc_1, nullptr);
|
||||
do_tcp_connections(logger, tc_2, nullptr);
|
||||
|
||||
ck_assert_msg(tcp_oobdata_callback_called, "could not recv packet.");
|
||||
|
||||
do_TCP_server_delay(tcp_s, mono_time, 50);
|
||||
do_tcp_server_delay(tcp_s, mono_time, 50);
|
||||
|
||||
do_tcp_connections(logger, tc_1, nullptr);
|
||||
do_tcp_connections(logger, tc_2, nullptr);
|
||||
@ -876,15 +901,15 @@ static void test_tcp_connection2(void)
|
||||
ck_assert_msg(tcp_data_callback_called, "could not recv packet.");
|
||||
ck_assert_msg(kill_tcp_connection_to(tc_1, 0) == 0, "could not kill connection to\n");
|
||||
|
||||
kill_TCP_server(tcp_s);
|
||||
kill_tcp_server(tcp_s);
|
||||
kill_tcp_connections(tc_1);
|
||||
kill_tcp_connections(tc_2);
|
||||
|
||||
logger_kill(logger);
|
||||
mono_time_free(mono_time);
|
||||
mono_time_free(mem, mono_time);
|
||||
}
|
||||
|
||||
static void TCP_suite(void)
|
||||
static void tcp_suite(void)
|
||||
{
|
||||
test_basic();
|
||||
test_some();
|
||||
@ -897,6 +922,6 @@ static void TCP_suite(void)
|
||||
int main(void)
|
||||
{
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
TCP_suite();
|
||||
tcp_suite();
|
||||
return 0;
|
||||
}
|
||||
|
@ -54,14 +54,17 @@ static void test_store_data(void)
|
||||
ck_assert(rng != nullptr);
|
||||
const Network *ns = system_network();
|
||||
ck_assert(ns != nullptr);
|
||||
const Memory *mem = system_memory();
|
||||
ck_assert(mem != nullptr);
|
||||
|
||||
Logger *log = logger_new();
|
||||
ck_assert(log != nullptr);
|
||||
logger_callback_log(log, print_debug_logger, nullptr, nullptr);
|
||||
Mono_Time *mono_time = mono_time_new(nullptr, nullptr);
|
||||
Networking_Core *net = new_networking_no_udp(log, ns);
|
||||
DHT *dht = new_dht(log, rng, ns, mono_time, net, true, true);
|
||||
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
|
||||
Networking_Core *net = new_networking_no_udp(log, mem, ns);
|
||||
DHT *dht = new_dht(log, mem, rng, ns, mono_time, net, true, true);
|
||||
Forwarding *forwarding = new_forwarding(log, rng, mono_time, dht);
|
||||
Announcements *announce = new_announcements(log, rng, mono_time, forwarding);
|
||||
Announcements *announce = new_announcements(log, mem, rng, mono_time, forwarding);
|
||||
ck_assert(announce != nullptr);
|
||||
|
||||
/* Just to prevent CI from complaining that set_synch_offset is unused: */
|
||||
@ -103,7 +106,7 @@ static void test_store_data(void)
|
||||
kill_forwarding(forwarding);
|
||||
kill_dht(dht);
|
||||
kill_networking(net);
|
||||
mono_time_free(mono_time);
|
||||
mono_time_free(mem, mono_time);
|
||||
logger_kill(log);
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
#define ABORT_ON_LOG_ERROR true
|
||||
#endif
|
||||
|
||||
Run_Auto_Options default_run_auto_options()
|
||||
Run_Auto_Options default_run_auto_options(void)
|
||||
{
|
||||
return (Run_Auto_Options) {
|
||||
.graph = GRAPH_COMPLETE,
|
||||
@ -27,7 +27,7 @@ static const struct BootstrapNodes {
|
||||
const char *ip;
|
||||
uint16_t port;
|
||||
const uint8_t key[32];
|
||||
} BootstrapNodes[] = {
|
||||
} bootstrap_nodes[] = {
|
||||
#ifndef USE_TEST_NETWORK
|
||||
{
|
||||
"tox.abilinski.com", 33445,
|
||||
@ -80,10 +80,10 @@ void bootstrap_tox_live_network(Tox *tox, bool enable_tcp)
|
||||
{
|
||||
ck_assert(tox != nullptr);
|
||||
|
||||
for (size_t j = 0; BootstrapNodes[j].ip != nullptr; ++j) {
|
||||
const char *ip = BootstrapNodes[j].ip;
|
||||
uint16_t port = BootstrapNodes[j].port;
|
||||
const uint8_t *key = BootstrapNodes[j].key;
|
||||
for (size_t j = 0; bootstrap_nodes[j].ip != nullptr; ++j) {
|
||||
const char *ip = bootstrap_nodes[j].ip;
|
||||
uint16_t port = bootstrap_nodes[j].port;
|
||||
const uint8_t *key = bootstrap_nodes[j].key;
|
||||
|
||||
Tox_Err_Bootstrap err;
|
||||
tox_bootstrap(tox, ip, port, key, &err);
|
||||
|
@ -217,7 +217,7 @@ static bool test_audio(AutoTox *autotoxes, const bool *disabled, bool quiet)
|
||||
printf("testing sending and receiving audio\n");
|
||||
}
|
||||
|
||||
const int16_t PCM[GROUP_AV_TEST_SAMPLES] = {0};
|
||||
const int16_t pcm[GROUP_AV_TEST_SAMPLES] = {0};
|
||||
|
||||
reset_received_audio(autotoxes);
|
||||
|
||||
@ -227,7 +227,7 @@ static bool test_audio(AutoTox *autotoxes, const bool *disabled, bool quiet)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (toxav_group_send_audio(autotoxes[i].tox, 0, PCM, GROUP_AV_TEST_SAMPLES, 1, 48000) != 0) {
|
||||
if (toxav_group_send_audio(autotoxes[i].tox, 0, pcm, GROUP_AV_TEST_SAMPLES, 1, 48000) != 0) {
|
||||
if (!quiet) {
|
||||
ck_abort_msg("#%u failed to send audio", autotoxes[i].index);
|
||||
}
|
||||
@ -255,8 +255,12 @@ static void test_eventual_audio(AutoTox *autotoxes, const bool *disabled, uint64
|
||||
uint64_t start = autotoxes[0].clock;
|
||||
|
||||
while (autotoxes[0].clock < start + timeout) {
|
||||
if (test_audio(autotoxes, disabled, true)
|
||||
&& test_audio(autotoxes, disabled, true)) {
|
||||
if (!test_audio(autotoxes, disabled, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// It needs to succeed twice in a row for the test to pass.
|
||||
if (test_audio(autotoxes, disabled, true)) {
|
||||
printf("audio test successful after %d seconds\n", (int)((autotoxes[0].clock - start) / 1000));
|
||||
return;
|
||||
}
|
||||
@ -268,12 +272,12 @@ static void test_eventual_audio(AutoTox *autotoxes, const bool *disabled, uint64
|
||||
|
||||
static void do_audio(AutoTox *autotoxes, uint32_t iterations)
|
||||
{
|
||||
const int16_t PCM[GROUP_AV_TEST_SAMPLES] = {0};
|
||||
const int16_t pcm[GROUP_AV_TEST_SAMPLES] = {0};
|
||||
printf("running audio for %u iterations\n", iterations);
|
||||
|
||||
for (uint32_t f = 0; f < iterations; ++f) {
|
||||
for (uint32_t i = 0; i < NUM_AV_GROUP_TOX; ++i) {
|
||||
ck_assert_msg(toxav_group_send_audio(autotoxes[i].tox, 0, PCM, GROUP_AV_TEST_SAMPLES, 1, 48000) == 0,
|
||||
ck_assert_msg(toxav_group_send_audio(autotoxes[i].tox, 0, pcm, GROUP_AV_TEST_SAMPLES, 1, 48000) == 0,
|
||||
"#%u failed to send audio", autotoxes[i].index);
|
||||
iterate_all_wait(autotoxes, NUM_AV_GROUP_TOX, ITERATION_INTERVAL);
|
||||
}
|
||||
|
@ -9,9 +9,7 @@
|
||||
|
||||
static void rand_bytes(const Random *rng, uint8_t *b, size_t blen)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < blen; i++) {
|
||||
for (size_t i = 0; i < blen; i++) {
|
||||
b[i] = random_u08(rng);
|
||||
}
|
||||
}
|
||||
@ -84,19 +82,18 @@ static void test_known(void)
|
||||
{
|
||||
uint8_t c[147];
|
||||
uint8_t m[131];
|
||||
uint16_t clen, mlen;
|
||||
|
||||
ck_assert_msg(sizeof(c) == sizeof(m) + CRYPTO_MAC_SIZE * sizeof(uint8_t),
|
||||
"cyphertext should be CRYPTO_MAC_SIZE bytes longer than plaintext");
|
||||
ck_assert_msg(sizeof(test_c) == sizeof(c), "sanity check failed");
|
||||
ck_assert_msg(sizeof(test_m) == sizeof(m), "sanity check failed");
|
||||
|
||||
clen = encrypt_data(bobpk, alicesk, test_nonce, test_m, sizeof(test_m) / sizeof(uint8_t), c);
|
||||
const uint16_t clen = encrypt_data(bobpk, alicesk, test_nonce, test_m, sizeof(test_m) / sizeof(uint8_t), c);
|
||||
|
||||
ck_assert_msg(memcmp(test_c, c, sizeof(c)) == 0, "cyphertext doesn't match test vector");
|
||||
ck_assert_msg(clen == sizeof(c) / sizeof(uint8_t), "wrong ciphertext length");
|
||||
|
||||
mlen = decrypt_data(bobpk, alicesk, test_nonce, test_c, sizeof(test_c) / sizeof(uint8_t), m);
|
||||
const uint16_t mlen = decrypt_data(bobpk, alicesk, test_nonce, test_c, sizeof(test_c) / sizeof(uint8_t), m);
|
||||
|
||||
ck_assert_msg(memcmp(test_m, m, sizeof(m)) == 0, "decrypted text doesn't match test vector");
|
||||
ck_assert_msg(mlen == sizeof(m) / sizeof(uint8_t), "wrong plaintext length");
|
||||
@ -107,7 +104,6 @@ static void test_fast_known(void)
|
||||
uint8_t k[CRYPTO_SHARED_KEY_SIZE];
|
||||
uint8_t c[147];
|
||||
uint8_t m[131];
|
||||
uint16_t clen, mlen;
|
||||
|
||||
encrypt_precompute(bobpk, alicesk, k);
|
||||
|
||||
@ -116,12 +112,12 @@ static void test_fast_known(void)
|
||||
ck_assert_msg(sizeof(test_c) == sizeof(c), "sanity check failed");
|
||||
ck_assert_msg(sizeof(test_m) == sizeof(m), "sanity check failed");
|
||||
|
||||
clen = encrypt_data_symmetric(k, test_nonce, test_m, sizeof(test_m) / sizeof(uint8_t), c);
|
||||
const uint16_t clen = encrypt_data_symmetric(k, test_nonce, test_m, sizeof(test_m) / sizeof(uint8_t), c);
|
||||
|
||||
ck_assert_msg(memcmp(test_c, c, sizeof(c)) == 0, "cyphertext doesn't match test vector");
|
||||
ck_assert_msg(clen == sizeof(c) / sizeof(uint8_t), "wrong ciphertext length");
|
||||
|
||||
mlen = decrypt_data_symmetric(k, test_nonce, test_c, sizeof(test_c) / sizeof(uint8_t), m);
|
||||
const uint16_t mlen = decrypt_data_symmetric(k, test_nonce, test_c, sizeof(test_c) / sizeof(uint8_t), m);
|
||||
|
||||
ck_assert_msg(memcmp(test_m, m, sizeof(m)) == 0, "decrypted text doesn't match test vector");
|
||||
ck_assert_msg(mlen == sizeof(m) / sizeof(uint8_t), "wrong plaintext length");
|
||||
@ -275,10 +271,10 @@ static void test_large_data_symmetric(void)
|
||||
|
||||
static void increment_nonce_number_cmp(uint8_t *nonce, uint32_t num)
|
||||
{
|
||||
uint32_t num1, num2;
|
||||
uint32_t num1 = 0;
|
||||
memcpy(&num1, nonce + (CRYPTO_NONCE_SIZE - sizeof(num1)), sizeof(num1));
|
||||
num1 = net_ntohl(num1);
|
||||
num2 = num + num1;
|
||||
uint32_t num2 = num + num1;
|
||||
|
||||
if (num2 < num1) {
|
||||
for (uint16_t i = CRYPTO_NONCE_SIZE - sizeof(num1); i != 0; --i) {
|
||||
@ -299,11 +295,9 @@ static void test_increment_nonce(void)
|
||||
const Random *rng = system_random();
|
||||
ck_assert(rng != nullptr);
|
||||
|
||||
uint32_t i;
|
||||
|
||||
uint8_t n[CRYPTO_NONCE_SIZE];
|
||||
|
||||
for (i = 0; i < CRYPTO_NONCE_SIZE; ++i) {
|
||||
for (uint32_t i = 0; i < CRYPTO_NONCE_SIZE; ++i) {
|
||||
n[i] = random_u08(rng);
|
||||
}
|
||||
|
||||
@ -311,13 +305,13 @@ static void test_increment_nonce(void)
|
||||
|
||||
memcpy(n1, n, CRYPTO_NONCE_SIZE);
|
||||
|
||||
for (i = 0; i < (1 << 18); ++i) {
|
||||
for (uint32_t i = 0; i < (1 << 18); ++i) {
|
||||
increment_nonce_number_cmp(n, 1);
|
||||
increment_nonce(n1);
|
||||
ck_assert_msg(memcmp(n, n1, CRYPTO_NONCE_SIZE) == 0, "Bad increment_nonce function");
|
||||
}
|
||||
|
||||
for (i = 0; i < (1 << 18); ++i) {
|
||||
for (uint32_t i = 0; i < (1 << 18); ++i) {
|
||||
const uint32_t r = random_u32(rng);
|
||||
increment_nonce_number_cmp(n, r);
|
||||
increment_nonce_number(n1, r);
|
||||
@ -331,9 +325,8 @@ static void test_memzero(void)
|
||||
memcpy(src, test_c, sizeof(test_c));
|
||||
|
||||
crypto_memzero(src, sizeof(src));
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < sizeof(src); i++) {
|
||||
for (size_t i = 0; i < sizeof(src); i++) {
|
||||
ck_assert_msg(src[i] == 0, "Memory is not zeroed");
|
||||
}
|
||||
}
|
||||
|
@ -172,12 +172,12 @@ static void file_transfer_test(void)
|
||||
uint32_t test = tox_friend_add(tox3, address, (const uint8_t *)"Gentoo", 7, nullptr);
|
||||
ck_assert_msg(test == 0, "Failed to add friend error code: %u", test);
|
||||
|
||||
uint8_t dhtKey[TOX_PUBLIC_KEY_SIZE];
|
||||
tox_self_get_dht_id(tox1, dhtKey);
|
||||
uint16_t dhtPort = tox_self_get_udp_port(tox1, nullptr);
|
||||
uint8_t dht_key[TOX_PUBLIC_KEY_SIZE];
|
||||
tox_self_get_dht_id(tox1, dht_key);
|
||||
uint16_t dht_port = tox_self_get_udp_port(tox1, nullptr);
|
||||
|
||||
tox_bootstrap(tox2, TOX_LOCALHOST, dhtPort, dhtKey, nullptr);
|
||||
tox_bootstrap(tox3, TOX_LOCALHOST, dhtPort, dhtKey, nullptr);
|
||||
tox_bootstrap(tox2, TOX_LOCALHOST, dht_port, dht_key, nullptr);
|
||||
tox_bootstrap(tox3, TOX_LOCALHOST, dht_port, dht_key, nullptr);
|
||||
|
||||
printf("Waiting for toxes to come online\n");
|
||||
|
||||
|
@ -102,56 +102,58 @@ typedef struct Forwarding_Subtox {
|
||||
Announcements *announce;
|
||||
} Forwarding_Subtox;
|
||||
|
||||
static Forwarding_Subtox *new_forwarding_subtox(bool no_udp, uint32_t *index, uint16_t port)
|
||||
static Forwarding_Subtox *new_forwarding_subtox(const Memory *mem, bool no_udp, uint32_t *index, uint16_t port)
|
||||
{
|
||||
const Random *rng = system_random();
|
||||
ck_assert(rng != nullptr);
|
||||
const Network *ns = system_network();
|
||||
ck_assert(ns != nullptr);
|
||||
|
||||
Forwarding_Subtox *subtox = (Forwarding_Subtox *)calloc(1, sizeof(Forwarding_Subtox));
|
||||
ck_assert(subtox != nullptr);
|
||||
|
||||
subtox->log = logger_new();
|
||||
ck_assert(subtox->log != nullptr);
|
||||
logger_callback_log(subtox->log, print_debug_logger, nullptr, index);
|
||||
subtox->mono_time = mono_time_new(nullptr, nullptr);
|
||||
|
||||
const Random *rng= system_random();
|
||||
ck_assert(rng != nullptr);
|
||||
const Network *ns = system_network();
|
||||
ck_assert(ns != nullptr);
|
||||
subtox->mono_time = mono_time_new(mem, nullptr, nullptr);
|
||||
|
||||
if (no_udp) {
|
||||
subtox->net = new_networking_no_udp(subtox->log, ns);
|
||||
subtox->net = new_networking_no_udp(subtox->log, mem, ns);
|
||||
} else {
|
||||
const IP ip = get_loopback();
|
||||
subtox->net = new_networking_ex(subtox->log, ns, &ip, port, port, nullptr);
|
||||
subtox->net = new_networking_ex(subtox->log, mem, ns, &ip, port, port, nullptr);
|
||||
}
|
||||
|
||||
subtox->dht = new_dht(subtox->log, rng, ns, subtox->mono_time, subtox->net, true, true);
|
||||
subtox->dht = new_dht(subtox->log, mem, rng, ns, subtox->mono_time, subtox->net, true, true);
|
||||
|
||||
const TCP_Proxy_Info inf = {{{{0}}}};
|
||||
subtox->c = new_net_crypto(subtox->log, rng, ns, subtox->mono_time, subtox->dht, &inf);
|
||||
subtox->c = new_net_crypto(subtox->log, mem, rng, ns, subtox->mono_time, subtox->dht, &inf);
|
||||
|
||||
subtox->forwarding = new_forwarding(subtox->log, rng, subtox->mono_time, subtox->dht);
|
||||
ck_assert(subtox->forwarding != nullptr);
|
||||
|
||||
subtox->announce = new_announcements(subtox->log, rng, subtox->mono_time, subtox->forwarding);
|
||||
subtox->announce = new_announcements(subtox->log, mem, rng, subtox->mono_time, subtox->forwarding);
|
||||
ck_assert(subtox->announce != nullptr);
|
||||
|
||||
return subtox;
|
||||
}
|
||||
|
||||
static void kill_forwarding_subtox(Forwarding_Subtox *subtox)
|
||||
static void kill_forwarding_subtox(const Memory *mem, Forwarding_Subtox *subtox)
|
||||
{
|
||||
kill_announcements(subtox->announce);
|
||||
kill_forwarding(subtox->forwarding);
|
||||
kill_net_crypto(subtox->c);
|
||||
kill_dht(subtox->dht);
|
||||
kill_networking(subtox->net);
|
||||
mono_time_free(subtox->mono_time);
|
||||
mono_time_free(mem, subtox->mono_time);
|
||||
logger_kill(subtox->log);
|
||||
free(subtox);
|
||||
}
|
||||
|
||||
static void test_forwarding(void)
|
||||
{
|
||||
const Memory *mem = system_memory();
|
||||
ck_assert(mem != nullptr);
|
||||
const Random *rng = system_random();
|
||||
ck_assert(rng != nullptr);
|
||||
const Network *ns = system_network();
|
||||
@ -165,7 +167,7 @@ static void test_forwarding(void)
|
||||
|
||||
for (uint32_t i = 0; i < NUM_FORWARDER; ++i) {
|
||||
index[i] = i + 1;
|
||||
subtoxes[i] = new_forwarding_subtox(i < NUM_FORWARDER_TCP, &index[i], FORWARDING_BASE_PORT + i);
|
||||
subtoxes[i] = new_forwarding_subtox(mem, i < NUM_FORWARDER_TCP, &index[i], FORWARDING_BASE_PORT + i);
|
||||
|
||||
test_data[i].net = subtoxes[i]->net;
|
||||
test_data[i].send_back = 0;
|
||||
@ -317,7 +319,7 @@ static void test_forwarding(void)
|
||||
|
||||
|
||||
for (uint32_t i = 0; i < NUM_FORWARDER; ++i) {
|
||||
kill_forwarding_subtox(subtoxes[i]);
|
||||
kill_forwarding_subtox(mem, subtoxes[i]);
|
||||
}
|
||||
|
||||
tox_kill(relay);
|
||||
|
@ -215,29 +215,32 @@ static void send_onion_packet(const Networking_Core *net, const Random *rng, con
|
||||
/** Initialize networking.
|
||||
* Added for reverse compatibility with old new_networking calls.
|
||||
*/
|
||||
static Networking_Core *new_networking(const Logger *log, const Network *ns, const IP *ip, uint16_t port)
|
||||
static Networking_Core *new_networking(const Logger *log, const Memory *mem, const Network *ns, const IP *ip, uint16_t port)
|
||||
{
|
||||
return new_networking_ex(log, ns, ip, port, port + (TOX_PORTRANGE_TO - TOX_PORTRANGE_FROM), nullptr);
|
||||
return new_networking_ex(log, mem, ns, ip, port, port + (TOX_PORTRANGE_TO - TOX_PORTRANGE_FROM), nullptr);
|
||||
}
|
||||
|
||||
static void test_basic(void)
|
||||
{
|
||||
uint32_t index[] = { 1, 2, 3 };
|
||||
const Network *ns = system_network();
|
||||
ck_assert(ns != nullptr);
|
||||
const Memory *mem = system_memory();
|
||||
ck_assert(mem != nullptr);
|
||||
const Random *rng = system_random();
|
||||
ck_assert(rng != nullptr);
|
||||
|
||||
Logger *log1 = logger_new();
|
||||
logger_callback_log(log1, print_debug_logger, nullptr, &index[0]);
|
||||
Logger *log2 = logger_new();
|
||||
logger_callback_log(log2, print_debug_logger, nullptr, &index[1]);
|
||||
|
||||
const Random *rng = system_random();
|
||||
ck_assert(rng != nullptr);
|
||||
Mono_Time *mono_time1 = mono_time_new(nullptr, nullptr);
|
||||
Mono_Time *mono_time2 = mono_time_new(nullptr, nullptr);
|
||||
Mono_Time *mono_time1 = mono_time_new(mem, nullptr, nullptr);
|
||||
Mono_Time *mono_time2 = mono_time_new(mem, nullptr, nullptr);
|
||||
|
||||
IP ip = get_loopback();
|
||||
Onion *onion1 = new_onion(log1, mono_time1, rng, new_dht(log1, rng, ns, mono_time1, new_networking(log1, ns, &ip, 36567), true, false));
|
||||
Onion *onion2 = new_onion(log2, mono_time2, rng, new_dht(log2, rng, ns, mono_time2, new_networking(log2, ns, &ip, 36568), true, false));
|
||||
Onion *onion1 = new_onion(log1, mem, mono_time1, rng, new_dht(log1, mem, rng, ns, mono_time1, new_networking(log1, mem, ns, &ip, 36567), true, false));
|
||||
Onion *onion2 = new_onion(log2, mem, mono_time2, rng, new_dht(log2, mem, rng, ns, mono_time2, new_networking(log2, mem, ns, &ip, 36568), true, false));
|
||||
ck_assert_msg((onion1 != nullptr) && (onion2 != nullptr), "Onion failed initializing.");
|
||||
networking_registerhandler(onion2->net, NET_PACKET_ANNOUNCE_REQUEST, &handle_test_1, onion2);
|
||||
|
||||
@ -280,8 +283,8 @@ static void test_basic(void)
|
||||
do_onion(mono_time2, onion2);
|
||||
} while (handled_test_2 == 0);
|
||||
|
||||
Onion_Announce *onion1_a = new_onion_announce(log1, rng, mono_time1, onion1->dht);
|
||||
Onion_Announce *onion2_a = new_onion_announce(log2, rng, mono_time2, onion2->dht);
|
||||
Onion_Announce *onion1_a = new_onion_announce(log1, mem, rng, mono_time1, onion1->dht);
|
||||
Onion_Announce *onion2_a = new_onion_announce(log2, mem, rng, mono_time2, onion2->dht);
|
||||
networking_registerhandler(onion1->net, NET_PACKET_ANNOUNCE_RESPONSE, &handle_test_3, onion1);
|
||||
networking_registerhandler(onion1->net, NET_PACKET_ANNOUNCE_RESPONSE_OLD, &handle_test_3_old, onion1);
|
||||
ck_assert_msg((onion1_a != nullptr) && (onion2_a != nullptr), "Onion_Announce failed initializing.");
|
||||
@ -331,9 +334,9 @@ static void test_basic(void)
|
||||
Logger *log3 = logger_new();
|
||||
logger_callback_log(log3, print_debug_logger, nullptr, &index[2]);
|
||||
|
||||
Mono_Time *mono_time3 = mono_time_new(nullptr, nullptr);
|
||||
Mono_Time *mono_time3 = mono_time_new(mem, nullptr, nullptr);
|
||||
|
||||
Onion *onion3 = new_onion(log3, mono_time3, rng, new_dht(log3, rng, ns, mono_time3, new_networking(log3, ns, &ip, 36569), true, false));
|
||||
Onion *onion3 = new_onion(log3, mem, mono_time3, rng, new_dht(log3, mem, rng, ns, mono_time3, new_networking(log3, mem, ns, &ip, 36569), true, false));
|
||||
ck_assert_msg((onion3 != nullptr), "Onion failed initializing.");
|
||||
|
||||
random_nonce(rng, nonce);
|
||||
@ -363,7 +366,7 @@ static void test_basic(void)
|
||||
kill_onion(onion);
|
||||
kill_dht(dht);
|
||||
kill_networking(net);
|
||||
mono_time_free(mono_time3);
|
||||
mono_time_free(mem, mono_time3);
|
||||
logger_kill(log3);
|
||||
}
|
||||
|
||||
@ -375,7 +378,7 @@ static void test_basic(void)
|
||||
kill_onion(onion);
|
||||
kill_dht(dht);
|
||||
kill_networking(net);
|
||||
mono_time_free(mono_time2);
|
||||
mono_time_free(mem, mono_time2);
|
||||
logger_kill(log2);
|
||||
}
|
||||
|
||||
@ -387,7 +390,7 @@ static void test_basic(void)
|
||||
kill_onion(onion);
|
||||
kill_dht(dht);
|
||||
kill_networking(net);
|
||||
mono_time_free(mono_time1);
|
||||
mono_time_free(mem, mono_time1);
|
||||
logger_kill(log1);
|
||||
}
|
||||
}
|
||||
@ -400,7 +403,7 @@ typedef struct {
|
||||
Onion_Client *onion_c;
|
||||
} Onions;
|
||||
|
||||
static Onions *new_onions(const Random *rng, uint16_t port, uint32_t *index)
|
||||
static Onions *new_onions(const Memory *mem, const Random *rng, uint16_t port, uint32_t *index)
|
||||
{
|
||||
IP ip = get_loopback();
|
||||
ip.ip.v6.uint8[15] = 1;
|
||||
@ -420,7 +423,7 @@ static Onions *new_onions(const Random *rng, uint16_t port, uint32_t *index)
|
||||
|
||||
logger_callback_log(on->log, print_debug_logger, nullptr, index);
|
||||
|
||||
on->mono_time = mono_time_new(nullptr, nullptr);
|
||||
on->mono_time = mono_time_new(mem, nullptr, nullptr);
|
||||
|
||||
if (!on->mono_time) {
|
||||
logger_kill(on->log);
|
||||
@ -428,57 +431,57 @@ static Onions *new_onions(const Random *rng, uint16_t port, uint32_t *index)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Networking_Core *net = new_networking(on->log, ns, &ip, port);
|
||||
Networking_Core *net = new_networking(on->log, mem, ns, &ip, port);
|
||||
|
||||
if (!net) {
|
||||
mono_time_free(on->mono_time);
|
||||
mono_time_free(mem, on->mono_time);
|
||||
logger_kill(on->log);
|
||||
free(on);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
DHT *dht = new_dht(on->log, rng, ns, on->mono_time, net, true, false);
|
||||
DHT *dht = new_dht(on->log, mem, rng, ns, on->mono_time, net, true, false);
|
||||
|
||||
if (!dht) {
|
||||
kill_networking(net);
|
||||
mono_time_free(on->mono_time);
|
||||
mono_time_free(mem, on->mono_time);
|
||||
logger_kill(on->log);
|
||||
free(on);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
on->onion = new_onion(on->log, on->mono_time, rng, dht);
|
||||
on->onion = new_onion(on->log, mem, on->mono_time, rng, dht);
|
||||
|
||||
if (!on->onion) {
|
||||
kill_dht(dht);
|
||||
kill_networking(net);
|
||||
mono_time_free(on->mono_time);
|
||||
mono_time_free(mem, on->mono_time);
|
||||
logger_kill(on->log);
|
||||
free(on);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
on->onion_a = new_onion_announce(on->log, rng, on->mono_time, dht);
|
||||
on->onion_a = new_onion_announce(on->log, mem, rng, on->mono_time, dht);
|
||||
|
||||
if (!on->onion_a) {
|
||||
kill_onion(on->onion);
|
||||
kill_dht(dht);
|
||||
kill_networking(net);
|
||||
mono_time_free(on->mono_time);
|
||||
mono_time_free(mem, on->mono_time);
|
||||
logger_kill(on->log);
|
||||
free(on);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
TCP_Proxy_Info inf = {{{{0}}}};
|
||||
on->onion_c = new_onion_client(on->log, rng, on->mono_time, new_net_crypto(on->log, rng, ns, on->mono_time, dht, &inf));
|
||||
on->onion_c = new_onion_client(on->log, mem, rng, on->mono_time, new_net_crypto(on->log, mem, rng, ns, on->mono_time, dht, &inf));
|
||||
|
||||
if (!on->onion_c) {
|
||||
kill_onion_announce(on->onion_a);
|
||||
kill_onion(on->onion);
|
||||
kill_dht(dht);
|
||||
kill_networking(net);
|
||||
mono_time_free(on->mono_time);
|
||||
mono_time_free(mem, on->mono_time);
|
||||
logger_kill(on->log);
|
||||
free(on);
|
||||
return nullptr;
|
||||
@ -496,7 +499,7 @@ static void do_onions(Onions *on)
|
||||
do_onion_client(on->onion_c);
|
||||
}
|
||||
|
||||
static void kill_onions(Onions *on)
|
||||
static void kill_onions(const Memory *mem, Onions *on)
|
||||
{
|
||||
Networking_Core *net = dht_get_net(on->onion->dht);
|
||||
DHT *dht = on->onion->dht;
|
||||
@ -507,7 +510,7 @@ static void kill_onions(Onions *on)
|
||||
kill_net_crypto(c);
|
||||
kill_dht(dht);
|
||||
kill_networking(net);
|
||||
mono_time_free(on->mono_time);
|
||||
mono_time_free(mem, on->mono_time);
|
||||
logger_kill(on->log);
|
||||
free(on);
|
||||
}
|
||||
@ -571,21 +574,22 @@ static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_pub
|
||||
|
||||
static void test_announce(void)
|
||||
{
|
||||
uint32_t i, j;
|
||||
uint32_t index[NUM_ONIONS];
|
||||
Onions *onions[NUM_ONIONS];
|
||||
const Random *rng = system_random();
|
||||
ck_assert(rng != nullptr);
|
||||
const Memory *mem = system_memory();
|
||||
ck_assert(mem != nullptr);
|
||||
|
||||
for (i = 0; i < NUM_ONIONS; ++i) {
|
||||
for (uint32_t i = 0; i < NUM_ONIONS; ++i) {
|
||||
index[i] = i + 1;
|
||||
onions[i] = new_onions(rng, i + 36655, &index[i]);
|
||||
onions[i] = new_onions(mem, rng, i + 36655, &index[i]);
|
||||
ck_assert_msg(onions[i] != nullptr, "Failed to create onions. %u", i);
|
||||
}
|
||||
|
||||
IP ip = get_loopback();
|
||||
|
||||
for (i = 3; i < NUM_ONIONS; ++i) {
|
||||
for (uint32_t i = 3; i < NUM_ONIONS; ++i) {
|
||||
IP_Port ip_port = {ip, net_port(onions[i - 1]->onion->net)};
|
||||
dht_bootstrap(onions[i]->onion->dht, &ip_port, dht_get_self_public_key(onions[i - 1]->onion->dht));
|
||||
IP_Port ip_port1 = {ip, net_port(onions[i - 2]->onion->net)};
|
||||
@ -599,7 +603,7 @@ static void test_announce(void)
|
||||
do {
|
||||
connected = 0;
|
||||
|
||||
for (i = 0; i < NUM_ONIONS; ++i) {
|
||||
for (uint32_t i = 0; i < NUM_ONIONS; ++i) {
|
||||
do_onions(onions[i]);
|
||||
connected += dht_isconnected(onions[i]->onion->dht);
|
||||
}
|
||||
@ -609,8 +613,8 @@ static void test_announce(void)
|
||||
|
||||
printf("connected\n");
|
||||
|
||||
for (i = 0; i < 25 * 2; ++i) {
|
||||
for (j = 0; j < NUM_ONIONS; ++j) {
|
||||
for (uint32_t i = 0; i < 25 * 2; ++i) {
|
||||
for (uint32_t j = 0; j < NUM_ONIONS; ++j) {
|
||||
do_onions(onions[j]);
|
||||
}
|
||||
|
||||
@ -632,7 +636,7 @@ static void test_announce(void)
|
||||
IP_Port ip_port;
|
||||
|
||||
do {
|
||||
for (i = 0; i < NUM_ONIONS; ++i) {
|
||||
for (uint32_t i = 0; i < NUM_ONIONS; ++i) {
|
||||
do_onions(onions[i]);
|
||||
}
|
||||
|
||||
@ -642,7 +646,7 @@ static void test_announce(void)
|
||||
printf("Waiting for ips\n");
|
||||
|
||||
do {
|
||||
for (i = 0; i < NUM_ONIONS; ++i) {
|
||||
for (uint32_t i = 0; i < NUM_ONIONS; ++i) {
|
||||
do_onions(onions[i]);
|
||||
}
|
||||
|
||||
@ -652,8 +656,8 @@ static void test_announce(void)
|
||||
onion_getfriendip(onions[NUM_LAST]->onion_c, frnum, &ip_port);
|
||||
ck_assert_msg(ip_port.port == net_port(onions[NUM_FIRST]->onion->net), "Port in returned ip not correct.");
|
||||
|
||||
for (i = 0; i < NUM_ONIONS; ++i) {
|
||||
kill_onions(onions[i]);
|
||||
for (uint32_t i = 0; i < NUM_ONIONS; ++i) {
|
||||
kill_onions(mem, onions[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ static void dump_events(const char *path, const Tox_Events *events)
|
||||
}
|
||||
}
|
||||
|
||||
static void print_events(Tox_Events *events)
|
||||
static void print_events(const Tox_System *sys, Tox_Events *events)
|
||||
{
|
||||
const uint32_t size = tox_events_bytes_size(events);
|
||||
|
||||
@ -52,11 +52,11 @@ static void print_events(Tox_Events *events)
|
||||
|
||||
tox_events_get_bytes(events, bytes);
|
||||
|
||||
Tox_Events *events_copy = tox_events_load(bytes, size);
|
||||
Tox_Events *events_copy = tox_events_load(sys, bytes, size);
|
||||
ck_assert(events_copy != nullptr);
|
||||
free(bytes);
|
||||
|
||||
ck_assert(tox_events_equal(events, events_copy));
|
||||
ck_assert(tox_events_equal(sys, events, events_copy));
|
||||
|
||||
tox_events_free(events_copy);
|
||||
tox_events_free(events);
|
||||
@ -64,9 +64,11 @@ static void print_events(Tox_Events *events)
|
||||
|
||||
static bool await_message(Tox **toxes, const Tox_Dispatch *dispatch)
|
||||
{
|
||||
const Tox_System *sys = tox_get_system(toxes[0]);
|
||||
|
||||
for (uint32_t i = 0; i < 100; ++i) {
|
||||
// Ignore events on tox 1.
|
||||
print_events(tox_events_iterate(toxes[0], false, nullptr));
|
||||
print_events(sys, tox_events_iterate(toxes[0], false, nullptr));
|
||||
// Check if tox 2 got the message from tox 1.
|
||||
Tox_Events *events = tox_events_iterate(toxes[1], false, nullptr);
|
||||
|
||||
@ -74,7 +76,7 @@ static bool await_message(Tox **toxes, const Tox_Dispatch *dispatch)
|
||||
|
||||
bool success = false;
|
||||
tox_dispatch_invoke(dispatch, events, toxes[1], &success);
|
||||
print_events(events);
|
||||
print_events(sys, events);
|
||||
|
||||
if (success) {
|
||||
return true;
|
||||
@ -101,6 +103,8 @@ static void test_tox_events(void)
|
||||
ck_assert_msg(toxes[i] != nullptr, "failed to create tox instances %u", i);
|
||||
}
|
||||
|
||||
const Tox_System *sys = tox_get_system(toxes[0]);
|
||||
|
||||
Tox_Err_Dispatch_New err_new;
|
||||
Tox_Dispatch *dispatch = tox_dispatch_new(&err_new);
|
||||
ck_assert_msg(dispatch != nullptr, "failed to create event dispatcher");
|
||||
@ -123,8 +127,8 @@ static void test_tox_events(void)
|
||||
while (tox_self_get_connection_status(toxes[0]) == TOX_CONNECTION_NONE ||
|
||||
tox_self_get_connection_status(toxes[1]) == TOX_CONNECTION_NONE) {
|
||||
// Ignore connection events for now.
|
||||
print_events(tox_events_iterate(toxes[0], false, nullptr));
|
||||
print_events(tox_events_iterate(toxes[1], false, nullptr));
|
||||
print_events(sys, tox_events_iterate(toxes[0], false, nullptr));
|
||||
print_events(sys, tox_events_iterate(toxes[1], false, nullptr));
|
||||
|
||||
c_sleep(tox_iteration_interval(toxes[0]));
|
||||
}
|
||||
@ -134,8 +138,8 @@ static void test_tox_events(void)
|
||||
while (tox_friend_get_connection_status(toxes[0], 0, nullptr) == TOX_CONNECTION_NONE ||
|
||||
tox_friend_get_connection_status(toxes[1], 0, nullptr) == TOX_CONNECTION_NONE) {
|
||||
// Ignore connection events for now.
|
||||
print_events(tox_events_iterate(toxes[0], false, nullptr));
|
||||
print_events(tox_events_iterate(toxes[1], false, nullptr));
|
||||
print_events(sys, tox_events_iterate(toxes[0], false, nullptr));
|
||||
print_events(sys, tox_events_iterate(toxes[1], false, nullptr));
|
||||
|
||||
c_sleep(tox_iteration_interval(toxes[0]));
|
||||
}
|
||||
|
@ -46,10 +46,9 @@ static void test_many_clients_tcp(void)
|
||||
long long unsigned int cur_time = time(nullptr);
|
||||
Tox *toxes[NUM_TOXES_TCP];
|
||||
uint32_t index[NUM_TOXES_TCP];
|
||||
uint32_t i, j;
|
||||
uint32_t to_comp = 974536;
|
||||
|
||||
for (i = 0; i < NUM_TOXES_TCP; ++i) {
|
||||
for (uint32_t i = 0; i < NUM_TOXES_TCP; ++i) {
|
||||
struct Tox_Options *opts = tox_options_new(nullptr);
|
||||
|
||||
if (i == 0) {
|
||||
@ -72,7 +71,7 @@ static void test_many_clients_tcp(void)
|
||||
tox_callback_friend_request(toxes[i], accept_friend_request);
|
||||
uint8_t dpk[TOX_PUBLIC_KEY_SIZE];
|
||||
tox_self_get_dht_id(toxes[0], dpk);
|
||||
Tox_Err_Bootstrap error = TOX_ERR_BOOTSTRAP_OK;
|
||||
Tox_Err_Bootstrap error;
|
||||
ck_assert_msg(tox_add_tcp_relay(toxes[i], TOX_LOCALHOST, tcp_relay_port, dpk, &error), "add relay error, %u, %d", i,
|
||||
error);
|
||||
uint16_t first_port = tox_self_get_udp_port(toxes[0], nullptr);
|
||||
@ -88,12 +87,12 @@ static void test_many_clients_tcp(void)
|
||||
|
||||
uint8_t address[TOX_ADDRESS_SIZE];
|
||||
|
||||
for (i = 0; i < NUM_FRIENDS; ++i) {
|
||||
for (uint32_t i = 0; i < NUM_FRIENDS; ++i) {
|
||||
loop_top:
|
||||
pairs[i].tox1 = random_u32(rng) % NUM_TOXES_TCP;
|
||||
pairs[i].tox2 = (pairs[i].tox1 + random_u32(rng) % (NUM_TOXES_TCP - 1) + 1) % NUM_TOXES_TCP;
|
||||
|
||||
for (j = 0; j < i; ++j) {
|
||||
for (uint32_t j = 0; j < i; ++j) {
|
||||
if (pairs[j].tox2 == pairs[i].tox1 && pairs[j].tox1 == pairs[i].tox2) {
|
||||
goto loop_top;
|
||||
}
|
||||
@ -114,8 +113,8 @@ loop_top:
|
||||
while (true) {
|
||||
uint16_t counter = 0;
|
||||
|
||||
for (i = 0; i < NUM_TOXES_TCP; ++i) {
|
||||
for (j = 0; j < tox_self_get_friend_list_size(toxes[i]); ++j) {
|
||||
for (uint32_t i = 0; i < NUM_TOXES_TCP; ++i) {
|
||||
for (uint32_t j = 0; j < tox_self_get_friend_list_size(toxes[i]); ++j) {
|
||||
if (tox_friend_get_connection_status(toxes[i], j, nullptr) == TOX_CONNECTION_TCP) {
|
||||
++counter;
|
||||
}
|
||||
@ -126,14 +125,14 @@ loop_top:
|
||||
break;
|
||||
}
|
||||
|
||||
for (i = 0; i < NUM_TOXES_TCP; ++i) {
|
||||
for (uint32_t i = 0; i < NUM_TOXES_TCP; ++i) {
|
||||
tox_iterate(toxes[i], &to_comp);
|
||||
}
|
||||
|
||||
c_sleep(50);
|
||||
}
|
||||
|
||||
for (i = 0; i < NUM_TOXES_TCP; ++i) {
|
||||
for (uint32_t i = 0; i < NUM_TOXES_TCP; ++i) {
|
||||
tox_kill(toxes[i]);
|
||||
}
|
||||
|
||||
@ -149,10 +148,9 @@ static void test_many_clients_tcp_b(void)
|
||||
long long unsigned int cur_time = time(nullptr);
|
||||
Tox *toxes[NUM_TOXES_TCP];
|
||||
uint32_t index[NUM_TOXES_TCP];
|
||||
uint32_t i, j;
|
||||
uint32_t to_comp = 974536;
|
||||
|
||||
for (i = 0; i < NUM_TOXES_TCP; ++i) {
|
||||
for (uint32_t i = 0; i < NUM_TOXES_TCP; ++i) {
|
||||
struct Tox_Options *opts = tox_options_new(nullptr);
|
||||
|
||||
if (i < NUM_TCP_RELAYS) {
|
||||
@ -183,12 +181,12 @@ static void test_many_clients_tcp_b(void)
|
||||
|
||||
uint8_t address[TOX_ADDRESS_SIZE];
|
||||
|
||||
for (i = 0; i < NUM_FRIENDS; ++i) {
|
||||
for (uint32_t i = 0; i < NUM_FRIENDS; ++i) {
|
||||
loop_top:
|
||||
pairs[i].tox1 = random_u32(rng) % NUM_TOXES_TCP;
|
||||
pairs[i].tox2 = (pairs[i].tox1 + random_u32(rng) % (NUM_TOXES_TCP - 1) + 1) % NUM_TOXES_TCP;
|
||||
|
||||
for (j = 0; j < i; ++j) {
|
||||
for (uint32_t j = 0; j < i; ++j) {
|
||||
if (pairs[j].tox2 == pairs[i].tox1 && pairs[j].tox1 == pairs[i].tox2) {
|
||||
goto loop_top;
|
||||
}
|
||||
@ -211,8 +209,8 @@ loop_top:
|
||||
while (true) {
|
||||
uint16_t counter = 0;
|
||||
|
||||
for (i = 0; i < NUM_TOXES_TCP; ++i) {
|
||||
for (j = 0; j < tox_self_get_friend_list_size(toxes[i]); ++j) {
|
||||
for (uint32_t i = 0; i < NUM_TOXES_TCP; ++i) {
|
||||
for (uint32_t j = 0; j < tox_self_get_friend_list_size(toxes[i]); ++j) {
|
||||
if (tox_friend_get_connection_status(toxes[i], j, nullptr) == TOX_CONNECTION_TCP) {
|
||||
++counter;
|
||||
}
|
||||
@ -228,14 +226,14 @@ loop_top:
|
||||
break;
|
||||
}
|
||||
|
||||
for (i = 0; i < NUM_TOXES_TCP; ++i) {
|
||||
for (uint32_t i = 0; i < NUM_TOXES_TCP; ++i) {
|
||||
tox_iterate(toxes[i], &to_comp);
|
||||
}
|
||||
|
||||
c_sleep(30);
|
||||
}
|
||||
|
||||
for (i = 0; i < NUM_TOXES_TCP; ++i) {
|
||||
for (uint32_t i = 0; i < NUM_TOXES_TCP; ++i) {
|
||||
tox_kill(toxes[i]);
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ typedef enum {
|
||||
POSITIVE
|
||||
} Comparison;
|
||||
|
||||
static const char *Comparison_Str[] = { "NEGATIVE", "ZERO", "POSITIVE" };
|
||||
static const char *comparison_str[] = { "NEGATIVE", "ZERO", "POSITIVE" };
|
||||
|
||||
static void verify(const char *s1, const char *s2, size_t n, Comparison expected)
|
||||
{
|
||||
@ -19,7 +19,7 @@ static void verify(const char *s1, const char *s2, size_t n, Comparison expected
|
||||
|
||||
ck_assert_msg(actual == expected,
|
||||
"tox_strncasecmp(\"%s\", \"%s\", %u) == %s, but expected %s.",
|
||||
s1, s2, (unsigned)n, Comparison_Str[actual], Comparison_Str[expected]);
|
||||
s1, s2, (unsigned)n, comparison_str[actual], comparison_str[expected]);
|
||||
}
|
||||
|
||||
static void test_general(void)
|
||||
|
@ -93,67 +93,67 @@ static void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const
|
||||
/**
|
||||
* Iterate helper
|
||||
*/
|
||||
static void iterate_tox(Tox *bootstrap, Tox *Alice, Tox *Bob)
|
||||
static void iterate_tox(Tox *bootstrap, Tox *alice, Tox *bob)
|
||||
{
|
||||
c_sleep(100);
|
||||
tox_iterate(bootstrap, nullptr);
|
||||
tox_iterate(Alice, nullptr);
|
||||
tox_iterate(Bob, nullptr);
|
||||
tox_iterate(alice, nullptr);
|
||||
tox_iterate(bob, nullptr);
|
||||
}
|
||||
|
||||
static bool toxav_audio_send_frame_helper(ToxAV *av, uint32_t friend_number, Toxav_Err_Send_Frame *error)
|
||||
{
|
||||
static const int16_t PCM[960] = {0};
|
||||
return toxav_audio_send_frame(av, 0, PCM, 960, 1, 48000, nullptr);
|
||||
static const int16_t pcm[960] = {0};
|
||||
return toxav_audio_send_frame(av, 0, pcm, 960, 1, 48000, nullptr);
|
||||
}
|
||||
|
||||
static void regular_call_flow(
|
||||
Tox *Alice, Tox *Bob, Tox *bootstrap,
|
||||
ToxAV *AliceAV, ToxAV *BobAV,
|
||||
CallControl *AliceCC, CallControl *BobCC,
|
||||
Tox *alice, Tox *bob, Tox *bootstrap,
|
||||
ToxAV *alice_av, ToxAV *bob_av,
|
||||
CallControl *alice_cc, CallControl *bob_cc,
|
||||
int a_br, int v_br)
|
||||
{
|
||||
clear_call_control(AliceCC);
|
||||
clear_call_control(BobCC);
|
||||
clear_call_control(alice_cc);
|
||||
clear_call_control(bob_cc);
|
||||
|
||||
Toxav_Err_Call call_err;
|
||||
toxav_call(AliceAV, 0, a_br, v_br, &call_err);
|
||||
toxav_call(alice_av, 0, a_br, v_br, &call_err);
|
||||
|
||||
ck_assert_msg(call_err == TOXAV_ERR_CALL_OK, "toxav_call failed: %d\n", call_err);
|
||||
|
||||
const time_t start_time = time(nullptr);
|
||||
|
||||
do {
|
||||
if (BobCC->incoming) {
|
||||
if (bob_cc->incoming) {
|
||||
Toxav_Err_Answer answer_err;
|
||||
toxav_answer(BobAV, 0, a_br, v_br, &answer_err);
|
||||
toxav_answer(bob_av, 0, a_br, v_br, &answer_err);
|
||||
|
||||
ck_assert_msg(answer_err == TOXAV_ERR_ANSWER_OK, "toxav_answer failed: %d\n", answer_err);
|
||||
|
||||
BobCC->incoming = false;
|
||||
bob_cc->incoming = false;
|
||||
} else { /* TODO(mannol): rtp */
|
||||
if (time(nullptr) - start_time >= 1) {
|
||||
|
||||
Toxav_Err_Call_Control cc_err;
|
||||
toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_CANCEL, &cc_err);
|
||||
toxav_call_control(alice_av, 0, TOXAV_CALL_CONTROL_CANCEL, &cc_err);
|
||||
|
||||
ck_assert_msg(cc_err == TOXAV_ERR_CALL_CONTROL_OK, "toxav_call_control failed: %d\n", cc_err);
|
||||
}
|
||||
}
|
||||
|
||||
iterate_tox(bootstrap, Alice, Bob);
|
||||
} while (BobCC->state != TOXAV_FRIEND_CALL_STATE_FINISHED);
|
||||
iterate_tox(bootstrap, alice, bob);
|
||||
} while (bob_cc->state != TOXAV_FRIEND_CALL_STATE_FINISHED);
|
||||
|
||||
printf("Success!\n");
|
||||
}
|
||||
|
||||
static void test_av_flows(void)
|
||||
{
|
||||
Tox *Alice, *Bob, *bootstrap;
|
||||
ToxAV *AliceAV, *BobAV;
|
||||
Tox *alice, *bob, *bootstrap;
|
||||
ToxAV *alice_av, *bob_av;
|
||||
uint32_t index[] = { 1, 2, 3 };
|
||||
|
||||
CallControl AliceCC, BobCC;
|
||||
CallControl alice_cc, bob_cc;
|
||||
|
||||
{
|
||||
Tox_Err_New error;
|
||||
@ -161,10 +161,10 @@ static void test_av_flows(void)
|
||||
bootstrap = tox_new_log(nullptr, &error, &index[0]);
|
||||
ck_assert(error == TOX_ERR_NEW_OK);
|
||||
|
||||
Alice = tox_new_log(nullptr, &error, &index[1]);
|
||||
alice = tox_new_log(nullptr, &error, &index[1]);
|
||||
ck_assert(error == TOX_ERR_NEW_OK);
|
||||
|
||||
Bob = tox_new_log(nullptr, &error, &index[2]);
|
||||
bob = tox_new_log(nullptr, &error, &index[2]);
|
||||
ck_assert(error == TOX_ERR_NEW_OK);
|
||||
}
|
||||
|
||||
@ -174,33 +174,33 @@ static void test_av_flows(void)
|
||||
|
||||
uint8_t address[TOX_ADDRESS_SIZE];
|
||||
|
||||
tox_callback_friend_request(Alice, t_accept_friend_request_cb);
|
||||
tox_self_get_address(Alice, address);
|
||||
tox_callback_friend_request(alice, t_accept_friend_request_cb);
|
||||
tox_self_get_address(alice, address);
|
||||
|
||||
printf("bootstrapping Alice and Bob off a third bootstrap node\n");
|
||||
uint8_t dht_key[TOX_PUBLIC_KEY_SIZE];
|
||||
tox_self_get_dht_id(bootstrap, dht_key);
|
||||
const uint16_t dht_port = tox_self_get_udp_port(bootstrap, nullptr);
|
||||
|
||||
tox_bootstrap(Alice, "localhost", dht_port, dht_key, nullptr);
|
||||
tox_bootstrap(Bob, "localhost", dht_port, dht_key, nullptr);
|
||||
tox_bootstrap(alice, "localhost", dht_port, dht_key, nullptr);
|
||||
tox_bootstrap(bob, "localhost", dht_port, dht_key, nullptr);
|
||||
|
||||
ck_assert(tox_friend_add(Bob, address, (const uint8_t *)"gentoo", 7, nullptr) != (uint32_t) -1);
|
||||
ck_assert(tox_friend_add(bob, address, (const uint8_t *)"gentoo", 7, nullptr) != (uint32_t) -1);
|
||||
|
||||
uint8_t off = 1;
|
||||
|
||||
while (true) {
|
||||
iterate_tox(bootstrap, Alice, Bob);
|
||||
iterate_tox(bootstrap, alice, bob);
|
||||
|
||||
if (tox_self_get_connection_status(bootstrap) &&
|
||||
tox_self_get_connection_status(Alice) &&
|
||||
tox_self_get_connection_status(Bob) && off) {
|
||||
tox_self_get_connection_status(alice) &&
|
||||
tox_self_get_connection_status(bob) && off) {
|
||||
printf("Toxes are online, took %llu seconds\n", time(nullptr) - cur_time);
|
||||
off = 0;
|
||||
}
|
||||
|
||||
if (tox_friend_get_connection_status(Alice, 0, nullptr) == TOX_CONNECTION_UDP &&
|
||||
tox_friend_get_connection_status(Bob, 0, nullptr) == TOX_CONNECTION_UDP) {
|
||||
if (tox_friend_get_connection_status(alice, 0, nullptr) == TOX_CONNECTION_UDP &&
|
||||
tox_friend_get_connection_status(bob, 0, nullptr) == TOX_CONNECTION_UDP) {
|
||||
break;
|
||||
}
|
||||
|
||||
@ -210,72 +210,72 @@ static void test_av_flows(void)
|
||||
|
||||
{
|
||||
Toxav_Err_New error;
|
||||
AliceAV = toxav_new(Alice, &error);
|
||||
alice_av = toxav_new(alice, &error);
|
||||
ck_assert(error == TOXAV_ERR_NEW_OK);
|
||||
|
||||
BobAV = toxav_new(Bob, &error);
|
||||
bob_av = toxav_new(bob, &error);
|
||||
ck_assert(error == TOXAV_ERR_NEW_OK);
|
||||
}
|
||||
|
||||
toxav_callback_call(AliceAV, t_toxav_call_cb, &AliceCC);
|
||||
toxav_callback_call_state(AliceAV, t_toxav_call_state_cb, &AliceCC);
|
||||
toxav_callback_video_receive_frame(AliceAV, t_toxav_receive_video_frame_cb, &AliceCC);
|
||||
toxav_callback_audio_receive_frame(AliceAV, t_toxav_receive_audio_frame_cb, &AliceCC);
|
||||
toxav_callback_call(alice_av, t_toxav_call_cb, &alice_cc);
|
||||
toxav_callback_call_state(alice_av, t_toxav_call_state_cb, &alice_cc);
|
||||
toxav_callback_video_receive_frame(alice_av, t_toxav_receive_video_frame_cb, &alice_cc);
|
||||
toxav_callback_audio_receive_frame(alice_av, t_toxav_receive_audio_frame_cb, &alice_cc);
|
||||
|
||||
toxav_callback_call(BobAV, t_toxav_call_cb, &BobCC);
|
||||
toxav_callback_call_state(BobAV, t_toxav_call_state_cb, &BobCC);
|
||||
toxav_callback_video_receive_frame(BobAV, t_toxav_receive_video_frame_cb, &BobCC);
|
||||
toxav_callback_audio_receive_frame(BobAV, t_toxav_receive_audio_frame_cb, &BobCC);
|
||||
toxav_callback_call(bob_av, t_toxav_call_cb, &bob_cc);
|
||||
toxav_callback_call_state(bob_av, t_toxav_call_state_cb, &bob_cc);
|
||||
toxav_callback_video_receive_frame(bob_av, t_toxav_receive_video_frame_cb, &bob_cc);
|
||||
toxav_callback_audio_receive_frame(bob_av, t_toxav_receive_audio_frame_cb, &bob_cc);
|
||||
|
||||
printf("Created 2 instances of ToxAV\n");
|
||||
printf("All set after %llu seconds!\n", time(nullptr) - cur_time);
|
||||
|
||||
if (TEST_REGULAR_AV) {
|
||||
printf("\nTrying regular call (Audio and Video)...\n");
|
||||
regular_call_flow(Alice, Bob, bootstrap, AliceAV, BobAV, &AliceCC, &BobCC,
|
||||
regular_call_flow(alice, bob, bootstrap, alice_av, bob_av, &alice_cc, &bob_cc,
|
||||
48, 4000);
|
||||
}
|
||||
|
||||
if (TEST_REGULAR_A) {
|
||||
printf("\nTrying regular call (Audio only)...\n");
|
||||
regular_call_flow(Alice, Bob, bootstrap, AliceAV, BobAV, &AliceCC, &BobCC,
|
||||
regular_call_flow(alice, bob, bootstrap, alice_av, bob_av, &alice_cc, &bob_cc,
|
||||
48, 0);
|
||||
}
|
||||
|
||||
if (TEST_REGULAR_V) {
|
||||
printf("\nTrying regular call (Video only)...\n");
|
||||
regular_call_flow(Alice, Bob, bootstrap, AliceAV, BobAV, &AliceCC, &BobCC,
|
||||
regular_call_flow(alice, bob, bootstrap, alice_av, bob_av, &alice_cc, &bob_cc,
|
||||
0, 4000);
|
||||
}
|
||||
|
||||
if (TEST_REJECT) { /* Alice calls; Bob rejects */
|
||||
printf("\nTrying reject flow...\n");
|
||||
|
||||
clear_call_control(&AliceCC);
|
||||
clear_call_control(&BobCC);
|
||||
clear_call_control(&alice_cc);
|
||||
clear_call_control(&bob_cc);
|
||||
|
||||
{
|
||||
Toxav_Err_Call rc;
|
||||
toxav_call(AliceAV, 0, 48, 0, &rc);
|
||||
toxav_call(alice_av, 0, 48, 0, &rc);
|
||||
|
||||
ck_assert_msg(rc == TOXAV_ERR_CALL_OK, "toxav_call failed: %d\n", rc);
|
||||
}
|
||||
|
||||
do {
|
||||
iterate_tox(bootstrap, Alice, Bob);
|
||||
} while (!BobCC.incoming);
|
||||
iterate_tox(bootstrap, alice, bob);
|
||||
} while (!bob_cc.incoming);
|
||||
|
||||
/* Reject */
|
||||
{
|
||||
Toxav_Err_Call_Control rc;
|
||||
toxav_call_control(BobAV, 0, TOXAV_CALL_CONTROL_CANCEL, &rc);
|
||||
toxav_call_control(bob_av, 0, TOXAV_CALL_CONTROL_CANCEL, &rc);
|
||||
|
||||
ck_assert_msg(rc == TOXAV_ERR_CALL_CONTROL_OK, "toxav_call_control failed: %d\n", rc);
|
||||
}
|
||||
|
||||
do {
|
||||
iterate_tox(bootstrap, Alice, Bob);
|
||||
} while (AliceCC.state != TOXAV_FRIEND_CALL_STATE_FINISHED);
|
||||
iterate_tox(bootstrap, alice, bob);
|
||||
} while (alice_cc.state != TOXAV_FRIEND_CALL_STATE_FINISHED);
|
||||
|
||||
printf("Success!\n");
|
||||
}
|
||||
@ -283,32 +283,32 @@ static void test_av_flows(void)
|
||||
if (TEST_CANCEL) { /* Alice calls; Alice cancels while ringing */
|
||||
printf("\nTrying cancel (while ringing) flow...\n");
|
||||
|
||||
clear_call_control(&AliceCC);
|
||||
clear_call_control(&BobCC);
|
||||
clear_call_control(&alice_cc);
|
||||
clear_call_control(&bob_cc);
|
||||
|
||||
{
|
||||
Toxav_Err_Call rc;
|
||||
toxav_call(AliceAV, 0, 48, 0, &rc);
|
||||
toxav_call(alice_av, 0, 48, 0, &rc);
|
||||
|
||||
ck_assert_msg(rc == TOXAV_ERR_CALL_OK, "toxav_call failed: %d\n", rc);
|
||||
}
|
||||
|
||||
do {
|
||||
iterate_tox(bootstrap, Alice, Bob);
|
||||
} while (!BobCC.incoming);
|
||||
iterate_tox(bootstrap, alice, bob);
|
||||
} while (!bob_cc.incoming);
|
||||
|
||||
/* Cancel */
|
||||
{
|
||||
Toxav_Err_Call_Control rc;
|
||||
toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_CANCEL, &rc);
|
||||
toxav_call_control(alice_av, 0, TOXAV_CALL_CONTROL_CANCEL, &rc);
|
||||
|
||||
ck_assert_msg(rc == TOXAV_ERR_CALL_CONTROL_OK, "toxav_call_control failed: %d\n", rc);
|
||||
}
|
||||
|
||||
/* Alice will not receive end state */
|
||||
do {
|
||||
iterate_tox(bootstrap, Alice, Bob);
|
||||
} while (BobCC.state != TOXAV_FRIEND_CALL_STATE_FINISHED);
|
||||
iterate_tox(bootstrap, alice, bob);
|
||||
} while (bob_cc.state != TOXAV_FRIEND_CALL_STATE_FINISHED);
|
||||
|
||||
printf("Success!\n");
|
||||
}
|
||||
@ -316,80 +316,80 @@ static void test_av_flows(void)
|
||||
if (TEST_MUTE_UNMUTE) { /* Check Mute-Unmute etc */
|
||||
printf("\nTrying mute functionality...\n");
|
||||
|
||||
clear_call_control(&AliceCC);
|
||||
clear_call_control(&BobCC);
|
||||
clear_call_control(&alice_cc);
|
||||
clear_call_control(&bob_cc);
|
||||
|
||||
/* Assume sending audio and video */
|
||||
{
|
||||
Toxav_Err_Call rc;
|
||||
toxav_call(AliceAV, 0, 48, 1000, &rc);
|
||||
toxav_call(alice_av, 0, 48, 1000, &rc);
|
||||
|
||||
ck_assert_msg(rc == TOXAV_ERR_CALL_OK, "toxav_call failed: %d\n", rc);
|
||||
}
|
||||
|
||||
do {
|
||||
iterate_tox(bootstrap, Alice, Bob);
|
||||
} while (!BobCC.incoming);
|
||||
iterate_tox(bootstrap, alice, bob);
|
||||
} while (!bob_cc.incoming);
|
||||
|
||||
/* At first try all stuff while in invalid state */
|
||||
ck_assert(!toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_PAUSE, nullptr));
|
||||
ck_assert(!toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_RESUME, nullptr));
|
||||
ck_assert(!toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_MUTE_AUDIO, nullptr));
|
||||
ck_assert(!toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_UNMUTE_AUDIO, nullptr));
|
||||
ck_assert(!toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_HIDE_VIDEO, nullptr));
|
||||
ck_assert(!toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_SHOW_VIDEO, nullptr));
|
||||
ck_assert(!toxav_call_control(alice_av, 0, TOXAV_CALL_CONTROL_PAUSE, nullptr));
|
||||
ck_assert(!toxav_call_control(alice_av, 0, TOXAV_CALL_CONTROL_RESUME, nullptr));
|
||||
ck_assert(!toxav_call_control(alice_av, 0, TOXAV_CALL_CONTROL_MUTE_AUDIO, nullptr));
|
||||
ck_assert(!toxav_call_control(alice_av, 0, TOXAV_CALL_CONTROL_UNMUTE_AUDIO, nullptr));
|
||||
ck_assert(!toxav_call_control(alice_av, 0, TOXAV_CALL_CONTROL_HIDE_VIDEO, nullptr));
|
||||
ck_assert(!toxav_call_control(alice_av, 0, TOXAV_CALL_CONTROL_SHOW_VIDEO, nullptr));
|
||||
|
||||
{
|
||||
Toxav_Err_Answer rc;
|
||||
toxav_answer(BobAV, 0, 48, 4000, &rc);
|
||||
toxav_answer(bob_av, 0, 48, 4000, &rc);
|
||||
|
||||
ck_assert_msg(rc == TOXAV_ERR_ANSWER_OK, "toxav_answer failed: %d\n", rc);
|
||||
}
|
||||
|
||||
iterate_tox(bootstrap, Alice, Bob);
|
||||
iterate_tox(bootstrap, alice, bob);
|
||||
|
||||
/* Pause and Resume */
|
||||
printf("Pause and Resume\n");
|
||||
ck_assert_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_PAUSE);
|
||||
iterate_tox(bootstrap, Alice, Bob);
|
||||
ck_assert(BobCC.state == 0);
|
||||
ck_assert_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_RESUME);
|
||||
iterate_tox(bootstrap, Alice, Bob);
|
||||
ck_assert(BobCC.state & (TOXAV_FRIEND_CALL_STATE_SENDING_A | TOXAV_FRIEND_CALL_STATE_SENDING_V));
|
||||
ck_assert_call_control(alice_av, 0, TOXAV_CALL_CONTROL_PAUSE);
|
||||
iterate_tox(bootstrap, alice, bob);
|
||||
ck_assert(bob_cc.state == 0);
|
||||
ck_assert_call_control(alice_av, 0, TOXAV_CALL_CONTROL_RESUME);
|
||||
iterate_tox(bootstrap, alice, bob);
|
||||
ck_assert(bob_cc.state & (TOXAV_FRIEND_CALL_STATE_SENDING_A | TOXAV_FRIEND_CALL_STATE_SENDING_V));
|
||||
|
||||
/* Mute/Unmute single */
|
||||
printf("Mute/Unmute single\n");
|
||||
ck_assert_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_MUTE_AUDIO);
|
||||
iterate_tox(bootstrap, Alice, Bob);
|
||||
ck_assert(BobCC.state ^ TOXAV_FRIEND_CALL_STATE_ACCEPTING_A);
|
||||
ck_assert_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_UNMUTE_AUDIO);
|
||||
iterate_tox(bootstrap, Alice, Bob);
|
||||
ck_assert(BobCC.state & TOXAV_FRIEND_CALL_STATE_ACCEPTING_A);
|
||||
ck_assert_call_control(alice_av, 0, TOXAV_CALL_CONTROL_MUTE_AUDIO);
|
||||
iterate_tox(bootstrap, alice, bob);
|
||||
ck_assert(bob_cc.state ^ TOXAV_FRIEND_CALL_STATE_ACCEPTING_A);
|
||||
ck_assert_call_control(alice_av, 0, TOXAV_CALL_CONTROL_UNMUTE_AUDIO);
|
||||
iterate_tox(bootstrap, alice, bob);
|
||||
ck_assert(bob_cc.state & TOXAV_FRIEND_CALL_STATE_ACCEPTING_A);
|
||||
|
||||
/* Mute/Unmute both */
|
||||
printf("Mute/Unmute both\n");
|
||||
ck_assert_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_MUTE_AUDIO);
|
||||
iterate_tox(bootstrap, Alice, Bob);
|
||||
ck_assert(BobCC.state ^ TOXAV_FRIEND_CALL_STATE_ACCEPTING_A);
|
||||
ck_assert_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_HIDE_VIDEO);
|
||||
iterate_tox(bootstrap, Alice, Bob);
|
||||
ck_assert(BobCC.state ^ TOXAV_FRIEND_CALL_STATE_ACCEPTING_V);
|
||||
ck_assert_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_UNMUTE_AUDIO);
|
||||
iterate_tox(bootstrap, Alice, Bob);
|
||||
ck_assert(BobCC.state & TOXAV_FRIEND_CALL_STATE_ACCEPTING_A);
|
||||
ck_assert_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_SHOW_VIDEO);
|
||||
iterate_tox(bootstrap, Alice, Bob);
|
||||
ck_assert(BobCC.state & TOXAV_FRIEND_CALL_STATE_ACCEPTING_V);
|
||||
ck_assert_call_control(alice_av, 0, TOXAV_CALL_CONTROL_MUTE_AUDIO);
|
||||
iterate_tox(bootstrap, alice, bob);
|
||||
ck_assert(bob_cc.state ^ TOXAV_FRIEND_CALL_STATE_ACCEPTING_A);
|
||||
ck_assert_call_control(alice_av, 0, TOXAV_CALL_CONTROL_HIDE_VIDEO);
|
||||
iterate_tox(bootstrap, alice, bob);
|
||||
ck_assert(bob_cc.state ^ TOXAV_FRIEND_CALL_STATE_ACCEPTING_V);
|
||||
ck_assert_call_control(alice_av, 0, TOXAV_CALL_CONTROL_UNMUTE_AUDIO);
|
||||
iterate_tox(bootstrap, alice, bob);
|
||||
ck_assert(bob_cc.state & TOXAV_FRIEND_CALL_STATE_ACCEPTING_A);
|
||||
ck_assert_call_control(alice_av, 0, TOXAV_CALL_CONTROL_SHOW_VIDEO);
|
||||
iterate_tox(bootstrap, alice, bob);
|
||||
ck_assert(bob_cc.state & TOXAV_FRIEND_CALL_STATE_ACCEPTING_V);
|
||||
|
||||
{
|
||||
Toxav_Err_Call_Control rc;
|
||||
toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_CANCEL, &rc);
|
||||
toxav_call_control(alice_av, 0, TOXAV_CALL_CONTROL_CANCEL, &rc);
|
||||
|
||||
ck_assert_msg(rc == TOXAV_ERR_CALL_CONTROL_OK, "toxav_call_control failed: %d\n", rc);
|
||||
}
|
||||
|
||||
iterate_tox(bootstrap, Alice, Bob);
|
||||
ck_assert(BobCC.state == TOXAV_FRIEND_CALL_STATE_FINISHED);
|
||||
iterate_tox(bootstrap, alice, bob);
|
||||
ck_assert(bob_cc.state == TOXAV_FRIEND_CALL_STATE_FINISHED);
|
||||
|
||||
printf("Success!\n");
|
||||
}
|
||||
@ -397,58 +397,58 @@ static void test_av_flows(void)
|
||||
if (TEST_STOP_RESUME_PAYLOAD) { /* Stop and resume audio/video payload */
|
||||
printf("\nTrying stop/resume functionality...\n");
|
||||
|
||||
clear_call_control(&AliceCC);
|
||||
clear_call_control(&BobCC);
|
||||
clear_call_control(&alice_cc);
|
||||
clear_call_control(&bob_cc);
|
||||
|
||||
/* Assume sending audio and video */
|
||||
{
|
||||
Toxav_Err_Call rc;
|
||||
toxav_call(AliceAV, 0, 48, 0, &rc);
|
||||
toxav_call(alice_av, 0, 48, 0, &rc);
|
||||
|
||||
ck_assert_msg(rc == TOXAV_ERR_CALL_OK, "toxav_call failed: %d\n", rc);
|
||||
}
|
||||
|
||||
do {
|
||||
iterate_tox(bootstrap, Alice, Bob);
|
||||
} while (!BobCC.incoming);
|
||||
iterate_tox(bootstrap, alice, bob);
|
||||
} while (!bob_cc.incoming);
|
||||
|
||||
{
|
||||
Toxav_Err_Answer rc;
|
||||
toxav_answer(BobAV, 0, 48, 0, &rc);
|
||||
toxav_answer(bob_av, 0, 48, 0, &rc);
|
||||
|
||||
ck_assert_msg(rc == TOXAV_ERR_ANSWER_OK, "toxav_answer failed: %d\n", rc);
|
||||
}
|
||||
|
||||
iterate_tox(bootstrap, Alice, Bob);
|
||||
iterate_tox(bootstrap, alice, bob);
|
||||
|
||||
printf("Call started as audio only\n");
|
||||
printf("Turning on video for Alice...\n");
|
||||
ck_assert(toxav_video_set_bit_rate(AliceAV, 0, 1000, nullptr));
|
||||
ck_assert(toxav_video_set_bit_rate(alice_av, 0, 1000, nullptr));
|
||||
|
||||
iterate_tox(bootstrap, Alice, Bob);
|
||||
ck_assert(BobCC.state & TOXAV_FRIEND_CALL_STATE_SENDING_V);
|
||||
iterate_tox(bootstrap, alice, bob);
|
||||
ck_assert(bob_cc.state & TOXAV_FRIEND_CALL_STATE_SENDING_V);
|
||||
|
||||
printf("Turning off video for Alice...\n");
|
||||
ck_assert(toxav_video_set_bit_rate(AliceAV, 0, 0, nullptr));
|
||||
ck_assert(toxav_video_set_bit_rate(alice_av, 0, 0, nullptr));
|
||||
|
||||
iterate_tox(bootstrap, Alice, Bob);
|
||||
ck_assert(!(BobCC.state & TOXAV_FRIEND_CALL_STATE_SENDING_V));
|
||||
iterate_tox(bootstrap, alice, bob);
|
||||
ck_assert(!(bob_cc.state & TOXAV_FRIEND_CALL_STATE_SENDING_V));
|
||||
|
||||
printf("Turning off audio for Alice...\n");
|
||||
ck_assert(toxav_audio_set_bit_rate(AliceAV, 0, 0, nullptr));
|
||||
ck_assert(toxav_audio_set_bit_rate(alice_av, 0, 0, nullptr));
|
||||
|
||||
iterate_tox(bootstrap, Alice, Bob);
|
||||
ck_assert(!(BobCC.state & TOXAV_FRIEND_CALL_STATE_SENDING_A));
|
||||
iterate_tox(bootstrap, alice, bob);
|
||||
ck_assert(!(bob_cc.state & TOXAV_FRIEND_CALL_STATE_SENDING_A));
|
||||
|
||||
{
|
||||
Toxav_Err_Call_Control rc;
|
||||
toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_CANCEL, &rc);
|
||||
toxav_call_control(alice_av, 0, TOXAV_CALL_CONTROL_CANCEL, &rc);
|
||||
|
||||
ck_assert_msg(rc == TOXAV_ERR_CALL_CONTROL_OK, "toxav_call_control failed: %d\n", rc);
|
||||
}
|
||||
|
||||
iterate_tox(bootstrap, Alice, Bob);
|
||||
ck_assert(BobCC.state == TOXAV_FRIEND_CALL_STATE_FINISHED);
|
||||
iterate_tox(bootstrap, alice, bob);
|
||||
ck_assert(bob_cc.state == TOXAV_FRIEND_CALL_STATE_FINISHED);
|
||||
|
||||
printf("Success!\n");
|
||||
}
|
||||
@ -456,56 +456,56 @@ static void test_av_flows(void)
|
||||
if (TEST_PAUSE_RESUME_SEND) { /* Stop and resume audio/video payload and test send options */
|
||||
printf("\nTrying stop/resume functionality...\n");
|
||||
|
||||
clear_call_control(&AliceCC);
|
||||
clear_call_control(&BobCC);
|
||||
clear_call_control(&alice_cc);
|
||||
clear_call_control(&bob_cc);
|
||||
|
||||
/* Assume sending audio and video */
|
||||
{
|
||||
Toxav_Err_Call rc;
|
||||
toxav_call(AliceAV, 0, 48, 0, &rc);
|
||||
toxav_call(alice_av, 0, 48, 0, &rc);
|
||||
|
||||
ck_assert_msg(rc == TOXAV_ERR_CALL_OK, "toxav_call failed: %d\n", rc);
|
||||
}
|
||||
|
||||
do {
|
||||
iterate_tox(bootstrap, Alice, Bob);
|
||||
} while (!BobCC.incoming);
|
||||
iterate_tox(bootstrap, alice, bob);
|
||||
} while (!bob_cc.incoming);
|
||||
|
||||
{
|
||||
Toxav_Err_Answer rc;
|
||||
toxav_answer(BobAV, 0, 48, 0, &rc);
|
||||
toxav_answer(bob_av, 0, 48, 0, &rc);
|
||||
|
||||
ck_assert_msg(rc == TOXAV_ERR_ANSWER_OK, "toxav_answer failed: %d\n", rc);
|
||||
}
|
||||
|
||||
iterate_tox(bootstrap, Alice, Bob);
|
||||
ck_assert_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_PAUSE);
|
||||
iterate_tox(bootstrap, Alice, Bob);
|
||||
ck_assert(!toxav_audio_send_frame_helper(AliceAV, 0, nullptr));
|
||||
ck_assert(!toxav_audio_send_frame_helper(BobAV, 0, nullptr));
|
||||
ck_assert_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_RESUME);
|
||||
iterate_tox(bootstrap, Alice, Bob);
|
||||
ck_assert(toxav_audio_send_frame_helper(AliceAV, 0, nullptr));
|
||||
ck_assert(toxav_audio_send_frame_helper(BobAV, 0, nullptr));
|
||||
iterate_tox(bootstrap, Alice, Bob);
|
||||
iterate_tox(bootstrap, alice, bob);
|
||||
ck_assert_call_control(alice_av, 0, TOXAV_CALL_CONTROL_PAUSE);
|
||||
iterate_tox(bootstrap, alice, bob);
|
||||
ck_assert(!toxav_audio_send_frame_helper(alice_av, 0, nullptr));
|
||||
ck_assert(!toxav_audio_send_frame_helper(bob_av, 0, nullptr));
|
||||
ck_assert_call_control(alice_av, 0, TOXAV_CALL_CONTROL_RESUME);
|
||||
iterate_tox(bootstrap, alice, bob);
|
||||
ck_assert(toxav_audio_send_frame_helper(alice_av, 0, nullptr));
|
||||
ck_assert(toxav_audio_send_frame_helper(bob_av, 0, nullptr));
|
||||
iterate_tox(bootstrap, alice, bob);
|
||||
|
||||
{
|
||||
Toxav_Err_Call_Control rc;
|
||||
toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_CANCEL, &rc);
|
||||
toxav_call_control(alice_av, 0, TOXAV_CALL_CONTROL_CANCEL, &rc);
|
||||
|
||||
ck_assert_msg(rc == TOXAV_ERR_CALL_CONTROL_OK, "toxav_call_control failed: %d\n", rc);
|
||||
}
|
||||
|
||||
iterate_tox(bootstrap, Alice, Bob);
|
||||
ck_assert(BobCC.state == TOXAV_FRIEND_CALL_STATE_FINISHED);
|
||||
iterate_tox(bootstrap, alice, bob);
|
||||
ck_assert(bob_cc.state == TOXAV_FRIEND_CALL_STATE_FINISHED);
|
||||
|
||||
printf("Success!\n");
|
||||
}
|
||||
|
||||
toxav_kill(BobAV);
|
||||
toxav_kill(AliceAV);
|
||||
tox_kill(Bob);
|
||||
tox_kill(Alice);
|
||||
toxav_kill(bob_av);
|
||||
toxav_kill(alice_av);
|
||||
tox_kill(bob);
|
||||
tox_kill(alice);
|
||||
tox_kill(bootstrap);
|
||||
|
||||
printf("\nTest successful!\n");
|
||||
|
@ -21,18 +21,18 @@
|
||||
#include "auto_test_support.h"
|
||||
#include "check_compat.h"
|
||||
|
||||
typedef struct {
|
||||
typedef struct CallControl {
|
||||
bool incoming;
|
||||
uint32_t state;
|
||||
} CallControl;
|
||||
|
||||
typedef struct {
|
||||
ToxAV *AliceAV;
|
||||
ToxAV *BobAV;
|
||||
CallControl *AliceCC;
|
||||
CallControl *BobCC;
|
||||
typedef struct Thread_Data {
|
||||
ToxAV *alice_av;
|
||||
ToxAV *bob_av;
|
||||
CallControl *alice_cc;
|
||||
CallControl *bob_cc;
|
||||
uint32_t friend_number;
|
||||
} thread_data;
|
||||
} Thread_Data;
|
||||
|
||||
/**
|
||||
* Callbacks
|
||||
@ -78,28 +78,28 @@ static void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const
|
||||
/**
|
||||
* Iterate helper
|
||||
*/
|
||||
static ToxAV *setup_av_instance(Tox *tox, CallControl *CC)
|
||||
static ToxAV *setup_av_instance(Tox *tox, CallControl *cc)
|
||||
{
|
||||
Toxav_Err_New error;
|
||||
|
||||
ToxAV *av = toxav_new(tox, &error);
|
||||
ck_assert(error == TOXAV_ERR_NEW_OK);
|
||||
|
||||
toxav_callback_call(av, t_toxav_call_cb, CC);
|
||||
toxav_callback_call_state(av, t_toxav_call_state_cb, CC);
|
||||
toxav_callback_video_receive_frame(av, t_toxav_receive_video_frame_cb, CC);
|
||||
toxav_callback_audio_receive_frame(av, t_toxav_receive_audio_frame_cb, CC);
|
||||
toxav_callback_call(av, t_toxav_call_cb, cc);
|
||||
toxav_callback_call_state(av, t_toxav_call_state_cb, cc);
|
||||
toxav_callback_video_receive_frame(av, t_toxav_receive_video_frame_cb, cc);
|
||||
toxav_callback_audio_receive_frame(av, t_toxav_receive_audio_frame_cb, cc);
|
||||
|
||||
return av;
|
||||
}
|
||||
|
||||
static void *call_thread(void *pd)
|
||||
{
|
||||
ToxAV *AliceAV = ((thread_data *) pd)->AliceAV;
|
||||
ToxAV *BobAV = ((thread_data *) pd)->BobAV;
|
||||
uint32_t friend_number = ((thread_data *) pd)->friend_number;
|
||||
ToxAV *alice_av = ((Thread_Data *) pd)->alice_av;
|
||||
ToxAV *bob_av = ((Thread_Data *) pd)->bob_av;
|
||||
uint32_t friend_number = ((Thread_Data *) pd)->friend_number;
|
||||
|
||||
int16_t *PCM = (int16_t *)calloc(960, sizeof(int16_t));
|
||||
int16_t *pcm = (int16_t *)calloc(960, sizeof(int16_t));
|
||||
uint8_t *video_y = (uint8_t *)calloc(800 * 600, sizeof(uint8_t));
|
||||
uint8_t *video_u = (uint8_t *)calloc(800 * 600 / 4, sizeof(uint8_t));
|
||||
uint8_t *video_v = (uint8_t *)calloc(800 * 600 / 4, sizeof(uint8_t));
|
||||
@ -107,19 +107,19 @@ static void *call_thread(void *pd)
|
||||
time_t start_time = time(nullptr);
|
||||
|
||||
do {
|
||||
toxav_iterate(AliceAV);
|
||||
toxav_iterate(BobAV);
|
||||
toxav_iterate(alice_av);
|
||||
toxav_iterate(bob_av);
|
||||
|
||||
toxav_audio_send_frame(AliceAV, friend_number, PCM, 960, 1, 48000, nullptr);
|
||||
toxav_audio_send_frame(BobAV, 0, PCM, 960, 1, 48000, nullptr);
|
||||
toxav_audio_send_frame(alice_av, friend_number, pcm, 960, 1, 48000, nullptr);
|
||||
toxav_audio_send_frame(bob_av, 0, pcm, 960, 1, 48000, nullptr);
|
||||
|
||||
toxav_video_send_frame(AliceAV, friend_number, 800, 600, video_y, video_u, video_v, nullptr);
|
||||
toxav_video_send_frame(BobAV, 0, 800, 600, video_y, video_u, video_v, nullptr);
|
||||
toxav_video_send_frame(alice_av, friend_number, 800, 600, video_y, video_u, video_v, nullptr);
|
||||
toxav_video_send_frame(bob_av, 0, 800, 600, video_y, video_u, video_v, nullptr);
|
||||
|
||||
c_sleep(10);
|
||||
} while (time(nullptr) - start_time < 4);
|
||||
|
||||
free(PCM);
|
||||
free(pcm);
|
||||
free(video_y);
|
||||
free(video_u);
|
||||
free(video_v);
|
||||
@ -160,11 +160,11 @@ static void set_current_time_callback(Tox *tox, Time_Data *time_data)
|
||||
static void test_av_three_calls(void)
|
||||
{
|
||||
uint32_t index[] = { 1, 2, 3, 4, 5 };
|
||||
Tox *Alice, *bootstrap, *Bobs[3];
|
||||
ToxAV *AliceAV, *BobsAV[3];
|
||||
Tox *alice, *bootstrap, *bobs[3];
|
||||
ToxAV *alice_av, *bobs_av[3];
|
||||
void *retval;
|
||||
|
||||
CallControl AliceCC[3], BobsCC[3];
|
||||
CallControl alice_cc[3], bobs_cc[3];
|
||||
|
||||
Time_Data time_data;
|
||||
pthread_mutex_init(&time_data.lock, nullptr);
|
||||
@ -177,21 +177,21 @@ static void test_av_three_calls(void)
|
||||
time_data.clock = current_time_monotonic(bootstrap->mono_time);
|
||||
set_current_time_callback(bootstrap, &time_data);
|
||||
|
||||
Alice = tox_new_log(nullptr, &error, &index[1]);
|
||||
alice = tox_new_log(nullptr, &error, &index[1]);
|
||||
ck_assert(error == TOX_ERR_NEW_OK);
|
||||
set_current_time_callback(Alice, &time_data);
|
||||
set_current_time_callback(alice, &time_data);
|
||||
|
||||
Bobs[0] = tox_new_log(nullptr, &error, &index[2]);
|
||||
bobs[0] = tox_new_log(nullptr, &error, &index[2]);
|
||||
ck_assert(error == TOX_ERR_NEW_OK);
|
||||
set_current_time_callback(Bobs[0], &time_data);
|
||||
set_current_time_callback(bobs[0], &time_data);
|
||||
|
||||
Bobs[1] = tox_new_log(nullptr, &error, &index[3]);
|
||||
bobs[1] = tox_new_log(nullptr, &error, &index[3]);
|
||||
ck_assert(error == TOX_ERR_NEW_OK);
|
||||
set_current_time_callback(Bobs[1], &time_data);
|
||||
set_current_time_callback(bobs[1], &time_data);
|
||||
|
||||
Bobs[2] = tox_new_log(nullptr, &error, &index[4]);
|
||||
bobs[2] = tox_new_log(nullptr, &error, &index[4]);
|
||||
ck_assert(error == TOX_ERR_NEW_OK);
|
||||
set_current_time_callback(Bobs[2], &time_data);
|
||||
set_current_time_callback(bobs[2], &time_data);
|
||||
}
|
||||
|
||||
printf("Created 5 instances of Tox\n");
|
||||
@ -200,48 +200,48 @@ static void test_av_three_calls(void)
|
||||
|
||||
uint8_t address[TOX_ADDRESS_SIZE];
|
||||
|
||||
tox_callback_friend_request(Alice, t_accept_friend_request_cb);
|
||||
tox_self_get_address(Alice, address);
|
||||
tox_callback_friend_request(alice, t_accept_friend_request_cb);
|
||||
tox_self_get_address(alice, address);
|
||||
|
||||
printf("bootstrapping Alice and the %u Bobs off a third bootstrap node\n",
|
||||
(unsigned)(sizeof(Bobs) / sizeof(Bobs[0])));
|
||||
(unsigned)(sizeof(bobs) / sizeof(bobs[0])));
|
||||
uint8_t dht_key[TOX_PUBLIC_KEY_SIZE];
|
||||
tox_self_get_dht_id(bootstrap, dht_key);
|
||||
const uint16_t dht_port = tox_self_get_udp_port(bootstrap, nullptr);
|
||||
|
||||
tox_bootstrap(Alice, "localhost", dht_port, dht_key, nullptr);
|
||||
tox_bootstrap(Bobs[0], "localhost", dht_port, dht_key, nullptr);
|
||||
tox_bootstrap(Bobs[1], "localhost", dht_port, dht_key, nullptr);
|
||||
tox_bootstrap(Bobs[2], "localhost", dht_port, dht_key, nullptr);
|
||||
tox_bootstrap(alice, "localhost", dht_port, dht_key, nullptr);
|
||||
tox_bootstrap(bobs[0], "localhost", dht_port, dht_key, nullptr);
|
||||
tox_bootstrap(bobs[1], "localhost", dht_port, dht_key, nullptr);
|
||||
tox_bootstrap(bobs[2], "localhost", dht_port, dht_key, nullptr);
|
||||
|
||||
ck_assert(tox_friend_add(Bobs[0], address, (const uint8_t *)"gentoo", 7, nullptr) != (uint32_t) -1);
|
||||
ck_assert(tox_friend_add(Bobs[1], address, (const uint8_t *)"gentoo", 7, nullptr) != (uint32_t) -1);
|
||||
ck_assert(tox_friend_add(Bobs[2], address, (const uint8_t *)"gentoo", 7, nullptr) != (uint32_t) -1);
|
||||
ck_assert(tox_friend_add(bobs[0], address, (const uint8_t *)"gentoo", 7, nullptr) != (uint32_t) -1);
|
||||
ck_assert(tox_friend_add(bobs[1], address, (const uint8_t *)"gentoo", 7, nullptr) != (uint32_t) -1);
|
||||
ck_assert(tox_friend_add(bobs[2], address, (const uint8_t *)"gentoo", 7, nullptr) != (uint32_t) -1);
|
||||
|
||||
uint8_t off = 1;
|
||||
|
||||
while (true) {
|
||||
tox_iterate(bootstrap, nullptr);
|
||||
tox_iterate(Alice, nullptr);
|
||||
tox_iterate(Bobs[0], nullptr);
|
||||
tox_iterate(Bobs[1], nullptr);
|
||||
tox_iterate(Bobs[2], nullptr);
|
||||
tox_iterate(alice, nullptr);
|
||||
tox_iterate(bobs[0], nullptr);
|
||||
tox_iterate(bobs[1], nullptr);
|
||||
tox_iterate(bobs[2], nullptr);
|
||||
|
||||
if (tox_self_get_connection_status(bootstrap) &&
|
||||
tox_self_get_connection_status(Alice) &&
|
||||
tox_self_get_connection_status(Bobs[0]) &&
|
||||
tox_self_get_connection_status(Bobs[1]) &&
|
||||
tox_self_get_connection_status(Bobs[2]) && off) {
|
||||
tox_self_get_connection_status(alice) &&
|
||||
tox_self_get_connection_status(bobs[0]) &&
|
||||
tox_self_get_connection_status(bobs[1]) &&
|
||||
tox_self_get_connection_status(bobs[2]) && off) {
|
||||
printf("Toxes are online, took %lu seconds\n", (unsigned long)(time(nullptr) - cur_time));
|
||||
off = 0;
|
||||
}
|
||||
|
||||
if (tox_friend_get_connection_status(Alice, 0, nullptr) == TOX_CONNECTION_UDP &&
|
||||
tox_friend_get_connection_status(Alice, 1, nullptr) == TOX_CONNECTION_UDP &&
|
||||
tox_friend_get_connection_status(Alice, 2, nullptr) == TOX_CONNECTION_UDP &&
|
||||
tox_friend_get_connection_status(Bobs[0], 0, nullptr) == TOX_CONNECTION_UDP &&
|
||||
tox_friend_get_connection_status(Bobs[1], 0, nullptr) == TOX_CONNECTION_UDP &&
|
||||
tox_friend_get_connection_status(Bobs[2], 0, nullptr) == TOX_CONNECTION_UDP) {
|
||||
if (tox_friend_get_connection_status(alice, 0, nullptr) == TOX_CONNECTION_UDP &&
|
||||
tox_friend_get_connection_status(alice, 1, nullptr) == TOX_CONNECTION_UDP &&
|
||||
tox_friend_get_connection_status(alice, 2, nullptr) == TOX_CONNECTION_UDP &&
|
||||
tox_friend_get_connection_status(bobs[0], 0, nullptr) == TOX_CONNECTION_UDP &&
|
||||
tox_friend_get_connection_status(bobs[1], 0, nullptr) == TOX_CONNECTION_UDP &&
|
||||
tox_friend_get_connection_status(bobs[2], 0, nullptr) == TOX_CONNECTION_UDP) {
|
||||
break;
|
||||
}
|
||||
|
||||
@ -249,24 +249,24 @@ static void test_av_three_calls(void)
|
||||
c_sleep(5);
|
||||
}
|
||||
|
||||
AliceAV = setup_av_instance(Alice, AliceCC);
|
||||
BobsAV[0] = setup_av_instance(Bobs[0], &BobsCC[0]);
|
||||
BobsAV[1] = setup_av_instance(Bobs[1], &BobsCC[1]);
|
||||
BobsAV[2] = setup_av_instance(Bobs[2], &BobsCC[2]);
|
||||
alice_av = setup_av_instance(alice, alice_cc);
|
||||
bobs_av[0] = setup_av_instance(bobs[0], &bobs_cc[0]);
|
||||
bobs_av[1] = setup_av_instance(bobs[1], &bobs_cc[1]);
|
||||
bobs_av[2] = setup_av_instance(bobs[2], &bobs_cc[2]);
|
||||
|
||||
printf("Created 4 instances of ToxAV\n");
|
||||
printf("All set after %lu seconds!\n", (unsigned long)(time(nullptr) - cur_time));
|
||||
|
||||
thread_data tds[3];
|
||||
Thread_Data tds[3];
|
||||
|
||||
for (size_t i = 0; i < 3; i++) {
|
||||
tds[i].AliceAV = AliceAV;
|
||||
tds[i].BobAV = BobsAV[i];
|
||||
tds[i].AliceCC = &AliceCC[i];
|
||||
tds[i].BobCC = &BobsCC[i];
|
||||
tds[i].alice_av = alice_av;
|
||||
tds[i].bob_av = bobs_av[i];
|
||||
tds[i].alice_cc = &alice_cc[i];
|
||||
tds[i].bob_cc = &bobs_cc[i];
|
||||
tds[i].friend_number = i;
|
||||
memset(tds[i].AliceCC, 0, sizeof(CallControl));
|
||||
memset(tds[i].BobCC, 0, sizeof(CallControl));
|
||||
memset(tds[i].alice_cc, 0, sizeof(CallControl));
|
||||
memset(tds[i].bob_cc, 0, sizeof(CallControl));
|
||||
}
|
||||
|
||||
pthread_t tids[3];
|
||||
@ -279,10 +279,10 @@ static void test_av_three_calls(void)
|
||||
|
||||
do {
|
||||
tox_iterate(bootstrap, nullptr);
|
||||
tox_iterate(Alice, nullptr);
|
||||
tox_iterate(Bobs[0], nullptr);
|
||||
tox_iterate(Bobs[1], nullptr);
|
||||
tox_iterate(Bobs[2], nullptr);
|
||||
tox_iterate(alice, nullptr);
|
||||
tox_iterate(bobs[0], nullptr);
|
||||
tox_iterate(bobs[1], nullptr);
|
||||
tox_iterate(bobs[2], nullptr);
|
||||
|
||||
increment_clock(&time_data, 100);
|
||||
c_sleep(5);
|
||||
@ -291,7 +291,7 @@ static void test_av_three_calls(void)
|
||||
/* Call */
|
||||
for (size_t i = 0; i < 3; i++) {
|
||||
Toxav_Err_Call rc;
|
||||
toxav_call(AliceAV, tds[i].friend_number, 48, 3000, &rc);
|
||||
toxav_call(alice_av, tds[i].friend_number, 48, 3000, &rc);
|
||||
|
||||
if (rc != TOXAV_ERR_CALL_OK) {
|
||||
printf("toxav_call failed: %d\n", rc);
|
||||
@ -302,23 +302,23 @@ static void test_av_three_calls(void)
|
||||
|
||||
do {
|
||||
tox_iterate(bootstrap, nullptr);
|
||||
tox_iterate(Alice, nullptr);
|
||||
tox_iterate(Bobs[0], nullptr);
|
||||
tox_iterate(Bobs[1], nullptr);
|
||||
tox_iterate(Bobs[2], nullptr);
|
||||
tox_iterate(alice, nullptr);
|
||||
tox_iterate(bobs[0], nullptr);
|
||||
tox_iterate(bobs[1], nullptr);
|
||||
tox_iterate(bobs[2], nullptr);
|
||||
|
||||
for (size_t i = 0; i < 3; i++) {
|
||||
if (BobsCC[i].incoming) {
|
||||
if (bobs_cc[i].incoming) {
|
||||
/* Answer */
|
||||
Toxav_Err_Answer rc;
|
||||
toxav_answer(BobsAV[i], 0, 8, 500, &rc);
|
||||
toxav_answer(bobs_av[i], 0, 8, 500, &rc);
|
||||
|
||||
if (rc != TOXAV_ERR_ANSWER_OK) {
|
||||
printf("toxav_answer failed: %d\n", rc);
|
||||
ck_assert(0);
|
||||
}
|
||||
|
||||
BobsCC[i].incoming = false;
|
||||
bobs_cc[i].incoming = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -329,19 +329,19 @@ static void test_av_three_calls(void)
|
||||
/* Hangup */
|
||||
for (size_t i = 0; i < 3; i++) {
|
||||
Toxav_Err_Call_Control rc;
|
||||
toxav_call_control(AliceAV, i, TOXAV_CALL_CONTROL_CANCEL, &rc);
|
||||
toxav_call_control(alice_av, i, TOXAV_CALL_CONTROL_CANCEL, &rc);
|
||||
|
||||
if (rc != TOXAV_ERR_CALL_CONTROL_OK) {
|
||||
printf("toxav_call_control failed: %d %p %p\n", rc, (void *)AliceAV, (void *)&BobsAV[i]);
|
||||
printf("toxav_call_control failed: %d %p %p\n", rc, (void *)alice_av, (void *)&bobs_av[i]);
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
tox_iterate(bootstrap, nullptr);
|
||||
tox_iterate(Alice, nullptr);
|
||||
tox_iterate(Bobs[0], nullptr);
|
||||
tox_iterate(Bobs[1], nullptr);
|
||||
tox_iterate(Bobs[2], nullptr);
|
||||
tox_iterate(alice, nullptr);
|
||||
tox_iterate(bobs[0], nullptr);
|
||||
tox_iterate(bobs[1], nullptr);
|
||||
tox_iterate(bobs[2], nullptr);
|
||||
|
||||
increment_clock(&time_data, 100);
|
||||
c_sleep(5);
|
||||
@ -357,14 +357,14 @@ static void test_av_three_calls(void)
|
||||
ck_assert(retval == nullptr);
|
||||
|
||||
printf("Killing all instances\n");
|
||||
toxav_kill(BobsAV[2]);
|
||||
toxav_kill(BobsAV[1]);
|
||||
toxav_kill(BobsAV[0]);
|
||||
toxav_kill(AliceAV);
|
||||
tox_kill(Bobs[2]);
|
||||
tox_kill(Bobs[1]);
|
||||
tox_kill(Bobs[0]);
|
||||
tox_kill(Alice);
|
||||
toxav_kill(bobs_av[2]);
|
||||
toxav_kill(bobs_av[1]);
|
||||
toxav_kill(bobs_av[0]);
|
||||
toxav_kill(alice_av);
|
||||
tox_kill(bobs[2]);
|
||||
tox_kill(bobs[1]);
|
||||
tox_kill(bobs[0]);
|
||||
tox_kill(alice);
|
||||
tox_kill(bootstrap);
|
||||
|
||||
pthread_mutex_destroy(&time_data.lock);
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "../toxcore/tox.h"
|
||||
#include "check_compat.h"
|
||||
|
||||
#define check(major, minor, patch, expected) \
|
||||
#define CHECK(major, minor, patch, expected) \
|
||||
do_check(TOX_VERSION_MAJOR, TOX_VERSION_MINOR, TOX_VERSION_PATCH, \
|
||||
major, minor, patch, \
|
||||
TOX_VERSION_IS_API_COMPATIBLE(major, minor, patch), expected)
|
||||
@ -26,11 +26,11 @@ int main(void)
|
||||
#define TOX_VERSION_MINOR 0
|
||||
#define TOX_VERSION_PATCH 4
|
||||
// Tox versions from 0.0.* are only compatible with themselves.
|
||||
check(0, 0, 0, false);
|
||||
check(0, 0, 3, false);
|
||||
check(0, 0, 4, true);
|
||||
check(0, 0, 5, false);
|
||||
check(1, 0, 4, false);
|
||||
CHECK(0, 0, 0, false);
|
||||
CHECK(0, 0, 3, false);
|
||||
CHECK(0, 0, 4, true);
|
||||
CHECK(0, 0, 5, false);
|
||||
CHECK(1, 0, 4, false);
|
||||
#undef TOX_VERSION_MAJOR
|
||||
#undef TOX_VERSION_MINOR
|
||||
#undef TOX_VERSION_PATCH
|
||||
@ -39,19 +39,19 @@ int main(void)
|
||||
#define TOX_VERSION_MINOR 1
|
||||
#define TOX_VERSION_PATCH 4
|
||||
// Tox versions from 0.1.* are only compatible with themselves or 0.1.<*
|
||||
check(0, 0, 0, false);
|
||||
check(0, 0, 4, false);
|
||||
check(0, 0, 5, false);
|
||||
check(0, 1, 0, true);
|
||||
check(0, 1, 4, true);
|
||||
check(0, 1, 5, false);
|
||||
check(0, 2, 0, false);
|
||||
check(0, 2, 4, false);
|
||||
check(0, 2, 5, false);
|
||||
check(1, 0, 0, false);
|
||||
check(1, 0, 4, false);
|
||||
check(1, 0, 5, false);
|
||||
check(1, 1, 4, false);
|
||||
CHECK(0, 0, 0, false);
|
||||
CHECK(0, 0, 4, false);
|
||||
CHECK(0, 0, 5, false);
|
||||
CHECK(0, 1, 0, true);
|
||||
CHECK(0, 1, 4, true);
|
||||
CHECK(0, 1, 5, false);
|
||||
CHECK(0, 2, 0, false);
|
||||
CHECK(0, 2, 4, false);
|
||||
CHECK(0, 2, 5, false);
|
||||
CHECK(1, 0, 0, false);
|
||||
CHECK(1, 0, 4, false);
|
||||
CHECK(1, 0, 5, false);
|
||||
CHECK(1, 1, 4, false);
|
||||
#undef TOX_VERSION_MAJOR
|
||||
#undef TOX_VERSION_MINOR
|
||||
#undef TOX_VERSION_PATCH
|
||||
@ -60,14 +60,14 @@ int main(void)
|
||||
#define TOX_VERSION_MINOR 0
|
||||
#define TOX_VERSION_PATCH 4
|
||||
// Beyond 0.*.* Tox is comfortable with any lower version within their major
|
||||
check(0, 0, 4, false);
|
||||
check(1, 0, 0, true);
|
||||
check(1, 0, 1, true);
|
||||
check(1, 0, 4, true);
|
||||
check(1, 0, 5, false);
|
||||
check(1, 1, 0, false);
|
||||
check(2, 0, 0, false);
|
||||
check(2, 0, 4, false);
|
||||
CHECK(0, 0, 4, false);
|
||||
CHECK(1, 0, 0, true);
|
||||
CHECK(1, 0, 1, true);
|
||||
CHECK(1, 0, 4, true);
|
||||
CHECK(1, 0, 5, false);
|
||||
CHECK(1, 1, 0, false);
|
||||
CHECK(2, 0, 0, false);
|
||||
CHECK(2, 0, 4, false);
|
||||
#undef TOX_VERSION_MAJOR
|
||||
#undef TOX_VERSION_MINOR
|
||||
#undef TOX_VERSION_PATCH
|
||||
@ -75,19 +75,19 @@ int main(void)
|
||||
#define TOX_VERSION_MAJOR 1
|
||||
#define TOX_VERSION_MINOR 1
|
||||
#define TOX_VERSION_PATCH 4
|
||||
check(0, 0, 4, false);
|
||||
check(1, 0, 0, true);
|
||||
check(1, 0, 4, true);
|
||||
check(1, 0, 5, true);
|
||||
check(1, 1, 0, true);
|
||||
check(1, 1, 1, true);
|
||||
check(1, 1, 4, true);
|
||||
check(1, 1, 5, false);
|
||||
check(1, 2, 0, false);
|
||||
check(1, 2, 4, false);
|
||||
check(1, 2, 5, false);
|
||||
check(2, 0, 0, false);
|
||||
check(2, 1, 4, false);
|
||||
CHECK(0, 0, 4, false);
|
||||
CHECK(1, 0, 0, true);
|
||||
CHECK(1, 0, 4, true);
|
||||
CHECK(1, 0, 5, true);
|
||||
CHECK(1, 1, 0, true);
|
||||
CHECK(1, 1, 1, true);
|
||||
CHECK(1, 1, 4, true);
|
||||
CHECK(1, 1, 5, false);
|
||||
CHECK(1, 2, 0, false);
|
||||
CHECK(1, 2, 4, false);
|
||||
CHECK(1, 2, 5, false);
|
||||
CHECK(2, 0, 0, false);
|
||||
CHECK(2, 1, 4, false);
|
||||
#undef TOX_VERSION_MAJOR
|
||||
#undef TOX_VERSION_MINOR
|
||||
#undef TOX_VERSION_PATCH
|
||||
|
Reference in New Issue
Block a user