mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-05 14:43:03 +00:00
f50eff5ebb
Co-authored-by: Xiaokang Wang <xiaokangwang@outlook.com> Co-authored-by: loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com> Co-authored-by: kslr <kslrwang@gmail.com>
42 lines
971 B
Go
42 lines
971 B
Go
package dns
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/xtls/xray-core/common/net"
|
|
"github.com/xtls/xray-core/features/dns"
|
|
"github.com/xtls/xray-core/features/dns/localdns"
|
|
)
|
|
|
|
// 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)
|
|
}
|
|
|
|
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)
|
|
}
|
|
|
|
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(),
|
|
}
|
|
}
|