mirror of
https://github.com/ratspeak/ratdeck.git
synced 2026-03-29 05:39:52 +00:00
Hide unknown hop count, remove hops_to and toHex from transport filter hot path
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include <LittleFS.h>
|
||||
#include <Preferences.h>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
|
||||
bool LittleFSFileSystem::init() { return true; }
|
||||
@@ -116,19 +117,17 @@ bool ReticulumManager::begin(SX1262* radio, FlashStore* flash) {
|
||||
if (++count > maxRate) return false;
|
||||
|
||||
// Skip re-validation of known paths (saves ~100ms Ed25519 per announce)
|
||||
// Allow through if hop count improved, or once per 5 min for name/ratchet updates
|
||||
// Allow through once per 5 min for name/ratchet updates.
|
||||
// Uses raw hash bytes as key (avoids expensive toHex + hops_to per packet).
|
||||
if (RNS::Transport::has_path(packet.destination_hash())) {
|
||||
static std::map<std::string, unsigned long> lastRevalidate;
|
||||
std::string destHex = packet.destination_hash().toHex();
|
||||
static std::unordered_map<std::string, unsigned long> lastRevalidate;
|
||||
std::string key((const char*)packet.destination_hash().data(),
|
||||
packet.destination_hash().size());
|
||||
|
||||
uint8_t existingHops = RNS::Transport::hops_to(packet.destination_hash());
|
||||
if (packet.hops() < existingHops) return true; // Better path, allow
|
||||
|
||||
auto it = lastRevalidate.find(destHex);
|
||||
auto it = lastRevalidate.find(key);
|
||||
if (it != lastRevalidate.end() && (now - it->second) < 300000) return false;
|
||||
lastRevalidate[destHex] = now;
|
||||
lastRevalidate[key] = now;
|
||||
|
||||
// Cap map size to prevent unbounded growth
|
||||
if (lastRevalidate.size() > 300) lastRevalidate.clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -297,7 +297,7 @@ void LvNodesScreen::syncVisibleRows() {
|
||||
// Hops + age + optional RSSI (dev mode)
|
||||
unsigned long ageSec = (millis() - node.lastSeen) / 1000;
|
||||
char infoBuf[32];
|
||||
if (node.hops < 128) {
|
||||
if (node.hops > 0 && node.hops < 128) {
|
||||
if (ageSec < 60) snprintf(infoBuf, sizeof(infoBuf), "%dhop %lus", node.hops, ageSec);
|
||||
else snprintf(infoBuf, sizeof(infoBuf), "%dhop %lum", node.hops, ageSec / 60);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user