github.com/v2fly/v2ray-core/v5@v5.16.2-0.20240507031116-8191faa6e095/features/dns/fakedns.go (about)

     1  package dns
     2  
     3  import (
     4  	"github.com/v2fly/v2ray-core/v5/common/net"
     5  	"github.com/v2fly/v2ray-core/v5/features"
     6  )
     7  
     8  // FakeDNSEngine is a V2Ray feature for converting between domain and fake IPs.
     9  //
    10  // v2ray:api:beta
    11  type FakeDNSEngine interface {
    12  	features.Feature
    13  
    14  	// GetFakeIPForDomain returns fake IP addresses for the given domain, and registers the domain with the returned IPs.
    15  	GetFakeIPForDomain(domain string) []net.Address
    16  
    17  	// GetDomainFromFakeDNS returns the bound domain name for the given fake IP.
    18  	GetDomainFromFakeDNS(ip net.Address) string
    19  }
    20  
    21  // FakeDNSEngineRev0 adds additional APIs for FakeDNSEngine.
    22  //
    23  // v2ray:api:beta
    24  type FakeDNSEngineRev0 interface {
    25  	FakeDNSEngine
    26  
    27  	// IsIPInIPPool tests whether the given IP address resides in managed fake IP pools.
    28  	IsIPInIPPool(ip net.Address) bool
    29  
    30  	// GetFakeIPForDomain3 registers and returns fake IP addresses for the given domain in IPv4 and/or IPv6.
    31  	GetFakeIPForDomain3(domain string, IPv4 bool, IPv6 bool) []net.Address
    32  }
    33  
    34  // ClientWithFakeDNS is an optional feature for utilizing FakeDNS feature of DNS client.
    35  //
    36  // v2ray:api:beta
    37  type ClientWithFakeDNS interface {
    38  	// AsFakeDNSClient converts the client to dns.Client that enables FakeDNS querying option.
    39  	AsFakeDNSClient() Client
    40  
    41  	// AsFakeDNSEngine converts the client to dns.FakeDNSEngine that could serve FakeDNSEngine feature.
    42  	AsFakeDNSEngine() FakeDNSEngine
    43  }
    44  
    45  // FakeDNSEngineType returns the type of FakeDNSEngine interface. Can be used for implementing common.HasType.
    46  //
    47  // v2ray:api:beta
    48  func FakeDNSEngineType() interface{} {
    49  	return (*FakeDNSEngine)(nil)
    50  }