diff --git a/tentacle/src/runtime/mod.rs b/tentacle/src/runtime/mod.rs index 52928afb..478a04d9 100644 --- a/tentacle/src/runtime/mod.rs +++ b/tentacle/src/runtime/mod.rs @@ -16,7 +16,7 @@ mod async_runtime; all(target_family = "wasm", feature = "wasm-timer") ))] mod generic_timer; -pub(crate) mod socks5_config; +pub(crate) mod proxy; #[cfg(all(not(target_family = "wasm"), feature = "tokio-runtime"))] mod tokio_runtime; #[cfg(target_family = "wasm")] diff --git a/tentacle/src/runtime/proxy/mod.rs b/tentacle/src/runtime/proxy/mod.rs new file mode 100644 index 00000000..668ebe72 --- /dev/null +++ b/tentacle/src/runtime/proxy/mod.rs @@ -0,0 +1,2 @@ +pub(crate) mod socks5; +pub(crate) mod socks5_config; diff --git a/tentacle/src/runtime/tokio_runtime/socks5.rs b/tentacle/src/runtime/proxy/socks5.rs similarity index 91% rename from tentacle/src/runtime/tokio_runtime/socks5.rs rename to tentacle/src/runtime/proxy/socks5.rs index d374609a..6ec4e381 100644 --- a/tentacle/src/runtime/tokio_runtime/socks5.rs +++ b/tentacle/src/runtime/proxy/socks5.rs @@ -5,16 +5,17 @@ use shadowsocks::relay::socks5::{ self, Address, Command, Error as Socks5Error, HandshakeRequest, HandshakeResponse, PasswdAuthRequest, PasswdAuthResponse, Reply, TcpRequestHeader, TcpResponseHeader, }; -use tokio::net::TcpStream; +use tokio::io::{AsyncRead, AsyncWrite}; -use super::super::socks5_config::Socks5Config; +use super::socks5_config::Socks5Config; -pub async fn establish_connection( - mut s: TcpStream, +pub async fn establish_connection( + mut s: S, target_addr: A, socks5_config: Socks5Config, -) -> Result +) -> Result where + S: AsyncRead + AsyncWrite + Unpin, A: Into
, { debug!( diff --git a/tentacle/src/runtime/socks5_config.rs b/tentacle/src/runtime/proxy/socks5_config.rs similarity index 100% rename from tentacle/src/runtime/socks5_config.rs rename to tentacle/src/runtime/proxy/socks5_config.rs diff --git a/tentacle/src/runtime/tokio_runtime/mod.rs b/tentacle/src/runtime/tokio_runtime/mod.rs index 6cbce569..54cc47d5 100644 --- a/tentacle/src/runtime/tokio_runtime/mod.rs +++ b/tentacle/src/runtime/tokio_runtime/mod.rs @@ -1,5 +1,4 @@ -use super::socks5_config; -mod socks5; +use super::proxy::socks5_config; use multiaddr::MultiAddr; pub use tokio::{ net::{TcpListener, TcpStream}, @@ -155,7 +154,7 @@ where let dial_addr: SocketAddr = socks5_config.proxy_url.parse().map_err(io::Error::other)?; let stream = connect_direct(dial_addr, tcp_socket_transformer).await?; - super::tokio_runtime::socks5::establish_connection(stream, target_addr, socks5_config) + super::proxy::socks5::establish_connection(stream, target_addr, socks5_config) .await .map_err(io::Error::other) }