upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/main/tollgate_main.c
diff options
context:
space:
mode:
authorYour Name <you@example.com>2026-05-19 02:31:19 +0530
committerYour Name <you@example.com>2026-05-19 02:32:41 +0530
commit81f2dc52dc42d01c89dff45a5407ec40b8863052 (patch)
tree15018c2438639ca89dc6d33a5144c10d0b1c2af0 /main/tollgate_main.c
parent75688d55b3c8d13c8c9a50da9668ec408f684cb3 (diff)
feat: local Nostr relay with relay selection, sync, and integration tests
Local Nostr relay (NIP-01) on port 4869 with LittleFS 4MB storage. All events published locally first, then synced to public relays via REQ-diff. Relay selection via NIP-11 HTTP probing with NIP-77 scoring and auto-failover. Components: - wisp_relay: 16-file local relay (ws_server, storage_engine, sub_manager, broadcaster, relay_validator, router, handlers, rate_limiter, nip11, deletion, flash_monitor, relay_types) - esp_littlefs: LittleFS VFS integration (git submodule) - negentropy: for future NIP-77 binary sync (git submodule) New source files: - local_relay.c/h: thin wrapper for relay init/start/publish - relay_selector.c/h: NIP-11 probe + scoring + auto-failover - sync_manager.c/h: REQ-diff sync (primary 30min, fallback 6h) Bug fixes: - config.c: use-after-free (cJSON_Delete before seed_relays/sync parsing) - local_relay: moved init to app_main for boot-time start (not gated on STA IP) Flash layout: 4MB LittleFS partition at 0x500000 for relay_store Test results (Board B, live hardware): - Smoke: ping + HTTP 4869 + NIP-11: PASS - NIP-11 info document: 10/11 PASS - WS pub/sub (connect, REQ/EOSE, EVENT/OK, CLOSE, concurrent): 6/6 PASS - Unit tests (relay_validator + relay_selector): 13/13 PASS Hardware test make targets in physical-router-test-automation/: - make relay-build, relay-flash-b, relay-test-smoke/nip11/pubsub/sync/full
Diffstat (limited to 'main/tollgate_main.c')
-rw-r--r--main/tollgate_main.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/main/tollgate_main.c b/main/tollgate_main.c
index ad5211a..4741765 100644
--- a/main/tollgate_main.c
+++ b/main/tollgate_main.c
@@ -24,6 +24,9 @@
24#include "lightning_payout.h" 24#include "lightning_payout.h"
25#include "cvm_server.h" 25#include "cvm_server.h"
26#include "display.h" 26#include "display.h"
27#include "local_relay.h"
28#include "relay_selector.h"
29#include "sync_manager.h"
27 30
28#define MAX_STA_RETRY 5 31#define MAX_STA_RETRY 5
29static const char *TAG = "tollgate_main"; 32static const char *TAG = "tollgate_main";
@@ -38,6 +41,9 @@ static bool s_services_running = false;
38static SemaphoreHandle_t s_services_mutex = NULL; 41static SemaphoreHandle_t s_services_mutex = NULL;
39static char s_ap_ip_str[16] = "10.0.0.1"; 42static char s_ap_ip_str[16] = "10.0.0.1";
40 43
44static relay_selector_t s_relay_selector;
45static sync_manager_t s_sync_manager;
46
41static void start_services(void); 47static void start_services(void);
42static void stop_services(void); 48static void stop_services(void);
43 49
@@ -159,6 +165,12 @@ static void start_services(void)
159 captive_portal_start(cfg->ap_ip_str); 165 captive_portal_start(cfg->ap_ip_str);
160 tollgate_api_start(); 166 tollgate_api_start();
161 167
168 relay_selector_init(&s_relay_selector);
169 relay_selector_seed_from_config(&s_relay_selector);
170
171 sync_manager_init(&s_sync_manager, &s_relay_selector);
172 sync_manager_start(&s_sync_manager);
173
162 xTaskCreate(publish_wifistr_task, "wifistr_init", 16384, NULL, 3, NULL); 174 xTaskCreate(publish_wifistr_task, "wifistr_init", 16384, NULL, 3, NULL);
163 175
164 const tollgate_config_t *cfg2 = tollgate_config_get(); 176 const tollgate_config_t *cfg2 = tollgate_config_get();
@@ -189,6 +201,9 @@ static void stop_services(void)
189 tollgate_api_stop(); 201 tollgate_api_stop();
190 dns_server_stop(); 202 dns_server_stop();
191 cvm_server_stop(); 203 cvm_server_stop();
204 sync_manager_stop(&s_sync_manager);
205 local_relay_stop();
206 relay_selector_destroy(&s_relay_selector);
192 firewall_revoke_all(); 207 firewall_revoke_all();
193 s_services_running = false; 208 s_services_running = false;
194 if (s_services_mutex) xSemaphoreGive(s_services_mutex); 209 if (s_services_mutex) xSemaphoreGive(s_services_mutex);
@@ -311,6 +326,9 @@ void app_main(void)
311 326
312 ESP_ERROR_CHECK(esp_wifi_start()); 327 ESP_ERROR_CHECK(esp_wifi_start());
313 328
329 local_relay_init();
330 local_relay_start();
331
314 ESP_LOGI(TAG, "WiFi AP+STA started, waiting for connection..."); 332 ESP_LOGI(TAG, "WiFi AP+STA started, waiting for connection...");
315 333
316 if (tollgate_config_get_wifi(&(wifi_config_t){0}) != ESP_OK) { 334 if (tollgate_config_get_wifi(&(wifi_config_t){0}) != ESP_OK) {