Browse Source

fixed variables name

pull/3/head
Karan Gauswami 4 years ago
parent
commit
6066fd54dc
  1. 22
      src/main.rs

22
src/main.rs

@ -26,6 +26,7 @@ async fn main() {
let socks_address = args.socks_address; let socks_address = args.socks_address;
let port = args.port; let port = args.port;
let addr = SocketAddr::from(([127, 0, 0, 1], port)); let addr = SocketAddr::from(([127, 0, 0, 1], port));
let socks_address = socks_address.to_socket_addrs().unwrap().next().unwrap();
let make_service = make_service_fn(move |_| { let make_service = make_service_fn(move |_| {
let socks_address = socks_address.clone(); let socks_address = socks_address.clone();
async move { async move {
@ -41,21 +42,12 @@ async fn main() {
eprintln!("{:?}", e); eprintln!("{:?}", e);
}; };
} }
async fn proxy(req: Request<Body>, socks_address: String) -> Result<Response<Body>> { async fn proxy(req: Request<Body>, socks_address: SocketAddr) -> Result<Response<Body>> {
let _response = Response::new(Body::empty()); let _response = Response::new(Body::empty());
if req.method() == hyper::Method::CONNECT { if req.method() == hyper::Method::CONNECT {
tokio::task::spawn(async move { tokio::task::spawn(async move {
let plain = req.uri().authority().unwrap().as_str().to_string(); let plain = req.uri().authority().unwrap().as_str().to_string();
let addr = req
.uri()
.authority()
.unwrap()
.as_str()
.to_socket_addrs()
.unwrap()
.next()
.unwrap();
match hyper::upgrade::on(req).await { match hyper::upgrade::on(req).await {
Ok(upgraded) => { Ok(upgraded) => {
if let Err(e) = tunnel(upgraded, plain, socks_address).await { if let Err(e) = tunnel(upgraded, plain, socks_address).await {
@ -73,19 +65,19 @@ async fn proxy(req: Request<Body>, socks_address: String) -> Result<Response<Bod
async fn tunnel( async fn tunnel(
upgraded: hyper::upgrade::Upgraded, upgraded: hyper::upgrade::Upgraded,
plain: String, target_addr: String,
socks_address: String, socks_address: SocketAddr,
) -> std::io::Result<()> { ) -> std::io::Result<()> {
let socket_address = socks_address.to_socket_addrs().unwrap().next().unwrap(); let socket_address = socks_address.to_socket_addrs().unwrap().next().unwrap();
let target_addr = plain.into_target_addr(); let target_addr = target_addr.into_target_addr();
let target_addr = target_addr.unwrap(); let target_addr = target_addr.unwrap();
let a = tokio_socks::tcp::Socks5Stream::connect(socket_address, target_addr) let socks_stream = tokio_socks::tcp::Socks5Stream::connect(socket_address, target_addr)
.await .await
.expect("Cannot Connect to Socks5 Server"); .expect("Cannot Connect to Socks5 Server");
let amounts = { let amounts = {
let (mut server_rd, mut server_wr) = tokio::io::split(a); let (mut server_rd, mut server_wr) = tokio::io::split(socks_stream);
let (mut client_rd, mut client_wr) = tokio::io::split(upgraded); let (mut client_rd, mut client_wr) = tokio::io::split(upgraded);
let client_to_server = tokio::io::copy(&mut client_rd, &mut server_wr); let client_to_server = tokio::io::copy(&mut client_rd, &mut server_wr);

Loading…
Cancel
Save