Publish reviewed history-free open-source snapshot (2026-10-12)
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
namespace UCVL.VPNPlus;
|
||||
|
||||
internal static class NetworkLearningLeaseSelfTest
|
||||
{
|
||||
internal static void AddChecks(Dictionary<string, bool> checks)
|
||||
{
|
||||
RoutingTarget Target(string name = "learn.example.com") => new() { TargetType = "domain", Target = name, MatchMode = "exact" };
|
||||
var needed = new ProxyProbe.PathComparison(false, true);
|
||||
var direct = new ProxyProbe.PathComparison(true, null);
|
||||
var unknown = new ProxyProbe.PathComparison(null, null);
|
||||
var book = new NetworkLearningLeases();
|
||||
book.Observe(Target(), needed, 0);
|
||||
checks["lease_fresh_proof_adds_rule"] = book.Count == 1 && book.Dirty;
|
||||
book.Applied();
|
||||
checks["lease_no_early_probe"] = book.Due(479_999).Length == 0;
|
||||
var due = book.Due(480_000).Single();
|
||||
checks["lease_rechecks_two_minutes_early"] = due.Expires == 600_000;
|
||||
book.Scheduled(due, 480_000);
|
||||
checks["lease_bounded_retry_no_duplicate"] = book.Due(509_999).Length == 0 && book.Due(510_000).Length == 1;
|
||||
book.Observe(Target(), needed, 481_000, due);
|
||||
checks["lease_renewal_does_not_replace_routes"] = !book.Dirty && book.Count == 1;
|
||||
book.Expire(601_000);
|
||||
checks["lease_survives_original_deadline"] = book.Count == 1 && !book.Dirty;
|
||||
book.Observe(Target(), direct, 602_000, due);
|
||||
checks["lease_stale_success_cannot_remove_new_proof"] = book.Count == 1;
|
||||
var next = book.Due(961_000).Single();
|
||||
book.Observe(Target(), unknown, 961_001, next);
|
||||
checks["lease_unknown_preserves_only_existing_deadline"] = book.Due(961_002).Single().Expires == 1_081_000;
|
||||
book.Observe(Target(), new(false, false), 961_003, next);
|
||||
checks["lease_proxy_failure_does_not_renew"] = book.Due(961_004).Single().Expires == 1_081_000;
|
||||
book.Expire(1_081_000);
|
||||
checks["lease_unverified_hard_expiry_enforced"] = book.Count == 0 && book.Dirty;
|
||||
book.Observe(Target(), needed, 1_081_001, next);
|
||||
checks["lease_late_proof_after_expiry_ignored"] = book.Count == 0;
|
||||
book.Observe(Target(), needed, 1_081_002);
|
||||
book.Applied();
|
||||
book.Observe(Target(), direct, 1_081_003);
|
||||
checks["lease_direct_recovery_removes_rule"] = book.Count == 0 && book.Dirty;
|
||||
book.Clear();
|
||||
for (var i = 0; i < 128; i++) book.Observe(Target($"t{i}.example.com"), needed, 0);
|
||||
book.Observe(Target("overflow.example.com"), needed, 0);
|
||||
checks["lease_capacity_bounded"] = book.Count == 128;
|
||||
var fullDue = book.Due(480_000)[0];
|
||||
book.Observe(fullDue.Target, needed, 480_001, fullDue);
|
||||
checks["lease_capacity_does_not_block_existing_renewal"] = !book.Current(fullDue) && book.Count == 128;
|
||||
book.Clear();
|
||||
book.Observe(Target(), needed, 0);
|
||||
var oldEpoch = book.Due(480_000).Single();
|
||||
book.Clear();
|
||||
book.Observe(Target(), needed, 480_001);
|
||||
book.Observe(Target(), direct, 480_002, oldEpoch);
|
||||
checks["lease_old_network_result_cannot_apply"] = book.Count == 1;
|
||||
book.Clear();
|
||||
book.Observe(Target(), needed, 0);
|
||||
book.Applied();
|
||||
var uninterrupted = true;
|
||||
// Virtual monotonic time: more than three real TTLs, not wall-clock acceptance.
|
||||
for (long time = 5_000; time <= 35 * 60_000; time += 5_000) {
|
||||
book.Expire(time);
|
||||
foreach (var entry in book.Due(time)) book.Observe(entry.Target, needed, time, entry);
|
||||
uninterrupted &= book.Count == 1 && !book.Dirty;
|
||||
}
|
||||
checks["lease_35_virtual_minutes_no_gap_or_replacement"] = uninterrupted;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user