mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-05-09 13:48:41 +00:00
Refine DNS strategies
This commit is contained in:
parent
f4a048aa0c
commit
726a722019
21 changed files with 255 additions and 208 deletions
|
@ -124,6 +124,7 @@ type DNSConfig struct {
|
|||
ClientIP *Address `json:"clientIp"`
|
||||
Tag string `json:"tag"`
|
||||
QueryStrategy string `json:"queryStrategy"`
|
||||
CacheStrategy string `json:"cacheStrategy"`
|
||||
DisableCache bool `json:"disableCache"`
|
||||
}
|
||||
|
||||
|
@ -142,8 +143,12 @@ func getHostMapping(addr *Address) *dns.Config_HostMapping {
|
|||
// Build implements Buildable
|
||||
func (c *DNSConfig) Build() (*dns.Config, error) {
|
||||
config := &dns.Config{
|
||||
Tag: c.Tag,
|
||||
DisableCache: c.DisableCache,
|
||||
Tag: c.Tag,
|
||||
CacheStrategy: dns.CacheStrategy_Cache_ALL,
|
||||
}
|
||||
|
||||
if c.DisableCache {
|
||||
config.CacheStrategy = dns.CacheStrategy_Cache_DISABLE
|
||||
}
|
||||
|
||||
if c.ClientIP != nil {
|
||||
|
@ -163,6 +168,15 @@ func (c *DNSConfig) Build() (*dns.Config, error) {
|
|||
config.QueryStrategy = dns.QueryStrategy_USE_IP6
|
||||
}
|
||||
|
||||
switch strings.ToLower(c.CacheStrategy) {
|
||||
case "noerror":
|
||||
config.CacheStrategy = dns.CacheStrategy_Cache_NOERROR
|
||||
case "all":
|
||||
config.CacheStrategy = dns.CacheStrategy_Cache_ALL
|
||||
case "disable", "none":
|
||||
config.CacheStrategy = dns.CacheStrategy_Cache_DISABLE
|
||||
}
|
||||
|
||||
for _, server := range c.Servers {
|
||||
ns, err := server.Build()
|
||||
if err != nil {
|
||||
|
|
|
@ -139,7 +139,7 @@ func TestDNSConfigParsing(t *testing.T) {
|
|||
},
|
||||
ClientIp: []byte{10, 0, 0, 1},
|
||||
QueryStrategy: dns.QueryStrategy_USE_IP4,
|
||||
DisableCache: true,
|
||||
CacheStrategy: dns.CacheStrategy_Cache_DISABLE,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue