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. --- main/tollgate_platform.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 main/tollgate_platform.c (limited to 'main/tollgate_platform.c') diff --git a/main/tollgate_platform.c b/main/tollgate_platform.c new file mode 100644 index 0000000..c992ea1 --- /dev/null +++ b/main/tollgate_platform.c @@ -0,0 +1,64 @@ +#include "tollgate_platform.h" +#include "tollgate_core.h" +#include "config.h" +#include "esp_log.h" +#include "esp_timer.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" + +static const char *TAG = "tollgate_platform"; + +static uint16_t platform_get_price_sats(void) +{ + const tollgate_config_t *cfg = tollgate_config_get(); + return cfg ? (uint16_t)cfg->price_per_step : 21; +} + +static int32_t platform_get_step_ms(void) +{ + const tollgate_config_t *cfg = tollgate_config_get(); + return cfg ? (int32_t)cfg->step_size_ms : 60000; +} + +static const char *platform_get_mint_url(void) +{ + const tollgate_config_t *cfg = tollgate_config_get(); + return cfg ? cfg->mint_url : "https://testnut.cashu.space"; +} + +static const char *platform_get_metric(void) +{ + const tollgate_config_t *cfg = tollgate_config_get(); + return cfg ? cfg->metric : "milliseconds"; +} + +static int32_t platform_get_step_bytes(void) +{ + const tollgate_config_t *cfg = tollgate_config_get(); + return cfg ? (int32_t)cfg->step_size_bytes : 22020096; +} + +static int64_t platform_get_time_ms(void) +{ + return (int64_t)xTaskGetTickCount() * portTICK_PERIOD_MS; +} + +static bool platform_spend_proofs(const char *raw_token_json) +{ + (void)raw_token_json; + return true; +} + +const tollgate_platform_t *tollgate_get_platform(void) +{ + static const tollgate_platform_t platform = { + .get_price_sats = platform_get_price_sats, + .get_step_ms = platform_get_step_ms, + .get_mint_url = platform_get_mint_url, + .get_metric = platform_get_metric, + .get_step_bytes = platform_get_step_bytes, + .get_time_ms = platform_get_time_ms, + .spend_proofs = platform_spend_proofs, + }; + return &platform; +} -- cgit v1.2.3