Ejemplo n.º 1
0
 private static bool TryParseAsExternalService(TorService torService, out ExternalService externalService)
 {
     externalService = null;
     if (torService.ServiceType == TorServiceType.P2P)
     {
         externalService = new ExternalService()
         {
             CryptoCode       = torService.Network.CryptoCode,
             DisplayName      = "Full node P2P",
             Type             = ExternalServiceTypes.P2P,
             ConnectionString = new ExternalConnectionString(new Uri($"bitcoin-p2p://{torService.OnionHost}:{torService.VirtualPort}", UriKind.Absolute)),
             ServiceName      = torService.Name,
         };
     }
     if (torService.ServiceType == TorServiceType.RPC)
     {
         externalService = new ExternalService()
         {
             CryptoCode       = torService.Network.CryptoCode,
             DisplayName      = "Full node RPC",
             Type             = ExternalServiceTypes.RPC,
             ConnectionString = new ExternalConnectionString(new Uri($"btcrpc://*****:*****@{torService.OnionHost}:{torService.VirtualPort}?label=BTCPayNode", UriKind.Absolute)),
             ServiceName      = torService.Name
         };
     }
     return(externalService != null);
 }
Ejemplo n.º 2
0
        internal void Refresh()
        {
            if (string.IsNullOrEmpty(_transmuterTorOptions.TorrcFile) || !File.Exists(_transmuterTorOptions.TorrcFile))
            {
                if (!string.IsNullOrEmpty(_transmuterTorOptions.TorrcFile))
                {
                    _logger.LogWarning("Torrc file is not found");
                }
                Services = Array.Empty <TorService>();
                return;
            }
            List <TorService> result = new List <TorService>();

            try
            {
                var torrcContent = File.ReadAllText(_transmuterTorOptions.TorrcFile);
                if (!Torrc.TryParse(torrcContent, out var torrc))
                {
                    _logger.LogWarning("Torrc file could not be parsed");
                    Services = Array.Empty <TorService>();
                    return;
                }

                var services = torrc.ServiceDirectories.SelectMany(d => d.ServicePorts.Select(p => (Directory: new DirectoryInfo(d.DirectoryPath), VirtualPort: p.VirtualPort)))
                               .Select(d => (ServiceName: d.Directory.Name,
                                             ReadingLines: System.IO.File.ReadAllLines(Path.Combine(d.Directory.FullName, "hostname")),
                                             VirtualPort: d.VirtualPort))
                               .ToArray();
                foreach (var service in services)
                {
                    try
                    {
                        var onionHost  = (service.ReadingLines)[0].Trim();
                        var torService = new TorService()
                        {
                            Name        = service.ServiceName,
                            OnionHost   = $"http://{onionHost}",
                            VirtualPort = service.VirtualPort
                        };
                        result.Add(torService);
                    }
                    catch (Exception ex)
                    {
                        _logger.LogWarning(ex, $"Error while reading hidden service {service.ServiceName} configuration");
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogWarning(ex, $"Error while reading torrc file");
            }
            Services = result.ToArray();
        }
 private static bool TryParseAsExternalService(TorService torService, out ExternalService externalService)
 {
     externalService = null;
     if (torService.ServiceType == TorServiceType.P2P)
     {
         externalService = new ExternalService()
         {
             CryptoCode       = torService.Network.CryptoCode,
             DisplayName      = "Nodo completo P2P",
             Type             = ExternalServiceTypes.P2P,
             ConnectionString = new ExternalConnectionString(new Uri($"bitcoin-p2p://{torService.OnionHost}:{torService.VirtualPort}", UriKind.Absolute)),
             ServiceName      = torService.Name,
         };
     }
     return(externalService != null);
 }