Skip to content

Commit

Permalink
net: fix UDP outbound socket binding
Browse files Browse the repository at this point in the history
  • Loading branch information
eycorsican committed Jun 1, 2024
1 parent f60e243 commit 3cbd445
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions leaf/src/proxy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,10 @@ pub async fn connect_datagram_outbound(
match handler.datagram()?.connect_addr() {
OutboundConnect::Proxy(network, addr, port) => match network {
Network::Udp => {
let socket = new_udp_socket(&sess.source).await?;
let socket = match addr.parse::<IpAddr>() {
Ok(ip) if ip.is_loopback() => new_udp_socket(&SocketAddr::new(ip, 0)).await?,
_ => new_udp_socket(&*crate::option::UNSPECIFIED_BIND_ADDR).await?,
};
Ok(Some(OutboundTransport::Datagram(Box::new(
DomainResolveOutboundDatagram::new(socket, dns_client.clone()),
))))
Expand All @@ -417,7 +420,7 @@ pub async fn connect_datagram_outbound(
},
OutboundConnect::Direct => match &sess.destination {
SocksAddr::Domain(domain, port) => {
let socket = new_udp_socket(&sess.source).await?;
let socket = new_udp_socket(&*crate::option::UNSPECIFIED_BIND_ADDR).await?;
Ok(Some(OutboundTransport::Datagram(Box::new(
DomainAssociatedOutboundDatagram::new(
socket,
Expand All @@ -427,8 +430,8 @@ pub async fn connect_datagram_outbound(
),
))))
}
SocksAddr::Ip(_) => {
let socket = new_udp_socket(&sess.source).await?;
SocksAddr::Ip(addr) => {
let socket = new_udp_socket(addr).await?;
Ok(Some(OutboundTransport::Datagram(Box::new(
StdOutboundDatagram::new(socket),
))))
Expand Down

2 comments on commit 3cbd445

@cattyhouse
Copy link

@cattyhouse cattyhouse commented on 3cbd445 Jun 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think there is also an issue with the UDP in NatManager, the speed is very slow and even laggy in the first few minutes, chrome has to pause and wait for more buffer, when:

  1. Google Chrome with QUIC enabled: chrome://flags/#enable-quic
  2. Play 4k 60fps video

after the first few minutes, speed becomes normal. I'm sorry that i don't know where to report the issue, so it got posted here.

the outbound protocol is trojan+tls and inbound protocol is socks5

@eycorsican
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think there is also an issue with the UDP in NatManager, the speed is very slow and even laggy in the first few minutes, chrome has to pause and wait for more buffer, when:

  1. Google Chrome with QUIC enabled: chrome://flags/#enable-quic
  2. Play 4k 60fps video

after the first few minutes, speed becomes normal. I'm sorry that i don't know where to report the issue, so it got posted here.

the outbound protocol is trojan+tls and inbound protocol is socks5

you can make a benchmark with proxychains-ng and iperf3

Please sign in to comment.