Table of Contents

Class SqliteDomainFilter

Namespace
VpnHood.Core.Filtering.Sqlite
Assembly
VpnHood.Core.Filtering.Sqlite.dll

Provides a stage of a domain filter pipe that decides by the sets of a split domain database.

public sealed class SqliteDomainFilter : IDomainFilter, IDisposable
Inheritance
SqliteDomainFilter
Implements
Inherited Members

Remarks

Its own sets decide first: a name in the block set is blocked, one in the exclude set excluded, and one in the include set included, which sends its flows through the tunnel past every IP filter; any other name gets the next stage's verdict. An entry matches its domain and every subdomain: a lookup tries the name and each of its parent domains. Names are compared as NormalizeDomain(string?) gives them.

The database is opened read-only when the stage is made and held until its disposal, so it stays readable while a manifest write deletes its file; which of its sets have rows is read once then, as it does not change. All threads' lookups share its one connection, one at a time; a lookup after the disposal finds no member.

Constructors

SqliteDomainFilter(IDomainFilter?, string, bool)

Initializes a new instance of the SqliteDomainFilter class, and opens its database.

public SqliteDomainFilter(IDomainFilter? next, string dbPath, bool autoDisposeNextFilter = true)

Parameters

next IDomainFilter

The stage that decides the names the database's sets do not match, or null to give them Default.

dbPath string

The path of the split domain database.

autoDisposeNextFilter bool

true to dispose next with this stage.

Properties

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 database's three sets 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()

Closes the database, and 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 database's sets, then by the next stage.

public FilterAction Process(string? domain)

Parameters

domain string

The name, or null.

Returns

FilterAction

The verdict of the first set 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

Remarks

It occurs when the next stage's event does: the stage's own database does not change.