Table of Contents

Class VpnServiceHost

Namespace
VpnHood.Core.Client.VpnServices.Host
Assembly
VpnHood.Core.Client.VpnServices.Host.dll

Hosts the VPN service's side of the app: it takes the app's requests, connects with the options the app saved, and reports the connection's state back.

public class VpnServiceHost : IVpnTunnelHolder, IDisposable
Inheritance
VpnServiceHost
Implements
Inherited Members

Remarks

The state goes to the config folder as VpnStatusFileName at each change, and with each answer. A session that ended because the server moved, or the network lacks its address's IP version, is followed at once by a new connect where the platform lets the service connect by itself (CanReconnect).

Constructors

VpnServiceHost(string, string, IVpnServiceHandler, IClientSocketFactory, IMessageListener, bool, IVpnTunnelLock?, IVpnKillSwitch?)

Initializes a new instance of the VpnServiceHost class: it makes the config folder where it is missing, starts listening to the app, and reports Initializing.

public VpnServiceHost(string configFolder, string dataFolder, IVpnServiceHandler vpnServiceHandler, IClientSocketFactory socketFactory, IMessageListener messageListener, bool withLogger = true, IVpnTunnelLock? tunnelLock = null, IVpnKillSwitch? killSwitch = null)

Parameters

configFolder string

The VPN service's config folder (IDevice.VpnServiceConfigFolder).

dataFolder string

The VPN service's data folder, with the person's proxies (IDevice.VpnServiceDataFolder).

vpnServiceHandler IVpnServiceHandler

The platform's part: the adapter, the client factory, and the notification.

socketFactory IClientSocketFactory

The factory of the client's sockets.

messageListener IMessageListener

The channel the app's requests come over, which the host disposes.

withLogger bool

true to keep a log file of its own, for a VPN service in a process of its own; in the app's process, its lines go to the app's log. The default is true.

tunnelLock IVpnTunnelLock

The machine's one tunnel, where the platform has one (the desktops), or null.

killSwitch IVpnKillSwitch

The device's kill switch, where it has one (IDevice.KillSwitch), or null.

Properties

DefaultConnectionInfo

Gets the placeholder info before the service has made a real one (Default).

public static ConnectionInfo DefaultConnectionInfo { get; }

Property Value

ConnectionInfo

IsTcpForwarding

Gets a value indicating whether the client forwards IPv4 TCP now: the live session's choice, which follows the server's support and a domain filter's needs; the client's setting before the session is up; and false with no client.

public bool IsTcpForwarding { get; }

Property Value

bool

Methods

Dispose()

Ends the connection at once, without reporting it, and stops listening to the app.

public void Dispose()

TryConnect(bool, bool)

Connects with the options the app saved, unless a connection is under way.

public Task<bool> TryConnect(bool forceReconnect = false, bool isAlwaysOn = false)

Parameters

forceReconnect bool

true to end a connection under way and connect anew; false to leave it.

isAlwaysOn bool

true if the system starts the VPN with no one asking, as Android's always-on; refused without AllowAlwaysOn.

Returns

Task<bool>

A task whose result is true once a connect was made and ran its course, its outcome in the state the app reads; false where none was made, as the host is disposed or a connection is under way.

Remarks

It never throws: a failure is reported to the app as the state's error, or, where it is not, logged.

TryDisconnect(Exception?)

Disconnects: it ends a connect under way and the session, and reports the end to the app; the kill switch's block stays as it is, as lifting it is the app's call.

public Task TryDisconnect(Exception? exception = null)

Parameters

exception Exception

Why, reported to the app as the end's error, or null to keep the reason an earlier disconnect or a revoke gave, if any.

Returns

Task

A task that completes once the session is gone; it never throws, and logs a failure.