shadowsocks-rust
shadowsocks-rust copied to clipboard
Use same port for SOCKS5/HTTP proxy
https://github.com/shadowsocks/shadowsocks-android/issues/2577
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 = =..
Accepts a
TcpStreamand 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是怎么实现?他们家好像见到能支持类似的功能
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 IIRC, some similar apps use pipes / channels to redirect the traffic to their HTTP modules.
BTW, I think it's a low priority request.
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(...) ?
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:
- Rewrite a HttpServer with the basic
httpcrate. Reinventing the whole wheel. - 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
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.
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.
Supported on master branch.