Browse Source

merge bad configuration error

v2ray 9 years ago
parent
commit
39737f6fc1

+ 2 - 1
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),

+ 2 - 3
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 {

+ 3 - 2
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())
 

+ 2 - 1
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),

+ 2 - 1
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 {

+ 2 - 1
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)
 

+ 4 - 3
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))

+ 2 - 1
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 {

+ 0 - 9
shell/point/errors.go

@@ -1,9 +0,0 @@
-package point
-
-import (
-	"errors"
-)
-
-var (
-	ErrBadConfiguration = errors.New("Bad configuration.")
-)

+ 6 - 5
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 {