<commit_before>﻿using System;
using System.Linq;
using System.Net;
using Google.Protobuf.Reflection;
using KillrVideo.Host.Config;

namespace KillrVideo.Protobuf.ServiceDiscovery
{
    /// <summary>
    /// Service discovery implementation that just points all service clients to the host/port where they
    /// have been configured to run locally.
    /// </summary>
    public class LocalServiceDiscovery : IFindGrpcServices
    {
        private readonly IHostConfiguration _hostConfig;
        private readonly Lazy<ServiceLocation> _localServicesIp; 

        public LocalServiceDiscovery(IHostConfiguration hostConfig)
        {
            if (hostConfig == null) throw new ArgumentNullException(nameof(hostConfig));
            _hostConfig = hostConfig;
            _localServicesIp = new Lazy<ServiceLocation>(GetLocalGrpcServer);
        }

        public ServiceLocation Find(ServiceDescriptor service)
        {
            return _localServicesIp.Value;
        }

        private ServiceLocation GetLocalGrpcServer()
        {
            // Get the host/port configuration for the Grpc Server
            string host = _hostConfig.GetRequiredConfigurationValue(GrpcServerTask.HostConfigKey);
            string portVal = _hostConfig.GetRequiredConfigurationValue(GrpcServerTask.HostPortKey);
            int port = int.Parse(portVal);

            return new ServiceLocation(host, port);
        }
    }
}<commit_msg>Fix local service discovery now that services are listening on 0.0.0.0<commit_after>﻿using System;
using Google.Protobuf.Reflection;
using KillrVideo.Host.Config;

namespace KillrVideo.Protobuf.ServiceDiscovery
{
    /// <summary>
    /// Service discovery implementation that just points all service clients to 'localhost' and the port
    /// where they have been configured to run locally.
    /// </summary>
    public class LocalServiceDiscovery : IFindGrpcServices
    {
        private readonly IHostConfiguration _hostConfig;
        private readonly Lazy<ServiceLocation> _localServicesIp; 

        public LocalServiceDiscovery(IHostConfiguration hostConfig)
        {
            if (hostConfig == null) throw new ArgumentNullException(nameof(hostConfig));
            _hostConfig = hostConfig;
            _localServicesIp = new Lazy<ServiceLocation>(GetLocalGrpcServer);
        }

        public ServiceLocation Find(ServiceDescriptor service)
        {
            return _localServicesIp.Value;
        }

        private ServiceLocation GetLocalGrpcServer()
        {
            // Get the host/port configuration for the Grpc Server
            string host = "localhost";
            string portVal = _hostConfig.GetRequiredConfigurationValue(GrpcServerTask.HostPortKey);
            int port = int.Parse(portVal);

            return new ServiceLocation(host, port);
        }
    }
}
{'fraction_non_alphanumeric': 0.06979203383856186, 'fraction_numerical': 0.0014099400775467042, 'mean_word_length': 2.768924302788845, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, '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': '5563354', 'n_tokens_mistral': 693, 'n_tokens_neox': 681, 'n_words': 188}