Skip to content

Commit

Permalink
#42 setting default ttl when there is not hostname, increasing cache …
Browse files Browse the repository at this point in the history
…size to about 1MB
  • Loading branch information
mageddo committed Oct 14, 2017
1 parent e76143e commit 4b0c735
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cache/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

var c cache.Cache;
func init(){
c = lru.New(256);
c = lru.New(43690); // about 1 MB considering HostnameVo struct
}

//
Expand Down
4 changes: 3 additions & 1 deletion proxy/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ func (s localDnsSolver) Solve(ctx context.Context, question dns.Question) (*dns.
if activeEnv == nil {
return nil, errors.New("original env")
}
var ttl int64 = 86400 // 24 hours
hostname,_ = activeEnv.GetHostname(key)
val := s.Cache.PutIfAbsent(key, timed.NewTimedValue(hostname, time.Now(), time.Duration(int64(hostname.Ttl)) * time.Second));
if hostname != nil { ttl = int64(hostname.Ttl) }
val := s.Cache.PutIfAbsent(key, timed.NewTimedValue(hostname, time.Now(), time.Duration(ttl) * time.Second));
LOGGER.Debugf("status=put, key=%s, value=%v", key, val)
}

Expand Down
17 changes: 17 additions & 0 deletions proxy/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,23 @@ func TestLocalDnsSolver_Solve(t *testing.T) {

}

func TestLocalDnsSolver_SolveNotFoundHost(t *testing.T) {

defer local.ResetConf()

expectedHostname := "github.com"
ctx := logging.NewContext()

question := new(dns.Question)
question.Name = expectedHostname + "."
solver := NewLocalDNSSolver(store.GetInstance())

// act
_, err := solver.Solve(ctx, *question)
assert.NotNil(t, err, "Fail to solve")

}


type MockCache struct {
mock.Mock
Expand Down

0 comments on commit 4b0c735

Please sign in to comment.