Skip to content

Commit 1fce193

Browse files
committed
feat: allow the large custom NGC packets to be handled also by the client
1 parent 6370d0f commit 1fce193

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

toxcore/group_chats.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5020,6 +5020,22 @@ static bool custom_gc_packet_length_is_valid(uint16_t length, bool lossless)
50205020
return true;
50215021
}
50225022

5023+
/** @brief Returns false if a custom incoming (non private) packet is too large. */
5024+
static bool custom_gc_incoming_non_private_packet_length_is_valid(uint16_t length, bool lossless)
5025+
{
5026+
if (lossless) {
5027+
if (length > MAX_GC_CUSTOM_LOSSLESS_INCOMING_ASSEMBLED_PACKET_SIZE) {
5028+
return false;
5029+
}
5030+
} else {
5031+
if (length > MAX_GC_CUSTOM_LOSSY_PACKET_SIZE) {
5032+
return false;
5033+
}
5034+
}
5035+
5036+
return true;
5037+
}
5038+
50235039
int gc_send_custom_private_packet(const GC_Chat *chat, bool lossless, uint32_t peer_id, const uint8_t *message,
50245040
uint16_t length)
50255041
{
@@ -5118,7 +5134,7 @@ non_null(1, 2, 3, 4) nullable(7)
51185134
static int handle_gc_custom_packet(const GC_Session *c, const GC_Chat *chat, const GC_Peer *peer, const uint8_t *data,
51195135
uint16_t length, bool lossless, void *userdata)
51205136
{
5121-
if (!custom_gc_packet_length_is_valid(length, lossless)) {
5137+
if (!custom_gc_incoming_non_private_packet_length_is_valid(length, lossless)) {
51225138
return -1;
51235139
}
51245140

toxcore/group_common.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@
4545
/* Max size of a complete encrypted packet including headers. */
4646
#define MAX_GC_PACKET_SIZE (MAX_GC_PACKET_CHUNK_SIZE * 100)
4747

48+
/* allow incoming NGC custom packets that are non private to be up to the total max size of MAX_GC_PACKET_SIZE
49+
* which is 50000 bytes. the data itself can only be less than that because of NGC header overhead
50+
*/
51+
#define MAX_GC_CUSTOM_LOSSLESS_INCOMING_ASSEMBLED_PACKET_SIZE MAX_GC_PACKET_SIZE
52+
53+
4854
/* Max number of messages to store in the send/recv arrays */
4955
#define GCC_BUFFER_SIZE 8192
5056

0 commit comments

Comments
 (0)