Skip to content

Commit 23f47e1

Browse files
committed
feat: allow the large custom NGC packets to be handled also by the client
1 parent 05ce5c1 commit 23f47e1

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
@@ -4993,6 +4993,22 @@ static bool custom_gc_packet_length_is_valid(uint16_t length, bool lossless)
49934993
return true;
49944994
}
49954995

4996+
/** @brief Returns false if a custom incoming (non private) packet is too large. */
4997+
static bool custom_gc_incoming_non_private_packet_length_is_valid(uint16_t length, bool lossless)
4998+
{
4999+
if (lossless) {
5000+
if (length > MAX_GC_CUSTOM_LOSSLESS_INCOMING_ASSEMBLED_PACKET_SIZE) {
5001+
return false;
5002+
}
5003+
} else {
5004+
if (length > MAX_GC_CUSTOM_LOSSY_PACKET_SIZE) {
5005+
return false;
5006+
}
5007+
}
5008+
5009+
return true;
5010+
}
5011+
49965012
int gc_send_custom_private_packet(const GC_Chat *chat, bool lossless, uint32_t peer_id, const uint8_t *message,
49975013
uint16_t length)
49985014
{
@@ -5089,7 +5105,7 @@ non_null(1, 2, 3, 4) nullable(7)
50895105
static int handle_gc_custom_packet(const GC_Session *c, const GC_Chat *chat, const GC_Peer *peer, const uint8_t *data,
50905106
uint16_t length, bool lossless, void *userdata)
50915107
{
5092-
if (!custom_gc_packet_length_is_valid(length, lossless)) {
5108+
if (!custom_gc_incoming_non_private_packet_length_is_valid(length, lossless)) {
50935109
return -1;
50945110
}
50955111

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)