From 19e175b1c1dea54efb61e8040ffdfa973fbac5d5 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 21 May 2026 16:46:51 +0530 Subject: Wallet receive via health task queue (no separate TLS worker) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Removed standalone TLS worker task (couldn't allocate 16KB internal stack) - Added wallet receive queue to mint_health task (already has 16KB stack + working TLS) - health_task processes wallet tokens between probe intervals (1s poll) - tls_worker_set_queue() registers queue from mint_health_start() - Fallback to synchronous receive if queue not available - Added freertos/queue.h and tollgate_api.h stubs for unit tests - Added BaseType_t/UBaseType_t/TickType_t/pdFALSE to FreeRTOS stub - Full payment round-trip confirmed: 2 payments → 41 sat balance --- main/tollgate_api.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'main/tollgate_api.c') diff --git a/main/tollgate_api.c b/main/tollgate_api.c index 7f2102e..be753ea 100644 --- a/main/tollgate_api.c +++ b/main/tollgate_api.c @@ -19,11 +19,37 @@ #include "lwip/sockets.h" #include "lwip/netdb.h" #include "freertos/task.h" +#include "freertos/queue.h" #include static const char *TAG = "tollgate_api"; static httpd_handle_t s_api_server = NULL; +static QueueHandle_t s_wallet_queue = NULL; + +void tls_worker_set_queue(QueueHandle_t q) +{ + s_wallet_queue = q; +} + +static void tls_worker_submit(const char *token) +{ + if (!s_wallet_queue) { + ESP_LOGW(TAG, "No wallet queue, receiving synchronously"); + nucula_wallet_receive(token); + return; + } + + char *copy = strdup(token); + if (!copy) return; + + if (xQueueSend(s_wallet_queue, ©, pdMS_TO_TICKS(1000)) != pdTRUE) { + ESP_LOGW(TAG, "Wallet queue full, receiving synchronously"); + nucula_wallet_receive(copy); + free(copy); + } +} + static esp_err_t get_client_ip(httpd_req_t *req, uint32_t *ip_out) { int sockfd = httpd_req_to_sockfd(req); @@ -343,7 +369,7 @@ static esp_err_t api_post_payment(httpd_req_t *req) cJSON_free(json); cJSON_Delete(session_event); - nucula_wallet_receive(body_copy); + tls_worker_submit(body_copy); free(states); free(token); @@ -820,6 +846,7 @@ esp_err_t tollgate_api_start(void) } ESP_LOGI(TAG, "TollGate API started on port 2121"); + return ESP_OK; } -- cgit v1.2.3