Move daemon publication onto managed Verse state
This commit is contained in:
parent
666fb5619d
commit
3f1be900e7
3 changed files with 204 additions and 34 deletions
|
|
@ -2,6 +2,7 @@ using Aetheria.State;
|
|||
using Aetheria.State.Documents;
|
||||
using GameCult.Aetheria.State.Verse;
|
||||
using GameCult.Caching;
|
||||
using GameCult.Mesh;
|
||||
using GameCult.Networking;
|
||||
using MessagePack;
|
||||
using System.Globalization;
|
||||
|
|
@ -140,9 +141,18 @@ static async Task<AetheriaRuntimeDaemonTickResult> TickAsync(
|
|||
.Where(command => command != null && !accountedCommandIds.Contains(command.CommandId ?? ""))
|
||||
.ToArray();
|
||||
var policyRejectedCommandIds = new List<string>();
|
||||
var authorityPolicy = await node.GetVerseAuthorityPolicyAsync().ConfigureAwait(false);
|
||||
var starbridgeScenario = await node.GetStarbridgeScenarioAsync().ConfigureAwait(false);
|
||||
var starbridgeSession = await node.GetStarbridgeSessionAsync().ConfigureAwait(false);
|
||||
var authorityPolicy = await LatestOrDefaultAsync(
|
||||
node.Document<AetheriaRuntimeVerseAuthorityPolicyDocument>(
|
||||
AetheriaRuntimeVerseRecordKeys.VerseAuthorityPolicy))
|
||||
.ConfigureAwait(false);
|
||||
var starbridgeScenario = await LatestOrDefaultAsync(
|
||||
node.Document<AetheriaRuntimeStarbridgeScenarioDocument>(
|
||||
AetheriaRuntimeVerseRecordKeys.StarbridgeScenarioLatest))
|
||||
.ConfigureAwait(false);
|
||||
var starbridgeSession = await LatestOrDefaultAsync(
|
||||
node.Document<AetheriaRuntimeStarbridgeSessionDocument>(
|
||||
AetheriaRuntimeVerseRecordKeys.StarbridgeSessionLatest))
|
||||
.ConfigureAwait(false);
|
||||
var authorityLeases = node.ReadAuthorityLeases();
|
||||
var authorizedCommands = AetheriaRuntimeAuthorityRouter.AuthorizedCommands(
|
||||
pendingObservedCommands,
|
||||
|
|
@ -392,7 +402,10 @@ static RudpCultNetSchemaServer StartRtsCultMeshHost(
|
|||
.ToArray();
|
||||
}
|
||||
|
||||
var health = await node.GetDaemonHealthAsync().ConfigureAwait(false);
|
||||
var health = await LatestOrDefaultAsync(
|
||||
node.Document<AetheriaRuntimeDaemonHealthDocument>(
|
||||
AetheriaRuntimeVerseRecordKeys.DaemonHealth))
|
||||
.ConfigureAwait(false);
|
||||
if (health != null && SnapshotWants(
|
||||
request,
|
||||
AetheriaRuntimeDaemonSchemas.Health,
|
||||
|
|
@ -415,7 +428,10 @@ static RudpCultNetSchemaServer StartRtsCultMeshHost(
|
|||
.ToArray();
|
||||
}
|
||||
|
||||
var authorityPolicy = await node.GetVerseAuthorityPolicyAsync().ConfigureAwait(false);
|
||||
var authorityPolicy = await LatestOrDefaultAsync(
|
||||
node.Document<AetheriaRuntimeVerseAuthorityPolicyDocument>(
|
||||
AetheriaRuntimeVerseRecordKeys.VerseAuthorityPolicy))
|
||||
.ConfigureAwait(false);
|
||||
if (authorityPolicy != null && SnapshotWants(
|
||||
request,
|
||||
AetheriaRuntimeDaemonSchemas.VerseAuthorityPolicy,
|
||||
|
|
@ -438,7 +454,10 @@ static RudpCultNetSchemaServer StartRtsCultMeshHost(
|
|||
.ToArray();
|
||||
}
|
||||
|
||||
var starbridgeScenario = await node.GetStarbridgeScenarioAsync().ConfigureAwait(false);
|
||||
var starbridgeScenario = await LatestOrDefaultAsync(
|
||||
node.Document<AetheriaRuntimeStarbridgeScenarioDocument>(
|
||||
AetheriaRuntimeVerseRecordKeys.StarbridgeScenarioLatest))
|
||||
.ConfigureAwait(false);
|
||||
if (starbridgeScenario != null && SnapshotWants(
|
||||
request,
|
||||
AetheriaRuntimeDaemonSchemas.StarbridgeScenario,
|
||||
|
|
@ -490,7 +509,10 @@ static RudpCultNetSchemaServer StartRtsCultMeshHost(
|
|||
AetheriaRuntimeVerseRecordKeys.DaemonEditorTuiSurface.ToString(),
|
||||
"editor-tui").ConfigureAwait(false);
|
||||
|
||||
var starbridgeSession = await node.GetStarbridgeSessionSummaryAsync().ConfigureAwait(false);
|
||||
var starbridgeSession = await LatestOrDefaultAsync(
|
||||
node.Document<AetheriaRuntimeStarbridgeSessionSummaryDocument>(
|
||||
AetheriaRuntimeVerseRecordKeys.StarbridgeSessionSummary))
|
||||
.ConfigureAwait(false);
|
||||
if (starbridgeSession != null &&
|
||||
SnapshotWants(
|
||||
request,
|
||||
|
|
@ -746,33 +768,67 @@ static bool TryGetDouble(
|
|||
double.TryParse(text, NumberStyles.Float, CultureInfo.InvariantCulture, out value);
|
||||
}
|
||||
|
||||
static async Task<TDocument?> LatestOrDefaultAsync<TDocument>(
|
||||
CultMeshDocumentHandle<TDocument> document)
|
||||
where TDocument : class
|
||||
{
|
||||
try
|
||||
{
|
||||
return await document.LatestAsync().ConfigureAwait(false);
|
||||
}
|
||||
catch (KeyNotFoundException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static async Task PublishDaemonApiDocumentsAsync(
|
||||
AetheriaStateNode node,
|
||||
AetheriaRuntimeDaemonTickResult result)
|
||||
{
|
||||
await node.PutDaemonFrameAsync(result.Frame).ConfigureAwait(false);
|
||||
await node.LatestFrame()
|
||||
.ReplaceAsync(result.Frame)
|
||||
.ConfigureAwait(false);
|
||||
if (result.SoaView != null &&
|
||||
string.Equals(result.SoaView.Schema, AetheriaRuntimeDaemonSchemas.SoaView, StringComparison.Ordinal))
|
||||
{
|
||||
await node.PutDaemonSoaViewAsync(result.SoaView).ConfigureAwait(false);
|
||||
await node.LatestSoaView()
|
||||
.ReplaceAsync(result.SoaView)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (result.ProviderAdvertisement != null)
|
||||
await node.PutDaemonProviderAdvertisementAsync(result.ProviderAdvertisement).ConfigureAwait(false);
|
||||
await node.ProviderAdvertisement()
|
||||
.ReplaceAsync(result.ProviderAdvertisement)
|
||||
.ConfigureAwait(false);
|
||||
if (result.Health != null)
|
||||
await node.PutDaemonHealthAsync(result.Health).ConfigureAwait(false);
|
||||
await node.Health()
|
||||
.ReplaceAsync(result.Health)
|
||||
.ConfigureAwait(false);
|
||||
if (result.CommandBoundary != null)
|
||||
await node.PutDaemonCommandBoundaryAsync(result.CommandBoundary).ConfigureAwait(false);
|
||||
await node.CommandBoundary()
|
||||
.ReplaceAsync(result.CommandBoundary)
|
||||
.ConfigureAwait(false);
|
||||
if (result.StarbridgeSessionSummary != null)
|
||||
await node.PutStarbridgeSessionSummaryAsync(result.StarbridgeSessionSummary).ConfigureAwait(false);
|
||||
await node.StarbridgeSessionSummary()
|
||||
.ReplaceAsync(result.StarbridgeSessionSummary)
|
||||
.ConfigureAwait(false);
|
||||
if (result.GameSurface != null)
|
||||
await node.PutDaemonGameSurfaceAsync(AetheriaRuntimeEveSurfaceStateProjector.ToState(result.GameSurface)).ConfigureAwait(false);
|
||||
await node.DaemonGameSurface()
|
||||
.ReplaceAsync(AetheriaRuntimeEveSurfaceStateProjector.ToState(result.GameSurface))
|
||||
.ConfigureAwait(false);
|
||||
if (result.GameTuiSurface != null)
|
||||
await node.PutDaemonGameTuiSurfaceAsync(AetheriaRuntimeEveSurfaceStateProjector.ToState(result.GameTuiSurface)).ConfigureAwait(false);
|
||||
await node.DaemonGameTuiSurface()
|
||||
.ReplaceAsync(AetheriaRuntimeEveSurfaceStateProjector.ToState(result.GameTuiSurface))
|
||||
.ConfigureAwait(false);
|
||||
if (result.EditorSurface != null)
|
||||
await node.PutDaemonEditorSurfaceAsync(AetheriaRuntimeEveSurfaceStateProjector.ToState(result.EditorSurface)).ConfigureAwait(false);
|
||||
await node.DaemonEditorSurface()
|
||||
.ReplaceAsync(AetheriaRuntimeEveSurfaceStateProjector.ToState(result.EditorSurface))
|
||||
.ConfigureAwait(false);
|
||||
if (result.EditorTuiSurface != null)
|
||||
await node.PutDaemonEditorTuiSurfaceAsync(AetheriaRuntimeEveSurfaceStateProjector.ToState(result.EditorTuiSurface)).ConfigureAwait(false);
|
||||
await node.DaemonEditorTuiSurface()
|
||||
.ReplaceAsync(AetheriaRuntimeEveSurfaceStateProjector.ToState(result.EditorTuiSurface))
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
static async Task AcceptEveCommandsAsync(AetheriaStateNode node, AetheriaDaemonHostOptions options)
|
||||
|
|
@ -1149,8 +1205,14 @@ static async Task EnsureStarbridgeSessionDocumentsAsync(
|
|||
AetheriaStateNode node,
|
||||
AetheriaDaemonHostOptions options)
|
||||
{
|
||||
var existingScenario = await node.GetStarbridgeScenarioAsync().ConfigureAwait(false);
|
||||
var existingSession = await node.GetStarbridgeSessionAsync().ConfigureAwait(false);
|
||||
var existingScenario = await LatestOrDefaultAsync(
|
||||
node.Document<AetheriaRuntimeStarbridgeScenarioDocument>(
|
||||
AetheriaRuntimeVerseRecordKeys.StarbridgeScenarioLatest))
|
||||
.ConfigureAwait(false);
|
||||
var existingSession = await LatestOrDefaultAsync(
|
||||
node.Document<AetheriaRuntimeStarbridgeSessionDocument>(
|
||||
AetheriaRuntimeVerseRecordKeys.StarbridgeSessionLatest))
|
||||
.ConfigureAwait(false);
|
||||
if (existingScenario != null &&
|
||||
string.Equals(existingScenario.Schema, AetheriaRuntimeDaemonSchemas.StarbridgeScenario, StringComparison.Ordinal) &&
|
||||
existingSession != null &&
|
||||
|
|
@ -1267,8 +1329,12 @@ static async Task EnsureStarbridgeSessionDocumentsAsync(
|
|||
RuntimeRoles = scenario.RuntimeRoles
|
||||
};
|
||||
|
||||
await node.PutStarbridgeScenarioAsync(scenario).ConfigureAwait(false);
|
||||
await node.PutStarbridgeSessionAsync(session).ConfigureAwait(false);
|
||||
await node.StarbridgeScenario()
|
||||
.ReplaceAsync(scenario)
|
||||
.ConfigureAwait(false);
|
||||
await node.StarbridgeSession()
|
||||
.ReplaceAsync(session)
|
||||
.ConfigureAwait(false);
|
||||
await node.FlushAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
|
|
@ -1276,7 +1342,10 @@ static async Task EnsureVerseAuthorityPolicyAsync(
|
|||
AetheriaStateNode node,
|
||||
AetheriaDaemonHostOptions options)
|
||||
{
|
||||
var existing = await node.GetVerseAuthorityPolicyAsync().ConfigureAwait(false);
|
||||
var existing = await LatestOrDefaultAsync(
|
||||
node.Document<AetheriaRuntimeVerseAuthorityPolicyDocument>(
|
||||
AetheriaRuntimeVerseRecordKeys.VerseAuthorityPolicy))
|
||||
.ConfigureAwait(false);
|
||||
if (existing != null && string.Equals(existing.Schema, AetheriaRuntimeVerseAuthoritySchemas.Policy, StringComparison.Ordinal))
|
||||
{
|
||||
AetheriaRuntimeDaemonPublicationStore.PublishVerseAuthorityPolicy(node.StatePath, existing);
|
||||
|
|
@ -1284,7 +1353,9 @@ static async Task EnsureVerseAuthorityPolicyAsync(
|
|||
}
|
||||
|
||||
var policy = AetheriaRuntimeVerseAuthorityPolicyDocument.TrustedCoop(options.VerseId, options.DaemonId);
|
||||
await node.PutVerseAuthorityPolicyAsync(policy).ConfigureAwait(false);
|
||||
await node.VerseAuthorityPolicy()
|
||||
.ReplaceAsync(policy)
|
||||
.ConfigureAwait(false);
|
||||
AetheriaRuntimeDaemonPublicationStore.PublishVerseAuthorityPolicy(node.StatePath, policy);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8800,6 +8800,11 @@ static void RequireDaemonVersePublication(string root)
|
|||
"Database.WatchRecord<TDocument>(key)",
|
||||
"public CultMeshDocumentHandle<AetheriaRuntimeCatalogSnapshot> RuntimeCatalog()",
|
||||
"AetheriaRuntimeCatalogStore.OpenReadOnly(StatePath)",
|
||||
"public CultMeshMutableStatePointer<AetheriaRuntimeDaemonFrameDocument> LatestFrame()",
|
||||
"public CultMeshMutableStatePointer<AetheriaRuntimeDaemonSoaViewDocument> LatestSoaView()",
|
||||
"public CultMeshMutableStatePointer<AetheriaRuntimeStarbridgeSessionSummaryDocument> StarbridgeSessionSummary()",
|
||||
"private CultMeshMutableStatePointer<T> MutableDocumentPointer<T>(CultRecordKey key)",
|
||||
"CultMesh.MutableStatePointer(",
|
||||
"AetheriaRuntimeVerseRecordKeys.DaemonFrameLatest",
|
||||
"PutDaemonProviderAdvertisementAsync(",
|
||||
"GetDaemonProviderAdvertisementAsync(",
|
||||
|
|
@ -8965,22 +8970,27 @@ static void RequireDaemonVersePublication(string root)
|
|||
".Document<AetheriaRuntimeDaemonFrameDocument>(AetheriaRuntimeVerseRecordKeys.DaemonFrameLatest)",
|
||||
".LatestAsync()",
|
||||
"Catalog = node.RuntimeCatalog().Latest()",
|
||||
"GetStarbridgeScenarioAsync()",
|
||||
"GetStarbridgeSessionAsync()",
|
||||
"node.Document<AetheriaRuntimeVerseAuthorityPolicyDocument>(",
|
||||
"node.Document<AetheriaRuntimeStarbridgeScenarioDocument>(",
|
||||
"node.Document<AetheriaRuntimeStarbridgeSessionDocument>(",
|
||||
"StarbridgeScenario = starbridgeScenario",
|
||||
"StarbridgeSession = starbridgeSession",
|
||||
"new AetheriaVerseDiscoveryHost(node)",
|
||||
"discoveryHost.Update(",
|
||||
"PublishDaemonApiDocumentsAsync(node, result)",
|
||||
"PutDaemonFrameAsync(result.Frame)",
|
||||
"PutDaemonSoaViewAsync(result.SoaView)",
|
||||
"PutDaemonProviderAdvertisementAsync(result.ProviderAdvertisement)",
|
||||
"PutDaemonHealthAsync(result.Health)",
|
||||
"PutDaemonCommandBoundaryAsync(result.CommandBoundary)",
|
||||
"PutStarbridgeSessionSummaryAsync(result.StarbridgeSessionSummary)",
|
||||
"PutDaemonGameSurfaceAsync(AetheriaRuntimeEveSurfaceStateProjector.ToState(result.GameSurface))",
|
||||
"PutDaemonEditorTuiSurfaceAsync(AetheriaRuntimeEveSurfaceStateProjector.ToState(result.EditorTuiSurface))",
|
||||
"GetStarbridgeSessionSummaryAsync()",
|
||||
"node.LatestFrame()",
|
||||
"node.LatestSoaView()",
|
||||
"node.ProviderAdvertisement()",
|
||||
"node.Health()",
|
||||
"node.CommandBoundary()",
|
||||
"node.StarbridgeSessionSummary()",
|
||||
"node.DaemonGameSurface()",
|
||||
"node.DaemonEditorTuiSurface()",
|
||||
".ReplaceAsync(result.Frame)",
|
||||
".ReplaceAsync(result.SoaView)",
|
||||
".ReplaceAsync(result.Health)",
|
||||
".ReplaceAsync(result.StarbridgeSessionSummary)",
|
||||
"LatestOrDefaultAsync(",
|
||||
"InjectEveSurfaceSnapshotAsync(",
|
||||
"ReadEveSurfacePublicationAsync(",
|
||||
"node.GetDaemonGameSurfaceAsync()",
|
||||
|
|
|
|||
|
|
@ -110,6 +110,80 @@ public sealed class AetheriaStateNode : IAsyncDisposable, IDisposable
|
|||
routeHint: new CultMeshRouteHint(CultMeshLocalityKind.SharedMemory, "Aetheria typed catalog state"));
|
||||
}
|
||||
|
||||
public CultMeshMutableStatePointer<AetheriaRuntimeDaemonProviderAdvertisementDocument> ProviderAdvertisement()
|
||||
{
|
||||
return MutableDocumentPointer<AetheriaRuntimeDaemonProviderAdvertisementDocument>(
|
||||
AetheriaRuntimeVerseRecordKeys.DaemonProviderAdvertisement);
|
||||
}
|
||||
|
||||
public CultMeshMutableStatePointer<AetheriaRuntimeDaemonHealthDocument> Health()
|
||||
{
|
||||
return MutableDocumentPointer<AetheriaRuntimeDaemonHealthDocument>(
|
||||
AetheriaRuntimeVerseRecordKeys.DaemonHealth);
|
||||
}
|
||||
|
||||
public CultMeshMutableStatePointer<AetheriaRuntimeDaemonCommandBoundaryDocument> CommandBoundary()
|
||||
{
|
||||
return MutableDocumentPointer<AetheriaRuntimeDaemonCommandBoundaryDocument>(
|
||||
AetheriaRuntimeVerseRecordKeys.DaemonCommandBoundary);
|
||||
}
|
||||
|
||||
public CultMeshMutableStatePointer<AetheriaRuntimeVerseAuthorityPolicyDocument> VerseAuthorityPolicy()
|
||||
{
|
||||
return MutableDocumentPointer<AetheriaRuntimeVerseAuthorityPolicyDocument>(
|
||||
AetheriaRuntimeVerseRecordKeys.VerseAuthorityPolicy);
|
||||
}
|
||||
|
||||
public CultMeshMutableStatePointer<AetheriaRuntimeDaemonFrameDocument> LatestFrame()
|
||||
{
|
||||
return MutableDocumentPointer<AetheriaRuntimeDaemonFrameDocument>(
|
||||
AetheriaRuntimeVerseRecordKeys.DaemonFrameLatest);
|
||||
}
|
||||
|
||||
public CultMeshMutableStatePointer<AetheriaRuntimeDaemonSoaViewDocument> LatestSoaView()
|
||||
{
|
||||
return MutableDocumentPointer<AetheriaRuntimeDaemonSoaViewDocument>(
|
||||
AetheriaRuntimeVerseRecordKeys.DaemonSoaViewLatest);
|
||||
}
|
||||
|
||||
public CultMeshMutableStatePointer<AetheriaRuntimeStarbridgeScenarioDocument> StarbridgeScenario()
|
||||
{
|
||||
return MutableDocumentPointer<AetheriaRuntimeStarbridgeScenarioDocument>(
|
||||
AetheriaRuntimeVerseRecordKeys.StarbridgeScenarioLatest);
|
||||
}
|
||||
|
||||
public CultMeshMutableStatePointer<AetheriaRuntimeStarbridgeSessionDocument> StarbridgeSession()
|
||||
{
|
||||
return MutableDocumentPointer<AetheriaRuntimeStarbridgeSessionDocument>(
|
||||
AetheriaRuntimeVerseRecordKeys.StarbridgeSessionLatest);
|
||||
}
|
||||
|
||||
public CultMeshMutableStatePointer<AetheriaRuntimeStarbridgeSessionSummaryDocument> StarbridgeSessionSummary()
|
||||
{
|
||||
return MutableDocumentPointer<AetheriaRuntimeStarbridgeSessionSummaryDocument>(
|
||||
AetheriaRuntimeVerseRecordKeys.StarbridgeSessionSummary);
|
||||
}
|
||||
|
||||
public CultMeshMutableStatePointer<EveSurfaceState> DaemonGameSurface()
|
||||
{
|
||||
return MutableDocumentPointer<EveSurfaceState>(AetheriaRuntimeVerseRecordKeys.DaemonGameSurface);
|
||||
}
|
||||
|
||||
public CultMeshMutableStatePointer<EveSurfaceState> DaemonGameTuiSurface()
|
||||
{
|
||||
return MutableDocumentPointer<EveSurfaceState>(AetheriaRuntimeVerseRecordKeys.DaemonGameTuiSurface);
|
||||
}
|
||||
|
||||
public CultMeshMutableStatePointer<EveSurfaceState> DaemonEditorSurface()
|
||||
{
|
||||
return MutableDocumentPointer<EveSurfaceState>(AetheriaRuntimeVerseRecordKeys.DaemonEditorSurface);
|
||||
}
|
||||
|
||||
public CultMeshMutableStatePointer<EveSurfaceState> DaemonEditorTuiSurface()
|
||||
{
|
||||
return MutableDocumentPointer<EveSurfaceState>(AetheriaRuntimeVerseRecordKeys.DaemonEditorTuiSurface);
|
||||
}
|
||||
|
||||
public Task<CultRecordHandle<AetheriaWorldState>> PutWorldAsync(AetheriaWorldState world)
|
||||
{
|
||||
return Database.PutAsync(new CultRecordKey("global:aetheria.world_state.v1"), world);
|
||||
|
|
@ -605,6 +679,21 @@ public sealed class AetheriaStateNode : IAsyncDisposable, IDisposable
|
|||
return string.IsNullOrWhiteSpace(token) ? "empty" : token;
|
||||
}
|
||||
|
||||
private CultMeshMutableStatePointer<T> MutableDocumentPointer<T>(CultRecordKey key) where T : class
|
||||
{
|
||||
return CultMesh.MutableStatePointer(
|
||||
key.ToString(),
|
||||
_ => Database.GetAsync<T>(key),
|
||||
_ => Database.WatchRecord<T>(key)
|
||||
.Where(change => change.Document != null)
|
||||
.Select(change => change.Document!),
|
||||
async (_, value) => { await Database.PutAsync(key, value).ConfigureAwait(false); },
|
||||
sources:
|
||||
[
|
||||
CultMesh.ProjectionSource(key.ToString())
|
||||
]);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_node.Dispose();
|
||||
|
|
|
|||
Loading…
Reference in a new issue