Skip to content

Commit 772a102

Browse files
committed
feat: allow the large custom NGC packets to be handled also by the client
1 parent 9592d59 commit 772a102

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

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

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)