Browse Source

Add shadowsocks 2022 relay config

pull/1180/head
yuhan6665 2 years ago
parent
commit
b67314796f
  1. 91
      infra/conf/shadowsocks.go

91
infra/conf/shadowsocks.go

@ -36,6 +36,8 @@ type ShadowsocksUserConfig struct {
Password string `json:"password"`
Level byte `json:"level"`
Email string `json:"email"`
Address *Address `json:"address"`
Port uint16 `json:"port"`
}
type ShadowsocksServerConfig struct {
@ -50,38 +52,7 @@ type ShadowsocksServerConfig struct {
func (v *ShadowsocksServerConfig) Build() (proto.Message, error) {
if C.Contains(shadowaead_2022.List, v.Cipher) {
if len(v.Users) > 0 {
if v.Cipher == "" {
return nil, newError("shadowsocks 2022 (multi-user): missing server method")
}
if !strings.Contains(v.Cipher, "aes") {
return nil, newError("shadowsocks 2022 (multi-user): only blake3-aes-*-gcm methods are supported")
}
config := new(shadowsocks_2022.MultiUserServerConfig)
config.Method = v.Cipher
config.Key = v.Password
config.Network = v.NetworkList.Build()
for _, user := range v.Users {
if user.Cipher != "" {
return nil, newError("shadowsocks 2022 (multi-user): users must have empty method")
}
config.Users = append(config.Users, &shadowsocks_2022.User{
Key: user.Password,
Email: user.Email,
})
}
return config, nil
}
config := new(shadowsocks_2022.ServerConfig)
config.Method = v.Cipher
config.Key = v.Password
config.Network = v.NetworkList.Build()
config.Email = v.Email
return config, nil
return buildShadowsocks2022(v)
}
config := new(shadowsocks.ServerConfig)
@ -129,6 +100,62 @@ func (v *ShadowsocksServerConfig) Build() (proto.Message, error) {
return config, nil
}
func buildShadowsocks2022(v *ShadowsocksServerConfig) (proto.Message, error) {
if len(v.Users) == 0 {
config := new(shadowsocks_2022.ServerConfig)
config.Method = v.Cipher
config.Key = v.Password
config.Network = v.NetworkList.Build()
config.Email = v.Email
return config, nil
}
if v.Cipher == "" {
return nil, newError("shadowsocks 2022 (multi-user): missing server method")
}
if !strings.Contains(v.Cipher, "aes") {
return nil, newError("shadowsocks 2022 (multi-user): only blake3-aes-*-gcm methods are supported")
}
if v.Users[0].Address == nil {
config := new(shadowsocks_2022.MultiUserServerConfig)
config.Method = v.Cipher
config.Key = v.Password
config.Network = v.NetworkList.Build()
for _, user := range v.Users {
if user.Cipher != "" {
return nil, newError("shadowsocks 2022 (multi-user): users must have empty method")
}
config.Users = append(config.Users, &shadowsocks_2022.User{
Key: user.Password,
Email: user.Email,
})
}
return config, nil
}
config := new(shadowsocks_2022.RelayServerConfig)
config.Method = v.Cipher
config.Key = v.Password
config.Network = v.NetworkList.Build()
for _, user := range v.Users {
if user.Cipher != "" {
return nil, newError("shadowsocks 2022 (relay): users must have empty method")
}
if user.Address == nil {
return nil, newError("shadowsocks 2022 (relay): all users must have relay address")
}
config.Destinations = append(config.Destinations, &shadowsocks_2022.RelayDestination{
Key: user.Password,
Email: user.Email,
Address: user.Address.Build(),
Port: uint32(user.Port),
})
}
return config, nil
}
type ShadowsocksServerTarget struct {
Address *Address `json:"address"`
Port uint16 `json:"port"`

Loading…
Cancel
Save