From 5b299f3ede82fae0a14b37c320ae2bf77986a5c3 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Wed, 17 Dec 2025 12:03:29 -0600 Subject: [PATCH] Prep work for better Store and Forward (#8999) * make channels.h getHash public * router.* make the encrypted packet copy available for modules to access * Update src/mesh/Router.h Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Set p_encrypted to nullptr after release --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/mesh/Channels.h | 4 ++-- src/mesh/Router.cpp | 3 ++- src/mesh/Router.h | 3 +++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/mesh/Channels.h b/src/mesh/Channels.h index b53f552fa..a3cc7791c 100644 --- a/src/mesh/Channels.h +++ b/src/mesh/Channels.h @@ -96,6 +96,8 @@ class Channels bool setDefaultPresetCryptoForHash(ChannelHash channelHash); + int16_t getHash(ChannelIndex i) { return hashes[i]; } + private: /** Given a channel index, change to use the crypto key specified by that index * @@ -113,8 +115,6 @@ class Channels */ int16_t generateHash(ChannelIndex channelNum); - int16_t getHash(ChannelIndex i) { return hashes[i]; } - /** * Validate a channel, fixing any errors as needed */ diff --git a/src/mesh/Router.cpp b/src/mesh/Router.cpp index ad0c0be6f..47ed0c85a 100644 --- a/src/mesh/Router.cpp +++ b/src/mesh/Router.cpp @@ -692,7 +692,7 @@ void Router::handleReceived(meshtastic_MeshPacket *p, RxSource src) // Store a copy of encrypted packet for MQTT DEBUG_HEAP_BEFORE; - meshtastic_MeshPacket *p_encrypted = packetPool.allocCopy(*p); + p_encrypted = packetPool.allocCopy(*p); DEBUG_HEAP_AFTER("Router::handleReceived", p_encrypted); // Take those raw bytes and convert them back into a well structured protobuf we can understand @@ -758,6 +758,7 @@ void Router::handleReceived(meshtastic_MeshPacket *p, RxSource src) } packetPool.release(p_encrypted); // Release the encrypted packet + p_encrypted = nullptr; } void Router::perhapsHandleReceived(meshtastic_MeshPacket *p) diff --git a/src/mesh/Router.h b/src/mesh/Router.h index 10a3771a7..dbe6f4f39 100644 --- a/src/mesh/Router.h +++ b/src/mesh/Router.h @@ -91,6 +91,9 @@ class Router : protected concurrency::OSThread, protected PacketHistory before us */ uint32_t rxDupe = 0, txRelayCanceled = 0; + // pointer to the encrypted packet + meshtastic_MeshPacket *p_encrypted = nullptr; + protected: friend class RoutingModule;