Browse Source

revert broken dns changes

ghost 5 years ago
parent
commit
02b658cd2b
2 changed files with 11 additions and 18 deletions
  1. 10 17
      app/dns/dnscommon.go
  2. 1 1
      app/dns/server.go

+ 10 - 17
app/dns/dnscommon.go

@@ -177,16 +177,10 @@ func parseResponse(payload []byte) (*IPRecord, error) {
 	}
 	}
 
 
 	now := time.Now()
 	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{
 	ipRecord := &IPRecord{
 		ReqID:  h.ID,
 		ReqID:  h.ID,
 		RCode:  h.RCode,
 		RCode:  h.RCode,
-		Expire: ipRecExpire,
+		Expire: now.Add(time.Second * 600),
 	}
 	}
 
 
 L:
 L:
@@ -199,6 +193,15 @@ L:
 			break
 			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 {
 		switch ah.Type {
 		case dnsmessage.TypeA:
 		case dnsmessage.TypeA:
 			ans, err := parser.AResource()
 			ans, err := parser.AResource()
@@ -221,16 +224,6 @@ L:
 			}
 			}
 			continue
 			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
 	return ipRecord, nil

+ 1 - 1
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() {
 func init() {