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

This commit is contained in:
medentem 2025-01-08 21:52:17 -06:00
parent 3bd2e40855
commit 87116837eb
4 changed files with 58 additions and 33 deletions

53
.vscode/settings.json vendored
View File

@ -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"
}
}

View File

@ -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<NodeNum> 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

View File

@ -930,22 +930,6 @@ std::vector<NodeNum> 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 isnt 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;
}
}
}
}

View File

@ -177,11 +177,8 @@ class NodeDB
*/
std::vector<NodeNum> 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);