Stream exact hot state over negotiated body planes
This commit is contained in:
parent
242c8aaddd
commit
743fa3889e
22 changed files with 320 additions and 14 deletions
|
|
@ -2852,6 +2852,40 @@ namespace GameCult.Mesh
|
|||
return new CultMeshRudpEndpoint(host, uri.Port, $"rudp://{uriHost}:{uri.Port}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens one exact hot-body subscription and advertises every body plane this runtime can
|
||||
/// actually open. The provider derives locality and publishes only the selected plane.
|
||||
/// </summary>
|
||||
public static Task<IReadOnlyList<object>> SubscribeHotBodyAsync(
|
||||
CultNetDatabaseSubscriptionClient subscriptions,
|
||||
IEnumerable<CultMeshBodyTransportKind> supportedBodyTransports,
|
||||
CultMeshHotBodySubscription subscription)
|
||||
{
|
||||
if (subscriptions == null) throw new ArgumentNullException(nameof(subscriptions));
|
||||
if (supportedBodyTransports == null) throw new ArgumentNullException(nameof(supportedBodyTransports));
|
||||
if (subscription == null) throw new ArgumentNullException(nameof(subscription));
|
||||
var transports = supportedBodyTransports.Distinct().ToArray();
|
||||
if (transports.Length == 0)
|
||||
throw new ArgumentException("At least one readable body transport is required.", nameof(supportedBodyTransports));
|
||||
return subscriptions.SubscribeAsync(
|
||||
subscription.SubscriptionId,
|
||||
recordKeys: subscription.RecordKeys,
|
||||
schemaIds: subscription.SchemaIds,
|
||||
consumerRuntimeId: subscription.ConsumerRuntimeId,
|
||||
bodyIds: new[] { subscription.BodyId },
|
||||
supportedBodyTransports: transports.Select(value => value.ToString()));
|
||||
}
|
||||
|
||||
/// <summary>Opens an exact hot-body subscription using a resolver's readable planes.</summary>
|
||||
public static Task<IReadOnlyList<object>> SubscribeHotBodyAsync(
|
||||
CultNetDatabaseSubscriptionClient subscriptions,
|
||||
CultMeshBodyPublicationResolver bodyResolver,
|
||||
CultMeshHotBodySubscription subscription)
|
||||
{
|
||||
if (bodyResolver == null) throw new ArgumentNullException(nameof(bodyResolver));
|
||||
return SubscribeHotBodyAsync(subscriptions, bodyResolver.SupportedTransports, subscription);
|
||||
}
|
||||
|
||||
/// <summary>Resolves a CultMesh URI or RUDP endpoint into a concrete RUDP endpoint.</summary>
|
||||
public static CultMeshRudpEndpoint ResolveRudpEndpoint(string endpointOrUri)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -150,6 +150,11 @@ namespace GameCult.Mesh
|
|||
private readonly Func<CultMeshBodyDescriptor, bool> _authorizeProducer;
|
||||
private readonly Func<string, CultMeshBodyDescriptor, bool>? _authorizeNamedProducer;
|
||||
|
||||
/// <summary>Gets locally available body planes in fastest-local-first order.</summary>
|
||||
public IReadOnlyList<CultMeshBodyTransportKind> SupportedTransports => _adapters.Keys
|
||||
.OrderByDescending(TransportPreference)
|
||||
.ToArray();
|
||||
|
||||
public CultMeshBodyTransportService(
|
||||
IEnumerable<ICultMeshBodyTransportAdapter> adapters,
|
||||
Func<CultMeshBodyDescriptor, bool> authorizeProducer)
|
||||
|
|
@ -264,6 +269,13 @@ namespace GameCult.Mesh
|
|||
left.AccessMode == right.AccessMode &&
|
||||
left.Synchronization == right.Synchronization &&
|
||||
string.Equals(left.SemanticHash, right.SemanticHash, StringComparison.Ordinal);
|
||||
|
||||
private static int TransportPreference(CultMeshBodyTransportKind transport) => transport switch
|
||||
{
|
||||
CultMeshBodyTransportKind.SharedMemory => 3,
|
||||
CultMeshBodyTransportKind.SharedFileMapping => 2,
|
||||
_ => 1
|
||||
};
|
||||
}
|
||||
|
||||
public sealed class CultMeshMappedBodyPublisher
|
||||
|
|
|
|||
|
|
@ -7,6 +7,57 @@ using GameCult.Networking;
|
|||
|
||||
namespace GameCult.Mesh
|
||||
{
|
||||
/// <summary>
|
||||
/// One exact hot-body subscription. The view record, latest-publication record, consumer body
|
||||
/// demand, and locally supported planes are one contract so callers cannot accidentally stream
|
||||
/// body bytes through retained document snapshots.
|
||||
/// </summary>
|
||||
public sealed class CultMeshHotBodySubscription
|
||||
{
|
||||
public CultMeshHotBodySubscription(
|
||||
string subscriptionId,
|
||||
string consumerRuntimeId,
|
||||
string viewRecordKey,
|
||||
string viewSchemaId,
|
||||
string bodyId,
|
||||
IEnumerable<string>? additionalRecordKeys = null,
|
||||
IEnumerable<string>? additionalSchemaIds = null)
|
||||
{
|
||||
SubscriptionId = Require(subscriptionId, nameof(subscriptionId));
|
||||
ConsumerRuntimeId = Require(consumerRuntimeId, nameof(consumerRuntimeId));
|
||||
BodyId = Require(bodyId, nameof(bodyId));
|
||||
RecordKeys = new[]
|
||||
{
|
||||
Require(viewRecordKey, nameof(viewRecordKey)),
|
||||
CultMeshBodyPublicationDocument.CreateLatestRecordKey(bodyId).Value
|
||||
}
|
||||
.Concat(additionalRecordKeys ?? Array.Empty<string>())
|
||||
.Where(value => !string.IsNullOrWhiteSpace(value))
|
||||
.Distinct(StringComparer.Ordinal)
|
||||
.ToArray();
|
||||
SchemaIds = new[]
|
||||
{
|
||||
Require(viewSchemaId, nameof(viewSchemaId)),
|
||||
CultMeshBodyPublicationSchemaVersions.Publication
|
||||
}
|
||||
.Concat(additionalSchemaIds ?? Array.Empty<string>())
|
||||
.Where(value => !string.IsNullOrWhiteSpace(value))
|
||||
.Distinct(StringComparer.Ordinal)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
public string SubscriptionId { get; }
|
||||
public string ConsumerRuntimeId { get; }
|
||||
public string BodyId { get; }
|
||||
public IReadOnlyList<string> RecordKeys { get; }
|
||||
public IReadOnlyList<string> SchemaIds { get; }
|
||||
|
||||
private static string Require(string value, string parameterName) =>
|
||||
string.IsNullOrWhiteSpace(value)
|
||||
? throw new ArgumentException("Value is required.", parameterName)
|
||||
: value;
|
||||
}
|
||||
|
||||
/// <summary>Derived transport work for one logical hot body.</summary>
|
||||
public sealed class CultMeshBodyDemandPlan
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Globalization;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
|
|
@ -361,6 +362,9 @@ namespace GameCult.Mesh
|
|||
public CultMeshBodyPublicationResolver(CultMeshBodyTransportService transport) =>
|
||||
_transport = transport ?? throw new ArgumentNullException(nameof(transport));
|
||||
|
||||
/// <summary>Gets the body planes this resolver can actually open.</summary>
|
||||
public IReadOnlyList<CultMeshBodyTransportKind> SupportedTransports => _transport.SupportedTransports;
|
||||
|
||||
public ICultMeshBodyReadLease ResolveReadOnly(
|
||||
CultMeshBodyPublicationDocument publication,
|
||||
CultMeshBodyValidationRequest request) =>
|
||||
|
|
|
|||
|
|
@ -918,6 +918,14 @@ stream demand merely by existing.
|
|||
and server disposal all update the same typed demand projection. Stable peer
|
||||
identity, not per-message wrapper identity, keys subscription lifetime.
|
||||
|
||||
`CultMesh.SubscribeHotBodyAsync(...)` is the public construction path. Its
|
||||
`CultMeshHotBodySubscription` keeps the exact view record, the body's stable
|
||||
latest-publication record, consumer identity, and logical body demand in one
|
||||
contract. The local `CultMeshBodyTransportService` contributes only adapters it
|
||||
can actually open, ordered shared-memory first; the server combines those
|
||||
capabilities with observed peer locality. Applications do not hand-assemble
|
||||
transport-name arrays or request one snapshot per frame.
|
||||
|
||||
**Cut line:** local frame publication writes directly into a mapped write lease
|
||||
and commits its descriptor. The compatibility byte-array publisher is copy-in
|
||||
only. The current remote frame representation may still use the verified CDN
|
||||
|
|
@ -925,6 +933,12 @@ body path when remote demand exists; Phase 6 must replace that expiry-sensitive
|
|||
traffic with a stream/datagram body plane rather than enlarging snapshot or CDN
|
||||
timeouts.
|
||||
|
||||
Reliable control messages larger than the RUDP receive mask explicitly
|
||||
acknowledge the packet just received. A retransmit older than the rolling
|
||||
32-packet summary can therefore always leave the sender queue; the rolling mask
|
||||
remains useful for piggyback acknowledgements but is not allowed to strand a
|
||||
fragment indefinitely.
|
||||
|
||||
### Gate
|
||||
|
||||
- Two local consumers map one verified CDN artifact without duplicate process
|
||||
|
|
|
|||
Loading…
Reference in a new issue