Skip to content

Commit

Permalink
Merge pull request #110 from gdm85/fix/simplify
Browse files Browse the repository at this point in the history
Simplify doDNSQuery call
  • Loading branch information
m13253 committed May 15, 2021
2 parents 56a0167 + 8a13f08 commit f172a7b
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions doh-server/server.go
Expand Up @@ -268,8 +268,7 @@ func (s *Server) handlerFunc(w http.ResponseWriter, r *http.Request) {

req = s.patchRootRD(req)

var err error
req, err = s.doDNSQuery(ctx, req)
err := s.doDNSQuery(ctx, req)
if err != nil {
jsondns.FormatError(w, fmt.Sprintf("DNS query failure (%s)", err.Error()), 503)
return
Expand Down Expand Up @@ -340,7 +339,7 @@ func (s *Server) indexQuestionType(msg *dns.Msg, qtype uint16) int {
return -1
}

func (s *Server) doDNSQuery(ctx context.Context, req *DNSRequest) (resp *DNSRequest, err error) {
func (s *Server) doDNSQuery(ctx context.Context, req *DNSRequest) (err error) {
numServers := len(s.conf.Upstream)
for i := uint(0); i < s.conf.Tries; i++ {
req.currentUpstream = s.conf.Upstream[rand.Intn(numServers)]
Expand All @@ -350,7 +349,7 @@ func (s *Server) doDNSQuery(ctx context.Context, req *DNSRequest) (resp *DNSRequ
switch t {
default:
log.Printf("invalid DNS type %q in upstream %q", t, upstream)
return nil, &configError{"invalid DNS type"}
return &configError{"invalid DNS type"}
// Use DNS-over-TLS (DoT) if configured to do so
case "tcp-tls":
req.response, _, err = s.tcpClientTLS.ExchangeContext(ctx, req.request, upstream)
Expand All @@ -375,9 +374,9 @@ func (s *Server) doDNSQuery(ctx context.Context, req *DNSRequest) (resp *DNSRequ
}

if err == nil {
return req, nil
return nil
}
log.Printf("DNS error from upstream %s: %s\n", req.currentUpstream, err.Error())
}
return req, err
return err
}

0 comments on commit f172a7b

Please sign in to comment.