Skip to content

Commit

Permalink
Migrate shadowsocks-2022 to protocol library
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed May 25, 2022
1 parent c375b14 commit 79f3057
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 72 deletions.
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ 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-20220523024450-2216901ec429
github.com/sagernet/sing v0.0.0-20220525123305-5b49366f6e34
github.com/sagernet/sing-shadowsocks v0.0.0-20220525123814-48809b0a9949
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
github.com/xtls/go v0.0.0-20210920065950-d4af136d3672
go.starlark.net v0.0.0-20220328144851-d1966c6b9fcd
golang.org/x/crypto v0.0.0-20220518034528-6f7dac969898
golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/net v0.0.0-20220524220425-1d687d428aca
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a
google.golang.org/grpc v1.46.2
google.golang.org/protobuf v1.28.0
Expand Down
15 changes: 10 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,12 @@ 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-20220523024450-2216901ec429 h1:31vx64WHtycaqw0bGLl6ImJvmHsXqHoPzkuwKmTqbx8=
github.com/sagernet/sing v0.0.0-20220523024450-2216901ec429/go.mod h1:7aFl1bLxdWLIhptc1DwhMWpRfT62rJYzKPYuYlzYs5w=
github.com/sagernet/sing v0.0.0-20220525123305-5b49366f6e34 h1:/FfHfteLZo5mOtZbYOx/9ymDEYxlwBuM5iHO9reVe/E=
github.com/sagernet/sing v0.0.0-20220525123305-5b49366f6e34/go.mod h1:w2HnJzXKHpD6F5Z/9XlSD4qbcpHY2RSZuQnFzqgELMg=
github.com/sagernet/sing-shadowsocks v0.0.0-20220525121912-9e43a1c42021 h1:pPIc8xricCQNMuAoOlblcGcrMYmc/pfcY1fwK62iSmo=
github.com/sagernet/sing-shadowsocks v0.0.0-20220525121912-9e43a1c42021/go.mod h1:aaKmw93taQ3PwzZA7RWNnFH9CmUme2PU/1E4/srxs0k=
github.com/sagernet/sing-shadowsocks v0.0.0-20220525123814-48809b0a9949 h1:zVl44h3nvP9w8La5BAmFwhuCvWT/Mfx9sVpuv+A/fe4=
github.com/sagernet/sing-shadowsocks v0.0.0-20220525123814-48809b0a9949/go.mod h1:kc9GdaD70dle09qJLrOjkX1fw6rVVGdouV4uzMMNlmc=
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=
Expand Down Expand Up @@ -260,8 +264,8 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2 h1:NWy5+hlRbC7HK+PmcXVUmW1IMyFce7to56IUvhUFm7Y=
golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220524220425-1d687d428aca h1:xTaFYiPROfpPhqrfTIDXj0ri1SpfueYT951s4bAuDO8=
golang.org/x/net v0.0.0-20220524220425-1d687d428aca/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
Expand All @@ -274,8 +278,9 @@ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29 h1:w8s32wxx3sY+OjLlv9qltkLU5yvJzxjjgiHWLjdIcw4=
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181029174526-d69651ed3497/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down
2 changes: 1 addition & 1 deletion infra/conf/shadowsocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"strings"

"github.com/golang/protobuf/proto"
"github.com/sagernet/sing-shadowsocks/shadowaead_2022"
C "github.com/sagernet/sing/common"
"github.com/sagernet/sing/protocol/shadowsocks/shadowaead_2022"
"github.com/xtls/xray-core/common/protocol"
"github.com/xtls/xray-core/common/serial"
"github.com/xtls/xray-core/proxy/shadowsocks"
Expand Down
40 changes: 14 additions & 26 deletions proxy/shadowsocks_2022/config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion proxy/shadowsocks_2022/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,4 @@ message ClientConfig {
uint32 port = 2;
string method = 3;
string key = 4;
bool reduced_iv_head_entropy = 5;
}
15 changes: 3 additions & 12 deletions proxy/shadowsocks_2022/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ package shadowsocks_2022

import (
"context"
"encoding/base64"

"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"
M "github.com/sagernet/sing/common/metadata"
N "github.com/sagernet/sing/common/network"
"github.com/sagernet/sing/common/random"
"github.com/sagernet/sing/protocol/shadowsocks"
"github.com/sagernet/sing/protocol/shadowsocks/shadowaead_2022"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/buf"
"github.com/xtls/xray-core/common/log"
Expand Down Expand Up @@ -51,14 +49,7 @@ func NewServer(ctx context.Context, config *ServerConfig) (*Inbound, error) {
if !C.Contains(shadowaead_2022.List, config.Method) {
return nil, newError("unsupported method ", config.Method)
}
if config.Key == "" {
return nil, newError("missing key")
}
psk, err := base64.StdEncoding.DecodeString(config.Key)
if err != nil {
return nil, newError("parse config").Base(err)
}
service, err := shadowaead_2022.NewService(config.Method, psk, "", random.Default, 500, inbound)
service, err := shadowaead_2022.NewServiceWithPassword(config.Method, config.Key, 500, inbound)
if err != nil {
return nil, newError("create service").Base(err)
}
Expand Down
8 changes: 4 additions & 4 deletions proxy/shadowsocks_2022/inbound_multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import (
"context"
"encoding/base64"

"github.com/sagernet/sing-shadowsocks"
"github.com/sagernet/sing-shadowsocks/shadowaead_2022"
B "github.com/sagernet/sing/common/buf"
"github.com/sagernet/sing/common/bufio"
M "github.com/sagernet/sing/common/metadata"
N "github.com/sagernet/sing/common/network"
"github.com/sagernet/sing/common/random"
"github.com/sagernet/sing/protocol/shadowsocks"
"github.com/sagernet/sing/protocol/shadowsocks/shadowaead_2022"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/buf"
"github.com/xtls/xray-core/common/log"
Expand Down Expand Up @@ -44,6 +43,7 @@ func NewMultiServer(ctx context.Context, config *MultiUserServerConfig) (*MultiU
}
inbound := &MultiUserInbound{
networks: networks,
users: config.Users,
}
if config.Key == "" {
return nil, newError("missing key")
Expand All @@ -52,7 +52,7 @@ func NewMultiServer(ctx context.Context, config *MultiUserServerConfig) (*MultiU
if err != nil {
return nil, newError("parse config").Base(err)
}
service, err := shadowaead_2022.NewMultiService[int](config.Method, psk, random.Default, 500, inbound)
service, err := shadowaead_2022.NewMultiService[int](config.Method, psk, 500, inbound)
if err != nil {
return nil, newError("create service").Base(err)
}
Expand Down
23 changes: 3 additions & 20 deletions proxy/shadowsocks_2022/outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@ package shadowsocks_2022

import (
"context"
"encoding/base64"
"io"
"runtime"
"strings"
"time"

"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"
N "github.com/sagernet/sing/common/network"
"github.com/sagernet/sing/common/random"
"github.com/sagernet/sing/protocol/shadowsocks"
"github.com/sagernet/sing/protocol/shadowsocks/shadowaead_2022"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/buf"
"github.com/xtls/xray-core/common/net"
Expand Down Expand Up @@ -48,21 +45,7 @@ func NewClient(ctx context.Context, config *ClientConfig) (*Outbound, error) {
if config.Key == "" {
return nil, newError("missing psk")
}
var pskList [][]byte
for _, ks := range strings.Split(config.Key, ":") {
psk, err := base64.StdEncoding.DecodeString(ks)
if err != nil {
return nil, newError("decode key ", ks).Base(err)
}
pskList = append(pskList, psk)
}
var rng io.Reader = random.Default
if config.ReducedIvHeadEntropy {
rng = &shadowsocks.ReducedEntropyReader{
Reader: rng,
}
}
method, err := shadowaead_2022.New(config.Method, pskList, "", rng)
method, err := shadowaead_2022.NewWithPassword(config.Method, config.Key)
if err != nil {
return nil, newError("create method").Base(err)
}
Expand Down

0 comments on commit 79f3057

Please sign in to comment.