add debug log

nghttp2
fangdingjun 6 years ago
parent 90d650c118
commit 4aa5ef896e

@ -39,7 +39,7 @@ func (srv *server) serveUDP() {
udpconn, err := net.ListenUDP("udp", &net.UDPAddr{IP: _ip, Port: _port}) udpconn, err := net.ListenUDP("udp", &net.UDPAddr{IP: _ip, Port: _port})
if err != nil { if err != nil {
log.Fatalf("listen udp error", err) log.Fatalf("listen udp error %s", err)
} }
defer udpconn.Close() defer udpconn.Close()

@ -52,10 +52,15 @@ func (srv *server) handleHTTP2Req(w http.ResponseWriter, r *http.Request) {
} }
reply := false reply := false
for _, up := range srv.upstreams { for _, up := range srv.upstreams {
log.Debugf("from %s query upstream %s", r.RemoteAddr, up.String())
log.Debugln("query", msg.Question[0].String())
m, err := queryUpstream(msg, up) m, err := queryUpstream(msg, up)
if err == nil { if err == nil {
w.Header().Set("content-type", "application/dns-message") w.Header().Set("content-type", "application/dns-message")
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
for _, a := range m.Answer {
log.Debugln("result", a.String())
}
d, _ := m.Pack() d, _ := m.Pack()
w.Write(d) w.Write(d)
reply = true reply = true

@ -19,8 +19,13 @@ func (srv *server) handleTCP(c net.Conn) {
} }
reply := false reply := false
for _, up := range srv.upstreams { for _, up := range srv.upstreams {
log.Debugf("from %s query upstream %s", conn.RemoteAddr(), up.String())
log.Debugln("query", msg.Question[0].String())
m, err := queryUpstream(msg, up) m, err := queryUpstream(msg, up)
if err == nil { if err == nil {
for _, a := range m.Answer {
log.Debugln("result", a.String())
}
log.Debugln("got reply", m.String()) log.Debugln("got reply", m.String())
conn.WriteMsg(m) conn.WriteMsg(m)
reply = true reply = true

@ -14,8 +14,13 @@ func (srv *server) handleUDP(buf []byte, addr net.Addr, conn *net.UDPConn) {
return return
} }
for _, up := range srv.upstreams { for _, up := range srv.upstreams {
log.Debugf("from %s query upstream %s", addr, up.String())
log.Debugln("query", msg.Question[0].String())
m, err := queryUpstream(msg, up) m, err := queryUpstream(msg, up)
if err == nil { if err == nil {
for _, a := range m.Answer {
log.Debugln("result", a.String())
}
d, _ := m.Pack() d, _ := m.Pack()
conn.WriteTo(d, addr) conn.WriteTo(d, addr)
break break

@ -35,7 +35,6 @@ func queryUpstream(msg *dns.Msg, upstream *url.URL) (*dns.Msg, error) {
} }
func queryUpstreamUDP(msg *dns.Msg, upstream *url.URL) (*dns.Msg, error) { func queryUpstreamUDP(msg *dns.Msg, upstream *url.URL) (*dns.Msg, error) {
log.Debugln("query upstream", upstream.String())
m, _, err := dnsClientUDP.Exchange(msg, upstream.Host) m, _, err := dnsClientUDP.Exchange(msg, upstream.Host)
if err != nil { if err != nil {
log.Debugf("query udp error %s", err) log.Debugf("query udp error %s", err)
@ -44,7 +43,6 @@ func queryUpstreamUDP(msg *dns.Msg, upstream *url.URL) (*dns.Msg, error) {
} }
func queryUpstreamTCP(msg *dns.Msg, upstream *url.URL) (*dns.Msg, error) { func queryUpstreamTCP(msg *dns.Msg, upstream *url.URL) (*dns.Msg, error) {
log.Debugln("query upstream", upstream.String())
m, _, err := dnsClientTCP.Exchange(msg, upstream.Host) m, _, err := dnsClientTCP.Exchange(msg, upstream.Host)
if err != nil { if err != nil {
log.Debugf("query tcp error %s", err) log.Debugf("query tcp error %s", err)
@ -53,7 +51,6 @@ func queryUpstreamTCP(msg *dns.Msg, upstream *url.URL) (*dns.Msg, error) {
} }
func queryUpstreamTLS(msg *dns.Msg, upstream *url.URL) (*dns.Msg, error) { func queryUpstreamTLS(msg *dns.Msg, upstream *url.URL) (*dns.Msg, error) {
log.Debugln("query upstream", upstream.String())
m, _, err := dnsClientTLS.Exchange(msg, upstream.Host) m, _, err := dnsClientTLS.Exchange(msg, upstream.Host)
if err != nil { if err != nil {
log.Debugf("query tls error %s", err) log.Debugf("query tls error %s", err)
@ -62,7 +59,6 @@ func queryUpstreamTLS(msg *dns.Msg, upstream *url.URL) (*dns.Msg, error) {
} }
func queryUpstreamHTTPS(msg *dns.Msg, upstream *url.URL) (*dns.Msg, error) { func queryUpstreamHTTPS(msg *dns.Msg, upstream *url.URL) (*dns.Msg, error) {
log.Debugln("query upstream", upstream.String())
m, _, err := dnsClientHTTPS.Exchange(msg, upstream.String()) m, _, err := dnsClientHTTPS.Exchange(msg, upstream.String())
if err != nil { if err != nil {
log.Debugf("query https error %s", err) log.Debugf("query https error %s", err)

Loading…
Cancel
Save