diff options
| author | Your Name <you@example.com> | 2026-05-26 22:07:55 +0530 |
|---|---|---|
| committer | Your Name <you@example.com> | 2026-05-26 22:07:55 +0530 |
| commit | d60fa03de6edae0667a93ac36be4206e76255a2c (patch) | |
| tree | 566adbe43f446a1f92a425c439c8c60f52c8ae51 /src/http_health.rs | |
| parent | 7b1b36b8c7e448d1d170c8c6e1f88bb766163fbb (diff) | |
Add NIP-46 remote signing for kind:30618 state events
- nip46.rs: full NIP-46 client with session management, NIP-04 encrypted
relay-based communication, oneshot response awaiting
- db.rs: nip46_sessions table, upsert/get methods
- config.rs: Nip46Config with relays + signing_timeout_secs
- git_mirror.rs: builds unsigned kind:30618 state event from bare repo refs,
signs via NIP-46 before push, publishes to target server relay
- http_health.rs: exposes NIP-46 session status in health endpoint
- main.rs: wires NIP-46 client into daemon startup, passes to mirror_cycle
Diffstat (limited to 'src/http_health.rs')
| -rw-r--r-- | src/http_health.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/http_health.rs b/src/http_health.rs index 0cdfeb5..d3f5df2 100644 --- a/src/http_health.rs +++ b/src/http_health.rs | |||
| @@ -12,6 +12,7 @@ pub struct HealthState { | |||
| 12 | pub cycle_count: watch::Receiver<u64>, | 12 | pub cycle_count: watch::Receiver<u64>, |
| 13 | pub last_cycle_ok: watch::Receiver<bool>, | 13 | pub last_cycle_ok: watch::Receiver<bool>, |
| 14 | pub db_path: String, | 14 | pub db_path: String, |
| 15 | pub nip46_client: Option<Arc<crate::nip46::Nip46Client>>, | ||
| 15 | } | 16 | } |
| 16 | 17 | ||
| 17 | pub async fn start_health_server(port: u16, state: Arc<HealthState>) -> anyhow::Result<()> { | 18 | pub async fn start_health_server(port: u16, state: Arc<HealthState>) -> anyhow::Result<()> { |
| @@ -31,10 +32,27 @@ async fn health_handler(State(state): State<Arc<HealthState>>) -> Json<Value> { | |||
| 31 | let cycle_count = *state.cycle_count.borrow(); | 32 | let cycle_count = *state.cycle_count.borrow(); |
| 32 | let last_ok = *state.last_cycle_ok.borrow(); | 33 | let last_ok = *state.last_cycle_ok.borrow(); |
| 33 | 34 | ||
| 35 | let nip46_sessions = if let Some(ref client) = state.nip46_client { | ||
| 36 | let statuses = client.get_status().await; | ||
| 37 | statuses | ||
| 38 | .into_iter() | ||
| 39 | .map(|s| { | ||
| 40 | json!({ | ||
| 41 | "npub": s.npub, | ||
| 42 | "connected": s.connected, | ||
| 43 | "pairing_uri": s.pairing_uri, | ||
| 44 | }) | ||
| 45 | }) | ||
| 46 | .collect::<Vec<_>>() | ||
| 47 | } else { | ||
| 48 | vec![] | ||
| 49 | }; | ||
| 50 | |||
| 34 | Json(json!({ | 51 | Json(json!({ |
| 35 | "status": if last_ok || cycle_count == 0 { "ok" } else { "degraded" }, | 52 | "status": if last_ok || cycle_count == 0 { "ok" } else { "degraded" }, |
| 36 | "uptime_secs": uptime.as_secs(), | 53 | "uptime_secs": uptime.as_secs(), |
| 37 | "cycle_count": cycle_count, | 54 | "cycle_count": cycle_count, |
| 38 | "last_cycle_ok": last_ok, | 55 | "last_cycle_ok": last_ok, |
| 56 | "nip46": nip46_sessions, | ||
| 39 | })) | 57 | })) |
| 40 | } | 58 | } |