dns.go 760 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package core
  2. import (
  3. "net"
  4. "sync"
  5. "v2ray.com/core/common"
  6. "v2ray.com/core/features/dns"
  7. )
  8. type syncDNSClient struct {
  9. sync.RWMutex
  10. dns.Client
  11. }
  12. func (d *syncDNSClient) LookupIP(host string) ([]net.IP, error) {
  13. d.RLock()
  14. defer d.RUnlock()
  15. if d.Client == nil {
  16. return net.LookupIP(host)
  17. }
  18. return d.Client.LookupIP(host)
  19. }
  20. func (d *syncDNSClient) Start() error {
  21. d.RLock()
  22. defer d.RUnlock()
  23. if d.Client == nil {
  24. return nil
  25. }
  26. return d.Client.Start()
  27. }
  28. func (d *syncDNSClient) Close() error {
  29. d.RLock()
  30. defer d.RUnlock()
  31. return common.Close(d.Client)
  32. }
  33. func (d *syncDNSClient) Set(client dns.Client) {
  34. if client == nil {
  35. return
  36. }
  37. d.Lock()
  38. defer d.Unlock()
  39. common.Close(d.Client) // nolint: errcheck
  40. d.Client = client
  41. }