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 /main/relay_selector.h | |
| 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 'main/relay_selector.h')
| -rw-r--r-- | main/relay_selector.h | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/main/relay_selector.h b/main/relay_selector.h new file mode 100644 index 0000000..4403944 --- /dev/null +++ b/main/relay_selector.h | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | #ifndef RELAY_SELECTOR_H | ||
| 2 | #define RELAY_SELECTOR_H | ||
| 3 | |||
| 4 | #include "esp_err.h" | ||
| 5 | #include "freertos/FreeRTOS.h" | ||
| 6 | #include "freertos/semphr.h" | ||
| 7 | #include <stdbool.h> | ||
| 8 | #include <stdint.h> | ||
| 9 | |||
| 10 | #define RELAY_SELECTOR_MAX_RELAYS 8 | ||
| 11 | #define RELAY_SELECTOR_URL_LEN 128 | ||
| 12 | |||
| 13 | typedef struct { | ||
| 14 | char url[RELAY_SELECTOR_URL_LEN]; | ||
| 15 | char name[64]; | ||
| 16 | uint32_t latency_ms; | ||
| 17 | bool supports_nip77; | ||
| 18 | bool alive; | ||
| 19 | int consecutive_failures; | ||
| 20 | uint32_t last_probe_time; | ||
| 21 | uint8_t supported_nips[32]; | ||
| 22 | size_t nips_count; | ||
| 23 | } relay_info_t; | ||
| 24 | |||
| 25 | typedef struct { | ||
| 26 | relay_info_t relays[RELAY_SELECTOR_MAX_RELAYS]; | ||
| 27 | size_t count; | ||
| 28 | int primary_idx; | ||
| 29 | int fallback_idx; | ||
| 30 | uint32_t last_full_probe; | ||
| 31 | SemaphoreHandle_t lock; | ||
| 32 | } relay_selector_t; | ||
| 33 | |||
| 34 | esp_err_t relay_selector_init(relay_selector_t *sel); | ||
| 35 | void relay_selector_destroy(relay_selector_t *sel); | ||
| 36 | |||
| 37 | esp_err_t relay_selector_probe_all(relay_selector_t *sel); | ||
| 38 | |||
| 39 | const relay_info_t *relay_selector_get_primary(relay_selector_t *sel); | ||
| 40 | const relay_info_t *relay_selector_get_fallback(relay_selector_t *sel, int idx); | ||
| 41 | |||
| 42 | void relay_selector_report_disconnect(relay_selector_t *sel, const char *url); | ||
| 43 | |||
| 44 | esp_err_t relay_selector_seed_from_config(relay_selector_t *sel); | ||
| 45 | |||
| 46 | #endif | ||