client.go 1.3 KB

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