From 22dce23aa41b0fad461212c9aa58ca3f63228b25 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 17 Oct 2025 10:15:24 -0700 Subject: [PATCH] Changes retransmit delay to not longer use buckets --- examples/simple_repeater/MyMesh.cpp | 19 +++++++++++++++++-- src/Mesh.cpp | 4 +++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/examples/simple_repeater/MyMesh.cpp b/examples/simple_repeater/MyMesh.cpp index 4bb9a2bbe..712ffb682 100644 --- a/examples/simple_repeater/MyMesh.cpp +++ b/examples/simple_repeater/MyMesh.cpp @@ -396,12 +396,27 @@ int MyMesh::calcRxDelay(float score, uint32_t air_time) const { } uint32_t MyMesh::getRetransmitDelay(const mesh::Packet *packet) { + if(_prefs.tx_delay_factor == 0) { + MESH_DEBUG_PRINTLN("getRetransmitDelay: Total tx delay: %d", _prefs.tx_delay_factor); + return 5; + } + uint32_t t = (_radio->getEstAirtimeFor(packet->path_len + packet->payload_len + 2) * _prefs.tx_delay_factor); - return getRNG()->nextInt(0, 6) * t; + uint32_t total_delay = getRNG()->nextInt(5, t); + MESH_DEBUG_PRINTLN("getRetransmitDelay: Total tx delay: %d", total_delay); + return total_delay; } + uint32_t MyMesh::getDirectRetransmitDelay(const mesh::Packet *packet) { + if(_prefs.direct_tx_delay_factor == 0) { + MESH_DEBUG_PRINTLN("getDirectRetransmitDelay: Total tx delay: %d", _prefs.direct_tx_delay_factor); + return 5; + } + uint32_t t = (_radio->getEstAirtimeFor(packet->path_len + packet->payload_len + 2) * _prefs.direct_tx_delay_factor); - return getRNG()->nextInt(0, 6) * t; + uint32_t total_delay = getRNG()->nextInt(5, t); + MESH_DEBUG_PRINTLN("getDirectRetransmitDelay: Total tx delay: %d", total_delay); + return total_delay; } void MyMesh::onAnonDataRecv(mesh::Packet *packet, const uint8_t *secret, const mesh::Identity &sender, diff --git a/src/Mesh.cpp b/src/Mesh.cpp index b055d8114..8925a3765 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -17,7 +17,9 @@ bool Mesh::allowPacketForward(const mesh::Packet* packet) { uint32_t Mesh::getRetransmitDelay(const mesh::Packet* packet) { uint32_t t = (_radio->getEstAirtimeFor(packet->getRawLength()) * 52 / 50) / 2; - return _rng->nextInt(0, 5)*t; + uint32_t total_delay = getRNG()->nextInt(5, t); + MESH_DEBUG_PRINTLN("getRetransmitDelay: Total tx delay: %d", total_delay); + return total_delay; } uint32_t Mesh::getDirectRetransmitDelay(const Packet* packet) { return 0; // by default, no delay