diff options
| author | Your Name <you@example.com> | 2026-05-16 03:37:20 +0530 |
|---|---|---|
| committer | Your Name <you@example.com> | 2026-05-16 03:37:20 +0530 |
| commit | c342801162e62ff017ead18688107397d229f606 (patch) | |
| tree | 84280cde11bd05226d338a07c0817337941f7cb1 /main/tollgate_api.c | |
| parent | aed51d824f598f7315282936037c4d5b6e7fb4b8 (diff) | |
Phase 2 WIP: token decode works, TLS checkstate succeeds (crashes after response)
- cashu.c: dynamic json_buf sizing (was 2048 stack, now heap based on token length)
- cashu.c: strip trailing newline/CR from token input (cashu CLI appends 'Balance: 0 sat')
- cashu.c: esp_crt_bundle_attach for HTTPS to mint API
- cashu.c: esp_http_client_open/write/fetch_headers/read pattern for HTTPS POST
- cashu.c: remove debug b64url_decode logging
- tollgate_api.c: loop httpd_req_recv for full body (was single call, missed TCP segments)
- tollgate_api.c: stack_size=32768 for TLS in httpd handler
- config.c: fix default mint URL from nofee.testnut to testnut.cashu.space
- CMakeLists.txt: add esp-tls dependency for cert bundle
- CHECKLIST.md: updated with infrastructure status and TDD plan
Known issue: device reboots after checkstate returns 966 bytes with status=200.
Crash likely in post-response processing (JSON parse or session create).
Diffstat (limited to 'main/tollgate_api.c')
| -rw-r--r-- | main/tollgate_api.c | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/main/tollgate_api.c b/main/tollgate_api.c index b2ad647..2af04bc 100644 --- a/main/tollgate_api.c +++ b/main/tollgate_api.c | |||
| @@ -162,17 +162,22 @@ static esp_err_t api_post_payment(httpd_req_t *req) | |||
| 162 | cJSON_Delete(notice); | 162 | cJSON_Delete(notice); |
| 163 | return ESP_OK; | 163 | return ESP_OK; |
| 164 | } | 164 | } |
| 165 | int received = httpd_req_recv(req, body, content_len); | 165 | int received = 0; |
| 166 | if (received <= 0) { | 166 | int total = 0; |
| 167 | free(body); | 167 | while (total < content_len) { |
| 168 | httpd_resp_set_status(req, "400 Bad Request"); | 168 | received = httpd_req_recv(req, body + total, content_len - total); |
| 169 | httpd_resp_set_type(req, "text/plain"); | 169 | if (received <= 0) { |
| 170 | httpd_resp_send(req, "bad request", 11); | 170 | free(body); |
| 171 | return ESP_OK; | 171 | httpd_resp_set_status(req, "400 Bad Request"); |
| 172 | httpd_resp_set_type(req, "text/plain"); | ||
| 173 | httpd_resp_send(req, "bad request", 11); | ||
| 174 | return ESP_OK; | ||
| 175 | } | ||
| 176 | total += received; | ||
| 172 | } | 177 | } |
| 173 | body[received] = '\0'; | 178 | body[total] = '\0'; |
| 174 | 179 | ||
| 175 | ESP_LOGI(TAG, "Payment received: %d bytes", received); | 180 | ESP_LOGI(TAG, "Payment received: %d bytes", total); |
| 176 | 181 | ||
| 177 | cashu_token_t token; | 182 | cashu_token_t token; |
| 178 | esp_err_t err = cashu_decode_token(body, &token); | 183 | esp_err_t err = cashu_decode_token(body, &token); |
| @@ -330,7 +335,7 @@ esp_err_t tollgate_api_start(void) | |||
| 330 | config.server_port = 2121; | 335 | config.server_port = 2121; |
| 331 | config.ctrl_port = 32769; | 336 | config.ctrl_port = 32769; |
| 332 | config.max_uri_handlers = 10; | 337 | config.max_uri_handlers = 10; |
| 333 | config.stack_size = 16384; | 338 | config.stack_size = 32768; |
| 334 | 339 | ||
| 335 | esp_err_t ret = httpd_start(&s_api_server, &config); | 340 | esp_err_t ret = httpd_start(&s_api_server, &config); |
| 336 | if (ret != ESP_OK) { | 341 | if (ret != ESP_OK) { |