From ab5332950c628f5dbbc34c8d08b15b33f70a2564 Mon Sep 17 00:00:00 2001 From: Mike Robbins Date: Fri, 5 Sep 2025 14:26:06 -0700 Subject: [PATCH] Add RadioInterface::shouldRebroadcastEarlyLikeRouter and add CLIENT_BASE condition --- src/mesh/RadioInterface.cpp | 20 ++++++++++++++++++-- src/mesh/RadioInterface.h | 3 +++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/mesh/RadioInterface.cpp b/src/mesh/RadioInterface.cpp index c7b57a36c..1cbee6f47 100644 --- a/src/mesh/RadioInterface.cpp +++ b/src/mesh/RadioInterface.cpp @@ -314,6 +314,23 @@ uint32_t RadioInterface::getTxDelayMsecWeightedWorst(float snr) return (2 * CWmax * slotTimeMsec) + pow_of_2(CWsize) * slotTimeMsec; } +/** Returns true if we should rebroadcast early like a ROUTER */ +bool RadioInterface::shouldRebroadcastEarlyLikeRouter(meshtastic_MeshPacket *p) +{ + // If we are a ROUTER or REPEATER, we always rebroadcast early + if (config.device.role == meshtastic_Config_DeviceConfig_Role_ROUTER || + config.device.role == meshtastic_Config_DeviceConfig_Role_REPEATER) { + return true; + } + + // If we are a CLIENT_BASE and the packet is from or to a favorited node, we should rebroadcast early + if (config.device.role == meshtastic_Config_DeviceConfig_Role_CLIENT_BASE) { + return nodeDB->isFromOrToFavoritedNode(*p); + } + + return false; +} + /** The delay to use when we want to flood a message */ uint32_t RadioInterface::getTxDelayMsecWeighted(float snr, meshtastic_MeshPacket *p) { @@ -322,8 +339,7 @@ uint32_t RadioInterface::getTxDelayMsecWeighted(float snr, meshtastic_MeshPacket uint32_t delay = 0; uint8_t CWsize = getCWsize(snr); // LOG_DEBUG("rx_snr of %f so setting CWsize to:%d", snr, CWsize); - if (config.device.role == meshtastic_Config_DeviceConfig_Role_ROUTER || - config.device.role == meshtastic_Config_DeviceConfig_Role_REPEATER) { + if (shouldRebroadcastEarlyLikeRouter(p)) { delay = random(0, 2 * CWsize) * slotTimeMsec; LOG_DEBUG("rx_snr found in packet. Router: setting tx delay:%d", delay); } else { diff --git a/src/mesh/RadioInterface.h b/src/mesh/RadioInterface.h index 7e36ac442..a89fa33dd 100644 --- a/src/mesh/RadioInterface.h +++ b/src/mesh/RadioInterface.h @@ -180,6 +180,9 @@ class RadioInterface /** The worst-case SNR_based packet delay */ uint32_t getTxDelayMsecWeightedWorst(float snr); + /** Returns true if we should rebroadcast early like a ROUTER */ + bool shouldRebroadcastEarlyLikeRouter(meshtastic_MeshPacket *p); + /** The delay to use when we want to flood a message. Use a weighted scale based on SNR */ uint32_t getTxDelayMsecWeighted(float snr, meshtastic_MeshPacket *p);