mirror of
https://github.com/meshtastic/firmware.git
synced 2025-02-08 13:41:28 +00:00
Add logic to nodeDB to prefer evicting boring nodes (#4441)
This commit is contained in:
parent
48eee747da
commit
bee959150b
@ -1115,11 +1115,24 @@ meshtastic_NodeInfoLite *NodeDB::getOrCreateMeshNode(NodeNum n)
|
|||||||
// look for oldest node and erase it
|
// look for oldest node and erase it
|
||||||
uint32_t oldest = UINT32_MAX;
|
uint32_t oldest = UINT32_MAX;
|
||||||
int oldestIndex = -1;
|
int oldestIndex = -1;
|
||||||
|
int oldestIndex = -1;
|
||||||
|
int oldestBoringIndex = -1;
|
||||||
for (int i = 1; i < numMeshNodes; i++) {
|
for (int i = 1; i < numMeshNodes; i++) {
|
||||||
|
// Simply the oldest non-favorite node
|
||||||
if (!meshNodes->at(i).is_favorite && meshNodes->at(i).last_heard < oldest) {
|
if (!meshNodes->at(i).is_favorite && meshNodes->at(i).last_heard < oldest) {
|
||||||
oldest = meshNodes->at(i).last_heard;
|
oldest = meshNodes->at(i).last_heard;
|
||||||
oldestIndex = i;
|
oldestIndex = i;
|
||||||
}
|
}
|
||||||
|
// The oldest "boring" node
|
||||||
|
if (!meshNodes->at(i).is_favorite && meshNodes->at(i).user.public_key.size == 0 &&
|
||||||
|
meshNodes->at(i).last_heard < oldestBoring) {
|
||||||
|
oldestBoring = meshNodes->at(i).last_heard;
|
||||||
|
oldestBoringIndex = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// if we found a "boring" node, evict it
|
||||||
|
if (oldestBoringIndex != -1) {
|
||||||
|
oldestIndex = oldestBoringIndex;
|
||||||
}
|
}
|
||||||
// Shove the remaining nodes down the chain
|
// Shove the remaining nodes down the chain
|
||||||
for (int i = oldestIndex; i < numMeshNodes - 1; i++) {
|
for (int i = oldestIndex; i < numMeshNodes - 1; i++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user