You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
v2ray-core/app/dns/nameserver.go

57 lines
1.1 KiB

// +build !confonly
7 years ago
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
}
6 years ago
// Client is the interface for DNS client.
type Client interface {
6 years ago
// Name of the Client.
Name() string
6 years ago
// 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(),
}
}