1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-01-03 07:56:42 -05:00

Outbound detour config

This commit is contained in:
V2Ray 2015-11-13 23:43:58 +01:00
parent 8597642002
commit 1d4b98ab9a
5 changed files with 49 additions and 8 deletions

View File

@ -5,7 +5,7 @@ type RouterConfig interface {
Settings() interface{} Settings() interface{}
} }
type ConnectionTag string type DetourTag string
type ConnectionConfig interface { type ConnectionConfig interface {
Protocol() string Protocol() string
@ -27,6 +27,12 @@ type InboundDetourConfig interface {
Settings() interface{} Settings() interface{}
} }
type OutboundDetourConfig interface {
Protocol() string
Tag() DetourTag
Settings() interface{}
}
type PointConfig interface { type PointConfig interface {
Port() uint16 Port() uint16
LogConfig() LogConfig LogConfig() LogConfig

View File

@ -17,6 +17,7 @@ type Config struct {
InboundConfigValue *ConnectionConfig `json:"inbound"` InboundConfigValue *ConnectionConfig `json:"inbound"`
OutboundConfigValue *ConnectionConfig `json:"outbound"` OutboundConfigValue *ConnectionConfig `json:"outbound"`
InboundDetoursValue []*InboundDetourConfig `json:"inboundDetour"` InboundDetoursValue []*InboundDetourConfig `json:"inboundDetour"`
OutboundDetoursValue []*OutboundDetourConfig `json:"outboundDetour"`
} }
func (config *Config) Port() uint16 { func (config *Config) Port() uint16 {
@ -52,6 +53,14 @@ func (this *Config) InboundDetours() []config.InboundDetourConfig {
return detours return detours
} }
func (this *Config) OutboundDetours() []config.OutboundDetourConfig {
detours := make([]config.OutboundDetourConfig, len(this.OutboundDetoursValue))
for idx, detour := range this.OutboundDetoursValue {
detours[idx] = detour
}
return detours
}
func LoadConfig(file string) (*Config, error) { func LoadConfig(file string) (*Config, error) {
fixedFile := os.ExpandEnv(file) fixedFile := os.ExpandEnv(file)
rawConfig, err := ioutil.ReadFile(fixedFile) rawConfig, err := ioutil.ReadFile(fixedFile)

View File

@ -0,0 +1,26 @@
package json
import (
"encoding/json"
"github.com/v2ray/v2ray-core/app/point/config"
proxyconfig "github.com/v2ray/v2ray-core/proxy/common/config"
)
type OutboundDetourConfig struct {
ProtocolValue string `json:"protocol"`
TagValue string `json:"tag"`
SettingsValue json.RawMessage `json:"settings"`
}
func (this *OutboundDetourConfig) Protocol() string {
return this.ProtocolValue
}
func (this *OutboundDetourConfig) Tag() config.DetourTag {
return config.DetourTag(this.TagValue)
}
func (this *OutboundDetourConfig) Settings() interface{} {
return loadConnectionConfig(this.SettingsValue, this.ProtocolValue, proxyconfig.TypeOutbound)
}

View File

@ -12,7 +12,7 @@ var (
) )
type Router interface { type Router interface {
TakeDetour(v2net.Packet) (config.ConnectionTag, error) TakeDetour(v2net.Packet) (config.DetourTag, error)
} }
type RouterFactory interface { type RouterFactory interface {

View File

@ -9,7 +9,7 @@ import (
type WildcardRouter struct { type WildcardRouter struct {
} }
func (router *WildcardRouter) TakeDetour(packet v2net.Packet) (config.ConnectionTag, error) { func (router *WildcardRouter) TakeDetour(packet v2net.Packet) (config.DetourTag, error) {
return "", nil return "", nil
} }