fix test without -json tag

pull/255/head
Darien Raymond 2016-08-25 13:25:59 +02:00
parent 3fd66ad795
commit 04d956462c
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
8 changed files with 59 additions and 18 deletions

View File

@ -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
}

View File

@ -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", "")
)

View File

@ -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{})
}

View File

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

View File

@ -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{})
}

View File

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

View File

@ -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{})
}

View File

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