1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-30 07:46:41 -04:00
v2fly/dns.go

60 lines
855 B
Go
Raw Normal View History

package core
2018-02-08 09:39:46 -05:00
import (
"sync"
"v2ray.com/core/common"
2018-10-11 17:09:15 -04:00
"v2ray.com/core/common/net"
2018-10-11 16:34:31 -04:00
"v2ray.com/core/features/dns"
2018-02-08 09:39:46 -05:00
)
type syncDNSClient struct {
sync.RWMutex
2018-10-11 16:34:31 -04:00
dns.Client
}
2018-10-12 17:57:56 -04: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 16:34:31 -04:00
if d.Client == nil {
return net.LookupIP(host)
}
2018-10-11 16:34:31 -04:00
return d.Client.LookupIP(host)
}
func (d *syncDNSClient) Start() error {
d.RLock()
defer d.RUnlock()
2018-10-11 16:34:31 -04:00
if d.Client == nil {
return nil
}
2018-10-11 16:34:31 -04:00
return d.Client.Start()
}
2018-02-08 09:39:46 -05:00
func (d *syncDNSClient) Close() error {
d.RLock()
defer d.RUnlock()
2018-10-11 16:34:31 -04:00
return common.Close(d.Client)
}
2018-10-11 16:34:31 -04:00
func (d *syncDNSClient) Set(client dns.Client) {
if client == nil {
return
}
d.Lock()
defer d.Unlock()
2018-10-11 16:34:31 -04:00
common.Close(d.Client) // nolint: errcheck
d.Client = client
}