code_before
stringlengths 16
1.81M
| edits
stringlengths 4
328k
| next_edit
stringlengths 0
76.5k
| code_after
stringlengths 3
49.9M
| label_window
sequencelengths 4
1.81k
| instruction
stringlengths 20
51.9k
| html_url
stringlengths 74
116
| file_name
stringlengths 3
311
|
---|---|---|---|---|---|---|---|
summed["stats_period"] = "24 hours"
json, err := json.Marshal(summed)
if err != nil {
errortext := fmt.Sprintf("Unable to marshal status json: %s", err)
log.Println(errortext)
http.Error(w, errortext, 500)
return
}
w.Header().Set("Content-Type", "application/json")
| </s> remove summed["stats_period"] = "24 hours"
</s> add </s> remove json, err := json.Marshal(summed)
</s> add // read the body entirely
body, err := ioutil.ReadAll(resp.Body) </s> remove http.Error(w, errortext, 500)
</s> add http.Error(w, errortext, http.StatusBadGateway) </s> remove http.Error(w, errortext, 500)
</s> add http.Error(w, errortext, http.StatusBadGateway) </s> remove errortext := fmt.Sprintf("Unable to marshal status json: %s", err)
</s> add errortext := fmt.Sprintf("Couldn't read response body: %s", err) | errortext := fmt.Sprintf("Couldn't read response body: %s", err) | summed["stats_period"] = "24 hours"
json, err := json.Marshal(summed)
if err != nil {
errortext := fmt.Sprintf("Couldn't read response body: %s", err)
log.Println(errortext)
http.Error(w, errortext, 500)
return
}
w.Header().Set("Content-Type", "application/json") | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Implement online stats calculation in coredns plugin instead of scraping prometheus. | https://github.com/AdguardTeam/AdGuardHome/commit/37f6d38c498740c7c3db59c31da031cd5c305694 | control.go |
json, err := json.Marshal(summed)
if err != nil {
errortext := fmt.Sprintf("Unable to marshal status json: %s", err)
log.Println(errortext)
http.Error(w, errortext, 500)
return
}
w.Header().Set("Content-Type", "application/json")
_, err = w.Write(json)
if err != nil {
| </s> remove http.Error(w, errortext, 500)
</s> add http.Error(w, errortext, http.StatusBadGateway) </s> remove errortext := fmt.Sprintf("Unable to marshal status json: %s", err)
</s> add errortext := fmt.Sprintf("Couldn't read response body: %s", err) </s> remove json, err := json.Marshal(summed)
</s> add // read the body entirely
body, err := ioutil.ReadAll(resp.Body) </s> remove summed["stats_period"] = "24 hours"
</s> add </s> remove errortext := fmt.Sprintf("Unable to marshal status json: %s", err)
</s> add errortext := fmt.Sprintf("Couldn't read response body: %s", err) | http.Error(w, errortext, http.StatusBadGateway) | json, err := json.Marshal(summed)
if err != nil {
errortext := fmt.Sprintf("Unable to marshal status json: %s", err)
log.Println(errortext)
http.Error(w, errortext, http.StatusBadGateway)
return
}
w.Header().Set("Content-Type", "application/json")
_, err = w.Write(json)
if err != nil { | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Implement online stats calculation in coredns plugin instead of scraping prometheus. | https://github.com/AdguardTeam/AdGuardHome/commit/37f6d38c498740c7c3db59c31da031cd5c305694 | control.go |
return
}
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Content-Length", strconv.Itoa(len(body)))
w.WriteHeader(resp.StatusCode)
_, err = w.Write(body)
| </s> remove _, err = w.Write(json)
</s> add w.Header().Set("Content-Length", strconv.Itoa(len(body)))
w.WriteHeader(resp.StatusCode)
_, err = w.Write(body) </s> remove _, err = w.Write(json)
</s> add w.Header().Set("Content-Length", strconv.Itoa(len(body)))
w.WriteHeader(resp.StatusCode)
_, err = w.Write(body) </s> remove errortext := fmt.Sprintf("Unable to write response json: %s", err)
</s> add errortext := fmt.Sprintf("Couldn't write body: %s", err) </s> remove errortext := fmt.Sprintf("Unable to write response json: %s", err)
</s> add errortext := fmt.Sprintf("Couldn't write body: %s", err) | // forward body entirely with status code | return
}
// forward body entirely with status code
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Content-Length", strconv.Itoa(len(body)))
w.WriteHeader(resp.StatusCode)
_, err = w.Write(body) | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | Implement online stats calculation in coredns plugin instead of scraping prometheus. | https://github.com/AdguardTeam/AdGuardHome/commit/37f6d38c498740c7c3db59c31da031cd5c305694 | control.go |
http.Error(w, errortext, 500)
return
}
w.Header().Set("Content-Type", "application/json")
_, err = w.Write(json)
if err != nil {
errortext := fmt.Sprintf("Unable to write response json: %s", err)
log.Println(errortext)
http.Error(w, errortext, 500)
return
| </s> remove _, err = w.Write(json)
</s> add w.Header().Set("Content-Length", strconv.Itoa(len(body)))
w.WriteHeader(resp.StatusCode)
_, err = w.Write(body) </s> remove errortext := fmt.Sprintf("Unable to write response json: %s", err)
</s> add errortext := fmt.Sprintf("Couldn't write body: %s", err) </s> remove errortext := fmt.Sprintf("Unable to write response json: %s", err)
</s> add errortext := fmt.Sprintf("Couldn't write body: %s", err) </s> remove http.Error(w, errortext, 500)
</s> add http.Error(w, errortext, http.StatusBadGateway) </s> remove http.Error(w, errortext, 500)
</s> add http.Error(w, errortext, http.StatusBadGateway) | w.Header().Set("Content-Length", strconv.Itoa(len(body)))
w.WriteHeader(resp.StatusCode)
_, err = w.Write(body) | http.Error(w, errortext, 500)
return
}
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Content-Length", strconv.Itoa(len(body)))
w.WriteHeader(resp.StatusCode)
_, err = w.Write(body)
if err != nil {
errortext := fmt.Sprintf("Unable to write response json: %s", err)
log.Println(errortext)
http.Error(w, errortext, 500)
return | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Implement online stats calculation in coredns plugin instead of scraping prometheus. | https://github.com/AdguardTeam/AdGuardHome/commit/37f6d38c498740c7c3db59c31da031cd5c305694 | control.go |
}
w.Header().Set("Content-Type", "application/json")
_, err = w.Write(json)
if err != nil {
errortext := fmt.Sprintf("Unable to write response json: %s", err)
log.Println(errortext)
http.Error(w, errortext, 500)
return
}
}
| </s> remove errortext := fmt.Sprintf("Unable to write response json: %s", err)
</s> add errortext := fmt.Sprintf("Couldn't write body: %s", err) </s> remove _, err = w.Write(json)
</s> add w.Header().Set("Content-Length", strconv.Itoa(len(body)))
w.WriteHeader(resp.StatusCode)
_, err = w.Write(body) </s> remove _, err = w.Write(json)
</s> add w.Header().Set("Content-Length", strconv.Itoa(len(body)))
w.WriteHeader(resp.StatusCode)
_, err = w.Write(body) </s> remove http.Error(w, errortext, 500)
return
</s> add http.Error(w, errortext, http.StatusInternalServerError) </s> remove http.Error(w, errortext, 500)
</s> add http.Error(w, errortext, http.StatusBadGateway) | errortext := fmt.Sprintf("Couldn't write body: %s", err) | }
w.Header().Set("Content-Type", "application/json")
_, err = w.Write(json)
if err != nil {
errortext := fmt.Sprintf("Couldn't write body: %s", err)
log.Println(errortext)
http.Error(w, errortext, 500)
return
}
} | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Implement online stats calculation in coredns plugin instead of scraping prometheus. | https://github.com/AdguardTeam/AdGuardHome/commit/37f6d38c498740c7c3db59c31da031cd5c305694 | control.go |
_, err = w.Write(json)
if err != nil {
errortext := fmt.Sprintf("Unable to write response json: %s", err)
log.Println(errortext)
http.Error(w, errortext, 500)
return
}
}
func handleStatsHistory(w http.ResponseWriter, r *http.Request) {
// handle time unit and prepare our time window size
| </s> remove // handle time unit and prepare our time window size
now := time.Now()
timeUnitString := r.URL.Query().Get("time_unit")
var stats *periodicStats
var timeUnit time.Duration
switch timeUnitString {
case "seconds":
timeUnit = time.Second
stats = &statistics.PerSecond
case "minutes":
timeUnit = time.Minute
stats = &statistics.PerMinute
case "hours":
timeUnit = time.Hour
stats = &statistics.PerHour
case "days":
timeUnit = time.Hour * 24
stats = &statistics.PerDay
default:
http.Error(w, "Must specify valid time_unit parameter", 400)
return
}
// parse start and end time
startTime, err := time.Parse(time.RFC3339, r.URL.Query().Get("start_time"))
if err != nil {
errortext := fmt.Sprintf("Must specify valid start_time parameter: %s", err)
log.Println(errortext)
http.Error(w, errortext, 400)
return
}
endTime, err := time.Parse(time.RFC3339, r.URL.Query().Get("end_time"))
</s> add resp, err := client.Get("http://127.0.0.1:8618/stats_history?" + r.URL.RawQuery) </s> remove http.Error(w, errortext, 500)
return
</s> add http.Error(w, errortext, http.StatusInternalServerError) </s> remove errortext := fmt.Sprintf("Unable to write response json: %s", err)
</s> add errortext := fmt.Sprintf("Couldn't write body: %s", err) </s> remove errortext := fmt.Sprintf("Unable to write response json: %s", err)
</s> add errortext := fmt.Sprintf("Couldn't write body: %s", err) </s> remove return
</s> add | http.Error(w, errortext, http.StatusInternalServerError) | _, err = w.Write(json)
if err != nil {
errortext := fmt.Sprintf("Unable to write response json: %s", err)
log.Println(errortext)
http.Error(w, errortext, http.StatusInternalServerError)
http.Error(w, errortext, http.StatusInternalServerError)
}
}
func handleStatsHistory(w http.ResponseWriter, r *http.Request) {
// handle time unit and prepare our time window size | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Implement online stats calculation in coredns plugin instead of scraping prometheus. | https://github.com/AdguardTeam/AdGuardHome/commit/37f6d38c498740c7c3db59c31da031cd5c305694 | control.go |
}
}
func handleStatsHistory(w http.ResponseWriter, r *http.Request) {
// handle time unit and prepare our time window size
now := time.Now()
timeUnitString := r.URL.Query().Get("time_unit")
var stats *periodicStats
var timeUnit time.Duration
switch timeUnitString {
case "seconds":
timeUnit = time.Second
stats = &statistics.PerSecond
case "minutes":
timeUnit = time.Minute
stats = &statistics.PerMinute
case "hours":
timeUnit = time.Hour
stats = &statistics.PerHour
case "days":
timeUnit = time.Hour * 24
stats = &statistics.PerDay
default:
http.Error(w, "Must specify valid time_unit parameter", 400)
return
}
// parse start and end time
startTime, err := time.Parse(time.RFC3339, r.URL.Query().Get("start_time"))
if err != nil {
errortext := fmt.Sprintf("Must specify valid start_time parameter: %s", err)
log.Println(errortext)
http.Error(w, errortext, 400)
return
}
endTime, err := time.Parse(time.RFC3339, r.URL.Query().Get("end_time"))
if err != nil {
errortext := fmt.Sprintf("Must specify valid end_time parameter: %s", err)
log.Println(errortext)
http.Error(w, errortext, 400)
return
| </s> remove http.Error(w, errortext, 400)
return
}
// check if start and time times are within supported time range
timeRange := timeUnit * statsHistoryElements
if startTime.Add(timeRange).Before(now) {
http.Error(w, "start_time parameter is outside of supported range", 501)
return
}
if endTime.Add(timeRange).Before(now) {
http.Error(w, "end_time parameter is outside of supported range", 501)
</s> add http.Error(w, errortext, http.StatusBadGateway) </s> remove errortext := fmt.Sprintf("Must specify valid end_time parameter: %s", err)
</s> add errortext := fmt.Sprintf("Couldn't get stats_top from coredns: %T %s\n", err, err) </s> remove http.Error(w, errortext, 500)
return
</s> add http.Error(w, errortext, http.StatusInternalServerError) </s> remove histrical := generateMapFromStats(&statistics.PerHour, 0, 24)
// sum them up
summed := map[string]interface{}{}
for key, values := range histrical {
summedValue := 0.0
floats, ok := values.([]float64)
if !ok {
continue
}
for _, v := range floats {
summedValue += v
}
summed[key] = summedValue
</s> add resp, err := client.Get("http://127.0.0.1:8618/stats")
if err != nil {
errortext := fmt.Sprintf("Couldn't get stats_top from coredns: %T %s\n", err, err)
log.Println(errortext)
http.Error(w, errortext, http.StatusBadGateway)
return
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close() </s> remove http.Error(w, errortext, 500)
return
</s> add http.Error(w, errortext, http.StatusInternalServerError) | resp, err := client.Get("http://127.0.0.1:8618/stats_history?" + r.URL.RawQuery) | }
}
func handleStatsHistory(w http.ResponseWriter, r *http.Request) {
resp, err := client.Get("http://127.0.0.1:8618/stats_history?" + r.URL.RawQuery)
resp, err := client.Get("http://127.0.0.1:8618/stats_history?" + r.URL.RawQuery)
resp, err := client.Get("http://127.0.0.1:8618/stats_history?" + r.URL.RawQuery)
resp, err := client.Get("http://127.0.0.1:8618/stats_history?" + r.URL.RawQuery)
resp, err := client.Get("http://127.0.0.1:8618/stats_history?" + r.URL.RawQuery)
resp, err := client.Get("http://127.0.0.1:8618/stats_history?" + r.URL.RawQuery)
resp, err := client.Get("http://127.0.0.1:8618/stats_history?" + r.URL.RawQuery)
resp, err := client.Get("http://127.0.0.1:8618/stats_history?" + r.URL.RawQuery)
resp, err := client.Get("http://127.0.0.1:8618/stats_history?" + r.URL.RawQuery)
resp, err := client.Get("http://127.0.0.1:8618/stats_history?" + r.URL.RawQuery)
resp, err := client.Get("http://127.0.0.1:8618/stats_history?" + r.URL.RawQuery)
resp, err := client.Get("http://127.0.0.1:8618/stats_history?" + r.URL.RawQuery)
resp, err := client.Get("http://127.0.0.1:8618/stats_history?" + r.URL.RawQuery)
resp, err := client.Get("http://127.0.0.1:8618/stats_history?" + r.URL.RawQuery)
resp, err := client.Get("http://127.0.0.1:8618/stats_history?" + r.URL.RawQuery)
resp, err := client.Get("http://127.0.0.1:8618/stats_history?" + r.URL.RawQuery)
resp, err := client.Get("http://127.0.0.1:8618/stats_history?" + r.URL.RawQuery)
resp, err := client.Get("http://127.0.0.1:8618/stats_history?" + r.URL.RawQuery)
resp, err := client.Get("http://127.0.0.1:8618/stats_history?" + r.URL.RawQuery)
resp, err := client.Get("http://127.0.0.1:8618/stats_history?" + r.URL.RawQuery)
resp, err := client.Get("http://127.0.0.1:8618/stats_history?" + r.URL.RawQuery)
resp, err := client.Get("http://127.0.0.1:8618/stats_history?" + r.URL.RawQuery)
resp, err := client.Get("http://127.0.0.1:8618/stats_history?" + r.URL.RawQuery)
resp, err := client.Get("http://127.0.0.1:8618/stats_history?" + r.URL.RawQuery)
resp, err := client.Get("http://127.0.0.1:8618/stats_history?" + r.URL.RawQuery)
resp, err := client.Get("http://127.0.0.1:8618/stats_history?" + r.URL.RawQuery)
resp, err := client.Get("http://127.0.0.1:8618/stats_history?" + r.URL.RawQuery)
resp, err := client.Get("http://127.0.0.1:8618/stats_history?" + r.URL.RawQuery)
resp, err := client.Get("http://127.0.0.1:8618/stats_history?" + r.URL.RawQuery)
resp, err := client.Get("http://127.0.0.1:8618/stats_history?" + r.URL.RawQuery)
resp, err := client.Get("http://127.0.0.1:8618/stats_history?" + r.URL.RawQuery)
resp, err := client.Get("http://127.0.0.1:8618/stats_history?" + r.URL.RawQuery)
if err != nil {
errortext := fmt.Sprintf("Must specify valid end_time parameter: %s", err)
log.Println(errortext)
http.Error(w, errortext, 400)
return | [
"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",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Implement online stats calculation in coredns plugin instead of scraping prometheus. | https://github.com/AdguardTeam/AdGuardHome/commit/37f6d38c498740c7c3db59c31da031cd5c305694 | control.go |
return
}
endTime, err := time.Parse(time.RFC3339, r.URL.Query().Get("end_time"))
if err != nil {
errortext := fmt.Sprintf("Must specify valid end_time parameter: %s", err)
log.Println(errortext)
http.Error(w, errortext, 400)
return
}
| </s> remove // handle time unit and prepare our time window size
now := time.Now()
timeUnitString := r.URL.Query().Get("time_unit")
var stats *periodicStats
var timeUnit time.Duration
switch timeUnitString {
case "seconds":
timeUnit = time.Second
stats = &statistics.PerSecond
case "minutes":
timeUnit = time.Minute
stats = &statistics.PerMinute
case "hours":
timeUnit = time.Hour
stats = &statistics.PerHour
case "days":
timeUnit = time.Hour * 24
stats = &statistics.PerDay
default:
http.Error(w, "Must specify valid time_unit parameter", 400)
return
}
// parse start and end time
startTime, err := time.Parse(time.RFC3339, r.URL.Query().Get("start_time"))
if err != nil {
errortext := fmt.Sprintf("Must specify valid start_time parameter: %s", err)
log.Println(errortext)
http.Error(w, errortext, 400)
return
}
endTime, err := time.Parse(time.RFC3339, r.URL.Query().Get("end_time"))
</s> add resp, err := client.Get("http://127.0.0.1:8618/stats_history?" + r.URL.RawQuery) </s> remove http.Error(w, errortext, 400)
return
}
// check if start and time times are within supported time range
timeRange := timeUnit * statsHistoryElements
if startTime.Add(timeRange).Before(now) {
http.Error(w, "start_time parameter is outside of supported range", 501)
return
}
if endTime.Add(timeRange).Before(now) {
http.Error(w, "end_time parameter is outside of supported range", 501)
</s> add http.Error(w, errortext, http.StatusBadGateway) </s> remove err := runningTop.addEntry(entry, now)
</s> add if len(entry.Question) == 0 {
log.Printf("entry question is absent, skipping")
return nil
}
if entry.Time.After(now) {
log.Printf("t %v vs %v is in the future, ignoring", entry.Time, now)
return nil
}
q := new(dns.Msg)
if err := q.Unpack(entry.Question); err != nil {
log.Printf("failed to unpack dns message question: %s", err)
return err
}
if len(q.Question) != 1 {
log.Printf("malformed dns message, has no questions, skipping")
return nil
}
err := runningTop.addEntry(entry, q, now) </s> remove log.Printf("Loading top from querylog")
err := loadTopFromFiles()
</s> add log.Printf("Loading stats from querylog")
err := fillStatsFromQueryLog() </s> remove errortext := fmt.Sprintf("Unable to write response json: %s", err)
</s> add errortext := fmt.Sprintf("Couldn't write body: %s", err) | errortext := fmt.Sprintf("Couldn't get stats_top from coredns: %T %s\n", err, err) | return
}
endTime, err := time.Parse(time.RFC3339, r.URL.Query().Get("end_time"))
if err != nil {
errortext := fmt.Sprintf("Couldn't get stats_top from coredns: %T %s\n", err, err)
log.Println(errortext)
http.Error(w, errortext, 400)
return
}
| [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Implement online stats calculation in coredns plugin instead of scraping prometheus. | https://github.com/AdguardTeam/AdGuardHome/commit/37f6d38c498740c7c3db59c31da031cd5c305694 | control.go |
endTime, err := time.Parse(time.RFC3339, r.URL.Query().Get("end_time"))
if err != nil {
errortext := fmt.Sprintf("Must specify valid end_time parameter: %s", err)
log.Println(errortext)
http.Error(w, errortext, 400)
return
}
// check if start and time times are within supported time range
timeRange := timeUnit * statsHistoryElements
if startTime.Add(timeRange).Before(now) {
http.Error(w, "start_time parameter is outside of supported range", 501)
return
}
if endTime.Add(timeRange).Before(now) {
http.Error(w, "end_time parameter is outside of supported range", 501)
return
}
// calculate start and end of our array
// basically it's how many hours/minutes/etc have passed since now
| </s> remove
// calculate start and end of our array
// basically it's how many hours/minutes/etc have passed since now
start := int(now.Sub(endTime) / timeUnit)
end := int(now.Sub(startTime) / timeUnit)
// swap them around if they're inverted
if start > end {
start, end = end, start
</s> add if resp != nil && resp.Body != nil {
defer resp.Body.Close() </s> remove // handle time unit and prepare our time window size
now := time.Now()
timeUnitString := r.URL.Query().Get("time_unit")
var stats *periodicStats
var timeUnit time.Duration
switch timeUnitString {
case "seconds":
timeUnit = time.Second
stats = &statistics.PerSecond
case "minutes":
timeUnit = time.Minute
stats = &statistics.PerMinute
case "hours":
timeUnit = time.Hour
stats = &statistics.PerHour
case "days":
timeUnit = time.Hour * 24
stats = &statistics.PerDay
default:
http.Error(w, "Must specify valid time_unit parameter", 400)
return
}
// parse start and end time
startTime, err := time.Parse(time.RFC3339, r.URL.Query().Get("start_time"))
if err != nil {
errortext := fmt.Sprintf("Must specify valid start_time parameter: %s", err)
log.Println(errortext)
http.Error(w, errortext, 400)
return
}
endTime, err := time.Parse(time.RFC3339, r.URL.Query().Get("end_time"))
</s> add resp, err := client.Get("http://127.0.0.1:8618/stats_history?" + r.URL.RawQuery) </s> remove errortext := fmt.Sprintf("Must specify valid end_time parameter: %s", err)
</s> add errortext := fmt.Sprintf("Couldn't get stats_top from coredns: %T %s\n", err, err) </s> remove http.Error(w, errortext, 500)
return
</s> add http.Error(w, errortext, http.StatusInternalServerError) </s> remove data := generateMapFromStats(stats, start, end)
json, err := json.Marshal(data)
</s> add // read the body entirely
body, err := ioutil.ReadAll(resp.Body) | http.Error(w, errortext, http.StatusBadGateway) | endTime, err := time.Parse(time.RFC3339, r.URL.Query().Get("end_time"))
if err != nil {
errortext := fmt.Sprintf("Must specify valid end_time parameter: %s", err)
log.Println(errortext)
http.Error(w, errortext, http.StatusBadGateway)
http.Error(w, errortext, http.StatusBadGateway)
http.Error(w, errortext, http.StatusBadGateway)
http.Error(w, errortext, http.StatusBadGateway)
http.Error(w, errortext, http.StatusBadGateway)
http.Error(w, errortext, http.StatusBadGateway)
http.Error(w, errortext, http.StatusBadGateway)
http.Error(w, errortext, http.StatusBadGateway)
http.Error(w, errortext, http.StatusBadGateway)
http.Error(w, errortext, http.StatusBadGateway)
http.Error(w, errortext, http.StatusBadGateway)
http.Error(w, errortext, http.StatusBadGateway)
return
}
// calculate start and end of our array
// basically it's how many hours/minutes/etc have passed since now | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Implement online stats calculation in coredns plugin instead of scraping prometheus. | https://github.com/AdguardTeam/AdGuardHome/commit/37f6d38c498740c7c3db59c31da031cd5c305694 | control.go |
if endTime.Add(timeRange).Before(now) {
http.Error(w, "end_time parameter is outside of supported range", 501)
return
}
// calculate start and end of our array
// basically it's how many hours/minutes/etc have passed since now
start := int(now.Sub(endTime) / timeUnit)
end := int(now.Sub(startTime) / timeUnit)
// swap them around if they're inverted
if start > end {
start, end = end, start
}
data := generateMapFromStats(stats, start, end)
json, err := json.Marshal(data)
if err != nil {
| </s> remove http.Error(w, errortext, 400)
return
}
// check if start and time times are within supported time range
timeRange := timeUnit * statsHistoryElements
if startTime.Add(timeRange).Before(now) {
http.Error(w, "start_time parameter is outside of supported range", 501)
return
}
if endTime.Add(timeRange).Before(now) {
http.Error(w, "end_time parameter is outside of supported range", 501)
</s> add http.Error(w, errortext, http.StatusBadGateway) </s> remove data := generateMapFromStats(stats, start, end)
json, err := json.Marshal(data)
</s> add // read the body entirely
body, err := ioutil.ReadAll(resp.Body) </s> remove errortext := fmt.Sprintf("Unable to marshal status json: %s", err)
</s> add errortext := fmt.Sprintf("Couldn't read response body: %s", err) </s> remove // handle time unit and prepare our time window size
now := time.Now()
timeUnitString := r.URL.Query().Get("time_unit")
var stats *periodicStats
var timeUnit time.Duration
switch timeUnitString {
case "seconds":
timeUnit = time.Second
stats = &statistics.PerSecond
case "minutes":
timeUnit = time.Minute
stats = &statistics.PerMinute
case "hours":
timeUnit = time.Hour
stats = &statistics.PerHour
case "days":
timeUnit = time.Hour * 24
stats = &statistics.PerDay
default:
http.Error(w, "Must specify valid time_unit parameter", 400)
return
}
// parse start and end time
startTime, err := time.Parse(time.RFC3339, r.URL.Query().Get("start_time"))
if err != nil {
errortext := fmt.Sprintf("Must specify valid start_time parameter: %s", err)
log.Println(errortext)
http.Error(w, errortext, 400)
return
}
endTime, err := time.Parse(time.RFC3339, r.URL.Query().Get("end_time"))
</s> add resp, err := client.Get("http://127.0.0.1:8618/stats_history?" + r.URL.RawQuery) </s> remove histrical := generateMapFromStats(&statistics.PerHour, 0, 24)
// sum them up
summed := map[string]interface{}{}
for key, values := range histrical {
summedValue := 0.0
floats, ok := values.([]float64)
if !ok {
continue
}
for _, v := range floats {
summedValue += v
}
summed[key] = summedValue
</s> add resp, err := client.Get("http://127.0.0.1:8618/stats")
if err != nil {
errortext := fmt.Sprintf("Couldn't get stats_top from coredns: %T %s\n", err, err)
log.Println(errortext)
http.Error(w, errortext, http.StatusBadGateway)
return
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close() | if resp != nil && resp.Body != nil {
defer resp.Body.Close() | if endTime.Add(timeRange).Before(now) {
http.Error(w, "end_time parameter is outside of supported range", 501)
return
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
data := generateMapFromStats(stats, start, end)
json, err := json.Marshal(data)
if err != nil { | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Implement online stats calculation in coredns plugin instead of scraping prometheus. | https://github.com/AdguardTeam/AdGuardHome/commit/37f6d38c498740c7c3db59c31da031cd5c305694 | control.go |
if start > end {
start, end = end, start
}
data := generateMapFromStats(stats, start, end)
json, err := json.Marshal(data)
if err != nil {
errortext := fmt.Sprintf("Unable to marshal status json: %s", err)
log.Println(errortext)
http.Error(w, errortext, 500)
return
| </s> remove
// calculate start and end of our array
// basically it's how many hours/minutes/etc have passed since now
start := int(now.Sub(endTime) / timeUnit)
end := int(now.Sub(startTime) / timeUnit)
// swap them around if they're inverted
if start > end {
start, end = end, start
</s> add if resp != nil && resp.Body != nil {
defer resp.Body.Close() </s> remove errortext := fmt.Sprintf("Unable to marshal status json: %s", err)
</s> add errortext := fmt.Sprintf("Couldn't read response body: %s", err) </s> remove http.Error(w, errortext, 500)
</s> add http.Error(w, errortext, http.StatusBadGateway) </s> remove http.Error(w, errortext, 500)
</s> add http.Error(w, errortext, http.StatusBadGateway) </s> remove errortext := fmt.Sprintf("Unable to marshal status json: %s", err)
</s> add errortext := fmt.Sprintf("Couldn't read response body: %s", err) | // read the body entirely
body, err := ioutil.ReadAll(resp.Body) | if start > end {
start, end = end, start
}
// read the body entirely
body, err := ioutil.ReadAll(resp.Body)
// read the body entirely
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
errortext := fmt.Sprintf("Unable to marshal status json: %s", err)
log.Println(errortext)
http.Error(w, errortext, 500)
return | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Implement online stats calculation in coredns plugin instead of scraping prometheus. | https://github.com/AdguardTeam/AdGuardHome/commit/37f6d38c498740c7c3db59c31da031cd5c305694 | control.go |
data := generateMapFromStats(stats, start, end)
json, err := json.Marshal(data)
if err != nil {
errortext := fmt.Sprintf("Unable to marshal status json: %s", err)
log.Println(errortext)
http.Error(w, errortext, 500)
return
}
w.Header().Set("Content-Type", "application/json")
| </s> remove data := generateMapFromStats(stats, start, end)
json, err := json.Marshal(data)
</s> add // read the body entirely
body, err := ioutil.ReadAll(resp.Body) </s> remove http.Error(w, errortext, 500)
</s> add http.Error(w, errortext, http.StatusBadGateway) </s> remove http.Error(w, errortext, 500)
</s> add http.Error(w, errortext, http.StatusBadGateway) </s> remove errortext := fmt.Sprintf("Unable to marshal status json: %s", err)
</s> add errortext := fmt.Sprintf("Couldn't read response body: %s", err) </s> remove
// calculate start and end of our array
// basically it's how many hours/minutes/etc have passed since now
start := int(now.Sub(endTime) / timeUnit)
end := int(now.Sub(startTime) / timeUnit)
// swap them around if they're inverted
if start > end {
start, end = end, start
</s> add if resp != nil && resp.Body != nil {
defer resp.Body.Close() | errortext := fmt.Sprintf("Couldn't read response body: %s", err) |
data := generateMapFromStats(stats, start, end)
json, err := json.Marshal(data)
if err != nil {
errortext := fmt.Sprintf("Couldn't read response body: %s", err)
log.Println(errortext)
http.Error(w, errortext, 500)
return
}
w.Header().Set("Content-Type", "application/json") | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Implement online stats calculation in coredns plugin instead of scraping prometheus. | https://github.com/AdguardTeam/AdGuardHome/commit/37f6d38c498740c7c3db59c31da031cd5c305694 | control.go |
json, err := json.Marshal(data)
if err != nil {
errortext := fmt.Sprintf("Unable to marshal status json: %s", err)
log.Println(errortext)
http.Error(w, errortext, 500)
return
}
w.Header().Set("Content-Type", "application/json")
_, err = w.Write(json)
if err != nil {
| </s> remove http.Error(w, errortext, 500)
</s> add http.Error(w, errortext, http.StatusBadGateway) </s> remove errortext := fmt.Sprintf("Unable to marshal status json: %s", err)
</s> add errortext := fmt.Sprintf("Couldn't read response body: %s", err) </s> remove errortext := fmt.Sprintf("Unable to marshal status json: %s", err)
</s> add errortext := fmt.Sprintf("Couldn't read response body: %s", err) </s> remove data := generateMapFromStats(stats, start, end)
json, err := json.Marshal(data)
</s> add // read the body entirely
body, err := ioutil.ReadAll(resp.Body) </s> remove errortext := fmt.Sprintf("Unable to write response json: %s", err)
</s> add errortext := fmt.Sprintf("Couldn't write body: %s", err) | http.Error(w, errortext, http.StatusBadGateway) | json, err := json.Marshal(data)
if err != nil {
errortext := fmt.Sprintf("Unable to marshal status json: %s", err)
log.Println(errortext)
http.Error(w, errortext, http.StatusBadGateway)
return
}
w.Header().Set("Content-Type", "application/json")
_, err = w.Write(json)
if err != nil { | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Implement online stats calculation in coredns plugin instead of scraping prometheus. | https://github.com/AdguardTeam/AdGuardHome/commit/37f6d38c498740c7c3db59c31da031cd5c305694 | control.go |
http.Error(w, errortext, http.StatusBadGateway)
return
}
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Content-Length", strconv.Itoa(len(body)))
w.WriteHeader(resp.StatusCode)
_, err = w.Write(body)
if err != nil {
errortext := fmt.Sprintf("Couldn't write body: %s", err)
| </s> remove _, err = w.Write(json)
</s> add w.Header().Set("Content-Length", strconv.Itoa(len(body)))
w.WriteHeader(resp.StatusCode)
_, err = w.Write(body) </s> remove _, err = w.Write(json)
</s> add w.Header().Set("Content-Length", strconv.Itoa(len(body)))
w.WriteHeader(resp.StatusCode)
_, err = w.Write(body) </s> remove errortext := fmt.Sprintf("Unable to write response json: %s", err)
</s> add errortext := fmt.Sprintf("Couldn't write body: %s", err) </s> remove errortext := fmt.Sprintf("Unable to write response json: %s", err)
</s> add errortext := fmt.Sprintf("Couldn't write body: %s", err) | // forward body entirely with status code | http.Error(w, errortext, http.StatusBadGateway)
return
}
// forward body entirely with status code
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Content-Length", strconv.Itoa(len(body)))
w.WriteHeader(resp.StatusCode)
_, err = w.Write(body)
if err != nil {
errortext := fmt.Sprintf("Couldn't write body: %s", err) | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Implement online stats calculation in coredns plugin instead of scraping prometheus. | https://github.com/AdguardTeam/AdGuardHome/commit/37f6d38c498740c7c3db59c31da031cd5c305694 | control.go |
http.Error(w, errortext, 500)
return
}
w.Header().Set("Content-Type", "application/json")
_, err = w.Write(json)
if err != nil {
errortext := fmt.Sprintf("Unable to write response json: %s", err)
log.Println(errortext)
http.Error(w, errortext, 500)
return
| </s> | w.Header().Set("Content-Length", strconv.Itoa(len(body)))
w.WriteHeader(resp.StatusCode)
_, err = w.Write(body) | http.Error(w, errortext, 500)
return
}
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Content-Length", strconv.Itoa(len(body)))
w.WriteHeader(resp.StatusCode)
_, err = w.Write(body)
if err != nil {
errortext := fmt.Sprintf("Unable to write response json: %s", err)
log.Println(errortext)
http.Error(w, errortext, 500)
return | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Implement online stats calculation in coredns plugin instead of scraping prometheus. | https://github.com/AdguardTeam/AdGuardHome/commit/37f6d38c498740c7c3db59c31da031cd5c305694 | control.go |
}
w.Header().Set("Content-Type", "application/json")
_, err = w.Write(json)
if err != nil {
errortext := fmt.Sprintf("Unable to write response json: %s", err)
log.Println(errortext)
http.Error(w, errortext, 500)
return
}
}
| </s> | errortext := fmt.Sprintf("Couldn't write body: %s", err) | }
w.Header().Set("Content-Type", "application/json")
_, err = w.Write(json)
if err != nil {
errortext := fmt.Sprintf("Couldn't write body: %s", err)
log.Println(errortext)
http.Error(w, errortext, 500)
return
}
} | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Implement online stats calculation in coredns plugin instead of scraping prometheus. | https://github.com/AdguardTeam/AdGuardHome/commit/37f6d38c498740c7c3db59c31da031cd5c305694 | control.go |
_, err = w.Write(json)
if err != nil {
errortext := fmt.Sprintf("Unable to write response json: %s", err)
log.Println(errortext)
http.Error(w, errortext, 500)
return
}
}
func handleQueryLog(w http.ResponseWriter, r *http.Request) {
isDownload := r.URL.Query().Get("download") != ""
| </s> remove http.Error(w, errortext, 500)
return
</s> add http.Error(w, errortext, http.StatusInternalServerError) </s> remove errortext := fmt.Sprintf("Unable to write response json: %s", err)
</s> add errortext := fmt.Sprintf("Couldn't write body: %s", err) </s> remove errortext := fmt.Sprintf("Unable to write response json: %s", err)
</s> add errortext := fmt.Sprintf("Couldn't write body: %s", err) </s> remove _, err = w.Write(json)
</s> add w.Header().Set("Content-Length", strconv.Itoa(len(body)))
w.WriteHeader(resp.StatusCode)
_, err = w.Write(body) </s> remove _, err = w.Write(json)
</s> add w.Header().Set("Content-Length", strconv.Itoa(len(body)))
w.WriteHeader(resp.StatusCode)
_, err = w.Write(body) | http.Error(w, errortext, http.StatusInternalServerError) | _, err = w.Write(json)
if err != nil {
errortext := fmt.Sprintf("Unable to write response json: %s", err)
log.Println(errortext)
http.Error(w, errortext, http.StatusInternalServerError)
http.Error(w, errortext, http.StatusInternalServerError)
}
}
func handleQueryLog(w http.ResponseWriter, r *http.Request) {
isDownload := r.URL.Query().Get("download") != "" | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Implement online stats calculation in coredns plugin instead of scraping prometheus. | https://github.com/AdguardTeam/AdGuardHome/commit/37f6d38c498740c7c3db59c31da031cd5c305694 | control.go |
ParentalBlockHost: "family.block.dns.adguard.com",
BlockedTTL: 3600, // in seconds
}
func newDNSCounter(name string, help string) prometheus.Counter {
return prometheus.NewCounter(prometheus.CounterOpts{
Namespace: plugin.Namespace,
Subsystem: "dnsfilter",
Name: name,
Help: help,
})
}
var (
requests = newDNSCounter("requests_total", "Count of requests seen by dnsfilter.")
filtered = newDNSCounter("filtered_total", "Count of requests filtered by dnsfilter.")
filteredLists = newDNSCounter("filtered_lists_total", "Count of requests filtered by dnsfilter using lists.")
filteredSafebrowsing = newDNSCounter("filtered_safebrowsing_total", "Count of requests filtered by dnsfilter using safebrowsing.")
filteredParental = newDNSCounter("filtered_parental_total", "Count of requests filtered by dnsfilter using parental.")
filteredInvalid = newDNSCounter("filtered_invalid_total", "Count of requests filtered by dnsfilter because they were invalid.")
whitelisted = newDNSCounter("whitelisted_total", "Count of requests not filtered by dnsfilter because they are whitelisted.")
safesearch = newDNSCounter("safesearch_total", "Count of requests replaced by dnsfilter safesearch.")
errorsTotal = newDNSCounter("errors_total", "Count of requests that dnsfilter couldn't process because of transitive errors.")
)
//
// coredns handling functions
//
func setupPlugin(c *caddy.Controller) (*plug, error) {
// create new Plugin and copy default values
| </s> remove http.Error(w, errortext, 400)
return
}
// check if start and time times are within supported time range
timeRange := timeUnit * statsHistoryElements
if startTime.Add(timeRange).Before(now) {
http.Error(w, "start_time parameter is outside of supported range", 501)
return
}
if endTime.Add(timeRange).Before(now) {
http.Error(w, "end_time parameter is outside of supported range", 501)
</s> add http.Error(w, errortext, http.StatusBadGateway) </s> remove
// calculate start and end of our array
// basically it's how many hours/minutes/etc have passed since now
start := int(now.Sub(endTime) / timeUnit)
end := int(now.Sub(startTime) / timeUnit)
// swap them around if they're inverted
if start > end {
start, end = end, start
</s> add if resp != nil && resp.Body != nil {
defer resp.Body.Close() </s> remove // handle time unit and prepare our time window size
now := time.Now()
timeUnitString := r.URL.Query().Get("time_unit")
var stats *periodicStats
var timeUnit time.Duration
switch timeUnitString {
case "seconds":
timeUnit = time.Second
stats = &statistics.PerSecond
case "minutes":
timeUnit = time.Minute
stats = &statistics.PerMinute
case "hours":
timeUnit = time.Hour
stats = &statistics.PerHour
case "days":
timeUnit = time.Hour * 24
stats = &statistics.PerDay
default:
http.Error(w, "Must specify valid time_unit parameter", 400)
return
}
// parse start and end time
startTime, err := time.Parse(time.RFC3339, r.URL.Query().Get("start_time"))
if err != nil {
errortext := fmt.Sprintf("Must specify valid start_time parameter: %s", err)
log.Println(errortext)
http.Error(w, errortext, 400)
return
}
endTime, err := time.Parse(time.RFC3339, r.URL.Query().Get("end_time"))
</s> add resp, err := client.Get("http://127.0.0.1:8618/stats_history?" + r.URL.RawQuery) </s> remove values := logBuffer
</s> add values = logBuffer </s> remove http.Error(w, errortext, 500)
return
</s> add http.Error(w, errortext, http.StatusInternalServerError) | ParentalBlockHost: "family.block.dns.adguard.com",
BlockedTTL: 3600, // in seconds
}
//
// coredns handling functions
//
func setupPlugin(c *caddy.Controller) (*plug, error) {
// create new Plugin and copy default values | [
"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",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Implement online stats calculation in coredns plugin instead of scraping prometheus. | https://github.com/AdguardTeam/AdGuardHome/commit/37f6d38c498740c7c3db59c31da031cd5c305694 | coredns_plugin/coredns_plugin.go |
|
return nil, err
}
}
log.Printf("Loading top from querylog")
err := loadTopFromFiles()
if err != nil {
log.Printf("Failed to load top from querylog: %s", err)
return nil, err
}
| </s> remove log.Printf("Failed to load top from querylog: %s", err)
</s> add log.Printf("Failed to load stats from querylog: %s", err) </s> remove err = runningTop.addEntry(&entry, now)
</s> add err = runningTop.addEntry(&entry, question, now) </s> remove errortext := fmt.Sprintf("Must specify valid end_time parameter: %s", err)
</s> add errortext := fmt.Sprintf("Couldn't get stats_top from coredns: %T %s\n", err, err) </s> remove err := runningTop.addEntry(entry, now)
</s> add if len(entry.Question) == 0 {
log.Printf("entry question is absent, skipping")
return nil
}
if entry.Time.After(now) {
log.Printf("t %v vs %v is in the future, ignoring", entry.Time, now)
return nil
}
q := new(dns.Msg)
if err := q.Unpack(entry.Question); err != nil {
log.Printf("failed to unpack dns message question: %s", err)
return err
}
if len(q.Question) != 1 {
log.Printf("malformed dns message, has no questions, skipping")
return nil
}
err := runningTop.addEntry(entry, q, now) </s> remove errortext := fmt.Sprintf("Unable to write response json: %s", err)
</s> add errortext := fmt.Sprintf("Couldn't write body: %s", err) | log.Printf("Loading stats from querylog")
err := fillStatsFromQueryLog() | return nil, err
}
}
log.Printf("Loading stats from querylog")
err := fillStatsFromQueryLog()
log.Printf("Loading stats from querylog")
err := fillStatsFromQueryLog()
if err != nil {
log.Printf("Failed to load top from querylog: %s", err)
return nil, err
}
| [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Implement online stats calculation in coredns plugin instead of scraping prometheus. | https://github.com/AdguardTeam/AdGuardHome/commit/37f6d38c498740c7c3db59c31da031cd5c305694 | coredns_plugin/coredns_plugin.go |
log.Printf("Loading top from querylog")
err := loadTopFromFiles()
if err != nil {
log.Printf("Failed to load top from querylog: %s", err)
return nil, err
}
if p.settings.QueryLogEnabled {
onceQueryLog.Do(func() {
| </s> remove log.Printf("Loading top from querylog")
err := loadTopFromFiles()
</s> add log.Printf("Loading stats from querylog")
err := fillStatsFromQueryLog() </s> remove err = runningTop.addEntry(&entry, now)
</s> add err = runningTop.addEntry(&entry, question, now) </s> remove err := runningTop.addEntry(entry, now)
</s> add if len(entry.Question) == 0 {
log.Printf("entry question is absent, skipping")
return nil
}
if entry.Time.After(now) {
log.Printf("t %v vs %v is in the future, ignoring", entry.Time, now)
return nil
}
q := new(dns.Msg)
if err := q.Unpack(entry.Question); err != nil {
log.Printf("failed to unpack dns message question: %s", err)
return err
}
if len(q.Question) != 1 {
log.Printf("malformed dns message, has no questions, skipping")
return nil
}
err := runningTop.addEntry(entry, q, now) </s> remove errortext := fmt.Sprintf("Must specify valid end_time parameter: %s", err)
</s> add errortext := fmt.Sprintf("Couldn't get stats_top from coredns: %T %s\n", err, err) </s> remove histrical := generateMapFromStats(&statistics.PerHour, 0, 24)
// sum them up
summed := map[string]interface{}{}
for key, values := range histrical {
summedValue := 0.0
floats, ok := values.([]float64)
if !ok {
continue
}
for _, v := range floats {
summedValue += v
}
summed[key] = summedValue
</s> add resp, err := client.Get("http://127.0.0.1:8618/stats")
if err != nil {
errortext := fmt.Sprintf("Couldn't get stats_top from coredns: %T %s\n", err, err)
log.Println(errortext)
http.Error(w, errortext, http.StatusBadGateway)
return
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close() | log.Printf("Failed to load stats from querylog: %s", err) |
log.Printf("Loading top from querylog")
err := loadTopFromFiles()
if err != nil {
log.Printf("Failed to load stats from querylog: %s", err)
return nil, err
}
if p.settings.QueryLogEnabled {
onceQueryLog.Do(func() { | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Implement online stats calculation in coredns plugin instead of scraping prometheus. | https://github.com/AdguardTeam/AdGuardHome/commit/37f6d38c498740c7c3db59c31da031cd5c305694 | coredns_plugin/coredns_plugin.go |
x.MustRegister(whitelisted)
x.MustRegister(safesearch)
x.MustRegister(errorsTotal)
x.MustRegister(p)
}
return nil
})
c.OnShutdown(p.onShutdown)
| </s> remove err := runningTop.addEntry(entry, now)
</s> add if len(entry.Question) == 0 {
log.Printf("entry question is absent, skipping")
return nil
}
if entry.Time.After(now) {
log.Printf("t %v vs %v is in the future, ignoring", entry.Time, now)
return nil
}
q := new(dns.Msg)
if err := q.Unpack(entry.Question); err != nil {
log.Printf("failed to unpack dns message question: %s", err)
return err
}
if len(q.Question) != 1 {
log.Printf("malformed dns message, has no questions, skipping")
return nil
}
err := runningTop.addEntry(entry, q, now) </s> remove log.Printf("file \"%s\": read %d entries", file, i)
</s> add elapsed := time.Since(now)
log.Printf("file \"%s\": read %d entries in %v, %v/entry", file, i, elapsed, elapsed/time.Duration(i)) </s> remove func loadTopFromFiles() error {
</s> add func fillStatsFromQueryLog() error { </s> remove q := new(dns.Msg)
if err := q.Unpack(entry.Question); err != nil {
log.Printf("failed to unpack dns message question: %s", err)
return err
}
if len(q.Question) != 1 {
log.Printf("malformed dns message, has no questions, skipping")
return nil
}
</s> add </s> remove log.Printf("Loading top from querylog")
err := loadTopFromFiles()
</s> add log.Printf("Loading stats from querylog")
err := fillStatsFromQueryLog() | x.MustRegister(elapsedTime) | x.MustRegister(whitelisted)
x.MustRegister(safesearch)
x.MustRegister(errorsTotal)
x.MustRegister(elapsedTime)
x.MustRegister(p)
}
return nil
})
c.OnShutdown(p.onShutdown) | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Implement online stats calculation in coredns plugin instead of scraping prometheus. | https://github.com/AdguardTeam/AdGuardHome/commit/37f6d38c498740c7c3db59c31da031cd5c305694 | coredns_plugin/coredns_plugin.go |
// log
if p.settings.QueryLogEnabled {
logRequest(r, rrw.Msg, result, time.Since(start), ip)
}
return rcode, err
}
| </s> remove log.Printf("Failed to load top from querylog: %s", err)
</s> add log.Printf("Failed to load stats from querylog: %s", err) </s> remove err = runningTop.addEntry(&entry, now)
</s> add err = runningTop.addEntry(&entry, question, now) </s> remove err := runningTop.addEntry(entry, now)
</s> add if len(entry.Question) == 0 {
log.Printf("entry question is absent, skipping")
return nil
}
if entry.Time.After(now) {
log.Printf("t %v vs %v is in the future, ignoring", entry.Time, now)
return nil
}
q := new(dns.Msg)
if err := q.Unpack(entry.Question); err != nil {
log.Printf("failed to unpack dns message question: %s", err)
return err
}
if len(q.Question) != 1 {
log.Printf("malformed dns message, has no questions, skipping")
return nil
}
err := runningTop.addEntry(entry, q, now) </s> remove log.Printf("Loading top from querylog")
err := loadTopFromFiles()
</s> add log.Printf("Loading stats from querylog")
err := fillStatsFromQueryLog() </s> remove q := new(dns.Msg)
if err := q.Unpack(entry.Question); err != nil {
log.Printf("failed to unpack dns message question: %s", err)
return err
}
if len(q.Question) != 1 {
log.Printf("malformed dns message, has no questions, skipping")
return nil
}
</s> add | elapsed := time.Since(start)
elapsedTime.Observe(elapsed.Seconds()) |
// log
elapsed := time.Since(start)
elapsedTime.Observe(elapsed.Seconds())
if p.settings.QueryLogEnabled {
logRequest(r, rrw.Msg, result, time.Since(start), ip)
}
return rcode, err
} | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Implement online stats calculation in coredns plugin instead of scraping prometheus. | https://github.com/AdguardTeam/AdGuardHome/commit/37f6d38c498740c7c3db59c31da031cd5c305694 | coredns_plugin/coredns_plugin.go |
}
logBufferLock.Unlock()
// add it to running top
err = runningTop.addEntry(&entry, now)
if err != nil {
log.Printf("Failed to add entry to running top: %s", err)
// don't do failure, just log
}
| </s> remove err := runningTop.addEntry(entry, now)
</s> add if len(entry.Question) == 0 {
log.Printf("entry question is absent, skipping")
return nil
}
if entry.Time.After(now) {
log.Printf("t %v vs %v is in the future, ignoring", entry.Time, now)
return nil
}
q := new(dns.Msg)
if err := q.Unpack(entry.Question); err != nil {
log.Printf("failed to unpack dns message question: %s", err)
return err
}
if len(q.Question) != 1 {
log.Printf("malformed dns message, has no questions, skipping")
return nil
}
err := runningTop.addEntry(entry, q, now) </s> remove log.Printf("Failed to load top from querylog: %s", err)
</s> add log.Printf("Failed to load stats from querylog: %s", err) </s> remove log.Printf("Loading top from querylog")
err := loadTopFromFiles()
</s> add log.Printf("Loading stats from querylog")
err := fillStatsFromQueryLog() </s> remove errortext := fmt.Sprintf("Unable to write response json: %s", err)
</s> add errortext := fmt.Sprintf("Couldn't write body: %s", err) </s> remove errortext := fmt.Sprintf("Unable to write response json: %s", err)
</s> add errortext := fmt.Sprintf("Couldn't write body: %s", err) | err = runningTop.addEntry(&entry, question, now) | }
logBufferLock.Unlock()
// add it to running top
err = runningTop.addEntry(&entry, question, now)
if err != nil {
log.Printf("Failed to add entry to running top: %s", err)
// don't do failure, just log
}
| [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Implement online stats calculation in coredns plugin instead of scraping prometheus. | https://github.com/AdguardTeam/AdGuardHome/commit/37f6d38c498740c7c3db59c31da031cd5c305694 | coredns_plugin/querylog.go |
// write to file
// do it in separate goroutine -- we are stalling DNS response this whole time
go flushToFile(flushBuffer)
}
return
}
func handleQueryLog(w http.ResponseWriter, r *http.Request) {
now := time.Now()
| </s> remove http.Error(w, errortext, 500)
return
</s> add http.Error(w, errortext, http.StatusInternalServerError) </s> remove http.Error(w, errortext, 500)
return
</s> add http.Error(w, errortext, http.StatusInternalServerError) </s> remove // handle time unit and prepare our time window size
now := time.Now()
timeUnitString := r.URL.Query().Get("time_unit")
var stats *periodicStats
var timeUnit time.Duration
switch timeUnitString {
case "seconds":
timeUnit = time.Second
stats = &statistics.PerSecond
case "minutes":
timeUnit = time.Minute
stats = &statistics.PerMinute
case "hours":
timeUnit = time.Hour
stats = &statistics.PerHour
case "days":
timeUnit = time.Hour * 24
stats = &statistics.PerDay
default:
http.Error(w, "Must specify valid time_unit parameter", 400)
return
}
// parse start and end time
startTime, err := time.Parse(time.RFC3339, r.URL.Query().Get("start_time"))
if err != nil {
errortext := fmt.Sprintf("Must specify valid start_time parameter: %s", err)
log.Println(errortext)
http.Error(w, errortext, 400)
return
}
endTime, err := time.Parse(time.RFC3339, r.URL.Query().Get("end_time"))
</s> add resp, err := client.Get("http://127.0.0.1:8618/stats_history?" + r.URL.RawQuery) </s> remove func loadTopFromFiles() error {
</s> add func fillStatsFromQueryLog() error { </s> remove func (r *dayTop) addEntry(entry *logEntry, now time.Time) error {
if len(entry.Question) == 0 {
log.Printf("entry question is absent, skipping")
return nil
}
if entry.Time.After(now) {
log.Printf("t %v vs %v is in the future, ignoring", entry.Time, now)
return nil
}
</s> add func (r *dayTop) addEntry(entry *logEntry, q *dns.Msg, now time.Time) error { | // write to file
// do it in separate goroutine -- we are stalling DNS response this whole time
go flushToFile(flushBuffer)
}
}
func handleQueryLog(w http.ResponseWriter, r *http.Request) {
now := time.Now()
| [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Implement online stats calculation in coredns plugin instead of scraping prometheus. | https://github.com/AdguardTeam/AdGuardHome/commit/37f6d38c498740c7c3db59c31da031cd5c305694 | coredns_plugin/querylog.go |
|
if needRefresh {
// need to get fresh data
logBufferLock.RLock()
values := logBuffer
logBufferLock.RUnlock()
if len(values) < queryLogCacheSize {
values = appendFromLogFile(values, queryLogCacheSize, queryLogTimeLimit)
}
| </s> remove histrical := generateMapFromStats(&statistics.PerHour, 0, 24)
// sum them up
summed := map[string]interface{}{}
for key, values := range histrical {
summedValue := 0.0
floats, ok := values.([]float64)
if !ok {
continue
}
for _, v := range floats {
summedValue += v
}
summed[key] = summedValue
</s> add resp, err := client.Get("http://127.0.0.1:8618/stats")
if err != nil {
errortext := fmt.Sprintf("Couldn't get stats_top from coredns: %T %s\n", err, err)
log.Println(errortext)
http.Error(w, errortext, http.StatusBadGateway)
return
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close() </s> remove data := generateMapFromStats(stats, start, end)
json, err := json.Marshal(data)
</s> add // read the body entirely
body, err := ioutil.ReadAll(resp.Body) </s> remove
// calculate start and end of our array
// basically it's how many hours/minutes/etc have passed since now
start := int(now.Sub(endTime) / timeUnit)
end := int(now.Sub(startTime) / timeUnit)
// swap them around if they're inverted
if start > end {
start, end = end, start
</s> add if resp != nil && resp.Body != nil {
defer resp.Body.Close() </s> remove q := new(dns.Msg)
if err := q.Unpack(entry.Question); err != nil {
log.Printf("failed to unpack dns message question: %s", err)
return err
}
if len(q.Question) != 1 {
log.Printf("malformed dns message, has no questions, skipping")
return nil
}
</s> add </s> remove errortext := fmt.Sprintf("Unable to marshal status json: %s", err)
</s> add errortext := fmt.Sprintf("Couldn't read response body: %s", err) | values = logBuffer |
if needRefresh {
// need to get fresh data
logBufferLock.RLock()
values = logBuffer
logBufferLock.RUnlock()
if len(values) < queryLogCacheSize {
values = appendFromLogFile(values, queryLogCacheSize, queryLogTimeLimit)
} | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Implement online stats calculation in coredns plugin instead of scraping prometheus. | https://github.com/AdguardTeam/AdGuardHome/commit/37f6d38c498740c7c3db59c31da031cd5c305694 | coredns_plugin/querylog.go |
listenAddr := net.JoinHostPort("127.0.0.1", queryLogAPIPort)
go periodicQueryLogRotate()
go periodicHourlyTopRotate()
http.HandleFunc("/querylog", handleQueryLog)
http.HandleFunc("/stats", handleStats)
http.HandleFunc("/stats_top", handleStatsTop)
http.HandleFunc("/stats_history", handleStatsHistory)
| </s> remove return
</s> add </s> remove errortext := fmt.Sprintf("Unable to marshal status json: %s", err)
</s> add errortext := fmt.Sprintf("Couldn't read response body: %s", err) </s> remove histrical := generateMapFromStats(&statistics.PerHour, 0, 24)
// sum them up
summed := map[string]interface{}{}
for key, values := range histrical {
summedValue := 0.0
floats, ok := values.([]float64)
if !ok {
continue
}
for _, v := range floats {
summedValue += v
}
summed[key] = summedValue
</s> add resp, err := client.Get("http://127.0.0.1:8618/stats")
if err != nil {
errortext := fmt.Sprintf("Couldn't get stats_top from coredns: %T %s\n", err, err)
log.Println(errortext)
http.Error(w, errortext, http.StatusBadGateway)
return
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close() | go statsRotator() | listenAddr := net.JoinHostPort("127.0.0.1", queryLogAPIPort)
go periodicQueryLogRotate()
go periodicHourlyTopRotate()
go statsRotator()
http.HandleFunc("/querylog", handleQueryLog)
http.HandleFunc("/stats", handleStats)
http.HandleFunc("/stats_top", handleStatsTop)
http.HandleFunc("/stats_history", handleStatsHistory) | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Implement online stats calculation in coredns plugin instead of scraping prometheus. | https://github.com/AdguardTeam/AdGuardHome/commit/37f6d38c498740c7c3db59c31da031cd5c305694 | coredns_plugin/querylog.go |
go periodicHourlyTopRotate()
go statsRotator()
http.HandleFunc("/querylog", handleQueryLog)
http.HandleFunc("/stats_top", handleStatsTop)
http.HandleFunc("/stats_history", handleStatsHistory)
if err := http.ListenAndServe(listenAddr, nil); err != nil {
log.Fatalf("error in ListenAndServe: %s", err)
}
}
| </s> remove err := runningTop.addEntry(entry, now)
</s> add if len(entry.Question) == 0 {
log.Printf("entry question is absent, skipping")
return nil
}
if entry.Time.After(now) {
log.Printf("t %v vs %v is in the future, ignoring", entry.Time, now)
return nil
}
q := new(dns.Msg)
if err := q.Unpack(entry.Question); err != nil {
log.Printf("failed to unpack dns message question: %s", err)
return err
}
if len(q.Question) != 1 {
log.Printf("malformed dns message, has no questions, skipping")
return nil
}
err := runningTop.addEntry(entry, q, now) </s> remove errortext := fmt.Sprintf("Unable to write response json: %s", err)
</s> add errortext := fmt.Sprintf("Couldn't write body: %s", err) </s> remove errortext := fmt.Sprintf("Unable to write response json: %s", err)
</s> add errortext := fmt.Sprintf("Couldn't write body: %s", err) | http.HandleFunc("/stats", handleStats) | go periodicHourlyTopRotate()
go statsRotator()
http.HandleFunc("/querylog", handleQueryLog)
http.HandleFunc("/stats", handleStats)
http.HandleFunc("/stats_top", handleStatsTop)
http.HandleFunc("/stats_history", handleStatsHistory)
if err := http.ListenAndServe(listenAddr, nil); err != nil {
log.Fatalf("error in ListenAndServe: %s", err)
}
} | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Implement online stats calculation in coredns plugin instead of scraping prometheus. | https://github.com/AdguardTeam/AdGuardHome/commit/37f6d38c498740c7c3db59c31da031cd5c305694 | coredns_plugin/querylog.go |
http.HandleFunc("/querylog", handleQueryLog)
http.HandleFunc("/stats", handleStats)
http.HandleFunc("/stats_top", handleStatsTop)
if err := http.ListenAndServe(listenAddr, nil); err != nil {
log.Fatalf("error in ListenAndServe: %s", err)
}
}
func trace(format string, args ...interface{}) {
| </s> remove err := runningTop.addEntry(entry, now)
</s> add if len(entry.Question) == 0 {
log.Printf("entry question is absent, skipping")
return nil
}
if entry.Time.After(now) {
log.Printf("t %v vs %v is in the future, ignoring", entry.Time, now)
return nil
}
q := new(dns.Msg)
if err := q.Unpack(entry.Question); err != nil {
log.Printf("failed to unpack dns message question: %s", err)
return err
}
if len(q.Question) != 1 {
log.Printf("malformed dns message, has no questions, skipping")
return nil
}
err := runningTop.addEntry(entry, q, now) </s> remove http.Error(w, errortext, 500)
return
</s> add http.Error(w, errortext, http.StatusInternalServerError) </s> remove log.Printf("file \"%s\": read %d entries", file, i)
</s> add elapsed := time.Since(now)
log.Printf("file \"%s\": read %d entries in %v, %v/entry", file, i, elapsed, elapsed/time.Duration(i)) | http.HandleFunc("/stats_history", handleStatsHistory) | http.HandleFunc("/querylog", handleQueryLog)
http.HandleFunc("/stats", handleStats)
http.HandleFunc("/stats_top", handleStatsTop)
http.HandleFunc("/stats_history", handleStatsHistory)
if err := http.ListenAndServe(listenAddr, nil); err != nil {
log.Fatalf("error in ListenAndServe: %s", err)
}
}
func trace(format string, args ...interface{}) { | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Implement online stats calculation in coredns plugin instead of scraping prometheus. | https://github.com/AdguardTeam/AdGuardHome/commit/37f6d38c498740c7c3db59c31da031cd5c305694 | coredns_plugin/querylog.go |
if err != nil {
return err
}
}
log.Printf("file \"%s\": read %d entries", file, i)
}
return nil
}
func appendFromLogFile(values []logEntry, maxLen int, timeWindow time.Duration) []logEntry {
| </s> remove err := runningTop.addEntry(entry, now)
</s> add if len(entry.Question) == 0 {
log.Printf("entry question is absent, skipping")
return nil
}
if entry.Time.After(now) {
log.Printf("t %v vs %v is in the future, ignoring", entry.Time, now)
return nil
}
q := new(dns.Msg)
if err := q.Unpack(entry.Question); err != nil {
log.Printf("failed to unpack dns message question: %s", err)
return err
}
if len(q.Question) != 1 {
log.Printf("malformed dns message, has no questions, skipping")
return nil
}
err := runningTop.addEntry(entry, q, now) </s> remove log.Printf("Loading top from querylog")
err := loadTopFromFiles()
</s> add log.Printf("Loading stats from querylog")
err := fillStatsFromQueryLog() </s> remove q := new(dns.Msg)
if err := q.Unpack(entry.Question); err != nil {
log.Printf("failed to unpack dns message question: %s", err)
return err
}
if len(q.Question) != 1 {
log.Printf("malformed dns message, has no questions, skipping")
return nil
}
</s> add </s> remove http.Error(w, errortext, 500)
return
</s> add http.Error(w, errortext, http.StatusInternalServerError) </s> remove histrical := generateMapFromStats(&statistics.PerHour, 0, 24)
// sum them up
summed := map[string]interface{}{}
for key, values := range histrical {
summedValue := 0.0
floats, ok := values.([]float64)
if !ok {
continue
}
for _, v := range floats {
summedValue += v
}
summed[key] = summedValue
</s> add resp, err := client.Get("http://127.0.0.1:8618/stats")
if err != nil {
errortext := fmt.Sprintf("Couldn't get stats_top from coredns: %T %s\n", err, err)
log.Println(errortext)
http.Error(w, errortext, http.StatusBadGateway)
return
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close() | elapsed := time.Since(now)
log.Printf("file \"%s\": read %d entries in %v, %v/entry", file, i, elapsed, elapsed/time.Duration(i)) | if err != nil {
return err
}
}
elapsed := time.Since(now)
log.Printf("file \"%s\": read %d entries in %v, %v/entry", file, i, elapsed, elapsed/time.Duration(i))
}
return nil
}
func appendFromLogFile(values []logEntry, maxLen int, timeWindow time.Duration) []logEntry { | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Implement online stats calculation in coredns plugin instead of scraping prometheus. | https://github.com/AdguardTeam/AdGuardHome/commit/37f6d38c498740c7c3db59c31da031cd5c305694 | coredns_plugin/querylog_file.go |
"sync"
"time"
"github.com/bluele/gcache"
"github.com/miekg/dns"
)
| </s> remove func newDNSCounter(name string, help string) prometheus.Counter {
return prometheus.NewCounter(prometheus.CounterOpts{
Namespace: plugin.Namespace,
Subsystem: "dnsfilter",
Name: name,
Help: help,
})
}
var (
requests = newDNSCounter("requests_total", "Count of requests seen by dnsfilter.")
filtered = newDNSCounter("filtered_total", "Count of requests filtered by dnsfilter.")
filteredLists = newDNSCounter("filtered_lists_total", "Count of requests filtered by dnsfilter using lists.")
filteredSafebrowsing = newDNSCounter("filtered_safebrowsing_total", "Count of requests filtered by dnsfilter using safebrowsing.")
filteredParental = newDNSCounter("filtered_parental_total", "Count of requests filtered by dnsfilter using parental.")
filteredInvalid = newDNSCounter("filtered_invalid_total", "Count of requests filtered by dnsfilter because they were invalid.")
whitelisted = newDNSCounter("whitelisted_total", "Count of requests not filtered by dnsfilter because they are whitelisted.")
safesearch = newDNSCounter("safesearch_total", "Count of requests replaced by dnsfilter safesearch.")
errorsTotal = newDNSCounter("errors_total", "Count of requests that dnsfilter couldn't process because of transitive errors.")
)
</s> add </s> remove err := runningTop.addEntry(entry, now)
</s> add if len(entry.Question) == 0 {
log.Printf("entry question is absent, skipping")
return nil
}
if entry.Time.After(now) {
log.Printf("t %v vs %v is in the future, ignoring", entry.Time, now)
return nil
}
q := new(dns.Msg)
if err := q.Unpack(entry.Question); err != nil {
log.Printf("failed to unpack dns message question: %s", err)
return err
}
if len(q.Question) != 1 {
log.Printf("malformed dns message, has no questions, skipping")
return nil
}
err := runningTop.addEntry(entry, q, now) </s> remove http.Error(w, errortext, 500)
return
</s> add http.Error(w, errortext, http.StatusInternalServerError) </s> remove errortext := fmt.Sprintf("Unable to marshal status json: %s", err)
</s> add errortext := fmt.Sprintf("Couldn't read response body: %s", err) </s> remove data := generateMapFromStats(stats, start, end)
json, err := json.Marshal(data)
</s> add // read the body entirely
body, err := ioutil.ReadAll(resp.Body) | "github.com/AdguardTeam/AdguardDNS/dnsfilter" | "sync"
"time"
"github.com/AdguardTeam/AdguardDNS/dnsfilter"
"github.com/bluele/gcache"
"github.com/miekg/dns"
)
| [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | Implement online stats calculation in coredns plugin instead of scraping prometheus. | https://github.com/AdguardTeam/AdGuardHome/commit/37f6d38c498740c7c3db59c31da031cd5c305694 | coredns_plugin/querylog_top.go |
func (top *hourTop) lockedGetClients(key string) (int, error) {
return top.lockedGetValue(key, top.clients)
}
func (r *dayTop) addEntry(entry *logEntry, now time.Time) error {
if len(entry.Question) == 0 {
log.Printf("entry question is absent, skipping")
return nil
}
if entry.Time.After(now) {
log.Printf("t %v vs %v is in the future, ignoring", entry.Time, now)
return nil
}
// figure out which hour bucket it belongs to
hour := int(now.Sub(entry.Time).Hours())
if hour >= 24 {
log.Printf("t %v is >24 hours ago, ignoring", entry.Time)
return nil
| </s> remove err := runningTop.addEntry(entry, now)
</s> add if len(entry.Question) == 0 {
log.Printf("entry question is absent, skipping")
return nil
}
if entry.Time.After(now) {
log.Printf("t %v vs %v is in the future, ignoring", entry.Time, now)
return nil
}
q := new(dns.Msg)
if err := q.Unpack(entry.Question); err != nil {
log.Printf("failed to unpack dns message question: %s", err)
return err
}
if len(q.Question) != 1 {
log.Printf("malformed dns message, has no questions, skipping")
return nil
}
err := runningTop.addEntry(entry, q, now) </s> remove q := new(dns.Msg)
if err := q.Unpack(entry.Question); err != nil {
log.Printf("failed to unpack dns message question: %s", err)
return err
}
if len(q.Question) != 1 {
log.Printf("malformed dns message, has no questions, skipping")
return nil
}
</s> add </s> remove func loadTopFromFiles() error {
</s> add func fillStatsFromQueryLog() error { </s> remove http.Error(w, errortext, 400)
return
}
// check if start and time times are within supported time range
timeRange := timeUnit * statsHistoryElements
if startTime.Add(timeRange).Before(now) {
http.Error(w, "start_time parameter is outside of supported range", 501)
return
}
if endTime.Add(timeRange).Before(now) {
http.Error(w, "end_time parameter is outside of supported range", 501)
</s> add http.Error(w, errortext, http.StatusBadGateway) </s> remove
// calculate start and end of our array
// basically it's how many hours/minutes/etc have passed since now
start := int(now.Sub(endTime) / timeUnit)
end := int(now.Sub(startTime) / timeUnit)
// swap them around if they're inverted
if start > end {
start, end = end, start
</s> add if resp != nil && resp.Body != nil {
defer resp.Body.Close() | func (r *dayTop) addEntry(entry *logEntry, q *dns.Msg, now time.Time) error { | func (top *hourTop) lockedGetClients(key string) (int, error) {
return top.lockedGetValue(key, top.clients)
}
func (r *dayTop) addEntry(entry *logEntry, q *dns.Msg, now time.Time) error {
func (r *dayTop) addEntry(entry *logEntry, q *dns.Msg, now time.Time) error {
func (r *dayTop) addEntry(entry *logEntry, q *dns.Msg, now time.Time) error {
func (r *dayTop) addEntry(entry *logEntry, q *dns.Msg, now time.Time) error {
func (r *dayTop) addEntry(entry *logEntry, q *dns.Msg, now time.Time) error {
func (r *dayTop) addEntry(entry *logEntry, q *dns.Msg, now time.Time) error {
func (r *dayTop) addEntry(entry *logEntry, q *dns.Msg, now time.Time) error {
func (r *dayTop) addEntry(entry *logEntry, q *dns.Msg, now time.Time) error {
func (r *dayTop) addEntry(entry *logEntry, q *dns.Msg, now time.Time) error {
func (r *dayTop) addEntry(entry *logEntry, q *dns.Msg, now time.Time) error {
// figure out which hour bucket it belongs to
hour := int(now.Sub(entry.Time).Hours())
if hour >= 24 {
log.Printf("t %v is >24 hours ago, ignoring", entry.Time)
return nil | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Implement online stats calculation in coredns plugin instead of scraping prometheus. | https://github.com/AdguardTeam/AdGuardHome/commit/37f6d38c498740c7c3db59c31da031cd5c305694 | coredns_plugin/querylog_top.go |
log.Printf("t %v is >24 hours ago, ignoring", entry.Time)
return nil
}
q := new(dns.Msg)
if err := q.Unpack(entry.Question); err != nil {
log.Printf("failed to unpack dns message question: %s", err)
return err
}
if len(q.Question) != 1 {
log.Printf("malformed dns message, has no questions, skipping")
return nil
}
hostname := strings.ToLower(strings.TrimSuffix(q.Question[0].Name, "."))
// get value, if not set, crate one
runningTop.hoursReadLock()
defer runningTop.hoursReadUnlock()
| </s> remove err := runningTop.addEntry(entry, now)
</s> add if len(entry.Question) == 0 {
log.Printf("entry question is absent, skipping")
return nil
}
if entry.Time.After(now) {
log.Printf("t %v vs %v is in the future, ignoring", entry.Time, now)
return nil
}
q := new(dns.Msg)
if err := q.Unpack(entry.Question); err != nil {
log.Printf("failed to unpack dns message question: %s", err)
return err
}
if len(q.Question) != 1 {
log.Printf("malformed dns message, has no questions, skipping")
return nil
}
err := runningTop.addEntry(entry, q, now) </s> remove func (r *dayTop) addEntry(entry *logEntry, now time.Time) error {
if len(entry.Question) == 0 {
log.Printf("entry question is absent, skipping")
return nil
}
if entry.Time.After(now) {
log.Printf("t %v vs %v is in the future, ignoring", entry.Time, now)
return nil
}
</s> add func (r *dayTop) addEntry(entry *logEntry, q *dns.Msg, now time.Time) error { </s> remove histrical := generateMapFromStats(&statistics.PerHour, 0, 24)
// sum them up
summed := map[string]interface{}{}
for key, values := range histrical {
summedValue := 0.0
floats, ok := values.([]float64)
if !ok {
continue
}
for _, v := range floats {
summedValue += v
}
summed[key] = summedValue
</s> add resp, err := client.Get("http://127.0.0.1:8618/stats")
if err != nil {
errortext := fmt.Sprintf("Couldn't get stats_top from coredns: %T %s\n", err, err)
log.Println(errortext)
http.Error(w, errortext, http.StatusBadGateway)
return
}
if resp != nil && resp.Body != nil {
defer resp.Body.Close() </s> remove errortext := fmt.Sprintf("Must specify valid end_time parameter: %s", err)
</s> add errortext := fmt.Sprintf("Couldn't get stats_top from coredns: %T %s\n", err, err) </s> remove http.Error(w, errortext, 500)
</s> add http.Error(w, errortext, http.StatusBadGateway) | log.Printf("t %v is >24 hours ago, ignoring", entry.Time)
return nil
}
hostname := strings.ToLower(strings.TrimSuffix(q.Question[0].Name, "."))
// get value, if not set, crate one
runningTop.hoursReadLock()
defer runningTop.hoursReadUnlock() | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Implement online stats calculation in coredns plugin instead of scraping prometheus. | https://github.com/AdguardTeam/AdGuardHome/commit/37f6d38c498740c7c3db59c31da031cd5c305694 | coredns_plugin/querylog_top.go |
|
return nil
}
func loadTopFromFiles() error {
now := time.Now()
runningTop.loadedWriteLock()
defer runningTop.loadedWriteUnlock()
if runningTop.loaded {
return nil
| </s> remove func (r *dayTop) addEntry(entry *logEntry, now time.Time) error {
if len(entry.Question) == 0 {
log.Printf("entry question is absent, skipping")
return nil
}
if entry.Time.After(now) {
log.Printf("t %v vs %v is in the future, ignoring", entry.Time, now)
return nil
}
</s> add func (r *dayTop) addEntry(entry *logEntry, q *dns.Msg, now time.Time) error { </s> remove err := runningTop.addEntry(entry, now)
</s> add if len(entry.Question) == 0 {
log.Printf("entry question is absent, skipping")
return nil
}
if entry.Time.After(now) {
log.Printf("t %v vs %v is in the future, ignoring", entry.Time, now)
return nil
}
q := new(dns.Msg)
if err := q.Unpack(entry.Question); err != nil {
log.Printf("failed to unpack dns message question: %s", err)
return err
}
if len(q.Question) != 1 {
log.Printf("malformed dns message, has no questions, skipping")
return nil
}
err := runningTop.addEntry(entry, q, now) </s> remove q := new(dns.Msg)
if err := q.Unpack(entry.Question); err != nil {
log.Printf("failed to unpack dns message question: %s", err)
return err
}
if len(q.Question) != 1 {
log.Printf("malformed dns message, has no questions, skipping")
return nil
}
</s> add </s> remove log.Printf("Loading top from querylog")
err := loadTopFromFiles()
</s> add log.Printf("Loading stats from querylog")
err := fillStatsFromQueryLog() </s> remove
// calculate start and end of our array
// basically it's how many hours/minutes/etc have passed since now
start := int(now.Sub(endTime) / timeUnit)
end := int(now.Sub(startTime) / timeUnit)
// swap them around if they're inverted
if start > end {
start, end = end, start
</s> add if resp != nil && resp.Body != nil {
defer resp.Body.Close() | func fillStatsFromQueryLog() error { |
return nil
}
func fillStatsFromQueryLog() error {
now := time.Now()
runningTop.loadedWriteLock()
defer runningTop.loadedWriteUnlock()
if runningTop.loaded {
return nil | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Implement online stats calculation in coredns plugin instead of scraping prometheus. | https://github.com/AdguardTeam/AdGuardHome/commit/37f6d38c498740c7c3db59c31da031cd5c305694 | coredns_plugin/querylog_top.go |
if runningTop.loaded {
return nil
}
onEntry := func(entry *logEntry) error {
err := runningTop.addEntry(entry, now)
if err != nil {
log.Printf("Failed to add entry to running top: %s", err)
return err
}
return nil
| </s> remove err = runningTop.addEntry(&entry, now)
</s> add err = runningTop.addEntry(&entry, question, now) </s> remove log.Printf("Failed to load top from querylog: %s", err)
</s> add log.Printf("Failed to load stats from querylog: %s", err) </s> remove log.Printf("Loading top from querylog")
err := loadTopFromFiles()
</s> add log.Printf("Loading stats from querylog")
err := fillStatsFromQueryLog() </s> remove func loadTopFromFiles() error {
</s> add func fillStatsFromQueryLog() error { </s> remove http.Error(w, errortext, 500)
</s> add http.Error(w, errortext, http.StatusBadGateway) | if len(entry.Question) == 0 {
log.Printf("entry question is absent, skipping")
return nil
}
if entry.Time.After(now) {
log.Printf("t %v vs %v is in the future, ignoring", entry.Time, now)
return nil
}
q := new(dns.Msg)
if err := q.Unpack(entry.Question); err != nil {
log.Printf("failed to unpack dns message question: %s", err)
return err
}
if len(q.Question) != 1 {
log.Printf("malformed dns message, has no questions, skipping")
return nil
}
err := runningTop.addEntry(entry, q, now) | if runningTop.loaded {
return nil
}
onEntry := func(entry *logEntry) error {
if len(entry.Question) == 0 {
log.Printf("entry question is absent, skipping")
return nil
}
if entry.Time.After(now) {
log.Printf("t %v vs %v is in the future, ignoring", entry.Time, now)
return nil
}
q := new(dns.Msg)
if err := q.Unpack(entry.Question); err != nil {
log.Printf("failed to unpack dns message question: %s", err)
return err
}
if len(q.Question) != 1 {
log.Printf("malformed dns message, has no questions, skipping")
return nil
}
err := runningTop.addEntry(entry, q, now)
if err != nil {
log.Printf("Failed to add entry to running top: %s", err)
return err
}
return nil | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Implement online stats calculation in coredns plugin instead of scraping prometheus. | https://github.com/AdguardTeam/AdGuardHome/commit/37f6d38c498740c7c3db59c31da031cd5c305694 | coredns_plugin/querylog_top.go |
github.com/gobuffalo/packr v1.19.0
github.com/joomcode/errorx v1.0.0
github.com/kardianos/osext v0.0.0-20170510131534-ae77be60afb1 // indirect
github.com/kardianos/service v0.0.0-20181115005516-4c239ee84e7b
github.com/krolaw/dhcp4 v0.0.0-20180925202202-7cead472c414
github.com/miekg/dns v1.1.19
github.com/sparrc/go-ping v0.0.0-20181106165434-ef3ab45e41b0
github.com/stretchr/testify v1.4.0
| </s> remove github.com/likexian/whois-go v0.0.0-20190627090909-384b3df3fc49
</s> add </s> remove github.com/likexian/gokit v0.0.0-20190309162924-0a377eecf7aa/go.mod h1:QdfYv6y6qPA9pbBA2qXtoT8BMKha6UyNbxWGWl/9Jfk=
github.com/likexian/gokit v0.0.0-20190418170008-ace88ad0983b/go.mod h1:KKqSnk/VVSW8kEyO2vVCXoanzEutKdlBAPohmGXkxCk=
github.com/likexian/gokit v0.0.0-20190501133040-e77ea8b19cdc/go.mod h1:3kvONayqCaj+UgrRZGpgfXzHdMYCAO0KAt4/8n0L57Y=
github.com/likexian/gokit v0.0.0-20190604165112-68b8a4ba758c h1:KByA4IxKqqYwpqzk/P+w1DBpkPbvy3DArTP/U3LSxTQ=
github.com/likexian/gokit v0.0.0-20190604165112-68b8a4ba758c/go.mod h1:kn+nTv3tqh6yhor9BC4Lfiu58SmH8NmQ2PmEl+uM6nU=
github.com/likexian/simplejson-go v0.0.0-20190409170913-40473a74d76d/go.mod h1:Typ1BfnATYtZ/+/shXfFYLrovhFyuKvzwrdOnIDHlmg=
github.com/likexian/simplejson-go v0.0.0-20190419151922-c1f9f0b4f084/go.mod h1:U4O1vIJvIKwbMZKUJ62lppfdvkCdVd2nfMimHK81eec=
github.com/likexian/simplejson-go v0.0.0-20190502021454-d8787b4bfa0b/go.mod h1:3BWwtmKP9cXWwYCr5bkoVDEfLywacOv0s06OBEDpyt8=
github.com/likexian/whois-go v0.0.0-20190627090909-384b3df3fc49 h1:xGa+flE6p2UnMgxIS8bm7Q9JSt47HRuYVtwneDVnfLk=
github.com/likexian/whois-go v0.0.0-20190627090909-384b3df3fc49/go.mod h1:oR3bJMzrOb55cqTAn14DEzYFLDpSPTXJ3ORe7go9Hc8=
</s> add | github.com/kr/pretty v0.1.0 // indirect | github.com/gobuffalo/packr v1.19.0
github.com/joomcode/errorx v1.0.0
github.com/kardianos/osext v0.0.0-20170510131534-ae77be60afb1 // indirect
github.com/kardianos/service v0.0.0-20181115005516-4c239ee84e7b
github.com/kr/pretty v0.1.0 // indirect
github.com/krolaw/dhcp4 v0.0.0-20180925202202-7cead472c414
github.com/miekg/dns v1.1.19
github.com/sparrc/go-ping v0.0.0-20181106165434-ef3ab45e41b0
github.com/stretchr/testify v1.4.0 | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | * whois: use whois.arin.net
+ robust redirect mechanism
* decrease timeout 30sec -> 5sec
* faster response parsing
* don't use likexian/whois-go package | https://github.com/AdguardTeam/AdGuardHome/commit/37fe3c148f6edcb7ad8567ed2490f8c67208c50f | go.mod |
github.com/joomcode/errorx v1.0.0
github.com/kardianos/osext v0.0.0-20170510131534-ae77be60afb1 // indirect
github.com/kardianos/service v0.0.0-20181115005516-4c239ee84e7b
github.com/krolaw/dhcp4 v0.0.0-20180925202202-7cead472c414
github.com/likexian/whois-go v0.0.0-20190627090909-384b3df3fc49
github.com/miekg/dns v1.1.19
github.com/sparrc/go-ping v0.0.0-20181106165434-ef3ab45e41b0
github.com/stretchr/testify v1.4.0
go.etcd.io/bbolt v1.3.3
golang.org/x/crypto v0.0.0-20191001170739-f9e2070545dc
| </s> remove github.com/likexian/gokit v0.0.0-20190309162924-0a377eecf7aa/go.mod h1:QdfYv6y6qPA9pbBA2qXtoT8BMKha6UyNbxWGWl/9Jfk=
github.com/likexian/gokit v0.0.0-20190418170008-ace88ad0983b/go.mod h1:KKqSnk/VVSW8kEyO2vVCXoanzEutKdlBAPohmGXkxCk=
github.com/likexian/gokit v0.0.0-20190501133040-e77ea8b19cdc/go.mod h1:3kvONayqCaj+UgrRZGpgfXzHdMYCAO0KAt4/8n0L57Y=
github.com/likexian/gokit v0.0.0-20190604165112-68b8a4ba758c h1:KByA4IxKqqYwpqzk/P+w1DBpkPbvy3DArTP/U3LSxTQ=
github.com/likexian/gokit v0.0.0-20190604165112-68b8a4ba758c/go.mod h1:kn+nTv3tqh6yhor9BC4Lfiu58SmH8NmQ2PmEl+uM6nU=
github.com/likexian/simplejson-go v0.0.0-20190409170913-40473a74d76d/go.mod h1:Typ1BfnATYtZ/+/shXfFYLrovhFyuKvzwrdOnIDHlmg=
github.com/likexian/simplejson-go v0.0.0-20190419151922-c1f9f0b4f084/go.mod h1:U4O1vIJvIKwbMZKUJ62lppfdvkCdVd2nfMimHK81eec=
github.com/likexian/simplejson-go v0.0.0-20190502021454-d8787b4bfa0b/go.mod h1:3BWwtmKP9cXWwYCr5bkoVDEfLywacOv0s06OBEDpyt8=
github.com/likexian/whois-go v0.0.0-20190627090909-384b3df3fc49 h1:xGa+flE6p2UnMgxIS8bm7Q9JSt47HRuYVtwneDVnfLk=
github.com/likexian/whois-go v0.0.0-20190627090909-384b3df3fc49/go.mod h1:oR3bJMzrOb55cqTAn14DEzYFLDpSPTXJ3ORe7go9Hc8=
</s> add </s> remove golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5 h1:58fnuSXlxZmFdJyvtTFVmVhcMLU6v5fEb/ok4wyqtNU=
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
</s> add | github.com/joomcode/errorx v1.0.0
github.com/kardianos/osext v0.0.0-20170510131534-ae77be60afb1 // indirect
github.com/kardianos/service v0.0.0-20181115005516-4c239ee84e7b
github.com/krolaw/dhcp4 v0.0.0-20180925202202-7cead472c414
github.com/miekg/dns v1.1.19
github.com/sparrc/go-ping v0.0.0-20181106165434-ef3ab45e41b0
github.com/stretchr/testify v1.4.0
go.etcd.io/bbolt v1.3.3
golang.org/x/crypto v0.0.0-20191001170739-f9e2070545dc | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * whois: use whois.arin.net
+ robust redirect mechanism
* decrease timeout 30sec -> 5sec
* faster response parsing
* don't use likexian/whois-go package | https://github.com/AdguardTeam/AdGuardHome/commit/37fe3c148f6edcb7ad8567ed2490f8c67208c50f | go.mod |
|
github.com/AdguardTeam/dnsproxy v0.19.4 h1:rZb40VUr/yN8RG4j3+NuGqODmPvte7acPfSDl0j2wiU=
github.com/AdguardTeam/dnsproxy v0.19.4/go.mod h1:NaulY9i279jZwN8QBbvbZnn5HkrjBgJi4hbFY5nW+Kc=
github.com/AdguardTeam/dnsproxy v0.19.5 h1:QAKWa2+rTp7GAeOFLMPqIYPS7eglLVEkVLH4kHRbnCQ=
github.com/AdguardTeam/dnsproxy v0.19.5/go.mod h1:qEiDndktnVJYYzHiQGKUl8Zm0b7HGpPmYWShAxmqjtw=
github.com/AdguardTeam/golibs v0.1.3 h1:hmapdTtMtIk3T8eQDwTOLdqZLGDKNKk9325uC8z12xg=
github.com/AdguardTeam/golibs v0.1.3/go.mod h1:b0XkhgIcn2TxwX6C5AQMtpIFAgjPehNgxJErWkwA3ko=
github.com/AdguardTeam/golibs v0.2.1 h1:jGCnbM5UOUq/GrG+8eLN7Y+OTfEo5F/8L0wq3ur2h4E=
| </s> remove github.com/AdguardTeam/urlfilter v0.5.0 h1:ATzs2Er0BMt7NbZnFJ4UEzt3uIV+rydbQCYqBXNRbJc=
github.com/AdguardTeam/urlfilter v0.5.0/go.mod h1:6YehXZ8e0Hx2MvqeQWLFom6IkPinm04tNhO1CkwAxmg=
</s> add </s> remove assert.True(t, strings.Index(resp, "OrgName: Google LLC") != -1)
assert.True(t, strings.Index(resp, "City: Mountain View") != -1)
assert.True(t, strings.Index(resp, "Country: US") != -1)
</s> add </s> remove resp, err := whois.Whois("8.8.8.8")
</s> add w := Whois{timeoutMsec: 5000}
resp, err := w.queryAll("8.8.8.8") </s> remove github.com/likexian/whois-go v0.0.0-20190627090909-384b3df3fc49
</s> add |
github.com/AdguardTeam/dnsproxy v0.19.5 h1:QAKWa2+rTp7GAeOFLMPqIYPS7eglLVEkVLH4kHRbnCQ=
github.com/AdguardTeam/dnsproxy v0.19.5/go.mod h1:qEiDndktnVJYYzHiQGKUl8Zm0b7HGpPmYWShAxmqjtw=
github.com/AdguardTeam/golibs v0.1.3 h1:hmapdTtMtIk3T8eQDwTOLdqZLGDKNKk9325uC8z12xg=
github.com/AdguardTeam/golibs v0.1.3/go.mod h1:b0XkhgIcn2TxwX6C5AQMtpIFAgjPehNgxJErWkwA3ko=
github.com/AdguardTeam/golibs v0.2.1 h1:jGCnbM5UOUq/GrG+8eLN7Y+OTfEo5F/8L0wq3ur2h4E= | [
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * whois: use whois.arin.net
+ robust redirect mechanism
* decrease timeout 30sec -> 5sec
* faster response parsing
* don't use likexian/whois-go package | https://github.com/AdguardTeam/AdGuardHome/commit/37fe3c148f6edcb7ad8567ed2490f8c67208c50f | go.sum |
|
github.com/AdguardTeam/golibs v0.1.3 h1:hmapdTtMtIk3T8eQDwTOLdqZLGDKNKk9325uC8z12xg=
github.com/AdguardTeam/golibs v0.1.3/go.mod h1:b0XkhgIcn2TxwX6C5AQMtpIFAgjPehNgxJErWkwA3ko=
github.com/AdguardTeam/golibs v0.2.1 h1:jGCnbM5UOUq/GrG+8eLN7Y+OTfEo5F/8L0wq3ur2h4E=
github.com/AdguardTeam/golibs v0.2.1/go.mod h1:caAJ5knSHbR6vV6qfRDgAfXVia4hHgLqeztAY4UX0fw=
github.com/AdguardTeam/urlfilter v0.5.0 h1:ATzs2Er0BMt7NbZnFJ4UEzt3uIV+rydbQCYqBXNRbJc=
github.com/AdguardTeam/urlfilter v0.5.0/go.mod h1:6YehXZ8e0Hx2MvqeQWLFom6IkPinm04tNhO1CkwAxmg=
github.com/AdguardTeam/urlfilter v0.6.0 h1:HVPfAsGcHW47HasmqcLNA/VJ41GaR/SzUufuIj70ouA=
github.com/AdguardTeam/urlfilter v0.6.0/go.mod h1:y+XdxBdbRG9v7pfjznlvv4Ufi2HTG8D0YMqR22OVy0Y=
github.com/NYTimes/gziphandler v1.1.1 h1:ZUDjpQae29j0ryrS0u/B8HZfJBtBQHjqw2rQ2cqUQ3I=
github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c=
github.com/StackExchange/wmi v0.0.0-20181212234831-e0a55b97c705 h1:UUppSQnhf4Yc6xGxSkoQpPhb7RVzuv5Nb1mwJ5VId9s=
| </s> remove github.com/AdguardTeam/dnsproxy v0.19.4 h1:rZb40VUr/yN8RG4j3+NuGqODmPvte7acPfSDl0j2wiU=
github.com/AdguardTeam/dnsproxy v0.19.4/go.mod h1:NaulY9i279jZwN8QBbvbZnn5HkrjBgJi4hbFY5nW+Kc=
</s> add </s> remove assert.True(t, strings.Index(resp, "OrgName: Google LLC") != -1)
assert.True(t, strings.Index(resp, "City: Mountain View") != -1)
assert.True(t, strings.Index(resp, "Country: US") != -1)
</s> add </s> remove resp, err := whois.Whois("8.8.8.8")
</s> add w := Whois{timeoutMsec: 5000}
resp, err := w.queryAll("8.8.8.8") | github.com/AdguardTeam/golibs v0.1.3 h1:hmapdTtMtIk3T8eQDwTOLdqZLGDKNKk9325uC8z12xg=
github.com/AdguardTeam/golibs v0.1.3/go.mod h1:b0XkhgIcn2TxwX6C5AQMtpIFAgjPehNgxJErWkwA3ko=
github.com/AdguardTeam/golibs v0.2.1 h1:jGCnbM5UOUq/GrG+8eLN7Y+OTfEo5F/8L0wq3ur2h4E=
github.com/AdguardTeam/golibs v0.2.1/go.mod h1:caAJ5knSHbR6vV6qfRDgAfXVia4hHgLqeztAY4UX0fw=
github.com/AdguardTeam/urlfilter v0.6.0 h1:HVPfAsGcHW47HasmqcLNA/VJ41GaR/SzUufuIj70ouA=
github.com/AdguardTeam/urlfilter v0.6.0/go.mod h1:y+XdxBdbRG9v7pfjznlvv4Ufi2HTG8D0YMqR22OVy0Y=
github.com/NYTimes/gziphandler v1.1.1 h1:ZUDjpQae29j0ryrS0u/B8HZfJBtBQHjqw2rQ2cqUQ3I=
github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c=
github.com/StackExchange/wmi v0.0.0-20181212234831-e0a55b97c705 h1:UUppSQnhf4Yc6xGxSkoQpPhb7RVzuv5Nb1mwJ5VId9s= | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * whois: use whois.arin.net
+ robust redirect mechanism
* decrease timeout 30sec -> 5sec
* faster response parsing
* don't use likexian/whois-go package | https://github.com/AdguardTeam/AdGuardHome/commit/37fe3c148f6edcb7ad8567ed2490f8c67208c50f | go.sum |
|
github.com/StackExchange/wmi v0.0.0-20181212234831-e0a55b97c705 h1:UUppSQnhf4Yc6xGxSkoQpPhb7RVzuv5Nb1mwJ5VId9s=
github.com/StackExchange/wmi v0.0.0-20181212234831-e0a55b97c705/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da h1:KjTM2ks9d14ZYCvmHS9iAKVt9AyzRSqNU1qabPih5BY=
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da/go.mod h1:eHEWzANqSiWQsof+nXEI9bUVUyV6F53Fp89EuCh2EAA=
github.com/aead/poly1305 v0.0.0-20180717145839-3fee0db0b635 h1:52m0LGchQBBVqJRyYYufQuIbVqRawmubW3OFGqK1ekw=
github.com/aead/poly1305 v0.0.0-20180717145839-3fee0db0b635/go.mod h1:lmLxL+FV291OopO93Bwf9fQLQeLyt33VJRUg5VJ30us=
| </s> remove github.com/AdguardTeam/urlfilter v0.5.0 h1:ATzs2Er0BMt7NbZnFJ4UEzt3uIV+rydbQCYqBXNRbJc=
github.com/AdguardTeam/urlfilter v0.5.0/go.mod h1:6YehXZ8e0Hx2MvqeQWLFom6IkPinm04tNhO1CkwAxmg=
</s> add </s> remove assert.True(t, strings.Index(resp, "OrgName: Google LLC") != -1)
assert.True(t, strings.Index(resp, "City: Mountain View") != -1)
assert.True(t, strings.Index(resp, "Country: US") != -1)
</s> add </s> remove resp, err := whois.Whois("8.8.8.8")
</s> add w := Whois{timeoutMsec: 5000}
resp, err := w.queryAll("8.8.8.8") </s> remove github.com/likexian/whois-go v0.0.0-20190627090909-384b3df3fc49
</s> add </s> remove github.com/AdguardTeam/dnsproxy v0.19.4 h1:rZb40VUr/yN8RG4j3+NuGqODmPvte7acPfSDl0j2wiU=
github.com/AdguardTeam/dnsproxy v0.19.4/go.mod h1:NaulY9i279jZwN8QBbvbZnn5HkrjBgJi4hbFY5nW+Kc=
</s> add | github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUWq3EgK3CesDbo8upS2Vm9/P3FtgI+Jk= | github.com/StackExchange/wmi v0.0.0-20181212234831-e0a55b97c705 h1:UUppSQnhf4Yc6xGxSkoQpPhb7RVzuv5Nb1mwJ5VId9s=
github.com/StackExchange/wmi v0.0.0-20181212234831-e0a55b97c705/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUWq3EgK3CesDbo8upS2Vm9/P3FtgI+Jk=
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da h1:KjTM2ks9d14ZYCvmHS9iAKVt9AyzRSqNU1qabPih5BY=
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da/go.mod h1:eHEWzANqSiWQsof+nXEI9bUVUyV6F53Fp89EuCh2EAA=
github.com/aead/poly1305 v0.0.0-20180717145839-3fee0db0b635 h1:52m0LGchQBBVqJRyYYufQuIbVqRawmubW3OFGqK1ekw=
github.com/aead/poly1305 v0.0.0-20180717145839-3fee0db0b635/go.mod h1:lmLxL+FV291OopO93Bwf9fQLQeLyt33VJRUg5VJ30us= | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * whois: use whois.arin.net
+ robust redirect mechanism
* decrease timeout 30sec -> 5sec
* faster response parsing
* don't use likexian/whois-go package | https://github.com/AdguardTeam/AdGuardHome/commit/37fe3c148f6edcb7ad8567ed2490f8c67208c50f | go.sum |
github.com/kardianos/service v0.0.0-20181115005516-4c239ee84e7b h1:vfiqKno48aUndBMjTeWFpCExNnTf2Xnd6d228L4EfTQ=
github.com/kardianos/service v0.0.0-20181115005516-4c239ee84e7b/go.mod h1:10UU/bEkzh2iEN6aYzbevY7J6p03KO5siTxQWXMEerg=
github.com/krolaw/dhcp4 v0.0.0-20180925202202-7cead472c414 h1:6wnYc2S/lVM7BvR32BM74ph7bPgqMztWopMYKgVyEho=
github.com/krolaw/dhcp4 v0.0.0-20180925202202-7cead472c414/go.mod h1:0AqAH3ZogsCrvrtUpvc6EtVKbc3w6xwZhkvGLuqyi3o=
github.com/markbates/oncer v0.0.0-20181014194634-05fccaae8fc4 h1:Mlji5gkcpzkqTROyE4ZxZ8hN7osunMb2RuGVrbvMvCc=
github.com/markbates/oncer v0.0.0-20181014194634-05fccaae8fc4/go.mod h1:Ld9puTsIW75CHf65OeIOkyKbteujpZVXDpWK6YGZbxE=
github.com/miekg/dns v1.1.8 h1:1QYRAKU3lN5cRfLCkPU08hwvLJFhvjP6MqNMmQz6ZVI=
| </s> remove github.com/likexian/gokit v0.0.0-20190309162924-0a377eecf7aa/go.mod h1:QdfYv6y6qPA9pbBA2qXtoT8BMKha6UyNbxWGWl/9Jfk=
github.com/likexian/gokit v0.0.0-20190418170008-ace88ad0983b/go.mod h1:KKqSnk/VVSW8kEyO2vVCXoanzEutKdlBAPohmGXkxCk=
github.com/likexian/gokit v0.0.0-20190501133040-e77ea8b19cdc/go.mod h1:3kvONayqCaj+UgrRZGpgfXzHdMYCAO0KAt4/8n0L57Y=
github.com/likexian/gokit v0.0.0-20190604165112-68b8a4ba758c h1:KByA4IxKqqYwpqzk/P+w1DBpkPbvy3DArTP/U3LSxTQ=
github.com/likexian/gokit v0.0.0-20190604165112-68b8a4ba758c/go.mod h1:kn+nTv3tqh6yhor9BC4Lfiu58SmH8NmQ2PmEl+uM6nU=
github.com/likexian/simplejson-go v0.0.0-20190409170913-40473a74d76d/go.mod h1:Typ1BfnATYtZ/+/shXfFYLrovhFyuKvzwrdOnIDHlmg=
github.com/likexian/simplejson-go v0.0.0-20190419151922-c1f9f0b4f084/go.mod h1:U4O1vIJvIKwbMZKUJ62lppfdvkCdVd2nfMimHK81eec=
github.com/likexian/simplejson-go v0.0.0-20190502021454-d8787b4bfa0b/go.mod h1:3BWwtmKP9cXWwYCr5bkoVDEfLywacOv0s06OBEDpyt8=
github.com/likexian/whois-go v0.0.0-20190627090909-384b3df3fc49 h1:xGa+flE6p2UnMgxIS8bm7Q9JSt47HRuYVtwneDVnfLk=
github.com/likexian/whois-go v0.0.0-20190627090909-384b3df3fc49/go.mod h1:oR3bJMzrOb55cqTAn14DEzYFLDpSPTXJ3ORe7go9Hc8=
</s> add </s> remove github.com/likexian/whois-go v0.0.0-20190627090909-384b3df3fc49
</s> add </s> remove resp, err := whois.Whois("8.8.8.8")
</s> add w := Whois{timeoutMsec: 5000}
resp, err := w.queryAll("8.8.8.8") </s> remove github.com/AdguardTeam/dnsproxy v0.19.4 h1:rZb40VUr/yN8RG4j3+NuGqODmPvte7acPfSDl0j2wiU=
github.com/AdguardTeam/dnsproxy v0.19.4/go.mod h1:NaulY9i279jZwN8QBbvbZnn5HkrjBgJi4hbFY5nW+Kc=
</s> add | github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= | github.com/kardianos/service v0.0.0-20181115005516-4c239ee84e7b h1:vfiqKno48aUndBMjTeWFpCExNnTf2Xnd6d228L4EfTQ=
github.com/kardianos/service v0.0.0-20181115005516-4c239ee84e7b/go.mod h1:10UU/bEkzh2iEN6aYzbevY7J6p03KO5siTxQWXMEerg=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/krolaw/dhcp4 v0.0.0-20180925202202-7cead472c414 h1:6wnYc2S/lVM7BvR32BM74ph7bPgqMztWopMYKgVyEho=
github.com/krolaw/dhcp4 v0.0.0-20180925202202-7cead472c414/go.mod h1:0AqAH3ZogsCrvrtUpvc6EtVKbc3w6xwZhkvGLuqyi3o=
github.com/markbates/oncer v0.0.0-20181014194634-05fccaae8fc4 h1:Mlji5gkcpzkqTROyE4ZxZ8hN7osunMb2RuGVrbvMvCc=
github.com/markbates/oncer v0.0.0-20181014194634-05fccaae8fc4/go.mod h1:Ld9puTsIW75CHf65OeIOkyKbteujpZVXDpWK6YGZbxE=
github.com/miekg/dns v1.1.8 h1:1QYRAKU3lN5cRfLCkPU08hwvLJFhvjP6MqNMmQz6ZVI= | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * whois: use whois.arin.net
+ robust redirect mechanism
* decrease timeout 30sec -> 5sec
* faster response parsing
* don't use likexian/whois-go package | https://github.com/AdguardTeam/AdGuardHome/commit/37fe3c148f6edcb7ad8567ed2490f8c67208c50f | go.sum |
github.com/kardianos/service v0.0.0-20181115005516-4c239ee84e7b h1:vfiqKno48aUndBMjTeWFpCExNnTf2Xnd6d228L4EfTQ=
github.com/kardianos/service v0.0.0-20181115005516-4c239ee84e7b/go.mod h1:10UU/bEkzh2iEN6aYzbevY7J6p03KO5siTxQWXMEerg=
github.com/krolaw/dhcp4 v0.0.0-20180925202202-7cead472c414 h1:6wnYc2S/lVM7BvR32BM74ph7bPgqMztWopMYKgVyEho=
github.com/krolaw/dhcp4 v0.0.0-20180925202202-7cead472c414/go.mod h1:0AqAH3ZogsCrvrtUpvc6EtVKbc3w6xwZhkvGLuqyi3o=
github.com/likexian/gokit v0.0.0-20190309162924-0a377eecf7aa/go.mod h1:QdfYv6y6qPA9pbBA2qXtoT8BMKha6UyNbxWGWl/9Jfk=
github.com/likexian/gokit v0.0.0-20190418170008-ace88ad0983b/go.mod h1:KKqSnk/VVSW8kEyO2vVCXoanzEutKdlBAPohmGXkxCk=
github.com/likexian/gokit v0.0.0-20190501133040-e77ea8b19cdc/go.mod h1:3kvONayqCaj+UgrRZGpgfXzHdMYCAO0KAt4/8n0L57Y=
github.com/likexian/gokit v0.0.0-20190604165112-68b8a4ba758c h1:KByA4IxKqqYwpqzk/P+w1DBpkPbvy3DArTP/U3LSxTQ=
github.com/likexian/gokit v0.0.0-20190604165112-68b8a4ba758c/go.mod h1:kn+nTv3tqh6yhor9BC4Lfiu58SmH8NmQ2PmEl+uM6nU=
github.com/likexian/simplejson-go v0.0.0-20190409170913-40473a74d76d/go.mod h1:Typ1BfnATYtZ/+/shXfFYLrovhFyuKvzwrdOnIDHlmg=
github.com/likexian/simplejson-go v0.0.0-20190419151922-c1f9f0b4f084/go.mod h1:U4O1vIJvIKwbMZKUJ62lppfdvkCdVd2nfMimHK81eec=
github.com/likexian/simplejson-go v0.0.0-20190502021454-d8787b4bfa0b/go.mod h1:3BWwtmKP9cXWwYCr5bkoVDEfLywacOv0s06OBEDpyt8=
github.com/likexian/whois-go v0.0.0-20190627090909-384b3df3fc49 h1:xGa+flE6p2UnMgxIS8bm7Q9JSt47HRuYVtwneDVnfLk=
github.com/likexian/whois-go v0.0.0-20190627090909-384b3df3fc49/go.mod h1:oR3bJMzrOb55cqTAn14DEzYFLDpSPTXJ3ORe7go9Hc8=
github.com/markbates/oncer v0.0.0-20181014194634-05fccaae8fc4 h1:Mlji5gkcpzkqTROyE4ZxZ8hN7osunMb2RuGVrbvMvCc=
github.com/markbates/oncer v0.0.0-20181014194634-05fccaae8fc4/go.mod h1:Ld9puTsIW75CHf65OeIOkyKbteujpZVXDpWK6YGZbxE=
github.com/miekg/dns v1.1.8 h1:1QYRAKU3lN5cRfLCkPU08hwvLJFhvjP6MqNMmQz6ZVI=
github.com/miekg/dns v1.1.8/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/miekg/dns v1.1.19 h1:0ymbfaLG1/utH2+BydNiF+dx1jSEmdr/nylOtkGHZZg=
| </s> remove github.com/likexian/whois-go v0.0.0-20190627090909-384b3df3fc49
</s> add </s> remove resp, err := whois.Whois("8.8.8.8")
</s> add w := Whois{timeoutMsec: 5000}
resp, err := w.queryAll("8.8.8.8") </s> remove github.com/AdguardTeam/dnsproxy v0.19.4 h1:rZb40VUr/yN8RG4j3+NuGqODmPvte7acPfSDl0j2wiU=
github.com/AdguardTeam/dnsproxy v0.19.4/go.mod h1:NaulY9i279jZwN8QBbvbZnn5HkrjBgJi4hbFY5nW+Kc=
</s> add | github.com/kardianos/service v0.0.0-20181115005516-4c239ee84e7b h1:vfiqKno48aUndBMjTeWFpCExNnTf2Xnd6d228L4EfTQ=
github.com/kardianos/service v0.0.0-20181115005516-4c239ee84e7b/go.mod h1:10UU/bEkzh2iEN6aYzbevY7J6p03KO5siTxQWXMEerg=
github.com/krolaw/dhcp4 v0.0.0-20180925202202-7cead472c414 h1:6wnYc2S/lVM7BvR32BM74ph7bPgqMztWopMYKgVyEho=
github.com/krolaw/dhcp4 v0.0.0-20180925202202-7cead472c414/go.mod h1:0AqAH3ZogsCrvrtUpvc6EtVKbc3w6xwZhkvGLuqyi3o=
github.com/markbates/oncer v0.0.0-20181014194634-05fccaae8fc4 h1:Mlji5gkcpzkqTROyE4ZxZ8hN7osunMb2RuGVrbvMvCc=
github.com/markbates/oncer v0.0.0-20181014194634-05fccaae8fc4/go.mod h1:Ld9puTsIW75CHf65OeIOkyKbteujpZVXDpWK6YGZbxE=
github.com/miekg/dns v1.1.8 h1:1QYRAKU3lN5cRfLCkPU08hwvLJFhvjP6MqNMmQz6ZVI=
github.com/miekg/dns v1.1.8/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/miekg/dns v1.1.19 h1:0ymbfaLG1/utH2+BydNiF+dx1jSEmdr/nylOtkGHZZg= | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * whois: use whois.arin.net
+ robust redirect mechanism
* decrease timeout 30sec -> 5sec
* faster response parsing
* don't use likexian/whois-go package | https://github.com/AdguardTeam/AdGuardHome/commit/37fe3c148f6edcb7ad8567ed2490f8c67208c50f | go.sum |
|
github.com/rogpeppe/go-charset v0.0.0-20180617210344-2471d30d28b4/go.mod h1:qgYeAmZ5ZIpBWTGllZSQnw97Dj+woV0toclVaRGI8pc=
github.com/rogpeppe/go-charset v0.0.0-20190617161244-0dc95cdf6f31/go.mod h1:qgYeAmZ5ZIpBWTGllZSQnw97Dj+woV0toclVaRGI8pc=
github.com/shirou/gopsutil v2.18.12+incompatible h1:1eaJvGomDnH74/5cF4CTmTbLHAriGFsTZppLXDX93OM=
github.com/shirou/gopsutil v2.18.12+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shirou/gopsutil v2.19.9+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 h1:udFKJ0aHUL60LboW/A+DfgoHVedieIzIXE8uylPue0U=
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4/go.mod h1:qsXQc7+bwAM3Q1u/4XEfrquwF8Lw7D7y5cD8CuHnfIc=
github.com/sparrc/go-ping v0.0.0-20181106165434-ef3ab45e41b0 h1:mu7brOsdaH5Dqf93vdch+mr/0To8Sgc+yInt/jE/RJM=
| </s> remove github.com/likexian/whois-go v0.0.0-20190627090909-384b3df3fc49
</s> add </s> remove resp, err := whois.Whois("8.8.8.8")
</s> add w := Whois{timeoutMsec: 5000}
resp, err := w.queryAll("8.8.8.8") </s> remove github.com/AdguardTeam/dnsproxy v0.19.4 h1:rZb40VUr/yN8RG4j3+NuGqODmPvte7acPfSDl0j2wiU=
github.com/AdguardTeam/dnsproxy v0.19.4/go.mod h1:NaulY9i279jZwN8QBbvbZnn5HkrjBgJi4hbFY5nW+Kc=
</s> add </s> remove github.com/AdguardTeam/urlfilter v0.5.0 h1:ATzs2Er0BMt7NbZnFJ4UEzt3uIV+rydbQCYqBXNRbJc=
github.com/AdguardTeam/urlfilter v0.5.0/go.mod h1:6YehXZ8e0Hx2MvqeQWLFom6IkPinm04tNhO1CkwAxmg=
</s> add | github.com/shirou/gopsutil v2.19.9+incompatible h1:IrPVlK4nfwW10DF7pW+7YJKws9NkgNzWozwwWv9FsgY= | github.com/rogpeppe/go-charset v0.0.0-20180617210344-2471d30d28b4/go.mod h1:qgYeAmZ5ZIpBWTGllZSQnw97Dj+woV0toclVaRGI8pc=
github.com/rogpeppe/go-charset v0.0.0-20190617161244-0dc95cdf6f31/go.mod h1:qgYeAmZ5ZIpBWTGllZSQnw97Dj+woV0toclVaRGI8pc=
github.com/shirou/gopsutil v2.18.12+incompatible h1:1eaJvGomDnH74/5cF4CTmTbLHAriGFsTZppLXDX93OM=
github.com/shirou/gopsutil v2.18.12+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shirou/gopsutil v2.19.9+incompatible h1:IrPVlK4nfwW10DF7pW+7YJKws9NkgNzWozwwWv9FsgY=
github.com/shirou/gopsutil v2.19.9+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 h1:udFKJ0aHUL60LboW/A+DfgoHVedieIzIXE8uylPue0U=
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4/go.mod h1:qsXQc7+bwAM3Q1u/4XEfrquwF8Lw7D7y5cD8CuHnfIc=
github.com/sparrc/go-ping v0.0.0-20181106165434-ef3ab45e41b0 h1:mu7brOsdaH5Dqf93vdch+mr/0To8Sgc+yInt/jE/RJM= | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | * whois: use whois.arin.net
+ robust redirect mechanism
* decrease timeout 30sec -> 5sec
* faster response parsing
* don't use likexian/whois-go package | https://github.com/AdguardTeam/AdGuardHome/commit/37fe3c148f6edcb7ad8567ed2490f8c67208c50f | go.sum |
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9 h1:mKdxBk7AujPs8kU4m80U72y/zjbZ3UcXC7dClwKbUI0=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5 h1:58fnuSXlxZmFdJyvtTFVmVhcMLU6v5fEb/ok4wyqtNU=
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY=
golang.org/x/crypto v0.0.0-20191001170739-f9e2070545dc h1:KyTYo8xkh/2WdbFLUyQwBS0Jfn3qfZ9QmuPbok2oENE=
golang.org/x/crypto v0.0.0-20191001170739-f9e2070545dc/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/net v0.0.0-20181102091132-c10e9556a7bc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190119204137-ed066c81e75e h1:MDa3fSUp6MdYHouVmCCNz/zaH2a6CRcxY3VhT/K3C5Q=
| </s> remove github.com/likexian/whois-go v0.0.0-20190627090909-384b3df3fc49
</s> add </s> remove assert.True(t, strings.Index(resp, "OrgName: Google LLC") != -1)
assert.True(t, strings.Index(resp, "City: Mountain View") != -1)
assert.True(t, strings.Index(resp, "Country: US") != -1)
</s> add </s> remove resp, err := whois.Whois("8.8.8.8")
</s> add w := Whois{timeoutMsec: 5000}
resp, err := w.queryAll("8.8.8.8") </s> remove github.com/AdguardTeam/dnsproxy v0.19.4 h1:rZb40VUr/yN8RG4j3+NuGqODmPvte7acPfSDl0j2wiU=
github.com/AdguardTeam/dnsproxy v0.19.4/go.mod h1:NaulY9i279jZwN8QBbvbZnn5HkrjBgJi4hbFY5nW+Kc=
</s> add </s> remove github.com/AdguardTeam/urlfilter v0.5.0 h1:ATzs2Er0BMt7NbZnFJ4UEzt3uIV+rydbQCYqBXNRbJc=
github.com/AdguardTeam/urlfilter v0.5.0/go.mod h1:6YehXZ8e0Hx2MvqeQWLFom6IkPinm04tNhO1CkwAxmg=
</s> add | golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9 h1:mKdxBk7AujPs8kU4m80U72y/zjbZ3UcXC7dClwKbUI0=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY=
golang.org/x/crypto v0.0.0-20191001170739-f9e2070545dc h1:KyTYo8xkh/2WdbFLUyQwBS0Jfn3qfZ9QmuPbok2oENE=
golang.org/x/crypto v0.0.0-20191001170739-f9e2070545dc/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/net v0.0.0-20181102091132-c10e9556a7bc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190119204137-ed066c81e75e h1:MDa3fSUp6MdYHouVmCCNz/zaH2a6CRcxY3VhT/K3C5Q= | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * whois: use whois.arin.net
+ robust redirect mechanism
* decrease timeout 30sec -> 5sec
* faster response parsing
* don't use likexian/whois-go package | https://github.com/AdguardTeam/AdGuardHome/commit/37fe3c148f6edcb7ad8567ed2490f8c67208c50f | go.sum |
|
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190122071731-054c452bb702 h1:Lk4tbZFnlyPgV+sLgTw5yGfzrlOn9kx4vSombi2FFlY=
golang.org/x/sys v0.0.0-20190122071731-054c452bb702/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
| </s> remove golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0 h1:HyfiK1WMnHj5FXFXatD+Qs1A/xC2Run6RzeW1SyHxpc=
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
</s> add </s> remove assert.True(t, strings.Index(resp, "OrgName: Google LLC") != -1)
assert.True(t, strings.Index(resp, "City: Mountain View") != -1)
assert.True(t, strings.Index(resp, "Country: US") != -1)
</s> add </s> remove resp, err := whois.Whois("8.8.8.8")
</s> add w := Whois{timeoutMsec: 5000}
resp, err := w.queryAll("8.8.8.8") </s> remove github.com/likexian/whois-go v0.0.0-20190627090909-384b3df3fc49
</s> add </s> remove github.com/AdguardTeam/dnsproxy v0.19.4 h1:rZb40VUr/yN8RG4j3+NuGqODmPvte7acPfSDl0j2wiU=
github.com/AdguardTeam/dnsproxy v0.19.4/go.mod h1:NaulY9i279jZwN8QBbvbZnn5HkrjBgJi4hbFY5nW+Kc=
</s> add | golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY= | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190122071731-054c452bb702 h1:Lk4tbZFnlyPgV+sLgTw5yGfzrlOn9kx4vSombi2FFlY=
golang.org/x/sys v0.0.0-20190122071731-054c452bb702/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * whois: use whois.arin.net
+ robust redirect mechanism
* decrease timeout 30sec -> 5sec
* faster response parsing
* don't use likexian/whois-go package | https://github.com/AdguardTeam/AdGuardHome/commit/37fe3c148f6edcb7ad8567ed2490f8c67208c50f | go.sum |
golang.org/x/sys v0.0.0-20190122071731-054c452bb702/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0 h1:HyfiK1WMnHj5FXFXatD+Qs1A/xC2Run6RzeW1SyHxpc=
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191002091554-b397fe3ad8ed h1:5TJcLJn2a55mJjzYk0yOoqN8X1OdvBDUnaZaKKyQtkY=
golang.org/x/sys v0.0.0-20191002091554-b397fe3ad8ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
| </s> remove assert.True(t, strings.Index(resp, "OrgName: Google LLC") != -1)
assert.True(t, strings.Index(resp, "City: Mountain View") != -1)
assert.True(t, strings.Index(resp, "Country: US") != -1)
</s> add </s> remove resp, err := whois.Whois("8.8.8.8")
</s> add w := Whois{timeoutMsec: 5000}
resp, err := w.queryAll("8.8.8.8") </s> remove github.com/likexian/whois-go v0.0.0-20190627090909-384b3df3fc49
</s> add </s> remove github.com/AdguardTeam/dnsproxy v0.19.4 h1:rZb40VUr/yN8RG4j3+NuGqODmPvte7acPfSDl0j2wiU=
github.com/AdguardTeam/dnsproxy v0.19.4/go.mod h1:NaulY9i279jZwN8QBbvbZnn5HkrjBgJi4hbFY5nW+Kc=
</s> add | golang.org/x/sys v0.0.0-20190122071731-054c452bb702/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191002091554-b397fe3ad8ed h1:5TJcLJn2a55mJjzYk0yOoqN8X1OdvBDUnaZaKKyQtkY=
golang.org/x/sys v0.0.0-20191002091554-b397fe3ad8ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * whois: use whois.arin.net
+ robust redirect mechanism
* decrease timeout 30sec -> 5sec
* faster response parsing
* don't use likexian/whois-go package | https://github.com/AdguardTeam/AdGuardHome/commit/37fe3c148f6edcb7ad8567ed2490f8c67208c50f | go.sum |
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.3 h1:fvjTMHxHEw/mxHbtzPi3JCcKXQRAnQTBRo6YCJSVHKI=
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
| </s> remove assert.True(t, strings.Index(resp, "OrgName: Google LLC") != -1)
assert.True(t, strings.Index(resp, "City: Mountain View") != -1)
assert.True(t, strings.Index(resp, "Country: US") != -1)
</s> add </s> remove resp, err := whois.Whois("8.8.8.8")
</s> add w := Whois{timeoutMsec: 5000}
resp, err := w.queryAll("8.8.8.8") </s> remove github.com/likexian/whois-go v0.0.0-20190627090909-384b3df3fc49
</s> add </s> remove github.com/AdguardTeam/dnsproxy v0.19.4 h1:rZb40VUr/yN8RG4j3+NuGqODmPvte7acPfSDl0j2wiU=
github.com/AdguardTeam/dnsproxy v0.19.4/go.mod h1:NaulY9i279jZwN8QBbvbZnn5HkrjBgJi4hbFY5nW+Kc=
</s> add </s> remove github.com/AdguardTeam/urlfilter v0.5.0 h1:ATzs2Er0BMt7NbZnFJ4UEzt3uIV+rydbQCYqBXNRbJc=
github.com/AdguardTeam/urlfilter v0.5.0/go.mod h1:6YehXZ8e0Hx2MvqeQWLFom6IkPinm04tNhO1CkwAxmg=
</s> add | gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.3 h1:fvjTMHxHEw/mxHbtzPi3JCcKXQRAnQTBRo6YCJSVHKI=
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * whois: use whois.arin.net
+ robust redirect mechanism
* decrease timeout 30sec -> 5sec
* faster response parsing
* don't use likexian/whois-go package | https://github.com/AdguardTeam/AdGuardHome/commit/37fe3c148f6edcb7ad8567ed2490f8c67208c50f | go.sum |
config.dnsctx.rdns = InitRDNS(&config.clients)
config.dnsctx.whois = initWhois(&config.clients)
topClients := config.stats.GetTopData(30)
for _, ip := range topClients {
ipAddr := net.ParseIP(ip)
if !ipAddr.IsLoopback() {
config.dnsctx.rdns.Begin(ip)
}
| </s> remove info := whoisProcess(ip)
</s> add info := w.process(ip) </s> remove lines := strings.Split(data, "\n")
for _, ln := range lines {
ln = strings.TrimSpace(ln)
if len(ln) == 0 || ln[0] == '#' {
</s> add for len(data) != 0 {
ln := SplitNext(&data, '\n')
if len(ln) == 0 || ln[0] == '#' || ln[0] == '%' { </s> remove resp, err := whois.Whois(ip)
</s> add resp, err := w.queryAll(ip) | const topClientsNumber = 30 // the number of clients to get
topClients := config.stats.GetTopClientsIP(topClientsNumber) |
config.dnsctx.rdns = InitRDNS(&config.clients)
config.dnsctx.whois = initWhois(&config.clients)
const topClientsNumber = 30 // the number of clients to get
topClients := config.stats.GetTopClientsIP(topClientsNumber)
for _, ip := range topClients {
ipAddr := net.ParseIP(ip)
if !ipAddr.IsLoopback() {
config.dnsctx.rdns.Begin(ip)
} | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * whois: use whois.arin.net
+ robust redirect mechanism
* decrease timeout 30sec -> 5sec
* faster response parsing
* don't use likexian/whois-go package | https://github.com/AdguardTeam/AdGuardHome/commit/37fe3c148f6edcb7ad8567ed2490f8c67208c50f | home/dns.go |
import (
"testing"
"github.com/AdguardTeam/golibs/log"
)
func TestGetValidNetInterfacesForWeb(t *testing.T) {
ifaces, err := getValidNetInterfacesForWeb()
| </s> remove whois "github.com/likexian/whois-go"
</s> add </s> remove "strings"
</s> add </s> remove resp, err := whois.Whois("8.8.8.8")
</s> add w := Whois{timeoutMsec: 5000}
resp, err := w.queryAll("8.8.8.8") | "github.com/stretchr/testify/assert" | import (
"testing"
"github.com/AdguardTeam/golibs/log"
"github.com/stretchr/testify/assert"
)
func TestGetValidNetInterfacesForWeb(t *testing.T) {
ifaces, err := getValidNetInterfacesForWeb() | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | * whois: use whois.arin.net
+ robust redirect mechanism
* decrease timeout 30sec -> 5sec
* faster response parsing
* don't use likexian/whois-go package | https://github.com/AdguardTeam/AdGuardHome/commit/37fe3c148f6edcb7ad8567ed2490f8c67208c50f | home/helpers_test.go |
log.Printf("%v", iface)
}
}
| </s> remove info := whoisProcess(ip)
</s> add info := w.process(ip) </s> remove resp, err := whois.Whois(ip)
</s> add resp, err := w.queryAll(ip) </s> remove topClients := config.stats.GetTopData(30)
</s> add const topClientsNumber = 30 // the number of clients to get
topClients := config.stats.GetTopClientsIP(topClientsNumber) | func TestSplitNext(t *testing.T) {
s := " a,b , c "
assert.True(t, SplitNext(&s, ',') == "a")
assert.True(t, SplitNext(&s, ',') == "b")
assert.True(t, SplitNext(&s, ',') == "c" && len(s) == 0)
} |
log.Printf("%v", iface)
}
}
func TestSplitNext(t *testing.T) {
s := " a,b , c "
assert.True(t, SplitNext(&s, ',') == "a")
assert.True(t, SplitNext(&s, ',') == "b")
assert.True(t, SplitNext(&s, ',') == "c" && len(s) == 0)
} | [
"keep",
"keep",
"keep",
"add"
] | * whois: use whois.arin.net
+ robust redirect mechanism
* decrease timeout 30sec -> 5sec
* faster response parsing
* don't use likexian/whois-go package | https://github.com/AdguardTeam/AdGuardHome/commit/37fe3c148f6edcb7ad8567ed2490f8c67208c50f | home/helpers_test.go |
import (
"strings"
"sync"
"time"
"github.com/AdguardTeam/golibs/log"
| </s> remove whois "github.com/likexian/whois-go"
</s> add </s> remove "strings"
</s> add </s> remove whois "github.com/likexian/whois-go"
</s> add | "fmt"
"io/ioutil"
"net" |
import (
"fmt"
"io/ioutil"
"net"
"strings"
"sync"
"time"
"github.com/AdguardTeam/golibs/log" | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * whois: use whois.arin.net
+ robust redirect mechanism
* decrease timeout 30sec -> 5sec
* faster response parsing
* don't use likexian/whois-go package | https://github.com/AdguardTeam/AdGuardHome/commit/37fe3c148f6edcb7ad8567ed2490f8c67208c50f | home/whois.go |
"io/ioutil"
"net"
"strings"
"sync"
"github.com/AdguardTeam/golibs/log"
)
const (
| </s> remove whois "github.com/likexian/whois-go"
</s> add </s> remove const maxValueLength = 250
</s> add const (
defaultServer = "whois.arin.net"
defaultPort = "43"
maxValueLength = 250
) </s> remove "strings"
</s> add | "time" | "io/ioutil"
"net"
"strings"
"sync"
"time"
"github.com/AdguardTeam/golibs/log"
)
const ( | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * whois: use whois.arin.net
+ robust redirect mechanism
* decrease timeout 30sec -> 5sec
* faster response parsing
* don't use likexian/whois-go package | https://github.com/AdguardTeam/AdGuardHome/commit/37fe3c148f6edcb7ad8567ed2490f8c67208c50f | home/whois.go |
"strings"
"sync"
"github.com/AdguardTeam/golibs/log"
whois "github.com/likexian/whois-go"
)
const maxValueLength = 250
// Whois - module context
| </s> remove const maxValueLength = 250
</s> add const (
defaultServer = "whois.arin.net"
defaultPort = "43"
maxValueLength = 250
) </s> remove clients *clientsContainer
ips map[string]bool
lock sync.Mutex
ipChan chan string
</s> add clients *clientsContainer
ips map[string]bool
lock sync.Mutex
ipChan chan string
timeoutMsec uint </s> remove "strings"
</s> add </s> remove whois "github.com/likexian/whois-go"
</s> add | "strings"
"sync"
"github.com/AdguardTeam/golibs/log"
)
const maxValueLength = 250
// Whois - module context | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * whois: use whois.arin.net
+ robust redirect mechanism
* decrease timeout 30sec -> 5sec
* faster response parsing
* don't use likexian/whois-go package | https://github.com/AdguardTeam/AdGuardHome/commit/37fe3c148f6edcb7ad8567ed2490f8c67208c50f | home/whois.go |
|
"github.com/AdguardTeam/golibs/log"
whois "github.com/likexian/whois-go"
)
const maxValueLength = 250
// Whois - module context
type Whois struct {
clients *clientsContainer
ips map[string]bool
| </s> remove clients *clientsContainer
ips map[string]bool
lock sync.Mutex
ipChan chan string
</s> add clients *clientsContainer
ips map[string]bool
lock sync.Mutex
ipChan chan string
timeoutMsec uint </s> remove whois "github.com/likexian/whois-go"
</s> add </s> remove "strings"
</s> add </s> remove whois "github.com/likexian/whois-go"
</s> add | const (
defaultServer = "whois.arin.net"
defaultPort = "43"
maxValueLength = 250
) | "github.com/AdguardTeam/golibs/log"
whois "github.com/likexian/whois-go"
)
const (
defaultServer = "whois.arin.net"
defaultPort = "43"
maxValueLength = 250
)
// Whois - module context
type Whois struct {
clients *clientsContainer
ips map[string]bool | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * whois: use whois.arin.net
+ robust redirect mechanism
* decrease timeout 30sec -> 5sec
* faster response parsing
* don't use likexian/whois-go package | https://github.com/AdguardTeam/AdGuardHome/commit/37fe3c148f6edcb7ad8567ed2490f8c67208c50f | home/whois.go |
const maxValueLength = 250
// Whois - module context
type Whois struct {
clients *clientsContainer
ips map[string]bool
lock sync.Mutex
ipChan chan string
}
// Create module context
func initWhois(clients *clientsContainer) *Whois {
w := Whois{}
| </s> remove const maxValueLength = 250
</s> add const (
defaultServer = "whois.arin.net"
defaultPort = "43"
maxValueLength = 250
) </s> remove whois "github.com/likexian/whois-go"
</s> add </s> remove topClients := config.stats.GetTopData(30)
</s> add const topClientsNumber = 30 // the number of clients to get
topClients := config.stats.GetTopClientsIP(topClientsNumber) </s> remove info := whoisProcess(ip)
</s> add info := w.process(ip) | clients *clientsContainer
ips map[string]bool
lock sync.Mutex
ipChan chan string
timeoutMsec uint | const maxValueLength = 250
// Whois - module context
type Whois struct {
clients *clientsContainer
ips map[string]bool
lock sync.Mutex
ipChan chan string
timeoutMsec uint
clients *clientsContainer
ips map[string]bool
lock sync.Mutex
ipChan chan string
timeoutMsec uint
clients *clientsContainer
ips map[string]bool
lock sync.Mutex
ipChan chan string
timeoutMsec uint
clients *clientsContainer
ips map[string]bool
lock sync.Mutex
ipChan chan string
timeoutMsec uint
}
// Create module context
func initWhois(clients *clientsContainer) *Whois {
w := Whois{} | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * whois: use whois.arin.net
+ robust redirect mechanism
* decrease timeout 30sec -> 5sec
* faster response parsing
* don't use likexian/whois-go package | https://github.com/AdguardTeam/AdGuardHome/commit/37fe3c148f6edcb7ad8567ed2490f8c67208c50f | home/whois.go |
func initWhois(clients *clientsContainer) *Whois {
w := Whois{}
w.clients = clients
w.ips = make(map[string]bool)
w.ipChan = make(chan string, 255)
go w.workerLoop()
return &w
}
| </s> remove clients *clientsContainer
ips map[string]bool
lock sync.Mutex
ipChan chan string
</s> add clients *clientsContainer
ips map[string]bool
lock sync.Mutex
ipChan chan string
timeoutMsec uint </s> remove topClients := config.stats.GetTopData(30)
</s> add const topClientsNumber = 30 // the number of clients to get
topClients := config.stats.GetTopClientsIP(topClientsNumber) </s> remove const maxValueLength = 250
</s> add const (
defaultServer = "whois.arin.net"
defaultPort = "43"
maxValueLength = 250
) </s> remove func whoisProcess(ip string) [][]string {
</s> add func (w *Whois) process(ip string) [][]string { | w.timeoutMsec = 5000 | func initWhois(clients *clientsContainer) *Whois {
w := Whois{}
w.timeoutMsec = 5000
w.clients = clients
w.ips = make(map[string]bool)
w.ipChan = make(chan string, 255)
go w.workerLoop()
return &w
} | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * whois: use whois.arin.net
+ robust redirect mechanism
* decrease timeout 30sec -> 5sec
* faster response parsing
* don't use likexian/whois-go package | https://github.com/AdguardTeam/AdGuardHome/commit/37fe3c148f6edcb7ad8567ed2490f8c67208c50f | home/whois.go |
func whoisParse(data string) map[string]string {
m := map[string]string{}
descr := ""
netname := ""
lines := strings.Split(data, "\n")
for _, ln := range lines {
ln = strings.TrimSpace(ln)
if len(ln) == 0 || ln[0] == '#' {
continue
}
kv := strings.SplitN(ln, ":", 2)
if len(kv) != 2 {
| </s> remove info := whoisProcess(ip)
</s> add info := w.process(ip) </s> remove topClients := config.stats.GetTopData(30)
</s> add const topClientsNumber = 30 // the number of clients to get
topClients := config.stats.GetTopClientsIP(topClientsNumber) </s> remove func whoisProcess(ip string) [][]string {
</s> add func (w *Whois) process(ip string) [][]string { </s> remove assert.True(t, strings.Index(resp, "OrgName: Google LLC") != -1)
assert.True(t, strings.Index(resp, "City: Mountain View") != -1)
assert.True(t, strings.Index(resp, "Country: US") != -1)
</s> add | for len(data) != 0 {
ln := SplitNext(&data, '\n')
if len(ln) == 0 || ln[0] == '#' || ln[0] == '%' { | func whoisParse(data string) map[string]string {
m := map[string]string{}
descr := ""
netname := ""
for len(data) != 0 {
ln := SplitNext(&data, '\n')
if len(ln) == 0 || ln[0] == '#' || ln[0] == '%' {
for len(data) != 0 {
ln := SplitNext(&data, '\n')
if len(ln) == 0 || ln[0] == '#' || ln[0] == '%' {
for len(data) != 0 {
ln := SplitNext(&data, '\n')
if len(ln) == 0 || ln[0] == '#' || ln[0] == '%' {
for len(data) != 0 {
ln := SplitNext(&data, '\n')
if len(ln) == 0 || ln[0] == '#' || ln[0] == '%' {
for len(data) != 0 {
ln := SplitNext(&data, '\n')
if len(ln) == 0 || ln[0] == '#' || ln[0] == '%' {
continue
}
kv := strings.SplitN(ln, ":", 2)
if len(kv) != 2 { | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * whois: use whois.arin.net
+ robust redirect mechanism
* decrease timeout 30sec -> 5sec
* faster response parsing
* don't use likexian/whois-go package | https://github.com/AdguardTeam/AdGuardHome/commit/37fe3c148f6edcb7ad8567ed2490f8c67208c50f | home/whois.go |
case "descr":
descr = v
case "netname":
netname = v
}
}
// descr or netname -> orgname
| </s> remove lines := strings.Split(data, "\n")
for _, ln := range lines {
ln = strings.TrimSpace(ln)
if len(ln) == 0 || ln[0] == '#' {
</s> add for len(data) != 0 {
ln := SplitNext(&data, '\n')
if len(ln) == 0 || ln[0] == '#' || ln[0] == '%' { </s> remove topClients := config.stats.GetTopData(30)
</s> add const topClientsNumber = 30 // the number of clients to get
topClients := config.stats.GetTopClientsIP(topClientsNumber) </s> remove const maxValueLength = 250
</s> add const (
defaultServer = "whois.arin.net"
defaultPort = "43"
maxValueLength = 250
) </s> remove info := whoisProcess(ip)
</s> add info := w.process(ip) | case "whois": // "whois: whois.arin.net"
m["whois"] = v
case "referralserver": // "ReferralServer: whois://whois.ripe.net"
if strings.HasPrefix(v, "whois://") {
m["whois"] = v[len("whois://"):]
} | case "descr":
descr = v
case "netname":
netname = v
case "whois": // "whois: whois.arin.net"
m["whois"] = v
case "referralserver": // "ReferralServer: whois://whois.ripe.net"
if strings.HasPrefix(v, "whois://") {
m["whois"] = v[len("whois://"):]
}
}
}
// descr or netname -> orgname | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | * whois: use whois.arin.net
+ robust redirect mechanism
* decrease timeout 30sec -> 5sec
* faster response parsing
* don't use likexian/whois-go package | https://github.com/AdguardTeam/AdGuardHome/commit/37fe3c148f6edcb7ad8567ed2490f8c67208c50f | home/whois.go |
return m
}
// Request WHOIS information
func whoisProcess(ip string) [][]string {
data := [][]string{}
resp, err := whois.Whois(ip)
if err != nil {
log.Debug("Whois: error: %s IP:%s", err, ip)
return data
| </s> remove resp, err := whois.Whois(ip)
</s> add resp, err := w.queryAll(ip) </s> remove resp, err := whois.Whois("8.8.8.8")
</s> add w := Whois{timeoutMsec: 5000}
resp, err := w.queryAll("8.8.8.8") </s> remove assert.True(t, strings.Index(resp, "OrgName: Google LLC") != -1)
assert.True(t, strings.Index(resp, "City: Mountain View") != -1)
assert.True(t, strings.Index(resp, "Country: US") != -1)
</s> add </s> remove lines := strings.Split(data, "\n")
for _, ln := range lines {
ln = strings.TrimSpace(ln)
if len(ln) == 0 || ln[0] == '#' {
</s> add for len(data) != 0 {
ln := SplitNext(&data, '\n')
if len(ln) == 0 || ln[0] == '#' || ln[0] == '%' { </s> remove whois "github.com/likexian/whois-go"
</s> add | func (w *Whois) process(ip string) [][]string { | return m
}
// Request WHOIS information
func (w *Whois) process(ip string) [][]string {
data := [][]string{}
resp, err := whois.Whois(ip)
if err != nil {
log.Debug("Whois: error: %s IP:%s", err, ip)
return data | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * whois: use whois.arin.net
+ robust redirect mechanism
* decrease timeout 30sec -> 5sec
* faster response parsing
* don't use likexian/whois-go package | https://github.com/AdguardTeam/AdGuardHome/commit/37fe3c148f6edcb7ad8567ed2490f8c67208c50f | home/whois.go |
// Request WHOIS information
func whoisProcess(ip string) [][]string {
data := [][]string{}
resp, err := whois.Whois(ip)
if err != nil {
log.Debug("Whois: error: %s IP:%s", err, ip)
return data
}
| </s> remove func whoisProcess(ip string) [][]string {
</s> add func (w *Whois) process(ip string) [][]string { </s> remove resp, err := whois.Whois("8.8.8.8")
</s> add w := Whois{timeoutMsec: 5000}
resp, err := w.queryAll("8.8.8.8") </s> remove assert.True(t, strings.Index(resp, "OrgName: Google LLC") != -1)
assert.True(t, strings.Index(resp, "City: Mountain View") != -1)
assert.True(t, strings.Index(resp, "Country: US") != -1)
</s> add </s> remove whois "github.com/likexian/whois-go"
</s> add </s> remove lines := strings.Split(data, "\n")
for _, ln := range lines {
ln = strings.TrimSpace(ln)
if len(ln) == 0 || ln[0] == '#' {
</s> add for len(data) != 0 {
ln := SplitNext(&data, '\n')
if len(ln) == 0 || ln[0] == '#' || ln[0] == '%' { | resp, err := w.queryAll(ip) |
// Request WHOIS information
func whoisProcess(ip string) [][]string {
data := [][]string{}
resp, err := w.queryAll(ip)
if err != nil {
log.Debug("Whois: error: %s IP:%s", err, ip)
return data
}
| [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * whois: use whois.arin.net
+ robust redirect mechanism
* decrease timeout 30sec -> 5sec
* faster response parsing
* don't use likexian/whois-go package | https://github.com/AdguardTeam/AdGuardHome/commit/37fe3c148f6edcb7ad8567ed2490f8c67208c50f | home/whois.go |
for {
var ip string
ip = <-w.ipChan
info := whoisProcess(ip)
if len(info) == 0 {
continue
}
w.clients.SetWhoisInfo(ip, info)
| </s> remove lines := strings.Split(data, "\n")
for _, ln := range lines {
ln = strings.TrimSpace(ln)
if len(ln) == 0 || ln[0] == '#' {
</s> add for len(data) != 0 {
ln := SplitNext(&data, '\n')
if len(ln) == 0 || ln[0] == '#' || ln[0] == '%' { </s> remove topClients := config.stats.GetTopData(30)
</s> add const topClientsNumber = 30 // the number of clients to get
topClients := config.stats.GetTopClientsIP(topClientsNumber) </s> remove clients *clientsContainer
ips map[string]bool
lock sync.Mutex
ipChan chan string
</s> add clients *clientsContainer
ips map[string]bool
lock sync.Mutex
ipChan chan string
timeoutMsec uint | info := w.process(ip) | for {
var ip string
ip = <-w.ipChan
info := w.process(ip)
if len(info) == 0 {
continue
}
w.clients.SetWhoisInfo(ip, info) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * whois: use whois.arin.net
+ robust redirect mechanism
* decrease timeout 30sec -> 5sec
* faster response parsing
* don't use likexian/whois-go package | https://github.com/AdguardTeam/AdGuardHome/commit/37fe3c148f6edcb7ad8567ed2490f8c67208c50f | home/whois.go |
package home
import (
"strings"
"testing"
whois "github.com/likexian/whois-go"
"github.com/stretchr/testify/assert"
)
| </s> remove whois "github.com/likexian/whois-go"
</s> add </s> remove whois "github.com/likexian/whois-go"
</s> add </s> remove const maxValueLength = 250
</s> add const (
defaultServer = "whois.arin.net"
defaultPort = "43"
maxValueLength = 250
) | package home
import (
"testing"
whois "github.com/likexian/whois-go"
"github.com/stretchr/testify/assert"
) | [
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * whois: use whois.arin.net
+ robust redirect mechanism
* decrease timeout 30sec -> 5sec
* faster response parsing
* don't use likexian/whois-go package | https://github.com/AdguardTeam/AdGuardHome/commit/37fe3c148f6edcb7ad8567ed2490f8c67208c50f | home/whois_test.go |
|
import (
"strings"
"testing"
whois "github.com/likexian/whois-go"
"github.com/stretchr/testify/assert"
)
func TestWhois(t *testing.T) {
resp, err := whois.Whois("8.8.8.8")
| </s> remove "strings"
</s> add </s> remove resp, err := whois.Whois("8.8.8.8")
</s> add w := Whois{timeoutMsec: 5000}
resp, err := w.queryAll("8.8.8.8") </s> remove assert.True(t, strings.Index(resp, "OrgName: Google LLC") != -1)
assert.True(t, strings.Index(resp, "City: Mountain View") != -1)
assert.True(t, strings.Index(resp, "Country: US") != -1)
</s> add </s> remove whois "github.com/likexian/whois-go"
</s> add | import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestWhois(t *testing.T) {
resp, err := whois.Whois("8.8.8.8") | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * whois: use whois.arin.net
+ robust redirect mechanism
* decrease timeout 30sec -> 5sec
* faster response parsing
* don't use likexian/whois-go package | https://github.com/AdguardTeam/AdGuardHome/commit/37fe3c148f6edcb7ad8567ed2490f8c67208c50f | home/whois_test.go |
|
"github.com/stretchr/testify/assert"
)
func TestWhois(t *testing.T) {
resp, err := whois.Whois("8.8.8.8")
assert.True(t, err == nil)
assert.True(t, strings.Index(resp, "OrgName: Google LLC") != -1)
assert.True(t, strings.Index(resp, "City: Mountain View") != -1)
assert.True(t, strings.Index(resp, "Country: US") != -1)
m := whoisParse(resp)
| </s> remove assert.True(t, strings.Index(resp, "OrgName: Google LLC") != -1)
assert.True(t, strings.Index(resp, "City: Mountain View") != -1)
assert.True(t, strings.Index(resp, "Country: US") != -1)
</s> add </s> remove whois "github.com/likexian/whois-go"
</s> add </s> remove resp, err := whois.Whois(ip)
</s> add resp, err := w.queryAll(ip) </s> remove func whoisProcess(ip string) [][]string {
</s> add func (w *Whois) process(ip string) [][]string { | w := Whois{timeoutMsec: 5000}
resp, err := w.queryAll("8.8.8.8") | "github.com/stretchr/testify/assert"
)
func TestWhois(t *testing.T) {
w := Whois{timeoutMsec: 5000}
resp, err := w.queryAll("8.8.8.8")
assert.True(t, err == nil)
assert.True(t, strings.Index(resp, "OrgName: Google LLC") != -1)
assert.True(t, strings.Index(resp, "City: Mountain View") != -1)
assert.True(t, strings.Index(resp, "Country: US") != -1)
m := whoisParse(resp) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * whois: use whois.arin.net
+ robust redirect mechanism
* decrease timeout 30sec -> 5sec
* faster response parsing
* don't use likexian/whois-go package | https://github.com/AdguardTeam/AdGuardHome/commit/37fe3c148f6edcb7ad8567ed2490f8c67208c50f | home/whois_test.go |
func TestWhois(t *testing.T) {
resp, err := whois.Whois("8.8.8.8")
assert.True(t, err == nil)
assert.True(t, strings.Index(resp, "OrgName: Google LLC") != -1)
assert.True(t, strings.Index(resp, "City: Mountain View") != -1)
assert.True(t, strings.Index(resp, "Country: US") != -1)
m := whoisParse(resp)
assert.True(t, m["orgname"] == "Google LLC")
assert.True(t, m["country"] == "US")
assert.True(t, m["city"] == "Mountain View")
}
| </s> remove resp, err := whois.Whois("8.8.8.8")
</s> add w := Whois{timeoutMsec: 5000}
resp, err := w.queryAll("8.8.8.8") </s> remove lines := strings.Split(data, "\n")
for _, ln := range lines {
ln = strings.TrimSpace(ln)
if len(ln) == 0 || ln[0] == '#' {
</s> add for len(data) != 0 {
ln := SplitNext(&data, '\n')
if len(ln) == 0 || ln[0] == '#' || ln[0] == '%' { </s> remove whois "github.com/likexian/whois-go"
</s> add </s> remove resp, err := whois.Whois(ip)
</s> add resp, err := w.queryAll(ip) |
func TestWhois(t *testing.T) {
resp, err := whois.Whois("8.8.8.8")
assert.True(t, err == nil)
m := whoisParse(resp)
assert.True(t, m["orgname"] == "Google LLC")
assert.True(t, m["country"] == "US")
assert.True(t, m["city"] == "Mountain View")
} | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * whois: use whois.arin.net
+ robust redirect mechanism
* decrease timeout 30sec -> 5sec
* faster response parsing
* don't use likexian/whois-go package | https://github.com/AdguardTeam/AdGuardHome/commit/37fe3c148f6edcb7ad8567ed2490f8c67208c50f | home/whois_test.go |
|
"github.com/AdguardTeam/AdGuardHome/internal/aghtest"
"github.com/AdguardTeam/AdGuardHome/internal/dhcpd"
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
"github.com/AdguardTeam/AdGuardHome/internal/filtering/safesearch"
"github.com/AdguardTeam/dnsproxy/proxy"
"github.com/AdguardTeam/dnsproxy/upstream"
"github.com/AdguardTeam/golibs/netutil"
| </s> remove "github.com/AdguardTeam/golibs/cache"
</s> add "github.com/AdguardTeam/AdGuardHome/internal/filtering/hashprefix" </s> remove "time"
</s> add </s> remove "strings"
</s> add | "github.com/AdguardTeam/AdGuardHome/internal/filtering/hashprefix" | "github.com/AdguardTeam/AdGuardHome/internal/aghtest"
"github.com/AdguardTeam/AdGuardHome/internal/dhcpd"
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
"github.com/AdguardTeam/AdGuardHome/internal/filtering/hashprefix"
"github.com/AdguardTeam/AdGuardHome/internal/filtering/safesearch"
"github.com/AdguardTeam/dnsproxy/proxy"
"github.com/AdguardTeam/dnsproxy/upstream"
"github.com/AdguardTeam/golibs/netutil" | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | Pull request 1837: AG-21462-imp-safebrowsing-parental
Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master
Squashed commit of the following:
commit 85016d4f1105e21a407efade0bd45b8362808061
Merge: 0e61edade 620b51e3e
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 16:36:30 2023 +0300
Merge branch 'master' into AG-21462-imp-safebrowsing-parental
commit 0e61edadeff34f6305e941c1db94575c82f238d9
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 14:51:37 2023 +0300
filtering: imp tests
commit 994255514cc0f67dfe33d5a0892432e8924d1e36
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:13:19 2023 +0300
filtering: fix typo
commit 96d1069573171538333330d6af94ef0f4208a9c4
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:00:18 2023 +0300
filtering: imp code more
commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 19:13:26 2023 +0300
all: add todo
commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 14:36:08 2023 +0300
all: imp code more
commit b6e734ccbeda82669023f6578481260b7c1f7161
Author: Stanislav Chzhen <[email protected]>
Date: Tue Apr 25 15:01:56 2023 +0300
filtering: imp code
commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 20:06:36 2023 +0300
all: imp code
commit 49fa6e587052a40bb431fea457701ee860493527
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 14:57:19 2023 +0300
all: rm safe browsing ctx
commit bbcb66cb03e18fa875e3c33cf16295892739e507
Author: Stanislav Chzhen <[email protected]>
Date: Fri Apr 21 17:54:18 2023 +0300
filtering: add cache item
commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 18:43:02 2023 +0300
filtering: fix hashes
commit 153fec46270212af03f3631bfb42c5d680c4e142
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 16:15:15 2023 +0300
filtering: add test cases
commit 09372f92bbb1fc082f1b1283594ee589100209c5
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 15:38:05 2023 +0300
filtering: imp code
commit 466bc26d524ea6d1c3efb33692a7785d39e491ca
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 18:38:40 2023 +0300
filtering: add tests
commit 24365ecf8c60512fdac65833ee603c80864ae018
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 11:38:57 2023 +0300
filtering: add hashprefix | https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c | internal/dnsforward/dnsforward_test.go |
assert.Equalf(t, net.IP{127, 0, 0, 1}, a.A, "dns server %s returned wrong answer instead of 8.8.8.8: %v", addr, a.A)
}
func TestBlockedBySafeBrowsing(t *testing.T) {
const hostname = "wmconvirus.narod.ru"
sbUps := aghtest.NewBlockUpstream(hostname, true)
ans4, _ := (&aghtest.TestResolver{}).HostToIPs(hostname)
filterConf := &filtering.Config{
| </s> remove sbUps := aghtest.NewBlockUpstream(hostname, true)
</s> add </s> remove ParentalEnabled: true,
SafeBrowsingEnabled: false,
</s> add ParentalEnabled: true,
SafeBrowsingEnabled: false,
SafeBrowsingChecker: newChecker(sbBlocked),
ParentalControlChecker: newChecker(pcBlocked), </s> remove d, setts := newForTest(t, &Config{SafeBrowsingEnabled: true}, nil)
</s> add d, setts := newForTest(t, &Config{
SafeBrowsingEnabled: true,
SafeBrowsingChecker: newChecker(sbBlocked),
}, nil) </s> remove // TODO(a.garipov): Make configurable.
const (
dnsTimeout = 3 * time.Second
defaultSafebrowsingServer = `https://family.adguard-dns.com/dns-query`
defaultParentalServer = `https://family.adguard-dns.com/dns-query`
sbTXTSuffix = `sb.dns.adguard.com.`
pcTXTSuffix = `pc.dns.adguard.com.`
)
// SetParentalUpstream sets the parental upstream for *DNSFilter.
//
// TODO(e.burkov): Remove this in v1 API to forbid the direct access.
func (d *DNSFilter) SetParentalUpstream(u upstream.Upstream) {
d.parentalUpstream = u
}
// SetSafeBrowsingUpstream sets the safe browsing upstream for *DNSFilter.
//
// TODO(e.burkov): Remove this in v1 API to forbid the direct access.
func (d *DNSFilter) SetSafeBrowsingUpstream(u upstream.Upstream) {
d.safeBrowsingUpstream = u
}
func (d *DNSFilter) initSecurityServices() error {
var err error
d.safeBrowsingServer = defaultSafebrowsingServer
d.parentalServer = defaultParentalServer
opts := &upstream.Options{
Timeout: dnsTimeout,
ServerIPAddrs: []net.IP{
{94, 140, 14, 15},
{94, 140, 15, 16},
net.ParseIP("2a10:50c0::bad1:ff"),
net.ParseIP("2a10:50c0::bad2:ff"),
},
}
parUps, err := upstream.AddressToUpstream(d.parentalServer, opts)
if err != nil {
return fmt.Errorf("converting parental server: %w", err)
}
d.SetParentalUpstream(parUps)
sbUps, err := upstream.AddressToUpstream(d.safeBrowsingServer, opts)
if err != nil {
return fmt.Errorf("converting safe browsing server: %w", err)
}
d.SetSafeBrowsingUpstream(sbUps)
return nil
}
/*
expire byte[4]
hash byte[32]
...
*/
func (c *sbCtx) setCache(prefix, hashes []byte) {
d := make([]byte, 4+len(hashes))
expire := uint(time.Now().Unix()) + c.cacheTime*60
binary.BigEndian.PutUint32(d[:4], uint32(expire))
copy(d[4:], hashes)
c.cache.Set(prefix, d)
log.Debug("%s: stored in cache: %v", c.svc, prefix)
}
// findInHash returns 32-byte hash if it's found in hashToHost.
func (c *sbCtx) findInHash(val []byte) (hash32 [32]byte, found bool) {
for i := 4; i < len(val); i += 32 {
hash := val[i : i+32]
copy(hash32[:], hash[0:32])
_, found = c.hashToHost[hash32]
if found {
return hash32, found
}
}
return [32]byte{}, false
}
func (c *sbCtx) getCached() int {
now := time.Now().Unix()
hashesToRequest := map[[32]byte]string{}
for k, v := range c.hashToHost {
// nolint:looppointer // The subsilce is used for a safe cache lookup.
val := c.cache.Get(k[0:2])
if val == nil || now >= int64(binary.BigEndian.Uint32(val)) {
hashesToRequest[k] = v
continue
}
if hash32, found := c.findInHash(val); found {
log.Debug("%s: found in cache: %s: blocked by %v", c.svc, c.host, hash32)
return 1
}
}
if len(hashesToRequest) == 0 {
log.Debug("%s: found in cache: %s: not blocked", c.svc, c.host)
return -1
}
c.hashToHost = hashesToRequest
return 0
}
type sbCtx struct {
host string
svc string
hashToHost map[[32]byte]string
cache cache.Cache
cacheTime uint
}
func hostnameToHashes(host string) map[[32]byte]string {
hashes := map[[32]byte]string{}
tld, icann := publicsuffix.PublicSuffix(host)
if !icann {
// private suffixes like cloudfront.net
tld = ""
}
curhost := host
nDots := 0
for i := len(curhost) - 1; i >= 0; i-- {
if curhost[i] == '.' {
nDots++
if nDots == 4 {
curhost = curhost[i+1:] // "xxx.a.b.c.d" -> "a.b.c.d"
break
}
}
}
for {
if curhost == "" {
// we've reached end of string
break
}
if tld != "" && curhost == tld {
// we've reached the TLD, don't hash it
break
}
sum := sha256.Sum256([]byte(curhost))
hashes[sum] = curhost
pos := strings.IndexByte(curhost, byte('.'))
if pos < 0 {
break
}
curhost = curhost[pos+1:]
}
return hashes
}
// convert hash array to string
func (c *sbCtx) getQuestion() string {
b := &strings.Builder{}
for hash := range c.hashToHost {
// nolint:looppointer // The subsilce is used for safe hex encoding.
stringutil.WriteToBuilder(b, hex.EncodeToString(hash[0:2]), ".")
}
if c.svc == "SafeBrowsing" {
stringutil.WriteToBuilder(b, sbTXTSuffix)
return b.String()
}
stringutil.WriteToBuilder(b, pcTXTSuffix)
return b.String()
}
// Find the target hash in TXT response
func (c *sbCtx) processTXT(resp *dns.Msg) (bool, [][]byte) {
matched := false
hashes := [][]byte{}
for _, a := range resp.Answer {
txt, ok := a.(*dns.TXT)
if !ok {
continue
}
log.Debug("%s: received hashes for %s: %v", c.svc, c.host, txt.Txt)
for _, t := range txt.Txt {
if len(t) != 32*2 {
continue
}
hash, err := hex.DecodeString(t)
if err != nil {
continue
}
hashes = append(hashes, hash)
if !matched {
var hash32 [32]byte
copy(hash32[:], hash)
var hashHost string
hashHost, ok = c.hashToHost[hash32]
if ok {
log.Debug("%s: matched %s by %s/%s", c.svc, c.host, hashHost, t)
matched = true
}
}
}
}
return matched, hashes
}
func (c *sbCtx) storeCache(hashes [][]byte) {
slices.SortFunc(hashes, func(a, b []byte) (sortsBefore bool) {
return bytes.Compare(a, b) == -1
})
var curData []byte
var prevPrefix []byte
for i, hash := range hashes {
// nolint:looppointer // The subsilce is used for a safe comparison.
if !bytes.Equal(hash[0:2], prevPrefix) {
if i != 0 {
c.setCache(prevPrefix, curData)
curData = nil
}
prevPrefix = hashes[i][0:2]
}
curData = append(curData, hash...)
}
if len(prevPrefix) != 0 {
c.setCache(prevPrefix, curData)
}
for hash := range c.hashToHost {
// nolint:looppointer // The subsilce is used for a safe cache lookup.
prefix := hash[0:2]
val := c.cache.Get(prefix)
if val == nil {
c.setCache(prefix, nil)
}
}
}
func check(c *sbCtx, r Result, u upstream.Upstream) (Result, error) {
c.hashToHost = hostnameToHashes(c.host)
switch c.getCached() {
case -1:
return Result{}, nil
case 1:
return r, nil
}
question := c.getQuestion()
log.Tracef("%s: checking %s: %s", c.svc, c.host, question)
req := (&dns.Msg{}).SetQuestion(question, dns.TypeTXT)
resp, err := u.Exchange(req)
if err != nil {
return Result{}, err
}
matched, receivedHashes := c.processTXT(resp)
c.storeCache(receivedHashes)
if matched {
return r, nil
}
return Result{}, nil
}
</s> add | const (
hostname = "wmconvirus.narod.ru"
cacheTime = 10 * time.Minute
cacheSize = 10000
)
sbChecker := hashprefix.New(&hashprefix.Config{
CacheTime: cacheTime,
CacheSize: cacheSize,
Upstream: aghtest.NewBlockUpstream(hostname, true),
}) | assert.Equalf(t, net.IP{127, 0, 0, 1}, a.A, "dns server %s returned wrong answer instead of 8.8.8.8: %v", addr, a.A)
}
func TestBlockedBySafeBrowsing(t *testing.T) {
const (
hostname = "wmconvirus.narod.ru"
cacheTime = 10 * time.Minute
cacheSize = 10000
)
sbChecker := hashprefix.New(&hashprefix.Config{
CacheTime: cacheTime,
CacheSize: cacheSize,
Upstream: aghtest.NewBlockUpstream(hostname, true),
})
sbUps := aghtest.NewBlockUpstream(hostname, true)
ans4, _ := (&aghtest.TestResolver{}).HostToIPs(hostname)
filterConf := &filtering.Config{ | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request 1837: AG-21462-imp-safebrowsing-parental
Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master
Squashed commit of the following:
commit 85016d4f1105e21a407efade0bd45b8362808061
Merge: 0e61edade 620b51e3e
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 16:36:30 2023 +0300
Merge branch 'master' into AG-21462-imp-safebrowsing-parental
commit 0e61edadeff34f6305e941c1db94575c82f238d9
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 14:51:37 2023 +0300
filtering: imp tests
commit 994255514cc0f67dfe33d5a0892432e8924d1e36
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:13:19 2023 +0300
filtering: fix typo
commit 96d1069573171538333330d6af94ef0f4208a9c4
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:00:18 2023 +0300
filtering: imp code more
commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 19:13:26 2023 +0300
all: add todo
commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 14:36:08 2023 +0300
all: imp code more
commit b6e734ccbeda82669023f6578481260b7c1f7161
Author: Stanislav Chzhen <[email protected]>
Date: Tue Apr 25 15:01:56 2023 +0300
filtering: imp code
commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 20:06:36 2023 +0300
all: imp code
commit 49fa6e587052a40bb431fea457701ee860493527
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 14:57:19 2023 +0300
all: rm safe browsing ctx
commit bbcb66cb03e18fa875e3c33cf16295892739e507
Author: Stanislav Chzhen <[email protected]>
Date: Fri Apr 21 17:54:18 2023 +0300
filtering: add cache item
commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 18:43:02 2023 +0300
filtering: fix hashes
commit 153fec46270212af03f3631bfb42c5d680c4e142
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 16:15:15 2023 +0300
filtering: add test cases
commit 09372f92bbb1fc082f1b1283594ee589100209c5
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 15:38:05 2023 +0300
filtering: imp code
commit 466bc26d524ea6d1c3efb33692a7785d39e491ca
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 18:38:40 2023 +0300
filtering: add tests
commit 24365ecf8c60512fdac65833ee603c80864ae018
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 11:38:57 2023 +0300
filtering: add hashprefix | https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c | internal/dnsforward/dnsforward_test.go |
func TestBlockedBySafeBrowsing(t *testing.T) {
const hostname = "wmconvirus.narod.ru"
sbUps := aghtest.NewBlockUpstream(hostname, true)
ans4, _ := (&aghtest.TestResolver{}).HostToIPs(hostname)
filterConf := &filtering.Config{
SafeBrowsingEnabled: true,
}
| </s> remove const hostname = "wmconvirus.narod.ru"
</s> add const (
hostname = "wmconvirus.narod.ru"
cacheTime = 10 * time.Minute
cacheSize = 10000
)
sbChecker := hashprefix.New(&hashprefix.Config{
CacheTime: cacheTime,
CacheSize: cacheSize,
Upstream: aghtest.NewBlockUpstream(hostname, true),
}) </s> remove d, setts := newForTest(t, &Config{SafeBrowsingEnabled: true}, nil)
</s> add d, setts := newForTest(t, &Config{
SafeBrowsingEnabled: true,
SafeBrowsingChecker: newChecker(sbBlocked),
}, nil) </s> remove ParentalEnabled: true,
SafeBrowsingEnabled: false,
</s> add ParentalEnabled: true,
SafeBrowsingEnabled: false,
SafeBrowsingChecker: newChecker(sbBlocked),
ParentalControlChecker: newChecker(pcBlocked), </s> remove d, setts := newForTest(b, &Config{SafeBrowsingEnabled: true}, nil)
</s> add d, setts := newForTest(b, &Config{
SafeBrowsingEnabled: true,
SafeBrowsingChecker: newChecker(sbBlocked),
}, nil) |
func TestBlockedBySafeBrowsing(t *testing.T) {
const hostname = "wmconvirus.narod.ru"
ans4, _ := (&aghtest.TestResolver{}).HostToIPs(hostname)
filterConf := &filtering.Config{
SafeBrowsingEnabled: true,
} | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request 1837: AG-21462-imp-safebrowsing-parental
Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master
Squashed commit of the following:
commit 85016d4f1105e21a407efade0bd45b8362808061
Merge: 0e61edade 620b51e3e
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 16:36:30 2023 +0300
Merge branch 'master' into AG-21462-imp-safebrowsing-parental
commit 0e61edadeff34f6305e941c1db94575c82f238d9
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 14:51:37 2023 +0300
filtering: imp tests
commit 994255514cc0f67dfe33d5a0892432e8924d1e36
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:13:19 2023 +0300
filtering: fix typo
commit 96d1069573171538333330d6af94ef0f4208a9c4
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:00:18 2023 +0300
filtering: imp code more
commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 19:13:26 2023 +0300
all: add todo
commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 14:36:08 2023 +0300
all: imp code more
commit b6e734ccbeda82669023f6578481260b7c1f7161
Author: Stanislav Chzhen <[email protected]>
Date: Tue Apr 25 15:01:56 2023 +0300
filtering: imp code
commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 20:06:36 2023 +0300
all: imp code
commit 49fa6e587052a40bb431fea457701ee860493527
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 14:57:19 2023 +0300
all: rm safe browsing ctx
commit bbcb66cb03e18fa875e3c33cf16295892739e507
Author: Stanislav Chzhen <[email protected]>
Date: Fri Apr 21 17:54:18 2023 +0300
filtering: add cache item
commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 18:43:02 2023 +0300
filtering: fix hashes
commit 153fec46270212af03f3631bfb42c5d680c4e142
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 16:15:15 2023 +0300
filtering: add test cases
commit 09372f92bbb1fc082f1b1283594ee589100209c5
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 15:38:05 2023 +0300
filtering: imp code
commit 466bc26d524ea6d1c3efb33692a7785d39e491ca
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 18:38:40 2023 +0300
filtering: add tests
commit 24365ecf8c60512fdac65833ee603c80864ae018
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 11:38:57 2023 +0300
filtering: add hashprefix | https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c | internal/dnsforward/dnsforward_test.go |
|
filterConf := &filtering.Config{
SafeBrowsingEnabled: true,
}
forwardConf := ServerConfig{
UDPListenAddrs: []*net.UDPAddr{{}},
TCPListenAddrs: []*net.TCPAddr{{}},
FilteringConfig: FilteringConfig{
| </s> remove sbUps := aghtest.NewBlockUpstream(hostname, true)
</s> add </s> remove const hostname = "wmconvirus.narod.ru"
</s> add const (
hostname = "wmconvirus.narod.ru"
cacheTime = 10 * time.Minute
cacheSize = 10000
)
sbChecker := hashprefix.New(&hashprefix.Config{
CacheTime: cacheTime,
CacheSize: cacheSize,
Upstream: aghtest.NewBlockUpstream(hostname, true),
}) </s> remove d, setts := newForTest(b, &Config{SafeBrowsingEnabled: true}, nil)
</s> add d, setts := newForTest(b, &Config{
SafeBrowsingEnabled: true,
SafeBrowsingChecker: newChecker(sbBlocked),
}, nil) </s> remove d, setts := newForTest(t, &Config{SafeBrowsingEnabled: true}, nil)
</s> add d, setts := newForTest(t, &Config{
SafeBrowsingEnabled: true,
SafeBrowsingChecker: newChecker(sbBlocked),
}, nil) </s> remove ParentalEnabled: true,
SafeBrowsingEnabled: false,
</s> add ParentalEnabled: true,
SafeBrowsingEnabled: false,
SafeBrowsingChecker: newChecker(sbBlocked),
ParentalControlChecker: newChecker(pcBlocked), | SafeBrowsingChecker: sbChecker, |
filterConf := &filtering.Config{
SafeBrowsingEnabled: true,
SafeBrowsingChecker: sbChecker,
}
forwardConf := ServerConfig{
UDPListenAddrs: []*net.UDPAddr{{}},
TCPListenAddrs: []*net.TCPAddr{{}},
FilteringConfig: FilteringConfig{ | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request 1837: AG-21462-imp-safebrowsing-parental
Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master
Squashed commit of the following:
commit 85016d4f1105e21a407efade0bd45b8362808061
Merge: 0e61edade 620b51e3e
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 16:36:30 2023 +0300
Merge branch 'master' into AG-21462-imp-safebrowsing-parental
commit 0e61edadeff34f6305e941c1db94575c82f238d9
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 14:51:37 2023 +0300
filtering: imp tests
commit 994255514cc0f67dfe33d5a0892432e8924d1e36
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:13:19 2023 +0300
filtering: fix typo
commit 96d1069573171538333330d6af94ef0f4208a9c4
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:00:18 2023 +0300
filtering: imp code more
commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 19:13:26 2023 +0300
all: add todo
commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 14:36:08 2023 +0300
all: imp code more
commit b6e734ccbeda82669023f6578481260b7c1f7161
Author: Stanislav Chzhen <[email protected]>
Date: Tue Apr 25 15:01:56 2023 +0300
filtering: imp code
commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 20:06:36 2023 +0300
all: imp code
commit 49fa6e587052a40bb431fea457701ee860493527
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 14:57:19 2023 +0300
all: rm safe browsing ctx
commit bbcb66cb03e18fa875e3c33cf16295892739e507
Author: Stanislav Chzhen <[email protected]>
Date: Fri Apr 21 17:54:18 2023 +0300
filtering: add cache item
commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 18:43:02 2023 +0300
filtering: fix hashes
commit 153fec46270212af03f3631bfb42c5d680c4e142
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 16:15:15 2023 +0300
filtering: add test cases
commit 09372f92bbb1fc082f1b1283594ee589100209c5
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 15:38:05 2023 +0300
filtering: imp code
commit 466bc26d524ea6d1c3efb33692a7785d39e491ca
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 18:38:40 2023 +0300
filtering: add tests
commit 24365ecf8c60512fdac65833ee603c80864ae018
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 11:38:57 2023 +0300
filtering: add hashprefix | https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c | internal/dnsforward/dnsforward_test.go |
},
},
}
s := createTestServer(t, filterConf, forwardConf, nil)
s.dnsFilter.SetSafeBrowsingUpstream(sbUps)
startDeferStop(t, s)
addr := s.dnsProxy.Addr(proxy.ProtoUDP)
// SafeBrowsing blocking.
req := createTestMessage(hostname + ".")
| </s> remove d, setts := newForTest(b, &Config{SafeBrowsingEnabled: true}, nil)
</s> add d, setts := newForTest(b, &Config{
SafeBrowsingEnabled: true,
SafeBrowsingChecker: newChecker(sbBlocked),
}, nil) </s> remove d, setts := newForTest(b, &Config{SafeBrowsingEnabled: true}, nil)
</s> add d, setts := newForTest(b, &Config{
SafeBrowsingEnabled: true,
SafeBrowsingChecker: newChecker(sbBlocked),
}, nil) </s> remove d, setts := newForTest(t, &Config{SafeBrowsingEnabled: true}, nil)
</s> add d, setts := newForTest(t, &Config{
SafeBrowsingEnabled: true,
SafeBrowsingChecker: newChecker(sbBlocked),
}, nil) </s> remove d, setts := newForTest(t, &Config{SafeBrowsingEnabled: true}, nil)
</s> add sbChecker := newChecker(sbBlocked)
d, setts := newForTest(t, &Config{
SafeBrowsingEnabled: true,
SafeBrowsingChecker: sbChecker,
}, nil) </s> remove d, setts := newForTest(t, &Config{ParentalEnabled: true}, nil)
</s> add d, setts := newForTest(t, &Config{
ParentalEnabled: true,
ParentalControlChecker: newChecker(pcBlocked),
}, nil) | },
},
}
s := createTestServer(t, filterConf, forwardConf, nil)
startDeferStop(t, s)
addr := s.dnsProxy.Addr(proxy.ProtoUDP)
// SafeBrowsing blocking.
req := createTestMessage(hostname + ".") | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request 1837: AG-21462-imp-safebrowsing-parental
Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master
Squashed commit of the following:
commit 85016d4f1105e21a407efade0bd45b8362808061
Merge: 0e61edade 620b51e3e
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 16:36:30 2023 +0300
Merge branch 'master' into AG-21462-imp-safebrowsing-parental
commit 0e61edadeff34f6305e941c1db94575c82f238d9
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 14:51:37 2023 +0300
filtering: imp tests
commit 994255514cc0f67dfe33d5a0892432e8924d1e36
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:13:19 2023 +0300
filtering: fix typo
commit 96d1069573171538333330d6af94ef0f4208a9c4
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:00:18 2023 +0300
filtering: imp code more
commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 19:13:26 2023 +0300
all: add todo
commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 14:36:08 2023 +0300
all: imp code more
commit b6e734ccbeda82669023f6578481260b7c1f7161
Author: Stanislav Chzhen <[email protected]>
Date: Tue Apr 25 15:01:56 2023 +0300
filtering: imp code
commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 20:06:36 2023 +0300
all: imp code
commit 49fa6e587052a40bb431fea457701ee860493527
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 14:57:19 2023 +0300
all: rm safe browsing ctx
commit bbcb66cb03e18fa875e3c33cf16295892739e507
Author: Stanislav Chzhen <[email protected]>
Date: Fri Apr 21 17:54:18 2023 +0300
filtering: add cache item
commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 18:43:02 2023 +0300
filtering: fix hashes
commit 153fec46270212af03f3631bfb42c5d680c4e142
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 16:15:15 2023 +0300
filtering: add test cases
commit 09372f92bbb1fc082f1b1283594ee589100209c5
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 15:38:05 2023 +0300
filtering: imp code
commit 466bc26d524ea6d1c3efb33692a7785d39e491ca
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 18:38:40 2023 +0300
filtering: add tests
commit 24365ecf8c60512fdac65833ee603c80864ae018
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 11:38:57 2023 +0300
filtering: add hashprefix | https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c | internal/dnsforward/dnsforward_test.go |
|
"sync/atomic"
"github.com/AdguardTeam/AdGuardHome/internal/aghhttp"
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
"github.com/AdguardTeam/dnsproxy/upstream"
"github.com/AdguardTeam/golibs/cache"
"github.com/AdguardTeam/golibs/errors"
"github.com/AdguardTeam/golibs/log"
"github.com/AdguardTeam/golibs/mathutil"
"github.com/AdguardTeam/golibs/stringutil"
"github.com/AdguardTeam/urlfilter"
| </s> remove "github.com/AdguardTeam/dnsproxy/upstream"
"github.com/AdguardTeam/golibs/cache"
</s> add </s> remove "github.com/AdguardTeam/golibs/stringutil"
"github.com/miekg/dns"
"golang.org/x/exp/slices"
"golang.org/x/net/publicsuffix"
</s> add </s> remove "time"
</s> add </s> remove "github.com/AdguardTeam/golibs/cache"
</s> add "github.com/AdguardTeam/AdGuardHome/internal/filtering/hashprefix" | "sync/atomic"
"github.com/AdguardTeam/AdGuardHome/internal/aghhttp"
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
"github.com/AdguardTeam/golibs/errors"
"github.com/AdguardTeam/golibs/log"
"github.com/AdguardTeam/golibs/mathutil"
"github.com/AdguardTeam/golibs/stringutil"
"github.com/AdguardTeam/urlfilter" | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request 1837: AG-21462-imp-safebrowsing-parental
Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master
Squashed commit of the following:
commit 85016d4f1105e21a407efade0bd45b8362808061
Merge: 0e61edade 620b51e3e
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 16:36:30 2023 +0300
Merge branch 'master' into AG-21462-imp-safebrowsing-parental
commit 0e61edadeff34f6305e941c1db94575c82f238d9
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 14:51:37 2023 +0300
filtering: imp tests
commit 994255514cc0f67dfe33d5a0892432e8924d1e36
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:13:19 2023 +0300
filtering: fix typo
commit 96d1069573171538333330d6af94ef0f4208a9c4
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:00:18 2023 +0300
filtering: imp code more
commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 19:13:26 2023 +0300
all: add todo
commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 14:36:08 2023 +0300
all: imp code more
commit b6e734ccbeda82669023f6578481260b7c1f7161
Author: Stanislav Chzhen <[email protected]>
Date: Tue Apr 25 15:01:56 2023 +0300
filtering: imp code
commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 20:06:36 2023 +0300
all: imp code
commit 49fa6e587052a40bb431fea457701ee860493527
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 14:57:19 2023 +0300
all: rm safe browsing ctx
commit bbcb66cb03e18fa875e3c33cf16295892739e507
Author: Stanislav Chzhen <[email protected]>
Date: Fri Apr 21 17:54:18 2023 +0300
filtering: add cache item
commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 18:43:02 2023 +0300
filtering: fix hashes
commit 153fec46270212af03f3631bfb42c5d680c4e142
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 16:15:15 2023 +0300
filtering: add test cases
commit 09372f92bbb1fc082f1b1283594ee589100209c5
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 15:38:05 2023 +0300
filtering: imp code
commit 466bc26d524ea6d1c3efb33692a7785d39e491ca
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 18:38:40 2023 +0300
filtering: add tests
commit 24365ecf8c60512fdac65833ee603c80864ae018
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 11:38:57 2023 +0300
filtering: add hashprefix | https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c | internal/filtering/filtering.go |
|
// Config allows you to configure DNS filtering with New() or just change variables directly.
type Config struct {
// enabled is used to be returned within Settings.
//
// It is of type uint32 to be accessed by atomic.
//
| </s> remove refreshLock: &sync.Mutex{},
filterTitleRegexp: regexp.MustCompile(`^! Title: +(.*)$`),
</s> add refreshLock: &sync.Mutex{},
filterTitleRegexp: regexp.MustCompile(`^! Title: +(.*)$`),
safeBrowsingChecker: c.SafeBrowsingChecker,
parentalControlChecker: c.ParentalControlChecker, </s> remove parentalServer string // access via methods
safeBrowsingServer string // access via methods
parentalUpstream upstream.Upstream
safeBrowsingUpstream upstream.Upstream
safebrowsingCache cache.Cache
parentalCache cache.Cache
</s> add </s> remove safeSearch SafeSearch
</s> add | // SafeBrowsingChecker is the safe browsing hash-prefix checker.
SafeBrowsingChecker Checker `yaml:"-"`
// ParentControl is the parental control hash-prefix checker.
ParentalControlChecker Checker `yaml:"-"`
| // Config allows you to configure DNS filtering with New() or just change variables directly.
type Config struct {
// SafeBrowsingChecker is the safe browsing hash-prefix checker.
SafeBrowsingChecker Checker `yaml:"-"`
// ParentControl is the parental control hash-prefix checker.
ParentalControlChecker Checker `yaml:"-"`
// enabled is used to be returned within Settings.
//
// It is of type uint32 to be accessed by atomic.
// | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | Pull request 1837: AG-21462-imp-safebrowsing-parental
Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master
Squashed commit of the following:
commit 85016d4f1105e21a407efade0bd45b8362808061
Merge: 0e61edade 620b51e3e
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 16:36:30 2023 +0300
Merge branch 'master' into AG-21462-imp-safebrowsing-parental
commit 0e61edadeff34f6305e941c1db94575c82f238d9
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 14:51:37 2023 +0300
filtering: imp tests
commit 994255514cc0f67dfe33d5a0892432e8924d1e36
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:13:19 2023 +0300
filtering: fix typo
commit 96d1069573171538333330d6af94ef0f4208a9c4
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:00:18 2023 +0300
filtering: imp code more
commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 19:13:26 2023 +0300
all: add todo
commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 14:36:08 2023 +0300
all: imp code more
commit b6e734ccbeda82669023f6578481260b7c1f7161
Author: Stanislav Chzhen <[email protected]>
Date: Tue Apr 25 15:01:56 2023 +0300
filtering: imp code
commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 20:06:36 2023 +0300
all: imp code
commit 49fa6e587052a40bb431fea457701ee860493527
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 14:57:19 2023 +0300
all: rm safe browsing ctx
commit bbcb66cb03e18fa875e3c33cf16295892739e507
Author: Stanislav Chzhen <[email protected]>
Date: Fri Apr 21 17:54:18 2023 +0300
filtering: add cache item
commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 18:43:02 2023 +0300
filtering: fix hashes
commit 153fec46270212af03f3631bfb42c5d680c4e142
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 16:15:15 2023 +0300
filtering: add test cases
commit 09372f92bbb1fc082f1b1283594ee589100209c5
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 15:38:05 2023 +0300
filtering: imp code
commit 466bc26d524ea6d1c3efb33692a7785d39e491ca
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 18:38:40 2023 +0300
filtering: add tests
commit 24365ecf8c60512fdac65833ee603c80864ae018
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 11:38:57 2023 +0300
filtering: add hashprefix | https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c | internal/filtering/filtering.go |
check func(host string, qtype uint16, setts *Settings) (res Result, err error)
name string
}
// DNSFilter matches hostnames and DNS requests against filtering rules.
type DNSFilter struct {
safeSearch SafeSearch
// safeBrowsingChecker is the safe browsing hash-prefix checker.
| </s> remove safeSearch SafeSearch
</s> add </s> remove d.SetParentalUpstream(aghtest.NewBlockUpstream(pcBlocked, true))
d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
</s> add </s> remove // TODO(a.garipov): Make configurable.
const (
dnsTimeout = 3 * time.Second
defaultSafebrowsingServer = `https://family.adguard-dns.com/dns-query`
defaultParentalServer = `https://family.adguard-dns.com/dns-query`
sbTXTSuffix = `sb.dns.adguard.com.`
pcTXTSuffix = `pc.dns.adguard.com.`
)
// SetParentalUpstream sets the parental upstream for *DNSFilter.
//
// TODO(e.burkov): Remove this in v1 API to forbid the direct access.
func (d *DNSFilter) SetParentalUpstream(u upstream.Upstream) {
d.parentalUpstream = u
}
// SetSafeBrowsingUpstream sets the safe browsing upstream for *DNSFilter.
//
// TODO(e.burkov): Remove this in v1 API to forbid the direct access.
func (d *DNSFilter) SetSafeBrowsingUpstream(u upstream.Upstream) {
d.safeBrowsingUpstream = u
}
func (d *DNSFilter) initSecurityServices() error {
var err error
d.safeBrowsingServer = defaultSafebrowsingServer
d.parentalServer = defaultParentalServer
opts := &upstream.Options{
Timeout: dnsTimeout,
ServerIPAddrs: []net.IP{
{94, 140, 14, 15},
{94, 140, 15, 16},
net.ParseIP("2a10:50c0::bad1:ff"),
net.ParseIP("2a10:50c0::bad2:ff"),
},
}
parUps, err := upstream.AddressToUpstream(d.parentalServer, opts)
if err != nil {
return fmt.Errorf("converting parental server: %w", err)
}
d.SetParentalUpstream(parUps)
sbUps, err := upstream.AddressToUpstream(d.safeBrowsingServer, opts)
if err != nil {
return fmt.Errorf("converting safe browsing server: %w", err)
}
d.SetSafeBrowsingUpstream(sbUps)
return nil
}
/*
expire byte[4]
hash byte[32]
...
*/
func (c *sbCtx) setCache(prefix, hashes []byte) {
d := make([]byte, 4+len(hashes))
expire := uint(time.Now().Unix()) + c.cacheTime*60
binary.BigEndian.PutUint32(d[:4], uint32(expire))
copy(d[4:], hashes)
c.cache.Set(prefix, d)
log.Debug("%s: stored in cache: %v", c.svc, prefix)
}
// findInHash returns 32-byte hash if it's found in hashToHost.
func (c *sbCtx) findInHash(val []byte) (hash32 [32]byte, found bool) {
for i := 4; i < len(val); i += 32 {
hash := val[i : i+32]
copy(hash32[:], hash[0:32])
_, found = c.hashToHost[hash32]
if found {
return hash32, found
}
}
return [32]byte{}, false
}
func (c *sbCtx) getCached() int {
now := time.Now().Unix()
hashesToRequest := map[[32]byte]string{}
for k, v := range c.hashToHost {
// nolint:looppointer // The subsilce is used for a safe cache lookup.
val := c.cache.Get(k[0:2])
if val == nil || now >= int64(binary.BigEndian.Uint32(val)) {
hashesToRequest[k] = v
continue
}
if hash32, found := c.findInHash(val); found {
log.Debug("%s: found in cache: %s: blocked by %v", c.svc, c.host, hash32)
return 1
}
}
if len(hashesToRequest) == 0 {
log.Debug("%s: found in cache: %s: not blocked", c.svc, c.host)
return -1
}
c.hashToHost = hashesToRequest
return 0
}
type sbCtx struct {
host string
svc string
hashToHost map[[32]byte]string
cache cache.Cache
cacheTime uint
}
func hostnameToHashes(host string) map[[32]byte]string {
hashes := map[[32]byte]string{}
tld, icann := publicsuffix.PublicSuffix(host)
if !icann {
// private suffixes like cloudfront.net
tld = ""
}
curhost := host
nDots := 0
for i := len(curhost) - 1; i >= 0; i-- {
if curhost[i] == '.' {
nDots++
if nDots == 4 {
curhost = curhost[i+1:] // "xxx.a.b.c.d" -> "a.b.c.d"
break
}
}
}
for {
if curhost == "" {
// we've reached end of string
break
}
if tld != "" && curhost == tld {
// we've reached the TLD, don't hash it
break
}
sum := sha256.Sum256([]byte(curhost))
hashes[sum] = curhost
pos := strings.IndexByte(curhost, byte('.'))
if pos < 0 {
break
}
curhost = curhost[pos+1:]
}
return hashes
}
// convert hash array to string
func (c *sbCtx) getQuestion() string {
b := &strings.Builder{}
for hash := range c.hashToHost {
// nolint:looppointer // The subsilce is used for safe hex encoding.
stringutil.WriteToBuilder(b, hex.EncodeToString(hash[0:2]), ".")
}
if c.svc == "SafeBrowsing" {
stringutil.WriteToBuilder(b, sbTXTSuffix)
return b.String()
}
stringutil.WriteToBuilder(b, pcTXTSuffix)
return b.String()
}
// Find the target hash in TXT response
func (c *sbCtx) processTXT(resp *dns.Msg) (bool, [][]byte) {
matched := false
hashes := [][]byte{}
for _, a := range resp.Answer {
txt, ok := a.(*dns.TXT)
if !ok {
continue
}
log.Debug("%s: received hashes for %s: %v", c.svc, c.host, txt.Txt)
for _, t := range txt.Txt {
if len(t) != 32*2 {
continue
}
hash, err := hex.DecodeString(t)
if err != nil {
continue
}
hashes = append(hashes, hash)
if !matched {
var hash32 [32]byte
copy(hash32[:], hash)
var hashHost string
hashHost, ok = c.hashToHost[hash32]
if ok {
log.Debug("%s: matched %s by %s/%s", c.svc, c.host, hashHost, t)
matched = true
}
}
}
}
return matched, hashes
}
func (c *sbCtx) storeCache(hashes [][]byte) {
slices.SortFunc(hashes, func(a, b []byte) (sortsBefore bool) {
return bytes.Compare(a, b) == -1
})
var curData []byte
var prevPrefix []byte
for i, hash := range hashes {
// nolint:looppointer // The subsilce is used for a safe comparison.
if !bytes.Equal(hash[0:2], prevPrefix) {
if i != 0 {
c.setCache(prevPrefix, curData)
curData = nil
}
prevPrefix = hashes[i][0:2]
}
curData = append(curData, hash...)
}
if len(prevPrefix) != 0 {
c.setCache(prevPrefix, curData)
}
for hash := range c.hashToHost {
// nolint:looppointer // The subsilce is used for a safe cache lookup.
prefix := hash[0:2]
val := c.cache.Get(prefix)
if val == nil {
c.setCache(prefix, nil)
}
}
}
func check(c *sbCtx, r Result, u upstream.Upstream) (Result, error) {
c.hashToHost = hostnameToHashes(c.host)
switch c.getCached() {
case -1:
return Result{}, nil
case 1:
return r, nil
}
question := c.getQuestion()
log.Tracef("%s: checking %s: %s", c.svc, c.host, question)
req := (&dns.Msg{}).SetQuestion(question, dns.TypeTXT)
resp, err := u.Exchange(req)
if err != nil {
return Result{}, err
}
matched, receivedHashes := c.processTXT(resp)
c.storeCache(receivedHashes)
if matched {
return r, nil
}
return Result{}, nil
}
</s> add | // Checker is used for safe browsing or parental control hash-prefix filtering.
type Checker interface {
// Check returns true if request for the host should be blocked.
Check(host string) (block bool, err error)
}
| check func(host string, qtype uint16, setts *Settings) (res Result, err error)
name string
}
// Checker is used for safe browsing or parental control hash-prefix filtering.
type Checker interface {
// Check returns true if request for the host should be blocked.
Check(host string) (block bool, err error)
}
// DNSFilter matches hostnames and DNS requests against filtering rules.
type DNSFilter struct {
safeSearch SafeSearch
// safeBrowsingChecker is the safe browsing hash-prefix checker. | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request 1837: AG-21462-imp-safebrowsing-parental
Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master
Squashed commit of the following:
commit 85016d4f1105e21a407efade0bd45b8362808061
Merge: 0e61edade 620b51e3e
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 16:36:30 2023 +0300
Merge branch 'master' into AG-21462-imp-safebrowsing-parental
commit 0e61edadeff34f6305e941c1db94575c82f238d9
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 14:51:37 2023 +0300
filtering: imp tests
commit 994255514cc0f67dfe33d5a0892432e8924d1e36
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:13:19 2023 +0300
filtering: fix typo
commit 96d1069573171538333330d6af94ef0f4208a9c4
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:00:18 2023 +0300
filtering: imp code more
commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 19:13:26 2023 +0300
all: add todo
commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 14:36:08 2023 +0300
all: imp code more
commit b6e734ccbeda82669023f6578481260b7c1f7161
Author: Stanislav Chzhen <[email protected]>
Date: Tue Apr 25 15:01:56 2023 +0300
filtering: imp code
commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 20:06:36 2023 +0300
all: imp code
commit 49fa6e587052a40bb431fea457701ee860493527
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 14:57:19 2023 +0300
all: rm safe browsing ctx
commit bbcb66cb03e18fa875e3c33cf16295892739e507
Author: Stanislav Chzhen <[email protected]>
Date: Fri Apr 21 17:54:18 2023 +0300
filtering: add cache item
commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 18:43:02 2023 +0300
filtering: fix hashes
commit 153fec46270212af03f3631bfb42c5d680c4e142
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 16:15:15 2023 +0300
filtering: add test cases
commit 09372f92bbb1fc082f1b1283594ee589100209c5
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 15:38:05 2023 +0300
filtering: imp code
commit 466bc26d524ea6d1c3efb33692a7785d39e491ca
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 18:38:40 2023 +0300
filtering: add tests
commit 24365ecf8c60512fdac65833ee603c80864ae018
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 11:38:57 2023 +0300
filtering: add hashprefix | https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c | internal/filtering/filtering.go |
}
// DNSFilter matches hostnames and DNS requests against filtering rules.
type DNSFilter struct {
rulesStorage *filterlist.RuleStorage
filteringEngine *urlfilter.DNSEngine
rulesStorageAllow *filterlist.RuleStorage
filteringEngineAllow *urlfilter.DNSEngine
| </s> remove parentalServer string // access via methods
safeBrowsingServer string // access via methods
parentalUpstream upstream.Upstream
safeBrowsingUpstream upstream.Upstream
safebrowsingCache cache.Cache
parentalCache cache.Cache
</s> add </s> remove safeSearch SafeSearch
</s> add </s> remove d.SetParentalUpstream(aghtest.NewBlockUpstream(pcBlocked, true))
d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
</s> add | safeSearch SafeSearch
// safeBrowsingChecker is the safe browsing hash-prefix checker.
safeBrowsingChecker Checker
// parentalControl is the parental control hash-prefix checker.
parentalControlChecker Checker
| }
// DNSFilter matches hostnames and DNS requests against filtering rules.
type DNSFilter struct {
safeSearch SafeSearch
// safeBrowsingChecker is the safe browsing hash-prefix checker.
safeBrowsingChecker Checker
// parentalControl is the parental control hash-prefix checker.
parentalControlChecker Checker
rulesStorage *filterlist.RuleStorage
filteringEngine *urlfilter.DNSEngine
rulesStorageAllow *filterlist.RuleStorage
filteringEngineAllow *urlfilter.DNSEngine
| [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request 1837: AG-21462-imp-safebrowsing-parental
Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master
Squashed commit of the following:
commit 85016d4f1105e21a407efade0bd45b8362808061
Merge: 0e61edade 620b51e3e
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 16:36:30 2023 +0300
Merge branch 'master' into AG-21462-imp-safebrowsing-parental
commit 0e61edadeff34f6305e941c1db94575c82f238d9
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 14:51:37 2023 +0300
filtering: imp tests
commit 994255514cc0f67dfe33d5a0892432e8924d1e36
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:13:19 2023 +0300
filtering: fix typo
commit 96d1069573171538333330d6af94ef0f4208a9c4
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:00:18 2023 +0300
filtering: imp code more
commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 19:13:26 2023 +0300
all: add todo
commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 14:36:08 2023 +0300
all: imp code more
commit b6e734ccbeda82669023f6578481260b7c1f7161
Author: Stanislav Chzhen <[email protected]>
Date: Tue Apr 25 15:01:56 2023 +0300
filtering: imp code
commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 20:06:36 2023 +0300
all: imp code
commit 49fa6e587052a40bb431fea457701ee860493527
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 14:57:19 2023 +0300
all: rm safe browsing ctx
commit bbcb66cb03e18fa875e3c33cf16295892739e507
Author: Stanislav Chzhen <[email protected]>
Date: Fri Apr 21 17:54:18 2023 +0300
filtering: add cache item
commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 18:43:02 2023 +0300
filtering: fix hashes
commit 153fec46270212af03f3631bfb42c5d680c4e142
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 16:15:15 2023 +0300
filtering: add test cases
commit 09372f92bbb1fc082f1b1283594ee589100209c5
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 15:38:05 2023 +0300
filtering: imp code
commit 466bc26d524ea6d1c3efb33692a7785d39e491ca
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 18:38:40 2023 +0300
filtering: add tests
commit 24365ecf8c60512fdac65833ee603c80864ae018
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 11:38:57 2023 +0300
filtering: add hashprefix | https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c | internal/filtering/filtering.go |
filteringEngineAllow *urlfilter.DNSEngine
engineLock sync.RWMutex
parentalServer string // access via methods
safeBrowsingServer string // access via methods
parentalUpstream upstream.Upstream
safeBrowsingUpstream upstream.Upstream
safebrowsingCache cache.Cache
parentalCache cache.Cache
Config // for direct access by library users, even a = assignment
// confLock protects Config.
confLock sync.RWMutex
// Channel for passing data to filters-initializer goroutine
| </s> remove // TODO(a.garipov): Make configurable.
const (
dnsTimeout = 3 * time.Second
defaultSafebrowsingServer = `https://family.adguard-dns.com/dns-query`
defaultParentalServer = `https://family.adguard-dns.com/dns-query`
sbTXTSuffix = `sb.dns.adguard.com.`
pcTXTSuffix = `pc.dns.adguard.com.`
)
// SetParentalUpstream sets the parental upstream for *DNSFilter.
//
// TODO(e.burkov): Remove this in v1 API to forbid the direct access.
func (d *DNSFilter) SetParentalUpstream(u upstream.Upstream) {
d.parentalUpstream = u
}
// SetSafeBrowsingUpstream sets the safe browsing upstream for *DNSFilter.
//
// TODO(e.burkov): Remove this in v1 API to forbid the direct access.
func (d *DNSFilter) SetSafeBrowsingUpstream(u upstream.Upstream) {
d.safeBrowsingUpstream = u
}
func (d *DNSFilter) initSecurityServices() error {
var err error
d.safeBrowsingServer = defaultSafebrowsingServer
d.parentalServer = defaultParentalServer
opts := &upstream.Options{
Timeout: dnsTimeout,
ServerIPAddrs: []net.IP{
{94, 140, 14, 15},
{94, 140, 15, 16},
net.ParseIP("2a10:50c0::bad1:ff"),
net.ParseIP("2a10:50c0::bad2:ff"),
},
}
parUps, err := upstream.AddressToUpstream(d.parentalServer, opts)
if err != nil {
return fmt.Errorf("converting parental server: %w", err)
}
d.SetParentalUpstream(parUps)
sbUps, err := upstream.AddressToUpstream(d.safeBrowsingServer, opts)
if err != nil {
return fmt.Errorf("converting safe browsing server: %w", err)
}
d.SetSafeBrowsingUpstream(sbUps)
return nil
}
/*
expire byte[4]
hash byte[32]
...
*/
func (c *sbCtx) setCache(prefix, hashes []byte) {
d := make([]byte, 4+len(hashes))
expire := uint(time.Now().Unix()) + c.cacheTime*60
binary.BigEndian.PutUint32(d[:4], uint32(expire))
copy(d[4:], hashes)
c.cache.Set(prefix, d)
log.Debug("%s: stored in cache: %v", c.svc, prefix)
}
// findInHash returns 32-byte hash if it's found in hashToHost.
func (c *sbCtx) findInHash(val []byte) (hash32 [32]byte, found bool) {
for i := 4; i < len(val); i += 32 {
hash := val[i : i+32]
copy(hash32[:], hash[0:32])
_, found = c.hashToHost[hash32]
if found {
return hash32, found
}
}
return [32]byte{}, false
}
func (c *sbCtx) getCached() int {
now := time.Now().Unix()
hashesToRequest := map[[32]byte]string{}
for k, v := range c.hashToHost {
// nolint:looppointer // The subsilce is used for a safe cache lookup.
val := c.cache.Get(k[0:2])
if val == nil || now >= int64(binary.BigEndian.Uint32(val)) {
hashesToRequest[k] = v
continue
}
if hash32, found := c.findInHash(val); found {
log.Debug("%s: found in cache: %s: blocked by %v", c.svc, c.host, hash32)
return 1
}
}
if len(hashesToRequest) == 0 {
log.Debug("%s: found in cache: %s: not blocked", c.svc, c.host)
return -1
}
c.hashToHost = hashesToRequest
return 0
}
type sbCtx struct {
host string
svc string
hashToHost map[[32]byte]string
cache cache.Cache
cacheTime uint
}
func hostnameToHashes(host string) map[[32]byte]string {
hashes := map[[32]byte]string{}
tld, icann := publicsuffix.PublicSuffix(host)
if !icann {
// private suffixes like cloudfront.net
tld = ""
}
curhost := host
nDots := 0
for i := len(curhost) - 1; i >= 0; i-- {
if curhost[i] == '.' {
nDots++
if nDots == 4 {
curhost = curhost[i+1:] // "xxx.a.b.c.d" -> "a.b.c.d"
break
}
}
}
for {
if curhost == "" {
// we've reached end of string
break
}
if tld != "" && curhost == tld {
// we've reached the TLD, don't hash it
break
}
sum := sha256.Sum256([]byte(curhost))
hashes[sum] = curhost
pos := strings.IndexByte(curhost, byte('.'))
if pos < 0 {
break
}
curhost = curhost[pos+1:]
}
return hashes
}
// convert hash array to string
func (c *sbCtx) getQuestion() string {
b := &strings.Builder{}
for hash := range c.hashToHost {
// nolint:looppointer // The subsilce is used for safe hex encoding.
stringutil.WriteToBuilder(b, hex.EncodeToString(hash[0:2]), ".")
}
if c.svc == "SafeBrowsing" {
stringutil.WriteToBuilder(b, sbTXTSuffix)
return b.String()
}
stringutil.WriteToBuilder(b, pcTXTSuffix)
return b.String()
}
// Find the target hash in TXT response
func (c *sbCtx) processTXT(resp *dns.Msg) (bool, [][]byte) {
matched := false
hashes := [][]byte{}
for _, a := range resp.Answer {
txt, ok := a.(*dns.TXT)
if !ok {
continue
}
log.Debug("%s: received hashes for %s: %v", c.svc, c.host, txt.Txt)
for _, t := range txt.Txt {
if len(t) != 32*2 {
continue
}
hash, err := hex.DecodeString(t)
if err != nil {
continue
}
hashes = append(hashes, hash)
if !matched {
var hash32 [32]byte
copy(hash32[:], hash)
var hashHost string
hashHost, ok = c.hashToHost[hash32]
if ok {
log.Debug("%s: matched %s by %s/%s", c.svc, c.host, hashHost, t)
matched = true
}
}
}
}
return matched, hashes
}
func (c *sbCtx) storeCache(hashes [][]byte) {
slices.SortFunc(hashes, func(a, b []byte) (sortsBefore bool) {
return bytes.Compare(a, b) == -1
})
var curData []byte
var prevPrefix []byte
for i, hash := range hashes {
// nolint:looppointer // The subsilce is used for a safe comparison.
if !bytes.Equal(hash[0:2], prevPrefix) {
if i != 0 {
c.setCache(prevPrefix, curData)
curData = nil
}
prevPrefix = hashes[i][0:2]
}
curData = append(curData, hash...)
}
if len(prevPrefix) != 0 {
c.setCache(prevPrefix, curData)
}
for hash := range c.hashToHost {
// nolint:looppointer // The subsilce is used for a safe cache lookup.
prefix := hash[0:2]
val := c.cache.Get(prefix)
if val == nil {
c.setCache(prefix, nil)
}
}
}
func check(c *sbCtx, r Result, u upstream.Upstream) (Result, error) {
c.hashToHost = hostnameToHashes(c.host)
switch c.getCached() {
case -1:
return Result{}, nil
case 1:
return r, nil
}
question := c.getQuestion()
log.Tracef("%s: checking %s: %s", c.svc, c.host, question)
req := (&dns.Msg{}).SetQuestion(question, dns.TypeTXT)
resp, err := u.Exchange(req)
if err != nil {
return Result{}, err
}
matched, receivedHashes := c.processTXT(resp)
c.storeCache(receivedHashes)
if matched {
return r, nil
}
return Result{}, nil
}
</s> add </s> remove safeSearch SafeSearch
</s> add | filteringEngineAllow *urlfilter.DNSEngine
engineLock sync.RWMutex
Config // for direct access by library users, even a = assignment
// confLock protects Config.
confLock sync.RWMutex
// Channel for passing data to filters-initializer goroutine | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request 1837: AG-21462-imp-safebrowsing-parental
Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master
Squashed commit of the following:
commit 85016d4f1105e21a407efade0bd45b8362808061
Merge: 0e61edade 620b51e3e
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 16:36:30 2023 +0300
Merge branch 'master' into AG-21462-imp-safebrowsing-parental
commit 0e61edadeff34f6305e941c1db94575c82f238d9
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 14:51:37 2023 +0300
filtering: imp tests
commit 994255514cc0f67dfe33d5a0892432e8924d1e36
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:13:19 2023 +0300
filtering: fix typo
commit 96d1069573171538333330d6af94ef0f4208a9c4
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:00:18 2023 +0300
filtering: imp code more
commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 19:13:26 2023 +0300
all: add todo
commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 14:36:08 2023 +0300
all: imp code more
commit b6e734ccbeda82669023f6578481260b7c1f7161
Author: Stanislav Chzhen <[email protected]>
Date: Tue Apr 25 15:01:56 2023 +0300
filtering: imp code
commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 20:06:36 2023 +0300
all: imp code
commit 49fa6e587052a40bb431fea457701ee860493527
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 14:57:19 2023 +0300
all: rm safe browsing ctx
commit bbcb66cb03e18fa875e3c33cf16295892739e507
Author: Stanislav Chzhen <[email protected]>
Date: Fri Apr 21 17:54:18 2023 +0300
filtering: add cache item
commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 18:43:02 2023 +0300
filtering: fix hashes
commit 153fec46270212af03f3631bfb42c5d680c4e142
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 16:15:15 2023 +0300
filtering: add test cases
commit 09372f92bbb1fc082f1b1283594ee589100209c5
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 15:38:05 2023 +0300
filtering: imp code
commit 466bc26d524ea6d1c3efb33692a7785d39e491ca
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 18:38:40 2023 +0300
filtering: add tests
commit 24365ecf8c60512fdac65833ee603c80864ae018
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 11:38:57 2023 +0300
filtering: add hashprefix | https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c | internal/filtering/filtering.go |
|
//
// TODO(e.burkov): Don't use regexp for such a simple text processing task.
filterTitleRegexp *regexp.Regexp
safeSearch SafeSearch
hostCheckers []hostChecker
}
// Filter represents a filter list
type Filter struct {
| </s> remove return check(sctx, res, d.parentalUpstream)
</s> add block, err := d.parentalControlChecker.Check(host)
if !block || err != nil {
return Result{}, err
}
return res, nil </s> remove refreshLock: &sync.Mutex{},
filterTitleRegexp: regexp.MustCompile(`^! Title: +(.*)$`),
</s> add refreshLock: &sync.Mutex{},
filterTitleRegexp: regexp.MustCompile(`^! Title: +(.*)$`),
safeBrowsingChecker: c.SafeBrowsingChecker,
parentalControlChecker: c.ParentalControlChecker, </s> remove // TODO(a.garipov): Make configurable.
const (
dnsTimeout = 3 * time.Second
defaultSafebrowsingServer = `https://family.adguard-dns.com/dns-query`
defaultParentalServer = `https://family.adguard-dns.com/dns-query`
sbTXTSuffix = `sb.dns.adguard.com.`
pcTXTSuffix = `pc.dns.adguard.com.`
)
// SetParentalUpstream sets the parental upstream for *DNSFilter.
//
// TODO(e.burkov): Remove this in v1 API to forbid the direct access.
func (d *DNSFilter) SetParentalUpstream(u upstream.Upstream) {
d.parentalUpstream = u
}
// SetSafeBrowsingUpstream sets the safe browsing upstream for *DNSFilter.
//
// TODO(e.burkov): Remove this in v1 API to forbid the direct access.
func (d *DNSFilter) SetSafeBrowsingUpstream(u upstream.Upstream) {
d.safeBrowsingUpstream = u
}
func (d *DNSFilter) initSecurityServices() error {
var err error
d.safeBrowsingServer = defaultSafebrowsingServer
d.parentalServer = defaultParentalServer
opts := &upstream.Options{
Timeout: dnsTimeout,
ServerIPAddrs: []net.IP{
{94, 140, 14, 15},
{94, 140, 15, 16},
net.ParseIP("2a10:50c0::bad1:ff"),
net.ParseIP("2a10:50c0::bad2:ff"),
},
}
parUps, err := upstream.AddressToUpstream(d.parentalServer, opts)
if err != nil {
return fmt.Errorf("converting parental server: %w", err)
}
d.SetParentalUpstream(parUps)
sbUps, err := upstream.AddressToUpstream(d.safeBrowsingServer, opts)
if err != nil {
return fmt.Errorf("converting safe browsing server: %w", err)
}
d.SetSafeBrowsingUpstream(sbUps)
return nil
}
/*
expire byte[4]
hash byte[32]
...
*/
func (c *sbCtx) setCache(prefix, hashes []byte) {
d := make([]byte, 4+len(hashes))
expire := uint(time.Now().Unix()) + c.cacheTime*60
binary.BigEndian.PutUint32(d[:4], uint32(expire))
copy(d[4:], hashes)
c.cache.Set(prefix, d)
log.Debug("%s: stored in cache: %v", c.svc, prefix)
}
// findInHash returns 32-byte hash if it's found in hashToHost.
func (c *sbCtx) findInHash(val []byte) (hash32 [32]byte, found bool) {
for i := 4; i < len(val); i += 32 {
hash := val[i : i+32]
copy(hash32[:], hash[0:32])
_, found = c.hashToHost[hash32]
if found {
return hash32, found
}
}
return [32]byte{}, false
}
func (c *sbCtx) getCached() int {
now := time.Now().Unix()
hashesToRequest := map[[32]byte]string{}
for k, v := range c.hashToHost {
// nolint:looppointer // The subsilce is used for a safe cache lookup.
val := c.cache.Get(k[0:2])
if val == nil || now >= int64(binary.BigEndian.Uint32(val)) {
hashesToRequest[k] = v
continue
}
if hash32, found := c.findInHash(val); found {
log.Debug("%s: found in cache: %s: blocked by %v", c.svc, c.host, hash32)
return 1
}
}
if len(hashesToRequest) == 0 {
log.Debug("%s: found in cache: %s: not blocked", c.svc, c.host)
return -1
}
c.hashToHost = hashesToRequest
return 0
}
type sbCtx struct {
host string
svc string
hashToHost map[[32]byte]string
cache cache.Cache
cacheTime uint
}
func hostnameToHashes(host string) map[[32]byte]string {
hashes := map[[32]byte]string{}
tld, icann := publicsuffix.PublicSuffix(host)
if !icann {
// private suffixes like cloudfront.net
tld = ""
}
curhost := host
nDots := 0
for i := len(curhost) - 1; i >= 0; i-- {
if curhost[i] == '.' {
nDots++
if nDots == 4 {
curhost = curhost[i+1:] // "xxx.a.b.c.d" -> "a.b.c.d"
break
}
}
}
for {
if curhost == "" {
// we've reached end of string
break
}
if tld != "" && curhost == tld {
// we've reached the TLD, don't hash it
break
}
sum := sha256.Sum256([]byte(curhost))
hashes[sum] = curhost
pos := strings.IndexByte(curhost, byte('.'))
if pos < 0 {
break
}
curhost = curhost[pos+1:]
}
return hashes
}
// convert hash array to string
func (c *sbCtx) getQuestion() string {
b := &strings.Builder{}
for hash := range c.hashToHost {
// nolint:looppointer // The subsilce is used for safe hex encoding.
stringutil.WriteToBuilder(b, hex.EncodeToString(hash[0:2]), ".")
}
if c.svc == "SafeBrowsing" {
stringutil.WriteToBuilder(b, sbTXTSuffix)
return b.String()
}
stringutil.WriteToBuilder(b, pcTXTSuffix)
return b.String()
}
// Find the target hash in TXT response
func (c *sbCtx) processTXT(resp *dns.Msg) (bool, [][]byte) {
matched := false
hashes := [][]byte{}
for _, a := range resp.Answer {
txt, ok := a.(*dns.TXT)
if !ok {
continue
}
log.Debug("%s: received hashes for %s: %v", c.svc, c.host, txt.Txt)
for _, t := range txt.Txt {
if len(t) != 32*2 {
continue
}
hash, err := hex.DecodeString(t)
if err != nil {
continue
}
hashes = append(hashes, hash)
if !matched {
var hash32 [32]byte
copy(hash32[:], hash)
var hashHost string
hashHost, ok = c.hashToHost[hash32]
if ok {
log.Debug("%s: matched %s by %s/%s", c.svc, c.host, hashHost, t)
matched = true
}
}
}
}
return matched, hashes
}
func (c *sbCtx) storeCache(hashes [][]byte) {
slices.SortFunc(hashes, func(a, b []byte) (sortsBefore bool) {
return bytes.Compare(a, b) == -1
})
var curData []byte
var prevPrefix []byte
for i, hash := range hashes {
// nolint:looppointer // The subsilce is used for a safe comparison.
if !bytes.Equal(hash[0:2], prevPrefix) {
if i != 0 {
c.setCache(prevPrefix, curData)
curData = nil
}
prevPrefix = hashes[i][0:2]
}
curData = append(curData, hash...)
}
if len(prevPrefix) != 0 {
c.setCache(prevPrefix, curData)
}
for hash := range c.hashToHost {
// nolint:looppointer // The subsilce is used for a safe cache lookup.
prefix := hash[0:2]
val := c.cache.Get(prefix)
if val == nil {
c.setCache(prefix, nil)
}
}
}
func check(c *sbCtx, r Result, u upstream.Upstream) (Result, error) {
c.hashToHost = hostnameToHashes(c.host)
switch c.getCached() {
case -1:
return Result{}, nil
case 1:
return r, nil
}
question := c.getQuestion()
log.Tracef("%s: checking %s: %s", c.svc, c.host, question)
req := (&dns.Msg{}).SetQuestion(question, dns.TypeTXT)
resp, err := u.Exchange(req)
if err != nil {
return Result{}, err
}
matched, receivedHashes := c.processTXT(resp)
c.storeCache(receivedHashes)
if matched {
return r, nil
}
return Result{}, nil
}
</s> add | //
// TODO(e.burkov): Don't use regexp for such a simple text processing task.
filterTitleRegexp *regexp.Regexp
hostCheckers []hostChecker
}
// Filter represents a filter list
type Filter struct { | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request 1837: AG-21462-imp-safebrowsing-parental
Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master
Squashed commit of the following:
commit 85016d4f1105e21a407efade0bd45b8362808061
Merge: 0e61edade 620b51e3e
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 16:36:30 2023 +0300
Merge branch 'master' into AG-21462-imp-safebrowsing-parental
commit 0e61edadeff34f6305e941c1db94575c82f238d9
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 14:51:37 2023 +0300
filtering: imp tests
commit 994255514cc0f67dfe33d5a0892432e8924d1e36
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:13:19 2023 +0300
filtering: fix typo
commit 96d1069573171538333330d6af94ef0f4208a9c4
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:00:18 2023 +0300
filtering: imp code more
commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 19:13:26 2023 +0300
all: add todo
commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 14:36:08 2023 +0300
all: imp code more
commit b6e734ccbeda82669023f6578481260b7c1f7161
Author: Stanislav Chzhen <[email protected]>
Date: Tue Apr 25 15:01:56 2023 +0300
filtering: imp code
commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 20:06:36 2023 +0300
all: imp code
commit 49fa6e587052a40bb431fea457701ee860493527
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 14:57:19 2023 +0300
all: rm safe browsing ctx
commit bbcb66cb03e18fa875e3c33cf16295892739e507
Author: Stanislav Chzhen <[email protected]>
Date: Fri Apr 21 17:54:18 2023 +0300
filtering: add cache item
commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 18:43:02 2023 +0300
filtering: fix hashes
commit 153fec46270212af03f3631bfb42c5d680c4e142
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 16:15:15 2023 +0300
filtering: add test cases
commit 09372f92bbb1fc082f1b1283594ee589100209c5
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 15:38:05 2023 +0300
filtering: imp code
commit 466bc26d524ea6d1c3efb33692a7785d39e491ca
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 18:38:40 2023 +0300
filtering: add tests
commit 24365ecf8c60512fdac65833ee603c80864ae018
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 11:38:57 2023 +0300
filtering: add hashprefix | https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c | internal/filtering/filtering.go |
|
// New creates properly initialized DNS Filter that is ready to be used. c must
// be non-nil.
func New(c *Config, blockFilters []Filter) (d *DNSFilter, err error) {
d = &DNSFilter{
refreshLock: &sync.Mutex{},
filterTitleRegexp: regexp.MustCompile(`^! Title: +(.*)$`),
}
d.safebrowsingCache = cache.New(cache.Config{
EnableLRU: true,
MaxSize: c.SafeBrowsingCacheSize,
| </s> remove d.safebrowsingCache = cache.New(cache.Config{
EnableLRU: true,
MaxSize: c.SafeBrowsingCacheSize,
})
d.parentalCache = cache.New(cache.Config{
EnableLRU: true,
MaxSize: c.ParentalCacheSize,
})
</s> add </s> remove func purgeCaches(d *DNSFilter) {
for _, c := range []cache.Cache{
d.safebrowsingCache,
d.parentalCache,
} {
if c != nil {
c.Clear()
}
}
}
</s> add </s> remove // TODO(a.garipov): Make configurable.
const (
dnsTimeout = 3 * time.Second
defaultSafebrowsingServer = `https://family.adguard-dns.com/dns-query`
defaultParentalServer = `https://family.adguard-dns.com/dns-query`
sbTXTSuffix = `sb.dns.adguard.com.`
pcTXTSuffix = `pc.dns.adguard.com.`
)
// SetParentalUpstream sets the parental upstream for *DNSFilter.
//
// TODO(e.burkov): Remove this in v1 API to forbid the direct access.
func (d *DNSFilter) SetParentalUpstream(u upstream.Upstream) {
d.parentalUpstream = u
}
// SetSafeBrowsingUpstream sets the safe browsing upstream for *DNSFilter.
//
// TODO(e.burkov): Remove this in v1 API to forbid the direct access.
func (d *DNSFilter) SetSafeBrowsingUpstream(u upstream.Upstream) {
d.safeBrowsingUpstream = u
}
func (d *DNSFilter) initSecurityServices() error {
var err error
d.safeBrowsingServer = defaultSafebrowsingServer
d.parentalServer = defaultParentalServer
opts := &upstream.Options{
Timeout: dnsTimeout,
ServerIPAddrs: []net.IP{
{94, 140, 14, 15},
{94, 140, 15, 16},
net.ParseIP("2a10:50c0::bad1:ff"),
net.ParseIP("2a10:50c0::bad2:ff"),
},
}
parUps, err := upstream.AddressToUpstream(d.parentalServer, opts)
if err != nil {
return fmt.Errorf("converting parental server: %w", err)
}
d.SetParentalUpstream(parUps)
sbUps, err := upstream.AddressToUpstream(d.safeBrowsingServer, opts)
if err != nil {
return fmt.Errorf("converting safe browsing server: %w", err)
}
d.SetSafeBrowsingUpstream(sbUps)
return nil
}
/*
expire byte[4]
hash byte[32]
...
*/
func (c *sbCtx) setCache(prefix, hashes []byte) {
d := make([]byte, 4+len(hashes))
expire := uint(time.Now().Unix()) + c.cacheTime*60
binary.BigEndian.PutUint32(d[:4], uint32(expire))
copy(d[4:], hashes)
c.cache.Set(prefix, d)
log.Debug("%s: stored in cache: %v", c.svc, prefix)
}
// findInHash returns 32-byte hash if it's found in hashToHost.
func (c *sbCtx) findInHash(val []byte) (hash32 [32]byte, found bool) {
for i := 4; i < len(val); i += 32 {
hash := val[i : i+32]
copy(hash32[:], hash[0:32])
_, found = c.hashToHost[hash32]
if found {
return hash32, found
}
}
return [32]byte{}, false
}
func (c *sbCtx) getCached() int {
now := time.Now().Unix()
hashesToRequest := map[[32]byte]string{}
for k, v := range c.hashToHost {
// nolint:looppointer // The subsilce is used for a safe cache lookup.
val := c.cache.Get(k[0:2])
if val == nil || now >= int64(binary.BigEndian.Uint32(val)) {
hashesToRequest[k] = v
continue
}
if hash32, found := c.findInHash(val); found {
log.Debug("%s: found in cache: %s: blocked by %v", c.svc, c.host, hash32)
return 1
}
}
if len(hashesToRequest) == 0 {
log.Debug("%s: found in cache: %s: not blocked", c.svc, c.host)
return -1
}
c.hashToHost = hashesToRequest
return 0
}
type sbCtx struct {
host string
svc string
hashToHost map[[32]byte]string
cache cache.Cache
cacheTime uint
}
func hostnameToHashes(host string) map[[32]byte]string {
hashes := map[[32]byte]string{}
tld, icann := publicsuffix.PublicSuffix(host)
if !icann {
// private suffixes like cloudfront.net
tld = ""
}
curhost := host
nDots := 0
for i := len(curhost) - 1; i >= 0; i-- {
if curhost[i] == '.' {
nDots++
if nDots == 4 {
curhost = curhost[i+1:] // "xxx.a.b.c.d" -> "a.b.c.d"
break
}
}
}
for {
if curhost == "" {
// we've reached end of string
break
}
if tld != "" && curhost == tld {
// we've reached the TLD, don't hash it
break
}
sum := sha256.Sum256([]byte(curhost))
hashes[sum] = curhost
pos := strings.IndexByte(curhost, byte('.'))
if pos < 0 {
break
}
curhost = curhost[pos+1:]
}
return hashes
}
// convert hash array to string
func (c *sbCtx) getQuestion() string {
b := &strings.Builder{}
for hash := range c.hashToHost {
// nolint:looppointer // The subsilce is used for safe hex encoding.
stringutil.WriteToBuilder(b, hex.EncodeToString(hash[0:2]), ".")
}
if c.svc == "SafeBrowsing" {
stringutil.WriteToBuilder(b, sbTXTSuffix)
return b.String()
}
stringutil.WriteToBuilder(b, pcTXTSuffix)
return b.String()
}
// Find the target hash in TXT response
func (c *sbCtx) processTXT(resp *dns.Msg) (bool, [][]byte) {
matched := false
hashes := [][]byte{}
for _, a := range resp.Answer {
txt, ok := a.(*dns.TXT)
if !ok {
continue
}
log.Debug("%s: received hashes for %s: %v", c.svc, c.host, txt.Txt)
for _, t := range txt.Txt {
if len(t) != 32*2 {
continue
}
hash, err := hex.DecodeString(t)
if err != nil {
continue
}
hashes = append(hashes, hash)
if !matched {
var hash32 [32]byte
copy(hash32[:], hash)
var hashHost string
hashHost, ok = c.hashToHost[hash32]
if ok {
log.Debug("%s: matched %s by %s/%s", c.svc, c.host, hashHost, t)
matched = true
}
}
}
}
return matched, hashes
}
func (c *sbCtx) storeCache(hashes [][]byte) {
slices.SortFunc(hashes, func(a, b []byte) (sortsBefore bool) {
return bytes.Compare(a, b) == -1
})
var curData []byte
var prevPrefix []byte
for i, hash := range hashes {
// nolint:looppointer // The subsilce is used for a safe comparison.
if !bytes.Equal(hash[0:2], prevPrefix) {
if i != 0 {
c.setCache(prevPrefix, curData)
curData = nil
}
prevPrefix = hashes[i][0:2]
}
curData = append(curData, hash...)
}
if len(prevPrefix) != 0 {
c.setCache(prevPrefix, curData)
}
for hash := range c.hashToHost {
// nolint:looppointer // The subsilce is used for a safe cache lookup.
prefix := hash[0:2]
val := c.cache.Get(prefix)
if val == nil {
c.setCache(prefix, nil)
}
}
}
func check(c *sbCtx, r Result, u upstream.Upstream) (Result, error) {
c.hashToHost = hostnameToHashes(c.host)
switch c.getCached() {
case -1:
return Result{}, nil
case 1:
return r, nil
}
question := c.getQuestion()
log.Tracef("%s: checking %s: %s", c.svc, c.host, question)
req := (&dns.Msg{}).SetQuestion(question, dns.TypeTXT)
resp, err := u.Exchange(req)
if err != nil {
return Result{}, err
}
matched, receivedHashes := c.processTXT(resp)
c.storeCache(receivedHashes)
if matched {
return r, nil
}
return Result{}, nil
}
</s> add | refreshLock: &sync.Mutex{},
filterTitleRegexp: regexp.MustCompile(`^! Title: +(.*)$`),
safeBrowsingChecker: c.SafeBrowsingChecker,
parentalControlChecker: c.ParentalControlChecker, | // New creates properly initialized DNS Filter that is ready to be used. c must
// be non-nil.
func New(c *Config, blockFilters []Filter) (d *DNSFilter, err error) {
d = &DNSFilter{
refreshLock: &sync.Mutex{},
filterTitleRegexp: regexp.MustCompile(`^! Title: +(.*)$`),
safeBrowsingChecker: c.SafeBrowsingChecker,
parentalControlChecker: c.ParentalControlChecker,
refreshLock: &sync.Mutex{},
filterTitleRegexp: regexp.MustCompile(`^! Title: +(.*)$`),
safeBrowsingChecker: c.SafeBrowsingChecker,
parentalControlChecker: c.ParentalControlChecker,
}
d.safebrowsingCache = cache.New(cache.Config{
EnableLRU: true,
MaxSize: c.SafeBrowsingCacheSize, | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request 1837: AG-21462-imp-safebrowsing-parental
Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master
Squashed commit of the following:
commit 85016d4f1105e21a407efade0bd45b8362808061
Merge: 0e61edade 620b51e3e
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 16:36:30 2023 +0300
Merge branch 'master' into AG-21462-imp-safebrowsing-parental
commit 0e61edadeff34f6305e941c1db94575c82f238d9
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 14:51:37 2023 +0300
filtering: imp tests
commit 994255514cc0f67dfe33d5a0892432e8924d1e36
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:13:19 2023 +0300
filtering: fix typo
commit 96d1069573171538333330d6af94ef0f4208a9c4
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:00:18 2023 +0300
filtering: imp code more
commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 19:13:26 2023 +0300
all: add todo
commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 14:36:08 2023 +0300
all: imp code more
commit b6e734ccbeda82669023f6578481260b7c1f7161
Author: Stanislav Chzhen <[email protected]>
Date: Tue Apr 25 15:01:56 2023 +0300
filtering: imp code
commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 20:06:36 2023 +0300
all: imp code
commit 49fa6e587052a40bb431fea457701ee860493527
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 14:57:19 2023 +0300
all: rm safe browsing ctx
commit bbcb66cb03e18fa875e3c33cf16295892739e507
Author: Stanislav Chzhen <[email protected]>
Date: Fri Apr 21 17:54:18 2023 +0300
filtering: add cache item
commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 18:43:02 2023 +0300
filtering: fix hashes
commit 153fec46270212af03f3631bfb42c5d680c4e142
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 16:15:15 2023 +0300
filtering: add test cases
commit 09372f92bbb1fc082f1b1283594ee589100209c5
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 15:38:05 2023 +0300
filtering: imp code
commit 466bc26d524ea6d1c3efb33692a7785d39e491ca
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 18:38:40 2023 +0300
filtering: add tests
commit 24365ecf8c60512fdac65833ee603c80864ae018
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 11:38:57 2023 +0300
filtering: add hashprefix | https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c | internal/filtering/filtering.go |
refreshLock: &sync.Mutex{},
filterTitleRegexp: regexp.MustCompile(`^! Title: +(.*)$`),
}
d.safebrowsingCache = cache.New(cache.Config{
EnableLRU: true,
MaxSize: c.SafeBrowsingCacheSize,
})
d.parentalCache = cache.New(cache.Config{
EnableLRU: true,
MaxSize: c.ParentalCacheSize,
})
d.safeSearch = c.SafeSearch
d.hostCheckers = []hostChecker{{
check: d.matchSysHosts,
name: "hosts container",
| </s> remove refreshLock: &sync.Mutex{},
filterTitleRegexp: regexp.MustCompile(`^! Title: +(.*)$`),
</s> add refreshLock: &sync.Mutex{},
filterTitleRegexp: regexp.MustCompile(`^! Title: +(.*)$`),
safeBrowsingChecker: c.SafeBrowsingChecker,
parentalControlChecker: c.ParentalControlChecker, </s> remove const hostname = "wmconvirus.narod.ru"
</s> add const (
hostname = "wmconvirus.narod.ru"
cacheTime = 10 * time.Minute
cacheSize = 10000
)
sbChecker := hashprefix.New(&hashprefix.Config{
CacheTime: cacheTime,
CacheSize: cacheSize,
Upstream: aghtest.NewBlockUpstream(hostname, true),
}) </s> remove sbUps := aghtest.NewBlockUpstream(hostname, true)
</s> add </s> remove func purgeCaches(d *DNSFilter) {
for _, c := range []cache.Cache{
d.safebrowsingCache,
d.parentalCache,
} {
if c != nil {
c.Clear()
}
}
}
</s> add </s> remove err = d.initSecurityServices()
if err != nil {
return nil, fmt.Errorf("initializing services: %s", err)
}
</s> add | refreshLock: &sync.Mutex{},
filterTitleRegexp: regexp.MustCompile(`^! Title: +(.*)$`),
}
d.safeSearch = c.SafeSearch
d.hostCheckers = []hostChecker{{
check: d.matchSysHosts,
name: "hosts container", | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request 1837: AG-21462-imp-safebrowsing-parental
Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master
Squashed commit of the following:
commit 85016d4f1105e21a407efade0bd45b8362808061
Merge: 0e61edade 620b51e3e
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 16:36:30 2023 +0300
Merge branch 'master' into AG-21462-imp-safebrowsing-parental
commit 0e61edadeff34f6305e941c1db94575c82f238d9
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 14:51:37 2023 +0300
filtering: imp tests
commit 994255514cc0f67dfe33d5a0892432e8924d1e36
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:13:19 2023 +0300
filtering: fix typo
commit 96d1069573171538333330d6af94ef0f4208a9c4
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:00:18 2023 +0300
filtering: imp code more
commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 19:13:26 2023 +0300
all: add todo
commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 14:36:08 2023 +0300
all: imp code more
commit b6e734ccbeda82669023f6578481260b7c1f7161
Author: Stanislav Chzhen <[email protected]>
Date: Tue Apr 25 15:01:56 2023 +0300
filtering: imp code
commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 20:06:36 2023 +0300
all: imp code
commit 49fa6e587052a40bb431fea457701ee860493527
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 14:57:19 2023 +0300
all: rm safe browsing ctx
commit bbcb66cb03e18fa875e3c33cf16295892739e507
Author: Stanislav Chzhen <[email protected]>
Date: Fri Apr 21 17:54:18 2023 +0300
filtering: add cache item
commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 18:43:02 2023 +0300
filtering: fix hashes
commit 153fec46270212af03f3631bfb42c5d680c4e142
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 16:15:15 2023 +0300
filtering: add test cases
commit 09372f92bbb1fc082f1b1283594ee589100209c5
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 15:38:05 2023 +0300
filtering: imp code
commit 466bc26d524ea6d1c3efb33692a7785d39e491ca
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 18:38:40 2023 +0300
filtering: add tests
commit 24365ecf8c60512fdac65833ee603c80864ae018
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 11:38:57 2023 +0300
filtering: add hashprefix | https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c | internal/filtering/filtering.go |
|
}}
defer func() { err = errors.Annotate(err, "filtering: %w") }()
err = d.initSecurityServices()
if err != nil {
return nil, fmt.Errorf("initializing services: %s", err)
}
d.Config = *c
d.filtersMu = &sync.RWMutex{}
err = d.prepareRewrites()
if err != nil {
| </s> remove return check(sctx, res, d.safeBrowsingUpstream)
</s> add block, err := d.safeBrowsingChecker.Check(host)
if !block || err != nil {
return Result{}, err
}
return res, nil </s> remove // TODO(a.garipov): Make configurable.
const (
dnsTimeout = 3 * time.Second
defaultSafebrowsingServer = `https://family.adguard-dns.com/dns-query`
defaultParentalServer = `https://family.adguard-dns.com/dns-query`
sbTXTSuffix = `sb.dns.adguard.com.`
pcTXTSuffix = `pc.dns.adguard.com.`
)
// SetParentalUpstream sets the parental upstream for *DNSFilter.
//
// TODO(e.burkov): Remove this in v1 API to forbid the direct access.
func (d *DNSFilter) SetParentalUpstream(u upstream.Upstream) {
d.parentalUpstream = u
}
// SetSafeBrowsingUpstream sets the safe browsing upstream for *DNSFilter.
//
// TODO(e.burkov): Remove this in v1 API to forbid the direct access.
func (d *DNSFilter) SetSafeBrowsingUpstream(u upstream.Upstream) {
d.safeBrowsingUpstream = u
}
func (d *DNSFilter) initSecurityServices() error {
var err error
d.safeBrowsingServer = defaultSafebrowsingServer
d.parentalServer = defaultParentalServer
opts := &upstream.Options{
Timeout: dnsTimeout,
ServerIPAddrs: []net.IP{
{94, 140, 14, 15},
{94, 140, 15, 16},
net.ParseIP("2a10:50c0::bad1:ff"),
net.ParseIP("2a10:50c0::bad2:ff"),
},
}
parUps, err := upstream.AddressToUpstream(d.parentalServer, opts)
if err != nil {
return fmt.Errorf("converting parental server: %w", err)
}
d.SetParentalUpstream(parUps)
sbUps, err := upstream.AddressToUpstream(d.safeBrowsingServer, opts)
if err != nil {
return fmt.Errorf("converting safe browsing server: %w", err)
}
d.SetSafeBrowsingUpstream(sbUps)
return nil
}
/*
expire byte[4]
hash byte[32]
...
*/
func (c *sbCtx) setCache(prefix, hashes []byte) {
d := make([]byte, 4+len(hashes))
expire := uint(time.Now().Unix()) + c.cacheTime*60
binary.BigEndian.PutUint32(d[:4], uint32(expire))
copy(d[4:], hashes)
c.cache.Set(prefix, d)
log.Debug("%s: stored in cache: %v", c.svc, prefix)
}
// findInHash returns 32-byte hash if it's found in hashToHost.
func (c *sbCtx) findInHash(val []byte) (hash32 [32]byte, found bool) {
for i := 4; i < len(val); i += 32 {
hash := val[i : i+32]
copy(hash32[:], hash[0:32])
_, found = c.hashToHost[hash32]
if found {
return hash32, found
}
}
return [32]byte{}, false
}
func (c *sbCtx) getCached() int {
now := time.Now().Unix()
hashesToRequest := map[[32]byte]string{}
for k, v := range c.hashToHost {
// nolint:looppointer // The subsilce is used for a safe cache lookup.
val := c.cache.Get(k[0:2])
if val == nil || now >= int64(binary.BigEndian.Uint32(val)) {
hashesToRequest[k] = v
continue
}
if hash32, found := c.findInHash(val); found {
log.Debug("%s: found in cache: %s: blocked by %v", c.svc, c.host, hash32)
return 1
}
}
if len(hashesToRequest) == 0 {
log.Debug("%s: found in cache: %s: not blocked", c.svc, c.host)
return -1
}
c.hashToHost = hashesToRequest
return 0
}
type sbCtx struct {
host string
svc string
hashToHost map[[32]byte]string
cache cache.Cache
cacheTime uint
}
func hostnameToHashes(host string) map[[32]byte]string {
hashes := map[[32]byte]string{}
tld, icann := publicsuffix.PublicSuffix(host)
if !icann {
// private suffixes like cloudfront.net
tld = ""
}
curhost := host
nDots := 0
for i := len(curhost) - 1; i >= 0; i-- {
if curhost[i] == '.' {
nDots++
if nDots == 4 {
curhost = curhost[i+1:] // "xxx.a.b.c.d" -> "a.b.c.d"
break
}
}
}
for {
if curhost == "" {
// we've reached end of string
break
}
if tld != "" && curhost == tld {
// we've reached the TLD, don't hash it
break
}
sum := sha256.Sum256([]byte(curhost))
hashes[sum] = curhost
pos := strings.IndexByte(curhost, byte('.'))
if pos < 0 {
break
}
curhost = curhost[pos+1:]
}
return hashes
}
// convert hash array to string
func (c *sbCtx) getQuestion() string {
b := &strings.Builder{}
for hash := range c.hashToHost {
// nolint:looppointer // The subsilce is used for safe hex encoding.
stringutil.WriteToBuilder(b, hex.EncodeToString(hash[0:2]), ".")
}
if c.svc == "SafeBrowsing" {
stringutil.WriteToBuilder(b, sbTXTSuffix)
return b.String()
}
stringutil.WriteToBuilder(b, pcTXTSuffix)
return b.String()
}
// Find the target hash in TXT response
func (c *sbCtx) processTXT(resp *dns.Msg) (bool, [][]byte) {
matched := false
hashes := [][]byte{}
for _, a := range resp.Answer {
txt, ok := a.(*dns.TXT)
if !ok {
continue
}
log.Debug("%s: received hashes for %s: %v", c.svc, c.host, txt.Txt)
for _, t := range txt.Txt {
if len(t) != 32*2 {
continue
}
hash, err := hex.DecodeString(t)
if err != nil {
continue
}
hashes = append(hashes, hash)
if !matched {
var hash32 [32]byte
copy(hash32[:], hash)
var hashHost string
hashHost, ok = c.hashToHost[hash32]
if ok {
log.Debug("%s: matched %s by %s/%s", c.svc, c.host, hashHost, t)
matched = true
}
}
}
}
return matched, hashes
}
func (c *sbCtx) storeCache(hashes [][]byte) {
slices.SortFunc(hashes, func(a, b []byte) (sortsBefore bool) {
return bytes.Compare(a, b) == -1
})
var curData []byte
var prevPrefix []byte
for i, hash := range hashes {
// nolint:looppointer // The subsilce is used for a safe comparison.
if !bytes.Equal(hash[0:2], prevPrefix) {
if i != 0 {
c.setCache(prevPrefix, curData)
curData = nil
}
prevPrefix = hashes[i][0:2]
}
curData = append(curData, hash...)
}
if len(prevPrefix) != 0 {
c.setCache(prevPrefix, curData)
}
for hash := range c.hashToHost {
// nolint:looppointer // The subsilce is used for a safe cache lookup.
prefix := hash[0:2]
val := c.cache.Get(prefix)
if val == nil {
c.setCache(prefix, nil)
}
}
}
func check(c *sbCtx, r Result, u upstream.Upstream) (Result, error) {
c.hashToHost = hostnameToHashes(c.host)
switch c.getCached() {
case -1:
return Result{}, nil
case 1:
return r, nil
}
question := c.getQuestion()
log.Tracef("%s: checking %s: %s", c.svc, c.host, question)
req := (&dns.Msg{}).SetQuestion(question, dns.TypeTXT)
resp, err := u.Exchange(req)
if err != nil {
return Result{}, err
}
matched, receivedHashes := c.processTXT(resp)
c.storeCache(receivedHashes)
if matched {
return r, nil
}
return Result{}, nil
}
</s> add </s> remove return check(sctx, res, d.parentalUpstream)
</s> add block, err := d.parentalControlChecker.Check(host)
if !block || err != nil {
return Result{}, err
}
return res, nil </s> remove func purgeCaches(d *DNSFilter) {
for _, c := range []cache.Cache{
d.safebrowsingCache,
d.parentalCache,
} {
if c != nil {
c.Clear()
}
}
}
</s> add </s> remove purgeCaches(f)
</s> add | }}
defer func() { err = errors.Annotate(err, "filtering: %w") }()
d.Config = *c
d.filtersMu = &sync.RWMutex{}
err = d.prepareRewrites()
if err != nil { | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request 1837: AG-21462-imp-safebrowsing-parental
Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master
Squashed commit of the following:
commit 85016d4f1105e21a407efade0bd45b8362808061
Merge: 0e61edade 620b51e3e
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 16:36:30 2023 +0300
Merge branch 'master' into AG-21462-imp-safebrowsing-parental
commit 0e61edadeff34f6305e941c1db94575c82f238d9
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 14:51:37 2023 +0300
filtering: imp tests
commit 994255514cc0f67dfe33d5a0892432e8924d1e36
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:13:19 2023 +0300
filtering: fix typo
commit 96d1069573171538333330d6af94ef0f4208a9c4
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:00:18 2023 +0300
filtering: imp code more
commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 19:13:26 2023 +0300
all: add todo
commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 14:36:08 2023 +0300
all: imp code more
commit b6e734ccbeda82669023f6578481260b7c1f7161
Author: Stanislav Chzhen <[email protected]>
Date: Tue Apr 25 15:01:56 2023 +0300
filtering: imp code
commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 20:06:36 2023 +0300
all: imp code
commit 49fa6e587052a40bb431fea457701ee860493527
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 14:57:19 2023 +0300
all: rm safe browsing ctx
commit bbcb66cb03e18fa875e3c33cf16295892739e507
Author: Stanislav Chzhen <[email protected]>
Date: Fri Apr 21 17:54:18 2023 +0300
filtering: add cache item
commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 18:43:02 2023 +0300
filtering: fix hashes
commit 153fec46270212af03f3631bfb42c5d680c4e142
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 16:15:15 2023 +0300
filtering: add test cases
commit 09372f92bbb1fc082f1b1283594ee589100209c5
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 15:38:05 2023 +0300
filtering: imp code
commit 466bc26d524ea6d1c3efb33692a7785d39e491ca
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 18:38:40 2023 +0300
filtering: add tests
commit 24365ecf8c60512fdac65833ee603c80864ae018
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 11:38:57 2023 +0300
filtering: add hashprefix | https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c | internal/filtering/filtering.go |
|
"net"
"testing"
"github.com/AdguardTeam/AdGuardHome/internal/aghtest"
"github.com/AdguardTeam/golibs/cache"
"github.com/AdguardTeam/golibs/log"
"github.com/AdguardTeam/golibs/testutil"
"github.com/AdguardTeam/urlfilter/rules"
"github.com/miekg/dns"
"github.com/stretchr/testify/assert"
| </s> remove "github.com/AdguardTeam/dnsproxy/upstream"
"github.com/AdguardTeam/golibs/cache"
</s> add </s> remove "time"
</s> add </s> remove "github.com/AdguardTeam/golibs/stringutil"
"github.com/miekg/dns"
"golang.org/x/exp/slices"
"golang.org/x/net/publicsuffix"
</s> add </s> remove "github.com/AdguardTeam/dnsproxy/upstream"
"github.com/AdguardTeam/golibs/cache"
</s> add | "github.com/AdguardTeam/AdGuardHome/internal/filtering/hashprefix" | "net"
"testing"
"github.com/AdguardTeam/AdGuardHome/internal/aghtest"
"github.com/AdguardTeam/AdGuardHome/internal/filtering/hashprefix"
"github.com/AdguardTeam/golibs/log"
"github.com/AdguardTeam/golibs/testutil"
"github.com/AdguardTeam/urlfilter/rules"
"github.com/miekg/dns"
"github.com/stretchr/testify/assert" | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request 1837: AG-21462-imp-safebrowsing-parental
Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master
Squashed commit of the following:
commit 85016d4f1105e21a407efade0bd45b8362808061
Merge: 0e61edade 620b51e3e
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 16:36:30 2023 +0300
Merge branch 'master' into AG-21462-imp-safebrowsing-parental
commit 0e61edadeff34f6305e941c1db94575c82f238d9
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 14:51:37 2023 +0300
filtering: imp tests
commit 994255514cc0f67dfe33d5a0892432e8924d1e36
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:13:19 2023 +0300
filtering: fix typo
commit 96d1069573171538333330d6af94ef0f4208a9c4
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:00:18 2023 +0300
filtering: imp code more
commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 19:13:26 2023 +0300
all: add todo
commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 14:36:08 2023 +0300
all: imp code more
commit b6e734ccbeda82669023f6578481260b7c1f7161
Author: Stanislav Chzhen <[email protected]>
Date: Tue Apr 25 15:01:56 2023 +0300
filtering: imp code
commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 20:06:36 2023 +0300
all: imp code
commit 49fa6e587052a40bb431fea457701ee860493527
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 14:57:19 2023 +0300
all: rm safe browsing ctx
commit bbcb66cb03e18fa875e3c33cf16295892739e507
Author: Stanislav Chzhen <[email protected]>
Date: Fri Apr 21 17:54:18 2023 +0300
filtering: add cache item
commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 18:43:02 2023 +0300
filtering: fix hashes
commit 153fec46270212af03f3631bfb42c5d680c4e142
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 16:15:15 2023 +0300
filtering: add test cases
commit 09372f92bbb1fc082f1b1283594ee589100209c5
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 15:38:05 2023 +0300
filtering: imp code
commit 466bc26d524ea6d1c3efb33692a7785d39e491ca
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 18:38:40 2023 +0300
filtering: add tests
commit 24365ecf8c60512fdac65833ee603c80864ae018
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 11:38:57 2023 +0300
filtering: add hashprefix | https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c | internal/filtering/filtering_test.go |
)
// Helpers.
func purgeCaches(d *DNSFilter) {
for _, c := range []cache.Cache{
d.safebrowsingCache,
d.parentalCache,
} {
if c != nil {
c.Clear()
}
}
}
func newForTest(t testing.TB, c *Config, filters []Filter) (f *DNSFilter, setts *Settings) {
setts = &Settings{
ProtectionEnabled: true,
FilteringEnabled: true,
}
| </s> remove refreshLock: &sync.Mutex{},
filterTitleRegexp: regexp.MustCompile(`^! Title: +(.*)$`),
</s> add refreshLock: &sync.Mutex{},
filterTitleRegexp: regexp.MustCompile(`^! Title: +(.*)$`),
safeBrowsingChecker: c.SafeBrowsingChecker,
parentalControlChecker: c.ParentalControlChecker, </s> remove // TODO(a.garipov): Make configurable.
const (
dnsTimeout = 3 * time.Second
defaultSafebrowsingServer = `https://family.adguard-dns.com/dns-query`
defaultParentalServer = `https://family.adguard-dns.com/dns-query`
sbTXTSuffix = `sb.dns.adguard.com.`
pcTXTSuffix = `pc.dns.adguard.com.`
)
// SetParentalUpstream sets the parental upstream for *DNSFilter.
//
// TODO(e.burkov): Remove this in v1 API to forbid the direct access.
func (d *DNSFilter) SetParentalUpstream(u upstream.Upstream) {
d.parentalUpstream = u
}
// SetSafeBrowsingUpstream sets the safe browsing upstream for *DNSFilter.
//
// TODO(e.burkov): Remove this in v1 API to forbid the direct access.
func (d *DNSFilter) SetSafeBrowsingUpstream(u upstream.Upstream) {
d.safeBrowsingUpstream = u
}
func (d *DNSFilter) initSecurityServices() error {
var err error
d.safeBrowsingServer = defaultSafebrowsingServer
d.parentalServer = defaultParentalServer
opts := &upstream.Options{
Timeout: dnsTimeout,
ServerIPAddrs: []net.IP{
{94, 140, 14, 15},
{94, 140, 15, 16},
net.ParseIP("2a10:50c0::bad1:ff"),
net.ParseIP("2a10:50c0::bad2:ff"),
},
}
parUps, err := upstream.AddressToUpstream(d.parentalServer, opts)
if err != nil {
return fmt.Errorf("converting parental server: %w", err)
}
d.SetParentalUpstream(parUps)
sbUps, err := upstream.AddressToUpstream(d.safeBrowsingServer, opts)
if err != nil {
return fmt.Errorf("converting safe browsing server: %w", err)
}
d.SetSafeBrowsingUpstream(sbUps)
return nil
}
/*
expire byte[4]
hash byte[32]
...
*/
func (c *sbCtx) setCache(prefix, hashes []byte) {
d := make([]byte, 4+len(hashes))
expire := uint(time.Now().Unix()) + c.cacheTime*60
binary.BigEndian.PutUint32(d[:4], uint32(expire))
copy(d[4:], hashes)
c.cache.Set(prefix, d)
log.Debug("%s: stored in cache: %v", c.svc, prefix)
}
// findInHash returns 32-byte hash if it's found in hashToHost.
func (c *sbCtx) findInHash(val []byte) (hash32 [32]byte, found bool) {
for i := 4; i < len(val); i += 32 {
hash := val[i : i+32]
copy(hash32[:], hash[0:32])
_, found = c.hashToHost[hash32]
if found {
return hash32, found
}
}
return [32]byte{}, false
}
func (c *sbCtx) getCached() int {
now := time.Now().Unix()
hashesToRequest := map[[32]byte]string{}
for k, v := range c.hashToHost {
// nolint:looppointer // The subsilce is used for a safe cache lookup.
val := c.cache.Get(k[0:2])
if val == nil || now >= int64(binary.BigEndian.Uint32(val)) {
hashesToRequest[k] = v
continue
}
if hash32, found := c.findInHash(val); found {
log.Debug("%s: found in cache: %s: blocked by %v", c.svc, c.host, hash32)
return 1
}
}
if len(hashesToRequest) == 0 {
log.Debug("%s: found in cache: %s: not blocked", c.svc, c.host)
return -1
}
c.hashToHost = hashesToRequest
return 0
}
type sbCtx struct {
host string
svc string
hashToHost map[[32]byte]string
cache cache.Cache
cacheTime uint
}
func hostnameToHashes(host string) map[[32]byte]string {
hashes := map[[32]byte]string{}
tld, icann := publicsuffix.PublicSuffix(host)
if !icann {
// private suffixes like cloudfront.net
tld = ""
}
curhost := host
nDots := 0
for i := len(curhost) - 1; i >= 0; i-- {
if curhost[i] == '.' {
nDots++
if nDots == 4 {
curhost = curhost[i+1:] // "xxx.a.b.c.d" -> "a.b.c.d"
break
}
}
}
for {
if curhost == "" {
// we've reached end of string
break
}
if tld != "" && curhost == tld {
// we've reached the TLD, don't hash it
break
}
sum := sha256.Sum256([]byte(curhost))
hashes[sum] = curhost
pos := strings.IndexByte(curhost, byte('.'))
if pos < 0 {
break
}
curhost = curhost[pos+1:]
}
return hashes
}
// convert hash array to string
func (c *sbCtx) getQuestion() string {
b := &strings.Builder{}
for hash := range c.hashToHost {
// nolint:looppointer // The subsilce is used for safe hex encoding.
stringutil.WriteToBuilder(b, hex.EncodeToString(hash[0:2]), ".")
}
if c.svc == "SafeBrowsing" {
stringutil.WriteToBuilder(b, sbTXTSuffix)
return b.String()
}
stringutil.WriteToBuilder(b, pcTXTSuffix)
return b.String()
}
// Find the target hash in TXT response
func (c *sbCtx) processTXT(resp *dns.Msg) (bool, [][]byte) {
matched := false
hashes := [][]byte{}
for _, a := range resp.Answer {
txt, ok := a.(*dns.TXT)
if !ok {
continue
}
log.Debug("%s: received hashes for %s: %v", c.svc, c.host, txt.Txt)
for _, t := range txt.Txt {
if len(t) != 32*2 {
continue
}
hash, err := hex.DecodeString(t)
if err != nil {
continue
}
hashes = append(hashes, hash)
if !matched {
var hash32 [32]byte
copy(hash32[:], hash)
var hashHost string
hashHost, ok = c.hashToHost[hash32]
if ok {
log.Debug("%s: matched %s by %s/%s", c.svc, c.host, hashHost, t)
matched = true
}
}
}
}
return matched, hashes
}
func (c *sbCtx) storeCache(hashes [][]byte) {
slices.SortFunc(hashes, func(a, b []byte) (sortsBefore bool) {
return bytes.Compare(a, b) == -1
})
var curData []byte
var prevPrefix []byte
for i, hash := range hashes {
// nolint:looppointer // The subsilce is used for a safe comparison.
if !bytes.Equal(hash[0:2], prevPrefix) {
if i != 0 {
c.setCache(prevPrefix, curData)
curData = nil
}
prevPrefix = hashes[i][0:2]
}
curData = append(curData, hash...)
}
if len(prevPrefix) != 0 {
c.setCache(prevPrefix, curData)
}
for hash := range c.hashToHost {
// nolint:looppointer // The subsilce is used for a safe cache lookup.
prefix := hash[0:2]
val := c.cache.Get(prefix)
if val == nil {
c.setCache(prefix, nil)
}
}
}
func check(c *sbCtx, r Result, u upstream.Upstream) (Result, error) {
c.hashToHost = hostnameToHashes(c.host)
switch c.getCached() {
case -1:
return Result{}, nil
case 1:
return r, nil
}
question := c.getQuestion()
log.Tracef("%s: checking %s: %s", c.svc, c.host, question)
req := (&dns.Msg{}).SetQuestion(question, dns.TypeTXT)
resp, err := u.Exchange(req)
if err != nil {
return Result{}, err
}
matched, receivedHashes := c.processTXT(resp)
c.storeCache(receivedHashes)
if matched {
return r, nil
}
return Result{}, nil
}
</s> add </s> remove return check(sctx, res, d.safeBrowsingUpstream)
</s> add block, err := d.safeBrowsingChecker.Check(host)
if !block || err != nil {
return Result{}, err
}
return res, nil </s> remove purgeCaches(f)
</s> add </s> remove err = d.initSecurityServices()
if err != nil {
return nil, fmt.Errorf("initializing services: %s", err)
}
</s> add | )
// Helpers.
func newForTest(t testing.TB, c *Config, filters []Filter) (f *DNSFilter, setts *Settings) {
setts = &Settings{
ProtectionEnabled: true,
FilteringEnabled: true,
} | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request 1837: AG-21462-imp-safebrowsing-parental
Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master
Squashed commit of the following:
commit 85016d4f1105e21a407efade0bd45b8362808061
Merge: 0e61edade 620b51e3e
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 16:36:30 2023 +0300
Merge branch 'master' into AG-21462-imp-safebrowsing-parental
commit 0e61edadeff34f6305e941c1db94575c82f238d9
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 14:51:37 2023 +0300
filtering: imp tests
commit 994255514cc0f67dfe33d5a0892432e8924d1e36
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:13:19 2023 +0300
filtering: fix typo
commit 96d1069573171538333330d6af94ef0f4208a9c4
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:00:18 2023 +0300
filtering: imp code more
commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 19:13:26 2023 +0300
all: add todo
commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 14:36:08 2023 +0300
all: imp code more
commit b6e734ccbeda82669023f6578481260b7c1f7161
Author: Stanislav Chzhen <[email protected]>
Date: Tue Apr 25 15:01:56 2023 +0300
filtering: imp code
commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 20:06:36 2023 +0300
all: imp code
commit 49fa6e587052a40bb431fea457701ee860493527
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 14:57:19 2023 +0300
all: rm safe browsing ctx
commit bbcb66cb03e18fa875e3c33cf16295892739e507
Author: Stanislav Chzhen <[email protected]>
Date: Fri Apr 21 17:54:18 2023 +0300
filtering: add cache item
commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 18:43:02 2023 +0300
filtering: fix hashes
commit 153fec46270212af03f3631bfb42c5d680c4e142
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 16:15:15 2023 +0300
filtering: add test cases
commit 09372f92bbb1fc082f1b1283594ee589100209c5
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 15:38:05 2023 +0300
filtering: imp code
commit 466bc26d524ea6d1c3efb33692a7785d39e491ca
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 18:38:40 2023 +0300
filtering: add tests
commit 24365ecf8c60512fdac65833ee603c80864ae018
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 11:38:57 2023 +0300
filtering: add hashprefix | https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c | internal/filtering/filtering_test.go |
|
}
f, err := New(c, filters)
require.NoError(t, err)
purgeCaches(f)
return f, setts
}
func (d *DNSFilter) checkMatch(t *testing.T, hostname string, setts *Settings) {
t.Helper()
| </s> remove return check(sctx, res, d.safeBrowsingUpstream)
</s> add block, err := d.safeBrowsingChecker.Check(host)
if !block || err != nil {
return Result{}, err
}
return res, nil </s> remove func purgeCaches(d *DNSFilter) {
for _, c := range []cache.Cache{
d.safebrowsingCache,
d.parentalCache,
} {
if c != nil {
c.Clear()
}
}
}
</s> add </s> remove // TODO(a.garipov): Make configurable.
const (
dnsTimeout = 3 * time.Second
defaultSafebrowsingServer = `https://family.adguard-dns.com/dns-query`
defaultParentalServer = `https://family.adguard-dns.com/dns-query`
sbTXTSuffix = `sb.dns.adguard.com.`
pcTXTSuffix = `pc.dns.adguard.com.`
)
// SetParentalUpstream sets the parental upstream for *DNSFilter.
//
// TODO(e.burkov): Remove this in v1 API to forbid the direct access.
func (d *DNSFilter) SetParentalUpstream(u upstream.Upstream) {
d.parentalUpstream = u
}
// SetSafeBrowsingUpstream sets the safe browsing upstream for *DNSFilter.
//
// TODO(e.burkov): Remove this in v1 API to forbid the direct access.
func (d *DNSFilter) SetSafeBrowsingUpstream(u upstream.Upstream) {
d.safeBrowsingUpstream = u
}
func (d *DNSFilter) initSecurityServices() error {
var err error
d.safeBrowsingServer = defaultSafebrowsingServer
d.parentalServer = defaultParentalServer
opts := &upstream.Options{
Timeout: dnsTimeout,
ServerIPAddrs: []net.IP{
{94, 140, 14, 15},
{94, 140, 15, 16},
net.ParseIP("2a10:50c0::bad1:ff"),
net.ParseIP("2a10:50c0::bad2:ff"),
},
}
parUps, err := upstream.AddressToUpstream(d.parentalServer, opts)
if err != nil {
return fmt.Errorf("converting parental server: %w", err)
}
d.SetParentalUpstream(parUps)
sbUps, err := upstream.AddressToUpstream(d.safeBrowsingServer, opts)
if err != nil {
return fmt.Errorf("converting safe browsing server: %w", err)
}
d.SetSafeBrowsingUpstream(sbUps)
return nil
}
/*
expire byte[4]
hash byte[32]
...
*/
func (c *sbCtx) setCache(prefix, hashes []byte) {
d := make([]byte, 4+len(hashes))
expire := uint(time.Now().Unix()) + c.cacheTime*60
binary.BigEndian.PutUint32(d[:4], uint32(expire))
copy(d[4:], hashes)
c.cache.Set(prefix, d)
log.Debug("%s: stored in cache: %v", c.svc, prefix)
}
// findInHash returns 32-byte hash if it's found in hashToHost.
func (c *sbCtx) findInHash(val []byte) (hash32 [32]byte, found bool) {
for i := 4; i < len(val); i += 32 {
hash := val[i : i+32]
copy(hash32[:], hash[0:32])
_, found = c.hashToHost[hash32]
if found {
return hash32, found
}
}
return [32]byte{}, false
}
func (c *sbCtx) getCached() int {
now := time.Now().Unix()
hashesToRequest := map[[32]byte]string{}
for k, v := range c.hashToHost {
// nolint:looppointer // The subsilce is used for a safe cache lookup.
val := c.cache.Get(k[0:2])
if val == nil || now >= int64(binary.BigEndian.Uint32(val)) {
hashesToRequest[k] = v
continue
}
if hash32, found := c.findInHash(val); found {
log.Debug("%s: found in cache: %s: blocked by %v", c.svc, c.host, hash32)
return 1
}
}
if len(hashesToRequest) == 0 {
log.Debug("%s: found in cache: %s: not blocked", c.svc, c.host)
return -1
}
c.hashToHost = hashesToRequest
return 0
}
type sbCtx struct {
host string
svc string
hashToHost map[[32]byte]string
cache cache.Cache
cacheTime uint
}
func hostnameToHashes(host string) map[[32]byte]string {
hashes := map[[32]byte]string{}
tld, icann := publicsuffix.PublicSuffix(host)
if !icann {
// private suffixes like cloudfront.net
tld = ""
}
curhost := host
nDots := 0
for i := len(curhost) - 1; i >= 0; i-- {
if curhost[i] == '.' {
nDots++
if nDots == 4 {
curhost = curhost[i+1:] // "xxx.a.b.c.d" -> "a.b.c.d"
break
}
}
}
for {
if curhost == "" {
// we've reached end of string
break
}
if tld != "" && curhost == tld {
// we've reached the TLD, don't hash it
break
}
sum := sha256.Sum256([]byte(curhost))
hashes[sum] = curhost
pos := strings.IndexByte(curhost, byte('.'))
if pos < 0 {
break
}
curhost = curhost[pos+1:]
}
return hashes
}
// convert hash array to string
func (c *sbCtx) getQuestion() string {
b := &strings.Builder{}
for hash := range c.hashToHost {
// nolint:looppointer // The subsilce is used for safe hex encoding.
stringutil.WriteToBuilder(b, hex.EncodeToString(hash[0:2]), ".")
}
if c.svc == "SafeBrowsing" {
stringutil.WriteToBuilder(b, sbTXTSuffix)
return b.String()
}
stringutil.WriteToBuilder(b, pcTXTSuffix)
return b.String()
}
// Find the target hash in TXT response
func (c *sbCtx) processTXT(resp *dns.Msg) (bool, [][]byte) {
matched := false
hashes := [][]byte{}
for _, a := range resp.Answer {
txt, ok := a.(*dns.TXT)
if !ok {
continue
}
log.Debug("%s: received hashes for %s: %v", c.svc, c.host, txt.Txt)
for _, t := range txt.Txt {
if len(t) != 32*2 {
continue
}
hash, err := hex.DecodeString(t)
if err != nil {
continue
}
hashes = append(hashes, hash)
if !matched {
var hash32 [32]byte
copy(hash32[:], hash)
var hashHost string
hashHost, ok = c.hashToHost[hash32]
if ok {
log.Debug("%s: matched %s by %s/%s", c.svc, c.host, hashHost, t)
matched = true
}
}
}
}
return matched, hashes
}
func (c *sbCtx) storeCache(hashes [][]byte) {
slices.SortFunc(hashes, func(a, b []byte) (sortsBefore bool) {
return bytes.Compare(a, b) == -1
})
var curData []byte
var prevPrefix []byte
for i, hash := range hashes {
// nolint:looppointer // The subsilce is used for a safe comparison.
if !bytes.Equal(hash[0:2], prevPrefix) {
if i != 0 {
c.setCache(prevPrefix, curData)
curData = nil
}
prevPrefix = hashes[i][0:2]
}
curData = append(curData, hash...)
}
if len(prevPrefix) != 0 {
c.setCache(prevPrefix, curData)
}
for hash := range c.hashToHost {
// nolint:looppointer // The subsilce is used for a safe cache lookup.
prefix := hash[0:2]
val := c.cache.Get(prefix)
if val == nil {
c.setCache(prefix, nil)
}
}
}
func check(c *sbCtx, r Result, u upstream.Upstream) (Result, error) {
c.hashToHost = hostnameToHashes(c.host)
switch c.getCached() {
case -1:
return Result{}, nil
case 1:
return r, nil
}
question := c.getQuestion()
log.Tracef("%s: checking %s: %s", c.svc, c.host, question)
req := (&dns.Msg{}).SetQuestion(question, dns.TypeTXT)
resp, err := u.Exchange(req)
if err != nil {
return Result{}, err
}
matched, receivedHashes := c.processTXT(resp)
c.storeCache(receivedHashes)
if matched {
return r, nil
}
return Result{}, nil
}
</s> add </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
</s> add | }
f, err := New(c, filters)
require.NoError(t, err)
return f, setts
}
func (d *DNSFilter) checkMatch(t *testing.T, hostname string, setts *Settings) {
t.Helper() | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request 1837: AG-21462-imp-safebrowsing-parental
Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master
Squashed commit of the following:
commit 85016d4f1105e21a407efade0bd45b8362808061
Merge: 0e61edade 620b51e3e
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 16:36:30 2023 +0300
Merge branch 'master' into AG-21462-imp-safebrowsing-parental
commit 0e61edadeff34f6305e941c1db94575c82f238d9
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 14:51:37 2023 +0300
filtering: imp tests
commit 994255514cc0f67dfe33d5a0892432e8924d1e36
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:13:19 2023 +0300
filtering: fix typo
commit 96d1069573171538333330d6af94ef0f4208a9c4
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:00:18 2023 +0300
filtering: imp code more
commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 19:13:26 2023 +0300
all: add todo
commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 14:36:08 2023 +0300
all: imp code more
commit b6e734ccbeda82669023f6578481260b7c1f7161
Author: Stanislav Chzhen <[email protected]>
Date: Tue Apr 25 15:01:56 2023 +0300
filtering: imp code
commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 20:06:36 2023 +0300
all: imp code
commit 49fa6e587052a40bb431fea457701ee860493527
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 14:57:19 2023 +0300
all: rm safe browsing ctx
commit bbcb66cb03e18fa875e3c33cf16295892739e507
Author: Stanislav Chzhen <[email protected]>
Date: Fri Apr 21 17:54:18 2023 +0300
filtering: add cache item
commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 18:43:02 2023 +0300
filtering: fix hashes
commit 153fec46270212af03f3631bfb42c5d680c4e142
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 16:15:15 2023 +0300
filtering: add test cases
commit 09372f92bbb1fc082f1b1283594ee589100209c5
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 15:38:05 2023 +0300
filtering: imp code
commit 466bc26d524ea6d1c3efb33692a7785d39e491ca
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 18:38:40 2023 +0300
filtering: add tests
commit 24365ecf8c60512fdac65833ee603c80864ae018
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 11:38:57 2023 +0300
filtering: add hashprefix | https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c | internal/filtering/filtering_test.go |
|
}
func (d *DNSFilter) checkMatch(t *testing.T, hostname string, setts *Settings) {
t.Helper()
res, err := d.CheckHost(hostname, dns.TypeA, setts)
| </s> remove purgeCaches(f)
</s> add </s> remove return check(sctx, res, d.safeBrowsingUpstream)
</s> add block, err := d.safeBrowsingChecker.Check(host)
if !block || err != nil {
return Result{}, err
}
return res, nil </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
</s> add </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
</s> add </s> remove func purgeCaches(d *DNSFilter) {
for _, c := range []cache.Cache{
d.safebrowsingCache,
d.parentalCache,
} {
if c != nil {
c.Clear()
}
}
}
</s> add | func newChecker(host string) Checker {
return hashprefix.New(&hashprefix.Config{
CacheTime: 10,
CacheSize: 100000,
Upstream: aghtest.NewBlockUpstream(host, true),
})
}
| }
func newChecker(host string) Checker {
return hashprefix.New(&hashprefix.Config{
CacheTime: 10,
CacheSize: 100000,
Upstream: aghtest.NewBlockUpstream(host, true),
})
}
func (d *DNSFilter) checkMatch(t *testing.T, hostname string, setts *Settings) {
t.Helper()
res, err := d.CheckHost(hostname, dns.TypeA, setts) | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | Pull request 1837: AG-21462-imp-safebrowsing-parental
Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master
Squashed commit of the following:
commit 85016d4f1105e21a407efade0bd45b8362808061
Merge: 0e61edade 620b51e3e
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 16:36:30 2023 +0300
Merge branch 'master' into AG-21462-imp-safebrowsing-parental
commit 0e61edadeff34f6305e941c1db94575c82f238d9
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 14:51:37 2023 +0300
filtering: imp tests
commit 994255514cc0f67dfe33d5a0892432e8924d1e36
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:13:19 2023 +0300
filtering: fix typo
commit 96d1069573171538333330d6af94ef0f4208a9c4
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:00:18 2023 +0300
filtering: imp code more
commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 19:13:26 2023 +0300
all: add todo
commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 14:36:08 2023 +0300
all: imp code more
commit b6e734ccbeda82669023f6578481260b7c1f7161
Author: Stanislav Chzhen <[email protected]>
Date: Tue Apr 25 15:01:56 2023 +0300
filtering: imp code
commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 20:06:36 2023 +0300
all: imp code
commit 49fa6e587052a40bb431fea457701ee860493527
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 14:57:19 2023 +0300
all: rm safe browsing ctx
commit bbcb66cb03e18fa875e3c33cf16295892739e507
Author: Stanislav Chzhen <[email protected]>
Date: Fri Apr 21 17:54:18 2023 +0300
filtering: add cache item
commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 18:43:02 2023 +0300
filtering: fix hashes
commit 153fec46270212af03f3631bfb42c5d680c4e142
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 16:15:15 2023 +0300
filtering: add test cases
commit 09372f92bbb1fc082f1b1283594ee589100209c5
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 15:38:05 2023 +0300
filtering: imp code
commit 466bc26d524ea6d1c3efb33692a7785d39e491ca
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 18:38:40 2023 +0300
filtering: add tests
commit 24365ecf8c60512fdac65833ee603c80864ae018
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 11:38:57 2023 +0300
filtering: add hashprefix | https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c | internal/filtering/filtering_test.go |
logOutput := &bytes.Buffer{}
aghtest.ReplaceLogWriter(t, logOutput)
aghtest.ReplaceLogLevel(t, log.DEBUG)
d, setts := newForTest(t, &Config{SafeBrowsingEnabled: true}, nil)
t.Cleanup(d.Close)
d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
d.checkMatch(t, sbBlocked, setts)
| </s> remove d, setts := newForTest(t, &Config{ParentalEnabled: true}, nil)
</s> add d, setts := newForTest(t, &Config{
ParentalEnabled: true,
ParentalControlChecker: newChecker(pcBlocked),
}, nil) </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
</s> add </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
</s> add </s> remove d.safeBrowsingServer = defaultSafebrowsingServer
</s> add </s> remove d.SetParentalUpstream(aghtest.NewBlockUpstream(pcBlocked, true))
</s> add | sbChecker := newChecker(sbBlocked)
d, setts := newForTest(t, &Config{
SafeBrowsingEnabled: true,
SafeBrowsingChecker: sbChecker,
}, nil) | logOutput := &bytes.Buffer{}
aghtest.ReplaceLogWriter(t, logOutput)
aghtest.ReplaceLogLevel(t, log.DEBUG)
sbChecker := newChecker(sbBlocked)
d, setts := newForTest(t, &Config{
SafeBrowsingEnabled: true,
SafeBrowsingChecker: sbChecker,
}, nil)
t.Cleanup(d.Close)
d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
d.checkMatch(t, sbBlocked, setts)
| [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request 1837: AG-21462-imp-safebrowsing-parental
Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master
Squashed commit of the following:
commit 85016d4f1105e21a407efade0bd45b8362808061
Merge: 0e61edade 620b51e3e
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 16:36:30 2023 +0300
Merge branch 'master' into AG-21462-imp-safebrowsing-parental
commit 0e61edadeff34f6305e941c1db94575c82f238d9
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 14:51:37 2023 +0300
filtering: imp tests
commit 994255514cc0f67dfe33d5a0892432e8924d1e36
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:13:19 2023 +0300
filtering: fix typo
commit 96d1069573171538333330d6af94ef0f4208a9c4
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:00:18 2023 +0300
filtering: imp code more
commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 19:13:26 2023 +0300
all: add todo
commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 14:36:08 2023 +0300
all: imp code more
commit b6e734ccbeda82669023f6578481260b7c1f7161
Author: Stanislav Chzhen <[email protected]>
Date: Tue Apr 25 15:01:56 2023 +0300
filtering: imp code
commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 20:06:36 2023 +0300
all: imp code
commit 49fa6e587052a40bb431fea457701ee860493527
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 14:57:19 2023 +0300
all: rm safe browsing ctx
commit bbcb66cb03e18fa875e3c33cf16295892739e507
Author: Stanislav Chzhen <[email protected]>
Date: Fri Apr 21 17:54:18 2023 +0300
filtering: add cache item
commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 18:43:02 2023 +0300
filtering: fix hashes
commit 153fec46270212af03f3631bfb42c5d680c4e142
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 16:15:15 2023 +0300
filtering: add test cases
commit 09372f92bbb1fc082f1b1283594ee589100209c5
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 15:38:05 2023 +0300
filtering: imp code
commit 466bc26d524ea6d1c3efb33692a7785d39e491ca
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 18:38:40 2023 +0300
filtering: add tests
commit 24365ecf8c60512fdac65833ee603c80864ae018
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 11:38:57 2023 +0300
filtering: add hashprefix | https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c | internal/filtering/filtering_test.go |
d, setts := newForTest(t, &Config{SafeBrowsingEnabled: true}, nil)
t.Cleanup(d.Close)
d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
d.checkMatch(t, sbBlocked, setts)
require.Contains(t, logOutput.String(), fmt.Sprintf("safebrowsing lookup for %q", sbBlocked))
d.checkMatch(t, "test."+sbBlocked, setts)
| </s> remove d.SetParentalUpstream(aghtest.NewBlockUpstream(pcBlocked, true))
</s> add </s> remove d, setts := newForTest(t, &Config{ParentalEnabled: true}, nil)
</s> add d, setts := newForTest(t, &Config{
ParentalEnabled: true,
ParentalControlChecker: newChecker(pcBlocked),
}, nil) </s> remove d, setts := newForTest(t, &Config{SafeBrowsingEnabled: true}, nil)
</s> add sbChecker := newChecker(sbBlocked)
d, setts := newForTest(t, &Config{
SafeBrowsingEnabled: true,
SafeBrowsingChecker: sbChecker,
}, nil) </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
</s> add </s> remove d.safeBrowsingServer = defaultSafebrowsingServer
</s> add |
d, setts := newForTest(t, &Config{SafeBrowsingEnabled: true}, nil)
t.Cleanup(d.Close)
d.checkMatch(t, sbBlocked, setts)
require.Contains(t, logOutput.String(), fmt.Sprintf("safebrowsing lookup for %q", sbBlocked))
d.checkMatch(t, "test."+sbBlocked, setts) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request 1837: AG-21462-imp-safebrowsing-parental
Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master
Squashed commit of the following:
commit 85016d4f1105e21a407efade0bd45b8362808061
Merge: 0e61edade 620b51e3e
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 16:36:30 2023 +0300
Merge branch 'master' into AG-21462-imp-safebrowsing-parental
commit 0e61edadeff34f6305e941c1db94575c82f238d9
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 14:51:37 2023 +0300
filtering: imp tests
commit 994255514cc0f67dfe33d5a0892432e8924d1e36
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:13:19 2023 +0300
filtering: fix typo
commit 96d1069573171538333330d6af94ef0f4208a9c4
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:00:18 2023 +0300
filtering: imp code more
commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 19:13:26 2023 +0300
all: add todo
commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 14:36:08 2023 +0300
all: imp code more
commit b6e734ccbeda82669023f6578481260b7c1f7161
Author: Stanislav Chzhen <[email protected]>
Date: Tue Apr 25 15:01:56 2023 +0300
filtering: imp code
commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 20:06:36 2023 +0300
all: imp code
commit 49fa6e587052a40bb431fea457701ee860493527
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 14:57:19 2023 +0300
all: rm safe browsing ctx
commit bbcb66cb03e18fa875e3c33cf16295892739e507
Author: Stanislav Chzhen <[email protected]>
Date: Fri Apr 21 17:54:18 2023 +0300
filtering: add cache item
commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 18:43:02 2023 +0300
filtering: fix hashes
commit 153fec46270212af03f3631bfb42c5d680c4e142
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 16:15:15 2023 +0300
filtering: add test cases
commit 09372f92bbb1fc082f1b1283594ee589100209c5
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 15:38:05 2023 +0300
filtering: imp code
commit 466bc26d524ea6d1c3efb33692a7785d39e491ca
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 18:38:40 2023 +0300
filtering: add tests
commit 24365ecf8c60512fdac65833ee603c80864ae018
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 11:38:57 2023 +0300
filtering: add hashprefix | https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c | internal/filtering/filtering_test.go |
|
d.checkMatchEmpty(t, "yandex.ru", setts)
d.checkMatchEmpty(t, pcBlocked, setts)
// Cached result.
d.safeBrowsingServer = "127.0.0.1"
d.checkMatch(t, sbBlocked, setts)
d.checkMatchEmpty(t, pcBlocked, setts)
d.safeBrowsingServer = defaultSafebrowsingServer
}
| </s> remove d.safeBrowsingServer = defaultSafebrowsingServer
</s> add </s> remove d.parentalServer = "127.0.0.1"
</s> add </s> remove d.SetParentalUpstream(aghtest.NewBlockUpstream(pcBlocked, true))
</s> add </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
</s> add </s> remove d, setts := newForTest(t, &Config{ParentalEnabled: true}, nil)
</s> add d, setts := newForTest(t, &Config{
ParentalEnabled: true,
ParentalControlChecker: newChecker(pcBlocked),
}, nil) | d.checkMatchEmpty(t, "yandex.ru", setts)
d.checkMatchEmpty(t, pcBlocked, setts)
// Cached result.
d.checkMatch(t, sbBlocked, setts)
d.checkMatchEmpty(t, pcBlocked, setts)
d.safeBrowsingServer = defaultSafebrowsingServer
}
| [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request 1837: AG-21462-imp-safebrowsing-parental
Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master
Squashed commit of the following:
commit 85016d4f1105e21a407efade0bd45b8362808061
Merge: 0e61edade 620b51e3e
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 16:36:30 2023 +0300
Merge branch 'master' into AG-21462-imp-safebrowsing-parental
commit 0e61edadeff34f6305e941c1db94575c82f238d9
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 14:51:37 2023 +0300
filtering: imp tests
commit 994255514cc0f67dfe33d5a0892432e8924d1e36
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:13:19 2023 +0300
filtering: fix typo
commit 96d1069573171538333330d6af94ef0f4208a9c4
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:00:18 2023 +0300
filtering: imp code more
commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 19:13:26 2023 +0300
all: add todo
commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 14:36:08 2023 +0300
all: imp code more
commit b6e734ccbeda82669023f6578481260b7c1f7161
Author: Stanislav Chzhen <[email protected]>
Date: Tue Apr 25 15:01:56 2023 +0300
filtering: imp code
commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 20:06:36 2023 +0300
all: imp code
commit 49fa6e587052a40bb431fea457701ee860493527
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 14:57:19 2023 +0300
all: rm safe browsing ctx
commit bbcb66cb03e18fa875e3c33cf16295892739e507
Author: Stanislav Chzhen <[email protected]>
Date: Fri Apr 21 17:54:18 2023 +0300
filtering: add cache item
commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 18:43:02 2023 +0300
filtering: fix hashes
commit 153fec46270212af03f3631bfb42c5d680c4e142
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 16:15:15 2023 +0300
filtering: add test cases
commit 09372f92bbb1fc082f1b1283594ee589100209c5
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 15:38:05 2023 +0300
filtering: imp code
commit 466bc26d524ea6d1c3efb33692a7785d39e491ca
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 18:38:40 2023 +0300
filtering: add tests
commit 24365ecf8c60512fdac65833ee603c80864ae018
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 11:38:57 2023 +0300
filtering: add hashprefix | https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c | internal/filtering/filtering_test.go |
|
// Cached result.
d.safeBrowsingServer = "127.0.0.1"
d.checkMatch(t, sbBlocked, setts)
d.checkMatchEmpty(t, pcBlocked, setts)
d.safeBrowsingServer = defaultSafebrowsingServer
}
func TestParallelSB(t *testing.T) {
d, setts := newForTest(t, &Config{SafeBrowsingEnabled: true}, nil)
t.Cleanup(d.Close)
| </s> remove d.safeBrowsingServer = "127.0.0.1"
</s> add </s> remove d, setts := newForTest(t, &Config{SafeBrowsingEnabled: true}, nil)
</s> add d, setts := newForTest(t, &Config{
SafeBrowsingEnabled: true,
SafeBrowsingChecker: newChecker(sbBlocked),
}, nil) </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
</s> add </s> remove d.parentalServer = "127.0.0.1"
</s> add </s> remove d.SetParentalUpstream(aghtest.NewBlockUpstream(pcBlocked, true))
</s> add | // Cached result.
d.safeBrowsingServer = "127.0.0.1"
d.checkMatch(t, sbBlocked, setts)
d.checkMatchEmpty(t, pcBlocked, setts)
}
func TestParallelSB(t *testing.T) {
d, setts := newForTest(t, &Config{SafeBrowsingEnabled: true}, nil)
t.Cleanup(d.Close) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request 1837: AG-21462-imp-safebrowsing-parental
Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master
Squashed commit of the following:
commit 85016d4f1105e21a407efade0bd45b8362808061
Merge: 0e61edade 620b51e3e
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 16:36:30 2023 +0300
Merge branch 'master' into AG-21462-imp-safebrowsing-parental
commit 0e61edadeff34f6305e941c1db94575c82f238d9
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 14:51:37 2023 +0300
filtering: imp tests
commit 994255514cc0f67dfe33d5a0892432e8924d1e36
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:13:19 2023 +0300
filtering: fix typo
commit 96d1069573171538333330d6af94ef0f4208a9c4
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:00:18 2023 +0300
filtering: imp code more
commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 19:13:26 2023 +0300
all: add todo
commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 14:36:08 2023 +0300
all: imp code more
commit b6e734ccbeda82669023f6578481260b7c1f7161
Author: Stanislav Chzhen <[email protected]>
Date: Tue Apr 25 15:01:56 2023 +0300
filtering: imp code
commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 20:06:36 2023 +0300
all: imp code
commit 49fa6e587052a40bb431fea457701ee860493527
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 14:57:19 2023 +0300
all: rm safe browsing ctx
commit bbcb66cb03e18fa875e3c33cf16295892739e507
Author: Stanislav Chzhen <[email protected]>
Date: Fri Apr 21 17:54:18 2023 +0300
filtering: add cache item
commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 18:43:02 2023 +0300
filtering: fix hashes
commit 153fec46270212af03f3631bfb42c5d680c4e142
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 16:15:15 2023 +0300
filtering: add test cases
commit 09372f92bbb1fc082f1b1283594ee589100209c5
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 15:38:05 2023 +0300
filtering: imp code
commit 466bc26d524ea6d1c3efb33692a7785d39e491ca
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 18:38:40 2023 +0300
filtering: add tests
commit 24365ecf8c60512fdac65833ee603c80864ae018
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 11:38:57 2023 +0300
filtering: add hashprefix | https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c | internal/filtering/filtering_test.go |
|
d.safeBrowsingServer = defaultSafebrowsingServer
}
func TestParallelSB(t *testing.T) {
d, setts := newForTest(t, &Config{SafeBrowsingEnabled: true}, nil)
t.Cleanup(d.Close)
d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
t.Run("group", func(t *testing.T) {
| </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
</s> add </s> remove d.safeBrowsingServer = defaultSafebrowsingServer
</s> add </s> remove d, setts := newForTest(b, &Config{SafeBrowsingEnabled: true}, nil)
</s> add d, setts := newForTest(b, &Config{
SafeBrowsingEnabled: true,
SafeBrowsingChecker: newChecker(sbBlocked),
}, nil) </s> remove d, setts := newForTest(t, &Config{SafeBrowsingEnabled: true}, nil)
</s> add sbChecker := newChecker(sbBlocked)
d, setts := newForTest(t, &Config{
SafeBrowsingEnabled: true,
SafeBrowsingChecker: sbChecker,
}, nil) </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
</s> add | d, setts := newForTest(t, &Config{
SafeBrowsingEnabled: true,
SafeBrowsingChecker: newChecker(sbBlocked),
}, nil) | d.safeBrowsingServer = defaultSafebrowsingServer
}
func TestParallelSB(t *testing.T) {
d, setts := newForTest(t, &Config{
SafeBrowsingEnabled: true,
SafeBrowsingChecker: newChecker(sbBlocked),
}, nil)
t.Cleanup(d.Close)
d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
t.Run("group", func(t *testing.T) { | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request 1837: AG-21462-imp-safebrowsing-parental
Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master
Squashed commit of the following:
commit 85016d4f1105e21a407efade0bd45b8362808061
Merge: 0e61edade 620b51e3e
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 16:36:30 2023 +0300
Merge branch 'master' into AG-21462-imp-safebrowsing-parental
commit 0e61edadeff34f6305e941c1db94575c82f238d9
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 14:51:37 2023 +0300
filtering: imp tests
commit 994255514cc0f67dfe33d5a0892432e8924d1e36
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:13:19 2023 +0300
filtering: fix typo
commit 96d1069573171538333330d6af94ef0f4208a9c4
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:00:18 2023 +0300
filtering: imp code more
commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 19:13:26 2023 +0300
all: add todo
commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 14:36:08 2023 +0300
all: imp code more
commit b6e734ccbeda82669023f6578481260b7c1f7161
Author: Stanislav Chzhen <[email protected]>
Date: Tue Apr 25 15:01:56 2023 +0300
filtering: imp code
commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 20:06:36 2023 +0300
all: imp code
commit 49fa6e587052a40bb431fea457701ee860493527
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 14:57:19 2023 +0300
all: rm safe browsing ctx
commit bbcb66cb03e18fa875e3c33cf16295892739e507
Author: Stanislav Chzhen <[email protected]>
Date: Fri Apr 21 17:54:18 2023 +0300
filtering: add cache item
commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 18:43:02 2023 +0300
filtering: fix hashes
commit 153fec46270212af03f3631bfb42c5d680c4e142
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 16:15:15 2023 +0300
filtering: add test cases
commit 09372f92bbb1fc082f1b1283594ee589100209c5
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 15:38:05 2023 +0300
filtering: imp code
commit 466bc26d524ea6d1c3efb33692a7785d39e491ca
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 18:38:40 2023 +0300
filtering: add tests
commit 24365ecf8c60512fdac65833ee603c80864ae018
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 11:38:57 2023 +0300
filtering: add hashprefix | https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c | internal/filtering/filtering_test.go |
func TestParallelSB(t *testing.T) {
d, setts := newForTest(t, &Config{SafeBrowsingEnabled: true}, nil)
t.Cleanup(d.Close)
d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
t.Run("group", func(t *testing.T) {
for i := 0; i < 100; i++ {
t.Run(fmt.Sprintf("aaa%d", i), func(t *testing.T) {
t.Parallel()
d.checkMatch(t, sbBlocked, setts)
| </s> remove d, setts := newForTest(t, &Config{SafeBrowsingEnabled: true}, nil)
</s> add d, setts := newForTest(t, &Config{
SafeBrowsingEnabled: true,
SafeBrowsingChecker: newChecker(sbBlocked),
}, nil) </s> remove d.safeBrowsingServer = defaultSafebrowsingServer
</s> add </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
</s> add </s> remove d, setts := newForTest(b, &Config{SafeBrowsingEnabled: true}, nil)
</s> add d, setts := newForTest(b, &Config{
SafeBrowsingEnabled: true,
SafeBrowsingChecker: newChecker(sbBlocked),
}, nil) </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
</s> add | func TestParallelSB(t *testing.T) {
d, setts := newForTest(t, &Config{SafeBrowsingEnabled: true}, nil)
t.Cleanup(d.Close)
t.Run("group", func(t *testing.T) {
for i := 0; i < 100; i++ {
t.Run(fmt.Sprintf("aaa%d", i), func(t *testing.T) {
t.Parallel()
d.checkMatch(t, sbBlocked, setts) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request 1837: AG-21462-imp-safebrowsing-parental
Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master
Squashed commit of the following:
commit 85016d4f1105e21a407efade0bd45b8362808061
Merge: 0e61edade 620b51e3e
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 16:36:30 2023 +0300
Merge branch 'master' into AG-21462-imp-safebrowsing-parental
commit 0e61edadeff34f6305e941c1db94575c82f238d9
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 14:51:37 2023 +0300
filtering: imp tests
commit 994255514cc0f67dfe33d5a0892432e8924d1e36
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:13:19 2023 +0300
filtering: fix typo
commit 96d1069573171538333330d6af94ef0f4208a9c4
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:00:18 2023 +0300
filtering: imp code more
commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 19:13:26 2023 +0300
all: add todo
commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 14:36:08 2023 +0300
all: imp code more
commit b6e734ccbeda82669023f6578481260b7c1f7161
Author: Stanislav Chzhen <[email protected]>
Date: Tue Apr 25 15:01:56 2023 +0300
filtering: imp code
commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 20:06:36 2023 +0300
all: imp code
commit 49fa6e587052a40bb431fea457701ee860493527
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 14:57:19 2023 +0300
all: rm safe browsing ctx
commit bbcb66cb03e18fa875e3c33cf16295892739e507
Author: Stanislav Chzhen <[email protected]>
Date: Fri Apr 21 17:54:18 2023 +0300
filtering: add cache item
commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 18:43:02 2023 +0300
filtering: fix hashes
commit 153fec46270212af03f3631bfb42c5d680c4e142
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 16:15:15 2023 +0300
filtering: add test cases
commit 09372f92bbb1fc082f1b1283594ee589100209c5
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 15:38:05 2023 +0300
filtering: imp code
commit 466bc26d524ea6d1c3efb33692a7785d39e491ca
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 18:38:40 2023 +0300
filtering: add tests
commit 24365ecf8c60512fdac65833ee603c80864ae018
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 11:38:57 2023 +0300
filtering: add hashprefix | https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c | internal/filtering/filtering_test.go |
|
logOutput := &bytes.Buffer{}
aghtest.ReplaceLogWriter(t, logOutput)
aghtest.ReplaceLogLevel(t, log.DEBUG)
d, setts := newForTest(t, &Config{ParentalEnabled: true}, nil)
t.Cleanup(d.Close)
d.SetParentalUpstream(aghtest.NewBlockUpstream(pcBlocked, true))
d.checkMatch(t, pcBlocked, setts)
require.Contains(t, logOutput.String(), fmt.Sprintf("parental lookup for %q", pcBlocked))
| </s> remove d.SetParentalUpstream(aghtest.NewBlockUpstream(pcBlocked, true))
</s> add </s> remove d, setts := newForTest(t, &Config{SafeBrowsingEnabled: true}, nil)
</s> add sbChecker := newChecker(sbBlocked)
d, setts := newForTest(t, &Config{
SafeBrowsingEnabled: true,
SafeBrowsingChecker: sbChecker,
}, nil) </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
</s> add </s> remove d.safeBrowsingServer = defaultSafebrowsingServer
</s> add </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
</s> add | d, setts := newForTest(t, &Config{
ParentalEnabled: true,
ParentalControlChecker: newChecker(pcBlocked),
}, nil) | logOutput := &bytes.Buffer{}
aghtest.ReplaceLogWriter(t, logOutput)
aghtest.ReplaceLogLevel(t, log.DEBUG)
d, setts := newForTest(t, &Config{
ParentalEnabled: true,
ParentalControlChecker: newChecker(pcBlocked),
}, nil)
t.Cleanup(d.Close)
d.SetParentalUpstream(aghtest.NewBlockUpstream(pcBlocked, true))
d.checkMatch(t, pcBlocked, setts)
require.Contains(t, logOutput.String(), fmt.Sprintf("parental lookup for %q", pcBlocked)) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request 1837: AG-21462-imp-safebrowsing-parental
Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master
Squashed commit of the following:
commit 85016d4f1105e21a407efade0bd45b8362808061
Merge: 0e61edade 620b51e3e
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 16:36:30 2023 +0300
Merge branch 'master' into AG-21462-imp-safebrowsing-parental
commit 0e61edadeff34f6305e941c1db94575c82f238d9
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 14:51:37 2023 +0300
filtering: imp tests
commit 994255514cc0f67dfe33d5a0892432e8924d1e36
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:13:19 2023 +0300
filtering: fix typo
commit 96d1069573171538333330d6af94ef0f4208a9c4
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:00:18 2023 +0300
filtering: imp code more
commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 19:13:26 2023 +0300
all: add todo
commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 14:36:08 2023 +0300
all: imp code more
commit b6e734ccbeda82669023f6578481260b7c1f7161
Author: Stanislav Chzhen <[email protected]>
Date: Tue Apr 25 15:01:56 2023 +0300
filtering: imp code
commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 20:06:36 2023 +0300
all: imp code
commit 49fa6e587052a40bb431fea457701ee860493527
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 14:57:19 2023 +0300
all: rm safe browsing ctx
commit bbcb66cb03e18fa875e3c33cf16295892739e507
Author: Stanislav Chzhen <[email protected]>
Date: Fri Apr 21 17:54:18 2023 +0300
filtering: add cache item
commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 18:43:02 2023 +0300
filtering: fix hashes
commit 153fec46270212af03f3631bfb42c5d680c4e142
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 16:15:15 2023 +0300
filtering: add test cases
commit 09372f92bbb1fc082f1b1283594ee589100209c5
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 15:38:05 2023 +0300
filtering: imp code
commit 466bc26d524ea6d1c3efb33692a7785d39e491ca
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 18:38:40 2023 +0300
filtering: add tests
commit 24365ecf8c60512fdac65833ee603c80864ae018
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 11:38:57 2023 +0300
filtering: add hashprefix | https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c | internal/filtering/filtering_test.go |
d, setts := newForTest(t, &Config{ParentalEnabled: true}, nil)
t.Cleanup(d.Close)
d.SetParentalUpstream(aghtest.NewBlockUpstream(pcBlocked, true))
d.checkMatch(t, pcBlocked, setts)
require.Contains(t, logOutput.String(), fmt.Sprintf("parental lookup for %q", pcBlocked))
d.checkMatch(t, "www."+pcBlocked, setts)
d.checkMatchEmpty(t, "www.yandex.ru", setts)
| </s> remove d, setts := newForTest(t, &Config{ParentalEnabled: true}, nil)
</s> add d, setts := newForTest(t, &Config{
ParentalEnabled: true,
ParentalControlChecker: newChecker(pcBlocked),
}, nil) </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
</s> add </s> remove d.safeBrowsingServer = defaultSafebrowsingServer
</s> add </s> remove d, setts := newForTest(t, &Config{SafeBrowsingEnabled: true}, nil)
</s> add sbChecker := newChecker(sbBlocked)
d, setts := newForTest(t, &Config{
SafeBrowsingEnabled: true,
SafeBrowsingChecker: sbChecker,
}, nil) </s> remove d.safeBrowsingServer = "127.0.0.1"
</s> add |
d, setts := newForTest(t, &Config{ParentalEnabled: true}, nil)
t.Cleanup(d.Close)
d.checkMatch(t, pcBlocked, setts)
require.Contains(t, logOutput.String(), fmt.Sprintf("parental lookup for %q", pcBlocked))
d.checkMatch(t, "www."+pcBlocked, setts)
d.checkMatchEmpty(t, "www.yandex.ru", setts) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request 1837: AG-21462-imp-safebrowsing-parental
Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master
Squashed commit of the following:
commit 85016d4f1105e21a407efade0bd45b8362808061
Merge: 0e61edade 620b51e3e
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 16:36:30 2023 +0300
Merge branch 'master' into AG-21462-imp-safebrowsing-parental
commit 0e61edadeff34f6305e941c1db94575c82f238d9
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 14:51:37 2023 +0300
filtering: imp tests
commit 994255514cc0f67dfe33d5a0892432e8924d1e36
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:13:19 2023 +0300
filtering: fix typo
commit 96d1069573171538333330d6af94ef0f4208a9c4
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:00:18 2023 +0300
filtering: imp code more
commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 19:13:26 2023 +0300
all: add todo
commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 14:36:08 2023 +0300
all: imp code more
commit b6e734ccbeda82669023f6578481260b7c1f7161
Author: Stanislav Chzhen <[email protected]>
Date: Tue Apr 25 15:01:56 2023 +0300
filtering: imp code
commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 20:06:36 2023 +0300
all: imp code
commit 49fa6e587052a40bb431fea457701ee860493527
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 14:57:19 2023 +0300
all: rm safe browsing ctx
commit bbcb66cb03e18fa875e3c33cf16295892739e507
Author: Stanislav Chzhen <[email protected]>
Date: Fri Apr 21 17:54:18 2023 +0300
filtering: add cache item
commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 18:43:02 2023 +0300
filtering: fix hashes
commit 153fec46270212af03f3631bfb42c5d680c4e142
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 16:15:15 2023 +0300
filtering: add test cases
commit 09372f92bbb1fc082f1b1283594ee589100209c5
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 15:38:05 2023 +0300
filtering: imp code
commit 466bc26d524ea6d1c3efb33692a7785d39e491ca
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 18:38:40 2023 +0300
filtering: add tests
commit 24365ecf8c60512fdac65833ee603c80864ae018
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 11:38:57 2023 +0300
filtering: add hashprefix | https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c | internal/filtering/filtering_test.go |
|
d.checkMatchEmpty(t, "yandex.ru", setts)
d.checkMatchEmpty(t, "api.jquery.com", setts)
// Test cached result.
d.parentalServer = "127.0.0.1"
d.checkMatch(t, pcBlocked, setts)
d.checkMatchEmpty(t, "yandex.ru", setts)
}
// Filtering.
| </s> remove d.safeBrowsingServer = "127.0.0.1"
</s> add </s> remove d.safeBrowsingServer = defaultSafebrowsingServer
</s> add </s> remove d.SetParentalUpstream(aghtest.NewBlockUpstream(pcBlocked, true))
</s> add </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
</s> add </s> remove d, setts := newForTest(t, &Config{ParentalEnabled: true}, nil)
</s> add d, setts := newForTest(t, &Config{
ParentalEnabled: true,
ParentalControlChecker: newChecker(pcBlocked),
}, nil) | d.checkMatchEmpty(t, "yandex.ru", setts)
d.checkMatchEmpty(t, "api.jquery.com", setts)
// Test cached result.
d.checkMatch(t, pcBlocked, setts)
d.checkMatchEmpty(t, "yandex.ru", setts)
}
// Filtering. | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request 1837: AG-21462-imp-safebrowsing-parental
Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master
Squashed commit of the following:
commit 85016d4f1105e21a407efade0bd45b8362808061
Merge: 0e61edade 620b51e3e
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 16:36:30 2023 +0300
Merge branch 'master' into AG-21462-imp-safebrowsing-parental
commit 0e61edadeff34f6305e941c1db94575c82f238d9
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 14:51:37 2023 +0300
filtering: imp tests
commit 994255514cc0f67dfe33d5a0892432e8924d1e36
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:13:19 2023 +0300
filtering: fix typo
commit 96d1069573171538333330d6af94ef0f4208a9c4
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:00:18 2023 +0300
filtering: imp code more
commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 19:13:26 2023 +0300
all: add todo
commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 14:36:08 2023 +0300
all: imp code more
commit b6e734ccbeda82669023f6578481260b7c1f7161
Author: Stanislav Chzhen <[email protected]>
Date: Tue Apr 25 15:01:56 2023 +0300
filtering: imp code
commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 20:06:36 2023 +0300
all: imp code
commit 49fa6e587052a40bb431fea457701ee860493527
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 14:57:19 2023 +0300
all: rm safe browsing ctx
commit bbcb66cb03e18fa875e3c33cf16295892739e507
Author: Stanislav Chzhen <[email protected]>
Date: Fri Apr 21 17:54:18 2023 +0300
filtering: add cache item
commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 18:43:02 2023 +0300
filtering: fix hashes
commit 153fec46270212af03f3631bfb42c5d680c4e142
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 16:15:15 2023 +0300
filtering: add test cases
commit 09372f92bbb1fc082f1b1283594ee589100209c5
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 15:38:05 2023 +0300
filtering: imp code
commit 466bc26d524ea6d1c3efb33692a7785d39e491ca
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 18:38:40 2023 +0300
filtering: add tests
commit 24365ecf8c60512fdac65833ee603c80864ae018
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 11:38:57 2023 +0300
filtering: add hashprefix | https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c | internal/filtering/filtering_test.go |
|
func TestClientSettings(t *testing.T) {
d, setts := newForTest(t,
&Config{
ParentalEnabled: true,
SafeBrowsingEnabled: false,
},
[]Filter{{
ID: 0, Data: []byte("||example.org^\n"),
}},
)
| </s> remove d, setts := newForTest(t, &Config{SafeBrowsingEnabled: true}, nil)
</s> add d, setts := newForTest(t, &Config{
SafeBrowsingEnabled: true,
SafeBrowsingChecker: newChecker(sbBlocked),
}, nil) </s> remove d, setts := newForTest(t, &Config{ParentalEnabled: true}, nil)
</s> add d, setts := newForTest(t, &Config{
ParentalEnabled: true,
ParentalControlChecker: newChecker(pcBlocked),
}, nil) </s> remove d, setts := newForTest(t, &Config{SafeBrowsingEnabled: true}, nil)
</s> add sbChecker := newChecker(sbBlocked)
d, setts := newForTest(t, &Config{
SafeBrowsingEnabled: true,
SafeBrowsingChecker: sbChecker,
}, nil) </s> remove d, setts := newForTest(b, &Config{SafeBrowsingEnabled: true}, nil)
</s> add d, setts := newForTest(b, &Config{
SafeBrowsingEnabled: true,
SafeBrowsingChecker: newChecker(sbBlocked),
}, nil) </s> remove d, setts := newForTest(b, &Config{SafeBrowsingEnabled: true}, nil)
</s> add d, setts := newForTest(b, &Config{
SafeBrowsingEnabled: true,
SafeBrowsingChecker: newChecker(sbBlocked),
}, nil) | ParentalEnabled: true,
SafeBrowsingEnabled: false,
SafeBrowsingChecker: newChecker(sbBlocked),
ParentalControlChecker: newChecker(pcBlocked), |
func TestClientSettings(t *testing.T) {
d, setts := newForTest(t,
&Config{
ParentalEnabled: true,
SafeBrowsingEnabled: false,
SafeBrowsingChecker: newChecker(sbBlocked),
ParentalControlChecker: newChecker(pcBlocked),
ParentalEnabled: true,
SafeBrowsingEnabled: false,
SafeBrowsingChecker: newChecker(sbBlocked),
ParentalControlChecker: newChecker(pcBlocked),
},
[]Filter{{
ID: 0, Data: []byte("||example.org^\n"),
}},
) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request 1837: AG-21462-imp-safebrowsing-parental
Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master
Squashed commit of the following:
commit 85016d4f1105e21a407efade0bd45b8362808061
Merge: 0e61edade 620b51e3e
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 16:36:30 2023 +0300
Merge branch 'master' into AG-21462-imp-safebrowsing-parental
commit 0e61edadeff34f6305e941c1db94575c82f238d9
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 14:51:37 2023 +0300
filtering: imp tests
commit 994255514cc0f67dfe33d5a0892432e8924d1e36
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:13:19 2023 +0300
filtering: fix typo
commit 96d1069573171538333330d6af94ef0f4208a9c4
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:00:18 2023 +0300
filtering: imp code more
commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 19:13:26 2023 +0300
all: add todo
commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 14:36:08 2023 +0300
all: imp code more
commit b6e734ccbeda82669023f6578481260b7c1f7161
Author: Stanislav Chzhen <[email protected]>
Date: Tue Apr 25 15:01:56 2023 +0300
filtering: imp code
commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 20:06:36 2023 +0300
all: imp code
commit 49fa6e587052a40bb431fea457701ee860493527
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 14:57:19 2023 +0300
all: rm safe browsing ctx
commit bbcb66cb03e18fa875e3c33cf16295892739e507
Author: Stanislav Chzhen <[email protected]>
Date: Fri Apr 21 17:54:18 2023 +0300
filtering: add cache item
commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 18:43:02 2023 +0300
filtering: fix hashes
commit 153fec46270212af03f3631bfb42c5d680c4e142
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 16:15:15 2023 +0300
filtering: add test cases
commit 09372f92bbb1fc082f1b1283594ee589100209c5
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 15:38:05 2023 +0300
filtering: imp code
commit 466bc26d524ea6d1c3efb33692a7785d39e491ca
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 18:38:40 2023 +0300
filtering: add tests
commit 24365ecf8c60512fdac65833ee603c80864ae018
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 11:38:57 2023 +0300
filtering: add hashprefix | https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c | internal/filtering/filtering_test.go |
}},
)
t.Cleanup(d.Close)
d.SetParentalUpstream(aghtest.NewBlockUpstream(pcBlocked, true))
d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
type testCase struct {
name string
host string
before bool
wantReason Reason
| </s> remove d.SetParentalUpstream(aghtest.NewBlockUpstream(pcBlocked, true))
</s> add </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
</s> add </s> remove d, setts := newForTest(t, &Config{SafeBrowsingEnabled: true}, nil)
</s> add d, setts := newForTest(t, &Config{
SafeBrowsingEnabled: true,
SafeBrowsingChecker: newChecker(sbBlocked),
}, nil) </s> remove d, setts := newForTest(t, &Config{ParentalEnabled: true}, nil)
</s> add d, setts := newForTest(t, &Config{
ParentalEnabled: true,
ParentalControlChecker: newChecker(pcBlocked),
}, nil) | }},
)
t.Cleanup(d.Close)
type testCase struct {
name string
host string
before bool
wantReason Reason | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request 1837: AG-21462-imp-safebrowsing-parental
Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master
Squashed commit of the following:
commit 85016d4f1105e21a407efade0bd45b8362808061
Merge: 0e61edade 620b51e3e
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 16:36:30 2023 +0300
Merge branch 'master' into AG-21462-imp-safebrowsing-parental
commit 0e61edadeff34f6305e941c1db94575c82f238d9
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 14:51:37 2023 +0300
filtering: imp tests
commit 994255514cc0f67dfe33d5a0892432e8924d1e36
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:13:19 2023 +0300
filtering: fix typo
commit 96d1069573171538333330d6af94ef0f4208a9c4
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:00:18 2023 +0300
filtering: imp code more
commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 19:13:26 2023 +0300
all: add todo
commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 14:36:08 2023 +0300
all: imp code more
commit b6e734ccbeda82669023f6578481260b7c1f7161
Author: Stanislav Chzhen <[email protected]>
Date: Tue Apr 25 15:01:56 2023 +0300
filtering: imp code
commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 20:06:36 2023 +0300
all: imp code
commit 49fa6e587052a40bb431fea457701ee860493527
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 14:57:19 2023 +0300
all: rm safe browsing ctx
commit bbcb66cb03e18fa875e3c33cf16295892739e507
Author: Stanislav Chzhen <[email protected]>
Date: Fri Apr 21 17:54:18 2023 +0300
filtering: add cache item
commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 18:43:02 2023 +0300
filtering: fix hashes
commit 153fec46270212af03f3631bfb42c5d680c4e142
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 16:15:15 2023 +0300
filtering: add test cases
commit 09372f92bbb1fc082f1b1283594ee589100209c5
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 15:38:05 2023 +0300
filtering: imp code
commit 466bc26d524ea6d1c3efb33692a7785d39e491ca
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 18:38:40 2023 +0300
filtering: add tests
commit 24365ecf8c60512fdac65833ee603c80864ae018
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 11:38:57 2023 +0300
filtering: add hashprefix | https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c | internal/filtering/filtering_test.go |
|
// Benchmarks.
func BenchmarkSafeBrowsing(b *testing.B) {
d, setts := newForTest(b, &Config{SafeBrowsingEnabled: true}, nil)
b.Cleanup(d.Close)
d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
for n := 0; n < b.N; n++ {
| </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
</s> add </s> remove d, setts := newForTest(b, &Config{SafeBrowsingEnabled: true}, nil)
</s> add d, setts := newForTest(b, &Config{
SafeBrowsingEnabled: true,
SafeBrowsingChecker: newChecker(sbBlocked),
}, nil) </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
</s> add </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
</s> add </s> remove d, setts := newForTest(t, &Config{SafeBrowsingEnabled: true}, nil)
</s> add d, setts := newForTest(t, &Config{
SafeBrowsingEnabled: true,
SafeBrowsingChecker: newChecker(sbBlocked),
}, nil) | d, setts := newForTest(b, &Config{
SafeBrowsingEnabled: true,
SafeBrowsingChecker: newChecker(sbBlocked),
}, nil) |
// Benchmarks.
func BenchmarkSafeBrowsing(b *testing.B) {
d, setts := newForTest(b, &Config{
SafeBrowsingEnabled: true,
SafeBrowsingChecker: newChecker(sbBlocked),
}, nil)
b.Cleanup(d.Close)
d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
for n := 0; n < b.N; n++ { | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request 1837: AG-21462-imp-safebrowsing-parental
Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master
Squashed commit of the following:
commit 85016d4f1105e21a407efade0bd45b8362808061
Merge: 0e61edade 620b51e3e
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 16:36:30 2023 +0300
Merge branch 'master' into AG-21462-imp-safebrowsing-parental
commit 0e61edadeff34f6305e941c1db94575c82f238d9
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 14:51:37 2023 +0300
filtering: imp tests
commit 994255514cc0f67dfe33d5a0892432e8924d1e36
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:13:19 2023 +0300
filtering: fix typo
commit 96d1069573171538333330d6af94ef0f4208a9c4
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:00:18 2023 +0300
filtering: imp code more
commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 19:13:26 2023 +0300
all: add todo
commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 14:36:08 2023 +0300
all: imp code more
commit b6e734ccbeda82669023f6578481260b7c1f7161
Author: Stanislav Chzhen <[email protected]>
Date: Tue Apr 25 15:01:56 2023 +0300
filtering: imp code
commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 20:06:36 2023 +0300
all: imp code
commit 49fa6e587052a40bb431fea457701ee860493527
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 14:57:19 2023 +0300
all: rm safe browsing ctx
commit bbcb66cb03e18fa875e3c33cf16295892739e507
Author: Stanislav Chzhen <[email protected]>
Date: Fri Apr 21 17:54:18 2023 +0300
filtering: add cache item
commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 18:43:02 2023 +0300
filtering: fix hashes
commit 153fec46270212af03f3631bfb42c5d680c4e142
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 16:15:15 2023 +0300
filtering: add test cases
commit 09372f92bbb1fc082f1b1283594ee589100209c5
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 15:38:05 2023 +0300
filtering: imp code
commit 466bc26d524ea6d1c3efb33692a7785d39e491ca
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 18:38:40 2023 +0300
filtering: add tests
commit 24365ecf8c60512fdac65833ee603c80864ae018
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 11:38:57 2023 +0300
filtering: add hashprefix | https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c | internal/filtering/filtering_test.go |
func BenchmarkSafeBrowsing(b *testing.B) {
d, setts := newForTest(b, &Config{SafeBrowsingEnabled: true}, nil)
b.Cleanup(d.Close)
d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
for n := 0; n < b.N; n++ {
res, err := d.CheckHost(sbBlocked, dns.TypeA, setts)
require.NoError(b, err)
assert.Truef(b, res.IsFiltered, "expected hostname %q to match", sbBlocked)
| </s> remove d, setts := newForTest(b, &Config{SafeBrowsingEnabled: true}, nil)
</s> add d, setts := newForTest(b, &Config{
SafeBrowsingEnabled: true,
SafeBrowsingChecker: newChecker(sbBlocked),
}, nil) </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
</s> add </s> remove d, setts := newForTest(b, &Config{SafeBrowsingEnabled: true}, nil)
</s> add d, setts := newForTest(b, &Config{
SafeBrowsingEnabled: true,
SafeBrowsingChecker: newChecker(sbBlocked),
}, nil) </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
</s> add | func BenchmarkSafeBrowsing(b *testing.B) {
d, setts := newForTest(b, &Config{SafeBrowsingEnabled: true}, nil)
b.Cleanup(d.Close)
for n := 0; n < b.N; n++ {
res, err := d.CheckHost(sbBlocked, dns.TypeA, setts)
require.NoError(b, err)
assert.Truef(b, res.IsFiltered, "expected hostname %q to match", sbBlocked) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request 1837: AG-21462-imp-safebrowsing-parental
Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master
Squashed commit of the following:
commit 85016d4f1105e21a407efade0bd45b8362808061
Merge: 0e61edade 620b51e3e
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 16:36:30 2023 +0300
Merge branch 'master' into AG-21462-imp-safebrowsing-parental
commit 0e61edadeff34f6305e941c1db94575c82f238d9
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 14:51:37 2023 +0300
filtering: imp tests
commit 994255514cc0f67dfe33d5a0892432e8924d1e36
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:13:19 2023 +0300
filtering: fix typo
commit 96d1069573171538333330d6af94ef0f4208a9c4
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:00:18 2023 +0300
filtering: imp code more
commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 19:13:26 2023 +0300
all: add todo
commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 14:36:08 2023 +0300
all: imp code more
commit b6e734ccbeda82669023f6578481260b7c1f7161
Author: Stanislav Chzhen <[email protected]>
Date: Tue Apr 25 15:01:56 2023 +0300
filtering: imp code
commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 20:06:36 2023 +0300
all: imp code
commit 49fa6e587052a40bb431fea457701ee860493527
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 14:57:19 2023 +0300
all: rm safe browsing ctx
commit bbcb66cb03e18fa875e3c33cf16295892739e507
Author: Stanislav Chzhen <[email protected]>
Date: Fri Apr 21 17:54:18 2023 +0300
filtering: add cache item
commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 18:43:02 2023 +0300
filtering: fix hashes
commit 153fec46270212af03f3631bfb42c5d680c4e142
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 16:15:15 2023 +0300
filtering: add test cases
commit 09372f92bbb1fc082f1b1283594ee589100209c5
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 15:38:05 2023 +0300
filtering: imp code
commit 466bc26d524ea6d1c3efb33692a7785d39e491ca
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 18:38:40 2023 +0300
filtering: add tests
commit 24365ecf8c60512fdac65833ee603c80864ae018
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 11:38:57 2023 +0300
filtering: add hashprefix | https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c | internal/filtering/filtering_test.go |
|
}
}
func BenchmarkSafeBrowsingParallel(b *testing.B) {
d, setts := newForTest(b, &Config{SafeBrowsingEnabled: true}, nil)
b.Cleanup(d.Close)
d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
b.RunParallel(func(pb *testing.PB) {
| </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
</s> add </s> remove d, setts := newForTest(b, &Config{SafeBrowsingEnabled: true}, nil)
</s> add d, setts := newForTest(b, &Config{
SafeBrowsingEnabled: true,
SafeBrowsingChecker: newChecker(sbBlocked),
}, nil) </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
</s> add </s> remove d, setts := newForTest(t, &Config{SafeBrowsingEnabled: true}, nil)
</s> add d, setts := newForTest(t, &Config{
SafeBrowsingEnabled: true,
SafeBrowsingChecker: newChecker(sbBlocked),
}, nil) </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
</s> add | d, setts := newForTest(b, &Config{
SafeBrowsingEnabled: true,
SafeBrowsingChecker: newChecker(sbBlocked),
}, nil) | }
}
func BenchmarkSafeBrowsingParallel(b *testing.B) {
d, setts := newForTest(b, &Config{
SafeBrowsingEnabled: true,
SafeBrowsingChecker: newChecker(sbBlocked),
}, nil)
b.Cleanup(d.Close)
d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
b.RunParallel(func(pb *testing.PB) { | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request 1837: AG-21462-imp-safebrowsing-parental
Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master
Squashed commit of the following:
commit 85016d4f1105e21a407efade0bd45b8362808061
Merge: 0e61edade 620b51e3e
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 16:36:30 2023 +0300
Merge branch 'master' into AG-21462-imp-safebrowsing-parental
commit 0e61edadeff34f6305e941c1db94575c82f238d9
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 14:51:37 2023 +0300
filtering: imp tests
commit 994255514cc0f67dfe33d5a0892432e8924d1e36
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:13:19 2023 +0300
filtering: fix typo
commit 96d1069573171538333330d6af94ef0f4208a9c4
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:00:18 2023 +0300
filtering: imp code more
commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 19:13:26 2023 +0300
all: add todo
commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 14:36:08 2023 +0300
all: imp code more
commit b6e734ccbeda82669023f6578481260b7c1f7161
Author: Stanislav Chzhen <[email protected]>
Date: Tue Apr 25 15:01:56 2023 +0300
filtering: imp code
commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 20:06:36 2023 +0300
all: imp code
commit 49fa6e587052a40bb431fea457701ee860493527
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 14:57:19 2023 +0300
all: rm safe browsing ctx
commit bbcb66cb03e18fa875e3c33cf16295892739e507
Author: Stanislav Chzhen <[email protected]>
Date: Fri Apr 21 17:54:18 2023 +0300
filtering: add cache item
commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 18:43:02 2023 +0300
filtering: fix hashes
commit 153fec46270212af03f3631bfb42c5d680c4e142
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 16:15:15 2023 +0300
filtering: add test cases
commit 09372f92bbb1fc082f1b1283594ee589100209c5
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 15:38:05 2023 +0300
filtering: imp code
commit 466bc26d524ea6d1c3efb33692a7785d39e491ca
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 18:38:40 2023 +0300
filtering: add tests
commit 24365ecf8c60512fdac65833ee603c80864ae018
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 11:38:57 2023 +0300
filtering: add hashprefix | https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c | internal/filtering/filtering_test.go |
func BenchmarkSafeBrowsingParallel(b *testing.B) {
d, setts := newForTest(b, &Config{SafeBrowsingEnabled: true}, nil)
b.Cleanup(d.Close)
d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
res, err := d.CheckHost(sbBlocked, dns.TypeA, setts)
require.NoError(b, err)
| </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
</s> add </s> remove d, setts := newForTest(b, &Config{SafeBrowsingEnabled: true}, nil)
</s> add d, setts := newForTest(b, &Config{
SafeBrowsingEnabled: true,
SafeBrowsingChecker: newChecker(sbBlocked),
}, nil) </s> remove d, setts := newForTest(b, &Config{SafeBrowsingEnabled: true}, nil)
</s> add d, setts := newForTest(b, &Config{
SafeBrowsingEnabled: true,
SafeBrowsingChecker: newChecker(sbBlocked),
}, nil) </s> remove d.SetSafeBrowsingUpstream(aghtest.NewBlockUpstream(sbBlocked, true))
</s> add </s> remove d, setts := newForTest(t, &Config{SafeBrowsingEnabled: true}, nil)
</s> add d, setts := newForTest(t, &Config{
SafeBrowsingEnabled: true,
SafeBrowsingChecker: newChecker(sbBlocked),
}, nil) | func BenchmarkSafeBrowsingParallel(b *testing.B) {
d, setts := newForTest(b, &Config{SafeBrowsingEnabled: true}, nil)
b.Cleanup(d.Close)
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
res, err := d.CheckHost(sbBlocked, dns.TypeA, setts)
require.NoError(b, err)
| [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request 1837: AG-21462-imp-safebrowsing-parental
Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master
Squashed commit of the following:
commit 85016d4f1105e21a407efade0bd45b8362808061
Merge: 0e61edade 620b51e3e
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 16:36:30 2023 +0300
Merge branch 'master' into AG-21462-imp-safebrowsing-parental
commit 0e61edadeff34f6305e941c1db94575c82f238d9
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 14:51:37 2023 +0300
filtering: imp tests
commit 994255514cc0f67dfe33d5a0892432e8924d1e36
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:13:19 2023 +0300
filtering: fix typo
commit 96d1069573171538333330d6af94ef0f4208a9c4
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:00:18 2023 +0300
filtering: imp code more
commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 19:13:26 2023 +0300
all: add todo
commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 14:36:08 2023 +0300
all: imp code more
commit b6e734ccbeda82669023f6578481260b7c1f7161
Author: Stanislav Chzhen <[email protected]>
Date: Tue Apr 25 15:01:56 2023 +0300
filtering: imp code
commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 20:06:36 2023 +0300
all: imp code
commit 49fa6e587052a40bb431fea457701ee860493527
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 14:57:19 2023 +0300
all: rm safe browsing ctx
commit bbcb66cb03e18fa875e3c33cf16295892739e507
Author: Stanislav Chzhen <[email protected]>
Date: Fri Apr 21 17:54:18 2023 +0300
filtering: add cache item
commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 18:43:02 2023 +0300
filtering: fix hashes
commit 153fec46270212af03f3631bfb42c5d680c4e142
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 16:15:15 2023 +0300
filtering: add test cases
commit 09372f92bbb1fc082f1b1283594ee589100209c5
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 15:38:05 2023 +0300
filtering: imp code
commit 466bc26d524ea6d1c3efb33692a7785d39e491ca
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 18:38:40 2023 +0300
filtering: add tests
commit 24365ecf8c60512fdac65833ee603c80864ae018
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 11:38:57 2023 +0300
filtering: add hashprefix | https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c | internal/filtering/filtering_test.go |
|
package filtering
import (
"bytes"
"crypto/sha256"
"encoding/binary"
"encoding/hex"
"fmt"
"net"
"net/http"
"strings"
"sync"
"time"
| </s> remove "strings"
</s> add </s> remove "time"
</s> add </s> remove "github.com/AdguardTeam/dnsproxy/upstream"
"github.com/AdguardTeam/golibs/cache"
</s> add </s> remove "github.com/AdguardTeam/golibs/cache"
</s> add "github.com/AdguardTeam/AdGuardHome/internal/filtering/hashprefix" | package filtering
import (
"net/http"
"strings"
"sync"
"time"
| [
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request 1837: AG-21462-imp-safebrowsing-parental
Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master
Squashed commit of the following:
commit 85016d4f1105e21a407efade0bd45b8362808061
Merge: 0e61edade 620b51e3e
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 16:36:30 2023 +0300
Merge branch 'master' into AG-21462-imp-safebrowsing-parental
commit 0e61edadeff34f6305e941c1db94575c82f238d9
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 14:51:37 2023 +0300
filtering: imp tests
commit 994255514cc0f67dfe33d5a0892432e8924d1e36
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:13:19 2023 +0300
filtering: fix typo
commit 96d1069573171538333330d6af94ef0f4208a9c4
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:00:18 2023 +0300
filtering: imp code more
commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 19:13:26 2023 +0300
all: add todo
commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 14:36:08 2023 +0300
all: imp code more
commit b6e734ccbeda82669023f6578481260b7c1f7161
Author: Stanislav Chzhen <[email protected]>
Date: Tue Apr 25 15:01:56 2023 +0300
filtering: imp code
commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 20:06:36 2023 +0300
all: imp code
commit 49fa6e587052a40bb431fea457701ee860493527
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 14:57:19 2023 +0300
all: rm safe browsing ctx
commit bbcb66cb03e18fa875e3c33cf16295892739e507
Author: Stanislav Chzhen <[email protected]>
Date: Fri Apr 21 17:54:18 2023 +0300
filtering: add cache item
commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 18:43:02 2023 +0300
filtering: fix hashes
commit 153fec46270212af03f3631bfb42c5d680c4e142
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 16:15:15 2023 +0300
filtering: add test cases
commit 09372f92bbb1fc082f1b1283594ee589100209c5
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 15:38:05 2023 +0300
filtering: imp code
commit 466bc26d524ea6d1c3efb33692a7785d39e491ca
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 18:38:40 2023 +0300
filtering: add tests
commit 24365ecf8c60512fdac65833ee603c80864ae018
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 11:38:57 2023 +0300
filtering: add hashprefix | https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c | internal/filtering/safebrowsing.go |
|
"encoding/hex"
"fmt"
"net"
"net/http"
"strings"
"sync"
"time"
"github.com/AdguardTeam/AdGuardHome/internal/aghhttp"
"github.com/AdguardTeam/dnsproxy/upstream"
| </s> remove "bytes"
"crypto/sha256"
"encoding/binary"
"encoding/hex"
"fmt"
"net"
</s> add </s> remove "time"
</s> add </s> remove "github.com/AdguardTeam/dnsproxy/upstream"
"github.com/AdguardTeam/golibs/cache"
</s> add </s> remove "github.com/AdguardTeam/dnsproxy/upstream"
"github.com/AdguardTeam/golibs/cache"
</s> add </s> remove "github.com/AdguardTeam/golibs/stringutil"
"github.com/miekg/dns"
"golang.org/x/exp/slices"
"golang.org/x/net/publicsuffix"
</s> add | "encoding/hex"
"fmt"
"net"
"net/http"
"sync"
"time"
"github.com/AdguardTeam/AdGuardHome/internal/aghhttp"
"github.com/AdguardTeam/dnsproxy/upstream" | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request 1837: AG-21462-imp-safebrowsing-parental
Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master
Squashed commit of the following:
commit 85016d4f1105e21a407efade0bd45b8362808061
Merge: 0e61edade 620b51e3e
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 16:36:30 2023 +0300
Merge branch 'master' into AG-21462-imp-safebrowsing-parental
commit 0e61edadeff34f6305e941c1db94575c82f238d9
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 14:51:37 2023 +0300
filtering: imp tests
commit 994255514cc0f67dfe33d5a0892432e8924d1e36
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:13:19 2023 +0300
filtering: fix typo
commit 96d1069573171538333330d6af94ef0f4208a9c4
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:00:18 2023 +0300
filtering: imp code more
commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 19:13:26 2023 +0300
all: add todo
commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 14:36:08 2023 +0300
all: imp code more
commit b6e734ccbeda82669023f6578481260b7c1f7161
Author: Stanislav Chzhen <[email protected]>
Date: Tue Apr 25 15:01:56 2023 +0300
filtering: imp code
commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 20:06:36 2023 +0300
all: imp code
commit 49fa6e587052a40bb431fea457701ee860493527
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 14:57:19 2023 +0300
all: rm safe browsing ctx
commit bbcb66cb03e18fa875e3c33cf16295892739e507
Author: Stanislav Chzhen <[email protected]>
Date: Fri Apr 21 17:54:18 2023 +0300
filtering: add cache item
commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 18:43:02 2023 +0300
filtering: fix hashes
commit 153fec46270212af03f3631bfb42c5d680c4e142
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 16:15:15 2023 +0300
filtering: add test cases
commit 09372f92bbb1fc082f1b1283594ee589100209c5
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 15:38:05 2023 +0300
filtering: imp code
commit 466bc26d524ea6d1c3efb33692a7785d39e491ca
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 18:38:40 2023 +0300
filtering: add tests
commit 24365ecf8c60512fdac65833ee603c80864ae018
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 11:38:57 2023 +0300
filtering: add hashprefix | https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c | internal/filtering/safebrowsing.go |
|
"net"
"net/http"
"strings"
"sync"
"time"
"github.com/AdguardTeam/AdGuardHome/internal/aghhttp"
"github.com/AdguardTeam/dnsproxy/upstream"
"github.com/AdguardTeam/golibs/cache"
"github.com/AdguardTeam/golibs/log"
| </s> remove "strings"
</s> add </s> remove "github.com/AdguardTeam/dnsproxy/upstream"
"github.com/AdguardTeam/golibs/cache"
</s> add </s> remove "bytes"
"crypto/sha256"
"encoding/binary"
"encoding/hex"
"fmt"
"net"
</s> add </s> remove "github.com/AdguardTeam/dnsproxy/upstream"
"github.com/AdguardTeam/golibs/cache"
</s> add </s> remove "github.com/AdguardTeam/golibs/stringutil"
"github.com/miekg/dns"
"golang.org/x/exp/slices"
"golang.org/x/net/publicsuffix"
</s> add | "net"
"net/http"
"strings"
"sync"
"github.com/AdguardTeam/AdGuardHome/internal/aghhttp"
"github.com/AdguardTeam/dnsproxy/upstream"
"github.com/AdguardTeam/golibs/cache"
"github.com/AdguardTeam/golibs/log" | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request 1837: AG-21462-imp-safebrowsing-parental
Merge in DNS/adguard-home from AG-21462-imp-safebrowsing-parental to master
Squashed commit of the following:
commit 85016d4f1105e21a407efade0bd45b8362808061
Merge: 0e61edade 620b51e3e
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 16:36:30 2023 +0300
Merge branch 'master' into AG-21462-imp-safebrowsing-parental
commit 0e61edadeff34f6305e941c1db94575c82f238d9
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 14:51:37 2023 +0300
filtering: imp tests
commit 994255514cc0f67dfe33d5a0892432e8924d1e36
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:13:19 2023 +0300
filtering: fix typo
commit 96d1069573171538333330d6af94ef0f4208a9c4
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 27 11:00:18 2023 +0300
filtering: imp code more
commit c2a5620b04c4a529eea69983f1520cd2bc82ea9b
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 19:13:26 2023 +0300
all: add todo
commit e5dcc2e9701f8bccfde6ef8c01a4a2e7eb31599e
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 26 14:36:08 2023 +0300
all: imp code more
commit b6e734ccbeda82669023f6578481260b7c1f7161
Author: Stanislav Chzhen <[email protected]>
Date: Tue Apr 25 15:01:56 2023 +0300
filtering: imp code
commit 530648dadf836c1a4bd9917e0d3b47256fa8ff52
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 20:06:36 2023 +0300
all: imp code
commit 49fa6e587052a40bb431fea457701ee860493527
Author: Stanislav Chzhen <[email protected]>
Date: Mon Apr 24 14:57:19 2023 +0300
all: rm safe browsing ctx
commit bbcb66cb03e18fa875e3c33cf16295892739e507
Author: Stanislav Chzhen <[email protected]>
Date: Fri Apr 21 17:54:18 2023 +0300
filtering: add cache item
commit cb7c9fffe8c4ff5e7a21ca912c223c799f61385f
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 18:43:02 2023 +0300
filtering: fix hashes
commit 153fec46270212af03f3631bfb42c5d680c4e142
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 16:15:15 2023 +0300
filtering: add test cases
commit 09372f92bbb1fc082f1b1283594ee589100209c5
Author: Stanislav Chzhen <[email protected]>
Date: Thu Apr 20 15:38:05 2023 +0300
filtering: imp code
commit 466bc26d524ea6d1c3efb33692a7785d39e491ca
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 18:38:40 2023 +0300
filtering: add tests
commit 24365ecf8c60512fdac65833ee603c80864ae018
Author: Stanislav Chzhen <[email protected]>
Date: Wed Apr 19 11:38:57 2023 +0300
filtering: add hashprefix | https://github.com/AdguardTeam/AdGuardHome/commit/381f2f651d1a94d29bf534185e531b05a755f16c | internal/filtering/safebrowsing.go |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.