Add C# CultMesh connected RUDP clients
This commit is contained in:
parent
d131d0f42a
commit
5af8ed57f7
7 changed files with 150 additions and 21 deletions
|
|
@ -224,6 +224,21 @@ namespace GameCult.Mesh
|
|||
public CultNetReconnectPolicy? ReconnectPolicy { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Options for CultMesh-branded connected RUDP client helpers.
|
||||
/// </summary>
|
||||
public sealed class CultMeshRudpClientOptions
|
||||
{
|
||||
/// <summary>Gets or sets the socket construction and transport profile options.</summary>
|
||||
public CultMeshRudpSocketOptions SocketOptions { get; set; } = new();
|
||||
/// <summary>Gets or sets the handshake payload.</summary>
|
||||
public byte[] ConnectPayload { get; set; } = Array.Empty<byte>();
|
||||
/// <summary>Gets or sets the handshake timeout.</summary>
|
||||
public TimeSpan ConnectTimeout { get; set; } = TimeSpan.FromSeconds(1);
|
||||
/// <summary>Gets or sets the handshake polling interval.</summary>
|
||||
public TimeSpan PollInterval { get; set; } = TimeSpan.FromMilliseconds(5);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Public CultMesh entrypoints.
|
||||
/// </summary>
|
||||
|
|
@ -415,6 +430,82 @@ namespace GameCult.Mesh
|
|||
return CreateRudpClientForPeer(runtimeId, connectionId, peer, options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates and handshakes a CultNet RUDP client transport for a parsed endpoint.
|
||||
/// </summary>
|
||||
public static CultNetRudpSocketTransportConnection ConnectRudpClient(
|
||||
string runtimeId,
|
||||
uint connectionId,
|
||||
CultMeshRudpEndpoint endpoint,
|
||||
CultMeshRudpClientOptions? options = null)
|
||||
{
|
||||
options ??= new CultMeshRudpClientOptions();
|
||||
var client = CreateRudpClient(runtimeId, connectionId, endpoint, options.SocketOptions);
|
||||
if (!client.ConnectAndWait(options.ConnectPayload, options.ConnectTimeout, options.PollInterval))
|
||||
{
|
||||
client.Dispose();
|
||||
throw new TimeoutException($"Timed out waiting for RUDP client {runtimeId} to connect.");
|
||||
}
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates and handshakes a CultNet RUDP client transport for a rudp://host:port endpoint.
|
||||
/// </summary>
|
||||
public static CultNetRudpSocketTransportConnection ConnectRudpClient(
|
||||
string runtimeId,
|
||||
uint connectionId,
|
||||
string endpoint,
|
||||
CultMeshRudpClientOptions? options = null)
|
||||
{
|
||||
return ConnectRudpClient(runtimeId, connectionId, ParseRudpEndpoint(endpoint), options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates and handshakes a CultNet RUDP client transport from a peer-card contact hint.
|
||||
/// </summary>
|
||||
public static CultNetRudpSocketTransportConnection ConnectRudpClientForPeer(
|
||||
string runtimeId,
|
||||
uint connectionId,
|
||||
CultMeshPeerCard peer,
|
||||
CultMeshRudpClientOptions? options = null)
|
||||
{
|
||||
if (peer == null) throw new ArgumentNullException(nameof(peer));
|
||||
var endpoint = peer.Endpoints.FirstOrDefault(value => value.StartsWith("rudp://", StringComparison.OrdinalIgnoreCase));
|
||||
if (endpoint == null)
|
||||
{
|
||||
throw new InvalidOperationException($"Peer {peer.PeerId} does not advertise a RUDP endpoint.");
|
||||
}
|
||||
|
||||
return ConnectRudpClient(runtimeId, connectionId, endpoint, options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates and handshakes a CultNet RUDP client transport from the first peer authorized for a Verse role.
|
||||
/// </summary>
|
||||
public static CultNetRudpSocketTransportConnection ConnectRudpClientForAuthorizedPeer(
|
||||
string runtimeId,
|
||||
uint connectionId,
|
||||
CultMeshPeerCatalog peers,
|
||||
CultMeshAuthorityLeaseCatalog leases,
|
||||
string verseId,
|
||||
string role,
|
||||
string? shardId = null,
|
||||
DateTimeOffset? at = null,
|
||||
CultMeshRudpClientOptions? options = null)
|
||||
{
|
||||
if (peers == null) throw new ArgumentNullException(nameof(peers));
|
||||
if (leases == null) throw new ArgumentNullException(nameof(leases));
|
||||
var peer = peers.FirstAuthorized(verseId, role, leases, shardId, at);
|
||||
if (peer == null)
|
||||
{
|
||||
throw new InvalidOperationException($"No authorized RUDP peer for role {role} in Verse {verseId}.");
|
||||
}
|
||||
|
||||
return ConnectRudpClientForPeer(runtimeId, connectionId, peer, options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a committer for writing quorum simulation facts to a mesh database.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ peer lookup with the lease catalog, so contact gossip stays separate from
|
|||
trust. The branded RUDP helpers use the same boundary:
|
||||
|
||||
```csharp
|
||||
using var rudpClient = CultMesh.CreateRudpClientForAuthorizedPeer(
|
||||
using var rudpClient = CultMesh.ConnectRudpClientForAuthorizedPeer(
|
||||
"aetheria-client",
|
||||
connectionId: 0x10203040,
|
||||
peers,
|
||||
|
|
@ -128,9 +128,12 @@ using var rudpClient = CultMesh.CreateRudpClientForAuthorizedPeer(
|
|||
```
|
||||
|
||||
`CreateRudpServer(...)`, `ParseRudpEndpoint(...)`,
|
||||
`CreateRudpClient(...)`, and `CreateRudpClientForPeer(...)` delegate to the
|
||||
CultNet RUDP socket transport. CultMesh owns peer/authority ergonomics; CultNet
|
||||
owns packet reliability, resend pressure, and channel semantics.
|
||||
`ConnectRudpClient(...)`, and `ConnectRudpClientForPeer(...)` delegate to the
|
||||
CultNet RUDP socket transport and return the same schema-message-capable
|
||||
transport after handshake. `CreateRudpClient(...)` and
|
||||
`CreateRudpClientForPeer(...)` remain available when a caller intentionally owns
|
||||
the handshake and polling loop. CultMesh owns peer/authority ergonomics;
|
||||
CultNet owns packet reliability, resend pressure, and channel semantics.
|
||||
|
||||
Clients can fetch more peers from known peers:
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,9 @@ Namespace: `GameCult.Mesh`
|
|||
- `CultMesh.CreateRudpClient(...)`
|
||||
- `CultMesh.CreateRudpClientForPeer(...)`
|
||||
- `CultMesh.CreateRudpClientForAuthorizedPeer(...)`
|
||||
- `CultMesh.ConnectRudpClient(...)`
|
||||
- `CultMesh.ConnectRudpClientForPeer(...)`
|
||||
- `CultMesh.ConnectRudpClientForAuthorizedPeer(...)`
|
||||
- `CultMesh.CreateSimulationFactCommitter(...)`
|
||||
- `CultMesh.CreateGameSession(...)`
|
||||
- `CultMesh.CreateClient(...)`
|
||||
|
|
@ -89,9 +92,12 @@ the world.
|
|||
`CultMesh.ParseRudpEndpoint(...)`, `CreateRudpServer(...)`,
|
||||
`CreateRudpClient(...)`, `CreateRudpClientForPeer(...)`, and
|
||||
`CreateRudpClientForAuthorizedPeer(...)` provide the branded CultMesh path to
|
||||
the native CultNet RUDP socket transport. These helpers parse endpoint contact
|
||||
hints and choose authorized peers; `GameCult.Networking` still owns the RUDP
|
||||
packet codec, session state, resend, fragmentation, and channel semantics.
|
||||
the native CultNet RUDP socket transport. `ConnectRudpClient(...)`,
|
||||
`ConnectRudpClientForPeer(...)`, and `ConnectRudpClientForAuthorizedPeer(...)`
|
||||
also perform the client handshake before returning the same transport. These
|
||||
helpers parse endpoint contact hints and choose authorized peers;
|
||||
`GameCult.Networking` still owns the RUDP packet codec, session state, resend,
|
||||
fragmentation, and channel semantics.
|
||||
|
||||
### Shard Authority
|
||||
|
||||
|
|
|
|||
|
|
@ -379,6 +379,11 @@ The native RUDP socket path also exposes `CultNetRudpReconnectLoop` for
|
|||
caller-owned game or service loops. The caller reports closure, calls
|
||||
`ReconnectIfDue(nowMs)` from its own scheduler, and the shared
|
||||
`CultNetReconnectController` owns retry attempts, delay, and exhaustion state.
|
||||
`GameCult.Mesh` adds discovery-shaped helpers such as
|
||||
`CultMesh.ConnectRudpClientForAuthorizedPeer(...)`, which perform authorized
|
||||
peer lookup and handshake before returning the same RUDP transport. Packet
|
||||
semantics, schema-channel send/receive helpers, and reconnect state still live
|
||||
in `GameCult.Networking`.
|
||||
|
||||
## Important Constraints
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue