upleb.uk

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

summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorYour Name <you@example.com>2026-05-20 02:10:01 +0530
committerYour Name <you@example.com>2026-05-20 02:10:01 +0530
commit82f1fc0d5535eda3fc9eab799d81b3e220dbe4ef (patch)
tree341dcecb0a87a6219bc51d424316dfadcf69bf65 /main
parent2c12c4281c47aa87a1c7bb82abe09bf9dbc788c3 (diff)
feat: add tollgate_core component + market config wiring
- Add tollgate_core ESP-IDF component (skeleton: cashu, dns, firewall, session) - Add tollgate_platform.c with SPIFFS config backend - Wire market_enabled, market_scan_interval_s, client_auto_switch in config.c - Add lwip_tollgate_hooks.h (updated from feature branch) - Add E2E fix plan, tollgate_core design doc, WPA autodetect plan - Add integration test network helpers - Add CONSOLIDATION.md plan Reverts the broken merge (be4788b) that gutted config.c/tollgate_main.c/tollgate_api.c and replaces it with a clean addition on top of intact master.
Diffstat (limited to 'main')
-rw-r--r--main/CMakeLists.txt3
-rw-r--r--main/config.c12
-rw-r--r--main/lwip_tollgate_hooks.h4
-rw-r--r--main/tollgate_platform.c63
4 files changed, 79 insertions, 3 deletions
diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt
index 90000b7..2107cf1 100644
--- a/main/CMakeLists.txt
+++ b/main/CMakeLists.txt
@@ -30,9 +30,10 @@ idf_component_register(SRCS "tollgate_main.c"
30 "stratum_proxy.c" 30 "stratum_proxy.c"
31 "sw_miner.c" 31 "sw_miner.c"
32 "asic_miner.c" 32 "asic_miner.c"
33 "tollgate_platform.c"
33 INCLUDE_DIRS "." 34 INCLUDE_DIRS "."
34 REQUIRES esp_wifi esp_event esp_netif nvs_flash esp_http_server 35 REQUIRES esp_wifi esp_event esp_netif nvs_flash esp_http_server
35 lwip json esp_http_client mbedtls esp-tls log spiffs 36 lwip json esp_http_client mbedtls esp-tls log spiffs
36 nucula_lib secp256k1 axs15231b qrcode wisp_relay 37 nucula_lib secp256k1 axs15231b qrcode wisp_relay
37 negentropy_lib tcp_transport 38 negentropy_lib tcp_transport tollgate_core
38 PRIV_REQUIRES esp-tls) 39 PRIV_REQUIRES esp-tls)
diff --git a/main/config.c b/main/config.c
index aa7da6d..43ab2a7 100644
--- a/main/config.c
+++ b/main/config.c
@@ -46,6 +46,9 @@ esp_err_t tollgate_config_init(void)
46 g_config.stratum_port = 3333; 46 g_config.stratum_port = 3333;
47 g_config.mining_port = 3334; 47 g_config.mining_port = 3334;
48 g_config.mining_sandbox_mint_access = true; 48 g_config.mining_sandbox_mint_access = true;
49 g_config.market_enabled = true;
50 g_config.market_scan_interval_s = 30;
51 g_config.client_auto_switch = false;
49 52
50 esp_vfs_spiffs_conf_t conf = { 53 esp_vfs_spiffs_conf_t conf = {
51 .base_path = "/spiffs", 54 .base_path = "/spiffs",
@@ -361,6 +364,15 @@ esp_err_t tollgate_config_init(void)
361 if (m_sandbox && cJSON_IsBool(m_sandbox)) g_config.mining_sandbox_mint_access = cJSON_IsTrue(m_sandbox); 364 if (m_sandbox && cJSON_IsBool(m_sandbox)) g_config.mining_sandbox_mint_access = cJSON_IsTrue(m_sandbox);
362 } 365 }
363 366
367 cJSON *market_enabled = cJSON_GetObjectItem(root, "market_enabled");
368 if (market_enabled && cJSON_IsBool(market_enabled)) g_config.market_enabled = cJSON_IsTrue(market_enabled);
369
370 cJSON *market_scan_interval = cJSON_GetObjectItem(root, "market_scan_interval_s");
371 if (market_scan_interval) g_config.market_scan_interval_s = market_scan_interval->valueint;
372
373 cJSON *client_auto_switch = cJSON_GetObjectItem(root, "client_auto_switch");
374 if (client_auto_switch && cJSON_IsBool(client_auto_switch)) g_config.client_auto_switch = cJSON_IsTrue(client_auto_switch);
375
364 cJSON_Delete(root); 376 cJSON_Delete(root);
365 377
366 if (g_config.payout.recipient_count == 0) { 378 if (g_config.payout.recipient_count == 0) {
diff --git a/main/lwip_tollgate_hooks.h b/main/lwip_tollgate_hooks.h
index 76017be..2953c48 100644
--- a/main/lwip_tollgate_hooks.h
+++ b/main/lwip_tollgate_hooks.h
@@ -3,8 +3,8 @@
3 3
4#include "lwip/pbuf.h" 4#include "lwip/pbuf.h"
5 5
6int tollgate_ip4_canforward_filter(struct pbuf *p, u32_t dest_addr_hostorder); 6int tollgate_core_ip4_canforward_filter(struct pbuf *p, u32_t dest_addr_hostorder);
7 7
8#define LWIP_HOOK_IP4_CANFORWARD(p, addr) tollgate_ip4_canforward_filter(p, addr) 8#define LWIP_HOOK_IP4_CANFORWARD(p, addr) tollgate_core_ip4_canforward_filter(p, addr)
9 9
10#endif 10#endif
diff --git a/main/tollgate_platform.c b/main/tollgate_platform.c
new file mode 100644
index 0000000..4083c4e
--- /dev/null
+++ b/main/tollgate_platform.c
@@ -0,0 +1,63 @@
1#include "tollgate_platform.h"
2#include "tollgate_core.h"
3#include "config.h"
4#include "esp_log.h"
5#include "freertos/FreeRTOS.h"
6#include "freertos/task.h"
7
8static const char *TAG = "tollgate_platform";
9
10static uint16_t platform_get_price_sats(void)
11{
12 const tollgate_config_t *cfg = tollgate_config_get();
13 return cfg ? (uint16_t)cfg->price_per_step : 21;
14}
15
16static int32_t platform_get_step_ms(void)
17{
18 const tollgate_config_t *cfg = tollgate_config_get();
19 return cfg ? (int32_t)cfg->step_size_ms : 60000;
20}
21
22static const char *platform_get_mint_url(void)
23{
24 const tollgate_config_t *cfg = tollgate_config_get();
25 return cfg ? cfg->mint_url : "https://testnut.cashu.space";
26}
27
28static const char *platform_get_metric(void)
29{
30 const tollgate_config_t *cfg = tollgate_config_get();
31 return cfg ? cfg->metric : "milliseconds";
32}
33
34static int32_t platform_get_step_bytes(void)
35{
36 const tollgate_config_t *cfg = tollgate_config_get();
37 return cfg ? (int32_t)cfg->step_size_bytes : 22020096;
38}
39
40static int64_t platform_get_time_ms(void)
41{
42 return (int64_t)xTaskGetTickCount() * portTICK_PERIOD_MS;
43}
44
45static bool platform_spend_proofs(const char *raw_token_json)
46{
47 (void)raw_token_json;
48 return true;
49}
50
51const tollgate_platform_t *tollgate_get_platform(void)
52{
53 static const tollgate_platform_t platform = {
54 .get_price_sats = platform_get_price_sats,
55 .get_step_ms = platform_get_step_ms,
56 .get_mint_url = platform_get_mint_url,
57 .get_metric = platform_get_metric,
58 .get_step_bytes = platform_get_step_bytes,
59 .get_time_ms = platform_get_time_ms,
60 .spend_proofs = platform_spend_proofs,
61 };
62 return &platform;
63}