Commit 9faf5cdf authored by Dan Peterson's avatar Dan Peterson Committed by Brad Fitzpatrick

net: change type of dnsConfig.timeout from int to time.Duration

Instead of keeping the desired number of seconds and converting to
time.Duration for every query, convert to time.Duration when
building the config.

Updates #15473

Change-Id: Ib24c050b593b3109011e359f4ed837a3fb45dc65
Reviewed-on: https://go-review.googlesource.com/22548Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 22db3c5a
......@@ -180,8 +180,7 @@ func tryOneName(ctx context.Context, cfg *dnsConfig, name string, qtype uint16)
return "", nil, &DNSError{Err: "no DNS servers", Name: name}
}
timeout := time.Duration(cfg.timeout) * time.Second
deadline := time.Now().Add(timeout)
deadline := time.Now().Add(cfg.timeout)
if old, ok := ctx.Deadline(); !ok || deadline.Before(old) {
var cancel context.CancelFunc
ctx, cancel = context.WithDeadline(ctx, deadline)
......
......@@ -22,7 +22,7 @@ type dnsConfig struct {
servers []string // servers to use
search []string // suffixes to append to local name
ndots int // number of dots in name to trigger absolute lookup
timeout int // seconds before giving up on packet
timeout time.Duration // wait before giving up on a query, including retries
attempts int // lost packets before giving up on server
rotate bool // round robin among servers
unknownOpt bool // anything unknown was encountered
......@@ -35,7 +35,7 @@ type dnsConfig struct {
func dnsReadConfig(filename string) *dnsConfig {
conf := &dnsConfig{
ndots: 1,
timeout: 5,
timeout: 5 * time.Second,
attempts: 2,
}
file, err := open(filename)
......@@ -101,7 +101,7 @@ func dnsReadConfig(filename string) *dnsConfig {
if n < 1 {
n = 1
}
conf.timeout = n
conf.timeout = time.Duration(n) * time.Second
case hasPrefix(s, "attempts:"):
n, _, _ := dtoi(s, 9)
if n < 1 {
......
......@@ -24,7 +24,7 @@ var dnsReadConfigTests = []struct {
servers: []string{"8.8.8.8", "2001:4860:4860::8888", "fe80::1%lo0"},
search: []string{"localdomain"},
ndots: 5,
timeout: 10,
timeout: 10 * time.Second,
attempts: 3,
rotate: true,
unknownOpt: true, // the "options attempts 3" line
......@@ -36,7 +36,7 @@ var dnsReadConfigTests = []struct {
servers: []string{"8.8.8.8"},
search: []string{"localdomain"},
ndots: 1,
timeout: 5,
timeout: 5 * time.Second,
attempts: 2,
},
},
......@@ -46,7 +46,7 @@ var dnsReadConfigTests = []struct {
servers: []string{"8.8.8.8"},
search: []string{"test", "invalid"},
ndots: 1,
timeout: 5,
timeout: 5 * time.Second,
attempts: 2,
},
},
......@@ -55,7 +55,7 @@ var dnsReadConfigTests = []struct {
want: &dnsConfig{
servers: defaultNS,
ndots: 1,
timeout: 5,
timeout: 5 * time.Second,
attempts: 2,
search: []string{"domain.local"},
},
......@@ -64,7 +64,7 @@ var dnsReadConfigTests = []struct {
name: "testdata/openbsd-resolv.conf",
want: &dnsConfig{
ndots: 1,
timeout: 5,
timeout: 5 * time.Second,
attempts: 2,
lookup: []string{"file", "bind"},
servers: []string{"169.254.169.254", "10.240.0.1"},
......@@ -103,7 +103,7 @@ func TestDNSReadMissingFile(t *testing.T) {
want := &dnsConfig{
servers: defaultNS,
ndots: 1,
timeout: 5,
timeout: 5 * time.Second,
attempts: 2,
search: []string{"domain.local"},
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment