Class VpnServiceHost
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
configFolderstringThe VPN service's config folder (
IDevice.VpnServiceConfigFolder).dataFolderstringThe VPN service's data folder, with the person's proxies (
IDevice.VpnServiceDataFolder).vpnServiceHandlerIVpnServiceHandlerThe platform's part: the adapter, the client factory, and the notification.
socketFactoryIClientSocketFactoryThe factory of the client's sockets.
messageListenerIMessageListenerThe channel the app's requests come over, which the host disposes.
withLoggerbooltrue 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.
tunnelLockIVpnTunnelLockThe machine's one tunnel, where the platform has one (the desktops), or null.
killSwitchIVpnKillSwitchThe 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
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
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
forceReconnectbooltrue to end a connection under way and connect anew; false to leave it.
isAlwaysOnbooltrue 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
exceptionExceptionWhy, 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.