From e9d20651e98adbae88161a6458bdaa12c9624fcb Mon Sep 17 00:00:00 2001 From: Aleksey Dmitrevskiy Date: Thu, 14 Mar 2019 18:06:53 +0300 Subject: [PATCH 1/2] Fix #606, Fix #610 [change] app, config: add symlink support, allow to specify absolute path in log_file --- app.go | 6 +++++- config.go | 10 ++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app.go b/app.go index 18d45b2e..91f4fbdd 100644 --- a/app.go +++ b/app.go @@ -288,7 +288,11 @@ func configureLogger(args options) { } } else { logFilePath := filepath.Join(config.ourWorkingDir, ls.LogFile) - file, err := os.OpenFile(logFilePath, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0755) + if filepath.IsAbs(ls.LogFile) { + logFilePath = ls.LogFile + } + + file, err := os.OpenFile(logFilePath, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644) if err != nil { log.Fatalf("cannot create a log file: %s", err) } diff --git a/config.go b/config.go index 05888888..b0da6532 100644 --- a/config.go +++ b/config.go @@ -137,9 +137,15 @@ var config = configuration{ // getConfigFilename returns path to the current config file func (c *configuration) getConfigFilename() string { - configFile := config.ourConfigFilename + configFile, err := filepath.EvalSymlinks(config.ourConfigFilename) + if err != nil { + if !os.IsNotExist(err) { + log.Error("unexpected error while config file path evaluation: %s", err) + } + configFile = config.ourConfigFilename + } if !filepath.IsAbs(configFile) { - configFile = filepath.Join(config.ourWorkingDir, config.ourConfigFilename) + configFile = filepath.Join(config.ourWorkingDir, configFile) } return configFile } From 6b223e2992f45aaba7ae9d685a741bd76c23d284 Mon Sep 17 00:00:00 2001 From: Aleksey Dmitrevskiy Date: Mon, 18 Mar 2019 14:50:33 +0300 Subject: [PATCH 2/2] * dnsfilter: extend logging --- dnsfilter/dnsfilter.go | 17 +++++++++++++++++ go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/dnsfilter/dnsfilter.go b/dnsfilter/dnsfilter.go index b33465f9..83818f1b 100644 --- a/dnsfilter/dnsfilter.go +++ b/dnsfilter/dnsfilter.go @@ -600,6 +600,11 @@ func hostnameToHashParam(host string, addslash bool) (string, map[string]bool) { } func (d *Dnsfilter) checkSafeSearch(host string) (Result, error) { + if log.GetLevel() >= log.DEBUG { + timer := log.StartTimer() + defer timer.LogElapsed("SafeSearch HTTP lookup for %s", host) + } + if safeSearchCache == nil { safeSearchCache = gcache.New(defaultCacheSize).LRU().Expiration(defaultCacheTime).Build() } @@ -608,6 +613,7 @@ func (d *Dnsfilter) checkSafeSearch(host string) (Result, error) { cachedValue, isFound, err := getCachedReason(safeSearchCache, host) if isFound { atomic.AddUint64(&stats.Safesearch.CacheHits, 1) + log.Tracef("%s: found in SafeSearch cache", host) return cachedValue, nil } @@ -656,6 +662,11 @@ func (d *Dnsfilter) checkSafeSearch(host string) (Result, error) { } func (d *Dnsfilter) checkSafeBrowsing(host string) (Result, error) { + if log.GetLevel() >= log.DEBUG { + timer := log.StartTimer() + defer timer.LogElapsed("SafeBrowsing HTTP lookup for %s", host) + } + // prevent recursion -- checking the host of safebrowsing server makes no sense if host == d.safeBrowsingServer { return Result{}, nil @@ -697,6 +708,11 @@ func (d *Dnsfilter) checkSafeBrowsing(host string) (Result, error) { } func (d *Dnsfilter) checkParental(host string) (Result, error) { + if log.GetLevel() >= log.DEBUG { + timer := log.StartTimer() + defer timer.LogElapsed("Parental HTTP lookup for %s", host) + } + // prevent recursion -- checking the host of parental safety server makes no sense if host == d.parentalServer { return Result{}, nil @@ -754,6 +770,7 @@ func (d *Dnsfilter) lookupCommon(host string, lookupstats *LookupStats, cache gc cachedValue, isFound, err := getCachedReason(cache, host) if isFound { atomic.AddUint64(&lookupstats.CacheHits, 1) + log.Tracef("%s: found in the lookup cache", host) return cachedValue, nil } if err != nil { diff --git a/go.mod b/go.mod index 62035c9c..01918844 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.12 require ( github.com/AdguardTeam/dnsproxy v0.11.2 - github.com/AdguardTeam/golibs v0.1.1 + github.com/AdguardTeam/golibs v0.1.3 github.com/StackExchange/wmi v0.0.0-20180725035823-b12b22c5341f // indirect github.com/bluele/gcache v0.0.0-20171010155617-472614239ac7 github.com/go-ole/go-ole v1.2.1 // indirect diff --git a/go.sum b/go.sum index c4bced69..fbd89b79 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,8 @@ github.com/AdguardTeam/dnsproxy v0.11.2 h1:S/Ag2q9qoZsmW1fvMohPZP7/5amEtz8NmFCp8kxUalQ= github.com/AdguardTeam/dnsproxy v0.11.2/go.mod h1:EPp92b5cYR7HZpO+OQu6xC7AyhUoBaXW3sfa3exq/0I= github.com/AdguardTeam/golibs v0.1.0/go.mod h1:zhi6xGwK4cMpjDocybhhLgvcGkstiSIjlpKbvyxC5Yc= -github.com/AdguardTeam/golibs v0.1.1 h1:aepIN7yulf8I4Ub2c0cAaIizfSHPVXB2wrh8j4BJxl4= -github.com/AdguardTeam/golibs v0.1.1/go.mod h1:b0XkhgIcn2TxwX6C5AQMtpIFAgjPehNgxJErWkwA3ko= +github.com/AdguardTeam/golibs v0.1.3 h1:hmapdTtMtIk3T8eQDwTOLdqZLGDKNKk9325uC8z12xg= +github.com/AdguardTeam/golibs v0.1.3/go.mod h1:b0XkhgIcn2TxwX6C5AQMtpIFAgjPehNgxJErWkwA3ko= github.com/StackExchange/wmi v0.0.0-20180725035823-b12b22c5341f h1:5ZfJxyXo8KyX8DgGXC5B7ILL8y51fci/qYz2B4j8iLY= github.com/StackExchange/wmi v0.0.0-20180725035823-b12b22c5341f/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da h1:KjTM2ks9d14ZYCvmHS9iAKVt9AyzRSqNU1qabPih5BY=