mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-30 05:56:54 -05:00
Remove config type in connection settings()
This commit is contained in:
parent
fdb41bbd50
commit
6e8425b23a
@ -27,7 +27,7 @@ func NewPoint(pConfig config.PointConfig) (*Point, error) {
|
|||||||
log.Error("Unknown inbound connection handler factory %s", pConfig.InboundConfig().Protocol())
|
log.Error("Unknown inbound connection handler factory %s", pConfig.InboundConfig().Protocol())
|
||||||
return nil, config.BadConfiguration
|
return nil, config.BadConfiguration
|
||||||
}
|
}
|
||||||
ichConfig := pConfig.InboundConfig().Settings(config.TypeInbound)
|
ichConfig := pConfig.InboundConfig().Settings()
|
||||||
ich, err := ichFactory.Create(vpoint, ichConfig)
|
ich, err := ichFactory.Create(vpoint, ichConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Failed to create inbound connection handler: %v", err)
|
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())
|
log.Error("Unknown outbound connection handler factory %s", pConfig.OutboundConfig().Protocol())
|
||||||
return nil, config.BadConfiguration
|
return nil, config.BadConfiguration
|
||||||
}
|
}
|
||||||
ochConfig := pConfig.OutboundConfig().Settings(config.TypeOutbound)
|
ochConfig := pConfig.OutboundConfig().Settings()
|
||||||
och, err := ochFactory.Create(ochConfig)
|
och, err := ochFactory.Create(ochConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Failed to create outbound connection handler: %v", err)
|
log.Error("Failed to create outbound connection handler: %v", err)
|
||||||
|
@ -16,7 +16,7 @@ type ConnectionTag string
|
|||||||
|
|
||||||
type ConnectionConfig interface {
|
type ConnectionConfig interface {
|
||||||
Protocol() string
|
Protocol() string
|
||||||
Settings(configType Type) interface{}
|
Settings() interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
type LogConfig interface {
|
type LogConfig interface {
|
||||||
|
@ -12,14 +12,15 @@ import (
|
|||||||
type ConnectionConfig struct {
|
type ConnectionConfig struct {
|
||||||
ProtocolString string `json:"protocol"`
|
ProtocolString string `json:"protocol"`
|
||||||
SettingsMessage json.RawMessage `json:"settings"`
|
SettingsMessage json.RawMessage `json:"settings"`
|
||||||
|
Type config.Type `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config *ConnectionConfig) Protocol() string {
|
func (config *ConnectionConfig) Protocol() string {
|
||||||
return config.ProtocolString
|
return config.ProtocolString
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config *ConnectionConfig) Settings(configType config.Type) interface{} {
|
func (config *ConnectionConfig) Settings() interface{} {
|
||||||
creator, found := configCache[getConfigKey(config.Protocol(), configType)]
|
creator, found := configCache[getConfigKey(config.Protocol(), config.Type)]
|
||||||
if !found {
|
if !found {
|
||||||
panic("Unknown protocol " + config.Protocol())
|
panic("Unknown protocol " + config.Protocol())
|
||||||
}
|
}
|
||||||
@ -88,5 +89,8 @@ func LoadConfig(file string) (*Config, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jsonConfig.InboundConfigValue.Type = config.TypeInbound
|
||||||
|
jsonConfig.OutboundConfigValue.Type = config.TypeOutbound
|
||||||
|
|
||||||
return jsonConfig, err
|
return jsonConfig, err
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/v2ray/v2ray-core/config"
|
|
||||||
"github.com/v2ray/v2ray-core/config/json"
|
"github.com/v2ray/v2ray-core/config/json"
|
||||||
_ "github.com/v2ray/v2ray-core/proxy/freedom/config/json"
|
_ "github.com/v2ray/v2ray-core/proxy/freedom/config/json"
|
||||||
_ "github.com/v2ray/v2ray-core/proxy/socks/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.Pointer(pointConfig.OutboundConfig()).IsNotNil()
|
||||||
|
|
||||||
assert.String(pointConfig.InboundConfig().Protocol()).Equals("socks")
|
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.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) {
|
func TestServerSampleConfig(t *testing.T) {
|
||||||
@ -47,8 +46,8 @@ func TestServerSampleConfig(t *testing.T) {
|
|||||||
assert.Pointer(pointConfig.OutboundConfig()).IsNotNil()
|
assert.Pointer(pointConfig.OutboundConfig()).IsNotNil()
|
||||||
|
|
||||||
assert.String(pointConfig.InboundConfig().Protocol()).Equals("vmess")
|
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.String(pointConfig.OutboundConfig().Protocol()).Equals("freedom")
|
||||||
assert.Pointer(pointConfig.OutboundConfig().Settings(config.TypeOutbound)).IsNotNil()
|
assert.Pointer(pointConfig.OutboundConfig().Settings()).IsNotNil()
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ func (config *ConnectionConfig) Protocol() string {
|
|||||||
return config.ProtocolValue
|
return config.ProtocolValue
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config *ConnectionConfig) Settings(config.Type) interface{} {
|
func (config *ConnectionConfig) Settings() interface{} {
|
||||||
return config.SettingsValue
|
return config.SettingsValue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user