diff --git a/core/archipelago/src/vpn.rs b/core/archipelago/src/vpn.rs index f5fdc5eb..89be9a7f 100644 --- a/core/archipelago/src/vpn.rs +++ b/core/archipelago/src/vpn.rs @@ -202,47 +202,34 @@ pub async fn get_status() -> VpnStatus { /// Check if NostrVPN system service is running and get its status. async fn get_nostr_vpn_status() -> Result { - // Check if nostr-vpn service is active or activating - let output = tokio::process::Command::new("systemctl") + // Fast check: is the service unit enabled/active? + let svc_state = tokio::process::Command::new("systemctl") .args(["is-active", "nostr-vpn"]) .output() .await .map(|o| String::from_utf8_lossy(&o.stdout).trim().to_string()) .unwrap_or_default(); - let active = output == "active" || output == "activating"; - if !active { - anyhow::bail!("nostr-vpn service not active"); + if svc_state != "active" && svc_state != "activating" { + anyhow::bail!("nostr-vpn service not running"); } - // Try to get status from nvpn CLI - let output = tokio::process::Command::new("nvpn") - .arg("status") - .output() - .await; - - let (peers, ip) = match output { - Ok(o) if o.status.success() => { - let stdout = String::from_utf8_lossy(&o.stdout); - let peers = stdout.lines() - .filter(|l| l.contains("peer") || l.contains("connected")) - .count() as u32; - let ip = stdout.lines() - .find(|l| l.contains("address") || l.contains("ip")) - .and_then(|l| l.split_whitespace().last()) - .map(|s| s.to_string()); - (peers, ip) - } - _ => (0, None), - }; + // Quick IP check: read from config file (fast, no subprocess) + let ip = tokio::fs::read_to_string("/var/lib/archipelago/nostr-vpn/.config/nvpn/config.json") + .await + .ok() + .and_then(|s| { + serde_json::from_str::(&s).ok() + }) + .and_then(|v| v.get("tunnel_ip").and_then(|t| t.as_str()).map(|s| s.to_string())); Ok(VpnStatus { - connected: true, + connected: svc_state == "active", provider: Some("nostr-vpn".to_string()), interface: Some("nvpn0".to_string()), ip_address: ip, hostname: None, - peers_connected: peers, + peers_connected: 0, bytes_in: 0, bytes_out: 0, })