Table of Contents

Class CachedIpFilter

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

Provides a stage of an IP filter pipe that remembers its next stage's verdict for each destination.

public class CachedIpFilter : IIpFilter, IDisposable
Inheritance
CachedIpFilter
Implements
Inherited Members

Remarks

A verdict is remembered by the destination alone, whatever the flow's protocol, so the next stage's verdicts must not depend on the protocol. 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

CachedIpFilter(IIpFilter, TimeSpan, bool)

Initializes a new instance of the CachedIpFilter class.

public CachedIpFilter(IIpFilter nextFilter, TimeSpan timeout, bool autoDisposeNextFilter = true)

Parameters

nextFilter IIpFilter

The stage whose verdicts to remember.

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: this stage holds no rule.

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(IpProtocol, IpEndPointValue)

Decides what happens to a flow.

public FilterAction Process(IpProtocol protocol, IpEndPointValue endPoint)

Parameters

protocol IpProtocol

The flow's protocol.

endPoint IpEndPointValue

The flow's destination.

Returns

FilterAction

The verdict; Default when the pipe has no objection.

Remarks

The verdict remembered for the destination answers, whatever protocol asked for it first.

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