using System.Net.Quic; using DTLib.Logging; using Meum.Core.Messages; namespace Meum.Server; public class ClientConnection : IAsyncDisposable { private readonly QuicConnection _quicConnection; private QuicStreamWrapper _systemStream; private ILogger _logger; private ClientConnection(QuicConnection quicConnection, QuicStreamWrapper systemStream, ILogger logger) { _quicConnection = quicConnection; _systemStream = systemStream; _logger = logger; } public static async Task OpenAsync( QuicConnection quicConnection, ILogger logger, CancellationToken ct) { var systemStream = await quicConnection.AcceptStreamAsync(QuicStreamType.Bidirectional, ct); await systemStream.ReceivePingSendPong(); var clientConnection = new ClientConnection(quicConnection, systemStream, logger); DataMessageHeader header = await systemStream.ReadDataMessageHeaderAsync(ct); switch (header.type_code) { case MessageTypeCode.RegistrationRequest: break; case MessageTypeCode.AuthorizationRequest: // if (authorized) // clientConnection.HandleClientRequestsAsync() break; default: throw new Exception($"New connection sent unexpected message: {header.type_code}"); } return clientConnection; } // private async void HandleClientRequestsAsync(CancellationToken ct = default) // { // // } public async ValueTask DisposeAsync() { await _quicConnection.DisposeAsync(); } }