diff --git a/g3proxy/src/escape/route_query/cache.rs b/g3proxy/src/escape/route_query/cache.rs index cd86d1c2c..6992e1afd 100644 --- a/g3proxy/src/escape/route_query/cache.rs +++ b/g3proxy/src/escape/route_query/cache.rs @@ -106,9 +106,13 @@ impl CacheHandle { pub(super) async fn spawn(config: &Arc) -> anyhow::Result { use anyhow::Context; - let (socket, _addr) = - g3_socket::udp::new_std_bind_connect(None, config.query_socket_buffer, Default::default()) - .context("failed to setup udp socket")?; + let socket = g3_socket::udp::new_std_socket_to( + config.query_peer_addr, + None, + config.query_socket_buffer, + Default::default(), + ) + .context("failed to setup udp socket")?; socket.connect(config.query_peer_addr).map_err(|e| { anyhow!( "failed to connect to peer address {}: {e:?}", diff --git a/g3proxy/src/serve/socks_proxy/task/common.rs b/g3proxy/src/serve/socks_proxy/task/common.rs index fb4a01ab5..91840efca 100644 --- a/g3proxy/src/serve/socks_proxy/task/common.rs +++ b/g3proxy/src/serve/socks_proxy/task/common.rs @@ -138,7 +138,7 @@ impl CommonTaskContext { let (clt_socket, listen_addr) = if let Some(port_range) = self.server_config.udp_bind_port_range { - g3_socket::udp::new_std_in_range_bind_connect( + g3_socket::udp::new_std_in_range_bind_lazy_connect( udp_bind_ip, port_range, self.server_config.udp_socket_buffer, @@ -150,7 +150,7 @@ impl CommonTaskContext { ) })? } else { - g3_socket::udp::new_std_bind_connect( + g3_socket::udp::new_std_bind_lazy_connect( Some(udp_bind_ip), self.server_config.udp_socket_buffer, misc_opts, diff --git a/lib/g3-ip-locate/src/config.rs b/lib/g3-ip-locate/src/config.rs index eef102b14..1840392f8 100644 --- a/lib/g3-ip-locate/src/config.rs +++ b/lib/g3-ip-locate/src/config.rs @@ -81,7 +81,8 @@ impl IpLocateServiceConfig { pub fn spawn_ip_locate_agent(&self) -> anyhow::Result { use anyhow::Context; - let (socket, _addr) = g3_socket::udp::new_std_bind_connect( + let socket = g3_socket::udp::new_std_socket_to( + self.query_peer_addr, None, self.query_socket_buffer, Default::default(), diff --git a/lib/g3-socket/src/udp.rs b/lib/g3-socket/src/udp.rs index 3a0e5e243..e45b198e4 100644 --- a/lib/g3-socket/src/udp.rs +++ b/lib/g3-socket/src/udp.rs @@ -52,7 +52,7 @@ pub fn new_std_socket_to( Ok(UdpSocket::from(socket)) } -pub fn new_std_bind_connect( +pub fn new_std_bind_lazy_connect( bind_ip: Option, buf_conf: SocketBufferConfig, misc_opts: UdpMiscSockOpts, @@ -71,7 +71,7 @@ pub fn new_std_bind_connect( Ok((socket, listen_addr)) } -pub fn new_std_in_range_bind_connect( +pub fn new_std_in_range_bind_lazy_connect( bind_ip: IpAddr, port: PortRange, buf_conf: SocketBufferConfig, @@ -216,7 +216,7 @@ mod tests { #[test] fn bind_to_ip() { - let (_socket, local_addr) = new_std_bind_connect( + let (_socket, local_addr) = new_std_bind_lazy_connect( Some(IpAddr::V4(Ipv4Addr::UNSPECIFIED)), SocketBufferConfig::default(), Default::default(), @@ -234,7 +234,7 @@ mod tests { let loop_len = 100usize; let mut v = Vec::::with_capacity(loop_len); for _i in 0..loop_len { - let (socket, local_addr) = new_std_in_range_bind_connect( + let (socket, local_addr) = new_std_in_range_bind_lazy_connect( ip, range, SocketBufferConfig::default(), diff --git a/lib/g3-tls-cert/src/agent/config.rs b/lib/g3-tls-cert/src/agent/config.rs index adf9a277a..74de1ecf1 100644 --- a/lib/g3-tls-cert/src/agent/config.rs +++ b/lib/g3-tls-cert/src/agent/config.rs @@ -87,7 +87,8 @@ impl CertAgentConfig { pub fn spawn_cert_agent(&self) -> anyhow::Result { use anyhow::Context; - let (socket, _addr) = g3_socket::udp::new_std_bind_connect( + let socket = g3_socket::udp::new_std_socket_to( + self.query_peer_addr, None, self.query_socket_buffer, Default::default(),