diff options
| author | Your Name <you@example.com> | 2026-05-18 18:50:20 +0530 |
|---|---|---|
| committer | Your Name <you@example.com> | 2026-05-18 18:50:20 +0530 |
| commit | f6369f5b87f5dab17a03315d82454fdcdd668ec9 (patch) | |
| tree | bc16c22f87253eafa680a30da370b1822d855ca4 /components/tollgate_core/include | |
| parent | d8c55d2a072433e16ae5c84b7b7c676587f6f2d9 (diff) | |
feat: extract tollgate_core ESP-IDF component
Extract shared TollGate business logic into a reusable ESP-IDF component
that can be consumed by esp-miner via the IDF Component Manager.
Component structure:
components/tollgate_core/
include/tollgate_core.h — public API
include/tollgate_platform.h — platform interface (config callbacks)
src/tollgate_core.c — orchestrator (init, payment, tick, owner)
src/tollgate_core_cashu.c/h — Cashu V3 token decode/verify
src/tollgate_core_dns.c/h — per-client DNS hijack/forward
src/tollgate_core_firewall.c/h — per-client NAT filter
src/tollgate_core_session.c/h — session lifecycle
Key design decisions:
- Platform interface pattern: consumers implement tollgate_platform_t
(config getters + optional spend_proofs wallet hook)
- Cross-module wiring (session→firewall→dns) stays internal
- No direct config.h dependency — all config via platform callbacks
- spend_proofs can be NULL (accepts payment without local wallet)
Standalone app updated:
- main/tollgate_platform.c implements platform via config singleton
- main/tollgate_main.c calls tollgate_core_init/tick/dns_start
- main/tollgate_api.c routes payment through tollgate_core_process_payment
- Removed cashu.c, dns_server.c, firewall.c, session.c from CMakeLists
Not yet build-verified — blocked on multi-mint, price-discovery,
cvm-integration, and display-fix branches merging to master.
Diffstat (limited to 'components/tollgate_core/include')
| -rw-r--r-- | components/tollgate_core/include/tollgate_core.h | 34 | ||||
| -rw-r--r-- | components/tollgate_core/include/tollgate_platform.h | 17 |
2 files changed, 51 insertions, 0 deletions
diff --git a/components/tollgate_core/include/tollgate_core.h b/components/tollgate_core/include/tollgate_core.h new file mode 100644 index 0000000..c47ebeb --- /dev/null +++ b/components/tollgate_core/include/tollgate_core.h | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | #ifndef TOLLGATE_CORE_H | ||
| 2 | #define TOLLGATE_CORE_H | ||
| 3 | |||
| 4 | #include "tollgate_platform.h" | ||
| 5 | #include "esp_err.h" | ||
| 6 | #include "esp_netif.h" | ||
| 7 | #include <stdbool.h> | ||
| 8 | #include <stdint.h> | ||
| 9 | |||
| 10 | esp_err_t tollgate_core_init(const tollgate_platform_t *platform, esp_ip4_addr_t ap_ip); | ||
| 11 | |||
| 12 | esp_err_t tollgate_core_dns_start(esp_ip4_addr_t upstream_dns); | ||
| 13 | void tollgate_core_dns_stop(void); | ||
| 14 | |||
| 15 | esp_err_t tollgate_core_process_payment(uint32_t client_ip, const char *token_str); | ||
| 16 | |||
| 17 | void tollgate_core_client_connected(const uint8_t *mac, uint32_t client_ip); | ||
| 18 | void tollgate_core_client_disconnected(const uint8_t *mac); | ||
| 19 | |||
| 20 | void tollgate_core_tick(void); | ||
| 21 | |||
| 22 | bool tollgate_core_is_client_allowed(uint32_t client_ip); | ||
| 23 | bool tollgate_core_is_dns_running(void); | ||
| 24 | |||
| 25 | char *tollgate_core_get_status_json(void); | ||
| 26 | char *tollgate_core_get_config_json(void); | ||
| 27 | |||
| 28 | int tollgate_core_active_session_count(void); | ||
| 29 | int tollgate_core_allowed_client_count(void); | ||
| 30 | |||
| 31 | bool tollgate_core_is_owner(uint32_t client_ip); | ||
| 32 | bool tollgate_core_is_owner_connected(void); | ||
| 33 | |||
| 34 | #endif | ||
diff --git a/components/tollgate_core/include/tollgate_platform.h b/components/tollgate_core/include/tollgate_platform.h new file mode 100644 index 0000000..f60f1f9 --- /dev/null +++ b/components/tollgate_core/include/tollgate_platform.h | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | #ifndef TOLLGATE_PLATFORM_H | ||
| 2 | #define TOLLGATE_PLATFORM_H | ||
| 3 | |||
| 4 | #include <stdint.h> | ||
| 5 | #include <stdbool.h> | ||
| 6 | |||
| 7 | typedef struct { | ||
| 8 | uint16_t (*get_price_sats)(void); | ||
| 9 | int32_t (*get_step_ms)(void); | ||
| 10 | const char * (*get_mint_url)(void); | ||
| 11 | const char * (*get_metric)(void); | ||
| 12 | int32_t (*get_step_bytes)(void); | ||
| 13 | int64_t (*get_time_ms)(void); | ||
| 14 | bool (*spend_proofs)(const char *raw_token_json); | ||
| 15 | } tollgate_platform_t; | ||
| 16 | |||
| 17 | #endif | ||