Skip to content

Commit cd34b60

Browse files
zoff99iphydf
authored andcommitted
feat: allow for larger incoming NGC packets
1 parent 94cf9d1 commit cd34b60

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a5b7485734edb8ce54146f95391d7e14ea9cce4dbc92ded64230e1933a3371e8 /usr/local/bin/tox-bootstrapd
1+
b2996d73cab7c7453dc10ccf7ad733622558de3b1ad0db824a379cf96f500379 /usr/local/bin/tox-bootstrapd

toxcore/group_chats.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,29 @@ static_assert(GCC_BUFFER_SIZE <= UINT16_MAX,
108108
static_assert(MAX_GC_PACKET_CHUNK_SIZE < MAX_GC_PACKET_SIZE,
109109
"MAX_GC_PACKET_CHUNK_SIZE must be < MAX_GC_PACKET_SIZE");
110110

111+
static_assert(MAX_GC_PACKET_INCOMING_CHUNK_SIZE < MAX_GC_PACKET_SIZE,
112+
"MAX_GC_PACKET_INCOMING_CHUNK_SIZE must be < MAX_GC_PACKET_SIZE");
113+
114+
static_assert(MAX_GC_PACKET_INCOMING_CHUNK_SIZE >= MAX_GC_PACKET_CHUNK_SIZE,
115+
"MAX_GC_PACKET_INCOMING_CHUNK_SIZE must be >= MAX_GC_PACKET_CHUNK_SIZE");
116+
111117
// size of a lossless handshake packet - lossless packets can't/shouldn't be split up
112118
static_assert(MAX_GC_PACKET_CHUNK_SIZE >= 171,
113119
"MAX_GC_PACKET_CHUNK_SIZE must be >= 171");
114120

121+
static_assert(MAX_GC_PACKET_INCOMING_CHUNK_SIZE >= 171,
122+
"MAX_GC_PACKET_INCOMING_CHUNK_SIZE must be >= 171");
123+
115124
// group_moderation constants assume this is the max packet size.
116125
static_assert(MAX_GC_PACKET_SIZE >= 50000,
117126
"MAX_GC_PACKET_SIZE doesn't match constants in group_moderation.h");
118127

119128
static_assert(MAX_GC_PACKET_SIZE <= UINT16_MAX - MAX_GC_PACKET_CHUNK_SIZE,
120129
"MAX_GC_PACKET_SIZE must be <= UINT16_MAX - MAX_GC_PACKET_CHUNK_SIZE");
121130

131+
static_assert(MAX_GC_PACKET_SIZE <= UINT16_MAX - MAX_GC_PACKET_INCOMING_CHUNK_SIZE,
132+
"MAX_GC_PACKET_SIZE must be <= UINT16_MAX - MAX_GC_PACKET_INCOMING_CHUNK_SIZE");
133+
122134
/** Types of broadcast messages. */
123135
typedef enum Group_Message_Type {
124136
GC_MESSAGE_TYPE_NORMAL = 0x00,
@@ -6255,13 +6267,13 @@ static int handle_gc_tcp_packet(void *object, int id, const uint8_t *packet, uin
62556267

62566268
if (length <= MIN_TCP_PACKET_SIZE) {
62576269
LOGGER_WARNING(m->log, "Got tcp packet with invalid length: %u (expected %u to %u)", length,
6258-
MIN_TCP_PACKET_SIZE, MAX_GC_PACKET_CHUNK_SIZE + MIN_TCP_PACKET_SIZE + ENC_PUBLIC_KEY_SIZE);
6270+
MIN_TCP_PACKET_SIZE, MAX_GC_PACKET_INCOMING_CHUNK_SIZE + MIN_TCP_PACKET_SIZE + ENC_PUBLIC_KEY_SIZE);
62596271
return -1;
62606272
}
62616273

6262-
if (length > MAX_GC_PACKET_CHUNK_SIZE + MIN_TCP_PACKET_SIZE + ENC_PUBLIC_KEY_SIZE) {
6274+
if (length > MAX_GC_PACKET_INCOMING_CHUNK_SIZE + MIN_TCP_PACKET_SIZE + ENC_PUBLIC_KEY_SIZE) {
62636275
LOGGER_WARNING(m->log, "Got tcp packet with invalid length: %u (expected %u to %u)", length,
6264-
MIN_TCP_PACKET_SIZE, MAX_GC_PACKET_CHUNK_SIZE + MIN_TCP_PACKET_SIZE + ENC_PUBLIC_KEY_SIZE);
6276+
MIN_TCP_PACKET_SIZE, MAX_GC_PACKET_INCOMING_CHUNK_SIZE + MIN_TCP_PACKET_SIZE + ENC_PUBLIC_KEY_SIZE);
62656277
return -1;
62666278
}
62676279

@@ -6336,13 +6348,13 @@ static int handle_gc_tcp_oob_packet(void *object, const uint8_t *public_key, uns
63366348

63376349
if (length <= GC_MIN_HS_PACKET_PAYLOAD_SIZE) {
63386350
LOGGER_WARNING(m->log, "Got tcp oob packet with invalid length: %u (expected %u to %u)", length,
6339-
GC_MIN_HS_PACKET_PAYLOAD_SIZE, MAX_GC_PACKET_CHUNK_SIZE + CRYPTO_MAC_SIZE + CRYPTO_NONCE_SIZE);
6351+
GC_MIN_HS_PACKET_PAYLOAD_SIZE, MAX_GC_PACKET_INCOMING_CHUNK_SIZE + CRYPTO_MAC_SIZE + CRYPTO_NONCE_SIZE);
63406352
return -1;
63416353
}
63426354

6343-
if (length > MAX_GC_PACKET_CHUNK_SIZE + CRYPTO_MAC_SIZE + CRYPTO_NONCE_SIZE) {
6355+
if (length > MAX_GC_PACKET_INCOMING_CHUNK_SIZE + CRYPTO_MAC_SIZE + CRYPTO_NONCE_SIZE) {
63446356
LOGGER_WARNING(m->log, "Got tcp oob packet with invalid length: %u (expected %u to %u)", length,
6345-
GC_MIN_HS_PACKET_PAYLOAD_SIZE, MAX_GC_PACKET_CHUNK_SIZE + CRYPTO_MAC_SIZE + CRYPTO_NONCE_SIZE);
6357+
GC_MIN_HS_PACKET_PAYLOAD_SIZE, MAX_GC_PACKET_INCOMING_CHUNK_SIZE + CRYPTO_MAC_SIZE + CRYPTO_NONCE_SIZE);
63466358
return -1;
63476359
}
63486360

@@ -6392,13 +6404,13 @@ static int handle_gc_udp_packet(void *object, const IP_Port *ipp, const uint8_t
63926404

63936405
if (length <= MIN_UDP_PACKET_SIZE) {
63946406
LOGGER_WARNING(m->log, "Got UDP packet with invalid length: %u (expected %u to %u)", length,
6395-
MIN_UDP_PACKET_SIZE, MAX_GC_PACKET_CHUNK_SIZE + MIN_UDP_PACKET_SIZE + ENC_PUBLIC_KEY_SIZE);
6407+
MIN_UDP_PACKET_SIZE, MAX_GC_PACKET_INCOMING_CHUNK_SIZE + MIN_UDP_PACKET_SIZE + ENC_PUBLIC_KEY_SIZE);
63966408
return -1;
63976409
}
63986410

6399-
if (length > MAX_GC_PACKET_CHUNK_SIZE + MIN_UDP_PACKET_SIZE + ENC_PUBLIC_KEY_SIZE) {
6411+
if (length > MAX_GC_PACKET_INCOMING_CHUNK_SIZE + MIN_UDP_PACKET_SIZE + ENC_PUBLIC_KEY_SIZE) {
64006412
LOGGER_WARNING(m->log, "Got UDP packet with invalid length: %u (expected %u to %u)", length,
6401-
MIN_UDP_PACKET_SIZE, MAX_GC_PACKET_CHUNK_SIZE + MIN_UDP_PACKET_SIZE + ENC_PUBLIC_KEY_SIZE);
6413+
MIN_UDP_PACKET_SIZE, MAX_GC_PACKET_INCOMING_CHUNK_SIZE + MIN_UDP_PACKET_SIZE + ENC_PUBLIC_KEY_SIZE);
64026414
return -1;
64036415
}
64046416

toxcore/group_common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
* For an explanation on why this value was chosen, see the following link: https://archive.ph/vsCOG
2929
*/
3030
#define MAX_GC_PACKET_CHUNK_SIZE 500
31+
/* Max size of an incoming packet chunk that is allowed */
32+
#define MAX_GC_PACKET_INCOMING_CHUNK_SIZE 1372
3133

3234
#define MAX_GC_MESSAGE_SIZE GROUP_MAX_MESSAGE_LENGTH
3335
#define MAX_GC_MESSAGE_RAW_SIZE (MAX_GC_MESSAGE_SIZE + GC_MESSAGE_PSEUDO_ID_SIZE)

toxcore/group_connection.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ static uint16_t reassemble_packet(const Logger *log, GC_Connection *gconn, uint8
366366
// search backwards in recv array until we find an empty slot or a non-fragment packet type
367367
while (!array_entry_is_empty(entry) && entry->packet_type == GP_FRAGMENT) {
368368
assert(entry->data != nullptr);
369-
assert(entry->data_length <= MAX_GC_PACKET_CHUNK_SIZE);
369+
assert(entry->data_length <= MAX_GC_PACKET_INCOMING_CHUNK_SIZE);
370370

371371
const uint16_t diff = packet_length + entry->data_length;
372372

0 commit comments

Comments
 (0)