rulelist

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

Documentation

Overview

Package rulelist contains the implementation of the standard rule-list filter that wraps an urlfilter filtering-engine.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Immutable

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

Immutable is a rule-list filter that doesn't refresh or change. It is used for users' custom rule-lists as well as in service blocking.

TODO(a.garipov): Consider not using rule-list engines for service and custom filters at all. It could be faster to simply go through all enabled rules sequentially instead. Alternatively, rework the urlfilter.DNSEngine and make it use the sequential scan if the number of rules is less than some constant value.

See AGDNS-342.

func NewImmutable

func NewImmutable(
	text string,
	id agd.FilterListID,
	svcID agd.BlockedServiceID,
	memCacheSize int,
	useMemCache bool,
) (f *Immutable, err error)

NewImmutable returns a new immutable DNS request and response filter using the provided rule text and ID.

func (Immutable) DNSResult

func (f Immutable) DNSResult(
	clientIP netip.Addr,
	clientName string,
	host string,
	rrType dnsmsg.RRType,
	isAns bool,
) (res *urlfilter.DNSResult)

DNSResult returns the result of applying the urlfilter DNS filtering engine. If the request is not filtered, DNSResult returns nil.

func (Immutable) ID

func (f Immutable) ID() (id agd.FilterListID, svcID agd.BlockedServiceID)

ID returns the filter list ID of this rule list filter, as well as the ID of the blocked service, if any.

func (Immutable) RulesCount

func (f Immutable) RulesCount() (n int)

RulesCount returns the number of rules in the filter's engine.

func (Immutable) URLFilterID

func (f Immutable) URLFilterID() (n int)

URLFilterID returns the synthetic ID used for the urlfilter module.

type Refreshable

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

Refreshable is a refreshable DNS request and response filter based on filter rule lists.

TODO(a.garipov): Consider adding a separate version that uses a single engine for multiple rule lists and using it to optimize the filtering using default filtering groups.

func NewFromString

func NewFromString(
	text string,
	id agd.FilterListID,
	svcID agd.BlockedServiceID,
	memCacheSize int,
	useMemCache bool,
) (f *Refreshable, err error)

NewFromString returns a new DNS request and response filter using the provided rule text and ID.

TODO(a.garipov): Only used in tests. Consider removing later.

func NewRefreshable

func NewRefreshable(
	c *internal.RefreshableConfig,
	memCacheSize int,
	useMemCache bool,
) (f *Refreshable)

NewRefreshable returns a new refreshable DNS request and response filter based on the provided rule list. c must be non-nil. The initial refresh should be called explicitly if necessary.

func (*Refreshable) DNSResult

func (f *Refreshable) DNSResult(
	clientIP netip.Addr,
	clientName string,
	host string,
	rrType dnsmsg.RRType,
	isAns bool,
) (res *urlfilter.DNSResult)

DNSResult returns the result of applying the urlfilter DNS filtering engine. If the request is not filtered, DNSResult returns nil.

func (Refreshable) ID

func (f Refreshable) ID() (id agd.FilterListID, svcID agd.BlockedServiceID)

ID returns the filter list ID of this rule list filter, as well as the ID of the blocked service, if any.

func (*Refreshable) Refresh

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

Refresh reloads the rule list data. If acceptStale is true, do not try to load the list from its URL when there is already a file in the cache directory, regardless of its staleness.

func (*Refreshable) RulesCount

func (f *Refreshable) RulesCount() (n int)

RulesCount returns the number of rules in the filter's engine.

func (Refreshable) URLFilterID

func (f Refreshable) URLFilterID() (n int)

URLFilterID returns the synthetic ID used for the urlfilter module.

Jump to

Keyboard shortcuts

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