mirror of
https://github.com/chatmail/core.git
synced 2026-04-28 19:06:35 +03:00
refactor: do not wrap shadowsocks::ProxyClientStream
Updated `shadowsocks` implements `Debug` for the type, so there is no need to wrap it.
This commit is contained in:
5
Cargo.lock
generated
5
Cargo.lock
generated
@@ -1315,7 +1315,6 @@ dependencies = [
|
||||
"parking_lot",
|
||||
"percent-encoding",
|
||||
"pgp",
|
||||
"pin-project",
|
||||
"pretty_assertions",
|
||||
"proptest",
|
||||
"qrcodegen",
|
||||
@@ -5385,9 +5384,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "shadowsocks"
|
||||
version = "1.20.2"
|
||||
version = "1.21.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06b6af20f0f009894644c9fb149ce6244c69b0a264ffcf7a53cbb3dd4883e4a3"
|
||||
checksum = "5ecb3780dfbc654de9383758015b9bb95c6e32fecace36ebded09d67e854d130"
|
||||
dependencies = [
|
||||
"aes",
|
||||
"async-trait",
|
||||
|
||||
@@ -77,7 +77,6 @@ once_cell = { workspace = true }
|
||||
parking_lot = "0.12"
|
||||
percent-encoding = "2.3"
|
||||
pgp = { version = "0.13.2", default-features = false }
|
||||
pin-project = "1"
|
||||
qrcodegen = "1.7.0"
|
||||
quick-xml = "0.36"
|
||||
quoted_printable = "0.5"
|
||||
@@ -90,7 +89,7 @@ serde_json = { workspace = true }
|
||||
serde_urlencoded = "0.7.1"
|
||||
serde = { workspace = true, features = ["derive"] }
|
||||
sha-1 = "0.10"
|
||||
shadowsocks = { version = "1.20.2", default-features = false, features = ["aead-cipher-2022"] }
|
||||
shadowsocks = { version = "1.21.0", default-features = false, features = ["aead-cipher-2022"] }
|
||||
smallvec = "1.13.2"
|
||||
strum = "0.26"
|
||||
strum_macros = "0.26"
|
||||
|
||||
@@ -13,8 +13,7 @@ use fast_socks5::util::target_addr::ToTargetAddr;
|
||||
use fast_socks5::AuthenticationMethod;
|
||||
use fast_socks5::Socks5Command;
|
||||
use percent_encoding::{percent_encode, NON_ALPHANUMERIC};
|
||||
use pin_project::pin_project;
|
||||
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
|
||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
use tokio::net::TcpStream;
|
||||
use tokio_io_timeout::TimeoutStream;
|
||||
use url::Url;
|
||||
@@ -41,62 +40,6 @@ impl PartialEq for ShadowsocksConfig {
|
||||
|
||||
impl Eq for ShadowsocksConfig {}
|
||||
|
||||
/// Wrapper for Shadowsocks stream implementing
|
||||
/// `Debug` and `SessionStream`.
|
||||
///
|
||||
/// Passes `AsyncRead` and `AsyncWrite` traits through.
|
||||
#[pin_project]
|
||||
pub(crate) struct ShadowsocksStream<S> {
|
||||
#[pin]
|
||||
pub(crate) stream: shadowsocks::ProxyClientStream<S>,
|
||||
}
|
||||
|
||||
impl<S> std::fmt::Debug for ShadowsocksStream<S> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "ShadowsocksStream")
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> AsyncRead for ShadowsocksStream<S>
|
||||
where
|
||||
S: AsyncRead + AsyncWrite + Unpin,
|
||||
{
|
||||
fn poll_read(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut std::task::Context<'_>,
|
||||
buf: &mut tokio::io::ReadBuf<'_>,
|
||||
) -> std::task::Poll<std::io::Result<()>> {
|
||||
self.project().stream.poll_read(cx, buf)
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> AsyncWrite for ShadowsocksStream<S>
|
||||
where
|
||||
S: AsyncRead + AsyncWrite + Unpin,
|
||||
{
|
||||
fn poll_write(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut std::task::Context<'_>,
|
||||
buf: &[u8],
|
||||
) -> std::task::Poll<Result<usize, std::io::Error>> {
|
||||
self.project().stream.poll_write(cx, buf)
|
||||
}
|
||||
|
||||
fn poll_flush(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut std::task::Context<'_>,
|
||||
) -> std::task::Poll<Result<(), std::io::Error>> {
|
||||
self.project().stream.poll_flush(cx)
|
||||
}
|
||||
|
||||
fn poll_shutdown(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut std::task::Context<'_>,
|
||||
) -> std::task::Poll<Result<(), std::io::Error>> {
|
||||
self.project().stream.poll_shutdown(cx)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct HttpConfig {
|
||||
/// HTTP proxy host.
|
||||
@@ -469,15 +412,12 @@ impl ProxyConfig {
|
||||
.context("Failed to connect to Shadowsocks proxy")?
|
||||
};
|
||||
|
||||
let proxy_client_stream = shadowsocks::ProxyClientStream::from_stream(
|
||||
let shadowsocks_stream = shadowsocks::ProxyClientStream::from_stream(
|
||||
shadowsocks_context,
|
||||
tcp_stream,
|
||||
server_config,
|
||||
(target_host.to_string(), target_port),
|
||||
);
|
||||
let shadowsocks_stream = ShadowsocksStream {
|
||||
stream: proxy_client_stream,
|
||||
};
|
||||
|
||||
Ok(Box::new(shadowsocks_stream))
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use crate::net::proxy::ShadowsocksStream;
|
||||
use async_native_tls::TlsStream;
|
||||
use fast_socks5::client::Socks5Stream;
|
||||
use std::pin::Pin;
|
||||
@@ -45,9 +44,9 @@ impl<T: SessionStream> SessionStream for Socks5Stream<T> {
|
||||
self.get_socket_mut().set_read_timeout(timeout)
|
||||
}
|
||||
}
|
||||
impl<T: SessionStream> SessionStream for ShadowsocksStream<T> {
|
||||
impl<T: SessionStream> SessionStream for shadowsocks::ProxyClientStream<T> {
|
||||
fn set_read_timeout(&mut self, timeout: Option<Duration>) {
|
||||
self.stream.get_mut().set_read_timeout(timeout)
|
||||
self.get_mut().set_read_timeout(timeout)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user