Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ssrlive committed Apr 7, 2024
1 parent 253bcd2 commit 80fc942
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,26 +393,16 @@ async fn handle_udp_associate_session(
) -> crate::Result<()> {
use socks5_impl::protocol::{Address, StreamOperation, UdpHeader};

let (session_info, server_addr, domain_name, udp_addr) = {
let (session_info, server_addr, domain_name) = {
let handler = proxy_handler.lock().await;
(
handler.get_session_info(),
handler.get_server_addr(),
handler.get_domain_name(),
handler.get_udp_associate(),
)
(handler.get_session_info(), handler.get_server_addr(), handler.get_domain_name())
};

log::info!("Beginning {}", session_info);

let (_server, udp_addr) = match udp_addr {
Some(udp_addr) => (None, udp_addr),
None => {
let mut server = create_tcp_stream(&socket_queue, server_addr).await?;
let udp_addr = handle_proxy_session(&mut server, proxy_handler).await?;
(Some(server), udp_addr.ok_or("udp associate failed")?)
}
};
let mut server = create_tcp_stream(&socket_queue, server_addr).await?;
let udp_addr = handle_proxy_session(&mut server, proxy_handler).await?;
let udp_addr = udp_addr.ok_or("udp associate failed")?;

let mut udp_server = create_udp_stream(&socket_queue, udp_addr).await?;

Expand Down Expand Up @@ -479,6 +469,9 @@ async fn handle_udp_associate_session(
Ok(())
}

/// This function is used to handle the business logic of tun2proxy and SOCKS5 server.
/// When handling UDP proxy, the return value UDP associate IP address is the result of this business logic.
/// However, when handling TCP business logic, the return value Ok(None) is meaningless, just indicating that the operation was successful.
async fn handle_dns_over_tcp_session(
mut udp_stack: IpStackUdpStream,
proxy_handler: Arc<Mutex<dyn ProxyHandler>>,
Expand Down

0 comments on commit 80fc942

Please sign in to comment.