github.com/EagleQL/Xray-core@v1.4.3/app/dns/nameserver.go (about) 1 package dns 2 3 import ( 4 "context" 5 6 "github.com/xtls/xray-core/common/net" 7 "github.com/xtls/xray-core/features/dns" 8 "github.com/xtls/xray-core/features/dns/localdns" 9 ) 10 11 // Client is the interface for DNS client. 12 type Client interface { 13 // Name of the Client. 14 Name() string 15 16 // QueryIP sends IP queries to its configured server. 17 QueryIP(ctx context.Context, domain string, option dns.IPOption) ([]net.IP, error) 18 } 19 20 type LocalNameServer struct { 21 client *localdns.Client 22 } 23 24 func (s *LocalNameServer) QueryIP(_ context.Context, domain string, option dns.IPOption) ([]net.IP, error) { 25 if option.IPv4Enable || option.IPv6Enable { 26 return s.client.LookupIP(domain, option) 27 } 28 29 return nil, newError("neither IPv4 nor IPv6 is enabled") 30 } 31 32 func (s *LocalNameServer) Name() string { 33 return "localhost" 34 } 35 36 func NewLocalNameServer() *LocalNameServer { 37 newError("DNS: created localhost client").AtInfo().WriteToLog() 38 return &LocalNameServer{ 39 client: localdns.New(), 40 } 41 }