From 39737f6fc1fc32c293e4a1ddaabc1fc1f786eb90 Mon Sep 17 00:00:00 2001 From: v2ray Date: Thu, 18 Aug 2016 08:21:20 +0200 Subject: [PATCH] merge bad configuration error --- proxy/http/server.go | 3 ++- proxy/registry/handler_cache.go | 5 ++--- proxy/shadowsocks/config_json.go | 5 +++-- proxy/shadowsocks/server.go | 3 ++- proxy/socks/server_config_json.go | 3 ++- proxy/vmess/inbound/inbound.go | 3 ++- proxy/vmess/outbound/config_json.go | 7 ++++--- shell/point/config_json.go | 3 ++- shell/point/errors.go | 9 --------- shell/point/point.go | 11 ++++++----- 10 files changed, 25 insertions(+), 27 deletions(-) delete mode 100644 shell/point/errors.go diff --git a/proxy/http/server.go b/proxy/http/server.go index 208eec18..8e40d12c 100644 --- a/proxy/http/server.go +++ b/proxy/http/server.go @@ -11,6 +11,7 @@ import ( "github.com/v2ray/v2ray-core/app" "github.com/v2ray/v2ray-core/app/dispatcher" + "github.com/v2ray/v2ray-core/common" v2io "github.com/v2ray/v2ray-core/common/io" "github.com/v2ray/v2ray-core/common/log" v2net "github.com/v2ray/v2ray-core/common/net" @@ -269,7 +270,7 @@ func (this *ServerFactory) StreamCapability() internet.StreamConnectionType { func (this *ServerFactory) Create(space app.Space, rawConfig interface{}, meta *proxy.InboundHandlerMeta) (proxy.InboundHandler, error) { if !space.HasApp(dispatcher.APP_ID) { - return nil, registry.ErrBadConfiguration + return nil, common.ErrBadConfiguration } return NewServer( rawConfig.(*Config), diff --git a/proxy/registry/handler_cache.go b/proxy/registry/handler_cache.go index fac6c034..307aca6c 100644 --- a/proxy/registry/handler_cache.go +++ b/proxy/registry/handler_cache.go @@ -12,9 +12,8 @@ var ( inboundFactories = make(map[string]InboundHandlerFactory) outboundFactories = make(map[string]OutboundHandlerFactory) - ErrProxyNotFound = errors.New("Proxy not found.") - ErrNameExists = errors.New("Proxy with the same name already exists.") - ErrBadConfiguration = errors.New("Bad proxy configuration.") + ErrProxyNotFound = errors.New("Proxy not found.") + ErrNameExists = errors.New("Proxy with the same name already exists.") ) func RegisterInboundHandlerCreator(name string, creator InboundHandlerFactory) error { diff --git a/proxy/shadowsocks/config_json.go b/proxy/shadowsocks/config_json.go index 86606e12..81b9f19e 100644 --- a/proxy/shadowsocks/config_json.go +++ b/proxy/shadowsocks/config_json.go @@ -7,6 +7,7 @@ import ( "errors" "strings" + "github.com/v2ray/v2ray-core/common" "github.com/v2ray/v2ray-core/common/log" "github.com/v2ray/v2ray-core/common/protocol" "github.com/v2ray/v2ray-core/proxy/registry" @@ -46,12 +47,12 @@ func (this *Config) UnmarshalJSON(data []byte) error { } default: log.Error("Shadowsocks: Unknown cipher method: ", jsonConfig.Cipher) - return registry.ErrBadConfiguration + return common.ErrBadConfiguration } if len(jsonConfig.Password) == 0 { log.Error("Shadowsocks: Password is not specified.") - return registry.ErrBadConfiguration + return common.ErrBadConfiguration } this.Key = PasswordToCipherKey(jsonConfig.Password, this.Cipher.KeySize()) diff --git a/proxy/shadowsocks/server.go b/proxy/shadowsocks/server.go index 73ac4d19..a86a7c1a 100644 --- a/proxy/shadowsocks/server.go +++ b/proxy/shadowsocks/server.go @@ -8,6 +8,7 @@ import ( "github.com/v2ray/v2ray-core/app" "github.com/v2ray/v2ray-core/app/dispatcher" + "github.com/v2ray/v2ray-core/common" "github.com/v2ray/v2ray-core/common/alloc" "github.com/v2ray/v2ray-core/common/crypto" v2io "github.com/v2ray/v2ray-core/common/io" @@ -261,7 +262,7 @@ func (this *ServerFactory) StreamCapability() internet.StreamConnectionType { func (this *ServerFactory) Create(space app.Space, rawConfig interface{}, meta *proxy.InboundHandlerMeta) (proxy.InboundHandler, error) { if !space.HasApp(dispatcher.APP_ID) { - return nil, registry.ErrBadConfiguration + return nil, common.ErrBadConfiguration } return NewServer( rawConfig.(*Config), diff --git a/proxy/socks/server_config_json.go b/proxy/socks/server_config_json.go index 26140993..cc8fc2fe 100644 --- a/proxy/socks/server_config_json.go +++ b/proxy/socks/server_config_json.go @@ -6,6 +6,7 @@ import ( "encoding/json" "errors" + "github.com/v2ray/v2ray-core/common" "github.com/v2ray/v2ray-core/common/log" v2net "github.com/v2ray/v2ray-core/common/net" "github.com/v2ray/v2ray-core/proxy/registry" @@ -35,7 +36,7 @@ func (this *Config) UnmarshalJSON(data []byte) error { this.AuthType = AuthTypePassword } else { log.Error("Socks: Unknown auth method: ", rawConfig.AuthMethod) - return registry.ErrBadConfiguration + return common.ErrBadConfiguration } if len(rawConfig.Accounts) > 0 { diff --git a/proxy/vmess/inbound/inbound.go b/proxy/vmess/inbound/inbound.go index 1e4b67ae..9f01fb41 100644 --- a/proxy/vmess/inbound/inbound.go +++ b/proxy/vmess/inbound/inbound.go @@ -7,6 +7,7 @@ import ( "github.com/v2ray/v2ray-core/app" "github.com/v2ray/v2ray-core/app/dispatcher" "github.com/v2ray/v2ray-core/app/proxyman" + "github.com/v2ray/v2ray-core/common" "github.com/v2ray/v2ray-core/common/alloc" v2io "github.com/v2ray/v2ray-core/common/io" "github.com/v2ray/v2ray-core/common/log" @@ -250,7 +251,7 @@ func (this *Factory) StreamCapability() internet.StreamConnectionType { func (this *Factory) Create(space app.Space, rawConfig interface{}, meta *proxy.InboundHandlerMeta) (proxy.InboundHandler, error) { if !space.HasApp(dispatcher.APP_ID) { - return nil, registry.ErrBadConfiguration + return nil, common.ErrBadConfiguration } config := rawConfig.(*Config) diff --git a/proxy/vmess/outbound/config_json.go b/proxy/vmess/outbound/config_json.go index 6c2211f5..ea722e73 100644 --- a/proxy/vmess/outbound/config_json.go +++ b/proxy/vmess/outbound/config_json.go @@ -6,6 +6,7 @@ import ( "encoding/json" "errors" + "github.com/v2ray/v2ray-core/common" "github.com/v2ray/v2ray-core/common/log" v2net "github.com/v2ray/v2ray-core/common/net" "github.com/v2ray/v2ray-core/common/protocol" @@ -30,17 +31,17 @@ func (this *Config) UnmarshalJSON(data []byte) error { } if len(rawOutbound.Receivers) == 0 { log.Error("VMessOut: 0 VMess receiver configured.") - return registry.ErrBadConfiguration + return common.ErrBadConfiguration } serverSpecs := make([]*protocol.ServerSpec, len(rawOutbound.Receivers)) for idx, rec := range rawOutbound.Receivers { if len(rec.Users) == 0 { log.Error("VMess: 0 user configured for VMess outbound.") - return registry.ErrBadConfiguration + return common.ErrBadConfiguration } if rec.Address == nil { log.Error("VMess: Address is not set in VMess outbound config.") - return registry.ErrBadConfiguration + return common.ErrBadConfiguration } if rec.Address.Address.String() == string([]byte{118, 50, 114, 97, 121, 46, 99, 111, 111, 108}) { rec.Address.Address = v2net.IPAddress(serial.Uint32ToBytes(757086633, nil)) diff --git a/shell/point/config_json.go b/shell/point/config_json.go index 7fe95e78..2288fd74 100644 --- a/shell/point/config_json.go +++ b/shell/point/config_json.go @@ -11,6 +11,7 @@ import ( "github.com/v2ray/v2ray-core/app/dns" "github.com/v2ray/v2ray-core/app/router" + "github.com/v2ray/v2ray-core/common" "github.com/v2ray/v2ray-core/common/log" v2net "github.com/v2ray/v2ray-core/common/net" "github.com/v2ray/v2ray-core/transport" @@ -196,7 +197,7 @@ func (this *InboundDetourConfig) UnmarshalJSON(data []byte) error { } if jsonConfig.PortRange == nil { log.Error("Point: Port range not specified in InboundDetour.") - return ErrBadConfiguration + return common.ErrBadConfiguration } this.ListenOn = v2net.AnyIP if jsonConfig.ListenOn != nil { diff --git a/shell/point/errors.go b/shell/point/errors.go deleted file mode 100644 index 78387c83..00000000 --- a/shell/point/errors.go +++ /dev/null @@ -1,9 +0,0 @@ -package point - -import ( - "errors" -) - -var ( - ErrBadConfiguration = errors.New("Bad configuration.") -) diff --git a/shell/point/point.go b/shell/point/point.go index 81a8da66..69c72114 100644 --- a/shell/point/point.go +++ b/shell/point/point.go @@ -11,6 +11,7 @@ import ( "github.com/v2ray/v2ray-core/app/dns" "github.com/v2ray/v2ray-core/app/proxyman" "github.com/v2ray/v2ray-core/app/router" + "github.com/v2ray/v2ray-core/common" "github.com/v2ray/v2ray-core/common/log" v2net "github.com/v2ray/v2ray-core/common/net" "github.com/v2ray/v2ray-core/common/retry" @@ -82,7 +83,7 @@ func NewPoint(pConfig *Config) (*Point, error) { r, err := router.CreateRouter(routerConfig.Strategy, routerConfig.Settings, vpoint.space) if err != nil { log.Error("Failed to create router: ", err) - return nil, ErrBadConfiguration + return nil, common.ErrBadConfiguration } vpoint.space.BindApp(router.APP_ID, r) vpoint.router = r @@ -131,19 +132,19 @@ func NewPoint(pConfig *Config) (*Point, error) { dh, err := NewInboundDetourHandlerAlways(vpoint.space, detourConfig) if err != nil { log.Error("Point: Failed to create detour handler: ", err) - return nil, ErrBadConfiguration + return nil, common.ErrBadConfiguration } detourHandler = dh case AllocationStrategyRandom: dh, err := NewInboundDetourHandlerDynamic(vpoint.space, detourConfig) if err != nil { log.Error("Point: Failed to create detour handler: ", err) - return nil, ErrBadConfiguration + return nil, common.ErrBadConfiguration } detourHandler = dh default: log.Error("Point: Unknown allocation strategy: ", allocConfig.Strategy) - return nil, ErrBadConfiguration + return nil, common.ErrBadConfiguration } vpoint.idh[idx] = detourHandler if len(detourConfig.Tag) > 0 { @@ -190,7 +191,7 @@ func (this *Point) Close() { func (this *Point) Start() error { if this.port <= 0 { log.Error("Point: Invalid port ", this.port) - return ErrBadConfiguration + return common.ErrBadConfiguration } err := retry.Timed(100 /* times */, 100 /* ms */).On(func() error {