mirror of https://github.com/v2ray/v2ray-core
fix test without -json tag
parent
3fd66ad795
commit
04d956462c
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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", "")
|
||||
)
|
||||
|
|
|
@ -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{})
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
// +build json
|
||||
|
||||
package noop
|
||||
|
||||
import (
|
||||
"v2ray.com/core/transport/internet"
|
||||
)
|
||||
|
||||
func init() {
|
||||
internet.RegisterAuthenticatorConfig("none", func() interface{} { return &NoOpAuthenticatorConfig{} })
|
||||
}
|
|
@ -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{})
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
// +build json
|
||||
|
||||
package srtp
|
||||
|
||||
import (
|
||||
"v2ray.com/core/transport/internet"
|
||||
)
|
||||
|
||||
func init() {
|
||||
internet.RegisterAuthenticatorConfig("srtp", func() interface{} { return &Config{} })
|
||||
}
|
|
@ -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{})
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
// +build json
|
||||
|
||||
package utp
|
||||
|
||||
import (
|
||||
"v2ray.com/core/transport/internet"
|
||||
)
|
||||
|
||||
func init() {
|
||||
internet.RegisterAuthenticatorConfig("srtp", func() interface{} { return &Config{} })
|
||||
}
|
Loading…
Reference in New Issue