blocklist

package
v1.7.2 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockList

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

BlockList type

Matching semantics:

  • A bare domain (e.g. "example.com") blocks that exact name AND every subdomain ("sub.example.com", "a.b.example.com", ...). This mirrors how Pi-hole/AdGuard/dnsmasq treat a blocked domain and makes the popular plain-domain lists (e.g. hagezi *-onlydomains) work as users expect.
  • A "*.example.com" wildcard blocks subdomains only, not the apex.

func New

func New(cfg *config.Config) *BlockList

New returns a new BlockList.

Configured whitelist/blocklist entries and existing local blocklist files are loaded synchronously so filtering is active as soon as New returns. Remote blocklist refresh runs asynchronously — a slow or unreachable source used to leave ServeDNS with empty maps for the entire HTTP timeout window even when local files were available.

func (*BlockList) Exists

func (b *BlockList) Exists(key string) bool

(*BlockList).Exists exists returns whether or not a key exists in the cache.

func (*BlockList) Get

func (b *BlockList) Get(key string) (bool, error)

(*BlockList).Get get returns the entry for a key or an error.

func (*BlockList) Length

func (b *BlockList) Length() int

(*BlockList).Length length returns the caches length.

func (*BlockList) Name

func (b *BlockList) Name() string

(*BlockList).Name name return middleware name.

func (*BlockList) Remove

func (b *BlockList) Remove(key string) bool

(*BlockList).Remove removes an entry from the blocklist.

The disk write happens outside b.mu so concurrent DNS queries (which take mu.RLock in ServeDNS) are not blocked during I/O.

func (*BlockList) RemoveBatch added in v1.6.6

func (b *BlockList) RemoveBatch(keys []string) int

(*BlockList).RemoveBatch removes multiple entries in a single mutation and a single disk write. Returns the number actually removed (excluding entries that weren't present).

func (*BlockList) ServeDNS

func (b *BlockList) ServeDNS(ctx context.Context, ch *middleware.Chain)

(*BlockList).ServeDNS serveDNS implements the Handle interface.

func (*BlockList) Set

func (b *BlockList) Set(key string) bool

(*BlockList).Set sets a value in the BlockList.

The disk write happens outside b.mu so concurrent DNS queries (which take mu.RLock in ServeDNS) are not blocked during I/O.

func (*BlockList) SetBatch added in v1.6.6

func (b *BlockList) SetBatch(keys []string) int

(*BlockList).SetBatch adds multiple entries in a single mutation and a single disk write. Whitelisted keys are skipped. Returns the number actually added (excluding duplicates and whitelisted entries).

Jump to

Keyboard shortcuts

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