Skip to content

Commit

Permalink
wip: try to let async_runtime and tokio_runtime reuse socks5 establish
Browse files Browse the repository at this point in the history
Signed-off-by: Eval EXEC <execvy@gmail.com>
  • Loading branch information
eval-exec committed Dec 18, 2024
1 parent c75286b commit c6bef08
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion tentacle/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
2 changes: 2 additions & 0 deletions tentacle/src/runtime/proxy/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub(crate) mod socks5;
pub(crate) mod socks5_config;
Original file line number Diff line number Diff line change
Expand Up @@ -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<A>(
mut s: TcpStream,
pub async fn establish_connection<S, A>(
mut s: S,
target_addr: A,
socks5_config: Socks5Config,
) -> Result<TcpStream, Socks5Error>
) -> Result<S, Socks5Error>
where
S: AsyncRead + AsyncWrite + Unpin,
A: Into<Address>,
{
debug!(
Expand Down
File renamed without changes.
5 changes: 2 additions & 3 deletions tentacle/src/runtime/tokio_runtime/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use super::socks5_config;
mod socks5;
use super::proxy::socks5_config;
use multiaddr::MultiAddr;
pub use tokio::{
net::{TcpListener, TcpStream},
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit c6bef08

Please sign in to comment.