Esempio n. 1
0
        /// <returns>Full path to Tor binary for selected <paramref name="platform"/>.</returns>
        public static string GetTorBinaryFilePath(OSPlatform?platform = null)
        {
            platform ??= MicroserviceHelpers.GetCurrentPlatform();

            string binaryPath = MicroserviceHelpers.GetBinaryPath(Path.Combine("Tor", "tor"), platform);

            return(platform == OSPlatform.OSX ? $"{binaryPath}.real" : binaryPath);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a new instance.
        /// </summary>
        /// <param name="dataDir">Application data directory.</param>
        /// <param name="logFilePath">Full Tor log file path.</param>
        /// <param name="distributionFolderPath">Full path to folder containing Tor installation files.</param>
        public TorSettings(string dataDir, string logFilePath, string distributionFolderPath)
        {
            TorBinaryFilePath = GetTorBinaryFilePath();
            TorBinaryDir      = Path.Combine(MicroserviceHelpers.GetBinaryFolder(), "Tor");

            TorDataDir         = Path.Combine(dataDir, "tordata");
            LogFilePath        = logFilePath;
            DistributionFolder = distributionFolderPath;

            GeoIpPath  = Path.Combine(DistributionFolder, "Tor", "Geoip", "geoip");
            GeoIp6Path = Path.Combine(DistributionFolder, "Tor", "Geoip", "geoip6");
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a new instance.
        /// </summary>
        /// <param name="dataDir">Application data directory.</param>
        /// <param name="logFilePath">Full Tor log file path.</param>
        /// <param name="distributionFolderPath">Full path to folder containing Tor installation files.</param>
        public TorSettings(string dataDir, string logFilePath, string distributionFolderPath)
        {
            var torBinary = MicroserviceHelpers.GetBinaryPath(Path.Combine("Tor", "tor"));

            TorBinaryFilePath = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? $"{torBinary}.real" : torBinary;
            TorBinaryDir      = Path.Combine(MicroserviceHelpers.GetBinaryFolder(), "Tor");

            TorDataDir         = Path.Combine(dataDir, "tordata");
            LogFilePath        = logFilePath;
            DistributionFolder = distributionFolderPath;

            GeoIpPath  = Path.Combine(DistributionFolder, "Tor", "Geoip", "geoip");
            GeoIp6Path = Path.Combine(DistributionFolder, "Tor", "Geoip", "geoip6");
        }
Esempio n. 4
0
        /// <param name="dataDir">Application data directory.</param>
        /// <param name="distributionFolderPath">Full path to folder containing Tor installation files.</param>
        public TorSettings(string dataDir, string distributionFolderPath, bool terminateOnExit, int?owningProcessId = null)
        {
            TorBinaryFilePath = GetTorBinaryFilePath();
            TorBinaryDir      = Path.Combine(MicroserviceHelpers.GetBinaryFolder(), "Tor");

            TorDataDir         = Path.Combine(dataDir, "tordata2");
            CookieAuthFilePath = Path.Combine(dataDir, "control_auth_cookie");
            LogFilePath        = Path.Combine(dataDir, "TorLogs.txt");
            IoHelpers.EnsureContainingDirectoryExists(LogFilePath);
            DistributionFolder = distributionFolderPath;
            TerminateOnExit    = terminateOnExit;
            OwningProcessId    = owningProcessId;
            GeoIpPath          = Path.Combine(DistributionFolder, "Tor", "Geoip", "geoip");
            GeoIp6Path         = Path.Combine(DistributionFolder, "Tor", "Geoip", "geoip6");
        }
Esempio n. 5
0
        public async void SendCommandImmediateCancelAsync()
        {
            await Assert.ThrowsAsync <TaskCanceledException>(async() =>
            {
                using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5));

                var startInfo = new ProcessStartInfo()
                {
                    FileName  = MicroserviceHelpers.GetBinaryPath("bitcoind"),
                    Arguments = "-regtest=1"
                };

                using var process = new ProcessAsync(startInfo);
                process.Start();

                await process.WaitForExitAsync(cts.Token, killOnCancel: true);
            });
        }
Esempio n. 6
0
        /// <summary>
        /// This method can be called only once.
        /// </summary>
        public async Task StartAsync(CancellationToken cancel)
        {
            int    ptcv            = PrintToConsole ? 1 : 0;
            string processPath     = MicroserviceHelpers.GetBinaryPath("bitcoind");
            string networkArgument = NetworkTranslator.GetCommandLineArguments(Network);

            string args = $"{networkArgument} -datadir=\"{DataDir}\" -printtoconsole={ptcv}";

            // Start bitcoind process.
            Process = new ProcessAsync(ProcessStartInfoFactory.Make(processPath, args));
            Process.Start();

            // Store PID in PID file.
            await PidFile.WriteFileAsync(Process.Id).ConfigureAwait(false);

            CachedPid = Process.Id;

            try
            {
                var exceptionTracker = new LastExceptionTracker();

                // Try to connect to bitcoin daemon RPC until we succeed.
                while (true)
                {
                    try
                    {
                        TimeSpan timeSpan = await RpcClient.UptimeAsync(cancel).ConfigureAwait(false);

                        Logger.LogInfo("RPC connection is successfully established.");
                        Logger.LogDebug($"RPC uptime is: {timeSpan}.");

                        // Bitcoin daemon is started. We are done.
                        break;
                    }
                    catch (Exception ex)
                    {
                        ExceptionInfo exceptionInfo = exceptionTracker.Process(ex);

                        // Don't log extensively.
                        if (exceptionInfo.IsFirst)
                        {
                            Logger.LogInfo($"{Constants.BuiltinBitcoinNodeName} is not yet ready... Reason: {exceptionInfo.Exception.Message}");
                        }

                        if (Process is { } p&& p.HasExited)
                        {
                            throw new BitcoindException($"Failed to start daemon, location: '{p.StartInfo.FileName} {p.StartInfo.Arguments}'", ex);
                        }
                    }

                    if (cancel.IsCancellationRequested)
                    {
                        Logger.LogDebug("Bitcoin daemon was not started yet and user requested to cancel the operation.");
                        await StopAsync(onlyOwned : true).ConfigureAwait(false);

                        cancel.ThrowIfCancellationRequested();
                    }

                    // Wait a moment before the next check.
                    await Task.Delay(100, cancel).ConfigureAwait(false);
                }
            }
            catch (Exception)
            {
                Process?.Dispose();
                throw;
            }
        }
 public HwiProcessBridge()
 {
     ProcessPath = MicroserviceHelpers.GetBinaryPath("hwi");
 }
 public BitcoindProcessBridge() : base(MicroserviceHelpers.GetBinaryPath("bitcoind"))
 {
 }
Esempio n. 9
0
 public HwiProcessBridge(ProcessInvoker processInvoker)
 {
     ProcessPath    = MicroserviceHelpers.GetBinaryPath("hwi");
     ProcessInvoker = processInvoker;
 }
Esempio n. 10
0
 public HwiProcessBridge() : base(MicroserviceHelpers.GetBinaryPath("hwi"))
 {
 }