Skip to content

Commit 446b180

Browse files
committed
feat(shadowsocks-service): AutoProxyClientStream prevent mapping fake-ips twice (#2028)
1 parent e2ffb9c commit 446b180

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

crates/shadowsocks-service/src/local/net/tcp/auto_proxy_stream.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ impl AutoProxyClientStream {
5858
}
5959
if context.check_target_bypassed(&addr).await {
6060
trace!("Bypassing target address {addr}");
61-
Self::connect_bypassed_with_opts(context, addr, opts).await
61+
Self::connect_bypassed_with_opts_inner(context, addr, opts).await
6262
} else {
6363
trace!("Proxying target address {addr}");
64-
Self::connect_proxied_with_opts(context, server, addr, opts).await
64+
Self::connect_proxied_with_opts_inner(context, server, addr, opts).await
6565
}
6666
}
6767

@@ -89,6 +89,18 @@ impl AutoProxyClientStream {
8989
if let Some(mapped_addr) = context.try_map_fake_address(&addr).await {
9090
addr = mapped_addr;
9191
}
92+
Self::connect_bypassed_with_opts_inner(context, addr, connect_opts).await
93+
}
94+
95+
async fn connect_bypassed_with_opts_inner<A>(
96+
context: Arc<ServiceContext>,
97+
addr: A,
98+
connect_opts: &ConnectOpts,
99+
) -> io::Result<Self>
100+
where
101+
A: Into<Address>,
102+
{
103+
let addr = addr.into();
92104
let stream = TcpStream::connect_remote_with_opts(context.context_ref(), &addr, connect_opts).await?;
93105
Ok(Self::Bypassed(stream))
94106
}
@@ -117,6 +129,18 @@ impl AutoProxyClientStream {
117129
if let Some(mapped_addr) = context.try_map_fake_address(&addr).await {
118130
addr = mapped_addr;
119131
}
132+
Self::connect_proxied_with_opts_inner(context, server, addr, connect_opts).await
133+
}
134+
135+
async fn connect_proxied_with_opts_inner<A>(
136+
context: Arc<ServiceContext>,
137+
server: &ServerIdent,
138+
addr: A,
139+
connect_opts: &ConnectOpts,
140+
) -> io::Result<Self>
141+
where
142+
A: Into<Address>,
143+
{
120144
let flow_stat = context.flow_stat();
121145
let stream = match ProxyClientStream::connect_with_opts_map(
122146
context.context(),

0 commit comments

Comments
 (0)