still wip

This commit is contained in:
2025-12-22 23:02:29 +01:00
parent 627acef32c
commit a48ef9d5e0
60 changed files with 6993 additions and 4939 deletions

View File

@@ -1,7 +1,62 @@
#include "config.h"
#include "ch32v30x_flash.h"
#include "util/hexdump.h"
#include "util/log.h"
PersistentData_t persistent;
#define TAG "Config"
NodeEntry * getNextNode() {
uint32_t oldest_timestamp = UINT32_MAX;
NodeEntry *selectedNode = &(persistent.contacts[0]);
for (int i = 0; i < CONTACT_COUNT; i++) {
NodeEntry *curNode = &(persistent.contacts[i]);
if (curNode->last_seen_lt == 0) {
break;
}
if (curNode->last_seen_lt < oldest_timestamp) {
oldest_timestamp = curNode->last_seen_lt;
selectedNode = curNode;
}
}
return selectedNode;
}
NodeEntry * getNode(uint8_t hash) {
NodeEntry *selectedNode = NULL;
for (int i = 0; i < CONTACT_COUNT; i++) {
NodeEntry *curNode = &(persistent.contacts[i]);
if (curNode->pubKey[0] == hash) {
selectedNode = curNode;
break;
}
}
return selectedNode;
}
void printNodeDB() {
printf("Node database:\n");
for (int i = 0; i < CONTACT_COUNT; i++) {
const NodeEntry *node = &(persistent.contacts[i]);
if (node->last_seen_lt == 0) continue; // skip inactive nodes
printf("Node %d:\n", i);
printf(" Name: %s\n", node->name);
hexdump("Pubkey", node->pubKey, sizeof(node->pubKey));
hexdump("Secret", node->secret, sizeof(node->secret));
printf("\n");
printf(" GPS: lat=%d, lon=%d\n", node->gps_latitude, node->gps_longitude);
printf(" Path: ... (not expanded, add if needed)\n");
printf(" Flags: 0x%02X\n", node->flags);
printf(" Type: 0x%02X\n", node->type);
printf(" Authenticated: %s\n", node->authenticated ? "Yes" : "No");
printf(" Last Seen (remote ts): %d\n", node->last_seen_rt);
printf(" Last Seen (local ts): %d\n", node->last_seen_lt);
printf(" Sync timestamp: %d\n", node->sync_timestamp);
printf("--------------------------------------\n");
}
}
void loadConfig() {
memcpy (&persistent, FLASH_USER_PAGE_ADDR, sizeof (persistent));