Windows 0.3.4 connection resilience and fixed-grid source delta; no private history or other platform changes
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
namespace UCVL.VPNPlus;
|
||||
|
||||
// Memory-only bounds from authenticated responses. This permits retention of
|
||||
// an already-running core; it never grants offline login or a new connection.
|
||||
internal sealed class ConnectionAuthorizationLease
|
||||
{
|
||||
private bool _known, _active;
|
||||
private DateTimeOffset? _sessionExpiry, _profileExpiry;
|
||||
private long? _sessionDeadline, _profileDeadline;
|
||||
|
||||
internal void Reset(DateTimeOffset? sessionExpiry, DateTimeOffset now, long ticks)
|
||||
{
|
||||
_known = _active = false;
|
||||
_sessionExpiry = sessionExpiry;
|
||||
_sessionDeadline = Deadline(sessionExpiry, now, ticks);
|
||||
_profileExpiry = null; _profileDeadline = null;
|
||||
}
|
||||
|
||||
internal void AcceptProfile(string status, DateTimeOffset? expiry, DateTimeOffset now, long ticks)
|
||||
{
|
||||
_known = !string.IsNullOrWhiteSpace(status); _active = status == "active";
|
||||
var deadline = Deadline(expiry, now, ticks);
|
||||
if (_profileExpiry == expiry && _profileDeadline.HasValue && deadline.HasValue)
|
||||
deadline = Math.Min(_profileDeadline.Value, deadline.Value);
|
||||
_profileExpiry = expiry;
|
||||
_profileDeadline = deadline;
|
||||
}
|
||||
|
||||
internal bool AccountIsValid(DateTimeOffset now, long ticks) => (!_known || _active)
|
||||
&& (_sessionExpiry is null || now < _sessionExpiry) && (_profileExpiry is null || now < _profileExpiry)
|
||||
&& (_sessionDeadline is null || ticks < _sessionDeadline) && (_profileDeadline is null || ticks < _profileDeadline);
|
||||
|
||||
internal bool CanRetain(DateTimeOffset now, long ticks, bool privateAuxiliary, long privateDeadline)
|
||||
=> AccountIsValid(now, ticks) && (!privateAuxiliary || privateDeadline > ticks);
|
||||
|
||||
private static long? Deadline(DateTimeOffset? expiry, DateTimeOffset now, long ticks)
|
||||
{
|
||||
if (expiry is null) return null;
|
||||
var remaining = Math.Max(0, (expiry.Value - now).TotalMilliseconds);
|
||||
return ticks + (long)Math.Min(remaining, long.MaxValue - Math.Max(0, ticks));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user