From 071ad7b3487c35aaf8cc08aa41b63b48821ccc05 Mon Sep 17 00:00:00 2001 From: medentem Date: Fri, 3 Jan 2025 15:06:49 -0600 Subject: [PATCH] updating to most optimal config per simulated testing --- src/mesh/FloodingRouter.cpp | 39 ++++++++++++++++++++++++++----------- src/mesh/MeshTypes.h | 2 +- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/mesh/FloodingRouter.cpp b/src/mesh/FloodingRouter.cpp index b82bb4796..3f729a4aa 100644 --- a/src/mesh/FloodingRouter.cpp +++ b/src/mesh/FloodingRouter.cpp @@ -14,9 +14,9 @@ ErrorCode FloodingRouter::send(meshtastic_MeshPacket *p) { // Add any messages _we_ send to the seen message list (so we will ignore all retransmissions we see) wasSeenRecently(p); // FIXME, move this to a sniffSent method - + CoverageFilter coverage; - // Is there anything upstream of this? + // Is there anything upstream of this? // I think not, but if so, we need to merge coverage. // loadCoverageFilterFromPacket(p, coverage); @@ -92,7 +92,6 @@ bool FloodingRouter::perhapsRebroadcast(const meshtastic_MeshPacket *p) } #endif - CoverageFilter updatedCoverage = incomingCoverage; mergeMyCoverage(updatedCoverage); storeCoverageFilterInPacket(updatedCoverage, tosend); @@ -162,7 +161,8 @@ float FloodingRouter::calculateForwardProbability(const CoverageFilter &incoming { #ifdef USERPREFS_USE_COVERAGE_FILTER bool useCoverageFilter = USERPREFS_USE_COVERAGE_FILTER; - if (!useCoverageFilter) return 1.0f; + if (!useCoverageFilter) + return 1.0f; #endif // If we are a router or repeater, always forward because it's assumed these are in the most advantageous locations if (config.device.role == meshtastic_Config_DeviceConfig_Role_ROUTER || @@ -184,7 +184,8 @@ float FloodingRouter::calculateForwardProbability(const CoverageFilter &incoming int neighbors = 0; for (auto nodeId : recentNeighbors) { // Don't count the person we got this packet from - if (nodeId == from) continue; + if (nodeId == from) + continue; neighbors++; @@ -199,15 +200,31 @@ float FloodingRouter::calculateForwardProbability(const CoverageFilter &incoming if (neighbors > 0) { coverageRatio = static_cast(uncovered) / static_cast(neighbors); } + float forwardProb = BASE_FORWARD_PROB; - // Calculate forwarding probability - float forwardProb = BASE_FORWARD_PROB + (coverageRatio * COVERAGE_SCALE_FACTOR); + /* BEGIN OPTION 1: forward probability is based on coverage ratio and scales up or down + * depending on the extent to which this node provides new coverage + */ + /* END OPTION 1 */ + forwardProb = BASE_FORWARD_PROB + (coverageRatio * COVERAGE_SCALE_FACTOR); - // Clamp probability between 0 and 1 - forwardProb = std::min(std::max(forwardProb, 0.0f), 1.0f); + /* BEGIN OPTION 2: forward probability is piecewise logic: + * - Reduce to BASE_FORWARD_PROB if no new coverage is likely + * (remember false positive rate of bloom filter means a node that think its neighbor is covered when it isnt) + * - If 1 uncovered neighbor, ramp probability up significantly to 0.8 + * - If more than 1 uncovered neighbor, ramp probability up to 1.0 + * if (uncovered == 1) { + * forwardProb = 0.8f; + * } else if (uncovered > 1) { + * forwardProb = 1.0f; + * } + */ + /* END OPTION 2 */∏ - LOG_DEBUG("CoverageRatio=%.2f, ForwardProb=%.2f (Uncovered=%d, Total=%zu)", coverageRatio, forwardProb, uncovered, - neighbors); + // Clamp probability between 0 and 1 + forwardProb = std::min(std::max(forwardProb, 0.0f), 1.0f); + + LOG_DEBUG("CoverageRatio=%.2f, ForwardProb=%.2f (Uncovered=%d, Total=%zu)", coverageRatio, forwardProb, uncovered, neighbors); return forwardProb; } \ No newline at end of file diff --git a/src/mesh/MeshTypes.h b/src/mesh/MeshTypes.h index 8693a6e70..04606a3ca 100644 --- a/src/mesh/MeshTypes.h +++ b/src/mesh/MeshTypes.h @@ -58,7 +58,7 @@ enum RxSource { #define BASE_FORWARD_PROB 0.2f // Coverage scaling factor -#define COVERAGE_SCALE_FACTOR 2.0f +#define COVERAGE_SCALE_FACTOR 4.0f // Recency threshold in minutes // Currently set to 1 hour because that is the minimum interval for nodeinfo broadcasts