1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-27 22:36:12 -04:00

Remove config type in connection settings()

This commit is contained in:
V2Ray 2015-10-29 23:35:54 +01:00
parent fdb41bbd50
commit 6e8425b23a
5 changed files with 14 additions and 11 deletions

View File

@ -27,7 +27,7 @@ func NewPoint(pConfig config.PointConfig) (*Point, error) {
log.Error("Unknown inbound connection handler factory %s", pConfig.InboundConfig().Protocol())
return nil, config.BadConfiguration
}
ichConfig := pConfig.InboundConfig().Settings(config.TypeInbound)
ichConfig := pConfig.InboundConfig().Settings()
ich, err := ichFactory.Create(vpoint, ichConfig)
if err != nil {
log.Error("Failed to create inbound connection handler: %v", err)
@ -40,7 +40,7 @@ func NewPoint(pConfig config.PointConfig) (*Point, error) {
log.Error("Unknown outbound connection handler factory %s", pConfig.OutboundConfig().Protocol())
return nil, config.BadConfiguration
}
ochConfig := pConfig.OutboundConfig().Settings(config.TypeOutbound)
ochConfig := pConfig.OutboundConfig().Settings()
och, err := ochFactory.Create(ochConfig)
if err != nil {
log.Error("Failed to create outbound connection handler: %v", err)

View File

@ -16,7 +16,7 @@ type ConnectionTag string
type ConnectionConfig interface {
Protocol() string
Settings(configType Type) interface{}
Settings() interface{}
}
type LogConfig interface {

View File

@ -12,14 +12,15 @@ import (
type ConnectionConfig struct {
ProtocolString string `json:"protocol"`
SettingsMessage json.RawMessage `json:"settings"`
Type config.Type `json:"-"`
}
func (config *ConnectionConfig) Protocol() string {
return config.ProtocolString
}
func (config *ConnectionConfig) Settings(configType config.Type) interface{} {
creator, found := configCache[getConfigKey(config.Protocol(), configType)]
func (config *ConnectionConfig) Settings() interface{} {
creator, found := configCache[getConfigKey(config.Protocol(), config.Type)]
if !found {
panic("Unknown protocol " + config.Protocol())
}
@ -88,5 +89,8 @@ func LoadConfig(file string) (*Config, error) {
return nil, err
}
jsonConfig.InboundConfigValue.Type = config.TypeInbound
jsonConfig.OutboundConfigValue.Type = config.TypeOutbound
return jsonConfig, err
}

View File

@ -4,7 +4,6 @@ import (
"path/filepath"
"testing"
"github.com/v2ray/v2ray-core/config"
"github.com/v2ray/v2ray-core/config/json"
_ "github.com/v2ray/v2ray-core/proxy/freedom/config/json"
_ "github.com/v2ray/v2ray-core/proxy/socks/config/json"
@ -27,10 +26,10 @@ func TestClientSampleConfig(t *testing.T) {
assert.Pointer(pointConfig.OutboundConfig()).IsNotNil()
assert.String(pointConfig.InboundConfig().Protocol()).Equals("socks")
assert.Pointer(pointConfig.InboundConfig().Settings(config.TypeInbound)).IsNotNil()
assert.Pointer(pointConfig.InboundConfig().Settings()).IsNotNil()
assert.String(pointConfig.OutboundConfig().Protocol()).Equals("vmess")
assert.Pointer(pointConfig.OutboundConfig().Settings(config.TypeOutbound)).IsNotNil()
assert.Pointer(pointConfig.OutboundConfig().Settings()).IsNotNil()
}
func TestServerSampleConfig(t *testing.T) {
@ -47,8 +46,8 @@ func TestServerSampleConfig(t *testing.T) {
assert.Pointer(pointConfig.OutboundConfig()).IsNotNil()
assert.String(pointConfig.InboundConfig().Protocol()).Equals("vmess")
assert.Pointer(pointConfig.InboundConfig().Settings(config.TypeInbound)).IsNotNil()
assert.Pointer(pointConfig.InboundConfig().Settings()).IsNotNil()
assert.String(pointConfig.OutboundConfig().Protocol()).Equals("freedom")
assert.Pointer(pointConfig.OutboundConfig().Settings(config.TypeOutbound)).IsNotNil()
assert.Pointer(pointConfig.OutboundConfig().Settings()).IsNotNil()
}

View File

@ -13,7 +13,7 @@ func (config *ConnectionConfig) Protocol() string {
return config.ProtocolValue
}
func (config *ConnectionConfig) Settings(config.Type) interface{} {
func (config *ConnectionConfig) Settings() interface{} {
return config.SettingsValue
}