Serve Verse discovery from daemon host settings
This commit is contained in:
parent
87a8ac5eea
commit
c1267795bf
6 changed files with 188 additions and 4 deletions
|
|
@ -21,6 +21,8 @@ public sealed class AetheriaStateNode : IAsyncDisposable, IDisposable
|
|||
|
||||
public string StatePath { get; }
|
||||
|
||||
public CultMeshNode MeshNode => _node;
|
||||
|
||||
public CultCache Cache => _node.Cache;
|
||||
|
||||
public CultNetDatabase Database => _node.Database;
|
||||
|
|
|
|||
54
Aetheria.State/AetheriaVerseCatalogProjector.cs
Normal file
54
Aetheria.State/AetheriaVerseCatalogProjector.cs
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
using Aetheria.State.Documents;
|
||||
using GameCult.Mesh;
|
||||
|
||||
namespace Aetheria.State;
|
||||
|
||||
public static class AetheriaVerseCatalogProjector
|
||||
{
|
||||
private const string TransportVersion = "cultmesh.v0";
|
||||
private const string RulesEpoch = "aetheria-runtime-state.v1";
|
||||
|
||||
public static CultMeshVerseDescriptor Build(AetheriaVerseHostSettings? settings)
|
||||
{
|
||||
var normalized = AetheriaVerseHostSettingsNormalizer.Normalize(settings);
|
||||
var discoveryEndpoint = BuildDiscoveryEndpoint(normalized);
|
||||
var rulesHash = CultMeshVerseDescriptor.ComputeRulesHash(
|
||||
"aetheria",
|
||||
RulesEpoch,
|
||||
normalized.RootVerse,
|
||||
normalized.CanonicalService);
|
||||
|
||||
return new CultMeshVerseDescriptor(
|
||||
normalized.VerseId,
|
||||
normalized.Title,
|
||||
CultMeshVerseAuthorityModel.OperatorCluster,
|
||||
new CultMeshVerseCompatibility(TransportVersion, rulesHash),
|
||||
discoveryEndpoints: new[] { discoveryEndpoint },
|
||||
authorityRuntimeIds: new[] { normalized.ServiceId },
|
||||
parentVerseId: normalized.RootVerse,
|
||||
description: BuildDescription(normalized));
|
||||
}
|
||||
|
||||
public static string BuildDiscoveryEndpoint(AetheriaVerseHostSettings? settings)
|
||||
{
|
||||
var normalized = AetheriaVerseHostSettingsNormalizer.Normalize(settings);
|
||||
var host = normalized.LocatedService;
|
||||
if (string.IsNullOrWhiteSpace(host))
|
||||
host = normalized.CanonicalService;
|
||||
if (string.IsNullOrWhiteSpace(host))
|
||||
host = "localhost";
|
||||
|
||||
host = host.Trim();
|
||||
var slashIndex = host.IndexOf('/', StringComparison.Ordinal);
|
||||
if (slashIndex >= 0)
|
||||
host = host.Substring(0, slashIndex);
|
||||
|
||||
return $"cultnet://{host}:3075";
|
||||
}
|
||||
|
||||
private static string BuildDescription(AetheriaVerseHostSettings settings)
|
||||
{
|
||||
var visibility = string.IsNullOrWhiteSpace(settings.Visibility) ? "private" : settings.Visibility;
|
||||
return $"{settings.Title} Verse host ({visibility})";
|
||||
}
|
||||
}
|
||||
67
Aetheria.State/AetheriaVerseDiscoveryHost.cs
Normal file
67
Aetheria.State/AetheriaVerseDiscoveryHost.cs
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
using Aetheria.State.Documents;
|
||||
using GameCult.Mesh;
|
||||
|
||||
namespace Aetheria.State;
|
||||
|
||||
public sealed class AetheriaVerseDiscoveryHost : IDisposable
|
||||
{
|
||||
private readonly AetheriaStateNode _node;
|
||||
private CultMeshVerseCatalog? _catalog;
|
||||
private CultMeshVerseDiscoveryServer? _server;
|
||||
private string _fingerprint = "";
|
||||
|
||||
public AetheriaVerseDiscoveryHost(AetheriaStateNode node)
|
||||
{
|
||||
_node = node ?? throw new ArgumentNullException(nameof(node));
|
||||
}
|
||||
|
||||
public void Update(AetheriaVerseHostSettings? settings)
|
||||
{
|
||||
var normalized = AetheriaVerseHostSettingsNormalizer.Normalize(settings);
|
||||
if (!string.Equals(normalized.Visibility, "public", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
DisposeServer();
|
||||
return;
|
||||
}
|
||||
|
||||
var nextFingerprint = CreateFingerprint(normalized);
|
||||
if (string.Equals(_fingerprint, nextFingerprint, StringComparison.Ordinal))
|
||||
return;
|
||||
|
||||
DisposeServer();
|
||||
|
||||
_catalog = CultMesh.CreateVerseCatalog();
|
||||
_catalog.Upsert(AetheriaVerseCatalogProjector.Build(normalized));
|
||||
_server = CultMesh.ServeVerseCatalog(_node.MeshNode, _catalog);
|
||||
_fingerprint = nextFingerprint;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
DisposeServer();
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
private void DisposeServer()
|
||||
{
|
||||
_server?.Dispose();
|
||||
_server = null;
|
||||
_catalog?.Dispose();
|
||||
_catalog = null;
|
||||
_fingerprint = "";
|
||||
}
|
||||
|
||||
private static string CreateFingerprint(AetheriaVerseHostSettings settings)
|
||||
{
|
||||
return string.Join(
|
||||
"\u001f",
|
||||
settings.ServiceId ?? "",
|
||||
settings.VerseId ?? "",
|
||||
settings.RootVerse ?? "",
|
||||
settings.CanonicalService ?? "",
|
||||
settings.LocatedService ?? "",
|
||||
settings.CultMeshAddress ?? "",
|
||||
settings.Title ?? "",
|
||||
settings.Visibility ?? "");
|
||||
}
|
||||
}
|
||||
|
|
@ -402,8 +402,11 @@ depth, accepted/applied/rejected counts, failures, timestamps, and player
|
|||
settings controls are typed state rather than console-only status. It also
|
||||
persists daemon-owned `aetheria.verse_host_settings.v1`, with boot-time
|
||||
defaults or overrides for service id, Verse id, visibility, and CultMesh
|
||||
address. The operations surface and provider advertisement project from that
|
||||
typed host document instead of hardcoded daemon identity strings. The provider
|
||||
address. When visibility is `public`, the long-running daemon also serves a
|
||||
derived CultMesh Verse catalog from that same typed host document, using the
|
||||
located service name as the discoverable `cultnet://...:3075` endpoint. The
|
||||
operations surface and provider advertisement project from that typed host
|
||||
document instead of hardcoded daemon identity strings. The provider
|
||||
advertisement still publishes `gamecult.eve.provider_advertisement.v1` for the
|
||||
`aetheria` provider, advertising the catalog, operations, and player-settings
|
||||
surfaces plus the typed schemas witnessed by the local `.cc` state file.
|
||||
|
|
|
|||
Loading…
Reference in a new issue