diff --git a/conf.go b/conf.go index 342b1e7..aeca9d1 100644 --- a/conf.go +++ b/conf.go @@ -10,6 +10,7 @@ import ( "github.com/nadoo/conflag" + "github.com/nadoo/glider/dns" "github.com/nadoo/glider/strategy" ) @@ -26,12 +27,8 @@ var conf struct { RuleFile []string RulesDir string - DNS string - DNSServers []string - DNSTimeout int - DNSMaxTTL int - DNSMinTTL int - DNSRecords []string + DNS string + DNSConfig dns.Config IPSet string @@ -53,11 +50,11 @@ func confInit() { flag.StringVar(&conf.RulesDir, "rules-dir", "", "rule file folder") flag.StringVar(&conf.DNS, "dns", "", "dns forwarder server listen address") - flag.StringSliceUniqVar(&conf.DNSServers, "dnsserver", []string{"8.8.8.8:53"}, "remote dns server") - flag.IntVar(&conf.DNSTimeout, "dnstimeout", 3, "timeout value used in multiple dnsservers switch(seconds)") - flag.IntVar(&conf.DNSMaxTTL, "dnsmaxttl", 1800, "maximum TTL value for entries in the CACHE(seconds)") - flag.IntVar(&conf.DNSMinTTL, "dnsminttl", 0, "minimum TTL value for entries in the CACHE(seconds)") - flag.StringSliceUniqVar(&conf.DNSRecords, "dnsrecord", nil, "custom dns record, format: domain/ip") + flag.StringSliceUniqVar(&conf.DNSConfig.Servers, "dnsserver", []string{"8.8.8.8:53"}, "remote dns server") + flag.IntVar(&conf.DNSConfig.Timeout, "dnstimeout", 3, "timeout value used in multiple dnsservers switch(seconds)") + flag.IntVar(&conf.DNSConfig.MaxTTL, "dnsmaxttl", 1800, "maximum TTL value for entries in the CACHE(seconds)") + flag.IntVar(&conf.DNSConfig.MinTTL, "dnsminttl", 0, "minimum TTL value for entries in the CACHE(seconds)") + flag.StringSliceUniqVar(&conf.DNSConfig.Records, "dnsrecord", nil, "custom dns record, format: domain/ip") flag.StringVar(&conf.IPSet, "ipset", "", "ipset name") diff --git a/dns/client.go b/dns/client.go index f5ef83d..5b2694a 100644 --- a/dns/client.go +++ b/dns/client.go @@ -206,8 +206,8 @@ func (c *Client) exchangeUDP(rc net.Conn, reqBytes []byte) ([]byte, error) { return reqBytes[:2+n], nil } -// SetServer sets a upstream dns server for the given domain -func (c *Client) SetServer(domain string, servers ...string) { +// SetServers sets upstream dns servers for the given domain +func (c *Client) SetServers(domain string, servers ...string) { c.upServerMap[domain] = append(c.upServerMap[domain], servers...) } diff --git a/main.go b/main.go index 8a10f46..c625b23 100644 --- a/main.go +++ b/main.go @@ -40,14 +40,7 @@ func main() { // DNS Server if conf.DNS != "" { - dnscfg := &dns.Config{ - Servers: conf.DNSServers, - Timeout: conf.DNSTimeout, - MaxTTL: conf.DNSMaxTTL, - MinTTL: conf.DNSMinTTL, - Records: conf.DNSRecords} - - d, err := dns.NewServer(conf.DNS, dialer, dnscfg) + d, err := dns.NewServer(conf.DNS, dialer, &conf.DNSConfig) if err != nil { log.Fatal(err) } @@ -56,7 +49,7 @@ func main() { for _, r := range conf.rules { for _, domain := range r.Domain { if len(r.DNSServers) > 0 { - d.SetServer(domain, r.DNSServers...) + d.SetServers(domain, r.DNSServers...) } } } diff --git a/strategy/strategy.go b/strategy/strategy.go index 8c65c03..1f624d8 100644 --- a/strategy/strategy.go +++ b/strategy/strategy.go @@ -151,7 +151,6 @@ func (rr *rrDialer) checkDialer(idx int) { d := rr.fwdrs[idx] for { - time.Sleep(time.Duration(rr.interval) * time.Second * time.Duration(retry>>1)) // check forwarders whose priority not less than current priority only