diff --git a/app/point/config/config.go b/app/point/config/config.go index 99dabd21c..bfd598a29 100644 --- a/app/point/config/config.go +++ b/app/point/config/config.go @@ -5,7 +5,7 @@ type RouterConfig interface { Settings() interface{} } -type ConnectionTag string +type DetourTag string type ConnectionConfig interface { Protocol() string @@ -27,6 +27,12 @@ type InboundDetourConfig interface { Settings() interface{} } +type OutboundDetourConfig interface { + Protocol() string + Tag() DetourTag + Settings() interface{} +} + type PointConfig interface { Port() uint16 LogConfig() LogConfig diff --git a/app/point/config/json/json.go b/app/point/config/json/json.go index d7e7533d7..b0fbf02c6 100644 --- a/app/point/config/json/json.go +++ b/app/point/config/json/json.go @@ -12,11 +12,12 @@ import ( // Config is the config for Point server. type Config struct { - PortValue uint16 `json:"port"` // Port of this Point server. - LogConfigValue *LogConfig `json:"log"` - InboundConfigValue *ConnectionConfig `json:"inbound"` - OutboundConfigValue *ConnectionConfig `json:"outbound"` - InboundDetoursValue []*InboundDetourConfig `json:"inboundDetour"` + PortValue uint16 `json:"port"` // Port of this Point server. + LogConfigValue *LogConfig `json:"log"` + InboundConfigValue *ConnectionConfig `json:"inbound"` + OutboundConfigValue *ConnectionConfig `json:"outbound"` + InboundDetoursValue []*InboundDetourConfig `json:"inboundDetour"` + OutboundDetoursValue []*OutboundDetourConfig `json:"outboundDetour"` } func (config *Config) Port() uint16 { @@ -52,6 +53,14 @@ func (this *Config) InboundDetours() []config.InboundDetourConfig { 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) { fixedFile := os.ExpandEnv(file) rawConfig, err := ioutil.ReadFile(fixedFile) diff --git a/app/point/config/json/outbound_detour.go b/app/point/config/json/outbound_detour.go new file mode 100644 index 000000000..8ffc20e9e --- /dev/null +++ b/app/point/config/json/outbound_detour.go @@ -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) +} diff --git a/app/router/router.go b/app/router/router.go index 51bd007f6..c984a809b 100644 --- a/app/router/router.go +++ b/app/router/router.go @@ -12,7 +12,7 @@ var ( ) type Router interface { - TakeDetour(v2net.Packet) (config.ConnectionTag, error) + TakeDetour(v2net.Packet) (config.DetourTag, error) } type RouterFactory interface { diff --git a/app/router/wildcard_router/router.go b/app/router/wildcard_router/router.go index f265c8ca0..bc18f41e3 100644 --- a/app/router/wildcard_router/router.go +++ b/app/router/wildcard_router/router.go @@ -9,7 +9,7 @@ import ( 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 }