From 0d023ea215f2ff21668fe1ae78f9473ac5c9c576 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Tue, 26 Sep 2023 07:02:06 -0500 Subject: [PATCH] Revert "Fix compression (#2806) (#2819)" (#2835) This reverts commit cdac643749ac3b8d91190bec3d1c4b3b539bf156. --- src/mesh/Router.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/mesh/Router.cpp b/src/mesh/Router.cpp index b4c456158..03aa57351 100644 --- a/src/mesh/Router.cpp +++ b/src/mesh/Router.cpp @@ -359,7 +359,6 @@ bool perhapsDecode(meshtastic_MeshPacket *p) // LOG_DEBUG("\n\n**\n\nDecompressed length - %d \n", decompressed_len); memcpy(p->decoded.payload.bytes, decompressed_out, decompressed_len); - p->decoded.payload.size = decompressed_len; // Switch the port from PortNum_TEXT_MESSAGE_COMPRESSED_APP to PortNum_TEXT_MESSAGE_APP p->decoded.portnum = meshtastic_PortNum_TEXT_MESSAGE_APP; @@ -383,7 +382,9 @@ meshtastic_Routing_Error perhapsEncode(meshtastic_MeshPacket *p) // If the packet is not yet encrypted, do so now if (p->which_payload_variant == meshtastic_MeshPacket_decoded_tag) { - // Only allow compression on the text message app. + size_t numbytes = pb_encode_to_bytes(bytes, sizeof(bytes), &meshtastic_Data_msg, &p->decoded); + + // Only allow encryption on the text message app. // TODO: Allow modules to opt into compression. if (p->decoded.portnum == meshtastic_PortNum_TEXT_MESSAGE_APP) { @@ -395,12 +396,17 @@ meshtastic_Routing_Error perhapsEncode(meshtastic_MeshPacket *p) int compressed_len; compressed_len = unishox2_compress_simple(original_payload, p->decoded.payload.size, compressed_out); - LOG_DEBUG("Length - %d, compressed length - %d \n", p->decoded.payload.size, compressed_len); + LOG_DEBUG("Original length - %d \n", p->decoded.payload.size); + LOG_DEBUG("Compressed length - %d \n", compressed_len); LOG_DEBUG("Original message - %s \n", p->decoded.payload.bytes); // If the compressed length is greater than or equal to the original size, don't use the compressed form if (compressed_len >= p->decoded.payload.size) { + LOG_DEBUG("Not using compressing message.\n"); + // Set the uncompressed payload variant anyway. Shouldn't hurt? + // p->decoded.which_payloadVariant = Data_payload_tag; + // Otherwise we use the compressor } else { LOG_DEBUG("Using compressed message.\n"); @@ -413,8 +419,6 @@ meshtastic_Routing_Error perhapsEncode(meshtastic_MeshPacket *p) } } - size_t numbytes = pb_encode_to_bytes(bytes, sizeof(bytes), &meshtastic_Data_msg, &p->decoded); - if (numbytes > MAX_RHPACKETLEN) return meshtastic_Routing_Error_TOO_LARGE;