You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
"v2ray.com/core/common"
|
|
|
|
"v2ray.com/core/features/dns"
|
|
|
|
)
|
|
|
|
|
|
|
|
type syncDNSClient struct {
|
|
|
|
sync.RWMutex
|
|
|
|
dns.Client
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|