forked from Green-Sky/tomato
Squashed 'external/toxcore/c-toxcore/' changes from 55752a2e2ef..11ab1d2a723
11ab1d2a723 fix: reduce memory usage in group chats by 75% Significantly reduced the memory usage of groups since all message slots are preallocated for every peer for send and receive buffers of buffer size (hundreds of MiB peak when save contained alot of peers to try to connect to) 4f09f4e147c chore: Fix tsan build by moving it to GitHub CI. 6460c25c9e0 refactor: Use `merge_sort` instead of `qsort` for sorting. c660bbe8c95 test: Fix crypto_test to initialise its plain text buffer. 0204db6184b cleanup: Fix layering check warnings. df2211e1548 refactor: Use tox memory allocator for temporary buffers in crypto. ac812871a2e feat: implement the last 2 missing network struct functions and make use of them 29d1043be0b test: friend request test now tests min/max message sizes 93aafd78c1f fix: friend requests with very long messages are no longer dropped 819aa2b2618 feat: Add option to disable DNS lookups in toxcore. 0ac23cee035 fix: windows use of REUSEADDR 7d2811d302d chore(ci): make bazel server shutdown faster 1dc399ba20d chore: Use vcpkg instead of conan in the MSVC build. 14d823165d9 chore: Migrate to conan 2. bdd17c16787 cleanup: Allocate logger using tox memory allocator. b396c061515 chore(deps): bump third_party/cmp from `2ac6bca` to `52bfcfa` 2e94da60d09 feat(net): add missing connect to network struct 41fb1839c7b chore: Add check to ensure version numbers agree. 934a8301113 chore: Release 0.2.20 3acef4bf044 fix: Add missing free in dht_get_nodes_response event. git-subtree-dir: external/toxcore/c-toxcore git-subtree-split: 11ab1d2a7232eee19b51ce126ccce267d6578903
This commit is contained in:
@ -30,6 +30,7 @@
|
||||
#include "group_moderation.h"
|
||||
#include "group_pack.h"
|
||||
#include "logger.h"
|
||||
#include "mem.h"
|
||||
#include "mono_time.h"
|
||||
#include "net_crypto.h"
|
||||
#include "network.h"
|
||||
@ -1473,8 +1474,8 @@ static bool sign_gc_shared_state(GC_Chat *chat)
|
||||
* Return -2 on decryption failure.
|
||||
* Return -3 if plaintext payload length is invalid.
|
||||
*/
|
||||
non_null(1, 2, 3, 5, 6) nullable(4)
|
||||
static int group_packet_unwrap(const Logger *log, const GC_Connection *gconn, uint8_t *data, uint64_t *message_id,
|
||||
non_null(1, 2, 3, 4, 6, 7) nullable(5)
|
||||
static int group_packet_unwrap(const Logger *log, const Memory *mem, const GC_Connection *gconn, uint8_t *data, uint64_t *message_id,
|
||||
uint8_t *packet_type, const uint8_t *packet, uint16_t length)
|
||||
{
|
||||
assert(data != nullptr);
|
||||
@ -1492,7 +1493,7 @@ static int group_packet_unwrap(const Logger *log, const GC_Connection *gconn, ui
|
||||
return -1;
|
||||
}
|
||||
|
||||
int plain_len = decrypt_data_symmetric(gconn->session_shared_key, packet, packet + CRYPTO_NONCE_SIZE,
|
||||
int plain_len = decrypt_data_symmetric(mem, gconn->session_shared_key, packet, packet + CRYPTO_NONCE_SIZE,
|
||||
length - CRYPTO_NONCE_SIZE, plain);
|
||||
|
||||
if (plain_len <= 0) {
|
||||
@ -1533,7 +1534,7 @@ static int group_packet_unwrap(const Logger *log, const GC_Connection *gconn, ui
|
||||
}
|
||||
|
||||
int group_packet_wrap(
|
||||
const Logger *log, const Random *rng, const uint8_t *self_pk, const uint8_t *shared_key, uint8_t *packet,
|
||||
const Logger *log, const Memory *mem, const Random *rng, const uint8_t *self_pk, const uint8_t *shared_key, uint8_t *packet,
|
||||
uint16_t packet_size, const uint8_t *data, uint16_t length, uint64_t message_id,
|
||||
uint8_t gp_packet_type, Net_Packet_Type net_packet_type)
|
||||
{
|
||||
@ -1588,7 +1589,7 @@ int group_packet_wrap(
|
||||
return -2;
|
||||
}
|
||||
|
||||
const int enc_len = encrypt_data_symmetric(shared_key, nonce, plain, plain_len, encrypt);
|
||||
const int enc_len = encrypt_data_symmetric(mem, shared_key, nonce, plain, plain_len, encrypt);
|
||||
|
||||
free(plain);
|
||||
|
||||
@ -1634,7 +1635,7 @@ static bool send_lossy_group_packet(const GC_Chat *chat, const GC_Connection *gc
|
||||
}
|
||||
|
||||
const int len = group_packet_wrap(
|
||||
chat->log, chat->rng, chat->self_public_key.enc, gconn->session_shared_key, packet,
|
||||
chat->log, chat->mem, chat->rng, chat->self_public_key.enc, gconn->session_shared_key, packet,
|
||||
packet_size, data, length, 0, packet_type, NET_PACKET_GC_LOSSY);
|
||||
|
||||
if (len < 0) {
|
||||
@ -5508,7 +5509,7 @@ static int handle_gc_broadcast(const GC_Session *c, GC_Chat *chat, uint32_t peer
|
||||
* Return -2 if decryption fails.
|
||||
*/
|
||||
non_null()
|
||||
static int unwrap_group_handshake_packet(const Logger *log, const uint8_t *self_sk, const uint8_t *sender_pk,
|
||||
static int unwrap_group_handshake_packet(const Logger *log, const Memory *mem, const uint8_t *self_sk, const uint8_t *sender_pk,
|
||||
uint8_t *plain, size_t plain_size, const uint8_t *packet, uint16_t length)
|
||||
{
|
||||
if (length <= CRYPTO_NONCE_SIZE) {
|
||||
@ -5516,7 +5517,7 @@ static int unwrap_group_handshake_packet(const Logger *log, const uint8_t *self_
|
||||
return -1;
|
||||
}
|
||||
|
||||
const int plain_len = decrypt_data(sender_pk, self_sk, packet, packet + CRYPTO_NONCE_SIZE,
|
||||
const int plain_len = decrypt_data(mem, sender_pk, self_sk, packet, packet + CRYPTO_NONCE_SIZE,
|
||||
length - CRYPTO_NONCE_SIZE, plain);
|
||||
|
||||
if (plain_len < 0 || (uint32_t)plain_len != plain_size) {
|
||||
@ -5539,7 +5540,7 @@ static int unwrap_group_handshake_packet(const Logger *log, const uint8_t *self_
|
||||
*/
|
||||
non_null()
|
||||
static int wrap_group_handshake_packet(
|
||||
const Logger *log, const Random *rng, const uint8_t *self_pk, const uint8_t *self_sk,
|
||||
const Logger *log, const Memory *mem, const Random *rng, const uint8_t *self_pk, const uint8_t *self_sk,
|
||||
const uint8_t *target_pk, uint8_t *packet, uint32_t packet_size,
|
||||
const uint8_t *data, uint16_t length)
|
||||
{
|
||||
@ -5558,7 +5559,7 @@ static int wrap_group_handshake_packet(
|
||||
return -2;
|
||||
}
|
||||
|
||||
const int enc_len = encrypt_data(target_pk, self_sk, nonce, data, length, encrypt);
|
||||
const int enc_len = encrypt_data(mem, target_pk, self_sk, nonce, data, length, encrypt);
|
||||
|
||||
if (enc_len < 0 || (size_t)enc_len != encrypt_buf_size) {
|
||||
LOGGER_ERROR(log, "Failed to encrypt group handshake packet (len: %d)", enc_len);
|
||||
@ -5622,7 +5623,7 @@ static int make_gc_handshake_packet(const GC_Chat *chat, const GC_Connection *gc
|
||||
}
|
||||
|
||||
const int enc_len = wrap_group_handshake_packet(
|
||||
chat->log, chat->rng, chat->self_public_key.enc, chat->self_secret_key.enc,
|
||||
chat->log, chat->mem, chat->rng, chat->self_public_key.enc, chat->self_secret_key.enc,
|
||||
gconn->addr.public_key.enc, packet, (uint16_t)packet_size, data, length);
|
||||
|
||||
if (enc_len != GC_MIN_ENCRYPTED_HS_PAYLOAD_SIZE + nodes_size) {
|
||||
@ -5951,7 +5952,7 @@ static int handle_gc_handshake_packet(GC_Chat *chat, const uint8_t *sender_pk, c
|
||||
return -1;
|
||||
}
|
||||
|
||||
const int plain_len = unwrap_group_handshake_packet(chat->log, chat->self_secret_key.enc, sender_pk, data,
|
||||
const int plain_len = unwrap_group_handshake_packet(chat->log, chat->mem, chat->self_secret_key.enc, sender_pk, data,
|
||||
data_buf_size, packet, length);
|
||||
|
||||
if (plain_len < GC_MIN_HS_PACKET_PAYLOAD_SIZE) {
|
||||
@ -6181,7 +6182,7 @@ static bool handle_gc_lossless_packet(const GC_Session *c, GC_Chat *chat, const
|
||||
uint8_t packet_type;
|
||||
uint64_t message_id;
|
||||
|
||||
const int len = group_packet_unwrap(chat->log, gconn, data, &message_id, &packet_type, packet, length);
|
||||
const int len = group_packet_unwrap(chat->log, chat->mem, gconn, data, &message_id, &packet_type, packet, length);
|
||||
|
||||
if (len < 0) {
|
||||
Ip_Ntoa ip_str;
|
||||
@ -6334,7 +6335,7 @@ static bool handle_gc_lossy_packet(const GC_Session *c, GC_Chat *chat, const uin
|
||||
|
||||
uint8_t packet_type;
|
||||
|
||||
const int len = group_packet_unwrap(chat->log, gconn, data, nullptr, &packet_type, packet, length);
|
||||
const int len = group_packet_unwrap(chat->log, chat->mem, gconn, data, nullptr, &packet_type, packet, length);
|
||||
|
||||
if (len <= 0) {
|
||||
Ip_Ntoa ip_str;
|
||||
|
Reference in New Issue
Block a user