From 04d956462c9ddcd8cf4f7a9b1b169c20c2383dc9 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Thu, 25 Aug 2016 13:25:59 +0200 Subject: [PATCH] fix test without -json tag --- transport/internet/authenticator.go | 14 ++--------- transport/internet/authenticator_json.go | 24 ++++++++++++++++--- .../internet/authenticators/noop/noop.go | 2 +- .../internet/authenticators/noop/noop_json.go | 11 +++++++++ .../internet/authenticators/srtp/srtp.go | 2 +- .../internet/authenticators/srtp/srtp_json.go | 11 +++++++++ transport/internet/authenticators/utp/utp.go | 2 +- .../internet/authenticators/utp/utp_json.go | 11 +++++++++ 8 files changed, 59 insertions(+), 18 deletions(-) create mode 100644 transport/internet/authenticators/noop/noop_json.go create mode 100644 transport/internet/authenticators/srtp/srtp_json.go create mode 100644 transport/internet/authenticators/utp/utp_json.go diff --git a/transport/internet/authenticator.go b/transport/internet/authenticator.go index 41af2c367..61079af90 100644 --- a/transport/internet/authenticator.go +++ b/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 } diff --git a/transport/internet/authenticator_json.go b/transport/internet/authenticator_json.go index 450cdc59f..6c093da1b 100644 --- a/transport/internet/authenticator_json.go +++ b/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", "") +) diff --git a/transport/internet/authenticators/noop/noop.go b/transport/internet/authenticators/noop/noop.go index 2ea99b28b..48b0ad357 100644 --- a/transport/internet/authenticators/noop/noop.go +++ b/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{}) } diff --git a/transport/internet/authenticators/noop/noop_json.go b/transport/internet/authenticators/noop/noop_json.go new file mode 100644 index 000000000..f87f0cef1 --- /dev/null +++ b/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{} }) +} diff --git a/transport/internet/authenticators/srtp/srtp.go b/transport/internet/authenticators/srtp/srtp.go index 84045325c..68258c641 100644 --- a/transport/internet/authenticators/srtp/srtp.go +++ b/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{}) } diff --git a/transport/internet/authenticators/srtp/srtp_json.go b/transport/internet/authenticators/srtp/srtp_json.go new file mode 100644 index 000000000..25bad13d9 --- /dev/null +++ b/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{} }) +} diff --git a/transport/internet/authenticators/utp/utp.go b/transport/internet/authenticators/utp/utp.go index 79deb2ac9..3a31acee1 100644 --- a/transport/internet/authenticators/utp/utp.go +++ b/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{}) } diff --git a/transport/internet/authenticators/utp/utp_json.go b/transport/internet/authenticators/utp/utp_json.go new file mode 100644 index 000000000..f5b29f3f3 --- /dev/null +++ b/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{} }) +}