From 02b658cd2beb5968818c7ed37388fb348b9b9cb9 Mon Sep 17 00:00:00 2001 From: ghost Date: Wed, 1 Jan 2020 10:23:14 +0800 Subject: [PATCH] revert broken dns changes --- app/dns/dnscommon.go | 27 ++++++++++----------------- app/dns/server.go | 2 +- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/app/dns/dnscommon.go b/app/dns/dnscommon.go index 65f4bc522..955962bcb 100644 --- a/app/dns/dnscommon.go +++ b/app/dns/dnscommon.go @@ -177,16 +177,10 @@ func parseResponse(payload []byte) (*IPRecord, error) { } now := time.Now() - var ipRecExpire time.Time - if h.RCode != dnsmessage.RCodeSuccess { - // A default TTL, maybe a negtive cache - ipRecExpire = now.Add(time.Second * 120) - } - ipRecord := &IPRecord{ ReqID: h.ID, RCode: h.RCode, - Expire: ipRecExpire, + Expire: now.Add(time.Second * 600), } L: @@ -199,6 +193,15 @@ L: break } + ttl := ah.TTL + if ttl == 0 { + ttl = 600 + } + expire := now.Add(time.Duration(ttl) * time.Second) + if ipRecord.Expire.After(expire) { + ipRecord.Expire = expire + } + switch ah.Type { case dnsmessage.TypeA: ans, err := parser.AResource() @@ -221,16 +224,6 @@ L: } continue } - - if ipRecord.Expire.IsZero() { - ttl := ah.TTL - if ttl < 600 { - // at least 10 mins TTL - ipRecord.Expire = now.Add(time.Minute * 10) - } else { - ipRecord.Expire = now.Add(time.Duration(ttl) * time.Second) - } - } } return ipRecord, nil diff --git a/app/dns/server.go b/app/dns/server.go index c2bf83f91..2d89f3aa8 100644 --- a/app/dns/server.go +++ b/app/dns/server.go @@ -364,7 +364,7 @@ func (s *Server) lookupIPInternal(domain string, option IPOption) ([]net.IP, err } } - return nil, dns.ErrEmptyResponse.Base(lastErr) + return nil, newError("returning nil for domain ", domain).Base(lastErr) } func init() {