From 78dd599277b8e8b2ddc39a4ae710ec91d737272e Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 17 May 2026 04:21:39 +0530 Subject: Phase 4: TollGate client detection + auto-payment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - New tollgate_client.c/h: detect upstream TollGate (kind=10021), auto-pay via nucula wallet, session monitoring with 20% renewal - State machine: IDLE→DETECTING→NEEDS_PAY→PAYING→PAID→RENEWING - Blocking: upstream payment before local services start - Synchronous wallet init (was async task) - Client config: enabled, steps_to_buy, renewal_threshold_pct - Updated PLAN.md with Phases 4-7 (client, payout, bytes, CVM) - Updated CHECKLIST.md with all new phase items - 30 new unit tests (all passing), 116 total --- main/tollgate_client.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 main/tollgate_client.h (limited to 'main/tollgate_client.h') diff --git a/main/tollgate_client.h b/main/tollgate_client.h new file mode 100644 index 0000000..2055e52 --- /dev/null +++ b/main/tollgate_client.h @@ -0,0 +1,46 @@ +#ifndef TOLLGATE_CLIENT_H +#define TOLLGATE_CLIENT_H + +#include "esp_err.h" +#include +#include + +#define TG_CLIENT_MAX_GW_IP_LEN 16 +#define TG_CLIENT_MAX_MINT_URL 256 +#define TG_CLIENT_MAX_METRIC 32 + +typedef enum { + TG_CLIENT_IDLE, + TG_CLIENT_DETECTING, + TG_CLIENT_NO_TOLLGATE, + TG_CLIENT_NEEDS_PAY, + TG_CLIENT_PAYING, + TG_CLIENT_PAID, + TG_CLIENT_RENEWING, + TG_CLIENT_ERROR +} tollgate_client_state_t; + +typedef struct { + bool is_tollgate; + int price_per_step; + int step_size_ms; + char mint_url[TG_CLIENT_MAX_MINT_URL]; + char metric[TG_CLIENT_MAX_METRIC]; +} tollgate_discovery_t; + +esp_err_t tollgate_client_init(void); + +esp_err_t tollgate_client_on_sta_connected(const char *gw_ip_str); + +void tollgate_client_on_sta_disconnected(void); + +void tollgate_client_tick(void); + +tollgate_client_state_t tollgate_client_get_state(void); + +const tollgate_discovery_t *tollgate_client_get_discovery(void); + +int64_t tollgate_client_get_remaining_ms(void); +int64_t tollgate_client_get_allotment_ms(void); + +#endif -- cgit v1.2.3