From 87116837eb5eda31aef8e361a4b3eaf0e7952ece Mon Sep 17 00:00:00 2001 From: medentem Date: Wed, 8 Jan 2025 21:52:17 -0600 Subject: [PATCH] every packet now contains direct neighbor nodeid. max last heard is removed because it is no longer needed. if we think we have no coverage, we fallback to the uncertain coverage rebroadcast probability --- .vscode/settings.json | 53 +++++++++++++++++++++++++++++++++++++ src/mesh/FloodingRouter.cpp | 11 +++----- src/mesh/NodeDB.cpp | 22 --------------- src/mesh/NodeDB.h | 5 +--- 4 files changed, 58 insertions(+), 33 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index bf9b82111..f2eeb22a3 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,5 +7,58 @@ "cmake.configureOnOpen": false, "[cpp]": { "editor.defaultFormatter": "trunk.io" + }, + "files.associations": { + "array": "cpp", + "atomic": "cpp", + "*.tcc": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "csignal": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "list": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "map": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "string": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "new": "cpp", + "ostream": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "cinttypes": "cpp", + "typeinfo": "cpp" } } diff --git a/src/mesh/FloodingRouter.cpp b/src/mesh/FloodingRouter.cpp index fa23802c2..38ec151bf 100644 --- a/src/mesh/FloodingRouter.cpp +++ b/src/mesh/FloodingRouter.cpp @@ -173,18 +173,15 @@ float FloodingRouter::calculateForwardProbability(const CoverageFilter &incoming return 1.0f; } - // If we haven't heard from any other nodes directly within the stale coverage time, fall back to always forward - if (nodeDB->secondsSinceLastDirectNeighborHeard() >= STALE_COVERAGE_SECONDS) { - return UNKNOWN_COVERAGE_FORWARD_PROB; - } - // Retrieve recent direct neighbors within the time window std::vector recentNeighbors = nodeDB->getCoveredNodes(RECENCY_THRESHOLD_MINUTES * 60); if (recentNeighbors.empty()) { - // No neighbors to add coverage for + // Having no direct neighbors is a sign that our coverage is + // inconclusive, so we should forward the packet using UNKNOWN_COVERAGE_FORWARD_PROB + // And if we truly have no neighbors, there is no harm in emitting another packet LOG_DEBUG("No recent direct neighbors to add coverage for."); - return 0.0f; + return UNKNOWN_COVERAGE_FORWARD_PROB; } // Count how many neighbors are NOT yet in the coverage diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 34192df78..3c84a4424 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -930,22 +930,6 @@ std::vector NodeDB::getCoveredNodes(uint32_t timeWindowSecs) return recentNeighbors; } -uint32_t NodeDB::secondsSinceLastDirectNeighborHeard() -{ - // If maxLastHeardDirectNeighbor_ == 0, we have not heard from any direct neighbors - if (maxLastHeardDirectNeighbor_ == 0) { - return UINT32_MAX; - } - - uint32_t now = getTime(); - // If the clock isn’t set or has jumped backwards, clamp to 0 - if (now < maxLastHeardDirectNeighbor_) { - return 0; - } - - return (now - maxLastHeardDirectNeighbor_); -} - void NodeDB::cleanupMeshDB() { int newPos = 0, removed = 0; @@ -954,9 +938,6 @@ void NodeDB::cleanupMeshDB() for (int i = 0; i < numMeshNodes; i++) { if (meshNodes->at(i).has_user) { - if (meshNodes->at(i).last_heard > maxLastHeardDirectNeighbor_) { - maxLastHeardDirectNeighbor_ = meshNodes->at(i).last_heard; - } if (meshNodes->at(i).user.public_key.size > 0) { if (memfll(meshNodes->at(i).user.public_key.bytes, 0, meshNodes->at(i).user.public_key.size)) { meshNodes->at(i).user.public_key.size = 0; @@ -1559,9 +1540,6 @@ void NodeDB::updateFrom(const meshtastic_MeshPacket &mp) if (mp.hop_start != 0 && mp.hop_limit <= mp.hop_start) { info->has_hops_away = true; info->hops_away = mp.hop_start - mp.hop_limit; - if (info->hops_away == 0 && info->last_heard && info->last_heard > maxLastHeardDirectNeighbor_) { - maxLastHeardDirectNeighbor_ = info->last_heard; - } } } } diff --git a/src/mesh/NodeDB.h b/src/mesh/NodeDB.h index d23f759c1..6f9f1c3f0 100644 --- a/src/mesh/NodeDB.h +++ b/src/mesh/NodeDB.h @@ -177,11 +177,8 @@ class NodeDB */ std::vector getCoveredNodes(uint32_t timeWindowSecs); - uint32_t secondsSinceLastDirectNeighborHeard(); - private: - uint32_t lastNodeDbSave = 0; // when we last saved our db to flash - uint32_t maxLastHeardDirectNeighbor_ = 0; // the most recent last_heard value we've seen + uint32_t lastNodeDbSave = 0; // when we last saved our db to flash /// Find a node in our DB, create an empty NodeInfoLite if missing meshtastic_NodeInfoLite *getOrCreateMeshNode(NodeNum n);