Advertise C# LiteNetLib transport profile

This commit is contained in:
Meta Vens 2026-06-16 07:30:56 +01:00
commit 7e10238c2e
7 changed files with 168 additions and 2 deletions

View file

@ -27,7 +27,7 @@ CultNet owns cross-runtime transport semantics:
| Runtime | Current data transport | Discovery | Transport authority today |
| --- | --- | --- | --- |
| C# `GameCult.Networking` | LiteNetLib UDP `NetManager` / `NetPeer`; sends legacy union messages and schema-v0 messages with `DeliveryMethod.ReliableOrdered`; single-peer RUDP socket transport exists in the library | LiteNetLib connection requests and app-level peer/catalog surfaces | Production LiteNetLib path plus UDP socket binding for the shared RUDP reliability owner |
| C# `GameCult.Networking` | LiteNetLib UDP `NetManager` / `NetPeer`; sends legacy union messages and schema-v0 messages with `DeliveryMethod.ReliableOrdered`; single-peer RUDP socket transport exists in the library | LiteNetLib connection requests and app-level peer/catalog surfaces | Production LiteNetLib adapter profile plus UDP socket binding for the shared RUDP reliability owner |
| C# interop peer | TCP stream with 4-byte length-prefixed MessagePack frames | UDP multicast probe/announce | Test harness only |
| TypeScript `cultnet-ts` | `CultNetPeer` over any Node `Duplex`, TCP-framed transport, or single-peer RUDP socket transport; interop uses TCP | UDP multicast probe/announce in the interop peer | First UDP socket binding for the shared RUDP reliability owner |
| Rust `cultnet-rs` | Interop example uses TCP length-prefixed MessagePack frames; single-peer RUDP socket transport exists in the library | UDP multicast probe/announce | UDP socket binding for the shared RUDP reliability owner |
@ -146,6 +146,11 @@ Current progress:
`TcpFramedTransportConnection` with schema-channel `SendAsync`,
`ReceiveAsync`, and transfer stats. The C# interop peer advertises and uses
that shared port instead of owning raw TCP frame I/O directly.
- C# now has a `litenetlib` transport profile helper, and the production
`Client`/`Server` expose profiles for the LiteNetLib lane. The profile names
both the modern reliable ordered `schema` channel and the legacy reliable
ordered `legacy` union-message channel, so LiteNetLib is described as an
adapter instead of remaining the hidden default.
- TypeScript has the first narrow transport connection port:
`TcpFramedTransportConnection` owns length-prefixed frame delivery, exposes
frame/close/error events, `send(channel, payload)`, `close`, and transfer

View file

@ -30,7 +30,7 @@ CultMesh.
| Runtime | Role | Claimed parity | Not claimed |
| --- | --- | --- | --- |
| C# | Reference implementation and production game/server substrate | CultCache typed documents and SoA, CultNet schema-v0, LiteNetLib production path, shared transport profiles, shared RUDP socket transport, RUDP reconnect policy/controller and reconnect-loop helper, LiteNetLib client reconnect-controller adoption, CultMesh node/session/catalog/stream/simulation surfaces | No need to abandon LiteNetLib before the CultNet adapter fully owns production service adoption |
| C# | Reference implementation and production game/server substrate | CultCache typed documents and SoA, CultNet schema-v0, LiteNetLib production path with adapter profile, shared transport profiles, shared RUDP socket transport, RUDP reconnect policy/controller and reconnect-loop helper, LiteNetLib client reconnect-controller adoption, CultMesh node/session/catalog/stream/simulation surfaces | No need to abandon LiteNetLib before the CultNet adapter fully owns production service adoption |
| Python | Package runtime, local daemon endpoint, raw interop peer, typed state participant | CultCache/CultNet/CultMesh package surface, schema catalogs, shard catalogs/logs, local TCP CultMesh server, session/prediction/simulation fact helpers, authority leases, streams, RUDP codec/session/socket transport, RUDP reconnect policy/controller and reconnect-loop helper, schema-v0 MessagePack over RUDP evidence, benchmark evidence against C# cache paths | Universal C# throughput, full C# daemon/server stack, and RUDP as the only public service pipe |
| TypeScript | Node/browser-adjacent projection and interop runtime | CultCache parity tests, CultNet schema-v0 peer, transport profiles, TCP-framed transport port, shared RUDP socket transport, RUDP reconnect policy/controller, RUDP reconnect-loop helper, local CultMesh node/catalog/authority/stream ergonomics | Full C# game session/server stack |
| Rust | Low-level cache/transport/runtime substrate | CultCache/CultNet interop lane, transport profiles, TCP-framed port, shared RUDP codec/session/socket transport, RUDP reconnect policy/controller and reconnect-loop helper, schema-v0 MessagePack over RUDP evidence, small CultMesh facade for peer cards, authority leases, RUDP endpoint parsing, and peer-card RUDP client construction | Full CultMesh game-session/server facade, stream catalog, or production game-session server |

View file

@ -84,6 +84,19 @@ namespace GameCult.Networking
/// </summary>
public CultNetReconnectPolicy ReconnectPolicy => _reconnectController.Policy;
/// <summary>
/// Gets a transport profile describing the client's current LiteNetLib production lane.
/// </summary>
public CultNetTransportProfile TransportProfile => CultNetTransportProfiles.CreateLiteNetLib(
"csharp-client",
new LiteNetLibTransportProfileOptions
{
TransportId = "litenetlib-client",
Host = _lastHost,
Port = _lastPort > 0 ? _lastPort : null,
ReconnectPolicy = ReconnectPolicy
});
/// <summary>
/// Gets the last scheduled reconnect attempt number.
/// </summary>
@ -118,6 +131,7 @@ namespace GameCult.Networking
/// Initializes a new client instance.
/// </summary>
/// <param name="security">Validated client security configuration. This must be provided explicitly by the caller.</param>
/// <param name="reconnectPolicy">Optional portable reconnect policy for the LiteNetLib client lane.</param>
public Client(ClientSecurityOptions security, CultNetReconnectPolicy? reconnectPolicy = null)
{
_security = security ?? throw new ArgumentNullException(nameof(security));

View file

@ -278,6 +278,33 @@ namespace GameCult.Networking
public CultNetReconnectPolicy? ReconnectPolicy { get; set; }
}
/// <summary>
/// Options for creating a LiteNetLib transport profile.
/// </summary>
public sealed class LiteNetLibTransportProfileOptions
{
/// <summary>
/// Gets or sets the advertised transport id.
/// </summary>
public string TransportId { get; set; } = "litenetlib";
/// <summary>
/// Gets or sets the advertised host.
/// </summary>
public string? Host { get; set; }
/// <summary>
/// Gets or sets the advertised port.
/// </summary>
public int? Port { get; set; }
/// <summary>
/// Gets or sets the maximum payload size for LiteNetLib channels.
/// </summary>
public int? MaxPayloadBytes { get; set; }
/// <summary>
/// Gets or sets the advertised reconnect policy for this LiteNetLib transport.
/// </summary>
public CultNetReconnectPolicy? ReconnectPolicy { get; set; }
}
/// <summary>
/// Options for creating a CultNet RUDP transport profile.
/// </summary>
@ -358,6 +385,56 @@ namespace GameCult.Networking
};
}
/// <summary>
/// Creates a profile for the current C# LiteNetLib production lane.
/// </summary>
public static CultNetTransportProfile CreateLiteNetLib(
string runtimeId,
LiteNetLibTransportProfileOptions? options = null)
{
if (string.IsNullOrWhiteSpace(runtimeId)) throw new ArgumentException("Runtime id is required.", nameof(runtimeId));
options ??= new LiteNetLibTransportProfileOptions();
return new CultNetTransportProfile
{
RuntimeId = runtimeId,
Transports =
[
new CultNetTransportDescriptor
{
TransportId = string.IsNullOrWhiteSpace(options.TransportId)
? "litenetlib"
: options.TransportId,
Protocol = "litenetlib",
Host = options.Host,
Port = options.Port,
WireContracts =
[
CultNetWireContracts.SchemaV0,
CultNetWireContracts.GameCultNetworkingV0
],
ReconnectPolicy = options.ReconnectPolicy ?? CultNetReconnectPolicies.CreateDefault(),
Channels =
[
new CultNetTransportChannel
{
ChannelId = "schema",
Delivery = "reliable",
Ordering = "ordered",
MaxPayloadBytes = options.MaxPayloadBytes
},
new CultNetTransportChannel
{
ChannelId = "legacy",
Delivery = "reliable",
Ordering = "ordered",
MaxPayloadBytes = options.MaxPayloadBytes
}
]
}
]
};
}
/// <summary>
/// Creates a profile for the CultNet reliable UDP transport.
/// </summary>

View file

@ -366,6 +366,11 @@ The client:
- automatically re-verifies using the stored signed session token
- exposes reconnect state for UI/operator surfaces
`Client.TransportProfile` and `Server.TransportProfile` describe the production
LiteNetLib lane as a `litenetlib` transport adapter with reliable ordered
`schema` and `legacy` channels. Discovery and operators can inspect the active
pipe without treating LiteNetLib as an implicit protocol truth.
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

View file

@ -59,6 +59,18 @@ namespace GameCult.Networking
private float Time => (float)(_timer?.Elapsed.TotalSeconds ?? 0d);
/// <summary>
/// Gets a transport profile describing the server's LiteNetLib production lane.
/// </summary>
public CultNetTransportProfile TransportProfile => CultNetTransportProfiles.CreateLiteNetLib(
"csharp-server",
new LiteNetLibTransportProfileOptions
{
TransportId = "litenetlib-server",
Host = "0.0.0.0",
Port = ServerPort
});
/// <summary>
/// Initializes a new server instance over the supplied cache.
/// </summary>

View file

@ -392,6 +392,59 @@ namespace GameCult.Networking.Tests
Is.EqualTo(new int?[] { 64, 64, 64 }));
}
[Test]
public void LiteNetLibTransportProfile_AdvertisesLegacyAndSchemaChannels()
{
var policy = CultNetReconnectPolicies.CreateDefault("client-policy", maxAttempts: 4);
var profile = CultNetTransportProfiles.CreateLiteNetLib(
"csharp-litenetlib",
new LiteNetLibTransportProfileOptions
{
TransportId = "game-server",
Host = "127.0.0.1",
Port = 3075,
MaxPayloadBytes = 65_507,
ReconnectPolicy = policy
});
var transport = profile.Transports.Single();
Assert.That(transport.Protocol, Is.EqualTo("litenetlib"));
Assert.That(transport.TransportId, Is.EqualTo("game-server"));
Assert.That(transport.Host, Is.EqualTo("127.0.0.1"));
Assert.That(transport.Port, Is.EqualTo(3075));
Assert.That(transport.WireContracts, Is.EqualTo(new[] { CultNetWireContracts.SchemaV0, CultNetWireContracts.GameCultNetworkingV0 }));
Assert.That(transport.ReconnectPolicy, Is.SameAs(policy));
Assert.That(
transport.Channels.Select(channel => $"{channel.ChannelId}:{channel.Delivery}:{channel.Ordering}:{channel.MaxPayloadBytes}").ToArray(),
Is.EqualTo(new[]
{
"schema:reliable:ordered:65507",
"legacy:reliable:ordered:65507"
}));
}
[Test]
public void LiteNetLibClientAndServer_ExposeTransportProfiles()
{
var policy = CultNetReconnectPolicies.CreateDefault("client-profile", maxAttempts: 3);
using var client = new Client(DevelopmentClientSecurity, policy);
using var server = new Server(new CultCache(), DevelopmentServerSecurity);
var clientTransport = client.TransportProfile.Transports.Single();
Assert.That(clientTransport.Protocol, Is.EqualTo("litenetlib"));
Assert.That(clientTransport.TransportId, Is.EqualTo("litenetlib-client"));
Assert.That(clientTransport.Host, Is.EqualTo("localhost"));
Assert.That(clientTransport.ReconnectPolicy, Is.SameAs(policy));
Assert.That(clientTransport.WireContracts, Is.EqualTo(new[] { CultNetWireContracts.SchemaV0, CultNetWireContracts.GameCultNetworkingV0 }));
var serverTransport = server.TransportProfile.Transports.Single();
Assert.That(serverTransport.Protocol, Is.EqualTo("litenetlib"));
Assert.That(serverTransport.TransportId, Is.EqualTo("litenetlib-server"));
Assert.That(serverTransport.Host, Is.EqualTo("0.0.0.0"));
Assert.That(serverTransport.Port, Is.EqualTo(3075));
Assert.That(serverTransport.Channels.Select(channel => channel.ChannelId).ToArray(), Is.EqualTo(new[] { "schema", "legacy" }));
}
[Test]
public void ReconnectPolicy_ExposesPortableDelayContract()
{