mirror of
https://github.com/meshtastic/firmware.git
synced 2025-09-04 10:38:57 +00:00
if we have no knowledge of a direct neighbor yet, we fallback to broadcast
This commit is contained in:
parent
163f1de6aa
commit
7b4f5fa418
@ -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;
|
||||
}
|
||||
|
||||
|
@ -936,20 +936,20 @@ std::vector<NodeNum> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -177,11 +177,11 @@ class NodeDB
|
||||
*/
|
||||
std::vector<NodeNum> 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);
|
||||
|
Loading…
Reference in New Issue
Block a user