Apply Verse discovery responses to catalogs
This commit is contained in:
parent
b831a8f3bf
commit
dfa7db607a
3 changed files with 52 additions and 0 deletions
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using GameCult.Networking;
|
||||
using R3;
|
||||
|
||||
namespace GameCult.Mesh
|
||||
|
|
@ -225,6 +226,19 @@ namespace GameCult.Mesh
|
|||
_updates.OnNext(verse);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds or replaces Verses from a wire catalog response.
|
||||
/// </summary>
|
||||
public void Upsert(CultMeshVerseCatalogResponseMessage response)
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
if (response == null) throw new ArgumentNullException(nameof(response));
|
||||
foreach (var verse in response.Verses)
|
||||
{
|
||||
Upsert(verse.ToVerseDescriptor());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a Verse by id, if known.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -45,6 +45,8 @@ It can publish discovery updates and find compatible transfer targets.
|
|||
`CultMesh.ServeVerseCatalog(node, catalog)` attaches schema-v0 Verse discovery
|
||||
responses to a node. The wire contracts are
|
||||
`cultmesh.verse_catalog_request.v0` and `cultmesh.verse_catalog_response.v0`.
|
||||
Consumers can apply a response directly with
|
||||
`CultMeshVerseCatalog.Upsert(CultMeshVerseCatalogResponseMessage)`.
|
||||
|
||||
### Shard Authority
|
||||
|
||||
|
|
|
|||
|
|
@ -861,6 +861,42 @@ namespace GameCult.Networking.Tests
|
|||
Assert.That(response.Verses[0].DiscoveryEndpoints, Is.EqualTo(["cultmesh://aetheria.example.test:3075"]));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CultMeshVerseCatalog_Upserts_WireDiscoveryResponse()
|
||||
{
|
||||
using var catalog = CultMesh.CreateVerseCatalog();
|
||||
var updates = new List<CultMeshVerseDescriptor>();
|
||||
using var subscription = catalog.Watch().Subscribe(updates.Add);
|
||||
|
||||
catalog.Upsert(new CultMeshVerseCatalogResponseMessage
|
||||
{
|
||||
MessageId = "verses-apply",
|
||||
Verses =
|
||||
[
|
||||
new CultMeshVerseDescriptorMessage
|
||||
{
|
||||
VerseId = "aetheria-branch",
|
||||
DisplayName = "Aetheria Branch",
|
||||
AuthorityModel = nameof(CultMeshVerseAuthorityModel.SubscribedOverlay),
|
||||
Compatibility = new CultMeshVerseCompatibilityMessage
|
||||
{
|
||||
TransportVersion = "cultmesh.v0",
|
||||
RulesHash = "branch-rules",
|
||||
CompatibleVerseIds = ["aetheria-main"]
|
||||
},
|
||||
ParentVerseId = "aetheria-main"
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
var verse = catalog.Get("aetheria-branch");
|
||||
|
||||
Assert.That(verse, Is.Not.Null);
|
||||
Assert.That(verse!.AuthorityModel, Is.EqualTo(CultMeshVerseAuthorityModel.SubscribedOverlay));
|
||||
Assert.That(verse.ParentVerseId, Is.EqualTo("aetheria-main"));
|
||||
Assert.That(updates, Has.Count.EqualTo(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task CultMeshNode_CanEnable_DurableShardLogs_WithDefaultPath()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue