1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-12-26 12:05:35 -05:00

massive refactoring for interoperability

This commit is contained in:
Darien Raymond
2018-01-10 12:22:37 +01:00
parent 5a3c7fdd20
commit 292d7cc353
66 changed files with 1515 additions and 1200 deletions

57
dns.go Normal file
View File

@@ -0,0 +1,57 @@
package core
import "net"
import "sync"
// DNSClient is a V2Ray feature for querying DNS information.
type DNSClient interface {
Feature
LookupIP(host string) ([]net.IP, error)
}
type syncDNSClient struct {
sync.RWMutex
DNSClient
}
func (d *syncDNSClient) LookupIP(host string) ([]net.IP, error) {
d.RLock()
defer d.RUnlock()
if d.DNSClient == nil {
return net.LookupIP(host)
}
return d.DNSClient.LookupIP(host)
}
func (d *syncDNSClient) Start() error {
d.RLock()
defer d.RUnlock()
if d.DNSClient == nil {
return nil
}
return d.DNSClient.Start()
}
func (d *syncDNSClient) Close() {
d.RLock()
defer d.RUnlock()
if d.DNSClient != nil {
d.DNSClient.Close()
}
}
func (d *syncDNSClient) Set(client DNSClient) {
if client == nil {
return
}
d.Lock()
defer d.Unlock()
d.DNSClient = client
}