mirror of
https://github.com/wweir/sower.git
synced 2026-10-19 16:14:33 +00:00
1. add comments, 2. optimize text message
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user