|
|
|
@ -13,7 +13,7 @@ import (
|
|
|
|
|
|
|
|
|
|
type cacheItem struct {
|
|
|
|
|
Query []byte
|
|
|
|
|
Date time.Time
|
|
|
|
|
ExpireDate time.Time
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//DomainCache stores a domain name inside the cache
|
|
|
|
@ -28,7 +28,17 @@ func DomainCache(s string, resp *dns.Msg) {
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println("Problems packing the response: ", err.Error())
|
|
|
|
|
}
|
|
|
|
|
domain2cache.Date = time.Now()
|
|
|
|
|
if resp.Rcode == dns.RcodeSuccess{
|
|
|
|
|
// on success stores response normally
|
|
|
|
|
domain2cache.ExpireDate = time.Now().Add((time.Duration(ZabovCacheTTL) * time.Hour))
|
|
|
|
|
}else
|
|
|
|
|
{
|
|
|
|
|
// on failure stores response for a very short time
|
|
|
|
|
if ZabovDebug {
|
|
|
|
|
fmt.Println("DomainCache(): DNS error Rcode: ", resp.Rcode, s, "cache time reduced to 10 seconds...")
|
|
|
|
|
}
|
|
|
|
|
domain2cache.ExpireDate = time.Now().Add((time.Duration(10) * time.Second))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = enc.Encode(domain2cache)
|
|
|
|
|
|
|
|
|
@ -65,7 +75,7 @@ func GetDomainFromCache(s string) *dns.Msg {
|
|
|
|
|
|
|
|
|
|
conf, errDB = MyZabovCDB.Get([]byte(s), nil)
|
|
|
|
|
if errDB != nil {
|
|
|
|
|
fmt.Println("Cant READ DB :" , errDB.Error() )
|
|
|
|
|
fmt.Println("Cant READ DB:" , errDB.Error() )
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -77,7 +87,10 @@ func GetDomainFromCache(s string) *dns.Msg {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if time.Since(record.Date) > (time.Duration(ZabovCacheTTL) * time.Hour) {
|
|
|
|
|
if time.Now().After(record.ExpireDate) {
|
|
|
|
|
if ZabovDebug {
|
|
|
|
|
fmt.Println("GetDomainFromCache(): entry expired:", s)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|