1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-18 02:16:10 -05:00
v2fly/app/dns/nameserver.go
vcptr ceb77ac8f5 only add to ipIndexMap if GeoIP is configured
clearer logging for expectIPs

refactor dns init code

optimal to default port logic

clear message exit if doh met error
2019-11-26 13:05:19 +08:00

57 lines
1.1 KiB
Go

// +build !confonly
package dns
import (
"context"
"v2ray.com/core/common/net"
"v2ray.com/core/features/dns/localdns"
)
// IPOption is an object for IP query options.
type IPOption struct {
IPv4Enable bool
IPv6Enable bool
}
// Client is the interface for DNS client.
type Client interface {
// Name of the Client.
Name() string
// QueryIP sends IP queries to its configured server.
QueryIP(ctx context.Context, domain string, option IPOption) ([]net.IP, error)
}
type localNameServer struct {
client *localdns.Client
}
func (s *localNameServer) QueryIP(ctx context.Context, domain string, option IPOption) ([]net.IP, error) {
if option.IPv4Enable && option.IPv6Enable {
return s.client.LookupIP(domain)
}
if option.IPv4Enable {
return s.client.LookupIPv4(domain)
}
if option.IPv6Enable {
return s.client.LookupIPv6(domain)
}
return nil, newError("neither IPv4 nor IPv6 is enabled")
}
func (s *localNameServer) Name() string {
return "localhost"
}
func NewLocalNameServer() *localNameServer {
newError("DNS: created localhost client").AtInfo().WriteToLog()
return &localNameServer{
client: localdns.New(),
}
}