docstring_tokens
stringlengths
18
16.9k
code_tokens
stringlengths
75
1.81M
html_url
stringlengths
74
116
file_name
stringlengths
3
311
keep keep keep keep replace replace replace replace replace replace replace keep keep keep keep keep
<mask> filterName = t('custom_filter_rules'); <mask> } else { <mask> const filterItem = Object.keys(filters).filter(key => filters[key].id === filterId)[0]; <mask> <mask> if (typeof filterItem !== 'undefined' && typeof filters[filterItem] !== 'undefined') { <mask> filterName = filters[filterItem].name; <mask> } <mask> <mask> if (!filterName) { <mask> filterName = t('unknown_filter', { filterId }); <mask> } <mask> } <mask> <mask> return ( <mask> <div className="logs__row logs__row--column"> <mask> <div className="logs__text-wrap"> </s> Merge: + client: show filter name for blocked items in the query log Closes #993 Squashed commit of the following: commit 4c5e17226c6efa8a7847a8c565c491a7bae2db59 Author: Ildar Kamalov <[email protected]> Date: Wed Jan 29 12:21:40 2020 +0300 - client: use constant commit 818c07d1cfb210965a6413dc8370fc8867979c7b Author: Ildar Kamalov <[email protected]> Date: Wed Jan 29 12:18:31 2020 +0300 - client: fix filter find commit 1f9132151c843dacbf26f814faeeea3cfdff9b73 Author: Ildar Kamalov <[email protected]> Date: Tue Jan 28 15:52:29 2020 +0300 + client: show filter name for blocked items in the query log </s> remove if (filterId === 0) { filterName = t('custom_filter_rules'); } else { const filterItem = Object.keys(filters).filter(key => filters[key].id === filterId)[0]; </s> add if (isBlockedCnameIp) { const normalizedAnswer = this.normalizeResponse(originalAnswer); </s> remove const normalizedAnswer = originalAnswer && this.normalizeResponse(originalAnswer); let filterName = ''; </s> add const filterName = this.getFilterName(filters, filterId, t); </s> remove {originalAnswer && ( <span className="logs__text"> <Trans>blocked_by_response</Trans> </span> )} {!originalAnswer && (isFiltered || isBlockedService) && ( </s> add {(isFiltered || isBlockedService) && !isBlackList && ( </s> remove const filterKey = reason.replace(FILTERED_REASON, ''); const parsedFilteredReason = t('query_log_filtered', { filter: filterKey }); </s> add const isBlackList = this.checkBlackList(reason); </s> remove const isBlockedService = reason === FILTERED_STATUS.FILTERED_BLOCKED_SERVICE; </s> add const isBlockedService = this.checkBlockedService(reason); const isBlockedCnameIp = originalAnswer; const filterKey = reason.replace(FILTERED_REASON, ''); const parsedFilteredReason = t('query_log_filtered', { filter: filterKey }); </s> remove import { SERVICES, FILTERED_STATUS, TABLE_DEFAULT_PAGE_SIZE } from '../../helpers/constants'; </s> add import { SERVICES, FILTERED_STATUS, TABLE_DEFAULT_PAGE_SIZE, CUSTOM_FILTERING_RULES_ID } from '../../helpers/constants';
https://github.com/AdguardTeam/AdGuardHome/commit/5e9c21b0a7917d0b89fe25cbf8b5790029ea2ac6
client/src/components/Logs/index.js
keep keep keep keep replace replace replace replace replace replace keep keep keep keep keep
<mask> <mask> return ( <mask> <div className="logs__row logs__row--column"> <mask> <div className="logs__text-wrap"> <mask> {originalAnswer && ( <mask> <span className="logs__text"> <mask> <Trans>blocked_by_response</Trans> <mask> </span> <mask> )} <mask> {!originalAnswer && (isFiltered || isBlockedService) && ( <mask> <span className="logs__text" title={parsedFilteredReason}> <mask> {parsedFilteredReason} <mask> </span> <mask> )} <mask> {isBlockedService </s> Merge: + client: show filter name for blocked items in the query log Closes #993 Squashed commit of the following: commit 4c5e17226c6efa8a7847a8c565c491a7bae2db59 Author: Ildar Kamalov <[email protected]> Date: Wed Jan 29 12:21:40 2020 +0300 - client: use constant commit 818c07d1cfb210965a6413dc8370fc8867979c7b Author: Ildar Kamalov <[email protected]> Date: Wed Jan 29 12:18:31 2020 +0300 - client: fix filter find commit 1f9132151c843dacbf26f814faeeea3cfdff9b73 Author: Ildar Kamalov <[email protected]> Date: Tue Jan 28 15:52:29 2020 +0300 + client: show filter name for blocked items in the query log </s> add {isBlackList && ( <span className="logs__text"> <Trans values={{ filter: filterName }}> query_log_filtered </Trans> </span> )} </s> remove if (typeof filterItem !== 'undefined' && typeof filters[filterItem] !== 'undefined') { filterName = filters[filterItem].name; } if (!filterName) { filterName = t('unknown_filter', { filterId }); } </s> add return ( <div className="logs__row logs__row--column"> <div className="logs__text-wrap"> <span className="logs__text"> <Trans>blocked_by_response</Trans> </span> </div> <div className="logs__list-wrap"> {this.renderResponseList(normalizedAnswer, status)} </div> </div> ); </s> remove {originalAnswer ? this.renderResponseList(normalizedAnswer, status) : this.renderResponseList(responses, status) } </s> add {this.renderResponseList(responses, status)} </s> remove if (filterId === 0) { filterName = t('custom_filter_rules'); } else { const filterItem = Object.keys(filters).filter(key => filters[key].id === filterId)[0]; </s> add if (isBlockedCnameIp) { const normalizedAnswer = this.normalizeResponse(originalAnswer); </s> remove const normalizedAnswer = originalAnswer && this.normalizeResponse(originalAnswer); let filterName = ''; </s> add const filterName = this.getFilterName(filters, filterId, t); </s> remove const isBlockedService = reason === FILTERED_STATUS.FILTERED_BLOCKED_SERVICE; </s> add const isBlockedService = this.checkBlockedService(reason); const isBlockedCnameIp = originalAnswer; const filterKey = reason.replace(FILTERED_REASON, ''); const parsedFilteredReason = t('query_log_filtered', { filter: filterKey });
https://github.com/AdguardTeam/AdGuardHome/commit/5e9c21b0a7917d0b89fe25cbf8b5790029ea2ac6
client/src/components/Logs/index.js
keep keep keep add keep keep keep keep keep keep
<mask> <span className="logs__text" title={parsedFilteredReason}> <mask> {parsedFilteredReason} <mask> </span> <mask> )} <mask> {isBlockedService <mask> ? this.renderTooltip(isFiltered, '', '', serviceName) <mask> : this.renderTooltip(isFiltered, rule, filterName)} <mask> {isRewrite && ( <mask> <strong> <mask> <Trans>rewrite_applied</Trans> </s> Merge: + client: show filter name for blocked items in the query log Closes #993 Squashed commit of the following: commit 4c5e17226c6efa8a7847a8c565c491a7bae2db59 Author: Ildar Kamalov <[email protected]> Date: Wed Jan 29 12:21:40 2020 +0300 - client: use constant commit 818c07d1cfb210965a6413dc8370fc8867979c7b Author: Ildar Kamalov <[email protected]> Date: Wed Jan 29 12:18:31 2020 +0300 - client: fix filter find commit 1f9132151c843dacbf26f814faeeea3cfdff9b73 Author: Ildar Kamalov <[email protected]> Date: Tue Jan 28 15:52:29 2020 +0300 + client: show filter name for blocked items in the query log </s> remove {originalAnswer && ( <span className="logs__text"> <Trans>blocked_by_response</Trans> </span> )} {!originalAnswer && (isFiltered || isBlockedService) && ( </s> add {(isFiltered || isBlockedService) && !isBlackList && ( </s> remove {originalAnswer ? this.renderResponseList(normalizedAnswer, status) : this.renderResponseList(responses, status) } </s> add {this.renderResponseList(responses, status)} </s> remove if (typeof filterItem !== 'undefined' && typeof filters[filterItem] !== 'undefined') { filterName = filters[filterItem].name; } if (!filterName) { filterName = t('unknown_filter', { filterId }); } </s> add return ( <div className="logs__row logs__row--column"> <div className="logs__text-wrap"> <span className="logs__text"> <Trans>blocked_by_response</Trans> </span> </div> <div className="logs__list-wrap"> {this.renderResponseList(normalizedAnswer, status)} </div> </div> ); </s> add checkBlackList = reason => reason === FILTERED_STATUS.FILTERED_BLACK_LIST; checkBlockedService = reason => reason === FILTERED_STATUS.FILTERED_BLOCKED_SERVICE; </s> remove if (filterId === 0) { filterName = t('custom_filter_rules'); } else { const filterItem = Object.keys(filters).filter(key => filters[key].id === filterId)[0]; </s> add if (isBlockedCnameIp) { const normalizedAnswer = this.normalizeResponse(originalAnswer); </s> remove const normalizedAnswer = originalAnswer && this.normalizeResponse(originalAnswer); let filterName = ''; </s> add const filterName = this.getFilterName(filters, filterId, t);
https://github.com/AdguardTeam/AdGuardHome/commit/5e9c21b0a7917d0b89fe25cbf8b5790029ea2ac6
client/src/components/Logs/index.js
keep keep keep keep replace replace replace replace keep keep keep keep keep
<mask> </strong> <mask> )} <mask> </div> <mask> <div className="logs__list-wrap"> <mask> {originalAnswer <mask> ? this.renderResponseList(normalizedAnswer, status) <mask> : this.renderResponseList(responses, status) <mask> } <mask> {isWhiteList && this.renderTooltip(isWhiteList, rule, filterName)} <mask> </div> <mask> </div> <mask> ); <mask> }; </s> Merge: + client: show filter name for blocked items in the query log Closes #993 Squashed commit of the following: commit 4c5e17226c6efa8a7847a8c565c491a7bae2db59 Author: Ildar Kamalov <[email protected]> Date: Wed Jan 29 12:21:40 2020 +0300 - client: use constant commit 818c07d1cfb210965a6413dc8370fc8867979c7b Author: Ildar Kamalov <[email protected]> Date: Wed Jan 29 12:18:31 2020 +0300 - client: fix filter find commit 1f9132151c843dacbf26f814faeeea3cfdff9b73 Author: Ildar Kamalov <[email protected]> Date: Tue Jan 28 15:52:29 2020 +0300 + client: show filter name for blocked items in the query log </s> remove if (typeof filterItem !== 'undefined' && typeof filters[filterItem] !== 'undefined') { filterName = filters[filterItem].name; } if (!filterName) { filterName = t('unknown_filter', { filterId }); } </s> add return ( <div className="logs__row logs__row--column"> <div className="logs__text-wrap"> <span className="logs__text"> <Trans>blocked_by_response</Trans> </span> </div> <div className="logs__list-wrap"> {this.renderResponseList(normalizedAnswer, status)} </div> </div> ); </s> add {isBlackList && ( <span className="logs__text"> <Trans values={{ filter: filterName }}> query_log_filtered </Trans> </span> )} </s> remove {originalAnswer && ( <span className="logs__text"> <Trans>blocked_by_response</Trans> </span> )} {!originalAnswer && (isFiltered || isBlockedService) && ( </s> add {(isFiltered || isBlockedService) && !isBlackList && ( </s> add checkBlackList = reason => reason === FILTERED_STATUS.FILTERED_BLACK_LIST; checkBlockedService = reason => reason === FILTERED_STATUS.FILTERED_BLOCKED_SERVICE; </s> remove if (filterId === 0) { filterName = t('custom_filter_rules'); } else { const filterItem = Object.keys(filters).filter(key => filters[key].id === filterId)[0]; </s> add if (isBlockedCnameIp) { const normalizedAnswer = this.normalizeResponse(originalAnswer); </s> remove const normalizedAnswer = originalAnswer && this.normalizeResponse(originalAnswer); let filterName = ''; </s> add const filterName = this.getFilterName(filters, filterId, t);
https://github.com/AdguardTeam/AdGuardHome/commit/5e9c21b0a7917d0b89fe25cbf8b5790029ea2ac6
client/src/components/Logs/index.js
keep add keep keep keep keep keep
<mask> os.Exit(1) <mask> } <mask> } <mask> <mask> if (runtime.GOOS == "linux" || runtime.GOOS == "darwin") && <mask> config.RlimitNoFile != 0 { <mask> setRlimit(config.RlimitNoFile) </s> + app: add --check-config command-line argument </s> add {"check-config", "", "Check configuration and exit", nil, func() { o.checkConfig = true }}, </s> add checkConfig bool // Check configuration and exit
https://github.com/AdguardTeam/AdGuardHome/commit/5fd35254a8f60cd311d8239cbc3f94122b252275
app.go
keep add keep keep keep keep
<mask> logFile string // Path to the log file. If empty, write to stdout. If "syslog", writes to syslog <mask> pidFile string // File name to save PID to <mask> <mask> // service control action (see service.ControlAction array + "status" command) <mask> serviceControlAction string <mask> </s> + app: add --check-config command-line argument </s> add {"check-config", "", "Check configuration and exit", nil, func() { o.checkConfig = true }}, </s> add if args.checkConfig { log.Info("Configuration file is OK") os.Exit(0) }
https://github.com/AdguardTeam/AdGuardHome/commit/5fd35254a8f60cd311d8239cbc3f94122b252275
app.go
keep keep keep add keep keep keep keep keep keep
<mask> {"logfile", "l", "path to the log file. If empty, writes to stdout, if 'syslog' -- system log", func(value string) { <mask> o.logFile = value <mask> }, nil}, <mask> {"pidfile", "", "File name to save PID to", func(value string) { o.pidFile = value }, nil}, <mask> {"verbose", "v", "enable verbose output", nil, func() { o.verbose = true }}, <mask> {"help", "", "print this help", nil, func() { <mask> printHelp() <mask> os.Exit(64) <mask> }}, <mask> } </s> + app: add --check-config command-line argument </s> add checkConfig bool // Check configuration and exit </s> add if args.checkConfig { log.Info("Configuration file is OK") os.Exit(0) }
https://github.com/AdguardTeam/AdGuardHome/commit/5fd35254a8f60cd311d8239cbc3f94122b252275
app.go
keep keep keep keep replace
<mask> <mask> VOLUME /data <mask> <mask> ENTRYPOINT ["/AdGuardHome"] <mask> CMD ["-o", "0.0.0.0"] </s> We'd better keep -h for host </s> remove CMD ["-o", "0.0.0.0"] </s> add </s> add CMD ["-h", "0.0.0.0"] </s> remove if v == "--"+opt.longName || v == "-"+opt.shortName { </s> add if v == "--"+opt.longName || (opt.shortName != "" && v == "-"+opt.shortName) { </s> remove fmt.Printf(" -%s, %-30s %s\n", opt.shortName, "--"+opt.longName, opt.description) </s> add if opt.shortName != "" { fmt.Printf(" -%s, %-30s %s\n", opt.shortName, "--"+opt.longName, opt.description) } else { fmt.Printf(" %-34s %s\n", "--"+opt.longName, opt.description) } </s> remove {"help", "h", "print this help", nil, func() { </s> add {"help", "", "print this help", nil, func() { </s> remove {"host", "o", "host address to bind HTTP server on", func(value string) { o.bindHost = value }, nil}, </s> add {"host", "h", "host address to bind HTTP server on", func(value string) { o.bindHost = value }, nil},
https://github.com/AdguardTeam/AdGuardHome/commit/5fed5c07184f12ec50bf26c95290de0fa697c1bc
Dockerfile
keep keep keep add
<mask> VOLUME /data <mask> <mask> ENTRYPOINT ["/AdGuardHome"] <mask> CMD ["-h", "0.0.0.0"] </s> We'd better keep -h for host </s> remove CMD ["-o", "0.0.0.0"] </s> add </s> remove CMD ["-o", "0.0.0.0"] </s> add </s> remove if v == "--"+opt.longName || v == "-"+opt.shortName { </s> add if v == "--"+opt.longName || (opt.shortName != "" && v == "-"+opt.shortName) { </s> remove fmt.Printf(" -%s, %-30s %s\n", opt.shortName, "--"+opt.longName, opt.description) </s> add if opt.shortName != "" { fmt.Printf(" -%s, %-30s %s\n", opt.shortName, "--"+opt.longName, opt.description) } else { fmt.Printf(" %-34s %s\n", "--"+opt.longName, opt.description) } </s> remove {"help", "h", "print this help", nil, func() { </s> add {"help", "", "print this help", nil, func() { </s> remove {"host", "o", "host address to bind HTTP server on", func(value string) { o.bindHost = value }, nil}, </s> add {"host", "h", "host address to bind HTTP server on", func(value string) { o.bindHost = value }, nil},
https://github.com/AdguardTeam/AdGuardHome/commit/5fed5c07184f12ec50bf26c95290de0fa697c1bc
Dockerfile
keep keep keep keep replace
<mask> <mask> VOLUME /data <mask> <mask> ENTRYPOINT ["/AdGuardHome"] <mask> CMD ["-o", "0.0.0.0"] </s> We'd better keep -h for host
https://github.com/AdguardTeam/AdGuardHome/commit/5fed5c07184f12ec50bf26c95290de0fa697c1bc
Dockerfile.travis
keep keep keep keep replace keep keep keep keep keep
<mask> callbackWithValue func(value string) <mask> callbackNoValue func() <mask> }{ <mask> {"config", "c", "path to config file", func(value string) { o.configFilename = value }, nil}, <mask> {"host", "o", "host address to bind HTTP server on", func(value string) { o.bindHost = value }, nil}, <mask> {"port", "p", "port to serve HTTP pages on", func(value string) { <mask> v, err := strconv.Atoi(value) <mask> if err != nil { <mask> panic("Got port that is not a number") <mask> } </s> We'd better keep -h for host </s> remove {"help", "h", "print this help", nil, func() { </s> add {"help", "", "print this help", nil, func() { </s> remove if v == "--"+opt.longName || v == "-"+opt.shortName { </s> add if v == "--"+opt.longName || (opt.shortName != "" && v == "-"+opt.shortName) { </s> remove fmt.Printf(" -%s, %-30s %s\n", opt.shortName, "--"+opt.longName, opt.description) </s> add if opt.shortName != "" { fmt.Printf(" -%s, %-30s %s\n", opt.shortName, "--"+opt.longName, opt.description) } else { fmt.Printf(" %-34s %s\n", "--"+opt.longName, opt.description) } </s> remove CMD ["-o", "0.0.0.0"] </s> add </s> add CMD ["-h", "0.0.0.0"] </s> remove CMD ["-o", "0.0.0.0"] </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/5fed5c07184f12ec50bf26c95290de0fa697c1bc
app.go
keep keep keep keep replace keep keep keep keep keep
<mask> {"logfile", "l", "path to the log file. If empty, writes to stdout, if 'syslog' -- system log", func(value string) { <mask> o.logFile = value <mask> }, nil}, <mask> {"verbose", "v", "enable verbose output", nil, func() { o.verbose = true }}, <mask> {"help", "h", "print this help", nil, func() { <mask> printHelp() <mask> os.Exit(64) <mask> }}, <mask> } <mask> printHelp = func() { </s> We'd better keep -h for host </s> remove {"host", "o", "host address to bind HTTP server on", func(value string) { o.bindHost = value }, nil}, </s> add {"host", "h", "host address to bind HTTP server on", func(value string) { o.bindHost = value }, nil}, </s> remove if v == "--"+opt.longName || v == "-"+opt.shortName { </s> add if v == "--"+opt.longName || (opt.shortName != "" && v == "-"+opt.shortName) { </s> remove fmt.Printf(" -%s, %-30s %s\n", opt.shortName, "--"+opt.longName, opt.description) </s> add if opt.shortName != "" { fmt.Printf(" -%s, %-30s %s\n", opt.shortName, "--"+opt.longName, opt.description) } else { fmt.Printf(" %-34s %s\n", "--"+opt.longName, opt.description) } </s> remove CMD ["-o", "0.0.0.0"] </s> add </s> add CMD ["-h", "0.0.0.0"] </s> remove CMD ["-o", "0.0.0.0"] </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/5fed5c07184f12ec50bf26c95290de0fa697c1bc
app.go
keep keep keep keep replace keep keep keep keep keep
<mask> fmt.Printf("Usage:\n\n") <mask> fmt.Printf("%s [options]\n\n", os.Args[0]) <mask> fmt.Printf("Options:\n") <mask> for _, opt := range opts { <mask> fmt.Printf(" -%s, %-30s %s\n", opt.shortName, "--"+opt.longName, opt.description) <mask> } <mask> } <mask> for i := 1; i < len(os.Args); i++ { <mask> v := os.Args[i] <mask> knownParam := false </s> We'd better keep -h for host </s> remove if v == "--"+opt.longName || v == "-"+opt.shortName { </s> add if v == "--"+opt.longName || (opt.shortName != "" && v == "-"+opt.shortName) { </s> remove {"host", "o", "host address to bind HTTP server on", func(value string) { o.bindHost = value }, nil}, </s> add {"host", "h", "host address to bind HTTP server on", func(value string) { o.bindHost = value }, nil}, </s> remove {"help", "h", "print this help", nil, func() { </s> add {"help", "", "print this help", nil, func() { </s> remove CMD ["-o", "0.0.0.0"] </s> add </s> add CMD ["-h", "0.0.0.0"] </s> remove CMD ["-o", "0.0.0.0"] </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/5fed5c07184f12ec50bf26c95290de0fa697c1bc
app.go
keep keep keep keep replace keep keep keep keep keep
<mask> for i := 1; i < len(os.Args); i++ { <mask> v := os.Args[i] <mask> knownParam := false <mask> for _, opt := range opts { <mask> if v == "--"+opt.longName || v == "-"+opt.shortName { <mask> if opt.callbackWithValue != nil { <mask> if i+1 >= len(os.Args) { <mask> log.Printf("ERROR: Got %s without argument\n", v) <mask> os.Exit(64) <mask> } </s> We'd better keep -h for host </s> remove fmt.Printf(" -%s, %-30s %s\n", opt.shortName, "--"+opt.longName, opt.description) </s> add if opt.shortName != "" { fmt.Printf(" -%s, %-30s %s\n", opt.shortName, "--"+opt.longName, opt.description) } else { fmt.Printf(" %-34s %s\n", "--"+opt.longName, opt.description) } </s> remove {"host", "o", "host address to bind HTTP server on", func(value string) { o.bindHost = value }, nil}, </s> add {"host", "h", "host address to bind HTTP server on", func(value string) { o.bindHost = value }, nil}, </s> remove {"help", "h", "print this help", nil, func() { </s> add {"help", "", "print this help", nil, func() { </s> remove CMD ["-o", "0.0.0.0"] </s> add </s> add CMD ["-h", "0.0.0.0"] </s> remove CMD ["-o", "0.0.0.0"] </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/5fed5c07184f12ec50bf26c95290de0fa697c1bc
app.go
keep keep add keep keep keep keep
<mask> "unblock_btn": "Unblock", <mask> "block_btn": "Block", <mask> "time_table_header": "Time", <mask> "domain_name_table_header": "Domain name", <mask> "type_table_header": "Type", <mask> "response_table_header": "Response", <mask> "client_table_header": "Client", </s> Fix missing translate key when added new filter url </s> remove <Trans>Url added successfully</Trans> </s> add <Trans>url_added_successfully</Trans> </s> remove "filter_label": "B\u1ed9 l\u1ecdc" </s> add "filter_label": "B\u1ed9 l\u1ecdc", "url_added_successfully": "Th\u00eam b\u1ed9 l\u1ecdc th\u00e0nh c\u00f4ng"
https://github.com/AdguardTeam/AdGuardHome/commit/607089cd2531e7b30f87663d4fb438d49350c1c7
client/src/__locales/en.json
keep keep keep keep replace keep
<mask> "source_label": "Ngu\u1ed3n", <mask> "found_in_known_domain_db": "T\u00ecm th\u1ea5y trong c\u01a1 s\u1edf d\u1eef li\u1ec7u t\u00ean mi\u1ec1n", <mask> "category_label": "Th\u1ec3 lo\u1ea1i", <mask> "rule_label": "Quy t\u1eafc", <mask> "filter_label": "B\u1ed9 l\u1ecdc" <mask> } </s> Fix missing translate key when added new filter url </s> remove <Trans>Url added successfully</Trans> </s> add <Trans>url_added_successfully</Trans> </s> add "url_added_successfully": "Url added successfully",
https://github.com/AdguardTeam/AdGuardHome/commit/607089cd2531e7b30f87663d4fb438d49350c1c7
client/src/__locales/vi.json
keep keep keep keep replace keep keep keep keep keep
<mask> ); <mask> } <mask> return ( <mask> <div className="description"> <mask> <Trans>Url added successfully</Trans> <mask> </div> <mask> ); <mask> }; <mask> <mask> const isValidForSubmit = !(url.length > 0 && isUrlValid && name.length > 0); </s> Fix missing translate key when added new filter url </s> add "url_added_successfully": "Url added successfully", </s> remove "filter_label": "B\u1ed9 l\u1ecdc" </s> add "filter_label": "B\u1ed9 l\u1ecdc", "url_added_successfully": "Th\u00eam b\u1ed9 l\u1ecdc th\u00e0nh c\u00f4ng"
https://github.com/AdguardTeam/AdGuardHome/commit/607089cd2531e7b30f87663d4fb438d49350c1c7
client/src/components/ui/Modal.js
keep add keep keep keep keep keep keep
<mask> return wrapErrPrint(err, "Couldn't start listening socket on 0.0.0.0:67") <mask> } <mask> <mask> s.conn = c <mask> <mask> go func() { <mask> // operate on c instead of c.conn because c.conn can change over time <mask> err := dhcp4.Serve(c, s) </s> * dhcp: refactor; log client's HW addr </s> remove // find a lease, but don't update lease time log.Tracef("Got from client: Discover") lease, err := s.reserveLease(p) if err != nil { log.Tracef("Couldn't find free lease: %s", err) // couldn't find lease, don't respond return nil } reply := dhcp4.ReplyPacket(p, dhcp4.Offer, s.ipnet.IP, lease.IP, s.leaseTime, s.leaseOptions.SelectOrderOrAll(options[dhcp4.OptionParameterRequestList])) log.Tracef("Replying with offer: offered IP %v for %v with options %+v", lease.IP, s.leaseTime, reply.ParseOptions()) return reply </s> add return s.handleDiscover(p, options) </s> add func (s *Server) handleDiscover(p dhcp4.Packet, options dhcp4.Options) dhcp4.Packet { // find a lease, but don't update lease time lease, err := s.reserveLease(p) if err != nil { log.Tracef("Couldn't find free lease: %s", err) // couldn't find lease, don't respond return nil } opt := s.leaseOptions.SelectOrderOrAll(options[dhcp4.OptionParameterRequestList]) reply := dhcp4.ReplyPacket(p, dhcp4.Offer, s.ipnet.IP, lease.IP, s.leaseTime, opt) log.Tracef("Replying with offer: offered IP %v for %v with options %+v", lease.IP, s.leaseTime, reply.ParseOptions()) return reply } </s> remove // Leases returns the list of current DHCP leases </s> add // Leases returns the list of current DHCP leases (thread-safe) </s> remove foundHWaddr := s.getIPpool(newIP) </s> add foundHWaddr := s.findReservedHWaddr(newIP) </s> remove return dhcp4.ReplyPacket(p, dhcp4.ACK, s.ipnet.IP, lease.IP, s.leaseTime, s.leaseOptions.SelectOrderOrAll(options[dhcp4.OptionParameterRequestList])) </s> add opt := s.leaseOptions.SelectOrderOrAll(options[dhcp4.OptionParameterRequestList]) return dhcp4.ReplyPacket(p, dhcp4.ACK, s.ipnet.IP, lease.IP, s.leaseTime, opt) </s> remove log.Tracef("IP pool:") for ip, hwaddr := range s.IPpool { log.Tracef("IP pool entry %s -> %s", net.IPv4(ip[0], ip[1], ip[2], ip[3]), hwaddr) } </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/60fa3b2e95e5fc111884f13c8bfa465f030a0b40
dhcpd/dhcpd.go
keep keep keep keep replace keep keep keep keep keep
<mask> // go from start to end, find unreserved IP <mask> var foundIP net.IP <mask> for i := 0; i < dhcp4.IPRange(s.leaseStart, s.leaseStop); i++ { <mask> newIP := dhcp4.IPAdd(s.leaseStart, i) <mask> foundHWaddr := s.getIPpool(newIP) <mask> log.Tracef("tried IP %v, got hwaddr %v", newIP, foundHWaddr) <mask> if foundHWaddr != nil && len(foundHWaddr) != 0 { <mask> // if !bytes.Equal(foundHWaddr, hwaddr) { <mask> // log.Tracef("SHOULD NOT HAPPEN: hwaddr in IP pool %s is not equal to hwaddr in lease %s", foundHWaddr, hwaddr) <mask> // } </s> * dhcp: refactor; log client's HW addr </s> remove hwaddr := s.getIPpool(reqIP) </s> add hwaddr := s.findReservedHWaddr(reqIP) </s> remove log.Tracef("IP pool:") for ip, hwaddr := range s.IPpool { log.Tracef("IP pool entry %s -> %s", net.IPv4(ip[0], ip[1], ip[2], ip[3]), hwaddr) } </s> add </s> add func (s *Server) handleDiscover(p dhcp4.Packet, options dhcp4.Options) dhcp4.Packet { // find a lease, but don't update lease time lease, err := s.reserveLease(p) if err != nil { log.Tracef("Couldn't find free lease: %s", err) // couldn't find lease, don't respond return nil } opt := s.leaseOptions.SelectOrderOrAll(options[dhcp4.OptionParameterRequestList]) reply := dhcp4.ReplyPacket(p, dhcp4.Offer, s.ipnet.IP, lease.IP, s.leaseTime, opt) log.Tracef("Replying with offer: offered IP %v for %v with options %+v", lease.IP, s.leaseTime, reply.ParseOptions()) return reply } </s> remove log.Tracef("Got from client: Request") if server, ok := options[dhcp4.OptionServerIdentifier]; ok && !net.IP(server).Equal(s.ipnet.IP) { </s> add server := options[dhcp4.OptionServerIdentifier] if server != nil && !net.IP(server).Equal(s.ipnet.IP) { </s> remove return dhcp4.ReplyPacket(p, dhcp4.ACK, s.ipnet.IP, lease.IP, s.leaseTime, s.leaseOptions.SelectOrderOrAll(options[dhcp4.OptionParameterRequestList])) </s> add opt := s.leaseOptions.SelectOrderOrAll(options[dhcp4.OptionParameterRequestList]) return dhcp4.ReplyPacket(p, dhcp4.ACK, s.ipnet.IP, lease.IP, s.leaseTime, opt) </s> remove // find a lease, but don't update lease time log.Tracef("Got from client: Discover") lease, err := s.reserveLease(p) if err != nil { log.Tracef("Couldn't find free lease: %s", err) // couldn't find lease, don't respond return nil } reply := dhcp4.ReplyPacket(p, dhcp4.Offer, s.ipnet.IP, lease.IP, s.leaseTime, s.leaseOptions.SelectOrderOrAll(options[dhcp4.OptionParameterRequestList])) log.Tracef("Replying with offer: offered IP %v for %v with options %+v", lease.IP, s.leaseTime, reply.ParseOptions()) return reply </s> add return s.handleDiscover(p, options)
https://github.com/AdguardTeam/AdGuardHome/commit/60fa3b2e95e5fc111884f13c8bfa465f030a0b40
dhcpd/dhcpd.go
keep keep keep keep replace keep keep keep keep keep
<mask> <mask> return foundIP, nil <mask> } <mask> <mask> func (s *Server) getIPpool(ip net.IP) net.HardwareAddr { <mask> rawIP := []byte(ip) <mask> IP4 := [4]byte{rawIP[0], rawIP[1], rawIP[2], rawIP[3]} <mask> return s.IPpool[IP4] <mask> } <mask> </s> * dhcp: refactor; log client's HW addr </s> add func (s *Server) handleDiscover(p dhcp4.Packet, options dhcp4.Options) dhcp4.Packet { // find a lease, but don't update lease time lease, err := s.reserveLease(p) if err != nil { log.Tracef("Couldn't find free lease: %s", err) // couldn't find lease, don't respond return nil } opt := s.leaseOptions.SelectOrderOrAll(options[dhcp4.OptionParameterRequestList]) reply := dhcp4.ReplyPacket(p, dhcp4.Offer, s.ipnet.IP, lease.IP, s.leaseTime, opt) log.Tracef("Replying with offer: offered IP %v for %v with options %+v", lease.IP, s.leaseTime, reply.ParseOptions()) return reply } </s> remove log.Tracef("Got from client: Request") if server, ok := options[dhcp4.OptionServerIdentifier]; ok && !net.IP(server).Equal(s.ipnet.IP) { </s> add server := options[dhcp4.OptionServerIdentifier] if server != nil && !net.IP(server).Equal(s.ipnet.IP) { </s> remove // Leases returns the list of current DHCP leases </s> add // Leases returns the list of current DHCP leases (thread-safe) </s> remove log.Tracef("Got %v message", msgType) </s> add log.Tracef("Message from client %s: %d", p.CHAddr(), msgType) </s> remove // find a lease, but don't update lease time log.Tracef("Got from client: Discover") lease, err := s.reserveLease(p) if err != nil { log.Tracef("Couldn't find free lease: %s", err) // couldn't find lease, don't respond return nil } reply := dhcp4.ReplyPacket(p, dhcp4.Offer, s.ipnet.IP, lease.IP, s.leaseTime, s.leaseOptions.SelectOrderOrAll(options[dhcp4.OptionParameterRequestList])) log.Tracef("Replying with offer: offered IP %v for %v with options %+v", lease.IP, s.leaseTime, reply.ParseOptions()) return reply </s> add return s.handleDiscover(p, options) </s> add log.Info("DHCP: listening on 0.0.0.0:67")
https://github.com/AdguardTeam/AdGuardHome/commit/60fa3b2e95e5fc111884f13c8bfa465f030a0b40
dhcpd/dhcpd.go
keep keep keep keep replace keep keep keep keep replace replace replace replace keep keep keep keep
<mask> } <mask> <mask> // ServeDHCP handles an incoming DHCP request <mask> func (s *Server) ServeDHCP(p dhcp4.Packet, msgType dhcp4.MessageType, options dhcp4.Options) dhcp4.Packet { <mask> log.Tracef("Got %v message", msgType) <mask> log.Tracef("Leases:") <mask> for i, lease := range s.leases { <mask> log.Tracef("Lease #%d: hwaddr %s, ip %s, expiry %s", i, lease.HWAddr, lease.IP, lease.Expiry) <mask> } <mask> log.Tracef("IP pool:") <mask> for ip, hwaddr := range s.IPpool { <mask> log.Tracef("IP pool entry %s -> %s", net.IPv4(ip[0], ip[1], ip[2], ip[3]), hwaddr) <mask> } <mask> <mask> switch msgType { <mask> case dhcp4.Discover: // Broadcast Packet From Client - Can I have an IP? <mask> // find a lease, but don't update lease time </s> * dhcp: refactor; log client's HW addr </s> remove // find a lease, but don't update lease time log.Tracef("Got from client: Discover") lease, err := s.reserveLease(p) if err != nil { log.Tracef("Couldn't find free lease: %s", err) // couldn't find lease, don't respond return nil } reply := dhcp4.ReplyPacket(p, dhcp4.Offer, s.ipnet.IP, lease.IP, s.leaseTime, s.leaseOptions.SelectOrderOrAll(options[dhcp4.OptionParameterRequestList])) log.Tracef("Replying with offer: offered IP %v for %v with options %+v", lease.IP, s.leaseTime, reply.ParseOptions()) return reply </s> add return s.handleDiscover(p, options) </s> add func (s *Server) handleDiscover(p dhcp4.Packet, options dhcp4.Options) dhcp4.Packet { // find a lease, but don't update lease time lease, err := s.reserveLease(p) if err != nil { log.Tracef("Couldn't find free lease: %s", err) // couldn't find lease, don't respond return nil } opt := s.leaseOptions.SelectOrderOrAll(options[dhcp4.OptionParameterRequestList]) reply := dhcp4.ReplyPacket(p, dhcp4.Offer, s.ipnet.IP, lease.IP, s.leaseTime, opt) log.Tracef("Replying with offer: offered IP %v for %v with options %+v", lease.IP, s.leaseTime, reply.ParseOptions()) return reply } </s> remove foundHWaddr := s.getIPpool(newIP) </s> add foundHWaddr := s.findReservedHWaddr(newIP) </s> remove log.Tracef("Got from client: Request") if server, ok := options[dhcp4.OptionServerIdentifier]; ok && !net.IP(server).Equal(s.ipnet.IP) { </s> add server := options[dhcp4.OptionServerIdentifier] if server != nil && !net.IP(server).Equal(s.ipnet.IP) { </s> remove hwaddr := s.getIPpool(reqIP) </s> add hwaddr := s.findReservedHWaddr(reqIP)
https://github.com/AdguardTeam/AdGuardHome/commit/60fa3b2e95e5fc111884f13c8bfa465f030a0b40
dhcpd/dhcpd.go
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace keep keep keep keep keep
<mask> } <mask> <mask> switch msgType { <mask> case dhcp4.Discover: // Broadcast Packet From Client - Can I have an IP? <mask> // find a lease, but don't update lease time <mask> log.Tracef("Got from client: Discover") <mask> lease, err := s.reserveLease(p) <mask> if err != nil { <mask> log.Tracef("Couldn't find free lease: %s", err) <mask> // couldn't find lease, don't respond <mask> return nil <mask> } <mask> reply := dhcp4.ReplyPacket(p, dhcp4.Offer, s.ipnet.IP, lease.IP, s.leaseTime, s.leaseOptions.SelectOrderOrAll(options[dhcp4.OptionParameterRequestList])) <mask> log.Tracef("Replying with offer: offered IP %v for %v with options %+v", lease.IP, s.leaseTime, reply.ParseOptions()) <mask> return reply <mask> case dhcp4.Request: // Broadcast From Client - I'll take that IP (Also start for renewals) <mask> // start/renew a lease -- update lease time <mask> // some clients (OSX) just go right ahead and do Request first from previously known IP, if they get NAK, they restart full cycle with Discover then Request <mask> return s.handleDHCP4Request(p, options) <mask> case dhcp4.Decline: // Broadcast From Client - Sorry I can't use that IP </s> * dhcp: refactor; log client's HW addr </s> add func (s *Server) handleDiscover(p dhcp4.Packet, options dhcp4.Options) dhcp4.Packet { // find a lease, but don't update lease time lease, err := s.reserveLease(p) if err != nil { log.Tracef("Couldn't find free lease: %s", err) // couldn't find lease, don't respond return nil } opt := s.leaseOptions.SelectOrderOrAll(options[dhcp4.OptionParameterRequestList]) reply := dhcp4.ReplyPacket(p, dhcp4.Offer, s.ipnet.IP, lease.IP, s.leaseTime, opt) log.Tracef("Replying with offer: offered IP %v for %v with options %+v", lease.IP, s.leaseTime, reply.ParseOptions()) return reply } </s> remove log.Tracef("IP pool:") for ip, hwaddr := range s.IPpool { log.Tracef("IP pool entry %s -> %s", net.IPv4(ip[0], ip[1], ip[2], ip[3]), hwaddr) } </s> add </s> remove return dhcp4.ReplyPacket(p, dhcp4.ACK, s.ipnet.IP, lease.IP, s.leaseTime, s.leaseOptions.SelectOrderOrAll(options[dhcp4.OptionParameterRequestList])) </s> add opt := s.leaseOptions.SelectOrderOrAll(options[dhcp4.OptionParameterRequestList]) return dhcp4.ReplyPacket(p, dhcp4.ACK, s.ipnet.IP, lease.IP, s.leaseTime, opt) </s> remove // do nothing </s> add </s> remove foundHWaddr := s.getIPpool(newIP) </s> add foundHWaddr := s.findReservedHWaddr(newIP) </s> remove hwaddr := s.getIPpool(reqIP) </s> add hwaddr := s.findReservedHWaddr(reqIP)
https://github.com/AdguardTeam/AdGuardHome/commit/60fa3b2e95e5fc111884f13c8bfa465f030a0b40
dhcpd/dhcpd.go
keep keep keep keep replace keep keep keep replace keep
<mask> log.Tracef("Got from client: Release") <mask> <mask> case dhcp4.Inform: // From Client, I have this IP and there's nothing you can do about it <mask> log.Tracef("Got from client: Inform") <mask> // do nothing <mask> <mask> // from server -- ignore those but enumerate just in case <mask> case dhcp4.Offer: // Broadcast From Server - Here's an IP <mask> log.Printf("SHOULD NOT HAPPEN -- FROM ANOTHER DHCP SERVER: Offer") <mask> case dhcp4.ACK: // From Server, Yes you can have that IP </s> * dhcp: refactor; log client's HW addr </s> remove log.Printf("SHOULD NOT HAPPEN -- FROM ANOTHER DHCP SERVER: ACK") </s> add log.Printf("DHCP: received message from another server: ACK") </s> remove log.Printf("SHOULD NOT HAPPEN -- FROM ANOTHER DHCP SERVER: NAK") </s> add log.Printf("DHCP: received message from another server: NAK") </s> remove // find a lease, but don't update lease time log.Tracef("Got from client: Discover") lease, err := s.reserveLease(p) if err != nil { log.Tracef("Couldn't find free lease: %s", err) // couldn't find lease, don't respond return nil } reply := dhcp4.ReplyPacket(p, dhcp4.Offer, s.ipnet.IP, lease.IP, s.leaseTime, s.leaseOptions.SelectOrderOrAll(options[dhcp4.OptionParameterRequestList])) log.Tracef("Replying with offer: offered IP %v for %v with options %+v", lease.IP, s.leaseTime, reply.ParseOptions()) return reply </s> add return s.handleDiscover(p, options) </s> remove log.Printf("Unknown DHCP packet detected, ignoring: %v", msgType) </s> add log.Printf("DHCP: unknown packet %v from client %s", msgType, p.CHAddr()) </s> remove return dhcp4.ReplyPacket(p, dhcp4.ACK, s.ipnet.IP, lease.IP, s.leaseTime, s.leaseOptions.SelectOrderOrAll(options[dhcp4.OptionParameterRequestList])) </s> add opt := s.leaseOptions.SelectOrderOrAll(options[dhcp4.OptionParameterRequestList]) return dhcp4.ReplyPacket(p, dhcp4.ACK, s.ipnet.IP, lease.IP, s.leaseTime, opt)
https://github.com/AdguardTeam/AdGuardHome/commit/60fa3b2e95e5fc111884f13c8bfa465f030a0b40
dhcpd/dhcpd.go
keep keep keep keep replace keep replace keep
<mask> // from server -- ignore those but enumerate just in case <mask> case dhcp4.Offer: // Broadcast From Server - Here's an IP <mask> log.Printf("SHOULD NOT HAPPEN -- FROM ANOTHER DHCP SERVER: Offer") <mask> case dhcp4.ACK: // From Server, Yes you can have that IP <mask> log.Printf("SHOULD NOT HAPPEN -- FROM ANOTHER DHCP SERVER: ACK") <mask> case dhcp4.NAK: // From Server, No you cannot have that IP <mask> log.Printf("SHOULD NOT HAPPEN -- FROM ANOTHER DHCP SERVER: NAK") <mask> default: </s> * dhcp: refactor; log client's HW addr </s> remove log.Printf("SHOULD NOT HAPPEN -- FROM ANOTHER DHCP SERVER: Offer") </s> add log.Printf("DHCP: received message from another server: Offer") </s> remove // do nothing </s> add </s> remove log.Printf("Unknown DHCP packet detected, ignoring: %v", msgType) </s> add log.Printf("DHCP: unknown packet %v from client %s", msgType, p.CHAddr()) </s> remove // find a lease, but don't update lease time log.Tracef("Got from client: Discover") lease, err := s.reserveLease(p) if err != nil { log.Tracef("Couldn't find free lease: %s", err) // couldn't find lease, don't respond return nil } reply := dhcp4.ReplyPacket(p, dhcp4.Offer, s.ipnet.IP, lease.IP, s.leaseTime, s.leaseOptions.SelectOrderOrAll(options[dhcp4.OptionParameterRequestList])) log.Tracef("Replying with offer: offered IP %v for %v with options %+v", lease.IP, s.leaseTime, reply.ParseOptions()) return reply </s> add return s.handleDiscover(p, options) </s> remove hwaddr := s.getIPpool(reqIP) </s> add hwaddr := s.findReservedHWaddr(reqIP)
https://github.com/AdguardTeam/AdGuardHome/commit/60fa3b2e95e5fc111884f13c8bfa465f030a0b40
dhcpd/dhcpd.go
keep keep keep keep replace keep keep keep keep keep
<mask> log.Printf("SHOULD NOT HAPPEN -- FROM ANOTHER DHCP SERVER: ACK") <mask> case dhcp4.NAK: // From Server, No you cannot have that IP <mask> log.Printf("SHOULD NOT HAPPEN -- FROM ANOTHER DHCP SERVER: NAK") <mask> default: <mask> log.Printf("Unknown DHCP packet detected, ignoring: %v", msgType) <mask> return nil <mask> } <mask> return nil <mask> } <mask> </s> * dhcp: refactor; log client's HW addr </s> remove log.Printf("SHOULD NOT HAPPEN -- FROM ANOTHER DHCP SERVER: NAK") </s> add log.Printf("DHCP: received message from another server: NAK") </s> remove log.Printf("SHOULD NOT HAPPEN -- FROM ANOTHER DHCP SERVER: ACK") </s> add log.Printf("DHCP: received message from another server: ACK") </s> remove log.Printf("SHOULD NOT HAPPEN -- FROM ANOTHER DHCP SERVER: Offer") </s> add log.Printf("DHCP: received message from another server: Offer") </s> remove // do nothing </s> add </s> add func (s *Server) handleDiscover(p dhcp4.Packet, options dhcp4.Options) dhcp4.Packet { // find a lease, but don't update lease time lease, err := s.reserveLease(p) if err != nil { log.Tracef("Couldn't find free lease: %s", err) // couldn't find lease, don't respond return nil } opt := s.leaseOptions.SelectOrderOrAll(options[dhcp4.OptionParameterRequestList]) reply := dhcp4.ReplyPacket(p, dhcp4.Offer, s.ipnet.IP, lease.IP, s.leaseTime, opt) log.Tracef("Replying with offer: offered IP %v for %v with options %+v", lease.IP, s.leaseTime, reply.ParseOptions()) return reply } </s> remove // find a lease, but don't update lease time log.Tracef("Got from client: Discover") lease, err := s.reserveLease(p) if err != nil { log.Tracef("Couldn't find free lease: %s", err) // couldn't find lease, don't respond return nil } reply := dhcp4.ReplyPacket(p, dhcp4.Offer, s.ipnet.IP, lease.IP, s.leaseTime, s.leaseOptions.SelectOrderOrAll(options[dhcp4.OptionParameterRequestList])) log.Tracef("Replying with offer: offered IP %v for %v with options %+v", lease.IP, s.leaseTime, reply.ParseOptions()) return reply </s> add return s.handleDiscover(p, options)
https://github.com/AdguardTeam/AdGuardHome/commit/60fa3b2e95e5fc111884f13c8bfa465f030a0b40
dhcpd/dhcpd.go
keep keep add keep keep keep keep keep keep
<mask> return nil <mask> } <mask> <mask> func (s *Server) handleDHCP4Request(p dhcp4.Packet, options dhcp4.Options) dhcp4.Packet { <mask> server := options[dhcp4.OptionServerIdentifier] <mask> if server != nil && !net.IP(server).Equal(s.ipnet.IP) { <mask> log.Tracef("Request message not for this DHCP server (%v vs %v)", server, s.ipnet.IP) <mask> return nil // Message not for this dhcp server <mask> } </s> * dhcp: refactor; log client's HW addr </s> remove log.Tracef("Got from client: Request") if server, ok := options[dhcp4.OptionServerIdentifier]; ok && !net.IP(server).Equal(s.ipnet.IP) { </s> add server := options[dhcp4.OptionServerIdentifier] if server != nil && !net.IP(server).Equal(s.ipnet.IP) { </s> remove log.Tracef("Got %v message", msgType) </s> add log.Tracef("Message from client %s: %d", p.CHAddr(), msgType) </s> remove func (s *Server) getIPpool(ip net.IP) net.HardwareAddr { </s> add func (s *Server) findReservedHWaddr(ip net.IP) net.HardwareAddr { </s> remove foundHWaddr := s.getIPpool(newIP) </s> add foundHWaddr := s.findReservedHWaddr(newIP) </s> remove hwaddr := s.getIPpool(reqIP) </s> add hwaddr := s.findReservedHWaddr(reqIP) </s> remove // find a lease, but don't update lease time log.Tracef("Got from client: Discover") lease, err := s.reserveLease(p) if err != nil { log.Tracef("Couldn't find free lease: %s", err) // couldn't find lease, don't respond return nil } reply := dhcp4.ReplyPacket(p, dhcp4.Offer, s.ipnet.IP, lease.IP, s.leaseTime, s.leaseOptions.SelectOrderOrAll(options[dhcp4.OptionParameterRequestList])) log.Tracef("Replying with offer: offered IP %v for %v with options %+v", lease.IP, s.leaseTime, reply.ParseOptions()) return reply </s> add return s.handleDiscover(p, options)
https://github.com/AdguardTeam/AdGuardHome/commit/60fa3b2e95e5fc111884f13c8bfa465f030a0b40
dhcpd/dhcpd.go
keep keep keep keep replace replace keep keep keep keep keep
<mask> return nil <mask> } <mask> <mask> func (s *Server) handleDHCP4Request(p dhcp4.Packet, options dhcp4.Options) dhcp4.Packet { <mask> log.Tracef("Got from client: Request") <mask> if server, ok := options[dhcp4.OptionServerIdentifier]; ok && !net.IP(server).Equal(s.ipnet.IP) { <mask> log.Tracef("Request message not for this DHCP server (%v vs %v)", server, s.ipnet.IP) <mask> return nil // Message not for this dhcp server <mask> } <mask> <mask> reqIP := net.IP(options[dhcp4.OptionRequestedIPAddress]) </s> * dhcp: refactor; log client's HW addr </s> add func (s *Server) handleDiscover(p dhcp4.Packet, options dhcp4.Options) dhcp4.Packet { // find a lease, but don't update lease time lease, err := s.reserveLease(p) if err != nil { log.Tracef("Couldn't find free lease: %s", err) // couldn't find lease, don't respond return nil } opt := s.leaseOptions.SelectOrderOrAll(options[dhcp4.OptionParameterRequestList]) reply := dhcp4.ReplyPacket(p, dhcp4.Offer, s.ipnet.IP, lease.IP, s.leaseTime, opt) log.Tracef("Replying with offer: offered IP %v for %v with options %+v", lease.IP, s.leaseTime, reply.ParseOptions()) return reply } </s> remove log.Tracef("Got %v message", msgType) </s> add log.Tracef("Message from client %s: %d", p.CHAddr(), msgType) </s> remove func (s *Server) getIPpool(ip net.IP) net.HardwareAddr { </s> add func (s *Server) findReservedHWaddr(ip net.IP) net.HardwareAddr { </s> remove hwaddr := s.getIPpool(reqIP) </s> add hwaddr := s.findReservedHWaddr(reqIP) </s> remove foundHWaddr := s.getIPpool(newIP) </s> add foundHWaddr := s.findReservedHWaddr(newIP) </s> remove // do nothing </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/60fa3b2e95e5fc111884f13c8bfa465f030a0b40
dhcpd/dhcpd.go
keep keep keep keep replace keep keep keep keep keep
<mask> if lease.IP.Equal(reqIP) { <mask> // IP matches lease IP, nothing else to do <mask> lease.Expiry = time.Now().Add(s.leaseTime) <mask> log.Tracef("Replying with ACK: request IP matches lease IP, nothing else to do. IP %v for %v", lease.IP, p.CHAddr()) <mask> return dhcp4.ReplyPacket(p, dhcp4.ACK, s.ipnet.IP, lease.IP, s.leaseTime, s.leaseOptions.SelectOrderOrAll(options[dhcp4.OptionParameterRequestList])) <mask> } <mask> <mask> // <mask> // requested IP different from lease <mask> // </s> * dhcp: refactor; log client's HW addr </s> remove hwaddr := s.getIPpool(reqIP) </s> add hwaddr := s.findReservedHWaddr(reqIP) </s> remove // find a lease, but don't update lease time log.Tracef("Got from client: Discover") lease, err := s.reserveLease(p) if err != nil { log.Tracef("Couldn't find free lease: %s", err) // couldn't find lease, don't respond return nil } reply := dhcp4.ReplyPacket(p, dhcp4.Offer, s.ipnet.IP, lease.IP, s.leaseTime, s.leaseOptions.SelectOrderOrAll(options[dhcp4.OptionParameterRequestList])) log.Tracef("Replying with offer: offered IP %v for %v with options %+v", lease.IP, s.leaseTime, reply.ParseOptions()) return reply </s> add return s.handleDiscover(p, options) </s> add func (s *Server) handleDiscover(p dhcp4.Packet, options dhcp4.Options) dhcp4.Packet { // find a lease, but don't update lease time lease, err := s.reserveLease(p) if err != nil { log.Tracef("Couldn't find free lease: %s", err) // couldn't find lease, don't respond return nil } opt := s.leaseOptions.SelectOrderOrAll(options[dhcp4.OptionParameterRequestList]) reply := dhcp4.ReplyPacket(p, dhcp4.Offer, s.ipnet.IP, lease.IP, s.leaseTime, opt) log.Tracef("Replying with offer: offered IP %v for %v with options %+v", lease.IP, s.leaseTime, reply.ParseOptions()) return reply } </s> remove foundHWaddr := s.getIPpool(newIP) </s> add foundHWaddr := s.findReservedHWaddr(newIP) </s> remove // do nothing </s> add </s> remove // Leases returns the list of current DHCP leases </s> add // Leases returns the list of current DHCP leases (thread-safe)
https://github.com/AdguardTeam/AdGuardHome/commit/60fa3b2e95e5fc111884f13c8bfa465f030a0b40
dhcpd/dhcpd.go
keep keep keep keep replace keep keep keep keep keep
<mask> // <mask> <mask> log.Tracef("lease IP is different from requested IP: %s vs %s", lease.IP, reqIP) <mask> <mask> hwaddr := s.getIPpool(reqIP) <mask> if hwaddr == nil { <mask> // not in pool, check if it's in DHCP range <mask> if dhcp4.IPInRange(s.leaseStart, s.leaseStop, reqIP) { <mask> // okay, we can give it to our client -- it's in our DHCP range and not taken, so let them use their IP <mask> log.Tracef("Replying with ACK: request IP %v is not taken, so assigning lease IP %v to it, for %v", reqIP, lease.IP, p.CHAddr()) </s> * dhcp: refactor; log client's HW addr </s> remove foundHWaddr := s.getIPpool(newIP) </s> add foundHWaddr := s.findReservedHWaddr(newIP) </s> remove return dhcp4.ReplyPacket(p, dhcp4.ACK, s.ipnet.IP, lease.IP, s.leaseTime, s.leaseOptions.SelectOrderOrAll(options[dhcp4.OptionParameterRequestList])) </s> add opt := s.leaseOptions.SelectOrderOrAll(options[dhcp4.OptionParameterRequestList]) return dhcp4.ReplyPacket(p, dhcp4.ACK, s.ipnet.IP, lease.IP, s.leaseTime, opt) </s> remove // Leases returns the list of current DHCP leases </s> add // Leases returns the list of current DHCP leases (thread-safe) </s> add func (s *Server) handleDiscover(p dhcp4.Packet, options dhcp4.Options) dhcp4.Packet { // find a lease, but don't update lease time lease, err := s.reserveLease(p) if err != nil { log.Tracef("Couldn't find free lease: %s", err) // couldn't find lease, don't respond return nil } opt := s.leaseOptions.SelectOrderOrAll(options[dhcp4.OptionParameterRequestList]) reply := dhcp4.ReplyPacket(p, dhcp4.Offer, s.ipnet.IP, lease.IP, s.leaseTime, opt) log.Tracef("Replying with offer: offered IP %v for %v with options %+v", lease.IP, s.leaseTime, reply.ParseOptions()) return reply } </s> remove log.Tracef("Got %v message", msgType) </s> add log.Tracef("Message from client %s: %d", p.CHAddr(), msgType) </s> remove // find a lease, but don't update lease time log.Tracef("Got from client: Discover") lease, err := s.reserveLease(p) if err != nil { log.Tracef("Couldn't find free lease: %s", err) // couldn't find lease, don't respond return nil } reply := dhcp4.ReplyPacket(p, dhcp4.Offer, s.ipnet.IP, lease.IP, s.leaseTime, s.leaseOptions.SelectOrderOrAll(options[dhcp4.OptionParameterRequestList])) log.Tracef("Replying with offer: offered IP %v for %v with options %+v", lease.IP, s.leaseTime, reply.ParseOptions()) return reply </s> add return s.handleDiscover(p, options)
https://github.com/AdguardTeam/AdGuardHome/commit/60fa3b2e95e5fc111884f13c8bfa465f030a0b40
dhcpd/dhcpd.go
keep keep keep keep replace keep keep keep keep keep
<mask> log.Tracef("Replying with NAK: request IP %s is outside of DHCP range [%s, %s], asked by %v", reqIP, s.leaseStart, s.leaseStop, p.CHAddr()) <mask> return dhcp4.ReplyPacket(p, dhcp4.NAK, s.ipnet.IP, nil, 0, nil) <mask> } <mask> <mask> // Leases returns the list of current DHCP leases <mask> func (s *Server) Leases() []*Lease { <mask> s.RLock() <mask> result := s.leases <mask> s.RUnlock() <mask> return result </s> * dhcp: refactor; log client's HW addr </s> remove hwaddr := s.getIPpool(reqIP) </s> add hwaddr := s.findReservedHWaddr(reqIP) </s> remove return dhcp4.ReplyPacket(p, dhcp4.ACK, s.ipnet.IP, lease.IP, s.leaseTime, s.leaseOptions.SelectOrderOrAll(options[dhcp4.OptionParameterRequestList])) </s> add opt := s.leaseOptions.SelectOrderOrAll(options[dhcp4.OptionParameterRequestList]) return dhcp4.ReplyPacket(p, dhcp4.ACK, s.ipnet.IP, lease.IP, s.leaseTime, opt) </s> add func (s *Server) handleDiscover(p dhcp4.Packet, options dhcp4.Options) dhcp4.Packet { // find a lease, but don't update lease time lease, err := s.reserveLease(p) if err != nil { log.Tracef("Couldn't find free lease: %s", err) // couldn't find lease, don't respond return nil } opt := s.leaseOptions.SelectOrderOrAll(options[dhcp4.OptionParameterRequestList]) reply := dhcp4.ReplyPacket(p, dhcp4.Offer, s.ipnet.IP, lease.IP, s.leaseTime, opt) log.Tracef("Replying with offer: offered IP %v for %v with options %+v", lease.IP, s.leaseTime, reply.ParseOptions()) return reply } </s> remove log.Tracef("Got %v message", msgType) </s> add log.Tracef("Message from client %s: %d", p.CHAddr(), msgType) </s> add log.Info("DHCP: listening on 0.0.0.0:67") </s> remove func (s *Server) getIPpool(ip net.IP) net.HardwareAddr { </s> add func (s *Server) findReservedHWaddr(ip net.IP) net.HardwareAddr {
https://github.com/AdguardTeam/AdGuardHome/commit/60fa3b2e95e5fc111884f13c8bfa465f030a0b40
dhcpd/dhcpd.go
keep keep keep replace keep keep keep replace keep keep
<mask> package querylog <mask> <mask> import ( <mask> "encoding/base64" <mask> "fmt" <mask> "net" <mask> "strconv" <mask> "strings" <mask> "time" <mask> </s> *(querylog): decode methods to a new file </s> remove "github.com/AdguardTeam/AdGuardHome/dnsfilter" </s> add </s> remove // decodeLogEntry - decodes query log entry from a line // nolint (gocyclo) func decodeLogEntry(ent *logEntry, str string) { var b bool var i int var err error for { k, v, t := readJSON(&str) if t == jsonTErr { break } switch k { case "IP": if len(ent.IP) == 0 { ent.IP = v } case "T": ent.Time, err = time.Parse(time.RFC3339, v) case "QH": ent.QHost = v case "QT": ent.QType = v case "QC": ent.QClass = v case "Answer": ent.Answer, err = base64.StdEncoding.DecodeString(v) case "OrigAnswer": ent.OrigAnswer, err = base64.StdEncoding.DecodeString(v) case "IsFiltered": b, err = strconv.ParseBool(v) ent.Result.IsFiltered = b case "Rule": ent.Result.Rule = v case "FilterID": i, err = strconv.Atoi(v) ent.Result.FilterID = int64(i) case "Reason": i, err = strconv.Atoi(v) ent.Result.Reason = dnsfilter.Reason(i) case "Upstream": ent.Upstream = v case "Elapsed": i, err = strconv.Atoi(v) ent.Elapsed = time.Duration(i) // pre-v0.99.3 compatibility: case "Question": var qstr []byte qstr, err = base64.StdEncoding.DecodeString(v) if err != nil { break } q := new(dns.Msg) err = q.Unpack(qstr) if err != nil { break } ent.QHost = q.Question[0].Name if len(ent.QHost) == 0 { break } ent.QHost = ent.QHost[:len(ent.QHost)-1] ent.QType = dns.TypeToString[q.Question[0].Qtype] ent.QClass = dns.ClassToString[q.Question[0].Qclass] case "Time": ent.Time, err = time.Parse(time.RFC3339, v) } if err != nil { log.Debug("decodeLogEntry err: %s", err) break } } } // Get value from "key":"value" func readJSONValue(s, name string) string { i := strings.Index(s, "\""+name+"\":\"") if i == -1 { return "" } start := i + 1 + len(name) + 3 i = strings.IndexByte(s[start:], '"') if i == -1 { return "" } end := start + i return s[start:end] } const ( jsonTErr = iota jsonTObj jsonTStr jsonTNum jsonTBool ) // Parse JSON key-value pair // e.g.: "key":VALUE where VALUE is "string", true|false (boolean), or 123.456 (number) // Note the limitations: // . doesn't support whitespace // . doesn't support "null" // . doesn't validate boolean or number // . no proper handling of {} braces // . no handling of [] brackets // Return (key, value, type) func readJSON(ps *string) (string, string, int32) { s := *ps k := "" v := "" t := int32(jsonTErr) q1 := strings.IndexByte(s, '"') if q1 == -1 { return k, v, t } q2 := strings.IndexByte(s[q1+1:], '"') if q2 == -1 { return k, v, t } k = s[q1+1 : q1+1+q2] s = s[q1+1+q2+1:] if len(s) < 2 || s[0] != ':' { return k, v, t } if s[1] == '"' { q2 = strings.IndexByte(s[2:], '"') if q2 == -1 { return k, v, t } v = s[2 : 2+q2] t = jsonTStr s = s[2+q2+1:] } else if s[1] == '{' { t = jsonTObj s = s[1+1:] } else { sep := strings.IndexAny(s[1:], ",}") if sep == -1 { return k, v, t } v = s[1 : 1+sep] if s[1] == 't' || s[1] == 'f' { t = jsonTBool } else if s[1] == '.' || (s[1] >= '0' && s[1] <= '9') { t = jsonTNum } s = s[1+sep+1:] } *ps = s return k, v, t } </s> add </s> remove func TestJSON(t *testing.T) { s := ` {"keystr":"val","obj":{"keybool":true,"keyint":123456}} ` k, v, jtype := readJSON(&s) assert.Equal(t, jtype, int32(jsonTStr)) assert.Equal(t, "keystr", k) assert.Equal(t, "val", v) k, v, jtype = readJSON(&s) assert.Equal(t, jtype, int32(jsonTObj)) assert.Equal(t, "obj", k) k, v, jtype = readJSON(&s) assert.Equal(t, jtype, int32(jsonTBool)) assert.Equal(t, "keybool", k) assert.Equal(t, "true", v) k, v, jtype = readJSON(&s) assert.Equal(t, jtype, int32(jsonTNum)) assert.Equal(t, "keyint", k) assert.Equal(t, "123456", v) k, v, jtype = readJSON(&s) assert.True(t, jtype == jsonTErr) } </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/61a24ffc71eda26e10a11e3a9c8506909b6c4b52
querylog/json.go
keep keep keep keep replace keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep keep
<mask> "strconv" <mask> "strings" <mask> "time" <mask> <mask> "github.com/AdguardTeam/AdGuardHome/dnsfilter" <mask> "github.com/AdguardTeam/golibs/log" <mask> "github.com/miekg/dns" <mask> ) <mask> <mask> // decodeLogEntry - decodes query log entry from a line <mask> // nolint (gocyclo) <mask> func decodeLogEntry(ent *logEntry, str string) { <mask> var b bool <mask> var i int <mask> var err error <mask> for { <mask> k, v, t := readJSON(&str) <mask> if t == jsonTErr { <mask> break <mask> } <mask> switch k { <mask> case "IP": <mask> if len(ent.IP) == 0 { <mask> ent.IP = v <mask> } <mask> case "T": <mask> ent.Time, err = time.Parse(time.RFC3339, v) <mask> <mask> case "QH": <mask> ent.QHost = v <mask> case "QT": <mask> ent.QType = v <mask> case "QC": <mask> ent.QClass = v <mask> <mask> case "Answer": <mask> ent.Answer, err = base64.StdEncoding.DecodeString(v) <mask> case "OrigAnswer": <mask> ent.OrigAnswer, err = base64.StdEncoding.DecodeString(v) <mask> <mask> case "IsFiltered": <mask> b, err = strconv.ParseBool(v) <mask> ent.Result.IsFiltered = b <mask> case "Rule": <mask> ent.Result.Rule = v <mask> case "FilterID": <mask> i, err = strconv.Atoi(v) <mask> ent.Result.FilterID = int64(i) <mask> case "Reason": <mask> i, err = strconv.Atoi(v) <mask> ent.Result.Reason = dnsfilter.Reason(i) <mask> <mask> case "Upstream": <mask> ent.Upstream = v <mask> case "Elapsed": <mask> i, err = strconv.Atoi(v) <mask> ent.Elapsed = time.Duration(i) <mask> <mask> // pre-v0.99.3 compatibility: <mask> case "Question": <mask> var qstr []byte <mask> qstr, err = base64.StdEncoding.DecodeString(v) <mask> if err != nil { <mask> break <mask> } <mask> q := new(dns.Msg) <mask> err = q.Unpack(qstr) <mask> if err != nil { <mask> break <mask> } <mask> ent.QHost = q.Question[0].Name <mask> if len(ent.QHost) == 0 { <mask> break <mask> } <mask> ent.QHost = ent.QHost[:len(ent.QHost)-1] <mask> ent.QType = dns.TypeToString[q.Question[0].Qtype] <mask> ent.QClass = dns.ClassToString[q.Question[0].Qclass] <mask> case "Time": <mask> ent.Time, err = time.Parse(time.RFC3339, v) <mask> } <mask> <mask> if err != nil { <mask> log.Debug("decodeLogEntry err: %s", err) <mask> break <mask> } <mask> } <mask> } <mask> <mask> // Get value from "key":"value" <mask> func readJSONValue(s, name string) string { <mask> i := strings.Index(s, "\""+name+"\":\"") <mask> if i == -1 { <mask> return "" <mask> } <mask> start := i + 1 + len(name) + 3 <mask> i = strings.IndexByte(s[start:], '"') <mask> if i == -1 { <mask> return "" <mask> } <mask> end := start + i <mask> return s[start:end] <mask> } <mask> <mask> const ( <mask> jsonTErr = iota <mask> jsonTObj <mask> jsonTStr <mask> jsonTNum <mask> jsonTBool <mask> ) <mask> <mask> // Parse JSON key-value pair <mask> // e.g.: "key":VALUE where VALUE is "string", true|false (boolean), or 123.456 (number) <mask> // Note the limitations: <mask> // . doesn't support whitespace <mask> // . doesn't support "null" <mask> // . doesn't validate boolean or number <mask> // . no proper handling of {} braces <mask> // . no handling of [] brackets <mask> // Return (key, value, type) <mask> func readJSON(ps *string) (string, string, int32) { <mask> s := *ps <mask> k := "" <mask> v := "" <mask> t := int32(jsonTErr) <mask> <mask> q1 := strings.IndexByte(s, '"') <mask> if q1 == -1 { <mask> return k, v, t <mask> } <mask> q2 := strings.IndexByte(s[q1+1:], '"') <mask> if q2 == -1 { <mask> return k, v, t <mask> } <mask> k = s[q1+1 : q1+1+q2] <mask> s = s[q1+1+q2+1:] <mask> <mask> if len(s) < 2 || s[0] != ':' { <mask> return k, v, t <mask> } <mask> <mask> if s[1] == '"' { <mask> q2 = strings.IndexByte(s[2:], '"') <mask> if q2 == -1 { <mask> return k, v, t <mask> } <mask> v = s[2 : 2+q2] <mask> t = jsonTStr <mask> s = s[2+q2+1:] <mask> <mask> } else if s[1] == '{' { <mask> t = jsonTObj <mask> s = s[1+1:] <mask> <mask> } else { <mask> sep := strings.IndexAny(s[1:], ",}") <mask> if sep == -1 { <mask> return k, v, t <mask> } <mask> v = s[1 : 1+sep] <mask> if s[1] == 't' || s[1] == 'f' { <mask> t = jsonTBool <mask> } else if s[1] == '.' || (s[1] >= '0' && s[1] <= '9') { <mask> t = jsonTNum <mask> } <mask> s = s[1+sep+1:] <mask> } <mask> <mask> *ps = s <mask> return k, v, t <mask> } <mask> <mask> // Get Client IP address <mask> func (l *queryLog) getClientIP(clientIP string) string { <mask> if l.conf.AnonymizeClientIP { </s> *(querylog): decode methods to a new file </s> remove func TestJSON(t *testing.T) { s := ` {"keystr":"val","obj":{"keybool":true,"keyint":123456}} ` k, v, jtype := readJSON(&s) assert.Equal(t, jtype, int32(jsonTStr)) assert.Equal(t, "keystr", k) assert.Equal(t, "val", v) k, v, jtype = readJSON(&s) assert.Equal(t, jtype, int32(jsonTObj)) assert.Equal(t, "obj", k) k, v, jtype = readJSON(&s) assert.Equal(t, jtype, int32(jsonTBool)) assert.Equal(t, "keybool", k) assert.Equal(t, "true", v) k, v, jtype = readJSON(&s) assert.Equal(t, jtype, int32(jsonTNum)) assert.Equal(t, "keyint", k) assert.Equal(t, "123456", v) k, v, jtype = readJSON(&s) assert.True(t, jtype == jsonTErr) } </s> add </s> remove "strings" </s> add </s> remove "encoding/base64" </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/61a24ffc71eda26e10a11e3a9c8506909b6c4b52
querylog/json.go
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep keep keep keep
<mask> entries, _ = l.search(params) <mask> assert.Equal(t, 10, len(entries)) <mask> } <mask> <mask> func TestJSON(t *testing.T) { <mask> s := ` <mask> {"keystr":"val","obj":{"keybool":true,"keyint":123456}} <mask> ` <mask> k, v, jtype := readJSON(&s) <mask> assert.Equal(t, jtype, int32(jsonTStr)) <mask> assert.Equal(t, "keystr", k) <mask> assert.Equal(t, "val", v) <mask> <mask> k, v, jtype = readJSON(&s) <mask> assert.Equal(t, jtype, int32(jsonTObj)) <mask> assert.Equal(t, "obj", k) <mask> <mask> k, v, jtype = readJSON(&s) <mask> assert.Equal(t, jtype, int32(jsonTBool)) <mask> assert.Equal(t, "keybool", k) <mask> assert.Equal(t, "true", v) <mask> <mask> k, v, jtype = readJSON(&s) <mask> assert.Equal(t, jtype, int32(jsonTNum)) <mask> assert.Equal(t, "keyint", k) <mask> assert.Equal(t, "123456", v) <mask> <mask> k, v, jtype = readJSON(&s) <mask> assert.True(t, jtype == jsonTErr) <mask> } <mask> <mask> func addEntry(l *queryLog, host, answerStr, client string) { <mask> q := dns.Msg{} <mask> q.Question = append(q.Question, dns.Question{ <mask> Name: host + ".", <mask> Qtype: dns.TypeA, </s> *(querylog): decode methods to a new file </s> remove // decodeLogEntry - decodes query log entry from a line // nolint (gocyclo) func decodeLogEntry(ent *logEntry, str string) { var b bool var i int var err error for { k, v, t := readJSON(&str) if t == jsonTErr { break } switch k { case "IP": if len(ent.IP) == 0 { ent.IP = v } case "T": ent.Time, err = time.Parse(time.RFC3339, v) case "QH": ent.QHost = v case "QT": ent.QType = v case "QC": ent.QClass = v case "Answer": ent.Answer, err = base64.StdEncoding.DecodeString(v) case "OrigAnswer": ent.OrigAnswer, err = base64.StdEncoding.DecodeString(v) case "IsFiltered": b, err = strconv.ParseBool(v) ent.Result.IsFiltered = b case "Rule": ent.Result.Rule = v case "FilterID": i, err = strconv.Atoi(v) ent.Result.FilterID = int64(i) case "Reason": i, err = strconv.Atoi(v) ent.Result.Reason = dnsfilter.Reason(i) case "Upstream": ent.Upstream = v case "Elapsed": i, err = strconv.Atoi(v) ent.Elapsed = time.Duration(i) // pre-v0.99.3 compatibility: case "Question": var qstr []byte qstr, err = base64.StdEncoding.DecodeString(v) if err != nil { break } q := new(dns.Msg) err = q.Unpack(qstr) if err != nil { break } ent.QHost = q.Question[0].Name if len(ent.QHost) == 0 { break } ent.QHost = ent.QHost[:len(ent.QHost)-1] ent.QType = dns.TypeToString[q.Question[0].Qtype] ent.QClass = dns.ClassToString[q.Question[0].Qclass] case "Time": ent.Time, err = time.Parse(time.RFC3339, v) } if err != nil { log.Debug("decodeLogEntry err: %s", err) break } } } // Get value from "key":"value" func readJSONValue(s, name string) string { i := strings.Index(s, "\""+name+"\":\"") if i == -1 { return "" } start := i + 1 + len(name) + 3 i = strings.IndexByte(s[start:], '"') if i == -1 { return "" } end := start + i return s[start:end] } const ( jsonTErr = iota jsonTObj jsonTStr jsonTNum jsonTBool ) // Parse JSON key-value pair // e.g.: "key":VALUE where VALUE is "string", true|false (boolean), or 123.456 (number) // Note the limitations: // . doesn't support whitespace // . doesn't support "null" // . doesn't validate boolean or number // . no proper handling of {} braces // . no handling of [] brackets // Return (key, value, type) func readJSON(ps *string) (string, string, int32) { s := *ps k := "" v := "" t := int32(jsonTErr) q1 := strings.IndexByte(s, '"') if q1 == -1 { return k, v, t } q2 := strings.IndexByte(s[q1+1:], '"') if q2 == -1 { return k, v, t } k = s[q1+1 : q1+1+q2] s = s[q1+1+q2+1:] if len(s) < 2 || s[0] != ':' { return k, v, t } if s[1] == '"' { q2 = strings.IndexByte(s[2:], '"') if q2 == -1 { return k, v, t } v = s[2 : 2+q2] t = jsonTStr s = s[2+q2+1:] } else if s[1] == '{' { t = jsonTObj s = s[1+1:] } else { sep := strings.IndexAny(s[1:], ",}") if sep == -1 { return k, v, t } v = s[1 : 1+sep] if s[1] == 't' || s[1] == 'f' { t = jsonTBool } else if s[1] == '.' || (s[1] >= '0' && s[1] <= '9') { t = jsonTNum } s = s[1+sep+1:] } *ps = s return k, v, t } </s> add </s> remove "github.com/AdguardTeam/AdGuardHome/dnsfilter" </s> add </s> remove "strings" </s> add </s> remove "encoding/base64" </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/61a24ffc71eda26e10a11e3a9c8506909b6c4b52
querylog/qlog_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> SafeSearchConf: safeSearchConf, <mask> SafeSearchCacheSize: 1000, <mask> CacheTime: 30, <mask> } <mask> safeSearch, err := safesearch.NewDefaultSafeSearch( <mask> safeSearchConf, <mask> filterConf.SafeSearchCacheSize, <mask> time.Minute*time.Duration(filterConf.CacheTime), <mask> ) <mask> require.NoError(t, err) </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> add "", </s> remove Upstreams: cj.Upstreams, </s> add if safeSearchConf.Enabled { err = c.setSafeSearch( safeSearchConf, clients.safeSearchCacheSize, clients.safeSearchCacheTTL, ) if err != nil { return nil, fmt.Errorf("creating safesearch for client %q: %w", c.Name, err) } </s> remove BlockedServices: cj.BlockedServices, </s> add } </s> remove return &Client{ Name: cj.Name, IDs: cj.IDs, Tags: cj.Tags, </s> add c = &Client{ safeSearchConf: safeSearchConf, Name: cj.Name, IDs: cj.IDs, Tags: cj.Tags, BlockedServices: cj.BlockedServices, Upstreams: cj.Upstreams, </s> remove ss, err := safesearch.NewDefaultSafeSearch( </s> add err := cli.setSafeSearch( </s> remove safeSearchConf: safeSearchConf, </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/dnsforward/dnsforward_test.go
keep add keep keep keep keep keep
<mask> safeSearch, err := safesearch.NewDefault( <mask> safeSearchConf, <mask> filterConf.SafeSearchCacheSize, <mask> time.Minute*time.Duration(filterConf.CacheTime), <mask> ) <mask> require.NoError(t, err) <mask> </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove safeSearch, err := safesearch.NewDefaultSafeSearch( </s> add safeSearch, err := safesearch.NewDefault( </s> add "default", </s> remove Upstreams: cj.Upstreams, </s> add if safeSearchConf.Enabled { err = c.setSafeSearch( safeSearchConf, clients.safeSearchCacheSize, clients.safeSearchCacheTTL, ) if err != nil { return nil, fmt.Errorf("creating safesearch for client %q: %w", c.Name, err) } </s> remove config.DNS.DnsfilterConf.SafeSearch, err = safesearch.NewDefaultSafeSearch( </s> add config.DNS.DnsfilterConf.SafeSearch, err = safesearch.NewDefault( </s> remove assert.False(t, res.IsFiltered) assert.Empty(t, res.Rules) ss = newForTest(t, defaultSafeSearchConf) res, err = ss.CheckHost(domain, dns.TypeA) </s> add res, err := ss.CheckHost("www.yandex.com", testQType) </s> remove var foundIP net.IP for _, ip := range ips { if ip.To4() != nil { foundIP = ip break } } res, err = ss.CheckHost(domain, dns.TypeA) </s> add res, err = ss.CheckHost("www.yandex.com", testQType)
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/dnsforward/dnsforward_test.go
keep keep replace replace replace replace keep keep keep replace replace replace replace keep keep keep keep
<mask> package filtering <mask> <mask> import ( <mask> "github.com/AdguardTeam/urlfilter/rules" <mask> "github.com/miekg/dns" <mask> ) <mask> <mask> // SafeSearch interface describes a service for search engines hosts rewrites. <mask> type SafeSearch interface { <mask> // SearchHost returns a replacement address for the search engine host. <mask> SearchHost(host string, qtype uint16) (res *rules.DNSRewrite) <mask> <mask> // CheckHost checks host with safe search engine. <mask> CheckHost(host string, qtype uint16) (res Result, err error) <mask> } <mask> <mask> // SafeSearchConfig is a struct with safe search related settings. </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> add // Update updates the configuration of the safe search filter. Update must // be safe for concurrent use. An implementation of Update may ignore some // fields, but it must document which. Update(conf SafeSearchConfig) (err error) </s> remove _ uint16, </s> add qtype uint16, </s> remove // DefaultSafeSearch is the default safesearch struct. type DefaultSafeSearch struct { engine *urlfilter.DNSEngine safeSearchCache cache.Cache resolver filtering.Resolver cacheTime time.Duration </s> add // Default is the default safe search filter that uses filtering rules with the // dnsrewrite modifier. type Default struct { // mu protects engine. mu *sync.RWMutex // engine is the filtering engine that contains the DNS rewrite rules. // engine may be nil, which means that this safe search filter is disabled. engine *urlfilter.DNSEngine cache cache.Cache resolver filtering.Resolver logPrefix string cacheTTL time.Duration </s> remove // SearchHost implements the [filtering.SafeSearch] interface for *DefaultSafeSearch. func (ss *DefaultSafeSearch) SearchHost(host string, qtype uint16) (res *rules.DNSRewrite) { r, _ := ss.engine.MatchRequest(&urlfilter.DNSRequest{ Hostname: strings.ToLower(host), DNSType: qtype, }) rewritesRules := r.DNSRewrites() if len(rewritesRules) > 0 { return rewritesRules[0].DNSRewrite } </s> add ss.log(log.INFO, "reset %d rules", ss.engine.RulesCount) </s> remove engine = urlfilter.NewDNSEngine(rs) log.Info("safesearch: filter %d: reset %d rules", listID, engine.RulesCount) return engine, nil } // type check var _ filtering.SafeSearch = (*DefaultSafeSearch)(nil) </s> add ss.engine = urlfilter.NewDNSEngine(rs)
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch.go
keep add keep keep keep keep keep keep
<mask> // for concurrent use. qtype must be either [dns.TypeA] or [dns.TypeAAAA]. <mask> CheckHost(host string, qtype uint16) (res Result, err error) <mask> } <mask> <mask> // SafeSearchConfig is a struct with safe search related settings. <mask> type SafeSearchConfig struct { <mask> // CustomResolver is the resolver used by safe search. <mask> CustomResolver Resolver `yaml:"-" json:"-"` </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove // SearchHost returns a replacement address for the search engine host. SearchHost(host string, qtype uint16) (res *rules.DNSRewrite) // CheckHost checks host with safe search engine. </s> add // CheckHost checks host with safe search filter. CheckHost must be safe // for concurrent use. qtype must be either [dns.TypeA] or [dns.TypeAAAA]. </s> remove // setCacheResult stores data in cache for host. func (ss *DefaultSafeSearch) setCacheResult(host string, res filtering.Result) { expire := uint32(time.Now().Add(ss.cacheTime).Unix()) </s> add // qtypeToProto returns "ip4" for [dns.TypeA] and "ip6" for [dns.TypeAAAA]. // It panics for other types. func qtypeToProto(qtype rules.RRType) (proto string) { switch qtype { case dns.TypeA: return "ip4" case dns.TypeAAAA: return "ip6" default: panic(fmt.Errorf("safesearch: unsupported question type %s", dns.Type(qtype))) } } // fitToProto returns a non-nil IP address if ip is the correct protocol version // for qtype. qtype is expected to be either [dns.TypeA] or [dns.TypeAAAA]. func fitToProto(ip net.IP, qtype rules.RRType) (res net.IP) { ip4 := ip.To4() if qtype == dns.TypeA { return ip4 } if ip4 == nil { return ip } return nil } // setCacheResult stores data in cache for host. qtype is expected to be either // [dns.TypeA] or [dns.TypeAAAA]. func (ss *Default) setCacheResult(host string, qtype rules.RRType, res filtering.Result) { expire := uint32(time.Now().Add(ss.cacheTTL).Unix()) </s> remove // DefaultSafeSearch is the default safesearch struct. type DefaultSafeSearch struct { engine *urlfilter.DNSEngine safeSearchCache cache.Cache resolver filtering.Resolver cacheTime time.Duration </s> add // Default is the default safe search filter that uses filtering rules with the // dnsrewrite modifier. type Default struct { // mu protects engine. mu *sync.RWMutex // engine is the filtering engine that contains the DNS rewrite rules. // engine may be nil, which means that this safe search filter is disabled. engine *urlfilter.DNSEngine cache cache.Cache resolver filtering.Resolver logPrefix string cacheTTL time.Duration </s> remove _ uint16, </s> add qtype uint16, </s> remove // newResult creates Result object from rewrite rule. func (ss *DefaultSafeSearch) newResult( </s> add // searchHost looks up DNS rewrites in the internal DNS filtering engine. func (ss *Default) searchHost(host string, qtype rules.RRType) (res *rules.DNSRewrite) { ss.mu.RLock() defer ss.mu.RUnlock() if ss.engine == nil { return nil } r, _ := ss.engine.MatchRequest(&urlfilter.DNSRequest{ Hostname: strings.ToLower(host), DNSType: qtype, }) rewritesRules := r.DNSRewrites() if len(rewritesRules) > 0 { return rewritesRules[0].DNSRewrite } return nil } // newResult creates Result object from rewrite rule. qtype must be either // [dns.TypeA] or [dns.TypeAAAA]. func (ss *Default) newResult( </s> remove // getCachedResult returns stored data from cache for host. func (ss *DefaultSafeSearch) getCachedResult(host string) (res filtering.Result, ok bool) { </s> add // getCachedResult returns stored data from cache for host. qtype is expected // to be either [dns.TypeA] or [dns.TypeAAAA]. func (ss *Default) getCachedResult( host string, qtype rules.RRType, ) (res filtering.Result, ok bool) {
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch.go
keep replace keep keep replace keep
<mask> host string, <mask> _ uint16, <mask> setts *Settings, <mask> ) (res Result, err error) { <mask> if !setts.ProtectionEnabled || !setts.SafeSearchEnabled { <mask> return Result{}, nil </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove func (ss *DefaultSafeSearch) CheckHost( </s> add func (ss *Default) CheckHost( </s> remove qtype uint16, </s> add qtype rules.RRType, </s> remove // SearchHost returns a replacement address for the search engine host. SearchHost(host string, qtype uint16) (res *rules.DNSRewrite) // CheckHost checks host with safe search engine. </s> add // CheckHost checks host with safe search filter. CheckHost must be safe // for concurrent use. qtype must be either [dns.TypeA] or [dns.TypeAAAA]. </s> remove if log.GetLevel() >= log.DEBUG { timer := log.StartTimer() defer timer.LogElapsed("safesearch: lookup for %s", host) </s> add start := time.Now() defer func() { ss.log(log.DEBUG, "lookup for %q finished in %s", host, time.Since(start)) }() if qtype != dns.TypeA && qtype != dns.TypeAAAA { return filtering.Result{}, fmt.Errorf("unsupported question type %s", dns.Type(qtype)) </s> remove qtype uint16, </s> add qtype rules.RRType,
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch.go
keep keep keep replace keep keep replace
<mask> <mask> clientSafeSearch := setts.ClientSafeSearch <mask> if clientSafeSearch != nil { <mask> return clientSafeSearch.CheckHost(host, dns.TypeA) <mask> } <mask> <mask> return d.safeSearch.CheckHost(host, dns.TypeA) </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove var dnsRewriteSink *rules.DNSRewrite func BenchmarkSafeSearch(b *testing.B) { ss := newForTest(b, defaultSafeSearchConf) for n := 0; n < b.N; n++ { dnsRewriteSink = ss.SearchHost(googleHost, dns.TypeA) } assert.Equal(b, "forcesafesearch.google.com", dnsRewriteSink.NewCNAME) } var dnsRewriteParallelSink *rules.DNSRewrite func BenchmarkSafeSearch_parallel(b *testing.B) { ss := newForTest(b, defaultSafeSearchConf) b.RunParallel(func(pb *testing.PB) { for pb.Next() { dnsRewriteParallelSink = ss.SearchHost(googleHost, dns.TypeA) } }) assert.Equal(b, "forcesafesearch.google.com", dnsRewriteParallelSink.NewCNAME) </s> add assert.False(t, res.IsFiltered) </s> remove var foundIP net.IP for _, ip := range ips { if ip.To4() != nil { foundIP = ip break } } res, err = ss.CheckHost(domain, dns.TypeA) </s> add res, err = ss.CheckHost("www.yandex.com", testQType) </s> remove res, err := ss.CheckHost(host, dns.TypeA) </s> add var res filtering.Result res, err = ss.CheckHost(host, testQType) </s> remove res, err := ss.CheckHost(host, dns.TypeA) </s> add var res filtering.Result res, err = ss.CheckHost(host, testQType) </s> remove return ss } func TestSafeSearch(t *testing.T) { ss := newForTest(t, defaultSafeSearchConf) val := ss.SearchHost("www.google.com", dns.TypeA) assert.Equal(t, &rules.DNSRewrite{NewCNAME: "forcesafesearch.google.com"}, val) } func TestCheckHostSafeSearchYandex(t *testing.T) { ss := newForTest(t, defaultSafeSearchConf) </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch.go
keep keep keep keep replace
<mask> |www.google.to^$dnsrewrite=NOERROR;CNAME;forcesafesearch.google.com <mask> |www.google.tt^$dnsrewrite=NOERROR;CNAME;forcesafesearch.google.com <mask> |www.google.vg^$dnsrewrite=NOERROR;CNAME;forcesafesearch.google.com <mask> |www.google.vu^$dnsrewrite=NOERROR;CNAME;forcesafesearch.google.com <mask> |www.google.ws^$dnsrewrite=NOERROR;CNAME;forcesafesearch.google.com </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> add |www.google.ws^$dnsrewrite=NOERROR;CNAME;forcesafesearch.google.com </s> remove log.Tracef("network:%v addr:%v", network, addr) </s> add log.Debug("home: customdial: dialing addr %q for network %s", addr, network) </s> remove if rewrite.NewCNAME == "" { </s> add host := rewrite.NewCNAME if host == "" { </s> remove cachedValue, isFound := ss.getCachedResult(host) </s> add cachedValue, isFound := ss.getCachedResult(host, qtype) </s> remove log.Debug("safesearch: found in cache: %s", host) </s> add ss.log(log.DEBUG, "found in cache: %q", host) </s> remove rewrite := ss.SearchHost(host, qtype) </s> add rewrite := ss.searchHost(host, qtype)
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/rules/google.txt
keep keep keep add
<mask> |www.google.tt^$dnsrewrite=NOERROR;CNAME;forcesafesearch.google.com <mask> |www.google.vg^$dnsrewrite=NOERROR;CNAME;forcesafesearch.google.com <mask> |www.google.vu^$dnsrewrite=NOERROR;CNAME;forcesafesearch.google.com <mask> |www.google.ws^$dnsrewrite=NOERROR;CNAME;forcesafesearch.google.com </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove |www.google.ws^$dnsrewrite=NOERROR;CNAME;forcesafesearch.google.com </s> add </s> remove log.Tracef("network:%v addr:%v", network, addr) </s> add log.Debug("home: customdial: dialing addr %q for network %s", addr, network) </s> remove if rewrite.NewCNAME == "" { </s> add host := rewrite.NewCNAME if host == "" { </s> remove cachedValue, isFound := ss.getCachedResult(host) </s> add cachedValue, isFound := ss.getCachedResult(host, qtype) </s> remove log.Debug("safesearch: found in cache: %s", host) </s> add ss.log(log.DEBUG, "found in cache: %q", host) </s> remove rewrite := ss.SearchHost(host, qtype) </s> add rewrite := ss.searchHost(host, qtype)
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/rules/google.txt
keep keep keep keep replace
<mask> |yandex.pl^$dnsrewrite=NOERROR;A;213.180.193.56 <mask> |yandex.ru^$dnsrewrite=NOERROR;A;213.180.193.56 <mask> |yandex.tj^$dnsrewrite=NOERROR;A;213.180.193.56 <mask> |yandex.tm^$dnsrewrite=NOERROR;A;213.180.193.56 <mask> |yandex.uz^$dnsrewrite=NOERROR;A;213.180.193.56 </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> add |yandex.uz^$dnsrewrite=NOERROR;A;213.180.193.56 </s> remove ips, err := ss.resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME) </s> add ss.log(log.DEBUG, "resolving %q", host) ips, err := ss.resolver.LookupIP(context.Background(), qtypeToProto(qtype), host) </s> remove cachedValue, isFound := ss.getCachedResult(host) </s> add cachedValue, isFound := ss.getCachedResult(host, qtype) </s> remove log.Debug("safesearch: found in cache: %s", host) </s> add ss.log(log.DEBUG, "found in cache: %q", host) </s> remove rewrite := ss.SearchHost(host, qtype) </s> add rewrite := ss.searchHost(host, qtype) </s> remove dRes, err := ss.newResult(rewrite, qtype) </s> add fltRes, err := ss.newResult(rewrite, qtype)
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/rules/yandex.txt
keep keep keep add
<mask> |yandex.ru^$dnsrewrite=NOERROR;A;213.180.193.56 <mask> |yandex.tj^$dnsrewrite=NOERROR;A;213.180.193.56 <mask> |yandex.tm^$dnsrewrite=NOERROR;A;213.180.193.56 <mask> |yandex.uz^$dnsrewrite=NOERROR;A;213.180.193.56 </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove |yandex.uz^$dnsrewrite=NOERROR;A;213.180.193.56 </s> add </s> remove ips, err := ss.resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME) </s> add ss.log(log.DEBUG, "resolving %q", host) ips, err := ss.resolver.LookupIP(context.Background(), qtypeToProto(qtype), host) </s> remove cachedValue, isFound := ss.getCachedResult(host) </s> add cachedValue, isFound := ss.getCachedResult(host, qtype) </s> remove log.Debug("safesearch: found in cache: %s", host) </s> add ss.log(log.DEBUG, "found in cache: %q", host) </s> remove rewrite := ss.SearchHost(host, qtype) </s> add rewrite := ss.searchHost(host, qtype) </s> remove dRes, err := ss.newResult(rewrite, qtype) </s> add fltRes, err := ss.newResult(rewrite, qtype)
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/rules/yandex.txt
keep keep keep keep replace
<mask> |www.youtube.com^$dnsrewrite=NOERROR;CNAME;restrictmoderate.youtube.com <mask> |m.youtube.com^$dnsrewrite=NOERROR;CNAME;restrictmoderate.youtube.com <mask> |youtubei.googleapis.com^$dnsrewrite=NOERROR;CNAME;restrictmoderate.youtube.com <mask> |youtube.googleapis.com^$dnsrewrite=NOERROR;CNAME;restrictmoderate.youtube.com <mask> |www.youtube-nocookie.com^$dnsrewrite=NOERROR;CNAME;restrictmoderate.youtube.com </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove log.Tracef("network:%v addr:%v", network, addr) </s> add log.Debug("home: customdial: dialing addr %q for network %s", addr, network) </s> remove if log.GetLevel() >= log.DEBUG { timer := log.StartTimer() defer timer.LogElapsed("safesearch: lookup for %s", host) </s> add start := time.Now() defer func() { ss.log(log.DEBUG, "lookup for %q finished in %s", host, time.Since(start)) }() if qtype != dns.TypeA && qtype != dns.TypeAAAA { return filtering.Result{}, fmt.Errorf("unsupported question type %s", dns.Type(qtype)) </s> remove cachedValue, isFound := ss.getCachedResult(host) </s> add cachedValue, isFound := ss.getCachedResult(host, qtype) </s> remove log.Debug("safesearch: found in cache: %s", host) </s> add ss.log(log.DEBUG, "found in cache: %q", host) </s> remove rewrite := ss.SearchHost(host, qtype) </s> add rewrite := ss.searchHost(host, qtype) </s> remove dRes, err := ss.newResult(rewrite, qtype) </s> add fltRes, err := ss.newResult(rewrite, qtype)
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/rules/youtube.txt
keep add keep keep keep keep keep keep
<mask> "net" <mask> "strings" <mask> "time" <mask> <mask> "github.com/AdguardTeam/AdGuardHome/internal/filtering" <mask> "github.com/AdguardTeam/golibs/cache" <mask> "github.com/AdguardTeam/golibs/log" <mask> "github.com/AdguardTeam/urlfilter" </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove "github.com/AdguardTeam/AdGuardHome/internal/filtering/safesearch" </s> add </s> remove "context" </s> add </s> add "github.com/AdguardTeam/AdGuardHome/internal/filtering" </s> add "time" </s> remove "github.com/AdguardTeam/urlfilter/rules" </s> add "github.com/AdguardTeam/AdGuardHome/internal/filtering/safesearch" "github.com/AdguardTeam/golibs/testutil" </s> remove package safesearch </s> add package safesearch_test
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch.go
keep keep replace replace replace replace replace replace keep keep replace replace replace keep keep keep
<mask> } <mask> <mask> // DefaultSafeSearch is the default safesearch struct. <mask> type DefaultSafeSearch struct { <mask> engine *urlfilter.DNSEngine <mask> safeSearchCache cache.Cache <mask> resolver filtering.Resolver <mask> cacheTime time.Duration <mask> } <mask> <mask> // NewDefaultSafeSearch returns new safesearch struct. CacheTime is an element <mask> // TTL (in minutes). <mask> func NewDefaultSafeSearch( <mask> conf filtering.SafeSearchConfig, <mask> cacheSize uint, <mask> cacheTime time.Duration, </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove cacheTime time.Duration, ) (ss *DefaultSafeSearch, err error) { engine, err := newEngine(filtering.SafeSearchListID, conf) if err != nil { return nil, err } </s> add cacheTTL time.Duration, ) (ss *Default, err error) { </s> add name string, </s> remove // newEngine creates new engine for provided safe search configuration. func newEngine(listID int, conf filtering.SafeSearchConfig) (engine *urlfilter.DNSEngine, err error) { </s> add // log is a helper for logging that includes the name of the safe search // filter. level must be one of [log.DEBUG], [log.INFO], and [log.ERROR]. func (ss *Default) log(level log.Level, msg string, args ...any) { switch level { case log.DEBUG: log.Debug(ss.logPrefix+msg, args...) case log.INFO: log.Info(ss.logPrefix+msg, args...) case log.ERROR: log.Error(ss.logPrefix+msg, args...) default: panic(fmt.Errorf("safesearch: unsupported logging level %d", level)) } } // resetEngine creates new engine for provided safe search configuration and // sets it in ss. func (ss *Default) resetEngine( listID int, conf filtering.SafeSearchConfig, ) (err error) { if !conf.Enabled { ss.log(log.INFO, "disabled") return nil } </s> add // safeSearchCacheSize is the size of the safe search cache to use for // persistent clients. safeSearchCacheSize uint // safeSearchCacheTTL is the TTL of the safe search cache to use for // persistent clients. safeSearchCacheTTL time.Duration </s> remove var defaultSafeSearchConf = filtering.SafeSearchConfig{ Enabled: true, </s> add // testConf is the default safe search configuration for tests. var testConf = filtering.SafeSearchConfig{ CustomResolver: nil, Enabled: true,
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch.go
keep keep add keep keep keep keep keep
<mask> // for logging. <mask> func NewDefault( <mask> conf filtering.SafeSearchConfig, <mask> cacheSize uint, <mask> cacheTTL time.Duration, <mask> ) (ss *Default, err error) { <mask> var resolver filtering.Resolver = net.DefaultResolver <mask> if conf.CustomResolver != nil { </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove cacheTime time.Duration, ) (ss *DefaultSafeSearch, err error) { engine, err := newEngine(filtering.SafeSearchListID, conf) if err != nil { return nil, err } </s> add cacheTTL time.Duration, ) (ss *Default, err error) { </s> remove // NewDefaultSafeSearch returns new safesearch struct. CacheTime is an element // TTL (in minutes). func NewDefaultSafeSearch( </s> add // NewDefault returns an initialized default safe search filter. name is used // for logging. func NewDefault( </s> remove ss := newForTest(t, defaultSafeSearchConf) ss.resolver = resolver </s> add conf := testConf conf.CustomResolver = resolver ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL) require.NoError(t, err) </s> remove // newEngine creates new engine for provided safe search configuration. func newEngine(listID int, conf filtering.SafeSearchConfig) (engine *urlfilter.DNSEngine, err error) { </s> add // log is a helper for logging that includes the name of the safe search // filter. level must be one of [log.DEBUG], [log.INFO], and [log.ERROR]. func (ss *Default) log(level log.Level, msg string, args ...any) { switch level { case log.DEBUG: log.Debug(ss.logPrefix+msg, args...) case log.INFO: log.Info(ss.logPrefix+msg, args...) case log.ERROR: log.Error(ss.logPrefix+msg, args...) default: panic(fmt.Errorf("safesearch: unsupported logging level %d", level)) } } // resetEngine creates new engine for provided safe search configuration and // sets it in ss. func (ss *Default) resetEngine( listID int, conf filtering.SafeSearchConfig, ) (err error) { if !conf.Enabled { ss.log(log.INFO, "disabled") return nil } </s> remove return &DefaultSafeSearch{ engine: engine, safeSearchCache: cache.New(cache.Config{ </s> add ss = &Default{ mu: &sync.RWMutex{}, cache: cache.New(cache.Config{ </s> remove func (ss *DefaultSafeSearch) CheckHost( </s> add func (ss *Default) CheckHost(
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch.go
keep keep keep keep replace replace replace replace replace replace replace keep keep keep keep keep
<mask> // TTL (in minutes). <mask> func NewDefaultSafeSearch( <mask> conf filtering.SafeSearchConfig, <mask> cacheSize uint, <mask> cacheTime time.Duration, <mask> ) (ss *DefaultSafeSearch, err error) { <mask> engine, err := newEngine(filtering.SafeSearchListID, conf) <mask> if err != nil { <mask> return nil, err <mask> } <mask> <mask> var resolver filtering.Resolver = net.DefaultResolver <mask> if conf.CustomResolver != nil { <mask> resolver = conf.CustomResolver <mask> } <mask> </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove // NewDefaultSafeSearch returns new safesearch struct. CacheTime is an element // TTL (in minutes). func NewDefaultSafeSearch( </s> add // NewDefault returns an initialized default safe search filter. name is used // for logging. func NewDefault( </s> add name string, </s> remove return &DefaultSafeSearch{ engine: engine, safeSearchCache: cache.New(cache.Config{ </s> add ss = &Default{ mu: &sync.RWMutex{}, cache: cache.New(cache.Config{ </s> remove ss := newForTest(t, defaultSafeSearchConf) ss.resolver = resolver </s> add conf := testConf conf.CustomResolver = resolver ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL) require.NoError(t, err) </s> remove // DefaultSafeSearch is the default safesearch struct. type DefaultSafeSearch struct { engine *urlfilter.DNSEngine safeSearchCache cache.Cache resolver filtering.Resolver cacheTime time.Duration </s> add // Default is the default safe search filter that uses filtering rules with the // dnsrewrite modifier. type Default struct { // mu protects engine. mu *sync.RWMutex // engine is the filtering engine that contains the DNS rewrite rules. // engine may be nil, which means that this safe search filter is disabled. engine *urlfilter.DNSEngine cache cache.Cache resolver filtering.Resolver logPrefix string cacheTTL time.Duration </s> add conf := *req err = d.safeSearch.Update(conf) if err != nil { aghhttp.Error(r, w, http.StatusBadRequest, "updating: %s", err) return }
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch.go
keep replace replace replace keep keep keep replace replace replace keep keep keep keep
<mask> <mask> return &DefaultSafeSearch{ <mask> engine: engine, <mask> safeSearchCache: cache.New(cache.Config{ <mask> EnableLRU: true, <mask> MaxSize: cacheSize, <mask> }), <mask> cacheTime: cacheTime, <mask> resolver: resolver, <mask> }, nil <mask> } <mask> <mask> // newEngine creates new engine for provided safe search configuration. <mask> func newEngine(listID int, conf filtering.SafeSearchConfig) (engine *urlfilter.DNSEngine, err error) { </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove // newEngine creates new engine for provided safe search configuration. func newEngine(listID int, conf filtering.SafeSearchConfig) (engine *urlfilter.DNSEngine, err error) { </s> add // log is a helper for logging that includes the name of the safe search // filter. level must be one of [log.DEBUG], [log.INFO], and [log.ERROR]. func (ss *Default) log(level log.Level, msg string, args ...any) { switch level { case log.DEBUG: log.Debug(ss.logPrefix+msg, args...) case log.INFO: log.Info(ss.logPrefix+msg, args...) case log.ERROR: log.Error(ss.logPrefix+msg, args...) default: panic(fmt.Errorf("safesearch: unsupported logging level %d", level)) } } // resetEngine creates new engine for provided safe search configuration and // sets it in ss. func (ss *Default) resetEngine( listID int, conf filtering.SafeSearchConfig, ) (err error) { if !conf.Enabled { ss.log(log.INFO, "disabled") return nil } </s> remove // NewDefaultSafeSearch returns new safesearch struct. CacheTime is an element // TTL (in minutes). func NewDefaultSafeSearch( </s> add // NewDefault returns an initialized default safe search filter. name is used // for logging. func NewDefault( </s> remove cacheTime time.Duration, ) (ss *DefaultSafeSearch, err error) { engine, err := newEngine(filtering.SafeSearchListID, conf) if err != nil { return nil, err } </s> add cacheTTL time.Duration, ) (ss *Default, err error) { </s> remove // SearchHost returns a replacement address for the search engine host. SearchHost(host string, qtype uint16) (res *rules.DNSRewrite) // CheckHost checks host with safe search engine. </s> add // CheckHost checks host with safe search filter. CheckHost must be safe // for concurrent use. qtype must be either [dns.TypeA] or [dns.TypeAAAA]. </s> remove // DefaultSafeSearch is the default safesearch struct. type DefaultSafeSearch struct { engine *urlfilter.DNSEngine safeSearchCache cache.Cache resolver filtering.Resolver cacheTime time.Duration </s> add // Default is the default safe search filter that uses filtering rules with the // dnsrewrite modifier. type Default struct { // mu protects engine. mu *sync.RWMutex // engine is the filtering engine that contains the DNS rewrite rules. // engine may be nil, which means that this safe search filter is disabled. engine *urlfilter.DNSEngine cache cache.Cache resolver filtering.Resolver logPrefix string cacheTTL time.Duration
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch.go
keep keep keep keep replace replace keep keep keep keep keep
<mask> resolver: resolver, <mask> }, nil <mask> } <mask> <mask> // newEngine creates new engine for provided safe search configuration. <mask> func newEngine(listID int, conf filtering.SafeSearchConfig) (engine *urlfilter.DNSEngine, err error) { <mask> var sb strings.Builder <mask> for service, serviceRules := range safeSearchRules { <mask> if isServiceProtected(conf, service) { <mask> sb.WriteString(serviceRules) <mask> } </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove cacheTime: cacheTime, resolver: resolver, }, nil </s> add resolver: resolver, // Use %s, because the client safe-search names already contain double // quotes. logPrefix: fmt.Sprintf("safesearch %s: ", name), cacheTTL: cacheTTL, } err = ss.resetEngine(filtering.SafeSearchListID, conf) if err != nil { // Don't wrap the error, because it's informative enough as is. return nil, err } return ss, nil </s> remove func newForTest(t testing.TB, ssConf filtering.SafeSearchConfig) (ss *DefaultSafeSearch) { ss, err := NewDefaultSafeSearch(ssConf, safeSearchCacheSize, cacheTime) </s> add func TestDefault_CheckHost_yandex(t *testing.T) { conf := testConf ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL) </s> remove // NewDefaultSafeSearch returns new safesearch struct. CacheTime is an element // TTL (in minutes). func NewDefaultSafeSearch( </s> add // NewDefault returns an initialized default safe search filter. name is used // for logging. func NewDefault( </s> remove cacheTime time.Duration, ) (ss *DefaultSafeSearch, err error) { engine, err := newEngine(filtering.SafeSearchListID, conf) if err != nil { return nil, err } </s> add cacheTTL time.Duration, ) (ss *Default, err error) { </s> remove return ss } func TestSafeSearch(t *testing.T) { ss := newForTest(t, defaultSafeSearchConf) val := ss.SearchHost("www.google.com", dns.TypeA) assert.Equal(t, &rules.DNSRewrite{NewCNAME: "forcesafesearch.google.com"}, val) } func TestCheckHostSafeSearchYandex(t *testing.T) { ss := newForTest(t, defaultSafeSearchConf) </s> add </s> remove // SearchHost returns a replacement address for the search engine host. SearchHost(host string, qtype uint16) (res *rules.DNSRewrite) // CheckHost checks host with safe search engine. </s> add // CheckHost checks host with safe search filter. CheckHost must be safe // for concurrent use. qtype must be either [dns.TypeA] or [dns.TypeAAAA].
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch.go
keep replace keep keep replace replace replace replace replace replace replace replace keep
<mask> if err != nil { <mask> return nil, fmt.Errorf("creating rule storage: %w", err) <mask> } <mask> <mask> engine = urlfilter.NewDNSEngine(rs) <mask> log.Info("safesearch: filter %d: reset %d rules", listID, engine.RulesCount) <mask> <mask> return engine, nil <mask> } <mask> <mask> // type check <mask> var _ filtering.SafeSearch = (*DefaultSafeSearch)(nil) <mask> </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove // SearchHost implements the [filtering.SafeSearch] interface for *DefaultSafeSearch. func (ss *DefaultSafeSearch) SearchHost(host string, qtype uint16) (res *rules.DNSRewrite) { r, _ := ss.engine.MatchRequest(&urlfilter.DNSRequest{ Hostname: strings.ToLower(host), DNSType: qtype, }) rewritesRules := r.DNSRewrites() if len(rewritesRules) > 0 { return rewritesRules[0].DNSRewrite } </s> add ss.log(log.INFO, "reset %d rules", ss.engine.RulesCount) </s> add // type check var _ filtering.SafeSearch = (*Default)(nil) </s> add return c, nil </s> remove Upstreams: cj.Upstreams, </s> add if safeSearchConf.Enabled { err = c.setSafeSearch( safeSearchConf, clients.safeSearchCacheSize, clients.safeSearchCacheTTL, ) if err != nil { return nil, fmt.Errorf("creating safesearch for client %q: %w", c.Name, err) } </s> remove cacheTime time.Duration, ) (ss *DefaultSafeSearch, err error) { engine, err := newEngine(filtering.SafeSearchListID, conf) if err != nil { return nil, err } </s> add cacheTTL time.Duration, ) (ss *Default, err error) {
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch.go
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace keep keep keep keep keep
<mask> <mask> // type check <mask> var _ filtering.SafeSearch = (*DefaultSafeSearch)(nil) <mask> <mask> // SearchHost implements the [filtering.SafeSearch] interface for *DefaultSafeSearch. <mask> func (ss *DefaultSafeSearch) SearchHost(host string, qtype uint16) (res *rules.DNSRewrite) { <mask> r, _ := ss.engine.MatchRequest(&urlfilter.DNSRequest{ <mask> Hostname: strings.ToLower(host), <mask> DNSType: qtype, <mask> }) <mask> <mask> rewritesRules := r.DNSRewrites() <mask> if len(rewritesRules) > 0 { <mask> return rewritesRules[0].DNSRewrite <mask> } <mask> <mask> return nil <mask> } <mask> <mask> // CheckHost implements the [filtering.SafeSearch] interface for </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove engine = urlfilter.NewDNSEngine(rs) log.Info("safesearch: filter %d: reset %d rules", listID, engine.RulesCount) return engine, nil } // type check var _ filtering.SafeSearch = (*DefaultSafeSearch)(nil) </s> add ss.engine = urlfilter.NewDNSEngine(rs) </s> add // type check var _ filtering.SafeSearch = (*Default)(nil) </s> remove // newResult creates Result object from rewrite rule. func (ss *DefaultSafeSearch) newResult( </s> add // searchHost looks up DNS rewrites in the internal DNS filtering engine. func (ss *Default) searchHost(host string, qtype rules.RRType) (res *rules.DNSRewrite) { ss.mu.RLock() defer ss.mu.RUnlock() if ss.engine == nil { return nil } r, _ := ss.engine.MatchRequest(&urlfilter.DNSRequest{ Hostname: strings.ToLower(host), DNSType: qtype, }) rewritesRules := r.DNSRewrites() if len(rewritesRules) > 0 { return rewritesRules[0].DNSRewrite } return nil } // newResult creates Result object from rewrite rule. qtype must be either // [dns.TypeA] or [dns.TypeAAAA]. func (ss *Default) newResult( </s> remove func (ss *DefaultSafeSearch) CheckHost( </s> add func (ss *Default) CheckHost( </s> remove qtype uint16, </s> add qtype rules.RRType, </s> remove // SearchHost returns a replacement address for the search engine host. SearchHost(host string, qtype uint16) (res *rules.DNSRewrite) // CheckHost checks host with safe search engine. </s> add // CheckHost checks host with safe search filter. CheckHost must be safe // for concurrent use. qtype must be either [dns.TypeA] or [dns.TypeAAAA].
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch.go
keep keep keep add keep keep keep keep keep
<mask> <mask> return nil <mask> } <mask> <mask> // CheckHost implements the [filtering.SafeSearch] interface for <mask> // *DefaultSafeSearch. <mask> func (ss *Default) CheckHost( <mask> host string, <mask> qtype rules.RRType, </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove func (ss *DefaultSafeSearch) CheckHost( </s> add func (ss *Default) CheckHost( </s> remove qtype uint16, </s> add qtype rules.RRType, </s> remove // SearchHost implements the [filtering.SafeSearch] interface for *DefaultSafeSearch. func (ss *DefaultSafeSearch) SearchHost(host string, qtype uint16) (res *rules.DNSRewrite) { r, _ := ss.engine.MatchRequest(&urlfilter.DNSRequest{ Hostname: strings.ToLower(host), DNSType: qtype, }) rewritesRules := r.DNSRewrites() if len(rewritesRules) > 0 { return rewritesRules[0].DNSRewrite } </s> add ss.log(log.INFO, "reset %d rules", ss.engine.RulesCount) </s> remove engine = urlfilter.NewDNSEngine(rs) log.Info("safesearch: filter %d: reset %d rules", listID, engine.RulesCount) return engine, nil } // type check var _ filtering.SafeSearch = (*DefaultSafeSearch)(nil) </s> add ss.engine = urlfilter.NewDNSEngine(rs) </s> remove // SearchHost returns a replacement address for the search engine host. SearchHost(host string, qtype uint16) (res *rules.DNSRewrite) // CheckHost checks host with safe search engine. </s> add // CheckHost checks host with safe search filter. CheckHost must be safe // for concurrent use. qtype must be either [dns.TypeA] or [dns.TypeAAAA]. </s> remove // getCachedResult returns stored data from cache for host. func (ss *DefaultSafeSearch) getCachedResult(host string) (res filtering.Result, ok bool) { </s> add // getCachedResult returns stored data from cache for host. qtype is expected // to be either [dns.TypeA] or [dns.TypeAAAA]. func (ss *Default) getCachedResult( host string, qtype rules.RRType, ) (res filtering.Result, ok bool) {
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch.go
keep keep keep keep replace keep replace keep keep keep
<mask> } <mask> <mask> // CheckHost implements the [filtering.SafeSearch] interface for <mask> // *DefaultSafeSearch. <mask> func (ss *DefaultSafeSearch) CheckHost( <mask> host string, <mask> qtype uint16, <mask> ) (res filtering.Result, err error) { <mask> if log.GetLevel() >= log.DEBUG { <mask> timer := log.StartTimer() </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove if log.GetLevel() >= log.DEBUG { timer := log.StartTimer() defer timer.LogElapsed("safesearch: lookup for %s", host) </s> add start := time.Now() defer func() { ss.log(log.DEBUG, "lookup for %q finished in %s", host, time.Since(start)) }() if qtype != dns.TypeA && qtype != dns.TypeAAAA { return filtering.Result{}, fmt.Errorf("unsupported question type %s", dns.Type(qtype)) </s> add // type check var _ filtering.SafeSearch = (*Default)(nil) </s> remove // SearchHost implements the [filtering.SafeSearch] interface for *DefaultSafeSearch. func (ss *DefaultSafeSearch) SearchHost(host string, qtype uint16) (res *rules.DNSRewrite) { r, _ := ss.engine.MatchRequest(&urlfilter.DNSRequest{ Hostname: strings.ToLower(host), DNSType: qtype, }) rewritesRules := r.DNSRewrites() if len(rewritesRules) > 0 { return rewritesRules[0].DNSRewrite } </s> add ss.log(log.INFO, "reset %d rules", ss.engine.RulesCount) </s> remove engine = urlfilter.NewDNSEngine(rs) log.Info("safesearch: filter %d: reset %d rules", listID, engine.RulesCount) return engine, nil } // type check var _ filtering.SafeSearch = (*DefaultSafeSearch)(nil) </s> add ss.engine = urlfilter.NewDNSEngine(rs) </s> remove // SearchHost returns a replacement address for the search engine host. SearchHost(host string, qtype uint16) (res *rules.DNSRewrite) // CheckHost checks host with safe search engine. </s> add // CheckHost checks host with safe search filter. CheckHost must be safe // for concurrent use. qtype must be either [dns.TypeA] or [dns.TypeAAAA].
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch.go
keep keep keep replace replace replace keep keep keep replace keep keep keep keep
<mask> host string, <mask> qtype uint16, <mask> ) (res filtering.Result, err error) { <mask> if log.GetLevel() >= log.DEBUG { <mask> timer := log.StartTimer() <mask> defer timer.LogElapsed("safesearch: lookup for %s", host) <mask> } <mask> <mask> // Check cache. Return cached result if it was found <mask> cachedValue, isFound := ss.getCachedResult(host) <mask> if isFound { <mask> log.Debug("safesearch: found in cache: %s", host) <mask> <mask> return cachedValue, nil </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove log.Debug("safesearch: found in cache: %s", host) </s> add ss.log(log.DEBUG, "found in cache: %q", host) </s> remove qtype uint16, </s> add qtype rules.RRType, </s> remove func (ss *DefaultSafeSearch) CheckHost( </s> add func (ss *Default) CheckHost( </s> remove // newResult creates Result object from rewrite rule. func (ss *DefaultSafeSearch) newResult( </s> add // searchHost looks up DNS rewrites in the internal DNS filtering engine. func (ss *Default) searchHost(host string, qtype rules.RRType) (res *rules.DNSRewrite) { ss.mu.RLock() defer ss.mu.RUnlock() if ss.engine == nil { return nil } r, _ := ss.engine.MatchRequest(&urlfilter.DNSRequest{ Hostname: strings.ToLower(host), DNSType: qtype, }) rewritesRules := r.DNSRewrites() if len(rewritesRules) > 0 { return rewritesRules[0].DNSRewrite } return nil } // newResult creates Result object from rewrite rule. qtype must be either // [dns.TypeA] or [dns.TypeAAAA]. func (ss *Default) newResult( </s> remove require.Len(t, res.Rules, 1) assert.True(t, res.Rules[0].IP.Equal(foundIP)) // Check cache. cachedValue, isFound := ss.getCachedResult(domain) require.True(t, isFound) require.Len(t, cachedValue.Rules, 1) assert.True(t, cachedValue.Rules[0].IP.Equal(foundIP)) } const googleHost = "www.google.com" </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch.go
keep keep keep keep replace keep keep keep keep keep
<mask> <mask> // Check cache. Return cached result if it was found <mask> cachedValue, isFound := ss.getCachedResult(host) <mask> if isFound { <mask> log.Debug("safesearch: found in cache: %s", host) <mask> <mask> return cachedValue, nil <mask> } <mask> <mask> rewrite := ss.SearchHost(host, qtype) </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove cachedValue, isFound := ss.getCachedResult(host) </s> add cachedValue, isFound := ss.getCachedResult(host, qtype) </s> remove if log.GetLevel() >= log.DEBUG { timer := log.StartTimer() defer timer.LogElapsed("safesearch: lookup for %s", host) </s> add start := time.Now() defer func() { ss.log(log.DEBUG, "lookup for %q finished in %s", host, time.Since(start)) }() if qtype != dns.TypeA && qtype != dns.TypeAAAA { return filtering.Result{}, fmt.Errorf("unsupported question type %s", dns.Type(qtype)) </s> remove rewrite := ss.SearchHost(host, qtype) </s> add rewrite := ss.searchHost(host, qtype) </s> remove require.Len(t, res.Rules, 1) assert.True(t, res.Rules[0].IP.Equal(foundIP)) // Check cache. cachedValue, isFound := ss.getCachedResult(domain) require.True(t, isFound) require.Len(t, cachedValue.Rules, 1) assert.True(t, cachedValue.Rules[0].IP.Equal(foundIP)) } const googleHost = "www.google.com" </s> add </s> remove // For yandex we already know valid IP. require.Len(t, res.Rules, 1) </s> add assert.True(t, res.IsFiltered) </s> remove assert.Equal(t, res.Rules[0].IP, yandexIP) // Check cache. cachedValue, isFound := ss.getCachedResult(domain) require.True(t, isFound) require.Len(t, cachedValue.Rules, 1) assert.Equal(t, cachedValue.Rules[0].IP, yandexIP) } func TestSafeSearchCacheGoogle(t *testing.T) { const domain = "www.google.ru" ss := newForTest(t, filtering.SafeSearchConfig{Enabled: false}) </s> add err = ss.Update(filtering.SafeSearchConfig{ Enabled: true, Google: false, }) require.NoError(t, err)
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch.go
keep replace keep keep keep keep replace
<mask> <mask> rewrite := ss.SearchHost(host, qtype) <mask> if rewrite == nil { <mask> return filtering.Result{}, nil <mask> } <mask> <mask> dRes, err := ss.newResult(rewrite, qtype) </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove log.Debug("safesearch: failed to lookup addresses for %s: %s", host, err) </s> add ss.log(log.DEBUG, "looking up addresses for %q: %s", host, err) </s> remove log.Debug("safesearch: found in cache: %s", host) </s> add ss.log(log.DEBUG, "found in cache: %q", host) </s> remove // newResult creates Result object from rewrite rule. func (ss *DefaultSafeSearch) newResult( </s> add // searchHost looks up DNS rewrites in the internal DNS filtering engine. func (ss *Default) searchHost(host string, qtype rules.RRType) (res *rules.DNSRewrite) { ss.mu.RLock() defer ss.mu.RUnlock() if ss.engine == nil { return nil } r, _ := ss.engine.MatchRequest(&urlfilter.DNSRequest{ Hostname: strings.ToLower(host), DNSType: qtype, }) rewritesRules := r.DNSRewrites() if len(rewritesRules) > 0 { return rewritesRules[0].DNSRewrite } return nil } // newResult creates Result object from rewrite rule. qtype must be either // [dns.TypeA] or [dns.TypeAAAA]. func (ss *Default) newResult( </s> remove if ip = ip.To4(); ip == nil { </s> add // TODO(a.garipov): Remove this filtering once the resolver we use // actually learns about network. ip = fitToProto(ip, qtype) if ip == nil { </s> remove return filtering.Result{}, fmt.Errorf("no ipv4 addresses in safe search response for %s", host) </s> add return filtering.Result{}, fmt.Errorf("no ipv4 addresses for %q", host)
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch.go
keep keep keep keep replace keep keep keep keep keep
<mask> } <mask> <mask> dRes, err := ss.newResult(rewrite, qtype) <mask> if err != nil { <mask> log.Debug("safesearch: failed to lookup addresses for %s: %s", host, err) <mask> <mask> return filtering.Result{}, err <mask> } <mask> <mask> if dRes != nil { </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove dRes, err := ss.newResult(rewrite, qtype) </s> add fltRes, err := ss.newResult(rewrite, qtype) </s> remove rewrite := ss.SearchHost(host, qtype) </s> add rewrite := ss.searchHost(host, qtype) </s> remove if dRes != nil { res = *dRes ss.setCacheResult(host, res) </s> add if fltRes != nil { res = *fltRes ss.setCacheResult(host, qtype, res) </s> remove log.Debug("safesearch: cache decoding: %s", err) </s> add ss.log(log.ERROR, "cache decoding: %s", err) </s> remove if log.GetLevel() >= log.DEBUG { timer := log.StartTimer() defer timer.LogElapsed("safesearch: lookup for %s", host) </s> add start := time.Now() defer func() { ss.log(log.DEBUG, "lookup for %q finished in %s", host, time.Since(start)) }() if qtype != dns.TypeA && qtype != dns.TypeAAAA { return filtering.Result{}, fmt.Errorf("unsupported question type %s", dns.Type(qtype)) </s> remove log.Error("safesearch: cache encoding: %s", err) </s> add ss.log(log.ERROR, "cache encoding: %s", err)
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch.go
keep keep keep keep replace replace replace keep keep keep keep keep
<mask> <mask> return filtering.Result{}, err <mask> } <mask> <mask> if dRes != nil { <mask> res = *dRes <mask> ss.setCacheResult(host, res) <mask> <mask> return res, nil <mask> } <mask> <mask> return filtering.Result{}, fmt.Errorf("no ipv4 addresses in safe search response for %s", host) </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove return filtering.Result{}, fmt.Errorf("no ipv4 addresses in safe search response for %s", host) </s> add return filtering.Result{}, fmt.Errorf("no ipv4 addresses for %q", host) </s> remove log.Debug("safesearch: failed to lookup addresses for %s: %s", host, err) </s> add ss.log(log.DEBUG, "looking up addresses for %q: %s", host, err) </s> remove // newResult creates Result object from rewrite rule. func (ss *DefaultSafeSearch) newResult( </s> add // searchHost looks up DNS rewrites in the internal DNS filtering engine. func (ss *Default) searchHost(host string, qtype rules.RRType) (res *rules.DNSRewrite) { ss.mu.RLock() defer ss.mu.RUnlock() if ss.engine == nil { return nil } r, _ := ss.engine.MatchRequest(&urlfilter.DNSRequest{ Hostname: strings.ToLower(host), DNSType: qtype, }) rewritesRules := r.DNSRewrites() if len(rewritesRules) > 0 { return rewritesRules[0].DNSRewrite } return nil } // newResult creates Result object from rewrite rule. qtype must be either // [dns.TypeA] or [dns.TypeAAAA]. func (ss *Default) newResult( </s> remove dRes, err := ss.newResult(rewrite, qtype) </s> add fltRes, err := ss.newResult(rewrite, qtype) </s> remove log.Debug("safesearch: cache decoding: %s", err) </s> add ss.log(log.ERROR, "cache decoding: %s", err) </s> remove if log.GetLevel() >= log.DEBUG { timer := log.StartTimer() defer timer.LogElapsed("safesearch: lookup for %s", host) </s> add start := time.Now() defer func() { ss.log(log.DEBUG, "lookup for %q finished in %s", host, time.Since(start)) }() if qtype != dns.TypeA && qtype != dns.TypeAAAA { return filtering.Result{}, fmt.Errorf("unsupported question type %s", dns.Type(qtype))
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch.go
keep keep keep keep replace keep keep keep keep keep
<mask> <mask> return res, nil <mask> } <mask> <mask> return filtering.Result{}, fmt.Errorf("no ipv4 addresses in safe search response for %s", host) <mask> } <mask> <mask> // newResult creates Result object from rewrite rule. <mask> func (ss *DefaultSafeSearch) newResult( <mask> rewrite *rules.DNSRewrite, </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove // newResult creates Result object from rewrite rule. func (ss *DefaultSafeSearch) newResult( </s> add // searchHost looks up DNS rewrites in the internal DNS filtering engine. func (ss *Default) searchHost(host string, qtype rules.RRType) (res *rules.DNSRewrite) { ss.mu.RLock() defer ss.mu.RUnlock() if ss.engine == nil { return nil } r, _ := ss.engine.MatchRequest(&urlfilter.DNSRequest{ Hostname: strings.ToLower(host), DNSType: qtype, }) rewritesRules := r.DNSRewrites() if len(rewritesRules) > 0 { return rewritesRules[0].DNSRewrite } return nil } // newResult creates Result object from rewrite rule. qtype must be either // [dns.TypeA] or [dns.TypeAAAA]. func (ss *Default) newResult( </s> remove qtype uint16, </s> add qtype rules.RRType, </s> remove if dRes != nil { res = *dRes ss.setCacheResult(host, res) </s> add if fltRes != nil { res = *fltRes ss.setCacheResult(host, qtype, res) </s> remove dRes, err := ss.newResult(rewrite, qtype) </s> add fltRes, err := ss.newResult(rewrite, qtype) </s> remove rewrite := ss.SearchHost(host, qtype) </s> add rewrite := ss.searchHost(host, qtype) </s> remove log.Debug("safesearch: found in cache: %s", host) </s> add ss.log(log.DEBUG, "found in cache: %q", host)
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch.go
keep keep keep replace replace keep replace keep
<mask> return filtering.Result{}, fmt.Errorf("no ipv4 addresses in safe search response for %s", host) <mask> } <mask> <mask> // newResult creates Result object from rewrite rule. <mask> func (ss *DefaultSafeSearch) newResult( <mask> rewrite *rules.DNSRewrite, <mask> qtype uint16, <mask> ) (res *filtering.Result, err error) { </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove return filtering.Result{}, fmt.Errorf("no ipv4 addresses in safe search response for %s", host) </s> add return filtering.Result{}, fmt.Errorf("no ipv4 addresses for %q", host) </s> remove if dRes != nil { res = *dRes ss.setCacheResult(host, res) </s> add if fltRes != nil { res = *fltRes ss.setCacheResult(host, qtype, res) </s> remove qtype uint16, </s> add qtype rules.RRType, </s> remove if log.GetLevel() >= log.DEBUG { timer := log.StartTimer() defer timer.LogElapsed("safesearch: lookup for %s", host) </s> add start := time.Now() defer func() { ss.log(log.DEBUG, "lookup for %q finished in %s", host, time.Since(start)) }() if qtype != dns.TypeA && qtype != dns.TypeAAAA { return filtering.Result{}, fmt.Errorf("unsupported question type %s", dns.Type(qtype)) </s> remove dRes, err := ss.newResult(rewrite, qtype) </s> add fltRes, err := ss.newResult(rewrite, qtype)
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch.go
keep keep keep keep replace keep keep keep keep keep
<mask> Reason: filtering.FilteredSafeSearch, <mask> IsFiltered: true, <mask> } <mask> <mask> if rewrite.RRType == qtype && (qtype == dns.TypeA || qtype == dns.TypeAAAA) { <mask> ip, ok := rewrite.Value.(net.IP) <mask> if !ok || ip == nil { <mask> return nil, nil <mask> } <mask> </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove if !setts.ProtectionEnabled || !setts.SafeSearchEnabled { </s> add if !setts.ProtectionEnabled || !setts.SafeSearchEnabled || (qtype != dns.TypeA && qtype != dns.TypeAAAA) { </s> remove if ip = ip.To4(); ip == nil { </s> add // TODO(a.garipov): Remove this filtering once the resolver we use // actually learns about network. ip = fitToProto(ip, qtype) if ip == nil { </s> remove if rewrite.NewCNAME == "" { </s> add host := rewrite.NewCNAME if host == "" { </s> remove // setCacheResult stores data in cache for host. func (ss *DefaultSafeSearch) setCacheResult(host string, res filtering.Result) { expire := uint32(time.Now().Add(ss.cacheTime).Unix()) </s> add // qtypeToProto returns "ip4" for [dns.TypeA] and "ip6" for [dns.TypeAAAA]. // It panics for other types. func qtypeToProto(qtype rules.RRType) (proto string) { switch qtype { case dns.TypeA: return "ip4" case dns.TypeAAAA: return "ip6" default: panic(fmt.Errorf("safesearch: unsupported question type %s", dns.Type(qtype))) } } // fitToProto returns a non-nil IP address if ip is the correct protocol version // for qtype. qtype is expected to be either [dns.TypeA] or [dns.TypeAAAA]. func fitToProto(ip net.IP, qtype rules.RRType) (res net.IP) { ip4 := ip.To4() if qtype == dns.TypeA { return ip4 } if ip4 == nil { return ip } return nil } // setCacheResult stores data in cache for host. qtype is expected to be either // [dns.TypeA] or [dns.TypeAAAA]. func (ss *Default) setCacheResult(host string, qtype rules.RRType, res filtering.Result) { expire := uint32(time.Now().Add(ss.cacheTTL).Unix()) </s> remove ips, err := ss.resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME) </s> add ss.log(log.DEBUG, "resolving %q", host) ips, err := ss.resolver.LookupIP(context.Background(), qtypeToProto(qtype), host) </s> remove rewrite := ss.SearchHost(host, qtype) </s> add rewrite := ss.searchHost(host, qtype)
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch.go
keep keep keep keep replace keep keep keep replace keep keep keep keep
<mask> <mask> return res, nil <mask> } <mask> <mask> if rewrite.NewCNAME == "" { <mask> return nil, nil <mask> } <mask> <mask> ips, err := ss.resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME) <mask> if err != nil { <mask> return nil, err <mask> } <mask> </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove var foundIP net.IP for _, ip := range ips { if ip.To4() != nil { foundIP = ip break } } res, err = ss.CheckHost(domain, dns.TypeA) </s> add res, err = ss.CheckHost("www.yandex.com", testQType) </s> remove dRes, err := ss.newResult(rewrite, qtype) </s> add fltRes, err := ss.newResult(rewrite, qtype) </s> remove cacheTime time.Duration, ) (ss *DefaultSafeSearch, err error) { engine, err := newEngine(filtering.SafeSearchListID, conf) if err != nil { return nil, err } </s> add cacheTTL time.Duration, ) (ss *Default, err error) { </s> remove c := jsonToClient(cj) </s> add c, err := clients.jsonToClient(cj) if err != nil { aghhttp.Error(r, w, http.StatusBadRequest, "%s", err) return } </s> remove if ip = ip.To4(); ip == nil { </s> add // TODO(a.garipov): Remove this filtering once the resolver we use // actually learns about network. ip = fitToProto(ip, qtype) if ip == nil {
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch.go
keep keep keep add keep keep keep keep
<mask> if err != nil { <mask> return nil, err <mask> } <mask> <mask> for _, ip := range ips { <mask> // TODO(a.garipov): Remove this filtering once the resolver we use <mask> // actually learns about network. <mask> ip = fitToProto(ip, qtype) </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove if ip = ip.To4(); ip == nil { </s> add // TODO(a.garipov): Remove this filtering once the resolver we use // actually learns about network. ip = fitToProto(ip, qtype) if ip == nil { </s> remove ips, err := ss.resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME) </s> add ss.log(log.DEBUG, "resolving %q", host) ips, err := ss.resolver.LookupIP(context.Background(), qtypeToProto(qtype), host) </s> remove var foundIP net.IP for _, ip := range ips { if ip.To4() != nil { foundIP = ip break } } res, err = ss.CheckHost(domain, dns.TypeA) </s> add res, err = ss.CheckHost("www.yandex.com", testQType) </s> remove resolver := &aghtest.TestResolver{} ss = newForTest(t, defaultSafeSearchConf) ss.resolver = resolver // Lookup for safesearch domain. rewrite := ss.SearchHost(domain, dns.TypeA) ips, err := resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME) </s> add err = ss.Update(filtering.SafeSearchConfig{ Enabled: false, Google: true, }) </s> add // // TODO(a.garipov): Support network. </s> remove dRes, err := ss.newResult(rewrite, qtype) </s> add fltRes, err := ss.newResult(rewrite, qtype)
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch.go
keep keep keep keep replace keep keep keep keep keep
<mask> return nil, err <mask> } <mask> <mask> for _, ip := range ips { <mask> if ip = ip.To4(); ip == nil { <mask> continue <mask> } <mask> <mask> res.Rules[0].IP = ip <mask> </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove ips, err := ss.resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME) </s> add ss.log(log.DEBUG, "resolving %q", host) ips, err := ss.resolver.LookupIP(context.Background(), qtypeToProto(qtype), host) </s> add ss.log(log.DEBUG, "resolved %s", ips) </s> remove var foundIP net.IP for _, ip := range ips { if ip.To4() != nil { foundIP = ip break } } res, err = ss.CheckHost(domain, dns.TypeA) </s> add res, err = ss.CheckHost("www.yandex.com", testQType) </s> remove if rewrite.RRType == qtype && (qtype == dns.TypeA || qtype == dns.TypeAAAA) { </s> add if rewrite.RRType == qtype { </s> remove resolver := &aghtest.TestResolver{} ss = newForTest(t, defaultSafeSearchConf) ss.resolver = resolver // Lookup for safesearch domain. rewrite := ss.SearchHost(domain, dns.TypeA) ips, err := resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME) </s> add err = ss.Update(filtering.SafeSearchConfig{ Enabled: false, Google: true, }) </s> remove clients := clientsContainer{ testing: true, } clients.Init(nil, nil, nil, nil, nil) </s> add clients := newClientsContainer()
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch.go
keep keep keep keep replace replace replace keep keep keep keep keep
<mask> <mask> return nil, nil <mask> } <mask> <mask> // setCacheResult stores data in cache for host. <mask> func (ss *DefaultSafeSearch) setCacheResult(host string, res filtering.Result) { <mask> expire := uint32(time.Now().Add(ss.cacheTime).Unix()) <mask> exp := make([]byte, 4) <mask> binary.BigEndian.PutUint32(exp, expire) <mask> buf := bytes.NewBuffer(exp) <mask> <mask> err := gob.NewEncoder(buf).Encode(res) </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove data := ss.safeSearchCache.Get([]byte(host)) </s> add data := ss.cache.Get([]byte(dns.Type(qtype).String() + " " + host)) </s> remove log.Error("safesearch: cache encoding: %s", err) </s> add ss.log(log.ERROR, "cache encoding: %s", err) </s> remove // getCachedResult returns stored data from cache for host. func (ss *DefaultSafeSearch) getCachedResult(host string) (res filtering.Result, ok bool) { </s> add // getCachedResult returns stored data from cache for host. qtype is expected // to be either [dns.TypeA] or [dns.TypeAAAA]. func (ss *Default) getCachedResult( host string, qtype rules.RRType, ) (res filtering.Result, ok bool) { </s> remove log.Debug("safesearch: stored in cache: %s (%d bytes)", host, len(val)) </s> add ss.log(log.DEBUG, "stored in cache: %q, %d bytes", host, len(val)) </s> remove ss.safeSearchCache.Del([]byte(host)) </s> add ss.cache.Del([]byte(host)) </s> remove _ = ss.safeSearchCache.Set([]byte(host), val) </s> add _ = ss.cache.Set([]byte(dns.Type(qtype).String()+" "+host), val)
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch.go
keep keep keep keep replace keep keep keep keep keep
<mask> buf := bytes.NewBuffer(exp) <mask> <mask> err := gob.NewEncoder(buf).Encode(res) <mask> if err != nil { <mask> log.Error("safesearch: cache encoding: %s", err) <mask> <mask> return <mask> } <mask> <mask> val := buf.Bytes() </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove log.Debug("safesearch: cache decoding: %s", err) </s> add ss.log(log.ERROR, "cache decoding: %s", err) </s> remove // setCacheResult stores data in cache for host. func (ss *DefaultSafeSearch) setCacheResult(host string, res filtering.Result) { expire := uint32(time.Now().Add(ss.cacheTime).Unix()) </s> add // qtypeToProto returns "ip4" for [dns.TypeA] and "ip6" for [dns.TypeAAAA]. // It panics for other types. func qtypeToProto(qtype rules.RRType) (proto string) { switch qtype { case dns.TypeA: return "ip4" case dns.TypeAAAA: return "ip6" default: panic(fmt.Errorf("safesearch: unsupported question type %s", dns.Type(qtype))) } } // fitToProto returns a non-nil IP address if ip is the correct protocol version // for qtype. qtype is expected to be either [dns.TypeA] or [dns.TypeAAAA]. func fitToProto(ip net.IP, qtype rules.RRType) (res net.IP) { ip4 := ip.To4() if qtype == dns.TypeA { return ip4 } if ip4 == nil { return ip } return nil } // setCacheResult stores data in cache for host. qtype is expected to be either // [dns.TypeA] or [dns.TypeAAAA]. func (ss *Default) setCacheResult(host string, qtype rules.RRType, res filtering.Result) { expire := uint32(time.Now().Add(ss.cacheTTL).Unix()) </s> remove dRes, err := ss.newResult(rewrite, qtype) </s> add fltRes, err := ss.newResult(rewrite, qtype) </s> remove c := jsonToClient(cj) </s> add c, err := clients.jsonToClient(cj) if err != nil { aghhttp.Error(r, w, http.StatusBadRequest, "%s", err) return } </s> remove _ = ss.safeSearchCache.Set([]byte(host), val) </s> add _ = ss.cache.Set([]byte(dns.Type(qtype).String()+" "+host), val) </s> remove log.Debug("safesearch: failed to lookup addresses for %s: %s", host, err) </s> add ss.log(log.DEBUG, "looking up addresses for %q: %s", host, err)
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch.go
keep keep keep keep replace keep keep keep keep keep
<mask> return <mask> } <mask> <mask> val := buf.Bytes() <mask> _ = ss.safeSearchCache.Set([]byte(host), val) <mask> <mask> log.Debug("safesearch: stored in cache: %s (%d bytes)", host, len(val)) <mask> } <mask> <mask> // getCachedResult returns stored data from cache for host. </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove log.Debug("safesearch: stored in cache: %s (%d bytes)", host, len(val)) </s> add ss.log(log.DEBUG, "stored in cache: %q, %d bytes", host, len(val)) </s> remove // getCachedResult returns stored data from cache for host. func (ss *DefaultSafeSearch) getCachedResult(host string) (res filtering.Result, ok bool) { </s> add // getCachedResult returns stored data from cache for host. qtype is expected // to be either [dns.TypeA] or [dns.TypeAAAA]. func (ss *Default) getCachedResult( host string, qtype rules.RRType, ) (res filtering.Result, ok bool) { </s> remove data := ss.safeSearchCache.Get([]byte(host)) </s> add data := ss.cache.Get([]byte(dns.Type(qtype).String() + " " + host)) </s> remove log.Error("safesearch: cache encoding: %s", err) </s> add ss.log(log.ERROR, "cache encoding: %s", err) </s> remove // setCacheResult stores data in cache for host. func (ss *DefaultSafeSearch) setCacheResult(host string, res filtering.Result) { expire := uint32(time.Now().Add(ss.cacheTime).Unix()) </s> add // qtypeToProto returns "ip4" for [dns.TypeA] and "ip6" for [dns.TypeAAAA]. // It panics for other types. func qtypeToProto(qtype rules.RRType) (proto string) { switch qtype { case dns.TypeA: return "ip4" case dns.TypeAAAA: return "ip6" default: panic(fmt.Errorf("safesearch: unsupported question type %s", dns.Type(qtype))) } } // fitToProto returns a non-nil IP address if ip is the correct protocol version // for qtype. qtype is expected to be either [dns.TypeA] or [dns.TypeAAAA]. func fitToProto(ip net.IP, qtype rules.RRType) (res net.IP) { ip4 := ip.To4() if qtype == dns.TypeA { return ip4 } if ip4 == nil { return ip } return nil } // setCacheResult stores data in cache for host. qtype is expected to be either // [dns.TypeA] or [dns.TypeAAAA]. func (ss *Default) setCacheResult(host string, qtype rules.RRType, res filtering.Result) { expire := uint32(time.Now().Add(ss.cacheTTL).Unix()) </s> remove log.Debug("safesearch: found in cache: %s", host) </s> add ss.log(log.DEBUG, "found in cache: %q", host)
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch.go
keep keep keep keep replace keep keep keep keep keep
<mask> <mask> val := buf.Bytes() <mask> _ = ss.safeSearchCache.Set([]byte(host), val) <mask> <mask> log.Debug("safesearch: stored in cache: %s (%d bytes)", host, len(val)) <mask> } <mask> <mask> // getCachedResult returns stored data from cache for host. <mask> func (ss *DefaultSafeSearch) getCachedResult(host string) (res filtering.Result, ok bool) { <mask> res = filtering.Result{} </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove _ = ss.safeSearchCache.Set([]byte(host), val) </s> add _ = ss.cache.Set([]byte(dns.Type(qtype).String()+" "+host), val) </s> remove // getCachedResult returns stored data from cache for host. func (ss *DefaultSafeSearch) getCachedResult(host string) (res filtering.Result, ok bool) { </s> add // getCachedResult returns stored data from cache for host. qtype is expected // to be either [dns.TypeA] or [dns.TypeAAAA]. func (ss *Default) getCachedResult( host string, qtype rules.RRType, ) (res filtering.Result, ok bool) { </s> remove data := ss.safeSearchCache.Get([]byte(host)) </s> add data := ss.cache.Get([]byte(dns.Type(qtype).String() + " " + host)) </s> remove // setCacheResult stores data in cache for host. func (ss *DefaultSafeSearch) setCacheResult(host string, res filtering.Result) { expire := uint32(time.Now().Add(ss.cacheTime).Unix()) </s> add // qtypeToProto returns "ip4" for [dns.TypeA] and "ip6" for [dns.TypeAAAA]. // It panics for other types. func qtypeToProto(qtype rules.RRType) (proto string) { switch qtype { case dns.TypeA: return "ip4" case dns.TypeAAAA: return "ip6" default: panic(fmt.Errorf("safesearch: unsupported question type %s", dns.Type(qtype))) } } // fitToProto returns a non-nil IP address if ip is the correct protocol version // for qtype. qtype is expected to be either [dns.TypeA] or [dns.TypeAAAA]. func fitToProto(ip net.IP, qtype rules.RRType) (res net.IP) { ip4 := ip.To4() if qtype == dns.TypeA { return ip4 } if ip4 == nil { return ip } return nil } // setCacheResult stores data in cache for host. qtype is expected to be either // [dns.TypeA] or [dns.TypeAAAA]. func (ss *Default) setCacheResult(host string, qtype rules.RRType, res filtering.Result) { expire := uint32(time.Now().Add(ss.cacheTTL).Unix()) </s> remove // newResult creates Result object from rewrite rule. func (ss *DefaultSafeSearch) newResult( </s> add // searchHost looks up DNS rewrites in the internal DNS filtering engine. func (ss *Default) searchHost(host string, qtype rules.RRType) (res *rules.DNSRewrite) { ss.mu.RLock() defer ss.mu.RUnlock() if ss.engine == nil { return nil } r, _ := ss.engine.MatchRequest(&urlfilter.DNSRequest{ Hostname: strings.ToLower(host), DNSType: qtype, }) rewritesRules := r.DNSRewrites() if len(rewritesRules) > 0 { return rewritesRules[0].DNSRewrite } return nil } // newResult creates Result object from rewrite rule. qtype must be either // [dns.TypeA] or [dns.TypeAAAA]. func (ss *Default) newResult( </s> remove log.Error("safesearch: cache encoding: %s", err) </s> add ss.log(log.ERROR, "cache encoding: %s", err)
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch.go
keep keep keep replace replace keep keep replace keep keep keep
<mask> log.Debug("safesearch: stored in cache: %s (%d bytes)", host, len(val)) <mask> } <mask> <mask> // getCachedResult returns stored data from cache for host. <mask> func (ss *DefaultSafeSearch) getCachedResult(host string) (res filtering.Result, ok bool) { <mask> res = filtering.Result{} <mask> <mask> data := ss.safeSearchCache.Get([]byte(host)) <mask> if data == nil { <mask> return res, false <mask> } </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove log.Debug("safesearch: stored in cache: %s (%d bytes)", host, len(val)) </s> add ss.log(log.DEBUG, "stored in cache: %q, %d bytes", host, len(val)) </s> remove _ = ss.safeSearchCache.Set([]byte(host), val) </s> add _ = ss.cache.Set([]byte(dns.Type(qtype).String()+" "+host), val) </s> remove // setCacheResult stores data in cache for host. func (ss *DefaultSafeSearch) setCacheResult(host string, res filtering.Result) { expire := uint32(time.Now().Add(ss.cacheTime).Unix()) </s> add // qtypeToProto returns "ip4" for [dns.TypeA] and "ip6" for [dns.TypeAAAA]. // It panics for other types. func qtypeToProto(qtype rules.RRType) (proto string) { switch qtype { case dns.TypeA: return "ip4" case dns.TypeAAAA: return "ip6" default: panic(fmt.Errorf("safesearch: unsupported question type %s", dns.Type(qtype))) } } // fitToProto returns a non-nil IP address if ip is the correct protocol version // for qtype. qtype is expected to be either [dns.TypeA] or [dns.TypeAAAA]. func fitToProto(ip net.IP, qtype rules.RRType) (res net.IP) { ip4 := ip.To4() if qtype == dns.TypeA { return ip4 } if ip4 == nil { return ip } return nil } // setCacheResult stores data in cache for host. qtype is expected to be either // [dns.TypeA] or [dns.TypeAAAA]. func (ss *Default) setCacheResult(host string, qtype rules.RRType, res filtering.Result) { expire := uint32(time.Now().Add(ss.cacheTTL).Unix()) </s> remove // newResult creates Result object from rewrite rule. func (ss *DefaultSafeSearch) newResult( </s> add // searchHost looks up DNS rewrites in the internal DNS filtering engine. func (ss *Default) searchHost(host string, qtype rules.RRType) (res *rules.DNSRewrite) { ss.mu.RLock() defer ss.mu.RUnlock() if ss.engine == nil { return nil } r, _ := ss.engine.MatchRequest(&urlfilter.DNSRequest{ Hostname: strings.ToLower(host), DNSType: qtype, }) rewritesRules := r.DNSRewrites() if len(rewritesRules) > 0 { return rewritesRules[0].DNSRewrite } return nil } // newResult creates Result object from rewrite rule. qtype must be either // [dns.TypeA] or [dns.TypeAAAA]. func (ss *Default) newResult( </s> remove log.Debug("safesearch: cache decoding: %s", err) </s> add ss.log(log.ERROR, "cache decoding: %s", err)
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch.go
keep keep keep keep replace keep keep keep keep keep
<mask> } <mask> <mask> exp := binary.BigEndian.Uint32(data[:4]) <mask> if exp <= uint32(time.Now().Unix()) { <mask> ss.safeSearchCache.Del([]byte(host)) <mask> <mask> return res, false <mask> } <mask> <mask> buf := bytes.NewBuffer(data[4:]) </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove data := ss.safeSearchCache.Get([]byte(host)) </s> add data := ss.cache.Get([]byte(dns.Type(qtype).String() + " " + host)) </s> remove log.Debug("safesearch: cache decoding: %s", err) </s> add ss.log(log.ERROR, "cache decoding: %s", err) </s> remove // setCacheResult stores data in cache for host. func (ss *DefaultSafeSearch) setCacheResult(host string, res filtering.Result) { expire := uint32(time.Now().Add(ss.cacheTime).Unix()) </s> add // qtypeToProto returns "ip4" for [dns.TypeA] and "ip6" for [dns.TypeAAAA]. // It panics for other types. func qtypeToProto(qtype rules.RRType) (proto string) { switch qtype { case dns.TypeA: return "ip4" case dns.TypeAAAA: return "ip6" default: panic(fmt.Errorf("safesearch: unsupported question type %s", dns.Type(qtype))) } } // fitToProto returns a non-nil IP address if ip is the correct protocol version // for qtype. qtype is expected to be either [dns.TypeA] or [dns.TypeAAAA]. func fitToProto(ip net.IP, qtype rules.RRType) (res net.IP) { ip4 := ip.To4() if qtype == dns.TypeA { return ip4 } if ip4 == nil { return ip } return nil } // setCacheResult stores data in cache for host. qtype is expected to be either // [dns.TypeA] or [dns.TypeAAAA]. func (ss *Default) setCacheResult(host string, qtype rules.RRType, res filtering.Result) { expire := uint32(time.Now().Add(ss.cacheTTL).Unix()) </s> remove log.Error("safesearch: cache encoding: %s", err) </s> add ss.log(log.ERROR, "cache encoding: %s", err) </s> remove if rewrite.NewCNAME == "" { </s> add host := rewrite.NewCNAME if host == "" { </s> remove var foundIP net.IP for _, ip := range ips { if ip.To4() != nil { foundIP = ip break } } res, err = ss.CheckHost(domain, dns.TypeA) </s> add res, err = ss.CheckHost("www.yandex.com", testQType)
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch.go
keep keep keep keep replace keep keep keep keep keep
<mask> buf := bytes.NewBuffer(data[4:]) <mask> <mask> err := gob.NewDecoder(buf).Decode(&res) <mask> if err != nil { <mask> log.Debug("safesearch: cache decoding: %s", err) <mask> <mask> return filtering.Result{}, false <mask> } <mask> <mask> return res, true </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove ss.safeSearchCache.Del([]byte(host)) </s> add ss.cache.Del([]byte(host)) </s> remove log.Error("safesearch: cache encoding: %s", err) </s> add ss.log(log.ERROR, "cache encoding: %s", err) </s> remove dRes, err := ss.newResult(rewrite, qtype) </s> add fltRes, err := ss.newResult(rewrite, qtype) </s> remove log.Debug("safesearch: failed to lookup addresses for %s: %s", host, err) </s> add ss.log(log.DEBUG, "looking up addresses for %q: %s", host, err) </s> remove if dRes != nil { res = *dRes ss.setCacheResult(host, res) </s> add if fltRes != nil { res = *fltRes ss.setCacheResult(host, qtype, res) </s> remove c := jsonToClient(cj) </s> add c, err := clients.jsonToClient(cj) if err != nil { aghhttp.Error(r, w, http.StatusBadRequest, "%s", err) return }
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch.go
replace keep keep replace keep keep keep keep keep
<mask> package safesearch <mask> <mask> import ( <mask> "context" <mask> "net" <mask> "testing" <mask> "time" <mask> <mask> "github.com/AdguardTeam/AdGuardHome/internal/aghtest" </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> add "time" </s> remove import ( "github.com/AdguardTeam/urlfilter/rules" "github.com/miekg/dns" ) </s> add import "github.com/miekg/dns" </s> remove "github.com/AdguardTeam/urlfilter/rules" </s> add "github.com/AdguardTeam/AdGuardHome/internal/filtering/safesearch" "github.com/AdguardTeam/golibs/testutil" </s> add "github.com/AdguardTeam/AdGuardHome/internal/filtering" </s> add "sync"
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> "time" <mask> <mask> "github.com/AdguardTeam/AdGuardHome/internal/aghtest" <mask> "github.com/AdguardTeam/AdGuardHome/internal/filtering" <mask> "github.com/AdguardTeam/urlfilter/rules" <mask> "github.com/miekg/dns" <mask> "github.com/stretchr/testify/assert" <mask> "github.com/stretchr/testify/require" <mask> ) <mask> </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> add "github.com/AdguardTeam/AdGuardHome/internal/filtering" </s> remove "context" </s> add </s> add "time" </s> remove import ( "github.com/AdguardTeam/urlfilter/rules" "github.com/miekg/dns" ) </s> add import "github.com/miekg/dns" </s> add "sync" </s> add func TestMain(m *testing.M) { testutil.DiscardLogOutput(m) } // Common test constants.
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch_test.go
keep keep keep add keep keep keep keep
<mask> "github.com/stretchr/testify/assert" <mask> "github.com/stretchr/testify/require" <mask> ) <mask> <mask> const ( <mask> // TODO(a.garipov): Add IPv6 tests. <mask> testQType = dns.TypeA <mask> testCacheSize = 5000 </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove safeSearchCacheSize = 5000 cacheTime = 30 * time.Minute </s> add // TODO(a.garipov): Add IPv6 tests. testQType = dns.TypeA testCacheSize = 5000 testCacheTTL = 30 * time.Minute </s> add "github.com/AdguardTeam/AdGuardHome/internal/filtering" </s> remove func TestClients(t *testing.T) { clients := clientsContainer{} clients.testing = true </s> add // newClientsContainer is a helper that creates a new clients container for // tests. func newClientsContainer() (c *clientsContainer) { c = &clientsContainer{ testing: true, } c.Init(nil, nil, nil, nil, &filtering.Config{}) </s> remove "github.com/AdguardTeam/urlfilter/rules" </s> add "github.com/AdguardTeam/AdGuardHome/internal/filtering/safesearch" "github.com/AdguardTeam/golibs/testutil" </s> remove var defaultSafeSearchConf = filtering.SafeSearchConfig{ Enabled: true, </s> add // testConf is the default safe search configuration for tests. var testConf = filtering.SafeSearchConfig{ CustomResolver: nil, Enabled: true, </s> add // // TODO(a.garipov): Support network.
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch_test.go
keep replace replace keep keep replace replace keep keep keep
<mask> const ( <mask> safeSearchCacheSize = 5000 <mask> cacheTime = 30 * time.Minute <mask> ) <mask> <mask> var defaultSafeSearchConf = filtering.SafeSearchConfig{ <mask> Enabled: true, <mask> Bing: true, <mask> DuckDuckGo: true, <mask> Google: true, </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove resolver := &aghtest.TestResolver{} ss = newForTest(t, defaultSafeSearchConf) ss.resolver = resolver // Lookup for safesearch domain. rewrite := ss.SearchHost(domain, dns.TypeA) ips, err := resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME) </s> add err = ss.Update(filtering.SafeSearchConfig{ Enabled: false, Google: true, }) </s> remove assert.Equal(t, res.Rules[0].IP, yandexIP) // Check cache. cachedValue, isFound := ss.getCachedResult(domain) require.True(t, isFound) require.Len(t, cachedValue.Rules, 1) assert.Equal(t, cachedValue.Rules[0].IP, yandexIP) } func TestSafeSearchCacheGoogle(t *testing.T) { const domain = "www.google.ru" ss := newForTest(t, filtering.SafeSearchConfig{Enabled: false}) </s> add err = ss.Update(filtering.SafeSearchConfig{ Enabled: true, Google: false, }) require.NoError(t, err) </s> add func TestMain(m *testing.M) { testutil.DiscardLogOutput(m) } // Common test constants. </s> remove func TestClients(t *testing.T) { clients := clientsContainer{} clients.testing = true </s> add // newClientsContainer is a helper that creates a new clients container for // tests. func newClientsContainer() (c *clientsContainer) { c = &clientsContainer{ testing: true, } c.Init(nil, nil, nil, nil, &filtering.Config{}) </s> add // yandexIP is the expected IP address of Yandex safe search results. Keep in // sync with the rules data.
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch_test.go
keep keep add keep keep keep keep
<mask> YouTube: true, <mask> } <mask> <mask> var yandexIP = net.IPv4(213, 180, 193, 56) <mask> <mask> func TestDefault_CheckHost_yandex(t *testing.T) { <mask> conf := testConf </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove func newForTest(t testing.TB, ssConf filtering.SafeSearchConfig) (ss *DefaultSafeSearch) { ss, err := NewDefaultSafeSearch(ssConf, safeSearchCacheSize, cacheTime) </s> add func TestDefault_CheckHost_yandex(t *testing.T) { conf := testConf ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL) </s> remove func TestSafeSearchCacheYandex(t *testing.T) { const domain = "yandex.ru" ss := newForTest(t, filtering.SafeSearchConfig{Enabled: false}) // Check host with disabled safesearch. res, err := ss.CheckHost(domain, dns.TypeA) </s> add func TestDefault_Update(t *testing.T) { conf := testConf ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL) </s> remove var defaultSafeSearchConf = filtering.SafeSearchConfig{ Enabled: true, </s> add // testConf is the default safe search configuration for tests. var testConf = filtering.SafeSearchConfig{ CustomResolver: nil, Enabled: true, </s> remove clients := clientsContainer{ testing: true, } clients.Init(nil, nil, nil, nil, nil) </s> add clients := newClientsContainer() </s> remove ss := newForTest(t, defaultSafeSearchConf) ss.resolver = resolver </s> add conf := testConf conf.CustomResolver = resolver ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL) require.NoError(t, err) </s> remove clients.Init(nil, nil, nil, nil, nil) </s> add return c } func TestClients(t *testing.T) { clients := newClientsContainer()
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch_test.go
keep keep keep keep replace replace keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep keep
<mask> } <mask> <mask> var yandexIP = net.IPv4(213, 180, 193, 56) <mask> <mask> func newForTest(t testing.TB, ssConf filtering.SafeSearchConfig) (ss *DefaultSafeSearch) { <mask> ss, err := NewDefaultSafeSearch(ssConf, safeSearchCacheSize, cacheTime) <mask> require.NoError(t, err) <mask> <mask> return ss <mask> } <mask> <mask> func TestSafeSearch(t *testing.T) { <mask> ss := newForTest(t, defaultSafeSearchConf) <mask> val := ss.SearchHost("www.google.com", dns.TypeA) <mask> <mask> assert.Equal(t, &rules.DNSRewrite{NewCNAME: "forcesafesearch.google.com"}, val) <mask> } <mask> <mask> func TestCheckHostSafeSearchYandex(t *testing.T) { <mask> ss := newForTest(t, defaultSafeSearchConf) <mask> <mask> // Check host for each domain. <mask> for _, host := range []string{ <mask> "yandex.ru", </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove ss := newForTest(t, defaultSafeSearchConf) ss.resolver = resolver </s> add conf := testConf conf.CustomResolver = resolver ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL) require.NoError(t, err) </s> remove func TestSafeSearchCacheYandex(t *testing.T) { const domain = "yandex.ru" ss := newForTest(t, filtering.SafeSearchConfig{Enabled: false}) // Check host with disabled safesearch. res, err := ss.CheckHost(domain, dns.TypeA) </s> add func TestDefault_Update(t *testing.T) { conf := testConf ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL) </s> remove func TestCheckHostSafeSearchGoogle(t *testing.T) { </s> add func TestDefault_CheckHost_google(t *testing.T) { </s> add // yandexIP is the expected IP address of Yandex safe search results. Keep in // sync with the rules data. </s> remove resolver := &aghtest.TestResolver{} ss = newForTest(t, defaultSafeSearchConf) ss.resolver = resolver // Lookup for safesearch domain. rewrite := ss.SearchHost(domain, dns.TypeA) ips, err := resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME) </s> add err = ss.Update(filtering.SafeSearchConfig{ Enabled: false, Google: true, })
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> "yandex.by", <mask> "yandex.kz", <mask> "www.yandex.com", <mask> } { <mask> res, err := ss.CheckHost(host, dns.TypeA) <mask> require.NoError(t, err) <mask> <mask> assert.True(t, res.IsFiltered) <mask> <mask> require.Len(t, res.Rules, 1) </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove res, err := ss.CheckHost(host, dns.TypeA) </s> add var res filtering.Result res, err = ss.CheckHost(host, testQType) </s> remove require.Len(t, res.Rules, 1) assert.True(t, res.Rules[0].IP.Equal(foundIP)) // Check cache. cachedValue, isFound := ss.getCachedResult(domain) require.True(t, isFound) require.Len(t, cachedValue.Rules, 1) assert.True(t, cachedValue.Rules[0].IP.Equal(foundIP)) } const googleHost = "www.google.com" </s> add </s> remove var foundIP net.IP for _, ip := range ips { if ip.To4() != nil { foundIP = ip break } } res, err = ss.CheckHost(domain, dns.TypeA) </s> add res, err = ss.CheckHost("www.yandex.com", testQType) </s> remove // For yandex we already know valid IP. require.Len(t, res.Rules, 1) </s> add assert.True(t, res.IsFiltered) </s> remove assert.False(t, res.IsFiltered) assert.Empty(t, res.Rules) ss = newForTest(t, defaultSafeSearchConf) res, err = ss.CheckHost(domain, dns.TypeA) </s> add res, err := ss.CheckHost("www.yandex.com", testQType) </s> remove assert.Equal(t, res.Rules[0].IP, yandexIP) // Check cache. cachedValue, isFound := ss.getCachedResult(domain) require.True(t, isFound) require.Len(t, cachedValue.Rules, 1) assert.Equal(t, cachedValue.Rules[0].IP, yandexIP) } func TestSafeSearchCacheGoogle(t *testing.T) { const domain = "www.google.ru" ss := newForTest(t, filtering.SafeSearchConfig{Enabled: false}) </s> add err = ss.Update(filtering.SafeSearchConfig{ Enabled: true, Google: false, }) require.NoError(t, err)
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch_test.go
keep replace keep keep keep replace replace keep
<mask> <mask> func TestCheckHostSafeSearchGoogle(t *testing.T) { <mask> resolver := &aghtest.TestResolver{} <mask> ip, _ := resolver.HostToIPs("forcesafesearch.google.com") <mask> <mask> ss := newForTest(t, defaultSafeSearchConf) <mask> ss.resolver = resolver <mask> </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove assert.Empty(t, res.Rules) </s> add </s> remove resolver := &aghtest.TestResolver{} ss = newForTest(t, defaultSafeSearchConf) ss.resolver = resolver // Lookup for safesearch domain. rewrite := ss.SearchHost(domain, dns.TypeA) ips, err := resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME) </s> add err = ss.Update(filtering.SafeSearchConfig{ Enabled: false, Google: true, }) </s> remove return ss } func TestSafeSearch(t *testing.T) { ss := newForTest(t, defaultSafeSearchConf) val := ss.SearchHost("www.google.com", dns.TypeA) assert.Equal(t, &rules.DNSRewrite{NewCNAME: "forcesafesearch.google.com"}, val) } func TestCheckHostSafeSearchYandex(t *testing.T) { ss := newForTest(t, defaultSafeSearchConf) </s> add </s> remove func TestSafeSearchCacheYandex(t *testing.T) { const domain = "yandex.ru" ss := newForTest(t, filtering.SafeSearchConfig{Enabled: false}) // Check host with disabled safesearch. res, err := ss.CheckHost(domain, dns.TypeA) </s> add func TestDefault_Update(t *testing.T) { conf := testConf ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL) </s> remove var dnsRewriteSink *rules.DNSRewrite func BenchmarkSafeSearch(b *testing.B) { ss := newForTest(b, defaultSafeSearchConf) for n := 0; n < b.N; n++ { dnsRewriteSink = ss.SearchHost(googleHost, dns.TypeA) } assert.Equal(b, "forcesafesearch.google.com", dnsRewriteSink.NewCNAME) } var dnsRewriteParallelSink *rules.DNSRewrite func BenchmarkSafeSearch_parallel(b *testing.B) { ss := newForTest(b, defaultSafeSearchConf) b.RunParallel(func(pb *testing.PB) { for pb.Next() { dnsRewriteParallelSink = ss.SearchHost(googleHost, dns.TypeA) } }) assert.Equal(b, "forcesafesearch.google.com", dnsRewriteParallelSink.NewCNAME) </s> add assert.False(t, res.IsFiltered)
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> "www.google.it", <mask> "www.google.je", <mask> } { <mask> t.Run(host, func(t *testing.T) { <mask> res, err := ss.CheckHost(host, dns.TypeA) <mask> require.NoError(t, err) <mask> <mask> assert.True(t, res.IsFiltered) <mask> <mask> require.Len(t, res.Rules, 1) </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove res, err := ss.CheckHost(host, dns.TypeA) </s> add var res filtering.Result res, err = ss.CheckHost(host, testQType) </s> remove require.Len(t, res.Rules, 1) assert.True(t, res.Rules[0].IP.Equal(foundIP)) // Check cache. cachedValue, isFound := ss.getCachedResult(domain) require.True(t, isFound) require.Len(t, cachedValue.Rules, 1) assert.True(t, cachedValue.Rules[0].IP.Equal(foundIP)) } const googleHost = "www.google.com" </s> add </s> remove var foundIP net.IP for _, ip := range ips { if ip.To4() != nil { foundIP = ip break } } res, err = ss.CheckHost(domain, dns.TypeA) </s> add res, err = ss.CheckHost("www.yandex.com", testQType) </s> remove // For yandex we already know valid IP. require.Len(t, res.Rules, 1) </s> add assert.True(t, res.IsFiltered) </s> remove assert.Equal(t, res.Rules[0].IP, yandexIP) // Check cache. cachedValue, isFound := ss.getCachedResult(domain) require.True(t, isFound) require.Len(t, cachedValue.Rules, 1) assert.Equal(t, cachedValue.Rules[0].IP, yandexIP) } func TestSafeSearchCacheGoogle(t *testing.T) { const domain = "www.google.ru" ss := newForTest(t, filtering.SafeSearchConfig{Enabled: false}) </s> add err = ss.Update(filtering.SafeSearchConfig{ Enabled: true, Google: false, }) require.NoError(t, err) </s> remove assert.False(t, res.IsFiltered) assert.Empty(t, res.Rules) ss = newForTest(t, defaultSafeSearchConf) res, err = ss.CheckHost(domain, dns.TypeA) </s> add res, err := ss.CheckHost("www.yandex.com", testQType)
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch_test.go
keep keep replace replace replace replace replace replace replace keep keep replace replace replace replace replace keep keep keep
<mask> } <mask> <mask> func TestSafeSearchCacheYandex(t *testing.T) { <mask> const domain = "yandex.ru" <mask> <mask> ss := newForTest(t, filtering.SafeSearchConfig{Enabled: false}) <mask> <mask> // Check host with disabled safesearch. <mask> res, err := ss.CheckHost(domain, dns.TypeA) <mask> require.NoError(t, err) <mask> <mask> assert.False(t, res.IsFiltered) <mask> assert.Empty(t, res.Rules) <mask> <mask> ss = newForTest(t, defaultSafeSearchConf) <mask> res, err = ss.CheckHost(domain, dns.TypeA) <mask> require.NoError(t, err) <mask> <mask> // For yandex we already know valid IP. </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove res, err := ss.CheckHost(domain, dns.TypeA) </s> add res, err = ss.CheckHost("www.yandex.com", testQType) </s> remove assert.Equal(t, res.Rules[0].IP, yandexIP) // Check cache. cachedValue, isFound := ss.getCachedResult(domain) require.True(t, isFound) require.Len(t, cachedValue.Rules, 1) assert.Equal(t, cachedValue.Rules[0].IP, yandexIP) } func TestSafeSearchCacheGoogle(t *testing.T) { const domain = "www.google.ru" ss := newForTest(t, filtering.SafeSearchConfig{Enabled: false}) </s> add err = ss.Update(filtering.SafeSearchConfig{ Enabled: true, Google: false, }) require.NoError(t, err) </s> remove // For yandex we already know valid IP. require.Len(t, res.Rules, 1) </s> add assert.True(t, res.IsFiltered) </s> remove assert.Empty(t, res.Rules) </s> add </s> remove return ss } func TestSafeSearch(t *testing.T) { ss := newForTest(t, defaultSafeSearchConf) val := ss.SearchHost("www.google.com", dns.TypeA) assert.Equal(t, &rules.DNSRewrite{NewCNAME: "forcesafesearch.google.com"}, val) } func TestCheckHostSafeSearchYandex(t *testing.T) { ss := newForTest(t, defaultSafeSearchConf) </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch_test.go
keep keep keep keep replace replace keep keep keep keep keep
<mask> ss = newForTest(t, defaultSafeSearchConf) <mask> res, err = ss.CheckHost(domain, dns.TypeA) <mask> require.NoError(t, err) <mask> <mask> // For yandex we already know valid IP. <mask> require.Len(t, res.Rules, 1) <mask> <mask> assert.Equal(t, res.Rules[0].IP, yandexIP) <mask> <mask> // Check cache. <mask> cachedValue, isFound := ss.getCachedResult(domain) </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove assert.Equal(t, res.Rules[0].IP, yandexIP) // Check cache. cachedValue, isFound := ss.getCachedResult(domain) require.True(t, isFound) require.Len(t, cachedValue.Rules, 1) assert.Equal(t, cachedValue.Rules[0].IP, yandexIP) } func TestSafeSearchCacheGoogle(t *testing.T) { const domain = "www.google.ru" ss := newForTest(t, filtering.SafeSearchConfig{Enabled: false}) </s> add err = ss.Update(filtering.SafeSearchConfig{ Enabled: true, Google: false, }) require.NoError(t, err) </s> remove assert.False(t, res.IsFiltered) assert.Empty(t, res.Rules) ss = newForTest(t, defaultSafeSearchConf) res, err = ss.CheckHost(domain, dns.TypeA) </s> add res, err := ss.CheckHost("www.yandex.com", testQType) </s> remove require.Len(t, res.Rules, 1) assert.True(t, res.Rules[0].IP.Equal(foundIP)) // Check cache. cachedValue, isFound := ss.getCachedResult(domain) require.True(t, isFound) require.Len(t, cachedValue.Rules, 1) assert.True(t, cachedValue.Rules[0].IP.Equal(foundIP)) } const googleHost = "www.google.com" </s> add </s> remove assert.Empty(t, res.Rules) </s> add </s> remove res, err := ss.CheckHost(host, dns.TypeA) </s> add var res filtering.Result res, err = ss.CheckHost(host, testQType) </s> remove var foundIP net.IP for _, ip := range ips { if ip.To4() != nil { foundIP = ip break } } res, err = ss.CheckHost(domain, dns.TypeA) </s> add res, err = ss.CheckHost("www.yandex.com", testQType)
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch_test.go
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep replace keep keep keep
<mask> <mask> // For yandex we already know valid IP. <mask> require.Len(t, res.Rules, 1) <mask> <mask> assert.Equal(t, res.Rules[0].IP, yandexIP) <mask> <mask> // Check cache. <mask> cachedValue, isFound := ss.getCachedResult(domain) <mask> require.True(t, isFound) <mask> require.Len(t, cachedValue.Rules, 1) <mask> <mask> assert.Equal(t, cachedValue.Rules[0].IP, yandexIP) <mask> } <mask> <mask> func TestSafeSearchCacheGoogle(t *testing.T) { <mask> const domain = "www.google.ru" <mask> <mask> ss := newForTest(t, filtering.SafeSearchConfig{Enabled: false}) <mask> <mask> res, err := ss.CheckHost(domain, dns.TypeA) <mask> require.NoError(t, err) <mask> <mask> assert.False(t, res.IsFiltered) </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove // For yandex we already know valid IP. require.Len(t, res.Rules, 1) </s> add assert.True(t, res.IsFiltered) </s> remove assert.False(t, res.IsFiltered) assert.Empty(t, res.Rules) ss = newForTest(t, defaultSafeSearchConf) res, err = ss.CheckHost(domain, dns.TypeA) </s> add res, err := ss.CheckHost("www.yandex.com", testQType) </s> remove require.Len(t, res.Rules, 1) assert.True(t, res.Rules[0].IP.Equal(foundIP)) // Check cache. cachedValue, isFound := ss.getCachedResult(domain) require.True(t, isFound) require.Len(t, cachedValue.Rules, 1) assert.True(t, cachedValue.Rules[0].IP.Equal(foundIP)) } const googleHost = "www.google.com" </s> add </s> remove func TestSafeSearchCacheYandex(t *testing.T) { const domain = "yandex.ru" ss := newForTest(t, filtering.SafeSearchConfig{Enabled: false}) // Check host with disabled safesearch. res, err := ss.CheckHost(domain, dns.TypeA) </s> add func TestDefault_Update(t *testing.T) { conf := testConf ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL) </s> remove res, err := ss.CheckHost(host, dns.TypeA) </s> add var res filtering.Result res, err = ss.CheckHost(host, testQType)
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch_test.go
keep keep keep replace keep keep keep keep keep keep keep keep replace replace replace replace replace replace replace replace keep keep
<mask> require.NoError(t, err) <mask> <mask> assert.False(t, res.IsFiltered) <mask> assert.Empty(t, res.Rules) <mask> <mask> resolver := &aghtest.TestResolver{} <mask> ss = newForTest(t, defaultSafeSearchConf) <mask> ss.resolver = resolver <mask> <mask> assert.False(t, res.IsFiltered) <mask> assert.Empty(t, res.Rules) <mask> <mask> resolver := &aghtest.TestResolver{} <mask> ss = newForTest(t, defaultSafeSearchConf) <mask> ss.resolver = resolver <mask> <mask> // Lookup for safesearch domain. <mask> rewrite := ss.SearchHost(domain, dns.TypeA) <mask> <mask> ips, err := resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME) <mask> require.NoError(t, err) <mask> </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove ss := newForTest(t, defaultSafeSearchConf) ss.resolver = resolver </s> add conf := testConf conf.CustomResolver = resolver ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL) require.NoError(t, err) </s> remove res, err := ss.CheckHost(domain, dns.TypeA) </s> add res, err = ss.CheckHost("www.yandex.com", testQType) </s> remove func TestCheckHostSafeSearchGoogle(t *testing.T) { </s> add func TestDefault_CheckHost_google(t *testing.T) { </s> remove assert.False(t, res.IsFiltered) assert.Empty(t, res.Rules) ss = newForTest(t, defaultSafeSearchConf) res, err = ss.CheckHost(domain, dns.TypeA) </s> add res, err := ss.CheckHost("www.yandex.com", testQType) </s> remove func TestSafeSearchCacheYandex(t *testing.T) { const domain = "yandex.ru" ss := newForTest(t, filtering.SafeSearchConfig{Enabled: false}) // Check host with disabled safesearch. res, err := ss.CheckHost(domain, dns.TypeA) </s> add func TestDefault_Update(t *testing.T) { conf := testConf ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL)
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch_test.go
keep keep keep keep replace replace replace replace replace replace replace replace replace replace keep replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep keep
<mask> <mask> ips, err := resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME) <mask> require.NoError(t, err) <mask> <mask> var foundIP net.IP <mask> for _, ip := range ips { <mask> if ip.To4() != nil { <mask> foundIP = ip <mask> <mask> break <mask> } <mask> } <mask> <mask> res, err = ss.CheckHost(domain, dns.TypeA) <mask> require.NoError(t, err) <mask> require.Len(t, res.Rules, 1) <mask> <mask> assert.True(t, res.Rules[0].IP.Equal(foundIP)) <mask> <mask> // Check cache. <mask> cachedValue, isFound := ss.getCachedResult(domain) <mask> require.True(t, isFound) <mask> require.Len(t, cachedValue.Rules, 1) <mask> <mask> assert.True(t, cachedValue.Rules[0].IP.Equal(foundIP)) <mask> } <mask> <mask> const googleHost = "www.google.com" <mask> <mask> var dnsRewriteSink *rules.DNSRewrite <mask> </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove assert.Equal(t, res.Rules[0].IP, yandexIP) // Check cache. cachedValue, isFound := ss.getCachedResult(domain) require.True(t, isFound) require.Len(t, cachedValue.Rules, 1) assert.Equal(t, cachedValue.Rules[0].IP, yandexIP) } func TestSafeSearchCacheGoogle(t *testing.T) { const domain = "www.google.ru" ss := newForTest(t, filtering.SafeSearchConfig{Enabled: false}) </s> add err = ss.Update(filtering.SafeSearchConfig{ Enabled: true, Google: false, }) require.NoError(t, err) </s> remove resolver := &aghtest.TestResolver{} ss = newForTest(t, defaultSafeSearchConf) ss.resolver = resolver // Lookup for safesearch domain. rewrite := ss.SearchHost(domain, dns.TypeA) ips, err := resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME) </s> add err = ss.Update(filtering.SafeSearchConfig{ Enabled: false, Google: true, }) </s> remove // For yandex we already know valid IP. require.Len(t, res.Rules, 1) </s> add assert.True(t, res.IsFiltered) </s> remove res, err := ss.CheckHost(host, dns.TypeA) </s> add var res filtering.Result res, err = ss.CheckHost(host, testQType) </s> remove res, err := ss.CheckHost(host, dns.TypeA) </s> add var res filtering.Result res, err = ss.CheckHost(host, testQType)
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch_test.go
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep
<mask> } <mask> <mask> const googleHost = "www.google.com" <mask> <mask> var dnsRewriteSink *rules.DNSRewrite <mask> <mask> func BenchmarkSafeSearch(b *testing.B) { <mask> ss := newForTest(b, defaultSafeSearchConf) <mask> <mask> for n := 0; n < b.N; n++ { <mask> dnsRewriteSink = ss.SearchHost(googleHost, dns.TypeA) <mask> } <mask> <mask> assert.Equal(b, "forcesafesearch.google.com", dnsRewriteSink.NewCNAME) <mask> } <mask> <mask> var dnsRewriteParallelSink *rules.DNSRewrite <mask> <mask> func BenchmarkSafeSearch_parallel(b *testing.B) { <mask> ss := newForTest(b, defaultSafeSearchConf) <mask> <mask> b.RunParallel(func(pb *testing.PB) { <mask> for pb.Next() { <mask> dnsRewriteParallelSink = ss.SearchHost(googleHost, dns.TypeA) <mask> } <mask> }) <mask> <mask> assert.Equal(b, "forcesafesearch.google.com", dnsRewriteParallelSink.NewCNAME) <mask> } </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove require.Len(t, res.Rules, 1) assert.True(t, res.Rules[0].IP.Equal(foundIP)) // Check cache. cachedValue, isFound := ss.getCachedResult(domain) require.True(t, isFound) require.Len(t, cachedValue.Rules, 1) assert.True(t, cachedValue.Rules[0].IP.Equal(foundIP)) } const googleHost = "www.google.com" </s> add </s> remove return ss } func TestSafeSearch(t *testing.T) { ss := newForTest(t, defaultSafeSearchConf) val := ss.SearchHost("www.google.com", dns.TypeA) assert.Equal(t, &rules.DNSRewrite{NewCNAME: "forcesafesearch.google.com"}, val) } func TestCheckHostSafeSearchYandex(t *testing.T) { ss := newForTest(t, defaultSafeSearchConf) </s> add </s> remove func TestCheckHostSafeSearchGoogle(t *testing.T) { </s> add func TestDefault_CheckHost_google(t *testing.T) { </s> remove func TestSafeSearchCacheYandex(t *testing.T) { const domain = "yandex.ru" ss := newForTest(t, filtering.SafeSearchConfig{Enabled: false}) // Check host with disabled safesearch. res, err := ss.CheckHost(domain, dns.TypeA) </s> add func TestDefault_Update(t *testing.T) { conf := testConf ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL) </s> remove resolver := &aghtest.TestResolver{} ss = newForTest(t, defaultSafeSearchConf) ss.resolver = resolver // Lookup for safesearch domain. rewrite := ss.SearchHost(domain, dns.TypeA) ips, err := resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME) </s> add err = ss.Update(filtering.SafeSearchConfig{ Enabled: false, Google: true, }) </s> remove func newForTest(t testing.TB, ssConf filtering.SafeSearchConfig) (ss *DefaultSafeSearch) { ss, err := NewDefaultSafeSearch(ssConf, safeSearchCacheSize, cacheTime) </s> add func TestDefault_CheckHost_yandex(t *testing.T) { conf := testConf ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL)
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearch/safesearch_test.go
keep keep add keep keep keep keep keep
<mask> return <mask> } <mask> <mask> func() { <mask> d.confLock.Lock() <mask> defer d.confLock.Unlock() <mask> <mask> d.Config.SafeSearchConf = conf </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove d.Config.SafeSearchConf = *req </s> add d.Config.SafeSearchConf = conf </s> remove if log.GetLevel() >= log.DEBUG { timer := log.StartTimer() defer timer.LogElapsed("safesearch: lookup for %s", host) </s> add start := time.Now() defer func() { ss.log(log.DEBUG, "lookup for %q finished in %s", host, time.Since(start)) }() if qtype != dns.TypeA && qtype != dns.TypeAAAA { return filtering.Result{}, fmt.Errorf("unsupported question type %s", dns.Type(qtype)) </s> remove cachedValue, isFound := ss.getCachedResult(host) </s> add cachedValue, isFound := ss.getCachedResult(host, qtype) </s> remove func newForTest(t testing.TB, ssConf filtering.SafeSearchConfig) (ss *DefaultSafeSearch) { ss, err := NewDefaultSafeSearch(ssConf, safeSearchCacheSize, cacheTime) </s> add func TestDefault_CheckHost_yandex(t *testing.T) { conf := testConf ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL) </s> remove qtype uint16, </s> add qtype rules.RRType, </s> remove cacheTime time.Duration, ) (ss *DefaultSafeSearch, err error) { engine, err := newEngine(filtering.SafeSearchListID, conf) if err != nil { return nil, err } </s> add cacheTTL time.Duration, ) (ss *Default, err error) {
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearchhttp.go
keep keep keep keep replace keep keep keep keep keep
<mask> func() { <mask> d.confLock.Lock() <mask> defer d.confLock.Unlock() <mask> <mask> d.Config.SafeSearchConf = *req <mask> }() <mask> <mask> d.Config.ConfigModified() <mask> <mask> aghhttp.OK(w) </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> add conf := *req err = d.safeSearch.Update(conf) if err != nil { aghhttp.Error(r, w, http.StatusBadRequest, "updating: %s", err) return } </s> remove if log.GetLevel() >= log.DEBUG { timer := log.StartTimer() defer timer.LogElapsed("safesearch: lookup for %s", host) </s> add start := time.Now() defer func() { ss.log(log.DEBUG, "lookup for %q finished in %s", host, time.Since(start)) }() if qtype != dns.TypeA && qtype != dns.TypeAAAA { return filtering.Result{}, fmt.Errorf("unsupported question type %s", dns.Type(qtype)) </s> remove qtype uint16, </s> add qtype rules.RRType, </s> remove cachedValue, isFound := ss.getCachedResult(host) </s> add cachedValue, isFound := ss.getCachedResult(host, qtype) </s> remove // newResult creates Result object from rewrite rule. func (ss *DefaultSafeSearch) newResult( </s> add // searchHost looks up DNS rewrites in the internal DNS filtering engine. func (ss *Default) searchHost(host string, qtype rules.RRType) (res *rules.DNSRewrite) { ss.mu.RLock() defer ss.mu.RUnlock() if ss.engine == nil { return nil } r, _ := ss.engine.MatchRequest(&urlfilter.DNSRequest{ Hostname: strings.ToLower(host), DNSType: qtype, }) rewritesRules := r.DNSRewrites() if len(rewritesRules) > 0 { return rewritesRules[0].DNSRewrite } return nil } // newResult creates Result object from rewrite rule. qtype must be either // [dns.TypeA] or [dns.TypeAAAA]. func (ss *Default) newResult( </s> remove var dnsRewriteSink *rules.DNSRewrite func BenchmarkSafeSearch(b *testing.B) { ss := newForTest(b, defaultSafeSearchConf) for n := 0; n < b.N; n++ { dnsRewriteSink = ss.SearchHost(googleHost, dns.TypeA) } assert.Equal(b, "forcesafesearch.google.com", dnsRewriteSink.NewCNAME) } var dnsRewriteParallelSink *rules.DNSRewrite func BenchmarkSafeSearch_parallel(b *testing.B) { ss := newForTest(b, defaultSafeSearchConf) b.RunParallel(func(pb *testing.PB) { for pb.Next() { dnsRewriteParallelSink = ss.SearchHost(googleHost, dns.TypeA) } }) assert.Equal(b, "forcesafesearch.google.com", dnsRewriteParallelSink.NewCNAME) </s> add assert.False(t, res.IsFiltered)
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/filtering/safesearchhttp.go
keep keep keep add keep keep keep keep keep keep
<mask> <mask> import ( <mask> "encoding" <mask> "fmt" <mask> <mask> "github.com/AdguardTeam/AdGuardHome/internal/filtering" <mask> "github.com/AdguardTeam/AdGuardHome/internal/filtering/safesearch" <mask> "github.com/AdguardTeam/dnsproxy/proxy" <mask> ) <mask> </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove "github.com/AdguardTeam/AdGuardHome/internal/filtering/safesearch" </s> add </s> add "github.com/AdguardTeam/AdGuardHome/internal/filtering/safesearch" </s> remove "github.com/AdguardTeam/urlfilter/rules" </s> add "github.com/AdguardTeam/AdGuardHome/internal/filtering/safesearch" "github.com/AdguardTeam/golibs/testutil" </s> remove "context" </s> add </s> remove package safesearch </s> add package safesearch_test </s> remove import ( "github.com/AdguardTeam/urlfilter/rules" "github.com/miekg/dns" ) </s> add import "github.com/miekg/dns"
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/home/client.go
keep add keep keep keep keep keep keep
<mask> <mask> "github.com/AdguardTeam/AdGuardHome/internal/filtering" <mask> "github.com/AdguardTeam/dnsproxy/proxy" <mask> ) <mask> <mask> // Client contains information about persistent clients. <mask> type Client struct { <mask> // upstreamConfig is the custom upstream config for this client. If </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> add // safeSearchCacheSize is the size of the safe search cache to use for // persistent clients. safeSearchCacheSize uint // safeSearchCacheTTL is the TTL of the safe search cache to use for // persistent clients. safeSearchCacheTTL time.Duration </s> remove // DefaultSafeSearch is the default safesearch struct. type DefaultSafeSearch struct { engine *urlfilter.DNSEngine safeSearchCache cache.Cache resolver filtering.Resolver cacheTime time.Duration </s> add // Default is the default safe search filter that uses filtering rules with the // dnsrewrite modifier. type Default struct { // mu protects engine. mu *sync.RWMutex // engine is the filtering engine that contains the DNS rewrite rules. // engine may be nil, which means that this safe search filter is disabled. engine *urlfilter.DNSEngine cache cache.Cache resolver filtering.Resolver logPrefix string cacheTTL time.Duration </s> add "time" </s> add ss.log(log.DEBUG, "resolved %s", ips) </s> add Name string `json:"name"` </s> remove Name string `json:"name"` </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/home/client.go
keep keep keep keep replace keep keep keep keep keep
<mask> "github.com/AdguardTeam/AdGuardHome/internal/aghnet" <mask> "github.com/AdguardTeam/AdGuardHome/internal/dhcpd" <mask> "github.com/AdguardTeam/AdGuardHome/internal/dnsforward" <mask> "github.com/AdguardTeam/AdGuardHome/internal/filtering" <mask> "github.com/AdguardTeam/AdGuardHome/internal/filtering/safesearch" <mask> "github.com/AdguardTeam/AdGuardHome/internal/querylog" <mask> "github.com/AdguardTeam/dnsproxy/proxy" <mask> "github.com/AdguardTeam/dnsproxy/upstream" <mask> "github.com/AdguardTeam/golibs/errors" <mask> "github.com/AdguardTeam/golibs/log" </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> add "time" </s> add "github.com/AdguardTeam/AdGuardHome/internal/filtering/safesearch" </s> add "github.com/AdguardTeam/AdGuardHome/internal/filtering" </s> add "sync" </s> remove "github.com/AdguardTeam/urlfilter/rules" </s> add "github.com/AdguardTeam/AdGuardHome/internal/filtering/safesearch" "github.com/AdguardTeam/golibs/testutil" </s> remove if dRes != nil { res = *dRes ss.setCacheResult(host, res) </s> add if fltRes != nil { res = *fltRes ss.setCacheResult(host, qtype, res)
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/home/clients.go
keep add keep keep keep keep
<mask> lock sync.Mutex <mask> <mask> // testing is a flag that disables some features for internal tests. <mask> // <mask> // TODO(a.garipov): Awful. Remove. <mask> testing bool </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove func TestClients(t *testing.T) { clients := clientsContainer{} clients.testing = true </s> add // newClientsContainer is a helper that creates a new clients container for // tests. func newClientsContainer() (c *clientsContainer) { c = &clientsContainer{ testing: true, } c.Init(nil, nil, nil, nil, &filtering.Config{}) </s> remove // DefaultSafeSearch is the default safesearch struct. type DefaultSafeSearch struct { engine *urlfilter.DNSEngine safeSearchCache cache.Cache resolver filtering.Resolver cacheTime time.Duration </s> add // Default is the default safe search filter that uses filtering rules with the // dnsrewrite modifier. type Default struct { // mu protects engine. mu *sync.RWMutex // engine is the filtering engine that contains the DNS rewrite rules. // engine may be nil, which means that this safe search filter is disabled. engine *urlfilter.DNSEngine cache cache.Cache resolver filtering.Resolver logPrefix string cacheTTL time.Duration </s> add // Update updates the configuration of the safe search filter. Update must // be safe for concurrent use. An implementation of Update may ignore some // fields, but it must document which. Update(conf SafeSearchConfig) (err error) </s> add func TestMain(m *testing.M) { testutil.DiscardLogOutput(m) } // Common test constants. </s> remove safeSearchCacheSize = 5000 cacheTime = 30 * time.Minute </s> add // TODO(a.garipov): Add IPv6 tests. testQType = dns.TypeA testCacheSize = 5000 testCacheTTL = 30 * time.Minute </s> remove var defaultSafeSearchConf = filtering.SafeSearchConfig{ Enabled: true, </s> add // testConf is the default safe search configuration for tests. var testConf = filtering.SafeSearchConfig{ CustomResolver: nil, Enabled: true,
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/home/clients.go
keep keep add keep keep keep keep keep keep
<mask> clients.arpdb = arpdb <mask> clients.addFromConfig(objects, filteringConf) <mask> <mask> if clients.testing { <mask> return <mask> } <mask> <mask> clients.updateFromDHCP(true) <mask> if clients.dhcpServer != nil { </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove clients.Init(nil, nil, nil, nil, nil) </s> add return c } func TestClients(t *testing.T) { clients := newClientsContainer() </s> remove if rewrite.NewCNAME == "" { </s> add host := rewrite.NewCNAME if host == "" { </s> remove func TestClients(t *testing.T) { clients := clientsContainer{} clients.testing = true </s> add // newClientsContainer is a helper that creates a new clients container for // tests. func newClientsContainer() (c *clientsContainer) { c = &clientsContainer{ testing: true, } c.Init(nil, nil, nil, nil, &filtering.Config{}) </s> remove if !setts.ProtectionEnabled || !setts.SafeSearchEnabled { </s> add if !setts.ProtectionEnabled || !setts.SafeSearchEnabled || (qtype != dns.TypeA && qtype != dns.TypeAAAA) { </s> remove c := jsonToClient(dj.Data) </s> add c, err := clients.jsonToClient(dj.Data) if err != nil { aghhttp.Error(r, w, http.StatusBadRequest, "%s", err) return } </s> remove return d.safeSearch.CheckHost(host, dns.TypeA) </s> add return d.safeSearch.CheckHost(host, qtype)
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/home/clients.go
keep keep keep keep replace keep keep keep keep keep
<mask> <mask> if o.SafeSearchConf.Enabled { <mask> o.SafeSearchConf.CustomResolver = safeSearchResolver{} <mask> <mask> ss, err := safesearch.NewDefaultSafeSearch( <mask> o.SafeSearchConf, <mask> filteringConf.SafeSearchCacheSize, <mask> time.Minute*time.Duration(filteringConf.CacheTime), <mask> ) <mask> if err != nil { </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove config.DNS.DnsfilterConf.SafeSearch, err = safesearch.NewDefaultSafeSearch( </s> add config.DNS.DnsfilterConf.SafeSearch, err = safesearch.NewDefault( </s> remove log.Error("clients: init client safesearch %s: %s", cli.Name, err) </s> add log.Error("clients: init client safesearch %q: %s", cli.Name, err) </s> add "default", </s> remove func newForTest(t testing.TB, ssConf filtering.SafeSearchConfig) (ss *DefaultSafeSearch) { ss, err := NewDefaultSafeSearch(ssConf, safeSearchCacheSize, cacheTime) </s> add func TestDefault_CheckHost_yandex(t *testing.T) { conf := testConf ss, err := safesearch.NewDefault(conf, "", testCacheSize, testCacheTTL) </s> remove cacheTime time.Duration, ) (ss *DefaultSafeSearch, err error) { engine, err := newEngine(filtering.SafeSearchListID, conf) if err != nil { return nil, err } </s> add cacheTTL time.Duration, ) (ss *Default, err error) { </s> remove safeSearch, err := safesearch.NewDefaultSafeSearch( </s> add safeSearch, err := safesearch.NewDefault(
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/home/clients.go
keep keep keep keep replace keep keep keep replace replace keep keep
<mask> filteringConf.SafeSearchCacheSize, <mask> time.Minute*time.Duration(filteringConf.CacheTime), <mask> ) <mask> if err != nil { <mask> log.Error("clients: init client safesearch %s: %s", cli.Name, err) <mask> <mask> continue <mask> } <mask> <mask> cli.SafeSearch = ss <mask> } <mask> </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove ss, err := safesearch.NewDefaultSafeSearch( </s> add err := cli.setSafeSearch( </s> remove log.Debug("safesearch: failed to lookup addresses for %s: %s", host, err) </s> add ss.log(log.DEBUG, "looking up addresses for %q: %s", host, err) </s> remove Upstreams: cj.Upstreams, </s> add if safeSearchConf.Enabled { err = c.setSafeSearch( safeSearchConf, clients.safeSearchCacheSize, clients.safeSearchCacheTTL, ) if err != nil { return nil, fmt.Errorf("creating safesearch for client %q: %w", c.Name, err) } </s> remove dRes, err := ss.newResult(rewrite, qtype) </s> add fltRes, err := ss.newResult(rewrite, qtype) </s> add return c, nil
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/home/clients.go
keep keep keep add keep keep keep keep keep keep
<mask> "testing" <mask> "time" <mask> <mask> "github.com/AdguardTeam/AdGuardHome/internal/dhcpd" <mask> "github.com/AdguardTeam/golibs/testutil" <mask> <mask> "github.com/stretchr/testify/assert" <mask> "github.com/stretchr/testify/require" <mask> ) <mask> </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove "github.com/AdguardTeam/urlfilter/rules" </s> add "github.com/AdguardTeam/AdGuardHome/internal/filtering/safesearch" "github.com/AdguardTeam/golibs/testutil" </s> remove "context" </s> add </s> add func TestMain(m *testing.M) { testutil.DiscardLogOutput(m) } // Common test constants. </s> remove func TestClients(t *testing.T) { clients := clientsContainer{} clients.testing = true </s> add // newClientsContainer is a helper that creates a new clients container for // tests. func newClientsContainer() (c *clientsContainer) { c = &clientsContainer{ testing: true, } c.Init(nil, nil, nil, nil, &filtering.Config{}) </s> add "time" </s> remove "github.com/AdguardTeam/AdGuardHome/internal/filtering/safesearch" </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/home/clients_test.go
keep keep keep keep replace replace replace keep replace keep keep
<mask> "github.com/stretchr/testify/assert" <mask> "github.com/stretchr/testify/require" <mask> ) <mask> <mask> func TestClients(t *testing.T) { <mask> clients := clientsContainer{} <mask> clients.testing = true <mask> <mask> clients.Init(nil, nil, nil, nil, nil) <mask> <mask> t.Run("add_success", func(t *testing.T) { </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove clients := clientsContainer{ testing: true, } clients.Init(nil, nil, nil, nil, nil) </s> add clients := newClientsContainer() </s> remove clients := clientsContainer{ testing: true, } clients.Init(nil, nil, nil, nil, nil) </s> add clients := newClientsContainer() </s> remove clients := clientsContainer{ testing: true, } clients.Init(nil, nil, nil, nil, nil) </s> add clients := newClientsContainer() </s> remove res, err := ss.CheckHost(host, dns.TypeA) </s> add var res filtering.Result res, err = ss.CheckHost(host, testQType) </s> remove func TestCheckHostSafeSearchGoogle(t *testing.T) { </s> add func TestDefault_CheckHost_google(t *testing.T) {
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/home/clients_test.go
keep keep keep keep replace replace replace replace keep keep keep keep keep
<mask> }) <mask> } <mask> <mask> func TestClientsWHOIS(t *testing.T) { <mask> clients := clientsContainer{ <mask> testing: true, <mask> } <mask> clients.Init(nil, nil, nil, nil, nil) <mask> whois := &RuntimeClientWHOISInfo{ <mask> Country: "AU", <mask> Orgname: "Example Org", <mask> } <mask> </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove clients := clientsContainer{ testing: true, } clients.Init(nil, nil, nil, nil, nil) </s> add clients := newClientsContainer() </s> remove clients := clientsContainer{ testing: true, } clients.Init(nil, nil, nil, nil, nil) </s> add clients := newClientsContainer() </s> remove func TestClients(t *testing.T) { clients := clientsContainer{} clients.testing = true </s> add // newClientsContainer is a helper that creates a new clients container for // tests. func newClientsContainer() (c *clientsContainer) { c = &clientsContainer{ testing: true, } c.Init(nil, nil, nil, nil, &filtering.Config{}) </s> remove clients.Init(nil, nil, nil, nil, nil) </s> add return c } func TestClients(t *testing.T) { clients := newClientsContainer() </s> remove ips, err := ss.resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME) </s> add ss.log(log.DEBUG, "resolving %q", host) ips, err := ss.resolver.LookupIP(context.Background(), qtypeToProto(qtype), host) </s> remove if rewrite.RRType == qtype && (qtype == dns.TypeA || qtype == dns.TypeAAAA) { </s> add if rewrite.RRType == qtype {
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/home/clients_test.go
keep keep keep keep replace replace replace replace keep keep keep keep keep
<mask> }) <mask> } <mask> <mask> func TestClientsAddExisting(t *testing.T) { <mask> clients := clientsContainer{ <mask> testing: true, <mask> } <mask> clients.Init(nil, nil, nil, nil, nil) <mask> <mask> t.Run("simple", func(t *testing.T) { <mask> ip := netip.MustParseAddr("1.1.1.1") <mask> <mask> // Add a client. </s> Pull request 1803: 5685-fix-safe-search Updates #5685. Squashed commit of the following: commit 5312147abfa0914c896acbf1e88f8c8f1af90f2b Author: Ainar Garipov <[email protected]> Date: Thu Apr 6 14:09:44 2023 +0300 safesearch: imp tests, logs commit 298b5d24ce292c5f83ebe33d1e92329e4b3c1acc Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:36:16 2023 +0300 safesearch: fix filters, logging commit 63d6ca5d694d45705473f2f0410e9e0b49cf7346 Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:24:47 2023 +0300 all: dry; fix logs commit fdbf2f364fd0484b47b3161bf6f4581856fdf47b Author: Ainar Garipov <[email protected]> Date: Wed Apr 5 20:01:08 2023 +0300 all: fix safe search update </s> remove clients := clientsContainer{ testing: true, } clients.Init(nil, nil, nil, nil, nil) </s> add clients := newClientsContainer() </s> remove clients := clientsContainer{ testing: true, } clients.Init(nil, nil, nil, nil, nil) </s> add clients := newClientsContainer() </s> remove func TestClients(t *testing.T) { clients := clientsContainer{} clients.testing = true </s> add // newClientsContainer is a helper that creates a new clients container for // tests. func newClientsContainer() (c *clientsContainer) { c = &clientsContainer{ testing: true, } c.Init(nil, nil, nil, nil, &filtering.Config{}) </s> remove clients.Init(nil, nil, nil, nil, nil) </s> add return c } func TestClients(t *testing.T) { clients := newClientsContainer() </s> remove ips, err := ss.resolver.LookupIP(context.Background(), "ip", rewrite.NewCNAME) </s> add ss.log(log.DEBUG, "resolving %q", host) ips, err := ss.resolver.LookupIP(context.Background(), qtypeToProto(qtype), host) </s> remove if rewrite.RRType == qtype && (qtype == dns.TypeA || qtype == dns.TypeAAAA) { </s> add if rewrite.RRType == qtype {
https://github.com/AdguardTeam/AdGuardHome/commit/61b4043775ecc3e06aebcdabc070b732c6dd0ff0
internal/home/clients_test.go