From 851801f50f1282ab1db5f8a241dbd245f59e447e Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 23 May 2026 04:10:28 +0530 Subject: Phase 5: Wire main/ shims to components/tollgate_core - session.c/h: thin shim casting session_t* <-> tg_session_t*, delegates to tollgate_core_session_* - firewall.c/h: keeps ESP-specific lwIP hooks, delegates allowlist to tollgate_core_fw_* - cashu.c/h: shim delegates to tollgate_core_cashu_*, multi-mint via config directly - mining_payment.c: shim delegates to tollgate_core_mining_* - tollgate_main.c: calls tollgate_core_init(tollgate_esp_get_platform(), ap_ip) in start_services() - tollgate_esp: removed target_sources for standalone sources, depends on tollgate_core component - tollgate_core component: added tollgate_core_get_platform(), tg_payment_method_t enum - Unit tests: updated Makefile for component source compilation, all 22 tests pass - Hardware verified: Board A boots, AP visible, 5/6 smoke tests pass (internet test needs upstream WiFi) --- components/tollgate_core/src/tollgate_core.c | 5 +++++ components/tollgate_core/src/tollgate_core_session.c | 6 ++++++ components/tollgate_core/src/tollgate_core_session.h | 7 +++++++ 3 files changed, 18 insertions(+) (limited to 'components/tollgate_core/src') diff --git a/components/tollgate_core/src/tollgate_core.c b/components/tollgate_core/src/tollgate_core.c index a731f48..2b337c3 100644 --- a/components/tollgate_core/src/tollgate_core.c +++ b/components/tollgate_core/src/tollgate_core.c @@ -234,3 +234,8 @@ bool tollgate_core_is_owner_connected(void) { return s_owner_connected; } + +const tollgate_platform_t *tollgate_core_get_platform(void) +{ + return s_platform; +} diff --git a/components/tollgate_core/src/tollgate_core_session.c b/components/tollgate_core/src/tollgate_core_session.c index 48d32e7..2329e0d 100644 --- a/components/tollgate_core/src/tollgate_core_session.c +++ b/components/tollgate_core/src/tollgate_core_session.c @@ -62,6 +62,7 @@ tg_session_t *tollgate_core_session_create(uint32_t client_ip, uint64_t allotmen s_sessions[i].allotment_ms = allotment_ms; s_sessions[i].start_time_ms = get_time_ms(); s_sessions[i].active = true; + s_sessions[i].payment_method = TG_PAYMENT_CASHU; populate_mac(&s_sessions[i], client_ip); s_session_count++; @@ -86,6 +87,7 @@ tg_session_t *tollgate_core_session_create_bytes(uint32_t client_ip, uint64_t al s->allotment_bytes = allotment_bytes; s->bytes_consumed = 0; s->allotment_ms = INT64_MAX; + s->payment_method = TG_PAYMENT_BYTES; esp_ip4_addr_t ip = { .addr = client_ip }; ESP_LOGI(TAG, "Bytes session created: " IPSTR " allotment=%llu bytes", IP2STR(&ip), (unsigned long long)allotment_bytes); @@ -135,6 +137,10 @@ bool tollgate_core_session_is_expired(const tg_session_t *session) { if (!session || !session->active) return true; + if (session->payment_method == TG_PAYMENT_BYTES) { + return session->bytes_consumed >= session->allotment_bytes; + } + if (s_platform && s_platform->get_metric) { const char *metric = s_platform->get_metric(); if (metric && strcmp(metric, "bytes") == 0) { diff --git a/components/tollgate_core/src/tollgate_core_session.h b/components/tollgate_core/src/tollgate_core_session.h index 444b9fa..b612f21 100644 --- a/components/tollgate_core/src/tollgate_core_session.h +++ b/components/tollgate_core/src/tollgate_core_session.h @@ -9,6 +9,12 @@ #define TG_SESSION_MAX_CLIENTS 10 #define TG_SESSION_MAX_MAC_LEN 18 +typedef enum { + TG_PAYMENT_CASHU, + TG_PAYMENT_MINING, + TG_PAYMENT_BYTES +} tg_payment_method_t; + typedef struct { uint32_t client_ip; char mac[TG_SESSION_MAX_MAC_LEN]; @@ -16,6 +22,7 @@ typedef struct { int64_t start_time_ms; uint64_t allotment_bytes; uint64_t bytes_consumed; + tg_payment_method_t payment_method; bool active; } tg_session_t; -- cgit v1.2.3