Skip to content

Use same port for SOCKS5/HTTP proxy #349

Description

@Mygod

Activity

  1. zonyitoo commented on Dec 16, 2020

    @zonyitoo
    Collaborator

    Accepts a TcpStream and then choose protocol automatically by the first byte?

    match first_byte {
        0x05 => handle_socks5_stream
        0x04 => handle_socks4_stream
        'H' | 'h' => handle_http_stream
    }

    That is quite hard to implement that with hyper. There is no API for this = =..

  2. dev4u commented on Dec 16, 2020

    @dev4u

    Accepts a TcpStream and then choose protocol automatically by the first byte?

    match first_byte {
        0x05 => handle_socks5_stream
        0x04 => handle_socks4_stream
        'H' | 'h' => handle_http_stream
    }

    That is quite hard to implement that with hyper. There is no API for this = =..

    或许可以参考一下,clash是怎么实现?他们家好像见到能支持类似的功能

  3. zonyitoo commented on Dec 16, 2020

    @zonyitoo
    Collaborator

    I know how to implement that, the only problem is hyper doesn't provide a API for me to customize Server's accept process.

  4. madeye commented on Dec 17, 2020

    @madeye
    Contributor

    @zonyitoo IIRC, some similar apps use pipes / channels to redirect the traffic to their HTTP modules.

    BTW, I think it's a low priority request.

  5. LuoZijun commented on Dec 20, 2020

    @LuoZijun
    Contributor

    I know how to implement that, the only problem is hyper doesn't provide a API for me to customize Server's accept process.

    first_byte 使用 .peek(...) ?

  6. zonyitoo commented on Dec 20, 2020

    @zonyitoo
    Collaborator

    I don't think the problem is how to guess which protocol going to be used,

    let mut version_buffer = [0u8; 1];
    let n = stream.peek(&mut version_buffer).await?;
    if n == 0 {
    return Err(ErrorKind::UnexpectedEof.into());
    }
    match version_buffer[0] {

    the key issue is that there is no API to feed an accepted TcpStream into a hyper Server instance.

    There are several ways to achieve this goal:

    1. Rewrite a HttpServer with the basic http crate. Reinventing the whole wheel.
    2. Customized an Acceptor and use hyper to handle all inbound connections, like a HTTPS server
      let make_service = make_service_fn(|socket: &TlsStream| {
      let client_addr = socket.remote_addr();
      let servers = servers.clone();
      let bypass_client = bypass_client.clone();
      async move {
      Ok::<_, Infallible>(service_fn(move |req: Request<Body>| {
      let svr_score = servers.pick_server();
      server_dispatch(req, svr_score, client_addr, bypass_client.clone())
      }))
      }
      });
      let acceptor = TlsAcceptor::bind(context.config(), &bind_addr)?;
      info!("shadowsocks HTTPS listening on {}", acceptor.local_addr());
      let server = Server::builder(acceptor).http1_only(true).serve(make_service);
  7. 18o commented on Mar 2, 2022

    @18o
    Contributor

    I think it could be all local services use one common port, or loop all ports set in local configure file, start tcp/udp services for each port and dispatch to different workers by checking the inbound package.In this way local dns can be mixed as well.

  8. database64128 commented on Mar 2, 2022

    @database64128
    Contributor

    I don't see how one could run out of ports for local services. Having multiple services over the same port adds unnecessary complexity and overhead.

  9. zonyitoo commented on Nov 28, 2023

    @zonyitoo
    Collaborator

    Supported on master branch.

  10. ljw20180420 commented on May 21, 2026

    @ljw20180420

    How to use SOCKS5/HTTP at the same port? I cannot find a guide on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions