Xray-core/infra/conf/dns_proxy.go

37 lines
870 B
Go
Raw Normal View History

2020-11-25 13:01:53 +02:00
package conf
import (
2021-05-03 16:45:21 +03:00
"strings"
2020-11-25 13:01:53 +02:00
"github.com/golang/protobuf/proto"
2020-12-04 03:36:16 +02:00
"github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/proxy/dns"
2020-11-25 13:01:53 +02:00
)
type DNSOutboundConfig struct {
2021-05-03 16:45:21 +03:00
Network Network `json:"network"`
Address *Address `json:"address"`
Port uint16 `json:"port"`
DomainStrategy string `json:"domainStrategy"`
2020-11-25 13:01:53 +02:00
}
func (c *DNSOutboundConfig) Build() (proto.Message, error) {
config := &dns.Config{
Server: &net.Endpoint{
Network: c.Network.Build(),
Port: uint32(c.Port),
},
}
if c.Address != nil {
config.Server.Address = c.Address.Build()
}
2021-05-03 16:45:21 +03:00
config.DomainStrategy = dns.Config_USE_ALL
switch strings.ToLower(c.DomainStrategy) {
case "useip", "use_ip", "use-ip":
config.DomainStrategy = dns.Config_USE_IP
case "fake", "fakedns":
config.DomainStrategy = dns.Config_USE_FAKE
}
2020-11-25 13:01:53 +02:00
return config, nil
}