upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/tollgate_core/include/tollgate_core.h
diff options
context:
space:
mode:
authorYour Name <you@example.com>2026-05-23 02:32:24 +0530
committerYour Name <you@example.com>2026-05-23 02:32:24 +0530
commit6771956f1647f377007ab61a59b116de6d536706 (patch)
treee8b6c74164040339134e33b8616c27c23ec1ade6 /tollgate_core/include/tollgate_core.h
parent10c69b0ddc34a1fafada3f8b68a622b4aa2bea77 (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.h65
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
8int tollgate_core_init(const tollgate_platform_t *platform, uint32_t ap_ip);
9void tollgate_core_tick(void);
10
11int tollgate_core_dns_start(uint32_t upstream_dns);
12void tollgate_core_dns_stop(void);
13
14int tollgate_core_process_payment(uint32_t client_ip, const char *token_str);
15int tollgate_core_process_share(uint32_t client_ip, const char *job_id,
16 const char *nonce, const char *ntime, const char *version);
17
18void tollgate_core_client_connected(const uint8_t *mac, uint32_t client_ip);
19void tollgate_core_client_disconnected(const uint8_t *mac);
20
21bool tollgate_core_is_client_allowed(uint32_t client_ip);
22bool tollgate_core_is_dns_running(void);
23
24char *tollgate_core_get_status_json(void);
25char *tollgate_core_get_config_json(void);
26
27int tollgate_core_active_session_count(void);
28int tollgate_core_allowed_client_count(void);
29int tollgate_core_firewall_revoke_all(void);
30void tollgate_core_firewall_set_mining_port(uint16_t port);
31void tollgate_core_firewall_set_sandbox_mint_access(bool enable);
32
33bool tollgate_core_is_owner(uint32_t client_ip);
34bool tollgate_core_is_owner_connected(void);
35
36double tollgate_core_get_hashprice(void);
37void tollgate_core_set_nbits(uint32_t nbits);
38const void *tollgate_core_get_current_job(void);
39void tollgate_core_set_job(const void *job);
40
41int tollgate_core_stratum_client_start(void);
42void tollgate_core_stratum_client_stop(void);
43
44int tollgate_core_stratum_proxy_init(uint16_t port);
45void tollgate_core_stratum_proxy_get_stats(void *out);
46
47void tollgate_core_mining_init(void);
48
49void tollgate_core_beacon_start(void);
50
51void tollgate_core_market_init(void);
52void tollgate_core_market_on_scan_result(const void *ie_data, int ie_len,
53 const uint8_t *bssid, int rssi);
54
55const void *tollgate_core_get_sessions_array(void);
56int tollgate_core_get_sessions_array_size(void);
57void *tollgate_core_find_session_by_ip(uint32_t ip);
58void *tollgate_core_find_session_by_mac(const char *mac);
59void tollgate_core_session_extend(void *session, uint64_t additional_ms);
60int tollgate_core_session_add_bytes(uint32_t client_ip, uint64_t bytes);
61
62const tollgate_platform_t *tollgate_core_get_platform(void);
63uint32_t tollgate_core_get_ap_ip(void);
64
65#endif