Merge remote-tracking branch 'upstream/master' into i18n

This commit is contained in:
Hoàng Rio 2018-11-05 11:23:16 +07:00
commit cd75c406c1
No known key found for this signature in database
GPG Key ID: B19526CDE69535A1
2 changed files with 13 additions and 33 deletions

View File

@ -41,16 +41,6 @@ func init() {
}) })
} }
type cacheEntry struct {
answer []dns.RR
lastUpdated time.Time
}
var (
lookupCacheTime = time.Minute * 30
lookupCache = map[string]cacheEntry{}
)
type plugFilter struct { type plugFilter struct {
ID int64 ID int64
Path string Path string
@ -345,29 +335,20 @@ func (p *plug) replaceHostWithValAndReply(ctx context.Context, w dns.ResponseWri
records = append(records, result) records = append(records, result)
} else { } else {
// this is a domain name, need to look it up // this is a domain name, need to look it up
cacheentry := lookupCache[val] req := new(dns.Msg)
if time.Since(cacheentry.lastUpdated) > lookupCacheTime { req.SetQuestion(dns.Fqdn(val), question.Qtype)
req := new(dns.Msg) req.RecursionDesired = true
req.SetQuestion(dns.Fqdn(val), question.Qtype) reqstate := request.Request{W: w, Req: req, Context: ctx}
req.RecursionDesired = true result, err := p.upstream.Lookup(reqstate, dns.Fqdn(val), reqstate.QType())
reqstate := request.Request{W: w, Req: req, Context: ctx} if err != nil {
result, err := p.upstream.Lookup(reqstate, dns.Fqdn(val), reqstate.QType()) log.Printf("Got error %s\n", err)
if err != nil { return dns.RcodeServerFailure, fmt.Errorf("plugin/dnsfilter: %s", err)
log.Printf("Got error %s\n", err) }
return dns.RcodeServerFailure, fmt.Errorf("plugin/dnsfilter: %s", err) if result != nil {
for _, answer := range result.Answer {
answer.Header().Name = question.Name
} }
if result != nil { records = result.Answer
for _, answer := range result.Answer {
answer.Header().Name = question.Name
}
records = result.Answer
cacheentry.answer = result.Answer
cacheentry.lastUpdated = time.Now()
lookupCache[val] = cacheentry
}
} else {
// get from cache
records = cacheentry.answer
} }
} }
m := new(dns.Msg) m := new(dns.Msg)

View File

@ -17,7 +17,6 @@ import (
"sync/atomic" "sync/atomic"
"time" "time"
_ "github.com/benburkert/dns/init"
"github.com/bluele/gcache" "github.com/bluele/gcache"
"golang.org/x/net/publicsuffix" "golang.org/x/net/publicsuffix"
) )