Table of Contents

Class StaticDomainFilter

Namespace
VpnHood.Core.Filtering.Abstractions
Assembly
VpnHood.Core.Filtering.Abstractions.dll

Provides a stage of a domain filter pipe that decides by three lists of domains held in memory: blocked, excluded and included.

public class StaticDomainFilter : IDomainFilter, IDisposable
Inheritance
StaticDomainFilter
Implements
Inherited Members

Remarks

An entry matches its domain and its subdomains, with or without a leading *., and names and entries are compared as NormalizeDomain(string?) gives them; but if no exact match is found, a lookup tests only the entry just before the name in the order of their reversed labels, so a listed parent is missed when that entry is not itself a parent, as with example-cdn.com between example.com and www.example.com. A name on the block list is blocked, one on the exclude list excluded, and one on the include list included, in that order; any other name gets the next stage's verdict. Setting a list raises Changed.

Constructors

StaticDomainFilter(IDomainFilter?, bool)

Initializes a new instance of the StaticDomainFilter class, with empty lists.

public StaticDomainFilter(IDomainFilter? nextFilter, bool autoDisposeNextFilter = true)

Parameters

nextFilter IDomainFilter

The stage that decides the names no list matches, or null to give them Default.

autoDisposeNextFilter bool

true to dispose nextFilter with this stage.

Properties

Blocks

Gets or sets the domains whose flows are blocked. The default is empty.

public IReadOnlyList<string> Blocks { get; set; }

Property Value

IReadOnlyList<string>

Excludes

Gets or sets the domains whose flows go around the tunnel. The default is empty.

public IReadOnlyList<string> Excludes { get; set; }

Property Value

IReadOnlyList<string>

Includes

Gets or sets the domains whose flows go through the tunnel, whatever an IP filter says. The default is empty.

public IReadOnlyList<string> Includes { get; set; }

Property Value

IReadOnlyList<string>

IsEmpty

Gets a value indicating whether the pipe holds no rule, so it can only answer Default. Read it again when Changed occurs.

public bool IsEmpty { get; }

Property Value

bool

true while the three lists are empty and the next stage, if any, is empty too.

Remarks

The client reads a flow's domain name from its TLS handshake only while the pipe is not empty, or while its options force the names to be logged.

Methods

Dispose()

Disposes the next stage when this stage was made to.

public void Dispose()

Process(string?)

Decides what happens to a flow for a domain name, by the lists, then by the next stage.

public FilterAction Process(string? domain)

Parameters

domain string

The name, or null.

Returns

FilterAction

The verdict of the first list that matches the name, or else the next stage's; Default for a null, empty or white-space name, which the next stage is not asked about.

Reconfigure(CancellationToken)

Tells the pipe that its configuration outside the program, such as a database's path, may have changed.

public Task Reconfigure(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task

A task that represents the asynchronous operation.

Remarks

Each stage passes it to its next one; a stage that owns such configuration reads it again and swaps its own parts, raising Changed if its verdicts may differ.

Events

Changed

Occurs when the pipe's verdicts may have changed, as when a stage swaps its rules. A stage raises its next stage's event as its own, so the event reaches the outermost stage; a stage whose verdicts never change never raises it.

public event EventHandler? Changed

Event Type

EventHandler