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