-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Respect DNS TTL #1085
Respect DNS TTL #1085
Conversation
Replaces the viki-org/dnscache DNS resolver with domainr/dnsr. The new resolver respects DNS record TTLs.
Package miekg/dns requires the new version.
The current setup does some things dnsr doesn't:
I've tried to preserve all of this. IP versions are detected by Those last 2 minimize network exchanges.
I could write up a summary of the logic if it would be useful. |
// findIP6 returns the first IPv6 address found in rrs. | ||
// Alternately returns a CNAME record if found. | ||
func findIP6(rrs []dnsr.RR) (net.IP, *dnsr.RR) { | ||
var cname *dnsr.RR = nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should drop = nil from declaration of var cname; it is the zero value (from golint
)
// findIP4 returns the first IPv4 address found in rrs. | ||
// Alternately returns a CNAME record if found. | ||
func findIP4(rrs []dnsr.RR) (net.IP, *dnsr.RR) { | ||
var cname *dnsr.RR = nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should drop = nil from declaration of var cname; it is the zero value (from golint
)
func findIP6(rrs []dnsr.RR) (net.IP, *dnsr.RR) { | ||
var cname *dnsr.RR = nil | ||
for _, rr := range rrs { | ||
ip := extractIP6(&rr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a reference for the variable on range scope rr
(from scopelint
)
return ip, nil | ||
} | ||
if rr.Type == "CNAME" { | ||
cname = &rr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a reference for the variable on range scope rr
(from scopelint
)
func findIP4(rrs []dnsr.RR) (net.IP, *dnsr.RR) { | ||
var cname *dnsr.RR = nil | ||
for _, rr := range rrs { | ||
ip := extractIP4(&rr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a reference for the variable on range scope rr
(from scopelint
)
return ip, nil | ||
} | ||
if rr.Type == "CNAME" { | ||
cname = &rr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a reference for the variable on range scope rr
(from scopelint
)
) | ||
|
||
var ip6 bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ip6
is a global variable (from gochecknoglobals
)
) | ||
|
||
var ip6 bool | ||
var ip4 bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ip4
is a global variable (from gochecknoglobals
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very sorry for the long delay, we were fixing issues in order to release v0.25.0 and it took way longer than expected ;(
Looking at the code ... it seems okay, and I don't see how else we could use dnsr/dns and if there is no alternative we will need at least 80% of this code either way. I left some comments on the current implementation, and will make a more full review looking through all the dns logic in more details (possibly with some rfcs) when you finish it ... or at least the tests pass :).
I would also prefer if this is code is very well tested ... although I don't know how hard that will be.
Also we do intend to add dns testing ( #851 ), so while definitely a lot will need to change for that, can you maybe refactor all the dns stuff to not be directly on the Dialer but possibly on a Resolver type ? This way we will possibly have less to refactor than and I think it will be better overall
@@ -3,595 +3,481 @@ | |||
|
|||
[[projects]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea why all the changes to this file has happened, but I would prefer if they are reverted ;) We will be moving to go modules #1070 as soon as we move to 1.13, so even if this is because dep changed we prefer if we don't have unnecessary amount of changes ...
} | ||
|
||
// detectInterfaces detects available IP network versions. | ||
func detectInterfaces() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be moved to some initialization of each Dialer
, and put the ip6,ip4 globalvars as fields of the Dialer. You could use sync.Once if no good place for initialization exists, although I doubt this
// NewDialer constructs a new Dialer and initializes its cache. | ||
func NewDialer(dialer net.Dialer) *Dialer { | ||
return &Dialer{ | ||
Dialer: dialer, | ||
Resolver: dnscache.New(0), | ||
Resolver: dnsr.NewExpiring(0), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here 0
means 1000
given the current code of dnsr. Can you either add a comment for this or actually put a 1000?
I know how it is. You can never tell how long these things will take. Thanks for looking at it. Will go over all of this soon. |
Closing this in favor of the new approach discussed offthread. |
Updates DNS resolution to respect TTL.
Replaces the
viki-org/dnscache
DNS resolver withdomainr/dnsr
which supports TTL.This adds several packages to
vendor
. All of them are deps of the underlyingmiekg/dns
package.This is a larger piece of logic than I originally described. There are some kinks to work out, I think because the new resolver returns some different errors. But I wanted to ask for feedback before getting into that, in case this is further than you really want to go.
Closes #726.