mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-25 10:01:28 +00:00
Merge shadowsocks 2022 config
This commit is contained in:
parent
22706041d1
commit
3b77e26fa7
|
@ -4,9 +4,12 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
|
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/protocol"
|
||||||
"github.com/xtls/xray-core/common/serial"
|
"github.com/xtls/xray-core/common/serial"
|
||||||
"github.com/xtls/xray-core/proxy/shadowsocks"
|
"github.com/xtls/xray-core/proxy/shadowsocks"
|
||||||
|
"github.com/xtls/xray-core/proxy/shadowsocks_2022"
|
||||||
)
|
)
|
||||||
|
|
||||||
func cipherFromString(c string) shadowsocks.CipherType {
|
func cipherFromString(c string) shadowsocks.CipherType {
|
||||||
|
@ -44,6 +47,17 @@ 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) {
|
||||||
|
config := new(shadowsocks_2022.ServerConfig)
|
||||||
|
config.Method = v.Cipher
|
||||||
|
config.Key = v.Password
|
||||||
|
config.Network = v.NetworkList.Build()
|
||||||
|
if len(v.Users) == 0 {
|
||||||
|
return nil, newError("shadowsocks 2022 ciphers accept no users.")
|
||||||
|
}
|
||||||
|
return config, nil
|
||||||
|
}
|
||||||
|
|
||||||
config := new(shadowsocks.ServerConfig)
|
config := new(shadowsocks.ServerConfig)
|
||||||
config.Network = v.NetworkList.Build()
|
config.Network = v.NetworkList.Build()
|
||||||
|
|
||||||
|
@ -104,14 +118,38 @@ type ShadowsocksClientConfig struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *ShadowsocksClientConfig) Build() (proto.Message, error) {
|
func (v *ShadowsocksClientConfig) Build() (proto.Message, error) {
|
||||||
config := new(shadowsocks.ClientConfig)
|
|
||||||
|
|
||||||
if len(v.Servers) == 0 {
|
if len(v.Servers) == 0 {
|
||||||
return nil, newError("0 Shadowsocks server configured.")
|
return nil, newError("0 Shadowsocks server configured.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(v.Servers) == 1 {
|
||||||
|
server := v.Servers[0]
|
||||||
|
if C.Contains(shadowaead_2022.List, server.Cipher) {
|
||||||
|
if server.Address == nil {
|
||||||
|
return nil, newError("Shadowsocks server address is not set.")
|
||||||
|
}
|
||||||
|
if server.Port == 0 {
|
||||||
|
return nil, newError("Invalid Shadowsocks port.")
|
||||||
|
}
|
||||||
|
if server.Password == "" {
|
||||||
|
return nil, newError("Shadowsocks password is not specified.")
|
||||||
|
}
|
||||||
|
|
||||||
|
config := new(shadowsocks_2022.ClientConfig)
|
||||||
|
config.Address = server.Address.Build()
|
||||||
|
config.Port = uint32(server.Port)
|
||||||
|
config.Method = server.Cipher
|
||||||
|
config.Key = server.Password
|
||||||
|
return config, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
config := new(shadowsocks.ClientConfig)
|
||||||
serverSpecs := make([]*protocol.ServerEndpoint, len(v.Servers))
|
serverSpecs := make([]*protocol.ServerEndpoint, len(v.Servers))
|
||||||
for idx, server := range v.Servers {
|
for idx, server := range v.Servers {
|
||||||
|
if C.Contains(shadowaead_2022.List, server.Cipher) {
|
||||||
|
return nil, newError("Shadowsocks 2022 accept no multi servers")
|
||||||
|
}
|
||||||
if server.Address == nil {
|
if server.Address == nil {
|
||||||
return nil, newError("Shadowsocks server address is not set.")
|
return nil, newError("Shadowsocks server address is not set.")
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,46 +0,0 @@
|
||||||
package conf
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/golang/protobuf/proto"
|
|
||||||
"github.com/xtls/xray-core/common/net"
|
|
||||||
"github.com/xtls/xray-core/proxy/shadowsocks_2022"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Shadowsocks2022ServerConfig struct {
|
|
||||||
Cipher string `json:"method"`
|
|
||||||
Key string `json:"key"`
|
|
||||||
NetworkList *NetworkList `json:"network"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *Shadowsocks2022ServerConfig) Build() (proto.Message, error) {
|
|
||||||
var network []net.Network
|
|
||||||
if v.NetworkList != nil {
|
|
||||||
network = v.NetworkList.Build()
|
|
||||||
}
|
|
||||||
return &shadowsocks_2022.ServerConfig{
|
|
||||||
Method: v.Cipher,
|
|
||||||
Key: v.Key,
|
|
||||||
Network: network,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type Shadowsocks2022ClientConfig struct {
|
|
||||||
Address *Address `json:"address"`
|
|
||||||
Port uint16 `json:"port"`
|
|
||||||
Cipher string `json:"method"`
|
|
||||||
Key string `json:"key"`
|
|
||||||
ReducedIvHeadEntropy bool `json:"reducedIvHeadEntropy"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *Shadowsocks2022ClientConfig) Build() (proto.Message, error) {
|
|
||||||
if v.Address == nil {
|
|
||||||
return nil, newError("shadowsocks 2022: missing server address")
|
|
||||||
}
|
|
||||||
return &shadowsocks_2022.ClientConfig{
|
|
||||||
Address: v.Address.Build(),
|
|
||||||
Port: uint32(v.Port),
|
|
||||||
Method: v.Cipher,
|
|
||||||
Key: v.Key,
|
|
||||||
ReducedIvHeadEntropy: v.ReducedIvHeadEntropy,
|
|
||||||
}, nil
|
|
||||||
}
|
|
|
@ -18,30 +18,28 @@ import (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
inboundConfigLoader = NewJSONConfigLoader(ConfigCreatorCache{
|
inboundConfigLoader = NewJSONConfigLoader(ConfigCreatorCache{
|
||||||
"dokodemo-door": func() interface{} { return new(DokodemoConfig) },
|
"dokodemo-door": func() interface{} { return new(DokodemoConfig) },
|
||||||
"http": func() interface{} { return new(HTTPServerConfig) },
|
"http": func() interface{} { return new(HTTPServerConfig) },
|
||||||
"shadowsocks": func() interface{} { return new(ShadowsocksServerConfig) },
|
"shadowsocks": func() interface{} { return new(ShadowsocksServerConfig) },
|
||||||
"socks": func() interface{} { return new(SocksServerConfig) },
|
"socks": func() interface{} { return new(SocksServerConfig) },
|
||||||
"vless": func() interface{} { return new(VLessInboundConfig) },
|
"vless": func() interface{} { return new(VLessInboundConfig) },
|
||||||
"vmess": func() interface{} { return new(VMessInboundConfig) },
|
"vmess": func() interface{} { return new(VMessInboundConfig) },
|
||||||
"trojan": func() interface{} { return new(TrojanServerConfig) },
|
"trojan": func() interface{} { return new(TrojanServerConfig) },
|
||||||
"mtproto": func() interface{} { return new(MTProtoServerConfig) },
|
"mtproto": func() interface{} { return new(MTProtoServerConfig) },
|
||||||
"shadowsocks-2022": func() interface{} { return new(Shadowsocks2022ServerConfig) },
|
|
||||||
}, "protocol", "settings")
|
}, "protocol", "settings")
|
||||||
|
|
||||||
outboundConfigLoader = NewJSONConfigLoader(ConfigCreatorCache{
|
outboundConfigLoader = NewJSONConfigLoader(ConfigCreatorCache{
|
||||||
"blackhole": func() interface{} { return new(BlackholeConfig) },
|
"blackhole": func() interface{} { return new(BlackholeConfig) },
|
||||||
"loopback": func() interface{} { return new(LoopbackConfig) },
|
"loopback": func() interface{} { return new(LoopbackConfig) },
|
||||||
"freedom": func() interface{} { return new(FreedomConfig) },
|
"freedom": func() interface{} { return new(FreedomConfig) },
|
||||||
"http": func() interface{} { return new(HTTPClientConfig) },
|
"http": func() interface{} { return new(HTTPClientConfig) },
|
||||||
"shadowsocks": func() interface{} { return new(ShadowsocksClientConfig) },
|
"shadowsocks": func() interface{} { return new(ShadowsocksClientConfig) },
|
||||||
"socks": func() interface{} { return new(SocksClientConfig) },
|
"socks": func() interface{} { return new(SocksClientConfig) },
|
||||||
"vless": func() interface{} { return new(VLessOutboundConfig) },
|
"vless": func() interface{} { return new(VLessOutboundConfig) },
|
||||||
"vmess": func() interface{} { return new(VMessOutboundConfig) },
|
"vmess": func() interface{} { return new(VMessOutboundConfig) },
|
||||||
"trojan": func() interface{} { return new(TrojanClientConfig) },
|
"trojan": func() interface{} { return new(TrojanClientConfig) },
|
||||||
"mtproto": func() interface{} { return new(MTProtoClientConfig) },
|
"mtproto": func() interface{} { return new(MTProtoClientConfig) },
|
||||||
"dns": func() interface{} { return new(DNSOutboundConfig) },
|
"dns": func() interface{} { return new(DNSOutboundConfig) },
|
||||||
"shadowsocks-2022": func() interface{} { return new(Shadowsocks2022ClientConfig) },
|
|
||||||
}, "protocol", "settings")
|
}, "protocol", "settings")
|
||||||
|
|
||||||
ctllog = log.New(os.Stderr, "xctl> ", 0)
|
ctllog = log.New(os.Stderr, "xctl> ", 0)
|
||||||
|
|
Loading…
Reference in a new issue