mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-12-25 06:59:48 +00:00
Add shadowsocks 2022 relay config
This commit is contained in:
parent
340234166b
commit
b67314796f
@ -32,10 +32,12 @@ func cipherFromString(c string) shadowsocks.CipherType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ShadowsocksUserConfig struct {
|
type ShadowsocksUserConfig struct {
|
||||||
Cipher string `json:"method"`
|
Cipher string `json:"method"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
Level byte `json:"level"`
|
Level byte `json:"level"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
|
Address *Address `json:"address"`
|
||||||
|
Port uint16 `json:"port"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ShadowsocksServerConfig struct {
|
type ShadowsocksServerConfig struct {
|
||||||
@ -50,38 +52,7 @@ type ShadowsocksServerConfig struct {
|
|||||||
|
|
||||||
func (v *ShadowsocksServerConfig) Build() (proto.Message, error) {
|
func (v *ShadowsocksServerConfig) Build() (proto.Message, error) {
|
||||||
if C.Contains(shadowaead_2022.List, v.Cipher) {
|
if C.Contains(shadowaead_2022.List, v.Cipher) {
|
||||||
if len(v.Users) > 0 {
|
return buildShadowsocks2022(v)
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
config := new(shadowsocks.ServerConfig)
|
config := new(shadowsocks.ServerConfig)
|
||||||
@ -129,6 +100,62 @@ func (v *ShadowsocksServerConfig) Build() (proto.Message, error) {
|
|||||||
return config, nil
|
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 {
|
type ShadowsocksServerTarget struct {
|
||||||
Address *Address `json:"address"`
|
Address *Address `json:"address"`
|
||||||
Port uint16 `json:"port"`
|
Port uint16 `json:"port"`
|
||||||
|
Loading…
Reference in New Issue
Block a user