Add room catch-up and Wi-Fi administration

This commit is contained in:
mikecarper committed 2026-10-10 11:51:00 -07:00
1 parent 0eb1d03a16
commit 4606f3da60
20 files changed
+2585 -64

No files matched your search

+56 -6
View File
@@ -8,6 +8,7 @@
#include <Packet.h>
#include <helpers/RoomAccessPolicy.h>
#include <helpers/RoomClientPathCommand.h>
#include <helpers/RoomCatchUp.h>
#include <helpers/ClientPathObservation.h>
#include <helpers/ClientPathPersistence.h>
#include <helpers/RemoteCliReplyCache.h>
@@ -21,8 +22,26 @@
@STR_HELPER@
#define MESH_CLIENT_REPEATER_ONLY 0
namespace mesh {
struct Identity { uint8_t pub_key[PUB_KEY_SIZE]; };
struct Identity {
uint8_t pub_key[PUB_KEY_SIZE];
bool matches(const Identity& other) const {
return memcmp(pub_key, other.pub_key, PUB_KEY_SIZE) == 0;
}
};
struct Utils {
static bool fromHex(uint8_t* out, size_t n, const char* text) {
if (strlen(text) != n * 2) return false;
for (size_t index = 0; index < n; ++index) {
const int high = cli::recentRepeaterHexNibble(text[index * 2]);
const int low = cli::recentRepeaterHexNibble(text[index * 2 + 1]);
if (high < 0 || low < 0) return false;
out[index] = (high << 4) | low;
}
return true;
}
static void sha256(uint8_t* out, size_t n, const uint8_t* data, size_t length) {
sha256(out, n, data, length, nullptr, 0);
}
static void sha256(uint8_t* out, size_t n, const uint8_t* left, size_t ln,
const uint8_t* right, size_t rn) {
memset(out, 0, n);
@@ -33,6 +52,7 @@ struct Utils {
@PACKET_METHODS@
}
@CLIENT_INFO@;
@POST_INFO@;
struct FakeACL {
ClientInfo clients[2]{};
@@ -42,6 +62,13 @@ struct FakeACL {
unsigned saves = 0;
int getNumClients() const { return 2; }
ClientInfo* getClientByIdx(int i) { assert(i >= 0 && i < 2); return &clients[i]; }
ClientInfo* getClient(const uint8_t* key, size_t length) {
assert(length == PUB_KEY_SIZE);
for (auto& client : clients) {
if (memcmp(client.id.pub_key, key, length) == 0) return &client;
}
return nullptr;
}
bool save(MemoryFS* fs, bool (*filter)(ClientInfo*)) {
++saves;
assert(fs != nullptr && filter != nullptr);
@@ -74,6 +101,7 @@ struct Sent {
};
struct MyMesh {
FakeACL acl;
mesh::Identity self_id{};
MemoryFS policy_fs;
MemoryFS* _fs = &policy_fs;
mesh::RoomAccessPolicy room_access;
@@ -89,7 +117,11 @@ struct MyMesh {
mesh::Packet pool[64];
unsigned used = 0, allocations = 0, releases = 0, fail_allocation = UINT32_MAX;
bool send_ok = true;
unsigned general_commands = 0, posts = 0, retry_replacements = 0, _num_post_pushes = 0;
unsigned general_commands = 0, post_count = 0, retry_replacements = 0, _num_post_pushes = 0;
PostInfo posts[MAX_UNSYNCED_POSTS]{};
unsigned message_cancellations = 0;
uint32_t cancelled_timestamp = 0;
uint8_t cancelled_key[MAX_HASH_SIZE]{};
uint32_t retry_timestamp = 0;
mesh::Packet retry_packet;
std::vector<Sent> sent;
@@ -162,16 +194,27 @@ struct MyMesh {
void replaceActiveMessageRetries(mesh::Packet* p, const uint8_t*, uint32_t timestamp) {
++retry_replacements; retry_packet = *p; retry_timestamp = timestamp;
}
void handleCommand(uint32_t, char*, char* reply, int, uint8_t) {
++general_commands; strcpy(reply, "OK admin");
void handleCommand(uint32_t, char* command, char* reply, int, uint8_t) {
++general_commands;
if (handleRoomManagementCommand(command, reply)) return;
strcpy(reply, "OK admin");
}
bool addPost(ClientInfo*, const char*) { ++posts; return true; }
bool addPost(ClientInfo*, const char*) { ++post_count; return true; }
void serviceRoomQuotas();
uint8_t getUnsyncedCount(ClientInfo*) { return 0; }
uint8_t getUnsyncedCount(ClientInfo*);
bool cancelActiveMessageRetries(const uint8_t* key, uint32_t timestamp) {
++message_cancellations; cancelled_timestamp = timestamp;
memcpy(cancelled_key, key, MAX_HASH_SIZE); return true;
}
int getExtraAckTransmitCount() { return 0; }
int handleRequest(ClientInfo*, uint32_t, uint8_t*, size_t, size_t) { return 0; }
static bool saveFilter(ClientInfo*);
bool handleClientPathCommand(ClientInfo*, char*, char*);
bool executeClientPathCommand(ClientInfo*, mesh::RoomClientPathCommand, const char*, char*);
bool handleRoomCatchUpCommand(ClientInfo*, char*, char*);
bool applyRoomCatchUpCommand(ClientInfo*, const char*, uint32_t, char*);
bool setRoomClientPath(ClientInfo*, const char*, const char*, char*);
bool handleRoomManagementCommand(char*, char*);
bool sendClientReply(ClientInfo*, mesh::Packet*, unsigned long, uint8_t);
bool pushRoomTextToClient(ClientInfo*, uint32_t, const mesh::Identity&, const char*, uint32_t);
void onPeerDataRecv(mesh::Packet*, uint8_t, int, const uint8_t*, uint8_t*, size_t);
@@ -191,6 +234,13 @@ struct MyMesh {
const auto& p = sent.back().packet;
return std::string((const char*)p.payload + 5, p.payload_len - 5);
}
void poll(uint32_t timestamp, uint32_t since, unsigned sender = 0) {
uint8_t data[10]{};
memcpy(data, &timestamp, 4); data[4] = REQ_TYPE_KEEP_ALIVE;
memcpy(data + 5, &since, 4);
mesh::Packet packet; packet.header = ROUTE_TYPE_DIRECT;
onPeerDataRecv(&packet, PAYLOAD_TYPE_REQ, sender, acl.clients[sender].shared_secret, data, 9);
}
};
@PRODUCTION_METHODS@
@TEST_CASES@