diff --git a/internal/filtering/rulelist/engine.go b/internal/filtering/rulelist/engine.go index b11c71f5..27d45843 100644 --- a/internal/filtering/rulelist/engine.go +++ b/internal/filtering/rulelist/engine.go @@ -19,6 +19,7 @@ import ( // // TODO(a.garipov): Merge with [TextEngine] in some way? type Engine struct { + // logger is used to log the operation of the engine and its refreshes. logger *slog.Logger // mu protects engine and storage. @@ -32,8 +33,7 @@ type Engine struct { // storage is the filtering-rule storage. It is saved here to close it. storage *filterlist.RuleStorage - // name is the human-readable name of the engine, like "allowed", "blocked", - // or "custom", used to report errors. + // name is the human-readable name of the engine. name string // filters is the data about rule filters in this engine. @@ -46,8 +46,8 @@ type EngineConfig struct { // Logger is used to log the operation of the engine. It must not be nil. Logger *slog.Logger - // name is the human-readable name of the engine, like "allowed", "blocked", - // or "custom", used to report errors. + // name is the human-readable name of the engine; see [EngineNameAllow] and + // similar constants. Name string // Filters is the data about rule lists in this engine. There must be no @@ -92,7 +92,7 @@ func (e *Engine) FilterRequest( } // currentEngine returns the current filtering engine. -func (e *Engine) currentEngine() (enging *urlfilter.DNSEngine) { +func (e *Engine) currentEngine() (engine *urlfilter.DNSEngine) { e.mu.RLock() defer e.mu.RUnlock() @@ -103,7 +103,7 @@ func (e *Engine) currentEngine() (enging *urlfilter.DNSEngine) { // parseBuf, cli, cacheDir, and maxSize are used for updates of rule-list // filters; see [Filter.Refresh]. // -// TODO(a.garipov): Unexport and test in an internal test or through enigne +// TODO(a.garipov): Unexport and test in an internal test or through engine // tests. func (e *Engine) Refresh( ctx context.Context, diff --git a/internal/filtering/rulelist/filter.go b/internal/filtering/rulelist/filter.go index a29897de..c438748e 100644 --- a/internal/filtering/rulelist/filter.go +++ b/internal/filtering/rulelist/filter.go @@ -105,7 +105,7 @@ func NewFilter(c *FilterConfig) (f *Filter, err error) { // buffer used to parse information from the data. cli and maxSize are only // used when f is a URL-based list. // -// TODO(a.garipov): Unexport and test in an internal test or through enigne +// TODO(a.garipov): Unexport and test in an internal test or through engine // tests. // // TODO(a.garipov): Consider not returning parseRes. diff --git a/internal/filtering/rulelist/rulelist.go b/internal/filtering/rulelist/rulelist.go index 021254c7..d8a82375 100644 --- a/internal/filtering/rulelist/rulelist.go +++ b/internal/filtering/rulelist/rulelist.go @@ -71,3 +71,10 @@ var _ fmt.Stringer = UID{} func (id UID) String() (s string) { return uuid.UUID(id).String() } + +// Common engine names. +const ( + EngineNameAllow = "allow" + EngineNameBlock = "block" + EngineNameCustom = "custom" +) diff --git a/internal/filtering/rulelist/storage.go b/internal/filtering/rulelist/storage.go index 4c35c4b3..3281032d 100644 --- a/internal/filtering/rulelist/storage.go +++ b/internal/filtering/rulelist/storage.go @@ -60,7 +60,7 @@ type StorageConfig struct { // refreshed, so a refresh should be performed before use. func NewStorage(c *StorageConfig) (s *Storage, err error) { custom, err := NewTextEngine(&TextEngineConfig{ - Name: "custom", + Name: EngineNameCustom, Rules: c.CustomRules, ID: URLFilterIDCustom, }) @@ -71,13 +71,13 @@ func NewStorage(c *StorageConfig) (s *Storage, err error) { return &Storage{ refreshMu: &sync.Mutex{}, allow: NewEngine(&EngineConfig{ - Logger: c.Logger.With("engine", "allow"), - Name: "allow", + Logger: c.Logger.With("engine", EngineNameAllow), + Name: EngineNameAllow, Filters: c.AllowFilters, }), block: NewEngine(&EngineConfig{ - Logger: c.Logger.With("engine", "block"), - Name: "block", + Logger: c.Logger.With("engine", EngineNameBlock), + Name: EngineNameBlock, Filters: c.BlockFilters, }), custom: custom, diff --git a/internal/filtering/rulelist/storage_test.go b/internal/filtering/rulelist/storage_test.go index b8199022..ac7e6ae3 100644 --- a/internal/filtering/rulelist/storage_test.go +++ b/internal/filtering/rulelist/storage_test.go @@ -41,6 +41,7 @@ func TestStorage_Refresh(t *testing.T) { MaxRuleListTextSize: 1 * datasize.KB, }) require.NoError(t, err) + testutil.CleanupAndRequireSuccess(t, strg.Close) ctx := testutil.ContextWithTimeout(t, testTimeout) err = strg.Refresh(ctx) diff --git a/internal/filtering/rulelist/textengine.go b/internal/filtering/rulelist/textengine.go index 4b5e8ce8..d04a8f5d 100644 --- a/internal/filtering/rulelist/textengine.go +++ b/internal/filtering/rulelist/textengine.go @@ -20,15 +20,15 @@ type TextEngine struct { // storage is the filtering-rule storage. It is saved here to close it. storage *filterlist.RuleStorage - // name is the human-readable name of the engine, like "custom". + // name is the human-readable name of the engine. name string } // TextEngineConfig is the configuration for a rule-list filtering engine // created from a filtering rule text. type TextEngineConfig struct { - // Name is the human-readable name of this engine, like "allowed", - // "blocked", or "custom". + // name is the human-readable name of the engine; see [EngineNameAllow] and + // similar constants. Name string // Rules is the text of the filtering rules for this engine.