ui: fix stale peer age display

This commit is contained in:
DeFiDude
2026-05-04 02:11:30 -06:00
parent c4e5610408
commit e87cef3fb3
5 changed files with 23 additions and 32 deletions
+10 -9
View File
@@ -150,7 +150,8 @@ void AnnounceManager::received_announce(
auto it = _hashIndex.find(key);
if (it != _hashIndex.end()) {
auto& node = _nodes[it->second];
if (now - node.lastSeen < ANNOUNCE_MIN_INTERVAL_MS) return;
if (node.lastSeen != 0 && now >= node.lastSeen &&
now - node.lastSeen < ANNOUNCE_MIN_INTERVAL_MS) return;
if (!name.empty()) node.name = name;
if (!idHex.empty()) node.identityHex = idHex;
node.lastSeen = now;
@@ -253,7 +254,7 @@ int AnnounceManager::nodesOnlineSince(unsigned long maxAgeMs) const {
unsigned long now = millis();
int count = 0;
for (const auto& n : _nodes) {
if (now - n.lastSeen <= maxAgeMs) count++;
if (n.lastSeen != 0 && now >= n.lastSeen && now - n.lastSeen <= maxAgeMs) count++;
}
return count;
}
@@ -307,7 +308,7 @@ void AnnounceManager::evictStale(unsigned long maxAgeMs) {
unsigned long now = millis();
_nodes.erase(std::remove_if(_nodes.begin(), _nodes.end(),
[now, maxAgeMs](const DiscoveredNode& n) {
return !n.saved && (now - n.lastSeen > maxAgeMs);
return !n.saved && (n.lastSeen == 0 || now < n.lastSeen || now - n.lastSeen > maxAgeMs);
}), _nodes.end());
rebuildIndex();
}
@@ -343,8 +344,6 @@ void AnnounceManager::saveContact(const DiscoveredNode& node) {
std::string hexHash = node.hash.toHex();
JsonDocument doc;
doc["hash"] = hexHash; doc["name"] = node.name;
doc["rssi"] = node.rssi; doc["snr"] = node.snr;
doc["hops"] = node.hops; doc["lastSeen"] = node.lastSeen;
String json;
serializeJson(doc, json);
String filename = hexHash.substr(0, 16).c_str();
@@ -392,10 +391,12 @@ void AnnounceManager::loadContacts() {
node.hash = hash;
node.name = sanitizeName(doc["name"] | "");
if (node.name.empty()) node.name = hexHash.substr(0, 12);
node.rssi = doc["rssi"] | 0;
node.snr = doc["snr"] | 0.0f;
node.hops = doc["hops"] | 0;
node.lastSeen = doc["lastSeen"] | (unsigned long)millis();
// Contacts persist address-book data only. Radio/path state
// is boot-relative and becomes misleading after restart.
node.rssi = 0;
node.snr = 0.0f;
node.hops = 0;
node.lastSeen = 0;
node.saved = true;
_hashIndex[key] = (int)_nodes.size();
_nodes.push_back(node);