github.com/eagleql/xray-core@v1.4.4/features/dns/client.go (about)

     1  package dns
     2  
     3  import (
     4  	"github.com/eagleql/xray-core/common/errors"
     5  	"github.com/eagleql/xray-core/common/net"
     6  	"github.com/eagleql/xray-core/common/serial"
     7  	"github.com/eagleql/xray-core/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 Xray feature for querying DNS information.
    18  //
    19  // xray: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, option IPOption) ([]net.IP, error)
    25  }
    26  
    27  // ClientType returns the type of Client interface. Can be used for implementing common.HasType.
    28  //
    29  // xray:api:beta
    30  func ClientType() interface{} {
    31  	return (*Client)(nil)
    32  }
    33  
    34  // ErrEmptyResponse indicates that DNS query succeeded but no answer was returned.
    35  var ErrEmptyResponse = errors.New("empty response")
    36  
    37  type RCodeError uint16
    38  
    39  func (e RCodeError) Error() string {
    40  	return serial.Concat("rcode: ", uint16(e))
    41  }
    42  
    43  func RCodeFromError(err error) uint16 {
    44  	if err == nil {
    45  		return 0
    46  	}
    47  	cause := errors.Cause(err)
    48  	if r, ok := cause.(RCodeError); ok {
    49  		return uint16(r)
    50  	}
    51  	return 0
    52  }