shadowsocks / shadowsocks-rust

A Rust port of shadowsocks
https://shadowsocks.org/
MIT License
8.67k stars 1.18k forks source link

[FR] Server instances per local port #1095

Open Kein opened 1 year ago

Kein commented 1 year ago

So, multiple server is a great addition to shadowsocks, however my issue is that it essentially works as load balancer rather than actual being separate servers. It would be great if we could define for each server a local listener instance with unique local port. For example, Server1-3 declared in the config file gets requests from 127.0.0.1:1080 but Servers 3-5 will be getting requests from 127.0.0.1:1081. This mean sslocal can open multiple listen ports and two or more instances no longer required for this to work.

So essentially:

{
    "servers": [
        {
            "address": ".ip.ip.ip.ip",
            "port": 8388,
            "password": "hello-world",
            "method": "aes-256-gcm",
            "timeout": 7200,
            "local_port": 1081,
            "local_address": "127.0.0.1"
        },
        {
            "address": "ip.ip.ip.ip",
            "port": 8389,
            "password": "hello-kitty",
            "method": "chacha20-ietf-poly1305",
            "local_port": 1082,
            "local_address": "127.0.0.1"
        },
    ],
    #Global listener for all servers who dont have it defined per server
    "local_port": 8888,
    "local_address": "127.0.0.1"
}
ArchGuyWu commented 1 year ago

You can start multiple shadowsocks instances use this:

#shadowsocks-rust-server@.service
[Unit]
Description=Shadowsocks-Rust Server Service
After=network.target
Wants=network-online.target

[Service]
Type=simple
DynamicUser=yes
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
ExecStart=/usr/bin/ssservice server --log-without-time -c /etc/shadowsocks-rust/%i.json

[Install]
WantedBy=multi-user.target
database64128 commented 1 year ago

I think a comprehensive routing system, like the one in shadowsocks-go, can cover even more use cases, and is much more flexible than the ACL in shadowsocks-rust.

I also don't quite like how the ACL code integrates with the rest of shadowsocks-rust. It seems overly complex with layers of abstractions and is such a special case. But I don't know, maybe I'm just new to Rust and this is how they do things in Rust.

Kein commented 1 year ago

You can start multiple shadowsocks instances use this:

Yes, I know, which is precisely the reason this request exist, because it is not very handy. Though if this is out of scope of the fork/port then I suppose it can be closed.

Also, my bad, when I said "server instances" I meant on client listener side, i.e. one client - multiple local listen/accept ports each tied to its own server or even group of servers

zonyitoo commented 1 year ago

It would be great if we could define for each server a local listener instance with unique local port.

Emm, it is quite easy to implement.

Ahh.. I was wrong. I through you want a unique outbound_bind_addr for each servers. But this is not what you want.

Kein commented 1 year ago

Yeah, basically I want one client instance being able to route and work with multiple different servers via port-recognition. This way you dont have to run multiple client instances.

zonyitoo commented 1 year ago

Well, you will need a v2ray-like router logic. That is quite a lot of work.