From 83e394ac6a9ec484985591471dff75b2c5ca04c4 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 28 Jun 2026 06:28:17 +0100 Subject: [PATCH] Read daemon Verse records through managed pointers --- Aetheria.State.Daemon/Program.cs | 81 +++++++------------------------- Aetheria.State.Verify/Program.cs | 21 ++++++--- 2 files changed, 30 insertions(+), 72 deletions(-) diff --git a/Aetheria.State.Daemon/Program.cs b/Aetheria.State.Daemon/Program.cs index 28f237312..24fa5df81 100644 --- a/Aetheria.State.Daemon/Program.cs +++ b/Aetheria.State.Daemon/Program.cs @@ -31,10 +31,7 @@ await EnsureVerseAuthorityPolicyAsync(node, options).ConfigureAwait(false); discoveryHost.Update(verseHost); await PublishRuntimeSessionAsync(node, options, startedAtUtc, "starting").ConfigureAwait(false); await PublishStateSurfacesAsync(node, options, startedAtUtc).ConfigureAwait(false); -var latestFrame = await node - .Document(AetheriaRuntimeVerseRecordKeys.DaemonFrameLatest) - .LatestAsync() - .ConfigureAwait(false); +var latestFrame = await node.LatestFrame().ReadAsync().ConfigureAwait(false); using var cultMeshRudpHost = StartRtsCultMeshHost(node, options, () => latestFrame); using var rtsPumpCancellation = new CancellationTokenSource(); var rtsPump = RunRtsCultMeshPumpAsync(cultMeshRudpHost, rtsPumpCancellation.Token); @@ -141,18 +138,9 @@ static async Task TickAsync( .Where(command => command != null && !accountedCommandIds.Contains(command.CommandId ?? "")) .ToArray(); var policyRejectedCommandIds = new List(); - var authorityPolicy = await LatestOrDefaultAsync( - node.Document( - AetheriaRuntimeVerseRecordKeys.VerseAuthorityPolicy)) - .ConfigureAwait(false); - var starbridgeScenario = await LatestOrDefaultAsync( - node.Document( - AetheriaRuntimeVerseRecordKeys.StarbridgeScenarioLatest)) - .ConfigureAwait(false); - var starbridgeSession = await LatestOrDefaultAsync( - node.Document( - AetheriaRuntimeVerseRecordKeys.StarbridgeSessionLatest)) - .ConfigureAwait(false); + var authorityPolicy = await node.VerseAuthorityPolicy().ReadAsync().ConfigureAwait(false); + var starbridgeScenario = await node.StarbridgeScenario().ReadAsync().ConfigureAwait(false); + var starbridgeSession = await node.StarbridgeSession().ReadAsync().ConfigureAwait(false); var authorityLeases = node.ReadAuthorityLeases(); var authorizedCommands = AetheriaRuntimeAuthorityRouter.AuthorizedCommands( pendingObservedCommands, @@ -402,10 +390,7 @@ static RudpCultNetSchemaServer StartRtsCultMeshHost( .ToArray(); } - var health = await LatestOrDefaultAsync( - node.Document( - AetheriaRuntimeVerseRecordKeys.DaemonHealth)) - .ConfigureAwait(false); + var health = await node.Health().ReadAsync().ConfigureAwait(false); if (health != null && SnapshotWants( request, AetheriaRuntimeDaemonSchemas.Health, @@ -428,10 +413,7 @@ static RudpCultNetSchemaServer StartRtsCultMeshHost( .ToArray(); } - var authorityPolicy = await LatestOrDefaultAsync( - node.Document( - AetheriaRuntimeVerseRecordKeys.VerseAuthorityPolicy)) - .ConfigureAwait(false); + var authorityPolicy = await node.VerseAuthorityPolicy().ReadAsync().ConfigureAwait(false); if (authorityPolicy != null && SnapshotWants( request, AetheriaRuntimeDaemonSchemas.VerseAuthorityPolicy, @@ -454,10 +436,7 @@ static RudpCultNetSchemaServer StartRtsCultMeshHost( .ToArray(); } - var starbridgeScenario = await LatestOrDefaultAsync( - node.Document( - AetheriaRuntimeVerseRecordKeys.StarbridgeScenarioLatest)) - .ConfigureAwait(false); + var starbridgeScenario = await node.StarbridgeScenario().ReadAsync().ConfigureAwait(false); if (starbridgeScenario != null && SnapshotWants( request, AetheriaRuntimeDaemonSchemas.StarbridgeScenario, @@ -509,10 +488,7 @@ static RudpCultNetSchemaServer StartRtsCultMeshHost( AetheriaRuntimeVerseRecordKeys.DaemonEditorTuiSurface.ToString(), "editor-tui").ConfigureAwait(false); - var starbridgeSession = await LatestOrDefaultAsync( - node.Document( - AetheriaRuntimeVerseRecordKeys.StarbridgeSessionSummary)) - .ConfigureAwait(false); + var starbridgeSession = await node.StarbridgeSessionSummary().ReadAsync().ConfigureAwait(false); if (starbridgeSession != null && SnapshotWants( request, @@ -648,16 +624,14 @@ static async Task InjectEveSurfaceSnapshotAsync( static Task ReadEveSurfacePublicationAsync(AetheriaStateNode node, string surfaceKind) { - var key = surfaceKind switch + return surfaceKind switch { - "game" => AetheriaRuntimeVerseRecordKeys.DaemonGameSurface, - "game-tui" => AetheriaRuntimeVerseRecordKeys.DaemonGameTuiSurface, - "editor" => AetheriaRuntimeVerseRecordKeys.DaemonEditorSurface, - "editor-tui" => AetheriaRuntimeVerseRecordKeys.DaemonEditorTuiSurface, + "game" => node.DaemonGameSurface().ReadAsync(), + "game-tui" => node.DaemonGameTuiSurface().ReadAsync(), + "editor" => node.DaemonEditorSurface().ReadAsync(), + "editor-tui" => node.DaemonEditorTuiSurface().ReadAsync(), _ => throw new ArgumentOutOfRangeException(nameof(surfaceKind), surfaceKind, "Unknown Eve surface publication.") }; - - return LatestOrDefaultAsync(node.Document(key)); } static async Task RunRtsCultMeshPumpAsync( @@ -770,20 +744,6 @@ static bool TryGetDouble( double.TryParse(text, NumberStyles.Float, CultureInfo.InvariantCulture, out value); } -static async Task LatestOrDefaultAsync( - CultMeshDocumentHandle document) - where TDocument : class -{ - try - { - return await document.LatestAsync().ConfigureAwait(false); - } - catch (KeyNotFoundException) - { - return null; - } -} - static async Task PublishDaemonApiDocumentsAsync( AetheriaStateNode node, AetheriaRuntimeDaemonTickResult result) @@ -1220,14 +1180,8 @@ static async Task EnsureStarbridgeSessionDocumentsAsync( AetheriaStateNode node, AetheriaDaemonHostOptions options) { - var existingScenario = await LatestOrDefaultAsync( - node.Document( - AetheriaRuntimeVerseRecordKeys.StarbridgeScenarioLatest)) - .ConfigureAwait(false); - var existingSession = await LatestOrDefaultAsync( - node.Document( - AetheriaRuntimeVerseRecordKeys.StarbridgeSessionLatest)) - .ConfigureAwait(false); + var existingScenario = await node.StarbridgeScenario().ReadAsync().ConfigureAwait(false); + var existingSession = await node.StarbridgeSession().ReadAsync().ConfigureAwait(false); if (existingScenario != null && string.Equals(existingScenario.Schema, AetheriaRuntimeDaemonSchemas.StarbridgeScenario, StringComparison.Ordinal) && existingSession != null && @@ -1357,10 +1311,7 @@ static async Task EnsureVerseAuthorityPolicyAsync( AetheriaStateNode node, AetheriaDaemonHostOptions options) { - var existing = await LatestOrDefaultAsync( - node.Document( - AetheriaRuntimeVerseRecordKeys.VerseAuthorityPolicy)) - .ConfigureAwait(false); + var existing = await node.VerseAuthorityPolicy().ReadAsync().ConfigureAwait(false); if (existing != null && string.Equals(existing.Schema, AetheriaRuntimeVerseAuthoritySchemas.Policy, StringComparison.Ordinal)) { AetheriaRuntimeDaemonPublicationStore.PublishVerseAuthorityPolicy(node.StatePath, existing); diff --git a/Aetheria.State.Verify/Program.cs b/Aetheria.State.Verify/Program.cs index 8d8e56887..80dc9eeae 100644 --- a/Aetheria.State.Verify/Program.cs +++ b/Aetheria.State.Verify/Program.cs @@ -8972,12 +8972,11 @@ static void RequireDaemonVersePublication(string root) "ProjectReference Include=\"..\\Aetheria.State\\Aetheria.State.csproj\"", "AetheriaStateNode.OpenAsync(", "startServer: true", - ".Document(AetheriaRuntimeVerseRecordKeys.DaemonFrameLatest)", - ".LatestAsync()", + "node.LatestFrame().ReadAsync()", "Catalog = node.RuntimeCatalog().Latest()", - "node.Document(", - "node.Document(", - "node.Document(", + "node.VerseAuthorityPolicy().ReadAsync()", + "node.StarbridgeScenario().ReadAsync()", + "node.StarbridgeSession().ReadAsync()", "StarbridgeScenario = starbridgeScenario", "StarbridgeSession = starbridgeSession", "new AetheriaVerseDiscoveryHost(node)", @@ -8988,6 +8987,10 @@ static void RequireDaemonVersePublication(string root) "node.ProviderAdvertisement()", "node.Health()", "node.CommandBoundary()", + "node.DaemonGameSurface().ReadAsync()", + "node.DaemonGameTuiSurface().ReadAsync()", + "node.DaemonEditorSurface().ReadAsync()", + "node.DaemonEditorTuiSurface().ReadAsync()", "node.StarbridgeSessionSummary()", "node.DaemonGameSurface()", "node.DaemonEditorTuiSurface()", @@ -8995,14 +8998,12 @@ static void RequireDaemonVersePublication(string root) ".ReplaceAsync(result.SoaView)", ".ReplaceAsync(result.Health)", ".ReplaceAsync(result.StarbridgeSessionSummary)", - "LatestOrDefaultAsync(", "InjectEveSurfaceSnapshotAsync(", "ReadEveSurfacePublicationAsync(", "AetheriaRuntimeVerseRecordKeys.DaemonGameSurface", "AetheriaRuntimeVerseRecordKeys.DaemonGameTuiSurface", "AetheriaRuntimeVerseRecordKeys.DaemonEditorSurface", "AetheriaRuntimeVerseRecordKeys.DaemonEditorTuiSurface", - "LatestOrDefaultAsync(node.Document(key))", "AetheriaEveCommandBridge.AcceptObservedAsync(", "ReadObservedDaemonCommands()", "currentFrame?.AccountedCommandIds ?? Array.Empty()", @@ -9096,6 +9097,12 @@ static void RequireDaemonVersePublication(string root) var forbiddenDaemonHostSymbols = new[] { + ".Document(", + "node.Document(", + "node.Document(", + "node.Document(", + "node.Document(", + "LatestOrDefaultAsync(", "AetheriaRuntimeDaemonFrameStore.TryReadFrame(node.StatePath", "Catalog = node.OpenRuntimeCatalog()", "AetheriaRuntimeDaemonCommandLog.",