From 28503540702350eeaccb47c7fb38633817af95f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Fri, 14 Apr 2023 20:49:34 +0800 Subject: [PATCH] shadowsocks: Multi-user support for legacy AEAD inbound Signed-off-by: wwqgtxx --- inbound/shadowsocks_multi.go | 30 +++++++++++++++++++++--------- option/shadowsocks.go | 2 +- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/inbound/shadowsocks_multi.go b/inbound/shadowsocks_multi.go index cfcd4225..3a998e36 100644 --- a/inbound/shadowsocks_multi.go +++ b/inbound/shadowsocks_multi.go @@ -9,6 +9,8 @@ import ( C "github.com/sagernet/sing-box/constant" "github.com/sagernet/sing-box/log" "github.com/sagernet/sing-box/option" + "github.com/sagernet/sing-shadowsocks" + "github.com/sagernet/sing-shadowsocks/shadowaead" "github.com/sagernet/sing-shadowsocks/shadowaead_2022" "github.com/sagernet/sing/common" "github.com/sagernet/sing/common/auth" @@ -25,7 +27,7 @@ var ( type ShadowsocksMulti struct { myInboundAdapter - service *shadowaead_2022.MultiService[int] + service shadowsocks.MultiService[int] users []option.ShadowsocksUser } @@ -49,16 +51,26 @@ func newShadowsocksMulti(ctx context.Context, router adapter.Router, logger log. } else { udpTimeout = int64(C.UDPTimeout.Seconds()) } - if !common.Contains(shadowaead_2022.List, options.Method) { + var ( + service shadowsocks.MultiService[int] + err error + ) + if common.Contains(shadowaead_2022.List, options.Method) { + service, err = shadowaead_2022.NewMultiServiceWithPassword[int]( + options.Method, + options.Password, + udpTimeout, + adapter.NewUpstreamContextHandler(inbound.newConnection, inbound.newPacketConnection, inbound), + router.TimeFunc(), + ) + } else if common.Contains(shadowaead.List, options.Method) { + service, err = shadowaead.NewMultiService[int]( + options.Method, + udpTimeout, + adapter.NewUpstreamContextHandler(inbound.newConnection, inbound.newPacketConnection, inbound)) + } else { return nil, E.New("unsupported method: " + options.Method) } - service, err := shadowaead_2022.NewMultiServiceWithPassword[int]( - options.Method, - options.Password, - udpTimeout, - adapter.NewUpstreamContextHandler(inbound.newConnection, inbound.newPacketConnection, inbound), - router.TimeFunc(), - ) if err != nil { return nil, err } diff --git a/option/shadowsocks.go b/option/shadowsocks.go index 3dc96171..38a18b83 100644 --- a/option/shadowsocks.go +++ b/option/shadowsocks.go @@ -4,7 +4,7 @@ type ShadowsocksInboundOptions struct { ListenOptions Network NetworkList `json:"network,omitempty"` Method string `json:"method"` - Password string `json:"password"` + Password string `json:"password,omitempty"` Users []ShadowsocksUser `json:"users,omitempty"` Destinations []ShadowsocksDestination `json:"destinations,omitempty"` }