domainset

package
v1.10.1 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: AGPL-3.0 Imports: 13 Imported by: 1

Documentation

Index

Constants

View Source
const MaxLinearDomains = 16

MaxLinearDomains is the maximum number of domain rules under which a linear matcher can outperform a map matcher.

View Source
const MaxLinearSuffixes = 4

MaxLinearSuffixes is the maximum number of suffix rules under which a linear matcher can outperform a trie matcher.

Variables

This section is empty.

Functions

func ParseCapacityHint added in v1.3.0

func ParseCapacityHint(line string) ([4]int, bool, error)

Types

type Builder

type Builder [4]MatcherBuilder

Builder stores the content of a domain set and provides methods for writing in different formats.

func BuilderFromGob

func BuilderFromGob(r io.Reader) (Builder, error)

func BuilderFromText

func BuilderFromText(text string) (Builder, error)

func BuilderFromTextFast added in v1.3.0

func BuilderFromTextFast(text string) (Builder, error)

func BuilderFromTextFunc added in v1.3.0

func BuilderFromTextFunc(
	text string,
	newDomainMatcherBuilderFunc,
	newSuffixMatcherBuilderFunc,
	newKeywordMatcherBuilderFunc,
	newRegexpMatcherBuilderFunc func(int) MatcherBuilder,
) (Builder, error)

func (Builder) DomainSet

func (dsb Builder) DomainSet() (DomainSet, error)

func (Builder) WriteGob

func (dsb Builder) WriteGob(w io.Writer) error

func (Builder) WriteText

func (dsb Builder) WriteText(w io.Writer) error

type BuilderGob added in v1.3.0

type BuilderGob struct {
	Domains  DomainMapMatcher
	Suffixes *DomainSuffixTrie
	Keywords KeywordLinearMatcher
	Regexps  RegexpMatcherBuilder
}

BuilderGob is the builder's gob serialization structure.

func BuilderGobFromBuilder added in v1.3.0

func BuilderGobFromBuilder(dsb Builder) (bg BuilderGob)

func BuilderGobFromReader added in v1.3.0

func BuilderGobFromReader(r io.Reader) (bg BuilderGob, err error)

func (BuilderGob) Builder added in v1.3.0

func (bg BuilderGob) Builder() Builder

func (BuilderGob) WriteGob added in v1.3.0

func (bg BuilderGob) WriteGob(w io.Writer) error

type Config

type Config struct {
	Name string `json:"name"`
	Type string `json:"type"`
	Path string `json:"path"`
}

Config is the configuration for a DomainSet.

func (Config) DomainSet

func (dsc Config) DomainSet() (DomainSet, error)

DomainSet creates a DomainSet from the configuration.

type DomainBinarySearchMatcher added in v1.7.0

type DomainBinarySearchMatcher []string

DomainBinarySearchMatcher matches domain rules using binary search.

func DomainBinarySearchMatcherFromSlice added in v1.7.0

func DomainBinarySearchMatcherFromSlice(domains []string) DomainBinarySearchMatcher

DomainBinarySearchMatcherFromSlice creates a DomainBinarySearchMatcher from a slice of domain rules.

func (*DomainBinarySearchMatcher) AppendTo added in v1.7.0

func (dbsmp *DomainBinarySearchMatcher) AppendTo(matchers []Matcher) ([]Matcher, error)

AppendTo implements the MatcherBuilder AppendTo method.

func (*DomainBinarySearchMatcher) Insert added in v1.7.0

func (dbsmp *DomainBinarySearchMatcher) Insert(rule string)

Insert implements the MatcherBuilder Insert method.

func (DomainBinarySearchMatcher) Match added in v1.7.0

func (dbsm DomainBinarySearchMatcher) Match(domain string) bool

Match implements the Matcher Match method.

func (DomainBinarySearchMatcher) MatcherCount added in v1.7.0

func (dbsm DomainBinarySearchMatcher) MatcherCount() int

MatcherCount implements the MatcherBuilder MatcherCount method.

func (DomainBinarySearchMatcher) Rules added in v1.7.0

func (dbsm DomainBinarySearchMatcher) Rules() []string

Rules implements the MatcherBuilder Rules method.

type DomainLinearMatcher added in v1.3.0

type DomainLinearMatcher []string

DomainLinearMatcher matches domain rules using linear search. It is faster than DomainMapMatcher when the number of rules is no greater than MaxLinearDomains.

func (*DomainLinearMatcher) AppendTo added in v1.3.0

func (dlmp *DomainLinearMatcher) AppendTo(matchers []Matcher) ([]Matcher, error)

AppendTo implements the MatcherBuilder AppendTo method.

func (*DomainLinearMatcher) Insert added in v1.3.0

func (dlmp *DomainLinearMatcher) Insert(rule string)

Insert implements the MatcherBuilder Insert method.

func (DomainLinearMatcher) Match added in v1.3.0

func (dlm DomainLinearMatcher) Match(domain string) bool

Match implements the Matcher Match method.

func (DomainLinearMatcher) MatcherCount added in v1.3.0

func (dlm DomainLinearMatcher) MatcherCount() int

MatcherCount implements the MatcherBuilder MatcherCount method.

func (DomainLinearMatcher) Rules added in v1.3.0

func (dlm DomainLinearMatcher) Rules() []string

Rules implements the MatcherBuilder Rules method.

type DomainMapMatcher added in v1.3.0

type DomainMapMatcher map[string]struct{}

DomainMapMatcher matches domain rules using a map. It is faster than DomainLinearMatcher when the number of rules is greater than MaxLinearDomains.

func DomainMapMatcherFromSlice added in v1.3.0

func DomainMapMatcherFromSlice(domains []string) DomainMapMatcher

DomainMapMatcherFromSlice creates a DomainMapMatcher from a slice of domain rules.

func (*DomainMapMatcher) AppendTo added in v1.3.0

func (dmmp *DomainMapMatcher) AppendTo(matchers []Matcher) ([]Matcher, error)

AppendTo implements the MatcherBuilder AppendTo method.

func (DomainMapMatcher) Insert added in v1.3.0

func (dmm DomainMapMatcher) Insert(rule string)

Insert implements the MatcherBuilder Insert method.

func (DomainMapMatcher) Match added in v1.3.0

func (dmm DomainMapMatcher) Match(domain string) bool

Match implements the Matcher Match method.

func (DomainMapMatcher) MatcherCount added in v1.3.0

func (dmm DomainMapMatcher) MatcherCount() int

MatcherCount implements the MatcherBuilder MatcherCount method.

func (DomainMapMatcher) Rules added in v1.3.0

func (dmm DomainMapMatcher) Rules() []string

Rules implements the MatcherBuilder Rules method.

type DomainSet

type DomainSet []Matcher

DomainSet is a set of domain matchers built from matching rules.

func (DomainSet) Match

func (ds DomainSet) Match(domain string) bool

Match returns whether the domain set contains the domain.

type DomainSuffixTrie

type DomainSuffixTrie struct {
	Included bool
	Children map[string]*DomainSuffixTrie
}

DomainSuffixTrie is a trie of domain parts segmented by '.'.

func DomainSuffixTrieFromSlice added in v1.3.0

func DomainSuffixTrieFromSlice(suffixes []string) *DomainSuffixTrie

func (*DomainSuffixTrie) AppendTo added in v1.3.0

func (dst *DomainSuffixTrie) AppendTo(matchers []Matcher) ([]Matcher, error)

AppendTo implements the MatcherBuilder AppendTo method.

func (*DomainSuffixTrie) Insert

func (dst *DomainSuffixTrie) Insert(domain string)

Insert inserts a domain suffix to the trie. Insertion purges the leaf node's children. If say, we insert "www.google.com" and then "google.com", The children of node "google" will be purged.

func (*DomainSuffixTrie) Keys

func (dst *DomainSuffixTrie) Keys() (keys []string)

Keys returns the keys of the trie.

func (*DomainSuffixTrie) Match

func (dst *DomainSuffixTrie) Match(domain string) bool

Match implements the Matcher Match method.

func (*DomainSuffixTrie) MatcherCount added in v1.3.0

func (dst *DomainSuffixTrie) MatcherCount() int

MatcherCount implements the MatcherBuilder MatcherCount method.

func (*DomainSuffixTrie) Rules added in v1.3.0

func (dst *DomainSuffixTrie) Rules() []string

Rules implements the MatcherBuilder Rules method.

type KeywordLinearMatcher added in v1.3.0

type KeywordLinearMatcher []string

KeywordLinearMatcher matches keyword rules by iterating over the keywords.

func (KeywordLinearMatcher) AppendTo added in v1.3.0

func (klm KeywordLinearMatcher) AppendTo(matchers []Matcher) ([]Matcher, error)

AppendTo implements the MatcherBuilder AppendTo method.

func (*KeywordLinearMatcher) Insert added in v1.3.0

func (klmp *KeywordLinearMatcher) Insert(rule string)

Insert implements the MatcherBuilder Insert method.

func (KeywordLinearMatcher) Match added in v1.3.0

func (klm KeywordLinearMatcher) Match(domain string) bool

Match implements the Matcher Match method.

func (KeywordLinearMatcher) MatcherCount added in v1.3.0

func (klm KeywordLinearMatcher) MatcherCount() int

MatcherCount implements the MatcherBuilder MatcherCount method.

func (KeywordLinearMatcher) Rules added in v1.3.0

func (klm KeywordLinearMatcher) Rules() []string

Rules implements the MatcherBuilder Rules method.

type Matcher added in v1.3.0

type Matcher interface {
	// Match returns whether the domain is matched by the matcher.
	Match(domain string) bool
}

Matcher provides the Match method.

type MatcherBuilder added in v1.3.0

type MatcherBuilder interface {
	// Insert inserts the rule string to the matcher.
	//
	// The rule string must not include the rule identifier.
	// For example, if the rule line is "suffix:google.com",
	// the rule string should be "google.com".
	Insert(rule string)

	// Rules returns the inserted rules as a slice.
	Rules() []string

	// MatcherCount returns the number of matchers that would be appended
	// to the matcher slice by calling [AppendTo].
	MatcherCount() int

	// AppendTo builds the matcher, appends the matcher to the matcher slice,
	// and returns the updated slice or an error.
	AppendTo(matchers []Matcher) ([]Matcher, error)
}

MatcherBuilder provides methods for building a Matcher.

func NewDomainBinarySearchMatcher added in v1.7.0

func NewDomainBinarySearchMatcher(capacity int) MatcherBuilder

NewDomainBinarySearchMatcher creates a DomainBinarySearchMatcher with the specified initial capacity.

func NewDomainLinearMatcher added in v1.3.0

func NewDomainLinearMatcher(capacity int) MatcherBuilder

NewDomainLinearMatcher creates a DomainLinearMatcher with the specified initial capacity.

func NewDomainMapMatcher added in v1.3.0

func NewDomainMapMatcher(capacity int) MatcherBuilder

NewDomainMapMatcher creates a DomainMapMatcher with the specified initial capacity.

func NewDomainSuffixTrie added in v1.3.0

func NewDomainSuffixTrie(capacity int) MatcherBuilder

func NewKeywordLinearMatcher added in v1.3.0

func NewKeywordLinearMatcher(capacity int) MatcherBuilder

NewKeywordLinearMatcher creates a KeywordLinearMatcher with the specified initial capacity.

func NewRegexpMatcherBuilder added in v1.3.0

func NewRegexpMatcherBuilder(capacity int) MatcherBuilder

NewRegexpMatcherBuilder creates a new RegexpMatcherBuilder with the specified initial capacity.

func NewSuffixLinearMatcher added in v1.3.0

func NewSuffixLinearMatcher(capacity int) MatcherBuilder

NewSuffixLinearMatcher creates a SuffixLinearMatcher with the specified initial capacity.

func NewSuffixMapMatcher added in v1.3.0

func NewSuffixMapMatcher(capacity int) MatcherBuilder

NewSuffixMapMatcher creates a SuffixMapMatcher with the specified initial capacity.

type RegexpMatcher added in v1.3.0

type RegexpMatcher regexp.Regexp

RegexpMatcher adapts regexp.Regexp to the Matcher interface.

func (*RegexpMatcher) Match added in v1.3.0

func (rlmp *RegexpMatcher) Match(domain string) bool

Match implements the Matcher Match method.

type RegexpMatcherBuilder added in v1.3.0

type RegexpMatcherBuilder []string

RegexpMatcherBuilder stores regular expressions for building RegexpMatcher instances.

func (RegexpMatcherBuilder) AppendTo added in v1.3.0

func (rmb RegexpMatcherBuilder) AppendTo(matchers []Matcher) ([]Matcher, error)

AppendTo implements the MatcherBuilder AppendTo method.

func (*RegexpMatcherBuilder) Insert added in v1.3.0

func (rmbp *RegexpMatcherBuilder) Insert(rule string)

Insert implements the MatcherBuilder Insert method.

func (RegexpMatcherBuilder) MatcherCount added in v1.3.0

func (rmb RegexpMatcherBuilder) MatcherCount() int

MatcherCount implements the MatcherBuilder MatcherCount method.

func (RegexpMatcherBuilder) Rules added in v1.3.0

func (rmb RegexpMatcherBuilder) Rules() []string

Rules implements the MatcherBuilder Rules method.

type SuffixLinearMatcher added in v1.3.0

type SuffixLinearMatcher []string

SuffixLinearMatcher matches suffix rules by iterating over the suffixes. It is faster than [SuffixTrieMatcher] when the number of rules is no greater than MaxLinearSuffixes.

func (*SuffixLinearMatcher) AppendTo added in v1.3.0

func (slmp *SuffixLinearMatcher) AppendTo(matchers []Matcher) ([]Matcher, error)

AppendTo implements the MatcherBuilder AppendTo method.

func (*SuffixLinearMatcher) Insert added in v1.3.0

func (slmp *SuffixLinearMatcher) Insert(rule string)

Insert implements the MatcherBuilder Insert method.

func (SuffixLinearMatcher) Match added in v1.3.0

func (slm SuffixLinearMatcher) Match(domain string) bool

Match implements the Matcher Match method.

func (SuffixLinearMatcher) MatcherCount added in v1.3.0

func (slm SuffixLinearMatcher) MatcherCount() int

MatcherCount implements the MatcherBuilder MatcherCount method.

func (SuffixLinearMatcher) Rules added in v1.3.0

func (slm SuffixLinearMatcher) Rules() []string

Rules implements the MatcherBuilder Rules method.

type SuffixMapMatcher added in v1.3.0

type SuffixMapMatcher map[string]struct{}

SuffixMapMatcher matches suffix rules using a single map.

func SuffixMapMatcherFromSlice added in v1.3.0

func SuffixMapMatcherFromSlice(suffixes []string) SuffixMapMatcher

SuffixMapMatcherFromSlice creates a SuffixMapMatcher from a slice of suffix rules.

func (*SuffixMapMatcher) AppendTo added in v1.3.0

func (smmp *SuffixMapMatcher) AppendTo(matchers []Matcher) ([]Matcher, error)

AppendTo implements the MatcherBuilder AppendTo method.

func (SuffixMapMatcher) Insert added in v1.3.0

func (smm SuffixMapMatcher) Insert(rule string)

Insert implements the MatcherBuilder Insert method.

func (SuffixMapMatcher) Match added in v1.3.0

func (smm SuffixMapMatcher) Match(domain string) bool

Match implements the Matcher Match method.

func (SuffixMapMatcher) MatcherCount added in v1.3.0

func (smm SuffixMapMatcher) MatcherCount() int

MatcherCount implements the MatcherBuilder MatcherCount method.

func (SuffixMapMatcher) Rules added in v1.3.0

func (smm SuffixMapMatcher) Rules() []string

Rules implements the MatcherBuilder Rules method.

Jump to

Keyboard shortcuts

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