Documentation ¶
Overview ¶
Package lookup implements index structures that we use to improve matching speed in the engines.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DomainsTable ¶
type DomainsTable struct {
// contains filtered or unexported fields
}
DomainsTable is a lookup table that uses domains from the $domain modifier to speed up the rules search. Only the rules with $domain modifier are eligible for this lookup table.
func NewDomainsTable ¶
func NewDomainsTable(rs *filterlist.RuleStorage) (s *DomainsTable)
NewDomainsTable creates a new instance of the DomainsTable.
func (*DomainsTable) MatchAll ¶
func (d *DomainsTable) MatchAll(r *rules.Request) (result []*rules.NetworkRule)
MatchAll implements the LookupTable interface for *DomainsTable.
func (*DomainsTable) TryAdd ¶
func (d *DomainsTable) TryAdd(f *rules.NetworkRule, storageIdx int64) (ok bool)
TryAdd implements the LookupTable interface for *DomainsTable.
type SeqScanTable ¶
type SeqScanTable struct {
// contains filtered or unexported fields
}
SeqScanTable is basically just a list of network rules that are scanned sequentially. Here we put the rules that are not eligible for other tables.
func (*SeqScanTable) MatchAll ¶
func (s *SeqScanTable) MatchAll(r *rules.Request) (result []*rules.NetworkRule)
MatchAll implements the LookupTable interface for *SeqScanTable.
func (*SeqScanTable) TryAdd ¶
func (s *SeqScanTable) TryAdd(f *rules.NetworkRule, _ int64) (ok bool)
TryAdd implements the LookupTable interface for *SeqScanTable.
type ShortcutsTable ¶
type ShortcutsTable struct {
// contains filtered or unexported fields
}
ShortcutsTable is a table that relies on the rule "shortcuts" to quickly find matching rules. Here's how it works:
- We extract from the rule the longest substring without special characters from, this string is called a "shortcut".
- We take a part of it of length "shortcutLength" and put it to the internal hashmap.
- When we match a request, we take all substrings of length "shortcutsLength" from it and check if there're any rules in the hashmap.
Note that only the rules with a shortcut are eligible for this table.
func NewShortcutsTable ¶
func NewShortcutsTable(rs *filterlist.RuleStorage) (s *ShortcutsTable)
NewShortcutsTable creates a new instance of the ShortcutsTable.
func (*ShortcutsTable) MatchAll ¶
func (s *ShortcutsTable) MatchAll(r *rules.Request) (result []*rules.NetworkRule)
MatchAll implements the LookupTable interface for *ShortcutsTable.
func (*ShortcutsTable) TryAdd ¶
func (s *ShortcutsTable) TryAdd(f *rules.NetworkRule, storageIdx int64) (ok bool)
TryAdd implements the LookupTable interface for *ShortcutsTable.
type Table ¶
type Table interface { // TryAdd attempts to add the rule to the lookup table. // It returns true/false depending on whether the rule is eligible for // this lookup table. TryAdd(f *rules.NetworkRule, storageIdx int64) (ok bool) // MatchAll finds all matching rules from this lookup table. MatchAll(r *rules.Request) (result []*rules.NetworkRule) }
Table is a common interface for all lookup tables.