Class FileAccessManager
- Namespace
- VpnHood.Core.Server.Access.Managers.FileAccessManagers
- Assembly
- VpnHood.Core.Server.Access.Managers.FileAccessManagers.dll
Represents an access manager on the server's own file system: its access keys and sessions in files, in a storage folder, for a server that runs without a remote access manager.
public class FileAccessManager : IAccessManager, IDisposable
- Inheritance
-
FileAccessManager
- Implements
- Inherited Members
Remarks
It makes the server's certificate where the folder has none, and its secret where neither the options nor the folder have one, and the server token its access keys carry. A derived manager reads the storage with LoadStorage(string, FileAccessManagerOptions, CancellationToken) and passes it to the constructor.
Constructors
FileAccessManager(FileAccessManagerStorage)
Initializes a new instance of the FileAccessManager class over what its storage gave.
protected FileAccessManager(FileAccessManagerStorage storage)
Parameters
storageFileAccessManagerStorageWhat LoadStorage(string, FileAccessManagerOptions, CancellationToken) read, which the manager owns.
Remarks
UDP is on unless the options set its endpoints: on the TCP endpoints' addresses, on the port the server keeps.
Exceptions
- Exception
The certificate has no host name.
Properties
AccessTokenService
Gets the manager's access keys.
public AccessTokenService AccessTokenService { get; }
Property Value
Methods
Acme_GetHttp01KeyAuthorization(string, CancellationToken)
Gets the key authorization of an ACME HTTP-01 challenge's token, which the server serves on port 80.
public virtual Task<string> Acme_GetHttp01KeyAuthorization(string token, CancellationToken cancellationToken)
Parameters
tokenstringThe challenge's token.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
Remarks
It has no ACME challenges: it always throws.
Exceptions
- KeyNotFoundException
The access manager knows no such token, or serves no HTTP-01 challenge.
- KeyNotFoundException
Always: the manager has no challenges.
Create(string, FileAccessManagerOptions, CancellationToken)
Makes a manager over a storage folder, whose files it reads here, as a constructor cannot wait on them.
public static Task<FileAccessManager> Create(string storagePath, FileAccessManagerOptions options, CancellationToken cancellationToken)
Parameters
storagePathstringThe storage folder, which it makes where it is missing.
optionsFileAccessManagerOptionsThe options; where they have no server secret, the one read or made in the folder goes into them.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<FileAccessManager>
A task whose result is the manager.
Remarks
The server token carries the server's location: where the options allow and the folder keeps none, the network is asked for it, and a failure goes without it until the next creation tries again; a location kept is used either way.
Exceptions
- ArgumentNullException
storagePathis null.- Exception
The public endpoints are missing or one is an "any" address, or the certificate has no subject.
- OperationCanceledException
cancellationTokenwas canceled.
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
Dispose(bool)
Releases the manager's sessions and certificate.
protected virtual void Dispose(bool disposing)
Parameters
GetAccessTokenIdFromAccessCode(string)
Gets the ID of the access key a premium code stands for.
protected virtual string? GetAccessTokenIdFromAccessCode(string accessCode)
Parameters
accessCodestringThe premium code.
Returns
- string
The access key's ID, or null where it stands for none, which refuses the code; this manager's always gives null.
GetToken(AccessToken)
Gets an access key as a client takes it, with the server token.
public Token GetToken(AccessToken accessToken)
Parameters
accessTokenAccessTokenThe access key as the manager keeps it.
Returns
- Token
The access key.
IsValidAd(string?)
Checks a rewarded ad's data.
protected virtual bool IsValidAd(string? adData)
Parameters
adDatastringThe ad's data.
Returns
LoadStorage(string, FileAccessManagerOptions, CancellationToken)
Reads a storage folder for a manager, as a derived manager's own Create does.
protected static Task<FileAccessManagerStorage> LoadStorage(string storagePath, FileAccessManagerOptions options, CancellationToken cancellationToken)
Parameters
storagePathstringThe storage folder, which it makes where it is missing.
optionsFileAccessManagerOptionsThe options; where they have no server secret, the one read or made in the folder goes into them.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<FileAccessManagerStorage>
A task whose result is what it read.
Exceptions
- ArgumentNullException
storagePathis null.- Exception
The public endpoints are missing or one is an "any" address, or the certificate has no subject.
- OperationCanceledException
cancellationTokenwas canceled.
Server_Configure(ServerInfo, CancellationToken)
Sends what the server is and has, and gets its configuration.
public virtual Task<ServerConfig> Server_Configure(ServerInfo serverInfo, CancellationToken cancellationToken)
Parameters
serverInfoServerInfoThe server's info.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<ServerConfig>
A task whose result is the configuration.
Remarks
It gives the options as the configuration, with the UDP and QUIC endpoints of port 0 on ports the server found free, and those left without one omitted. The UDP port it keeps in the storage folder and uses again as it is, so a firewall rule made for it holds across restarts.
Exceptions
- OperationCanceledException
cancellationTokenwas canceled.
Server_UpdateStatus(ServerStatus, CancellationToken)
Sends the server's status, with its sessions' usage, and gets what the access manager wants of it.
public virtual Task<ServerCommand> Server_UpdateStatus(ServerStatus serverStatus, CancellationToken cancellationToken)
Parameters
serverStatusServerStatusThe status.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<ServerCommand>
A task whose result is the access manager's answer: the configuration's code and the sessions' states.
Remarks
It adds the sessions' usage to their access keys.
Exceptions
- OperationCanceledException
cancellationTokenwas canceled.
Session_AddUsage(ulong, Traffic, string?, CancellationToken)
Adds a session's traffic, and a rewarded ad's data, without closing it.
public Task<SessionResponse> Session_AddUsage(ulong sessionId, Traffic traffic, string? adData, CancellationToken cancellationToken)
Parameters
sessionIdulongThe session's ID.
trafficTrafficThe session's traffic since its last report.
adDatastringA rewarded ad's data, or null.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<SessionResponse>
A task whose result is the session's state.
Exceptions
- OperationCanceledException
cancellationTokenwas canceled.
Session_AddUsage(SessionUsage, CancellationToken)
Adds a session's usage to its access key, closes the session where the usage carries an error, and checks its ad's data where it has some.
protected virtual Task<SessionResponse> Session_AddUsage(SessionUsage sessionUsage, CancellationToken cancellationToken)
Parameters
sessionUsageSessionUsageThe session's usage.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<SessionResponse>
A task whose result is the session's answer.
Exceptions
- OperationCanceledException
cancellationTokenwas canceled.
Session_AddUsages(SessionUsage[], CancellationToken)
Adds the traffic of many sessions, and their closes, in one call.
public Task<Dictionary<ulong, SessionResponse>> Session_AddUsages(SessionUsage[] sessionUsages, CancellationToken cancellationToken)
Parameters
sessionUsagesSessionUsage[]The sessions' usage.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<Dictionary<ulong, SessionResponse>>
A task whose result is each session's state, by its ID; the server sends again no entry the answer leaves out or answers with an error.
Remarks
A session's failure, but a cancel, is logged and answered with an access error; the sessions suppressed meanwhile that the list leaves out are answered too.
Exceptions
- OperationCanceledException
cancellationTokenwas canceled.
Session_Close(ulong, Traffic, CancellationToken)
Closes a session with its last traffic.
public virtual Task<SessionResponse> Session_Close(ulong sessionId, Traffic traffic, CancellationToken cancellationToken)
Parameters
sessionIdulongThe session's ID.
trafficTrafficThe session's traffic since its last report.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<SessionResponse>
A task whose result is the session's last state.
Exceptions
- OperationCanceledException
cancellationTokenwas canceled.
Session_Create(SessionRequestEx, CancellationToken)
Creates a session for a client's hello.
public virtual Task<SessionResponseEx> Session_Create(SessionRequestEx sessionRequestEx, CancellationToken cancellationToken)
Parameters
sessionRequestExSessionRequestExThe client's request, with what the server knows of the client.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<SessionResponseEx>
A task whose result is the session, or its refusal in its error code.
Remarks
A premium code takes the access key GetAccessTokenIdFromAccessCode(string) gives for it, and one that gives none is refused, as this manager's own does for every code. Where the options allow, the answer carries the access key the client connected with, with the manager's current server token.
Exceptions
- OperationCanceledException
cancellationTokenwas canceled.
Session_Get(ulong, IPEndPoint, IPAddress?, CancellationToken)
Gets a session the server does not hold in memory, as after a restart, to take it up again.
public virtual Task<SessionResponseEx> Session_Get(ulong sessionId, IPEndPoint hostEndPoint, IPAddress? clientIp, CancellationToken cancellationToken)
Parameters
sessionIdulongThe session's ID.
hostEndPointIPEndPointThe server's endpoint the client came to.
clientIpIPAddressThe client's IP, or null.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<SessionResponseEx>
A task whose result is the session, or its error in its error code.
Remarks
The server's endpoint and the client's IP are not checked; the session is marked as used.
Exceptions
- OperationCanceledException
cancellationTokenwas canceled.- JsonException
The access key's file holds malformed JSON, or JSON that cannot be read as an access key.
- InvalidDataException
The access key's file holds
null.
Session_GetAll(CancellationToken)
Gets the server's sessions, to take them up again at its start.
public Task<SessionResponseEx[]> Session_GetAll(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<SessionResponseEx[]>
A task whose result is the sessions.
Remarks
A session whose access key is gone is left out, and one that fails is logged and left out.
Exceptions
- OperationCanceledException
cancellationTokenwas canceled.