Skip to content

Commit

Permalink
fix: rtt time should include tcp.Dial
Browse files Browse the repository at this point in the history
Ref #39
  • Loading branch information
mr-karan committed May 17, 2022
1 parent 8d70524 commit 0ce04d0
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions pkg/resolvers/classic.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package resolvers

import (
"time"

"github.com/miekg/dns"
"github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -65,11 +67,15 @@ func (r *ClassicResolver) Lookup(question dns.Question) (Response, error) {
"ndots": r.resolverOptions.Ndots,
"nameserver": r.server,
}).Debug("Attempting to resolve")
in, rtt, err := r.client.Exchange(&msg, r.server)

// Since the library doesn't include tcp.Dial time,
// it's better to not rely on `rtt` provided here and calculate it ourselves.
now := time.Now()
in, _, err := r.client.Exchange(&msg, r.server)
if err != nil {
return rsp, err
}
// pack questions in output.
// Pack questions in output.
for _, q := range msg.Question {
ques := Question{
Name: q.Name,
Expand All @@ -78,13 +84,15 @@ func (r *ClassicResolver) Lookup(question dns.Question) (Response, error) {
}
rsp.Questions = append(rsp.Questions, ques)
}
// get the authorities and answers.
rtt := time.Since(now)

// Get the authorities and answers.
output := parseMessage(in, rtt, r.server)
rsp.Authorities = output.Authorities
rsp.Answers = output.Answers

if len(output.Answers) > 0 {
// stop iterating the searchlist.
// Stop iterating the searchlist.
break
}
}
Expand Down

0 comments on commit 0ce04d0

Please sign in to comment.