upleb.uk

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

summaryrefslogtreecommitdiff
path: root/main/session.h
diff options
context:
space:
mode:
authorYour Name <you@example.com>2026-05-15 22:27:14 +0530
committerYour Name <you@example.com>2026-05-15 22:27:14 +0530
commit1263d86314fc0760d9be8eea415ccecbc047a5eb (patch)
tree778130f0beb59d52f68e0e5f11388bf4b1470130 /main/session.h
parenta7d0a672d59bf8985a6fc0e61b49015fabd96513 (diff)
Phase 2 WIP: Cashu payment endpoints, session tracking, updated checklist
- Add cashu.c/h: Cashu token decode (cashuA/base64url), proof state check via mint API, allotment calculator - Add session.c/h: time-based session management with allotment/expiry, spent secret tracking - Add tollgate_api.c/h: HTTP server on :2121 with GET / (kind=10021 discovery), POST / (payment processing), /usage, /whoami - Update captive portal HTML: replace Grant Free Access with Cashu token paste form + Pay & Connect button - Update tollgate_main.c: wire in session manager, TollGate API, 1s session tick loop - Add tests/phase2.mjs: Phase 2 test suite (discovery, invalid token, wrong mint, valid payment) - Update CHECKLIST.md: reflect Phase 1 complete, Phase 2 in progress with known bugs Known issues (not yet flashed): - Stack overflow crash in httpd POST handler (need stack_size=16384 + heap allocations) - cashu_decode_token uses 2KB stack buffer (needs heap alloc) - Mint URL should be testnut.cashu.space (nofee.testnut has API compat issues)
Diffstat (limited to 'main/session.h')
-rw-r--r--main/session.h44
1 files changed, 44 insertions, 0 deletions
diff --git a/main/session.h b/main/session.h
new file mode 100644
index 0000000..e7d78d4
--- /dev/null
+++ b/main/session.h
@@ -0,0 +1,44 @@
1#ifndef SESSION_H
2#define SESSION_H
3
4#include "esp_err.h"
5#include <stdint.h>
6#include <stdbool.h>
7
8#define SESSION_MAX_CLIENTS 10
9#define SESSION_MAX_MAC_LEN 18
10
11typedef struct {
12 uint32_t client_ip;
13 char mac[SESSION_MAX_MAC_LEN];
14 uint64_t allotment_ms;
15 int64_t start_time_ms;
16 bool active;
17 char spent_secrets[5][65];
18 int spent_secret_count;
19} session_t;
20
21esp_err_t session_manager_init(void);
22
23session_t *session_create(uint32_t client_ip, uint64_t allotment_ms,
24 const char *spent_secrets[], int secret_count);
25
26session_t *session_find_by_ip(uint32_t client_ip);
27
28void session_extend(session_t *session, uint64_t additional_ms);
29
30bool session_is_expired(const session_t *session);
31
32bool session_is_secret_spent(const char *secret);
33
34void session_check_expiry(void);
35
36void session_revoke(session_t *session);
37
38void session_revoke_all(void);
39
40int session_active_count(void);
41
42void session_tick(void);
43
44#endif