Table of Contents

Class CachedDomainFilter

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

Provides a stage of a domain filter pipe that remembers its next stage's verdict for each domain name.

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

Remarks

A verdict expires once it has gone unused for the timeout. When the next stage raises Changed, every remembered verdict is dropped, and the event is raised as this stage's own.

Constructors

CachedDomainFilter(IDomainFilter?, TimeSpan, bool)

Initializes a new instance of the CachedDomainFilter class.

public CachedDomainFilter(IDomainFilter? nextFilter, TimeSpan timeout, bool autoDisposeNextFilter = true)

Parameters

nextFilter IDomainFilter

The stage whose verdicts to remember, or null, which makes every verdict Default.

timeout TimeSpan

How long a verdict may go unused before it expires.

autoDisposeNextFilter bool

true to dispose nextFilter 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

The next stage's value, or true without one: this stage holds no rule.

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

ClearCache()

Drops every remembered verdict, expired or not.

public void ClearCache()

Dispose()

Releases the remembered verdicts, 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: the next stage's verdict, remembered.

public FilterAction Process(string? domain)

Parameters

domain string

The name, or null, whose verdict is not remembered.

Returns

FilterAction

The verdict; Default when the pipe has no objection.

Remarks

Names are remembered as given, so names that differ only in case are remembered apart.

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