upleb.uk

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

summaryrefslogtreecommitdiff
path: root/components/tollgate_core/src
diff options
context:
space:
mode:
authorYour Name <you@example.com>2026-05-23 04:10:28 +0530
committerYour Name <you@example.com>2026-05-23 04:10:28 +0530
commit851801f50f1282ab1db5f8a241dbd245f59e447e (patch)
tree3285d0714da89879acd21b8c3fb9afeff586ed1e /components/tollgate_core/src
parent39aa27a9522aeb8f731f4d3de48939e75775900e (diff)
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)
Diffstat (limited to 'components/tollgate_core/src')
-rw-r--r--components/tollgate_core/src/tollgate_core.c5
-rw-r--r--components/tollgate_core/src/tollgate_core_session.c6
-rw-r--r--components/tollgate_core/src/tollgate_core_session.h7
3 files changed, 18 insertions, 0 deletions
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)
234{ 234{
235 return s_owner_connected; 235 return s_owner_connected;
236} 236}
237
238const tollgate_platform_t *tollgate_core_get_platform(void)
239{
240 return s_platform;
241}
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
62 s_sessions[i].allotment_ms = allotment_ms; 62 s_sessions[i].allotment_ms = allotment_ms;
63 s_sessions[i].start_time_ms = get_time_ms(); 63 s_sessions[i].start_time_ms = get_time_ms();
64 s_sessions[i].active = true; 64 s_sessions[i].active = true;
65 s_sessions[i].payment_method = TG_PAYMENT_CASHU;
65 populate_mac(&s_sessions[i], client_ip); 66 populate_mac(&s_sessions[i], client_ip);
66 67
67 s_session_count++; 68 s_session_count++;
@@ -86,6 +87,7 @@ tg_session_t *tollgate_core_session_create_bytes(uint32_t client_ip, uint64_t al
86 s->allotment_bytes = allotment_bytes; 87 s->allotment_bytes = allotment_bytes;
87 s->bytes_consumed = 0; 88 s->bytes_consumed = 0;
88 s->allotment_ms = INT64_MAX; 89 s->allotment_ms = INT64_MAX;
90 s->payment_method = TG_PAYMENT_BYTES;
89 esp_ip4_addr_t ip = { .addr = client_ip }; 91 esp_ip4_addr_t ip = { .addr = client_ip };
90 ESP_LOGI(TAG, "Bytes session created: " IPSTR " allotment=%llu bytes", IP2STR(&ip), 92 ESP_LOGI(TAG, "Bytes session created: " IPSTR " allotment=%llu bytes", IP2STR(&ip),
91 (unsigned long long)allotment_bytes); 93 (unsigned long long)allotment_bytes);
@@ -135,6 +137,10 @@ bool tollgate_core_session_is_expired(const tg_session_t *session)
135{ 137{
136 if (!session || !session->active) return true; 138 if (!session || !session->active) return true;
137 139
140 if (session->payment_method == TG_PAYMENT_BYTES) {
141 return session->bytes_consumed >= session->allotment_bytes;
142 }
143
138 if (s_platform && s_platform->get_metric) { 144 if (s_platform && s_platform->get_metric) {
139 const char *metric = s_platform->get_metric(); 145 const char *metric = s_platform->get_metric();
140 if (metric && strcmp(metric, "bytes") == 0) { 146 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 @@
9#define TG_SESSION_MAX_CLIENTS 10 9#define TG_SESSION_MAX_CLIENTS 10
10#define TG_SESSION_MAX_MAC_LEN 18 10#define TG_SESSION_MAX_MAC_LEN 18
11 11
12typedef enum {
13 TG_PAYMENT_CASHU,
14 TG_PAYMENT_MINING,
15 TG_PAYMENT_BYTES
16} tg_payment_method_t;
17
12typedef struct { 18typedef struct {
13 uint32_t client_ip; 19 uint32_t client_ip;
14 char mac[TG_SESSION_MAX_MAC_LEN]; 20 char mac[TG_SESSION_MAX_MAC_LEN];
@@ -16,6 +22,7 @@ typedef struct {
16 int64_t start_time_ms; 22 int64_t start_time_ms;
17 uint64_t allotment_bytes; 23 uint64_t allotment_bytes;
18 uint64_t bytes_consumed; 24 uint64_t bytes_consumed;
25 tg_payment_method_t payment_method;
19 bool active; 26 bool active;
20} tg_session_t; 27} tg_session_t;
21 28