tun init logic seperation by platforms

This commit is contained in:
2026-03-13 14:36:55 +07:00
parent d4ffb90152
commit 66036c1451
8 changed files with 47 additions and 16 deletions
+6 -7
View File
@@ -13,8 +13,12 @@ use std::sync::OnceLock;
use tokio::runtime::Runtime;
use tokio::sync::oneshot;
use tracing::{error, info};
pub mod platform;
use crate::tun::{engine::Engine, tun::Tun};
use crate::{
platform::setup_platform_routing,
tun::{engine::Engine, tun::Tun},
};
static RUNTIME: OnceLock<Runtime> = OnceLock::new();
fn get_runtime() -> &'static Runtime {
@@ -75,12 +79,7 @@ impl SessionManager {
.expect("Failed to init TUN")
};
#[cfg(feature = "desktop")]
{
let proxy_ip = remote_address.split(':').next().unwrap_or(&remote_address);
tun_device.setup_routing(proxy_ip).expect("Routing failed");
tun_device.setup_dns_redirection().expect("DNS failed");
}
setup_platform_routing(&tun_device, &remote_address);
// 2. Инициализация сети
let config = Config::new(smoltcp::wire::HardwareAddress::Ip);
+5 -3
View File
@@ -1,6 +1,9 @@
use std::net::Ipv4Addr;
use netrunner_client::{tun::engine::Engine, tun::tun::Tun};
use netrunner_client::{
platform::setup_platform_routing,
tun::{engine::Engine, tun::Tun},
};
use netrunner_core::{
logger_init,
proxy::{connection::connection::ConnectionRole, network::Network},
@@ -23,8 +26,7 @@ async fn main() {
})
.expect("Failed to initialize TUN device");
let remote_address: String = "62.60.244.156:443".into();
tun_device.setup_routing(&remote_address);
tun_device.setup_dns_redirection();
setup_platform_routing(&tun_device, &remote_address);
info!("TUN interface is UP: 10.0.0.1/24");
+9
View File
@@ -0,0 +1,9 @@
use crate::tun::tun::Tun; // Убедись, что путь к Tun верный
use std::io;
pub fn setup_platform_routing(tun_device: &Tun, remote_address: &str) -> io::Result<()> {
let proxy_ip = remote_address.split(':').next().unwrap_or(remote_address);
tun_device.setup_routing(proxy_ip)?;
tun_device.setup_dns_redirection()?;
Ok(())
}
+7
View File
@@ -0,0 +1,7 @@
use crate::tun::tun::Tun;
use std::io;
pub fn setup_platform_routing(_tun_device: &Tun, _remote_address: &str) -> io::Result<()> {
eprintln!("Android routing on Kotlin side");
Ok(())
}
+15
View File
@@ -0,0 +1,15 @@
#[cfg(feature = "desktop")]
pub mod desktop;
#[cfg(feature = "mobile")]
pub mod mobile;
pub fn setup_platform_routing(tun: &crate::tun::tun::Tun, addr: &str) -> std::io::Result<()> {
#[cfg(feature = "desktop")]
{
desktop::setup_platform_routing(tun, addr)
}
#[cfg(not(feature = "desktop"))]
{
mobile::setup_platform_routing(tun, addr)
}
}