Meum/Meum.Server/ClientConnection.cs
2025-05-09 16:32:35 +05:00

57 lines
1.7 KiB
C#

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<ClientConnection> 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();
}
}