Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add proxy router example & support (take 2) #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

GlenDC
Copy link

@GlenDC GlenDC commented May 8, 2022

Retry of original attempt at #18

Not much changed except that I figured out the missing part.
Turns out it requires the data transfer not to happen yet,
while we do want all the other code to have been executed.

This should work now.

Resolves #18 .
It also closes #19, as you already supported that, and now we can use it correctly.

@AbelChe
Copy link

AbelChe commented Mar 1, 2023

First, thanks for your code @ router.rs

I want know if it is possible to implement "socks5 => socks4"...
I tried to use "socks4/client.rs", but it seems unable to work...
the code :

use fast_socks5::socks4::client::Socks4Stream;

// proxy_addr: "socks4://1.2.3.4:1234" 
match &proxy_addr.as_str()[5..6] {
            "4" => {
                let mut stream = Socks4Stream::connect(
                        proxy_addr.clone().as_str()[9..proxy_addr.len()].to_string(),
                        socket_addr.ip().to_string(),
                        socket_addr.port(),
                        false,
                    )
                    .await
                    .context("connect to downstream proxy for incoming socket")?;
                match tokio::io::copy_bidirectional(&mut stream, &mut socks5_socket).await {
                    Ok(res) => {
                        debug!("socket transfer closed ({}, {})", res.0, res.1);
                        Ok(())
                    }
                    Err(err) => match err.kind() {
                        ErrorKind::NotConnected => {
                            debug!("socket transfer closed by client");
                            Ok(())
                        },
                        ErrorKind::ConnectionReset => {
                            debug!("socket transfer closed by downstream proxy");
                            Ok(())
                        },
                        _ => Err(SocksError::Other(anyhow!(
                            "socket transfer error: {:#}",
                            err
                        )))
                    },
                }
            },
            "5" => {
                let mut stream = Socks5Stream::connect(
                   ........

@GlenDC
Copy link
Author

GlenDC commented Mar 1, 2023

I want know if it is possible to implement "socks5 => socks4"... I tried to use "socks4/client.rs", but it seems unable to work... the code :

Once you have 2 byte streams you should be able to copy between them, regardless of it was created. I am not affiliate with this repository though, an neither have I use it in a while. Might use it again in near future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature request: ability to receive the original unresolved target address
2 participants