From e366ceb336550a72c76efea4c98a2a08cca27bce Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 19 May 2026 14:25:18 +0530 Subject: feat(mining): Bitcoin mining-for-bandwidth payment system New modules: - mining_payment.c/h: hashprice calc (nbits->difficulty->sat/GH/s/day), share validation, client stats, allotment conversion (ms + bytes) - stratum_client.c/h: SV1 upstream pool connection (subscribe/authorize/submit) - stratum_proxy.c/h: Local SV1 TCP server for downstream miners, job broadcast - sw_miner.c/h: Software SHA256d miner (ESP32 CPU fallback) - asic_miner.c/h: ASIC detection stub (BM1366/BM1368 SPI) Config: - config.h/c: mining_payout_mode_t enum (auto/pool/upstream/proxy_only), stratum pool settings, mining port, hashprice override, sandbox mint access - Defaults fill nostr_seed_relays (8/8) and nostr_relays (4/4) with fast relays Integration into existing modules: - session.h/c: payment_method_t enum (CASHU/MINING/BYTES) - firewall.h/c: firewall_set_mining_port(), firewall_set_sandbox_mint_access() - tollgate_api.c: GET /mining/job, POST /mining/share, GET /mining/stats - tollgate_client.h/c: TG_CLIENT_MINING state, mining discovery tag parsing - tollgate_main.c: mining init in start_services(), stratum_client_tick() in loop - captive_portal.c: tabbed Cashu/Mine UI with live hashrate polling Unit tests (69 new assertions across 4 suites): - test_mining_payment (23 tests): nbits->difficulty, hashprice, client stats, allotment - test_stratum_proxy (21 tests): job set/get, stats, type validation - test_session_payment_method (12 tests): PAYMENT_METHOD enum, bytes/cashu methods - test_tollgate_client_mining (20 tests): mining tag parsing, discovery struct - test_firewall_sandbox (16 tests): client grant/revoke, max clients, setters Enhanced test stubs: - BaseType_t/pdPASS in freertos/task.h - lwip: sockets.h, etharp.h, prot/ip.h, prot/ip4.h, prot/tcp.h, netif.h - dns_server.h, esp_wifi_ap_get_sta_list.h Build fixes: - cvm_server.c: replace esp_timer_get_time() with xTaskGetTickCount(), fix process_relay_message() 3-arg call to 2-arg, add WS keepalive ping - stratum_proxy.c: widen task_name buffer 16->20 - sw_miner.c: add missing #include esp_random.h - nucula_src: save_proofs() moved to public in wallet.hpp Nostr relay updates: - nostr_seed_relays: +relay.anzenkodo.workers.dev, +nostr.koning-degraaf.nl, +knostr.neutrine.com, +nostr.einundzwanzig.space (8/8 slots) - nostr_relays: +relay.anzenkodo.workers.dev, +nostr.koning-degraaf.nl (4/4 slots) Squash-merge of feature/mining-payment (5 commits: c75230e..9d98ba1) --- tests/unit/stubs/lwip/etharp.h | 22 ++++++++++++++++++++++ tests/unit/stubs/lwip/ip4_addr.h | 3 +++ tests/unit/stubs/lwip/lwip_napt.h | 6 ++++++ tests/unit/stubs/lwip/napt.h | 6 ------ tests/unit/stubs/lwip/netif.h | 16 ++++++++++++++++ tests/unit/stubs/lwip/prot/ip.h | 20 ++++++++++++++++++++ tests/unit/stubs/lwip/prot/ip4.h | 6 ++++++ tests/unit/stubs/lwip/prot/tcp.h | 13 +++++++++++++ tests/unit/stubs/lwip/sockets.h | 6 ++++++ 9 files changed, 92 insertions(+), 6 deletions(-) create mode 100644 tests/unit/stubs/lwip/etharp.h create mode 100644 tests/unit/stubs/lwip/lwip_napt.h delete mode 100644 tests/unit/stubs/lwip/napt.h create mode 100644 tests/unit/stubs/lwip/prot/ip.h create mode 100644 tests/unit/stubs/lwip/prot/ip4.h create mode 100644 tests/unit/stubs/lwip/prot/tcp.h (limited to 'tests/unit/stubs/lwip') diff --git a/tests/unit/stubs/lwip/etharp.h b/tests/unit/stubs/lwip/etharp.h new file mode 100644 index 0000000..adc6b7b --- /dev/null +++ b/tests/unit/stubs/lwip/etharp.h @@ -0,0 +1,22 @@ +#ifndef STUBS_LWIP_ETHARP_H +#define STUBS_LWIP_ETHARP_H + +#include +#include +#include "lwip/ip4_addr.h" + +struct eth_addr { + uint8_t addr[6]; +}; + +struct netif; + +typedef int err_t; +#define ERR_OK 0 + +static inline err_t etharp_get_entry(ssize_t i, ip4_addr_t **ip, struct netif **netif, struct eth_addr **eth) { + (void)i; (void)ip; (void)netif; (void)eth; + return -1; +} + +#endif diff --git a/tests/unit/stubs/lwip/ip4_addr.h b/tests/unit/stubs/lwip/ip4_addr.h index 174211b..9d92ff0 100644 --- a/tests/unit/stubs/lwip/ip4_addr.h +++ b/tests/unit/stubs/lwip/ip4_addr.h @@ -3,6 +3,9 @@ #include +typedef uint32_t u32_t; +typedef uint16_t u16_t; + typedef struct { uint32_t addr; } ip4_addr_t; diff --git a/tests/unit/stubs/lwip/lwip_napt.h b/tests/unit/stubs/lwip/lwip_napt.h new file mode 100644 index 0000000..c6a5ca1 --- /dev/null +++ b/tests/unit/stubs/lwip/lwip_napt.h @@ -0,0 +1,6 @@ +#ifndef STUBS_LWIP_NAPT_H +#define STUBS_LWIP_NAPT_H + +static inline void ip_napt_enable(uint32_t num, int enable) { (void)num; (void)enable; } + +#endif diff --git a/tests/unit/stubs/lwip/napt.h b/tests/unit/stubs/lwip/napt.h deleted file mode 100644 index c6a5ca1..0000000 --- a/tests/unit/stubs/lwip/napt.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef STUBS_LWIP_NAPT_H -#define STUBS_LWIP_NAPT_H - -static inline void ip_napt_enable(uint32_t num, int enable) { (void)num; (void)enable; } - -#endif diff --git a/tests/unit/stubs/lwip/netif.h b/tests/unit/stubs/lwip/netif.h index 461a64e..9415539 100644 --- a/tests/unit/stubs/lwip/netif.h +++ b/tests/unit/stubs/lwip/netif.h @@ -1,4 +1,20 @@ #ifndef STUBS_LWIP_NETIF_H #define STUBS_LWIP_NETIF_H +#include +#include + +struct pbuf { + void *payload; + uint16_t len; +}; + +static inline uint32_t lwip_ntohl(uint32_t n) { + return ((n & 0xFF) << 24) | ((n & 0xFF00) << 8) | ((n >> 8) & 0xFF00) | ((n >> 24) & 0xFF); +} + +static inline uint16_t lwip_ntohs(uint16_t n) { + return ((n & 0xFF) << 8) | ((n >> 8) & 0xFF); +} + #endif diff --git a/tests/unit/stubs/lwip/prot/ip.h b/tests/unit/stubs/lwip/prot/ip.h new file mode 100644 index 0000000..0770760 --- /dev/null +++ b/tests/unit/stubs/lwip/prot/ip.h @@ -0,0 +1,20 @@ +#ifndef STUBS_LWIP_PROT_IP_H +#define STUBS_LWIP_PROT_IP_H + +#include + +#define IP_PROTO_TCP 6 +#define IP_PROTO_UDP 17 +#define IP_HLEN 20 + +struct ip_hdr { + uint8_t _proto; + union { + uint32_t addr; + } src; + union { + uint32_t addr; + } dest; +}; + +#endif diff --git a/tests/unit/stubs/lwip/prot/ip4.h b/tests/unit/stubs/lwip/prot/ip4.h new file mode 100644 index 0000000..0f70170 --- /dev/null +++ b/tests/unit/stubs/lwip/prot/ip4.h @@ -0,0 +1,6 @@ +#ifndef STUBS_LWIP_PROT_IP4_H +#define STUBS_LWIP_PROT_IP4_H + +#include "ip.h" + +#endif diff --git a/tests/unit/stubs/lwip/prot/tcp.h b/tests/unit/stubs/lwip/prot/tcp.h new file mode 100644 index 0000000..5841371 --- /dev/null +++ b/tests/unit/stubs/lwip/prot/tcp.h @@ -0,0 +1,13 @@ +#ifndef STUBS_LWIP_PROT_TCP_H +#define STUBS_LWIP_PROT_TCP_H + +#include + +#define TCP_HLEN 20 + +struct tcp_hdr { + uint16_t src; + uint16_t dest; +}; + +#endif diff --git a/tests/unit/stubs/lwip/sockets.h b/tests/unit/stubs/lwip/sockets.h index 44f03ac..91bf8b2 100644 --- a/tests/unit/stubs/lwip/sockets.h +++ b/tests/unit/stubs/lwip/sockets.h @@ -1,4 +1,10 @@ #ifndef STUBS_LWIP_SOCKETS_H #define STUBS_LWIP_SOCKETS_H +#include +#include +#include +#include +#include + #endif -- cgit v1.2.3