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-18 03:37:27 +0530
committerYour Name <you@example.com>2026-05-18 03:37:27 +0530
commit8a2f7a6c9423e0c00fae3c1233bee9e0bb3ae239 (patch)
tree8f8d2ede379b7e3cc0da82d472bcf0eeedcbf03b /main/tollgate_main.c
parentfe7c3be2fd9d464dbc837d1913409d2691bd50f5 (diff)
feat: ContextVM (MCP over Nostr) server with WS masking fix
- Full CVM server: persistent WS relay listener, kind 25910 subscription - MCP protocol handlers: initialize, tools/list, tools/call, ping - 10 MCP tools: get_config, set_config, get_balance, wallet_send, get_sessions, get_usage, set_payout, set_metric, set_price, wallet_melt - CEP-6 announcements via WS (kinds 11316, 11317, 10002) - Auth check: owner npub only - Fix: WebSocket client-to-server frame masking (RFC 6455 requirement) - Fix: Raw event JSON in EVENT wrapper (no re-parsing that breaks sig) - SNTP init after STA gets IP - 282 unit tests passing (61 CVM + 60 MCP handler + 161 existing) - Integration test scaffold: tests/integration/test-cvm.mjs
Diffstat (limited to 'main/tollgate_main.c')
-rw-r--r--main/tollgate_main.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/main/tollgate_main.c b/main/tollgate_main.c
index 1350d70..c0ff65f 100644
--- a/main/tollgate_main.c
+++ b/main/tollgate_main.c
@@ -9,6 +9,7 @@
9#include "esp_netif.h" 9#include "esp_netif.h"
10#include "lwip/netif.h" 10#include "lwip/netif.h"
11#include "lwip/dns.h" 11#include "lwip/dns.h"
12#include "esp_sntp.h"
12#include "dhcpserver/dhcpserver.h" 13#include "dhcpserver/dhcpserver.h"
13#include "config.h" 14#include "config.h"
14#include "identity.h" 15#include "identity.h"
@@ -22,6 +23,7 @@
22#include "tollgate_client.h" 23#include "tollgate_client.h"
23#include "lightning_payout.h" 24#include "lightning_payout.h"
24#include "cvm_server.h" 25#include "cvm_server.h"
26#include "display.h"
25 27
26#define MAX_STA_RETRY 5 28#define MAX_STA_RETRY 5
27static const char *TAG = "tollgate_main"; 29static const char *TAG = "tollgate_main";
@@ -94,6 +96,13 @@ static void ip_event_handler(void *arg, esp_event_base_t event_base,
94 s_retry_count = 0; 96 s_retry_count = 0;
95 xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT); 97 xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT);
96 98
99 esp_sntp_stop();
100 esp_sntp_setoperatingmode(SNTP_OPMODE_POLL);
101 esp_sntp_setservername(0, "pool.ntp.org");
102 esp_sntp_setservername(1, "time.google.com");
103 esp_sntp_init();
104 ESP_LOGI(TAG, "SNTP time sync started");
105
97 char gw_ip_str[16]; 106 char gw_ip_str[16];
98 snprintf(gw_ip_str, sizeof(gw_ip_str), IPSTR, IP2STR(&event->ip_info.gw)); 107 snprintf(gw_ip_str, sizeof(gw_ip_str), IPSTR, IP2STR(&event->ip_info.gw));
99 tollgate_client_on_sta_connected(gw_ip_str); 108 tollgate_client_on_sta_connected(gw_ip_str);
@@ -160,6 +169,11 @@ static void start_services(void)
160 s_services_running = true; 169 s_services_running = true;
161 if (s_services_mutex) xSemaphoreGive(s_services_mutex); 170 if (s_services_mutex) xSemaphoreGive(s_services_mutex);
162 ESP_LOGI(TAG, "=== TollGate services started ==="); 171 ESP_LOGI(TAG, "=== TollGate services started ===");
172
173 display_set_state(DISPLAY_READY);
174 char portal_url[128];
175 snprintf(portal_url, sizeof(portal_url), "http://%s/", cfg->ap_ip_str);
176 display_update(cfg->ap_ssid, 0, 0, portal_url);
163} 177}
164 178
165static void stop_services(void) 179static void stop_services(void)
@@ -240,6 +254,9 @@ void app_main(void)
240{ 254{
241 ESP_LOGI(TAG, "=== TollGate ESP32 Starting ==="); 255 ESP_LOGI(TAG, "=== TollGate ESP32 Starting ===");
242 256
257 display_init();
258 display_set_state(DISPLAY_BOOT);
259
243 esp_err_t ret = nvs_flash_init(); 260 esp_err_t ret = nvs_flash_init();
244 if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { 261 if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
245 ESP_ERROR_CHECK(nvs_flash_erase()); 262 ESP_ERROR_CHECK(nvs_flash_erase());