Documentation ¶
Overview ¶
Package hashprefix defines a storage of hashes of domain names used for filtering and serving TXT records with domain-name hashes.
Index ¶
Constants ¶
const ( // PrefixLen is the length of the hash prefix of the filtered hostname. PrefixLen = 2 // PrefixEncLen is the encoded length of the hash prefix. Two text // bytes per one binary byte. PrefixEncLen = PrefixLen * 2 )
Hash and hash part length constants.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Filter ¶
type Filter struct {
// contains filtered or unexported fields
}
Filter is a filter that matches hosts by their hashes based on a hash-prefix table.
func NewFilter ¶
func NewFilter(c *FilterConfig) (f *Filter, err error)
NewFilter returns a new hash-prefix filter. c must not be nil.
func (*Filter) FilterRequest ¶
func (f *Filter) FilterRequest( ctx context.Context, req *dns.Msg, ri *agd.RequestInfo, ) (r internal.Result, err error)
FilterRequest implements the internal.RequestFilter interface for *Filter. It modifies the response if host matches f.
func (*Filter) ID ¶
func (f *Filter) ID() (id agd.FilterListID)
ID implements the internal.RequestFilter interface for *Filter.
type FilterConfig ¶
type FilterConfig struct { // Cloner is used to clone messages taken from filtering-result cache. Cloner *dnsmsg.Cloner // Hashes are the hostname hashes for this filter. Hashes *Storage // URL is the URL used to update the filter. URL *url.URL // ErrColl is used to collect non-critical and rare errors. ErrColl errcoll.Interface // Resolver is used to resolve hosts for the hash-prefix filter. Resolver agdnet.Resolver // ID is the ID of this hash storage for logging and error reporting. ID agd.FilterListID // CachePath is the path to the file containing the cached filtered // hostnames, one per line. CachePath string // ReplacementHost is the replacement host for this filter. Queries // matched by the filter receive a response with the IP addresses of // this host. ReplacementHost string // Staleness is the time after which a file is considered stale. Staleness time.Duration // CacheTTL is the time-to-live value used to cache the results of the // filter. // // TODO(a.garipov): Currently unused. See AGDNS-398. CacheTTL time.Duration // CacheSize is the size of the filter's result cache. CacheSize int // MaxSize is the maximum size in bytes of the downloadable rule-list. MaxSize uint64 }
FilterConfig is the hash-prefix filter configuration structure.
type Matcher ¶
type Matcher struct {
// contains filtered or unexported fields
}
Matcher is a hash-prefix matcher that uses the hash-prefix storages as the source of its data.
func NewMatcher ¶
NewMatcher returns a new hash-prefix matcher. storages is a mapping of domain-name suffixes to the storage containing hashes for this domain.
func (*Matcher) MatchByPrefix ¶
func (m *Matcher) MatchByPrefix( _ context.Context, host string, ) (hashes []string, matched bool, err error)
MatchByPrefix implements the [filter.HashMatcher] interface for *Matcher. It returns the matched hashes if the host matched one of the domain names in m's storages.
TODO(a.garipov): Use the context for logging etc.
type Prefix ¶
Prefix is the type of the SHA256 hash prefix used to match against the domain-name database.
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
Storage stores hashes of the filtered hostnames. All methods are safe for concurrent use.
TODO(a.garipov): See if we could unexport this.
func NewStorage ¶
NewStorage returns a new hash storage containing hashes of the domain names listed in hostnames, one domain name per line.
func (*Storage) Hashes ¶
Hashes returns all hashes starting with the given prefixes, if any. The resulting slice shares storage for all underlying strings.
TODO(a.garipov): This currently doesn't take duplicates into account.