Exemplo n.º 1
0
        public void Run(string[] args)
        {
            INetworkSet networkSet = AltNetworkSets.Bitcoin;
            var         argsConf   = new TextFileConfiguration(args);
            var         debug      = argsConf.GetOrDefault <bool>("debug", false);

            ConsoleLoggerProcessor loggerProcessor = new ConsoleLoggerProcessor();

            Logs.Configure(new FuncLoggerFactory(i => new CustomerConsoleLogger(i, Logs.SupportDebug(debug), null, loggerProcessor)));

            using (var interactive = new Interactive())
            {
                var config = new TumblerConfiguration();
                config.LoadArgs(networkSet, args);
                try
                {
                    var runtime = TumblerRuntime.FromConfiguration(config, new TextWriterClientInteraction(Console.Out, Console.In));
                    interactive.Runtime = new ServerInteractiveRuntime(runtime);
                    StoppableWebHost host = null;
                    if (!config.OnlyMonitor)
                    {
                        host = new StoppableWebHost(() => new WebHostBuilder()
                                                    .UseAppConfiguration(runtime)
                                                    .UseContentRoot(Directory.GetCurrentDirectory())
                                                    .UseStartup <Startup>()
                                                    .Build());
                    }

                    var job = new BroadcasterJob(interactive.Runtime.Services);
                    job.Start();
                    interactive.Services.Add(job);

                    var tor = new TorRegisterJob(config, runtime);
                    tor.Start();
                    interactive.Services.Add(tor);

                    if (!config.OnlyMonitor)
                    {
                        host.Start();
                        interactive.Services.Add(host);
                    }

                    interactive.StartInteractive();
                }
                catch (ConfigException ex)
                {
                    if (!string.IsNullOrEmpty(ex.Message))
                    {
                        Logs.Configuration.LogError(ex.Message);
                    }
                }
                catch (InterruptedConsoleException) { }
                catch (Exception exception)
                {
                    Logs.Tumbler.LogError("Exception thrown while running the server");
                    Logs.Tumbler.LogError(exception.ToString());
                }
            }
        }
Exemplo n.º 2
0
        public void Run(string[] args)
        {
            Logs.Configure(new FuncLoggerFactory(i => new CustomerConsoleLogger(i, (a, b) => true, false)));

            using (var interactive = new Interactive())
            {
                var config = new TumblerConfiguration();
                config.LoadArgs(args);
                try
                {
                    var runtime = TumblerRuntime.FromConfiguration(config, new TextWriterClientInteraction(Console.Out, Console.In));
                    interactive.Runtime = new ServerInteractiveRuntime(runtime);
                    StoppableWebHost host = null;
                    if (!config.OnlyMonitor)
                    {
                        host = new StoppableWebHost(() => new WebHostBuilder()
                                                    .UseKestrel()
                                                    .UseAppConfiguration(runtime)
                                                    .UseContentRoot(Directory.GetCurrentDirectory())
                                                    .UseStartup <Startup>()
                                                    .UseUrls(config.GetUrls()).Build());
                    }

                    var job = new BroadcasterJob(interactive.Runtime.Services);
                    job.Start();
                    interactive.Services.Add(job);

                    if (!config.OnlyMonitor)
                    {
                        host.Start();
                        interactive.Services.Add(host);
                    }

                    interactive.StartInteractive();
                }
                catch (ConfigException ex)
                {
                    if (!string.IsNullOrEmpty(ex.Message))
                    {
                        Logs.Configuration.LogError(ex.Message);
                    }
                }
                catch (InterruptedConsoleException) { }
                catch (Exception exception)
                {
                    Logs.Tumbler.LogError("Exception thrown while running the server");
                    Logs.Tumbler.LogError(exception.ToString());
                }
            }
        }
Exemplo n.º 3
0
        public void StartTumbler(BreezeConfiguration breezeConfig, bool getConfigOnly, string ntumblebitServerConf = null, string datadir = null)
        {
            var argsTemp = new List <string>();

            argsTemp.Add("-debug");

            if (breezeConfig.TumblerNetwork == Network.TestNet)
            {
                argsTemp.Add("-testnet");
            }
            else if (breezeConfig.TumblerNetwork == Network.RegTest)
            {
                argsTemp.Add("-regtest");
            }
            // No else needed, mainnet is defaulted

            if (ntumblebitServerConf != null)
            {
                argsTemp.Add("-conf=" + ntumblebitServerConf);
            }

            if (datadir != null)
            {
                argsTemp.Add("-datadir=" + datadir);
            }

            string[] args     = argsTemp.ToArray();
            var      argsConf = new TextFileConfiguration(args);
            var      debug    = argsConf.GetOrDefault <bool>("debug", false);

            ConsoleLoggerProcessor loggerProcessor = new ConsoleLoggerProcessor();

            Logs.Configure(new FuncLoggerFactory(i => new CustomerConsoleLogger(i, Logs.SupportDebug(debug), false, loggerProcessor)));

            if (getConfigOnly)
            {
                config = new TumblerConfiguration();
                config.LoadArgs(args);
                runtime = TumblerRuntime.FromConfiguration(config, new AcceptAllClientInteraction());
                return;
            }

            using (var interactive = new Interactive())
            {
                config = new TumblerConfiguration();
                config.LoadArgs(args);
                try
                {
                    runtime             = TumblerRuntime.FromConfiguration(config, new TextWriterClientInteraction(Console.Out, Console.In));
                    interactive.Runtime = new ServerInteractiveRuntime(runtime);
                    StoppableWebHost host = null;
                    if (!config.OnlyMonitor)
                    {
                        host = new StoppableWebHost(() => new WebHostBuilder()
                                                    .UseAppConfiguration(runtime)
                                                    .UseContentRoot(Directory.GetCurrentDirectory())
                                                    .UseStartup <Startup>()
                                                    .Build());
                    }

                    var job = new BroadcasterJob(interactive.Runtime.Services);
                    job.Start();
                    interactive.Services.Add(job);

                    var tor = new TorRegisterJob(config, runtime);
                    tor.Start();
                    interactive.Services.Add(tor);

                    if (!config.OnlyMonitor)
                    {
                        host.Start();
                        interactive.Services.Add(host);
                    }

                    interactive.StartInteractive();
                }
                catch (ConfigException ex)
                {
                    if (!string.IsNullOrEmpty(ex.Message))
                    {
                        Logs.Configuration.LogError(ex.Message);
                    }
                }
                catch (InterruptedConsoleException) { }
                catch (Exception exception)
                {
                    Logs.Tumbler.LogError("Exception thrown while running the server");
                    Logs.Tumbler.LogError(exception.ToString());
                }
            }
        }
Exemplo n.º 4
0
        public void StartTumbler(BreezeConfiguration breezeConfig, bool getConfigOnly, string ntumblebitServerConf = null, string dataDir = null, bool torMandatory = true, TumblerProtocolType?tumblerProtocol = null)
        {
            var argsTemp = new List <string>();

            argsTemp.Add("-debug");

            if (breezeConfig.TumblerNetwork == Network.TestNet)
            {
                argsTemp.Add("-testnet");
            }
            else if (breezeConfig.TumblerNetwork == Network.RegTest)
            {
                argsTemp.Add("-regtest");
            }
            // No else needed, mainnet is defaulted

            if (ntumblebitServerConf != null)
            {
                argsTemp.Add("-conf=" + ntumblebitServerConf);
            }

            if (dataDir != null)
            {
                argsTemp.Add("-datadir=" + dataDir);
            }

            if (tumblerProtocol.HasValue)
            {
                argsTemp.Add($"-tumblerProtocol={tumblerProtocol.Value}");
            }

            string[] args     = argsTemp.ToArray();
            var      argsConf = new TextFileConfiguration(args);
            var      debug    = argsConf.GetOrDefault <bool>("debug", false);

            ConsoleLoggerProcessor loggerProcessor = new ConsoleLoggerProcessor();

            if (dataDir == null)
            {
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    dataDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ImpleumNode");
                    dataDir = argsConf.GetOrDefault <string>("dataDir", dataDir);
                }
                else
                {
                    dataDir = Path.Combine(Environment.GetEnvironmentVariable("HOME"), ".impleumnode");
                    dataDir = argsConf.GetOrDefault <string>("dataDir", dataDir);
                }
            }

            string logDir = Path.Combine(dataDir, breezeConfig.TumblerNetwork.RootFolderName, breezeConfig.TumblerNetwork.Name, "Logs");

            if (!Directory.Exists(logDir))
            {
                Directory.CreateDirectory(logDir);
            }

            Logs.Configure(new FuncLoggerFactory(i => new CustomerConsoleLogger(i, Logs.SupportDebug(debug), false, loggerProcessor)), logDir);

            if (getConfigOnly)
            {
                config = new TumblerConfiguration();
                if (!torMandatory)
                {
                    config.TorMandatory = false;
                }

                config.LoadArgs(args);
                runtime = TumblerRuntime.FromConfiguration(config, new AcceptAllClientInteraction());
                return;
            }

            using (var interactive = new Interactive())
            {
                config = new TumblerConfiguration();
                config.LoadArgs(args);

                if (!torMandatory)
                {
                    config.TorMandatory = false;
                }

                try
                {
                    runtime             = TumblerRuntime.FromConfiguration(config, new TextWriterClientInteraction(Console.Out, Console.In));
                    interactive.Runtime = new ServerInteractiveRuntime(runtime);
                    StoppableWebHost host = null;
                    if (!config.OnlyMonitor)
                    {
                        host = new StoppableWebHost(() => new WebHostBuilder()
                                                    .UseAppConfiguration(runtime)
                                                    .UseContentRoot(Directory.GetCurrentDirectory())
                                                    .UseStartup <Startup>()
                                                    .Build());
                    }

                    var job = new BroadcasterJob(interactive.Runtime.Services);
                    job.Start();
                    interactive.Services.Add(job);

                    var tor = new TorRegisterJob(config, runtime);
                    tor.Start();
                    interactive.Services.Add(tor);

                    if (!config.OnlyMonitor)
                    {
                        host.Start();
                        interactive.Services.Add(host);
                    }

                    string baseUri;

                    if (breezeConfig.UseTor)
                    {
                        baseUri = runtime.TorUri.ToString().TrimEnd('/');
                    }
                    else
                    {
                        baseUri = runtime.LocalEndpoint.ToString();
                    }

                    if (!baseUri.StartsWith("http://") && (!baseUri.StartsWith("ctb://")))
                    {
                        baseUri = "http://" + baseUri;
                    }

                    var tempUri = (baseUri + "?h=" + runtime.ClassicTumblerParametersHash).Replace("http:", "ctb:");

                    //The uri.txt is only used in the integration tests as there is no registration service running (no Stratis daemon)
                    File.WriteAllText(Path.Combine(config.DataDir, "uri.txt"), tempUri);

                    interactive.StartInteractive();
                }
                catch (ConfigException ex)
                {
                    if (!string.IsNullOrEmpty(ex.Message))
                    {
                        Logs.Configuration.LogError(ex.Message);
                    }
                }
                catch (InterruptedConsoleException) { }
                catch (Exception exception)
                {
                    Logs.Tumbler.LogError("Exception thrown while running the server");
                    Logs.Tumbler.LogError(exception.ToString());
                }
            }
        }
Exemplo n.º 5
0
        public void Run(string[] args)
        {
            var argsConf = new TextFileConfiguration(args);
            var debug    = argsConf.GetOrDefault <bool>("debug", false);

            ConsoleLoggerProcessor loggerProcessor = new ConsoleLoggerProcessor();

            bool isTestNet = argsConf.GetOrDefault <bool>("testnet", false);
            bool isRegTest = argsConf.GetOrDefault <bool>("regtest", false);

            string dataDir;

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                dataDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ImpleumNode");
                dataDir = argsConf.GetOrDefault <string>("dataDir", dataDir);
            }
            else
            {
                dataDir = Path.Combine(Environment.GetEnvironmentVariable("HOME"), ".impleumnode");
                dataDir = argsConf.GetOrDefault <string>("dataDir", dataDir);
            }

            string networkRootFolderName = Network.Main.RootFolderName;

            if (isTestNet)
            {
                networkRootFolderName = Network.TestNet.RootFolderName;
            }
            else if (isRegTest)
            {
                networkRootFolderName = Network.RegTest.RootFolderName;
            }

            string logDir = Path.Combine(dataDir, networkRootFolderName, Network.Main.Name, "Logs");

            Logs.Configure(new FuncLoggerFactory(i => new CustomerConsoleLogger(i, Logs.SupportDebug(debug), false, loggerProcessor)), logDir);

            using (var interactive = new Interactive())
            {
                var config = new TumblerConfiguration();
                config.LoadArgs(args);
                try
                {
                    var runtime = TumblerRuntime.FromConfiguration(config, new TextWriterClientInteraction(Console.Out, Console.In));
                    interactive.Runtime = new ServerInteractiveRuntime(runtime);
                    StoppableWebHost host = null;
                    if (!config.OnlyMonitor)
                    {
                        host = new StoppableWebHost(() => new WebHostBuilder()
                                                    .UseAppConfiguration(runtime)
                                                    .UseContentRoot(Directory.GetCurrentDirectory())
                                                    .UseStartup <Startup>()
                                                    .Build());
                    }

                    var job = new BroadcasterJob(interactive.Runtime.Services);
                    job.Start();
                    interactive.Services.Add(job);

                    var tor = new TorRegisterJob(config, runtime);
                    tor.Start();
                    interactive.Services.Add(tor);

                    if (!config.OnlyMonitor)
                    {
                        host.Start();
                        interactive.Services.Add(host);
                    }

                    interactive.StartInteractive();
                }
                catch (ConfigException ex)
                {
                    if (!string.IsNullOrEmpty(ex.Message))
                    {
                        Logs.Configuration.LogError(ex.Message);
                    }
                }
                catch (InterruptedConsoleException) { }
                catch (Exception exception)
                {
                    Logs.Tumbler.LogError("Exception thrown while running the server");
                    Logs.Tumbler.LogError(exception.ToString());
                }
            }
        }
Exemplo n.º 6
0
        public void StartTumbler(bool testnet, bool getConfigOnly)
        {
            string[] args;

            if (!testnet)
            {
                // TODO: Tumbler is locked to testnet for testing
                args = new string[] { "-testnet" }
            }
            ;
            else
            {
                args = new string[] { "-testnet" }
            };

            var argsConf = new TextFileConfiguration(args);
            var debug    = argsConf.GetOrDefault <bool>("debug", false);

            ConsoleLoggerProcessor loggerProcessor = new ConsoleLoggerProcessor();

            Logs.Configure(new FuncLoggerFactory(i => new CustomerConsoleLogger(i, Logs.SupportDebug(debug), false, loggerProcessor)));

            if (getConfigOnly)
            {
                config = new TumblerConfiguration();
                config.LoadArgs(args);
                runtime = TumblerRuntime.FromConfiguration(config, new AcceptAllClientInteraction());
                return;
            }

            using (var interactive = new Interactive())
            {
                config = new TumblerConfiguration();
                config.LoadArgs(args);
                try
                {
                    runtime             = TumblerRuntime.FromConfiguration(config, new TextWriterClientInteraction(Console.Out, Console.In));
                    interactive.Runtime = new ServerInteractiveRuntime(runtime);
                    StoppableWebHost host = null;
                    if (!config.OnlyMonitor)
                    {
                        host = new StoppableWebHost(() => new WebHostBuilder()
                                                    .UseAppConfiguration(runtime)
                                                    .UseContentRoot(Directory.GetCurrentDirectory())
                                                    .UseStartup <Startup>()
                                                    .Build());
                    }

                    var job = new BroadcasterJob(interactive.Runtime.Services);
                    job.Start();
                    interactive.Services.Add(job);

                    if (!config.OnlyMonitor)
                    {
                        host.Start();
                        interactive.Services.Add(host);
                    }

                    interactive.StartInteractive();
                }
                catch (ConfigException ex)
                {
                    if (!string.IsNullOrEmpty(ex.Message))
                    {
                        Logs.Configuration.LogError(ex.Message);
                    }
                }
                catch (InterruptedConsoleException) { }
                catch (Exception exception)
                {
                    Logs.Tumbler.LogError("Exception thrown while running the server");
                    Logs.Tumbler.LogError(exception.ToString());
                }
            }
        }
    }
Exemplo n.º 7
0
        public void StartTumbler(BreezeConfiguration breezeConfig, bool getConfigOnly, string ntumblebitServerConf = null, string datadir = null, bool torMandatory = true)
        {
            var argsTemp = new List <string>();

            argsTemp.Add("-debug");

            if (breezeConfig.TumblerNetwork == Network.TestNet)
            {
                argsTemp.Add("-testnet");
            }
            else if (breezeConfig.TumblerNetwork == Network.RegTest)
            {
                argsTemp.Add("-regtest");
            }
            // No else needed, mainnet is defaulted

            if (ntumblebitServerConf != null)
            {
                argsTemp.Add("-conf=" + ntumblebitServerConf);
            }

            if (datadir != null)
            {
                argsTemp.Add("-datadir=" + datadir);
            }

            string[] args     = argsTemp.ToArray();
            var      argsConf = new TextFileConfiguration(args);
            var      debug    = argsConf.GetOrDefault <bool>("debug", false);

            ConsoleLoggerProcessor loggerProcessor = new ConsoleLoggerProcessor();

            Logs.Configure(new FuncLoggerFactory(i => new CustomerConsoleLogger(i, Logs.SupportDebug(debug), false, loggerProcessor)));

            if (getConfigOnly)
            {
                config = new TumblerConfiguration();
                config.LoadArgs(args);
                runtime = TumblerRuntime.FromConfiguration(config, new AcceptAllClientInteraction());
                return;
            }

            using (var interactive = new Interactive())
            {
                config = new TumblerConfiguration();
                config.LoadArgs(args);

                if (!torMandatory)
                {
                    config.TorMandatory = false;
                }

                try
                {
                    runtime             = TumblerRuntime.FromConfiguration(config, new TextWriterClientInteraction(Console.Out, Console.In));
                    interactive.Runtime = new ServerInteractiveRuntime(runtime);
                    StoppableWebHost host = null;
                    if (!config.OnlyMonitor)
                    {
                        host = new StoppableWebHost(() => new WebHostBuilder()
                                                    .UseAppConfiguration(runtime)
                                                    .UseContentRoot(Directory.GetCurrentDirectory())
                                                    .UseStartup <Startup>()
                                                    .Build());
                    }

                    var job = new BroadcasterJob(interactive.Runtime.Services);
                    job.Start();
                    interactive.Services.Add(job);

                    var tor = new TorRegisterJob(config, runtime);
                    tor.Start();
                    interactive.Services.Add(tor);

                    if (!config.OnlyMonitor)
                    {
                        host.Start();
                        interactive.Services.Add(host);
                    }

                    string baseUri;

                    if (runtime.TorUri == null)
                    {
                        baseUri = runtime.LocalEndpoint.ToString();
                    }
                    else
                    {
                        if (runtime.TorUri.ToString().EndsWith("/"))
                        {
                            baseUri = runtime.TorUri.ToString().Substring(0, runtime.TorUri.ToString().Length - 1);
                        }
                        else
                        {
                            baseUri = runtime.TorUri.ToString();
                        }
                    }

                    if (!baseUri.StartsWith("http://") && (!baseUri.StartsWith("ctb://")))
                    {
                        baseUri = "http://" + baseUri;
                    }

                    var tempUri = (baseUri + "?h=" + runtime.ClassicTumblerParametersHash).Replace("http:", "ctb:");
                    File.WriteAllText(Path.Combine(config.DataDir, "uri.txt"), tempUri);

                    interactive.StartInteractive();
                }
                catch (ConfigException ex)
                {
                    if (!string.IsNullOrEmpty(ex.Message))
                    {
                        Logs.Configuration.LogError(ex.Message);
                    }
                }
                catch (InterruptedConsoleException) { }
                catch (Exception exception)
                {
                    Logs.Tumbler.LogError("Exception thrown while running the server");
                    Logs.Tumbler.LogError(exception.ToString());
                }
            }
        }