Merge commit '3105cc20ef3173b87fdc1688962ed6318a1fd039'
This commit is contained in:
@ -48,7 +48,7 @@ auto_test(conference_simple)
|
||||
auto_test(conference_two)
|
||||
auto_test(crypto)
|
||||
#auto_test(dht) # Doesn't work with UNITY_BUILD.
|
||||
auto_test(dht_getnodes_api)
|
||||
auto_test(dht_nodes_response_api)
|
||||
auto_test(encryptsave)
|
||||
auto_test(file_saving)
|
||||
auto_test(file_streaming)
|
||||
|
22
external/toxcore/c-toxcore/auto_tests/TCP_test.c
vendored
22
external/toxcore/c-toxcore/auto_tests/TCP_test.c
vendored
@ -271,7 +271,7 @@ static void kill_tcp_con(struct sec_TCP_con *con)
|
||||
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, const Memory *mem, struct sec_TCP_con *con, const uint8_t *data,
|
||||
uint16_t length)
|
||||
{
|
||||
const uint16_t packet_size = sizeof(uint16_t) + length + CRYPTO_MAC_SIZE;
|
||||
@ -338,9 +338,9 @@ static void test_some(void)
|
||||
|
||||
// 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, mem, 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, mem, con3, requ_p, sizeof(requ_p));
|
||||
|
||||
do_tcp_server_delay(tcp_s, mono_time, 50);
|
||||
|
||||
@ -362,9 +362,9 @@ static void test_some(void)
|
||||
|
||||
const 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, mem, con3, test_packet, sizeof(test_packet));
|
||||
write_packet_tcp_test_connection(logger, mem, con3, test_packet, sizeof(test_packet));
|
||||
write_packet_tcp_test_connection(logger, mem, con3, test_packet, sizeof(test_packet));
|
||||
|
||||
do_tcp_server_delay(tcp_s, mono_time, 50);
|
||||
|
||||
@ -388,9 +388,9 @@ static void test_some(void)
|
||||
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));
|
||||
write_packet_tcp_test_connection(logger, mem, con1, test_packet, sizeof(test_packet));
|
||||
write_packet_tcp_test_connection(logger, mem, con1, test_packet, sizeof(test_packet));
|
||||
write_packet_tcp_test_connection(logger, mem, 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);
|
||||
@ -405,8 +405,8 @@ static void test_some(void)
|
||||
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));
|
||||
const uint8_t ping_packet[1 + sizeof(uint64_t)] = {TCP_PACKET_PING, 8, 6, 9, 67};
|
||||
write_packet_tcp_test_connection(logger, mem, con1, ping_packet, sizeof(ping_packet));
|
||||
|
||||
do_tcp_server_delay(tcp_s, mono_time, 50);
|
||||
|
||||
|
@ -1,12 +1,11 @@
|
||||
/**
|
||||
* This autotest creates a small local DHT and makes sure that each peer can crawl
|
||||
* the entire DHT using the DHT getnodes api functions.
|
||||
* the entire DHT using the DHT nodes request/response api functions.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "../toxcore/tox.h"
|
||||
#include "../toxcore/tox_private.h"
|
||||
@ -72,16 +71,16 @@ static bool all_nodes_crawled(const AutoTox *autotoxes, uint32_t num_toxes, uint
|
||||
return true;
|
||||
}
|
||||
|
||||
static void getnodes_response_cb(const Tox_Event_Dht_Get_Nodes_Response *event, void *user_data)
|
||||
static void nodes_response_cb(const Tox_Event_Dht_Nodes_Response *event, void *user_data)
|
||||
{
|
||||
ck_assert(user_data != nullptr);
|
||||
|
||||
AutoTox *autotox = (AutoTox *)user_data;
|
||||
State *state = (State *)autotox->state;
|
||||
|
||||
const uint8_t *public_key = tox_event_dht_get_nodes_response_get_public_key(event);
|
||||
const char *ip = (const char *)tox_event_dht_get_nodes_response_get_ip(event);
|
||||
const uint16_t port = tox_event_dht_get_nodes_response_get_port(event);
|
||||
const uint8_t *public_key = tox_event_dht_nodes_response_get_public_key(event);
|
||||
const char *ip = (const char *)tox_event_dht_nodes_response_get_ip(event);
|
||||
const uint16_t port = tox_event_dht_nodes_response_get_port(event);
|
||||
|
||||
if (node_crawled(state->nodes, state->num_nodes, public_key)) {
|
||||
return;
|
||||
@ -101,11 +100,11 @@ static void getnodes_response_cb(const Tox_Event_Dht_Get_Nodes_Response *event,
|
||||
|
||||
// ask new node to give us their close nodes to every public key
|
||||
for (size_t i = 0; i < NUM_TOXES; ++i) {
|
||||
tox_dht_get_nodes(autotox->tox, public_key, ip, port, state->public_key_list[i], nullptr);
|
||||
tox_dht_send_nodes_request(autotox->tox, public_key, ip, port, state->public_key_list[i], nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_dht_getnodes(AutoTox *autotoxes)
|
||||
static void test_dht_nodes_request(AutoTox *autotoxes)
|
||||
{
|
||||
ck_assert(NUM_TOXES >= 2);
|
||||
|
||||
@ -125,7 +124,7 @@ static void test_dht_getnodes(AutoTox *autotoxes)
|
||||
ck_assert(public_key_list[i] != nullptr);
|
||||
|
||||
tox_self_get_dht_id(autotoxes[i].tox, public_key_list[i]);
|
||||
tox_events_callback_dht_get_nodes_response(autotoxes[i].dispatch, getnodes_response_cb);
|
||||
tox_events_callback_dht_nodes_response(autotoxes[i].dispatch, nodes_response_cb);
|
||||
|
||||
printf("Peer %zu dht closenode count total/announce-capable: %d/%d\n",
|
||||
i,
|
||||
@ -153,7 +152,7 @@ int main(void)
|
||||
Run_Auto_Options options = default_run_auto_options();
|
||||
options.graph = GRAPH_LINEAR;
|
||||
|
||||
run_auto_test(nullptr, NUM_TOXES, test_dht_getnodes, sizeof(State), &options);
|
||||
run_auto_test(nullptr, NUM_TOXES, test_dht_nodes_request, sizeof(State), &options);
|
||||
|
||||
return 0;
|
||||
}
|
@ -13,11 +13,13 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "../toxcore/ccompat.h"
|
||||
#include "../toxcore/tox.h"
|
||||
#include "auto_test_support.h"
|
||||
#include "check_compat.h"
|
||||
|
||||
#include "../toxcore/ccompat.h"
|
||||
#include "../toxcore/tox.h"
|
||||
#include "../toxencryptsave/toxencryptsave.h"
|
||||
|
||||
static const char *pphrase = "bar";
|
||||
@ -27,21 +29,26 @@ static const char *savefile = "./save";
|
||||
static void save_data_encrypted(void)
|
||||
{
|
||||
struct Tox_Options *options = tox_options_new(nullptr);
|
||||
ck_assert(options != nullptr);
|
||||
Tox *t = tox_new_log(options, nullptr, nullptr);
|
||||
ck_assert(t != nullptr);
|
||||
tox_options_free(options);
|
||||
|
||||
tox_self_set_name(t, (const uint8_t *)name, strlen(name), nullptr);
|
||||
|
||||
FILE *f = fopen(savefile, "wb");
|
||||
ck_assert(f != nullptr);
|
||||
|
||||
size_t size = tox_get_savedata_size(t);
|
||||
uint8_t *clear = (uint8_t *)malloc(size);
|
||||
ck_assert(clear != nullptr);
|
||||
|
||||
/*this function does not write any data at all*/
|
||||
tox_get_savedata(t, clear);
|
||||
|
||||
size += TOX_PASS_ENCRYPTION_EXTRA_LENGTH;
|
||||
uint8_t *cipher = (uint8_t *)malloc(size);
|
||||
ck_assert(cipher != nullptr);
|
||||
|
||||
Tox_Err_Encryption eerr;
|
||||
|
||||
@ -66,11 +73,12 @@ static void load_data_decrypted(void)
|
||||
int64_t size = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
|
||||
ck_assert_msg(0 <= size && size <= UINT_MAX, "file size out of range");
|
||||
ck_assert_msg(TOX_PASS_ENCRYPTION_EXTRA_LENGTH <= size && size <= UINT_MAX, "file size out of range");
|
||||
|
||||
uint8_t *cipher = (uint8_t *)malloc(size);
|
||||
ck_assert(cipher != nullptr);
|
||||
uint8_t *clear = (uint8_t *)malloc(size - TOX_PASS_ENCRYPTION_EXTRA_LENGTH);
|
||||
const size_t clear_size = size - TOX_PASS_ENCRYPTION_EXTRA_LENGTH;
|
||||
uint8_t *clear = (uint8_t *)malloc(clear_size);
|
||||
ck_assert(clear != nullptr);
|
||||
size_t read_value = fread(cipher, sizeof(*cipher), size, f);
|
||||
printf("Read read_value = %u of %u\n", (unsigned)read_value, (unsigned)size);
|
||||
@ -78,23 +86,23 @@ static void load_data_decrypted(void)
|
||||
Tox_Err_Decryption derr;
|
||||
|
||||
ck_assert_msg(tox_pass_decrypt(cipher, size, (const uint8_t *)pphrase, strlen(pphrase), clear, &derr),
|
||||
"Could not decrypt, error code %d.", derr);
|
||||
"Could not decrypt, error code %s.", tox_err_decryption_to_string(derr));
|
||||
|
||||
struct Tox_Options *options = tox_options_new(nullptr);
|
||||
ck_assert(options != nullptr);
|
||||
|
||||
tox_options_set_experimental_owned_data(options, true);
|
||||
tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE);
|
||||
|
||||
tox_options_set_savedata_data(options, clear, size);
|
||||
ck_assert(tox_options_set_savedata_data(options, clear, clear_size));
|
||||
free(clear);
|
||||
|
||||
Tox_Err_New err;
|
||||
|
||||
Tox *t = tox_new_log(options, &err, nullptr);
|
||||
ck_assert_msg(t != nullptr, "tox_new returned the error value %s", tox_err_new_to_string(err));
|
||||
|
||||
tox_options_free(options);
|
||||
|
||||
ck_assert_msg(t != nullptr, "tox_new returned the error value %d", err);
|
||||
|
||||
uint8_t *readname = (uint8_t *)malloc(tox_self_get_name_size(t));
|
||||
ck_assert(readname != nullptr);
|
||||
tox_self_get_name(t, readname);
|
||||
@ -103,7 +111,6 @@ static void load_data_decrypted(void)
|
||||
"name returned by tox_self_get_name does not match expected result");
|
||||
|
||||
tox_kill(t);
|
||||
free(clear);
|
||||
free(cipher);
|
||||
free(readname);
|
||||
fclose(f);
|
||||
|
@ -1,7 +1,5 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../testing/misc_tools.h"
|
||||
#include "../toxcore/network.h"
|
||||
#include "check_compat.h"
|
||||
|
||||
@ -34,9 +32,8 @@ static void test_addr_resolv_localhost(void)
|
||||
bool res = addr_resolve_or_parse_ip(ns, mem, localhost, &ip, nullptr, true);
|
||||
|
||||
int error = net_error();
|
||||
char *strerror = net_new_strerror(error);
|
||||
ck_assert_msg(res, "Resolver failed: %d, %s", error, strerror);
|
||||
net_kill_strerror(strerror);
|
||||
Net_Strerror error_str;
|
||||
ck_assert_msg(res, "Resolver failed: %d, %s", error, net_strerror(error, &error_str));
|
||||
|
||||
Ip_Ntoa ip_str;
|
||||
ck_assert_msg(net_family_is_ipv4(ip.family), "Expected family TOX_AF_INET, got %u.", ip.family.value);
|
||||
@ -57,9 +54,7 @@ static void test_addr_resolv_localhost(void)
|
||||
}
|
||||
|
||||
error = net_error();
|
||||
strerror = net_new_strerror(error);
|
||||
ck_assert_msg(res, "Resolver failed: %d, %s", error, strerror);
|
||||
net_kill_strerror(strerror);
|
||||
ck_assert_msg(res, "Resolver failed: %d, %s", error, net_strerror(error, &error_str));
|
||||
|
||||
ck_assert_msg(net_family_is_ipv6(ip.family), "Expected family TOX_AF_INET6 (%d), got %u.", TOX_AF_INET6,
|
||||
ip.family.value);
|
||||
@ -80,9 +75,7 @@ static void test_addr_resolv_localhost(void)
|
||||
ip_reset(&extra);
|
||||
res = addr_resolve_or_parse_ip(ns, mem, localhost, &ip, &extra, true);
|
||||
error = net_error();
|
||||
strerror = net_new_strerror(error);
|
||||
ck_assert_msg(res, "Resolver failed: %d, %s", error, strerror);
|
||||
net_kill_strerror(strerror);
|
||||
ck_assert_msg(res, "Resolver failed: %d, %s", error, net_strerror(error, &error_str));
|
||||
|
||||
#if USE_IPV6
|
||||
ck_assert_msg(net_family_is_ipv6(ip.family), "Expected family TOX_AF_INET6 (%d), got %u.", TOX_AF_INET6,
|
||||
|
@ -60,7 +60,7 @@ int main(int argc, char **argv)
|
||||
c_sleep(100);
|
||||
}
|
||||
|
||||
const uint16_t tcp_port = 8082;
|
||||
const uint16_t tcp_port = 7082;
|
||||
uint32_t index[] = { 1, 2, 3, 4 };
|
||||
|
||||
struct Tox_Options *tox_options = tox_options_new(nullptr);
|
||||
@ -92,7 +92,7 @@ int main(int argc, char **argv)
|
||||
// tox3 has UDP disabled and connects to tox1 via an HTTP proxy
|
||||
tox_options_set_udp_enabled(tox_options, false);
|
||||
tox_options_set_proxy_host(tox_options, "127.0.0.1");
|
||||
tox_options_set_proxy_port(tox_options, 8080);
|
||||
tox_options_set_proxy_port(tox_options, 7080);
|
||||
tox_options_set_proxy_type(tox_options, TOX_PROXY_TYPE_HTTP);
|
||||
|
||||
Tox *tox3 = tox_new_log(tox_options, nullptr, &index[2]);
|
||||
@ -101,7 +101,7 @@ int main(int argc, char **argv)
|
||||
// tox4 has UDP disabled and connects to tox1 via a SOCKS5 proxy
|
||||
tox_options_set_udp_enabled(tox_options, false);
|
||||
tox_options_set_proxy_host(tox_options, "127.0.0.1");
|
||||
tox_options_set_proxy_port(tox_options, 8081);
|
||||
tox_options_set_proxy_port(tox_options, 7081);
|
||||
tox_options_set_proxy_type(tox_options, TOX_PROXY_TYPE_SOCKS5);
|
||||
|
||||
Tox *tox4 = tox_new_log(tox_options, nullptr, &index[3]);
|
||||
|
Reference in New Issue
Block a user