<commit_before>﻿using System;
using System.Buffers;
using System.IO;
using System.IO.Pipelines;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace SupportManager.Proxy.VoiceBlue
{
    internal class ProxyService : BackgroundService
    {
        private readonly ILogger<ProxyService> logger;
        private static readonly Regex LoginRegex = new(@"Login:\s*");
        private static readonly Regex PasswordRegex = new(@"Password:\s*");
        private static readonly MemoryPool<byte> MemoryPool = MemoryPool<byte>.Shared;
        private static readonly byte[] NewLine = Encoding.ASCII.GetBytes("\r\n");
        private static readonly byte[] Ok = Encoding.ASCII.GetBytes("OK");

        private readonly byte[] prefix;

        public string RemoteHost { get; }
        public int RemotePort { get; }
        public string RemoteUserName { get; }
        public string RemotePassword { get; }
        public int SimSlot { get; }
        public int LocalPort { get; }

        public ProxyService(string remoteHost, int remotePort, string remoteUserName, string remotePassword, int simSlot, int localPort, ILogger<ProxyService> logger)
        {
            this.logger = logger;
            RemoteHost = remoteHost;
            RemotePort = remotePort;
            RemoteUserName = remoteUserName;
            RemotePassword = <PASSWORD>;
            SimSlot = simSlot;
            LocalPort = localPort;

            prefix = Encoding.ASCII.GetBytes($"AT&G{SimSlot:00}=");
        }

        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            var listenSocket = new Socket(SocketType.Stream, ProtocolType.Tcp);
            listenSocket.Bind(new IPEndPoint(IPAddress.Loopback, LocalPort));

            logger.Log(LogLevel.Information, $"Listening on port {LocalPort}");

            listenSocket.Listen(10);

            await using (stoppingToken.UnsafeRegister(_ => listenSocket.Close(), null))
            {
                while (!stoppingToken.IsCancellationRequested)
                {
                    var socket = await listenSocket.AcceptAsync();
                    _ = ProxyCommands(socket);<commit_msg>Proxy.VoiceBlue: Listen on all interfaces<commit_after>﻿using System;
using System.Buffers;
using System.IO;
using System.IO.Pipelines;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace SupportManager.Proxy.VoiceBlue
{
    internal class ProxyService : BackgroundService
    {
        private readonly ILogger<ProxyService> logger;
        private static readonly Regex LoginRegex = new(@"Login:\s*");
        private static readonly Regex PasswordRegex = new(@"Password:\s*");
        private static readonly MemoryPool<byte> MemoryPool = MemoryPool<byte>.Shared;
        private static readonly byte[] NewLine = Encoding.ASCII.GetBytes("\r\n");
        private static readonly byte[] Ok = Encoding.ASCII.GetBytes("OK");

        private readonly byte[] prefix;

        public string RemoteHost { get; }
        public int RemotePort { get; }
        public string RemoteUserName { get; }
        public string RemotePassword { get; }
        public int SimSlot { get; }
        public int LocalPort { get; }

        public ProxyService(string remoteHost, int remotePort, string remoteUserName, string remotePassword, int simSlot, int localPort, ILogger<ProxyService> logger)
        {
            this.logger = logger;
            RemoteHost = remoteHost;
            RemotePort = remotePort;
            RemoteUserName = remoteUserName;
            RemotePassword = <PASSWORD>;
            SimSlot = simSlot;
            LocalPort = localPort;

            prefix = Encoding.ASCII.GetBytes($"AT&G{SimSlot:00}=");
        }

        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            var listenSocket = new Socket(SocketType.Stream, ProtocolType.Tcp);
            listenSocket.Bind(new IPEndPoint(IPAddress.Any, LocalPort));

            logger.Log(LogLevel.Information, $"Listening on port {LocalPort}");

            listenSocket.Listen(10);

            await using (stoppingToken.UnsafeRegister(_ => listenSocket.Close(), null))
            {
                while (!stoppingToken.IsCancellationRequested)
                {
                    var socket = await listenSocket.AcceptAsync();
                    _ = ProxyCommands(socket);
{'fraction_non_alphanumeric': 0.09047120418848167, 'fraction_numerical': 0.001675392670157068, 'mean_word_length': 2.7254290171606863, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5620152', 'n_tokens_mistral': 1234, 'n_tokens_neox': 1211, 'n_words': 317}