コード例 #1
0
ファイル: Program.cs プロジェクト: tzcoins/NTumbleBit
        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());
                }
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Yzord/NTumbleBit
        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());
                }
            }
        }
コード例 #3
0
 public MainController(TumblerConfiguration configuration, ClassicTumblerRepository repo, ClassicTumblerParameters parameters, ExternalServices services)
 {
     if (configuration == null)
     {
         throw new ArgumentNullException(nameof(configuration));
     }
     if (parameters == null)
     {
         throw new ArgumentNullException(nameof(parameters));
     }
     if (services == null)
     {
         throw new ArgumentNullException(nameof(services));
     }
     if (repo == null)
     {
         throw new ArgumentNullException(nameof(repo));
     }
     _Tumbler    = configuration;
     _Repository = repo;
     _Parameters = parameters;
     _Services   = services;
 }
コード例 #4
0
        public TumblerServerTester(string directory, bool shouldBeStandard)
        {
            try
            {
                var rootTestData = "TestData";
                directory  = rootTestData + "/" + directory;
                _Directory = directory;
                if (!Directory.Exists(rootTestData))
                {
                    Directory.CreateDirectory(rootTestData);
                }

                if (!TryDelete(directory, false))
                {
                    foreach (var process in Process.GetProcessesByName("bitcoind"))
                    {
                        if (process.MainModule.FileName.Replace("\\", "/").StartsWith(Path.GetFullPath(rootTestData).Replace("\\", "/"), StringComparison.Ordinal))
                        {
                            process.Kill();
                            process.WaitForExit();
                        }
                    }
                    TryDelete(directory, true);
                }

                _NodeBuilder = NodeBuilder.Create(directory);
                _NodeBuilder.ConfigParameters.Add("prematurewitness", "1");
                _NodeBuilder.ConfigParameters.Add("walletprematurewitness", "1");

                _TumblerNode = _NodeBuilder.CreateNode(false);
                _AliceNode   = _NodeBuilder.CreateNode(false);
                _BobNode     = _NodeBuilder.CreateNode(false);

                Directory.CreateDirectory(directory);

                _NodeBuilder.StartAll();

                //Activate segwit
                SyncNodes();
                _TumblerNode.Generate(440);
                _TumblerNode.CreateRPCClient().SendToAddress(_AliceNode.CreateRPCClient().GetNewAddress(), Money.Coins(100m));
                _TumblerNode.Generate(1);
                SyncNodes();

                var conf = new TumblerConfiguration();
                conf.DataDir = Path.Combine(directory, "server");
                Directory.CreateDirectory(conf.DataDir);
                File.WriteAllBytes(Path.Combine(conf.DataDir, "Tumbler.pem"), TestKeys.Default.ToBytes());
                File.WriteAllBytes(Path.Combine(conf.DataDir, "Voucher.pem"), TestKeys.Default2.ToBytes());

                conf.RPC.Url = TumblerNode.CreateRPCClient().Address;
                var creds = ExtractCredentials(File.ReadAllText(_TumblerNode.Config));
                conf.RPC.User      = creds.Item1;
                conf.RPC.Password  = creds.Item2;
                conf.TorMandatory  = false;
                conf.Network       = Network.RegTest;
                conf.Listen        = new System.Net.IPEndPoint(IPAddress.Parse("127.0.0.1"), 5000);
                conf.AllowInsecure = !shouldBeStandard;

                conf.NoRSAProof = !shouldBeStandard;
                if (!shouldBeStandard)
                {
                    conf.ClassicTumblerParameters.FakePuzzleCount                 = 10;
                    conf.ClassicTumblerParameters.FakeTransactionCount            = 10;
                    conf.ClassicTumblerParameters.RealTransactionCount            = 10;
                    conf.ClassicTumblerParameters.RealPuzzleCount                 = 2;
                    conf.ClassicTumblerParameters.CycleGenerator.FirstCycle.Start = 105;
                }
                else
                {
                    var standard = new StandardCycles(conf.Network).Shorty2x;
                    conf.ClassicTumblerParameters.CycleGenerator = standard.Generator;
                    conf.ClassicTumblerParameters.Denomination   = standard.Denomination;
                }

                var runtime = TumblerRuntime.FromConfiguration(conf, new AcceptAllClientInteraction());
                _Host = new WebHostBuilder()
                        .UseAppConfiguration(runtime)
                        .UseContentRoot(Path.GetFullPath(directory))
                        .UseStartup <Startup>()
                        .Build();

                _Host.Start();
                ServerRuntime = runtime;

                //Overrides server fee
                ((RPCFeeService)runtime.Services.FeeService).FallBackFeeRate     = new FeeRate(Money.Satoshis(100), 1);
                ((RPCWalletService)runtime.Services.WalletService).BatchInterval = TimeSpan.FromMilliseconds(10);
                ((RPCWalletService)runtime.Services.WalletService).AddressGenerationBatchInterval = TimeSpan.FromMilliseconds(10);
                ((RPCBroadcastService)runtime.Services.BroadcastService).BatchInterval            = TimeSpan.FromMilliseconds(10);
                ((RPCBlockExplorerService)runtime.Services.BlockExplorerService).BatchInterval    = TimeSpan.FromMilliseconds(10);


                var clientConfig = new TumblerClientConfiguration();
                clientConfig.DataDir       = Path.Combine(directory, "client");
                clientConfig.AllowInsecure = !shouldBeStandard;
                Directory.CreateDirectory(clientConfig.DataDir);
                clientConfig.Network              = conf.Network;
                clientConfig.CheckIp              = false;
                clientConfig.TorMandatory         = false;
                clientConfig.OutputWallet.KeyPath = new KeyPath("0");
                clientConfig.OutputWallet.RootKey = new ExtKey().Neuter().GetWif(conf.Network);
                clientConfig.RPCArgs.Url          = AliceNode.CreateRPCClient().Address;
                creds = ExtractCredentials(File.ReadAllText(AliceNode.Config));
                clientConfig.RPCArgs.User     = creds.Item1;
                clientConfig.RPCArgs.Password = creds.Item2;
                clientConfig.TumblerServer    = runtime.TumblerUris.First();

                ClientRuntime = TumblerClientRuntime.FromConfiguration(clientConfig, new AcceptAllClientInteraction());

                //Overrides client fee
                ((RPCFeeService)ClientRuntime.Services.FeeService).FallBackFeeRate = new FeeRate(Money.Satoshis(50), 1);
            }
            catch { Dispose(); throw; }
        }
コード例 #5
0
        public TumblerServerTester(string directory)
        {
            var rootTestData = "TestData";

            directory  = rootTestData + "/" + directory;
            _Directory = directory;
            if (!Directory.Exists(rootTestData))
            {
                Directory.CreateDirectory(rootTestData);
            }

            if (!TryDelete(directory, false))
            {
                foreach (var process in Process.GetProcessesByName("bitcoind"))
                {
                    if (process.MainModule.FileName.Replace("\\", "/").StartsWith(Path.GetFullPath(rootTestData).Replace("\\", "/"), StringComparison.Ordinal))
                    {
                        process.Kill();
                        process.WaitForExit();
                    }
                }
                TryDelete(directory, true);
            }

            _NodeBuilder = NodeBuilder.Create(directory);
            _TumblerNode = _NodeBuilder.CreateNode(false);
            _AliceNode   = _NodeBuilder.CreateNode(false);
            _BobNode     = _NodeBuilder.CreateNode(false);

            Directory.CreateDirectory(directory);

            _NodeBuilder.StartAll();

            SyncNodes();

            var rpc = _TumblerNode.CreateRPCClient();

            var conf = new TumblerConfiguration();

            conf.DataDir    = directory;
            conf.Network    = Network.RegTest;
            conf.RPCClient  = rpc;
            conf.TumblerKey = TestKeys.Default;
            conf.VoucherKey = TestKeys.Default2;
            conf.ClassicTumblerParameters.FakePuzzleCount                /= 4;
            conf.ClassicTumblerParameters.FakeTransactionCount           /= 4;
            conf.ClassicTumblerParameters.RealTransactionCount           /= 4;
            conf.ClassicTumblerParameters.RealPuzzleCount                /= 4;
            conf.ClassicTumblerParameters.CycleGenerator.FirstCycle.Start = 105;

            _Host = new WebHostBuilder()
                    .UseKestrel()
                    .UseAppConfiguration(conf)
                    .UseContentRoot(Path.GetFullPath(directory))
                    .UseIISIntegration()
                    .UseStartup <Startup>()
                    .Build();

            _Host.Start();

            ServerContext = new TumblerServerContext(_Host);
            var repo = new Client.Tumbler.Services.DBreezeRepository(Path.Combine(directory, "client"));

            ClientContext = new TumblerClientContext(CreateTumblerClient(), AliceNode.CreateRPCClient(), repo);
        }
コード例 #6
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());
                }
            }
        }
コード例 #7
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());
                }
            }
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: stepkillah/BreezeProject
        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());
                }
            }
        }
コード例 #9
0
 public TorRegisterJob(TumblerConfiguration conf, TumblerRuntime runtime)
 {
     this.conf    = conf;
     this.runtime = runtime;
 }
コード例 #10
0
        public TumblerServerTester(string directory)
        {
            try
            {
                var rootTestData = "TestData";
                directory  = rootTestData + "/" + directory;
                _Directory = directory;
                if (!Directory.Exists(rootTestData))
                {
                    Directory.CreateDirectory(rootTestData);
                }

                if (!TryDelete(directory, false))
                {
                    foreach (var process in Process.GetProcessesByName("bitcoind"))
                    {
                        if (process.MainModule.FileName.Replace("\\", "/").StartsWith(Path.GetFullPath(rootTestData).Replace("\\", "/"), StringComparison.Ordinal))
                        {
                            process.Kill();
                            process.WaitForExit();
                        }
                    }
                    TryDelete(directory, true);
                }

                _NodeBuilder = NodeBuilder.Create(directory);
                _TumblerNode = _NodeBuilder.CreateNode(false);
                _AliceNode   = _NodeBuilder.CreateNode(false);
                _BobNode     = _NodeBuilder.CreateNode(false);

                Directory.CreateDirectory(directory);

                _NodeBuilder.StartAll();

                SyncNodes();

                var conf = new TumblerConfiguration();
                conf.DataDir = Path.Combine(directory, "server");
                Directory.CreateDirectory(conf.DataDir);
                File.WriteAllBytes(Path.Combine(conf.DataDir, "Tumbler.pem"), TestKeys.Default.ToBytes());
                File.WriteAllBytes(Path.Combine(conf.DataDir, "Voucher.pem"), TestKeys.Default2.ToBytes());
                conf.RPC.Url = TumblerNode.CreateRPCClient().Address;
                var creds = ExtractCredentials(File.ReadAllText(_TumblerNode.Config));
                conf.RPC.User     = creds.Item1;
                conf.RPC.Password = creds.Item2;
                conf.Network      = Network.RegTest;
                conf.Listen.Add(new System.Net.IPEndPoint(IPAddress.Parse("127.0.0.1"), 5000));
                conf.ClassicTumblerParameters.FakePuzzleCount                /= 4;
                conf.ClassicTumblerParameters.FakeTransactionCount           /= 4;
                conf.ClassicTumblerParameters.RealTransactionCount           /= 4;
                conf.ClassicTumblerParameters.RealPuzzleCount                /= 4;
                conf.ClassicTumblerParameters.CycleGenerator.FirstCycle.Start = 105;

                var runtime = TumblerRuntime.FromConfiguration(conf, new AcceptAllClientInteraction());
                _Host = new WebHostBuilder()
                        .UseKestrel()
                        .UseAppConfiguration(runtime)
                        .UseContentRoot(Path.GetFullPath(directory))
                        .UseStartup <Startup>()
                        .UseUrls(conf.GetUrls())
                        .Build();

                _Host.Start();
                ServerRuntime = runtime;

                //Overrides server fee
                ((RPCFeeService)runtime.Services.FeeService).FallBackFeeRate = new FeeRate(Money.Satoshis(100), 1);


                var clientConfig = new TumblerClientConfiguration();
                clientConfig.DataDir       = Path.Combine(directory, "client");
                clientConfig.AllowInsecure = true;
                Directory.CreateDirectory(clientConfig.DataDir);
                clientConfig.Network = conf.Network;
                clientConfig.CheckIp = false;
                clientConfig.OutputWallet.KeyPath = new KeyPath("0");
                clientConfig.OutputWallet.RootKey = new ExtKey().Neuter().GetWif(conf.Network);
                clientConfig.RPCArgs.Url          = AliceNode.CreateRPCClient().Address;
                creds = ExtractCredentials(File.ReadAllText(AliceNode.Config));
                clientConfig.RPCArgs.User     = creds.Item1;
                clientConfig.RPCArgs.Password = creds.Item2;
                clientConfig.TumblerServer    = Address;

                ClientRuntime = TumblerClientRuntime.FromConfiguration(clientConfig, new AcceptAllClientInteraction());

                //Overrides client fee
                ((RPCFeeService)ClientRuntime.Services.FeeService).FallBackFeeRate = new FeeRate(Money.Satoshis(50), 1);
            }
            catch { Dispose(); throw; }
        }
コード例 #11
0
        public void StartTumbler(bool testnet)
        {
            Logs.Configure(new NTumbleBit.Logging.FuncLoggerFactory(i => new ConsoleLogger(i, (a, b) => true, false)));

            string[] args;

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

            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);
                    IWebHost host = null;
                    if (!config.OnlyMonitor)
                    {
                        host = new WebHostBuilder()
                               .UseKestrel()
                               .UseAppConfiguration(runtime)
                               .UseContentRoot(Directory.GetCurrentDirectory())
                               .UseStartup <Startup>()
                               .UseUrls(config.GetUrls())
                               .Build();
                    }

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

                    if (!config.OnlyMonitor)
                    {
                        new Thread(() =>
                        {
                            try
                            {
                                host.Run(interactive.MixingCancellationToken);
                            }
                            catch (Exception ex)
                            {
                                if (!interactive.MixingCancellationToken.IsCancellationRequested)
                                {
                                    Logs.Tumbler.LogCritical(1, ex, "Error while starting the host");
                                }
                            }
                            if (interactive.MixingCancellationToken.IsCancellationRequested)
                            {
                                Logs.Tumbler.LogInformation("Server stopped");
                            }
                        }).Start();
                    }
                    interactive.StartInteractive();
                }
                catch (ConfigException ex)
                {
                    if (!string.IsNullOrEmpty(ex.Message))
                    {
                        Logs.Configuration.LogError(ex.Message);
                    }
                }
                catch (Exception exception)
                {
                    Logs.Tumbler.LogError("Exception thrown while running the server");
                    Logs.Tumbler.LogError(exception.ToString());
                }
            }
        }
    }
コード例 #12
0
ファイル: TumblerService.cs プロジェクト: w1r2p1/BreezeServer
        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());
                }
            }
        }
    }
コード例 #13
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());
                }
            }
        }