diff options
| author | Your Name <you@example.com> | 2026-05-23 02:32:24 +0530 |
|---|---|---|
| committer | Your Name <you@example.com> | 2026-05-23 02:32:24 +0530 |
| commit | 6771956f1647f377007ab61a59b116de6d536706 (patch) | |
| tree | e8b6c74164040339134e33b8616c27c23ec1ade6 /tollgate_core/include/tollgate_core.h | |
| parent | 10c69b0ddc34a1fafada3f8b68a622b4aa2bea77 (diff) | |
feat: create tollgate_core standalone C library + tollgate_esp IDF component
Phase 1-4: Extract core business logic into reusable library
tollgate_core/ — standalone C library (zero ESP-IDF deps):
- tollgate_core.c — orchestrator (init, process_payment, process_share, tick)
- tollgate_cashu.c — V3 token decode, checkstate via platform callback, allotment math
- tollgate_session.c — session lifecycle state machine (create/find/revoke/extend)
- tollgate_firewall.c — client allowlist, NAT filter, packet filter
- tollgate_mining.c — hashprice, nbits→difficulty, shares-to-allotment, client stats
components/tollgate_esp/ — ESP-IDF component wrapper:
- tollgate_esp_platform.c — implements tollgate_platform_t using ESP-IDF APIs
- CMakeLists.txt — compiles tollgate_core + ESP wrapper, links to ESP-IDF
- idf_component.yml — for IDF Component Registry
Platform interface (tollgate_platform.h):
- Config access: price, step_size, mint_url, metric
- Time: get_time_ms (via FreeRTOS ticks on ESP)
- Logging: log_info/warn/error (via ESP_LOG on ESP)
- Wallet: receive/send/balance (via nucula on ESP)
- HTTP: http_post (via esp_http_client on ESP)
- WiFi/MAC: mac_for_ip, napt_enable
- Mining: stratum config, hashprice override
Build verification:
- tollgate_core compiles standalone: cmake + make (gcc, host)
- tollgate_esp + ESP-IDF full build: passes (idf.py build)
- Unit tests: 22/22 pass (make test-unit)
- No behavioral change to existing main/ code yet (Phase 5)
Diffstat (limited to 'tollgate_core/include/tollgate_core.h')
| -rw-r--r-- | tollgate_core/include/tollgate_core.h | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/tollgate_core/include/tollgate_core.h b/tollgate_core/include/tollgate_core.h new file mode 100644 index 0000000..fc20caa --- /dev/null +++ b/tollgate_core/include/tollgate_core.h | |||
| @@ -0,0 +1,65 @@ | |||
| 1 | #ifndef TOLLGATE_CORE_H | ||
| 2 | #define TOLLGATE_CORE_H | ||
| 3 | |||
| 4 | #include "tollgate_platform.h" | ||
| 5 | #include <stdbool.h> | ||
| 6 | #include <stdint.h> | ||
| 7 | |||
| 8 | int tollgate_core_init(const tollgate_platform_t *platform, uint32_t ap_ip); | ||
| 9 | void tollgate_core_tick(void); | ||
| 10 | |||
| 11 | int tollgate_core_dns_start(uint32_t upstream_dns); | ||
| 12 | void tollgate_core_dns_stop(void); | ||
| 13 | |||
| 14 | int tollgate_core_process_payment(uint32_t client_ip, const char *token_str); | ||
| 15 | int tollgate_core_process_share(uint32_t client_ip, const char *job_id, | ||
| 16 | const char *nonce, const char *ntime, const char *version); | ||
| 17 | |||
| 18 | void tollgate_core_client_connected(const uint8_t *mac, uint32_t client_ip); | ||
| 19 | void tollgate_core_client_disconnected(const uint8_t *mac); | ||
| 20 | |||
| 21 | bool tollgate_core_is_client_allowed(uint32_t client_ip); | ||
| 22 | bool tollgate_core_is_dns_running(void); | ||
| 23 | |||
| 24 | char *tollgate_core_get_status_json(void); | ||
| 25 | char *tollgate_core_get_config_json(void); | ||
| 26 | |||
| 27 | int tollgate_core_active_session_count(void); | ||
| 28 | int tollgate_core_allowed_client_count(void); | ||
| 29 | int tollgate_core_firewall_revoke_all(void); | ||
| 30 | void tollgate_core_firewall_set_mining_port(uint16_t port); | ||
| 31 | void tollgate_core_firewall_set_sandbox_mint_access(bool enable); | ||
| 32 | |||
| 33 | bool tollgate_core_is_owner(uint32_t client_ip); | ||
| 34 | bool tollgate_core_is_owner_connected(void); | ||
| 35 | |||
| 36 | double tollgate_core_get_hashprice(void); | ||
| 37 | void tollgate_core_set_nbits(uint32_t nbits); | ||
| 38 | const void *tollgate_core_get_current_job(void); | ||
| 39 | void tollgate_core_set_job(const void *job); | ||
| 40 | |||
| 41 | int tollgate_core_stratum_client_start(void); | ||
| 42 | void tollgate_core_stratum_client_stop(void); | ||
| 43 | |||
| 44 | int tollgate_core_stratum_proxy_init(uint16_t port); | ||
| 45 | void tollgate_core_stratum_proxy_get_stats(void *out); | ||
| 46 | |||
| 47 | void tollgate_core_mining_init(void); | ||
| 48 | |||
| 49 | void tollgate_core_beacon_start(void); | ||
| 50 | |||
| 51 | void tollgate_core_market_init(void); | ||
| 52 | void tollgate_core_market_on_scan_result(const void *ie_data, int ie_len, | ||
| 53 | const uint8_t *bssid, int rssi); | ||
| 54 | |||
| 55 | const void *tollgate_core_get_sessions_array(void); | ||
| 56 | int tollgate_core_get_sessions_array_size(void); | ||
| 57 | void *tollgate_core_find_session_by_ip(uint32_t ip); | ||
| 58 | void *tollgate_core_find_session_by_mac(const char *mac); | ||
| 59 | void tollgate_core_session_extend(void *session, uint64_t additional_ms); | ||
| 60 | int tollgate_core_session_add_bytes(uint32_t client_ip, uint64_t bytes); | ||
| 61 | |||
| 62 | const tollgate_platform_t *tollgate_core_get_platform(void); | ||
| 63 | uint32_t tollgate_core_get_ap_ip(void); | ||
| 64 | |||
| 65 | #endif | ||