mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2025-12-20 01:11:03 +08:00
all: imp code
Some checks failed
build / test (macOS-latest) (push) Has been cancelled
build / test (ubuntu-latest) (push) Has been cancelled
build / test (windows-latest) (push) Has been cancelled
lint / go-lint (push) Has been cancelled
lint / eslint (push) Has been cancelled
build / build-release (push) Has been cancelled
build / notify (push) Has been cancelled
lint / notify (push) Has been cancelled
Some checks failed
build / test (macOS-latest) (push) Has been cancelled
build / test (ubuntu-latest) (push) Has been cancelled
build / test (windows-latest) (push) Has been cancelled
lint / go-lint (push) Has been cancelled
lint / eslint (push) Has been cancelled
build / build-release (push) Has been cancelled
build / notify (push) Has been cancelled
lint / notify (push) Has been cancelled
This commit is contained in:
@@ -22,7 +22,8 @@ var serviceRules map[string][]*rules.NetworkRule
|
||||
// serviceIDs contains service IDs sorted alphabetically.
|
||||
var serviceIDs []string
|
||||
|
||||
// initBlockedServices initializes package-level blocked service data.
|
||||
// initBlockedServices initializes package-level blocked service data. l must
|
||||
// not be nil.
|
||||
func initBlockedServices(ctx context.Context, l *slog.Logger) {
|
||||
svcLen := len(blockedServices)
|
||||
serviceIDs = make([]string, svcLen)
|
||||
|
||||
@@ -1029,9 +1029,9 @@ func makeResult(matchedRules []rules.Rule, reason Reason) (res Result) {
|
||||
}
|
||||
}
|
||||
|
||||
// InitModule manually initializes blocked services map.
|
||||
func InitModule(l *slog.Logger) {
|
||||
initBlockedServices(context.TODO(), l)
|
||||
// InitModule manually initializes blocked services map. l must not be nil.
|
||||
func InitModule(ctx context.Context, l *slog.Logger) {
|
||||
initBlockedServices(ctx, l)
|
||||
}
|
||||
|
||||
// New creates properly initialized DNS Filter that is ready to be used. c must
|
||||
|
||||
@@ -18,15 +18,14 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
testutil.DiscardLogOutput(m)
|
||||
}
|
||||
|
||||
const (
|
||||
sbBlocked = "wmconvirus.narod.ru"
|
||||
pcBlocked = "pornhub.com"
|
||||
)
|
||||
|
||||
// testLogger is the common logger for tests.
|
||||
var testLogger = slogutil.NewDiscardLogger()
|
||||
|
||||
// Helpers.
|
||||
|
||||
func newForTest(t testing.TB, c *Config, filters []Filter) (f *DNSFilter, setts *Settings) {
|
||||
@@ -35,7 +34,7 @@ func newForTest(t testing.TB, c *Config, filters []Filter) (f *DNSFilter, setts
|
||||
FilteringEnabled: true,
|
||||
}
|
||||
if c != nil {
|
||||
c.Logger = cmp.Or(c.Logger, slogutil.NewDiscardLogger())
|
||||
c.Logger = cmp.Or(c.Logger, testLogger)
|
||||
c.SafeBrowsingCacheSize = 10000
|
||||
c.ParentalCacheSize = 10000
|
||||
c.SafeSearchCacheSize = 1000
|
||||
@@ -46,7 +45,7 @@ func newForTest(t testing.TB, c *Config, filters []Filter) (f *DNSFilter, setts
|
||||
} else {
|
||||
// It must not be nil.
|
||||
c = &Config{
|
||||
Logger: slogutil.NewDiscardLogger(),
|
||||
Logger: testLogger,
|
||||
}
|
||||
}
|
||||
f, err := New(c, filters)
|
||||
@@ -57,7 +56,7 @@ func newForTest(t testing.TB, c *Config, filters []Filter) (f *DNSFilter, setts
|
||||
|
||||
func newChecker(host string) Checker {
|
||||
return hashprefix.New(&hashprefix.Config{
|
||||
Logger: slogutil.NewDiscardLogger(),
|
||||
Logger: testLogger,
|
||||
CacheTime: 10,
|
||||
CacheSize: 100000,
|
||||
Upstream: aghtest.NewBlockUpstream(host, true),
|
||||
@@ -676,7 +675,7 @@ func TestClientSettings(t *testing.T) {
|
||||
|
||||
func BenchmarkSafeBrowsing(b *testing.B) {
|
||||
d, setts := newForTest(b, &Config{
|
||||
Logger: slogutil.NewDiscardLogger(),
|
||||
Logger: testLogger,
|
||||
SafeBrowsingEnabled: true,
|
||||
SafeBrowsingChecker: newChecker(sbBlocked),
|
||||
}, nil)
|
||||
@@ -703,7 +702,7 @@ func BenchmarkSafeBrowsing(b *testing.B) {
|
||||
|
||||
func BenchmarkSafeBrowsing_parallel(b *testing.B) {
|
||||
d, setts := newForTest(b, &Config{
|
||||
Logger: slogutil.NewDiscardLogger(),
|
||||
Logger: testLogger,
|
||||
SafeBrowsingEnabled: true,
|
||||
SafeBrowsingChecker: newChecker(sbBlocked),
|
||||
}, nil)
|
||||
|
||||
@@ -3,7 +3,6 @@ package home
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"net/netip"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -519,7 +518,6 @@ var config = &configuration{
|
||||
Name: "AdAway Default Blocklist",
|
||||
}},
|
||||
Filtering: &filtering.Config{
|
||||
Logger: slog.Default(),
|
||||
ProtectionEnabled: true,
|
||||
BlockingMode: filtering.BlockingModeDefault,
|
||||
BlockedResponseTTL: 10, // in seconds
|
||||
|
||||
@@ -357,11 +357,11 @@ func setupDNSFilteringConf(
|
||||
const (
|
||||
dnsTimeout = 3 * time.Second
|
||||
|
||||
sbService = "safe browsing"
|
||||
sbService = "safe_browsing"
|
||||
defaultSafeBrowsingServer = `https://family.adguard-dns.com/dns-query`
|
||||
sbTXTSuffix = `sb.dns.adguard.com.`
|
||||
|
||||
pcService = "parental control"
|
||||
pcService = "parental_control"
|
||||
defaultParentalServer = `https://family.adguard-dns.com/dns-query`
|
||||
pcTXTSuffix = `pc.dns.adguard.com.`
|
||||
)
|
||||
@@ -417,7 +417,11 @@ func setupDNSFilteringConf(
|
||||
// default.
|
||||
if conf.SafeBrowsingBlockHost == "" {
|
||||
host := defaultSafeBrowsingBlockHost
|
||||
log.Info("%s: warning: empty blocking host; using default: %q", sbService, host)
|
||||
baseLogger.WarnContext(ctx,
|
||||
"empty blocking host; set default",
|
||||
"service", sbService,
|
||||
"host", host,
|
||||
)
|
||||
|
||||
conf.SafeBrowsingBlockHost = host
|
||||
}
|
||||
@@ -441,7 +445,11 @@ func setupDNSFilteringConf(
|
||||
// default.
|
||||
if conf.ParentalBlockHost == "" {
|
||||
host := defaultParentalBlockHost
|
||||
log.Info("%s: warning: empty blocking host; using default: %q", pcService, host)
|
||||
baseLogger.WarnContext(ctx,
|
||||
"empty blocking host; set default",
|
||||
"service", pcService,
|
||||
"host", host,
|
||||
)
|
||||
|
||||
conf.ParentalBlockHost = host
|
||||
}
|
||||
@@ -616,13 +624,13 @@ func run(opts options, clientBuildFS fs.FS, done chan struct{}, sigHdlr *signalH
|
||||
err = configureOS(config)
|
||||
fatalOnError(err)
|
||||
|
||||
// TODO(s.chzhen): Use it for the entire initialization process.
|
||||
ctx := context.Background()
|
||||
|
||||
// Clients package uses filtering package's static data
|
||||
// (filtering.BlockedSvcKnown()), so we have to initialize filtering static
|
||||
// data first, but also to avoid relying on automatic Go init() function.
|
||||
filtering.InitModule(slogLogger)
|
||||
|
||||
// TODO(s.chzhen): Use it for the entire initialization process.
|
||||
ctx := context.Background()
|
||||
filtering.InitModule(ctx, slogLogger)
|
||||
|
||||
err = initContextClients(ctx, slogLogger, sigHdlr)
|
||||
fatalOnError(err)
|
||||
|
||||
Reference in New Issue
Block a user