Serve daemon snapshots from managed records
This commit is contained in:
parent
73e8111666
commit
ee16e3a29f
4 changed files with 93 additions and 30 deletions
|
|
@ -393,12 +393,6 @@ static RudpCultNetSchemaServer StartRtsCultMeshHost(
|
|||
}
|
||||
|
||||
var health = await node.GetDaemonHealthAsync().ConfigureAwait(false);
|
||||
if (health == null &&
|
||||
AetheriaRuntimeDaemonPublicationStore.TryReadHealth(node.StatePath, out var publishedHealth))
|
||||
{
|
||||
health = publishedHealth;
|
||||
}
|
||||
|
||||
if (health != null && SnapshotWants(
|
||||
request,
|
||||
AetheriaRuntimeDaemonSchemas.Health,
|
||||
|
|
@ -467,47 +461,46 @@ static RudpCultNetSchemaServer StartRtsCultMeshHost(
|
|||
.ToArray();
|
||||
}
|
||||
|
||||
InjectEveSurfaceSnapshot(
|
||||
await InjectEveSurfaceSnapshotAsync(
|
||||
node,
|
||||
options,
|
||||
request,
|
||||
response,
|
||||
AetheriaRuntimeVerseRecordKeys.DaemonGameSurface.ToString(),
|
||||
"game");
|
||||
InjectEveSurfaceSnapshot(
|
||||
"game").ConfigureAwait(false);
|
||||
await InjectEveSurfaceSnapshotAsync(
|
||||
node,
|
||||
options,
|
||||
request,
|
||||
response,
|
||||
AetheriaRuntimeVerseRecordKeys.DaemonGameTuiSurface.ToString(),
|
||||
"game-tui");
|
||||
InjectEveSurfaceSnapshot(
|
||||
"game-tui").ConfigureAwait(false);
|
||||
await InjectEveSurfaceSnapshotAsync(
|
||||
node,
|
||||
options,
|
||||
request,
|
||||
response,
|
||||
AetheriaRuntimeVerseRecordKeys.DaemonEditorSurface.ToString(),
|
||||
"editor");
|
||||
InjectEveSurfaceSnapshot(
|
||||
"editor").ConfigureAwait(false);
|
||||
await InjectEveSurfaceSnapshotAsync(
|
||||
node,
|
||||
options,
|
||||
request,
|
||||
response,
|
||||
AetheriaRuntimeVerseRecordKeys.DaemonEditorTuiSurface.ToString(),
|
||||
"editor-tui");
|
||||
"editor-tui").ConfigureAwait(false);
|
||||
|
||||
if (AetheriaRuntimeDaemonPublicationStore.TryReadStarbridgeSessionSummary(
|
||||
node.StatePath,
|
||||
out var starbridgeSession) &&
|
||||
var starbridgeSession = await node.GetStarbridgeSessionSummaryAsync().ConfigureAwait(false);
|
||||
if (starbridgeSession != null &&
|
||||
SnapshotWants(
|
||||
request,
|
||||
AetheriaRuntimeDaemonSchemas.StarbridgeSessionSummary,
|
||||
"daemon:aetheria.starbridge.session.latest.v1"))
|
||||
AetheriaRuntimeVerseRecordKeys.StarbridgeSessionSummary.ToString()))
|
||||
{
|
||||
var starbridgePut = node.Database.Documents.CreateRawDocumentPutMessage(
|
||||
response.MessageId,
|
||||
new CultRecordHandle<AetheriaRuntimeStarbridgeSessionSummaryDocument>(
|
||||
new CultRecordKey("daemon:aetheria.starbridge.session.latest.v1")),
|
||||
AetheriaRuntimeVerseRecordKeys.StarbridgeSessionSummary),
|
||||
starbridgeSession,
|
||||
new CultNetDocumentMessageOptions
|
||||
{
|
||||
|
|
@ -599,7 +592,7 @@ static RudpCultNetSchemaServer StartRtsCultMeshHost(
|
|||
return server;
|
||||
}
|
||||
|
||||
static void InjectEveSurfaceSnapshot(
|
||||
static async Task InjectEveSurfaceSnapshotAsync(
|
||||
AetheriaStateNode node,
|
||||
AetheriaDaemonHostOptions options,
|
||||
CultNetSnapshotRequestMessage request,
|
||||
|
|
@ -611,11 +604,14 @@ static void InjectEveSurfaceSnapshot(
|
|||
if (!SnapshotWants(request, EveSurfaceSchema, recordKey))
|
||||
return;
|
||||
|
||||
var surfaceDocument = ReadEveSurfacePublication(node.StatePath, surfaceKind);
|
||||
var surfaceState = await ReadEveSurfacePublicationAsync(node, surfaceKind).ConfigureAwait(false);
|
||||
if (surfaceState == null)
|
||||
return;
|
||||
|
||||
var surfacePut = node.Database.Documents.CreateRawDocumentPutMessage(
|
||||
response.MessageId,
|
||||
new CultRecordHandle<EveSurfaceState>(new CultRecordKey(recordKey)),
|
||||
AetheriaRuntimeEveSurfaceStateProjector.ToState(surfaceDocument),
|
||||
surfaceState,
|
||||
new CultNetDocumentMessageOptions
|
||||
{
|
||||
SourceRuntimeId = options.DaemonId,
|
||||
|
|
@ -628,18 +624,16 @@ static void InjectEveSurfaceSnapshot(
|
|||
.ToArray();
|
||||
}
|
||||
|
||||
static AetheriaRuntimeSurfaceDocument ReadEveSurfacePublication(string statePath, string surfaceKind)
|
||||
static Task<EveSurfaceState?> ReadEveSurfacePublicationAsync(AetheriaStateNode node, string surfaceKind)
|
||||
{
|
||||
AetheriaRuntimeSurfaceDocument document;
|
||||
_ = surfaceKind switch
|
||||
return surfaceKind switch
|
||||
{
|
||||
"game" => AetheriaRuntimeDaemonPublicationStore.TryReadGameSurface(statePath, out document),
|
||||
"game-tui" => AetheriaRuntimeDaemonPublicationStore.TryReadGameTuiSurface(statePath, out document),
|
||||
"editor" => AetheriaRuntimeDaemonPublicationStore.TryReadEditorSurface(statePath, out document),
|
||||
"editor-tui" => AetheriaRuntimeDaemonPublicationStore.TryReadEditorTuiSurface(statePath, out document),
|
||||
"game" => node.GetDaemonGameSurfaceAsync(),
|
||||
"game-tui" => node.GetDaemonGameTuiSurfaceAsync(),
|
||||
"editor" => node.GetDaemonEditorSurfaceAsync(),
|
||||
"editor-tui" => node.GetDaemonEditorTuiSurfaceAsync(),
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(surfaceKind), surfaceKind, "Unknown Eve surface publication.")
|
||||
};
|
||||
return document;
|
||||
}
|
||||
|
||||
static async Task RunRtsCultMeshPumpAsync(
|
||||
|
|
@ -769,6 +763,8 @@ static async Task PublishDaemonApiDocumentsAsync(
|
|||
await node.PutDaemonHealthAsync(health).ConfigureAwait(false);
|
||||
if (AetheriaRuntimeDaemonPublicationStore.TryReadCommandBoundary(node.StatePath, out var commandBoundary))
|
||||
await node.PutDaemonCommandBoundaryAsync(commandBoundary).ConfigureAwait(false);
|
||||
if (AetheriaRuntimeDaemonPublicationStore.TryReadStarbridgeSessionSummary(node.StatePath, out var starbridgeSummary))
|
||||
await node.PutStarbridgeSessionSummaryAsync(starbridgeSummary).ConfigureAwait(false);
|
||||
if (AetheriaRuntimeDaemonPublicationStore.TryReadGameSurface(node.StatePath, out var gameSurface))
|
||||
await node.PutDaemonGameSurfaceAsync(AetheriaRuntimeEveSurfaceStateProjector.ToState(gameSurface)).ConfigureAwait(false);
|
||||
if (AetheriaRuntimeDaemonPublicationStore.TryReadGameTuiSurface(node.StatePath, out var gameTuiSurface))
|
||||
|
|
|
|||
|
|
@ -8759,6 +8759,8 @@ static void RequireDaemonVersePublication(string root)
|
|||
"GetDaemonFrameAsync(",
|
||||
"PutDaemonSoaViewAsync(",
|
||||
"GetDaemonSoaViewAsync(",
|
||||
"PutStarbridgeSessionSummaryAsync(",
|
||||
"GetStarbridgeSessionSummaryAsync(",
|
||||
"PutDaemonGameSurfaceAsync(",
|
||||
"GetDaemonGameSurfaceAsync(",
|
||||
"PutDaemonGameTuiSurfaceAsync(",
|
||||
|
|
@ -8913,8 +8915,16 @@ static void RequireDaemonVersePublication(string root)
|
|||
"discoveryHost.Update(",
|
||||
"PublishDaemonApiDocumentsAsync(node, result)",
|
||||
"PutDaemonFrameAsync(result.Frame)",
|
||||
"PutStarbridgeSessionSummaryAsync(starbridgeSummary)",
|
||||
"PutDaemonGameSurfaceAsync(AetheriaRuntimeEveSurfaceStateProjector.ToState(gameSurface))",
|
||||
"PutDaemonEditorTuiSurfaceAsync(AetheriaRuntimeEveSurfaceStateProjector.ToState(editorTuiSurface))",
|
||||
"GetStarbridgeSessionSummaryAsync()",
|
||||
"InjectEveSurfaceSnapshotAsync(",
|
||||
"ReadEveSurfacePublicationAsync(",
|
||||
"node.GetDaemonGameSurfaceAsync()",
|
||||
"node.GetDaemonGameTuiSurfaceAsync()",
|
||||
"node.GetDaemonEditorSurfaceAsync()",
|
||||
"node.GetDaemonEditorTuiSurfaceAsync()",
|
||||
"AetheriaEveCommandBridge.AcceptObservedAsync(",
|
||||
"ReadObservedDaemonCommands()",
|
||||
"currentFrame?.AccountedCommandIds ?? Array.Empty<string>()",
|
||||
|
|
@ -8937,6 +8947,46 @@ static void RequireDaemonVersePublication(string root)
|
|||
string.Join(", ", missingDaemonHostSymbols));
|
||||
}
|
||||
|
||||
var snapshotHandlerStart = daemonHostSource.IndexOf(
|
||||
"server.OnCultNet<CultNetSnapshotRequestMessage>",
|
||||
StringComparison.Ordinal);
|
||||
var snapshotHandlerEnd = snapshotHandlerStart >= 0
|
||||
? daemonHostSource.IndexOf("var factPuts = node.ReadCommittedCommandFacts()", snapshotHandlerStart, StringComparison.Ordinal)
|
||||
: -1;
|
||||
var snapshotHandler = snapshotHandlerStart >= 0 && snapshotHandlerEnd > snapshotHandlerStart
|
||||
? daemonHostSource.Substring(snapshotHandlerStart, snapshotHandlerEnd - snapshotHandlerStart)
|
||||
: "";
|
||||
var forbiddenSnapshotStoreReads = new[]
|
||||
{
|
||||
"AetheriaRuntimeDaemonPublicationStore.TryReadHealth",
|
||||
"AetheriaRuntimeDaemonPublicationStore.TryReadStarbridgeSessionSummary"
|
||||
};
|
||||
var snapshotStoreHits = forbiddenSnapshotStoreReads
|
||||
.Where(symbol => snapshotHandler.Contains(symbol, StringComparison.Ordinal))
|
||||
.ToArray();
|
||||
if (snapshotStoreHits.Length > 0)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"RUDP snapshot responses must inject managed daemon node documents instead of reopening publication-store files: " +
|
||||
string.Join(", ", snapshotStoreHits));
|
||||
}
|
||||
|
||||
var surfaceSnapshotStart = daemonHostSource.IndexOf(
|
||||
"static async Task InjectEveSurfaceSnapshotAsync",
|
||||
StringComparison.Ordinal);
|
||||
var surfaceSnapshotEnd = surfaceSnapshotStart >= 0
|
||||
? daemonHostSource.IndexOf("static Task<EveSurfaceState?> ReadEveSurfacePublicationAsync", surfaceSnapshotStart, StringComparison.Ordinal)
|
||||
: -1;
|
||||
var surfaceSnapshotBlock = surfaceSnapshotStart >= 0 && surfaceSnapshotEnd > surfaceSnapshotStart
|
||||
? daemonHostSource.Substring(surfaceSnapshotStart, surfaceSnapshotEnd - surfaceSnapshotStart)
|
||||
: "";
|
||||
if (surfaceSnapshotBlock.Contains("AetheriaRuntimeDaemonPublicationStore.TryRead", StringComparison.Ordinal) ||
|
||||
surfaceSnapshotBlock.Contains("AetheriaRuntimeEveSurfaceStateProjector.ToState(surfaceDocument)", StringComparison.Ordinal))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"RUDP Eve surface snapshots still reopen publication-store files instead of using managed Eve surface records.");
|
||||
}
|
||||
|
||||
var forbiddenDaemonHostSymbols = new[]
|
||||
{
|
||||
"AetheriaRuntimeDaemonFrameStore.TryReadFrame(node.StatePath",
|
||||
|
|
@ -9389,6 +9439,8 @@ static void RequireAetheriaRuntimeVerseClientContract(string root)
|
|||
"CultMesh.CreateCultNetDocumentRegistry(RuntimeDocumentTypes, registry)",
|
||||
"typeof(AetheriaRuntimeVerseAuthorityPolicyDocument)",
|
||||
"AetheriaRuntimeVerseRecordKeys.VerseAuthorityPolicy",
|
||||
"public static CultRecordKey StarbridgeSessionSummary",
|
||||
"new CultRecordKey(\"daemon:aetheria.starbridge.session.latest.v1\")",
|
||||
"Document<AetheriaRuntimeVerseAuthorityPolicyDocument>(",
|
||||
"typeof(EveSurfaceState)",
|
||||
"WatchDaemonGameTuiSurfaces()",
|
||||
|
|
|
|||
|
|
@ -441,6 +441,18 @@ public sealed class AetheriaStateNode : IAsyncDisposable, IDisposable
|
|||
AetheriaRuntimeVerseRecordKeys.StarbridgeSessionLatest);
|
||||
}
|
||||
|
||||
public Task<CultRecordHandle<AetheriaRuntimeStarbridgeSessionSummaryDocument>> PutStarbridgeSessionSummaryAsync(
|
||||
AetheriaRuntimeStarbridgeSessionSummaryDocument summary)
|
||||
{
|
||||
return Database.PutAsync(AetheriaRuntimeVerseRecordKeys.StarbridgeSessionSummary, summary);
|
||||
}
|
||||
|
||||
public Task<AetheriaRuntimeStarbridgeSessionSummaryDocument?> GetStarbridgeSessionSummaryAsync()
|
||||
{
|
||||
return Database.GetAsync<AetheriaRuntimeStarbridgeSessionSummaryDocument>(
|
||||
AetheriaRuntimeVerseRecordKeys.StarbridgeSessionSummary);
|
||||
}
|
||||
|
||||
public Task<CultRecordHandle<EveSurfaceState>> PutDaemonGameSurfaceAsync(EveSurfaceState surface)
|
||||
{
|
||||
return Database.PutAsync(new CultRecordKey(AetheriaProviderAdvertisementProjector.DaemonGameSurfaceKey), surface);
|
||||
|
|
|
|||
|
|
@ -42,6 +42,9 @@ namespace GameCult.Aetheria.State.Verse
|
|||
public static CultRecordKey StarbridgeSessionLatest { get; } =
|
||||
new CultRecordKey("starbridge:aetheria.session.latest.v1");
|
||||
|
||||
public static CultRecordKey StarbridgeSessionSummary { get; } =
|
||||
new CultRecordKey("daemon:aetheria.starbridge.session.latest.v1");
|
||||
|
||||
public static CultRecordKey StarbridgePlayerSeat(string seatId)
|
||||
{
|
||||
return new CultRecordKey(AetheriaRuntimeStarbridgePlayerSeatDocument.RecordKey(seatId));
|
||||
|
|
|
|||
Loading…
Reference in a new issue