From bd0cf955c7fbd2f65a77c3c260f7c51cea9d7421 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Mon, 6 Jun 2022 14:12:59 +0800 Subject: [PATCH] Update shadowsocks-2022 multi-server usage --- go.mod | 4 ++-- go.sum | 8 ++++---- proxy/shadowsocks_2022/inbound_multi.go | 19 ++++++++++--------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index f050add2..b521548d 100644 --- a/go.mod +++ b/go.mod @@ -16,8 +16,8 @@ require ( github.com/pelletier/go-toml v1.9.5 github.com/pires/go-proxyproto v0.6.2 github.com/refraction-networking/utls v1.1.0 - github.com/sagernet/sing v0.0.0-20220605012533-e0f722558141 - github.com/sagernet/sing-shadowsocks v0.0.0-20220605012719-1e22882ea853 + github.com/sagernet/sing v0.0.0-20220606055031-45523fbbe7ae + github.com/sagernet/sing-shadowsocks v0.0.0-20220606055616-292d3a4b6cce github.com/seiflotfy/cuckoofilter v0.0.0-20220411075957-e3b120b3f5fb github.com/stretchr/testify v1.7.1 github.com/v2fly/ss-bloomring v0.0.0-20210312155135-28617310f63e diff --git a/go.sum b/go.sum index 07ffb25a..481a2fae 100644 --- a/go.sum +++ b/go.sum @@ -174,10 +174,10 @@ github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3 h1:f/FNXud6gA3MNr github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3/go.mod h1:HgjTstvQsPGkxUsCd2KWxErBblirPizecHcpD3ffK+s= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= -github.com/sagernet/sing v0.0.0-20220605012533-e0f722558141 h1:YN9EeHRIFYKei1woz2OucLTSpiNrULAHH+jl6upDemQ= -github.com/sagernet/sing v0.0.0-20220605012533-e0f722558141/go.mod h1:w2HnJzXKHpD6F5Z/9XlSD4qbcpHY2RSZuQnFzqgELMg= -github.com/sagernet/sing-shadowsocks v0.0.0-20220605012719-1e22882ea853 h1:t1pn8v3kPvlaST/fY7GsPV8yIUFJDXzNcmSYQ+nrbEM= -github.com/sagernet/sing-shadowsocks v0.0.0-20220605012719-1e22882ea853/go.mod h1:Afu8UIFlEwxTnlidTMSWqWHIduAWOrwY0tFr2LxBACQ= +github.com/sagernet/sing v0.0.0-20220606055031-45523fbbe7ae h1:SrqT/QhXJwAw7hfAxgDqEPF3J0yK2U6Y8lGZhAubs9E= +github.com/sagernet/sing v0.0.0-20220606055031-45523fbbe7ae/go.mod h1:w2HnJzXKHpD6F5Z/9XlSD4qbcpHY2RSZuQnFzqgELMg= +github.com/sagernet/sing-shadowsocks v0.0.0-20220606055616-292d3a4b6cce h1:Hz1Km249vB6aoA0/45WLE5H8Ej/n07Id1lMaWkd6T2Q= +github.com/sagernet/sing-shadowsocks v0.0.0-20220606055616-292d3a4b6cce/go.mod h1:4Wb0SmPgT8ZBQeY2kf4LFI6jl4T9mHJ2uDPdxG5ky38= github.com/seiflotfy/cuckoofilter v0.0.0-20220411075957-e3b120b3f5fb h1:XfLJSPIOUX+osiMraVgIrMR27uMXnRJWGm1+GL8/63U= github.com/seiflotfy/cuckoofilter v0.0.0-20220411075957-e3b120b3f5fb/go.mod h1:bR6DqgcAl1zTcOX8/pE2Qkj9XO00eCNqmKb7lXP8EAg= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= diff --git a/proxy/shadowsocks_2022/inbound_multi.go b/proxy/shadowsocks_2022/inbound_multi.go index 03ab1f9b..1b1da464 100644 --- a/proxy/shadowsocks_2022/inbound_multi.go +++ b/proxy/shadowsocks_2022/inbound_multi.go @@ -5,9 +5,11 @@ package shadowsocks_2022 import ( "context" "encoding/base64" + "strconv" "github.com/sagernet/sing-shadowsocks" "github.com/sagernet/sing-shadowsocks/shadowaead_2022" + C "github.com/sagernet/sing/common" B "github.com/sagernet/sing/common/buf" "github.com/sagernet/sing/common/bufio" E "github.com/sagernet/sing/common/exceptions" @@ -63,17 +65,16 @@ func NewMultiServer(ctx context.Context, config *MultiUserServerConfig) (*MultiU for i, user := range config.Users { if user.Email == "" { u := uuid.New() - user.Email = "(user with empty email - " + u.String() + ")" - } - uPSK, err := base64.StdEncoding.DecodeString(user.Key) - if err != nil { - return nil, newError("parse user key for ", user.Email).Base(err) - } - err = service.AddUser(i, uPSK) - if err != nil { - return nil, newError("add user").Base(err) + user.Email = "unnamed-user-" + strconv.Itoa(i) + "-" + u.String() } } + err = service.UpdateUsersWithPasswords( + C.MapIndexed(config.Users, func(index int, it *User) int { return index }), + C.Map(config.Users, func(it *User) string { return it.Key }), + ) + if err != nil { + return nil, newError("create service").Base(err) + } inbound.service = service return inbound, nil