1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-05-26 14:09:06 -04:00

Move proxy/common/config to proxy/internal/config

This commit is contained in:
v2ray
2016-01-02 17:40:51 +01:00
parent dc86eb76da
commit 1c4c9bffad
29 changed files with 225 additions and 221 deletions

View File

@@ -9,7 +9,7 @@ import (
type ConnectionConfig interface {
Protocol() string
Settings() interface{}
Settings() []byte
}
type LogConfig interface {
@@ -40,13 +40,13 @@ type InboundDetourConfig interface {
PortRange() v2net.PortRange
Tag() string
Allocation() InboundDetourAllocationConfig
Settings() interface{}
Settings() []byte
}
type OutboundDetourConfig interface {
Protocol() string
Tag() string
Settings() interface{}
Settings() []byte
}
type PointConfig interface {

View File

@@ -2,35 +2,17 @@ package json
import (
"encoding/json"
"github.com/v2ray/v2ray-core/common/log"
proxyconfig "github.com/v2ray/v2ray-core/proxy/common/config"
proxyjson "github.com/v2ray/v2ray-core/proxy/common/config/json"
)
type ConnectionConfig struct {
ProtocolString string `json:"protocol"`
SettingsMessage json.RawMessage `json:"settings"`
Type proxyconfig.Type `json:"-"`
ProtocolString string `json:"protocol"`
SettingsMessage json.RawMessage `json:"settings"`
}
func (c *ConnectionConfig) Protocol() string {
return c.ProtocolString
}
func (c *ConnectionConfig) Settings() interface{} {
return loadConnectionConfig(c.SettingsMessage, c.Protocol(), c.Type)
}
func loadConnectionConfig(message json.RawMessage, protocol string, cType proxyconfig.Type) interface{} {
configObj := proxyjson.CreateConfig(protocol, cType)
if configObj == nil {
panic("Unknown protocol " + protocol)
}
err := json.Unmarshal(message, configObj)
if err != nil {
log.Error("Unable to parse connection config: %v", err)
panic("Failed to parse connection config.")
}
return configObj
func (c *ConnectionConfig) Settings() []byte {
return []byte(c.SettingsMessage)
}

View File

@@ -5,7 +5,6 @@ import (
v2net "github.com/v2ray/v2ray-core/common/net"
v2netjson "github.com/v2ray/v2ray-core/common/net/json"
proxyconfig "github.com/v2ray/v2ray-core/proxy/common/config"
"github.com/v2ray/v2ray-core/shell/point"
)
@@ -47,8 +46,8 @@ func (this *InboundDetourConfig) PortRange() v2net.PortRange {
return this.PortRangeValue
}
func (this *InboundDetourConfig) Settings() interface{} {
return loadConnectionConfig(this.SettingsValue, this.ProtocolValue, proxyconfig.TypeInbound)
func (this *InboundDetourConfig) Settings() []byte {
return []byte(this.SettingsValue)
}
func (this *InboundDetourConfig) Tag() string {

View File

@@ -9,7 +9,6 @@ import (
routerjson "github.com/v2ray/v2ray-core/app/router/json"
"github.com/v2ray/v2ray-core/common/log"
v2net "github.com/v2ray/v2ray-core/common/net"
proxyconfig "github.com/v2ray/v2ray-core/proxy/common/config"
"github.com/v2ray/v2ray-core/shell/point"
)
@@ -87,8 +86,5 @@ func LoadConfig(file string) (*Config, error) {
return nil, err
}
jsonConfig.InboundConfigValue.Type = proxyconfig.TypeInbound
jsonConfig.OutboundConfigValue.Type = proxyconfig.TypeOutbound
return jsonConfig, err
}

View File

@@ -2,8 +2,6 @@ package json
import (
"encoding/json"
proxyconfig "github.com/v2ray/v2ray-core/proxy/common/config"
)
type OutboundDetourConfig struct {
@@ -20,6 +18,6 @@ func (this *OutboundDetourConfig) Tag() string {
return this.TagValue
}
func (this *OutboundDetourConfig) Settings() interface{} {
return loadConnectionConfig(this.SettingsValue, this.ProtocolValue, proxyconfig.TypeOutbound)
func (this *OutboundDetourConfig) Settings() []byte {
return []byte(this.SettingsValue)
}

View File

@@ -10,14 +10,14 @@ import (
type ConnectionConfig struct {
ProtocolValue string
SettingsValue interface{}
SettingsValue []byte
}
func (config *ConnectionConfig) Protocol() string {
return config.ProtocolValue
}
func (config *ConnectionConfig) Settings() interface{} {
func (config *ConnectionConfig) Settings() []byte {
return config.SettingsValue
}