From 43dfb8ced340d559fd9f870d04d2083fdf43f554 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Tue, 25 Apr 2017 11:18:13 +0200 Subject: [PATCH] json config for domain override --- tools/conf/v2ray.go | 57 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 13 deletions(-) diff --git a/tools/conf/v2ray.go b/tools/conf/v2ray.go index 6318fad60..e9f3a9162 100644 --- a/tools/conf/v2ray.go +++ b/tools/conf/v2ray.go @@ -30,13 +30,29 @@ var ( }, "protocol", "settings") ) +func toProtocolList(s []string) ([]proxyman.KnownProtocols, error) { + kp := make([]proxyman.KnownProtocols, 0, 8) + for _, p := range s { + switch strings.ToLower(p) { + case "http": + kp = append(kp, proxyman.KnownProtocols_HTTP) + case "https", "tls", "ssl": + kp = append(kp, proxyman.KnownProtocols_TLS) + default: + return nil, newError("Unknown protocol: ", p) + } + } + return kp, nil +} + type InboundConnectionConfig struct { - Port uint16 `json:"port"` - Listen *Address `json:"listen"` - Protocol string `json:"protocol"` - StreamSetting *StreamConfig `json:"streamSettings"` - Settings json.RawMessage `json:"settings"` - Tag string `json:"tag"` + Port uint16 `json:"port"` + Listen *Address `json:"listen"` + Protocol string `json:"protocol"` + StreamSetting *StreamConfig `json:"streamSettings"` + Settings json.RawMessage `json:"settings"` + Tag string `json:"tag"` + DomainOverride *StringList `json:"domainOverride"` } func (v *InboundConnectionConfig) Build() (*proxyman.InboundHandlerConfig, error) { @@ -59,6 +75,13 @@ func (v *InboundConnectionConfig) Build() (*proxyman.InboundHandlerConfig, error } receiverConfig.StreamSettings = ts } + if v.DomainOverride != nil { + kp, err := toProtocolList(*v.DomainOverride) + if err != nil { + return nil, newError("failed to parse inbound config").Base(err) + } + receiverConfig.DomainOverride = kp + } jsonConfig, err := inboundConfigLoader.LoadWithID(v.Settings, v.Protocol) if err != nil { @@ -183,13 +206,14 @@ func (v *InboundDetourAllocationConfig) Build() (*proxyman.AllocationStrategy, e } type InboundDetourConfig struct { - Protocol string `json:"protocol"` - PortRange *PortRange `json:"port"` - ListenOn *Address `json:"listen"` - Settings json.RawMessage `json:"settings"` - Tag string `json:"tag"` - Allocation *InboundDetourAllocationConfig `json:"allocate"` - StreamSetting *StreamConfig `json:"streamSettings"` + Protocol string `json:"protocol"` + PortRange *PortRange `json:"port"` + ListenOn *Address `json:"listen"` + Settings json.RawMessage `json:"settings"` + Tag string `json:"tag"` + Allocation *InboundDetourAllocationConfig `json:"allocate"` + StreamSetting *StreamConfig `json:"streamSettings"` + DomainOverride *StringList `json:"domainOverride"` } func (v *InboundDetourConfig) Build() (*proxyman.InboundHandlerConfig, error) { @@ -220,6 +244,13 @@ func (v *InboundDetourConfig) Build() (*proxyman.InboundHandlerConfig, error) { } receiverSettings.StreamSettings = ss } + if v.DomainOverride != nil { + kp, err := toProtocolList(*v.DomainOverride) + if err != nil { + return nil, newError("failed to parse inbound detour config").Base(err) + } + receiverSettings.DomainOverride = kp + } rawConfig, err := inboundConfigLoader.LoadWithID(v.Settings, v.Protocol) if err != nil {