mirror of
https://github.com/nadoo/glider.git
synced 2025-02-23 01:15:41 +08:00
conf: use dns.Config instead of multiple variables
This commit is contained in:
parent
e0c07146dc
commit
3a8af82f87
19
conf.go
19
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")
|
||||
|
||||
|
@ -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...)
|
||||
}
|
||||
|
||||
|
11
main.go
11
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...)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user