diff options
| author | Your Name <you@example.com> | 2026-05-17 04:21:39 +0530 |
|---|---|---|
| committer | Your Name <you@example.com> | 2026-05-17 04:21:39 +0530 |
| commit | 78dd599277b8e8b2ddc39a4ae710ec91d737272e (patch) | |
| tree | 9fbd89695cede00b8ff3b12ce428e96a2aa70e9b /main/tollgate_client.h | |
| parent | b0d7394e089f00a9ffa67a2b33a502e47b778a93 (diff) | |
Phase 4: TollGate client detection + auto-payment
- 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
Diffstat (limited to 'main/tollgate_client.h')
| -rw-r--r-- | main/tollgate_client.h | 46 |
1 files changed, 46 insertions, 0 deletions
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 @@ | |||
| 1 | #ifndef TOLLGATE_CLIENT_H | ||
| 2 | #define TOLLGATE_CLIENT_H | ||
| 3 | |||
| 4 | #include "esp_err.h" | ||
| 5 | #include <stdint.h> | ||
| 6 | #include <stdbool.h> | ||
| 7 | |||
| 8 | #define TG_CLIENT_MAX_GW_IP_LEN 16 | ||
| 9 | #define TG_CLIENT_MAX_MINT_URL 256 | ||
| 10 | #define TG_CLIENT_MAX_METRIC 32 | ||
| 11 | |||
| 12 | typedef enum { | ||
| 13 | TG_CLIENT_IDLE, | ||
| 14 | TG_CLIENT_DETECTING, | ||
| 15 | TG_CLIENT_NO_TOLLGATE, | ||
| 16 | TG_CLIENT_NEEDS_PAY, | ||
| 17 | TG_CLIENT_PAYING, | ||
| 18 | TG_CLIENT_PAID, | ||
| 19 | TG_CLIENT_RENEWING, | ||
| 20 | TG_CLIENT_ERROR | ||
| 21 | } tollgate_client_state_t; | ||
| 22 | |||
| 23 | typedef struct { | ||
| 24 | bool is_tollgate; | ||
| 25 | int price_per_step; | ||
| 26 | int step_size_ms; | ||
| 27 | char mint_url[TG_CLIENT_MAX_MINT_URL]; | ||
| 28 | char metric[TG_CLIENT_MAX_METRIC]; | ||
| 29 | } tollgate_discovery_t; | ||
| 30 | |||
| 31 | esp_err_t tollgate_client_init(void); | ||
| 32 | |||
| 33 | esp_err_t tollgate_client_on_sta_connected(const char *gw_ip_str); | ||
| 34 | |||
| 35 | void tollgate_client_on_sta_disconnected(void); | ||
| 36 | |||
| 37 | void tollgate_client_tick(void); | ||
| 38 | |||
| 39 | tollgate_client_state_t tollgate_client_get_state(void); | ||
| 40 | |||
| 41 | const tollgate_discovery_t *tollgate_client_get_discovery(void); | ||
| 42 | |||
| 43 | int64_t tollgate_client_get_remaining_ms(void); | ||
| 44 | int64_t tollgate_client_get_allotment_ms(void); | ||
| 45 | |||
| 46 | #endif | ||