Fix frontend ignoring tunnel errors & fix blocking wintun routines

This commit is contained in:
ospab 2026-05-28 16:32:59 +03:00
parent 6547b99798
commit 1e7f562f81
4 changed files with 44 additions and 27 deletions

View File

@ -70,18 +70,22 @@ pub async fn run_native_tunnel(
New-NetRoute -DestinationPrefix '0.0.0.0/0' -InterfaceAlias 'ostp_tun' -NextHop '10.1.0.1' -RouteMetric 1 -ErrorAction SilentlyContinue\n", New-NetRoute -DestinationPrefix '0.0.0.0/0' -InterfaceAlias 'ostp_tun' -NextHop '10.1.0.1' -RouteMetric 1 -ErrorAction SilentlyContinue\n",
server_ip_str, current_exe server_ip_str, current_exe
); );
let _ = Command::new("powershell") let _ = tokio::task::spawn_blocking(move || {
Command::new("powershell")
.creation_flags(CREATE_NO_WINDOW) .creation_flags(CREATE_NO_WINDOW)
.args(["-NoProfile", "-Command", &setup_script]) .args(["-NoProfile", "-Command", &setup_script])
.output()?; .output()
}).await.unwrap()?;
if let Some(ref dns) = config.dns_server { if let Some(ref dns) = config.dns_server {
if !dns.is_empty() { if !dns.is_empty() {
let net_setup = format!("netsh interface ipv4 set dnsservers name=\"ostp_tun\" static {} primary\n", dns); let net_setup = format!("netsh interface ipv4 set dnsservers name=\"ostp_tun\" static {} primary\n", dns);
let _ = Command::new("powershell") let _ = tokio::task::spawn_blocking(move || {
Command::new("powershell")
.creation_flags(CREATE_NO_WINDOW) .creation_flags(CREATE_NO_WINDOW)
.args(["-NoProfile", "-Command", &net_setup]) .args(["-NoProfile", "-Command", &net_setup])
.output()?; .output()
}).await.unwrap()?;
} }
} }
} }

View File

@ -60,14 +60,16 @@ pub async fn run_wintun_tunnel(
// 1. Delete stale TUN adapter if it exists from a previous run. // 1. Delete stale TUN adapter if it exists from a previous run.
// This prevents wintun from creating "ostp_tun 2", "ostp_tun 3", etc. // This prevents wintun from creating "ostp_tun 2", "ostp_tun 3", etc.
tracing::info!("Cleaning up stale TUN adapter..."); tracing::info!("Cleaning up stale TUN adapter...");
let _ = Command::new("powershell") let _ = tokio::task::spawn_blocking(move || {
Command::new("powershell")
.creation_flags(CREATE_NO_WINDOW) .creation_flags(CREATE_NO_WINDOW)
.args(["-NoProfile", "-Command", &format!( .args(["-NoProfile", "-Command", &format!(
"Get-NetAdapter -Name '{TUN_NAME}*' -ErrorAction SilentlyContinue | \ "Get-NetAdapter -Name '{TUN_NAME}*' -ErrorAction SilentlyContinue | \
Disable-NetAdapter -Confirm:$false -ErrorAction SilentlyContinue; \ Disable-NetAdapter -Confirm:$false -ErrorAction SilentlyContinue; \
netsh interface set interface \"{TUN_NAME}\" admin=disable 2>$null" netsh interface set interface \"{TUN_NAME}\" admin=disable 2>$null"
)]) )])
.output(); .output()
}).await;
// Brief pause to let the driver release the adapter // Brief pause to let the driver release the adapter
tokio::time::sleep(std::time::Duration::from_millis(200)).await; tokio::time::sleep(std::time::Duration::from_millis(200)).await;
@ -138,11 +140,13 @@ pub async fn run_wintun_tunnel(
let mut adapter_ready = false; let mut adapter_ready = false;
while tokio::time::Instant::now() < adapter_deadline { while tokio::time::Instant::now() < adapter_deadline {
tokio::time::sleep(std::time::Duration::from_millis(250)).await; tokio::time::sleep(std::time::Duration::from_millis(250)).await;
let check = Command::new("powershell") let check = tokio::task::spawn_blocking(move || {
Command::new("powershell")
.creation_flags(CREATE_NO_WINDOW) .creation_flags(CREATE_NO_WINDOW)
.args(["-NoProfile", "-Command", .args(["-NoProfile", "-Command",
&format!("(Get-NetAdapter -Name '{TUN_NAME}' -ErrorAction SilentlyContinue).Status")]) &format!("(Get-NetAdapter -Name '{TUN_NAME}' -ErrorAction SilentlyContinue).Status")])
.output(); .output()
}).await.unwrap();
if let Ok(out) = check { if let Ok(out) = check {
let status = String::from_utf8_lossy(&out.stdout).trim().to_string(); let status = String::from_utf8_lossy(&out.stdout).trim().to_string();
if debug { if debug {
@ -181,10 +185,12 @@ pub async fn run_wintun_tunnel(
} }
} }
let _ = Command::new("powershell") let _ = tokio::task::spawn_blocking(move || {
Command::new("powershell")
.creation_flags(CREATE_NO_WINDOW) .creation_flags(CREATE_NO_WINDOW)
.args(["-NoProfile", "-Command", &net_setup]) .args(["-NoProfile", "-Command", &net_setup])
.output()?; .output()
}).await.unwrap()?;
tracing::info!("TUN tunnel active. All traffic is routed through OSTP."); tracing::info!("TUN tunnel active. All traffic is routed through OSTP.");

View File

@ -2632,7 +2632,7 @@ dependencies = [
[[package]] [[package]]
name = "ostp-client" name = "ostp-client"
version = "0.2.58" version = "0.2.60"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"base64 0.22.1", "base64 0.22.1",
@ -2662,7 +2662,7 @@ dependencies = [
[[package]] [[package]]
name = "ostp-core" name = "ostp-core"
version = "0.2.58" version = "0.2.60"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bytes", "bytes",

View File

@ -367,6 +367,13 @@ window.addEventListener('DOMContentLoaded', async () => {
setState('disconnected'); setState('disconnected');
// Event wiring // Event wiring
if (window.__TAURI__ && window.__TAURI__.event) {
window.__TAURI__.event.listen('tunnel-error', (evt) => {
setState('disconnected');
showToast(String(evt.payload), 'error');
});
}
btnConnect.addEventListener('click', handleToggle); btnConnect.addEventListener('click', handleToggle);
btnGoSettings.addEventListener('click', () => showScreen('settings')); btnGoSettings.addEventListener('click', () => showScreen('settings'));
btnBack.addEventListener('click', () => showScreen('home')); btnBack.addEventListener('click', () => showScreen('home'));