public void MergeInto(TextFileConfiguration destination) { foreach (var kv in _Args) { foreach (var v in kv.Value) { destination.Add(kv.Key, v); } } }
public BreezeConfiguration(string configPath, string datadir = null) { try { if (!File.Exists(configPath)) { StringBuilder builder = new StringBuilder(); builder.AppendLine("# Breeze TumbleBit daemon settings"); builder.AppendLine("#network=testnet"); builder.AppendLine("#tor.enabled="); builder.AppendLine("#rpc.user="******"#rpc.password="******"#rpc.url=http://127.0.0.1:16174"); builder.AppendLine("#breeze.ipv4="); builder.AppendLine("#breeze.ipv6="); builder.AppendLine("#breeze.onion="); builder.AppendLine("#breeze.port="); builder.AppendLine("# Value of each registration transaction output (in satoshi)"); builder.AppendLine("#breeze.regtxoutputvalue="); builder.AppendLine("# Value of registration transaction fee (in satoshi)"); builder.AppendLine("#breeze.regtxfeevalue="); builder.AppendLine("#tumbler.url="); builder.AppendLine("#tumbler.rsakeyfile="); builder.AppendLine("#tumbler.ecdsakeyaddress="); File.WriteAllText(configPath, builder.ToString()); Console.WriteLine("*** Default blank configuration file created, please set configuration values and restart ***"); Environment.Exit(0); } var configFile = TextFileConfiguration.Parse(File.ReadAllText(configPath)); if (configFile.GetOrDefault <string>("network", "testnet").Equals("testnet")) { TumblerNetwork = Network.TestNet; } if (configFile.GetOrDefault <string>("tor.enabled", "true").Equals("true")) { UseTor = true; } if (configFile.GetOrDefault <string>("network", "testnet").Equals("regtest")) { TumblerNetwork = Network.RegTest; } if (configFile.GetOrDefault <string>("network", "testnet").Equals("main")) { TumblerNetwork = Network.Main; } RpcUser = configFile.GetOrDefault <string>("rpc.user", null); RpcPassword = configFile.GetOrDefault <string>("rpc.password", null); RpcUrl = configFile.GetOrDefault <string>("rpc.url", null); if (RpcUser == null || RpcPassword == null || RpcUrl == null) { throw new Exception("ERROR: RPC information in config file is invalid"); } try { // Assume that if it parses it's valid string defaultAddress = this.UseTor ? null : NTumbleBit.Utils.GetInternetConnectedAddress().ToString(); Ipv4Address = IPAddress.Parse(configFile.GetOrDefault <string>("breeze.ipv4", defaultAddress)); } catch (Exception) { Ipv4Address = null; } try { // Assume that if it parses it's valid Ipv6Address = IPAddress.Parse(configFile.GetOrDefault <string>("breeze.ipv6", null)); } catch (Exception) { Ipv6Address = null; } try { OnionAddress = configFile.GetOrDefault <string>("breeze.onion", null); if (OnionAddress.Length > 16) { // Regard as invalid, do not try to truncate etc. OnionAddress = null; } } catch (Exception) { OnionAddress = null; } //if (Ipv4Address == null && Ipv6Address == null && OnionAddress == null) //{ // throw new Exception("ERROR: No valid IP/onion addresses in configuration"); //} Port = configFile.GetOrDefault <int>("breeze.port", 37123); TumblerApiBaseUrl = configFile.GetOrDefault <string>("tumbler.url", null); // Use user keyfile; default new key if invalid string bitcoinNetwork; if (TumblerNetwork == Network.Main) { bitcoinNetwork = "MainNet"; } else if (TumblerNetwork == Network.RegTest) { bitcoinNetwork = "RegTest"; } else // TumblerNetwork == Network.TestNet { bitcoinNetwork = "TestNet"; } if (datadir == null) { // Create default directory for key files if it does not already exist Directory.CreateDirectory(Path.Combine(GetDefaultDataDir("NTumbleBitServer"), bitcoinNetwork)); TumblerRsaKeyFile = configFile.GetOrDefault <string>("tumbler.rsakeyfile", Path.Combine(GetDefaultDataDir("NTumbleBitServer"), bitcoinNetwork, "Tumbler.pem")); } else { Directory.CreateDirectory(Path.Combine(datadir, bitcoinNetwork)); TumblerRsaKeyFile = configFile.GetOrDefault <string>("tumbler.rsakeyfile", Path.Combine(datadir, bitcoinNetwork, "Tumbler.pem")); } TumblerRsaKeyFile = BreezeConfigurationValidator.ValidateTumblerRsaKeyFile( TumblerRsaKeyFile, TumblerRsaKeyFile ); TumblerEcdsaKeyAddress = configFile.GetOrDefault <string>("tumbler.ecdsakeyaddress", null); TxOutputValueSetting = new Money(configFile.GetOrDefault <int>("breeze.regtxoutputvalue", 1000), MoneyUnit.Satoshi); TxFeeValueSetting = new Money(configFile.GetOrDefault <int>("breeze.regtxfeevalue", 10000), MoneyUnit.Satoshi); } catch (Exception e) { throw new Exception("ERROR: Unable to read configuration. " + e); } }
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()); } } } }
public BreezeConfiguration(string configPath) { try { if (!File.Exists(configPath)) { StringBuilder builder = new StringBuilder(); builder.AppendLine("# Stratis TumbleBit daemon settings"); builder.AppendLine("#rpc.user="******"#rpc.password="******"#rpc.url=http://127.0.0.1:16174"); builder.AppendLine("#breeze.ipv4="); builder.AppendLine("#breeze.ipv6="); builder.AppendLine("#breeze.onion="); builder.AppendLine("#breeze.port="); builder.AppendLine("# Value of each registration transaction output (in satoshi)"); builder.AppendLine("#breeze.regtxoutputvalue="); builder.AppendLine("# Value of registration transaction fee (in satoshi)"); builder.AppendLine("#breeze.regtxfeevalue="); builder.AppendLine("#tumbler.url="); builder.AppendLine("#tumbler.rsakeypath="); builder.AppendLine("#tumbler.ecdsakeyaddress="); File.WriteAllText(configPath, builder.ToString()); Console.WriteLine("*** Default blank configuration file created, please set configuration values and restart ***"); Environment.Exit(0); } var configFile = TextFileConfiguration.Parse(File.ReadAllText(configPath)); IsTestNet = configFile.GetOrDefault <bool>("testnet", false); RpcUser = configFile.GetOrDefault <string>("rpc.user", null); RpcPassword = configFile.GetOrDefault <string>("rpc.password", null); RpcUrl = configFile.GetOrDefault <string>("rpc.url", null); if (RpcUser == null || RpcPassword == null || RpcUrl == null) { throw new Exception("ERROR: RPC information in config file is invalid"); } try { // Assume that if it parses it's valid Ipv4Address = IPAddress.Parse(configFile.GetOrDefault <string>("breeze.ipv4", null)); } catch (Exception) { Ipv4Address = null; } try { // Assume that if it parses it's valid Ipv6Address = IPAddress.Parse(configFile.GetOrDefault <string>("breeze.ipv6", null)); } catch (Exception) { Ipv6Address = null; } try { OnionAddress = configFile.GetOrDefault <string>("breeze.onion", null); if (OnionAddress.Length > 16) { // Regard as invalid, do not try to truncate etc. OnionAddress = null; } } catch (Exception) { OnionAddress = null; } if (Ipv4Address == null && Ipv6Address == null && OnionAddress == null) { throw new Exception("ERROR: No valid IP/onion addresses in configuration"); } Port = configFile.GetOrDefault <int>("breeze.port", 37123); TumblerApiBaseUrl = configFile.GetOrDefault <string>("tumbler.url", null); TumblerRsaKeyPath = configFile.GetOrDefault <string>("tumbler.rsakeypath", null); TumblerEcdsaKeyAddress = configFile.GetOrDefault <string>("tumbler.ecdsakeyaddress", null); TxOutputValueSetting = new Money(configFile.GetOrDefault <int>("breeze.regtxoutputvalue", 1000), MoneyUnit.Satoshi); TxFeeValueSetting = new Money(configFile.GetOrDefault <int>("breeze.regtxfeevalue", 10000), MoneyUnit.Satoshi); } catch (Exception e) { Console.WriteLine(e); throw new Exception("ERROR: Unable to read configuration"); } }