diff --git a/Services/Notification/README.md b/Services/Notification/README.md index 86a92b2..a958fa6 100644 --- a/Services/Notification/README.md +++ b/Services/Notification/README.md @@ -76,7 +76,7 @@ Works by receiving the same request than email method from the gatewayserver, bu ### Steps 1-Excute this [Update_ItemLock.sql Script](/Database/CommunityProvided/F3rreNotificationService/Scripts/Update_ItemLock.sql) -2-Excute this [Update_ItemLock.sql Script](/Database/CommunityProvided/F3rreNotificationService/Scripts/Update_SecPassWord.sql) +2-Excute this [Update_SecPassWord.sql Script](/Database/CommunityProvided/F3rreNotificationService/Scripts/Update_SecPassWord.sql) 3-Excute this [Update_TbUser.sql Script](/Database/CommunityProvided/F3rreNotificationService/Scripts/UpdateTbUser.sql) diff --git a/Services/Ping/NationPingService.cs b/Services/Ping/NationPingService.cs index 919dc22..c79f9b8 100644 --- a/Services/Ping/NationPingService.cs +++ b/Services/Ping/NationPingService.cs @@ -1,8 +1,11 @@ -using System.Net; -using System.Net.Sockets; using ISRORBilling.Models.Ping; + using Microsoft.Extensions.Options; +using System.Buffers; +using System.Net; +using System.Net.Sockets; + namespace ISRORBilling.Services.Ping { public class NationPingService : BackgroundService @@ -29,45 +32,46 @@ protected override Task ExecuteAsync(CancellationToken cancellationToken) _logger.LogInformation( "Ping Service listening on [{ServiceOptionsListenAddress}:{ServiceOptionsListenPort}]", _options.ListenAddress, _options.ListenPort); - return RequestHandler(cancellationToken); + + return ProcessAccept(cancellationToken); } - private async Task RequestHandler(CancellationToken cancellationToken) + private async Task ProcessAccept(CancellationToken cancellationToken) { while (!cancellationToken.IsCancellationRequested) { - var client = await _tcpListener.AcceptTcpClientAsync(cancellationToken).ConfigureAwait(false); - var innerCancellationToken = new CancellationTokenSource(); - var linkedCancellationToken = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, innerCancellationToken.Token); - try - { - await DoRequest(client, linkedCancellationToken.Token); - } - catch - { - innerCancellationToken.Cancel(); - } + var socket = await _tcpListener.AcceptSocketAsync(cancellationToken).ConfigureAwait(false); + + if (_logger.IsEnabled(LogLevel.Debug)) + _logger.LogDebug("[{clientEndPoint}]: connected.", socket.RemoteEndPoint); + + _ = ProcessSocket(socket, cancellationToken); } } - private async Task DoRequest(TcpClient client, CancellationToken cancellationToken) + private static async Task ProcessSocket(Socket socket, CancellationToken cancellationToken) { - _logger.LogDebug("[{@ClientRemoteEndPoint}]: connected", client.Client.RemoteEndPoint); - var stream = client.GetStream(); - while (!cancellationToken.IsCancellationRequested && client.Connected) + await using var stream = new NetworkStream(socket, true); + + var buffer = ArrayPool.Shared.Rent(14); + var memory = new Memory(buffer)[..14]; + try { - var received = new byte[14]; - await stream.ReadExactlyAsync(received, cancellationToken); + await stream.ReadExactlyAsync(memory, cancellationToken).ConfigureAwait(false); + if (buffer[2] != (byte)'R' || buffer[3] != (byte)'E' || buffer[4] != (byte)'Q' || buffer[5] != (byte)'\0') + return; - received[2] = (byte)'A'; - received[3] = (byte)'C'; - received[4] = (byte)'K'; + buffer[2] = (byte)'A'; + buffer[3] = (byte)'C'; + buffer[4] = (byte)'K'; + buffer[5] = (byte)'\0'; - await stream.WriteAsync(received, cancellationToken); - client.Close(); + await stream.WriteAsync(memory, cancellationToken).ConfigureAwait(false); + } + finally + { + ArrayPool.Shared.Return(buffer); } - - stream.Close(); //If the GW wants to keep the session alive this should be after the while loop } } } \ No newline at end of file