Table of Contents

Class SqliteIpFilter

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

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

public sealed class SqliteIpFilter : IIpFilter, IDisposable
Inheritance
SqliteIpFilter
Implements
Inherited Members

Remarks

The next stage decides first, and its verdict stands unless it is Default. Then an address in the block set is blocked; one in the exclude set excluded; and, when the include set is not empty, one outside it is excluded too, so include sets chained this way meet. The rest get Default: the stage's own sets never give Include. An IPv4-mapped IPv6 address is looked up as IPv4.

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

SqliteIpFilter(IIpFilter?, string, bool)

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

public SqliteIpFilter(IIpFilter? next, string dbPath, bool autoDisposeNextFilter = true)

Parameters

next IIpFilter

The stage that decides first, or null.

dbPath string

The path of the split IP 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.

Methods

Dispose()

Closes the database, 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 next stage decides first; see the class's remarks for the order of the sets.

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.