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.

42 lines
971 B

4 years ago
package dns
import (
"context"
4 years ago
"github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/features/dns"
4 years ago
"github.com/xtls/xray-core/features/dns/localdns"
4 years ago
)
// 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 dns.IPOption) ([]net.IP, error)
4 years ago
}
type LocalNameServer struct {
client *localdns.Client
}
func (s *LocalNameServer) QueryIP(_ context.Context, domain string, option dns.IPOption) ([]net.IP, error) {
if option.IPv4Enable || option.IPv6Enable {
return s.client.LookupIP(domain, option)
4 years ago
}
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(),
}
}