forked from v2ray/v2ray-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdns.go
59 lines (44 loc) · 855 Bytes
/
dns.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package core
import (
"sync"
"v2ray.com/core/common"
"v2ray.com/core/common/net"
"v2ray.com/core/features/dns"
)
type syncDNSClient struct {
sync.RWMutex
dns.Client
}
func (d *syncDNSClient) Type() interface{} {
return dns.ClientType()
}
func (d *syncDNSClient) LookupIP(host string) ([]net.IP, error) {
d.RLock()
defer d.RUnlock()
if d.Client == nil {
return net.LookupIP(host)
}
return d.Client.LookupIP(host)
}
func (d *syncDNSClient) Start() error {
d.RLock()
defer d.RUnlock()
if d.Client == nil {
return nil
}
return d.Client.Start()
}
func (d *syncDNSClient) Close() error {
d.RLock()
defer d.RUnlock()
return common.Close(d.Client)
}
func (d *syncDNSClient) Set(client dns.Client) {
if client == nil {
return
}
d.Lock()
defer d.Unlock()
common.Close(d.Client) // nolint: errcheck
d.Client = client
}