upleb.uk

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

summaryrefslogtreecommitdiff
path: root/main/config.c
diff options
context:
space:
mode:
authorYour Name <you@example.com>2026-05-17 04:50:07 +0530
committerYour Name <you@example.com>2026-05-17 04:50:07 +0530
commitedd125d0e3fe5fe7c0edf30c429723f3b0120c68 (patch)
tree5b1134ad7a6cfce7adeb46f5069e33b509ce9751 /main/config.c
parentcb4bd7d7c10cadcb43f82c09b13ffed744e541f7 (diff)
feat(phase6): bytes-based billing - dual metric support
- session_create_bytes() + session_add_bytes() for bytes-metric sessions - session_is_expired() dispatches on config metric (bytes vs milliseconds) - cashu_calculate_allotment() unified dispatcher for both metrics - tollgate_api discovery/usage/session_event use configured metric - config: metric field defaults to 'bytes', step_size_bytes=22020096 (21MB) - 14 new unit tests (148 total passing) - ASSERT_EQ_UINT64 macro added to test framework
Diffstat (limited to 'main/config.c')
-rw-r--r--main/config.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/main/config.c b/main/config.c
index 9257397..3e01efc 100644
--- a/main/config.c
+++ b/main/config.c
@@ -20,6 +20,8 @@ esp_err_t tollgate_config_init(void)
20 g_config.ap_max_conn = 4; 20 g_config.ap_max_conn = 4;
21 g_config.price_per_step = 21; 21 g_config.price_per_step = 21;
22 g_config.step_size_ms = 60000; 22 g_config.step_size_ms = 60000;
23 g_config.step_size_bytes = 22020096;
24 strncpy(g_config.metric, "bytes", sizeof(g_config.metric) - 1);
23 g_config.persist_threshold_sats = 1; 25 g_config.persist_threshold_sats = 1;
24 g_config.nostr_publish_interval_s = 21600; 26 g_config.nostr_publish_interval_s = 21600;
25 g_config.client_enabled = false; 27 g_config.client_enabled = false;
@@ -136,6 +138,14 @@ esp_err_t tollgate_config_init(void)
136 cJSON *step = cJSON_GetObjectItem(root, "step_size_ms"); 138 cJSON *step = cJSON_GetObjectItem(root, "step_size_ms");
137 if (step) g_config.step_size_ms = step->valueint; 139 if (step) g_config.step_size_ms = step->valueint;
138 140
141 cJSON *step_bytes = cJSON_GetObjectItem(root, "step_size_bytes");
142 if (step_bytes) g_config.step_size_bytes = step_bytes->valueint;
143
144 cJSON *metric = cJSON_GetObjectItem(root, "metric");
145 if (metric && cJSON_IsString(metric)) {
146 strncpy(g_config.metric, metric->valuestring, sizeof(g_config.metric) - 1);
147 }
148
139 cJSON *persist = cJSON_GetObjectItem(root, "persist_threshold_sats"); 149 cJSON *persist = cJSON_GetObjectItem(root, "persist_threshold_sats");
140 if (persist) g_config.persist_threshold_sats = (uint64_t)persist->valuedouble; 150 if (persist) g_config.persist_threshold_sats = (uint64_t)persist->valuedouble;
141 151