shadowsocks-rust icon indicating copy to clipboard operation
shadowsocks-rust copied to clipboard

Use same port for SOCKS5/HTTP proxy

Open Mygod opened this issue 4 years ago • 8 comments

https://github.com/shadowsocks/shadowsocks-android/issues/2577

Mygod avatar Dec 15 '20 20:12 Mygod

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 = =..

zonyitoo avatar Dec 16 '20 01:12 zonyitoo

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是怎么实现?他们家好像见到能支持类似的功能

dev4u avatar Dec 16 '20 11:12 dev4u

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

zonyitoo avatar Dec 16 '20 13:12 zonyitoo

@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.

madeye avatar Dec 17 '20 01:12 madeye

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(...)

LuoZijun avatar Dec 20 '20 05:12 LuoZijun

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

https://github.com/shadowsocks/shadowsocks-rust/blob/1d11fba996c3a62333da511354cc21315b0af552/crates/shadowsocks-service/src/local/socks/server/mod.rs#L171-L177

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 https://github.com/shadowsocks/shadowsocks-rust/blob/a7c9f75d0767f5d8b8f2d23c6a8f70278429819f/shadowsocks/src/relay/tcprelay/http_local.rs#L883-L899

zonyitoo avatar Dec 20 '20 05:12 zonyitoo

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.

18o avatar Mar 02 '22 12:03 18o

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.

database64128 avatar Mar 02 '22 12:03 database64128

Supported on master branch.

zonyitoo avatar Nov 28 '23 02:11 zonyitoo