From 81303b5db74705535b9810b7daddd196891079c5 Mon Sep 17 00:00:00 2001 From: Simon Zolin Date: Tue, 23 Jul 2019 15:57:44 +0300 Subject: [PATCH] + config: add cache size settings --- dnsfilter/dnsfilter.go | 11 +++++++---- home/config.go | 4 ++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/dnsfilter/dnsfilter.go b/dnsfilter/dnsfilter.go index 3716139c..b9b8c7d2 100644 --- a/dnsfilter/dnsfilter.go +++ b/dnsfilter/dnsfilter.go @@ -26,7 +26,6 @@ import ( "golang.org/x/net/publicsuffix" ) -const defaultCacheSize = 64 * 1024 // in number of elements const defaultCacheTime = 30 * time.Minute const defaultHTTPTimeout = 5 * time.Minute @@ -56,6 +55,10 @@ type Config struct { SafeBrowsingEnabled bool `yaml:"safebrowsing_enabled"` ResolverAddress string // DNS server address + SafeBrowsingCacheSize int `yaml:"safebrowsing_cache_size"` + SafeSearchCacheSize int `yaml:"safesearch_cache_size"` + ParentalCacheSize int `yaml:"parental_cache_size"` + // Filtering callback function FilterHandler func(clientAddr string, settings *RequestFilteringSettings) `yaml:"-"` } @@ -732,13 +735,13 @@ func New(c *Config, filters map[int]string) *Dnsfilter { if c != nil { // initialize objects only once if gctx.safebrowsingCache == nil { - gctx.safebrowsingCache = gcache.New(defaultCacheSize).LRU().Expiration(defaultCacheTime).Build() + gctx.safebrowsingCache = gcache.New(c.SafeBrowsingCacheSize).LRU().Expiration(defaultCacheTime).Build() } if gctx.safeSearchCache == nil { - gctx.safeSearchCache = gcache.New(defaultCacheSize).LRU().Expiration(defaultCacheTime).Build() + gctx.safeSearchCache = gcache.New(c.SafeSearchCacheSize).LRU().Expiration(defaultCacheTime).Build() } if gctx.parentalCache == nil { - gctx.parentalCache = gcache.New(defaultCacheSize).LRU().Expiration(defaultCacheTime).Build() + gctx.parentalCache = gcache.New(c.ParentalCacheSize).LRU().Expiration(defaultCacheTime).Build() } if len(c.ResolverAddress) != 0 && gctx.dialCache == nil { gctx.dialCache = gcache.New(maxDialCacheSize).LRU().Expiration(defaultCacheTime).Build() diff --git a/home/config.go b/home/config.go index 079a9298..9fa4cbad 100644 --- a/home/config.go +++ b/home/config.go @@ -205,6 +205,10 @@ func initConfig() { // also change the default config config.DNS.UpstreamDNS = defaultDNS } + + config.DNS.SafeBrowsingCacheSize = 64 * 1024 + config.DNS.SafeSearchCacheSize = 64 * 1024 + config.DNS.ParentalCacheSize = 64 * 1024 } // getConfigFilename returns path to the current config file