Feature: implemented a strategy similar to optimistic DNS (#647)
This commit is contained in:
12
dns/util.go
12
dns/util.go
@ -79,21 +79,21 @@ func (e EnhancedMode) String() string {
|
||||
}
|
||||
}
|
||||
|
||||
func putMsgToCache(c *cache.Cache, key string, msg *D.Msg) {
|
||||
var ttl time.Duration
|
||||
func putMsgToCache(c *cache.LruCache, key string, msg *D.Msg) {
|
||||
var ttl uint32
|
||||
switch {
|
||||
case len(msg.Answer) != 0:
|
||||
ttl = time.Duration(msg.Answer[0].Header().Ttl) * time.Second
|
||||
ttl = msg.Answer[0].Header().Ttl
|
||||
case len(msg.Ns) != 0:
|
||||
ttl = time.Duration(msg.Ns[0].Header().Ttl) * time.Second
|
||||
ttl = msg.Ns[0].Header().Ttl
|
||||
case len(msg.Extra) != 0:
|
||||
ttl = time.Duration(msg.Extra[0].Header().Ttl) * time.Second
|
||||
ttl = msg.Extra[0].Header().Ttl
|
||||
default:
|
||||
log.Debugln("[DNS] response msg error: %#v", msg)
|
||||
return
|
||||
}
|
||||
|
||||
c.Put(key, msg.Copy(), ttl)
|
||||
c.SetWithExpire(key, msg.Copy(), time.Now().Add(time.Second*time.Duration(ttl)))
|
||||
}
|
||||
|
||||
func setMsgTTL(msg *D.Msg, ttl uint32) {
|
||||
|
Reference in New Issue
Block a user