mirror of
https://github.com/nadoo/glider.git
synced 2025-02-23 09:25: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/conflag"
|
||||||
|
|
||||||
|
"github.com/nadoo/glider/dns"
|
||||||
"github.com/nadoo/glider/strategy"
|
"github.com/nadoo/glider/strategy"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -26,12 +27,8 @@ var conf struct {
|
|||||||
RuleFile []string
|
RuleFile []string
|
||||||
RulesDir string
|
RulesDir string
|
||||||
|
|
||||||
DNS string
|
DNS string
|
||||||
DNSServers []string
|
DNSConfig dns.Config
|
||||||
DNSTimeout int
|
|
||||||
DNSMaxTTL int
|
|
||||||
DNSMinTTL int
|
|
||||||
DNSRecords []string
|
|
||||||
|
|
||||||
IPSet string
|
IPSet string
|
||||||
|
|
||||||
@ -53,11 +50,11 @@ func confInit() {
|
|||||||
flag.StringVar(&conf.RulesDir, "rules-dir", "", "rule file folder")
|
flag.StringVar(&conf.RulesDir, "rules-dir", "", "rule file folder")
|
||||||
|
|
||||||
flag.StringVar(&conf.DNS, "dns", "", "dns forwarder server listen address")
|
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.StringSliceUniqVar(&conf.DNSConfig.Servers, "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.DNSConfig.Timeout, "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.DNSConfig.MaxTTL, "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.IntVar(&conf.DNSConfig.MinTTL, "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.Records, "dnsrecord", nil, "custom dns record, format: domain/ip")
|
||||||
|
|
||||||
flag.StringVar(&conf.IPSet, "ipset", "", "ipset name")
|
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
|
return reqBytes[:2+n], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetServer sets a upstream dns server for the given domain
|
// SetServers sets upstream dns servers for the given domain
|
||||||
func (c *Client) SetServer(domain string, servers ...string) {
|
func (c *Client) SetServers(domain string, servers ...string) {
|
||||||
c.upServerMap[domain] = append(c.upServerMap[domain], servers...)
|
c.upServerMap[domain] = append(c.upServerMap[domain], servers...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
11
main.go
11
main.go
@ -40,14 +40,7 @@ func main() {
|
|||||||
|
|
||||||
// DNS Server
|
// DNS Server
|
||||||
if conf.DNS != "" {
|
if conf.DNS != "" {
|
||||||
dnscfg := &dns.Config{
|
d, err := dns.NewServer(conf.DNS, dialer, &conf.DNSConfig)
|
||||||
Servers: conf.DNSServers,
|
|
||||||
Timeout: conf.DNSTimeout,
|
|
||||||
MaxTTL: conf.DNSMaxTTL,
|
|
||||||
MinTTL: conf.DNSMinTTL,
|
|
||||||
Records: conf.DNSRecords}
|
|
||||||
|
|
||||||
d, err := dns.NewServer(conf.DNS, dialer, dnscfg)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -56,7 +49,7 @@ func main() {
|
|||||||
for _, r := range conf.rules {
|
for _, r := range conf.rules {
|
||||||
for _, domain := range r.Domain {
|
for _, domain := range r.Domain {
|
||||||
if len(r.DNSServers) > 0 {
|
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]
|
d := rr.fwdrs[idx]
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
|
||||||
time.Sleep(time.Duration(rr.interval) * time.Second * time.Duration(retry>>1))
|
time.Sleep(time.Duration(rr.interval) * time.Second * time.Duration(retry>>1))
|
||||||
|
|
||||||
// check forwarders whose priority not less than current priority only
|
// check forwarders whose priority not less than current priority only
|
||||||
|
Loading…
Reference in New Issue
Block a user