Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions common/protocol/server_spec.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package protocol

import (
"github.com/xtls/xray-core/common/errors"
"github.com/xtls/xray-core/common/net"
)

Expand All @@ -17,6 +18,9 @@ func NewServerSpec(dest net.Destination, user *MemoryUser) *ServerSpec {
}

func NewServerSpecFromPB(spec *ServerEndpoint) (*ServerSpec, error) {
if spec == nil || spec.Address == nil {
return nil, errors.New("server address is not set")
}
dest := net.TCPDestination(spec.Address.AsAddress(), net.Port(spec.Port))
var dUser *MemoryUser
if spec.User != nil {
Expand Down
6 changes: 6 additions & 0 deletions infra/conf/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ type Address struct {

// MarshalJSON implements encoding/json.Marshaler.MarshalJSON
func (v *Address) MarshalJSON() ([]byte, error) {
if v.Address == nil {
return json.Marshal(net.AnyIP.String())
}
return json.Marshal(v.Address.String())
}

Expand All @@ -68,6 +71,9 @@ func (v *Address) Build() *net.IPOrDomain {
if v == nil {
return nil
}
if v.Address == nil {
return net.NewIPOrDomain(net.AnyIP)
}
return net.NewIPOrDomain(v.Address)
}

Expand Down
2 changes: 1 addition & 1 deletion infra/conf/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (c *HTTPServerConfig) Build() (proto.Message, error) {
}

type HTTPClientConfig struct {
Address *Address `json:"address"`
Address Address `json:"address"`
Port uint16 `json:"port"`
Level uint32 `json:"level"`
Email string `json:"email"`
Expand Down
6 changes: 3 additions & 3 deletions infra/conf/hysteria.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
)

type HysteriaClientConfig struct {
Version int32 `json:"version"`
Address *Address `json:"address"`
Port uint16 `json:"port"`
Version int32 `json:"version"`
Address Address `json:"address"`
Port uint16 `json:"port"`
}

func (c *HysteriaClientConfig) Build() (proto.Message, error) {
Expand Down
5 changes: 1 addition & 4 deletions infra/conf/masque.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,12 @@ import (
)

type MasqueClientConfig struct {
Address *Address `json:"address"`
Address Address `json:"address"`
Port uint16 `json:"port"`
RemoteDNS []string `json:"remoteDNS"`
}

func (c *MasqueClientConfig) Build() (proto.Message, error) {
if c.Address == nil {
return nil, errors.New(`MASQUE: "address" is not set`)
}
if c.Port == 0 {
return nil, errors.New(`MASQUE: "port" is not set`)
}
Expand Down
15 changes: 6 additions & 9 deletions infra/conf/shadowsocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,20 +178,17 @@ func buildShadowsocks2022(v *ShadowsocksServerConfig) (proto.Message, error) {
}

type ShadowsocksClientConfig struct {
Address *Address `json:"address"`
Port uint16 `json:"port"`
Level byte `json:"level"`
Email string `json:"email"`
Cipher string `json:"method"`
Password string `json:"password"`
Address Address `json:"address"`
Port uint16 `json:"port"`
Level byte `json:"level"`
Email string `json:"email"`
Cipher string `json:"method"`
Password string `json:"password"`
}

func (v *ShadowsocksClientConfig) Build() (proto.Message, error) {
errors.PrintNonRemovalDeprecatedFeatureWarning("Shadowsocks (with no Forward Secrecy, etc.)", "VLESS Encryption")

if v.Address == nil {
return nil, errors.New("Shadowsocks server address is not set.")
}
if v.Port == 0 {
return nil, errors.New("Invalid Shadowsocks port.")
}
Expand Down
12 changes: 6 additions & 6 deletions infra/conf/socks.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ func (v *SocksServerConfig) Build() (proto.Message, error) {
}

type SocksClientConfig struct {
Address *Address `json:"address"`
Port uint16 `json:"port"`
Level uint32 `json:"level"`
Email string `json:"email"`
Username string `json:"user"`
Password string `json:"pass"`
Address Address `json:"address"`
Port uint16 `json:"port"`
Level uint32 `json:"level"`
Email string `json:"email"`
Username string `json:"user"`
Password string `json:"pass"`
}

func (v *SocksClientConfig) Build() (proto.Message, error) {
Expand Down
3 changes: 3 additions & 0 deletions infra/conf/transport_finalmask.go
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,9 @@ func (c *XDNS) Build() (proto.Message, error) {
return nil, err
}
quicConfig = proto.(*internet.QuicParams)
if quicConfig.Congestion == "brutal" {
return nil, errors.New(`XDNS: "brutal" is for Hysteria, use "force-brutal", "bbr" or "reno"`)
}
}
for j := range c.Resolvers[i].Addrs {
var u *url.URL
Expand Down
3 changes: 3 additions & 0 deletions infra/conf/transport_internet.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ func (c *StreamConfig) Build() (*internet.StreamConfig, error) {
return nil, errors.New(`XDRIVE: brutal is for Hysteria servers, over h3 "congestion" is "bbr" or "reno", not "`, config.QuicParams.Congestion, `"`)
}
}
if config.ProtocolName == "splithttp" && config.QuicParams != nil && config.QuicParams.Congestion == "brutal" {
return nil, errors.New(`XHTTP: "brutal" is for Hysteria, use "force-brutal", "bbr" or "reno"`)
}

return config, nil
}
3 changes: 3 additions & 0 deletions infra/conf/transport_method.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,9 @@ func (c *SplitHTTPConfig) Build() (proto.Message, error) {
if c.ServerMaxHeaderBytes < 0 {
return nil, errors.New("invalid negative value of maxHeaderBytes")
}
if c.ScMaxEachPostBytes.From < 0 || c.ScMaxEachPostBytes.To < 0 || (c.ScMaxEachPostBytes.To > 0 && c.ScMaxEachPostBytes.From <= 0) {
return nil, errors.New("`scMaxEachPostBytes` must be greater than 0")
}

if c.Xmux.MaxConnections.To > 0 && c.Xmux.MaxConcurrency.To > 0 {
return nil, errors.New("maxConnections cannot be specified together with maxConcurrency")
Expand Down
13 changes: 5 additions & 8 deletions infra/conf/trojan.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import (

// TrojanClientConfig is configuration of trojan servers
type TrojanClientConfig struct {
Address *Address `json:"address"`
Port uint16 `json:"port"`
Level byte `json:"level"`
Email string `json:"email"`
Password string `json:"password"`
Address Address `json:"address"`
Port uint16 `json:"port"`
Level byte `json:"level"`
Email string `json:"email"`
Password string `json:"password"`
}

// Build implements Buildable
Expand All @@ -32,9 +32,6 @@ func (c *TrojanClientConfig) Build() (proto.Message, error) {

config := &trojan.ClientConfig{}

if c.Address == nil {
return nil, errors.New("Trojan server address is not set.")
}
if c.Port == 0 {
return nil, errors.New("Invalid Trojan port.")
}
Expand Down
Loading
Loading