internal

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: 19 Imported by: 0

Documentation

Overview

Package internal contains common constants, types, and utilities shared by other subpackages of package filter/.

Index

Constants

View Source
const DefaultFilterRefreshTimeout = 3 * time.Minute

DefaultFilterRefreshTimeout is the default timeout to use when fetching filter lists data.

View Source
const DefaultResolveTimeout = 1 * time.Second

DefaultResolveTimeout is the default timeout for resolving hosts for safe-search and safe-browsing filters.

TODO(ameshkov): Consider making configurable.

Variables

This section is empty.

Functions

This section is empty.

Types

type Interface

type Interface interface {
	// FilterRequest filters the DNS request for the provided client.  All
	// parameters must be non-nil.  req must have exactly one question.  If a is
	// nil, the request doesn't match any of the rules.
	FilterRequest(ctx context.Context, req *dns.Msg, ri *agd.RequestInfo) (r Result, err error)

	// FilterResponse filters the DNS response for the provided client.  All
	// parameters must be non-nil.  If a is nil, the response doesn't match any
	// of the rules.
	FilterResponse(ctx context.Context, resp *dns.Msg, ri *agd.RequestInfo) (r Result, err error)
}

Interface is the DNS request and response filter interface.

type Refreshable

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

Refreshable contains entities common to filters that can refresh themselves from a file and a URL.

func NewRefreshable

func NewRefreshable(c *RefreshableConfig) (f *Refreshable)

NewRefreshable returns a new refreshable filter. c must not be nil.

func (*Refreshable) Refresh

func (f *Refreshable) Refresh(
	ctx context.Context,
	acceptStale bool,
) (text string, err error)

Refresh reloads the filter data. If acceptStale is true, refresh doesn't try to load the filter data from its URL when there is already a file in the cache directory, regardless of its staleness.

TODO(a.garipov): Consider making refresh return a reader instead of a string.

type RefreshableConfig

type RefreshableConfig struct {
	// URL is the URL used to refresh the filter.
	URL *url.URL

	// ID is the filter list ID for this filter.
	ID agd.FilterListID

	// CachePath is the path to the file containing the cached filter rules.
	CachePath string

	// Staleness is the time after which a file is considered stale.
	Staleness time.Duration

	// Timeout is the timeout for the HTTP client used by this refreshable
	// filter.
	Timeout time.Duration

	// MaxSize is the maximum size in bytes of the downloadable filter content.
	MaxSize uint64
}

RefreshableConfig is the configuration structure for a refreshable filter.

type RequestFilter

type RequestFilter interface {
	FilterRequest(ctx context.Context, req *dns.Msg, ri *agd.RequestInfo) (r Result, err error)
	ID() (id agd.FilterListID)
}

RequestFilter can filter a request based on the request info.

type Result

type Result interface {
	// MatchedRule returns data about the matched rule and its rule list.
	MatchedRule() (id agd.FilterListID, text agd.FilterRuleText)
	// contains filtered or unexported methods
}

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

type ResultAllowed

type ResultAllowed struct {
	List agd.FilterListID
	Rule agd.FilterRuleText
}

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

func (*ResultAllowed) MatchedRule

func (a *ResultAllowed) MatchedRule() (id agd.FilterListID, text agd.FilterRuleText)

MatchedRule implements the Result interface for *ResultAllowed.

type ResultBlocked

type ResultBlocked struct {
	List agd.FilterListID
	Rule agd.FilterRuleText
}

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

func (*ResultBlocked) MatchedRule

func (b *ResultBlocked) MatchedRule() (id agd.FilterListID, text agd.FilterRuleText)

MatchedRule implements the Result interface for *ResultBlocked.

type ResultModified

type ResultModified struct {
	// Msg is the new, rewritten or modified request or response.
	Msg *dns.Msg

	// List is the ID of the filter list.
	List agd.FilterListID

	// Rule is the filtering rule that triggered the rewrite.
	Rule agd.FilterRuleText
}

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

func (*ResultModified) Clone

func (m *ResultModified) Clone(c *dnsmsg.Cloner) (clone *ResultModified)

Clone returns a deep clone of m.

func (*ResultModified) CloneForReq

func (m *ResultModified) CloneForReq(c *dnsmsg.Cloner, req *dns.Msg) (clone *ResultModified)

CloneForReq returns a deep clone of m with Msg set as a reply to req, if any.

func (*ResultModified) MatchedRule

func (m *ResultModified) MatchedRule() (id agd.FilterListID, text agd.FilterRuleText)

MatchedRule implements the Result interface for *ResultModified.

Directories

Path Synopsis
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.
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.
Package filtertest contains common constants and utilities for the internal filtering packages.
Package filtertest contains common constants and utilities for the internal filtering packages.
Package resultcache contains a cache for filtering results.
Package resultcache contains a cache for filtering results.
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.
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.
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