Centralize CultMesh authority resolution

This commit is contained in:
Meta Vens 2026-07-13 14:00:26 +01:00
commit fb24e30ab6
6 changed files with 547 additions and 73 deletions

View file

@ -192,23 +192,40 @@ namespace GameCult.Mesh
}
/// <summary>Finds peers that advertise a Verse role and are authorized by the supplied lease catalog.</summary>
[Obsolete("Supply CultMeshAuthorityResolver and an explicit authority epoch. This compatibility path denies unverifiable leases.")]
public IReadOnlyList<CultMeshPeerCard> FindAuthorized(
string verseId,
string role,
CultMeshAuthorityLeaseCatalog leases,
string? shardId = null,
DateTimeOffset? at = null)
{
if (leases == null) throw new ArgumentNullException(nameof(leases));
var resolver = CultMeshAuthorityResolver.CreateDenyByDefault(leases,
at.HasValue ? new PeerCatalogFixedClock(at.Value) : null);
return FindAuthorized(verseId, role, resolver, 0, shardId);
}
/// <summary>Finds contact candidates accepted by the authority resolver.</summary>
public IReadOnlyList<CultMeshPeerCard> FindAuthorized(
string verseId,
string role,
CultMeshAuthorityResolver resolver,
long authorityEpoch,
string? shardId = null,
string? resourceScope = null)
{
ThrowIfDisposed();
if (string.IsNullOrWhiteSpace(verseId)) throw new ArgumentException("Value must be non-empty.", nameof(verseId));
if (string.IsNullOrWhiteSpace(role)) throw new ArgumentException("Value must be non-empty.", nameof(role));
if (leases == null) throw new ArgumentNullException(nameof(leases));
if (resolver == null) throw new ArgumentNullException(nameof(resolver));
return Find(verseId, role)
.Where(peer => leases.IsAuthorized(peer, role, shardId, at))
.Where(peer => resolver.Resolve(new CultMeshAuthorityRequest(peer, role, shardId, authorityEpoch, resourceScope)).IsAuthorized)
.ToArray();
}
/// <summary>Returns the first peer that advertises a Verse role and is authorized by the supplied lease catalog.</summary>
[Obsolete("Supply CultMeshAuthorityResolver and an explicit authority epoch. This compatibility path denies unverifiable leases.")]
public CultMeshPeerCard? FirstAuthorized(
string verseId,
string role,
@ -219,6 +236,18 @@ namespace GameCult.Mesh
return FindAuthorized(verseId, role, leases, shardId, at).FirstOrDefault();
}
/// <summary>Returns the first contact candidate accepted by the authority resolver.</summary>
public CultMeshPeerCard? FirstAuthorized(
string verseId,
string role,
CultMeshAuthorityResolver resolver,
long authorityEpoch,
string? shardId = null,
string? resourceScope = null)
{
return FindAuthorized(verseId, role, resolver, authorityEpoch, shardId, resourceScope).FirstOrDefault();
}
/// <inheritdoc />
public void Dispose()
{
@ -239,6 +268,13 @@ namespace GameCult.Mesh
throw new ObjectDisposedException(nameof(CultMeshPeerCatalog));
}
}
private sealed class PeerCatalogFixedClock : ICultMeshClock
{
public PeerCatalogFixedClock(DateTimeOffset utcNow) => UtcNow = utcNow;
public DateTimeOffset UtcNow { get; }
public Task DelayAsync(TimeSpan delay, CancellationToken cancellationToken = default) => Task.CompletedTask;
}
}
/// <summary>