github.com/v2fly/v2ray-core/v4@v4.45.2/features/dns/client.go (about) 1 package dns 2 3 import ( 4 "github.com/v2fly/v2ray-core/v4/common/errors" 5 "github.com/v2fly/v2ray-core/v4/common/net" 6 "github.com/v2fly/v2ray-core/v4/common/serial" 7 "github.com/v2fly/v2ray-core/v4/features" 8 ) 9 10 // IPOption is an object for IP query options. 11 type IPOption struct { 12 IPv4Enable bool 13 IPv6Enable bool 14 FakeEnable bool 15 } 16 17 // Client is a V2Ray feature for querying DNS information. 18 // 19 // v2ray:api:stable 20 type Client interface { 21 features.Feature 22 23 // LookupIP returns IP address for the given domain. IPs may contain IPv4 and/or IPv6 addresses. 24 LookupIP(domain string) ([]net.IP, error) 25 } 26 27 // IPv4Lookup is an optional feature for querying IPv4 addresses only. 28 // 29 // v2ray:api:beta 30 type IPv4Lookup interface { 31 LookupIPv4(domain string) ([]net.IP, error) 32 } 33 34 // IPv6Lookup is an optional feature for querying IPv6 addresses only. 35 // 36 // v2ray:api:beta 37 type IPv6Lookup interface { 38 LookupIPv6(domain string) ([]net.IP, error) 39 } 40 41 // ClientWithIPOption is an optional feature for querying DNS information. 42 // 43 // v2ray:api:beta 44 type ClientWithIPOption interface { 45 // GetIPOption returns IPOption for the DNS client. 46 GetIPOption() *IPOption 47 48 // SetQueryOption sets IPv4Enable and IPv6Enable for the DNS client. 49 SetQueryOption(isIPv4Enable, isIPv6Enable bool) 50 51 // SetFakeDNSOption sets FakeEnable option for DNS client. 52 SetFakeDNSOption(isFakeEnable bool) 53 } 54 55 // ClientType returns the type of Client interface. Can be used for implementing common.HasType. 56 // 57 // v2ray:api:beta 58 func ClientType() interface{} { 59 return (*Client)(nil) 60 } 61 62 // ErrEmptyResponse indicates that DNS query succeeded but no answer was returned. 63 var ErrEmptyResponse = errors.New("empty response") 64 65 type RCodeError uint16 66 67 func (e RCodeError) Error() string { 68 return serial.Concat("rcode: ", uint16(e)) 69 } 70 71 func RCodeFromError(err error) uint16 { 72 if err == nil { 73 return 0 74 } 75 cause := errors.Cause(err) 76 if r, ok := cause.(RCodeError); ok { 77 return uint16(r) 78 } 79 return 0 80 }