Documentation
¶
Overview ¶
Package filterlist provides methods to work with filter lists.
Index ¶
- Variables
- type Bytes
- type BytesConfig
- type File
- type FileConfig
- type Interface
- type RuleScanner
- type RuleStorage
- func (s *RuleStorage) Close() (err error)
- func (s *RuleStorage) NewRuleStorageScanner() (sc *RuleStorageScanner)
- func (s *RuleStorage) RetrieveHostRule(id StorageID) (hr *rules.HostRule)
- func (s *RuleStorage) RetrieveNetworkRule(id StorageID) (nr *rules.NetworkRule)
- func (s *RuleStorage) RetrieveRule(id StorageID) (r rules.Rule, err error)
- func (s *RuleStorage) SizeEstimate() (est datasize.ByteSize)
- type RuleStorageScanner
- type StorageID
- type String
- type StringConfig
Constants ¶
This section is empty.
Variables ¶
var ErrRuleRetrieval errors.Error = "cannot retrieve the rule"
ErrRuleRetrieval signals that the rule cannot be retrieved by the specified index.
Functions ¶
This section is empty.
Types ¶
type Bytes ¶ added in v0.21.0
type Bytes struct {
// contains filtered or unexported fields
}
Bytes is an Interface implementation which stores rules within a byte slice.
func NewBytes ¶ added in v0.21.0
func NewBytes(conf *BytesConfig) (s *Bytes)
NewBytes creates a new bytes-based rule list with the given configuration.
func (*Bytes) NewScanner ¶ added in v0.21.0
func (b *Bytes) NewScanner() (sc *RuleScanner)
NewScanner implements the Interface interface for *Bytes.
func (*Bytes) RetrieveRule ¶ added in v0.21.0
RetrieveRule implements the Interface interface for *Bytes.
type BytesConfig ¶ added in v0.21.0
type BytesConfig struct {
// RulesText is the slice of bytes containing rules, each rule is separated
// by a newline. It must not be modified after calling [NewBytes].
RulesText []byte
// ID is the rule list identifier.
ID rules.ListID
// IgnoreCosmetic tells whether to ignore cosmetic rules or not.
IgnoreCosmetic bool
}
BytesConfig represents configuration for a bytes-based rule list.
type File ¶ added in v0.21.0
type File struct {
// contains filtered or unexported fields
}
File is an Interface implementation which stores rules within a file.
func NewFile ¶ added in v0.21.0
func NewFile(conf *FileConfig) (f *File, err error)
NewFile creates a new file-based rule list with the given configuration.
func (*File) NewScanner ¶ added in v0.21.0
func (f *File) NewScanner() (sc *RuleScanner)
NewScanner creates a new rules scanner that reads the list contents. The returned scanner should not be used concurrently with RetrieveRule.
func (*File) RetrieveRule ¶ added in v0.21.0
RetrieveRule finds and deserializes rule by its index. If there's no rule by that index or rule is invalid, it will return an error. It should not be used concurrently with the scanner returned from NewScanner.
type FileConfig ¶ added in v0.21.0
type FileConfig struct {
// Path is the path to the file with rules.
Path string
// ID is the rule list identifier.
ID rules.ListID
// IgnoreCosmetic tells whether to ignore cosmetic rules or not.
IgnoreCosmetic bool
}
FileConfig represents configuration for a file-based rule list.
type Interface ¶ added in v0.21.0
type Interface interface {
// ListID returns the rule-list identifier.
ListID() (id rules.ListID)
// NewScanner creates a new scanner that reads the list contents.
NewScanner() (scanner *RuleScanner)
// RetrieveRule returns a rule by its index. ruleIdx must not be negative.
RetrieveRule(ruleIdx int64) (r rules.Rule, err error)
// SizeEstimate returns the size estimate of all rule-lists in the
// filtering-rule list.
SizeEstimate() (est datasize.ByteSize)
io.Closer
}
Interface represents a set of filtering rules.
type RuleScanner ¶
type RuleScanner struct {
// contains filtered or unexported fields
}
RuleScanner implements an interface for reading filtering rules.
func NewRuleScanner ¶
NewRuleScanner returns a new RuleScanner to read from the given reader.
func (*RuleScanner) Rule ¶
func (s *RuleScanner) Rule() (r rules.Rule, idx int64)
Rule returns the most recent rule generated by a call to Scan, and the index of this rule's text.
func (*RuleScanner) Scan ¶
func (s *RuleScanner) Scan() (ok bool)
Scan advances the RuleScanner to the next rule, which will then be available through the Rule method. It returns false when the scan stops, either by reaching the end of the input or an error.
type RuleStorage ¶
type RuleStorage struct {
// contains filtered or unexported fields
}
RuleStorage is an abstraction that combines several rule lists. It can be scanned using a RuleStorageScanner, and also it allows retrieving rules by its index.
The idea is to keep rules in a serialized format (even original format in the case of File) and create them in a lazy manner only when we really need them. When the filtering engine is being initialized, we need to scan the rule lists once in order to fill up the index. We use rule indexes as a unique rule identifier instead of the rule itself. The rule is created (see RuleStorage.RetrieveRule) only when there's a chance that it's needed.
func NewRuleStorage ¶
func NewRuleStorage(lists []Interface) (s *RuleStorage, err error)
NewRuleStorage creates a new instance of the *RuleStorage and validates the list of rules specified.
func (*RuleStorage) Close ¶
func (s *RuleStorage) Close() (err error)
Close closes the storage instance.
func (*RuleStorage) NewRuleStorageScanner ¶
func (s *RuleStorage) NewRuleStorageScanner() (sc *RuleStorageScanner)
NewRuleStorageScanner creates a new instance of RuleStorageScanner. It can be used to read and parse all the storage contents.
func (*RuleStorage) RetrieveHostRule ¶
func (s *RuleStorage) RetrieveHostRule(id StorageID) (hr *rules.HostRule)
RetrieveHostRule is a helper method that retrieves a host rule from the storage. It returns a pointer to the rule or nil in any other case (not found or error).
TODO(a.garipov): Rewrite into a helper function instead of a method and return the error.
func (*RuleStorage) RetrieveNetworkRule ¶
func (s *RuleStorage) RetrieveNetworkRule(id StorageID) (nr *rules.NetworkRule)
RetrieveNetworkRule is a helper method that retrieves a network rule from the storage. It returns a pointer to the rule or nil in any other case (not found or error).
TODO(a.garipov): Rewrite into a helper function instead of a method and return the error.
func (*RuleStorage) RetrieveRule ¶
func (s *RuleStorage) RetrieveRule(id StorageID) (r rules.Rule, err error)
RetrieveRule looks for the filtering rule in this storage. id is the storage ID as received from the scanner.
func (*RuleStorage) SizeEstimate ¶ added in v0.22.0
func (s *RuleStorage) SizeEstimate() (est datasize.ByteSize)
SizeEstimate returns the size estimate of all rule-lists in the storage.
type RuleStorageScanner ¶
type RuleStorageScanner struct {
// Scanners is the list of list scanners backing this combined scanner,
Scanners []*RuleScanner
// contains filtered or unexported fields
}
RuleStorageScanner scans multiple RuleScanner instances. The rule index is built from the rule index in the list + the list ID. First 4 bytes is the rule index in the list, second 4 bytes is the list ID.
func (*RuleStorageScanner) Rule ¶
func (s *RuleStorageScanner) Rule() (r rules.Rule, id StorageID)
Rule returns the most recent rule generated by a call to *RuleStorageScanner.Scan, if any, and the ID of this rule.
func (*RuleStorageScanner) Scan ¶
func (s *RuleStorageScanner) Scan() (ok bool)
Scan advances the RuleStorageScanner to the next rule, which will then be available through the Rule method. It returns false when the scan stops, either by reaching the end of the input or an error.
type StorageID ¶ added in v0.22.0
type StorageID struct {
// contains filtered or unexported fields
}
StorageID is a compound identifier of a single rule.
func NewStorageID ¶ added in v0.22.0
NewStorageID converts a pair of a rules.ListID and rule-list index into a StorageID. ruleIdx must not be negative.
func (StorageID) AppendBinary ¶ added in v0.23.0
AppendBinary implements the encoding.BinaryAppender interface for StorageID. Backwards compatibility is only guaranteed within one version of the module.
func (*StorageID) UnmarshalBinary ¶ added in v0.23.0
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface for *StorageID. b should be data that has been encoded by StorageID.AppendBinary.
func (*StorageID) UnmarshalBinaryRest ¶ added in v0.23.0
UnmarshalBinaryRest implements the ufencoding.BinaryUnmarshalerRest interface for *StorageID. b should be data that has been encoded by StorageID.AppendBinary.
type String ¶ added in v0.21.0
type String struct {
// contains filtered or unexported fields
}
String is an Interface implementation which stores rules within a string.
func NewString ¶ added in v0.21.0
func NewString(conf *StringConfig) (s *String)
NewString creates a new string-based rule list with the given configuration.
func (*String) NewScanner ¶ added in v0.21.0
func (s *String) NewScanner() (sc *RuleScanner)
NewScanner implements the Interface interface for *String.
func (*String) RetrieveRule ¶ added in v0.21.0
RetrieveRule implements the Interface interface for *String.
type StringConfig ¶ added in v0.21.0
type StringConfig struct {
// RulesText is a string with filtering rules (one per line).
RulesText string
// ID is the rule list identifier.
ID rules.ListID
// IgnoreCosmetic tells whether to ignore cosmetic rules or not.
IgnoreCosmetic bool
}
StringConfig represents configuration for a string-based rule list.