diff options
| author | Your Name <you@example.com> | 2026-05-21 16:46:51 +0530 |
|---|---|---|
| committer | Your Name <you@example.com> | 2026-05-21 16:46:51 +0530 |
| commit | 19e175b1c1dea54efb61e8040ffdfa973fbac5d5 (patch) | |
| tree | f41ca977a993cc24f8bf136e96370c8097ceeaf1 /main/tollgate_api.c | |
| parent | 243e4808246555f86d464d1c476681a902e644ff (diff) | |
Wallet receive via health task queue (no separate TLS worker)
- 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
Diffstat (limited to 'main/tollgate_api.c')
| -rw-r--r-- | main/tollgate_api.c | 29 |
1 files changed, 28 insertions, 1 deletions
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 @@ | |||
| 19 | #include "lwip/sockets.h" | 19 | #include "lwip/sockets.h" |
| 20 | #include "lwip/netdb.h" | 20 | #include "lwip/netdb.h" |
| 21 | #include "freertos/task.h" | 21 | #include "freertos/task.h" |
| 22 | #include "freertos/queue.h" | ||
| 22 | #include <string.h> | 23 | #include <string.h> |
| 23 | 24 | ||
| 24 | static const char *TAG = "tollgate_api"; | 25 | static const char *TAG = "tollgate_api"; |
| 25 | static httpd_handle_t s_api_server = NULL; | 26 | static httpd_handle_t s_api_server = NULL; |
| 26 | 27 | ||
| 28 | static QueueHandle_t s_wallet_queue = NULL; | ||
| 29 | |||
| 30 | void tls_worker_set_queue(QueueHandle_t q) | ||
| 31 | { | ||
| 32 | s_wallet_queue = q; | ||
| 33 | } | ||
| 34 | |||
| 35 | static void tls_worker_submit(const char *token) | ||
| 36 | { | ||
| 37 | if (!s_wallet_queue) { | ||
| 38 | ESP_LOGW(TAG, "No wallet queue, receiving synchronously"); | ||
| 39 | nucula_wallet_receive(token); | ||
| 40 | return; | ||
| 41 | } | ||
| 42 | |||
| 43 | char *copy = strdup(token); | ||
| 44 | if (!copy) return; | ||
| 45 | |||
| 46 | if (xQueueSend(s_wallet_queue, ©, pdMS_TO_TICKS(1000)) != pdTRUE) { | ||
| 47 | ESP_LOGW(TAG, "Wallet queue full, receiving synchronously"); | ||
| 48 | nucula_wallet_receive(copy); | ||
| 49 | free(copy); | ||
| 50 | } | ||
| 51 | } | ||
| 52 | |||
| 27 | static esp_err_t get_client_ip(httpd_req_t *req, uint32_t *ip_out) | 53 | static esp_err_t get_client_ip(httpd_req_t *req, uint32_t *ip_out) |
| 28 | { | 54 | { |
| 29 | int sockfd = httpd_req_to_sockfd(req); | 55 | int sockfd = httpd_req_to_sockfd(req); |
| @@ -343,7 +369,7 @@ static esp_err_t api_post_payment(httpd_req_t *req) | |||
| 343 | cJSON_free(json); | 369 | cJSON_free(json); |
| 344 | cJSON_Delete(session_event); | 370 | cJSON_Delete(session_event); |
| 345 | 371 | ||
| 346 | nucula_wallet_receive(body_copy); | 372 | tls_worker_submit(body_copy); |
| 347 | 373 | ||
| 348 | free(states); | 374 | free(states); |
| 349 | free(token); | 375 | free(token); |
| @@ -820,6 +846,7 @@ esp_err_t tollgate_api_start(void) | |||
| 820 | } | 846 | } |
| 821 | 847 | ||
| 822 | ESP_LOGI(TAG, "TollGate API started on port 2121"); | 848 | ESP_LOGI(TAG, "TollGate API started on port 2121"); |
| 849 | |||
| 823 | return ESP_OK; | 850 | return ESP_OK; |
| 824 | } | 851 | } |
| 825 | 852 | ||