Add observed login path commands

This commit is contained in:
mikecarper committed 2026-09-02 19:23:56 -07:00
1 parent 66894f9958
commit ef92505429
8 files changed
+302 -24

No files matched your search

+2
View File
@@ -461,6 +461,7 @@ void ClientACL::load(FILESYSTEM* fs, const mesh::LocalIdentity& self_id) {
memset(&c, 0, sizeof(c));
c.alt_path_len = OUT_PATH_UNKNOWN;
c.observed_path_len = OUT_PATH_UNKNOWN;
bool success = (file.read(pub_key, 32) == 32);
success = success && (file.read((uint8_t *) &c.permissions, 1) == 1);
@@ -694,6 +695,7 @@ ClientInfo* ClientACL::putClient(const mesh::Identity& id, uint8_t init_perms) {
c->out_path_len = OUT_PATH_UNKNOWN;
c->out_path_is_persistable = true;
c->alt_path_len = OUT_PATH_UNKNOWN;
c->observed_path_len = OUT_PATH_UNKNOWN;
return c;
}
+4
View File
@@ -23,6 +23,10 @@ struct ClientInfo {
bool out_path_is_persistable; // live route may replace, but not erase, durable route
uint8_t alt_path_len;
uint8_t alt_path[MAX_PATH_SIZE];
uint8_t observed_path_len; // reciprocal login PATH (transient)
uint8_t observed_path[MAX_PATH_SIZE];
bool observed_path_pending;
uint32_t observed_path_expiry;
uint8_t shared_secret[PUB_KEY_SIZE];
uint32_t last_timestamp; // by THEIR clock (exact live floor; reserved ceiling after load)
uint32_t last_activity; // by OUR clock (transient)
+93
View File
@@ -0,0 +1,93 @@
#pragma once
#include <stddef.h>
#include <stdint.h>
#include <string.h>
namespace mesh {
inline size_t observedClientPathByteLength(uint8_t encoded_path_len) {
const size_t hash_count = encoded_path_len & 63U;
const size_t hash_size = (encoded_path_len >> 6) + 1U;
return hash_count * hash_size;
}
inline bool isValidObservedClientPathLength(uint8_t encoded_path_len,
size_t capacity) {
const size_t hash_size = (encoded_path_len >> 6) + 1U;
return hash_size != 4U
&& observedClientPathByteLength(encoded_path_len) <= capacity;
}
template <typename Client>
void clearObservedClientPath(Client& client, uint8_t unknown_path) {
memset(client.observed_path, 0, sizeof(client.observed_path));
client.observed_path_len = unknown_path;
client.observed_path_pending = false;
client.observed_path_expiry = 0;
}
template <typename Client>
void beginObservedClientPath(Client& client, uint8_t unknown_path,
uint32_t expiry) {
clearObservedClientPath(client, unknown_path);
client.observed_path_pending = true;
client.observed_path_expiry = expiry;
}
template <typename Client>
bool isObservedClientPathPending(Client& client, uint32_t now) {
if (!client.observed_path_pending) return false;
if (static_cast<int32_t>(now - client.observed_path_expiry) < 0) return true;
client.observed_path_pending = false;
client.observed_path_expiry = 0;
return false;
}
// Keep the most recently received, authenticated PAYLOAD_TYPE_PATH separate
// from the selected output route so CLI reads never need to mutate out_path.
template <typename Client>
bool captureObservedClientPath(Client& client, const uint8_t* path,
uint8_t encoded_path_len, uint32_t now) {
if (!isObservedClientPathPending(client, now)) return false;
const size_t path_bytes = observedClientPathByteLength(encoded_path_len);
if (!isValidObservedClientPathLength(
encoded_path_len, sizeof(client.observed_path))
|| (path_bytes != 0 && path == NULL)) {
return false;
}
memset(client.observed_path, 0, sizeof(client.observed_path));
if (path_bytes != 0) {
memcpy(client.observed_path, path, path_bytes);
}
client.observed_path_len = encoded_path_len;
client.observed_path_pending = false;
client.observed_path_expiry = 0;
return true;
}
// Promote a previously observed PATH to the selected output route. Invalid
// sentinels (including UNKNOWN/FORCE_FLOOD) cannot be promoted.
template <typename Client>
bool promoteObservedClientPath(Client& client) {
const uint8_t encoded_path_len = client.observed_path_len;
if (!isValidObservedClientPathLength(
encoded_path_len, sizeof(client.observed_path))) {
return false;
}
const size_t path_bytes = observedClientPathByteLength(encoded_path_len);
if (path_bytes > sizeof(client.out_path)) return false;
memset(client.out_path, 0, sizeof(client.out_path));
if (path_bytes != 0) {
memcpy(client.out_path, client.observed_path, path_bytes);
}
client.out_path_len = encoded_path_len;
return true;
}
} // namespace mesh