upleb.uk

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

summaryrefslogtreecommitdiff
path: root/tollgate_core
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 /tollgate_core
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 'tollgate_core')
-rw-r--r--tollgate_core/include/tollgate_core.h25
-rw-r--r--tollgate_core/src/tollgate_core.c112
2 files changed, 137 insertions, 0 deletions
diff --git a/tollgate_core/include/tollgate_core.h b/tollgate_core/include/tollgate_core.h
index fc20caa..bbae7cf 100644
--- a/tollgate_core/include/tollgate_core.h
+++ b/tollgate_core/include/tollgate_core.h
@@ -56,8 +56,33 @@ const void *tollgate_core_get_sessions_array(void);
56int tollgate_core_get_sessions_array_size(void); 56int tollgate_core_get_sessions_array_size(void);
57void *tollgate_core_find_session_by_ip(uint32_t ip); 57void *tollgate_core_find_session_by_ip(uint32_t ip);
58void *tollgate_core_find_session_by_mac(const char *mac); 58void *tollgate_core_find_session_by_mac(const char *mac);
59void *tollgate_core_session_create(uint32_t client_ip, uint64_t allotment_ms);
60void *tollgate_core_session_create_bytes(uint32_t client_ip, uint64_t allotment_bytes);
59void tollgate_core_session_extend(void *session, uint64_t additional_ms); 61void tollgate_core_session_extend(void *session, uint64_t additional_ms);
62void tollgate_core_session_revoke(void *session);
60int tollgate_core_session_add_bytes(uint32_t client_ip, uint64_t bytes); 63int tollgate_core_session_add_bytes(uint32_t client_ip, uint64_t bytes);
64bool tollgate_core_session_is_expired(const void *session);
65
66void tollgate_core_firewall_grant(uint32_t client_ip);
67void tollgate_core_firewall_revoke(uint32_t client_ip);
68int tollgate_core_firewall_get_mac_for_ip(uint32_t client_ip, char *mac_out, int mac_out_size);
69
70int tollgate_core_cashu_decode(const char *token_str, void *out);
71int tollgate_core_cashu_check_states(const char *mint_url, const void *token,
72 void *states, int *state_count);
73uint64_t tollgate_core_cashu_allotment(uint64_t amount, uint64_t price, uint64_t step_size);
74bool tollgate_core_cashu_is_mint_accepted(const char *mint_url);
75const char *tollgate_core_cashu_token_mint(const void *token);
76uint64_t tollgate_core_cashu_token_amount(const void *token);
77
78void tollgate_core_mining_update_hashrate(uint32_t client_ip, bool accepted);
79const void *tollgate_core_mining_get_client_stats(uint32_t client_ip);
80double tollgate_core_mining_get_hashprice(void);
81uint64_t tollgate_core_mining_shares_to_allotment_ms(double hashrate, double hashprice,
82 int price, int step_ms);
83uint64_t tollgate_core_mining_shares_to_allotment_bytes(double hashrate, double hashprice,
84 int price, int step_bytes);
85void tollgate_core_mining_set_nbits(uint32_t nbits);
61 86
62const tollgate_platform_t *tollgate_core_get_platform(void); 87const tollgate_platform_t *tollgate_core_get_platform(void);
63uint32_t tollgate_core_get_ap_ip(void); 88uint32_t tollgate_core_get_ap_ip(void);
diff --git a/tollgate_core/src/tollgate_core.c b/tollgate_core/src/tollgate_core.c
index 2f32576..c7c2902 100644
--- a/tollgate_core/src/tollgate_core.c
+++ b/tollgate_core/src/tollgate_core.c
@@ -345,6 +345,118 @@ int tollgate_core_session_add_bytes(uint32_t client_ip, uint64_t bytes)
345 return 0; 345 return 0;
346} 346}
347 347
348void *tollgate_core_session_create(uint32_t client_ip, uint64_t allotment_ms)
349{
350 return tg_session_create(client_ip, allotment_ms);
351}
352
353void *tollgate_core_session_create_bytes(uint32_t client_ip, uint64_t allotment_bytes)
354{
355 return tg_session_create_bytes(client_ip, allotment_bytes);
356}
357
358void tollgate_core_session_revoke(void *session)
359{
360 tg_session_revoke((tg_session_t *)session);
361}
362
363bool tollgate_core_session_is_expired(const void *session)
364{
365 return tg_session_is_expired((const tg_session_t *)session);
366}
367
368void tollgate_core_firewall_grant(uint32_t client_ip)
369{
370 tg_firewall_grant(client_ip);
371}
372
373void tollgate_core_firewall_revoke(uint32_t client_ip)
374{
375 tg_firewall_revoke(client_ip);
376}
377
378int tollgate_core_firewall_get_mac_for_ip(uint32_t client_ip, char *mac_out, int mac_out_size)
379{
380 return tg_firewall_get_mac_for_ip(client_ip, mac_out, mac_out_size);
381}
382
383int tollgate_core_cashu_decode(const char *token_str, void *out)
384{
385 return tg_cashu_decode_token(token_str, (tg_cashu_token_t *)out);
386}
387
388int tollgate_core_cashu_check_states(const char *mint_url, const void *token,
389 void *states, int *state_count)
390{
391 return tg_cashu_check_proof_states(mint_url, (const tg_cashu_token_t *)token,
392 (tg_cashu_proof_state_t *)states, state_count);
393}
394
395uint64_t tollgate_core_cashu_allotment(uint64_t amount, uint64_t price, uint64_t step_size)
396{
397 return tg_cashu_calculate_allotment(amount, price, step_size);
398}
399
400bool tollgate_core_cashu_is_mint_accepted(const char *mint_url)
401{
402 if (!s_platform) return false;
403 const char *accepted = s_platform->get_mint_url ? s_platform->get_mint_url() : NULL;
404 if (!accepted) return false;
405 if (s_platform->get_accepted_mint_count && s_platform->get_accepted_mint) {
406 int count = s_platform->get_accepted_mint_count();
407 for (int i = 0; i < count; i++) {
408 if (tg_cashu_is_mint_accepted(mint_url, s_platform->get_accepted_mint(i)))
409 return true;
410 }
411 return false;
412 }
413 return tg_cashu_is_mint_accepted(mint_url, accepted);
414}
415
416const char *tollgate_core_cashu_token_mint(const void *token)
417{
418 const tg_cashu_token_t *t = (const tg_cashu_token_t *)token;
419 return t->mint_url;
420}
421
422uint64_t tollgate_core_cashu_token_amount(const void *token)
423{
424 const tg_cashu_token_t *t = (const tg_cashu_token_t *)token;
425 return t->total_amount;
426}
427
428void tollgate_core_mining_update_hashrate(uint32_t client_ip, bool accepted)
429{
430 tg_mining_update_hashrate(client_ip, accepted);
431}
432
433const void *tollgate_core_mining_get_client_stats(uint32_t client_ip)
434{
435 return tg_mining_get_client_stats(client_ip);
436}
437
438double tollgate_core_mining_get_hashprice(void)
439{
440 return tg_mining_get_current_hashprice();
441}
442
443uint64_t tollgate_core_mining_shares_to_allotment_ms(double hashrate, double hashprice,
444 int price, int step_ms)
445{
446 return tg_mining_shares_to_allotment_ms(hashrate, hashprice, price, step_ms);
447}
448
449uint64_t tollgate_core_mining_shares_to_allotment_bytes(double hashrate, double hashprice,
450 int price, int step_bytes)
451{
452 return tg_mining_shares_to_allotment_bytes(hashrate, hashprice, price, step_bytes);
453}
454
455void tollgate_core_mining_set_nbits(uint32_t nbits)
456{
457 tg_mining_set_current_nbits(nbits);
458}
459
348int tollgate_core_dns_start(uint32_t upstream_dns) 460int tollgate_core_dns_start(uint32_t upstream_dns)
349{ 461{
350 (void)upstream_dns; 462 (void)upstream_dns;