mirror of
https://github.com/liquidraver/ZephCore.git
synced 2026-12-06 06:15:03 +00:00
92 lines
2.9 KiB
C++
92 lines
2.9 KiB
C++
#pragma once
|
|
|
|
//#include <Arduino.h> // needed for PlatformIO
|
|
#include <mesh/Mesh.h>
|
|
#include <helpers/IdentityStore.h>
|
|
|
|
#define PERM_ACL_ROLE_MASK 3 // lower 2 bits
|
|
#define PERM_ACL_GUEST 0
|
|
#define PERM_ACL_READ_ONLY 1
|
|
#define PERM_ACL_READ_WRITE 2
|
|
#define PERM_ACL_ADMIN 3
|
|
|
|
#define OUT_PATH_UNKNOWN 0xFF
|
|
|
|
struct ClientInfo {
|
|
mesh::Identity id;
|
|
uint8_t permissions;
|
|
uint8_t out_path_len;
|
|
uint8_t out_path[MAX_PATH_SIZE];
|
|
uint8_t shared_secret[PUB_KEY_SIZE];
|
|
uint32_t last_timestamp; // by THEIR clock (transient)
|
|
uint32_t last_activity; // by OUR clock (transient)
|
|
uint32_t last_req_timestamp; // ZEPHCORE: by THEIR clock (transient), REQ only; a login resets it
|
|
union {
|
|
struct {
|
|
uint32_t sync_since; // sync messages SINCE this timestamp (by OUR clock)
|
|
uint32_t pending_ack;
|
|
uint32_t push_post_timestamp;
|
|
unsigned long ack_timeout;
|
|
uint8_t push_failures;
|
|
} room;
|
|
#if 0 // ZEPHCORE: no sensor role; dropping it saves 20+ bytes of RAM per client
|
|
struct {
|
|
uint32_t expiry_timestamp; // epoch seconds
|
|
uint32_t push_tag;
|
|
uint16_t scope_region_id; // scope to use when sending telemetry to this client/subscriber
|
|
uint8_t min_deltas_len;
|
|
uint8_t min_deltas[14]; // LPP encoded
|
|
uint8_t prev_telem[14]; // LPP encoded
|
|
} sensor;
|
|
#endif
|
|
} extra;
|
|
|
|
bool isAdmin() const { return (permissions & PERM_ACL_ROLE_MASK) == PERM_ACL_ADMIN; }
|
|
|
|
// ZEPHCORE: stands in for upstream's memset (Identity has a ctor, so memset
|
|
// trips -Wclass-memaccess). out_path_len is OUT_PATH_UNKNOWN, not 0: 0 is a
|
|
// valid "zero-hop direct" path, so a cleared slot would claim a usable route.
|
|
void clear() {
|
|
id = mesh::Identity();
|
|
permissions = 0;
|
|
out_path_len = OUT_PATH_UNKNOWN;
|
|
memset(out_path, 0, sizeof(out_path));
|
|
memset(shared_secret, 0, sizeof(shared_secret));
|
|
last_timestamp = 0;
|
|
last_activity = 0;
|
|
last_req_timestamp = 0;
|
|
memset(&extra, 0, sizeof(extra));
|
|
}
|
|
};
|
|
|
|
// ZEPHCORE: table size from Kconfig.
|
|
#ifdef CONFIG_ZEPHCORE_MAX_CLIENTS
|
|
#define MAX_CLIENTS CONFIG_ZEPHCORE_MAX_CLIENTS
|
|
#endif
|
|
|
|
#ifndef MAX_CLIENTS
|
|
#define MAX_CLIENTS 32
|
|
#endif
|
|
|
|
class ClientACL {
|
|
FILESYSTEM* _fs;
|
|
ClientInfo clients[MAX_CLIENTS];
|
|
int num_clients;
|
|
|
|
public:
|
|
ClientACL() {
|
|
for (int i = 0; i < MAX_CLIENTS; i++) clients[i].clear(); // ZEPHCORE: was memset
|
|
num_clients = 0;
|
|
}
|
|
void load(FILESYSTEM* _fs, const mesh::LocalIdentity& self_id);
|
|
void save(FILESYSTEM* _fs, bool (*filter)(ClientInfo*)=NULL);
|
|
bool clear();
|
|
|
|
ClientInfo* getClient(const uint8_t* pubkey, int key_len);
|
|
ClientInfo* putClient(const mesh::Identity& id, uint8_t init_perms);
|
|
bool applyPermissions(const mesh::LocalIdentity& self_id, const uint8_t* pubkey, int key_len, uint8_t perms);
|
|
|
|
int getNumClients() const { return num_clients; }
|
|
ClientInfo* getClientByIdx(int idx) { return &clients[idx]; }
|
|
};
|