continuity/Server/AuthorizationServerSession.cs

44 lines
No EOL
1.1 KiB
C#

using System.Net.Sockets;
using Microsoft.Extensions.Logging;
using NetCoreServer;
namespace Server;
public class AuthorizationServerSession : TcpSession
{
private readonly ILogger _logger;
private readonly AesProvider _aesProvider;
public AuthorizationServerSession(AuthorizationServer server, ILogger logger, AesProvider aesProvider) : base(server)
{
_logger = logger;
_aesProvider = aesProvider;
}
public override long Send(byte[] buffer, long offset, long size)
{
var bytes = _aesProvider.Encrypt(buffer);
return bytes.Length;
}
public override long Receive(byte[] buffer, long offset, long size)
{
var bytes = _aesProvider.Decrypt(buffer);
return bytes.Length;
}
protected override void OnConnected()
{
_logger.LogInformation("Session with Id {Id} is connected.", Id);
}
protected override void OnDisconnected()
{
_logger.LogInformation("Session with Id {Id} is disconnected.", Id);
}
protected override void OnError(SocketError error)
{
_logger.LogError("Authorization session caught an error with code {error}", error);
}
}