From a4c22321fca6fc8da7bab157c3812055603512ba Mon Sep 17 00:00:00 2001 From: GUVWAF <78759985+GUVWAF@users.noreply.github.com> Date: Sun, 31 Mar 2024 15:03:29 +0200 Subject: [PATCH] Don't save Neighbors to flash when receiving (#3519) * Don't save Neighbors to flash when receiving * Move `shouldSave` to `saveProtoForModule()` --------- Co-authored-by: Ben Meadors --- src/modules/NeighborInfoModule.cpp | 9 +++++---- src/modules/NeighborInfoModule.h | 3 +++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/modules/NeighborInfoModule.cpp b/src/modules/NeighborInfoModule.cpp index 1e9652469..92395ffc5 100644 --- a/src/modules/NeighborInfoModule.cpp +++ b/src/modules/NeighborInfoModule.cpp @@ -114,8 +114,8 @@ size_t NeighborInfoModule::cleanUpNeighbors() (*numNeighbors)--; } - // Save the neighbor list if we removed any neighbors - if (indices_to_remove.size() > 0) { + // Save the neighbor list if we removed any neighbors or neighbors were already updated upon receiving a packet + if (indices_to_remove.size() > 0 || shouldSave) { saveProtoForModule(); } @@ -210,7 +210,6 @@ meshtastic_Neighbor *NeighborInfoModule::getOrCreateNeighbor(NodeNum originalSen // Only if this is the original sender, the broadcast interval corresponds to it if (originalSender == n && node_broadcast_interval_secs != 0) nbr->node_broadcast_interval_secs = node_broadcast_interval_secs; - saveProtoForModule(); // Save the updated neighbor return nbr; } } @@ -228,7 +227,7 @@ meshtastic_Neighbor *NeighborInfoModule::getOrCreateNeighbor(NodeNum originalSen new_nbr->node_broadcast_interval_secs = node_broadcast_interval_secs; else // Assume the same broadcast interval as us for the neighbor if we don't know it new_nbr->node_broadcast_interval_secs = moduleConfig.neighbor_info.update_interval; - saveProtoForModule(); // Save the new neighbor + shouldSave = true; // Save the new neighbor upon next cleanup return new_nbr; } @@ -255,6 +254,8 @@ bool NeighborInfoModule::saveProtoForModule() #endif okay &= nodeDB->saveProto(neighborInfoConfigFile, meshtastic_NeighborInfo_size, &meshtastic_NeighborInfo_msg, &neighborState); + if (okay) + shouldSave = false; return okay; } \ No newline at end of file diff --git a/src/modules/NeighborInfoModule.h b/src/modules/NeighborInfoModule.h index b4acb0f66..d47004981 100644 --- a/src/modules/NeighborInfoModule.h +++ b/src/modules/NeighborInfoModule.h @@ -20,6 +20,9 @@ class NeighborInfoModule : public ProtobufModule, priva bool saveProtoForModule(); + private: + bool shouldSave = false; // Whether we should save the neighbor info to flash + protected: // Note: this holds our local info. meshtastic_NeighborInfo neighborState;