Feature: add custom DNS support (#56)

This commit is contained in:
Dreamacro
2018-12-05 21:13:29 +08:00
committed by GitHub
parent da5db36ccf
commit 03c249ecb1
23 changed files with 939 additions and 124 deletions

View File

@ -4,6 +4,7 @@ import (
adapters "github.com/Dreamacro/clash/adapters/outbound"
"github.com/Dreamacro/clash/config"
C "github.com/Dreamacro/clash/constant"
"github.com/Dreamacro/clash/dns"
"github.com/Dreamacro/clash/log"
P "github.com/Dreamacro/clash/proxy"
T "github.com/Dreamacro/clash/tunnel"
@ -26,6 +27,8 @@ func ApplyConfig(cfg *config.Config, force bool) {
}
updateProxies(cfg.Proxies)
updateRules(cfg.Rules)
updateGeneral(cfg.General)
updateDNS(cfg.DNS)
}
func GetGeneral() *config.General {
@ -40,6 +43,22 @@ func GetGeneral() *config.General {
}
}
func updateDNS(c *config.DNS) {
if c.Enable == false {
T.Instance().SetResolver(nil)
dns.ReCreateServer("", nil)
return
}
r := dns.New(dns.Config{
Main: c.NameServer,
Fallback: c.Fallback,
IPv6: c.IPv6,
EnhancedMode: c.EnhancedMode,
})
T.Instance().SetResolver(r)
dns.ReCreateServer(c.Listen, r)
}
func updateProxies(proxies map[string]C.Proxy) {
tunnel := T.Instance()
oldProxies := tunnel.Proxies()