v2ray-core/dns.go

60 lines
855 B
Go
Raw Normal View History

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