24 lines
1.1 KiB
C#
24 lines
1.1 KiB
C#
namespace UCVL.VPNPlus;
|
|
|
|
internal static class ConnectionRecoveryPolicy
|
|
{
|
|
// A control-plane timeout is not evidence that the existing data-plane
|
|
// process needs to be destroyed. Revoked authorization still stops service.
|
|
internal static bool KeepExisting(bool reconnect, bool replacementStarted, bool coreRunning, Exception failure,
|
|
bool authorizationValid = true)
|
|
=> reconnect && !replacementStarted && coreRunning && authorizationValid
|
|
&& failure is not ApiException { StatusCode: 401 or 403 };
|
|
|
|
internal static bool SelfTest()
|
|
{
|
|
var timeout = new TimeoutException();
|
|
return KeepExisting(true, false, true, timeout)
|
|
&& KeepExisting(true, false, true, new TaskCanceledException())
|
|
&& !KeepExisting(false, false, true, timeout)
|
|
&& !KeepExisting(true, true, true, timeout)
|
|
&& !KeepExisting(true, false, false, timeout)
|
|
&& !KeepExisting(true, false, true, new ApiException(401, "test revoked"))
|
|
&& !KeepExisting(true, false, true, new ApiException(403, "test forbidden"));
|
|
}
|
|
}
|