Bind mapped CDN bodies to verified paths
This commit is contained in:
parent
15bffc6d8c
commit
682a3e9f8d
4 changed files with 57 additions and 6 deletions
|
|
@ -80,6 +80,27 @@ namespace GameCult.Mesh
|
|||
public int MaxConcurrentChunkRequests { get; set; } = DefaultMaxConcurrentChunkRequests;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Binds the transfer owner's atomically committed file to an ephemeral read-only
|
||||
/// mapped-body descriptor for the same logical generation.
|
||||
/// </summary>
|
||||
public sealed class CultMeshMappedContent
|
||||
{
|
||||
internal CultMeshMappedContent(string verifiedPath, CultMeshBodyDescriptor descriptor)
|
||||
{
|
||||
VerifiedPath = string.IsNullOrWhiteSpace(verifiedPath)
|
||||
? throw new ArgumentException("Verified content path is required.", nameof(verifiedPath))
|
||||
: Path.GetFullPath(verifiedPath);
|
||||
Descriptor = descriptor ?? throw new ArgumentNullException(nameof(descriptor));
|
||||
}
|
||||
|
||||
/// <summary>Gets the immutable file promoted by the content transfer owner.</summary>
|
||||
public string VerifiedPath { get; }
|
||||
|
||||
/// <summary>Gets the opaque mapped-body capability for the same verified file.</summary>
|
||||
public CultMeshBodyDescriptor Descriptor { get; }
|
||||
}
|
||||
|
||||
public sealed class CultMeshContentTransferService
|
||||
{
|
||||
private readonly CultCache _stateCache;
|
||||
|
|
@ -115,6 +136,26 @@ namespace GameCult.Mesh
|
|||
DateTimeOffset nowUtc,
|
||||
TimeSpan leaseDuration,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var mapped = await FetchMappedContentAsync(
|
||||
manifest,
|
||||
networkDescriptor,
|
||||
nowUtc,
|
||||
leaseDuration,
|
||||
cancellationToken).ConfigureAwait(false);
|
||||
return mapped.Descriptor;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches and atomically verifies one artifact, then grants a mapped read-only
|
||||
/// representation without making the consumer infer the transfer cache path.
|
||||
/// </summary>
|
||||
public async Task<CultMeshMappedContent> FetchMappedContentAsync(
|
||||
CultMeshCdnArtifactManifest manifest,
|
||||
CultMeshBodyDescriptor networkDescriptor,
|
||||
DateTimeOffset nowUtc,
|
||||
TimeSpan leaseDuration,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (_mappedBodies == null)
|
||||
throw new InvalidOperationException("Verified body mapping is not configured for this transfer service.");
|
||||
|
|
@ -132,7 +173,8 @@ namespace GameCult.Mesh
|
|||
var networkExpiry = DateTimeOffset.FromUnixTimeMilliseconds(networkDescriptor.LeaseExpiresAtUnixMs);
|
||||
var expiry = requestedExpiry <= networkExpiry ? requestedExpiry : networkExpiry;
|
||||
if (expiry <= nowUtc) throw new InvalidOperationException("Network body lease has expired.");
|
||||
return _mappedBodies.GrantVerified(contentHash, path, networkDescriptor, expiry);
|
||||
var descriptor = _mappedBodies.GrantVerified(contentHash, path, networkDescriptor, expiry);
|
||||
return new CultMeshMappedContent(path, descriptor);
|
||||
}
|
||||
|
||||
public async Task<string> FetchAsync(
|
||||
|
|
|
|||
|
|
@ -34,9 +34,11 @@ verifies the complete SHA-256 identity, and atomically publishes
|
|||
implement a second retry, failover, or promotion policy.
|
||||
|
||||
For local consumers, configure `CultMeshVerifiedBodyMappingBroker` and call
|
||||
`FetchMappedBodyAsync`. The resulting descriptor maps only the completed body;
|
||||
mapping failure remains observable and falls back through the equivalent
|
||||
network descriptor without changing logical identity.
|
||||
`FetchMappedContentAsync`. The result binds the transfer owner's verified path
|
||||
to the mapped descriptor, so consumers do not infer cache filenames. The older
|
||||
`FetchMappedBodyAsync` shape delegates to the same owner when only the
|
||||
descriptor is needed. Mapping failure remains observable and falls back through
|
||||
the equivalent network descriptor without changing logical identity.
|
||||
|
||||
The content protocol uses one bounded response per manifest chunk. A snapshot
|
||||
response containing `gamecult.mesh.cdn_artifact_chunk.v1` payload records is a
|
||||
|
|
|
|||
|
|
@ -682,6 +682,8 @@ the equivalent network body descriptor, and a bounded lease.
|
|||
**Outputs:** a read-only file-mapping descriptor for the same logical generation.
|
||||
Multiple consumers map the same completed cache file and therefore share the OS
|
||||
page cache; no process-sized byte array or republished body file is created.
|
||||
`CultMeshMappedContent` binds that descriptor to the exact final path returned
|
||||
by the transfer owner, so runtime lowerers never reconstruct cache layout.
|
||||
|
||||
**Derived state:** opaque capability tokens and their expiry. Tokens are neither
|
||||
content hashes nor paths and do not confer producer authority or content trust.
|
||||
|
|
@ -696,7 +698,9 @@ failure is observed by body negotiation and falls back to that network
|
|||
representation.
|
||||
|
||||
**Cut line:** there is no second CDN publication path. Mapping is granted only
|
||||
after the transfer owner returns its verified final file.
|
||||
after the transfer owner returns its verified final file. The compatibility
|
||||
descriptor-only method delegates to the path-and-descriptor result rather than
|
||||
repeating transfer or cache-path policy.
|
||||
|
||||
### Cut first
|
||||
|
||||
|
|
|
|||
|
|
@ -228,10 +228,13 @@ public sealed class CultMeshContentTransferTests
|
|||
var now = DateTimeOffset.UtcNow;
|
||||
var network = NetworkDescriptor(artifact, now);
|
||||
|
||||
var first = await service.FetchMappedBodyAsync(artifact.Manifest, network, now, TimeSpan.FromMinutes(1));
|
||||
var firstContent = await service.FetchMappedContentAsync(
|
||||
artifact.Manifest, network, now, TimeSpan.FromMinutes(1));
|
||||
var first = firstContent.Descriptor;
|
||||
var second = await service.FetchMappedBodyAsync(artifact.Manifest, network, now, TimeSpan.FromMinutes(1));
|
||||
|
||||
first.Should().BeEquivalentTo(second, options => options.Excluding(value => value.CapabilityToken));
|
||||
firstContent.VerifiedPath.Should().Be(Path.Combine(_directory, artifact.Manifest.ContentHash + ".body"));
|
||||
first.CapabilityToken.Should().NotBe(artifact.Manifest.ContentHash);
|
||||
first.CapabilityToken.Should().NotContain(Path.DirectorySeparatorChar.ToString());
|
||||
first.CapabilityToken.Should().NotContain(Path.AltDirectorySeparatorChar.ToString());
|
||||
|
|
|
|||
Loading…
Reference in a new issue