2016-10-17 12:35:13 +00:00
|
|
|
package conf
|
|
|
|
|
|
|
|
import (
|
|
|
|
"v2ray.com/core/app/dns"
|
|
|
|
v2net "v2ray.com/core/common/net"
|
|
|
|
)
|
|
|
|
|
|
|
|
type DnsConfig struct {
|
|
|
|
Servers []*Address `json:"servers"`
|
|
|
|
Hosts map[string]*Address `json:"hosts"`
|
|
|
|
}
|
|
|
|
|
2016-11-27 20:39:09 +00:00
|
|
|
func (v *DnsConfig) Build() *dns.Config {
|
2016-10-17 12:35:13 +00:00
|
|
|
config := new(dns.Config)
|
2016-11-27 20:39:09 +00:00
|
|
|
config.NameServers = make([]*v2net.Endpoint, len(v.Servers))
|
|
|
|
for idx, server := range v.Servers {
|
2016-10-17 12:35:13 +00:00
|
|
|
config.NameServers[idx] = &v2net.Endpoint{
|
|
|
|
Network: v2net.Network_UDP,
|
|
|
|
Address: server.Build(),
|
|
|
|
Port: 53,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-27 20:39:09 +00:00
|
|
|
if v.Hosts != nil {
|
2016-10-17 12:35:13 +00:00
|
|
|
config.Hosts = make(map[string]*v2net.IPOrDomain)
|
2016-11-27 20:39:09 +00:00
|
|
|
for domain, ip := range v.Hosts {
|
2016-11-27 16:01:44 +00:00
|
|
|
config.Hosts[domain] = ip.Build()
|
2016-10-17 12:35:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return config
|
|
|
|
}
|