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
+1 -1
View File
@@ -1,5 +1,5 @@
{ {
"rust-analyzer.cargo.features": ["desktop", "mobile"], "rust-analyzer.cargo.features": ["desktop"],
"rust-analyzer.linkedProjects": ["Cargo.toml"], "rust-analyzer.linkedProjects": ["Cargo.toml"],
"rust-analyzer.cargo.buildScripts.enable": true, "rust-analyzer.cargo.buildScripts.enable": true,
"rust-analyzer.procMacro.enable": true, "rust-analyzer.procMacro.enable": true,
+4 -4
View File
@@ -14,7 +14,7 @@ debug-client:
debug-server: debug-server:
@echo "--- Сборка сервера (Debug) ---" @echo "--- Сборка сервера (Debug) ---"
cargo build --bin netrunner-server cargo build --bin netrunner-server --features desktop
@echo "--- Запуск сервера локально ---" @echo "--- Запуск сервера локально ---"
sudo ./target/debug/netrunner-server --port=4443 --host=0.0.0.0 sudo ./target/debug/netrunner-server --port=4443 --host=0.0.0.0
@@ -24,7 +24,7 @@ ABIS = arm64-v8a armeabi-v7a x86_64 x86
build-android: build-android:
@for abi in $(ABIS); do \ @for abi in $(ABIS); do \
echo "Building for $$abi..."; \ echo "Building for $$abi..."; \
cargo ndk -t $$abi -o ./gen build --bin netrunner-client --release --features mobile; \ cargo ndk -t $$abi -o ./gen build --bin netrunner-client --features mobile --release; \
cargo run --bin bindgen-tool generate \ cargo run --bin bindgen-tool generate \
--library gen/$$abi/libnetrunner_client.so \ --library gen/$$abi/libnetrunner_client.so \
--language kotlin \ --language kotlin \
@@ -33,7 +33,7 @@ build-android:
done done
build-server: build-server:
cargo build --bin netrunner-server --release cargo build --bin netrunner-server --release --features desktop
setup-server: setup-server:
@echo "--- Обновление системы и установка зависимостей ---" @echo "--- Обновление системы и установка зависимостей ---"
@@ -44,7 +44,7 @@ setup-server:
mkdir -p $(REMOTE_PATH)" mkdir -p $(REMOTE_PATH)"
# Деплой # Деплой
deploy-server: build-server deploy-server:
@echo "--- Останавливаем старый сервер ---" @echo "--- Останавливаем старый сервер ---"
ssh $(REMOTE_USER)@$(SERVER_IP) "systemctl stop $(SERVICE_NAME)" || true ssh $(REMOTE_USER)@$(SERVER_IP) "systemctl stop $(SERVICE_NAME)" || true
-1
View File
@@ -39,7 +39,6 @@ uniffi = { version = "0.31.0", features = ["build"] }
[features] [features]
default = ["desktop"]
desktop = [] desktop = []
mobile = [] mobile = []
+6 -7
View File
@@ -13,8 +13,12 @@ use std::sync::OnceLock;
use tokio::runtime::Runtime; use tokio::runtime::Runtime;
use tokio::sync::oneshot; use tokio::sync::oneshot;
use tracing::{error, info}; 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(); static RUNTIME: OnceLock<Runtime> = OnceLock::new();
fn get_runtime() -> &'static Runtime { fn get_runtime() -> &'static Runtime {
@@ -75,12 +79,7 @@ impl SessionManager {
.expect("Failed to init TUN") .expect("Failed to init TUN")
}; };
#[cfg(feature = "desktop")] setup_platform_routing(&tun_device, &remote_address);
{
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");
}
// 2. Инициализация сети // 2. Инициализация сети
let config = Config::new(smoltcp::wire::HardwareAddress::Ip); let config = Config::new(smoltcp::wire::HardwareAddress::Ip);
+5 -3
View File
@@ -1,6 +1,9 @@
use std::net::Ipv4Addr; 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::{ use netrunner_core::{
logger_init, logger_init,
proxy::{connection::connection::ConnectionRole, network::Network}, proxy::{connection::connection::ConnectionRole, network::Network},
@@ -23,8 +26,7 @@ async fn main() {
}) })
.expect("Failed to initialize TUN device"); .expect("Failed to initialize TUN device");
let remote_address: String = "62.60.244.156:443".into(); let remote_address: String = "62.60.244.156:443".into();
tun_device.setup_routing(&remote_address); setup_platform_routing(&tun_device, &remote_address);
tun_device.setup_dns_redirection();
info!("TUN interface is UP: 10.0.0.1/24"); 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)
}
}