From 1263d86314fc0760d9be8eea415ccecbc047a5eb Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 15 May 2026 22:27:14 +0530 Subject: Phase 2 WIP: Cashu payment endpoints, session tracking, updated checklist - Add cashu.c/h: Cashu token decode (cashuA/base64url), proof state check via mint API, allotment calculator - Add session.c/h: time-based session management with allotment/expiry, spent secret tracking - Add tollgate_api.c/h: HTTP server on :2121 with GET / (kind=10021 discovery), POST / (payment processing), /usage, /whoami - Update captive portal HTML: replace Grant Free Access with Cashu token paste form + Pay & Connect button - Update tollgate_main.c: wire in session manager, TollGate API, 1s session tick loop - Add tests/phase2.mjs: Phase 2 test suite (discovery, invalid token, wrong mint, valid payment) - Update CHECKLIST.md: reflect Phase 1 complete, Phase 2 in progress with known bugs Known issues (not yet flashed): - Stack overflow crash in httpd POST handler (need stack_size=16384 + heap allocations) - cashu_decode_token uses 2KB stack buffer (needs heap alloc) - Mint URL should be testnut.cashu.space (nofee.testnut has API compat issues) --- main/tollgate_main.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'main/tollgate_main.c') diff --git a/main/tollgate_main.c b/main/tollgate_main.c index 9eba61f..04f64b9 100644 --- a/main/tollgate_main.c +++ b/main/tollgate_main.c @@ -14,6 +14,8 @@ #include "dns_server.h" #include "captive_portal.h" #include "firewall.h" +#include "session.h" +#include "tollgate_api.h" #define MAX_STA_RETRY 5 #define AP_IP_ADDR "192.168.4.1" @@ -105,9 +107,11 @@ static void start_services(void) upstream_dns.addr = dns_addr->addr; firewall_init(ap_ip_info.ip); + session_manager_init(); dns_server_start(ap_ip_info.ip, upstream_dns); captive_portal_start(); + tollgate_api_start(); s_services_running = true; if (s_services_mutex) xSemaphoreGive(s_services_mutex); @@ -123,6 +127,7 @@ static void stop_services(void) } captive_portal_stop(); + tollgate_api_stop(); dns_server_stop(); firewall_disable_nat(); firewall_revoke_all(); @@ -218,4 +223,9 @@ void app_main(void) ESP_ERROR_CHECK(esp_wifi_start()); ESP_LOGI(TAG, "WiFi AP+STA started, waiting for connection..."); + + while (1) { + vTaskDelay(pdMS_TO_TICKS(1000)); + session_tick(); + } } -- cgit v1.2.3