diff options
| author | Your Name <you@example.com> | 2026-05-19 02:31:19 +0530 |
|---|---|---|
| committer | Your Name <you@example.com> | 2026-05-19 02:32:41 +0530 |
| commit | 81f2dc52dc42d01c89dff45a5407ec40b8863052 (patch) | |
| tree | 15018c2438639ca89dc6d33a5144c10d0b1c2af0 /components/wisp_relay/flash_monitor.c | |
| parent | 75688d55b3c8d13c8c9a50da9668ec408f684cb3 (diff) | |
feat: local Nostr relay with relay selection, sync, and integration tests
Local Nostr relay (NIP-01) on port 4869 with LittleFS 4MB storage.
All events published locally first, then synced to public relays via REQ-diff.
Relay selection via NIP-11 HTTP probing with NIP-77 scoring and auto-failover.
Components:
- wisp_relay: 16-file local relay (ws_server, storage_engine, sub_manager,
broadcaster, relay_validator, router, handlers, rate_limiter, nip11,
deletion, flash_monitor, relay_types)
- esp_littlefs: LittleFS VFS integration (git submodule)
- negentropy: for future NIP-77 binary sync (git submodule)
New source files:
- local_relay.c/h: thin wrapper for relay init/start/publish
- relay_selector.c/h: NIP-11 probe + scoring + auto-failover
- sync_manager.c/h: REQ-diff sync (primary 30min, fallback 6h)
Bug fixes:
- config.c: use-after-free (cJSON_Delete before seed_relays/sync parsing)
- local_relay: moved init to app_main for boot-time start (not gated on STA IP)
Flash layout: 4MB LittleFS partition at 0x500000 for relay_store
Test results (Board B, live hardware):
- Smoke: ping + HTTP 4869 + NIP-11: PASS
- NIP-11 info document: 10/11 PASS
- WS pub/sub (connect, REQ/EOSE, EVENT/OK, CLOSE, concurrent): 6/6 PASS
- Unit tests (relay_validator + relay_selector): 13/13 PASS
Hardware test make targets in physical-router-test-automation/:
- make relay-build, relay-flash-b, relay-test-smoke/nip11/pubsub/sync/full
Diffstat (limited to 'components/wisp_relay/flash_monitor.c')
| -rw-r--r-- | components/wisp_relay/flash_monitor.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/components/wisp_relay/flash_monitor.c b/components/wisp_relay/flash_monitor.c new file mode 100644 index 0000000..ceb8c3b --- /dev/null +++ b/components/wisp_relay/flash_monitor.c | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | #include "flash_monitor.h" | ||
| 2 | #include "esp_littlefs.h" | ||
| 3 | #include "esp_log.h" | ||
| 4 | #include <string.h> | ||
| 5 | |||
| 6 | static const char *TAG = "flash_monitor"; | ||
| 7 | |||
| 8 | void flash_get_health(const char *partition_label, flash_health_t *health) | ||
| 9 | { | ||
| 10 | memset(health, 0, sizeof(flash_health_t)); | ||
| 11 | |||
| 12 | esp_err_t ret = esp_littlefs_info(partition_label, | ||
| 13 | &health->total_bytes, | ||
| 14 | &health->used_bytes); | ||
| 15 | if (ret != ESP_OK) { | ||
| 16 | ESP_LOGE(TAG, "Failed to get LittleFS info: %s", esp_err_to_name(ret)); | ||
| 17 | return; | ||
| 18 | } | ||
| 19 | |||
| 20 | if (health->total_bytes == 0) { | ||
| 21 | health->free_bytes = 0; | ||
| 22 | health->usage_percent = 0.0f; | ||
| 23 | } else { | ||
| 24 | health->free_bytes = health->total_bytes - health->used_bytes; | ||
| 25 | health->usage_percent = (float)health->used_bytes / health->total_bytes * 100.0f; | ||
| 26 | } | ||
| 27 | |||
| 28 | ESP_LOGD(TAG, "Flash: %.1f%% used (%zu/%zu bytes)", | ||
| 29 | health->usage_percent, health->used_bytes, health->total_bytes); | ||
| 30 | } | ||