Browse Source

fix test without -json tag

Darien Raymond 9 years ago
parent
commit
04d956462c

+ 2 - 12
transport/internet/authenticator.go

@@ -3,7 +3,6 @@ package internet
 import (
 	"v2ray.com/core/common"
 	"v2ray.com/core/common/alloc"
-	"v2ray.com/core/common/loader"
 )
 
 type Authenticator interface {
@@ -21,15 +20,14 @@ type AuthenticatorConfig interface {
 
 var (
 	authenticatorCache = make(map[string]AuthenticatorFactory)
-	configCache        loader.ConfigLoader
 )
 
-func RegisterAuthenticator(name string, factory AuthenticatorFactory, configCreator loader.ConfigCreator) error {
+func RegisterAuthenticator(name string, factory AuthenticatorFactory) error {
 	if _, found := authenticatorCache[name]; found {
 		return common.ErrDuplicatedName
 	}
 	authenticatorCache[name] = factory
-	return configCache.RegisterCreator(name, configCreator)
+	return nil
 }
 
 func CreateAuthenticator(name string, config AuthenticatorConfig) (Authenticator, error) {
@@ -40,14 +38,6 @@ func CreateAuthenticator(name string, config AuthenticatorConfig) (Authenticator
 	return factory.Create(config), nil
 }
 
-func CreateAuthenticatorConfig(rawConfig []byte) (string, AuthenticatorConfig, error) {
-	config, name, err := configCache.Load(rawConfig)
-	if err != nil {
-		return name, nil, err
-	}
-	return name, config, nil
-}
-
 type AuthenticatorChain struct {
 	authenticators []Authenticator
 }

+ 21 - 3
transport/internet/authenticator_json.go

@@ -2,8 +2,26 @@
 
 package internet
 
-import "v2ray.com/core/common/loader"
+import (
+	"v2ray.com/core/common"
+	"v2ray.com/core/common/loader"
+)
 
-func init() {
-	configCache = loader.NewJSONConfigLoader("type", "")
+func RegisterAuthenticatorConfig(name string, configCreator loader.ConfigCreator) error {
+	if _, found := authenticatorCache[name]; found {
+		return common.ErrDuplicatedName
+	}
+	return configCache.RegisterCreator(name, configCreator)
+}
+
+func CreateAuthenticatorConfig(rawConfig []byte) (string, AuthenticatorConfig, error) {
+	config, name, err := configCache.Load(rawConfig)
+	if err != nil {
+		return name, nil, err
+	}
+	return name, config, nil
 }
+
+var (
+	configCache = loader.NewJSONConfigLoader("type", "")
+)

+ 1 - 1
transport/internet/authenticators/noop/noop.go

@@ -24,5 +24,5 @@ func (this NoOpAuthenticatorFactory) Create(config internet.AuthenticatorConfig)
 type NoOpAuthenticatorConfig struct{}
 
 func init() {
-	internet.RegisterAuthenticator("none", NoOpAuthenticatorFactory{}, func() interface{} { return &NoOpAuthenticatorConfig{} })
+	internet.RegisterAuthenticator("none", NoOpAuthenticatorFactory{})
 }

+ 11 - 0
transport/internet/authenticators/noop/noop_json.go

@@ -0,0 +1,11 @@
+// +build json
+
+package noop
+
+import (
+	"v2ray.com/core/transport/internet"
+)
+
+func init() {
+	internet.RegisterAuthenticatorConfig("none", func() interface{} { return &NoOpAuthenticatorConfig{} })
+}

+ 1 - 1
transport/internet/authenticators/srtp/srtp.go

@@ -47,5 +47,5 @@ func (this SRTPFactory) Create(rawSettings internet.AuthenticatorConfig) interne
 }
 
 func init() {
-	internet.RegisterAuthenticator("srtp", SRTPFactory{}, func() interface{} { return new(Config) })
+	internet.RegisterAuthenticator("srtp", SRTPFactory{})
 }

+ 11 - 0
transport/internet/authenticators/srtp/srtp_json.go

@@ -0,0 +1,11 @@
+// +build json
+
+package srtp
+
+import (
+	"v2ray.com/core/transport/internet"
+)
+
+func init() {
+	internet.RegisterAuthenticatorConfig("srtp", func() interface{} { return &Config{} })
+}

+ 1 - 1
transport/internet/authenticators/utp/utp.go

@@ -42,5 +42,5 @@ func (this UTPFactory) Create(rawSettings internet.AuthenticatorConfig) internet
 }
 
 func init() {
-	internet.RegisterAuthenticator("utp", UTPFactory{}, func() interface{} { return new(Config) })
+	internet.RegisterAuthenticator("utp", UTPFactory{})
 }

+ 11 - 0
transport/internet/authenticators/utp/utp_json.go

@@ -0,0 +1,11 @@
+// +build json
+
+package utp
+
+import (
+	"v2ray.com/core/transport/internet"
+)
+
+func init() {
+	internet.RegisterAuthenticatorConfig("srtp", func() interface{} { return &Config{} })
+}