Feature: implemented a strategy similar to optimistic DNS (#647)

This commit is contained in:
Comzyh
2020-05-07 15:10:14 +08:00
committed by GitHub
parent b085addbb0
commit b979ff0bc2
4 changed files with 121 additions and 45 deletions

View File

@ -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) {