perf: accelerate protocol via low-latency ACK windows and suppress high-velocity console spam logs

This commit is contained in:
ospab 2026-05-15 17:44:06 +03:00
parent f6f497a418
commit 6e35609f42
6 changed files with 54 additions and 29 deletions

8
Cargo.lock generated
View File

@ -476,7 +476,7 @@ checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381"
[[package]] [[package]]
name = "ostp" name = "ostp"
version = "0.1.31" version = "0.1.34"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"base64", "base64",
@ -491,7 +491,7 @@ dependencies = [
[[package]] [[package]]
name = "ostp-client" name = "ostp-client"
version = "0.1.31" version = "0.1.34"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bytes", "bytes",
@ -506,7 +506,7 @@ dependencies = [
[[package]] [[package]]
name = "ostp-core" name = "ostp-core"
version = "0.1.31" version = "0.1.34"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-trait", "async-trait",
@ -538,7 +538,7 @@ dependencies = [
[[package]] [[package]]
name = "ostp-server" name = "ostp-server"
version = "0.1.31" version = "0.1.34"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bytes", "bytes",

View File

@ -28,6 +28,7 @@ struct SessionState {
pub struct Bridge { pub struct Bridge {
running: bool, running: bool,
pub debug: bool,
profile: TrafficProfile, profile: TrafficProfile,
server_addr: String, server_addr: String,
local_bind_addr: String, local_bind_addr: String,
@ -56,6 +57,7 @@ impl Bridge {
pub fn new(config: &ClientConfig, metrics: Arc<BridgeMetrics>) -> Result<Self> { pub fn new(config: &ClientConfig, metrics: Arc<BridgeMetrics>) -> Result<Self> {
Ok(Self { Ok(Self {
running: false, running: false,
debug: config.debug,
profile: TrafficProfile::JsonRpc, profile: TrafficProfile::JsonRpc,
server_addr: config.ostp.server_addr.clone(), server_addr: config.ostp.server_addr.clone(),
local_bind_addr: config.ostp.local_bind_addr.clone(), local_bind_addr: config.ostp.local_bind_addr.clone(),
@ -305,12 +307,14 @@ impl Bridge {
Ok(ProtocolAction::SendDatagram(frame)) => { Ok(ProtocolAction::SendDatagram(frame)) => {
if session.socket.send(&frame).await.is_ok() { if session.socket.send(&frame).await.is_ok() {
self.metrics.bytes_sent.fetch_add(frame.len() as u64, Ordering::Relaxed); self.metrics.bytes_sent.fetch_add(frame.len() as u64, Ordering::Relaxed);
if self.debug {
let _ = tx.send(UiEvent::Log(format!( let _ = tx.send(UiEvent::Log(format!(
"Outbound datagram sent stream_id={stream_id} bytes={}", "Outbound datagram sent stream_id={stream_id} bytes={}",
frame.len() frame.len()
))).await; ))).await;
} }
} }
}
Ok(ProtocolAction::Multiple(list)) => { Ok(ProtocolAction::Multiple(list)) => {
let mut sent = 0usize; let mut sent = 0usize;
for item in list { for item in list {
@ -321,20 +325,26 @@ impl Bridge {
} }
} }
} }
if self.debug {
let _ = tx.send(UiEvent::Log(format!( let _ = tx.send(UiEvent::Log(format!(
"Outbound datagram batch stream_id={stream_id} sent={sent}" "Outbound datagram batch stream_id={stream_id} sent={sent}"
))).await; ))).await;
} }
}
Ok(ProtocolAction::Noop) => { Ok(ProtocolAction::Noop) => {
if self.debug {
let _ = tx.send(UiEvent::Log(format!( let _ = tx.send(UiEvent::Log(format!(
"Outbound datagram noop stream_id={stream_id}" "Outbound datagram noop stream_id={stream_id}"
))).await; ))).await;
} }
}
Ok(_) => { Ok(_) => {
if self.debug {
let _ = tx.send(UiEvent::Log(format!( let _ = tx.send(UiEvent::Log(format!(
"Outbound datagram unexpected action stream_id={stream_id}" "Outbound datagram unexpected action stream_id={stream_id}"
))).await; ))).await;
} }
}
Err(e) => { Err(e) => {
let _ = tx.send(UiEvent::Log(format!("Protocol error packing TCP: {e}"))).await; let _ = tx.send(UiEvent::Log(format!("Protocol error packing TCP: {e}"))).await;
} }
@ -491,8 +501,8 @@ impl Bridge {
obfuscation_key: obf_key, obfuscation_key: obf_key,
max_reorder: 262144, max_reorder: 262144,
max_reorder_buffer: 8192, max_reorder_buffer: 8192,
ack_delay_ms: 20, ack_delay_ms: 5, // Reduced from 20ms to 5ms for rapid ACK unblocking and throughput acceleration
rto_ms: 200, rto_ms: 100, // Reduced from 200ms to 100ms for faster recovery on packet loss
max_retries: 8, max_retries: 8,
max_sent_history: 16384, max_sent_history: 16384,
})?; })?;

View File

@ -106,7 +106,9 @@ pub async fn run_linux_tunnel(
} }
// 5. Prepare and launch tun2socks // 5. Prepare and launch tun2socks
let proxy_url = format!("socks5://{}", config.local_proxy.bind_addr); // Using HTTP Proxy natively avoids any UDP Associate requests,
// providing clean TCP proxying with maximum reliability.
let proxy_url = format!("http://{}", config.local_proxy.bind_addr);
if debug { if debug {
println!("[ostp-client] Spawning {} -device ostp_tun -proxy {}", tun2socks_exe.display(), proxy_url); println!("[ostp-client] Spawning {} -device ostp_tun -proxy {}", tun2socks_exe.display(), proxy_url);

View File

@ -64,10 +64,11 @@ pub async fn run_local_socks5_proxy(
matcher_clone, matcher_clone,
).await { ).await {
let msg = err.to_string(); let msg = err.to_string();
// Suppress routine disconnects from spam logs // Suppress routine disconnects and unsupported SOCKS5 command attempts (like UDP) from spam logs
if !msg.contains("UnexpectedEof") if !msg.contains("UnexpectedEof")
&& !msg.contains("Connection reset") && !msg.contains("Connection reset")
&& !msg.contains("Broken pipe") && !msg.contains("Broken pipe")
&& !msg.contains("unsupported SOCKS5 command")
{ {
if debug { if debug {
eprintln!("[ostp-client] proxy client error: {err}"); eprintln!("[ostp-client] proxy client error: {err}");

View File

@ -49,8 +49,17 @@ pub async fn run_wintun_tunnel(
$route = Get-NetRoute -DestinationPrefix '0.0.0.0/0' | Where-Object {{ $_.InterfaceAlias -notmatch 'tun' -and $_.InterfaceAlias -notmatch 'wintun' }} | Sort-Object RouteMetric | Select-Object -First 1\n\ $route = Get-NetRoute -DestinationPrefix '0.0.0.0/0' | Where-Object {{ $_.InterfaceAlias -notmatch 'tun' -and $_.InterfaceAlias -notmatch 'wintun' }} | Sort-Object RouteMetric | Select-Object -First 1\n\
$gw = $route.NextHop\n\ $gw = $route.NextHop\n\
$ifIndex = $route.InterfaceIndex\n\ $ifIndex = $route.InterfaceIndex\n\
# 1. Bypass route for the proxy server itself\n\
New-NetRoute -DestinationPrefix \"$remote_ip/32\" -NextHop $gw -InterfaceIndex $ifIndex -RouteMetric 1 -ErrorAction SilentlyContinue\n\ New-NetRoute -DestinationPrefix \"$remote_ip/32\" -NextHop $gw -InterfaceIndex $ifIndex -RouteMetric 1 -ErrorAction SilentlyContinue\n\
# 2. Bypass routes for all current Physical DNS servers to avoid UDP associate deadlocks\n\
$dns_ips = Get-DnsClientServerAddress -InterfaceIndex $ifIndex | Select-Object -ExpandProperty ServerAddresses\n\
foreach ($dns in $dns_ips) {{\n\
if ($dns -match '^\\d+\\.\\d+\\.\\d+\\.\\d+$') {{\n\
New-NetRoute -DestinationPrefix \"$dns/32\" -NextHop $gw -InterfaceIndex $ifIndex -RouteMetric 1 -ErrorAction SilentlyContinue\n\
}}\n\
}}\n\
New-NetRoute -DestinationPrefix \"1.1.1.1/32\" -NextHop $gw -InterfaceIndex $ifIndex -RouteMetric 1 -ErrorAction SilentlyContinue\n\ New-NetRoute -DestinationPrefix \"1.1.1.1/32\" -NextHop $gw -InterfaceIndex $ifIndex -RouteMetric 1 -ErrorAction SilentlyContinue\n\
# 3. Windows Firewall Rules\n\
New-NetFirewallRule -DisplayName 'OSTP Tunnel In' -Direction Inbound -Program $exe_path -Action Allow -Enabled True -ErrorAction SilentlyContinue\n\ New-NetFirewallRule -DisplayName 'OSTP Tunnel In' -Direction Inbound -Program $exe_path -Action Allow -Enabled True -ErrorAction SilentlyContinue\n\
New-NetFirewallRule -DisplayName 'OSTP Tunnel Out' -Direction Outbound -Program $exe_path -Action Allow -Enabled True -ErrorAction SilentlyContinue\n", New-NetFirewallRule -DisplayName 'OSTP Tunnel Out' -Direction Outbound -Program $exe_path -Action Allow -Enabled True -ErrorAction SilentlyContinue\n",
server_ip_str, current_exe server_ip_str, current_exe
@ -65,7 +74,9 @@ pub async fn run_wintun_tunnel(
} }
// 4. Prepare and launch tun2socks.exe in the background // 4. Prepare and launch tun2socks.exe in the background
let proxy_url = format!("socks5://{}", config.local_proxy.bind_addr); // Switch from SOCKS5 to HTTP protocol. This natively forces tun2socks NOT to attempt UDP Associate,
// preventing SOCKS5 command 3 unsupported errors while still tunneling 100% of global TCP traffic!
let proxy_url = format!("http://{}", config.local_proxy.bind_addr);
if debug { if debug {
println!("[ostp-client] Spawning tun2socks daemon pointing to {}", proxy_url); println!("[ostp-client] Spawning tun2socks daemon pointing to {}", proxy_url);
@ -78,22 +89,23 @@ pub async fn run_wintun_tunnel(
"-loglevel", if debug { "debug" } else { "error" } "-loglevel", if debug { "debug" } else { "error" }
]) ])
.current_dir(dir) .current_dir(dir)
.stdout(Stdio::piped()) .stdout(if debug { Stdio::piped() } else { Stdio::null() })
.stderr(Stdio::piped()) .stderr(if debug { Stdio::piped() } else { Stdio::null() })
.spawn() .spawn()
.map_err(|e| anyhow!("Failed to launch tun2socks.exe background process: {}", e))?; .map_err(|e| anyhow!("Failed to launch tun2socks.exe background process: {}", e))?;
// 5. Once tun2socks creates the interface, apply network settings (IP, metric, DNS) // 5. Once tun2socks creates the interface, apply network settings (IP, metric)
tokio::time::sleep(tokio::time::Duration::from_secs(2)).await; tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
if debug { if debug {
println!("[ostp-client] Applying network configurations onto 'ostp_tun' interface..."); println!("[ostp-client] Applying network configurations onto 'ostp_tun' interface...");
} }
// We omit setting dnsservers on the TUN interface entirely. This allows Windows to natively fallback
// to the physical interface DNS servers, which are physically routed and work flawlessly.
let net_setup = "\ let net_setup = "\
netsh interface ipv4 set address name=\"ostp_tun\" static 10.1.0.2 255.255.255.0 10.1.0.1\n\ netsh interface ipv4 set address name=\"ostp_tun\" static 10.1.0.2 255.255.255.0 10.1.0.1\n\
netsh interface ipv4 set interface name=\"ostp_tun\" metric=5\n\ netsh interface ipv4 set interface name=\"ostp_tun\" metric=5\n";
netsh interface ipv4 set dnsservers name=\"ostp_tun\" static 1.1.1.1 primary\n";
let _ = Command::new("powershell") let _ = Command::new("powershell")
.args(["-Command", net_setup]) .args(["-Command", net_setup])

View File

@ -127,8 +127,8 @@ pub async fn run_server(
obfuscation_key: [0u8; 8], obfuscation_key: [0u8; 8],
max_reorder: 262144, max_reorder: 262144,
max_reorder_buffer: 8192, max_reorder_buffer: 8192,
ack_delay_ms: 20, ack_delay_ms: 5, // Reduced to 5ms for drastically faster ACK loopback throughput
rto_ms: 200, rto_ms: 100, // Reduced to 100ms for aggressive, low-latency packet recovery
max_retries: 8, max_retries: 8,
max_sent_history: 16384, max_sent_history: 16384,
}; };