Skip to content

Commit

Permalink
g3proxy: fix bind addr for agent udp connect
Browse files Browse the repository at this point in the history
  • Loading branch information
zh-jq-b committed May 15, 2024
1 parent 8d43140 commit 782f162
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
10 changes: 7 additions & 3 deletions g3proxy/src/escape/route_query/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,13 @@ impl CacheHandle {
pub(super) async fn spawn(config: &Arc<RouteQueryEscaperConfig>) -> anyhow::Result<CacheHandle> {
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:?}",
Expand Down
4 changes: 2 additions & 2 deletions g3proxy/src/serve/socks_proxy/task/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion lib/g3-ip-locate/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ impl IpLocateServiceConfig {
pub fn spawn_ip_locate_agent(&self) -> anyhow::Result<IpLocationServiceHandle> {
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(),
Expand Down
8 changes: 4 additions & 4 deletions lib/g3-socket/src/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IpAddr>,
buf_conf: SocketBufferConfig,
misc_opts: UdpMiscSockOpts,
Expand All @@ -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,
Expand Down Expand Up @@ -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(),
Expand All @@ -234,7 +234,7 @@ mod tests {
let loop_len = 100usize;
let mut v = Vec::<UdpSocket>::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(),
Expand Down
3 changes: 2 additions & 1 deletion lib/g3-tls-cert/src/agent/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ impl CertAgentConfig {
pub fn spawn_cert_agent(&self) -> anyhow::Result<CertAgentHandle> {
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(),
Expand Down

0 comments on commit 782f162

Please sign in to comment.