v2ray-core/dns.go

60 lines
855 B
Go
Raw Normal View History

package core
2018-02-08 14:39:46 +00:00
import (
"sync"
"v2ray.com/core/common"
2018-10-11 21:09:15 +00:00
"v2ray.com/core/common/net"
2018-10-11 20:34:31 +00:00
"v2ray.com/core/features/dns"
2018-02-08 14:39:46 +00:00
)
type syncDNSClient struct {
sync.RWMutex
2018-10-11 20:34:31 +00:00
dns.Client
}
2018-10-12 21:57:56 +00:00
func (d *syncDNSClient) Type() interface{} {
return dns.ClientType()
}
func (d *syncDNSClient) LookupIP(host string) ([]net.IP, error) {
d.RLock()
defer d.RUnlock()
2018-10-11 20:34:31 +00:00
if d.Client == nil {
return net.LookupIP(host)
}
2018-10-11 20:34:31 +00:00
return d.Client.LookupIP(host)
}
func (d *syncDNSClient) Start() error {
d.RLock()
defer d.RUnlock()
2018-10-11 20:34:31 +00:00
if d.Client == nil {
return nil
}
2018-10-11 20:34:31 +00:00
return d.Client.Start()
}
2018-02-08 14:39:46 +00:00
func (d *syncDNSClient) Close() error {
d.RLock()
defer d.RUnlock()
2018-10-11 20:34:31 +00:00
return common.Close(d.Client)
}
2018-10-11 20:34:31 +00:00
func (d *syncDNSClient) Set(client dns.Client) {
if client == nil {
return
}
d.Lock()
defer d.Unlock()
2018-10-11 20:34:31 +00:00
common.Close(d.Client) // nolint: errcheck
d.Client = client
}