mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2025-05-01 13:41:07 +03:00
Pull request 2286: AGDNS-2374-slog-safesearch
Squashed commit of the following: commit 1909dfed99b8815c1215c709efcae77a70b52ea3 Merge:3856fda5f
2c64ab5a5
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Oct 9 16:21:38 2024 +0300 Merge branch 'master' into AGDNS-2374-slog-safesearch commit3856fda5f3
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Oct 8 20:04:34 2024 +0300 home: imp code commitde774009aa
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Oct 7 16:41:58 2024 +0300 all: imp code commit038bae59d5
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Oct 3 20:24:48 2024 +0300 all: imp code commit792975e248
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Oct 3 15:46:40 2024 +0300 all: slog safesearch
This commit is contained in:
parent
2c64ab5a51
commit
6363f8a2e7
12 changed files with 237 additions and 122 deletions
internal/home
|
@ -278,8 +278,8 @@ func setupOpts(opts options) (err error) {
|
|||
}
|
||||
|
||||
// initContextClients initializes Context clients and related fields.
|
||||
func initContextClients(logger *slog.Logger) (err error) {
|
||||
err = setupDNSFilteringConf(config.Filtering)
|
||||
func initContextClients(ctx context.Context, logger *slog.Logger) (err error) {
|
||||
err = setupDNSFilteringConf(ctx, logger, config.Filtering)
|
||||
if err != nil {
|
||||
// Don't wrap the error, because it's informative enough as is.
|
||||
return err
|
||||
|
@ -306,6 +306,8 @@ func initContextClients(logger *slog.Logger) (err error) {
|
|||
}
|
||||
|
||||
return Context.clients.Init(
|
||||
ctx,
|
||||
logger,
|
||||
config.Clients.Persistent,
|
||||
Context.dhcpServer,
|
||||
Context.etcHosts,
|
||||
|
@ -355,7 +357,11 @@ func setupBindOpts(opts options) (err error) {
|
|||
}
|
||||
|
||||
// setupDNSFilteringConf sets up DNS filtering configuration settings.
|
||||
func setupDNSFilteringConf(conf *filtering.Config) (err error) {
|
||||
func setupDNSFilteringConf(
|
||||
ctx context.Context,
|
||||
baseLogger *slog.Logger,
|
||||
conf *filtering.Config,
|
||||
) (err error) {
|
||||
const (
|
||||
dnsTimeout = 3 * time.Second
|
||||
|
||||
|
@ -446,12 +452,13 @@ func setupDNSFilteringConf(conf *filtering.Config) (err error) {
|
|||
conf.ParentalBlockHost = host
|
||||
}
|
||||
|
||||
conf.SafeSearch, err = safesearch.NewDefault(
|
||||
conf.SafeSearchConf,
|
||||
"default",
|
||||
conf.SafeSearchCacheSize,
|
||||
cacheTime,
|
||||
)
|
||||
logger := baseLogger.With(slogutil.KeyPrefix, safesearch.LogPrefix)
|
||||
conf.SafeSearch, err = safesearch.NewDefault(ctx, &safesearch.DefaultConfig{
|
||||
Logger: logger,
|
||||
ServicesConfig: conf.SafeSearchConf,
|
||||
CacheSize: conf.SafeSearchCacheSize,
|
||||
CacheTTL: cacheTime,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("initializing safesearch: %w", err)
|
||||
}
|
||||
|
@ -584,7 +591,10 @@ func run(opts options, clientBuildFS fs.FS, done chan struct{}) {
|
|||
// data first, but also to avoid relying on automatic Go init() function.
|
||||
filtering.InitModule()
|
||||
|
||||
err = initContextClients(slogLogger)
|
||||
// TODO(s.chzhen): Use it for the entire initialization process.
|
||||
ctx := context.Background()
|
||||
|
||||
err = initContextClients(ctx, slogLogger)
|
||||
fatalOnError(err)
|
||||
|
||||
err = setupOpts(opts)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue