fix(mqtt-neighbors): report unusable heard ages as null
A neighbour heard before the clock is set carries the firmware's unset-clock
default (1715770351, 15 May 2024). Subtracting that from an NTP-synced clock
published ages of ~806 days for neighbours that had just answered a live scope
query, and a backwards clock step reported 0, i.e. "heard just now".
- finishNeighborDiscover() reports the age as unknown ("heard_secs_ago": null)
when the stored stamp and the current clock come from different epochs, or
when the clock has stepped backwards
- handleNeighborDiscoverResponse() re-stamps heard_timestamp on a zero-hop scope
reply, in both the snapshot and the live table, so entries heal once per
discovery cycle instead of waiting for the neighbour's next advert
- publish ordering places usable ages ahead of unknown ones so a poisoned stamp
cannot displace fresh entries when the JSON buffer truncates
- document the null case, and the always-present total_neighbors /
queried_neighbors / truncated fields the payload sample omitted
- add UPSTREAM_BUGS.md, tracking the monotonic-uptime fix to propose upstream
plus the unclamped subtraction in the companion and CLI readouts
Containment only: upstream still stamps neighbours from the wall clock at
packet-reception time, which on a cold boot always precedes NTP.
This commit is contained in:
1 parent
d8fd3defc4
commit
5828a3c563
11 files changed
+296
-17
No files matched your search
@@ -18,6 +18,10 @@ static const uint32_t kDefaultJwtLifetimeSecs = 86400UL;
|
||||
static const uint32_t kMaxJwtStaggerSecs = 300UL;
|
||||
static const uint32_t kMinimumValidEpoch = 1000000000UL;
|
||||
static const uint32_t kJwtClockThreshold = 1735689600UL; // 2025-01-01 UTC
|
||||
// A wall clock at or past this instant was set from a real source (NTP or an
|
||||
// admin); anything earlier is the firmware's unset-clock default (1715770351,
|
||||
// 15 May 2024), so a delta spanning the sync is meaningless.
|
||||
static const uint32_t kSyncedClockEpoch = kJwtClockThreshold;
|
||||
|
||||
// Unsigned subtraction is intentionally used: it is the standard millis()
|
||||
// idiom and remains correct across a single 32-bit counter rollover.
|
||||
|
||||
@@ -220,7 +220,11 @@ static void addNeighborsMessageEntry(
|
||||
JsonObject nb = arr.add<JsonObject>();
|
||||
nb["pubkey"] = neighbor.pubkey_hex;
|
||||
nb["snr"] = neighbor.snr;
|
||||
nb["heard_secs_ago"] = neighbor.heard_secs_ago;
|
||||
if (neighbor.heard_unknown) {
|
||||
nb["heard_secs_ago"] = nullptr; // age unknown, not zero
|
||||
} else {
|
||||
nb["heard_secs_ago"] = neighbor.heard_secs_ago;
|
||||
}
|
||||
nb["scopes"] = neighbor.scopes ? neighbor.scopes : "";
|
||||
nb["status"] = neighbor.status;
|
||||
}
|
||||
|
||||
@@ -75,6 +75,11 @@ public:
|
||||
uint32_t heard_secs_ago;
|
||||
const char* scopes;
|
||||
const char* status;
|
||||
// True renders heard_secs_ago as JSON null, for a neighbour whose stored
|
||||
// stamp cannot yield an age. No default initializer: the struct stays an
|
||||
// aggregate for the device toolchain, and a zeroed tail means "age known",
|
||||
// so size-measurement callers keep reserving the widest numeric value.
|
||||
bool heard_unknown;
|
||||
};
|
||||
|
||||
// Build neighbors-table JSON for the meshcore/{iata}/{device}/neighbors topic.
|
||||
|
||||
Reference in new issue
Block a user