fakedns.go 1.6 KB

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