From 7e10238c2ee0d31d1f0c31ed594c28c778915870 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 16 Jun 2026 07:30:56 +0100 Subject: [PATCH] Advertise C# LiteNetLib transport profile --- docs/cultnet-transport-parity.md | 7 +- docs/runtime-parity-scope.md | 2 +- src/GameCult.Networking/Client.cs | 14 ++++ src/GameCult.Networking/CultNetTransport.cs | 77 +++++++++++++++++++ src/GameCult.Networking/README.md | 5 ++ src/GameCult.Networking/Server.cs | 12 +++ .../NetworkingTests.cs | 53 +++++++++++++ 7 files changed, 168 insertions(+), 2 deletions(-) diff --git a/docs/cultnet-transport-parity.md b/docs/cultnet-transport-parity.md index c9ff1d96..15b0e3d9 100644 --- a/docs/cultnet-transport-parity.md +++ b/docs/cultnet-transport-parity.md @@ -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 diff --git a/docs/runtime-parity-scope.md b/docs/runtime-parity-scope.md index 4d85325c..b802d283 100644 --- a/docs/runtime-parity-scope.md +++ b/docs/runtime-parity-scope.md @@ -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 | diff --git a/src/GameCult.Networking/Client.cs b/src/GameCult.Networking/Client.cs index e7e948b0..29203227 100644 --- a/src/GameCult.Networking/Client.cs +++ b/src/GameCult.Networking/Client.cs @@ -84,6 +84,19 @@ namespace GameCult.Networking /// public CultNetReconnectPolicy ReconnectPolicy => _reconnectController.Policy; + /// + /// Gets a transport profile describing the client's current LiteNetLib production lane. + /// + public CultNetTransportProfile TransportProfile => CultNetTransportProfiles.CreateLiteNetLib( + "csharp-client", + new LiteNetLibTransportProfileOptions + { + TransportId = "litenetlib-client", + Host = _lastHost, + Port = _lastPort > 0 ? _lastPort : null, + ReconnectPolicy = ReconnectPolicy + }); + /// /// Gets the last scheduled reconnect attempt number. /// @@ -118,6 +131,7 @@ namespace GameCult.Networking /// Initializes a new client instance. /// /// Validated client security configuration. This must be provided explicitly by the caller. + /// Optional portable reconnect policy for the LiteNetLib client lane. public Client(ClientSecurityOptions security, CultNetReconnectPolicy? reconnectPolicy = null) { _security = security ?? throw new ArgumentNullException(nameof(security)); diff --git a/src/GameCult.Networking/CultNetTransport.cs b/src/GameCult.Networking/CultNetTransport.cs index 53acc28b..4aa4719c 100644 --- a/src/GameCult.Networking/CultNetTransport.cs +++ b/src/GameCult.Networking/CultNetTransport.cs @@ -278,6 +278,33 @@ namespace GameCult.Networking public CultNetReconnectPolicy? ReconnectPolicy { get; set; } } + /// + /// Options for creating a LiteNetLib transport profile. + /// + public sealed class LiteNetLibTransportProfileOptions + { + /// + /// Gets or sets the advertised transport id. + /// + public string TransportId { get; set; } = "litenetlib"; + /// + /// Gets or sets the advertised host. + /// + public string? Host { get; set; } + /// + /// Gets or sets the advertised port. + /// + public int? Port { get; set; } + /// + /// Gets or sets the maximum payload size for LiteNetLib channels. + /// + public int? MaxPayloadBytes { get; set; } + /// + /// Gets or sets the advertised reconnect policy for this LiteNetLib transport. + /// + public CultNetReconnectPolicy? ReconnectPolicy { get; set; } + } + /// /// Options for creating a CultNet RUDP transport profile. /// @@ -358,6 +385,56 @@ namespace GameCult.Networking }; } + /// + /// Creates a profile for the current C# LiteNetLib production lane. + /// + 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 + } + ] + } + ] + }; + } + /// /// Creates a profile for the CultNet reliable UDP transport. /// diff --git a/src/GameCult.Networking/README.md b/src/GameCult.Networking/README.md index 59e3bacf..08f68cd1 100644 --- a/src/GameCult.Networking/README.md +++ b/src/GameCult.Networking/README.md @@ -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 diff --git a/src/GameCult.Networking/Server.cs b/src/GameCult.Networking/Server.cs index de6d5470..a4b28d0d 100644 --- a/src/GameCult.Networking/Server.cs +++ b/src/GameCult.Networking/Server.cs @@ -59,6 +59,18 @@ namespace GameCult.Networking private float Time => (float)(_timer?.Elapsed.TotalSeconds ?? 0d); + /// + /// Gets a transport profile describing the server's LiteNetLib production lane. + /// + public CultNetTransportProfile TransportProfile => CultNetTransportProfiles.CreateLiteNetLib( + "csharp-server", + new LiteNetLibTransportProfileOptions + { + TransportId = "litenetlib-server", + Host = "0.0.0.0", + Port = ServerPort + }); + /// /// Initializes a new server instance over the supplied cache. /// diff --git a/tests/GameCult.Networking.Tests/NetworkingTests.cs b/tests/GameCult.Networking.Tests/NetworkingTests.cs index 8885d7cc..df96828b 100644 --- a/tests/GameCult.Networking.Tests/NetworkingTests.cs +++ b/tests/GameCult.Networking.Tests/NetworkingTests.cs @@ -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() {