diff --git a/Aetheria.State.Daemon/Program.cs b/Aetheria.State.Daemon/Program.cs index c434aded6..a04151501 100644 --- a/Aetheria.State.Daemon/Program.cs +++ b/Aetheria.State.Daemon/Program.cs @@ -900,7 +900,7 @@ static RudpCultNetSchemaServer StartClientCultMeshHost( } } - await InjectCultMeshCdnAssetSnapshotsAsync(options, bundleCdnDocuments, request, response).ConfigureAwait(false); + InjectCultMeshCdnManifestSnapshots(bundleCdnDocuments, request, response); peer.SendCultNet(response); } catch (Exception ex) @@ -926,14 +926,11 @@ static RudpCultNetSchemaServer StartClientCultMeshHost( return server; } -static async Task InjectCultMeshCdnAssetSnapshotsAsync( - AetheriaDaemonHostOptions options, +static void InjectCultMeshCdnManifestSnapshots( IReadOnlyDictionary bundleCdnDocuments, CultNetSnapshotRequestMessage request, CultNetSnapshotResponseRawMessage response) { - var schemaIds = request.SchemaIds ?? Array.Empty(); - var recordKeys = request.RecordKeys ?? Array.Empty(); if (recordKeys.Length == 0) return; @@ -946,33 +943,7 @@ static async Task InjectCultMeshCdnAssetSnapshotsAsync( if (string.Equals(Environment.GetEnvironmentVariable("AETHERIA_TRACE_EVE_SNAPSHOTS"), "1", StringComparison.Ordinal)) Console.WriteLine($"Eve CDN snapshot schema={bundleDocument.SchemaId} record={recordKey}"); documents.Add(bundleDocument); - continue; } - if (schemaIds.Length > 0 && - !schemaIds.Contains(AetheriaRuntimeDaemonSchemas.CultMeshCdnAssetBlob, StringComparer.Ordinal)) - continue; - if (!TryResolveCultMeshCdnAssetPath(options, recordKey, out var filePath, out var mimeType, out var canonicalUri)) - continue; - - var bytes = await File.ReadAllBytesAsync(filePath).ConfigureAwait(false); - documents.Add(new CultNetRawDocumentRecord - { - SchemaId = AetheriaRuntimeDaemonSchemas.CultMeshCdnAssetBlob, - RecordKey = recordKey, - StoredAt = DateTimeOffset.UtcNow.ToString("O"), - PayloadEncoding = "messagepack", - Payload = MessagePackSerializer.Serialize(bytes), - SourceRuntimeId = options.DaemonId, - SourceRole = "aetheria-cultmesh-cdn", - Tags = - [ - "aetheria", - "cultmesh-cdn", - "asset", - $"mime:{mimeType}", - $"canonical:{canonicalUri}" - ] - }); } if (documents.Count == 0) @@ -1014,122 +985,6 @@ static IReadOnlyDictionary BuildBundleCdnDocum } } -static bool TryResolveCultMeshCdnAssetPath( - AetheriaDaemonHostOptions options, - string recordKey, - out string filePath, - out string mimeType, - out string canonicalUri) -{ - filePath = ""; - mimeType = "application/octet-stream"; - canonicalUri = ""; - - var assetPath = ParseCultMeshAssetPath(recordKey); - if (string.IsNullOrWhiteSpace(assetPath)) - return false; - - var relative = ResolveCultMeshAssetResourcePath(assetPath); - if (string.IsNullOrWhiteSpace(relative)) - return false; - - var candidates = new[] - { - Path.Combine(options.AetheriaResourcesRoot, relative), - Path.Combine(options.AetheriaResourcesRoot, relative + ".png"), - Path.Combine(options.AetheriaResourcesRoot, relative + ".PNG"), - Path.Combine(options.AetheriaResourcesRoot, relative + ".jpg"), - Path.Combine(options.AetheriaResourcesRoot, relative + ".jpeg"), - Path.Combine(options.AetheriaResourcesRoot, relative + ".psd") - }; - filePath = candidates.FirstOrDefault(path => - File.Exists(path) && - Path.GetFullPath(path).StartsWith(Path.GetFullPath(options.AetheriaResourcesRoot), StringComparison.OrdinalIgnoreCase)) ?? ""; - if (string.IsNullOrWhiteSpace(filePath)) - return false; - - mimeType = ContentTypeForPath(filePath); - canonicalUri = recordKey.StartsWith("cultmesh://", StringComparison.OrdinalIgnoreCase) - ? recordKey - : $"cultmesh://aetheria/assets/{assetPath.Trim('/')}"; - return true; -} - -static string ParseCultMeshAssetPath(string recordKey) -{ - var text = (recordKey ?? "").Trim(); - if (text.Length == 0) - return ""; - - if (!text.StartsWith("cultmesh://", StringComparison.OrdinalIgnoreCase)) - return text.Trim('/'); - - if (!Uri.TryCreate(text, UriKind.Absolute, out var uri)) - return ""; - - var parts = uri.AbsolutePath.Trim('/').Split('/', StringSplitOptions.RemoveEmptyEntries); - var assetIndex = Array.FindIndex(parts, part => string.Equals(part, "assets", StringComparison.OrdinalIgnoreCase)); - return string.Join("/", assetIndex >= 0 ? parts.Skip(assetIndex + 1) : parts); -} - -static string ResolveCultMeshAssetResourcePath(string assetPath) -{ - var path = (assetPath ?? "").Trim('/').Replace('\\', '/'); - var aliases = new Dictionary(StringComparer.OrdinalIgnoreCase) - { - ["icons/ui/sun"] = "Sprites/Icons/Stroked/Sun", - ["icons/ui/star"] = "Sprites/Icons/Stroked/Sun", - ["icons/ui/planet"] = "Sprites/Icons/Stroked/Planet", - ["icons/ui/gasgiant"] = "Sprites/Icons/Stroked/gasgiant", - ["icons/ui/asteroid"] = "Sprites/Icons/Stroked/Planet", - ["icons/ui/ship"] = "Sprites/Icons/Stroked/Ship", - ["icons/ui/player"] = "Sprites/Icons/Stroked/Ship", - ["icons/ui/station"] = "Sprites/Icons/station1", - ["icons/ui/orbital"] = "Sprites/Icons/Stroked/orbital", - ["map/entity/player"] = "Sprites/Icons/Stroked/Ship", - ["map/entity/ship"] = "Sprites/Icons/Stroked/Ship", - ["map/entity/orbital"] = "Sprites/Icons/Stroked/orbital", - ["map/entity/station"] = "Sprites/Icons/station1", - ["map/entity/projectile"] = "Sprites/Icons/Lightning Bolt", - ["map/body/planet"] = "Sprites/Icons/Stroked/Planet", - ["map/body/sun"] = "Sprites/Icons/Stroked/Sun", - ["map/body/asteroid"] = "Sprites/Icons/Stroked/Planet", - ["textures/tint_splat"] = "Sprites/Flat UI/areaFade2", - ["textures/perlines-nebula"] = "Sprites/Icons/Tech/Cloud", - ["inventory/cell/background_atlas"] = "Sprites/Flat UI/Nodes/Nodes8BG", - ["inventory/cell/foreground_atlas"] = "Sprites/Flat UI/Nodes/Nodes8", - ["inventory/cell/thermal_layer_atlas"] = "Sprites/Flat UI/pipes" - }; - if (aliases.TryGetValue(path, out var relative)) - return relative; - - if (path.StartsWith("icons/star.", StringComparison.OrdinalIgnoreCase)) - return "Sprites/Icons/Stroked/Sun"; - if (path.StartsWith("icons/body.", StringComparison.OrdinalIgnoreCase)) - return path.Contains("vesper", StringComparison.OrdinalIgnoreCase) - ? "Sprites/Icons/Stroked/gasgiant" - : "Sprites/Icons/Stroked/Planet"; - if (path.StartsWith("icons/ship.", StringComparison.OrdinalIgnoreCase)) - return "Sprites/Icons/Stroked/Ship"; - if (path.StartsWith("icons/station.", StringComparison.OrdinalIgnoreCase)) - return "Sprites/Icons/station1"; - - return path; -} - -static string ContentTypeForPath(string filePath) -{ - return Path.GetExtension(filePath).ToLowerInvariant() switch - { - ".png" => "image/png", - ".jpg" => "image/jpeg", - ".jpeg" => "image/jpeg", - ".svg" => "image/svg+xml", - ".psd" => "image/vnd.adobe.photoshop", - _ => "application/octet-stream" - }; -} - static async Task InjectEveSurfaceSnapshotAsync( AetheriaStateNode node, AetheriaDaemonHostOptions options, diff --git a/Aetheria.State.Verify/Program.cs b/Aetheria.State.Verify/Program.cs index e8815d915..e36062d2e 100644 --- a/Aetheria.State.Verify/Program.cs +++ b/Aetheria.State.Verify/Program.cs @@ -10,6 +10,7 @@ var statePath = args.Length > 1 : AetheriaStatePaths.ResolveDefaultStatePath(root); RequireGameplaySourcePurity(root); +RequireManagedContentOnlyAssetDelivery(root); RequirePackageSerializerBoundary(root); RequireSharedEvePackagesImportedFromEveRepo(root); RequireSharedRuntimeSurfaceCommandsUseCultMeshTransport(root); @@ -20810,3 +20811,39 @@ static async Task RequireLegacyLookupAsync( throw new InvalidOperationException($"Typed legacy-id lookup failed for {label} {legacyId}."); } } + +static void RequireManagedContentOnlyAssetDelivery(string root) +{ + var daemonPath = Path.Combine(root, "Aetheria.State.Daemon", "Program.cs"); + var documentsPath = Path.Combine( + root, + "Packages", + "org.gamecult.aetheria.state", + "Runtime", + "AetheriaRuntimeDaemonDocuments.cs"); + var daemon = File.ReadAllText(daemonPath); + var documents = File.ReadAllText(documentsPath); + var forbidden = new[] + { + "CultMeshCdnAssetBlob", + "gamecult.cultmesh.cdn.asset_blob.v1", + "TryResolveCultMeshCdnAssetPath" + }; + var surviving = forbidden + .Where(symbol => daemon.Contains(symbol, StringComparison.Ordinal) || + documents.Contains(symbol, StringComparison.Ordinal)) + .ToArray(); + if (surviving.Length > 0) + { + throw new InvalidOperationException( + "Snapshot delivery regained a byte-body authority; managed content sessions must be the sole asset-body transport: " + + string.Join(", ", surviving)); + } + + if (!daemon.Contains("InjectCultMeshCdnManifestSnapshots", StringComparison.Ordinal) || + !daemon.Contains("CultMeshContentServer", StringComparison.Ordinal)) + { + throw new InvalidOperationException( + "Daemon asset delivery must publish snapshot manifests and host managed CultMesh content sessions."); + } +} diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonDocuments.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonDocuments.cs index 9ae75cf09..00c742566 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonDocuments.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonDocuments.cs @@ -67,7 +67,6 @@ namespace GameCult.Aetheria.State.Verse public const string GravityViewport = "gamecult.fields.gravity.v1"; public const string RenderSplatsViewport = "gamecult.fields.splats.v1"; public const string AssetManifest = "gamecult.aetheria.asset_manifest.v1"; - public const string CultMeshCdnAssetBlob = "gamecult.cultmesh.cdn.asset_blob.v1"; public const string CurrentZone = "gamecult.aetheria.current_zone.v1"; public const string CurrentEntity = "gamecult.aetheria.current_entity.v1"; public const string CurrentDocking = "gamecult.aetheria.current_docking.v1"; diff --git a/docs/aetheria-perfect-machine-map.md b/docs/aetheria-perfect-machine-map.md index 9a58b88ae..5d5967c52 100644 --- a/docs/aetheria-perfect-machine-map.md +++ b/docs/aetheria-perfect-machine-map.md @@ -865,6 +865,26 @@ legacy catalog cache, and legacy UI paths should be migration-only or deleted. height, and negative body splats. Released cold/warm witnesses exercise the persisted daemon path. +### Daemon Asset Content Delivery + +- Owner: the Aetheria daemon owns bundle content and serves bytes only through + the managed `cultmesh.content.v1` session hosted by CultMesh. +- Inputs: provider bundle path, packed artifact manifest, content hash, byte + length, negotiated chunk requests, and resumable client checkpoint. +- Outputs: snapshot delivery publishes the typed artifact manifest only; + content-session requests return bounded byte ranges which the generic runtime + verifies and atomically promotes to a hash-named `.body`. +- Derived state: Unity `AssetBundle` instances, native prefab lookup, cache + files, progress UI, and screenshots cannot publish or mutate provider bytes. +- Forbidden writers: batched snapshot chunks and the former + `gamecult.cultmesh.cdn.asset_blob.v1` fallback are deleted. Eve surfaces and + renderer code cannot smuggle bundle bytes through state records. +- Shared paths: cold transfer, resume, and warm cache reuse all resolve the same + advertised manifest and content hash through the generic runtime transport. +- Cut line: CultMesh snapshots index manifests; managed content sessions are the + sole bundle-body transport until a negotiated mapped/network body transport + replaces their byte-copy implementation. + - Owner: `Aetheria.State` owns the new typed state spine for durable state. The embedded `GameCult.Aetheria.State.Unity` package owns Unity's runtime typed state file path plus the boot-time state-file probe, and is the landing