1. add comments, 2. optimize text message

This commit is contained in:
wweir
2021-08-11 06:48:18 +08:00
parent 65234b1666
commit 38c7391ceb
5 changed files with 17 additions and 11 deletions
+2
View File
@@ -16,6 +16,7 @@ func (r *Router) ServeDNS(w dns.ResponseWriter, req *dns.Msg) {
}
domain := req.Question[0].Name
// 1. rule_based( block > direct > proxy )
switch {
case r.blockRule.Match(domain):
_ = w.WriteMsg(r.dnsFail(req, dns.RcodeNameError))
@@ -28,6 +29,7 @@ func (r *Router) ServeDNS(w dns.ResponseWriter, req *dns.Msg) {
return
}
// 2. direct with cache, do not fallback to proxy to avoid side-effect
c := &dnsCache{Router: r, Req: req}
if err := r.dns.cache.Remember(c, req.Question[0].String()); err != nil {
_ = w.WriteMsg(r.dnsFail(req, dns.RcodeServerFailure))
+1
View File
@@ -30,6 +30,7 @@ type ping struct {
}
func (p *ping) Fulfill(key string) error {
// just like `curl -I http://domain.com:80`
_, err := pingClient.Head(net.JoinHostPort(key, "80"))
deferlog.Std.DebugWarn(err).
Str("domain", key).
+4 -3
View File
@@ -107,6 +107,9 @@ func (r *Router) RouteHandle(conn net.Conn, domain string, port uint16) (err err
addr := net.JoinHostPort(domain, strconv.FormatUint(uint64(port), 10))
// 1. rule_based( block > direct > proxy )
// 2. detect_based( CN IP || access site )
// 3. fallback( proxy )
switch {
case r.blockRule.Match(domain):
return nil
@@ -117,9 +120,7 @@ func (r *Router) RouteHandle(conn net.Conn, domain string, port uint16) (err err
case r.proxyRule.Match(domain):
return r.ProxyHandle(conn, domain, port)
case r.localSite(domain):
return r.DirectHandle(conn, addr)
case r.isAccess(domain, port):
case r.localSite(domain), r.isAccess(domain, port):
return r.DirectHandle(conn, addr)
default:
return r.ProxyHandle(conn, domain, port)