docstring_tokens
stringlengths
0
76.5k
code_tokens
stringlengths
75
1.81M
label_window
sequencelengths
4
2.12k
html_url
stringlengths
74
116
file_name
stringlengths
3
311
filters := []Filter{{
<mask> func TestWhitelist(t *testing.T) { <mask> rules := `||host1^ <mask> ||host2^ <mask> ` <mask> filters := []Filter{Filter{ <mask> ID: 0, Data: []byte(rules), <mask> }} <mask> <mask> whiteRules := `||host1^ <mask> ||host3^ </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove whiteFilters := []Filter{Filter{ </s> add whiteFilters := []Filter{{ </s> remove filters := []Filter{Filter{ </s> add filters := []Filter{{ </s> remove filters := []Filter{Filter{ </s> add filters := []Filter{{ </s> remove filters := []Filter{Filter{ </s> add filters := []Filter{{ </s> remove if err != nil { return false } return true </s> add return err == nil
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dnsfilter/dnsfilter_test.go
whiteFilters := []Filter{{
<mask> <mask> whiteRules := `||host1^ <mask> ||host3^ <mask> ` <mask> whiteFilters := []Filter{Filter{ <mask> ID: 0, Data: []byte(whiteRules), <mask> }} <mask> d := NewForTest(nil, filters) <mask> d.SetFilters(filters, whiteFilters, false) <mask> defer d.Close() </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove filters := []Filter{Filter{ </s> add filters := []Filter{{ </s> remove filters := []Filter{Filter{ </s> add filters := []Filter{{ </s> remove filters := []Filter{Filter{ </s> add filters := []Filter{{ </s> remove filters := []Filter{Filter{ </s> add filters := []Filter{{ </s> remove func prepareTestDir() string { const dir = "./agh-test" _ = os.RemoveAll(dir) _ = os.MkdirAll(dir, 0755) return dir } </s> add
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dnsfilter/dnsfilter_test.go
filters := []Filter{{
<mask> // Check behaviour without any per-client settings, <mask> // then apply per-client settings and check behaviour once again <mask> func TestClientSettings(t *testing.T) { <mask> var r Result <mask> filters := []Filter{Filter{ <mask> ID: 0, Data: []byte("||example.org^\n"), <mask> }} <mask> d := NewForTest(&Config{ParentalEnabled: true, SafeBrowsingEnabled: false}, filters) <mask> defer d.Close() <mask> </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove filters := []Filter{Filter{ </s> add filters := []Filter{{ </s> remove filters := []Filter{Filter{ </s> add filters := []Filter{{ </s> remove whiteFilters := []Filter{Filter{ </s> add whiteFilters := []Filter{{ </s> remove filters := []Filter{Filter{ </s> add filters := []Filter{{ </s> remove var ip string ip = <-r.ipChannel </s> add ip := <-r.ipChannel
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dnsfilter/dnsfilter_test.go
<mask> r, _ = d.CheckHost("facebook.com", dns.TypeA, &setts) <mask> assert.True(t, r.IsFiltered && r.Reason == FilteredBlockedService) <mask> } <mask> <mask> func prepareTestDir() string { <mask> const dir = "./agh-test" <mask> _ = os.RemoveAll(dir) <mask> _ = os.MkdirAll(dir, 0755) <mask> return dir <mask> } <mask> <mask> // BENCHMARKS <mask> <mask> func BenchmarkSafeBrowsing(b *testing.B) { <mask> d := NewForTest(&Config{SafeBrowsingEnabled: true}, nil) <mask> defer d.Close() </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove q += fmt.Sprintf("%s.", hex.EncodeToString(hash[0:2])) </s> add // Ignore errors, since strings.(*Buffer).Write never returns // errors. // // TODO(e.burkov, a.garipov): Find out and document why exactly // this slice. _, _ = encoder.Write(hash[0:2]) _, _ = b.WriteRune('.') </s> remove case _ = <-a.watcher.Events: // skip this event </s> add case <-a.watcher.Events: // Skip this duplicating event </s> remove // skip duplicate events </s> add </s> remove return q </s> add // See comment above. _, _ = b.WriteString(pcTXTSuffix) return b.String() </s> remove func (w *Whois) query(target string, serverAddr string) (string, error) { </s> add func (w *Whois) query(target, serverAddr string) (string, error) {
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dnsfilter/dnsfilter_test.go
exp := make([]byte, 4)
<mask> func (d *Dnsfilter) setCacheResult(cache cache.Cache, host string, res Result) int { <mask> var buf bytes.Buffer <mask> <mask> expire := uint(time.Now().Unix()) + d.Config.CacheTime*60 <mask> var exp []byte <mask> exp = make([]byte, 4) <mask> binary.BigEndian.PutUint32(exp, uint32(expire)) <mask> _, _ = buf.Write(exp) <mask> <mask> enc := gob.NewEncoder(&buf) <mask> err := enc.Encode(res) </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove func (c *sbCtx) setCache(prefix []byte, hashes []byte) { </s> add func (c *sbCtx) setCache(prefix, hashes []byte) { </s> remove /* expire byte[4] name_len byte[2] name byte[] */ </s> add </s> remove var data []byte data = make([]byte, 4+2+len(s.userName)) </s> add const ( expireLen = 4 nameLen = 2 ) data := make([]byte, expireLen+nameLen+len(s.userName)) </s> remove func (d *Dnsfilter) checkMatchIP(t *testing.T, hostname string, ip string, qtype uint16) { </s> add func (d *Dnsfilter) checkMatchIP(t *testing.T, hostname, ip string, qtype uint16) { </s> remove func (w *Whois) query(target string, serverAddr string) (string, error) { </s> add func (w *Whois) query(target, serverAddr string) (string, error) {
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dnsfilter/safe_search.go
const ( dnsTimeout = 3 * time.Second defaultSafebrowsingServer = `https://dns-family.adguard.com/dns-query` defaultParentalServer = `https://dns-family.adguard.com/dns-query` sbTXTSuffix = `sb.dns.adguard.com.` pcTXTSuffix = `pc.dns.adguard.com.` )
<mask> "github.com/miekg/dns" <mask> "golang.org/x/net/publicsuffix" <mask> ) <mask> <mask> const dnsTimeout = 3 * time.Second <mask> const defaultSafebrowsingServer = "https://dns-family.adguard.com/dns-query" <mask> const defaultParentalServer = "https://dns-family.adguard.com/dns-query" <mask> const sbTXTSuffix = "sb.dns.adguard.com." <mask> const pcTXTSuffix = "pc.dns.adguard.com." <mask> <mask> func (d *Dnsfilter) initSecurityServices() error { <mask> var err error <mask> d.safeBrowsingServer = defaultSafebrowsingServer <mask> d.parentalServer = defaultParentalServer </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove var blockingRules = "||example.org^\n" var whitelistRules = "||example.org^\n@@||test.example.org\n" var importantRules = "@@||example.org^\n||test.example.org^$important\n" var regexRules = "/example\\.org/\n@@||test.example.org^\n" var maskRules = "test*.example.org^\nexam*.com\n" </s> add const nl = "\n" const ( blockingRules = `||example.org^` + nl whitelistRules = `||example.org^` + nl + `@@||test.example.org` + nl importantRules = `@@||example.org^` + nl + `||test.example.org^$important` + nl regexRules = `/example\.org/` + nl + `@@||test.example.org^` + nl maskRules = `test*.example.org^` + nl + `exam*.com` + nl ) </s> remove var data []byte data = make([]byte, 4+2+len(s.userName)) </s> add const ( expireLen = 4 nameLen = 2 ) data := make([]byte, expireLen+nameLen+len(s.userName)) </s> remove func prepareTestDir() string { const dir = "./agh-test" _ = os.RemoveAll(dir) _ = os.MkdirAll(dir, 0755) return dir } </s> add </s> remove var exp []byte exp = make([]byte, 4) </s> add exp := make([]byte, 4) </s> remove s.db, err = bolt.Open(s.conf.Filename, 0644, nil) </s> add s.db, err = bolt.Open(s.conf.Filename, 0o644, nil)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dnsfilter/sb_pc.go
func (c *sbCtx) setCache(prefix, hashes []byte) {
<mask> expire byte[4] <mask> hash byte[32] <mask> ... <mask> */ <mask> func (c *sbCtx) setCache(prefix []byte, hashes []byte) { <mask> d := make([]byte, 4+len(hashes)) <mask> expire := uint(time.Now().Unix()) + c.cacheTime*60 <mask> binary.BigEndian.PutUint32(d[:4], uint32(expire)) <mask> copy(d[4:], hashes) <mask> c.cache.Set(prefix, d) </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove var exp []byte exp = make([]byte, 4) </s> add exp := make([]byte, 4) </s> remove /* expire byte[4] name_len byte[2] name byte[] */ </s> add </s> remove q := "" </s> add b := &strings.Builder{} encoder := hex.NewEncoder(b) </s> remove return q </s> add // See comment above. _, _ = b.WriteString(pcTXTSuffix) return b.String() </s> remove q += fmt.Sprintf("%s.", hex.EncodeToString(hash[0:2])) </s> add // Ignore errors, since strings.(*Buffer).Write never returns // errors. // // TODO(e.burkov, a.garipov): Find out and document why exactly // this slice. _, _ = encoder.Write(hash[0:2]) _, _ = b.WriteRune('.')
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dnsfilter/sb_pc.go
b := &strings.Builder{} encoder := hex.NewEncoder(b)
<mask> } <mask> <mask> // convert hash array to string <mask> func (c *sbCtx) getQuestion() string { <mask> q := "" <mask> for hash := range c.hashToHost { <mask> q += fmt.Sprintf("%s.", hex.EncodeToString(hash[0:2])) <mask> } <mask> if c.svc == "SafeBrowsing" { <mask> q += sbTXTSuffix </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove q += fmt.Sprintf("%s.", hex.EncodeToString(hash[0:2])) </s> add // Ignore errors, since strings.(*Buffer).Write never returns // errors. // // TODO(e.burkov, a.garipov): Find out and document why exactly // this slice. _, _ = encoder.Write(hash[0:2]) _, _ = b.WriteRune('.') </s> remove q += sbTXTSuffix } else { q += pcTXTSuffix </s> add // See comment above. _, _ = b.WriteString(sbTXTSuffix) return b.String() </s> remove return q </s> add // See comment above. _, _ = b.WriteString(pcTXTSuffix) return b.String() </s> remove // ContainsString checks if "v" is in the array "arr" func ContainsString(arr []string, v string) bool { for _, i := range arr { if i == v { </s> add // ContainsString checks if string is in the slice of strings. func ContainsString(strs []string, str string) bool { for _, s := range strs { if s == str { </s> remove func (c *sbCtx) setCache(prefix []byte, hashes []byte) { </s> add func (c *sbCtx) setCache(prefix, hashes []byte) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dnsfilter/sb_pc.go
// Ignore errors, since strings.(*Buffer).Write never returns // errors. // // TODO(e.burkov, a.garipov): Find out and document why exactly // this slice. _, _ = encoder.Write(hash[0:2]) _, _ = b.WriteRune('.')
<mask> // convert hash array to string <mask> func (c *sbCtx) getQuestion() string { <mask> q := "" <mask> for hash := range c.hashToHost { <mask> q += fmt.Sprintf("%s.", hex.EncodeToString(hash[0:2])) <mask> } <mask> if c.svc == "SafeBrowsing" { <mask> q += sbTXTSuffix <mask> } else { <mask> q += pcTXTSuffix </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove q := "" </s> add b := &strings.Builder{} encoder := hex.NewEncoder(b) </s> remove q += sbTXTSuffix } else { q += pcTXTSuffix </s> add // See comment above. _, _ = b.WriteString(sbTXTSuffix) return b.String() </s> remove return q </s> add // See comment above. _, _ = b.WriteString(pcTXTSuffix) return b.String() </s> remove // ContainsString checks if "v" is in the array "arr" func ContainsString(arr []string, v string) bool { for _, i := range arr { if i == v { </s> add // ContainsString checks if string is in the slice of strings. func ContainsString(strs []string, str string) bool { for _, s := range strs { if s == str { </s> remove // gather full buffer firstChunk and perform its data tests num := util.MinInt(n, len(firstChunk)-firstChunkLen) </s> add num := len(firstChunk) - firstChunkLen if n < num { num = n }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dnsfilter/sb_pc.go
// See comment above. _, _ = b.WriteString(sbTXTSuffix) return b.String()
<mask> for hash := range c.hashToHost { <mask> q += fmt.Sprintf("%s.", hex.EncodeToString(hash[0:2])) <mask> } <mask> if c.svc == "SafeBrowsing" { <mask> q += sbTXTSuffix <mask> } else { <mask> q += pcTXTSuffix <mask> } <mask> return q <mask> } <mask> <mask> // Find the target hash in TXT response </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove q := "" </s> add b := &strings.Builder{} encoder := hex.NewEncoder(b) </s> remove return q </s> add // See comment above. _, _ = b.WriteString(pcTXTSuffix) return b.String() </s> remove q += fmt.Sprintf("%s.", hex.EncodeToString(hash[0:2])) </s> add // Ignore errors, since strings.(*Buffer).Write never returns // errors. // // TODO(e.burkov, a.garipov): Find out and document why exactly // this slice. _, _ = encoder.Write(hash[0:2]) _, _ = b.WriteRune('.') </s> remove // ContainsString checks if "v" is in the array "arr" func ContainsString(arr []string, v string) bool { for _, i := range arr { if i == v { </s> add // ContainsString checks if string is in the slice of strings. func ContainsString(strs []string, str string) bool { for _, s := range strs { if s == str { </s> remove // gather full buffer firstChunk and perform its data tests num := util.MinInt(n, len(firstChunk)-firstChunkLen) </s> add num := len(firstChunk) - firstChunkLen if n < num { num = n }
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dnsfilter/sb_pc.go
// See comment above. _, _ = b.WriteString(pcTXTSuffix) return b.String()
<mask> q += sbTXTSuffix <mask> } else { <mask> q += pcTXTSuffix <mask> } <mask> return q <mask> } <mask> <mask> // Find the target hash in TXT response <mask> func (c *sbCtx) processTXT(resp *dns.Msg) (bool, [][]byte) { <mask> matched := false </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove q += sbTXTSuffix } else { q += pcTXTSuffix </s> add // See comment above. _, _ = b.WriteString(sbTXTSuffix) return b.String() </s> remove q += fmt.Sprintf("%s.", hex.EncodeToString(hash[0:2])) </s> add // Ignore errors, since strings.(*Buffer).Write never returns // errors. // // TODO(e.burkov, a.garipov): Find out and document why exactly // this slice. _, _ = encoder.Write(hash[0:2]) _, _ = b.WriteRune('.') </s> remove q := "" </s> add b := &strings.Builder{} encoder := hex.NewEncoder(b) </s> remove func (w *Whois) query(target string, serverAddr string) (string, error) { </s> add func (w *Whois) query(target, serverAddr string) (string, error) { </s> remove func (c *sbCtx) setCache(prefix []byte, hashes []byte) { </s> add func (c *sbCtx) setCache(prefix, hashes []byte) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dnsfilter/sb_pc.go
svc: "SafeBrowsing", hashToHost: hashes,
<mask> _, ok = hashes[sha256.Sum256([]byte("com"))] <mask> assert.False(t, ok) <mask> <mask> c := &sbCtx{ <mask> svc: "SafeBrowsing", <mask> } <mask> <mask> // test getQuestion() <mask> c.hashToHost = hashes <mask> q := c.getQuestion() </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove // test getQuestion() c.hashToHost = hashes </s> add </s> remove assert.True(t, strings.Index(q, "7a1b.") >= 0) assert.True(t, strings.Index(q, "af5a.") >= 0) assert.True(t, strings.Index(q, "eb11.") >= 0) assert.True(t, strings.Index(q, "sb.dns.adguard.com.") > 0) </s> add assert.True(t, strings.Contains(q, "7a1b.")) assert.True(t, strings.Contains(q, "af5a.")) assert.True(t, strings.Contains(q, "eb11.")) assert.True(t, strings.HasSuffix(q, "sb.dns.adguard.com.")) </s> remove q += fmt.Sprintf("%s.", hex.EncodeToString(hash[0:2])) </s> add // Ignore errors, since strings.(*Buffer).Write never returns // errors. // // TODO(e.burkov, a.garipov): Find out and document why exactly // this slice. _, _ = encoder.Write(hash[0:2]) _, _ = b.WriteRune('.') </s> remove q := "" </s> add b := &strings.Builder{} encoder := hex.NewEncoder(b) </s> remove q += sbTXTSuffix } else { q += pcTXTSuffix </s> add // See comment above. _, _ = b.WriteString(sbTXTSuffix) return b.String()
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dnsfilter/sb_pc_test.go
<mask> c := &sbCtx{ <mask> svc: "SafeBrowsing", <mask> } <mask> <mask> // test getQuestion() <mask> c.hashToHost = hashes <mask> q := c.getQuestion() <mask> assert.True(t, strings.Index(q, "7a1b.") >= 0) <mask> assert.True(t, strings.Index(q, "af5a.") >= 0) <mask> assert.True(t, strings.Index(q, "eb11.") >= 0) <mask> assert.True(t, strings.Index(q, "sb.dns.adguard.com.") > 0) </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove assert.True(t, strings.Index(q, "7a1b.") >= 0) assert.True(t, strings.Index(q, "af5a.") >= 0) assert.True(t, strings.Index(q, "eb11.") >= 0) assert.True(t, strings.Index(q, "sb.dns.adguard.com.") > 0) </s> add assert.True(t, strings.Contains(q, "7a1b.")) assert.True(t, strings.Contains(q, "af5a.")) assert.True(t, strings.Contains(q, "eb11.")) assert.True(t, strings.HasSuffix(q, "sb.dns.adguard.com.")) </s> remove svc: "SafeBrowsing", </s> add svc: "SafeBrowsing", hashToHost: hashes, </s> remove m := make(map[string]string, 0) </s> add m := make(map[string]string) </s> remove func prepareTestDir() string { const dir = "./agh-test" _ = os.RemoveAll(dir) _ = os.MkdirAll(dir, 0755) return dir } </s> add </s> remove if a[i].Count >= a[j].Count { return true } return false </s> add return a[j].Count < a[i].Count
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dnsfilter/sb_pc_test.go
assert.True(t, strings.Contains(q, "7a1b.")) assert.True(t, strings.Contains(q, "af5a.")) assert.True(t, strings.Contains(q, "eb11.")) assert.True(t, strings.HasSuffix(q, "sb.dns.adguard.com."))
<mask> <mask> // test getQuestion() <mask> c.hashToHost = hashes <mask> q := c.getQuestion() <mask> assert.True(t, strings.Index(q, "7a1b.") >= 0) <mask> assert.True(t, strings.Index(q, "af5a.") >= 0) <mask> assert.True(t, strings.Index(q, "eb11.") >= 0) <mask> assert.True(t, strings.Index(q, "sb.dns.adguard.com.") > 0) <mask> } <mask> <mask> func TestSafeBrowsingCache(t *testing.T) { <mask> c := &sbCtx{ <mask> svc: "SafeBrowsing", </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove // test getQuestion() c.hashToHost = hashes </s> add </s> remove svc: "SafeBrowsing", </s> add svc: "SafeBrowsing", hashToHost: hashes, </s> remove func prepareTestDir() string { const dir = "./agh-test" _ = os.RemoveAll(dir) _ = os.MkdirAll(dir, 0755) return dir } </s> add </s> remove m := make(map[string]string, 0) </s> add m := make(map[string]string) </s> remove if a[i].Count >= a[j].Count { return true } return false </s> add return a[j].Count < a[i].Count
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/dnsfilter/sb_pc_test.go
<mask> userName string <mask> expire uint32 // expiration time (in seconds) <mask> } <mask> <mask> /* <mask> expire byte[4] <mask> name_len byte[2] <mask> name byte[] <mask> */ <mask> func (s *session) serialize() []byte { <mask> var data []byte <mask> data = make([]byte, 4+2+len(s.userName)) <mask> binary.BigEndian.PutUint32(data[0:4], s.expire) <mask> binary.BigEndian.PutUint16(data[4:6], uint16(len(s.userName))) </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove var data []byte data = make([]byte, 4+2+len(s.userName)) </s> add const ( expireLen = 4 nameLen = 2 ) data := make([]byte, expireLen+nameLen+len(s.userName)) </s> remove func (c *sbCtx) setCache(prefix []byte, hashes []byte) { </s> add func (c *sbCtx) setCache(prefix, hashes []byte) { </s> remove var exp []byte exp = make([]byte, 4) </s> add exp := make([]byte, 4) </s> remove var hour int32 hour = 1 </s> add var hour int32 = 1 </s> remove // gather full buffer firstChunk and perform its data tests num := util.MinInt(n, len(firstChunk)-firstChunkLen) </s> add num := len(firstChunk) - firstChunkLen if n < num { num = n }
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/home/auth.go
const ( expireLen = 4 nameLen = 2 ) data := make([]byte, expireLen+nameLen+len(s.userName))
<mask> name_len byte[2] <mask> name byte[] <mask> */ <mask> func (s *session) serialize() []byte { <mask> var data []byte <mask> data = make([]byte, 4+2+len(s.userName)) <mask> binary.BigEndian.PutUint32(data[0:4], s.expire) <mask> binary.BigEndian.PutUint16(data[4:6], uint16(len(s.userName))) <mask> copy(data[6:], []byte(s.userName)) <mask> return data <mask> } </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove /* expire byte[4] name_len byte[2] name byte[] */ </s> add </s> remove var exp []byte exp = make([]byte, 4) </s> add exp := make([]byte, 4) </s> remove // gather full buffer firstChunk and perform its data tests num := util.MinInt(n, len(firstChunk)-firstChunkLen) </s> add num := len(firstChunk) - firstChunkLen if n < num { num = n } </s> remove func (c *sbCtx) setCache(prefix []byte, hashes []byte) { </s> add func (c *sbCtx) setCache(prefix, hashes []byte) { </s> remove s.db, err = bolt.Open(s.conf.Filename, 0644, nil) </s> add s.db, err = bolt.Open(s.conf.Filename, 0o644, nil)
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/home/auth.go
func (a *Auth) UserFind(login, password string) User {
<mask> log.Debug("Auth: added user: %s", u.Name) <mask> } <mask> <mask> // UserFind - find a user <mask> func (a *Auth) UserFind(login string, password string) User { <mask> a.lock.Lock() <mask> defer a.lock.Unlock() <mask> for _, u := range a.users { <mask> if u.Name == login && <mask> bcrypt.CompareHashAndPassword([]byte(u.PasswordHash), []byte(password)) == nil { </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove if err != nil { return false } return true </s> add return err == nil </s> remove // ContainsString checks if "v" is in the array "arr" func ContainsString(arr []string, v string) bool { for _, i := range arr { if i == v { </s> add // ContainsString checks if string is in the slice of strings. func ContainsString(strs []string, str string) bool { for _, s := range strs { if s == str { </s> remove if err != nil { return false } return true </s> add return err == nil </s> remove for { select { case ok := <-a.updateChan: if !ok { log.Debug("Finished AutoHosts update loop") return } a.updateHosts() </s> add for ok := range a.updateChan { if !ok { log.Debug("Finished AutoHosts update loop") return </s> remove // Process - get the list of IP addresses for the hostname // Return nil if not found </s> add // Process returns the list of IP addresses for the hostname or nil if nothing // found.
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/home/auth.go
<mask> "sync/atomic" <mask> "time" <mask> <mask> "github.com/AdguardTeam/AdGuardHome/internal/dnsfilter" <mask> "github.com/AdguardTeam/AdGuardHome/internal/util" <mask> "github.com/AdguardTeam/golibs/log" <mask> ) <mask> <mask> var nextFilterID = time.Now().Unix() // semi-stable way to generate an unique ID <mask> </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove var ( // DefaultServers is the address of all link-local DHCP servers and // relay agents. DefaultServers = &net.UDPAddr{ IP: net.IPv4bcast, Port: ServerPort, } ) </s> add // DefaultServers is the address of all link-local DHCP servers and // relay agents. var DefaultServers = &net.UDPAddr{ IP: net.IPv4bcast, Port: ServerPort, } </s> remove var blockingRules = "||example.org^\n" var whitelistRules = "||example.org^\n@@||test.example.org\n" var importantRules = "@@||example.org^\n||test.example.org^$important\n" var regexRules = "/example\\.org/\n@@||test.example.org^\n" var maskRules = "test*.example.org^\nexam*.com\n" </s> add const nl = "\n" const ( blockingRules = `||example.org^` + nl whitelistRules = `||example.org^` + nl + `@@||test.example.org` + nl importantRules = `@@||example.org^` + nl + `||test.example.org^$important` + nl regexRules = `/example\.org/` + nl + `@@||test.example.org^` + nl maskRules = `test*.example.org^` + nl + `exam*.com` + nl ) </s> remove data.WarningValidation = fmt.Sprintf("You have specified an empty certificate") </s> add data.WarningValidation = "You have specified an empty certificate" </s> remove // matchHost is a low-level way to check only if hostname is filtered by rules, skipping expensive safebrowsing and parental lookups </s> add // matchHost is a low-level way to check only if hostname is filtered by rules, // skipping expensive safebrowsing and parental lookups. </s> remove s.db, err = bolt.Open(s.conf.Filename, 0644, nil) </s> add s.db, err = bolt.Open(s.conf.Filename, 0o644, nil)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/home/filter.go
num := len(firstChunk) - firstChunkLen if n < num { num = n }
<mask> n, err := reader.Read(buf) <mask> total += n <mask> <mask> if htmlTest { <mask> // gather full buffer firstChunk and perform its data tests <mask> num := util.MinInt(n, len(firstChunk)-firstChunkLen) <mask> copied := copy(firstChunk[firstChunkLen:], buf[:num]) <mask> firstChunkLen += copied <mask> <mask> if firstChunkLen == len(firstChunk) || err == io.EOF { <mask> if !isPrintableText(firstChunk, firstChunkLen) { </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove q := "" </s> add b := &strings.Builder{} encoder := hex.NewEncoder(b) </s> remove if strings.Index(s, "<html") >= 0 || strings.Index(s, "<!doctype") >= 0 { </s> add if strings.Contains(s, "<html") || strings.Contains(s, "<!doctype") { </s> remove q += fmt.Sprintf("%s.", hex.EncodeToString(hash[0:2])) </s> add // Ignore errors, since strings.(*Buffer).Write never returns // errors. // // TODO(e.burkov, a.garipov): Find out and document why exactly // this slice. _, _ = encoder.Write(hash[0:2]) _, _ = b.WriteRune('.') </s> remove q += sbTXTSuffix } else { q += pcTXTSuffix </s> add // See comment above. _, _ = b.WriteString(sbTXTSuffix) return b.String() </s> remove if err != nil { return false } return true </s> add return err == nil
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/home/filter.go
if strings.Contains(s, "<html") || strings.Contains(s, "<!doctype") {
<mask> return false, fmt.Errorf("data contains non-printable characters") <mask> } <mask> <mask> s := strings.ToLower(string(firstChunk)) <mask> if strings.Index(s, "<html") >= 0 || <mask> strings.Index(s, "<!doctype") >= 0 { <mask> return false, fmt.Errorf("data is HTML, not plain text") <mask> } <mask> <mask> htmlTest = false <mask> firstChunk = nil </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove if a[i].Count >= a[j].Count { return true } return false </s> add return a[j].Count < a[i].Count </s> remove // gather full buffer firstChunk and perform its data tests num := util.MinInt(n, len(firstChunk)-firstChunkLen) </s> add num := len(firstChunk) - firstChunkLen if n < num { num = n } </s> remove // test getQuestion() c.hashToHost = hashes </s> add </s> remove ips, _ := a.table[host] if len(ips) != 0 { </s> add if ips, ok := a.table[host]; ok { </s> remove if IsOpenWrt() { </s> add if IsOpenWRT() {
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/home/filter.go
func Main(version, channel, armVer string) {
<mask> // Context - a global context object <mask> var Context homeContext <mask> <mask> // Main is the entry point <mask> func Main(version string, channel string, armVer string) { <mask> // Init update-related global variables <mask> versionString = version <mask> updateChannel = channel <mask> ARMVersion = armVer <mask> versionCheckURL = "https://static.adguard.com/adguardhome/" + updateChannel + "/version.json" </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove var blockingRules = "||example.org^\n" var whitelistRules = "||example.org^\n@@||test.example.org\n" var importantRules = "@@||example.org^\n||test.example.org^$important\n" var regexRules = "/example\\.org/\n@@||test.example.org^\n" var maskRules = "test*.example.org^\nexam*.com\n" </s> add const nl = "\n" const ( blockingRules = `||example.org^` + nl whitelistRules = `||example.org^` + nl + `@@||test.example.org` + nl importantRules = `@@||example.org^` + nl + `||test.example.org^$important` + nl regexRules = `/example\.org/` + nl + `@@||test.example.org^` + nl maskRules = `test*.example.org^` + nl + `exam*.com` + nl ) </s> remove func (w *Whois) query(target string, serverAddr string) (string, error) { </s> add func (w *Whois) query(target, serverAddr string) (string, error) { </s> remove var exp []byte exp = make([]byte, 4) </s> add exp := make([]byte, 4) </s> remove // Process - get the list of IP addresses for the hostname // Return nil if not found </s> add // Process returns the list of IP addresses for the hostname or nil if nothing // found. </s> remove var ( // DefaultServers is the address of all link-local DHCP servers and // relay agents. DefaultServers = &net.UDPAddr{ IP: net.IPv4bcast, Port: ServerPort, } ) </s> add // DefaultServers is the address of all link-local DHCP servers and // relay agents. var DefaultServers = &net.UDPAddr{ IP: net.IPv4bcast, Port: ServerPort, }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/home/home.go
return os.IsNotExist(err)
<mask> if !filepath.IsAbs(configfile) { <mask> configfile = filepath.Join(Context.workDir, Context.configFilename) <mask> } <mask> _, err := os.Stat(configfile) <mask> if !os.IsNotExist(err) { <mask> // do nothing, file exists <mask> return false <mask> } <mask> return true <mask> } <mask> <mask> // Connect to a remote server resolving hostname using our own DNS server <mask> func customDialContext(ctx context.Context, network, addr string) (net.Conn, error) { <mask> log.Tracef("network:%v addr:%v", network, addr) </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove func (w *Whois) query(target string, serverAddr string) (string, error) { </s> add func (w *Whois) query(target, serverAddr string) (string, error) { </s> remove // fileExists returns TRUE if file exists </s> add // FileExists returns true if file exists. </s> remove if err != nil { return false } return true </s> add return err == nil </s> remove if err != nil { return false } return true </s> add return err == nil </s> remove // Return TRUE if file exists </s> add // fileExists returns true if file exists.
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/home/home.go
msg := fmt.Sprintf("Unable to write response json: %s", err) log.Println(msg) http.Error(w, msg, http.StatusInternalServerError)
<mask> w.Header().Set("Content-Type", "text/plain") <mask> log.Printf("config.Language is %s", config.Language) <mask> _, err := fmt.Fprintf(w, "%s\n", config.Language) <mask> if err != nil { <mask> errorText := fmt.Sprintf("Unable to write response json: %s", err) <mask> log.Println(errorText) <mask> http.Error(w, errorText, http.StatusInternalServerError) <mask> return <mask> } <mask> } <mask> <mask> func handleI18nChangeLanguage(w http.ResponseWriter, r *http.Request) { </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove errorText := fmt.Sprintf("failed to read request body: %s", err) log.Println(errorText) http.Error(w, errorText, http.StatusBadRequest) </s> add msg := fmt.Sprintf("failed to read request body: %s", err) log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> remove errorText := fmt.Sprintf("failed to read request body: %s", err) log.Error(errorText) http.Error(w, errorText, http.StatusBadRequest) </s> add msg := fmt.Sprintf("failed to read request body: %s", err) log.Error(msg) http.Error(w, msg, http.StatusBadRequest) </s> remove errorText := fmt.Sprintf("unknown language specified: %s", language) log.Println(errorText) http.Error(w, errorText, http.StatusBadRequest) </s> add msg := fmt.Sprintf("unknown language specified: %s", language) log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> remove errorText := fmt.Sprintf("empty language specified") log.Println(errorText) http.Error(w, errorText, http.StatusBadRequest) </s> add msg := "empty language specified" log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> remove func (d *Dnsfilter) checkMatchIP(t *testing.T, hostname string, ip string, qtype uint16) { </s> add func (d *Dnsfilter) checkMatchIP(t *testing.T, hostname, ip string, qtype uint16) {
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/home/i18n.go
msg := fmt.Sprintf("failed to read request body: %s", err) log.Println(msg) http.Error(w, msg, http.StatusBadRequest)
<mask> <mask> func handleI18nChangeLanguage(w http.ResponseWriter, r *http.Request) { <mask> body, err := ioutil.ReadAll(r.Body) <mask> if err != nil { <mask> errorText := fmt.Sprintf("failed to read request body: %s", err) <mask> log.Println(errorText) <mask> http.Error(w, errorText, http.StatusBadRequest) <mask> return <mask> } <mask> <mask> language := strings.TrimSpace(string(body)) <mask> if language == "" { </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove errorText := fmt.Sprintf("failed to read request body: %s", err) log.Error(errorText) http.Error(w, errorText, http.StatusBadRequest) </s> add msg := fmt.Sprintf("failed to read request body: %s", err) log.Error(msg) http.Error(w, msg, http.StatusBadRequest) </s> remove errorText := fmt.Sprintf("empty language specified") log.Println(errorText) http.Error(w, errorText, http.StatusBadRequest) </s> add msg := "empty language specified" log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> remove errorText := fmt.Sprintf("Unable to write response json: %s", err) log.Println(errorText) http.Error(w, errorText, http.StatusInternalServerError) </s> add msg := fmt.Sprintf("Unable to write response json: %s", err) log.Println(msg) http.Error(w, msg, http.StatusInternalServerError) </s> remove errorText := fmt.Sprintf("unknown language specified: %s", language) log.Println(errorText) http.Error(w, errorText, http.StatusBadRequest) </s> add msg := fmt.Sprintf("unknown language specified: %s", language) log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> remove errorText := fmt.Sprintf("empty interface name specified") log.Error(errorText) http.Error(w, errorText, http.StatusBadRequest) </s> add msg := "empty interface name specified" log.Error(msg) http.Error(w, msg, http.StatusBadRequest)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/home/i18n.go
msg := "empty language specified" log.Println(msg) http.Error(w, msg, http.StatusBadRequest)
<mask> } <mask> <mask> language := strings.TrimSpace(string(body)) <mask> if language == "" { <mask> errorText := fmt.Sprintf("empty language specified") <mask> log.Println(errorText) <mask> http.Error(w, errorText, http.StatusBadRequest) <mask> return <mask> } <mask> if !isLanguageAllowed(language) { <mask> errorText := fmt.Sprintf("unknown language specified: %s", language) <mask> log.Println(errorText) </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove errorText := fmt.Sprintf("unknown language specified: %s", language) log.Println(errorText) http.Error(w, errorText, http.StatusBadRequest) </s> add msg := fmt.Sprintf("unknown language specified: %s", language) log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> remove errorText := fmt.Sprintf("failed to read request body: %s", err) log.Println(errorText) http.Error(w, errorText, http.StatusBadRequest) </s> add msg := fmt.Sprintf("failed to read request body: %s", err) log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> remove errorText := fmt.Sprintf("empty interface name specified") log.Error(errorText) http.Error(w, errorText, http.StatusBadRequest) </s> add msg := "empty interface name specified" log.Error(msg) http.Error(w, msg, http.StatusBadRequest) </s> remove errorText := fmt.Sprintf("failed to read request body: %s", err) log.Error(errorText) http.Error(w, errorText, http.StatusBadRequest) </s> add msg := fmt.Sprintf("failed to read request body: %s", err) log.Error(msg) http.Error(w, msg, http.StatusBadRequest) </s> remove errorText := fmt.Sprintf("Unable to write response json: %s", err) log.Println(errorText) http.Error(w, errorText, http.StatusInternalServerError) </s> add msg := fmt.Sprintf("Unable to write response json: %s", err) log.Println(msg) http.Error(w, msg, http.StatusInternalServerError)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/home/i18n.go
msg := fmt.Sprintf("unknown language specified: %s", language) log.Println(msg) http.Error(w, msg, http.StatusBadRequest)
<mask> http.Error(w, errorText, http.StatusBadRequest) <mask> return <mask> } <mask> if !isLanguageAllowed(language) { <mask> errorText := fmt.Sprintf("unknown language specified: %s", language) <mask> log.Println(errorText) <mask> http.Error(w, errorText, http.StatusBadRequest) <mask> return <mask> } <mask> <mask> config.Language = language <mask> onConfigModified() </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove errorText := fmt.Sprintf("empty language specified") log.Println(errorText) http.Error(w, errorText, http.StatusBadRequest) </s> add msg := "empty language specified" log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> remove errorText := fmt.Sprintf("failed to read request body: %s", err) log.Println(errorText) http.Error(w, errorText, http.StatusBadRequest) </s> add msg := fmt.Sprintf("failed to read request body: %s", err) log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> remove errorText := fmt.Sprintf("empty interface name specified") log.Error(errorText) http.Error(w, errorText, http.StatusBadRequest) </s> add msg := "empty interface name specified" log.Error(msg) http.Error(w, msg, http.StatusBadRequest) </s> remove errorText := fmt.Sprintf("failed to read request body: %s", err) log.Error(errorText) http.Error(w, errorText, http.StatusBadRequest) </s> add msg := fmt.Sprintf("failed to read request body: %s", err) log.Error(msg) http.Error(w, msg, http.StatusBadRequest) </s> remove errorText := fmt.Sprintf("Unable to write response json: %s", err) log.Println(errorText) http.Error(w, errorText, http.StatusInternalServerError) </s> add msg := fmt.Sprintf("Unable to write response json: %s", err) log.Println(msg) http.Error(w, msg, http.StatusInternalServerError)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/home/i18n.go
for range ticker.C { log.Debug("free os memory") debug.FreeOSMemory()
<mask> // periodically call "debug.FreeOSMemory" so <mask> // that the OS could reclaim the free memory <mask> go func() { <mask> ticker := time.NewTicker(5 * time.Minute) <mask> for { <mask> select { <mask> case t := <-ticker.C: <mask> t.Second() <mask> log.Debug("Free OS memory") <mask> debug.FreeOSMemory() <mask> } <mask> } <mask> }() <mask> } </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove // MinInt - return the minimum value func MinInt(a, b int) int { if a < b { return a } return b } // IsOpenWrt checks if OS is OpenWRT func IsOpenWrt() bool { </s> add // IsOpenWRT checks if OS is OpenWRT. func IsOpenWRT() bool { </s> remove case _ = <-a.watcher.Events: // skip this event </s> add case <-a.watcher.Events: // Skip this duplicating event </s> remove // updateLoop - read static hosts from system files </s> add // updateLoop reads static hosts from system files. </s> remove // skip duplicate events </s> add </s> remove for { select { case ok := <-a.updateChan: if !ok { log.Debug("Finished AutoHosts update loop") return } a.updateHosts() </s> add for ok := range a.updateChan { if !ok { log.Debug("Finished AutoHosts update loop") return
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/home/memory.go
ip := <-r.ipChannel
<mask> // Wait for a signal and then synchronously resolve hostname by IP address <mask> // Add the hostname:IP pair to "Clients" array <mask> func (r *RDNS) workerLoop() { <mask> for { <mask> var ip string <mask> ip = <-r.ipChannel <mask> <mask> host := r.resolve(ip) <mask> if len(host) == 0 { <mask> continue <mask> } </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove var ip string ip = <-w.ipChan </s> add ip := <-w.ipChan </s> remove func ip6InRange(start net.IP, ip net.IP) bool { </s> add func ip6InRange(start, ip net.IP) bool { </s> remove // Process - get the list of IP addresses for the hostname // Return nil if not found </s> add // Process returns the list of IP addresses for the hostname or nil if nothing // found. </s> remove func (d *Dnsfilter) checkMatchIP(t *testing.T, hostname string, ip string, qtype uint16) { </s> add func (d *Dnsfilter) checkMatchIP(t *testing.T, hostname, ip string, qtype uint16) { </s> remove q += fmt.Sprintf("%s.", hex.EncodeToString(hash[0:2])) </s> add // Ignore errors, since strings.(*Buffer).Write never returns // errors. // // TODO(e.burkov, a.garipov): Find out and document why exactly // this slice. _, _ = encoder.Write(hash[0:2]) _, _ = b.WriteRune('.')
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/home/rdns.go
if util.IsOpenWRT() {
<mask> if err != nil { <mask> log.Fatal(err) <mask> } <mask> <mask> if util.IsOpenWrt() { <mask> // On OpenWrt it is important to run enable after the service installation <mask> // Otherwise, the service won't start on the system startup <mask> _, err := runInitdCommand("enable") <mask> if err != nil { <mask> log.Fatal(err) </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove if util.IsOpenWrt() { </s> add if util.IsOpenWRT() { </s> remove // Return TRUE if file exists </s> add // fileExists returns true if file exists. </s> remove } else if util.IsFreeBSD() { </s> add } else if runtime.GOOS == "freebsd" { </s> remove // On OpenWrt we're using a different type of sysvScript if util.IsOpenWrt() { </s> add // On OpenWrt we're using a different type of sysvScript. if util.IsOpenWRT() { </s> remove // Use modified service file templates </s> add // Use modified service file templates.
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/home/service.go
if util.IsOpenWRT() {
<mask> } <mask> <mask> // handleServiceStatusCommand handles service "uninstall" command <mask> func handleServiceUninstallCommand(s service.Service) { <mask> if util.IsOpenWrt() { <mask> // On OpenWrt it is important to run disable command first <mask> // as it will remove the symlink <mask> _, err := runInitdCommand("disable") <mask> if err != nil { <mask> log.Fatal(err) </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove if util.IsOpenWrt() { </s> add if util.IsOpenWRT() { </s> remove } else if util.IsFreeBSD() { </s> add } else if runtime.GOOS == "freebsd" { </s> remove if err != nil { return false } return true </s> add return err == nil </s> remove // On OpenWrt we're using a different type of sysvScript if util.IsOpenWrt() { </s> add // On OpenWrt we're using a different type of sysvScript. if util.IsOpenWRT() { </s> remove // runCommand runs shell command </s> add // RunCommand runs shell command.
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/home/service.go
// Use modified service file templates.
<mask> // POSIX <mask> // Redirect StdErr & StdOut to files. <mask> c.Option["LogOutput"] = true <mask> <mask> // Use modified service file templates <mask> c.Option["SystemdScript"] = systemdScript <mask> c.Option["SysvScript"] = sysvScript <mask> <mask> // On OpenWrt we're using a different type of sysvScript <mask> if util.IsOpenWrt() { </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove // On OpenWrt we're using a different type of sysvScript if util.IsOpenWrt() { </s> add // On OpenWrt we're using a different type of sysvScript. if util.IsOpenWRT() { </s> remove } else if util.IsFreeBSD() { </s> add } else if runtime.GOOS == "freebsd" { </s> remove if util.IsOpenWrt() { </s> add if util.IsOpenWRT() { </s> remove if util.IsOpenWrt() { </s> add if util.IsOpenWRT() { </s> remove // it's difficult to update this file while it's being used. </s> add // it's difficult to update this file while it's being // used.
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/home/service.go
// On OpenWrt we're using a different type of sysvScript. if util.IsOpenWRT() {
<mask> // Use modified service file templates <mask> c.Option["SystemdScript"] = systemdScript <mask> c.Option["SysvScript"] = sysvScript <mask> <mask> // On OpenWrt we're using a different type of sysvScript <mask> if util.IsOpenWrt() { <mask> c.Option["SysvScript"] = openWrtScript <mask> } else if util.IsFreeBSD() { <mask> c.Option["SysvScript"] = freeBSDScript <mask> } <mask> } </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove // Use modified service file templates </s> add // Use modified service file templates. </s> remove } else if util.IsFreeBSD() { </s> add } else if runtime.GOOS == "freebsd" { </s> remove if util.IsOpenWrt() { </s> add if util.IsOpenWRT() { </s> remove // it's difficult to update this file while it's being used. </s> add // it's difficult to update this file while it's being // used. </s> remove if util.IsOpenWrt() { </s> add if util.IsOpenWRT() {
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/home/service.go
} else if runtime.GOOS == "freebsd" {
<mask> <mask> // On OpenWrt we're using a different type of sysvScript <mask> if util.IsOpenWrt() { <mask> c.Option["SysvScript"] = openWrtScript <mask> } else if util.IsFreeBSD() { <mask> c.Option["SysvScript"] = freeBSDScript <mask> } <mask> } <mask> <mask> // runInitdCommand runs init.d service command </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove // On OpenWrt we're using a different type of sysvScript if util.IsOpenWrt() { </s> add // On OpenWrt we're using a different type of sysvScript. if util.IsOpenWRT() { </s> remove // Use modified service file templates </s> add // Use modified service file templates. </s> remove if util.IsOpenWrt() { </s> add if util.IsOpenWRT() { </s> remove if util.IsOpenWrt() { </s> add if util.IsOpenWRT() { </s> remove // it's difficult to update this file while it's being used. </s> add // it's difficult to update this file while it's being // used.
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/home/service.go
func verifyCertChain(data *tlsConfigStatus, certChain, serverName string) error {
<mask> }() <mask> } <mask> } <mask> <mask> func verifyCertChain(data *tlsConfigStatus, certChain string, serverName string) error { <mask> log.Tracef("TLS: got certificate: %d bytes", len(certChain)) <mask> <mask> // now do a more extended validation <mask> var certs []*pem.Block // PEM-encoded certificates <mask> </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove if !os.IsNotExist(err) { // do nothing, file exists return false } return true </s> add return os.IsNotExist(err) </s> remove func Main(version string, channel string, armVer string) { </s> add func Main(version, channel, armVer string) { </s> remove if err != nil { return false } return true </s> add return err == nil </s> remove func (a *Auth) UserFind(login string, password string) User { </s> add func (a *Auth) UserFind(login, password string) User { </s> remove func (w *Whois) query(target string, serverAddr string) (string, error) { </s> add func (w *Whois) query(target, serverAddr string) (string, error) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/home/tls.go
data.WarningValidation = "You have specified an empty certificate"
<mask> parsedCerts = append(parsedCerts, parsed) <mask> } <mask> <mask> if len(parsedCerts) == 0 { <mask> data.WarningValidation = fmt.Sprintf("You have specified an empty certificate") <mask> return errors.New(data.WarningValidation) <mask> } <mask> <mask> data.ValidCert = true <mask> </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove if IsOpenWrt() { </s> add if IsOpenWRT() { </s> remove for _, it := range u.nResult { udb.NResult = append(udb.NResult, it) } </s> add udb.NResult = append(udb.NResult, u.nResult...) </s> remove if a[i].Count >= a[j].Count { return true } return false </s> add return a[j].Count < a[i].Count </s> remove if strings.Index(s, "<html") >= 0 || strings.Index(s, "<!doctype") >= 0 { </s> add if strings.Contains(s, "<html") || strings.Contains(s, "<!doctype") { </s> remove ips, _ := a.table[host] if len(ips) != 0 { </s> add if ips, ok := a.table[host]; ok {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/home/tls.go
func (w *Whois) query(target, serverAddr string) (string, error) {
<mask> return m <mask> } <mask> <mask> // Send request to a server and receive the response <mask> func (w *Whois) query(target string, serverAddr string) (string, error) { <mask> addr, _, _ := net.SplitHostPort(serverAddr) <mask> if addr == "whois.arin.net" { <mask> target = "n + " + target <mask> } <mask> conn, err := customDialContext(context.TODO(), "tcp", serverAddr) </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove if !os.IsNotExist(err) { // do nothing, file exists return false } return true </s> add return os.IsNotExist(err) </s> remove q += sbTXTSuffix } else { q += pcTXTSuffix </s> add // See comment above. _, _ = b.WriteString(sbTXTSuffix) return b.String() </s> remove return q </s> add // See comment above. _, _ = b.WriteString(pcTXTSuffix) return b.String() </s> remove if err != nil { return false } return true </s> add return err == nil </s> remove func Main(version string, channel string, armVer string) { </s> add func Main(version, channel, armVer string) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/home/whois.go
ip := <-w.ipChan
<mask> <mask> // Get IP address from channel; get WHOIS info; associate info with a client <mask> func (w *Whois) workerLoop() { <mask> for { <mask> var ip string <mask> ip = <-w.ipChan <mask> <mask> info := w.process(ip) <mask> if len(info) == 0 { <mask> continue <mask> } </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove var ip string ip = <-r.ipChannel </s> add ip := <-r.ipChannel </s> remove func ip6InRange(start net.IP, ip net.IP) bool { </s> add func ip6InRange(start, ip net.IP) bool { </s> remove func (w *Whois) query(target string, serverAddr string) (string, error) { </s> add func (w *Whois) query(target, serverAddr string) (string, error) { </s> remove // Process - get the list of IP addresses for the hostname // Return nil if not found </s> add // Process returns the list of IP addresses for the hostname or nil if nothing // found. </s> remove // updateLoop - read static hosts from system files </s> add // updateLoop reads static hosts from system files.
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/home/whois.go
func UIntArrayEquals(a, b []uint64) bool {
<mask> <mask> "github.com/stretchr/testify/assert" <mask> ) <mask> <mask> func UIntArrayEquals(a []uint64, b []uint64) bool { <mask> if len(a) != len(b) { <mask> return false <mask> } <mask> <mask> for i := range a { </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove // ContainsString checks if "v" is in the array "arr" func ContainsString(arr []string, v string) bool { for _, i := range arr { if i == v { </s> add // ContainsString checks if string is in the slice of strings. func ContainsString(strs []string, str string) bool { for _, s := range strs { if s == str { </s> remove // MinInt - return the minimum value func MinInt(a, b int) int { if a < b { return a } return b } // IsOpenWrt checks if OS is OpenWRT func IsOpenWrt() bool { </s> add // IsOpenWRT checks if OS is OpenWRT. func IsOpenWRT() bool { </s> remove if a[i].Count >= a[j].Count { return true } return false </s> add return a[j].Count < a[i].Count </s> remove if err != nil { return false } return true </s> add return err == nil </s> remove func ip6InRange(start net.IP, ip net.IP) bool { </s> add func ip6InRange(start, ip net.IP) bool {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/stats/stats_test.go
var hour int32 = 1
<mask> os.Remove(conf.Filename) <mask> } <mask> <mask> func TestLargeNumbers(t *testing.T) { <mask> var hour int32 <mask> hour = 1 <mask> newID := func() uint32 { <mask> // use "atomic" to make Go race detector happy <mask> return uint32(atomic.LoadInt32(&hour)) <mask> } <mask> </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove func _Func() string { pc := make([]uintptr, 10) // at least 1 entry needed runtime.Callers(2, pc) f := runtime.FuncForPC(pc[0]) return path.Base(f.Name()) } </s> add </s> remove /* expire byte[4] name_len byte[2] name byte[] */ </s> add </s> remove func check(t *testing.T, result bool, msg string) { if !result { t.Fatal(msg) } } </s> add </s> remove for { select { case t := <-ticker.C: t.Second() log.Debug("Free OS memory") debug.FreeOSMemory() } </s> add for range ticker.C { log.Debug("free os memory") debug.FreeOSMemory()
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/stats/stats_test.go
s.db, err = bolt.Open(s.conf.Filename, 0o644, nil)
<mask> <mask> func (s *statsCtx) dbOpen() bool { <mask> var err error <mask> log.Tracef("db.Open...") <mask> s.db, err = bolt.Open(s.conf.Filename, 0644, nil) <mask> if err != nil { <mask> log.Error("Stats: open DB: %s: %s", s.conf.Filename, err) <mask> if err.Error() == "invalid argument" { <mask> log.Error("AdGuard Home cannot be initialized due to an incompatible file system.\nPlease read the explanation here: https://github.com/AdguardTeam/AdGuardHome/internal/wiki/Getting-Started#limitations") <mask> } </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove errorText := fmt.Sprintf("failed to read request body: %s", err) log.Error(errorText) http.Error(w, errorText, http.StatusBadRequest) </s> add msg := fmt.Sprintf("failed to read request body: %s", err) log.Error(msg) http.Error(w, msg, http.StatusBadRequest) </s> remove errorText := fmt.Sprintf("failed to read request body: %s", err) log.Println(errorText) http.Error(w, errorText, http.StatusBadRequest) </s> add msg := fmt.Sprintf("failed to read request body: %s", err) log.Println(msg) http.Error(w, msg, http.StatusBadRequest) </s> remove // it's difficult to update this file while it's being used. </s> add // it's difficult to update this file while it's being // used. </s> remove func (d *Dnsfilter) checkMatchIP(t *testing.T, hostname string, ip string, qtype uint16) { </s> add func (d *Dnsfilter) checkMatchIP(t *testing.T, hostname, ip string, qtype uint16) { </s> remove // fileExists returns TRUE if file exists </s> add // FileExists returns true if file exists.
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/stats/stats_unit.go
return a[j].Count < a[i].Count
<mask> pair.Count = v <mask> a = append(a, pair) <mask> } <mask> less := func(i, j int) bool { <mask> if a[i].Count >= a[j].Count { <mask> return true <mask> } <mask> return false <mask> } <mask> sort.Slice(a, less) <mask> if max > len(a) { <mask> max = len(a) <mask> } </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove func UIntArrayEquals(a []uint64, b []uint64) bool { </s> add func UIntArrayEquals(a, b []uint64) bool { </s> remove // ContainsString checks if "v" is in the array "arr" func ContainsString(arr []string, v string) bool { for _, i := range arr { if i == v { </s> add // ContainsString checks if string is in the slice of strings. func ContainsString(strs []string, str string) bool { for _, s := range strs { if s == str { </s> remove // MinInt - return the minimum value func MinInt(a, b int) int { if a < b { return a } return b } // IsOpenWrt checks if OS is OpenWRT func IsOpenWrt() bool { </s> add // IsOpenWRT checks if OS is OpenWRT. func IsOpenWRT() bool { </s> remove if strings.Index(s, "<html") >= 0 || strings.Index(s, "<!doctype") >= 0 { </s> add if strings.Contains(s, "<html") || strings.Contains(s, "<!doctype") { </s> remove // fileExists returns TRUE if file exists </s> add // FileExists returns true if file exists.
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/stats/stats_unit.go
udb.NResult = append(udb.NResult, u.nResult...)
<mask> <mask> func serialize(u *unit) *unitDB { <mask> udb := unitDB{} <mask> udb.NTotal = u.nTotal <mask> for _, it := range u.nResult { <mask> udb.NResult = append(udb.NResult, it) <mask> } <mask> if u.nTotal != 0 { <mask> udb.TimeAvg = uint32(u.timeSum / u.nTotal) <mask> } <mask> udb.Domains = convertMapToArray(u.domains, maxDomains) <mask> udb.BlockedDomains = convertMapToArray(u.blockedDomains, maxDomains) </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove ips, _ := a.table[host] if len(ips) != 0 { </s> add if ips, ok := a.table[host]; ok { </s> remove if IsOpenWrt() { </s> add if IsOpenWRT() { </s> remove func _Func() string { pc := make([]uintptr, 10) // at least 1 entry needed runtime.Callers(2, pc) f := runtime.FuncForPC(pc[0]) return path.Base(f.Name()) } </s> add </s> remove if strings.Index(s, "<html") >= 0 || strings.Index(s, "<!doctype") >= 0 { </s> add if strings.Contains(s, "<html") || strings.Contains(s, "<!doctype") {
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/stats/stats_unit.go
// Per-hour units. units := []*unitDB{}
<mask> curUnit := serialize(s.unit) <mask> curID := s.unit.id <mask> s.unitLock.Unlock() <mask> <mask> units := []*unitDB{} //per-hour units <mask> firstID := curID - limit + 1 <mask> for i := firstID; i != curID; i++ { <mask> u := s.loadUnitFromDB(tx, i) <mask> if u == nil { <mask> u = &unitDB{} </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove m := make(map[string]string, 0) </s> add m := make(map[string]string) </s> remove func (a *Auth) UserFind(login string, password string) User { </s> add func (a *Auth) UserFind(login, password string) User { </s> remove // ContainsString checks if "v" is in the array "arr" func ContainsString(arr []string, v string) bool { for _, i := range arr { if i == v { </s> add // ContainsString checks if string is in the slice of strings. func ContainsString(strs []string, str string) bool { for _, s := range strs { if s == str { </s> remove func UIntArrayEquals(a []uint64, b []uint64) bool { </s> add func UIntArrayEquals(a, b []uint64) bool { </s> remove func _Func() string { pc := make([]uintptr, 10) // at least 1 entry needed runtime.Callers(2, pc) f := runtime.FuncForPC(pc[0]) return path.Base(f.Name()) } </s> add
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/stats/stats_unit.go
if IsOpenWRT() {
<mask> if len(hostsFn) != 0 { <mask> a.hostsFn = hostsFn <mask> } <mask> <mask> if IsOpenWrt() { <mask> a.hostsDirs = append(a.hostsDirs, "/tmp/hosts") // OpenWRT: "/tmp/hosts/dhcp.cfg01411c" <mask> } <mask> <mask> // Load hosts initially <mask> a.updateHosts() </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove for { select { case ok := <-a.updateChan: if !ok { log.Debug("Finished AutoHosts update loop") return } a.updateHosts() </s> add for ok := range a.updateChan { if !ok { log.Debug("Finished AutoHosts update loop") return </s> remove // MinInt - return the minimum value func MinInt(a, b int) int { if a < b { return a } return b } // IsOpenWrt checks if OS is OpenWRT func IsOpenWrt() bool { </s> add // IsOpenWRT checks if OS is OpenWRT. func IsOpenWRT() bool { </s> remove // updateLoop - read static hosts from system files </s> add // updateLoop reads static hosts from system files. </s> remove } else if util.IsFreeBSD() { </s> add } else if runtime.GOOS == "freebsd" {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/util/auto_hosts.go
// Process returns the list of IP addresses for the hostname or nil if nothing // found.
<mask> _ = a.watcher.Close() <mask> } <mask> } <mask> <mask> // Process - get the list of IP addresses for the hostname <mask> // Return nil if not found <mask> func (a *AutoHosts) Process(host string, qtype uint16) []net.IP { <mask> if qtype == dns.TypePTR { <mask> return nil <mask> } <mask> </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove func (d *Dnsfilter) checkMatchIP(t *testing.T, hostname string, ip string, qtype uint16) { </s> add func (d *Dnsfilter) checkMatchIP(t *testing.T, hostname, ip string, qtype uint16) { </s> remove // updateLoop - read static hosts from system files </s> add // updateLoop reads static hosts from system files. </s> remove for { select { case ok := <-a.updateChan: if !ok { log.Debug("Finished AutoHosts update loop") return } a.updateHosts() </s> add for ok := range a.updateChan { if !ok { log.Debug("Finished AutoHosts update loop") return </s> remove var ip string ip = <-r.ipChannel </s> add ip := <-r.ipChannel </s> remove func (a *Auth) UserFind(login string, password string) User { </s> add func (a *Auth) UserFind(login, password string) User {
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/util/auto_hosts.go
if ips, ok := a.table[host]; ok {
<mask> } <mask> <mask> var ipsCopy []net.IP <mask> a.lock.Lock() <mask> ips, _ := a.table[host] <mask> if len(ips) != 0 { <mask> ipsCopy = make([]net.IP, len(ips)) <mask> copy(ipsCopy, ips) <mask> } <mask> a.lock.Unlock() <mask> </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove func (a *Auth) UserFind(login string, password string) User { </s> add func (a *Auth) UserFind(login, password string) User { </s> remove if IsOpenWrt() { </s> add if IsOpenWRT() { </s> remove for _, it := range u.nResult { udb.NResult = append(udb.NResult, it) } </s> add udb.NResult = append(udb.NResult, u.nResult...) </s> remove // Process - get the list of IP addresses for the hostname // Return nil if not found </s> add // Process returns the list of IP addresses for the hostname or nil if nothing // found. </s> remove if strings.Index(s, "<html") >= 0 || strings.Index(s, "<!doctype") >= 0 { </s> add if strings.Contains(s, "<html") || strings.Contains(s, "<!doctype") {
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/util/auto_hosts.go
<mask> if !ok { <mask> return <mask> } <mask> <mask> // skip duplicate events <mask> repeat := true <mask> for repeat { <mask> select { <mask> case _ = <-a.watcher.Events: <mask> // skip this event </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove case _ = <-a.watcher.Events: // skip this event </s> add case <-a.watcher.Events: // Skip this duplicating event </s> remove for { select { case ok := <-a.updateChan: if !ok { log.Debug("Finished AutoHosts update loop") return } a.updateHosts() </s> add for ok := range a.updateChan { if !ok { log.Debug("Finished AutoHosts update loop") return </s> remove // updateLoop - read static hosts from system files </s> add // updateLoop reads static hosts from system files. </s> remove q += fmt.Sprintf("%s.", hex.EncodeToString(hash[0:2])) </s> add // Ignore errors, since strings.(*Buffer).Write never returns // errors. // // TODO(e.burkov, a.garipov): Find out and document why exactly // this slice. _, _ = encoder.Write(hash[0:2]) _, _ = b.WriteRune('.') </s> remove for { select { case t := <-ticker.C: t.Second() log.Debug("Free OS memory") debug.FreeOSMemory() } </s> add for range ticker.C { log.Debug("free os memory") debug.FreeOSMemory()
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/util/auto_hosts.go
case <-a.watcher.Events: // Skip this duplicating event
<mask> // skip duplicate events <mask> repeat := true <mask> for repeat { <mask> select { <mask> case _ = <-a.watcher.Events: <mask> // skip this event <mask> default: <mask> repeat = false <mask> } <mask> } <mask> </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove // skip duplicate events </s> add </s> remove // updateLoop - read static hosts from system files </s> add // updateLoop reads static hosts from system files. </s> remove q += fmt.Sprintf("%s.", hex.EncodeToString(hash[0:2])) </s> add // Ignore errors, since strings.(*Buffer).Write never returns // errors. // // TODO(e.burkov, a.garipov): Find out and document why exactly // this slice. _, _ = encoder.Write(hash[0:2]) _, _ = b.WriteRune('.') </s> remove for { select { case t := <-ticker.C: t.Second() log.Debug("Free OS memory") debug.FreeOSMemory() } </s> add for range ticker.C { log.Debug("free os memory") debug.FreeOSMemory() </s> remove for { select { case ok := <-a.updateChan: if !ok { log.Debug("Finished AutoHosts update loop") return } a.updateHosts() </s> add for ok := range a.updateChan { if !ok { log.Debug("Finished AutoHosts update loop") return
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/util/auto_hosts.go
// updateLoop reads static hosts from system files.
<mask> } <mask> } <mask> } <mask> <mask> // updateLoop - read static hosts from system files <mask> func (a *AutoHosts) updateLoop() { <mask> for { <mask> select { <mask> case ok := <-a.updateChan: <mask> if !ok { </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove for { select { case ok := <-a.updateChan: if !ok { log.Debug("Finished AutoHosts update loop") return } a.updateHosts() </s> add for ok := range a.updateChan { if !ok { log.Debug("Finished AutoHosts update loop") return </s> remove // skip duplicate events </s> add </s> remove // Process - get the list of IP addresses for the hostname // Return nil if not found </s> add // Process returns the list of IP addresses for the hostname or nil if nothing // found. </s> remove case _ = <-a.watcher.Events: // skip this event </s> add case <-a.watcher.Events: // Skip this duplicating event
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/util/auto_hosts.go
for ok := range a.updateChan { if !ok { log.Debug("Finished AutoHosts update loop") return
<mask> } <mask> <mask> // updateLoop - read static hosts from system files <mask> func (a *AutoHosts) updateLoop() { <mask> for { <mask> select { <mask> case ok := <-a.updateChan: <mask> if !ok { <mask> log.Debug("Finished AutoHosts update loop") <mask> return <mask> } <mask> <mask> a.updateHosts() <mask> } <mask> } <mask> } <mask> <mask> // updateHosts - loads system hosts </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove // updateLoop - read static hosts from system files </s> add // updateLoop reads static hosts from system files. </s> remove if IsOpenWrt() { </s> add if IsOpenWRT() { </s> remove // skip duplicate events </s> add </s> remove // Process - get the list of IP addresses for the hostname // Return nil if not found </s> add // Process returns the list of IP addresses for the hostname or nil if nothing // found.
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/util/auto_hosts.go
a.updateHosts()
<mask> log.Debug("Finished AutoHosts update loop") <mask> return <mask> } <mask> } <mask> } <mask> <mask> // updateHosts - loads system hosts <mask> func (a *AutoHosts) updateHosts() { </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove for { select { case ok := <-a.updateChan: if !ok { log.Debug("Finished AutoHosts update loop") return } a.updateHosts() </s> add for ok := range a.updateChan { if !ok { log.Debug("Finished AutoHosts update loop") return </s> remove // updateLoop - read static hosts from system files </s> add // updateLoop reads static hosts from system files. </s> remove // Process - get the list of IP addresses for the hostname // Return nil if not found </s> add // Process returns the list of IP addresses for the hostname or nil if nothing // found. </s> remove func (a *Auth) UserFind(login string, password string) User { </s> add func (a *Auth) UserFind(login, password string) User { </s> remove // MinInt - return the minimum value func MinInt(a, b int) int { if a < b { return a } return b } // IsOpenWrt checks if OS is OpenWRT func IsOpenWrt() bool { </s> add // IsOpenWRT checks if OS is OpenWRT. func IsOpenWRT() bool {
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/util/auto_hosts.go
// ContainsString checks if string is in the slice of strings. func ContainsString(strs []string, str string) bool { for _, s := range strs { if s == str {
<mask> "runtime" <mask> "strings" <mask> ) <mask> <mask> // ContainsString checks if "v" is in the array "arr" <mask> func ContainsString(arr []string, v string) bool { <mask> for _, i := range arr { <mask> if i == v { <mask> return true <mask> } <mask> } <mask> return false <mask> } </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove func UIntArrayEquals(a []uint64, b []uint64) bool { </s> add func UIntArrayEquals(a, b []uint64) bool { </s> remove // IsFreeBSD checks if OS is FreeBSD func IsFreeBSD() bool { if runtime.GOOS == "freebsd" { return true } return false } </s> add </s> remove // MinInt - return the minimum value func MinInt(a, b int) int { if a < b { return a } return b } // IsOpenWrt checks if OS is OpenWRT func IsOpenWrt() bool { </s> add // IsOpenWRT checks if OS is OpenWRT. func IsOpenWRT() bool { </s> remove if err != nil { return false } return true </s> add return err == nil </s> remove if a[i].Count >= a[j].Count { return true } return false </s> add return a[j].Count < a[i].Count
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/util/helpers.go
// FileExists returns true if file exists.
<mask> } <mask> return false <mask> } <mask> <mask> // fileExists returns TRUE if file exists <mask> func FileExists(fn string) bool { <mask> _, err := os.Stat(fn) <mask> if err != nil { <mask> return false <mask> } </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove if err != nil { return false } return true </s> add return err == nil </s> remove // Return TRUE if file exists </s> add // fileExists returns true if file exists. </s> remove if err != nil { return false } return true </s> add return err == nil </s> remove if !os.IsNotExist(err) { // do nothing, file exists return false } return true </s> add return os.IsNotExist(err) </s> remove // MinInt - return the minimum value func MinInt(a, b int) int { if a < b { return a } return b } // IsOpenWrt checks if OS is OpenWRT func IsOpenWrt() bool { </s> add // IsOpenWRT checks if OS is OpenWRT. func IsOpenWRT() bool {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/util/helpers.go
return err == nil
<mask> <mask> // fileExists returns TRUE if file exists <mask> func FileExists(fn string) bool { <mask> _, err := os.Stat(fn) <mask> if err != nil { <mask> return false <mask> } <mask> return true <mask> } <mask> <mask> // runCommand runs shell command <mask> func RunCommand(command string, arguments ...string) (int, string, error) { <mask> cmd := exec.Command(command, arguments...) </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove // runCommand runs shell command </s> add // RunCommand runs shell command. </s> remove // fileExists returns TRUE if file exists </s> add // FileExists returns true if file exists. </s> remove // Return TRUE if file exists </s> add // fileExists returns true if file exists. </s> remove if err != nil { return false } return true </s> add return err == nil </s> remove if !os.IsNotExist(err) { // do nothing, file exists return false } return true </s> add return os.IsNotExist(err)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/util/helpers.go
// RunCommand runs shell command.
<mask> } <mask> return true <mask> } <mask> <mask> // runCommand runs shell command <mask> func RunCommand(command string, arguments ...string) (int, string, error) { <mask> cmd := exec.Command(command, arguments...) <mask> out, err := cmd.Output() <mask> if err != nil { <mask> return 1, "", fmt.Errorf("exec.Command(%s) failed: %v: %s", command, err, string(out)) </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove if err != nil { return false } return true </s> add return err == nil </s> remove func (d *Dnsfilter) checkMatchIP(t *testing.T, hostname string, ip string, qtype uint16) { </s> add func (d *Dnsfilter) checkMatchIP(t *testing.T, hostname, ip string, qtype uint16) { </s> remove if err != nil { return false } return true </s> add return err == nil </s> remove if util.IsOpenWrt() { </s> add if util.IsOpenWRT() { </s> remove // fileExists returns TRUE if file exists </s> add // FileExists returns true if file exists.
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/util/helpers.go
// IsOpenWRT checks if OS is OpenWRT. func IsOpenWRT() bool {
<mask> } <mask> return strings.TrimSpace(s) <mask> } <mask> <mask> // MinInt - return the minimum value <mask> func MinInt(a, b int) int { <mask> if a < b { <mask> return a <mask> } <mask> return b <mask> } <mask> <mask> // IsOpenWrt checks if OS is OpenWRT <mask> func IsOpenWrt() bool { <mask> if runtime.GOOS != "linux" { <mask> return false <mask> } <mask> <mask> body, err := ioutil.ReadFile("/etc/os-release") </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove func UIntArrayEquals(a []uint64, b []uint64) bool { </s> add func UIntArrayEquals(a, b []uint64) bool { </s> remove // IsFreeBSD checks if OS is FreeBSD func IsFreeBSD() bool { if runtime.GOOS == "freebsd" { return true } return false } </s> add </s> remove // ContainsString checks if "v" is in the array "arr" func ContainsString(arr []string, v string) bool { for _, i := range arr { if i == v { </s> add // ContainsString checks if string is in the slice of strings. func ContainsString(strs []string, str string) bool { for _, s := range strs { if s == str { </s> remove if a[i].Count >= a[j].Count { return true } return false </s> add return a[j].Count < a[i].Count </s> remove // fileExists returns TRUE if file exists </s> add // FileExists returns true if file exists.
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/util/helpers.go
<mask> } <mask> <mask> return strings.Contains(string(body), "OpenWrt") <mask> } <mask> <mask> // IsFreeBSD checks if OS is FreeBSD <mask> func IsFreeBSD() bool { <mask> if runtime.GOOS == "freebsd" { <mask> return true <mask> } <mask> <mask> return false <mask> } </s> Pull request:* all: fix all staticcheck simplification and unused warnings Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master Squashed commit of the following: commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29 Merge: 50dc3ef5c 7e16fda57 Author: Eugene Burkov <[email protected]> Date: Fri Nov 6 11:54:09 2020 +0300 Merge branch 'master' into 2270-fix-s-u-warnings commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 19:48:54 2020 +0300 * all: improve code quality commit d6d804f759ce3e47154a389b427550e72c4b9090 Author: Eugene Burkov <[email protected]> Date: Thu Nov 5 18:03:35 2020 +0300 * all: fix all staticcheck simplification and unused warnings Closes #2270. </s> remove // MinInt - return the minimum value func MinInt(a, b int) int { if a < b { return a } return b } // IsOpenWrt checks if OS is OpenWRT func IsOpenWrt() bool { </s> add // IsOpenWRT checks if OS is OpenWRT. func IsOpenWRT() bool { </s> remove // ContainsString checks if "v" is in the array "arr" func ContainsString(arr []string, v string) bool { for _, i := range arr { if i == v { </s> add // ContainsString checks if string is in the slice of strings. func ContainsString(strs []string, str string) bool { for _, s := range strs { if s == str { </s> remove } else if util.IsFreeBSD() { </s> add } else if runtime.GOOS == "freebsd" { </s> remove // fileExists returns TRUE if file exists </s> add // FileExists returns true if file exists. </s> remove func ip6InRange(start net.IP, ip net.IP) bool { </s> add func ip6InRange(start, ip net.IP) bool {
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3e1f922252e2a9b735b0be28733067f3b85bb6f3
internal/util/helpers.go
// Package aghos contains utilities for functions requiring system calls and // other OS-specific APIs. OS-specific network handling should go to aghnet // instead.
<mask> // Package aghos contains utilities for functions requiring system calls. <mask> package aghos <mask> <mask> import ( <mask> "fmt" <mask> "os/exec" </s> Pull request: all: imp ipset, add tests Closes #2611. Squashed commit of the following: commit f72577757e5cd0299863ccc01780ad9307adc6ea Author: Ainar Garipov <[email protected]> Date: Fri Jun 18 17:32:41 2021 +0300 dnsforward: imp err msgs commit ed8d6dd4b5d7171dfbd57742b53bf96be6cbec29 Author: Ainar Garipov <[email protected]> Date: Fri Jun 18 17:00:49 2021 +0300 all: imp ipset code commit 887b3268bae496f4ad616b277f5e28d3ee24a370 Author: Ainar Garipov <[email protected]> Date: Fri Jun 18 16:09:08 2021 +0300 dnsforward: imp ipset, add tests </s> remove "os" </s> add </s> remove // IPSET configuration - add IP addresses of the specified domain names to an ipset list // Syntax: // "DOMAIN[,DOMAIN].../IPSET_NAME" IPSETList []string `yaml:"ipset"` </s> add // IpsetList is the ipset configuration that allows AdGuard Home to add // IP addresses of the specified domain names to an ipset list. Syntax: // // DOMAIN[,DOMAIN].../IPSET_NAME // IpsetList []string `yaml:"ipset"` </s> remove if !errors.Is(err, os.ErrInvalid) && !errors.Is(err, os.ErrPermission) { return fmt.Errorf("cannot initialize ipset: %w", err) } // ipset cannot currently be initialized if the server was // installed from Snap or when the user or the binary doesn't // have the required permissions, or when the kernel doesn't // support netfilter. // // Log and go on. // // TODO(a.garipov): The Snap problem can probably be solved if // we add the netlink-connector interface plug. log.Info("warning: cannot initialize ipset: %s", err) </s> add return err </s> remove // Initialize IPSET configuration </s> add // Initialize ipset configuration
[ "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3ee0369cb91a0785cbea8ee99eadadad69d54cfa
internal/aghos/os.go
// IpsetList is the ipset configuration that allows AdGuard Home to add // IP addresses of the specified domain names to an ipset list. Syntax: // // DOMAIN[,DOMAIN].../IPSET_NAME // IpsetList []string `yaml:"ipset"`
<mask> EnableDNSSEC bool `yaml:"enable_dnssec"` // Set DNSSEC flag in outcoming DNS request <mask> EnableEDNSClientSubnet bool `yaml:"edns_client_subnet"` // Enable EDNS Client Subnet option <mask> MaxGoroutines uint32 `yaml:"max_goroutines"` // Max. number of parallel goroutines for processing incoming requests <mask> <mask> // IPSET configuration - add IP addresses of the specified domain names to an ipset list <mask> // Syntax: <mask> // "DOMAIN[,DOMAIN].../IPSET_NAME" <mask> IPSETList []string `yaml:"ipset"` <mask> } <mask> <mask> // TLSConfig is the TLS configuration for HTTPS, DNS-over-HTTPS, and DNS-over-TLS <mask> type TLSConfig struct { <mask> TLSListenAddrs []*net.TCPAddr `yaml:"-" json:"-"` </s> Pull request: all: imp ipset, add tests Closes #2611. Squashed commit of the following: commit f72577757e5cd0299863ccc01780ad9307adc6ea Author: Ainar Garipov <[email protected]> Date: Fri Jun 18 17:32:41 2021 +0300 dnsforward: imp err msgs commit ed8d6dd4b5d7171dfbd57742b53bf96be6cbec29 Author: Ainar Garipov <[email protected]> Date: Fri Jun 18 17:00:49 2021 +0300 all: imp ipset code commit 887b3268bae496f4ad616b277f5e28d3ee24a370 Author: Ainar Garipov <[email protected]> Date: Fri Jun 18 16:09:08 2021 +0300 dnsforward: imp ipset, add tests </s> remove // Initialize IPSET configuration </s> add // Initialize ipset configuration </s> remove if !errors.Is(err, os.ErrInvalid) && !errors.Is(err, os.ErrPermission) { return fmt.Errorf("cannot initialize ipset: %w", err) } // ipset cannot currently be initialized if the server was // installed from Snap or when the user or the binary doesn't // have the required permissions, or when the kernel doesn't // support netfilter. // // Log and go on. // // TODO(a.garipov): The Snap problem can probably be solved if // we add the netlink-connector interface plug. log.Info("warning: cannot initialize ipset: %s", err) </s> add return err </s> remove // Package aghos contains utilities for functions requiring system calls. </s> add // Package aghos contains utilities for functions requiring system calls and // other OS-specific APIs. OS-specific network handling should go to aghnet // instead. </s> remove if err := s.ipset.Close(); err != nil { </s> add if err := s.ipset.close(); err != nil {
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3ee0369cb91a0785cbea8ee99eadadad69d54cfa
internal/dnsforward/config.go
<mask> import ( <mask> "fmt" <mask> "net" <mask> "net/http" <mask> "os" <mask> "runtime" <mask> "strings" <mask> "sync" <mask> "time" <mask> </s> Pull request: all: imp ipset, add tests Closes #2611. Squashed commit of the following: commit f72577757e5cd0299863ccc01780ad9307adc6ea Author: Ainar Garipov <[email protected]> Date: Fri Jun 18 17:32:41 2021 +0300 dnsforward: imp err msgs commit ed8d6dd4b5d7171dfbd57742b53bf96be6cbec29 Author: Ainar Garipov <[email protected]> Date: Fri Jun 18 17:00:49 2021 +0300 all: imp ipset code commit 887b3268bae496f4ad616b277f5e28d3ee24a370 Author: Ainar Garipov <[email protected]> Date: Fri Jun 18 16:09:08 2021 +0300 dnsforward: imp ipset, add tests </s> remove // Package aghos contains utilities for functions requiring system calls. </s> add // Package aghos contains utilities for functions requiring system calls and // other OS-specific APIs. OS-specific network handling should go to aghnet // instead. </s> remove if !errors.Is(err, os.ErrInvalid) && !errors.Is(err, os.ErrPermission) { return fmt.Errorf("cannot initialize ipset: %w", err) } // ipset cannot currently be initialized if the server was // installed from Snap or when the user or the binary doesn't // have the required permissions, or when the kernel doesn't // support netfilter. // // Log and go on. // // TODO(a.garipov): The Snap problem can probably be solved if // we add the netlink-connector interface plug. log.Info("warning: cannot initialize ipset: %s", err) </s> add return err </s> remove err := s.ipset.init(s.conf.IPSETList) </s> add err := s.ipset.init(s.conf.IpsetList) </s> remove // Initialize IPSET configuration </s> add // Initialize ipset configuration
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3ee0369cb91a0785cbea8ee99eadadad69d54cfa
internal/dnsforward/dnsforward.go
if err := s.ipset.close(); err != nil {
<mask> s.stats = nil <mask> s.queryLog = nil <mask> s.dnsProxy = nil <mask> <mask> if err := s.ipset.Close(); err != nil { <mask> log.Error("closing ipset: %s", err) <mask> } <mask> } <mask> <mask> // WriteDiskConfig - write configuration </s> Pull request: all: imp ipset, add tests Closes #2611. Squashed commit of the following: commit f72577757e5cd0299863ccc01780ad9307adc6ea Author: Ainar Garipov <[email protected]> Date: Fri Jun 18 17:32:41 2021 +0300 dnsforward: imp err msgs commit ed8d6dd4b5d7171dfbd57742b53bf96be6cbec29 Author: Ainar Garipov <[email protected]> Date: Fri Jun 18 17:00:49 2021 +0300 all: imp ipset code commit 887b3268bae496f4ad616b277f5e28d3ee24a370 Author: Ainar Garipov <[email protected]> Date: Fri Jun 18 16:09:08 2021 +0300 dnsforward: imp ipset, add tests </s> remove if !errors.Is(err, os.ErrInvalid) && !errors.Is(err, os.ErrPermission) { return fmt.Errorf("cannot initialize ipset: %w", err) } // ipset cannot currently be initialized if the server was // installed from Snap or when the user or the binary doesn't // have the required permissions, or when the kernel doesn't // support netfilter. // // Log and go on. // // TODO(a.garipov): The Snap problem can probably be solved if // we add the netlink-connector interface plug. log.Info("warning: cannot initialize ipset: %s", err) </s> add return err </s> remove err := s.ipset.init(s.conf.IPSETList) </s> add err := s.ipset.init(s.conf.IpsetList) </s> remove // Initialize IPSET configuration </s> add // Initialize ipset configuration </s> remove // IPSET configuration - add IP addresses of the specified domain names to an ipset list // Syntax: // "DOMAIN[,DOMAIN].../IPSET_NAME" IPSETList []string `yaml:"ipset"` </s> add // IpsetList is the ipset configuration that allows AdGuard Home to add // IP addresses of the specified domain names to an ipset list. Syntax: // // DOMAIN[,DOMAIN].../IPSET_NAME // IpsetList []string `yaml:"ipset"`
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3ee0369cb91a0785cbea8ee99eadadad69d54cfa
internal/dnsforward/dnsforward.go
// Initialize ipset configuration
<mask> // Set default values in the case if nothing is configured <mask> // -- <mask> s.initDefaultSettings() <mask> <mask> // Initialize IPSET configuration <mask> // -- <mask> err := s.ipset.init(s.conf.IPSETList) <mask> if err != nil { <mask> if !errors.Is(err, os.ErrInvalid) && !errors.Is(err, os.ErrPermission) { <mask> return fmt.Errorf("cannot initialize ipset: %w", err) </s> Pull request: all: imp ipset, add tests Closes #2611. Squashed commit of the following: commit f72577757e5cd0299863ccc01780ad9307adc6ea Author: Ainar Garipov <[email protected]> Date: Fri Jun 18 17:32:41 2021 +0300 dnsforward: imp err msgs commit ed8d6dd4b5d7171dfbd57742b53bf96be6cbec29 Author: Ainar Garipov <[email protected]> Date: Fri Jun 18 17:00:49 2021 +0300 all: imp ipset code commit 887b3268bae496f4ad616b277f5e28d3ee24a370 Author: Ainar Garipov <[email protected]> Date: Fri Jun 18 16:09:08 2021 +0300 dnsforward: imp ipset, add tests </s> remove err := s.ipset.init(s.conf.IPSETList) </s> add err := s.ipset.init(s.conf.IpsetList) </s> remove if !errors.Is(err, os.ErrInvalid) && !errors.Is(err, os.ErrPermission) { return fmt.Errorf("cannot initialize ipset: %w", err) } // ipset cannot currently be initialized if the server was // installed from Snap or when the user or the binary doesn't // have the required permissions, or when the kernel doesn't // support netfilter. // // Log and go on. // // TODO(a.garipov): The Snap problem can probably be solved if // we add the netlink-connector interface plug. log.Info("warning: cannot initialize ipset: %s", err) </s> add return err </s> remove if err := s.ipset.Close(); err != nil { </s> add if err := s.ipset.close(); err != nil { </s> remove // IPSET configuration - add IP addresses of the specified domain names to an ipset list // Syntax: // "DOMAIN[,DOMAIN].../IPSET_NAME" IPSETList []string `yaml:"ipset"` </s> add // IpsetList is the ipset configuration that allows AdGuard Home to add // IP addresses of the specified domain names to an ipset list. Syntax: // // DOMAIN[,DOMAIN].../IPSET_NAME // IpsetList []string `yaml:"ipset"`
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3ee0369cb91a0785cbea8ee99eadadad69d54cfa
internal/dnsforward/dnsforward.go
err := s.ipset.init(s.conf.IpsetList)
<mask> s.initDefaultSettings() <mask> <mask> // Initialize IPSET configuration <mask> // -- <mask> err := s.ipset.init(s.conf.IPSETList) <mask> if err != nil { <mask> if !errors.Is(err, os.ErrInvalid) && !errors.Is(err, os.ErrPermission) { <mask> return fmt.Errorf("cannot initialize ipset: %w", err) <mask> } <mask> </s> Pull request: all: imp ipset, add tests Closes #2611. Squashed commit of the following: commit f72577757e5cd0299863ccc01780ad9307adc6ea Author: Ainar Garipov <[email protected]> Date: Fri Jun 18 17:32:41 2021 +0300 dnsforward: imp err msgs commit ed8d6dd4b5d7171dfbd57742b53bf96be6cbec29 Author: Ainar Garipov <[email protected]> Date: Fri Jun 18 17:00:49 2021 +0300 all: imp ipset code commit 887b3268bae496f4ad616b277f5e28d3ee24a370 Author: Ainar Garipov <[email protected]> Date: Fri Jun 18 16:09:08 2021 +0300 dnsforward: imp ipset, add tests </s> remove // Initialize IPSET configuration </s> add // Initialize ipset configuration </s> remove if !errors.Is(err, os.ErrInvalid) && !errors.Is(err, os.ErrPermission) { return fmt.Errorf("cannot initialize ipset: %w", err) } // ipset cannot currently be initialized if the server was // installed from Snap or when the user or the binary doesn't // have the required permissions, or when the kernel doesn't // support netfilter. // // Log and go on. // // TODO(a.garipov): The Snap problem can probably be solved if // we add the netlink-connector interface plug. log.Info("warning: cannot initialize ipset: %s", err) </s> add return err </s> remove if err := s.ipset.Close(); err != nil { </s> add if err := s.ipset.close(); err != nil { </s> remove // IPSET configuration - add IP addresses of the specified domain names to an ipset list // Syntax: // "DOMAIN[,DOMAIN].../IPSET_NAME" IPSETList []string `yaml:"ipset"` </s> add // IpsetList is the ipset configuration that allows AdGuard Home to add // IP addresses of the specified domain names to an ipset list. Syntax: // // DOMAIN[,DOMAIN].../IPSET_NAME // IpsetList []string `yaml:"ipset"`
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3ee0369cb91a0785cbea8ee99eadadad69d54cfa
internal/dnsforward/dnsforward.go
return err
<mask> // Initialize IPSET configuration <mask> // -- <mask> err := s.ipset.init(s.conf.IPSETList) <mask> if err != nil { <mask> if !errors.Is(err, os.ErrInvalid) && !errors.Is(err, os.ErrPermission) { <mask> return fmt.Errorf("cannot initialize ipset: %w", err) <mask> } <mask> <mask> // ipset cannot currently be initialized if the server was <mask> // installed from Snap or when the user or the binary doesn't <mask> // have the required permissions, or when the kernel doesn't <mask> // support netfilter. <mask> // <mask> // Log and go on. <mask> // <mask> // TODO(a.garipov): The Snap problem can probably be solved if <mask> // we add the netlink-connector interface plug. <mask> log.Info("warning: cannot initialize ipset: %s", err) <mask> } <mask> <mask> // Prepare DNS servers settings <mask> // -- <mask> err = s.prepareUpstreamSettings() </s> Pull request: all: imp ipset, add tests Closes #2611. Squashed commit of the following: commit f72577757e5cd0299863ccc01780ad9307adc6ea Author: Ainar Garipov <[email protected]> Date: Fri Jun 18 17:32:41 2021 +0300 dnsforward: imp err msgs commit ed8d6dd4b5d7171dfbd57742b53bf96be6cbec29 Author: Ainar Garipov <[email protected]> Date: Fri Jun 18 17:00:49 2021 +0300 all: imp ipset code commit 887b3268bae496f4ad616b277f5e28d3ee24a370 Author: Ainar Garipov <[email protected]> Date: Fri Jun 18 16:09:08 2021 +0300 dnsforward: imp ipset, add tests </s> remove // Initialize IPSET configuration </s> add // Initialize ipset configuration </s> remove err := s.ipset.init(s.conf.IPSETList) </s> add err := s.ipset.init(s.conf.IpsetList) </s> remove // IPSET configuration - add IP addresses of the specified domain names to an ipset list // Syntax: // "DOMAIN[,DOMAIN].../IPSET_NAME" IPSETList []string `yaml:"ipset"` </s> add // IpsetList is the ipset configuration that allows AdGuard Home to add // IP addresses of the specified domain names to an ipset list. Syntax: // // DOMAIN[,DOMAIN].../IPSET_NAME // IpsetList []string `yaml:"ipset"` </s> remove if err := s.ipset.Close(); err != nil { </s> add if err := s.ipset.close(); err != nil {
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3ee0369cb91a0785cbea8ee99eadadad69d54cfa
internal/dnsforward/dnsforward.go
log.Debug("inited ipset")
<mask> return err <mask> } <mask> <mask> // Prepare DNS servers settings <mask> // -- <mask> err = s.prepareUpstreamSettings() <mask> if err != nil { <mask> return err <mask> } </s> Pull request: all: imp ipset, add tests Closes #2611. Squashed commit of the following: commit f72577757e5cd0299863ccc01780ad9307adc6ea Author: Ainar Garipov <[email protected]> Date: Fri Jun 18 17:32:41 2021 +0300 dnsforward: imp err msgs commit ed8d6dd4b5d7171dfbd57742b53bf96be6cbec29 Author: Ainar Garipov <[email protected]> Date: Fri Jun 18 17:00:49 2021 +0300 all: imp ipset code commit 887b3268bae496f4ad616b277f5e28d3ee24a370 Author: Ainar Garipov <[email protected]> Date: Fri Jun 18 16:09:08 2021 +0300 dnsforward: imp ipset, add tests </s> remove if !errors.Is(err, os.ErrInvalid) && !errors.Is(err, os.ErrPermission) { return fmt.Errorf("cannot initialize ipset: %w", err) } // ipset cannot currently be initialized if the server was // installed from Snap or when the user or the binary doesn't // have the required permissions, or when the kernel doesn't // support netfilter. // // Log and go on. // // TODO(a.garipov): The Snap problem can probably be solved if // we add the netlink-connector interface plug. log.Info("warning: cannot initialize ipset: %s", err) </s> add return err </s> remove if err := s.ipset.Close(); err != nil { </s> add if err := s.ipset.close(); err != nil { </s> remove err := s.ipset.init(s.conf.IPSETList) </s> add err := s.ipset.init(s.conf.IpsetList) </s> remove // Initialize IPSET configuration </s> add // Initialize ipset configuration </s> remove // IPSET configuration - add IP addresses of the specified domain names to an ipset list // Syntax: // "DOMAIN[,DOMAIN].../IPSET_NAME" IPSETList []string `yaml:"ipset"` </s> add // IpsetList is the ipset configuration that allows AdGuard Home to add // IP addresses of the specified domain names to an ipset list. Syntax: // // DOMAIN[,DOMAIN].../IPSET_NAME // IpsetList []string `yaml:"ipset"`
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3ee0369cb91a0785cbea8ee99eadadad69d54cfa
internal/dnsforward/dnsforward.go
// To transfer information between modules type dnsContext struct { srv *Server proxyCtx *proxy.DNSContext setts *dnsfilter.RequestFilteringSettings // filtering settings for this client startTime time.Time result *dnsfilter.Result origResp *dns.Msg // response received from upstream servers. Set when response is modified by filtering origQuestion dns.Question // question received from client. Set when Rewrites are used. err error // error returned from the module protectionEnabled bool // filtering is enabled, dnsfilter object is ready responseFromUpstream bool // response is received from upstream servers } const ( resultDone = iota // module has completed its job, continue resultFinish // module has completed its job, exit normally resultError // an error occurred, exit with an error )
<mask> <mask> return true, nil <mask> } <mask> <mask> // handleDNSRequest filters the incoming DNS requests and writes them to the query log <mask> // nolint (gocyclo) <mask> func (s *Server) handleDNSRequest(p *proxy.Proxy, d *proxy.DNSContext) error { <mask> start := time.Now() <mask> <mask> if s.conf.AAAADisabled && d.Req.Question[0].Qtype == dns.TypeAAAA { <mask> _ = proxy.CheckDisabledAAAARequest(d, true) <mask> return nil <mask> } </s> Merge: * dns: refactor Squashed commit of the following: commit e9469266cafa3df537b5a4d5e28ca51db8289a34 Merge: 17cf6d60 e7e946fa Author: Simon Zolin <[email protected]> Date: Tue Jan 21 13:04:30 2020 +0300 Merge remote-tracking branch 'origin/master' into refactor commit 17cf6d60d11602df3837316119ba8828f41a95df Author: Simon Zolin <[email protected]> Date: Mon Jan 20 15:25:43 2020 +0300 minor commit 7b79462ebbeb743a10417bd28ceb70262ff9fa5c Author: Simon Zolin <[email protected]> Date: Fri Jan 17 17:50:09 2020 +0300 minor commit d8b175c7eda36005c0277e7876f0f0a55a661b05 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 15:30:37 2020 +0300 minor commit 93370aa32aa560d42fc67c95fd13f027ddc01b94 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 14:28:14 2020 +0300 * dns: refactor . introduce a local context object . move filtering, upstream logic, stats, querylog code to separate functions </s> remove return nil </s> add return resultFinish </s> remove func (s *Server) filterDNSRequest(d *proxy.DNSContext, setts *dnsfilter.RequestFilteringSettings) (*dnsfilter.Result, error) { </s> add func (s *Server) filterDNSRequest(ctx *dnsContext) (*dnsfilter.Result, error) { d := ctx.proxyCtx </s> remove res, err := s.dnsFilter.CheckHost(host, d.Req.Question[0].Qtype, setts) </s> add res, err := s.dnsFilter.CheckHost(host, d.Req.Question[0].Qtype, ctx.setts) </s> remove var origResp *dns.Msg if d.Res == nil { answer := []dns.RR{} originalQuestion := d.Req.Question[0] </s> add // Pass request to upstream servers; process the response func processUpstream(ctx *dnsContext) int { s := ctx.srv d := ctx.proxyCtx if d.Res != nil { return resultDone // response is already set - nothing to do }
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3f7e2f7241caa0cf0847579efefaa276e273f89e
dnsforward/dnsforward.go
// Perform initial checks; process WHOIS & rDNS func processInitial(ctx *dnsContext) int { s := ctx.srv d := ctx.proxyCtx
<mask> ) <mask> <mask> if s.conf.AAAADisabled && d.Req.Question[0].Qtype == dns.TypeAAAA { <mask> _ = proxy.CheckDisabledAAAARequest(d, true) <mask> return resultFinish <mask> } </s> Merge: * dns: refactor Squashed commit of the following: commit e9469266cafa3df537b5a4d5e28ca51db8289a34 Merge: 17cf6d60 e7e946fa Author: Simon Zolin <[email protected]> Date: Tue Jan 21 13:04:30 2020 +0300 Merge remote-tracking branch 'origin/master' into refactor commit 17cf6d60d11602df3837316119ba8828f41a95df Author: Simon Zolin <[email protected]> Date: Mon Jan 20 15:25:43 2020 +0300 minor commit 7b79462ebbeb743a10417bd28ceb70262ff9fa5c Author: Simon Zolin <[email protected]> Date: Fri Jan 17 17:50:09 2020 +0300 minor commit d8b175c7eda36005c0277e7876f0f0a55a661b05 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 15:30:37 2020 +0300 minor commit 93370aa32aa560d42fc67c95fd13f027ddc01b94 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 14:28:14 2020 +0300 * dns: refactor . introduce a local context object . move filtering, upstream logic, stats, querylog code to separate functions </s> remove return nil </s> add return resultFinish </s> remove // handleDNSRequest filters the incoming DNS requests and writes them to the query log // nolint (gocyclo) func (s *Server) handleDNSRequest(p *proxy.Proxy, d *proxy.DNSContext) error { start := time.Now() </s> add // To transfer information between modules type dnsContext struct { srv *Server proxyCtx *proxy.DNSContext setts *dnsfilter.RequestFilteringSettings // filtering settings for this client startTime time.Time result *dnsfilter.Result origResp *dns.Msg // response received from upstream servers. Set when response is modified by filtering origQuestion dns.Question // question received from client. Set when Rewrites are used. err error // error returned from the module protectionEnabled bool // filtering is enabled, dnsfilter object is ready responseFromUpstream bool // response is received from upstream servers } const ( resultDone = iota // module has completed its job, continue resultFinish // module has completed its job, exit normally resultError // an error occurred, exit with an error ) </s> remove return nil </s> add return resultFinish </s> remove // request was not filtered so let it be processed further err = p.Resolve(d) if err != nil { return err } </s> add ctx.responseFromUpstream = true return resultDone } </s> remove if len(d.Res.Answer) != 0 { answer = append(answer, d.Res.Answer...) // host -> IP d.Res.Answer = answer } </s> add if !ctx.responseFromUpstream { return resultDone // don't process response if it's not from upstream servers }
[ "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3f7e2f7241caa0cf0847579efefaa276e273f89e
dnsforward/dnsforward.go
return resultFinish
<mask> start := time.Now() <mask> <mask> if s.conf.AAAADisabled && d.Req.Question[0].Qtype == dns.TypeAAAA { <mask> _ = proxy.CheckDisabledAAAARequest(d, true) <mask> return nil <mask> } <mask> <mask> if s.conf.OnDNSRequest != nil { <mask> s.conf.OnDNSRequest(d) <mask> } </s> Merge: * dns: refactor Squashed commit of the following: commit e9469266cafa3df537b5a4d5e28ca51db8289a34 Merge: 17cf6d60 e7e946fa Author: Simon Zolin <[email protected]> Date: Tue Jan 21 13:04:30 2020 +0300 Merge remote-tracking branch 'origin/master' into refactor commit 17cf6d60d11602df3837316119ba8828f41a95df Author: Simon Zolin <[email protected]> Date: Mon Jan 20 15:25:43 2020 +0300 minor commit 7b79462ebbeb743a10417bd28ceb70262ff9fa5c Author: Simon Zolin <[email protected]> Date: Fri Jan 17 17:50:09 2020 +0300 minor commit d8b175c7eda36005c0277e7876f0f0a55a661b05 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 15:30:37 2020 +0300 minor commit 93370aa32aa560d42fc67c95fd13f027ddc01b94 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 14:28:14 2020 +0300 * dns: refactor . introduce a local context object . move filtering, upstream logic, stats, querylog code to separate functions </s> remove // handleDNSRequest filters the incoming DNS requests and writes them to the query log // nolint (gocyclo) func (s *Server) handleDNSRequest(p *proxy.Proxy, d *proxy.DNSContext) error { start := time.Now() </s> add // To transfer information between modules type dnsContext struct { srv *Server proxyCtx *proxy.DNSContext setts *dnsfilter.RequestFilteringSettings // filtering settings for this client startTime time.Time result *dnsfilter.Result origResp *dns.Msg // response received from upstream servers. Set when response is modified by filtering origQuestion dns.Question // question received from client. Set when Rewrites are used. err error // error returned from the module protectionEnabled bool // filtering is enabled, dnsfilter object is ready responseFromUpstream bool // response is received from upstream servers } const ( resultDone = iota // module has completed its job, continue resultFinish // module has completed its job, exit normally resultError // an error occurred, exit with an error ) </s> remove if d.Res != nil { d.Res.Compress = true // some devices require DNS message compression </s> add } else if res.Reason != dnsfilter.NotFilteredWhiteList && ctx.protectionEnabled { origResp2 := d.Res ctx.result, err = s.filterDNSResponse(ctx) if err != nil { ctx.err = err return resultError } if ctx.result != nil { ctx.origResp = origResp2 // matched by response } else { ctx.result = &dnsfilter.Result{} } </s> remove } else if res.Reason != dnsfilter.NotFilteredWhiteList && protectionEnabled { origResp2 := d.Res res, err = s.filterDNSResponse(d, setts) if err != nil { return err } if res != nil { origResp = origResp2 // matched by response } else { res = &dnsfilter.Result{} } </s> add if res.Reason == dnsfilter.ReasonRewrite && len(res.CanonName) != 0 { d.Req.Question[0] = ctx.origQuestion d.Res.Question[0] = ctx.origQuestion if len(d.Res.Answer) != 0 { answer := []dns.RR{} answer = append(answer, s.genCNAMEAnswer(d.Req, res.CanonName)) answer = append(answer, d.Res.Answer...) // host -> IP d.Res.Answer = answer </s> remove return err </s> add ctx.err = err return resultError
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3f7e2f7241caa0cf0847579efefaa276e273f89e
dnsforward/dnsforward.go
return resultFinish
<mask> // disable Mozilla DoH <mask> if (d.Req.Question[0].Qtype == dns.TypeA || d.Req.Question[0].Qtype == dns.TypeAAAA) && <mask> d.Req.Question[0].Name == "use-application-dns.net." { <mask> d.Res = s.genNXDomain(d.Req) <mask> return nil <mask> } <mask> <mask> // use dnsfilter before cache -- changed settings or filters would require cache invalidation otherwise <mask> s.RLock() <mask> // Synchronize access to s.dnsFilter so it won't be suddenly uninitialized while in use. </s> Merge: * dns: refactor Squashed commit of the following: commit e9469266cafa3df537b5a4d5e28ca51db8289a34 Merge: 17cf6d60 e7e946fa Author: Simon Zolin <[email protected]> Date: Tue Jan 21 13:04:30 2020 +0300 Merge remote-tracking branch 'origin/master' into refactor commit 17cf6d60d11602df3837316119ba8828f41a95df Author: Simon Zolin <[email protected]> Date: Mon Jan 20 15:25:43 2020 +0300 minor commit 7b79462ebbeb743a10417bd28ceb70262ff9fa5c Author: Simon Zolin <[email protected]> Date: Fri Jan 17 17:50:09 2020 +0300 minor commit d8b175c7eda36005c0277e7876f0f0a55a661b05 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 15:30:37 2020 +0300 minor commit 93370aa32aa560d42fc67c95fd13f027ddc01b94 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 14:28:14 2020 +0300 * dns: refactor . introduce a local context object . move filtering, upstream logic, stats, querylog code to separate functions </s> remove // use dnsfilter before cache -- changed settings or filters would require cache invalidation otherwise </s> add return resultDone } // Apply filtering logic func processFilteringBeforeRequest(ctx *dnsContext) int { s := ctx.srv d := ctx.proxyCtx </s> remove elapsed := time.Since(start) </s> add </s> remove if d.Addr != nil && s.conf.GetUpstreamsByClient != nil { clientIP := ipFromAddr(d.Addr) upstreams := s.conf.GetUpstreamsByClient(clientIP) if len(upstreams) > 0 { log.Debug("Using custom upstreams for %s", clientIP) d.Upstreams = upstreams } } </s> add // request was not filtered so let it be processed further err := s.dnsProxy.Resolve(d) if err != nil { ctx.err = err return resultError } </s> remove // request was not filtered so let it be processed further err = p.Resolve(d) if err != nil { return err } </s> add ctx.responseFromUpstream = true return resultDone }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3f7e2f7241caa0cf0847579efefaa276e273f89e
dnsforward/dnsforward.go
return resultDone } // Apply filtering logic func processFilteringBeforeRequest(ctx *dnsContext) int { s := ctx.srv d := ctx.proxyCtx
<mask> d.Res = s.genNXDomain(d.Req) <mask> return nil <mask> } <mask> <mask> // use dnsfilter before cache -- changed settings or filters would require cache invalidation otherwise <mask> s.RLock() <mask> // Synchronize access to s.dnsFilter so it won't be suddenly uninitialized while in use. <mask> // This could happen after proxy server has been stopped, but its workers are not yet exited. <mask> // <mask> // A better approach is for proxy.Stop() to wait until all its workers exit, </s> Merge: * dns: refactor Squashed commit of the following: commit e9469266cafa3df537b5a4d5e28ca51db8289a34 Merge: 17cf6d60 e7e946fa Author: Simon Zolin <[email protected]> Date: Tue Jan 21 13:04:30 2020 +0300 Merge remote-tracking branch 'origin/master' into refactor commit 17cf6d60d11602df3837316119ba8828f41a95df Author: Simon Zolin <[email protected]> Date: Mon Jan 20 15:25:43 2020 +0300 minor commit 7b79462ebbeb743a10417bd28ceb70262ff9fa5c Author: Simon Zolin <[email protected]> Date: Fri Jan 17 17:50:09 2020 +0300 minor commit d8b175c7eda36005c0277e7876f0f0a55a661b05 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 15:30:37 2020 +0300 minor commit 93370aa32aa560d42fc67c95fd13f027ddc01b94 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 14:28:14 2020 +0300 * dns: refactor . introduce a local context object . move filtering, upstream logic, stats, querylog code to separate functions </s> remove return nil </s> add return resultFinish </s> remove elapsed := time.Since(start) </s> add </s> remove var setts *dnsfilter.RequestFilteringSettings </s> add </s> remove // handleDNSRequest filters the incoming DNS requests and writes them to the query log // nolint (gocyclo) func (s *Server) handleDNSRequest(p *proxy.Proxy, d *proxy.DNSContext) error { start := time.Now() </s> add // To transfer information between modules type dnsContext struct { srv *Server proxyCtx *proxy.DNSContext setts *dnsfilter.RequestFilteringSettings // filtering settings for this client startTime time.Time result *dnsfilter.Result origResp *dns.Msg // response received from upstream servers. Set when response is modified by filtering origQuestion dns.Question // question received from client. Set when Rewrites are used. err error // error returned from the module protectionEnabled bool // filtering is enabled, dnsfilter object is ready responseFromUpstream bool // response is received from upstream servers } const ( resultDone = iota // module has completed its job, continue resultFinish // module has completed its job, exit normally resultError // an error occurred, exit with an error ) </s> remove if d.Addr != nil && s.conf.GetUpstreamsByClient != nil { clientIP := ipFromAddr(d.Addr) upstreams := s.conf.GetUpstreamsByClient(clientIP) if len(upstreams) > 0 { log.Debug("Using custom upstreams for %s", clientIP) d.Upstreams = upstreams } } </s> add // request was not filtered so let it be processed further err := s.dnsProxy.Resolve(d) if err != nil { ctx.err = err return resultError }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3f7e2f7241caa0cf0847579efefaa276e273f89e
dnsforward/dnsforward.go
<mask> // A better approach is for proxy.Stop() to wait until all its workers exit, <mask> // but this would require the Upstream interface to have Close() function <mask> // (to prevent from hanging while waiting for unresponsive DNS server to respond). <mask> <mask> var setts *dnsfilter.RequestFilteringSettings <mask> var err error <mask> res := &dnsfilter.Result{} <mask> protectionEnabled := s.conf.ProtectionEnabled && s.dnsFilter != nil <mask> if protectionEnabled { <mask> setts = s.getClientRequestFilteringSettings(d) </s> Merge: * dns: refactor Squashed commit of the following: commit e9469266cafa3df537b5a4d5e28ca51db8289a34 Merge: 17cf6d60 e7e946fa Author: Simon Zolin <[email protected]> Date: Tue Jan 21 13:04:30 2020 +0300 Merge remote-tracking branch 'origin/master' into refactor commit 17cf6d60d11602df3837316119ba8828f41a95df Author: Simon Zolin <[email protected]> Date: Mon Jan 20 15:25:43 2020 +0300 minor commit 7b79462ebbeb743a10417bd28ceb70262ff9fa5c Author: Simon Zolin <[email protected]> Date: Fri Jan 17 17:50:09 2020 +0300 minor commit d8b175c7eda36005c0277e7876f0f0a55a661b05 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 15:30:37 2020 +0300 minor commit 93370aa32aa560d42fc67c95fd13f027ddc01b94 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 14:28:14 2020 +0300 * dns: refactor . introduce a local context object . move filtering, upstream logic, stats, querylog code to separate functions </s> remove res := &dnsfilter.Result{} protectionEnabled := s.conf.ProtectionEnabled && s.dnsFilter != nil if protectionEnabled { setts = s.getClientRequestFilteringSettings(d) res, err = s.filterDNSRequest(d, setts) </s> add ctx.protectionEnabled = s.conf.ProtectionEnabled && s.dnsFilter != nil if ctx.protectionEnabled { ctx.setts = s.getClientRequestFilteringSettings(d) ctx.result, err = s.filterDNSRequest(ctx) </s> remove // use dnsfilter before cache -- changed settings or filters would require cache invalidation otherwise </s> add return resultDone } // Apply filtering logic func processFilteringBeforeRequest(ctx *dnsContext) int { s := ctx.srv d := ctx.proxyCtx </s> remove // handleDNSRequest filters the incoming DNS requests and writes them to the query log // nolint (gocyclo) func (s *Server) handleDNSRequest(p *proxy.Proxy, d *proxy.DNSContext) error { start := time.Now() </s> add // To transfer information between modules type dnsContext struct { srv *Server proxyCtx *proxy.DNSContext setts *dnsfilter.RequestFilteringSettings // filtering settings for this client startTime time.Time result *dnsfilter.Result origResp *dns.Msg // response received from upstream servers. Set when response is modified by filtering origQuestion dns.Question // question received from client. Set when Rewrites are used. err error // error returned from the module protectionEnabled bool // filtering is enabled, dnsfilter object is ready responseFromUpstream bool // response is received from upstream servers } const ( resultDone = iota // module has completed its job, continue resultFinish // module has completed its job, exit normally resultError // an error occurred, exit with an error ) </s> remove if res.Reason == dnsfilter.ReasonRewrite && len(res.CanonName) != 0 { d.Req.Question[0] = originalQuestion d.Res.Question[0] = originalQuestion </s> add // Apply filtering logic after we have received response from upstream servers func processFilteringAfterResponse(ctx *dnsContext) int { s := ctx.srv d := ctx.proxyCtx res := ctx.result var err error </s> remove elapsed := time.Since(start) </s> add
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3f7e2f7241caa0cf0847579efefaa276e273f89e
dnsforward/dnsforward.go
ctx.protectionEnabled = s.conf.ProtectionEnabled && s.dnsFilter != nil if ctx.protectionEnabled { ctx.setts = s.getClientRequestFilteringSettings(d) ctx.result, err = s.filterDNSRequest(ctx)
<mask> // (to prevent from hanging while waiting for unresponsive DNS server to respond). <mask> <mask> var setts *dnsfilter.RequestFilteringSettings <mask> var err error <mask> res := &dnsfilter.Result{} <mask> protectionEnabled := s.conf.ProtectionEnabled && s.dnsFilter != nil <mask> if protectionEnabled { <mask> setts = s.getClientRequestFilteringSettings(d) <mask> res, err = s.filterDNSRequest(d, setts) <mask> } <mask> s.RUnlock() <mask> if err != nil { <mask> return err <mask> } </s> Merge: * dns: refactor Squashed commit of the following: commit e9469266cafa3df537b5a4d5e28ca51db8289a34 Merge: 17cf6d60 e7e946fa Author: Simon Zolin <[email protected]> Date: Tue Jan 21 13:04:30 2020 +0300 Merge remote-tracking branch 'origin/master' into refactor commit 17cf6d60d11602df3837316119ba8828f41a95df Author: Simon Zolin <[email protected]> Date: Mon Jan 20 15:25:43 2020 +0300 minor commit 7b79462ebbeb743a10417bd28ceb70262ff9fa5c Author: Simon Zolin <[email protected]> Date: Fri Jan 17 17:50:09 2020 +0300 minor commit d8b175c7eda36005c0277e7876f0f0a55a661b05 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 15:30:37 2020 +0300 minor commit 93370aa32aa560d42fc67c95fd13f027ddc01b94 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 14:28:14 2020 +0300 * dns: refactor . introduce a local context object . move filtering, upstream logic, stats, querylog code to separate functions </s> remove var setts *dnsfilter.RequestFilteringSettings </s> add </s> remove return err </s> add ctx.err = err return resultError </s> remove } else if res.Reason != dnsfilter.NotFilteredWhiteList && protectionEnabled { origResp2 := d.Res res, err = s.filterDNSResponse(d, setts) if err != nil { return err } if res != nil { origResp = origResp2 // matched by response } else { res = &dnsfilter.Result{} } </s> add if res.Reason == dnsfilter.ReasonRewrite && len(res.CanonName) != 0 { d.Req.Question[0] = ctx.origQuestion d.Res.Question[0] = ctx.origQuestion if len(d.Res.Answer) != 0 { answer := []dns.RR{} answer = append(answer, s.genCNAMEAnswer(d.Req, res.CanonName)) answer = append(answer, d.Res.Answer...) // host -> IP d.Res.Answer = answer </s> remove if res.Reason == dnsfilter.ReasonRewrite && len(res.CanonName) != 0 { d.Req.Question[0] = originalQuestion d.Res.Question[0] = originalQuestion </s> add // Apply filtering logic after we have received response from upstream servers func processFilteringAfterResponse(ctx *dnsContext) int { s := ctx.srv d := ctx.proxyCtx res := ctx.result var err error </s> remove res, err := s.dnsFilter.CheckHostRules(host, d.Req.Question[0].Qtype, setts) </s> add res, err := s.dnsFilter.CheckHostRules(host, d.Req.Question[0].Qtype, ctx.setts)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3f7e2f7241caa0cf0847579efefaa276e273f89e
dnsforward/dnsforward.go
ctx.err = err return resultError
<mask> res, err = s.filterDNSRequest(d, setts) <mask> } <mask> s.RUnlock() <mask> if err != nil { <mask> return err <mask> } <mask> <mask> var origResp *dns.Msg <mask> if d.Res == nil { <mask> answer := []dns.RR{} </s> Merge: * dns: refactor Squashed commit of the following: commit e9469266cafa3df537b5a4d5e28ca51db8289a34 Merge: 17cf6d60 e7e946fa Author: Simon Zolin <[email protected]> Date: Tue Jan 21 13:04:30 2020 +0300 Merge remote-tracking branch 'origin/master' into refactor commit 17cf6d60d11602df3837316119ba8828f41a95df Author: Simon Zolin <[email protected]> Date: Mon Jan 20 15:25:43 2020 +0300 minor commit 7b79462ebbeb743a10417bd28ceb70262ff9fa5c Author: Simon Zolin <[email protected]> Date: Fri Jan 17 17:50:09 2020 +0300 minor commit d8b175c7eda36005c0277e7876f0f0a55a661b05 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 15:30:37 2020 +0300 minor commit 93370aa32aa560d42fc67c95fd13f027ddc01b94 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 14:28:14 2020 +0300 * dns: refactor . introduce a local context object . move filtering, upstream logic, stats, querylog code to separate functions </s> remove res := &dnsfilter.Result{} protectionEnabled := s.conf.ProtectionEnabled && s.dnsFilter != nil if protectionEnabled { setts = s.getClientRequestFilteringSettings(d) res, err = s.filterDNSRequest(d, setts) </s> add ctx.protectionEnabled = s.conf.ProtectionEnabled && s.dnsFilter != nil if ctx.protectionEnabled { ctx.setts = s.getClientRequestFilteringSettings(d) ctx.result, err = s.filterDNSRequest(ctx) </s> remove var origResp *dns.Msg if d.Res == nil { answer := []dns.RR{} originalQuestion := d.Req.Question[0] </s> add // Pass request to upstream servers; process the response func processUpstream(ctx *dnsContext) int { s := ctx.srv d := ctx.proxyCtx if d.Res != nil { return resultDone // response is already set - nothing to do } </s> remove } else if res.Reason != dnsfilter.NotFilteredWhiteList && protectionEnabled { origResp2 := d.Res res, err = s.filterDNSResponse(d, setts) if err != nil { return err } if res != nil { origResp = origResp2 // matched by response } else { res = &dnsfilter.Result{} } </s> add if res.Reason == dnsfilter.ReasonRewrite && len(res.CanonName) != 0 { d.Req.Question[0] = ctx.origQuestion d.Res.Question[0] = ctx.origQuestion if len(d.Res.Answer) != 0 { answer := []dns.RR{} answer = append(answer, s.genCNAMEAnswer(d.Req, res.CanonName)) answer = append(answer, d.Res.Answer...) // host -> IP d.Res.Answer = answer </s> remove res, err := s.dnsFilter.CheckHostRules(host, d.Req.Question[0].Qtype, setts) </s> add res, err := s.dnsFilter.CheckHostRules(host, d.Req.Question[0].Qtype, ctx.setts) </s> remove if len(d.Res.Answer) != 0 { answer = append(answer, d.Res.Answer...) // host -> IP d.Res.Answer = answer } </s> add if !ctx.responseFromUpstream { return resultDone // don't process response if it's not from upstream servers }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3f7e2f7241caa0cf0847579efefaa276e273f89e
dnsforward/dnsforward.go
return resultDone }
<mask> ctx.err = err <mask> return resultError <mask> } <mask> <mask> // Pass request to upstream servers; process the response <mask> func processUpstream(ctx *dnsContext) int { <mask> s := ctx.srv <mask> d := ctx.proxyCtx </s> Merge: * dns: refactor Squashed commit of the following: commit e9469266cafa3df537b5a4d5e28ca51db8289a34 Merge: 17cf6d60 e7e946fa Author: Simon Zolin <[email protected]> Date: Tue Jan 21 13:04:30 2020 +0300 Merge remote-tracking branch 'origin/master' into refactor commit 17cf6d60d11602df3837316119ba8828f41a95df Author: Simon Zolin <[email protected]> Date: Mon Jan 20 15:25:43 2020 +0300 minor commit 7b79462ebbeb743a10417bd28ceb70262ff9fa5c Author: Simon Zolin <[email protected]> Date: Fri Jan 17 17:50:09 2020 +0300 minor commit d8b175c7eda36005c0277e7876f0f0a55a661b05 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 15:30:37 2020 +0300 minor commit 93370aa32aa560d42fc67c95fd13f027ddc01b94 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 14:28:14 2020 +0300 * dns: refactor . introduce a local context object . move filtering, upstream logic, stats, querylog code to separate functions </s> remove var origResp *dns.Msg if d.Res == nil { answer := []dns.RR{} originalQuestion := d.Req.Question[0] </s> add // Pass request to upstream servers; process the response func processUpstream(ctx *dnsContext) int { s := ctx.srv d := ctx.proxyCtx if d.Res != nil { return resultDone // response is already set - nothing to do } </s> remove if res.Reason == dnsfilter.ReasonRewrite && len(res.CanonName) != 0 { d.Req.Question[0] = originalQuestion d.Res.Question[0] = originalQuestion </s> add // Apply filtering logic after we have received response from upstream servers func processFilteringAfterResponse(ctx *dnsContext) int { s := ctx.srv d := ctx.proxyCtx res := ctx.result var err error </s> remove if d.Addr != nil && s.conf.GetUpstreamsByClient != nil { clientIP := ipFromAddr(d.Addr) upstreams := s.conf.GetUpstreamsByClient(clientIP) if len(upstreams) > 0 { log.Debug("Using custom upstreams for %s", clientIP) d.Upstreams = upstreams } } </s> add // request was not filtered so let it be processed further err := s.dnsProxy.Resolve(d) if err != nil { ctx.err = err return resultError }
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3f7e2f7241caa0cf0847579efefaa276e273f89e
dnsforward/dnsforward.go
// Pass request to upstream servers; process the response func processUpstream(ctx *dnsContext) int { s := ctx.srv d := ctx.proxyCtx if d.Res != nil { return resultDone // response is already set - nothing to do }
<mask> if err != nil { <mask> return err <mask> } <mask> <mask> var origResp *dns.Msg <mask> if d.Res == nil { <mask> answer := []dns.RR{} <mask> originalQuestion := d.Req.Question[0] <mask> <mask> if res.Reason == dnsfilter.ReasonRewrite && len(res.CanonName) != 0 { <mask> answer = append(answer, s.genCNAMEAnswer(d.Req, res.CanonName)) <mask> // resolve canonical name, not the original host name <mask> d.Req.Question[0].Name = dns.Fqdn(res.CanonName) </s> Merge: * dns: refactor Squashed commit of the following: commit e9469266cafa3df537b5a4d5e28ca51db8289a34 Merge: 17cf6d60 e7e946fa Author: Simon Zolin <[email protected]> Date: Tue Jan 21 13:04:30 2020 +0300 Merge remote-tracking branch 'origin/master' into refactor commit 17cf6d60d11602df3837316119ba8828f41a95df Author: Simon Zolin <[email protected]> Date: Mon Jan 20 15:25:43 2020 +0300 minor commit 7b79462ebbeb743a10417bd28ceb70262ff9fa5c Author: Simon Zolin <[email protected]> Date: Fri Jan 17 17:50:09 2020 +0300 minor commit d8b175c7eda36005c0277e7876f0f0a55a661b05 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 15:30:37 2020 +0300 minor commit 93370aa32aa560d42fc67c95fd13f027ddc01b94 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 14:28:14 2020 +0300 * dns: refactor . introduce a local context object . move filtering, upstream logic, stats, querylog code to separate functions </s> remove if res.Reason == dnsfilter.ReasonRewrite && len(res.CanonName) != 0 { answer = append(answer, s.genCNAMEAnswer(d.Req, res.CanonName)) // resolve canonical name, not the original host name d.Req.Question[0].Name = dns.Fqdn(res.CanonName) </s> add if d.Addr != nil && s.conf.GetUpstreamsByClient != nil { clientIP := ipFromAddr(d.Addr) upstreams := s.conf.GetUpstreamsByClient(clientIP) if len(upstreams) > 0 { log.Debug("Using custom upstreams for %s", clientIP) d.Upstreams = upstreams </s> remove } else if res.Reason != dnsfilter.NotFilteredWhiteList && protectionEnabled { origResp2 := d.Res res, err = s.filterDNSResponse(d, setts) if err != nil { return err } if res != nil { origResp = origResp2 // matched by response } else { res = &dnsfilter.Result{} } </s> add if res.Reason == dnsfilter.ReasonRewrite && len(res.CanonName) != 0 { d.Req.Question[0] = ctx.origQuestion d.Res.Question[0] = ctx.origQuestion if len(d.Res.Answer) != 0 { answer := []dns.RR{} answer = append(answer, s.genCNAMEAnswer(d.Req, res.CanonName)) answer = append(answer, d.Res.Answer...) // host -> IP d.Res.Answer = answer </s> remove if len(d.Res.Answer) != 0 { answer = append(answer, d.Res.Answer...) // host -> IP d.Res.Answer = answer } </s> add if !ctx.responseFromUpstream { return resultDone // don't process response if it's not from upstream servers } </s> remove if res.Reason == dnsfilter.ReasonRewrite && len(res.CanonName) != 0 { d.Req.Question[0] = originalQuestion d.Res.Question[0] = originalQuestion </s> add // Apply filtering logic after we have received response from upstream servers func processFilteringAfterResponse(ctx *dnsContext) int { s := ctx.srv d := ctx.proxyCtx res := ctx.result var err error
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3f7e2f7241caa0cf0847579efefaa276e273f89e
dnsforward/dnsforward.go
if d.Addr != nil && s.conf.GetUpstreamsByClient != nil { clientIP := ipFromAddr(d.Addr) upstreams := s.conf.GetUpstreamsByClient(clientIP) if len(upstreams) > 0 { log.Debug("Using custom upstreams for %s", clientIP) d.Upstreams = upstreams
<mask> if d.Res == nil { <mask> answer := []dns.RR{} <mask> originalQuestion := d.Req.Question[0] <mask> <mask> if res.Reason == dnsfilter.ReasonRewrite && len(res.CanonName) != 0 { <mask> answer = append(answer, s.genCNAMEAnswer(d.Req, res.CanonName)) <mask> // resolve canonical name, not the original host name <mask> d.Req.Question[0].Name = dns.Fqdn(res.CanonName) <mask> } <mask> <mask> if d.Addr != nil && s.conf.GetUpstreamsByClient != nil { <mask> clientIP := ipFromAddr(d.Addr) <mask> upstreams := s.conf.GetUpstreamsByClient(clientIP) </s> Merge: * dns: refactor Squashed commit of the following: commit e9469266cafa3df537b5a4d5e28ca51db8289a34 Merge: 17cf6d60 e7e946fa Author: Simon Zolin <[email protected]> Date: Tue Jan 21 13:04:30 2020 +0300 Merge remote-tracking branch 'origin/master' into refactor commit 17cf6d60d11602df3837316119ba8828f41a95df Author: Simon Zolin <[email protected]> Date: Mon Jan 20 15:25:43 2020 +0300 minor commit 7b79462ebbeb743a10417bd28ceb70262ff9fa5c Author: Simon Zolin <[email protected]> Date: Fri Jan 17 17:50:09 2020 +0300 minor commit d8b175c7eda36005c0277e7876f0f0a55a661b05 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 15:30:37 2020 +0300 minor commit 93370aa32aa560d42fc67c95fd13f027ddc01b94 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 14:28:14 2020 +0300 * dns: refactor . introduce a local context object . move filtering, upstream logic, stats, querylog code to separate functions </s> remove var origResp *dns.Msg if d.Res == nil { answer := []dns.RR{} originalQuestion := d.Req.Question[0] </s> add // Pass request to upstream servers; process the response func processUpstream(ctx *dnsContext) int { s := ctx.srv d := ctx.proxyCtx if d.Res != nil { return resultDone // response is already set - nothing to do } </s> remove if d.Addr != nil && s.conf.GetUpstreamsByClient != nil { clientIP := ipFromAddr(d.Addr) upstreams := s.conf.GetUpstreamsByClient(clientIP) if len(upstreams) > 0 { log.Debug("Using custom upstreams for %s", clientIP) d.Upstreams = upstreams } } </s> add // request was not filtered so let it be processed further err := s.dnsProxy.Resolve(d) if err != nil { ctx.err = err return resultError } </s> remove } else if res.Reason != dnsfilter.NotFilteredWhiteList && protectionEnabled { origResp2 := d.Res res, err = s.filterDNSResponse(d, setts) if err != nil { return err } if res != nil { origResp = origResp2 // matched by response } else { res = &dnsfilter.Result{} } </s> add if res.Reason == dnsfilter.ReasonRewrite && len(res.CanonName) != 0 { d.Req.Question[0] = ctx.origQuestion d.Res.Question[0] = ctx.origQuestion if len(d.Res.Answer) != 0 { answer := []dns.RR{} answer = append(answer, s.genCNAMEAnswer(d.Req, res.CanonName)) answer = append(answer, d.Res.Answer...) // host -> IP d.Res.Answer = answer </s> remove if len(d.Res.Answer) != 0 { answer = append(answer, d.Res.Answer...) // host -> IP d.Res.Answer = answer } </s> add if !ctx.responseFromUpstream { return resultDone // don't process response if it's not from upstream servers }
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3f7e2f7241caa0cf0847579efefaa276e273f89e
dnsforward/dnsforward.go
}
<mask> d.Upstreams = upstreams <mask> } <mask> <mask> // request was not filtered so let it be processed further <mask> err := s.dnsProxy.Resolve(d) <mask> if err != nil { </s> Merge: * dns: refactor Squashed commit of the following: commit e9469266cafa3df537b5a4d5e28ca51db8289a34 Merge: 17cf6d60 e7e946fa Author: Simon Zolin <[email protected]> Date: Tue Jan 21 13:04:30 2020 +0300 Merge remote-tracking branch 'origin/master' into refactor commit 17cf6d60d11602df3837316119ba8828f41a95df Author: Simon Zolin <[email protected]> Date: Mon Jan 20 15:25:43 2020 +0300 minor commit 7b79462ebbeb743a10417bd28ceb70262ff9fa5c Author: Simon Zolin <[email protected]> Date: Fri Jan 17 17:50:09 2020 +0300 minor commit d8b175c7eda36005c0277e7876f0f0a55a661b05 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 15:30:37 2020 +0300 minor commit 93370aa32aa560d42fc67c95fd13f027ddc01b94 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 14:28:14 2020 +0300 * dns: refactor . introduce a local context object . move filtering, upstream logic, stats, querylog code to separate functions </s> remove if d.Addr != nil && s.conf.GetUpstreamsByClient != nil { clientIP := ipFromAddr(d.Addr) upstreams := s.conf.GetUpstreamsByClient(clientIP) if len(upstreams) > 0 { log.Debug("Using custom upstreams for %s", clientIP) d.Upstreams = upstreams } } </s> add // request was not filtered so let it be processed further err := s.dnsProxy.Resolve(d) if err != nil { ctx.err = err return resultError } </s> remove // request was not filtered so let it be processed further err = p.Resolve(d) if err != nil { return err } </s> add ctx.responseFromUpstream = true return resultDone } </s> remove if res.Reason == dnsfilter.ReasonRewrite && len(res.CanonName) != 0 { answer = append(answer, s.genCNAMEAnswer(d.Req, res.CanonName)) // resolve canonical name, not the original host name d.Req.Question[0].Name = dns.Fqdn(res.CanonName) </s> add if d.Addr != nil && s.conf.GetUpstreamsByClient != nil { clientIP := ipFromAddr(d.Addr) upstreams := s.conf.GetUpstreamsByClient(clientIP) if len(upstreams) > 0 { log.Debug("Using custom upstreams for %s", clientIP) d.Upstreams = upstreams </s> remove func (s *Server) filterDNSRequest(d *proxy.DNSContext, setts *dnsfilter.RequestFilteringSettings) (*dnsfilter.Result, error) { </s> add func (s *Server) filterDNSRequest(ctx *dnsContext) (*dnsfilter.Result, error) { d := ctx.proxyCtx </s> remove res, err := s.dnsFilter.CheckHost(host, d.Req.Question[0].Qtype, setts) </s> add res, err := s.dnsFilter.CheckHost(host, d.Req.Question[0].Qtype, ctx.setts)
[ "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3f7e2f7241caa0cf0847579efefaa276e273f89e
dnsforward/dnsforward.go
// request was not filtered so let it be processed further err := s.dnsProxy.Resolve(d) if err != nil { ctx.err = err return resultError }
<mask> // resolve canonical name, not the original host name <mask> d.Req.Question[0].Name = dns.Fqdn(res.CanonName) <mask> } <mask> <mask> if d.Addr != nil && s.conf.GetUpstreamsByClient != nil { <mask> clientIP := ipFromAddr(d.Addr) <mask> upstreams := s.conf.GetUpstreamsByClient(clientIP) <mask> if len(upstreams) > 0 { <mask> log.Debug("Using custom upstreams for %s", clientIP) <mask> d.Upstreams = upstreams <mask> } <mask> } <mask> <mask> // request was not filtered so let it be processed further <mask> err = p.Resolve(d) <mask> if err != nil { <mask> return err </s> Merge: * dns: refactor Squashed commit of the following: commit e9469266cafa3df537b5a4d5e28ca51db8289a34 Merge: 17cf6d60 e7e946fa Author: Simon Zolin <[email protected]> Date: Tue Jan 21 13:04:30 2020 +0300 Merge remote-tracking branch 'origin/master' into refactor commit 17cf6d60d11602df3837316119ba8828f41a95df Author: Simon Zolin <[email protected]> Date: Mon Jan 20 15:25:43 2020 +0300 minor commit 7b79462ebbeb743a10417bd28ceb70262ff9fa5c Author: Simon Zolin <[email protected]> Date: Fri Jan 17 17:50:09 2020 +0300 minor commit d8b175c7eda36005c0277e7876f0f0a55a661b05 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 15:30:37 2020 +0300 minor commit 93370aa32aa560d42fc67c95fd13f027ddc01b94 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 14:28:14 2020 +0300 * dns: refactor . introduce a local context object . move filtering, upstream logic, stats, querylog code to separate functions </s> remove if res.Reason == dnsfilter.ReasonRewrite && len(res.CanonName) != 0 { answer = append(answer, s.genCNAMEAnswer(d.Req, res.CanonName)) // resolve canonical name, not the original host name d.Req.Question[0].Name = dns.Fqdn(res.CanonName) </s> add if d.Addr != nil && s.conf.GetUpstreamsByClient != nil { clientIP := ipFromAddr(d.Addr) upstreams := s.conf.GetUpstreamsByClient(clientIP) if len(upstreams) > 0 { log.Debug("Using custom upstreams for %s", clientIP) d.Upstreams = upstreams </s> remove // request was not filtered so let it be processed further err = p.Resolve(d) if err != nil { return err } </s> add ctx.responseFromUpstream = true return resultDone } </s> remove var origResp *dns.Msg if d.Res == nil { answer := []dns.RR{} originalQuestion := d.Req.Question[0] </s> add // Pass request to upstream servers; process the response func processUpstream(ctx *dnsContext) int { s := ctx.srv d := ctx.proxyCtx if d.Res != nil { return resultDone // response is already set - nothing to do }
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3f7e2f7241caa0cf0847579efefaa276e273f89e
dnsforward/dnsforward.go
ctx.responseFromUpstream = true return resultDone }
<mask> d.Upstreams = upstreams <mask> } <mask> } <mask> <mask> // request was not filtered so let it be processed further <mask> err = p.Resolve(d) <mask> if err != nil { <mask> return err <mask> } <mask> <mask> if res.Reason == dnsfilter.ReasonRewrite && len(res.CanonName) != 0 { <mask> d.Req.Question[0] = originalQuestion <mask> d.Res.Question[0] = originalQuestion <mask> </s> Merge: * dns: refactor Squashed commit of the following: commit e9469266cafa3df537b5a4d5e28ca51db8289a34 Merge: 17cf6d60 e7e946fa Author: Simon Zolin <[email protected]> Date: Tue Jan 21 13:04:30 2020 +0300 Merge remote-tracking branch 'origin/master' into refactor commit 17cf6d60d11602df3837316119ba8828f41a95df Author: Simon Zolin <[email protected]> Date: Mon Jan 20 15:25:43 2020 +0300 minor commit 7b79462ebbeb743a10417bd28ceb70262ff9fa5c Author: Simon Zolin <[email protected]> Date: Fri Jan 17 17:50:09 2020 +0300 minor commit d8b175c7eda36005c0277e7876f0f0a55a661b05 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 15:30:37 2020 +0300 minor commit 93370aa32aa560d42fc67c95fd13f027ddc01b94 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 14:28:14 2020 +0300 * dns: refactor . introduce a local context object . move filtering, upstream logic, stats, querylog code to separate functions </s> remove if d.Addr != nil && s.conf.GetUpstreamsByClient != nil { clientIP := ipFromAddr(d.Addr) upstreams := s.conf.GetUpstreamsByClient(clientIP) if len(upstreams) > 0 { log.Debug("Using custom upstreams for %s", clientIP) d.Upstreams = upstreams } } </s> add // request was not filtered so let it be processed further err := s.dnsProxy.Resolve(d) if err != nil { ctx.err = err return resultError } </s> remove if len(d.Res.Answer) != 0 { answer = append(answer, d.Res.Answer...) // host -> IP d.Res.Answer = answer } </s> add if !ctx.responseFromUpstream { return resultDone // don't process response if it's not from upstream servers } </s> remove if res.Reason == dnsfilter.ReasonRewrite && len(res.CanonName) != 0 { d.Req.Question[0] = originalQuestion d.Res.Question[0] = originalQuestion </s> add // Apply filtering logic after we have received response from upstream servers func processFilteringAfterResponse(ctx *dnsContext) int { s := ctx.srv d := ctx.proxyCtx res := ctx.result var err error </s> remove if res.Reason == dnsfilter.ReasonRewrite && len(res.CanonName) != 0 { answer = append(answer, s.genCNAMEAnswer(d.Req, res.CanonName)) // resolve canonical name, not the original host name d.Req.Question[0].Name = dns.Fqdn(res.CanonName) </s> add if d.Addr != nil && s.conf.GetUpstreamsByClient != nil { clientIP := ipFromAddr(d.Addr) upstreams := s.conf.GetUpstreamsByClient(clientIP) if len(upstreams) > 0 { log.Debug("Using custom upstreams for %s", clientIP) d.Upstreams = upstreams
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3f7e2f7241caa0cf0847579efefaa276e273f89e
dnsforward/dnsforward.go
// Apply filtering logic after we have received response from upstream servers func processFilteringAfterResponse(ctx *dnsContext) int { s := ctx.srv d := ctx.proxyCtx res := ctx.result var err error
<mask> if err != nil { <mask> return err <mask> } <mask> <mask> if res.Reason == dnsfilter.ReasonRewrite && len(res.CanonName) != 0 { <mask> d.Req.Question[0] = originalQuestion <mask> d.Res.Question[0] = originalQuestion <mask> <mask> if len(d.Res.Answer) != 0 { <mask> answer = append(answer, d.Res.Answer...) // host -> IP <mask> d.Res.Answer = answer <mask> } </s> Merge: * dns: refactor Squashed commit of the following: commit e9469266cafa3df537b5a4d5e28ca51db8289a34 Merge: 17cf6d60 e7e946fa Author: Simon Zolin <[email protected]> Date: Tue Jan 21 13:04:30 2020 +0300 Merge remote-tracking branch 'origin/master' into refactor commit 17cf6d60d11602df3837316119ba8828f41a95df Author: Simon Zolin <[email protected]> Date: Mon Jan 20 15:25:43 2020 +0300 minor commit 7b79462ebbeb743a10417bd28ceb70262ff9fa5c Author: Simon Zolin <[email protected]> Date: Fri Jan 17 17:50:09 2020 +0300 minor commit d8b175c7eda36005c0277e7876f0f0a55a661b05 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 15:30:37 2020 +0300 minor commit 93370aa32aa560d42fc67c95fd13f027ddc01b94 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 14:28:14 2020 +0300 * dns: refactor . introduce a local context object . move filtering, upstream logic, stats, querylog code to separate functions </s> remove if len(d.Res.Answer) != 0 { answer = append(answer, d.Res.Answer...) // host -> IP d.Res.Answer = answer } </s> add if !ctx.responseFromUpstream { return resultDone // don't process response if it's not from upstream servers } </s> remove } else if res.Reason != dnsfilter.NotFilteredWhiteList && protectionEnabled { origResp2 := d.Res res, err = s.filterDNSResponse(d, setts) if err != nil { return err } if res != nil { origResp = origResp2 // matched by response } else { res = &dnsfilter.Result{} } </s> add if res.Reason == dnsfilter.ReasonRewrite && len(res.CanonName) != 0 { d.Req.Question[0] = ctx.origQuestion d.Res.Question[0] = ctx.origQuestion if len(d.Res.Answer) != 0 { answer := []dns.RR{} answer = append(answer, s.genCNAMEAnswer(d.Req, res.CanonName)) answer = append(answer, d.Res.Answer...) // host -> IP d.Res.Answer = answer </s> remove // request was not filtered so let it be processed further err = p.Resolve(d) if err != nil { return err } </s> add ctx.responseFromUpstream = true return resultDone } </s> remove var origResp *dns.Msg if d.Res == nil { answer := []dns.RR{} originalQuestion := d.Req.Question[0] </s> add // Pass request to upstream servers; process the response func processUpstream(ctx *dnsContext) int { s := ctx.srv d := ctx.proxyCtx if d.Res != nil { return resultDone // response is already set - nothing to do } </s> remove if res.Reason == dnsfilter.ReasonRewrite && len(res.CanonName) != 0 { answer = append(answer, s.genCNAMEAnswer(d.Req, res.CanonName)) // resolve canonical name, not the original host name d.Req.Question[0].Name = dns.Fqdn(res.CanonName) </s> add if d.Addr != nil && s.conf.GetUpstreamsByClient != nil { clientIP := ipFromAddr(d.Addr) upstreams := s.conf.GetUpstreamsByClient(clientIP) if len(upstreams) > 0 { log.Debug("Using custom upstreams for %s", clientIP) d.Upstreams = upstreams
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3f7e2f7241caa0cf0847579efefaa276e273f89e
dnsforward/dnsforward.go
if !ctx.responseFromUpstream { return resultDone // don't process response if it's not from upstream servers }
<mask> if res.Reason == dnsfilter.ReasonRewrite && len(res.CanonName) != 0 { <mask> d.Req.Question[0] = originalQuestion <mask> d.Res.Question[0] = originalQuestion <mask> <mask> if len(d.Res.Answer) != 0 { <mask> answer = append(answer, d.Res.Answer...) // host -> IP <mask> d.Res.Answer = answer <mask> } <mask> <mask> } else if res.Reason != dnsfilter.NotFilteredWhiteList && protectionEnabled { <mask> origResp2 := d.Res <mask> res, err = s.filterDNSResponse(d, setts) <mask> if err != nil { </s> Merge: * dns: refactor Squashed commit of the following: commit e9469266cafa3df537b5a4d5e28ca51db8289a34 Merge: 17cf6d60 e7e946fa Author: Simon Zolin <[email protected]> Date: Tue Jan 21 13:04:30 2020 +0300 Merge remote-tracking branch 'origin/master' into refactor commit 17cf6d60d11602df3837316119ba8828f41a95df Author: Simon Zolin <[email protected]> Date: Mon Jan 20 15:25:43 2020 +0300 minor commit 7b79462ebbeb743a10417bd28ceb70262ff9fa5c Author: Simon Zolin <[email protected]> Date: Fri Jan 17 17:50:09 2020 +0300 minor commit d8b175c7eda36005c0277e7876f0f0a55a661b05 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 15:30:37 2020 +0300 minor commit 93370aa32aa560d42fc67c95fd13f027ddc01b94 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 14:28:14 2020 +0300 * dns: refactor . introduce a local context object . move filtering, upstream logic, stats, querylog code to separate functions </s> remove } else if res.Reason != dnsfilter.NotFilteredWhiteList && protectionEnabled { origResp2 := d.Res res, err = s.filterDNSResponse(d, setts) if err != nil { return err } if res != nil { origResp = origResp2 // matched by response } else { res = &dnsfilter.Result{} } </s> add if res.Reason == dnsfilter.ReasonRewrite && len(res.CanonName) != 0 { d.Req.Question[0] = ctx.origQuestion d.Res.Question[0] = ctx.origQuestion if len(d.Res.Answer) != 0 { answer := []dns.RR{} answer = append(answer, s.genCNAMEAnswer(d.Req, res.CanonName)) answer = append(answer, d.Res.Answer...) // host -> IP d.Res.Answer = answer </s> remove if res.Reason == dnsfilter.ReasonRewrite && len(res.CanonName) != 0 { d.Req.Question[0] = originalQuestion d.Res.Question[0] = originalQuestion </s> add // Apply filtering logic after we have received response from upstream servers func processFilteringAfterResponse(ctx *dnsContext) int { s := ctx.srv d := ctx.proxyCtx res := ctx.result var err error </s> remove // request was not filtered so let it be processed further err = p.Resolve(d) if err != nil { return err } </s> add ctx.responseFromUpstream = true return resultDone } </s> remove if res.Reason == dnsfilter.ReasonRewrite && len(res.CanonName) != 0 { answer = append(answer, s.genCNAMEAnswer(d.Req, res.CanonName)) // resolve canonical name, not the original host name d.Req.Question[0].Name = dns.Fqdn(res.CanonName) </s> add if d.Addr != nil && s.conf.GetUpstreamsByClient != nil { clientIP := ipFromAddr(d.Addr) upstreams := s.conf.GetUpstreamsByClient(clientIP) if len(upstreams) > 0 { log.Debug("Using custom upstreams for %s", clientIP) d.Upstreams = upstreams </s> remove var origResp *dns.Msg if d.Res == nil { answer := []dns.RR{} originalQuestion := d.Req.Question[0] </s> add // Pass request to upstream servers; process the response func processUpstream(ctx *dnsContext) int { s := ctx.srv d := ctx.proxyCtx if d.Res != nil { return resultDone // response is already set - nothing to do }
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3f7e2f7241caa0cf0847579efefaa276e273f89e
dnsforward/dnsforward.go
if res.Reason == dnsfilter.ReasonRewrite && len(res.CanonName) != 0 { d.Req.Question[0] = ctx.origQuestion d.Res.Question[0] = ctx.origQuestion if len(d.Res.Answer) != 0 { answer := []dns.RR{} answer = append(answer, s.genCNAMEAnswer(d.Req, res.CanonName)) answer = append(answer, d.Res.Answer...) // host -> IP d.Res.Answer = answer
<mask> answer = append(answer, d.Res.Answer...) // host -> IP <mask> d.Res.Answer = answer <mask> } <mask> <mask> } else if res.Reason != dnsfilter.NotFilteredWhiteList && protectionEnabled { <mask> origResp2 := d.Res <mask> res, err = s.filterDNSResponse(d, setts) <mask> if err != nil { <mask> return err <mask> } <mask> if res != nil { <mask> origResp = origResp2 // matched by response <mask> } else { <mask> res = &dnsfilter.Result{} <mask> } <mask> } <mask> } <mask> <mask> if d.Res != nil { <mask> d.Res.Compress = true // some devices require DNS message compression </s> Merge: * dns: refactor Squashed commit of the following: commit e9469266cafa3df537b5a4d5e28ca51db8289a34 Merge: 17cf6d60 e7e946fa Author: Simon Zolin <[email protected]> Date: Tue Jan 21 13:04:30 2020 +0300 Merge remote-tracking branch 'origin/master' into refactor commit 17cf6d60d11602df3837316119ba8828f41a95df Author: Simon Zolin <[email protected]> Date: Mon Jan 20 15:25:43 2020 +0300 minor commit 7b79462ebbeb743a10417bd28ceb70262ff9fa5c Author: Simon Zolin <[email protected]> Date: Fri Jan 17 17:50:09 2020 +0300 minor commit d8b175c7eda36005c0277e7876f0f0a55a661b05 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 15:30:37 2020 +0300 minor commit 93370aa32aa560d42fc67c95fd13f027ddc01b94 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 14:28:14 2020 +0300 * dns: refactor . introduce a local context object . move filtering, upstream logic, stats, querylog code to separate functions </s> remove if d.Res != nil { d.Res.Compress = true // some devices require DNS message compression </s> add } else if res.Reason != dnsfilter.NotFilteredWhiteList && ctx.protectionEnabled { origResp2 := d.Res ctx.result, err = s.filterDNSResponse(ctx) if err != nil { ctx.err = err return resultError } if ctx.result != nil { ctx.origResp = origResp2 // matched by response } else { ctx.result = &dnsfilter.Result{} } </s> remove if len(d.Res.Answer) != 0 { answer = append(answer, d.Res.Answer...) // host -> IP d.Res.Answer = answer } </s> add if !ctx.responseFromUpstream { return resultDone // don't process response if it's not from upstream servers } </s> remove } </s> add </s> remove if res.Reason == dnsfilter.ReasonRewrite && len(res.CanonName) != 0 { d.Req.Question[0] = originalQuestion d.Res.Question[0] = originalQuestion </s> add // Apply filtering logic after we have received response from upstream servers func processFilteringAfterResponse(ctx *dnsContext) int { s := ctx.srv d := ctx.proxyCtx res := ctx.result var err error </s> remove res := &dnsfilter.Result{} protectionEnabled := s.conf.ProtectionEnabled && s.dnsFilter != nil if protectionEnabled { setts = s.getClientRequestFilteringSettings(d) res, err = s.filterDNSRequest(d, setts) </s> add ctx.protectionEnabled = s.conf.ProtectionEnabled && s.dnsFilter != nil if ctx.protectionEnabled { ctx.setts = s.getClientRequestFilteringSettings(d) ctx.result, err = s.filterDNSRequest(ctx)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3f7e2f7241caa0cf0847579efefaa276e273f89e
dnsforward/dnsforward.go
<mask> } else { <mask> res = &dnsfilter.Result{} <mask> } <mask> } <mask> } <mask> <mask> if d.Res != nil { <mask> d.Res.Compress = true // some devices require DNS message compression <mask> } <mask> </s> Merge: * dns: refactor Squashed commit of the following: commit e9469266cafa3df537b5a4d5e28ca51db8289a34 Merge: 17cf6d60 e7e946fa Author: Simon Zolin <[email protected]> Date: Tue Jan 21 13:04:30 2020 +0300 Merge remote-tracking branch 'origin/master' into refactor commit 17cf6d60d11602df3837316119ba8828f41a95df Author: Simon Zolin <[email protected]> Date: Mon Jan 20 15:25:43 2020 +0300 minor commit 7b79462ebbeb743a10417bd28ceb70262ff9fa5c Author: Simon Zolin <[email protected]> Date: Fri Jan 17 17:50:09 2020 +0300 minor commit d8b175c7eda36005c0277e7876f0f0a55a661b05 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 15:30:37 2020 +0300 minor commit 93370aa32aa560d42fc67c95fd13f027ddc01b94 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 14:28:14 2020 +0300 * dns: refactor . introduce a local context object . move filtering, upstream logic, stats, querylog code to separate functions </s> remove if d.Res != nil { d.Res.Compress = true // some devices require DNS message compression </s> add } else if res.Reason != dnsfilter.NotFilteredWhiteList && ctx.protectionEnabled { origResp2 := d.Res ctx.result, err = s.filterDNSResponse(ctx) if err != nil { ctx.err = err return resultError } if ctx.result != nil { ctx.origResp = origResp2 // matched by response } else { ctx.result = &dnsfilter.Result{} } </s> remove } else if res.Reason != dnsfilter.NotFilteredWhiteList && protectionEnabled { origResp2 := d.Res res, err = s.filterDNSResponse(d, setts) if err != nil { return err } if res != nil { origResp = origResp2 // matched by response } else { res = &dnsfilter.Result{} } </s> add if res.Reason == dnsfilter.ReasonRewrite && len(res.CanonName) != 0 { d.Req.Question[0] = ctx.origQuestion d.Res.Question[0] = ctx.origQuestion if len(d.Res.Answer) != 0 { answer := []dns.RR{} answer = append(answer, s.genCNAMEAnswer(d.Req, res.CanonName)) answer = append(answer, d.Res.Answer...) // host -> IP d.Res.Answer = answer </s> remove res := &dnsfilter.Result{} protectionEnabled := s.conf.ProtectionEnabled && s.dnsFilter != nil if protectionEnabled { setts = s.getClientRequestFilteringSettings(d) res, err = s.filterDNSRequest(d, setts) </s> add ctx.protectionEnabled = s.conf.ProtectionEnabled && s.dnsFilter != nil if ctx.protectionEnabled { ctx.setts = s.getClientRequestFilteringSettings(d) ctx.result, err = s.filterDNSRequest(ctx) </s> remove // request was not filtered so let it be processed further err = p.Resolve(d) if err != nil { return err } </s> add ctx.responseFromUpstream = true return resultDone } </s> remove if len(d.Res.Answer) != 0 { answer = append(answer, d.Res.Answer...) // host -> IP d.Res.Answer = answer } </s> add if !ctx.responseFromUpstream { return resultDone // don't process response if it's not from upstream servers }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3f7e2f7241caa0cf0847579efefaa276e273f89e
dnsforward/dnsforward.go
} else if res.Reason != dnsfilter.NotFilteredWhiteList && ctx.protectionEnabled { origResp2 := d.Res ctx.result, err = s.filterDNSResponse(ctx) if err != nil { ctx.err = err return resultError } if ctx.result != nil { ctx.origResp = origResp2 // matched by response } else { ctx.result = &dnsfilter.Result{} }
<mask> } <mask> } <mask> } <mask> <mask> if d.Res != nil { <mask> d.Res.Compress = true // some devices require DNS message compression <mask> } <mask> <mask> shouldLog := true <mask> msg := d.Req <mask> </s> Merge: * dns: refactor Squashed commit of the following: commit e9469266cafa3df537b5a4d5e28ca51db8289a34 Merge: 17cf6d60 e7e946fa Author: Simon Zolin <[email protected]> Date: Tue Jan 21 13:04:30 2020 +0300 Merge remote-tracking branch 'origin/master' into refactor commit 17cf6d60d11602df3837316119ba8828f41a95df Author: Simon Zolin <[email protected]> Date: Mon Jan 20 15:25:43 2020 +0300 minor commit 7b79462ebbeb743a10417bd28ceb70262ff9fa5c Author: Simon Zolin <[email protected]> Date: Fri Jan 17 17:50:09 2020 +0300 minor commit d8b175c7eda36005c0277e7876f0f0a55a661b05 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 15:30:37 2020 +0300 minor commit 93370aa32aa560d42fc67c95fd13f027ddc01b94 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 14:28:14 2020 +0300 * dns: refactor . introduce a local context object . move filtering, upstream logic, stats, querylog code to separate functions </s> remove } </s> add </s> remove } else if res.Reason != dnsfilter.NotFilteredWhiteList && protectionEnabled { origResp2 := d.Res res, err = s.filterDNSResponse(d, setts) if err != nil { return err } if res != nil { origResp = origResp2 // matched by response } else { res = &dnsfilter.Result{} } </s> add if res.Reason == dnsfilter.ReasonRewrite && len(res.CanonName) != 0 { d.Req.Question[0] = ctx.origQuestion d.Res.Question[0] = ctx.origQuestion if len(d.Res.Answer) != 0 { answer := []dns.RR{} answer = append(answer, s.genCNAMEAnswer(d.Req, res.CanonName)) answer = append(answer, d.Res.Answer...) // host -> IP d.Res.Answer = answer </s> remove // request was not filtered so let it be processed further err = p.Resolve(d) if err != nil { return err } </s> add ctx.responseFromUpstream = true return resultDone } </s> remove res := &dnsfilter.Result{} protectionEnabled := s.conf.ProtectionEnabled && s.dnsFilter != nil if protectionEnabled { setts = s.getClientRequestFilteringSettings(d) res, err = s.filterDNSRequest(d, setts) </s> add ctx.protectionEnabled = s.conf.ProtectionEnabled && s.dnsFilter != nil if ctx.protectionEnabled { ctx.setts = s.getClientRequestFilteringSettings(d) ctx.result, err = s.filterDNSRequest(ctx)
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3f7e2f7241caa0cf0847579efefaa276e273f89e
dnsforward/dnsforward.go
return resultDone } // Write Stats data and logs func processQueryLogsAndStats(ctx *dnsContext) int { elapsed := time.Since(ctx.startTime) s := ctx.srv d := ctx.proxyCtx
<mask> } <mask> <mask> shouldLog := true <mask> msg := d.Req <mask> <mask> // don't log ANY request if refuseAny is enabled <mask> if len(msg.Question) >= 1 && msg.Question[0].Qtype == dns.TypeANY && s.conf.RefuseAny { </s> Merge: * dns: refactor Squashed commit of the following: commit e9469266cafa3df537b5a4d5e28ca51db8289a34 Merge: 17cf6d60 e7e946fa Author: Simon Zolin <[email protected]> Date: Tue Jan 21 13:04:30 2020 +0300 Merge remote-tracking branch 'origin/master' into refactor commit 17cf6d60d11602df3837316119ba8828f41a95df Author: Simon Zolin <[email protected]> Date: Mon Jan 20 15:25:43 2020 +0300 minor commit 7b79462ebbeb743a10417bd28ceb70262ff9fa5c Author: Simon Zolin <[email protected]> Date: Fri Jan 17 17:50:09 2020 +0300 minor commit d8b175c7eda36005c0277e7876f0f0a55a661b05 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 15:30:37 2020 +0300 minor commit 93370aa32aa560d42fc67c95fd13f027ddc01b94 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 14:28:14 2020 +0300 * dns: refactor . introduce a local context object . move filtering, upstream logic, stats, querylog code to separate functions </s> remove elapsed := time.Since(start) </s> add </s> remove if d.Res != nil { d.Res.Compress = true // some devices require DNS message compression </s> add } else if res.Reason != dnsfilter.NotFilteredWhiteList && ctx.protectionEnabled { origResp2 := d.Res ctx.result, err = s.filterDNSResponse(ctx) if err != nil { ctx.err = err return resultError } if ctx.result != nil { ctx.origResp = origResp2 // matched by response } else { ctx.result = &dnsfilter.Result{} } </s> remove if len(d.Res.Answer) != 0 { answer = append(answer, d.Res.Answer...) // host -> IP d.Res.Answer = answer } </s> add if !ctx.responseFromUpstream { return resultDone // don't process response if it's not from upstream servers } </s> remove var origResp *dns.Msg if d.Res == nil { answer := []dns.RR{} originalQuestion := d.Req.Question[0] </s> add // Pass request to upstream servers; process the response func processUpstream(ctx *dnsContext) int { s := ctx.srv d := ctx.proxyCtx if d.Res != nil { return resultDone // response is already set - nothing to do } </s> remove } else if res.Reason != dnsfilter.NotFilteredWhiteList && protectionEnabled { origResp2 := d.Res res, err = s.filterDNSResponse(d, setts) if err != nil { return err } if res != nil { origResp = origResp2 // matched by response } else { res = &dnsfilter.Result{} } </s> add if res.Reason == dnsfilter.ReasonRewrite && len(res.CanonName) != 0 { d.Req.Question[0] = ctx.origQuestion d.Res.Question[0] = ctx.origQuestion if len(d.Res.Answer) != 0 { answer := []dns.RR{} answer = append(answer, s.genCNAMEAnswer(d.Req, res.CanonName)) answer = append(answer, d.Res.Answer...) // host -> IP d.Res.Answer = answer
[ "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3f7e2f7241caa0cf0847579efefaa276e273f89e
dnsforward/dnsforward.go
<mask> if len(msg.Question) >= 1 && msg.Question[0].Qtype == dns.TypeANY && s.conf.RefuseAny { <mask> shouldLog = false <mask> } <mask> <mask> elapsed := time.Since(start) <mask> s.RLock() <mask> // Synchronize access to s.queryLog and s.stats so they won't be suddenly uninitialized while in use. <mask> // This can happen after proxy server has been stopped, but its workers haven't yet exited. <mask> if shouldLog && s.queryLog != nil { <mask> p := querylog.AddParams{ </s> Merge: * dns: refactor Squashed commit of the following: commit e9469266cafa3df537b5a4d5e28ca51db8289a34 Merge: 17cf6d60 e7e946fa Author: Simon Zolin <[email protected]> Date: Tue Jan 21 13:04:30 2020 +0300 Merge remote-tracking branch 'origin/master' into refactor commit 17cf6d60d11602df3837316119ba8828f41a95df Author: Simon Zolin <[email protected]> Date: Mon Jan 20 15:25:43 2020 +0300 minor commit 7b79462ebbeb743a10417bd28ceb70262ff9fa5c Author: Simon Zolin <[email protected]> Date: Fri Jan 17 17:50:09 2020 +0300 minor commit d8b175c7eda36005c0277e7876f0f0a55a661b05 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 15:30:37 2020 +0300 minor commit 93370aa32aa560d42fc67c95fd13f027ddc01b94 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 14:28:14 2020 +0300 * dns: refactor . introduce a local context object . move filtering, upstream logic, stats, querylog code to separate functions </s> remove // use dnsfilter before cache -- changed settings or filters would require cache invalidation otherwise </s> add return resultDone } // Apply filtering logic func processFilteringBeforeRequest(ctx *dnsContext) int { s := ctx.srv d := ctx.proxyCtx </s> remove return nil </s> add return resultFinish </s> remove OrigAnswer: origResp, Result: res, </s> add OrigAnswer: ctx.origResp, Result: ctx.result, </s> remove var setts *dnsfilter.RequestFilteringSettings </s> add
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3f7e2f7241caa0cf0847579efefaa276e273f89e
dnsforward/dnsforward.go
OrigAnswer: ctx.origResp, Result: ctx.result,
<mask> if shouldLog && s.queryLog != nil { <mask> p := querylog.AddParams{ <mask> Question: msg, <mask> Answer: d.Res, <mask> OrigAnswer: origResp, <mask> Result: res, <mask> Elapsed: elapsed, <mask> ClientIP: getIP(d.Addr), <mask> } <mask> if d.Upstream != nil { <mask> p.Upstream = d.Upstream.Address() </s> Merge: * dns: refactor Squashed commit of the following: commit e9469266cafa3df537b5a4d5e28ca51db8289a34 Merge: 17cf6d60 e7e946fa Author: Simon Zolin <[email protected]> Date: Tue Jan 21 13:04:30 2020 +0300 Merge remote-tracking branch 'origin/master' into refactor commit 17cf6d60d11602df3837316119ba8828f41a95df Author: Simon Zolin <[email protected]> Date: Mon Jan 20 15:25:43 2020 +0300 minor commit 7b79462ebbeb743a10417bd28ceb70262ff9fa5c Author: Simon Zolin <[email protected]> Date: Fri Jan 17 17:50:09 2020 +0300 minor commit d8b175c7eda36005c0277e7876f0f0a55a661b05 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 15:30:37 2020 +0300 minor commit 93370aa32aa560d42fc67c95fd13f027ddc01b94 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 14:28:14 2020 +0300 * dns: refactor . introduce a local context object . move filtering, upstream logic, stats, querylog code to separate functions </s> remove elapsed := time.Since(start) </s> add </s> remove if d.Res != nil { d.Res.Compress = true // some devices require DNS message compression </s> add } else if res.Reason != dnsfilter.NotFilteredWhiteList && ctx.protectionEnabled { origResp2 := d.Res ctx.result, err = s.filterDNSResponse(ctx) if err != nil { ctx.err = err return resultError } if ctx.result != nil { ctx.origResp = origResp2 // matched by response } else { ctx.result = &dnsfilter.Result{} } </s> remove } else if res.Reason != dnsfilter.NotFilteredWhiteList && protectionEnabled { origResp2 := d.Res res, err = s.filterDNSResponse(d, setts) if err != nil { return err } if res != nil { origResp = origResp2 // matched by response } else { res = &dnsfilter.Result{} } </s> add if res.Reason == dnsfilter.ReasonRewrite && len(res.CanonName) != 0 { d.Req.Question[0] = ctx.origQuestion d.Res.Question[0] = ctx.origQuestion if len(d.Res.Answer) != 0 { answer := []dns.RR{} answer = append(answer, s.genCNAMEAnswer(d.Req, res.CanonName)) answer = append(answer, d.Res.Answer...) // host -> IP d.Res.Answer = answer </s> remove res := &dnsfilter.Result{} protectionEnabled := s.conf.ProtectionEnabled && s.dnsFilter != nil if protectionEnabled { setts = s.getClientRequestFilteringSettings(d) res, err = s.filterDNSRequest(d, setts) </s> add ctx.protectionEnabled = s.conf.ProtectionEnabled && s.dnsFilter != nil if ctx.protectionEnabled { ctx.setts = s.getClientRequestFilteringSettings(d) ctx.result, err = s.filterDNSRequest(ctx) </s> remove if res.Reason == dnsfilter.ReasonRewrite && len(res.CanonName) != 0 { answer = append(answer, s.genCNAMEAnswer(d.Req, res.CanonName)) // resolve canonical name, not the original host name d.Req.Question[0].Name = dns.Fqdn(res.CanonName) </s> add if d.Addr != nil && s.conf.GetUpstreamsByClient != nil { clientIP := ipFromAddr(d.Addr) upstreams := s.conf.GetUpstreamsByClient(clientIP) if len(upstreams) > 0 { log.Debug("Using custom upstreams for %s", clientIP) d.Upstreams = upstreams
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3f7e2f7241caa0cf0847579efefaa276e273f89e
dnsforward/dnsforward.go
s.updateStats(d, elapsed, *ctx.result)
<mask> } <mask> s.queryLog.Add(p) <mask> } <mask> <mask> s.updateStats(d, elapsed, *res) <mask> s.RUnlock() <mask> <mask> return nil <mask> } <mask> </s> Merge: * dns: refactor Squashed commit of the following: commit e9469266cafa3df537b5a4d5e28ca51db8289a34 Merge: 17cf6d60 e7e946fa Author: Simon Zolin <[email protected]> Date: Tue Jan 21 13:04:30 2020 +0300 Merge remote-tracking branch 'origin/master' into refactor commit 17cf6d60d11602df3837316119ba8828f41a95df Author: Simon Zolin <[email protected]> Date: Mon Jan 20 15:25:43 2020 +0300 minor commit 7b79462ebbeb743a10417bd28ceb70262ff9fa5c Author: Simon Zolin <[email protected]> Date: Fri Jan 17 17:50:09 2020 +0300 minor commit d8b175c7eda36005c0277e7876f0f0a55a661b05 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 15:30:37 2020 +0300 minor commit 93370aa32aa560d42fc67c95fd13f027ddc01b94 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 14:28:14 2020 +0300 * dns: refactor . introduce a local context object . move filtering, upstream logic, stats, querylog code to separate functions </s> remove return err </s> add ctx.err = err return resultError </s> remove res, err := s.dnsFilter.CheckHostRules(host, d.Req.Question[0].Qtype, setts) </s> add res, err := s.dnsFilter.CheckHostRules(host, d.Req.Question[0].Qtype, ctx.setts) </s> remove OrigAnswer: origResp, Result: res, </s> add OrigAnswer: ctx.origResp, Result: ctx.result, </s> remove res := &dnsfilter.Result{} protectionEnabled := s.conf.ProtectionEnabled && s.dnsFilter != nil if protectionEnabled { setts = s.getClientRequestFilteringSettings(d) res, err = s.filterDNSRequest(d, setts) </s> add ctx.protectionEnabled = s.conf.ProtectionEnabled && s.dnsFilter != nil if ctx.protectionEnabled { ctx.setts = s.getClientRequestFilteringSettings(d) ctx.result, err = s.filterDNSRequest(ctx) </s> remove return nil </s> add return resultFinish
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3f7e2f7241caa0cf0847579efefaa276e273f89e
dnsforward/dnsforward.go
func (s *Server) filterDNSRequest(ctx *dnsContext) (*dnsfilter.Result, error) { d := ctx.proxyCtx
<mask> return &setts <mask> } <mask> <mask> // filterDNSRequest applies the dnsFilter and sets d.Res if the request was filtered <mask> func (s *Server) filterDNSRequest(d *proxy.DNSContext, setts *dnsfilter.RequestFilteringSettings) (*dnsfilter.Result, error) { <mask> req := d.Req <mask> host := strings.TrimSuffix(req.Question[0].Name, ".") <mask> res, err := s.dnsFilter.CheckHost(host, d.Req.Question[0].Qtype, setts) <mask> if err != nil { <mask> // Return immediately if there's an error </s> Merge: * dns: refactor Squashed commit of the following: commit e9469266cafa3df537b5a4d5e28ca51db8289a34 Merge: 17cf6d60 e7e946fa Author: Simon Zolin <[email protected]> Date: Tue Jan 21 13:04:30 2020 +0300 Merge remote-tracking branch 'origin/master' into refactor commit 17cf6d60d11602df3837316119ba8828f41a95df Author: Simon Zolin <[email protected]> Date: Mon Jan 20 15:25:43 2020 +0300 minor commit 7b79462ebbeb743a10417bd28ceb70262ff9fa5c Author: Simon Zolin <[email protected]> Date: Fri Jan 17 17:50:09 2020 +0300 minor commit d8b175c7eda36005c0277e7876f0f0a55a661b05 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 15:30:37 2020 +0300 minor commit 93370aa32aa560d42fc67c95fd13f027ddc01b94 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 14:28:14 2020 +0300 * dns: refactor . introduce a local context object . move filtering, upstream logic, stats, querylog code to separate functions </s> remove res, err := s.dnsFilter.CheckHost(host, d.Req.Question[0].Qtype, setts) </s> add res, err := s.dnsFilter.CheckHost(host, d.Req.Question[0].Qtype, ctx.setts) </s> remove func (s *Server) filterDNSResponse(d *proxy.DNSContext, setts *dnsfilter.RequestFilteringSettings) (*dnsfilter.Result, error) { </s> add func (s *Server) filterDNSResponse(ctx *dnsContext) (*dnsfilter.Result, error) { d := ctx.proxyCtx </s> remove if d.Addr != nil && s.conf.GetUpstreamsByClient != nil { clientIP := ipFromAddr(d.Addr) upstreams := s.conf.GetUpstreamsByClient(clientIP) if len(upstreams) > 0 { log.Debug("Using custom upstreams for %s", clientIP) d.Upstreams = upstreams } } </s> add // request was not filtered so let it be processed further err := s.dnsProxy.Resolve(d) if err != nil { ctx.err = err return resultError } </s> remove res, err := s.dnsFilter.CheckHostRules(host, d.Req.Question[0].Qtype, setts) </s> add res, err := s.dnsFilter.CheckHostRules(host, d.Req.Question[0].Qtype, ctx.setts) </s> remove res := &dnsfilter.Result{} protectionEnabled := s.conf.ProtectionEnabled && s.dnsFilter != nil if protectionEnabled { setts = s.getClientRequestFilteringSettings(d) res, err = s.filterDNSRequest(d, setts) </s> add ctx.protectionEnabled = s.conf.ProtectionEnabled && s.dnsFilter != nil if ctx.protectionEnabled { ctx.setts = s.getClientRequestFilteringSettings(d) ctx.result, err = s.filterDNSRequest(ctx)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3f7e2f7241caa0cf0847579efefaa276e273f89e
dnsforward/dnsforward.go
res, err := s.dnsFilter.CheckHost(host, d.Req.Question[0].Qtype, ctx.setts)
<mask> // filterDNSRequest applies the dnsFilter and sets d.Res if the request was filtered <mask> func (s *Server) filterDNSRequest(d *proxy.DNSContext, setts *dnsfilter.RequestFilteringSettings) (*dnsfilter.Result, error) { <mask> req := d.Req <mask> host := strings.TrimSuffix(req.Question[0].Name, ".") <mask> res, err := s.dnsFilter.CheckHost(host, d.Req.Question[0].Qtype, setts) <mask> if err != nil { <mask> // Return immediately if there's an error <mask> return nil, errorx.Decorate(err, "dnsfilter failed to check host '%s'", host) <mask> <mask> } else if res.IsFiltered { </s> Merge: * dns: refactor Squashed commit of the following: commit e9469266cafa3df537b5a4d5e28ca51db8289a34 Merge: 17cf6d60 e7e946fa Author: Simon Zolin <[email protected]> Date: Tue Jan 21 13:04:30 2020 +0300 Merge remote-tracking branch 'origin/master' into refactor commit 17cf6d60d11602df3837316119ba8828f41a95df Author: Simon Zolin <[email protected]> Date: Mon Jan 20 15:25:43 2020 +0300 minor commit 7b79462ebbeb743a10417bd28ceb70262ff9fa5c Author: Simon Zolin <[email protected]> Date: Fri Jan 17 17:50:09 2020 +0300 minor commit d8b175c7eda36005c0277e7876f0f0a55a661b05 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 15:30:37 2020 +0300 minor commit 93370aa32aa560d42fc67c95fd13f027ddc01b94 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 14:28:14 2020 +0300 * dns: refactor . introduce a local context object . move filtering, upstream logic, stats, querylog code to separate functions </s> remove func (s *Server) filterDNSRequest(d *proxy.DNSContext, setts *dnsfilter.RequestFilteringSettings) (*dnsfilter.Result, error) { </s> add func (s *Server) filterDNSRequest(ctx *dnsContext) (*dnsfilter.Result, error) { d := ctx.proxyCtx </s> remove func (s *Server) filterDNSResponse(d *proxy.DNSContext, setts *dnsfilter.RequestFilteringSettings) (*dnsfilter.Result, error) { </s> add func (s *Server) filterDNSResponse(ctx *dnsContext) (*dnsfilter.Result, error) { d := ctx.proxyCtx </s> remove res, err := s.dnsFilter.CheckHostRules(host, d.Req.Question[0].Qtype, setts) </s> add res, err := s.dnsFilter.CheckHostRules(host, d.Req.Question[0].Qtype, ctx.setts) </s> remove if d.Addr != nil && s.conf.GetUpstreamsByClient != nil { clientIP := ipFromAddr(d.Addr) upstreams := s.conf.GetUpstreamsByClient(clientIP) if len(upstreams) > 0 { log.Debug("Using custom upstreams for %s", clientIP) d.Upstreams = upstreams } } </s> add // request was not filtered so let it be processed further err := s.dnsProxy.Resolve(d) if err != nil { ctx.err = err return resultError } </s> remove var origResp *dns.Msg if d.Res == nil { answer := []dns.RR{} originalQuestion := d.Req.Question[0] </s> add // Pass request to upstream servers; process the response func processUpstream(ctx *dnsContext) int { s := ctx.srv d := ctx.proxyCtx if d.Res != nil { return resultDone // response is already set - nothing to do }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3f7e2f7241caa0cf0847579efefaa276e273f89e
dnsforward/dnsforward.go
} else if res.Reason == dnsfilter.ReasonRewrite && len(res.CanonName) != 0 { ctx.origQuestion = d.Req.Question[0] // resolve canonical name, not the original host name d.Req.Question[0].Name = dns.Fqdn(res.CanonName)
<mask> } <mask> } <mask> <mask> d.Res = resp <mask> } <mask> <mask> return &res, err <mask> } <mask> <mask> // If response contains CNAME, A or AAAA records, we apply filtering to each canonical host name or IP address. </s> Merge: * dns: refactor Squashed commit of the following: commit e9469266cafa3df537b5a4d5e28ca51db8289a34 Merge: 17cf6d60 e7e946fa Author: Simon Zolin <[email protected]> Date: Tue Jan 21 13:04:30 2020 +0300 Merge remote-tracking branch 'origin/master' into refactor commit 17cf6d60d11602df3837316119ba8828f41a95df Author: Simon Zolin <[email protected]> Date: Mon Jan 20 15:25:43 2020 +0300 minor commit 7b79462ebbeb743a10417bd28ceb70262ff9fa5c Author: Simon Zolin <[email protected]> Date: Fri Jan 17 17:50:09 2020 +0300 minor commit d8b175c7eda36005c0277e7876f0f0a55a661b05 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 15:30:37 2020 +0300 minor commit 93370aa32aa560d42fc67c95fd13f027ddc01b94 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 14:28:14 2020 +0300 * dns: refactor . introduce a local context object . move filtering, upstream logic, stats, querylog code to separate functions </s> remove func (s *Server) filterDNSResponse(d *proxy.DNSContext, setts *dnsfilter.RequestFilteringSettings) (*dnsfilter.Result, error) { </s> add func (s *Server) filterDNSResponse(ctx *dnsContext) (*dnsfilter.Result, error) { d := ctx.proxyCtx </s> remove if res.Reason == dnsfilter.ReasonRewrite && len(res.CanonName) != 0 { d.Req.Question[0] = originalQuestion d.Res.Question[0] = originalQuestion </s> add // Apply filtering logic after we have received response from upstream servers func processFilteringAfterResponse(ctx *dnsContext) int { s := ctx.srv d := ctx.proxyCtx res := ctx.result var err error </s> remove // use dnsfilter before cache -- changed settings or filters would require cache invalidation otherwise </s> add return resultDone } // Apply filtering logic func processFilteringBeforeRequest(ctx *dnsContext) int { s := ctx.srv d := ctx.proxyCtx </s> remove var origResp *dns.Msg if d.Res == nil { answer := []dns.RR{} originalQuestion := d.Req.Question[0] </s> add // Pass request to upstream servers; process the response func processUpstream(ctx *dnsContext) int { s := ctx.srv d := ctx.proxyCtx if d.Res != nil { return resultDone // response is already set - nothing to do } </s> remove } else if res.Reason != dnsfilter.NotFilteredWhiteList && protectionEnabled { origResp2 := d.Res res, err = s.filterDNSResponse(d, setts) if err != nil { return err } if res != nil { origResp = origResp2 // matched by response } else { res = &dnsfilter.Result{} } </s> add if res.Reason == dnsfilter.ReasonRewrite && len(res.CanonName) != 0 { d.Req.Question[0] = ctx.origQuestion d.Res.Question[0] = ctx.origQuestion if len(d.Res.Answer) != 0 { answer := []dns.RR{} answer = append(answer, s.genCNAMEAnswer(d.Req, res.CanonName)) answer = append(answer, d.Res.Answer...) // host -> IP d.Res.Answer = answer
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3f7e2f7241caa0cf0847579efefaa276e273f89e
dnsforward/dnsforward.go
func (s *Server) filterDNSResponse(ctx *dnsContext) (*dnsfilter.Result, error) { d := ctx.proxyCtx
<mask> } <mask> <mask> // If response contains CNAME, A or AAAA records, we apply filtering to each canonical host name or IP address. <mask> // If this is a match, we set a new response in d.Res and return. <mask> func (s *Server) filterDNSResponse(d *proxy.DNSContext, setts *dnsfilter.RequestFilteringSettings) (*dnsfilter.Result, error) { <mask> for _, a := range d.Res.Answer { <mask> host := "" <mask> <mask> switch v := a.(type) { <mask> case *dns.CNAME: </s> Merge: * dns: refactor Squashed commit of the following: commit e9469266cafa3df537b5a4d5e28ca51db8289a34 Merge: 17cf6d60 e7e946fa Author: Simon Zolin <[email protected]> Date: Tue Jan 21 13:04:30 2020 +0300 Merge remote-tracking branch 'origin/master' into refactor commit 17cf6d60d11602df3837316119ba8828f41a95df Author: Simon Zolin <[email protected]> Date: Mon Jan 20 15:25:43 2020 +0300 minor commit 7b79462ebbeb743a10417bd28ceb70262ff9fa5c Author: Simon Zolin <[email protected]> Date: Fri Jan 17 17:50:09 2020 +0300 minor commit d8b175c7eda36005c0277e7876f0f0a55a661b05 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 15:30:37 2020 +0300 minor commit 93370aa32aa560d42fc67c95fd13f027ddc01b94 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 14:28:14 2020 +0300 * dns: refactor . introduce a local context object . move filtering, upstream logic, stats, querylog code to separate functions </s> remove func (s *Server) filterDNSRequest(d *proxy.DNSContext, setts *dnsfilter.RequestFilteringSettings) (*dnsfilter.Result, error) { </s> add func (s *Server) filterDNSRequest(ctx *dnsContext) (*dnsfilter.Result, error) { d := ctx.proxyCtx </s> remove res, err := s.dnsFilter.CheckHost(host, d.Req.Question[0].Qtype, setts) </s> add res, err := s.dnsFilter.CheckHost(host, d.Req.Question[0].Qtype, ctx.setts) </s> remove if res.Reason == dnsfilter.ReasonRewrite && len(res.CanonName) != 0 { d.Req.Question[0] = originalQuestion d.Res.Question[0] = originalQuestion </s> add // Apply filtering logic after we have received response from upstream servers func processFilteringAfterResponse(ctx *dnsContext) int { s := ctx.srv d := ctx.proxyCtx res := ctx.result var err error </s> remove var origResp *dns.Msg if d.Res == nil { answer := []dns.RR{} originalQuestion := d.Req.Question[0] </s> add // Pass request to upstream servers; process the response func processUpstream(ctx *dnsContext) int { s := ctx.srv d := ctx.proxyCtx if d.Res != nil { return resultDone // response is already set - nothing to do }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3f7e2f7241caa0cf0847579efefaa276e273f89e
dnsforward/dnsforward.go
res, err := s.dnsFilter.CheckHostRules(host, d.Req.Question[0].Qtype, ctx.setts)
<mask> if !s.conf.ProtectionEnabled || s.dnsFilter == nil { <mask> s.RUnlock() <mask> continue <mask> } <mask> res, err := s.dnsFilter.CheckHostRules(host, d.Req.Question[0].Qtype, setts) <mask> s.RUnlock() <mask> <mask> if err != nil { <mask> return nil, err <mask> </s> Merge: * dns: refactor Squashed commit of the following: commit e9469266cafa3df537b5a4d5e28ca51db8289a34 Merge: 17cf6d60 e7e946fa Author: Simon Zolin <[email protected]> Date: Tue Jan 21 13:04:30 2020 +0300 Merge remote-tracking branch 'origin/master' into refactor commit 17cf6d60d11602df3837316119ba8828f41a95df Author: Simon Zolin <[email protected]> Date: Mon Jan 20 15:25:43 2020 +0300 minor commit 7b79462ebbeb743a10417bd28ceb70262ff9fa5c Author: Simon Zolin <[email protected]> Date: Fri Jan 17 17:50:09 2020 +0300 minor commit d8b175c7eda36005c0277e7876f0f0a55a661b05 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 15:30:37 2020 +0300 minor commit 93370aa32aa560d42fc67c95fd13f027ddc01b94 Author: Simon Zolin <[email protected]> Date: Fri Jan 17 14:28:14 2020 +0300 * dns: refactor . introduce a local context object . move filtering, upstream logic, stats, querylog code to separate functions </s> remove return err </s> add ctx.err = err return resultError </s> remove res := &dnsfilter.Result{} protectionEnabled := s.conf.ProtectionEnabled && s.dnsFilter != nil if protectionEnabled { setts = s.getClientRequestFilteringSettings(d) res, err = s.filterDNSRequest(d, setts) </s> add ctx.protectionEnabled = s.conf.ProtectionEnabled && s.dnsFilter != nil if ctx.protectionEnabled { ctx.setts = s.getClientRequestFilteringSettings(d) ctx.result, err = s.filterDNSRequest(ctx) </s> remove res, err := s.dnsFilter.CheckHost(host, d.Req.Question[0].Qtype, setts) </s> add res, err := s.dnsFilter.CheckHost(host, d.Req.Question[0].Qtype, ctx.setts) </s> remove func (s *Server) filterDNSRequest(d *proxy.DNSContext, setts *dnsfilter.RequestFilteringSettings) (*dnsfilter.Result, error) { </s> add func (s *Server) filterDNSRequest(ctx *dnsContext) (*dnsfilter.Result, error) { d := ctx.proxyCtx </s> remove if len(d.Res.Answer) != 0 { answer = append(answer, d.Res.Answer...) // host -> IP d.Res.Answer = answer } </s> add if !ctx.responseFromUpstream { return resultDone // don't process response if it's not from upstream servers }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/3f7e2f7241caa0cf0847579efefaa276e273f89e
dnsforward/dnsforward.go
ProtectionEnabled bool `yaml:"protection_enabled"`
<mask> coreFile string <mask> FilterFile string `yaml:"-"` <mask> Port int `yaml:"port"` <mask> FilteringEnabled bool `yaml:"filtering_enabled"` <mask> SafeBrowsingEnabled bool `yaml:"safebrowsing_enabled"` <mask> SafeSearchEnabled bool `yaml:"safesearch_enabled"` <mask> ParentalEnabled bool `yaml:"parental_enabled"` <mask> ParentalSensitivity int `yaml:"parental_sensitivity"` <mask> BlockedResponseTTL int `yaml:"blocked_response_ttl"` </s> API backend -- implement ability to turn toggle all protection in one go, helpful to temporarily disable all kinds of filtering </s> remove err = writeAllConfigs() if err != nil { errortext := fmt.Sprintf("Couldn't write config file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add </s> remove dnsfilter {{if .FilteringEnabled}}{{.FilterFile}}{{end}} { </s> add {{if .ProtectionEnabled}}dnsfilter {{if .FilteringEnabled}}{{.FilterFile}}{{end}} { </s> remove } </s> add }{{end}} </s> remove "running": isRunning(), "version": VersionString, "dns_address": config.BindHost, "dns_port": config.CoreDNS.Port, "querylog_enabled": config.CoreDNS.QueryLogEnabled, "upstream_dns": config.CoreDNS.UpstreamDNS, </s> add "dns_address": config.BindHost, "dns_port": config.CoreDNS.Port, "protection_enabled": config.CoreDNS.ProtectionEnabled, "querylog_enabled": config.CoreDNS.QueryLogEnabled, "running": isRunning(), "upstream_dns": config.CoreDNS.UpstreamDNS, "version": VersionString,
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/413228e6ecaf9019c8eac7034f1404b5c9c497fd
config.go
ProtectionEnabled: true,
<mask> Port: 53, <mask> binaryFile: "coredns", // only filename, no path <mask> coreFile: "Corefile", // only filename, no path <mask> FilterFile: "dnsfilter.txt", // only filename, no path <mask> FilteringEnabled: true, <mask> SafeBrowsingEnabled: false, <mask> BlockedResponseTTL: 60, // in seconds <mask> QueryLogEnabled: true, <mask> UpstreamDNS: defaultDNS, </s> API backend -- implement ability to turn toggle all protection in one go, helpful to temporarily disable all kinds of filtering </s> remove err = writeAllConfigs() if err != nil { errortext := fmt.Sprintf("Couldn't write config file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add </s> remove tellCoreDNSToReload() _, err = fmt.Fprintf(w, "OK\n") if err != nil { errortext := fmt.Sprintf("Couldn't write body: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) } // TODO: regenerate coredns config and tell coredns to reload it if it's running </s> add httpUpdateConfigReloadDNSReturnOK(w, r) </s> remove err := writeAllConfigsAndReloadCoreDNS() if err != nil { errortext := fmt.Sprintf("Couldn't write config file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } _, err = fmt.Fprintf(w, "OK\n") if err != nil { errortext := fmt.Sprintf("Couldn't write body: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) } </s> add httpUpdateConfigReloadDNSReturnOK(w, r) </s> remove err := writeAllConfigsAndReloadCoreDNS() if err != nil { errortext := fmt.Sprintf("Couldn't write config file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } _, err = fmt.Fprintf(w, "OK\n") if err != nil { errortext := fmt.Sprintf("Couldn't write body: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) } </s> add httpUpdateConfigReloadDNSReturnOK(w, r)
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/413228e6ecaf9019c8eac7034f1404b5c9c497fd
config.go
{{if .ProtectionEnabled}}dnsfilter {{if .FilteringEnabled}}{{.FilterFile}}{{end}} {
<mask> return nil <mask> } <mask> <mask> const coreDNSConfigTemplate = `. { <mask> dnsfilter {{if .FilteringEnabled}}{{.FilterFile}}{{end}} { <mask> {{if .SafeBrowsingEnabled}}safebrowsing{{end}} <mask> {{if .ParentalEnabled}}parental {{.ParentalSensitivity}}{{end}} <mask> {{if .SafeSearchEnabled}}safesearch{{end}} <mask> {{if .QueryLogEnabled}}querylog{{end}} <mask> blocked_ttl {{.BlockedResponseTTL}} </s> API backend -- implement ability to turn toggle all protection in one go, helpful to temporarily disable all kinds of filtering </s> remove } </s> add }{{end}} </s> remove err = writeAllConfigsAndReloadCoreDNS() if err != nil { errortext := fmt.Sprintf("Couldn't write config file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } _, err = fmt.Fprintf(w, "OK\n") if err != nil { errortext := fmt.Sprintf("Couldn't write body: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) } </s> add httpUpdateConfigReloadDNSReturnOK(w, r) </s> remove err = writeAllConfigs() if err != nil { errortext := fmt.Sprintf("Couldn't write config file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add </s> remove err := writeAllConfigsAndReloadCoreDNS() if err != nil { errortext := fmt.Sprintf("Couldn't write config file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } _, err = fmt.Fprintf(w, "OK\n") if err != nil { errortext := fmt.Sprintf("Couldn't write body: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) } </s> add httpUpdateConfigReloadDNSReturnOK(w, r) </s> remove err = writeAllConfigs() if err != nil { errortext := fmt.Sprintf("Couldn't write config file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } </s> add
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/413228e6ecaf9019c8eac7034f1404b5c9c497fd
config.go
}{{end}}
<mask> {{if .ParentalEnabled}}parental {{.ParentalSensitivity}}{{end}} <mask> {{if .SafeSearchEnabled}}safesearch{{end}} <mask> {{if .QueryLogEnabled}}querylog{{end}} <mask> blocked_ttl {{.BlockedResponseTTL}} <mask> } <mask> {{.Pprof}} <mask> hosts { <mask> fallthrough <mask> } <mask> {{if .UpstreamDNS}}forward . {{range .UpstreamDNS}}{{.}} {{end}}{{end}} </s> API backend -- implement ability to turn toggle all protection in one go, helpful to temporarily disable all kinds of filtering </s> remove dnsfilter {{if .FilteringEnabled}}{{.FilterFile}}{{end}} { </s> add {{if .ProtectionEnabled}}dnsfilter {{if .FilteringEnabled}}{{.FilterFile}}{{end}} { </s> remove tellCoreDNSToReload() _, err = fmt.Fprintf(w, "OK\n") if err != nil { errortext := fmt.Sprintf("Couldn't write body: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) } </s> add httpUpdateConfigReloadDNSReturnOK(w, r) </s> remove err := writeAllConfigsAndReloadCoreDNS() if err != nil { errortext := fmt.Sprintf("Couldn't write config file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } _, err = fmt.Fprintf(w, "OK\n") if err != nil { errortext := fmt.Sprintf("Couldn't write body: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) } </s> add httpUpdateConfigReloadDNSReturnOK(w, r) </s> remove tellCoreDNSToReload() _, err = fmt.Fprintf(w, "OK\n") if err != nil { errortext := fmt.Sprintf("Couldn't write body: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) } </s> add httpUpdateConfigReloadDNSReturnOK(w, r)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/413228e6ecaf9019c8eac7034f1404b5c9c497fd
config.go
"dns_address": config.BindHost, "dns_port": config.CoreDNS.Port, "protection_enabled": config.CoreDNS.ProtectionEnabled, "querylog_enabled": config.CoreDNS.QueryLogEnabled, "running": isRunning(), "upstream_dns": config.CoreDNS.UpstreamDNS, "version": VersionString,
<mask> } <mask> <mask> func handleStatus(w http.ResponseWriter, r *http.Request) { <mask> data := map[string]interface{}{ <mask> "running": isRunning(), <mask> "version": VersionString, <mask> "dns_address": config.BindHost, <mask> "dns_port": config.CoreDNS.Port, <mask> "querylog_enabled": config.CoreDNS.QueryLogEnabled, <mask> "upstream_dns": config.CoreDNS.UpstreamDNS, <mask> } <mask> <mask> json, err := json.Marshal(data) <mask> if err != nil { <mask> errortext := fmt.Sprintf("Unable to marshal status json: %s", err) </s> API backend -- implement ability to turn toggle all protection in one go, helpful to temporarily disable all kinds of filtering </s> remove err := writeAllConfigsAndReloadCoreDNS() if err != nil { errortext := fmt.Sprintf("Couldn't write config file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } _, err = fmt.Fprintf(w, "OK\n") if err != nil { errortext := fmt.Sprintf("Couldn't write body: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) } </s> add httpUpdateConfigReloadDNSReturnOK(w, r) </s> remove err := writeAllConfigsAndReloadCoreDNS() if err != nil { errortext := fmt.Sprintf("Couldn't write config file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } _, err = fmt.Fprintf(w, "OK\n") if err != nil { errortext := fmt.Sprintf("Couldn't write body: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) } </s> add httpUpdateConfigReloadDNSReturnOK(w, r) </s> remove err := writeAllConfigsAndReloadCoreDNS() if err != nil { errortext := fmt.Sprintf("Couldn't write config file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } _, err = fmt.Fprintf(w, "OK\n") if err != nil { errortext := fmt.Sprintf("Couldn't write body: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) } </s> add httpUpdateConfigReloadDNSReturnOK(w, r) </s> remove err := writeAllConfigsAndReloadCoreDNS() if err != nil { errortext := fmt.Sprintf("Couldn't write config file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } _, err = fmt.Fprintf(w, "OK\n") if err != nil { errortext := fmt.Sprintf("Couldn't write body: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) } </s> add httpUpdateConfigReloadDNSReturnOK(w, r) </s> remove err := writeAllConfigsAndReloadCoreDNS() if err != nil { errortext := fmt.Sprintf("Couldn't write config file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } _, err = fmt.Fprintf(w, "OK\n") if err != nil { errortext := fmt.Sprintf("Couldn't write body: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) } </s> add httpUpdateConfigReloadDNSReturnOK(w, r)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/413228e6ecaf9019c8eac7034f1404b5c9c497fd
control.go
func handleProtectionEnable(w http.ResponseWriter, r *http.Request) { config.CoreDNS.ProtectionEnabled = true httpUpdateConfigReloadDNSReturnOK(w, r) } func handleProtectionDisable(w http.ResponseWriter, r *http.Request) { config.CoreDNS.ProtectionEnabled = false httpUpdateConfigReloadDNSReturnOK(w, r) }
<mask> } <mask> <mask> // ----- <mask> // stats <mask> // ----- <mask> func handleStats(w http.ResponseWriter, r *http.Request) { <mask> resp, err := client.Get("http://127.0.0.1:8618/stats") </s> API backend -- implement ability to turn toggle all protection in one go, helpful to temporarily disable all kinds of filtering </s> remove err := writeAllConfigsAndReloadCoreDNS() if err != nil { errortext := fmt.Sprintf("Couldn't write config file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } _, err = fmt.Fprintf(w, "OK\n") if err != nil { errortext := fmt.Sprintf("Couldn't write body: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) } </s> add httpUpdateConfigReloadDNSReturnOK(w, r) </s> remove err := writeAllConfigsAndReloadCoreDNS() if err != nil { errortext := fmt.Sprintf("Couldn't write config file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } _, err = fmt.Fprintf(w, "OK\n") if err != nil { errortext := fmt.Sprintf("Couldn't write body: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) } </s> add httpUpdateConfigReloadDNSReturnOK(w, r) </s> remove err := writeAllConfigsAndReloadCoreDNS() if err != nil { errortext := fmt.Sprintf("Couldn't write config file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } _, err = fmt.Fprintf(w, "OK\n") if err != nil { errortext := fmt.Sprintf("Couldn't write body: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) } </s> add httpUpdateConfigReloadDNSReturnOK(w, r) </s> remove err := writeAllConfigsAndReloadCoreDNS() if err != nil { errortext := fmt.Sprintf("Couldn't write config file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } _, err = fmt.Fprintf(w, "OK\n") if err != nil { errortext := fmt.Sprintf("Couldn't write body: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) } </s> add httpUpdateConfigReloadDNSReturnOK(w, r) </s> remove tellCoreDNSToReload() _, err = fmt.Fprintf(w, "OK\n") if err != nil { errortext := fmt.Sprintf("Couldn't write body: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) } // TODO: regenerate coredns config and tell coredns to reload it if it's running </s> add httpUpdateConfigReloadDNSReturnOK(w, r)
[ "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/413228e6ecaf9019c8eac7034f1404b5c9c497fd
control.go
httpUpdateConfigReloadDNSReturnOK(w, r)
<mask> } <mask> <mask> func handleQueryLogEnable(w http.ResponseWriter, r *http.Request) { <mask> config.CoreDNS.QueryLogEnabled = true <mask> err := writeAllConfigsAndReloadCoreDNS() <mask> if err != nil { <mask> errortext := fmt.Sprintf("Couldn't write config file: %s", err) <mask> log.Println(errortext) <mask> http.Error(w, errortext, http.StatusInternalServerError) <mask> return <mask> } <mask> _, err = fmt.Fprintf(w, "OK\n") <mask> if err != nil { <mask> errortext := fmt.Sprintf("Couldn't write body: %s", err) <mask> log.Println(errortext) <mask> http.Error(w, errortext, http.StatusInternalServerError) <mask> } <mask> } <mask> <mask> func handleQueryLogDisable(w http.ResponseWriter, r *http.Request) { <mask> config.CoreDNS.QueryLogEnabled = false <mask> err := writeAllConfigsAndReloadCoreDNS() </s> API backend -- implement ability to turn toggle all protection in one go, helpful to temporarily disable all kinds of filtering </s> remove err := writeAllConfigsAndReloadCoreDNS() if err != nil { errortext := fmt.Sprintf("Couldn't write config file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } _, err = fmt.Fprintf(w, "OK\n") if err != nil { errortext := fmt.Sprintf("Couldn't write body: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) } </s> add httpUpdateConfigReloadDNSReturnOK(w, r) </s> remove err := writeAllConfigsAndReloadCoreDNS() if err != nil { errortext := fmt.Sprintf("Couldn't write config file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } _, err = fmt.Fprintf(w, "OK\n") if err != nil { errortext := fmt.Sprintf("Couldn't write body: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) } </s> add httpUpdateConfigReloadDNSReturnOK(w, r) </s> remove err := writeAllConfigsAndReloadCoreDNS() if err != nil { errortext := fmt.Sprintf("Couldn't write config file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } _, err = fmt.Fprintf(w, "OK\n") if err != nil { errortext := fmt.Sprintf("Couldn't write body: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) } </s> add httpUpdateConfigReloadDNSReturnOK(w, r) </s> remove err := writeAllConfigsAndReloadCoreDNS() if err != nil { errortext := fmt.Sprintf("Couldn't write config file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } _, err = fmt.Fprintf(w, "OK\n") if err != nil { errortext := fmt.Sprintf("Couldn't write body: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) } </s> add httpUpdateConfigReloadDNSReturnOK(w, r) </s> remove err = writeAllConfigsAndReloadCoreDNS() if err != nil { errortext := fmt.Sprintf("Couldn't write config file: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) return } _, err = fmt.Fprintf(w, "OK\n") if err != nil { errortext := fmt.Sprintf("Couldn't write body: %s", err) log.Println(errortext) http.Error(w, errortext, http.StatusInternalServerError) } </s> add httpUpdateConfigReloadDNSReturnOK(w, r)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/413228e6ecaf9019c8eac7034f1404b5c9c497fd
control.go