github.com/Uhtred009/v2ray-core-1@v4.31.2+incompatible/features/dns/client.go (about) 1 package dns 2 3 import ( 4 "v2ray.com/core/common/errors" 5 "v2ray.com/core/common/net" 6 "v2ray.com/core/common/serial" 7 "v2ray.com/core/features" 8 ) 9 10 // Client is a V2Ray feature for querying DNS information. 11 // 12 // v2ray:api:stable 13 type Client interface { 14 features.Feature 15 16 // LookupIP returns IP address for the given domain. IPs may contain IPv4 and/or IPv6 addresses. 17 LookupIP(domain string) ([]net.IP, error) 18 } 19 20 // IPv4Lookup is an optional feature for querying IPv4 addresses only. 21 // 22 // v2ray:api:beta 23 type IPv4Lookup interface { 24 LookupIPv4(domain string) ([]net.IP, error) 25 } 26 27 // IPv6Lookup is an optional feature for querying IPv6 addresses only. 28 // 29 // v2ray:api:beta 30 type IPv6Lookup interface { 31 LookupIPv6(domain string) ([]net.IP, error) 32 } 33 34 // ClientType returns the type of Client interface. Can be used for implementing common.HasType. 35 // 36 // v2ray:api:beta 37 func ClientType() interface{} { 38 return (*Client)(nil) 39 } 40 41 // ErrEmptyResponse indicates that DNS query succeeded but no answer was returned. 42 var ErrEmptyResponse = errors.New("empty response") 43 44 type RCodeError uint16 45 46 func (e RCodeError) Error() string { 47 return serial.Concat("rcode: ", uint16(e)) 48 } 49 50 func RCodeFromError(err error) uint16 { 51 if err == nil { 52 return 0 53 } 54 cause := errors.Cause(err) 55 if r, ok := cause.(RCodeError); ok { 56 return uint16(r) 57 } 58 return 0 59 }