From 682a3e9f8de83263495470586d5f03cbf4051fb2 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 16 Jul 2026 14:07:50 +0100 Subject: [PATCH] Bind mapped CDN bodies to verified paths --- src/GameCult.Mesh/CultMeshContentTransfer.cs | 44 ++++++++++++++++++- src/GameCult.Mesh/docs/content-sessions.md | 8 ++-- .../docs/reliability-migration-plan.md | 6 ++- .../CultMeshContentTransferTests.cs | 5 ++- 4 files changed, 57 insertions(+), 6 deletions(-) diff --git a/src/GameCult.Mesh/CultMeshContentTransfer.cs b/src/GameCult.Mesh/CultMeshContentTransfer.cs index cbcf641d..59f89a15 100644 --- a/src/GameCult.Mesh/CultMeshContentTransfer.cs +++ b/src/GameCult.Mesh/CultMeshContentTransfer.cs @@ -80,6 +80,27 @@ namespace GameCult.Mesh public int MaxConcurrentChunkRequests { get; set; } = DefaultMaxConcurrentChunkRequests; } + /// + /// Binds the transfer owner's atomically committed file to an ephemeral read-only + /// mapped-body descriptor for the same logical generation. + /// + 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)); + } + + /// Gets the immutable file promoted by the content transfer owner. + public string VerifiedPath { get; } + + /// Gets the opaque mapped-body capability for the same verified file. + 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; + } + + /// + /// Fetches and atomically verifies one artifact, then grants a mapped read-only + /// representation without making the consumer infer the transfer cache path. + /// + public async Task 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 FetchAsync( diff --git a/src/GameCult.Mesh/docs/content-sessions.md b/src/GameCult.Mesh/docs/content-sessions.md index 8f2d074d..1eae6b6c 100644 --- a/src/GameCult.Mesh/docs/content-sessions.md +++ b/src/GameCult.Mesh/docs/content-sessions.md @@ -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 diff --git a/src/GameCult.Mesh/docs/reliability-migration-plan.md b/src/GameCult.Mesh/docs/reliability-migration-plan.md index 8c2d993d..25cd2865 100644 --- a/src/GameCult.Mesh/docs/reliability-migration-plan.md +++ b/src/GameCult.Mesh/docs/reliability-migration-plan.md @@ -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 diff --git a/tests/GameCult.Mesh.Tests/CultMeshContentTransferTests.cs b/tests/GameCult.Mesh.Tests/CultMeshContentTransferTests.cs index bad8ac74..8bbf43a9 100644 --- a/tests/GameCult.Mesh.Tests/CultMeshContentTransferTests.cs +++ b/tests/GameCult.Mesh.Tests/CultMeshContentTransferTests.cs @@ -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());