From f6369f5b87f5dab17a03315d82454fdcdd668ec9 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 18 May 2026 18:50:20 +0530 Subject: feat: extract tollgate_core ESP-IDF component MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- components/tollgate_core/include/tollgate_core.h | 34 ++++++++++++++++++++++ .../tollgate_core/include/tollgate_platform.h | 17 +++++++++++ 2 files changed, 51 insertions(+) create mode 100644 components/tollgate_core/include/tollgate_core.h create mode 100644 components/tollgate_core/include/tollgate_platform.h (limited to 'components/tollgate_core/include') 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 @@ +#ifndef TOLLGATE_CORE_H +#define TOLLGATE_CORE_H + +#include "tollgate_platform.h" +#include "esp_err.h" +#include "esp_netif.h" +#include +#include + +esp_err_t tollgate_core_init(const tollgate_platform_t *platform, esp_ip4_addr_t ap_ip); + +esp_err_t tollgate_core_dns_start(esp_ip4_addr_t upstream_dns); +void tollgate_core_dns_stop(void); + +esp_err_t tollgate_core_process_payment(uint32_t client_ip, const char *token_str); + +void tollgate_core_client_connected(const uint8_t *mac, uint32_t client_ip); +void tollgate_core_client_disconnected(const uint8_t *mac); + +void tollgate_core_tick(void); + +bool tollgate_core_is_client_allowed(uint32_t client_ip); +bool tollgate_core_is_dns_running(void); + +char *tollgate_core_get_status_json(void); +char *tollgate_core_get_config_json(void); + +int tollgate_core_active_session_count(void); +int tollgate_core_allowed_client_count(void); + +bool tollgate_core_is_owner(uint32_t client_ip); +bool tollgate_core_is_owner_connected(void); + +#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 @@ +#ifndef TOLLGATE_PLATFORM_H +#define TOLLGATE_PLATFORM_H + +#include +#include + +typedef struct { + uint16_t (*get_price_sats)(void); + int32_t (*get_step_ms)(void); + const char * (*get_mint_url)(void); + const char * (*get_metric)(void); + int32_t (*get_step_bytes)(void); + int64_t (*get_time_ms)(void); + bool (*spend_proofs)(const char *raw_token_json); +} tollgate_platform_t; + +#endif -- cgit v1.2.3