Skip to content

Commit

Permalink
Implement connect_by_proxy and connect_onion for async_runtime
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 def1af2 commit c75286b
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions tentacle/src/runtime/async_runtime/os.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use crate::{
runtime::CompatStream2,
service::config::{TcpSocket, TcpSocketConfig},
runtime::{proxy::socks5_config, CompatStream2},
service::{
config::{TcpSocket, TcpSocketConfig, TcpSocketTransformer},
ProxyConfig,
},
};
use async_io::Async;
use async_std::net::{TcpListener as AsyncListener, TcpStream as AsyncStream, ToSocketAddrs};
Expand All @@ -12,6 +15,7 @@ use futures::{
future::select,
FutureExt, SinkExt, StreamExt,
};
use multiaddr::MultiAddr;
use std::{
pin::Pin,
task::{Context, Poll},
Expand Down Expand Up @@ -207,3 +211,28 @@ pub(crate) async fn connect(
Some(err) => Err(err),
}
}

async fn connect_by_proxy<A>(
target_addr: A,
tcp_socket_transformer: TcpSocketTransformer,
proxy_config: ProxyConfig,
) -> io::Result<TcpStream>
where
A: Into<shadowsocks::relay::Address>,
{
let socks5_config = socks5_config::parse(&proxy_config.proxy_url)?;

let dial_addr: SocketAddr = socks5_config.proxy_url.parse().map_err(io::Error::other)?;
let stream = connect_direct(dial_addr, tcp_socket_transformer).await?;

crate::runtime::proxy::socks5::establish_connection(stream, target_addr, socks5_config)
.await
.map_err(io::Error::other)
}

pub(crate) async fn connect_onion(
onion_addr: MultiAddr,
tcp_config: TcpSocketConfig,
) -> io::Result<TcpStream> {
todo!()
}

0 comments on commit c75286b

Please sign in to comment.