From 7b4f5fa418cae3beceeb3c2b7220439901ed0f4d Mon Sep 17 00:00:00 2001 From: medentem Date: Tue, 7 Jan 2025 14:52:12 -0600 Subject: [PATCH] if we have no knowledge of a direct neighbor yet, we fallback to broadcast --- src/mesh/FloodingRouter.cpp | 4 ++-- src/mesh/NodeDB.cpp | 20 ++++++++++---------- src/mesh/NodeDB.h | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/mesh/FloodingRouter.cpp b/src/mesh/FloodingRouter.cpp index 85b620efe..81098fbca 100644 --- a/src/mesh/FloodingRouter.cpp +++ b/src/mesh/FloodingRouter.cpp @@ -168,10 +168,10 @@ float FloodingRouter::calculateForwardProbability(const CoverageFilter &incoming return 1.0f; #endif // If we are a router or repeater, always forward because it's assumed these are in the most advantageous locations - // or if we haven't heard from any other nodes within the stale coverage time, fall back to always forward + // or if we haven't heard from any other nodes directly within the stale coverage time, fall back to always forward if (config.device.role == meshtastic_Config_DeviceConfig_Role_ROUTER || config.device.role == meshtastic_Config_DeviceConfig_Role_REPEATER || - nodeDB->secondsSinceLastNodeHeard() >= STALE_COVERAGE_SECONDS) { + nodeDB->secondsSinceLastDirectNeighborHeard() >= STALE_COVERAGE_SECONDS) { return 1.0f; } diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index a43c6f87b..9b67f26fa 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -936,20 +936,20 @@ std::vector NodeDB::getCoveredNodes(uint32_t timeWindowSecs) return recentNeighbors; } -uint32_t NodeDB::secondsSinceLastNodeHeard() +uint32_t NodeDB::secondsSinceLastDirectNeighborHeard() { - // If maxLastHeard_ == 0, we have not heard from any remote node - if (maxLastHeard_ == 0) { + // 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 < maxLastHeard_) { + if (now < maxLastHeardDirectNeighbor_) { return 0; } - return (now - maxLastHeard_); + return (now - maxLastHeardDirectNeighbor_); } void NodeDB::cleanupMeshDB() @@ -960,8 +960,8 @@ void NodeDB::cleanupMeshDB() for (int i = 0; i < numMeshNodes; i++) { if (meshNodes->at(i).has_user) { - if (meshNodes->at(i).last_heard > maxLastHeard_) { - maxLastHeard_ = meshNodes->at(i).last_heard; + if (meshNodes->at(i).has_hops_away && meshNodes->at(i).hops_away == 0 && 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)) { @@ -1554,9 +1554,6 @@ void NodeDB::updateFrom(const meshtastic_MeshPacket &mp) if (mp.rx_time) { // if the packet has a valid timestamp use it to update our last_heard info->last_heard = mp.rx_time; - if (info->last_heard > maxLastHeard_) { - maxLastHeard_ = info->last_heard; - } } if (mp.rx_snr) @@ -1568,6 +1565,9 @@ 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 a554e546d..8caa5ce1f 100644 --- a/src/mesh/NodeDB.h +++ b/src/mesh/NodeDB.h @@ -177,11 +177,11 @@ class NodeDB */ std::vector getCoveredNodes(uint32_t timeWindowSecs); - uint32_t secondsSinceLastNodeHeard(); + uint32_t secondsSinceLastDirectNeighborHeard(); private: uint32_t lastNodeDbSave = 0; // when we last saved our db to flash - uint32_t maxLastHeard_ = 0; // the most recent last_heard value we've seen + uint32_t maxLastHeardDirectNeighbor_ = 0; // the most recent last_heard value we've seen /// Find a node in our DB, create an empty NodeInfoLite if missing meshtastic_NodeInfoLite *getOrCreateMeshNode(NodeNum n);