enhance logging for dns

This commit is contained in:
xvzc 2024-07-31 20:47:19 +09:00
parent 378b980301
commit 10a3860fad
2 changed files with 7 additions and 7 deletions

View File

@ -4,8 +4,8 @@ import (
"context"
"errors"
"regexp"
"time"
"strconv"
"time"
"github.com/likexian/doh"
dohDns "github.com/likexian/doh/dns"
@ -53,12 +53,12 @@ func (d *DnsResolver) Lookup(domain string) (string, error) {
for _, answer := range response.Answer {
if record, ok := answer.(*dns.A); ok {
log.Debug("[DNS] resolved dns for "+domain+": ", record.A.String())
log.Debug("[DNS] resolved ", domain, ": ", record.A.String())
return record.A.String(), nil
}
}
return "", errors.New("couldn not resolve the domain")
return "", errors.New("no record found")
}
func dohLookup(domain string) (string, error) {
@ -79,12 +79,12 @@ func dohLookup(domain string) (string, error) {
continue
}
log.Debug("[DOH] resolved dns for "+domain+": ", a.Data)
log.Debug("[DOH] resolved ", domain, ": ", a.Data)
return a.Data, nil
}
// close the client
c.Close()
return "", errors.New("couldn not resolve the domain")
return "", errors.New("no record found")
}

View File

@ -76,7 +76,7 @@ func (pxy *Proxy) Start() {
ip, err := pxy.resolver.Lookup(pkt.Domain())
if err != nil {
log.Error("[PROXY] Error looking up for domain with ", pkt.Domain(), " ", err)
log.Error("[PROXY] Error while dns lookup: ", pkt.Domain(), " ", err)
conn.Write([]byte(pkt.Version() + " 502 Bad Gateway\r\n\r\n"))
conn.Close()
return