Skip to content

Commit

Permalink
refactor: store current retry in resolver struct
Browse files Browse the repository at this point in the history
  • Loading branch information
developStorm committed Nov 13, 2024
1 parent b73a77e commit 148eb28
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
6 changes: 2 additions & 4 deletions src/zdns/dnssec.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ func (r *Resolver) getDNSKEYs(ctx context.Context, signerDomain string, nameServ
ksks := make(map[uint16]*dns.DNSKEY)
zsks := make(map[uint16]*dns.DNSKEY)

retries := r.retries
nameWithoutTrailingDot := removeTrailingDotIfNotRoot(signerDomain)
if signerDomain == rootZone {
nameWithoutTrailingDot = rootZone
Expand All @@ -157,7 +156,7 @@ func (r *Resolver) getDNSKEYs(ctx context.Context, signerDomain string, nameServ
Type: dns.TypeDNSKEY,
Class: dns.ClassINET,
},
RetriesRemaining: &retries,
RetriesRemaining: &r.retriesRemaining,
}

res, trace, status, err := r.lookup(ctx, &dnskeyQuestion, r.rootNameServers, isIterative, trace)
Expand Down Expand Up @@ -217,7 +216,6 @@ func (r *Resolver) getDNSKEYs(ctx context.Context, signerDomain string, nameServ
// - Trace: Updated trace context with the DS query included.
// - error: If validation fails for any DS record, returns an error with details.
func (r *Resolver) validateDSRecords(ctx context.Context, signerDomain string, dnskeyMap map[uint16]*dns.DNSKEY, nameServer *NameServer, isIterative bool, trace Trace, depth int) (bool, Trace, error) {
retries := r.retries
nameWithoutTrailingDot := removeTrailingDotIfNotRoot(signerDomain)

dsQuestion := QuestionWithMetadata{
Expand All @@ -226,7 +224,7 @@ func (r *Resolver) validateDSRecords(ctx context.Context, signerDomain string, d
Type: dns.TypeDS,
Class: dns.ClassINET,
},
RetriesRemaining: &retries,
RetriesRemaining: &r.retriesRemaining,
}

dsRecords := make(map[uint16]dns.DS)
Expand Down
10 changes: 5 additions & 5 deletions src/zdns/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ func (r *Resolver) doDstServersLookup(q Question, nameServers []NameServer, isIt
}
ctx, cancel := context.WithTimeout(context.Background(), r.timeout)
defer cancel()
retries := r.retries
r.retriesRemaining = r.retries
questionWithMeta := QuestionWithMetadata{
Q: q,
RetriesRemaining: &retries,
RetriesRemaining: &r.retriesRemaining,
}
if r.followCNAMEs {
return r.followingLookup(ctx, &questionWithMeta, nameServers, isIterative)
Expand Down Expand Up @@ -904,7 +904,7 @@ func (r *Resolver) iterateOnAuthorities(ctx context.Context, qWithMeta *Question
var nsStatus Status
var nextLayer string
r.verboseLog(depth+1, "Trying Authority: ", elem)
ns, nsStatus, nextLayer, newTrace = r.extractAuthority(ctx, elem, layer, qWithMeta.RetriesRemaining, depth, result, newTrace)
ns, nsStatus, nextLayer, newTrace = r.extractAuthority(ctx, elem, layer, depth, result, newTrace)
r.verboseLog(depth+1, "Output from extract authorities: ", ns.String())

if nsStatus == StatusIterTimeout {
Expand Down Expand Up @@ -949,7 +949,7 @@ func (r *Resolver) iterateOnAuthorities(ctx context.Context, qWithMeta *Question
}
}

func (r *Resolver) extractAuthority(ctx context.Context, authority interface{}, layer string, retriesRemaining *int, depth int, result *SingleQueryResult, trace Trace) (*NameServer, Status, string, Trace) {
func (r *Resolver) extractAuthority(ctx context.Context, authority interface{}, layer string, depth int, result *SingleQueryResult, trace Trace) (*NameServer, Status, string, Trace) {
// Is it an answer
ans, ok := authority.(Answer)
if !ok {
Expand Down Expand Up @@ -983,7 +983,7 @@ func (r *Resolver) extractAuthority(ctx context.Context, authority interface{},
} else {
q.Q.Type = dns.TypeA
}
q.RetriesRemaining = retriesRemaining
q.RetriesRemaining = &r.retriesRemaining
res, trace, status, _ = r.iterativeLookup(ctx, &q, r.rootNameServers, depth+1, ".", trace)
}
if status == StatusIterTimeout || status == StatusNoNeededGlue {
Expand Down
5 changes: 3 additions & 2 deletions src/zdns/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,9 @@ type Resolver struct {
connInfoIPv4Loopback *ConnectionInfo // used for IPv4 lookups to loopback nameservers
connInfoIPv6Loopback *ConnectionInfo // used for IPv6 lookups to loopback nameservers

retries int
logLevel log.Level
retries int
retriesRemaining int
logLevel log.Level

transportMode transportMode
ipVersionMode IPVersionMode
Expand Down

0 comments on commit 148eb28

Please sign in to comment.