Merge pull request #943 from inercia/weave-941
make negative TTL default to same value as TTL Fixes #941.
This commit is contained in:
commit
cfe14ff568
4 files changed
+14
-15
No files matched your search
@@ -22,8 +22,6 @@ var (
|
||||
)
|
||||
|
||||
const (
|
||||
DefaultCacheNegLocalTTL = 30 // Default TTL for negative local resolutions
|
||||
|
||||
defPendingTimeout int = 5 // timeout for a resolution
|
||||
)
|
||||
|
||||
|
||||
@@ -196,26 +196,26 @@ func TestCacheEntries(t *testing.T) {
|
||||
question3 := &questionMsg3.Question[0]
|
||||
|
||||
t.Logf("Checking that a entry with CacheNoLocalReplies return an error")
|
||||
l.Put(questionMsg3, nil, DefaultCacheNegLocalTTL, CacheNoLocalReplies)
|
||||
l.Put(questionMsg3, nil, DefaultLocalTTL, CacheNoLocalReplies)
|
||||
resp, err = l.Get(questionMsg3, minUDPSize)
|
||||
wt.AssertNil(t, resp, "Get() response with CacheNoLocalReplies")
|
||||
wt.AssertTrue(t, err == errNoLocalReplies, "Get() error with CacheNoLocalReplies")
|
||||
|
||||
t.Logf("Checking that more Put's do not make the negative TTL longer")
|
||||
clk.Add(time.Duration(DefaultCacheNegLocalTTL/2) * time.Second)
|
||||
l.Put(questionMsg3, nil, DefaultCacheNegLocalTTL, CacheNoLocalReplies)
|
||||
clk.Add(time.Duration(DefaultLocalTTL/2) * time.Second)
|
||||
l.Put(questionMsg3, nil, DefaultLocalTTL, CacheNoLocalReplies)
|
||||
clk.Add(time.Duration(1) * time.Second)
|
||||
l.Put(questionMsg3, nil, DefaultCacheNegLocalTTL, CacheNoLocalReplies)
|
||||
l.Put(questionMsg3, nil, DefaultLocalTTL, CacheNoLocalReplies)
|
||||
clk.Add(time.Duration(1) * time.Second)
|
||||
l.Put(questionMsg3, nil, DefaultCacheNegLocalTTL, CacheNoLocalReplies)
|
||||
l.Put(questionMsg3, nil, DefaultLocalTTL, CacheNoLocalReplies)
|
||||
resp, err = l.Get(questionMsg3, minUDPSize)
|
||||
wt.AssertNil(t, resp, "Get() response with CacheNoLocalReplies")
|
||||
wt.AssertTrue(t, err == errNoLocalReplies, "Get() error with CacheNoLocalReplies")
|
||||
|
||||
clk.Add(time.Duration(DefaultCacheNegLocalTTL/2) * time.Second)
|
||||
t.Logf("Checking that we get an expired response after %f seconds", DefaultCacheNegLocalTTL)
|
||||
clk.Add(time.Second * time.Duration(DefaultCacheNegLocalTTL+1))
|
||||
t.Logf("Checking that we get an expired response after %d seconds", DefaultCacheNegLocalTTL)
|
||||
clk.Add(time.Duration(DefaultLocalTTL/2) * time.Second)
|
||||
t.Logf("Checking that we get an expired response after %f seconds", DefaultLocalTTL)
|
||||
clk.Add(time.Second * time.Duration(DefaultLocalTTL+1))
|
||||
t.Logf("Checking that we get an expired response after %d seconds", DefaultLocalTTL)
|
||||
resp, err = l.Get(questionMsg3, minUDPSize)
|
||||
wt.AssertNil(t, resp, "expired Get() response with CacheNoLocalReplies")
|
||||
wt.AssertNil(t, err, "expired Get() error with CacheNoLocalReplies")
|
||||
|
||||
@@ -45,7 +45,7 @@ type DNSServerConfig struct {
|
||||
Cache ZoneCache
|
||||
// (Optional) TTL for local domain responses
|
||||
LocalTTL int
|
||||
// (Optional) TTL for negative results in the local domain
|
||||
// (Optional) TTL for negative results in the local domain (defaults to LocalTTL)
|
||||
CacheNegLocalTTL int
|
||||
// (Optional) for a specific clock provider
|
||||
Clock clock.Clock
|
||||
@@ -120,7 +120,6 @@ func NewDNSServer(config DNSServerConfig) (s *DNSServer, err error) {
|
||||
cacheDisabled: false,
|
||||
maxAnswers: DefaultMaxAnswers,
|
||||
localTTL: DefaultLocalTTL,
|
||||
negLocalTTL: DefaultCacheNegLocalTTL,
|
||||
clock: config.Clock,
|
||||
}
|
||||
|
||||
@@ -164,6 +163,8 @@ func NewDNSServer(config DNSServerConfig) (s *DNSServer, err error) {
|
||||
}
|
||||
if config.CacheNegLocalTTL > 0 {
|
||||
s.negLocalTTL = config.CacheNegLocalTTL
|
||||
} else {
|
||||
s.negLocalTTL = s.localTTL
|
||||
}
|
||||
if config.CacheDisabled {
|
||||
s.cacheDisabled = true
|
||||
|
||||
Reference in new issue
Block a user