tun init logic seperation by platforms
This commit is contained in:
+6
-7
@@ -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
@@ -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");
|
||||
|
||||
|
||||
@@ -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(())
|
||||
}
|
||||
@@ -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(())
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user