fix: fast VPN status — read config file instead of slow nvpn CLI
All checks were successful
Build Archipelago ISO (dev) / build-iso (push) Successful in 49m48s

nvpn status command hangs for seconds (connects to relays), causing
the Network page to never finish loading. Read tunnel_ip from the
local config file instead (instant).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Dorian
2026-04-08 00:36:49 +02:00
parent 37b6b376b2
commit fac5f117a9

View File

@@ -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<VpnStatus> {
// 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::<serde_json::Value>(&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,
})