Class VpnHoodServer
- Namespace
- VpnHood.Core.Server
- Assembly
- VpnHood.Core.Server.dll
Represents a VPN server: it takes its configuration from its access manager, listens for clients, and carries their sessions, until it is disposed.
public class VpnHoodServer : IAsyncDisposable, IDisposable
- Inheritance
-
VpnHoodServer
- Implements
- Inherited Members
Remarks
Once started, it asks the access manager for its configuration until it has one, pausing after failures, then sends it its status at the configuration's interval, by default every 2 minutes, which may ask for a new configuration. A configuration of its own (Config) overrides the settings it sets.
Constructors
VpnHoodServer(IAccessManager, ServerOptions)
Initializes a new instance of the VpnHoodServer class.
public VpnHoodServer(IAccessManager accessManager, ServerOptions options)
Parameters
accessManagerIAccessManagerThe access manager, which the server disposes with itself.
optionsServerOptionsThe options.
Exceptions
- ArgumentNullException
accessManageris null.- InvalidProgramException
The options' VPN adapter has no NAT for IPv4.
Properties
ServerVersion
Gets the server's version: this assembly's.
public static Version ServerVersion { get; }
Property Value
SessionManager
Gets the server's sessions.
public SessionManager SessionManager { get; }
Property Value
Methods
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
Remarks
The quick close: it waits for no peer, so the sessions' usage since their last sync is lost, and the host's close goes on alone. It tries at once to take off the addresses the server added to the machine, logging a failure, and one being added meanwhile is taken off once added; the access manager is disposed too.
DisposeAsync()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.
public ValueTask DisposeAsync()
Returns
- ValueTask
A task that represents the asynchronous dispose operation.
Remarks
The graceful close: it starts the host's close, gives a status upload under way up to 7 seconds, waits for the configuration and the upload under way to end, and for the host's close, whose own limit lets it go on alone, tries a last sync of the sessions' usage, logging a failure and going on, then releases the rest as Dispose() does. A second call waits for the first one's end.
Start(CancellationToken)
Starts the server: it recovers the sessions it had before a restart, then configures itself and sends its status to the access manager, and keeps doing so.
public Task Start(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task
A task that completes once the first attempt at the configuration has run; a failure of the recovery or of the configuration is logged, not thrown.
Exceptions
- ObjectDisposedException
The server is disposed.
- Exception
The server has started already.
- OperationCanceledException
cancellationTokenwas canceled.