Merge commit '9ddeea3d06045c8ae38cd2d6eed0fc2891c6e146'

This commit is contained in:
2023-12-15 15:21:40 +01:00
78 changed files with 892 additions and 415 deletions

View File

@ -1,7 +1,5 @@
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
package(features = ["layering_check"])
cc_library(
name = "check_compat",
testonly = True,

View File

@ -269,6 +269,30 @@ static void test_large_data_symmetric(void)
free(m1);
}
static void test_very_large_data(void)
{
const Random *rng = system_random();
ck_assert(rng != nullptr);
uint8_t nonce[CRYPTO_NONCE_SIZE] = {0};
uint8_t pk[CRYPTO_PUBLIC_KEY_SIZE];
uint8_t sk[CRYPTO_SECRET_KEY_SIZE];
crypto_new_keypair(rng, pk, sk);
// 100 MiB of data (all zeroes, doesn't matter what's inside).
const uint32_t plain_size = 100 * 1024 * 1024;
uint8_t *plain = (uint8_t *)malloc(plain_size);
uint8_t *encrypted = (uint8_t *)malloc(plain_size + CRYPTO_MAC_SIZE);
ck_assert(plain != nullptr);
ck_assert(encrypted != nullptr);
encrypt_data(pk, sk, nonce, plain, plain_size, encrypted);
free(encrypted);
free(plain);
}
static void increment_nonce_number_cmp(uint8_t *nonce, uint32_t num)
{
uint32_t num1 = 0;
@ -340,6 +364,7 @@ int main(void)
test_endtoend(); /* waiting up to 15 seconds */
test_large_data();
test_large_data_symmetric();
test_very_large_data();
test_increment_nonce();
test_memzero();

View File

@ -123,7 +123,7 @@ static void test_dht_getnodes(AutoTox *autotoxes)
tox_self_get_dht_id(autotoxes[i].tox, public_key_list[i]);
tox_callback_dht_get_nodes_response(autotoxes[i].tox, getnodes_response_cb);
printf("Peer %zu dht closenode count total/annouce-capable: %d/%d\n",
printf("Peer %zu dht closenode count total/announce-capable: %d/%d\n",
i,
tox_dht_get_num_closelist(autotoxes[i].tox),
tox_dht_get_num_closelist_announce_capable(autotoxes[i].tox)

View File

@ -44,6 +44,10 @@ typedef struct State {
#define TEST_CUSTOM_PACKET "Why'd ya spill yer beans?"
#define TEST_CUSTOM_PACKET_LEN (sizeof(TEST_CUSTOM_PACKET) - 1)
#define TEST_CUSTOM_PACKET_LARGE "Where is it I've read that someone condemned to death says or thinks, an hour before his death, that if he had to live on some high rock, on such a narrow ledge that he'd only room to stand, and the ocean, everlasting darkness, everlasting solitude, everlasting tempest around him, if he had to remain standing on a square yard of space all his life, a thousand years, eternity, it were better to live so than to die at once. Only to live, to live and live! Life, whatever it may be! ...............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................0123456789"
#define TEST_CUSTOM_PACKET_LARGE_LEN (sizeof(TEST_CUSTOM_PACKET_LARGE) - 1)
static_assert(TEST_CUSTOM_PACKET_LARGE_LEN == TOX_GROUP_MAX_CUSTOM_LOSSY_PACKET_LENGTH, "Should be max");
#define TEST_CUSTOM_PRIVATE_PACKET "This is a custom private packet. Enjoy."
#define TEST_CUSTOM_PRIVATE_PACKET_LEN (sizeof(TEST_CUSTOM_PRIVATE_PACKET) - 1)
@ -187,6 +191,21 @@ static void group_custom_packet_handler(Tox *tox, uint32_t groupnumber, uint32_t
++state->custom_packets_received;
}
static void group_custom_packet_large_handler(Tox *tox, uint32_t groupnumber, uint32_t peer_id, const uint8_t *data,
size_t length, void *user_data)
{
ck_assert_msg(length == TEST_CUSTOM_PACKET_LARGE_LEN, "Failed to receive large custom packet. Invalid length: %zu\n", length);
ck_assert(memcmp(data, TEST_CUSTOM_PACKET_LARGE, length) == 0);
AutoTox *autotox = (AutoTox *)user_data;
ck_assert(autotox != nullptr);
State *state = (State *)autotox->state;
++state->custom_packets_received;
}
static void group_message_handler(Tox *tox, uint32_t groupnumber, uint32_t peer_id, TOX_MESSAGE_TYPE type,
const uint8_t *message, size_t length, uint32_t pseudo_msg_id, void *user_data)
{
@ -450,6 +469,19 @@ static void group_message_test(AutoTox *autotoxes)
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
}
// tox0 sends a large max sized lossy custom packet
// overwrite callback for larger packet
tox_callback_group_custom_packet(tox0, group_custom_packet_large_handler);
tox_group_send_custom_packet(tox1, group_number, false, (const uint8_t *)TEST_CUSTOM_PACKET_LARGE, TEST_CUSTOM_PACKET_LARGE_LEN,
&c_err);
ck_assert_msg(c_err == TOX_ERR_GROUP_SEND_CUSTOM_PACKET_OK, "%d", c_err);
while (state0->custom_packets_received < 3) {
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
}
uint8_t m[TOX_GROUP_MAX_MESSAGE_LENGTH] = {0};
fprintf(stderr, "Doing lossless packet test...\n");
@ -538,6 +570,8 @@ int main(void)
#undef TEST_PRIVATE_MESSAGE_LEN
#undef TEST_CUSTOM_PACKET
#undef TEST_CUSTOM_PACKET_LEN
#undef TEST_CUSTOM_PACKET_LARGE
#undef TEST_CUSTOM_PACKET_LARGE_LEN
#undef TEST_CUSTOM_PRIVATE_PACKET
#undef TEST_CUSTOM_PRIVATE_PACKET_LEN
#undef IGNORE_MESSAGE