better fallback logical

nghttp2
fangdingjun 9 years ago
parent 9f9a78555e
commit 667dc1ff49

@ -12919,5 +12919,7 @@
"mmbang.info": 1, "mmbang.info": 1,
"fequan.com": 1, "fequan.com": 1,
"fangdd.com": 1, "fangdd.com": 1,
"qianzhan.com": 1 "qianzhan.com": 1,
"simicloud.com": 1,
"i4season.com": 1
} }

@ -84,8 +84,6 @@ func handleRoot(w dns.ResponseWriter, r *dns.Msg) {
var res *dns.Msg var res *dns.Msg
domain := r.Question[0].Name domain := r.Question[0].Name
var done int
/* /*
reply from hosts reply from hosts
*/ */
@ -135,7 +133,6 @@ func handleRoot(w dns.ResponseWriter, r *dns.Msg) {
// forward to upstream server // forward to upstream server
for i := 0; i < 2; i++ { for i := 0; i < 2; i++ {
done = 0
for _, sv := range Servers { for _, sv := range Servers {
if sv.match(domain) { if sv.match(domain) {
@ -165,14 +162,14 @@ func handleRoot(w dns.ResponseWriter, r *dns.Msg) {
dns_cache.Add(key, strings.Join(v, "|")) dns_cache.Add(key, strings.Join(v, "|"))
} }
w.WriteMsg(res) w.WriteMsg(res)
done = 1 return
break }
} }
} }
} }
// fallback to default upstream server // fallback to default upstream server
if done != 1 { for i := 0; i < 2; i++ {
logger.Debug("%s query %s %s %s, use default server\n", logger.Debug("%s query %s %s %s, use default server\n",
w.RemoteAddr(), w.RemoteAddr(),
domain, domain,
@ -192,20 +189,12 @@ func handleRoot(w dns.ResponseWriter, r *dns.Msg) {
dns_cache.Add(key, strings.Join(v, "|")) dns_cache.Add(key, strings.Join(v, "|"))
} }
w.WriteMsg(res) w.WriteMsg(res)
done = 1 return
break
}
} }
if done == 1 {
break
}
} }
if done != 1 {
dns.HandleFailed(w, r) dns.HandleFailed(w, r)
}
} }
func main() { func main() {

Loading…
Cancel
Save