diff options
| author | Your Name <you@example.com> | 2026-05-23 04:55:11 +0530 |
|---|---|---|
| committer | Your Name <you@example.com> | 2026-05-23 04:55:11 +0530 |
| commit | fb8558cbf964fae5a840f8f948b89a0d42045802 (patch) | |
| tree | 7b95a9e8cfa665c13ce56c8c0b9bdba950bc4934 | |
| parent | 9330b01c28aebc865a3c0a51df8730196cb4152e (diff) | |
Phase 6e-6f: Break circular dependencies
6e: Extract tls_worker queue from tollgate_api.c into shared tls_worker.c/h
- mint_health.c no longer includes tollgate_api.h
- tollgate_api.c no longer defines tls_worker functions
- Clean circular dependency broken
6f: Move payout_config_t from lightning_payout.h to config.h
- config.h no longer includes lightning_payout.h
- lightning_payout.h includes config.h for types
- Reverse dependency broken
All 21 unit tests pass. ESP-IDF build passes.
| -rw-r--r-- | main/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | main/config.h | 26 | ||||
| -rw-r--r-- | main/lightning_payout.h | 29 | ||||
| -rw-r--r-- | main/mint_health.c | 2 | ||||
| -rw-r--r-- | main/tls_worker.c | 31 | ||||
| -rw-r--r-- | main/tls_worker.h | 10 | ||||
| -rw-r--r-- | main/tollgate_api.c | 26 | ||||
| -rw-r--r-- | main/tollgate_api.h | 1 | ||||
| -rw-r--r-- | tests/unit/stubs/tollgate_api.h | 7 | ||||
| -rwxr-xr-x | tests/unit/test_beacon_price | bin | 35744 -> 35592 bytes | |||
| -rwxr-xr-x | tests/unit/test_firewall_sandbox | bin | 111016 -> 111016 bytes | |||
| -rwxr-xr-x | tests/unit/test_market | bin | 49456 -> 49360 bytes | |||
| -rwxr-xr-x | tests/unit/test_session_payment_method | bin | 117880 -> 117792 bytes | |||
| -rwxr-xr-x | tests/unit/test_tollgate_client_mining | bin | 48448 -> 48424 bytes |
14 files changed, 70 insertions, 63 deletions
diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index da90967..3a8613d 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt | |||
| @@ -17,6 +17,7 @@ idf_component_register(SRCS "tollgate_main.c" | |||
| 17 | "mcp_handler.c" | 17 | "mcp_handler.c" |
| 18 | "cvm_server.c" | 18 | "cvm_server.c" |
| 19 | "mint_health.c" | 19 | "mint_health.c" |
| 20 | "tls_worker.c" | ||
| 20 | "display.c" | 21 | "display.c" |
| 21 | "font.c" | 22 | "font.c" |
| 22 | "local_relay.c" | 23 | "local_relay.c" |
diff --git a/main/config.h b/main/config.h index 3092306..c501f1a 100644 --- a/main/config.h +++ b/main/config.h | |||
| @@ -5,8 +5,32 @@ | |||
| 5 | #include "esp_wifi.h" | 5 | #include "esp_wifi.h" |
| 6 | #include "esp_netif.h" | 6 | #include "esp_netif.h" |
| 7 | #include <stdbool.h> | 7 | #include <stdbool.h> |
| 8 | #include <stdint.h> | ||
| 8 | 9 | ||
| 9 | #include "lightning_payout.h" | 10 | #define PAYOUT_MAX_RECIPIENTS 4 |
| 11 | #define PAYOUT_MAX_MINTS 3 | ||
| 12 | #define PAYOUT_MAX_ADDR_LEN 128 | ||
| 13 | |||
| 14 | typedef struct { | ||
| 15 | char lightning_address[PAYOUT_MAX_ADDR_LEN]; | ||
| 16 | double factor; | ||
| 17 | } payout_recipient_t; | ||
| 18 | |||
| 19 | typedef struct { | ||
| 20 | char url[256]; | ||
| 21 | uint64_t min_balance; | ||
| 22 | uint64_t min_payout_amount; | ||
| 23 | } payout_mint_config_t; | ||
| 24 | |||
| 25 | typedef struct { | ||
| 26 | bool enabled; | ||
| 27 | payout_mint_config_t mints[PAYOUT_MAX_MINTS]; | ||
| 28 | int mint_count; | ||
| 29 | payout_recipient_t recipients[PAYOUT_MAX_RECIPIENTS]; | ||
| 30 | int recipient_count; | ||
| 31 | uint64_t fee_tolerance_pct; | ||
| 32 | int check_interval_s; | ||
| 33 | } payout_config_t; | ||
| 10 | 34 | ||
| 11 | #define TOLLGATE_MAX_WIFI_NETWORKS 5 | 35 | #define TOLLGATE_MAX_WIFI_NETWORKS 5 |
| 12 | #define TOLLGATE_MAX_MINT_URLS 8 | 36 | #define TOLLGATE_MAX_MINT_URLS 8 |
diff --git a/main/lightning_payout.h b/main/lightning_payout.h index d353902..7aea61b 100644 --- a/main/lightning_payout.h +++ b/main/lightning_payout.h | |||
| @@ -1,34 +1,7 @@ | |||
| 1 | #ifndef LIGHTNING_PAYOUT_H | 1 | #ifndef LIGHTNING_PAYOUT_H |
| 2 | #define LIGHTNING_PAYOUT_H | 2 | #define LIGHTNING_PAYOUT_H |
| 3 | 3 | ||
| 4 | #include "esp_err.h" | 4 | #include "config.h" |
| 5 | #include <stdint.h> | ||
| 6 | #include <stdbool.h> | ||
| 7 | |||
| 8 | #define PAYOUT_MAX_RECIPIENTS 4 | ||
| 9 | #define PAYOUT_MAX_MINTS 3 | ||
| 10 | #define PAYOUT_MAX_ADDR_LEN 128 | ||
| 11 | |||
| 12 | typedef struct { | ||
| 13 | char lightning_address[PAYOUT_MAX_ADDR_LEN]; | ||
| 14 | double factor; | ||
| 15 | } payout_recipient_t; | ||
| 16 | |||
| 17 | typedef struct { | ||
| 18 | char url[256]; | ||
| 19 | uint64_t min_balance; | ||
| 20 | uint64_t min_payout_amount; | ||
| 21 | } payout_mint_config_t; | ||
| 22 | |||
| 23 | typedef struct { | ||
| 24 | bool enabled; | ||
| 25 | payout_mint_config_t mints[PAYOUT_MAX_MINTS]; | ||
| 26 | int mint_count; | ||
| 27 | payout_recipient_t recipients[PAYOUT_MAX_RECIPIENTS]; | ||
| 28 | int recipient_count; | ||
| 29 | uint64_t fee_tolerance_pct; | ||
| 30 | int check_interval_s; | ||
| 31 | } payout_config_t; | ||
| 32 | 5 | ||
| 33 | esp_err_t lightning_payout_init(const payout_config_t *config); | 6 | esp_err_t lightning_payout_init(const payout_config_t *config); |
| 34 | 7 | ||
diff --git a/main/mint_health.c b/main/mint_health.c index 4ed8a19..d309731 100644 --- a/main/mint_health.c +++ b/main/mint_health.c | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | #include "mint_health.h" | 1 | #include "mint_health.h" |
| 2 | #include "tls_worker.h" | ||
| 2 | #include "esp_log.h" | 3 | #include "esp_log.h" |
| 3 | #include "esp_http_client.h" | 4 | #include "esp_http_client.h" |
| 4 | #include "esp_crt_bundle.h" | 5 | #include "esp_crt_bundle.h" |
| @@ -7,7 +8,6 @@ | |||
| 7 | #include "freertos/semphr.h" | 8 | #include "freertos/semphr.h" |
| 8 | #include "freertos/queue.h" | 9 | #include "freertos/queue.h" |
| 9 | #include "nucula_wallet.h" | 10 | #include "nucula_wallet.h" |
| 10 | #include "tollgate_api.h" | ||
| 11 | #include <string.h> | 11 | #include <string.h> |
| 12 | #include <stdlib.h> | 12 | #include <stdlib.h> |
| 13 | 13 | ||
diff --git a/main/tls_worker.c b/main/tls_worker.c new file mode 100644 index 0000000..1c3a7ef --- /dev/null +++ b/main/tls_worker.c | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | #include "tls_worker.h" | ||
| 2 | #include "nucula_wallet.h" | ||
| 3 | #include "esp_log.h" | ||
| 4 | #include <string.h> | ||
| 5 | #include <stdlib.h> | ||
| 6 | |||
| 7 | static const char *TAG = "tls_worker"; | ||
| 8 | static QueueHandle_t s_wallet_queue = NULL; | ||
| 9 | |||
| 10 | void tls_worker_set_queue(QueueHandle_t q) | ||
| 11 | { | ||
| 12 | s_wallet_queue = q; | ||
| 13 | } | ||
| 14 | |||
| 15 | void tls_worker_submit(const char *token) | ||
| 16 | { | ||
| 17 | if (!s_wallet_queue) { | ||
| 18 | ESP_LOGW(TAG, "No wallet queue, receiving synchronously"); | ||
| 19 | nucula_wallet_receive(token); | ||
| 20 | return; | ||
| 21 | } | ||
| 22 | |||
| 23 | char *copy = strdup(token); | ||
| 24 | if (!copy) return; | ||
| 25 | |||
| 26 | if (xQueueSend(s_wallet_queue, ©, pdMS_TO_TICKS(1000)) != pdTRUE) { | ||
| 27 | ESP_LOGW(TAG, "Wallet queue full, receiving synchronously"); | ||
| 28 | nucula_wallet_receive(copy); | ||
| 29 | free(copy); | ||
| 30 | } | ||
| 31 | } | ||
diff --git a/main/tls_worker.h b/main/tls_worker.h new file mode 100644 index 0000000..013dea5 --- /dev/null +++ b/main/tls_worker.h | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | #ifndef TLS_WORKER_H | ||
| 2 | #define TLS_WORKER_H | ||
| 3 | |||
| 4 | #include "freertos/FreeRTOS.h" | ||
| 5 | #include "freertos/queue.h" | ||
| 6 | |||
| 7 | void tls_worker_set_queue(QueueHandle_t q); | ||
| 8 | void tls_worker_submit(const char *token); | ||
| 9 | |||
| 10 | #endif | ||
diff --git a/main/tollgate_api.c b/main/tollgate_api.c index be753ea..4e9de43 100644 --- a/main/tollgate_api.c +++ b/main/tollgate_api.c | |||
| @@ -13,6 +13,7 @@ | |||
| 13 | #include "mining_payment.h" | 13 | #include "mining_payment.h" |
| 14 | #include "stratum_proxy.h" | 14 | #include "stratum_proxy.h" |
| 15 | #include "stratum_client.h" | 15 | #include "stratum_client.h" |
| 16 | #include "tls_worker.h" | ||
| 16 | #include "esp_log.h" | 17 | #include "esp_log.h" |
| 17 | #include "esp_system.h" | 18 | #include "esp_system.h" |
| 18 | #include "cJSON.h" | 19 | #include "cJSON.h" |
| @@ -25,31 +26,6 @@ | |||
| 25 | static const char *TAG = "tollgate_api"; | 26 | static const char *TAG = "tollgate_api"; |
| 26 | static httpd_handle_t s_api_server = NULL; | 27 | static httpd_handle_t s_api_server = NULL; |
| 27 | 28 | ||
| 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 | |||
| 53 | static esp_err_t get_client_ip(httpd_req_t *req, uint32_t *ip_out) | 29 | static esp_err_t get_client_ip(httpd_req_t *req, uint32_t *ip_out) |
| 54 | { | 30 | { |
| 55 | int sockfd = httpd_req_to_sockfd(req); | 31 | int sockfd = httpd_req_to_sockfd(req); |
diff --git a/main/tollgate_api.h b/main/tollgate_api.h index 2af4b8c..23e0d75 100644 --- a/main/tollgate_api.h +++ b/main/tollgate_api.h | |||
| @@ -6,6 +6,5 @@ | |||
| 6 | 6 | ||
| 7 | esp_err_t tollgate_api_start(void); | 7 | esp_err_t tollgate_api_start(void); |
| 8 | void tollgate_api_stop(void); | 8 | void tollgate_api_stop(void); |
| 9 | void tls_worker_set_queue(QueueHandle_t q); | ||
| 10 | 9 | ||
| 11 | #endif | 10 | #endif |
diff --git a/tests/unit/stubs/tollgate_api.h b/tests/unit/stubs/tollgate_api.h index 7e20fce..88292da 100644 --- a/tests/unit/stubs/tollgate_api.h +++ b/tests/unit/stubs/tollgate_api.h | |||
| @@ -1,11 +1,4 @@ | |||
| 1 | #ifndef STUB_TOLLGATE_API_H | 1 | #ifndef STUB_TOLLGATE_API_H |
| 2 | #define STUB_TOLLGATE_API_H | 2 | #define STUB_TOLLGATE_API_H |
| 3 | 3 | ||
| 4 | #include "freertos/queue.h" | ||
| 5 | |||
| 6 | static inline void tls_worker_set_queue(QueueHandle_t q) | ||
| 7 | { | ||
| 8 | (void)q; | ||
| 9 | } | ||
| 10 | |||
| 11 | #endif | 4 | #endif |
diff --git a/tests/unit/test_beacon_price b/tests/unit/test_beacon_price index a9f6357..5e4bf90 100755 --- a/tests/unit/test_beacon_price +++ b/tests/unit/test_beacon_price | |||
| Binary files differ | |||
diff --git a/tests/unit/test_firewall_sandbox b/tests/unit/test_firewall_sandbox index 7e5aa6d..0c3aa59 100755 --- a/tests/unit/test_firewall_sandbox +++ b/tests/unit/test_firewall_sandbox | |||
| Binary files differ | |||
diff --git a/tests/unit/test_market b/tests/unit/test_market index 8efac8e..d68ab15 100755 --- a/tests/unit/test_market +++ b/tests/unit/test_market | |||
| Binary files differ | |||
diff --git a/tests/unit/test_session_payment_method b/tests/unit/test_session_payment_method index 44cafd3..258fb01 100755 --- a/tests/unit/test_session_payment_method +++ b/tests/unit/test_session_payment_method | |||
| Binary files differ | |||
diff --git a/tests/unit/test_tollgate_client_mining b/tests/unit/test_tollgate_client_mining index d331bd1..750c145 100755 --- a/tests/unit/test_tollgate_client_mining +++ b/tests/unit/test_tollgate_client_mining | |||
| Binary files differ | |||