Simple solution for #292, preventing active probing

This commit is contained in:
zonyitoo
2020-09-08 23:31:20 +08:00
parent 5af929004e
commit 9f7e9a928e
4 changed files with 20 additions and 0 deletions

View File

@@ -90,6 +90,11 @@ where
pub fn get_ref(&self) -> &S {
self.stream.get_ref()
}
/// Get the internal stream and consume this Connection
pub fn into_inner(self) -> S {
self.stream.into_inner()
}
}
#[inline]

View File

@@ -140,6 +140,11 @@ impl<S> CryptoStream<S> {
pub fn get_ref(&self) -> &S {
&self.stream
}
/// Consume the CryptoStream and return the internal stream instance
pub fn into_inner(self) -> S {
self.stream
}
}
impl<S> CryptoStream<S>

View File

@@ -24,6 +24,10 @@ impl<S> TcpMonStream<S> {
pub fn new(flow_stat: SharedServerFlowStatistic, stream: S) -> TcpMonStream<S> {
TcpMonStream { stream, flow_stat }
}
pub fn into_inner(self) -> S {
self.stream
}
}
impl<S> AsyncRead for TcpMonStream<S>

View File

@@ -58,6 +58,12 @@ async fn handle_client(
"failed to decode Address, may be wrong method or key, from client {}, error: {}",
peer_addr, err
);
// Hold the TCP connection until it closes by itself for preventing active probing.
// Further discussion: https://github.com/shadowsocks/shadowsocks-rust/issues/292
let mut tcp = stream.into_inner().into_inner().into_inner();
let _ = super::ignore_until_end(&mut tcp).await;
return Err(From::from(err));
}
};