filter

package
v0.0.0-...-b6e3791 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 11, 2024 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Overview

Package filter contains the filter interface and its implementations along with types that combine them based on the settings in profile and filtering group.

Index

Constants

View Source
const (
	GeneralTXTSuffix       = ".sb.dns.adguard.com"
	AdultBlockingTXTSuffix = ".pc.dns.adguard.com"
)

Default safe-browsing host suffixes.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultStorage

type DefaultStorage struct {
	// contains filtered or unexported fields
}

DefaultStorage is the default storage for filters, including the filters based on rule lists, custom filters of profiles, safe browsing, and safe search ones.

func NewDefaultStorage

func NewDefaultStorage(c *DefaultStorageConfig) (s *DefaultStorage, err error)

NewDefaultStorage returns a new filter storage. c must not be nil.

func (*DefaultStorage) FilterFromContext

func (s *DefaultStorage) FilterFromContext(ctx context.Context, ri *agd.RequestInfo) (f Interface)

FilterFromContext implements the Storage interface for *DefaultStorage.

func (*DefaultStorage) HasListID

func (s *DefaultStorage) HasListID(id agd.FilterListID) (ok bool)

HasListID implements the Storage interface for *DefaultStorage.

func (*DefaultStorage) Refresh

func (s *DefaultStorage) Refresh(ctx context.Context) (err error)

Refresh implements the agdservice.Refresher interface for *DefaultStorage.

type DefaultStorageConfig

type DefaultStorageConfig struct {
	// FilterIndexURL is the URL of the filtering rule index document.
	FilterIndexURL *url.URL

	// BlockedServiceIndexURL is the URL of the blocked service index document.
	BlockedServiceIndexURL *url.URL

	// GeneralSafeSearchRulesURL is the URL to refresh general safe search rules
	// list.
	GeneralSafeSearchRulesURL *url.URL

	// YoutubeSafeSearchRulesURL is the URL to refresh YouTube safe search rules
	// list.
	YoutubeSafeSearchRulesURL *url.URL

	// SafeBrowsing is the configuration for the default safe browsing filter.
	// It must not be nil.
	SafeBrowsing *hashprefix.Filter

	// AdultBlocking is the configuration for the adult content blocking safe
	// browsing filter.  It must not be nil.
	AdultBlocking *hashprefix.Filter

	// NewRegDomains is the configuration for the newly registered domains safe
	// browsing filter.  It must not be nil.
	NewRegDomains *hashprefix.Filter

	// Now is a function that returns current time.
	Now func() (now time.Time)

	// ErrColl is used to collect non-critical and rare errors.
	ErrColl errcoll.Interface

	// Resolver is used to resolve hosts in safe search.
	Resolver agdnet.Resolver

	// Cloner is used to clone messages taken from filtering-result caches.
	Cloner *dnsmsg.Cloner

	// CacheDir is the path to the directory where the cached filter files are
	// put.  The directory must exist.
	CacheDir string

	// CustomFilterCacheSize is the number of cached custom filters for
	// profiles.
	CustomFilterCacheSize int

	// SafeSearchCacheSize is the size of the LRU cache of results of the safe
	// search filters: the general one and the YouTube one.
	SafeSearchCacheSize int

	// SafeSearchCacheTTL is the time-to-live value used for the cache of
	// results of the safe search filters: the general one and the YouTube one.
	SafeSearchCacheTTL time.Duration

	// RuleListCacheSize defines the size of the LRU cache of rule-list
	// filtering results.
	RuleListCacheSize int

	// RefreshIvl is the refresh interval for this storage.  It defines how
	// often the filter rule lists are updated from the index.
	//
	// TODO(a.garipov): This value is used both for refreshes and for filter
	// staleness, which can cause issues.  Consider splitting the two.
	RefreshIvl time.Duration

	// UseRuleListCache, if true, enables rule list cache.
	UseRuleListCache bool

	// MaxRuleListSize is the maximum size in bytes of the downloadable
	// rule-list content.
	MaxRuleListSize uint64
}

DefaultStorageConfig contains configuration for a filter storage based on rule lists.

type HashMatcher

type HashMatcher interface {
	MatchByPrefix(ctx context.Context, host string) (hashes []string, matched bool, err error)
}

HashMatcher is the interface for a safe-browsing and adult-blocking hash matcher, which is used to respond to a TXT query based on the domain name.

type Interface

type Interface = internal.Interface

Interface is the DNS request and response filter interface.

type Result

type Result = internal.Result

Result is a sum type of all possible filtering actions. See the following types as implementations:

type ResultAllowed

type ResultAllowed = internal.ResultAllowed

ResultAllowed means that this request or response was allowed by an allowlist rule within the given filter list.

type ResultBlocked

type ResultBlocked = internal.ResultBlocked

ResultBlocked means that this request or response was blocked by a blocklist rule within the given filter list.

type ResultModified

type ResultModified = internal.ResultModified

ResultModified means that this request or response was rewritten or modified by a rewrite rule within the given filter list.

type Storage

type Storage interface {
	// FilterFromContext returns a filter combining rules and types of filtering
	// for all entities from the context.  ri must not be nil.
	FilterFromContext(ctx context.Context, ri *agd.RequestInfo) (f Interface)

	// HasListID returns true if id is within the rule lists that are currently
	// in the storage.
	HasListID(id agd.FilterListID) (ok bool)
}

Storage is a storage for filters.

Directories

Path Synopsis
Package hashprefix defines a storage of hashes of domain names used for filtering and serving TXT records with domain-name hashes.
Package hashprefix defines a storage of hashes of domain names used for filtering and serving TXT records with domain-name hashes.
Package internal contains common constants, types, and utilities shared by other subpackages of package filter/.
Package internal contains common constants, types, and utilities shared by other subpackages of package filter/.
composite
Package composite implements a composite filter based on several types of filters and the logic of the filter application.
Package composite implements a composite filter based on several types of filters and the logic of the filter application.
custom
Package custom contains the caching storage of filters made from custom filtering rules of profiles.
Package custom contains the caching storage of filters made from custom filtering rules of profiles.
filtertest
Package filtertest contains common constants and utilities for the internal filtering packages.
Package filtertest contains common constants and utilities for the internal filtering packages.
resultcache
Package resultcache contains a cache for filtering results.
Package resultcache contains a cache for filtering results.
rulelist
Package rulelist contains the implementation of the standard rule-list filter that wraps an urlfilter filtering-engine.
Package rulelist contains the implementation of the standard rule-list filter that wraps an urlfilter filtering-engine.
safesearch
Package safesearch contains the implementation of the safe-search filter that uses lists of DNS rewrite rules to enforce safe search.
Package safesearch contains the implementation of the safe-search filter that uses lists of DNS rewrite rules to enforce safe search.
serviceblock
Package serviceblock contains an implementation of a filter that blocks services using rule lists.
Package serviceblock contains an implementation of a filter that blocks services using rule lists.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL