Partial Implementation of AuthSession
This commit is contained in:
parent
e3eb36639a
commit
2a9f1bc244
1 changed files with 44 additions and 0 deletions
44
Server/AuthorizationServerSession.cs
Normal file
44
Server/AuthorizationServerSession.cs
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue