Ver código fonte

json config for domain override

Darien Raymond 8 anos atrás
pai
commit
43dfb8ced3
1 arquivos alterados com 44 adições e 13 exclusões
  1. 44 13
      tools/conf/v2ray.go

+ 44 - 13
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 {