docstring_tokens
stringlengths 0
76.5k
| code_tokens
stringlengths 75
1.81M
| label_window
sequencelengths 4
2.12k
| html_url
stringlengths 74
116
| file_name
stringlengths 3
311
|
---|---|---|---|---|
hwaddr := s.findReservedHWaddr(reqIP) | <mask> //
<mask>
<mask> log.Tracef("lease IP is different from requested IP: %s vs %s", lease.IP, reqIP)
<mask>
<mask> hwaddr := s.getIPpool(reqIP)
<mask> if hwaddr == nil {
<mask> // not in pool, check if it's in DHCP range
<mask> if dhcp4.IPInRange(s.leaseStart, s.leaseStop, reqIP) {
<mask> // okay, we can give it to our client -- it's in our DHCP range and not taken, so let them use their IP
<mask> log.Tracef("Replying with ACK: request IP %v is not taken, so assigning lease IP %v to it, for %v", reqIP, lease.IP, p.CHAddr())
</s> * dhcp: refactor; log client's HW addr </s> remove foundHWaddr := s.getIPpool(newIP)
</s> add foundHWaddr := s.findReservedHWaddr(newIP) </s> remove return dhcp4.ReplyPacket(p, dhcp4.ACK, s.ipnet.IP, lease.IP, s.leaseTime, s.leaseOptions.SelectOrderOrAll(options[dhcp4.OptionParameterRequestList]))
</s> add opt := s.leaseOptions.SelectOrderOrAll(options[dhcp4.OptionParameterRequestList])
return dhcp4.ReplyPacket(p, dhcp4.ACK, s.ipnet.IP, lease.IP, s.leaseTime, opt) </s> remove // Leases returns the list of current DHCP leases
</s> add // Leases returns the list of current DHCP leases (thread-safe) </s> remove log.Tracef("Got %v message", msgType)
</s> add log.Tracef("Message from client %s: %d", p.CHAddr(), msgType)
| [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/60fa3b2e95e5fc111884f13c8bfa465f030a0b40 | dhcpd/dhcpd.go |
// Leases returns the list of current DHCP leases (thread-safe) | <mask> log.Tracef("Replying with NAK: request IP %s is outside of DHCP range [%s, %s], asked by %v", reqIP, s.leaseStart, s.leaseStop, p.CHAddr())
<mask> return dhcp4.ReplyPacket(p, dhcp4.NAK, s.ipnet.IP, nil, 0, nil)
<mask> }
<mask>
<mask> // Leases returns the list of current DHCP leases
<mask> func (s *Server) Leases() []*Lease {
<mask> s.RLock()
<mask> result := s.leases
<mask> s.RUnlock()
<mask> return result
</s> * dhcp: refactor; log client's HW addr </s> remove hwaddr := s.getIPpool(reqIP)
</s> add hwaddr := s.findReservedHWaddr(reqIP) </s> remove return dhcp4.ReplyPacket(p, dhcp4.ACK, s.ipnet.IP, lease.IP, s.leaseTime, s.leaseOptions.SelectOrderOrAll(options[dhcp4.OptionParameterRequestList]))
</s> add opt := s.leaseOptions.SelectOrderOrAll(options[dhcp4.OptionParameterRequestList])
return dhcp4.ReplyPacket(p, dhcp4.ACK, s.ipnet.IP, lease.IP, s.leaseTime, opt) </s> remove log.Tracef("Got %v message", msgType)
</s> add log.Tracef("Message from client %s: %d", p.CHAddr(), msgType)
| [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/60fa3b2e95e5fc111884f13c8bfa465f030a0b40 | dhcpd/dhcpd.go |
<mask> package querylog
<mask>
<mask> import (
<mask> "encoding/base64"
<mask> "fmt"
<mask> "net"
<mask> "strconv"
<mask> "strings"
<mask> "time"
</s> *(querylog): decode methods to a new file </s> remove "strings"
</s> add </s> remove "github.com/AdguardTeam/AdGuardHome/dnsfilter"
</s> add </s> remove // decodeLogEntry - decodes query log entry from a line
// nolint (gocyclo)
func decodeLogEntry(ent *logEntry, str string) {
var b bool
var i int
var err error
for {
k, v, t := readJSON(&str)
if t == jsonTErr {
break
}
switch k {
case "IP":
if len(ent.IP) == 0 {
ent.IP = v
}
case "T":
ent.Time, err = time.Parse(time.RFC3339, v)
case "QH":
ent.QHost = v
case "QT":
ent.QType = v
case "QC":
ent.QClass = v
case "Answer":
ent.Answer, err = base64.StdEncoding.DecodeString(v)
case "OrigAnswer":
ent.OrigAnswer, err = base64.StdEncoding.DecodeString(v)
case "IsFiltered":
b, err = strconv.ParseBool(v)
ent.Result.IsFiltered = b
case "Rule":
ent.Result.Rule = v
case "FilterID":
i, err = strconv.Atoi(v)
ent.Result.FilterID = int64(i)
case "Reason":
i, err = strconv.Atoi(v)
ent.Result.Reason = dnsfilter.Reason(i)
case "Upstream":
ent.Upstream = v
case "Elapsed":
i, err = strconv.Atoi(v)
ent.Elapsed = time.Duration(i)
// pre-v0.99.3 compatibility:
case "Question":
var qstr []byte
qstr, err = base64.StdEncoding.DecodeString(v)
if err != nil {
break
}
q := new(dns.Msg)
err = q.Unpack(qstr)
if err != nil {
break
}
ent.QHost = q.Question[0].Name
if len(ent.QHost) == 0 {
break
}
ent.QHost = ent.QHost[:len(ent.QHost)-1]
ent.QType = dns.TypeToString[q.Question[0].Qtype]
ent.QClass = dns.ClassToString[q.Question[0].Qclass]
case "Time":
ent.Time, err = time.Parse(time.RFC3339, v)
}
if err != nil {
log.Debug("decodeLogEntry err: %s", err)
break
}
}
}
// Get value from "key":"value"
func readJSONValue(s, name string) string {
i := strings.Index(s, "\""+name+"\":\"")
if i == -1 {
return ""
}
start := i + 1 + len(name) + 3
i = strings.IndexByte(s[start:], '"')
if i == -1 {
return ""
}
end := start + i
return s[start:end]
}
const (
jsonTErr = iota
jsonTObj
jsonTStr
jsonTNum
jsonTBool
)
// Parse JSON key-value pair
// e.g.: "key":VALUE where VALUE is "string", true|false (boolean), or 123.456 (number)
// Note the limitations:
// . doesn't support whitespace
// . doesn't support "null"
// . doesn't validate boolean or number
// . no proper handling of {} braces
// . no handling of [] brackets
// Return (key, value, type)
func readJSON(ps *string) (string, string, int32) {
s := *ps
k := ""
v := ""
t := int32(jsonTErr)
q1 := strings.IndexByte(s, '"')
if q1 == -1 {
return k, v, t
}
q2 := strings.IndexByte(s[q1+1:], '"')
if q2 == -1 {
return k, v, t
}
k = s[q1+1 : q1+1+q2]
s = s[q1+1+q2+1:]
if len(s) < 2 || s[0] != ':' {
return k, v, t
}
if s[1] == '"' {
q2 = strings.IndexByte(s[2:], '"')
if q2 == -1 {
return k, v, t
}
v = s[2 : 2+q2]
t = jsonTStr
s = s[2+q2+1:]
} else if s[1] == '{' {
t = jsonTObj
s = s[1+1:]
} else {
sep := strings.IndexAny(s[1:], ",}")
if sep == -1 {
return k, v, t
}
v = s[1 : 1+sep]
if s[1] == 't' || s[1] == 'f' {
t = jsonTBool
} else if s[1] == '.' || (s[1] >= '0' && s[1] <= '9') {
t = jsonTNum
}
s = s[1+sep+1:]
}
*ps = s
return k, v, t
}
</s> add </s> remove func TestJSON(t *testing.T) {
s := `
{"keystr":"val","obj":{"keybool":true,"keyint":123456}}
`
k, v, jtype := readJSON(&s)
assert.Equal(t, jtype, int32(jsonTStr))
assert.Equal(t, "keystr", k)
assert.Equal(t, "val", v)
k, v, jtype = readJSON(&s)
assert.Equal(t, jtype, int32(jsonTObj))
assert.Equal(t, "obj", k)
k, v, jtype = readJSON(&s)
assert.Equal(t, jtype, int32(jsonTBool))
assert.Equal(t, "keybool", k)
assert.Equal(t, "true", v)
k, v, jtype = readJSON(&s)
assert.Equal(t, jtype, int32(jsonTNum))
assert.Equal(t, "keyint", k)
assert.Equal(t, "123456", v)
k, v, jtype = readJSON(&s)
assert.True(t, jtype == jsonTErr)
}
</s> add | [
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61a24ffc71eda26e10a11e3a9c8506909b6c4b52 | querylog/json.go |
|
<mask> "encoding/base64"
<mask> "fmt"
<mask> "net"
<mask> "strconv"
<mask> "strings"
<mask> "time"
<mask>
<mask> "github.com/AdguardTeam/AdGuardHome/dnsfilter"
<mask> "github.com/AdguardTeam/golibs/log"
<mask> "github.com/miekg/dns"
</s> *(querylog): decode methods to a new file </s> remove "encoding/base64"
</s> add </s> remove "github.com/AdguardTeam/AdGuardHome/dnsfilter"
</s> add </s> remove // decodeLogEntry - decodes query log entry from a line
// nolint (gocyclo)
func decodeLogEntry(ent *logEntry, str string) {
var b bool
var i int
var err error
for {
k, v, t := readJSON(&str)
if t == jsonTErr {
break
}
switch k {
case "IP":
if len(ent.IP) == 0 {
ent.IP = v
}
case "T":
ent.Time, err = time.Parse(time.RFC3339, v)
case "QH":
ent.QHost = v
case "QT":
ent.QType = v
case "QC":
ent.QClass = v
case "Answer":
ent.Answer, err = base64.StdEncoding.DecodeString(v)
case "OrigAnswer":
ent.OrigAnswer, err = base64.StdEncoding.DecodeString(v)
case "IsFiltered":
b, err = strconv.ParseBool(v)
ent.Result.IsFiltered = b
case "Rule":
ent.Result.Rule = v
case "FilterID":
i, err = strconv.Atoi(v)
ent.Result.FilterID = int64(i)
case "Reason":
i, err = strconv.Atoi(v)
ent.Result.Reason = dnsfilter.Reason(i)
case "Upstream":
ent.Upstream = v
case "Elapsed":
i, err = strconv.Atoi(v)
ent.Elapsed = time.Duration(i)
// pre-v0.99.3 compatibility:
case "Question":
var qstr []byte
qstr, err = base64.StdEncoding.DecodeString(v)
if err != nil {
break
}
q := new(dns.Msg)
err = q.Unpack(qstr)
if err != nil {
break
}
ent.QHost = q.Question[0].Name
if len(ent.QHost) == 0 {
break
}
ent.QHost = ent.QHost[:len(ent.QHost)-1]
ent.QType = dns.TypeToString[q.Question[0].Qtype]
ent.QClass = dns.ClassToString[q.Question[0].Qclass]
case "Time":
ent.Time, err = time.Parse(time.RFC3339, v)
}
if err != nil {
log.Debug("decodeLogEntry err: %s", err)
break
}
}
}
// Get value from "key":"value"
func readJSONValue(s, name string) string {
i := strings.Index(s, "\""+name+"\":\"")
if i == -1 {
return ""
}
start := i + 1 + len(name) + 3
i = strings.IndexByte(s[start:], '"')
if i == -1 {
return ""
}
end := start + i
return s[start:end]
}
const (
jsonTErr = iota
jsonTObj
jsonTStr
jsonTNum
jsonTBool
)
// Parse JSON key-value pair
// e.g.: "key":VALUE where VALUE is "string", true|false (boolean), or 123.456 (number)
// Note the limitations:
// . doesn't support whitespace
// . doesn't support "null"
// . doesn't validate boolean or number
// . no proper handling of {} braces
// . no handling of [] brackets
// Return (key, value, type)
func readJSON(ps *string) (string, string, int32) {
s := *ps
k := ""
v := ""
t := int32(jsonTErr)
q1 := strings.IndexByte(s, '"')
if q1 == -1 {
return k, v, t
}
q2 := strings.IndexByte(s[q1+1:], '"')
if q2 == -1 {
return k, v, t
}
k = s[q1+1 : q1+1+q2]
s = s[q1+1+q2+1:]
if len(s) < 2 || s[0] != ':' {
return k, v, t
}
if s[1] == '"' {
q2 = strings.IndexByte(s[2:], '"')
if q2 == -1 {
return k, v, t
}
v = s[2 : 2+q2]
t = jsonTStr
s = s[2+q2+1:]
} else if s[1] == '{' {
t = jsonTObj
s = s[1+1:]
} else {
sep := strings.IndexAny(s[1:], ",}")
if sep == -1 {
return k, v, t
}
v = s[1 : 1+sep]
if s[1] == 't' || s[1] == 'f' {
t = jsonTBool
} else if s[1] == '.' || (s[1] >= '0' && s[1] <= '9') {
t = jsonTNum
}
s = s[1+sep+1:]
}
*ps = s
return k, v, t
}
</s> add </s> remove func TestJSON(t *testing.T) {
s := `
{"keystr":"val","obj":{"keybool":true,"keyint":123456}}
`
k, v, jtype := readJSON(&s)
assert.Equal(t, jtype, int32(jsonTStr))
assert.Equal(t, "keystr", k)
assert.Equal(t, "val", v)
k, v, jtype = readJSON(&s)
assert.Equal(t, jtype, int32(jsonTObj))
assert.Equal(t, "obj", k)
k, v, jtype = readJSON(&s)
assert.Equal(t, jtype, int32(jsonTBool))
assert.Equal(t, "keybool", k)
assert.Equal(t, "true", v)
k, v, jtype = readJSON(&s)
assert.Equal(t, jtype, int32(jsonTNum))
assert.Equal(t, "keyint", k)
assert.Equal(t, "123456", v)
k, v, jtype = readJSON(&s)
assert.True(t, jtype == jsonTErr)
}
</s> add | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61a24ffc71eda26e10a11e3a9c8506909b6c4b52 | querylog/json.go |
|
<mask> "strconv"
<mask> "strings"
<mask> "time"
<mask>
<mask> "github.com/AdguardTeam/AdGuardHome/dnsfilter"
<mask> "github.com/AdguardTeam/golibs/log"
<mask> "github.com/miekg/dns"
<mask> )
<mask>
<mask> // decodeLogEntry - decodes query log entry from a line
</s> *(querylog): decode methods to a new file </s> remove "strings"
</s> add </s> remove // decodeLogEntry - decodes query log entry from a line
// nolint (gocyclo)
func decodeLogEntry(ent *logEntry, str string) {
var b bool
var i int
var err error
for {
k, v, t := readJSON(&str)
if t == jsonTErr {
break
}
switch k {
case "IP":
if len(ent.IP) == 0 {
ent.IP = v
}
case "T":
ent.Time, err = time.Parse(time.RFC3339, v)
case "QH":
ent.QHost = v
case "QT":
ent.QType = v
case "QC":
ent.QClass = v
case "Answer":
ent.Answer, err = base64.StdEncoding.DecodeString(v)
case "OrigAnswer":
ent.OrigAnswer, err = base64.StdEncoding.DecodeString(v)
case "IsFiltered":
b, err = strconv.ParseBool(v)
ent.Result.IsFiltered = b
case "Rule":
ent.Result.Rule = v
case "FilterID":
i, err = strconv.Atoi(v)
ent.Result.FilterID = int64(i)
case "Reason":
i, err = strconv.Atoi(v)
ent.Result.Reason = dnsfilter.Reason(i)
case "Upstream":
ent.Upstream = v
case "Elapsed":
i, err = strconv.Atoi(v)
ent.Elapsed = time.Duration(i)
// pre-v0.99.3 compatibility:
case "Question":
var qstr []byte
qstr, err = base64.StdEncoding.DecodeString(v)
if err != nil {
break
}
q := new(dns.Msg)
err = q.Unpack(qstr)
if err != nil {
break
}
ent.QHost = q.Question[0].Name
if len(ent.QHost) == 0 {
break
}
ent.QHost = ent.QHost[:len(ent.QHost)-1]
ent.QType = dns.TypeToString[q.Question[0].Qtype]
ent.QClass = dns.ClassToString[q.Question[0].Qclass]
case "Time":
ent.Time, err = time.Parse(time.RFC3339, v)
}
if err != nil {
log.Debug("decodeLogEntry err: %s", err)
break
}
}
}
// Get value from "key":"value"
func readJSONValue(s, name string) string {
i := strings.Index(s, "\""+name+"\":\"")
if i == -1 {
return ""
}
start := i + 1 + len(name) + 3
i = strings.IndexByte(s[start:], '"')
if i == -1 {
return ""
}
end := start + i
return s[start:end]
}
const (
jsonTErr = iota
jsonTObj
jsonTStr
jsonTNum
jsonTBool
)
// Parse JSON key-value pair
// e.g.: "key":VALUE where VALUE is "string", true|false (boolean), or 123.456 (number)
// Note the limitations:
// . doesn't support whitespace
// . doesn't support "null"
// . doesn't validate boolean or number
// . no proper handling of {} braces
// . no handling of [] brackets
// Return (key, value, type)
func readJSON(ps *string) (string, string, int32) {
s := *ps
k := ""
v := ""
t := int32(jsonTErr)
q1 := strings.IndexByte(s, '"')
if q1 == -1 {
return k, v, t
}
q2 := strings.IndexByte(s[q1+1:], '"')
if q2 == -1 {
return k, v, t
}
k = s[q1+1 : q1+1+q2]
s = s[q1+1+q2+1:]
if len(s) < 2 || s[0] != ':' {
return k, v, t
}
if s[1] == '"' {
q2 = strings.IndexByte(s[2:], '"')
if q2 == -1 {
return k, v, t
}
v = s[2 : 2+q2]
t = jsonTStr
s = s[2+q2+1:]
} else if s[1] == '{' {
t = jsonTObj
s = s[1+1:]
} else {
sep := strings.IndexAny(s[1:], ",}")
if sep == -1 {
return k, v, t
}
v = s[1 : 1+sep]
if s[1] == 't' || s[1] == 'f' {
t = jsonTBool
} else if s[1] == '.' || (s[1] >= '0' && s[1] <= '9') {
t = jsonTNum
}
s = s[1+sep+1:]
}
*ps = s
return k, v, t
}
</s> add </s> remove "encoding/base64"
</s> add </s> remove func TestJSON(t *testing.T) {
s := `
{"keystr":"val","obj":{"keybool":true,"keyint":123456}}
`
k, v, jtype := readJSON(&s)
assert.Equal(t, jtype, int32(jsonTStr))
assert.Equal(t, "keystr", k)
assert.Equal(t, "val", v)
k, v, jtype = readJSON(&s)
assert.Equal(t, jtype, int32(jsonTObj))
assert.Equal(t, "obj", k)
k, v, jtype = readJSON(&s)
assert.Equal(t, jtype, int32(jsonTBool))
assert.Equal(t, "keybool", k)
assert.Equal(t, "true", v)
k, v, jtype = readJSON(&s)
assert.Equal(t, jtype, int32(jsonTNum))
assert.Equal(t, "keyint", k)
assert.Equal(t, "123456", v)
k, v, jtype = readJSON(&s)
assert.True(t, jtype == jsonTErr)
}
</s> add | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61a24ffc71eda26e10a11e3a9c8506909b6c4b52 | querylog/json.go |
|
<mask> "github.com/AdguardTeam/golibs/log"
<mask> "github.com/miekg/dns"
<mask> )
<mask>
<mask> // decodeLogEntry - decodes query log entry from a line
<mask> // nolint (gocyclo)
<mask> func decodeLogEntry(ent *logEntry, str string) {
<mask> var b bool
<mask> var i int
<mask> var err error
<mask> for {
<mask> k, v, t := readJSON(&str)
<mask> if t == jsonTErr {
<mask> break
<mask> }
<mask> switch k {
<mask> case "IP":
<mask> if len(ent.IP) == 0 {
<mask> ent.IP = v
<mask> }
<mask> case "T":
<mask> ent.Time, err = time.Parse(time.RFC3339, v)
<mask>
<mask> case "QH":
<mask> ent.QHost = v
<mask> case "QT":
<mask> ent.QType = v
<mask> case "QC":
<mask> ent.QClass = v
<mask>
<mask> case "Answer":
<mask> ent.Answer, err = base64.StdEncoding.DecodeString(v)
<mask> case "OrigAnswer":
<mask> ent.OrigAnswer, err = base64.StdEncoding.DecodeString(v)
<mask>
<mask> case "IsFiltered":
<mask> b, err = strconv.ParseBool(v)
<mask> ent.Result.IsFiltered = b
<mask> case "Rule":
<mask> ent.Result.Rule = v
<mask> case "FilterID":
<mask> i, err = strconv.Atoi(v)
<mask> ent.Result.FilterID = int64(i)
<mask> case "Reason":
<mask> i, err = strconv.Atoi(v)
<mask> ent.Result.Reason = dnsfilter.Reason(i)
<mask>
<mask> case "Upstream":
<mask> ent.Upstream = v
<mask> case "Elapsed":
<mask> i, err = strconv.Atoi(v)
<mask> ent.Elapsed = time.Duration(i)
<mask>
<mask> // pre-v0.99.3 compatibility:
<mask> case "Question":
<mask> var qstr []byte
<mask> qstr, err = base64.StdEncoding.DecodeString(v)
<mask> if err != nil {
<mask> break
<mask> }
<mask> q := new(dns.Msg)
<mask> err = q.Unpack(qstr)
<mask> if err != nil {
<mask> break
<mask> }
<mask> ent.QHost = q.Question[0].Name
<mask> if len(ent.QHost) == 0 {
<mask> break
<mask> }
<mask> ent.QHost = ent.QHost[:len(ent.QHost)-1]
<mask> ent.QType = dns.TypeToString[q.Question[0].Qtype]
<mask> ent.QClass = dns.ClassToString[q.Question[0].Qclass]
<mask> case "Time":
<mask> ent.Time, err = time.Parse(time.RFC3339, v)
<mask> }
<mask>
<mask> if err != nil {
<mask> log.Debug("decodeLogEntry err: %s", err)
<mask> break
<mask> }
<mask> }
<mask> }
<mask>
<mask> // Get value from "key":"value"
<mask> func readJSONValue(s, name string) string {
<mask> i := strings.Index(s, "\""+name+"\":\"")
<mask> if i == -1 {
<mask> return ""
<mask> }
<mask> start := i + 1 + len(name) + 3
<mask> i = strings.IndexByte(s[start:], '"')
<mask> if i == -1 {
<mask> return ""
<mask> }
<mask> end := start + i
<mask> return s[start:end]
<mask> }
<mask>
<mask> const (
<mask> jsonTErr = iota
<mask> jsonTObj
<mask> jsonTStr
<mask> jsonTNum
<mask> jsonTBool
<mask> )
<mask>
<mask> // Parse JSON key-value pair
<mask> // e.g.: "key":VALUE where VALUE is "string", true|false (boolean), or 123.456 (number)
<mask> // Note the limitations:
<mask> // . doesn't support whitespace
<mask> // . doesn't support "null"
<mask> // . doesn't validate boolean or number
<mask> // . no proper handling of {} braces
<mask> // . no handling of [] brackets
<mask> // Return (key, value, type)
<mask> func readJSON(ps *string) (string, string, int32) {
<mask> s := *ps
<mask> k := ""
<mask> v := ""
<mask> t := int32(jsonTErr)
<mask>
<mask> q1 := strings.IndexByte(s, '"')
<mask> if q1 == -1 {
<mask> return k, v, t
<mask> }
<mask> q2 := strings.IndexByte(s[q1+1:], '"')
<mask> if q2 == -1 {
<mask> return k, v, t
<mask> }
<mask> k = s[q1+1 : q1+1+q2]
<mask> s = s[q1+1+q2+1:]
<mask>
<mask> if len(s) < 2 || s[0] != ':' {
<mask> return k, v, t
<mask> }
<mask>
<mask> if s[1] == '"' {
<mask> q2 = strings.IndexByte(s[2:], '"')
<mask> if q2 == -1 {
<mask> return k, v, t
<mask> }
<mask> v = s[2 : 2+q2]
<mask> t = jsonTStr
<mask> s = s[2+q2+1:]
<mask>
<mask> } else if s[1] == '{' {
<mask> t = jsonTObj
<mask> s = s[1+1:]
<mask>
<mask> } else {
<mask> sep := strings.IndexAny(s[1:], ",}")
<mask> if sep == -1 {
<mask> return k, v, t
<mask> }
<mask> v = s[1 : 1+sep]
<mask> if s[1] == 't' || s[1] == 'f' {
<mask> t = jsonTBool
<mask> } else if s[1] == '.' || (s[1] >= '0' && s[1] <= '9') {
<mask> t = jsonTNum
<mask> }
<mask> s = s[1+sep+1:]
<mask> }
<mask>
<mask> *ps = s
<mask> return k, v, t
<mask> }
<mask>
<mask> // Get Client IP address
<mask> func (l *queryLog) getClientIP(clientIP string) string {
<mask> if l.conf.AnonymizeClientIP {
<mask> ip := net.ParseIP(clientIP)
<mask> if ip != nil {
</s> *(querylog): decode methods to a new file </s> remove func TestJSON(t *testing.T) {
s := `
{"keystr":"val","obj":{"keybool":true,"keyint":123456}}
`
k, v, jtype := readJSON(&s)
assert.Equal(t, jtype, int32(jsonTStr))
assert.Equal(t, "keystr", k)
assert.Equal(t, "val", v)
k, v, jtype = readJSON(&s)
assert.Equal(t, jtype, int32(jsonTObj))
assert.Equal(t, "obj", k)
k, v, jtype = readJSON(&s)
assert.Equal(t, jtype, int32(jsonTBool))
assert.Equal(t, "keybool", k)
assert.Equal(t, "true", v)
k, v, jtype = readJSON(&s)
assert.Equal(t, jtype, int32(jsonTNum))
assert.Equal(t, "keyint", k)
assert.Equal(t, "123456", v)
k, v, jtype = readJSON(&s)
assert.True(t, jtype == jsonTErr)
}
</s> add </s> remove "github.com/AdguardTeam/AdGuardHome/dnsfilter"
</s> add </s> remove "strings"
</s> add </s> remove "encoding/base64"
</s> add | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61a24ffc71eda26e10a11e3a9c8506909b6c4b52 | querylog/json.go |
|
<mask> entries, _ = l.search(params)
<mask> assert.Equal(t, 10, len(entries))
<mask> }
<mask>
<mask> func TestJSON(t *testing.T) {
<mask> s := `
<mask> {"keystr":"val","obj":{"keybool":true,"keyint":123456}}
<mask> `
<mask> k, v, jtype := readJSON(&s)
<mask> assert.Equal(t, jtype, int32(jsonTStr))
<mask> assert.Equal(t, "keystr", k)
<mask> assert.Equal(t, "val", v)
<mask>
<mask> k, v, jtype = readJSON(&s)
<mask> assert.Equal(t, jtype, int32(jsonTObj))
<mask> assert.Equal(t, "obj", k)
<mask>
<mask> k, v, jtype = readJSON(&s)
<mask> assert.Equal(t, jtype, int32(jsonTBool))
<mask> assert.Equal(t, "keybool", k)
<mask> assert.Equal(t, "true", v)
<mask>
<mask> k, v, jtype = readJSON(&s)
<mask> assert.Equal(t, jtype, int32(jsonTNum))
<mask> assert.Equal(t, "keyint", k)
<mask> assert.Equal(t, "123456", v)
<mask>
<mask> k, v, jtype = readJSON(&s)
<mask> assert.True(t, jtype == jsonTErr)
<mask> }
<mask>
<mask> func addEntry(l *queryLog, host, answerStr, client string) {
<mask> q := dns.Msg{}
<mask> q.Question = append(q.Question, dns.Question{
<mask> Name: host + ".",
<mask> Qtype: dns.TypeA,
</s> *(querylog): decode methods to a new file </s> remove // decodeLogEntry - decodes query log entry from a line
// nolint (gocyclo)
func decodeLogEntry(ent *logEntry, str string) {
var b bool
var i int
var err error
for {
k, v, t := readJSON(&str)
if t == jsonTErr {
break
}
switch k {
case "IP":
if len(ent.IP) == 0 {
ent.IP = v
}
case "T":
ent.Time, err = time.Parse(time.RFC3339, v)
case "QH":
ent.QHost = v
case "QT":
ent.QType = v
case "QC":
ent.QClass = v
case "Answer":
ent.Answer, err = base64.StdEncoding.DecodeString(v)
case "OrigAnswer":
ent.OrigAnswer, err = base64.StdEncoding.DecodeString(v)
case "IsFiltered":
b, err = strconv.ParseBool(v)
ent.Result.IsFiltered = b
case "Rule":
ent.Result.Rule = v
case "FilterID":
i, err = strconv.Atoi(v)
ent.Result.FilterID = int64(i)
case "Reason":
i, err = strconv.Atoi(v)
ent.Result.Reason = dnsfilter.Reason(i)
case "Upstream":
ent.Upstream = v
case "Elapsed":
i, err = strconv.Atoi(v)
ent.Elapsed = time.Duration(i)
// pre-v0.99.3 compatibility:
case "Question":
var qstr []byte
qstr, err = base64.StdEncoding.DecodeString(v)
if err != nil {
break
}
q := new(dns.Msg)
err = q.Unpack(qstr)
if err != nil {
break
}
ent.QHost = q.Question[0].Name
if len(ent.QHost) == 0 {
break
}
ent.QHost = ent.QHost[:len(ent.QHost)-1]
ent.QType = dns.TypeToString[q.Question[0].Qtype]
ent.QClass = dns.ClassToString[q.Question[0].Qclass]
case "Time":
ent.Time, err = time.Parse(time.RFC3339, v)
}
if err != nil {
log.Debug("decodeLogEntry err: %s", err)
break
}
}
}
// Get value from "key":"value"
func readJSONValue(s, name string) string {
i := strings.Index(s, "\""+name+"\":\"")
if i == -1 {
return ""
}
start := i + 1 + len(name) + 3
i = strings.IndexByte(s[start:], '"')
if i == -1 {
return ""
}
end := start + i
return s[start:end]
}
const (
jsonTErr = iota
jsonTObj
jsonTStr
jsonTNum
jsonTBool
)
// Parse JSON key-value pair
// e.g.: "key":VALUE where VALUE is "string", true|false (boolean), or 123.456 (number)
// Note the limitations:
// . doesn't support whitespace
// . doesn't support "null"
// . doesn't validate boolean or number
// . no proper handling of {} braces
// . no handling of [] brackets
// Return (key, value, type)
func readJSON(ps *string) (string, string, int32) {
s := *ps
k := ""
v := ""
t := int32(jsonTErr)
q1 := strings.IndexByte(s, '"')
if q1 == -1 {
return k, v, t
}
q2 := strings.IndexByte(s[q1+1:], '"')
if q2 == -1 {
return k, v, t
}
k = s[q1+1 : q1+1+q2]
s = s[q1+1+q2+1:]
if len(s) < 2 || s[0] != ':' {
return k, v, t
}
if s[1] == '"' {
q2 = strings.IndexByte(s[2:], '"')
if q2 == -1 {
return k, v, t
}
v = s[2 : 2+q2]
t = jsonTStr
s = s[2+q2+1:]
} else if s[1] == '{' {
t = jsonTObj
s = s[1+1:]
} else {
sep := strings.IndexAny(s[1:], ",}")
if sep == -1 {
return k, v, t
}
v = s[1 : 1+sep]
if s[1] == 't' || s[1] == 'f' {
t = jsonTBool
} else if s[1] == '.' || (s[1] >= '0' && s[1] <= '9') {
t = jsonTNum
}
s = s[1+sep+1:]
}
*ps = s
return k, v, t
}
</s> add </s> remove "github.com/AdguardTeam/AdGuardHome/dnsfilter"
</s> add </s> remove "strings"
</s> add </s> remove "encoding/base64"
</s> add | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61a24ffc71eda26e10a11e3a9c8506909b6c4b52 | querylog/qlog_test.go |
|
safeSearch, err := safesearch.NewDefault( | <mask> SafeSearchConf: safeSearchConf,
<mask> SafeSearchCacheSize: 1000,
<mask> CacheTime: 30,
<mask> }
<mask> safeSearch, err := safesearch.NewDefaultSafeSearch(
<mask> safeSearchConf,
<mask> filterConf.SafeSearchCacheSize,
<mask> time.Minute*time.Duration(filterConf.CacheTime),
<mask> )
<mask> require.NoError(t, err)
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove Upstreams: cj.Upstreams,
</s> add if safeSearchConf.Enabled {
err = c.setSafeSearch(
safeSearchConf,
clients.safeSearchCacheSize,
clients.safeSearchCacheTTL,
)
if err != nil {
return nil, fmt.Errorf("creating safesearch for client %q: %w", c.Name, err)
} </s> remove BlockedServices: cj.BlockedServices,
</s> add } </s> remove return &Client{
Name: cj.Name,
IDs: cj.IDs,
Tags: cj.Tags,
</s> add c = &Client{
safeSearchConf: safeSearchConf,
Name: cj.Name,
IDs: cj.IDs,
Tags: cj.Tags,
BlockedServices: cj.BlockedServices,
Upstreams: cj.Upstreams,
</s> remove ss, err := safesearch.NewDefaultSafeSearch(
</s> add err := cli.setSafeSearch( | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/dnsforward/dnsforward_test.go |
"", | <mask> safeSearch, err := safesearch.NewDefault(
<mask> safeSearchConf,
<mask> filterConf.SafeSearchCacheSize,
<mask> time.Minute*time.Duration(filterConf.CacheTime),
<mask> )
<mask> require.NoError(t, err)
<mask>
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove safeSearch, err := safesearch.NewDefaultSafeSearch(
</s> add safeSearch, err := safesearch.NewDefault( </s> remove Upstreams: cj.Upstreams,
</s> add if safeSearchConf.Enabled {
err = c.setSafeSearch(
safeSearchConf,
clients.safeSearchCacheSize,
clients.safeSearchCacheTTL,
)
if err != nil {
return nil, fmt.Errorf("creating safesearch for client %q: %w", c.Name, err)
} </s> remove config.DNS.DnsfilterConf.SafeSearch, err = safesearch.NewDefaultSafeSearch(
</s> add config.DNS.DnsfilterConf.SafeSearch, err = safesearch.NewDefault( </s> remove assert.False(t, res.IsFiltered)
assert.Empty(t, res.Rules)
ss = newForTest(t, defaultSafeSearchConf)
res, err = ss.CheckHost(domain, dns.TypeA)
</s> add res, err := ss.CheckHost("www.yandex.com", testQType) | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/dnsforward/dnsforward_test.go |
import "github.com/miekg/dns" | <mask> package filtering
<mask>
<mask> import (
<mask> "github.com/AdguardTeam/urlfilter/rules"
<mask> "github.com/miekg/dns"
<mask> )
<mask>
<mask> // SafeSearch interface describes a service for search engines hosts rewrites.
<mask> type SafeSearch interface {
<mask> // SearchHost returns a replacement address for the search engine host.
<mask> SearchHost(host string, qtype uint16) (res *rules.DNSRewrite)
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove // SearchHost returns a replacement address for the search engine host.
SearchHost(host string, qtype uint16) (res *rules.DNSRewrite)
// CheckHost checks host with safe search engine.
</s> add // CheckHost checks host with safe search filter. CheckHost must be safe
// for concurrent use. qtype must be either [dns.TypeA] or [dns.TypeAAAA]. </s> remove // SearchHost implements the [filtering.SafeSearch] interface for *DefaultSafeSearch.
func (ss *DefaultSafeSearch) SearchHost(host string, qtype uint16) (res *rules.DNSRewrite) {
r, _ := ss.engine.MatchRequest(&urlfilter.DNSRequest{
Hostname: strings.ToLower(host),
DNSType: qtype,
})
rewritesRules := r.DNSRewrites()
if len(rewritesRules) > 0 {
return rewritesRules[0].DNSRewrite
}
</s> add ss.log(log.INFO, "reset %d rules", ss.engine.RulesCount) </s> remove engine = urlfilter.NewDNSEngine(rs)
log.Info("safesearch: filter %d: reset %d rules", listID, engine.RulesCount)
return engine, nil
}
// type check
var _ filtering.SafeSearch = (*DefaultSafeSearch)(nil)
</s> add ss.engine = urlfilter.NewDNSEngine(rs) </s> remove // DefaultSafeSearch is the default safesearch struct.
type DefaultSafeSearch struct {
engine *urlfilter.DNSEngine
safeSearchCache cache.Cache
resolver filtering.Resolver
cacheTime time.Duration
</s> add // Default is the default safe search filter that uses filtering rules with the
// dnsrewrite modifier.
type Default struct {
// mu protects engine.
mu *sync.RWMutex
// engine is the filtering engine that contains the DNS rewrite rules.
// engine may be nil, which means that this safe search filter is disabled.
engine *urlfilter.DNSEngine
cache cache.Cache
resolver filtering.Resolver
logPrefix string
cacheTTL time.Duration | [
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch.go |
// CheckHost checks host with safe search filter. CheckHost must be safe
// for concurrent use. qtype must be either [dns.TypeA] or [dns.TypeAAAA]. | <mask> )
<mask>
<mask> // SafeSearch interface describes a service for search engines hosts rewrites.
<mask> type SafeSearch interface {
<mask> // SearchHost returns a replacement address for the search engine host.
<mask> SearchHost(host string, qtype uint16) (res *rules.DNSRewrite)
<mask>
<mask> // CheckHost checks host with safe search engine.
<mask> CheckHost(host string, qtype uint16) (res Result, err error)
<mask> }
<mask>
<mask> // SafeSearchConfig is a struct with safe search related settings.
<mask> type SafeSearchConfig struct {
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove import (
"github.com/AdguardTeam/urlfilter/rules"
"github.com/miekg/dns"
)
</s> add import "github.com/miekg/dns" </s> remove _ uint16,
</s> add qtype uint16, </s> remove // DefaultSafeSearch is the default safesearch struct.
type DefaultSafeSearch struct {
engine *urlfilter.DNSEngine
safeSearchCache cache.Cache
resolver filtering.Resolver
cacheTime time.Duration
</s> add // Default is the default safe search filter that uses filtering rules with the
// dnsrewrite modifier.
type Default struct {
// mu protects engine.
mu *sync.RWMutex
// engine is the filtering engine that contains the DNS rewrite rules.
// engine may be nil, which means that this safe search filter is disabled.
engine *urlfilter.DNSEngine
cache cache.Cache
resolver filtering.Resolver
logPrefix string
cacheTTL time.Duration </s> remove // SearchHost implements the [filtering.SafeSearch] interface for *DefaultSafeSearch.
func (ss *DefaultSafeSearch) SearchHost(host string, qtype uint16) (res *rules.DNSRewrite) {
r, _ := ss.engine.MatchRequest(&urlfilter.DNSRequest{
Hostname: strings.ToLower(host),
DNSType: qtype,
})
rewritesRules := r.DNSRewrites()
if len(rewritesRules) > 0 {
return rewritesRules[0].DNSRewrite
}
</s> add ss.log(log.INFO, "reset %d rules", ss.engine.RulesCount) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch.go |
// Update updates the configuration of the safe search filter. Update must
// be safe for concurrent use. An implementation of Update may ignore some
// fields, but it must document which.
Update(conf SafeSearchConfig) (err error) | <mask> // for concurrent use. qtype must be either [dns.TypeA] or [dns.TypeAAAA].
<mask> CheckHost(host string, qtype uint16) (res Result, err error)
<mask> }
<mask>
<mask> // SafeSearchConfig is a struct with safe search related settings.
<mask> type SafeSearchConfig struct {
<mask> // CustomResolver is the resolver used by safe search.
<mask> CustomResolver Resolver `yaml:"-" json:"-"`
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove // SearchHost returns a replacement address for the search engine host.
SearchHost(host string, qtype uint16) (res *rules.DNSRewrite)
// CheckHost checks host with safe search engine.
</s> add // CheckHost checks host with safe search filter. CheckHost must be safe
// for concurrent use. qtype must be either [dns.TypeA] or [dns.TypeAAAA]. </s> remove // setCacheResult stores data in cache for host.
func (ss *DefaultSafeSearch) setCacheResult(host string, res filtering.Result) {
expire := uint32(time.Now().Add(ss.cacheTime).Unix())
</s> add // qtypeToProto returns "ip4" for [dns.TypeA] and "ip6" for [dns.TypeAAAA].
// It panics for other types.
func qtypeToProto(qtype rules.RRType) (proto string) {
switch qtype {
case dns.TypeA:
return "ip4"
case dns.TypeAAAA:
return "ip6"
default:
panic(fmt.Errorf("safesearch: unsupported question type %s", dns.Type(qtype)))
}
}
// fitToProto returns a non-nil IP address if ip is the correct protocol version
// for qtype. qtype is expected to be either [dns.TypeA] or [dns.TypeAAAA].
func fitToProto(ip net.IP, qtype rules.RRType) (res net.IP) {
ip4 := ip.To4()
if qtype == dns.TypeA {
return ip4
}
if ip4 == nil {
return ip
}
return nil
}
// setCacheResult stores data in cache for host. qtype is expected to be either
// [dns.TypeA] or [dns.TypeAAAA].
func (ss *Default) setCacheResult(host string, qtype rules.RRType, res filtering.Result) {
expire := uint32(time.Now().Add(ss.cacheTTL).Unix()) </s> remove // DefaultSafeSearch is the default safesearch struct.
type DefaultSafeSearch struct {
engine *urlfilter.DNSEngine
safeSearchCache cache.Cache
resolver filtering.Resolver
cacheTime time.Duration
</s> add // Default is the default safe search filter that uses filtering rules with the
// dnsrewrite modifier.
type Default struct {
// mu protects engine.
mu *sync.RWMutex
// engine is the filtering engine that contains the DNS rewrite rules.
// engine may be nil, which means that this safe search filter is disabled.
engine *urlfilter.DNSEngine
cache cache.Cache
resolver filtering.Resolver
logPrefix string
cacheTTL time.Duration </s> remove _ uint16,
</s> add qtype uint16, </s> remove // newResult creates Result object from rewrite rule.
func (ss *DefaultSafeSearch) newResult(
</s> add // searchHost looks up DNS rewrites in the internal DNS filtering engine.
func (ss *Default) searchHost(host string, qtype rules.RRType) (res *rules.DNSRewrite) {
ss.mu.RLock()
defer ss.mu.RUnlock()
if ss.engine == nil {
return nil
}
r, _ := ss.engine.MatchRequest(&urlfilter.DNSRequest{
Hostname: strings.ToLower(host),
DNSType: qtype,
})
rewritesRules := r.DNSRewrites()
if len(rewritesRules) > 0 {
return rewritesRules[0].DNSRewrite
}
return nil
}
// newResult creates Result object from rewrite rule. qtype must be either
// [dns.TypeA] or [dns.TypeAAAA].
func (ss *Default) newResult( | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch.go |
qtype uint16, | <mask> // checkSafeSearch checks host with safe search engine. Matches
<mask> // [hostChecker.check].
<mask> func (d *DNSFilter) checkSafeSearch(
<mask> host string,
<mask> _ uint16,
<mask> setts *Settings,
<mask> ) (res Result, err error) {
<mask> if !setts.ProtectionEnabled || !setts.SafeSearchEnabled {
<mask> return Result{}, nil
<mask> }
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove if !setts.ProtectionEnabled || !setts.SafeSearchEnabled {
</s> add if !setts.ProtectionEnabled ||
!setts.SafeSearchEnabled ||
(qtype != dns.TypeA && qtype != dns.TypeAAAA) { </s> remove // SearchHost returns a replacement address for the search engine host.
SearchHost(host string, qtype uint16) (res *rules.DNSRewrite)
// CheckHost checks host with safe search engine.
</s> add // CheckHost checks host with safe search filter. CheckHost must be safe
// for concurrent use. qtype must be either [dns.TypeA] or [dns.TypeAAAA]. </s> remove func (ss *DefaultSafeSearch) CheckHost(
</s> add func (ss *Default) CheckHost( </s> remove qtype uint16,
</s> add qtype rules.RRType, </s> remove // newResult creates Result object from rewrite rule.
func (ss *DefaultSafeSearch) newResult(
</s> add // searchHost looks up DNS rewrites in the internal DNS filtering engine.
func (ss *Default) searchHost(host string, qtype rules.RRType) (res *rules.DNSRewrite) {
ss.mu.RLock()
defer ss.mu.RUnlock()
if ss.engine == nil {
return nil
}
r, _ := ss.engine.MatchRequest(&urlfilter.DNSRequest{
Hostname: strings.ToLower(host),
DNSType: qtype,
})
rewritesRules := r.DNSRewrites()
if len(rewritesRules) > 0 {
return rewritesRules[0].DNSRewrite
}
return nil
}
// newResult creates Result object from rewrite rule. qtype must be either
// [dns.TypeA] or [dns.TypeAAAA].
func (ss *Default) newResult( | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch.go |
if !setts.ProtectionEnabled ||
!setts.SafeSearchEnabled ||
(qtype != dns.TypeA && qtype != dns.TypeAAAA) { | <mask> host string,
<mask> _ uint16,
<mask> setts *Settings,
<mask> ) (res Result, err error) {
<mask> if !setts.ProtectionEnabled || !setts.SafeSearchEnabled {
<mask> return Result{}, nil
<mask> }
<mask>
<mask> if d.safeSearch == nil {
<mask> return Result{}, nil
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove _ uint16,
</s> add qtype uint16, </s> remove if rewrite.RRType == qtype && (qtype == dns.TypeA || qtype == dns.TypeAAAA) {
</s> add if rewrite.RRType == qtype { </s> remove func (ss *DefaultSafeSearch) CheckHost(
</s> add func (ss *Default) CheckHost( </s> remove qtype uint16,
</s> add qtype rules.RRType, </s> remove if rewrite.NewCNAME == "" {
</s> add host := rewrite.NewCNAME
if host == "" { | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch.go |
return clientSafeSearch.CheckHost(host, qtype) | <mask> }
<mask>
<mask> clientSafeSearch := setts.ClientSafeSearch
<mask> if clientSafeSearch != nil {
<mask> return clientSafeSearch.CheckHost(host, dns.TypeA)
<mask> }
<mask>
<mask> return d.safeSearch.CheckHost(host, dns.TypeA)
<mask> }
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove return d.safeSearch.CheckHost(host, dns.TypeA)
</s> add return d.safeSearch.CheckHost(host, qtype) </s> remove var dnsRewriteSink *rules.DNSRewrite
func BenchmarkSafeSearch(b *testing.B) {
ss := newForTest(b, defaultSafeSearchConf)
for n := 0; n < b.N; n++ {
dnsRewriteSink = ss.SearchHost(googleHost, dns.TypeA)
}
assert.Equal(b, "forcesafesearch.google.com", dnsRewriteSink.NewCNAME)
}
var dnsRewriteParallelSink *rules.DNSRewrite
func BenchmarkSafeSearch_parallel(b *testing.B) {
ss := newForTest(b, defaultSafeSearchConf)
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
dnsRewriteParallelSink = ss.SearchHost(googleHost, dns.TypeA)
}
})
assert.Equal(b, "forcesafesearch.google.com", dnsRewriteParallelSink.NewCNAME)
</s> add assert.False(t, res.IsFiltered) </s> remove var foundIP net.IP
for _, ip := range ips {
if ip.To4() != nil {
foundIP = ip
break
}
}
res, err = ss.CheckHost(domain, dns.TypeA)
</s> add res, err = ss.CheckHost("www.yandex.com", testQType) </s> remove func TestSafeSearchCacheYandex(t *testing.T) {
const domain = "yandex.ru"
ss := newForTest(t, filtering.SafeSearchConfig{Enabled: false})
// Check host with disabled safesearch.
res, err := ss.CheckHost(domain, dns.TypeA)
</s> add func TestDefault_Update(t *testing.T) {
conf := testConf
ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL) </s> remove res, err := ss.CheckHost(host, dns.TypeA)
</s> add var res filtering.Result
res, err = ss.CheckHost(host, testQType) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch.go |
return d.safeSearch.CheckHost(host, qtype) | <mask> if clientSafeSearch != nil {
<mask> return clientSafeSearch.CheckHost(host, dns.TypeA)
<mask> }
<mask>
<mask> return d.safeSearch.CheckHost(host, dns.TypeA)
<mask> }
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove return clientSafeSearch.CheckHost(host, dns.TypeA)
</s> add return clientSafeSearch.CheckHost(host, qtype) </s> remove var dnsRewriteSink *rules.DNSRewrite
func BenchmarkSafeSearch(b *testing.B) {
ss := newForTest(b, defaultSafeSearchConf)
for n := 0; n < b.N; n++ {
dnsRewriteSink = ss.SearchHost(googleHost, dns.TypeA)
}
assert.Equal(b, "forcesafesearch.google.com", dnsRewriteSink.NewCNAME)
}
var dnsRewriteParallelSink *rules.DNSRewrite
func BenchmarkSafeSearch_parallel(b *testing.B) {
ss := newForTest(b, defaultSafeSearchConf)
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
dnsRewriteParallelSink = ss.SearchHost(googleHost, dns.TypeA)
}
})
assert.Equal(b, "forcesafesearch.google.com", dnsRewriteParallelSink.NewCNAME)
</s> add assert.False(t, res.IsFiltered) </s> remove var foundIP net.IP
for _, ip := range ips {
if ip.To4() != nil {
foundIP = ip
break
}
}
res, err = ss.CheckHost(domain, dns.TypeA)
</s> add res, err = ss.CheckHost("www.yandex.com", testQType) </s> remove res, err := ss.CheckHost(host, dns.TypeA)
</s> add var res filtering.Result
res, err = ss.CheckHost(host, testQType) </s> remove res, err := ss.CheckHost(host, dns.TypeA)
</s> add var res filtering.Result
res, err = ss.CheckHost(host, testQType) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch.go |
<mask> |www.google.to^$dnsrewrite=NOERROR;CNAME;forcesafesearch.google.com
<mask> |www.google.tt^$dnsrewrite=NOERROR;CNAME;forcesafesearch.google.com
<mask> |www.google.vg^$dnsrewrite=NOERROR;CNAME;forcesafesearch.google.com
<mask> |www.google.vu^$dnsrewrite=NOERROR;CNAME;forcesafesearch.google.com
<mask> |www.google.ws^$dnsrewrite=NOERROR;CNAME;forcesafesearch.google.com </s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove log.Tracef("network:%v addr:%v", network, addr)
</s> add log.Debug("home: customdial: dialing addr %q for network %s", addr, network) </s> remove if rewrite.NewCNAME == "" {
</s> add host := rewrite.NewCNAME
if host == "" { </s> remove cachedValue, isFound := ss.getCachedResult(host)
</s> add cachedValue, isFound := ss.getCachedResult(host, qtype) </s> remove log.Debug("safesearch: found in cache: %s", host)
</s> add ss.log(log.DEBUG, "found in cache: %q", host) | [
"keep",
"keep",
"keep",
"keep",
"replace"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/rules/google.txt |
|
|www.google.ws^$dnsrewrite=NOERROR;CNAME;forcesafesearch.google.com | <mask> |www.google.tt^$dnsrewrite=NOERROR;CNAME;forcesafesearch.google.com
<mask> |www.google.vg^$dnsrewrite=NOERROR;CNAME;forcesafesearch.google.com
<mask> |www.google.vu^$dnsrewrite=NOERROR;CNAME;forcesafesearch.google.com
<mask> |www.google.ws^$dnsrewrite=NOERROR;CNAME;forcesafesearch.google.com
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove |www.google.ws^$dnsrewrite=NOERROR;CNAME;forcesafesearch.google.com </s> add </s> remove log.Tracef("network:%v addr:%v", network, addr)
</s> add log.Debug("home: customdial: dialing addr %q for network %s", addr, network) </s> remove if rewrite.NewCNAME == "" {
</s> add host := rewrite.NewCNAME
if host == "" { </s> remove cachedValue, isFound := ss.getCachedResult(host)
</s> add cachedValue, isFound := ss.getCachedResult(host, qtype) </s> remove log.Debug("safesearch: found in cache: %s", host)
</s> add ss.log(log.DEBUG, "found in cache: %q", host) | [
"keep",
"keep",
"keep",
"add"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/rules/google.txt |
<mask> |yandex.pl^$dnsrewrite=NOERROR;A;213.180.193.56
<mask> |yandex.ru^$dnsrewrite=NOERROR;A;213.180.193.56
<mask> |yandex.tj^$dnsrewrite=NOERROR;A;213.180.193.56
<mask> |yandex.tm^$dnsrewrite=NOERROR;A;213.180.193.56
<mask> |yandex.uz^$dnsrewrite=NOERROR;A;213.180.193.56 </s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove ips, err := ss.resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME)
</s> add ss.log(log.DEBUG, "resolving %q", host)
ips, err := ss.resolver.LookupIP(context.Background(), qtypeToProto(qtype), host) </s> remove cachedValue, isFound := ss.getCachedResult(host)
</s> add cachedValue, isFound := ss.getCachedResult(host, qtype) </s> remove log.Debug("safesearch: found in cache: %s", host)
</s> add ss.log(log.DEBUG, "found in cache: %q", host) </s> remove rewrite := ss.SearchHost(host, qtype)
</s> add rewrite := ss.searchHost(host, qtype) | [
"keep",
"keep",
"keep",
"keep",
"replace"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/rules/yandex.txt |
|
|yandex.uz^$dnsrewrite=NOERROR;A;213.180.193.56 | <mask> |yandex.ru^$dnsrewrite=NOERROR;A;213.180.193.56
<mask> |yandex.tj^$dnsrewrite=NOERROR;A;213.180.193.56
<mask> |yandex.tm^$dnsrewrite=NOERROR;A;213.180.193.56
<mask> |yandex.uz^$dnsrewrite=NOERROR;A;213.180.193.56
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove |yandex.uz^$dnsrewrite=NOERROR;A;213.180.193.56 </s> add </s> remove ips, err := ss.resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME)
</s> add ss.log(log.DEBUG, "resolving %q", host)
ips, err := ss.resolver.LookupIP(context.Background(), qtypeToProto(qtype), host) </s> remove cachedValue, isFound := ss.getCachedResult(host)
</s> add cachedValue, isFound := ss.getCachedResult(host, qtype) </s> remove log.Debug("safesearch: found in cache: %s", host)
</s> add ss.log(log.DEBUG, "found in cache: %q", host) </s> remove rewrite := ss.SearchHost(host, qtype)
</s> add rewrite := ss.searchHost(host, qtype) | [
"keep",
"keep",
"keep",
"add"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/rules/yandex.txt |
<mask> |www.youtube.com^$dnsrewrite=NOERROR;CNAME;restrictmoderate.youtube.com
<mask> |m.youtube.com^$dnsrewrite=NOERROR;CNAME;restrictmoderate.youtube.com
<mask> |youtubei.googleapis.com^$dnsrewrite=NOERROR;CNAME;restrictmoderate.youtube.com
<mask> |youtube.googleapis.com^$dnsrewrite=NOERROR;CNAME;restrictmoderate.youtube.com
<mask> |www.youtube-nocookie.com^$dnsrewrite=NOERROR;CNAME;restrictmoderate.youtube.com </s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove log.Tracef("network:%v addr:%v", network, addr)
</s> add log.Debug("home: customdial: dialing addr %q for network %s", addr, network) </s> remove if log.GetLevel() >= log.DEBUG {
timer := log.StartTimer()
defer timer.LogElapsed("safesearch: lookup for %s", host)
</s> add start := time.Now()
defer func() {
ss.log(log.DEBUG, "lookup for %q finished in %s", host, time.Since(start))
}()
if qtype != dns.TypeA && qtype != dns.TypeAAAA {
return filtering.Result{}, fmt.Errorf("unsupported question type %s", dns.Type(qtype)) </s> remove cachedValue, isFound := ss.getCachedResult(host)
</s> add cachedValue, isFound := ss.getCachedResult(host, qtype) </s> remove log.Debug("safesearch: found in cache: %s", host)
</s> add ss.log(log.DEBUG, "found in cache: %q", host) </s> remove rewrite := ss.SearchHost(host, qtype)
</s> add rewrite := ss.searchHost(host, qtype) | [
"keep",
"keep",
"keep",
"keep",
"replace"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/rules/youtube.txt |
|
"sync" | <mask> "net"
<mask> "strings"
<mask> "time"
<mask>
<mask> "github.com/AdguardTeam/AdGuardHome/internal/filtering"
<mask> "github.com/AdguardTeam/golibs/cache"
<mask> "github.com/AdguardTeam/golibs/log"
<mask> "github.com/AdguardTeam/urlfilter"
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove "github.com/AdguardTeam/AdGuardHome/internal/filtering/safesearch"
</s> add </s> remove "context"
</s> add </s> remove "github.com/AdguardTeam/urlfilter/rules"
</s> add "github.com/AdguardTeam/AdGuardHome/internal/filtering/safesearch"
"github.com/AdguardTeam/golibs/testutil" | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch.go |
// Default is the default safe search filter that uses filtering rules with the
// dnsrewrite modifier.
type Default struct {
// mu protects engine.
mu *sync.RWMutex
// engine is the filtering engine that contains the DNS rewrite rules.
// engine may be nil, which means that this safe search filter is disabled.
engine *urlfilter.DNSEngine
cache cache.Cache
resolver filtering.Resolver
logPrefix string
cacheTTL time.Duration | <mask> panic(fmt.Errorf("safesearch: invalid sources: not found service %q", service))
<mask> }
<mask> }
<mask>
<mask> // DefaultSafeSearch is the default safesearch struct.
<mask> type DefaultSafeSearch struct {
<mask> engine *urlfilter.DNSEngine
<mask> safeSearchCache cache.Cache
<mask> resolver filtering.Resolver
<mask> cacheTime time.Duration
<mask> }
<mask>
<mask> // NewDefaultSafeSearch returns new safesearch struct. CacheTime is an element
<mask> // TTL (in minutes).
<mask> func NewDefaultSafeSearch(
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove // NewDefaultSafeSearch returns new safesearch struct. CacheTime is an element
// TTL (in minutes).
func NewDefaultSafeSearch(
</s> add // NewDefault returns an initialized default safe search filter. name is used
// for logging.
func NewDefault( </s> remove cacheTime time.Duration,
) (ss *DefaultSafeSearch, err error) {
engine, err := newEngine(filtering.SafeSearchListID, conf)
if err != nil {
return nil, err
}
</s> add cacheTTL time.Duration,
) (ss *Default, err error) { </s> remove // SearchHost returns a replacement address for the search engine host.
SearchHost(host string, qtype uint16) (res *rules.DNSRewrite)
// CheckHost checks host with safe search engine.
</s> add // CheckHost checks host with safe search filter. CheckHost must be safe
// for concurrent use. qtype must be either [dns.TypeA] or [dns.TypeAAAA]. </s> remove // newEngine creates new engine for provided safe search configuration.
func newEngine(listID int, conf filtering.SafeSearchConfig) (engine *urlfilter.DNSEngine, err error) {
</s> add // log is a helper for logging that includes the name of the safe search
// filter. level must be one of [log.DEBUG], [log.INFO], and [log.ERROR].
func (ss *Default) log(level log.Level, msg string, args ...any) {
switch level {
case log.DEBUG:
log.Debug(ss.logPrefix+msg, args...)
case log.INFO:
log.Info(ss.logPrefix+msg, args...)
case log.ERROR:
log.Error(ss.logPrefix+msg, args...)
default:
panic(fmt.Errorf("safesearch: unsupported logging level %d", level))
}
}
// resetEngine creates new engine for provided safe search configuration and
// sets it in ss.
func (ss *Default) resetEngine(
listID int,
conf filtering.SafeSearchConfig,
) (err error) {
if !conf.Enabled {
ss.log(log.INFO, "disabled")
return nil
}
| [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch.go |
// NewDefault returns an initialized default safe search filter. name is used
// for logging.
func NewDefault( | <mask> resolver filtering.Resolver
<mask> cacheTime time.Duration
<mask> }
<mask>
<mask> // NewDefaultSafeSearch returns new safesearch struct. CacheTime is an element
<mask> // TTL (in minutes).
<mask> func NewDefaultSafeSearch(
<mask> conf filtering.SafeSearchConfig,
<mask> cacheSize uint,
<mask> cacheTime time.Duration,
<mask> ) (ss *DefaultSafeSearch, err error) {
<mask> engine, err := newEngine(filtering.SafeSearchListID, conf)
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove cacheTime time.Duration,
) (ss *DefaultSafeSearch, err error) {
engine, err := newEngine(filtering.SafeSearchListID, conf)
if err != nil {
return nil, err
}
</s> add cacheTTL time.Duration,
) (ss *Default, err error) { </s> remove // DefaultSafeSearch is the default safesearch struct.
type DefaultSafeSearch struct {
engine *urlfilter.DNSEngine
safeSearchCache cache.Cache
resolver filtering.Resolver
cacheTime time.Duration
</s> add // Default is the default safe search filter that uses filtering rules with the
// dnsrewrite modifier.
type Default struct {
// mu protects engine.
mu *sync.RWMutex
// engine is the filtering engine that contains the DNS rewrite rules.
// engine may be nil, which means that this safe search filter is disabled.
engine *urlfilter.DNSEngine
cache cache.Cache
resolver filtering.Resolver
logPrefix string
cacheTTL time.Duration </s> remove // newEngine creates new engine for provided safe search configuration.
func newEngine(listID int, conf filtering.SafeSearchConfig) (engine *urlfilter.DNSEngine, err error) {
</s> add // log is a helper for logging that includes the name of the safe search
// filter. level must be one of [log.DEBUG], [log.INFO], and [log.ERROR].
func (ss *Default) log(level log.Level, msg string, args ...any) {
switch level {
case log.DEBUG:
log.Debug(ss.logPrefix+msg, args...)
case log.INFO:
log.Info(ss.logPrefix+msg, args...)
case log.ERROR:
log.Error(ss.logPrefix+msg, args...)
default:
panic(fmt.Errorf("safesearch: unsupported logging level %d", level))
}
}
// resetEngine creates new engine for provided safe search configuration and
// sets it in ss.
func (ss *Default) resetEngine(
listID int,
conf filtering.SafeSearchConfig,
) (err error) {
if !conf.Enabled {
ss.log(log.INFO, "disabled")
return nil
}
</s> remove cacheTime: cacheTime,
resolver: resolver,
}, nil
</s> add resolver: resolver,
// Use %s, because the client safe-search names already contain double
// quotes.
logPrefix: fmt.Sprintf("safesearch %s: ", name),
cacheTTL: cacheTTL,
}
err = ss.resetEngine(filtering.SafeSearchListID, conf)
if err != nil {
// Don't wrap the error, because it's informative enough as is.
return nil, err
}
return ss, nil | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch.go |
name string, | <mask> // for logging.
<mask> func NewDefault(
<mask> conf filtering.SafeSearchConfig,
<mask> cacheSize uint,
<mask> cacheTTL time.Duration,
<mask> ) (ss *Default, err error) {
<mask> var resolver filtering.Resolver = net.DefaultResolver
<mask> if conf.CustomResolver != nil {
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove cacheTime time.Duration,
) (ss *DefaultSafeSearch, err error) {
engine, err := newEngine(filtering.SafeSearchListID, conf)
if err != nil {
return nil, err
}
</s> add cacheTTL time.Duration,
) (ss *Default, err error) { </s> remove // NewDefaultSafeSearch returns new safesearch struct. CacheTime is an element
// TTL (in minutes).
func NewDefaultSafeSearch(
</s> add // NewDefault returns an initialized default safe search filter. name is used
// for logging.
func NewDefault( </s> remove ss := newForTest(t, defaultSafeSearchConf)
ss.resolver = resolver
</s> add conf := testConf
conf.CustomResolver = resolver
ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL)
require.NoError(t, err) </s> remove // newEngine creates new engine for provided safe search configuration.
func newEngine(listID int, conf filtering.SafeSearchConfig) (engine *urlfilter.DNSEngine, err error) {
</s> add // log is a helper for logging that includes the name of the safe search
// filter. level must be one of [log.DEBUG], [log.INFO], and [log.ERROR].
func (ss *Default) log(level log.Level, msg string, args ...any) {
switch level {
case log.DEBUG:
log.Debug(ss.logPrefix+msg, args...)
case log.INFO:
log.Info(ss.logPrefix+msg, args...)
case log.ERROR:
log.Error(ss.logPrefix+msg, args...)
default:
panic(fmt.Errorf("safesearch: unsupported logging level %d", level))
}
}
// resetEngine creates new engine for provided safe search configuration and
// sets it in ss.
func (ss *Default) resetEngine(
listID int,
conf filtering.SafeSearchConfig,
) (err error) {
if !conf.Enabled {
ss.log(log.INFO, "disabled")
return nil
}
</s> remove return &DefaultSafeSearch{
engine: engine,
safeSearchCache: cache.New(cache.Config{
</s> add ss = &Default{
mu: &sync.RWMutex{},
cache: cache.New(cache.Config{ | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch.go |
cacheTTL time.Duration,
) (ss *Default, err error) { | <mask> // TTL (in minutes).
<mask> func NewDefaultSafeSearch(
<mask> conf filtering.SafeSearchConfig,
<mask> cacheSize uint,
<mask> cacheTime time.Duration,
<mask> ) (ss *DefaultSafeSearch, err error) {
<mask> engine, err := newEngine(filtering.SafeSearchListID, conf)
<mask> if err != nil {
<mask> return nil, err
<mask> }
<mask>
<mask> var resolver filtering.Resolver = net.DefaultResolver
<mask> if conf.CustomResolver != nil {
<mask> resolver = conf.CustomResolver
<mask> }
<mask>
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove // NewDefaultSafeSearch returns new safesearch struct. CacheTime is an element
// TTL (in minutes).
func NewDefaultSafeSearch(
</s> add // NewDefault returns an initialized default safe search filter. name is used
// for logging.
func NewDefault( </s> remove return &DefaultSafeSearch{
engine: engine,
safeSearchCache: cache.New(cache.Config{
</s> add ss = &Default{
mu: &sync.RWMutex{},
cache: cache.New(cache.Config{ </s> remove ss := newForTest(t, defaultSafeSearchConf)
ss.resolver = resolver
</s> add conf := testConf
conf.CustomResolver = resolver
ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL)
require.NoError(t, err) </s> remove // DefaultSafeSearch is the default safesearch struct.
type DefaultSafeSearch struct {
engine *urlfilter.DNSEngine
safeSearchCache cache.Cache
resolver filtering.Resolver
cacheTime time.Duration
</s> add // Default is the default safe search filter that uses filtering rules with the
// dnsrewrite modifier.
type Default struct {
// mu protects engine.
mu *sync.RWMutex
// engine is the filtering engine that contains the DNS rewrite rules.
// engine may be nil, which means that this safe search filter is disabled.
engine *urlfilter.DNSEngine
cache cache.Cache
resolver filtering.Resolver
logPrefix string
cacheTTL time.Duration | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch.go |
ss = &Default{
mu: &sync.RWMutex{},
cache: cache.New(cache.Config{ | <mask> if conf.CustomResolver != nil {
<mask> resolver = conf.CustomResolver
<mask> }
<mask>
<mask> return &DefaultSafeSearch{
<mask> engine: engine,
<mask> safeSearchCache: cache.New(cache.Config{
<mask> EnableLRU: true,
<mask> MaxSize: cacheSize,
<mask> }),
<mask> cacheTime: cacheTime,
<mask> resolver: resolver,
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove cacheTime: cacheTime,
resolver: resolver,
}, nil
</s> add resolver: resolver,
// Use %s, because the client safe-search names already contain double
// quotes.
logPrefix: fmt.Sprintf("safesearch %s: ", name),
cacheTTL: cacheTTL,
}
err = ss.resetEngine(filtering.SafeSearchListID, conf)
if err != nil {
// Don't wrap the error, because it's informative enough as is.
return nil, err
}
return ss, nil </s> remove cacheTime time.Duration,
) (ss *DefaultSafeSearch, err error) {
engine, err := newEngine(filtering.SafeSearchListID, conf)
if err != nil {
return nil, err
}
</s> add cacheTTL time.Duration,
) (ss *Default, err error) { </s> remove ss := newForTest(t, defaultSafeSearchConf)
ss.resolver = resolver
</s> add conf := testConf
conf.CustomResolver = resolver
ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL)
require.NoError(t, err) </s> remove resolver := &aghtest.TestResolver{}
ss = newForTest(t, defaultSafeSearchConf)
ss.resolver = resolver
// Lookup for safesearch domain.
rewrite := ss.SearchHost(domain, dns.TypeA)
ips, err := resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME)
</s> add err = ss.Update(filtering.SafeSearchConfig{
Enabled: false,
Google: true,
}) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch.go |
resolver: resolver,
// Use %s, because the client safe-search names already contain double
// quotes.
logPrefix: fmt.Sprintf("safesearch %s: ", name),
cacheTTL: cacheTTL,
}
err = ss.resetEngine(filtering.SafeSearchListID, conf)
if err != nil {
// Don't wrap the error, because it's informative enough as is.
return nil, err
}
return ss, nil | <mask> safeSearchCache: cache.New(cache.Config{
<mask> EnableLRU: true,
<mask> MaxSize: cacheSize,
<mask> }),
<mask> cacheTime: cacheTime,
<mask> resolver: resolver,
<mask> }, nil
<mask> }
<mask>
<mask> // newEngine creates new engine for provided safe search configuration.
<mask> func newEngine(listID int, conf filtering.SafeSearchConfig) (engine *urlfilter.DNSEngine, err error) {
<mask> var sb strings.Builder
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove return &DefaultSafeSearch{
engine: engine,
safeSearchCache: cache.New(cache.Config{
</s> add ss = &Default{
mu: &sync.RWMutex{},
cache: cache.New(cache.Config{ </s> remove // newEngine creates new engine for provided safe search configuration.
func newEngine(listID int, conf filtering.SafeSearchConfig) (engine *urlfilter.DNSEngine, err error) {
</s> add // log is a helper for logging that includes the name of the safe search
// filter. level must be one of [log.DEBUG], [log.INFO], and [log.ERROR].
func (ss *Default) log(level log.Level, msg string, args ...any) {
switch level {
case log.DEBUG:
log.Debug(ss.logPrefix+msg, args...)
case log.INFO:
log.Info(ss.logPrefix+msg, args...)
case log.ERROR:
log.Error(ss.logPrefix+msg, args...)
default:
panic(fmt.Errorf("safesearch: unsupported logging level %d", level))
}
}
// resetEngine creates new engine for provided safe search configuration and
// sets it in ss.
func (ss *Default) resetEngine(
listID int,
conf filtering.SafeSearchConfig,
) (err error) {
if !conf.Enabled {
ss.log(log.INFO, "disabled")
return nil
}
</s> remove // NewDefaultSafeSearch returns new safesearch struct. CacheTime is an element
// TTL (in minutes).
func NewDefaultSafeSearch(
</s> add // NewDefault returns an initialized default safe search filter. name is used
// for logging.
func NewDefault( </s> remove // SearchHost returns a replacement address for the search engine host.
SearchHost(host string, qtype uint16) (res *rules.DNSRewrite)
// CheckHost checks host with safe search engine.
</s> add // CheckHost checks host with safe search filter. CheckHost must be safe
// for concurrent use. qtype must be either [dns.TypeA] or [dns.TypeAAAA]. | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch.go |
// log is a helper for logging that includes the name of the safe search
// filter. level must be one of [log.DEBUG], [log.INFO], and [log.ERROR].
func (ss *Default) log(level log.Level, msg string, args ...any) {
switch level {
case log.DEBUG:
log.Debug(ss.logPrefix+msg, args...)
case log.INFO:
log.Info(ss.logPrefix+msg, args...)
case log.ERROR:
log.Error(ss.logPrefix+msg, args...)
default:
panic(fmt.Errorf("safesearch: unsupported logging level %d", level))
}
}
// resetEngine creates new engine for provided safe search configuration and
// sets it in ss.
func (ss *Default) resetEngine(
listID int,
conf filtering.SafeSearchConfig,
) (err error) {
if !conf.Enabled {
ss.log(log.INFO, "disabled")
return nil
}
| <mask> resolver: resolver,
<mask> }, nil
<mask> }
<mask>
<mask> // newEngine creates new engine for provided safe search configuration.
<mask> func newEngine(listID int, conf filtering.SafeSearchConfig) (engine *urlfilter.DNSEngine, err error) {
<mask> var sb strings.Builder
<mask> for service, serviceRules := range safeSearchRules {
<mask> if isServiceProtected(conf, service) {
<mask> sb.WriteString(serviceRules)
<mask> }
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove cacheTime: cacheTime,
resolver: resolver,
}, nil
</s> add resolver: resolver,
// Use %s, because the client safe-search names already contain double
// quotes.
logPrefix: fmt.Sprintf("safesearch %s: ", name),
cacheTTL: cacheTTL,
}
err = ss.resetEngine(filtering.SafeSearchListID, conf)
if err != nil {
// Don't wrap the error, because it's informative enough as is.
return nil, err
}
return ss, nil </s> remove func newForTest(t testing.TB, ssConf filtering.SafeSearchConfig) (ss *DefaultSafeSearch) {
ss, err := NewDefaultSafeSearch(ssConf, safeSearchCacheSize, cacheTime)
</s> add func TestDefault_CheckHost_yandex(t *testing.T) {
conf := testConf
ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL) </s> remove // NewDefaultSafeSearch returns new safesearch struct. CacheTime is an element
// TTL (in minutes).
func NewDefaultSafeSearch(
</s> add // NewDefault returns an initialized default safe search filter. name is used
// for logging.
func NewDefault( </s> remove cacheTime time.Duration,
) (ss *DefaultSafeSearch, err error) {
engine, err := newEngine(filtering.SafeSearchListID, conf)
if err != nil {
return nil, err
}
</s> add cacheTTL time.Duration,
) (ss *Default, err error) { </s> remove return ss
}
func TestSafeSearch(t *testing.T) {
ss := newForTest(t, defaultSafeSearchConf)
val := ss.SearchHost("www.google.com", dns.TypeA)
assert.Equal(t, &rules.DNSRewrite{NewCNAME: "forcesafesearch.google.com"}, val)
}
func TestCheckHostSafeSearchYandex(t *testing.T) {
ss := newForTest(t, defaultSafeSearchConf)
</s> add | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch.go |
return fmt.Errorf("creating rule storage: %w", err) | <mask> }
<mask>
<mask> rs, err := filterlist.NewRuleStorage([]filterlist.RuleList{strList})
<mask> if err != nil {
<mask> return nil, fmt.Errorf("creating rule storage: %w", err)
<mask> }
<mask>
<mask> engine = urlfilter.NewDNSEngine(rs)
<mask> log.Info("safesearch: filter %d: reset %d rules", listID, engine.RulesCount)
<mask>
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove engine = urlfilter.NewDNSEngine(rs)
log.Info("safesearch: filter %d: reset %d rules", listID, engine.RulesCount)
return engine, nil
}
// type check
var _ filtering.SafeSearch = (*DefaultSafeSearch)(nil)
</s> add ss.engine = urlfilter.NewDNSEngine(rs) </s> remove Upstreams: cj.Upstreams,
</s> add if safeSearchConf.Enabled {
err = c.setSafeSearch(
safeSearchConf,
clients.safeSearchCacheSize,
clients.safeSearchCacheTTL,
)
if err != nil {
return nil, fmt.Errorf("creating safesearch for client %q: %w", c.Name, err)
} </s> remove ips, err := ss.resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME)
</s> add ss.log(log.DEBUG, "resolving %q", host)
ips, err := ss.resolver.LookupIP(context.Background(), qtypeToProto(qtype), host) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch.go |
ss.engine = urlfilter.NewDNSEngine(rs) | <mask> if err != nil {
<mask> return nil, fmt.Errorf("creating rule storage: %w", err)
<mask> }
<mask>
<mask> engine = urlfilter.NewDNSEngine(rs)
<mask> log.Info("safesearch: filter %d: reset %d rules", listID, engine.RulesCount)
<mask>
<mask> return engine, nil
<mask> }
<mask>
<mask> // type check
<mask> var _ filtering.SafeSearch = (*DefaultSafeSearch)(nil)
<mask>
<mask> // SearchHost implements the [filtering.SafeSearch] interface for *DefaultSafeSearch.
<mask> func (ss *DefaultSafeSearch) SearchHost(host string, qtype uint16) (res *rules.DNSRewrite) {
<mask> r, _ := ss.engine.MatchRequest(&urlfilter.DNSRequest{
<mask> Hostname: strings.ToLower(host),
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove // SearchHost implements the [filtering.SafeSearch] interface for *DefaultSafeSearch.
func (ss *DefaultSafeSearch) SearchHost(host string, qtype uint16) (res *rules.DNSRewrite) {
r, _ := ss.engine.MatchRequest(&urlfilter.DNSRequest{
Hostname: strings.ToLower(host),
DNSType: qtype,
})
rewritesRules := r.DNSRewrites()
if len(rewritesRules) > 0 {
return rewritesRules[0].DNSRewrite
}
</s> add ss.log(log.INFO, "reset %d rules", ss.engine.RulesCount) </s> remove return nil, fmt.Errorf("creating rule storage: %w", err)
</s> add return fmt.Errorf("creating rule storage: %w", err) </s> remove func (ss *DefaultSafeSearch) CheckHost(
</s> add func (ss *Default) CheckHost( </s> remove qtype uint16,
</s> add qtype rules.RRType, | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch.go |
ss.log(log.INFO, "reset %d rules", ss.engine.RulesCount) | <mask>
<mask> // type check
<mask> var _ filtering.SafeSearch = (*DefaultSafeSearch)(nil)
<mask>
<mask> // SearchHost implements the [filtering.SafeSearch] interface for *DefaultSafeSearch.
<mask> func (ss *DefaultSafeSearch) SearchHost(host string, qtype uint16) (res *rules.DNSRewrite) {
<mask> r, _ := ss.engine.MatchRequest(&urlfilter.DNSRequest{
<mask> Hostname: strings.ToLower(host),
<mask> DNSType: qtype,
<mask> })
<mask>
<mask> rewritesRules := r.DNSRewrites()
<mask> if len(rewritesRules) > 0 {
<mask> return rewritesRules[0].DNSRewrite
<mask> }
<mask>
<mask> return nil
<mask> }
<mask>
<mask> // CheckHost implements the [filtering.SafeSearch] interface for
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove engine = urlfilter.NewDNSEngine(rs)
log.Info("safesearch: filter %d: reset %d rules", listID, engine.RulesCount)
return engine, nil
}
// type check
var _ filtering.SafeSearch = (*DefaultSafeSearch)(nil)
</s> add ss.engine = urlfilter.NewDNSEngine(rs) </s> remove // newResult creates Result object from rewrite rule.
func (ss *DefaultSafeSearch) newResult(
</s> add // searchHost looks up DNS rewrites in the internal DNS filtering engine.
func (ss *Default) searchHost(host string, qtype rules.RRType) (res *rules.DNSRewrite) {
ss.mu.RLock()
defer ss.mu.RUnlock()
if ss.engine == nil {
return nil
}
r, _ := ss.engine.MatchRequest(&urlfilter.DNSRequest{
Hostname: strings.ToLower(host),
DNSType: qtype,
})
rewritesRules := r.DNSRewrites()
if len(rewritesRules) > 0 {
return rewritesRules[0].DNSRewrite
}
return nil
}
// newResult creates Result object from rewrite rule. qtype must be either
// [dns.TypeA] or [dns.TypeAAAA].
func (ss *Default) newResult( </s> remove func (ss *DefaultSafeSearch) CheckHost(
</s> add func (ss *Default) CheckHost( </s> remove qtype uint16,
</s> add qtype rules.RRType, | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch.go |
// type check
var _ filtering.SafeSearch = (*Default)(nil)
| <mask>
<mask> return nil
<mask> }
<mask>
<mask> // CheckHost implements the [filtering.SafeSearch] interface for
<mask> // *DefaultSafeSearch.
<mask> func (ss *Default) CheckHost(
<mask> host string,
<mask> qtype rules.RRType,
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove func (ss *DefaultSafeSearch) CheckHost(
</s> add func (ss *Default) CheckHost( </s> remove qtype uint16,
</s> add qtype rules.RRType, </s> remove // SearchHost implements the [filtering.SafeSearch] interface for *DefaultSafeSearch.
func (ss *DefaultSafeSearch) SearchHost(host string, qtype uint16) (res *rules.DNSRewrite) {
r, _ := ss.engine.MatchRequest(&urlfilter.DNSRequest{
Hostname: strings.ToLower(host),
DNSType: qtype,
})
rewritesRules := r.DNSRewrites()
if len(rewritesRules) > 0 {
return rewritesRules[0].DNSRewrite
}
</s> add ss.log(log.INFO, "reset %d rules", ss.engine.RulesCount) </s> remove engine = urlfilter.NewDNSEngine(rs)
log.Info("safesearch: filter %d: reset %d rules", listID, engine.RulesCount)
return engine, nil
}
// type check
var _ filtering.SafeSearch = (*DefaultSafeSearch)(nil)
</s> add ss.engine = urlfilter.NewDNSEngine(rs) </s> remove // SearchHost returns a replacement address for the search engine host.
SearchHost(host string, qtype uint16) (res *rules.DNSRewrite)
// CheckHost checks host with safe search engine.
</s> add // CheckHost checks host with safe search filter. CheckHost must be safe
// for concurrent use. qtype must be either [dns.TypeA] or [dns.TypeAAAA]. | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch.go |
func (ss *Default) CheckHost( | <mask> }
<mask>
<mask> // CheckHost implements the [filtering.SafeSearch] interface for
<mask> // *DefaultSafeSearch.
<mask> func (ss *DefaultSafeSearch) CheckHost(
<mask> host string,
<mask> qtype uint16,
<mask> ) (res filtering.Result, err error) {
<mask> if log.GetLevel() >= log.DEBUG {
<mask> timer := log.StartTimer()
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove qtype uint16,
</s> add qtype rules.RRType, </s> remove if log.GetLevel() >= log.DEBUG {
timer := log.StartTimer()
defer timer.LogElapsed("safesearch: lookup for %s", host)
</s> add start := time.Now()
defer func() {
ss.log(log.DEBUG, "lookup for %q finished in %s", host, time.Since(start))
}()
if qtype != dns.TypeA && qtype != dns.TypeAAAA {
return filtering.Result{}, fmt.Errorf("unsupported question type %s", dns.Type(qtype)) </s> remove // SearchHost implements the [filtering.SafeSearch] interface for *DefaultSafeSearch.
func (ss *DefaultSafeSearch) SearchHost(host string, qtype uint16) (res *rules.DNSRewrite) {
r, _ := ss.engine.MatchRequest(&urlfilter.DNSRequest{
Hostname: strings.ToLower(host),
DNSType: qtype,
})
rewritesRules := r.DNSRewrites()
if len(rewritesRules) > 0 {
return rewritesRules[0].DNSRewrite
}
</s> add ss.log(log.INFO, "reset %d rules", ss.engine.RulesCount) </s> remove engine = urlfilter.NewDNSEngine(rs)
log.Info("safesearch: filter %d: reset %d rules", listID, engine.RulesCount)
return engine, nil
}
// type check
var _ filtering.SafeSearch = (*DefaultSafeSearch)(nil)
</s> add ss.engine = urlfilter.NewDNSEngine(rs) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch.go |
qtype rules.RRType, | <mask> // CheckHost implements the [filtering.SafeSearch] interface for
<mask> // *DefaultSafeSearch.
<mask> func (ss *DefaultSafeSearch) CheckHost(
<mask> host string,
<mask> qtype uint16,
<mask> ) (res filtering.Result, err error) {
<mask> if log.GetLevel() >= log.DEBUG {
<mask> timer := log.StartTimer()
<mask> defer timer.LogElapsed("safesearch: lookup for %s", host)
<mask> }
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove func (ss *DefaultSafeSearch) CheckHost(
</s> add func (ss *Default) CheckHost( </s> remove if log.GetLevel() >= log.DEBUG {
timer := log.StartTimer()
defer timer.LogElapsed("safesearch: lookup for %s", host)
</s> add start := time.Now()
defer func() {
ss.log(log.DEBUG, "lookup for %q finished in %s", host, time.Since(start))
}()
if qtype != dns.TypeA && qtype != dns.TypeAAAA {
return filtering.Result{}, fmt.Errorf("unsupported question type %s", dns.Type(qtype)) </s> remove // SearchHost implements the [filtering.SafeSearch] interface for *DefaultSafeSearch.
func (ss *DefaultSafeSearch) SearchHost(host string, qtype uint16) (res *rules.DNSRewrite) {
r, _ := ss.engine.MatchRequest(&urlfilter.DNSRequest{
Hostname: strings.ToLower(host),
DNSType: qtype,
})
rewritesRules := r.DNSRewrites()
if len(rewritesRules) > 0 {
return rewritesRules[0].DNSRewrite
}
</s> add ss.log(log.INFO, "reset %d rules", ss.engine.RulesCount) </s> remove engine = urlfilter.NewDNSEngine(rs)
log.Info("safesearch: filter %d: reset %d rules", listID, engine.RulesCount)
return engine, nil
}
// type check
var _ filtering.SafeSearch = (*DefaultSafeSearch)(nil)
</s> add ss.engine = urlfilter.NewDNSEngine(rs) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch.go |
start := time.Now()
defer func() {
ss.log(log.DEBUG, "lookup for %q finished in %s", host, time.Since(start))
}()
if qtype != dns.TypeA && qtype != dns.TypeAAAA {
return filtering.Result{}, fmt.Errorf("unsupported question type %s", dns.Type(qtype)) | <mask> func (ss *DefaultSafeSearch) CheckHost(
<mask> host string,
<mask> qtype uint16,
<mask> ) (res filtering.Result, err error) {
<mask> if log.GetLevel() >= log.DEBUG {
<mask> timer := log.StartTimer()
<mask> defer timer.LogElapsed("safesearch: lookup for %s", host)
<mask> }
<mask>
<mask> // Check cache. Return cached result if it was found
<mask> cachedValue, isFound := ss.getCachedResult(host)
<mask> if isFound {
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove cachedValue, isFound := ss.getCachedResult(host)
</s> add cachedValue, isFound := ss.getCachedResult(host, qtype) </s> remove qtype uint16,
</s> add qtype rules.RRType, </s> remove log.Debug("safesearch: found in cache: %s", host)
</s> add ss.log(log.DEBUG, "found in cache: %q", host) </s> remove func (ss *DefaultSafeSearch) CheckHost(
</s> add func (ss *Default) CheckHost( </s> remove // newResult creates Result object from rewrite rule.
func (ss *DefaultSafeSearch) newResult(
</s> add // searchHost looks up DNS rewrites in the internal DNS filtering engine.
func (ss *Default) searchHost(host string, qtype rules.RRType) (res *rules.DNSRewrite) {
ss.mu.RLock()
defer ss.mu.RUnlock()
if ss.engine == nil {
return nil
}
r, _ := ss.engine.MatchRequest(&urlfilter.DNSRequest{
Hostname: strings.ToLower(host),
DNSType: qtype,
})
rewritesRules := r.DNSRewrites()
if len(rewritesRules) > 0 {
return rewritesRules[0].DNSRewrite
}
return nil
}
// newResult creates Result object from rewrite rule. qtype must be either
// [dns.TypeA] or [dns.TypeAAAA].
func (ss *Default) newResult( | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch.go |
cachedValue, isFound := ss.getCachedResult(host, qtype) | <mask> defer timer.LogElapsed("safesearch: lookup for %s", host)
<mask> }
<mask>
<mask> // Check cache. Return cached result if it was found
<mask> cachedValue, isFound := ss.getCachedResult(host)
<mask> if isFound {
<mask> log.Debug("safesearch: found in cache: %s", host)
<mask>
<mask> return cachedValue, nil
<mask> }
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove log.Debug("safesearch: found in cache: %s", host)
</s> add ss.log(log.DEBUG, "found in cache: %q", host) </s> remove if log.GetLevel() >= log.DEBUG {
timer := log.StartTimer()
defer timer.LogElapsed("safesearch: lookup for %s", host)
</s> add start := time.Now()
defer func() {
ss.log(log.DEBUG, "lookup for %q finished in %s", host, time.Since(start))
}()
if qtype != dns.TypeA && qtype != dns.TypeAAAA {
return filtering.Result{}, fmt.Errorf("unsupported question type %s", dns.Type(qtype)) </s> remove qtype uint16,
</s> add qtype rules.RRType, </s> remove require.Len(t, res.Rules, 1)
assert.True(t, res.Rules[0].IP.Equal(foundIP))
// Check cache.
cachedValue, isFound := ss.getCachedResult(domain)
require.True(t, isFound)
require.Len(t, cachedValue.Rules, 1)
assert.True(t, cachedValue.Rules[0].IP.Equal(foundIP))
}
const googleHost = "www.google.com"
</s> add </s> remove // For yandex we already know valid IP.
require.Len(t, res.Rules, 1)
</s> add assert.True(t, res.IsFiltered) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch.go |
ss.log(log.DEBUG, "found in cache: %q", host) | <mask>
<mask> // Check cache. Return cached result if it was found
<mask> cachedValue, isFound := ss.getCachedResult(host)
<mask> if isFound {
<mask> log.Debug("safesearch: found in cache: %s", host)
<mask>
<mask> return cachedValue, nil
<mask> }
<mask>
<mask> rewrite := ss.SearchHost(host, qtype)
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove cachedValue, isFound := ss.getCachedResult(host)
</s> add cachedValue, isFound := ss.getCachedResult(host, qtype) </s> remove if log.GetLevel() >= log.DEBUG {
timer := log.StartTimer()
defer timer.LogElapsed("safesearch: lookup for %s", host)
</s> add start := time.Now()
defer func() {
ss.log(log.DEBUG, "lookup for %q finished in %s", host, time.Since(start))
}()
if qtype != dns.TypeA && qtype != dns.TypeAAAA {
return filtering.Result{}, fmt.Errorf("unsupported question type %s", dns.Type(qtype)) </s> remove rewrite := ss.SearchHost(host, qtype)
</s> add rewrite := ss.searchHost(host, qtype) </s> remove require.Len(t, res.Rules, 1)
assert.True(t, res.Rules[0].IP.Equal(foundIP))
// Check cache.
cachedValue, isFound := ss.getCachedResult(domain)
require.True(t, isFound)
require.Len(t, cachedValue.Rules, 1)
assert.True(t, cachedValue.Rules[0].IP.Equal(foundIP))
}
const googleHost = "www.google.com"
</s> add </s> remove // For yandex we already know valid IP.
require.Len(t, res.Rules, 1)
</s> add assert.True(t, res.IsFiltered) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch.go |
rewrite := ss.searchHost(host, qtype) | <mask>
<mask> return cachedValue, nil
<mask> }
<mask>
<mask> rewrite := ss.SearchHost(host, qtype)
<mask> if rewrite == nil {
<mask> return filtering.Result{}, nil
<mask> }
<mask>
<mask> dRes, err := ss.newResult(rewrite, qtype)
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove dRes, err := ss.newResult(rewrite, qtype)
</s> add fltRes, err := ss.newResult(rewrite, qtype) </s> remove log.Debug("safesearch: found in cache: %s", host)
</s> add ss.log(log.DEBUG, "found in cache: %q", host) </s> remove log.Debug("safesearch: failed to lookup addresses for %s: %s", host, err)
</s> add ss.log(log.DEBUG, "looking up addresses for %q: %s", host, err) </s> remove cachedValue, isFound := ss.getCachedResult(host)
</s> add cachedValue, isFound := ss.getCachedResult(host, qtype) </s> remove // newResult creates Result object from rewrite rule.
func (ss *DefaultSafeSearch) newResult(
</s> add // searchHost looks up DNS rewrites in the internal DNS filtering engine.
func (ss *Default) searchHost(host string, qtype rules.RRType) (res *rules.DNSRewrite) {
ss.mu.RLock()
defer ss.mu.RUnlock()
if ss.engine == nil {
return nil
}
r, _ := ss.engine.MatchRequest(&urlfilter.DNSRequest{
Hostname: strings.ToLower(host),
DNSType: qtype,
})
rewritesRules := r.DNSRewrites()
if len(rewritesRules) > 0 {
return rewritesRules[0].DNSRewrite
}
return nil
}
// newResult creates Result object from rewrite rule. qtype must be either
// [dns.TypeA] or [dns.TypeAAAA].
func (ss *Default) newResult( | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch.go |
fltRes, err := ss.newResult(rewrite, qtype) | <mask> if rewrite == nil {
<mask> return filtering.Result{}, nil
<mask> }
<mask>
<mask> dRes, err := ss.newResult(rewrite, qtype)
<mask> if err != nil {
<mask> log.Debug("safesearch: failed to lookup addresses for %s: %s", host, err)
<mask>
<mask> return filtering.Result{}, err
<mask> }
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove log.Debug("safesearch: failed to lookup addresses for %s: %s", host, err)
</s> add ss.log(log.DEBUG, "looking up addresses for %q: %s", host, err) </s> remove rewrite := ss.SearchHost(host, qtype)
</s> add rewrite := ss.searchHost(host, qtype) </s> remove log.Debug("safesearch: cache decoding: %s", err)
</s> add ss.log(log.ERROR, "cache decoding: %s", err) </s> remove if dRes != nil {
res = *dRes
ss.setCacheResult(host, res)
</s> add if fltRes != nil {
res = *fltRes
ss.setCacheResult(host, qtype, res) </s> remove return filtering.Result{}, fmt.Errorf("no ipv4 addresses in safe search response for %s", host)
</s> add return filtering.Result{}, fmt.Errorf("no ipv4 addresses for %q", host) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch.go |
ss.log(log.DEBUG, "looking up addresses for %q: %s", host, err) | <mask> }
<mask>
<mask> dRes, err := ss.newResult(rewrite, qtype)
<mask> if err != nil {
<mask> log.Debug("safesearch: failed to lookup addresses for %s: %s", host, err)
<mask>
<mask> return filtering.Result{}, err
<mask> }
<mask>
<mask> if dRes != nil {
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove dRes, err := ss.newResult(rewrite, qtype)
</s> add fltRes, err := ss.newResult(rewrite, qtype) </s> remove rewrite := ss.SearchHost(host, qtype)
</s> add rewrite := ss.searchHost(host, qtype) </s> remove if dRes != nil {
res = *dRes
ss.setCacheResult(host, res)
</s> add if fltRes != nil {
res = *fltRes
ss.setCacheResult(host, qtype, res) </s> remove log.Debug("safesearch: cache decoding: %s", err)
</s> add ss.log(log.ERROR, "cache decoding: %s", err) </s> remove if log.GetLevel() >= log.DEBUG {
timer := log.StartTimer()
defer timer.LogElapsed("safesearch: lookup for %s", host)
</s> add start := time.Now()
defer func() {
ss.log(log.DEBUG, "lookup for %q finished in %s", host, time.Since(start))
}()
if qtype != dns.TypeA && qtype != dns.TypeAAAA {
return filtering.Result{}, fmt.Errorf("unsupported question type %s", dns.Type(qtype)) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch.go |
if fltRes != nil {
res = *fltRes
ss.setCacheResult(host, qtype, res) | <mask>
<mask> return filtering.Result{}, err
<mask> }
<mask>
<mask> if dRes != nil {
<mask> res = *dRes
<mask> ss.setCacheResult(host, res)
<mask>
<mask> return res, nil
<mask> }
<mask>
<mask> return filtering.Result{}, fmt.Errorf("no ipv4 addresses in safe search response for %s", host)
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove return filtering.Result{}, fmt.Errorf("no ipv4 addresses in safe search response for %s", host)
</s> add return filtering.Result{}, fmt.Errorf("no ipv4 addresses for %q", host) </s> remove log.Debug("safesearch: failed to lookup addresses for %s: %s", host, err)
</s> add ss.log(log.DEBUG, "looking up addresses for %q: %s", host, err) </s> remove // newResult creates Result object from rewrite rule.
func (ss *DefaultSafeSearch) newResult(
</s> add // searchHost looks up DNS rewrites in the internal DNS filtering engine.
func (ss *Default) searchHost(host string, qtype rules.RRType) (res *rules.DNSRewrite) {
ss.mu.RLock()
defer ss.mu.RUnlock()
if ss.engine == nil {
return nil
}
r, _ := ss.engine.MatchRequest(&urlfilter.DNSRequest{
Hostname: strings.ToLower(host),
DNSType: qtype,
})
rewritesRules := r.DNSRewrites()
if len(rewritesRules) > 0 {
return rewritesRules[0].DNSRewrite
}
return nil
}
// newResult creates Result object from rewrite rule. qtype must be either
// [dns.TypeA] or [dns.TypeAAAA].
func (ss *Default) newResult( </s> remove dRes, err := ss.newResult(rewrite, qtype)
</s> add fltRes, err := ss.newResult(rewrite, qtype) </s> remove log.Debug("safesearch: cache decoding: %s", err)
</s> add ss.log(log.ERROR, "cache decoding: %s", err) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch.go |
return filtering.Result{}, fmt.Errorf("no ipv4 addresses for %q", host) | <mask>
<mask> return res, nil
<mask> }
<mask>
<mask> return filtering.Result{}, fmt.Errorf("no ipv4 addresses in safe search response for %s", host)
<mask> }
<mask>
<mask> // newResult creates Result object from rewrite rule.
<mask> func (ss *DefaultSafeSearch) newResult(
<mask> rewrite *rules.DNSRewrite,
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove // newResult creates Result object from rewrite rule.
func (ss *DefaultSafeSearch) newResult(
</s> add // searchHost looks up DNS rewrites in the internal DNS filtering engine.
func (ss *Default) searchHost(host string, qtype rules.RRType) (res *rules.DNSRewrite) {
ss.mu.RLock()
defer ss.mu.RUnlock()
if ss.engine == nil {
return nil
}
r, _ := ss.engine.MatchRequest(&urlfilter.DNSRequest{
Hostname: strings.ToLower(host),
DNSType: qtype,
})
rewritesRules := r.DNSRewrites()
if len(rewritesRules) > 0 {
return rewritesRules[0].DNSRewrite
}
return nil
}
// newResult creates Result object from rewrite rule. qtype must be either
// [dns.TypeA] or [dns.TypeAAAA].
func (ss *Default) newResult( </s> remove qtype uint16,
</s> add qtype rules.RRType, </s> remove if dRes != nil {
res = *dRes
ss.setCacheResult(host, res)
</s> add if fltRes != nil {
res = *fltRes
ss.setCacheResult(host, qtype, res) </s> remove dRes, err := ss.newResult(rewrite, qtype)
</s> add fltRes, err := ss.newResult(rewrite, qtype) </s> remove rewrite := ss.SearchHost(host, qtype)
</s> add rewrite := ss.searchHost(host, qtype) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch.go |
// searchHost looks up DNS rewrites in the internal DNS filtering engine.
func (ss *Default) searchHost(host string, qtype rules.RRType) (res *rules.DNSRewrite) {
ss.mu.RLock()
defer ss.mu.RUnlock()
if ss.engine == nil {
return nil
}
r, _ := ss.engine.MatchRequest(&urlfilter.DNSRequest{
Hostname: strings.ToLower(host),
DNSType: qtype,
})
rewritesRules := r.DNSRewrites()
if len(rewritesRules) > 0 {
return rewritesRules[0].DNSRewrite
}
return nil
}
// newResult creates Result object from rewrite rule. qtype must be either
// [dns.TypeA] or [dns.TypeAAAA].
func (ss *Default) newResult( | <mask>
<mask> return filtering.Result{}, fmt.Errorf("no ipv4 addresses in safe search response for %s", host)
<mask> }
<mask>
<mask> // newResult creates Result object from rewrite rule.
<mask> func (ss *DefaultSafeSearch) newResult(
<mask> rewrite *rules.DNSRewrite,
<mask> qtype uint16,
<mask> ) (res *filtering.Result, err error) {
<mask> res = &filtering.Result{
<mask> Rules: []*filtering.ResultRule{{
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove return filtering.Result{}, fmt.Errorf("no ipv4 addresses in safe search response for %s", host)
</s> add return filtering.Result{}, fmt.Errorf("no ipv4 addresses for %q", host) </s> remove qtype uint16,
</s> add qtype rules.RRType, </s> remove if dRes != nil {
res = *dRes
ss.setCacheResult(host, res)
</s> add if fltRes != nil {
res = *fltRes
ss.setCacheResult(host, qtype, res) </s> remove qtype uint16,
</s> add qtype rules.RRType, </s> remove if log.GetLevel() >= log.DEBUG {
timer := log.StartTimer()
defer timer.LogElapsed("safesearch: lookup for %s", host)
</s> add start := time.Now()
defer func() {
ss.log(log.DEBUG, "lookup for %q finished in %s", host, time.Since(start))
}()
if qtype != dns.TypeA && qtype != dns.TypeAAAA {
return filtering.Result{}, fmt.Errorf("unsupported question type %s", dns.Type(qtype)) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch.go |
qtype rules.RRType, | <mask>
<mask> // newResult creates Result object from rewrite rule.
<mask> func (ss *DefaultSafeSearch) newResult(
<mask> rewrite *rules.DNSRewrite,
<mask> qtype uint16,
<mask> ) (res *filtering.Result, err error) {
<mask> res = &filtering.Result{
<mask> Rules: []*filtering.ResultRule{{
<mask> FilterListID: filtering.SafeSearchListID,
<mask> }},
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove // newResult creates Result object from rewrite rule.
func (ss *DefaultSafeSearch) newResult(
</s> add // searchHost looks up DNS rewrites in the internal DNS filtering engine.
func (ss *Default) searchHost(host string, qtype rules.RRType) (res *rules.DNSRewrite) {
ss.mu.RLock()
defer ss.mu.RUnlock()
if ss.engine == nil {
return nil
}
r, _ := ss.engine.MatchRequest(&urlfilter.DNSRequest{
Hostname: strings.ToLower(host),
DNSType: qtype,
})
rewritesRules := r.DNSRewrites()
if len(rewritesRules) > 0 {
return rewritesRules[0].DNSRewrite
}
return nil
}
// newResult creates Result object from rewrite rule. qtype must be either
// [dns.TypeA] or [dns.TypeAAAA].
func (ss *Default) newResult( </s> remove return filtering.Result{}, fmt.Errorf("no ipv4 addresses in safe search response for %s", host)
</s> add return filtering.Result{}, fmt.Errorf("no ipv4 addresses for %q", host) </s> remove func (ss *DefaultSafeSearch) CheckHost(
</s> add func (ss *Default) CheckHost( </s> remove qtype uint16,
</s> add qtype rules.RRType, </s> remove // getCachedResult returns stored data from cache for host.
func (ss *DefaultSafeSearch) getCachedResult(host string) (res filtering.Result, ok bool) {
</s> add // getCachedResult returns stored data from cache for host. qtype is expected
// to be either [dns.TypeA] or [dns.TypeAAAA].
func (ss *Default) getCachedResult(
host string,
qtype rules.RRType,
) (res filtering.Result, ok bool) { | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch.go |
if rewrite.RRType == qtype { | <mask> Reason: filtering.FilteredSafeSearch,
<mask> IsFiltered: true,
<mask> }
<mask>
<mask> if rewrite.RRType == qtype && (qtype == dns.TypeA || qtype == dns.TypeAAAA) {
<mask> ip, ok := rewrite.Value.(net.IP)
<mask> if !ok || ip == nil {
<mask> return nil, nil
<mask> }
<mask>
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove if !setts.ProtectionEnabled || !setts.SafeSearchEnabled {
</s> add if !setts.ProtectionEnabled ||
!setts.SafeSearchEnabled ||
(qtype != dns.TypeA && qtype != dns.TypeAAAA) { </s> remove if ip = ip.To4(); ip == nil {
</s> add // TODO(a.garipov): Remove this filtering once the resolver we use
// actually learns about network.
ip = fitToProto(ip, qtype)
if ip == nil { </s> remove if rewrite.NewCNAME == "" {
</s> add host := rewrite.NewCNAME
if host == "" { </s> remove // setCacheResult stores data in cache for host.
func (ss *DefaultSafeSearch) setCacheResult(host string, res filtering.Result) {
expire := uint32(time.Now().Add(ss.cacheTime).Unix())
</s> add // qtypeToProto returns "ip4" for [dns.TypeA] and "ip6" for [dns.TypeAAAA].
// It panics for other types.
func qtypeToProto(qtype rules.RRType) (proto string) {
switch qtype {
case dns.TypeA:
return "ip4"
case dns.TypeAAAA:
return "ip6"
default:
panic(fmt.Errorf("safesearch: unsupported question type %s", dns.Type(qtype)))
}
}
// fitToProto returns a non-nil IP address if ip is the correct protocol version
// for qtype. qtype is expected to be either [dns.TypeA] or [dns.TypeAAAA].
func fitToProto(ip net.IP, qtype rules.RRType) (res net.IP) {
ip4 := ip.To4()
if qtype == dns.TypeA {
return ip4
}
if ip4 == nil {
return ip
}
return nil
}
// setCacheResult stores data in cache for host. qtype is expected to be either
// [dns.TypeA] or [dns.TypeAAAA].
func (ss *Default) setCacheResult(host string, qtype rules.RRType, res filtering.Result) {
expire := uint32(time.Now().Add(ss.cacheTTL).Unix()) </s> remove ips, err := ss.resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME)
</s> add ss.log(log.DEBUG, "resolving %q", host)
ips, err := ss.resolver.LookupIP(context.Background(), qtypeToProto(qtype), host) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch.go |
host := rewrite.NewCNAME
if host == "" { | <mask>
<mask> return res, nil
<mask> }
<mask>
<mask> if rewrite.NewCNAME == "" {
<mask> return nil, nil
<mask> }
<mask>
<mask> ips, err := ss.resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME)
<mask> if err != nil {
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove ips, err := ss.resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME)
</s> add ss.log(log.DEBUG, "resolving %q", host)
ips, err := ss.resolver.LookupIP(context.Background(), qtypeToProto(qtype), host) </s> remove var foundIP net.IP
for _, ip := range ips {
if ip.To4() != nil {
foundIP = ip
break
}
}
res, err = ss.CheckHost(domain, dns.TypeA)
</s> add res, err = ss.CheckHost("www.yandex.com", testQType) </s> remove resolver := &aghtest.TestResolver{}
ss = newForTest(t, defaultSafeSearchConf)
ss.resolver = resolver
// Lookup for safesearch domain.
rewrite := ss.SearchHost(domain, dns.TypeA)
ips, err := resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME)
</s> add err = ss.Update(filtering.SafeSearchConfig{
Enabled: false,
Google: true,
}) </s> remove dRes, err := ss.newResult(rewrite, qtype)
</s> add fltRes, err := ss.newResult(rewrite, qtype) </s> remove if rewrite.RRType == qtype && (qtype == dns.TypeA || qtype == dns.TypeAAAA) {
</s> add if rewrite.RRType == qtype { | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch.go |
ss.log(log.DEBUG, "resolving %q", host)
ips, err := ss.resolver.LookupIP(context.Background(), qtypeToProto(qtype), host) | <mask> if rewrite.NewCNAME == "" {
<mask> return nil, nil
<mask> }
<mask>
<mask> ips, err := ss.resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME)
<mask> if err != nil {
<mask> return nil, err
<mask> }
<mask>
<mask> for _, ip := range ips {
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove if rewrite.NewCNAME == "" {
</s> add host := rewrite.NewCNAME
if host == "" { </s> remove var foundIP net.IP
for _, ip := range ips {
if ip.To4() != nil {
foundIP = ip
break
}
}
res, err = ss.CheckHost(domain, dns.TypeA)
</s> add res, err = ss.CheckHost("www.yandex.com", testQType) </s> remove if ip = ip.To4(); ip == nil {
</s> add // TODO(a.garipov): Remove this filtering once the resolver we use
// actually learns about network.
ip = fitToProto(ip, qtype)
if ip == nil { </s> remove resolver := &aghtest.TestResolver{}
ss = newForTest(t, defaultSafeSearchConf)
ss.resolver = resolver
// Lookup for safesearch domain.
rewrite := ss.SearchHost(domain, dns.TypeA)
ips, err := resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME)
</s> add err = ss.Update(filtering.SafeSearchConfig{
Enabled: false,
Google: true,
}) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch.go |
ss.log(log.DEBUG, "resolved %s", ips)
| <mask> if err != nil {
<mask> return nil, err
<mask> }
<mask>
<mask> for _, ip := range ips {
<mask> // TODO(a.garipov): Remove this filtering once the resolver we use
<mask> // actually learns about network.
<mask> ip = fitToProto(ip, qtype)
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove if ip = ip.To4(); ip == nil {
</s> add // TODO(a.garipov): Remove this filtering once the resolver we use
// actually learns about network.
ip = fitToProto(ip, qtype)
if ip == nil { </s> remove ips, err := ss.resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME)
</s> add ss.log(log.DEBUG, "resolving %q", host)
ips, err := ss.resolver.LookupIP(context.Background(), qtypeToProto(qtype), host) </s> remove var foundIP net.IP
for _, ip := range ips {
if ip.To4() != nil {
foundIP = ip
break
}
}
res, err = ss.CheckHost(domain, dns.TypeA)
</s> add res, err = ss.CheckHost("www.yandex.com", testQType) </s> remove resolver := &aghtest.TestResolver{}
ss = newForTest(t, defaultSafeSearchConf)
ss.resolver = resolver
// Lookup for safesearch domain.
rewrite := ss.SearchHost(domain, dns.TypeA)
ips, err := resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME)
</s> add err = ss.Update(filtering.SafeSearchConfig{
Enabled: false,
Google: true,
}) | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch.go |
// TODO(a.garipov): Remove this filtering once the resolver we use
// actually learns about network.
ip = fitToProto(ip, qtype)
if ip == nil { | <mask> return nil, err
<mask> }
<mask>
<mask> for _, ip := range ips {
<mask> if ip = ip.To4(); ip == nil {
<mask> continue
<mask> }
<mask>
<mask> res.Rules[0].IP = ip
<mask>
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove ips, err := ss.resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME)
</s> add ss.log(log.DEBUG, "resolving %q", host)
ips, err := ss.resolver.LookupIP(context.Background(), qtypeToProto(qtype), host) </s> remove var foundIP net.IP
for _, ip := range ips {
if ip.To4() != nil {
foundIP = ip
break
}
}
res, err = ss.CheckHost(domain, dns.TypeA)
</s> add res, err = ss.CheckHost("www.yandex.com", testQType) </s> remove if rewrite.RRType == qtype && (qtype == dns.TypeA || qtype == dns.TypeAAAA) {
</s> add if rewrite.RRType == qtype { </s> remove resolver := &aghtest.TestResolver{}
ss = newForTest(t, defaultSafeSearchConf)
ss.resolver = resolver
// Lookup for safesearch domain.
rewrite := ss.SearchHost(domain, dns.TypeA)
ips, err := resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME)
</s> add err = ss.Update(filtering.SafeSearchConfig{
Enabled: false,
Google: true,
}) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch.go |
// qtypeToProto returns "ip4" for [dns.TypeA] and "ip6" for [dns.TypeAAAA].
// It panics for other types.
func qtypeToProto(qtype rules.RRType) (proto string) {
switch qtype {
case dns.TypeA:
return "ip4"
case dns.TypeAAAA:
return "ip6"
default:
panic(fmt.Errorf("safesearch: unsupported question type %s", dns.Type(qtype)))
}
}
// fitToProto returns a non-nil IP address if ip is the correct protocol version
// for qtype. qtype is expected to be either [dns.TypeA] or [dns.TypeAAAA].
func fitToProto(ip net.IP, qtype rules.RRType) (res net.IP) {
ip4 := ip.To4()
if qtype == dns.TypeA {
return ip4
}
if ip4 == nil {
return ip
}
return nil
}
// setCacheResult stores data in cache for host. qtype is expected to be either
// [dns.TypeA] or [dns.TypeAAAA].
func (ss *Default) setCacheResult(host string, qtype rules.RRType, res filtering.Result) {
expire := uint32(time.Now().Add(ss.cacheTTL).Unix()) | <mask>
<mask> return nil, nil
<mask> }
<mask>
<mask> // setCacheResult stores data in cache for host.
<mask> func (ss *DefaultSafeSearch) setCacheResult(host string, res filtering.Result) {
<mask> expire := uint32(time.Now().Add(ss.cacheTime).Unix())
<mask> exp := make([]byte, 4)
<mask> binary.BigEndian.PutUint32(exp, expire)
<mask> buf := bytes.NewBuffer(exp)
<mask>
<mask> err := gob.NewEncoder(buf).Encode(res)
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove data := ss.safeSearchCache.Get([]byte(host))
</s> add data := ss.cache.Get([]byte(dns.Type(qtype).String() + " " + host)) </s> remove log.Error("safesearch: cache encoding: %s", err)
</s> add ss.log(log.ERROR, "cache encoding: %s", err) </s> remove // getCachedResult returns stored data from cache for host.
func (ss *DefaultSafeSearch) getCachedResult(host string) (res filtering.Result, ok bool) {
</s> add // getCachedResult returns stored data from cache for host. qtype is expected
// to be either [dns.TypeA] or [dns.TypeAAAA].
func (ss *Default) getCachedResult(
host string,
qtype rules.RRType,
) (res filtering.Result, ok bool) { </s> remove log.Debug("safesearch: stored in cache: %s (%d bytes)", host, len(val))
</s> add ss.log(log.DEBUG, "stored in cache: %q, %d bytes", host, len(val)) </s> remove ss.safeSearchCache.Del([]byte(host))
</s> add ss.cache.Del([]byte(host)) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch.go |
ss.log(log.ERROR, "cache encoding: %s", err) | <mask> buf := bytes.NewBuffer(exp)
<mask>
<mask> err := gob.NewEncoder(buf).Encode(res)
<mask> if err != nil {
<mask> log.Error("safesearch: cache encoding: %s", err)
<mask>
<mask> return
<mask> }
<mask>
<mask> val := buf.Bytes()
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove log.Debug("safesearch: cache decoding: %s", err)
</s> add ss.log(log.ERROR, "cache decoding: %s", err) </s> remove // setCacheResult stores data in cache for host.
func (ss *DefaultSafeSearch) setCacheResult(host string, res filtering.Result) {
expire := uint32(time.Now().Add(ss.cacheTime).Unix())
</s> add // qtypeToProto returns "ip4" for [dns.TypeA] and "ip6" for [dns.TypeAAAA].
// It panics for other types.
func qtypeToProto(qtype rules.RRType) (proto string) {
switch qtype {
case dns.TypeA:
return "ip4"
case dns.TypeAAAA:
return "ip6"
default:
panic(fmt.Errorf("safesearch: unsupported question type %s", dns.Type(qtype)))
}
}
// fitToProto returns a non-nil IP address if ip is the correct protocol version
// for qtype. qtype is expected to be either [dns.TypeA] or [dns.TypeAAAA].
func fitToProto(ip net.IP, qtype rules.RRType) (res net.IP) {
ip4 := ip.To4()
if qtype == dns.TypeA {
return ip4
}
if ip4 == nil {
return ip
}
return nil
}
// setCacheResult stores data in cache for host. qtype is expected to be either
// [dns.TypeA] or [dns.TypeAAAA].
func (ss *Default) setCacheResult(host string, qtype rules.RRType, res filtering.Result) {
expire := uint32(time.Now().Add(ss.cacheTTL).Unix()) </s> remove dRes, err := ss.newResult(rewrite, qtype)
</s> add fltRes, err := ss.newResult(rewrite, qtype) </s> remove c := jsonToClient(cj)
</s> add c, err := clients.jsonToClient(cj)
if err != nil {
aghhttp.Error(r, w, http.StatusBadRequest, "%s", err)
return
}
</s> remove _ = ss.safeSearchCache.Set([]byte(host), val)
</s> add _ = ss.cache.Set([]byte(dns.Type(qtype).String()+" "+host), val) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch.go |
_ = ss.cache.Set([]byte(dns.Type(qtype).String()+" "+host), val) | <mask> return
<mask> }
<mask>
<mask> val := buf.Bytes()
<mask> _ = ss.safeSearchCache.Set([]byte(host), val)
<mask>
<mask> log.Debug("safesearch: stored in cache: %s (%d bytes)", host, len(val))
<mask> }
<mask>
<mask> // getCachedResult returns stored data from cache for host.
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove log.Debug("safesearch: stored in cache: %s (%d bytes)", host, len(val))
</s> add ss.log(log.DEBUG, "stored in cache: %q, %d bytes", host, len(val)) </s> remove // getCachedResult returns stored data from cache for host.
func (ss *DefaultSafeSearch) getCachedResult(host string) (res filtering.Result, ok bool) {
</s> add // getCachedResult returns stored data from cache for host. qtype is expected
// to be either [dns.TypeA] or [dns.TypeAAAA].
func (ss *Default) getCachedResult(
host string,
qtype rules.RRType,
) (res filtering.Result, ok bool) { </s> remove data := ss.safeSearchCache.Get([]byte(host))
</s> add data := ss.cache.Get([]byte(dns.Type(qtype).String() + " " + host)) </s> remove log.Error("safesearch: cache encoding: %s", err)
</s> add ss.log(log.ERROR, "cache encoding: %s", err) </s> remove // setCacheResult stores data in cache for host.
func (ss *DefaultSafeSearch) setCacheResult(host string, res filtering.Result) {
expire := uint32(time.Now().Add(ss.cacheTime).Unix())
</s> add // qtypeToProto returns "ip4" for [dns.TypeA] and "ip6" for [dns.TypeAAAA].
// It panics for other types.
func qtypeToProto(qtype rules.RRType) (proto string) {
switch qtype {
case dns.TypeA:
return "ip4"
case dns.TypeAAAA:
return "ip6"
default:
panic(fmt.Errorf("safesearch: unsupported question type %s", dns.Type(qtype)))
}
}
// fitToProto returns a non-nil IP address if ip is the correct protocol version
// for qtype. qtype is expected to be either [dns.TypeA] or [dns.TypeAAAA].
func fitToProto(ip net.IP, qtype rules.RRType) (res net.IP) {
ip4 := ip.To4()
if qtype == dns.TypeA {
return ip4
}
if ip4 == nil {
return ip
}
return nil
}
// setCacheResult stores data in cache for host. qtype is expected to be either
// [dns.TypeA] or [dns.TypeAAAA].
func (ss *Default) setCacheResult(host string, qtype rules.RRType, res filtering.Result) {
expire := uint32(time.Now().Add(ss.cacheTTL).Unix()) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch.go |
ss.log(log.DEBUG, "stored in cache: %q, %d bytes", host, len(val)) | <mask>
<mask> val := buf.Bytes()
<mask> _ = ss.safeSearchCache.Set([]byte(host), val)
<mask>
<mask> log.Debug("safesearch: stored in cache: %s (%d bytes)", host, len(val))
<mask> }
<mask>
<mask> // getCachedResult returns stored data from cache for host.
<mask> func (ss *DefaultSafeSearch) getCachedResult(host string) (res filtering.Result, ok bool) {
<mask> res = filtering.Result{}
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove _ = ss.safeSearchCache.Set([]byte(host), val)
</s> add _ = ss.cache.Set([]byte(dns.Type(qtype).String()+" "+host), val) </s> remove // getCachedResult returns stored data from cache for host.
func (ss *DefaultSafeSearch) getCachedResult(host string) (res filtering.Result, ok bool) {
</s> add // getCachedResult returns stored data from cache for host. qtype is expected
// to be either [dns.TypeA] or [dns.TypeAAAA].
func (ss *Default) getCachedResult(
host string,
qtype rules.RRType,
) (res filtering.Result, ok bool) { </s> remove data := ss.safeSearchCache.Get([]byte(host))
</s> add data := ss.cache.Get([]byte(dns.Type(qtype).String() + " " + host)) </s> remove // setCacheResult stores data in cache for host.
func (ss *DefaultSafeSearch) setCacheResult(host string, res filtering.Result) {
expire := uint32(time.Now().Add(ss.cacheTime).Unix())
</s> add // qtypeToProto returns "ip4" for [dns.TypeA] and "ip6" for [dns.TypeAAAA].
// It panics for other types.
func qtypeToProto(qtype rules.RRType) (proto string) {
switch qtype {
case dns.TypeA:
return "ip4"
case dns.TypeAAAA:
return "ip6"
default:
panic(fmt.Errorf("safesearch: unsupported question type %s", dns.Type(qtype)))
}
}
// fitToProto returns a non-nil IP address if ip is the correct protocol version
// for qtype. qtype is expected to be either [dns.TypeA] or [dns.TypeAAAA].
func fitToProto(ip net.IP, qtype rules.RRType) (res net.IP) {
ip4 := ip.To4()
if qtype == dns.TypeA {
return ip4
}
if ip4 == nil {
return ip
}
return nil
}
// setCacheResult stores data in cache for host. qtype is expected to be either
// [dns.TypeA] or [dns.TypeAAAA].
func (ss *Default) setCacheResult(host string, qtype rules.RRType, res filtering.Result) {
expire := uint32(time.Now().Add(ss.cacheTTL).Unix()) </s> remove // newResult creates Result object from rewrite rule.
func (ss *DefaultSafeSearch) newResult(
</s> add // searchHost looks up DNS rewrites in the internal DNS filtering engine.
func (ss *Default) searchHost(host string, qtype rules.RRType) (res *rules.DNSRewrite) {
ss.mu.RLock()
defer ss.mu.RUnlock()
if ss.engine == nil {
return nil
}
r, _ := ss.engine.MatchRequest(&urlfilter.DNSRequest{
Hostname: strings.ToLower(host),
DNSType: qtype,
})
rewritesRules := r.DNSRewrites()
if len(rewritesRules) > 0 {
return rewritesRules[0].DNSRewrite
}
return nil
}
// newResult creates Result object from rewrite rule. qtype must be either
// [dns.TypeA] or [dns.TypeAAAA].
func (ss *Default) newResult( | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch.go |
// getCachedResult returns stored data from cache for host. qtype is expected
// to be either [dns.TypeA] or [dns.TypeAAAA].
func (ss *Default) getCachedResult(
host string,
qtype rules.RRType,
) (res filtering.Result, ok bool) { | <mask>
<mask> log.Debug("safesearch: stored in cache: %s (%d bytes)", host, len(val))
<mask> }
<mask>
<mask> // getCachedResult returns stored data from cache for host.
<mask> func (ss *DefaultSafeSearch) getCachedResult(host string) (res filtering.Result, ok bool) {
<mask> res = filtering.Result{}
<mask>
<mask> data := ss.safeSearchCache.Get([]byte(host))
<mask> if data == nil {
<mask> return res, false
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove log.Debug("safesearch: stored in cache: %s (%d bytes)", host, len(val))
</s> add ss.log(log.DEBUG, "stored in cache: %q, %d bytes", host, len(val)) </s> remove data := ss.safeSearchCache.Get([]byte(host))
</s> add data := ss.cache.Get([]byte(dns.Type(qtype).String() + " " + host)) </s> remove _ = ss.safeSearchCache.Set([]byte(host), val)
</s> add _ = ss.cache.Set([]byte(dns.Type(qtype).String()+" "+host), val) </s> remove // setCacheResult stores data in cache for host.
func (ss *DefaultSafeSearch) setCacheResult(host string, res filtering.Result) {
expire := uint32(time.Now().Add(ss.cacheTime).Unix())
</s> add // qtypeToProto returns "ip4" for [dns.TypeA] and "ip6" for [dns.TypeAAAA].
// It panics for other types.
func qtypeToProto(qtype rules.RRType) (proto string) {
switch qtype {
case dns.TypeA:
return "ip4"
case dns.TypeAAAA:
return "ip6"
default:
panic(fmt.Errorf("safesearch: unsupported question type %s", dns.Type(qtype)))
}
}
// fitToProto returns a non-nil IP address if ip is the correct protocol version
// for qtype. qtype is expected to be either [dns.TypeA] or [dns.TypeAAAA].
func fitToProto(ip net.IP, qtype rules.RRType) (res net.IP) {
ip4 := ip.To4()
if qtype == dns.TypeA {
return ip4
}
if ip4 == nil {
return ip
}
return nil
}
// setCacheResult stores data in cache for host. qtype is expected to be either
// [dns.TypeA] or [dns.TypeAAAA].
func (ss *Default) setCacheResult(host string, qtype rules.RRType, res filtering.Result) {
expire := uint32(time.Now().Add(ss.cacheTTL).Unix()) </s> remove // newResult creates Result object from rewrite rule.
func (ss *DefaultSafeSearch) newResult(
</s> add // searchHost looks up DNS rewrites in the internal DNS filtering engine.
func (ss *Default) searchHost(host string, qtype rules.RRType) (res *rules.DNSRewrite) {
ss.mu.RLock()
defer ss.mu.RUnlock()
if ss.engine == nil {
return nil
}
r, _ := ss.engine.MatchRequest(&urlfilter.DNSRequest{
Hostname: strings.ToLower(host),
DNSType: qtype,
})
rewritesRules := r.DNSRewrites()
if len(rewritesRules) > 0 {
return rewritesRules[0].DNSRewrite
}
return nil
}
// newResult creates Result object from rewrite rule. qtype must be either
// [dns.TypeA] or [dns.TypeAAAA].
func (ss *Default) newResult( | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch.go |
data := ss.cache.Get([]byte(dns.Type(qtype).String() + " " + host)) | <mask> // getCachedResult returns stored data from cache for host.
<mask> func (ss *DefaultSafeSearch) getCachedResult(host string) (res filtering.Result, ok bool) {
<mask> res = filtering.Result{}
<mask>
<mask> data := ss.safeSearchCache.Get([]byte(host))
<mask> if data == nil {
<mask> return res, false
<mask> }
<mask>
<mask> exp := binary.BigEndian.Uint32(data[:4])
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove // getCachedResult returns stored data from cache for host.
func (ss *DefaultSafeSearch) getCachedResult(host string) (res filtering.Result, ok bool) {
</s> add // getCachedResult returns stored data from cache for host. qtype is expected
// to be either [dns.TypeA] or [dns.TypeAAAA].
func (ss *Default) getCachedResult(
host string,
qtype rules.RRType,
) (res filtering.Result, ok bool) { </s> remove log.Debug("safesearch: stored in cache: %s (%d bytes)", host, len(val))
</s> add ss.log(log.DEBUG, "stored in cache: %q, %d bytes", host, len(val)) </s> remove _ = ss.safeSearchCache.Set([]byte(host), val)
</s> add _ = ss.cache.Set([]byte(dns.Type(qtype).String()+" "+host), val) </s> remove // setCacheResult stores data in cache for host.
func (ss *DefaultSafeSearch) setCacheResult(host string, res filtering.Result) {
expire := uint32(time.Now().Add(ss.cacheTime).Unix())
</s> add // qtypeToProto returns "ip4" for [dns.TypeA] and "ip6" for [dns.TypeAAAA].
// It panics for other types.
func qtypeToProto(qtype rules.RRType) (proto string) {
switch qtype {
case dns.TypeA:
return "ip4"
case dns.TypeAAAA:
return "ip6"
default:
panic(fmt.Errorf("safesearch: unsupported question type %s", dns.Type(qtype)))
}
}
// fitToProto returns a non-nil IP address if ip is the correct protocol version
// for qtype. qtype is expected to be either [dns.TypeA] or [dns.TypeAAAA].
func fitToProto(ip net.IP, qtype rules.RRType) (res net.IP) {
ip4 := ip.To4()
if qtype == dns.TypeA {
return ip4
}
if ip4 == nil {
return ip
}
return nil
}
// setCacheResult stores data in cache for host. qtype is expected to be either
// [dns.TypeA] or [dns.TypeAAAA].
func (ss *Default) setCacheResult(host string, qtype rules.RRType, res filtering.Result) {
expire := uint32(time.Now().Add(ss.cacheTTL).Unix()) </s> remove ss.safeSearchCache.Del([]byte(host))
</s> add ss.cache.Del([]byte(host)) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch.go |
ss.cache.Del([]byte(host)) | <mask> }
<mask>
<mask> exp := binary.BigEndian.Uint32(data[:4])
<mask> if exp <= uint32(time.Now().Unix()) {
<mask> ss.safeSearchCache.Del([]byte(host))
<mask>
<mask> return res, false
<mask> }
<mask>
<mask> buf := bytes.NewBuffer(data[4:])
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove data := ss.safeSearchCache.Get([]byte(host))
</s> add data := ss.cache.Get([]byte(dns.Type(qtype).String() + " " + host)) </s> remove log.Debug("safesearch: cache decoding: %s", err)
</s> add ss.log(log.ERROR, "cache decoding: %s", err) </s> remove // setCacheResult stores data in cache for host.
func (ss *DefaultSafeSearch) setCacheResult(host string, res filtering.Result) {
expire := uint32(time.Now().Add(ss.cacheTime).Unix())
</s> add // qtypeToProto returns "ip4" for [dns.TypeA] and "ip6" for [dns.TypeAAAA].
// It panics for other types.
func qtypeToProto(qtype rules.RRType) (proto string) {
switch qtype {
case dns.TypeA:
return "ip4"
case dns.TypeAAAA:
return "ip6"
default:
panic(fmt.Errorf("safesearch: unsupported question type %s", dns.Type(qtype)))
}
}
// fitToProto returns a non-nil IP address if ip is the correct protocol version
// for qtype. qtype is expected to be either [dns.TypeA] or [dns.TypeAAAA].
func fitToProto(ip net.IP, qtype rules.RRType) (res net.IP) {
ip4 := ip.To4()
if qtype == dns.TypeA {
return ip4
}
if ip4 == nil {
return ip
}
return nil
}
// setCacheResult stores data in cache for host. qtype is expected to be either
// [dns.TypeA] or [dns.TypeAAAA].
func (ss *Default) setCacheResult(host string, qtype rules.RRType, res filtering.Result) {
expire := uint32(time.Now().Add(ss.cacheTTL).Unix()) </s> remove log.Error("safesearch: cache encoding: %s", err)
</s> add ss.log(log.ERROR, "cache encoding: %s", err) </s> remove if rewrite.NewCNAME == "" {
</s> add host := rewrite.NewCNAME
if host == "" { | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch.go |
ss.log(log.ERROR, "cache decoding: %s", err) | <mask> buf := bytes.NewBuffer(data[4:])
<mask>
<mask> err := gob.NewDecoder(buf).Decode(&res)
<mask> if err != nil {
<mask> log.Debug("safesearch: cache decoding: %s", err)
<mask>
<mask> return filtering.Result{}, false
<mask> }
<mask>
<mask> return res, true
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove ss.safeSearchCache.Del([]byte(host))
</s> add ss.cache.Del([]byte(host)) </s> remove log.Error("safesearch: cache encoding: %s", err)
</s> add ss.log(log.ERROR, "cache encoding: %s", err) </s> remove dRes, err := ss.newResult(rewrite, qtype)
</s> add fltRes, err := ss.newResult(rewrite, qtype) </s> remove log.Debug("safesearch: failed to lookup addresses for %s: %s", host, err)
</s> add ss.log(log.DEBUG, "looking up addresses for %q: %s", host, err) </s> remove if dRes != nil {
res = *dRes
ss.setCacheResult(host, res)
</s> add if fltRes != nil {
res = *fltRes
ss.setCacheResult(host, qtype, res) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch.go |
package safesearch_test | <mask> package safesearch
<mask>
<mask> import (
<mask> "context"
<mask> "net"
<mask> "testing"
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove "context"
</s> add </s> remove import (
"github.com/AdguardTeam/urlfilter/rules"
"github.com/miekg/dns"
)
</s> add import "github.com/miekg/dns" | [
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch_test.go |
<mask> package safesearch
<mask>
<mask> import (
<mask> "context"
<mask> "net"
<mask> "testing"
<mask> "time"
<mask>
<mask> "github.com/AdguardTeam/AdGuardHome/internal/aghtest"
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove package safesearch
</s> add package safesearch_test </s> remove import (
"github.com/AdguardTeam/urlfilter/rules"
"github.com/miekg/dns"
)
</s> add import "github.com/miekg/dns" </s> remove "github.com/AdguardTeam/urlfilter/rules"
</s> add "github.com/AdguardTeam/AdGuardHome/internal/filtering/safesearch"
"github.com/AdguardTeam/golibs/testutil" | [
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch_test.go |
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering/safesearch"
"github.com/AdguardTeam/golibs/testutil" | <mask> "time"
<mask>
<mask> "github.com/AdguardTeam/AdGuardHome/internal/aghtest"
<mask> "github.com/AdguardTeam/AdGuardHome/internal/filtering"
<mask> "github.com/AdguardTeam/urlfilter/rules"
<mask> "github.com/miekg/dns"
<mask> "github.com/stretchr/testify/assert"
<mask> "github.com/stretchr/testify/require"
<mask> )
<mask>
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove "context"
</s> add </s> remove import (
"github.com/AdguardTeam/urlfilter/rules"
"github.com/miekg/dns"
)
</s> add import "github.com/miekg/dns" | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch_test.go |
func TestMain(m *testing.M) {
testutil.DiscardLogOutput(m)
}
// Common test constants. | <mask> "github.com/stretchr/testify/assert"
<mask> "github.com/stretchr/testify/require"
<mask> )
<mask>
<mask> const (
<mask> // TODO(a.garipov): Add IPv6 tests.
<mask> testQType = dns.TypeA
<mask> testCacheSize = 5000
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove safeSearchCacheSize = 5000
cacheTime = 30 * time.Minute
</s> add // TODO(a.garipov): Add IPv6 tests.
testQType = dns.TypeA
testCacheSize = 5000
testCacheTTL = 30 * time.Minute </s> remove func TestClients(t *testing.T) {
clients := clientsContainer{}
clients.testing = true
</s> add // newClientsContainer is a helper that creates a new clients container for
// tests.
func newClientsContainer() (c *clientsContainer) {
c = &clientsContainer{
testing: true,
}
c.Init(nil, nil, nil, nil, &filtering.Config{}) </s> remove "github.com/AdguardTeam/urlfilter/rules"
</s> add "github.com/AdguardTeam/AdGuardHome/internal/filtering/safesearch"
"github.com/AdguardTeam/golibs/testutil" </s> remove var defaultSafeSearchConf = filtering.SafeSearchConfig{
Enabled: true,
</s> add // testConf is the default safe search configuration for tests.
var testConf = filtering.SafeSearchConfig{
CustomResolver: nil,
Enabled: true,
| [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch_test.go |
// TODO(a.garipov): Add IPv6 tests.
testQType = dns.TypeA
testCacheSize = 5000
testCacheTTL = 30 * time.Minute | <mask> "github.com/stretchr/testify/require"
<mask> )
<mask>
<mask> const (
<mask> safeSearchCacheSize = 5000
<mask> cacheTime = 30 * time.Minute
<mask> )
<mask>
<mask> var defaultSafeSearchConf = filtering.SafeSearchConfig{
<mask> Enabled: true,
<mask> Bing: true,
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove var defaultSafeSearchConf = filtering.SafeSearchConfig{
Enabled: true,
</s> add // testConf is the default safe search configuration for tests.
var testConf = filtering.SafeSearchConfig{
CustomResolver: nil,
Enabled: true,
</s> remove func TestClients(t *testing.T) {
clients := clientsContainer{}
clients.testing = true
</s> add // newClientsContainer is a helper that creates a new clients container for
// tests.
func newClientsContainer() (c *clientsContainer) {
c = &clientsContainer{
testing: true,
}
c.Init(nil, nil, nil, nil, &filtering.Config{}) </s> remove assert.Equal(t, res.Rules[0].IP, yandexIP)
// Check cache.
cachedValue, isFound := ss.getCachedResult(domain)
require.True(t, isFound)
require.Len(t, cachedValue.Rules, 1)
assert.Equal(t, cachedValue.Rules[0].IP, yandexIP)
}
func TestSafeSearchCacheGoogle(t *testing.T) {
const domain = "www.google.ru"
ss := newForTest(t, filtering.SafeSearchConfig{Enabled: false})
</s> add err = ss.Update(filtering.SafeSearchConfig{
Enabled: true,
Google: false,
})
require.NoError(t, err) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch_test.go |
// testConf is the default safe search configuration for tests.
var testConf = filtering.SafeSearchConfig{
CustomResolver: nil,
Enabled: true,
| <mask> safeSearchCacheSize = 5000
<mask> cacheTime = 30 * time.Minute
<mask> )
<mask>
<mask> var defaultSafeSearchConf = filtering.SafeSearchConfig{
<mask> Enabled: true,
<mask> Bing: true,
<mask> DuckDuckGo: true,
<mask> Google: true,
<mask> Pixabay: true,
<mask> Yandex: true,
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove safeSearchCacheSize = 5000
cacheTime = 30 * time.Minute
</s> add // TODO(a.garipov): Add IPv6 tests.
testQType = dns.TypeA
testCacheSize = 5000
testCacheTTL = 30 * time.Minute </s> remove resolver := &aghtest.TestResolver{}
ss = newForTest(t, defaultSafeSearchConf)
ss.resolver = resolver
// Lookup for safesearch domain.
rewrite := ss.SearchHost(domain, dns.TypeA)
ips, err := resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME)
</s> add err = ss.Update(filtering.SafeSearchConfig{
Enabled: false,
Google: true,
}) </s> remove assert.Equal(t, res.Rules[0].IP, yandexIP)
// Check cache.
cachedValue, isFound := ss.getCachedResult(domain)
require.True(t, isFound)
require.Len(t, cachedValue.Rules, 1)
assert.Equal(t, cachedValue.Rules[0].IP, yandexIP)
}
func TestSafeSearchCacheGoogle(t *testing.T) {
const domain = "www.google.ru"
ss := newForTest(t, filtering.SafeSearchConfig{Enabled: false})
</s> add err = ss.Update(filtering.SafeSearchConfig{
Enabled: true,
Google: false,
})
require.NoError(t, err) </s> remove clients := clientsContainer{
testing: true,
}
clients.Init(nil, nil, nil, nil, nil)
</s> add clients := newClientsContainer() | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch_test.go |
// yandexIP is the expected IP address of Yandex safe search results. Keep in
// sync with the rules data. | <mask> YouTube: true,
<mask> }
<mask>
<mask> var yandexIP = net.IPv4(213, 180, 193, 56)
<mask>
<mask> func TestDefault_CheckHost_yandex(t *testing.T) {
<mask> conf := testConf
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove func newForTest(t testing.TB, ssConf filtering.SafeSearchConfig) (ss *DefaultSafeSearch) {
ss, err := NewDefaultSafeSearch(ssConf, safeSearchCacheSize, cacheTime)
</s> add func TestDefault_CheckHost_yandex(t *testing.T) {
conf := testConf
ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL) </s> remove func TestSafeSearchCacheYandex(t *testing.T) {
const domain = "yandex.ru"
ss := newForTest(t, filtering.SafeSearchConfig{Enabled: false})
// Check host with disabled safesearch.
res, err := ss.CheckHost(domain, dns.TypeA)
</s> add func TestDefault_Update(t *testing.T) {
conf := testConf
ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL) </s> remove var defaultSafeSearchConf = filtering.SafeSearchConfig{
Enabled: true,
</s> add // testConf is the default safe search configuration for tests.
var testConf = filtering.SafeSearchConfig{
CustomResolver: nil,
Enabled: true,
</s> remove clients := clientsContainer{
testing: true,
}
clients.Init(nil, nil, nil, nil, nil)
</s> add clients := newClientsContainer() </s> remove ss := newForTest(t, defaultSafeSearchConf)
ss.resolver = resolver
</s> add conf := testConf
conf.CustomResolver = resolver
ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL)
require.NoError(t, err) | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch_test.go |
func TestDefault_CheckHost_yandex(t *testing.T) {
conf := testConf
ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL) | <mask> }
<mask>
<mask> var yandexIP = net.IPv4(213, 180, 193, 56)
<mask>
<mask> func newForTest(t testing.TB, ssConf filtering.SafeSearchConfig) (ss *DefaultSafeSearch) {
<mask> ss, err := NewDefaultSafeSearch(ssConf, safeSearchCacheSize, cacheTime)
<mask> require.NoError(t, err)
<mask>
<mask> return ss
<mask> }
<mask>
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove return ss
}
func TestSafeSearch(t *testing.T) {
ss := newForTest(t, defaultSafeSearchConf)
val := ss.SearchHost("www.google.com", dns.TypeA)
assert.Equal(t, &rules.DNSRewrite{NewCNAME: "forcesafesearch.google.com"}, val)
}
func TestCheckHostSafeSearchYandex(t *testing.T) {
ss := newForTest(t, defaultSafeSearchConf)
</s> add </s> remove func TestSafeSearchCacheYandex(t *testing.T) {
const domain = "yandex.ru"
ss := newForTest(t, filtering.SafeSearchConfig{Enabled: false})
// Check host with disabled safesearch.
res, err := ss.CheckHost(domain, dns.TypeA)
</s> add func TestDefault_Update(t *testing.T) {
conf := testConf
ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL) </s> remove require.Len(t, res.Rules, 1)
assert.True(t, res.Rules[0].IP.Equal(foundIP))
// Check cache.
cachedValue, isFound := ss.getCachedResult(domain)
require.True(t, isFound)
require.Len(t, cachedValue.Rules, 1)
assert.True(t, cachedValue.Rules[0].IP.Equal(foundIP))
}
const googleHost = "www.google.com"
</s> add </s> remove var foundIP net.IP
for _, ip := range ips {
if ip.To4() != nil {
foundIP = ip
break
}
}
res, err = ss.CheckHost(domain, dns.TypeA)
</s> add res, err = ss.CheckHost("www.yandex.com", testQType) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch_test.go |
<mask> func newForTest(t testing.TB, ssConf filtering.SafeSearchConfig) (ss *DefaultSafeSearch) {
<mask> ss, err := NewDefaultSafeSearch(ssConf, safeSearchCacheSize, cacheTime)
<mask> require.NoError(t, err)
<mask>
<mask> return ss
<mask> }
<mask>
<mask> func TestSafeSearch(t *testing.T) {
<mask> ss := newForTest(t, defaultSafeSearchConf)
<mask> val := ss.SearchHost("www.google.com", dns.TypeA)
<mask>
<mask> assert.Equal(t, &rules.DNSRewrite{NewCNAME: "forcesafesearch.google.com"}, val)
<mask> }
<mask>
<mask> func TestCheckHostSafeSearchYandex(t *testing.T) {
<mask> ss := newForTest(t, defaultSafeSearchConf)
<mask>
<mask> // Check host for each domain.
<mask> for _, host := range []string{
<mask> "yandex.ru",
<mask> "yAndeX.ru",
<mask> "YANdex.COM",
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove func newForTest(t testing.TB, ssConf filtering.SafeSearchConfig) (ss *DefaultSafeSearch) {
ss, err := NewDefaultSafeSearch(ssConf, safeSearchCacheSize, cacheTime)
</s> add func TestDefault_CheckHost_yandex(t *testing.T) {
conf := testConf
ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL) </s> remove ss := newForTest(t, defaultSafeSearchConf)
ss.resolver = resolver
</s> add conf := testConf
conf.CustomResolver = resolver
ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL)
require.NoError(t, err) </s> remove func TestSafeSearchCacheYandex(t *testing.T) {
const domain = "yandex.ru"
ss := newForTest(t, filtering.SafeSearchConfig{Enabled: false})
// Check host with disabled safesearch.
res, err := ss.CheckHost(domain, dns.TypeA)
</s> add func TestDefault_Update(t *testing.T) {
conf := testConf
ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL) </s> remove func TestCheckHostSafeSearchGoogle(t *testing.T) {
</s> add func TestDefault_CheckHost_google(t *testing.T) { </s> remove resolver := &aghtest.TestResolver{}
ss = newForTest(t, defaultSafeSearchConf)
ss.resolver = resolver
// Lookup for safesearch domain.
rewrite := ss.SearchHost(domain, dns.TypeA)
ips, err := resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME)
</s> add err = ss.Update(filtering.SafeSearchConfig{
Enabled: false,
Google: true,
}) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch_test.go |
|
var res filtering.Result
res, err = ss.CheckHost(host, testQType) | <mask> "yandex.by",
<mask> "yandex.kz",
<mask> "www.yandex.com",
<mask> } {
<mask> res, err := ss.CheckHost(host, dns.TypeA)
<mask> require.NoError(t, err)
<mask>
<mask> assert.True(t, res.IsFiltered)
<mask>
<mask> require.Len(t, res.Rules, 1)
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove res, err := ss.CheckHost(host, dns.TypeA)
</s> add var res filtering.Result
res, err = ss.CheckHost(host, testQType) </s> remove require.Len(t, res.Rules, 1)
assert.True(t, res.Rules[0].IP.Equal(foundIP))
// Check cache.
cachedValue, isFound := ss.getCachedResult(domain)
require.True(t, isFound)
require.Len(t, cachedValue.Rules, 1)
assert.True(t, cachedValue.Rules[0].IP.Equal(foundIP))
}
const googleHost = "www.google.com"
</s> add </s> remove var foundIP net.IP
for _, ip := range ips {
if ip.To4() != nil {
foundIP = ip
break
}
}
res, err = ss.CheckHost(domain, dns.TypeA)
</s> add res, err = ss.CheckHost("www.yandex.com", testQType) </s> remove // For yandex we already know valid IP.
require.Len(t, res.Rules, 1)
</s> add assert.True(t, res.IsFiltered) </s> remove assert.False(t, res.IsFiltered)
assert.Empty(t, res.Rules)
ss = newForTest(t, defaultSafeSearchConf)
res, err = ss.CheckHost(domain, dns.TypeA)
</s> add res, err := ss.CheckHost("www.yandex.com", testQType) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch_test.go |
func TestDefault_CheckHost_google(t *testing.T) { | <mask> assert.EqualValues(t, filtering.SafeSearchListID, res.Rules[0].FilterListID)
<mask> }
<mask> }
<mask>
<mask> func TestCheckHostSafeSearchGoogle(t *testing.T) {
<mask> resolver := &aghtest.TestResolver{}
<mask> ip, _ := resolver.HostToIPs("forcesafesearch.google.com")
<mask>
<mask> ss := newForTest(t, defaultSafeSearchConf)
<mask> ss.resolver = resolver
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove ss := newForTest(t, defaultSafeSearchConf)
ss.resolver = resolver
</s> add conf := testConf
conf.CustomResolver = resolver
ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL)
require.NoError(t, err) </s> remove assert.Empty(t, res.Rules)
</s> add </s> remove resolver := &aghtest.TestResolver{}
ss = newForTest(t, defaultSafeSearchConf)
ss.resolver = resolver
// Lookup for safesearch domain.
rewrite := ss.SearchHost(domain, dns.TypeA)
ips, err := resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME)
</s> add err = ss.Update(filtering.SafeSearchConfig{
Enabled: false,
Google: true,
}) </s> remove return ss
}
func TestSafeSearch(t *testing.T) {
ss := newForTest(t, defaultSafeSearchConf)
val := ss.SearchHost("www.google.com", dns.TypeA)
assert.Equal(t, &rules.DNSRewrite{NewCNAME: "forcesafesearch.google.com"}, val)
}
func TestCheckHostSafeSearchYandex(t *testing.T) {
ss := newForTest(t, defaultSafeSearchConf)
</s> add </s> remove func TestSafeSearchCacheYandex(t *testing.T) {
const domain = "yandex.ru"
ss := newForTest(t, filtering.SafeSearchConfig{Enabled: false})
// Check host with disabled safesearch.
res, err := ss.CheckHost(domain, dns.TypeA)
</s> add func TestDefault_Update(t *testing.T) {
conf := testConf
ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch_test.go |
conf := testConf
conf.CustomResolver = resolver
ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL)
require.NoError(t, err) | <mask> func TestCheckHostSafeSearchGoogle(t *testing.T) {
<mask> resolver := &aghtest.TestResolver{}
<mask> ip, _ := resolver.HostToIPs("forcesafesearch.google.com")
<mask>
<mask> ss := newForTest(t, defaultSafeSearchConf)
<mask> ss.resolver = resolver
<mask>
<mask> // Check host for each domain.
<mask> for _, host := range []string{
<mask> "www.google.com",
<mask> "www.google.im",
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove func TestCheckHostSafeSearchGoogle(t *testing.T) {
</s> add func TestDefault_CheckHost_google(t *testing.T) { </s> remove return ss
}
func TestSafeSearch(t *testing.T) {
ss := newForTest(t, defaultSafeSearchConf)
val := ss.SearchHost("www.google.com", dns.TypeA)
assert.Equal(t, &rules.DNSRewrite{NewCNAME: "forcesafesearch.google.com"}, val)
}
func TestCheckHostSafeSearchYandex(t *testing.T) {
ss := newForTest(t, defaultSafeSearchConf)
</s> add </s> remove resolver := &aghtest.TestResolver{}
ss = newForTest(t, defaultSafeSearchConf)
ss.resolver = resolver
// Lookup for safesearch domain.
rewrite := ss.SearchHost(domain, dns.TypeA)
ips, err := resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME)
</s> add err = ss.Update(filtering.SafeSearchConfig{
Enabled: false,
Google: true,
}) </s> remove assert.Empty(t, res.Rules)
</s> add </s> remove func TestSafeSearchCacheYandex(t *testing.T) {
const domain = "yandex.ru"
ss := newForTest(t, filtering.SafeSearchConfig{Enabled: false})
// Check host with disabled safesearch.
res, err := ss.CheckHost(domain, dns.TypeA)
</s> add func TestDefault_Update(t *testing.T) {
conf := testConf
ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch_test.go |
var res filtering.Result
res, err = ss.CheckHost(host, testQType) | <mask> "www.google.it",
<mask> "www.google.je",
<mask> } {
<mask> t.Run(host, func(t *testing.T) {
<mask> res, err := ss.CheckHost(host, dns.TypeA)
<mask> require.NoError(t, err)
<mask>
<mask> assert.True(t, res.IsFiltered)
<mask>
<mask> require.Len(t, res.Rules, 1)
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove res, err := ss.CheckHost(host, dns.TypeA)
</s> add var res filtering.Result
res, err = ss.CheckHost(host, testQType) </s> remove require.Len(t, res.Rules, 1)
assert.True(t, res.Rules[0].IP.Equal(foundIP))
// Check cache.
cachedValue, isFound := ss.getCachedResult(domain)
require.True(t, isFound)
require.Len(t, cachedValue.Rules, 1)
assert.True(t, cachedValue.Rules[0].IP.Equal(foundIP))
}
const googleHost = "www.google.com"
</s> add </s> remove var foundIP net.IP
for _, ip := range ips {
if ip.To4() != nil {
foundIP = ip
break
}
}
res, err = ss.CheckHost(domain, dns.TypeA)
</s> add res, err = ss.CheckHost("www.yandex.com", testQType) </s> remove // For yandex we already know valid IP.
require.Len(t, res.Rules, 1)
</s> add assert.True(t, res.IsFiltered) </s> remove assert.Equal(t, res.Rules[0].IP, yandexIP)
// Check cache.
cachedValue, isFound := ss.getCachedResult(domain)
require.True(t, isFound)
require.Len(t, cachedValue.Rules, 1)
assert.Equal(t, cachedValue.Rules[0].IP, yandexIP)
}
func TestSafeSearchCacheGoogle(t *testing.T) {
const domain = "www.google.ru"
ss := newForTest(t, filtering.SafeSearchConfig{Enabled: false})
</s> add err = ss.Update(filtering.SafeSearchConfig{
Enabled: true,
Google: false,
})
require.NoError(t, err) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch_test.go |
func TestDefault_Update(t *testing.T) {
conf := testConf
ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL) | <mask> })
<mask> }
<mask> }
<mask>
<mask> func TestSafeSearchCacheYandex(t *testing.T) {
<mask> const domain = "yandex.ru"
<mask>
<mask> ss := newForTest(t, filtering.SafeSearchConfig{Enabled: false})
<mask>
<mask> // Check host with disabled safesearch.
<mask> res, err := ss.CheckHost(domain, dns.TypeA)
<mask> require.NoError(t, err)
<mask>
<mask> assert.False(t, res.IsFiltered)
<mask> assert.Empty(t, res.Rules)
<mask>
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove res, err := ss.CheckHost(domain, dns.TypeA)
</s> add res, err = ss.CheckHost("www.yandex.com", testQType) </s> remove assert.False(t, res.IsFiltered)
assert.Empty(t, res.Rules)
ss = newForTest(t, defaultSafeSearchConf)
res, err = ss.CheckHost(domain, dns.TypeA)
</s> add res, err := ss.CheckHost("www.yandex.com", testQType) </s> remove assert.Equal(t, res.Rules[0].IP, yandexIP)
// Check cache.
cachedValue, isFound := ss.getCachedResult(domain)
require.True(t, isFound)
require.Len(t, cachedValue.Rules, 1)
assert.Equal(t, cachedValue.Rules[0].IP, yandexIP)
}
func TestSafeSearchCacheGoogle(t *testing.T) {
const domain = "www.google.ru"
ss := newForTest(t, filtering.SafeSearchConfig{Enabled: false})
</s> add err = ss.Update(filtering.SafeSearchConfig{
Enabled: true,
Google: false,
})
require.NoError(t, err) </s> remove assert.Empty(t, res.Rules)
</s> add </s> remove resolver := &aghtest.TestResolver{}
ss = newForTest(t, defaultSafeSearchConf)
ss.resolver = resolver
// Lookup for safesearch domain.
rewrite := ss.SearchHost(domain, dns.TypeA)
ips, err := resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME)
</s> add err = ss.Update(filtering.SafeSearchConfig{
Enabled: false,
Google: true,
}) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch_test.go |
res, err := ss.CheckHost("www.yandex.com", testQType) | <mask> // Check host with disabled safesearch.
<mask> res, err := ss.CheckHost(domain, dns.TypeA)
<mask> require.NoError(t, err)
<mask>
<mask> assert.False(t, res.IsFiltered)
<mask> assert.Empty(t, res.Rules)
<mask>
<mask> ss = newForTest(t, defaultSafeSearchConf)
<mask> res, err = ss.CheckHost(domain, dns.TypeA)
<mask> require.NoError(t, err)
<mask>
<mask> // For yandex we already know valid IP.
<mask> require.Len(t, res.Rules, 1)
<mask>
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove // For yandex we already know valid IP.
require.Len(t, res.Rules, 1)
</s> add assert.True(t, res.IsFiltered) </s> remove assert.Equal(t, res.Rules[0].IP, yandexIP)
// Check cache.
cachedValue, isFound := ss.getCachedResult(domain)
require.True(t, isFound)
require.Len(t, cachedValue.Rules, 1)
assert.Equal(t, cachedValue.Rules[0].IP, yandexIP)
}
func TestSafeSearchCacheGoogle(t *testing.T) {
const domain = "www.google.ru"
ss := newForTest(t, filtering.SafeSearchConfig{Enabled: false})
</s> add err = ss.Update(filtering.SafeSearchConfig{
Enabled: true,
Google: false,
})
require.NoError(t, err) </s> remove assert.Empty(t, res.Rules)
</s> add </s> remove func TestSafeSearchCacheYandex(t *testing.T) {
const domain = "yandex.ru"
ss := newForTest(t, filtering.SafeSearchConfig{Enabled: false})
// Check host with disabled safesearch.
res, err := ss.CheckHost(domain, dns.TypeA)
</s> add func TestDefault_Update(t *testing.T) {
conf := testConf
ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL) </s> remove res, err := ss.CheckHost(domain, dns.TypeA)
</s> add res, err = ss.CheckHost("www.yandex.com", testQType) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch_test.go |
assert.True(t, res.IsFiltered) | <mask> ss = newForTest(t, defaultSafeSearchConf)
<mask> res, err = ss.CheckHost(domain, dns.TypeA)
<mask> require.NoError(t, err)
<mask>
<mask> // For yandex we already know valid IP.
<mask> require.Len(t, res.Rules, 1)
<mask>
<mask> assert.Equal(t, res.Rules[0].IP, yandexIP)
<mask>
<mask> // Check cache.
<mask> cachedValue, isFound := ss.getCachedResult(domain)
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove assert.Equal(t, res.Rules[0].IP, yandexIP)
// Check cache.
cachedValue, isFound := ss.getCachedResult(domain)
require.True(t, isFound)
require.Len(t, cachedValue.Rules, 1)
assert.Equal(t, cachedValue.Rules[0].IP, yandexIP)
}
func TestSafeSearchCacheGoogle(t *testing.T) {
const domain = "www.google.ru"
ss := newForTest(t, filtering.SafeSearchConfig{Enabled: false})
</s> add err = ss.Update(filtering.SafeSearchConfig{
Enabled: true,
Google: false,
})
require.NoError(t, err) </s> remove assert.False(t, res.IsFiltered)
assert.Empty(t, res.Rules)
ss = newForTest(t, defaultSafeSearchConf)
res, err = ss.CheckHost(domain, dns.TypeA)
</s> add res, err := ss.CheckHost("www.yandex.com", testQType) </s> remove require.Len(t, res.Rules, 1)
assert.True(t, res.Rules[0].IP.Equal(foundIP))
// Check cache.
cachedValue, isFound := ss.getCachedResult(domain)
require.True(t, isFound)
require.Len(t, cachedValue.Rules, 1)
assert.True(t, cachedValue.Rules[0].IP.Equal(foundIP))
}
const googleHost = "www.google.com"
</s> add </s> remove assert.Empty(t, res.Rules)
</s> add </s> remove res, err := ss.CheckHost(host, dns.TypeA)
</s> add var res filtering.Result
res, err = ss.CheckHost(host, testQType) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch_test.go |
err = ss.Update(filtering.SafeSearchConfig{
Enabled: true,
Google: false,
})
require.NoError(t, err) | <mask>
<mask> // For yandex we already know valid IP.
<mask> require.Len(t, res.Rules, 1)
<mask>
<mask> assert.Equal(t, res.Rules[0].IP, yandexIP)
<mask>
<mask> // Check cache.
<mask> cachedValue, isFound := ss.getCachedResult(domain)
<mask> require.True(t, isFound)
<mask> require.Len(t, cachedValue.Rules, 1)
<mask>
<mask> assert.Equal(t, cachedValue.Rules[0].IP, yandexIP)
<mask> }
<mask>
<mask> func TestSafeSearchCacheGoogle(t *testing.T) {
<mask> const domain = "www.google.ru"
<mask>
<mask> ss := newForTest(t, filtering.SafeSearchConfig{Enabled: false})
<mask>
<mask> res, err := ss.CheckHost(domain, dns.TypeA)
<mask> require.NoError(t, err)
<mask>
<mask> assert.False(t, res.IsFiltered)
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove // For yandex we already know valid IP.
require.Len(t, res.Rules, 1)
</s> add assert.True(t, res.IsFiltered) </s> remove assert.False(t, res.IsFiltered)
assert.Empty(t, res.Rules)
ss = newForTest(t, defaultSafeSearchConf)
res, err = ss.CheckHost(domain, dns.TypeA)
</s> add res, err := ss.CheckHost("www.yandex.com", testQType) </s> remove require.Len(t, res.Rules, 1)
assert.True(t, res.Rules[0].IP.Equal(foundIP))
// Check cache.
cachedValue, isFound := ss.getCachedResult(domain)
require.True(t, isFound)
require.Len(t, cachedValue.Rules, 1)
assert.True(t, cachedValue.Rules[0].IP.Equal(foundIP))
}
const googleHost = "www.google.com"
</s> add </s> remove res, err := ss.CheckHost(domain, dns.TypeA)
</s> add res, err = ss.CheckHost("www.yandex.com", testQType) </s> remove func TestSafeSearchCacheYandex(t *testing.T) {
const domain = "yandex.ru"
ss := newForTest(t, filtering.SafeSearchConfig{Enabled: false})
// Check host with disabled safesearch.
res, err := ss.CheckHost(domain, dns.TypeA)
</s> add func TestDefault_Update(t *testing.T) {
conf := testConf
ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch_test.go |
res, err = ss.CheckHost("www.yandex.com", testQType) | <mask> const domain = "www.google.ru"
<mask>
<mask> ss := newForTest(t, filtering.SafeSearchConfig{Enabled: false})
<mask>
<mask> res, err := ss.CheckHost(domain, dns.TypeA)
<mask> require.NoError(t, err)
<mask>
<mask> assert.False(t, res.IsFiltered)
<mask> assert.Empty(t, res.Rules)
<mask>
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove func TestSafeSearchCacheYandex(t *testing.T) {
const domain = "yandex.ru"
ss := newForTest(t, filtering.SafeSearchConfig{Enabled: false})
// Check host with disabled safesearch.
res, err := ss.CheckHost(domain, dns.TypeA)
</s> add func TestDefault_Update(t *testing.T) {
conf := testConf
ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL) </s> remove assert.Empty(t, res.Rules)
</s> add </s> remove assert.Equal(t, res.Rules[0].IP, yandexIP)
// Check cache.
cachedValue, isFound := ss.getCachedResult(domain)
require.True(t, isFound)
require.Len(t, cachedValue.Rules, 1)
assert.Equal(t, cachedValue.Rules[0].IP, yandexIP)
}
func TestSafeSearchCacheGoogle(t *testing.T) {
const domain = "www.google.ru"
ss := newForTest(t, filtering.SafeSearchConfig{Enabled: false})
</s> add err = ss.Update(filtering.SafeSearchConfig{
Enabled: true,
Google: false,
})
require.NoError(t, err) </s> remove assert.False(t, res.IsFiltered)
assert.Empty(t, res.Rules)
ss = newForTest(t, defaultSafeSearchConf)
res, err = ss.CheckHost(domain, dns.TypeA)
</s> add res, err := ss.CheckHost("www.yandex.com", testQType) </s> remove resolver := &aghtest.TestResolver{}
ss = newForTest(t, defaultSafeSearchConf)
ss.resolver = resolver
// Lookup for safesearch domain.
rewrite := ss.SearchHost(domain, dns.TypeA)
ips, err := resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME)
</s> add err = ss.Update(filtering.SafeSearchConfig{
Enabled: false,
Google: true,
}) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch_test.go |
<mask> res, err := ss.CheckHost(domain, dns.TypeA)
<mask> require.NoError(t, err)
<mask>
<mask> assert.False(t, res.IsFiltered)
<mask> assert.Empty(t, res.Rules)
<mask>
<mask> resolver := &aghtest.TestResolver{}
<mask> ss = newForTest(t, defaultSafeSearchConf)
<mask> ss.resolver = resolver
<mask>
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove resolver := &aghtest.TestResolver{}
ss = newForTest(t, defaultSafeSearchConf)
ss.resolver = resolver
// Lookup for safesearch domain.
rewrite := ss.SearchHost(domain, dns.TypeA)
ips, err := resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME)
</s> add err = ss.Update(filtering.SafeSearchConfig{
Enabled: false,
Google: true,
}) </s> remove res, err := ss.CheckHost(domain, dns.TypeA)
</s> add res, err = ss.CheckHost("www.yandex.com", testQType) </s> remove assert.False(t, res.IsFiltered)
assert.Empty(t, res.Rules)
ss = newForTest(t, defaultSafeSearchConf)
res, err = ss.CheckHost(domain, dns.TypeA)
</s> add res, err := ss.CheckHost("www.yandex.com", testQType) </s> remove func TestSafeSearchCacheYandex(t *testing.T) {
const domain = "yandex.ru"
ss := newForTest(t, filtering.SafeSearchConfig{Enabled: false})
// Check host with disabled safesearch.
res, err := ss.CheckHost(domain, dns.TypeA)
</s> add func TestDefault_Update(t *testing.T) {
conf := testConf
ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL) </s> remove ss := newForTest(t, defaultSafeSearchConf)
ss.resolver = resolver
</s> add conf := testConf
conf.CustomResolver = resolver
ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL)
require.NoError(t, err) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch_test.go |
|
err = ss.Update(filtering.SafeSearchConfig{
Enabled: false,
Google: true,
}) | <mask>
<mask> assert.False(t, res.IsFiltered)
<mask> assert.Empty(t, res.Rules)
<mask>
<mask> resolver := &aghtest.TestResolver{}
<mask> ss = newForTest(t, defaultSafeSearchConf)
<mask> ss.resolver = resolver
<mask>
<mask> // Lookup for safesearch domain.
<mask> rewrite := ss.SearchHost(domain, dns.TypeA)
<mask>
<mask> ips, err := resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME)
<mask> require.NoError(t, err)
<mask>
<mask> var foundIP net.IP
<mask> for _, ip := range ips {
<mask> if ip.To4() != nil {
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove var foundIP net.IP
for _, ip := range ips {
if ip.To4() != nil {
foundIP = ip
break
}
}
res, err = ss.CheckHost(domain, dns.TypeA)
</s> add res, err = ss.CheckHost("www.yandex.com", testQType) </s> remove assert.Empty(t, res.Rules)
</s> add </s> remove ss := newForTest(t, defaultSafeSearchConf)
ss.resolver = resolver
</s> add conf := testConf
conf.CustomResolver = resolver
ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL)
require.NoError(t, err) </s> remove ips, err := ss.resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME)
</s> add ss.log(log.DEBUG, "resolving %q", host)
ips, err := ss.resolver.LookupIP(context.Background(), qtypeToProto(qtype), host) </s> remove func TestCheckHostSafeSearchGoogle(t *testing.T) {
</s> add func TestDefault_CheckHost_google(t *testing.T) { | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch_test.go |
res, err = ss.CheckHost("www.yandex.com", testQType) | <mask>
<mask> ips, err := resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME)
<mask> require.NoError(t, err)
<mask>
<mask> var foundIP net.IP
<mask> for _, ip := range ips {
<mask> if ip.To4() != nil {
<mask> foundIP = ip
<mask>
<mask> break
<mask> }
<mask> }
<mask>
<mask> res, err = ss.CheckHost(domain, dns.TypeA)
<mask> require.NoError(t, err)
<mask> require.Len(t, res.Rules, 1)
<mask>
<mask> assert.True(t, res.Rules[0].IP.Equal(foundIP))
<mask>
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove resolver := &aghtest.TestResolver{}
ss = newForTest(t, defaultSafeSearchConf)
ss.resolver = resolver
// Lookup for safesearch domain.
rewrite := ss.SearchHost(domain, dns.TypeA)
ips, err := resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME)
</s> add err = ss.Update(filtering.SafeSearchConfig{
Enabled: false,
Google: true,
}) </s> remove require.Len(t, res.Rules, 1)
assert.True(t, res.Rules[0].IP.Equal(foundIP))
// Check cache.
cachedValue, isFound := ss.getCachedResult(domain)
require.True(t, isFound)
require.Len(t, cachedValue.Rules, 1)
assert.True(t, cachedValue.Rules[0].IP.Equal(foundIP))
}
const googleHost = "www.google.com"
</s> add </s> remove ips, err := ss.resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME)
</s> add ss.log(log.DEBUG, "resolving %q", host)
ips, err := ss.resolver.LookupIP(context.Background(), qtypeToProto(qtype), host) </s> remove res, err := ss.CheckHost(host, dns.TypeA)
</s> add var res filtering.Result
res, err = ss.CheckHost(host, testQType) </s> remove res, err := ss.CheckHost(host, dns.TypeA)
</s> add var res filtering.Result
res, err = ss.CheckHost(host, testQType) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch_test.go |
<mask> }
<mask>
<mask> res, err = ss.CheckHost(domain, dns.TypeA)
<mask> require.NoError(t, err)
<mask> require.Len(t, res.Rules, 1)
<mask>
<mask> assert.True(t, res.Rules[0].IP.Equal(foundIP))
<mask>
<mask> // Check cache.
<mask> cachedValue, isFound := ss.getCachedResult(domain)
<mask> require.True(t, isFound)
<mask> require.Len(t, cachedValue.Rules, 1)
<mask>
<mask> assert.True(t, cachedValue.Rules[0].IP.Equal(foundIP))
<mask> }
<mask>
<mask> const googleHost = "www.google.com"
<mask>
<mask> var dnsRewriteSink *rules.DNSRewrite
<mask>
<mask> func BenchmarkSafeSearch(b *testing.B) {
<mask> ss := newForTest(b, defaultSafeSearchConf)
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove assert.Equal(t, res.Rules[0].IP, yandexIP)
// Check cache.
cachedValue, isFound := ss.getCachedResult(domain)
require.True(t, isFound)
require.Len(t, cachedValue.Rules, 1)
assert.Equal(t, cachedValue.Rules[0].IP, yandexIP)
}
func TestSafeSearchCacheGoogle(t *testing.T) {
const domain = "www.google.ru"
ss := newForTest(t, filtering.SafeSearchConfig{Enabled: false})
</s> add err = ss.Update(filtering.SafeSearchConfig{
Enabled: true,
Google: false,
})
require.NoError(t, err) </s> remove // For yandex we already know valid IP.
require.Len(t, res.Rules, 1)
</s> add assert.True(t, res.IsFiltered) </s> remove var dnsRewriteSink *rules.DNSRewrite
func BenchmarkSafeSearch(b *testing.B) {
ss := newForTest(b, defaultSafeSearchConf)
for n := 0; n < b.N; n++ {
dnsRewriteSink = ss.SearchHost(googleHost, dns.TypeA)
}
assert.Equal(b, "forcesafesearch.google.com", dnsRewriteSink.NewCNAME)
}
var dnsRewriteParallelSink *rules.DNSRewrite
func BenchmarkSafeSearch_parallel(b *testing.B) {
ss := newForTest(b, defaultSafeSearchConf)
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
dnsRewriteParallelSink = ss.SearchHost(googleHost, dns.TypeA)
}
})
assert.Equal(b, "forcesafesearch.google.com", dnsRewriteParallelSink.NewCNAME)
</s> add assert.False(t, res.IsFiltered) </s> remove var foundIP net.IP
for _, ip := range ips {
if ip.To4() != nil {
foundIP = ip
break
}
}
res, err = ss.CheckHost(domain, dns.TypeA)
</s> add res, err = ss.CheckHost("www.yandex.com", testQType) </s> remove res, err := ss.CheckHost(host, dns.TypeA)
</s> add var res filtering.Result
res, err = ss.CheckHost(host, testQType) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch_test.go |
|
assert.False(t, res.IsFiltered) | <mask> }
<mask>
<mask> const googleHost = "www.google.com"
<mask>
<mask> var dnsRewriteSink *rules.DNSRewrite
<mask>
<mask> func BenchmarkSafeSearch(b *testing.B) {
<mask> ss := newForTest(b, defaultSafeSearchConf)
<mask>
<mask> for n := 0; n < b.N; n++ {
<mask> dnsRewriteSink = ss.SearchHost(googleHost, dns.TypeA)
<mask> }
<mask>
<mask> assert.Equal(b, "forcesafesearch.google.com", dnsRewriteSink.NewCNAME)
<mask> }
<mask>
<mask> var dnsRewriteParallelSink *rules.DNSRewrite
<mask>
<mask> func BenchmarkSafeSearch_parallel(b *testing.B) {
<mask> ss := newForTest(b, defaultSafeSearchConf)
<mask>
<mask> b.RunParallel(func(pb *testing.PB) {
<mask> for pb.Next() {
<mask> dnsRewriteParallelSink = ss.SearchHost(googleHost, dns.TypeA)
<mask> }
<mask> })
<mask>
<mask> assert.Equal(b, "forcesafesearch.google.com", dnsRewriteParallelSink.NewCNAME)
<mask> }
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove require.Len(t, res.Rules, 1)
assert.True(t, res.Rules[0].IP.Equal(foundIP))
// Check cache.
cachedValue, isFound := ss.getCachedResult(domain)
require.True(t, isFound)
require.Len(t, cachedValue.Rules, 1)
assert.True(t, cachedValue.Rules[0].IP.Equal(foundIP))
}
const googleHost = "www.google.com"
</s> add </s> remove return ss
}
func TestSafeSearch(t *testing.T) {
ss := newForTest(t, defaultSafeSearchConf)
val := ss.SearchHost("www.google.com", dns.TypeA)
assert.Equal(t, &rules.DNSRewrite{NewCNAME: "forcesafesearch.google.com"}, val)
}
func TestCheckHostSafeSearchYandex(t *testing.T) {
ss := newForTest(t, defaultSafeSearchConf)
</s> add </s> remove func TestCheckHostSafeSearchGoogle(t *testing.T) {
</s> add func TestDefault_CheckHost_google(t *testing.T) { </s> remove func TestSafeSearchCacheYandex(t *testing.T) {
const domain = "yandex.ru"
ss := newForTest(t, filtering.SafeSearchConfig{Enabled: false})
// Check host with disabled safesearch.
res, err := ss.CheckHost(domain, dns.TypeA)
</s> add func TestDefault_Update(t *testing.T) {
conf := testConf
ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL) </s> remove resolver := &aghtest.TestResolver{}
ss = newForTest(t, defaultSafeSearchConf)
ss.resolver = resolver
// Lookup for safesearch domain.
rewrite := ss.SearchHost(domain, dns.TypeA)
ips, err := resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME)
</s> add err = ss.Update(filtering.SafeSearchConfig{
Enabled: false,
Google: true,
}) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearch/safesearch_test.go |
conf := *req
err = d.safeSearch.Update(conf)
if err != nil {
aghhttp.Error(r, w, http.StatusBadRequest, "updating: %s", err)
return
}
| <mask> return
<mask> }
<mask>
<mask> func() {
<mask> d.confLock.Lock()
<mask> defer d.confLock.Unlock()
<mask>
<mask> d.Config.SafeSearchConf = conf
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove d.Config.SafeSearchConf = *req
</s> add d.Config.SafeSearchConf = conf </s> remove if log.GetLevel() >= log.DEBUG {
timer := log.StartTimer()
defer timer.LogElapsed("safesearch: lookup for %s", host)
</s> add start := time.Now()
defer func() {
ss.log(log.DEBUG, "lookup for %q finished in %s", host, time.Since(start))
}()
if qtype != dns.TypeA && qtype != dns.TypeAAAA {
return filtering.Result{}, fmt.Errorf("unsupported question type %s", dns.Type(qtype)) </s> remove cachedValue, isFound := ss.getCachedResult(host)
</s> add cachedValue, isFound := ss.getCachedResult(host, qtype) </s> remove func newForTest(t testing.TB, ssConf filtering.SafeSearchConfig) (ss *DefaultSafeSearch) {
ss, err := NewDefaultSafeSearch(ssConf, safeSearchCacheSize, cacheTime)
</s> add func TestDefault_CheckHost_yandex(t *testing.T) {
conf := testConf
ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL) </s> remove qtype uint16,
</s> add qtype rules.RRType, | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearchhttp.go |
d.Config.SafeSearchConf = conf | <mask> func() {
<mask> d.confLock.Lock()
<mask> defer d.confLock.Unlock()
<mask>
<mask> d.Config.SafeSearchConf = *req
<mask> }()
<mask>
<mask> d.Config.ConfigModified()
<mask>
<mask> aghhttp.OK(w)
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove if log.GetLevel() >= log.DEBUG {
timer := log.StartTimer()
defer timer.LogElapsed("safesearch: lookup for %s", host)
</s> add start := time.Now()
defer func() {
ss.log(log.DEBUG, "lookup for %q finished in %s", host, time.Since(start))
}()
if qtype != dns.TypeA && qtype != dns.TypeAAAA {
return filtering.Result{}, fmt.Errorf("unsupported question type %s", dns.Type(qtype)) </s> remove qtype uint16,
</s> add qtype rules.RRType, </s> remove cachedValue, isFound := ss.getCachedResult(host)
</s> add cachedValue, isFound := ss.getCachedResult(host, qtype) </s> remove // newResult creates Result object from rewrite rule.
func (ss *DefaultSafeSearch) newResult(
</s> add // searchHost looks up DNS rewrites in the internal DNS filtering engine.
func (ss *Default) searchHost(host string, qtype rules.RRType) (res *rules.DNSRewrite) {
ss.mu.RLock()
defer ss.mu.RUnlock()
if ss.engine == nil {
return nil
}
r, _ := ss.engine.MatchRequest(&urlfilter.DNSRequest{
Hostname: strings.ToLower(host),
DNSType: qtype,
})
rewritesRules := r.DNSRewrites()
if len(rewritesRules) > 0 {
return rewritesRules[0].DNSRewrite
}
return nil
}
// newResult creates Result object from rewrite rule. qtype must be either
// [dns.TypeA] or [dns.TypeAAAA].
func (ss *Default) newResult( | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/filtering/safesearchhttp.go |
"time" | <mask>
<mask> import (
<mask> "encoding"
<mask> "fmt"
<mask>
<mask> "github.com/AdguardTeam/AdGuardHome/internal/filtering"
<mask> "github.com/AdguardTeam/AdGuardHome/internal/filtering/safesearch"
<mask> "github.com/AdguardTeam/dnsproxy/proxy"
<mask> )
<mask>
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove "github.com/AdguardTeam/AdGuardHome/internal/filtering/safesearch"
</s> add </s> remove "github.com/AdguardTeam/urlfilter/rules"
</s> add "github.com/AdguardTeam/AdGuardHome/internal/filtering/safesearch"
"github.com/AdguardTeam/golibs/testutil" </s> remove "context"
</s> add </s> remove package safesearch
</s> add package safesearch_test | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/home/client.go |
"github.com/AdguardTeam/AdGuardHome/internal/filtering/safesearch" | <mask>
<mask> "github.com/AdguardTeam/AdGuardHome/internal/filtering"
<mask> "github.com/AdguardTeam/dnsproxy/proxy"
<mask> )
<mask>
<mask> // Client contains information about persistent clients.
<mask> type Client struct {
<mask> // upstreamConfig is the custom upstream config for this client. If
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove // DefaultSafeSearch is the default safesearch struct.
type DefaultSafeSearch struct {
engine *urlfilter.DNSEngine
safeSearchCache cache.Cache
resolver filtering.Resolver
cacheTime time.Duration
</s> add // Default is the default safe search filter that uses filtering rules with the
// dnsrewrite modifier.
type Default struct {
// mu protects engine.
mu *sync.RWMutex
// engine is the filtering engine that contains the DNS rewrite rules.
// engine may be nil, which means that this safe search filter is disabled.
engine *urlfilter.DNSEngine
cache cache.Cache
resolver filtering.Resolver
logPrefix string
cacheTTL time.Duration | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/home/client.go |
<mask> "github.com/AdguardTeam/AdGuardHome/internal/aghnet"
<mask> "github.com/AdguardTeam/AdGuardHome/internal/dhcpd"
<mask> "github.com/AdguardTeam/AdGuardHome/internal/dnsforward"
<mask> "github.com/AdguardTeam/AdGuardHome/internal/filtering"
<mask> "github.com/AdguardTeam/AdGuardHome/internal/filtering/safesearch"
<mask> "github.com/AdguardTeam/AdGuardHome/internal/querylog"
<mask> "github.com/AdguardTeam/dnsproxy/proxy"
<mask> "github.com/AdguardTeam/dnsproxy/upstream"
<mask> "github.com/AdguardTeam/golibs/errors"
<mask> "github.com/AdguardTeam/golibs/log"
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove "github.com/AdguardTeam/urlfilter/rules"
</s> add "github.com/AdguardTeam/AdGuardHome/internal/filtering/safesearch"
"github.com/AdguardTeam/golibs/testutil" | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/home/clients.go |
|
// safeSearchCacheSize is the size of the safe search cache to use for
// persistent clients.
safeSearchCacheSize uint
// safeSearchCacheTTL is the TTL of the safe search cache to use for
// persistent clients.
safeSearchCacheTTL time.Duration
| <mask> lock sync.Mutex
<mask>
<mask> // testing is a flag that disables some features for internal tests.
<mask> //
<mask> // TODO(a.garipov): Awful. Remove.
<mask> testing bool
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove func TestClients(t *testing.T) {
clients := clientsContainer{}
clients.testing = true
</s> add // newClientsContainer is a helper that creates a new clients container for
// tests.
func newClientsContainer() (c *clientsContainer) {
c = &clientsContainer{
testing: true,
}
c.Init(nil, nil, nil, nil, &filtering.Config{}) </s> remove // DefaultSafeSearch is the default safesearch struct.
type DefaultSafeSearch struct {
engine *urlfilter.DNSEngine
safeSearchCache cache.Cache
resolver filtering.Resolver
cacheTime time.Duration
</s> add // Default is the default safe search filter that uses filtering rules with the
// dnsrewrite modifier.
type Default struct {
// mu protects engine.
mu *sync.RWMutex
// engine is the filtering engine that contains the DNS rewrite rules.
// engine may be nil, which means that this safe search filter is disabled.
engine *urlfilter.DNSEngine
cache cache.Cache
resolver filtering.Resolver
logPrefix string
cacheTTL time.Duration </s> remove safeSearchCacheSize = 5000
cacheTime = 30 * time.Minute
</s> add // TODO(a.garipov): Add IPv6 tests.
testQType = dns.TypeA
testCacheSize = 5000
testCacheTTL = 30 * time.Minute | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/home/clients.go |
clients.safeSearchCacheSize = filteringConf.SafeSearchCacheSize
clients.safeSearchCacheTTL = time.Minute * time.Duration(filteringConf.CacheTime)
| <mask> clients.arpdb = arpdb
<mask> clients.addFromConfig(objects, filteringConf)
<mask>
<mask> if clients.testing {
<mask> return
<mask> }
<mask>
<mask> clients.updateFromDHCP(true)
<mask> if clients.dhcpServer != nil {
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove clients.Init(nil, nil, nil, nil, nil)
</s> add return c
}
func TestClients(t *testing.T) {
clients := newClientsContainer() </s> remove if rewrite.NewCNAME == "" {
</s> add host := rewrite.NewCNAME
if host == "" { </s> remove func TestClients(t *testing.T) {
clients := clientsContainer{}
clients.testing = true
</s> add // newClientsContainer is a helper that creates a new clients container for
// tests.
func newClientsContainer() (c *clientsContainer) {
c = &clientsContainer{
testing: true,
}
c.Init(nil, nil, nil, nil, &filtering.Config{}) </s> remove if !setts.ProtectionEnabled || !setts.SafeSearchEnabled {
</s> add if !setts.ProtectionEnabled ||
!setts.SafeSearchEnabled ||
(qtype != dns.TypeA && qtype != dns.TypeAAAA) { </s> remove c := jsonToClient(dj.Data)
</s> add c, err := clients.jsonToClient(dj.Data)
if err != nil {
aghhttp.Error(r, w, http.StatusBadRequest, "%s", err)
return
}
| [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/home/clients.go |
err := cli.setSafeSearch( | <mask>
<mask> if o.SafeSearchConf.Enabled {
<mask> o.SafeSearchConf.CustomResolver = safeSearchResolver{}
<mask>
<mask> ss, err := safesearch.NewDefaultSafeSearch(
<mask> o.SafeSearchConf,
<mask> filteringConf.SafeSearchCacheSize,
<mask> time.Minute*time.Duration(filteringConf.CacheTime),
<mask> )
<mask> if err != nil {
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove config.DNS.DnsfilterConf.SafeSearch, err = safesearch.NewDefaultSafeSearch(
</s> add config.DNS.DnsfilterConf.SafeSearch, err = safesearch.NewDefault( </s> remove log.Error("clients: init client safesearch %s: %s", cli.Name, err)
</s> add log.Error("clients: init client safesearch %q: %s", cli.Name, err) </s> remove func newForTest(t testing.TB, ssConf filtering.SafeSearchConfig) (ss *DefaultSafeSearch) {
ss, err := NewDefaultSafeSearch(ssConf, safeSearchCacheSize, cacheTime)
</s> add func TestDefault_CheckHost_yandex(t *testing.T) {
conf := testConf
ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL) </s> remove cacheTime time.Duration,
) (ss *DefaultSafeSearch, err error) {
engine, err := newEngine(filtering.SafeSearchListID, conf)
if err != nil {
return nil, err
}
</s> add cacheTTL time.Duration,
) (ss *Default, err error) { | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/home/clients.go |
log.Error("clients: init client safesearch %q: %s", cli.Name, err) | <mask> filteringConf.SafeSearchCacheSize,
<mask> time.Minute*time.Duration(filteringConf.CacheTime),
<mask> )
<mask> if err != nil {
<mask> log.Error("clients: init client safesearch %s: %s", cli.Name, err)
<mask>
<mask> continue
<mask> }
<mask>
<mask> cli.SafeSearch = ss
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove
cli.SafeSearch = ss
</s> add </s> remove ss, err := safesearch.NewDefaultSafeSearch(
</s> add err := cli.setSafeSearch( </s> remove log.Debug("safesearch: failed to lookup addresses for %s: %s", host, err)
</s> add ss.log(log.DEBUG, "looking up addresses for %q: %s", host, err) </s> remove Upstreams: cj.Upstreams,
</s> add if safeSearchConf.Enabled {
err = c.setSafeSearch(
safeSearchConf,
clients.safeSearchCacheSize,
clients.safeSearchCacheTTL,
)
if err != nil {
return nil, fmt.Errorf("creating safesearch for client %q: %w", c.Name, err)
} </s> remove dRes, err := ss.newResult(rewrite, qtype)
</s> add fltRes, err := ss.newResult(rewrite, qtype) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/home/clients.go |
<mask> log.Error("clients: init client safesearch %s: %s", cli.Name, err)
<mask>
<mask> continue
<mask> }
<mask>
<mask> cli.SafeSearch = ss
<mask> }
<mask>
<mask> for _, s := range o.BlockedServices {
<mask> if filtering.BlockedSvcKnown(s) {
<mask> cli.BlockedServices = append(cli.BlockedServices, s)
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove log.Error("clients: init client safesearch %s: %s", cli.Name, err)
</s> add log.Error("clients: init client safesearch %q: %s", cli.Name, err) </s> remove if ip = ip.To4(); ip == nil {
</s> add // TODO(a.garipov): Remove this filtering once the resolver we use
// actually learns about network.
ip = fitToProto(ip, qtype)
if ip == nil { </s> remove return ss
}
func TestSafeSearch(t *testing.T) {
ss := newForTest(t, defaultSafeSearchConf)
val := ss.SearchHost("www.google.com", dns.TypeA)
assert.Equal(t, &rules.DNSRewrite{NewCNAME: "forcesafesearch.google.com"}, val)
}
func TestCheckHostSafeSearchYandex(t *testing.T) {
ss := newForTest(t, defaultSafeSearchConf)
</s> add </s> remove log.Debug("safesearch: failed to lookup addresses for %s: %s", host, err)
</s> add ss.log(log.DEBUG, "looking up addresses for %q: %s", host, err) </s> remove resolver := &aghtest.TestResolver{}
ss = newForTest(t, defaultSafeSearchConf)
ss.resolver = resolver
// Lookup for safesearch domain.
rewrite := ss.SearchHost(domain, dns.TypeA)
ips, err := resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME)
</s> add err = ss.Update(filtering.SafeSearchConfig{
Enabled: false,
Google: true,
}) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/home/clients.go |
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering" | <mask> "testing"
<mask> "time"
<mask>
<mask> "github.com/AdguardTeam/AdGuardHome/internal/dhcpd"
<mask> "github.com/AdguardTeam/golibs/testutil"
<mask>
<mask> "github.com/stretchr/testify/assert"
<mask> "github.com/stretchr/testify/require"
<mask> )
<mask>
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove "github.com/AdguardTeam/urlfilter/rules"
</s> add "github.com/AdguardTeam/AdGuardHome/internal/filtering/safesearch"
"github.com/AdguardTeam/golibs/testutil" </s> remove "context"
</s> add </s> remove func TestClients(t *testing.T) {
clients := clientsContainer{}
clients.testing = true
</s> add // newClientsContainer is a helper that creates a new clients container for
// tests.
func newClientsContainer() (c *clientsContainer) {
c = &clientsContainer{
testing: true,
}
c.Init(nil, nil, nil, nil, &filtering.Config{}) | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/home/clients_test.go |
// newClientsContainer is a helper that creates a new clients container for
// tests.
func newClientsContainer() (c *clientsContainer) {
c = &clientsContainer{
testing: true,
}
c.Init(nil, nil, nil, nil, &filtering.Config{}) | <mask> "github.com/stretchr/testify/assert"
<mask> "github.com/stretchr/testify/require"
<mask> )
<mask>
<mask> func TestClients(t *testing.T) {
<mask> clients := clientsContainer{}
<mask> clients.testing = true
<mask>
<mask> clients.Init(nil, nil, nil, nil, nil)
<mask>
<mask> t.Run("add_success", func(t *testing.T) {
<mask> var (
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove clients.Init(nil, nil, nil, nil, nil)
</s> add return c
}
func TestClients(t *testing.T) {
clients := newClientsContainer() </s> remove clients := clientsContainer{
testing: true,
}
clients.Init(nil, nil, nil, nil, nil)
</s> add clients := newClientsContainer() </s> remove clients := clientsContainer{
testing: true,
}
clients.Init(nil, nil, nil, nil, nil)
</s> add clients := newClientsContainer() </s> remove clients := clientsContainer{
testing: true,
}
clients.Init(nil, nil, nil, nil, nil)
</s> add clients := newClientsContainer() | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/home/clients_test.go |
return c
}
func TestClients(t *testing.T) {
clients := newClientsContainer() | <mask> func TestClients(t *testing.T) {
<mask> clients := clientsContainer{}
<mask> clients.testing = true
<mask>
<mask> clients.Init(nil, nil, nil, nil, nil)
<mask>
<mask> t.Run("add_success", func(t *testing.T) {
<mask> var (
<mask> cliNone = "1.2.3.4"
<mask> cli1 = "1.1.1.1"
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove func TestClients(t *testing.T) {
clients := clientsContainer{}
clients.testing = true
</s> add // newClientsContainer is a helper that creates a new clients container for
// tests.
func newClientsContainer() (c *clientsContainer) {
c = &clientsContainer{
testing: true,
}
c.Init(nil, nil, nil, nil, &filtering.Config{}) </s> remove clients := clientsContainer{
testing: true,
}
clients.Init(nil, nil, nil, nil, nil)
</s> add clients := newClientsContainer() </s> remove clients := clientsContainer{
testing: true,
}
clients.Init(nil, nil, nil, nil, nil)
</s> add clients := newClientsContainer() </s> remove clients := clientsContainer{
testing: true,
}
clients.Init(nil, nil, nil, nil, nil)
</s> add clients := newClientsContainer() </s> remove res, err := ss.CheckHost(host, dns.TypeA)
</s> add var res filtering.Result
res, err = ss.CheckHost(host, testQType) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/home/clients_test.go |
clients := newClientsContainer() | <mask> })
<mask> }
<mask>
<mask> func TestClientsWHOIS(t *testing.T) {
<mask> clients := clientsContainer{
<mask> testing: true,
<mask> }
<mask> clients.Init(nil, nil, nil, nil, nil)
<mask> whois := &RuntimeClientWHOISInfo{
<mask> Country: "AU",
<mask> Orgname: "Example Org",
<mask> }
<mask>
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove clients := clientsContainer{
testing: true,
}
clients.Init(nil, nil, nil, nil, nil)
</s> add clients := newClientsContainer() </s> remove clients := clientsContainer{
testing: true,
}
clients.Init(nil, nil, nil, nil, nil)
</s> add clients := newClientsContainer() </s> remove func TestClients(t *testing.T) {
clients := clientsContainer{}
clients.testing = true
</s> add // newClientsContainer is a helper that creates a new clients container for
// tests.
func newClientsContainer() (c *clientsContainer) {
c = &clientsContainer{
testing: true,
}
c.Init(nil, nil, nil, nil, &filtering.Config{}) </s> remove clients.Init(nil, nil, nil, nil, nil)
</s> add return c
}
func TestClients(t *testing.T) {
clients := newClientsContainer() </s> remove ips, err := ss.resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME)
</s> add ss.log(log.DEBUG, "resolving %q", host)
ips, err := ss.resolver.LookupIP(context.Background(), qtypeToProto(qtype), host) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/home/clients_test.go |
clients := newClientsContainer() | <mask> })
<mask> }
<mask>
<mask> func TestClientsAddExisting(t *testing.T) {
<mask> clients := clientsContainer{
<mask> testing: true,
<mask> }
<mask> clients.Init(nil, nil, nil, nil, nil)
<mask>
<mask> t.Run("simple", func(t *testing.T) {
<mask> ip := netip.MustParseAddr("1.1.1.1")
<mask>
<mask> // Add a client.
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove clients := clientsContainer{
testing: true,
}
clients.Init(nil, nil, nil, nil, nil)
</s> add clients := newClientsContainer() </s> remove clients := clientsContainer{
testing: true,
}
clients.Init(nil, nil, nil, nil, nil)
</s> add clients := newClientsContainer() </s> remove func TestClients(t *testing.T) {
clients := clientsContainer{}
clients.testing = true
</s> add // newClientsContainer is a helper that creates a new clients container for
// tests.
func newClientsContainer() (c *clientsContainer) {
c = &clientsContainer{
testing: true,
}
c.Init(nil, nil, nil, nil, &filtering.Config{}) </s> remove clients.Init(nil, nil, nil, nil, nil)
</s> add return c
}
func TestClients(t *testing.T) {
clients := newClientsContainer() </s> remove ips, err := ss.resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME)
</s> add ss.log(log.DEBUG, "resolving %q", host)
ips, err := ss.resolver.LookupIP(context.Background(), qtypeToProto(qtype), host) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/home/clients_test.go |
clients := newClientsContainer() | <mask> })
<mask> }
<mask>
<mask> func TestClientsCustomUpstream(t *testing.T) {
<mask> clients := clientsContainer{
<mask> testing: true,
<mask> }
<mask> clients.Init(nil, nil, nil, nil, nil)
<mask>
<mask> // Add client with upstreams.
<mask> ok, err := clients.Add(&Client{
<mask> IDs: []string{"1.1.1.1", "1:2:3::4", "aa:aa:aa:aa:aa:aa"},
<mask> Name: "client1",
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove clients := clientsContainer{
testing: true,
}
clients.Init(nil, nil, nil, nil, nil)
</s> add clients := newClientsContainer() </s> remove clients := clientsContainer{
testing: true,
}
clients.Init(nil, nil, nil, nil, nil)
</s> add clients := newClientsContainer() </s> remove func TestClients(t *testing.T) {
clients := clientsContainer{}
clients.testing = true
</s> add // newClientsContainer is a helper that creates a new clients container for
// tests.
func newClientsContainer() (c *clientsContainer) {
c = &clientsContainer{
testing: true,
}
c.Init(nil, nil, nil, nil, &filtering.Config{}) </s> remove clients.Init(nil, nil, nil, nil, nil)
</s> add return c
}
func TestClients(t *testing.T) {
clients := newClientsContainer() </s> remove func TestSafeSearchCacheYandex(t *testing.T) {
const domain = "yandex.ru"
ss := newForTest(t, filtering.SafeSearchConfig{Enabled: false})
// Check host with disabled safesearch.
res, err := ss.CheckHost(domain, dns.TypeA)
</s> add func TestDefault_Update(t *testing.T) {
conf := testConf
ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/home/clients_test.go |
<mask>
<mask> type runtimeClientJSON struct {
<mask> WHOISInfo *RuntimeClientWHOISInfo `json:"whois_info"`
<mask>
<mask> Name string `json:"name"`
<mask> IP netip.Addr `json:"ip"`
<mask> Source clientSource `json:"source"`
<mask> }
<mask>
<mask> type clientListJSON struct {
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove // DefaultSafeSearch is the default safesearch struct.
type DefaultSafeSearch struct {
engine *urlfilter.DNSEngine
safeSearchCache cache.Cache
resolver filtering.Resolver
cacheTime time.Duration
</s> add // Default is the default safe search filter that uses filtering rules with the
// dnsrewrite modifier.
type Default struct {
// mu protects engine.
mu *sync.RWMutex
// engine is the filtering engine that contains the DNS rewrite rules.
// engine may be nil, which means that this safe search filter is disabled.
engine *urlfilter.DNSEngine
cache cache.Cache
resolver filtering.Resolver
logPrefix string
cacheTTL time.Duration </s> remove // SearchHost returns a replacement address for the search engine host.
SearchHost(host string, qtype uint16) (res *rules.DNSRewrite)
// CheckHost checks host with safe search engine.
</s> add // CheckHost checks host with safe search filter. CheckHost must be safe
// for concurrent use. qtype must be either [dns.TypeA] or [dns.TypeAAAA]. | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/home/clientshttp.go |
|
Name string `json:"name"` | <mask> type runtimeClientJSON struct {
<mask> WHOISInfo *RuntimeClientWHOISInfo `json:"whois_info"`
<mask>
<mask> IP netip.Addr `json:"ip"`
<mask> Source clientSource `json:"source"`
<mask> }
<mask>
<mask> type clientListJSON struct {
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove Name string `json:"name"`
</s> add </s> remove // SearchHost returns a replacement address for the search engine host.
SearchHost(host string, qtype uint16) (res *rules.DNSRewrite)
// CheckHost checks host with safe search engine.
</s> add // CheckHost checks host with safe search filter. CheckHost must be safe
// for concurrent use. qtype must be either [dns.TypeA] or [dns.TypeAAAA]. </s> remove // DefaultSafeSearch is the default safesearch struct.
type DefaultSafeSearch struct {
engine *urlfilter.DNSEngine
safeSearchCache cache.Cache
resolver filtering.Resolver
cacheTime time.Duration
</s> add // Default is the default safe search filter that uses filtering rules with the
// dnsrewrite modifier.
type Default struct {
// mu protects engine.
mu *sync.RWMutex
// engine is the filtering engine that contains the DNS rewrite rules.
// engine may be nil, which means that this safe search filter is disabled.
engine *urlfilter.DNSEngine
cache cache.Cache
resolver filtering.Resolver
logPrefix string
cacheTTL time.Duration | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/home/clientshttp.go |
func (clients *clientsContainer) jsonToClient(cj clientJSON) (c *Client, err error) { | <mask> _ = aghhttp.WriteJSONResponse(w, r, data)
<mask> }
<mask>
<mask> // jsonToClient converts JSON object to Client object.
<mask> func jsonToClient(cj clientJSON) (c *Client) {
<mask> var safeSearchConf filtering.SafeSearchConfig
<mask> if cj.SafeSearchConf != nil {
<mask> safeSearchConf = *cj.SafeSearchConf
<mask> } else {
<mask> // TODO(d.kolyshev): Remove after cleaning the deprecated
</s> Pull request 1803: 5685-fix-safe-search
Updates #5685.
Squashed commit of the following:
commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b
Author: Ainar Garipov <[email protected]>
Date: Thu Apr 6 14:09:44 2023 +0300
safesearch: imp tests, logs
commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:36:16 2023 +0300
safesearch: fix filters, logging
commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:24:47 2023 +0300
all: dry; fix logs
commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b
Author: Ainar Garipov <[email protected]>
Date: Wed Apr 5 20:01:08 2023 +0300
all: fix safe search update </s> remove safeSearchConf = filtering.SafeSearchConfig{Enabled: cj.SafeSearchEnabled}
</s> add safeSearchConf = filtering.SafeSearchConfig{
Enabled: cj.SafeSearchEnabled,
} </s> remove Upstreams: cj.Upstreams,
</s> add if safeSearchConf.Enabled {
err = c.setSafeSearch(
safeSearchConf,
clients.safeSearchCacheSize,
clients.safeSearchCacheTTL,
)
if err != nil {
return nil, fmt.Errorf("creating safesearch for client %q: %w", c.Name, err)
} </s> remove engine = urlfilter.NewDNSEngine(rs)
log.Info("safesearch: filter %d: reset %d rules", listID, engine.RulesCount)
return engine, nil
}
// type check
var _ filtering.SafeSearch = (*DefaultSafeSearch)(nil)
</s> add ss.engine = urlfilter.NewDNSEngine(rs) </s> remove // SearchHost implements the [filtering.SafeSearch] interface for *DefaultSafeSearch.
func (ss *DefaultSafeSearch) SearchHost(host string, qtype uint16) (res *rules.DNSRewrite) {
r, _ := ss.engine.MatchRequest(&urlfilter.DNSRequest{
Hostname: strings.ToLower(host),
DNSType: qtype,
})
rewritesRules := r.DNSRewrites()
if len(rewritesRules) > 0 {
return rewritesRules[0].DNSRewrite
}
</s> add ss.log(log.INFO, "reset %d rules", ss.engine.RulesCount) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0 | internal/home/clientshttp.go |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.