internal void LoadArgs(string[] args) { ConfigurationFile = args.Where(a => a.StartsWith("-conf=", StringComparison.Ordinal)).Select(a => a.Substring("-conf=".Length).Replace("\"", "")).FirstOrDefault(); DataDir = args.Where(a => a.StartsWith("-datadir=", StringComparison.Ordinal)).Select(a => a.Substring("-datadir=".Length).Replace("\"", "")).FirstOrDefault(); if (DataDir != null && ConfigurationFile != null) { var isRelativePath = Path.GetFullPath(ConfigurationFile).Length > ConfigurationFile.Length; if (isRelativePath) { ConfigurationFile = Path.Combine(DataDir, ConfigurationFile); } } if (ConfigurationFile != null) { AssetConfigFileExists(); } if (DataDir == null) { DataDir = DefaultDataDirectory.GetDefaultDirectory("XSwap"); } if (ConfigurationFile == null) { ConfigurationFile = GetDefaultConfigurationFile(DataDir); } Logs.Configuration.LogInformation("Data directory set to " + DataDir); Logs.Configuration.LogInformation("Configuration file set to " + ConfigurationFile); if (!Directory.Exists(DataDir)) { throw new ConfigException("Data directory does not exists"); } var consoleConfig = new TextFileConfiguration(args); var config = TextFileConfiguration.Parse(File.ReadAllText(ConfigurationFile)); consoleConfig.MergeInto(config, true); SupportedChains = KnownChains.Enumerate().Select(c => new SupportedChain(RPCArgs.Parse(config, c), c)).ToArray(); }
public TumblerConfiguration LoadArgs(String[] args) { ConfigurationFile = args.Where(a => a.StartsWith("-conf=", StringComparison.Ordinal)).Select(a => a.Substring("-conf=".Length).Replace("\"", "")).FirstOrDefault(); DataDir = args.Where(a => a.StartsWith("-datadir=", StringComparison.Ordinal)).Select(a => a.Substring("-datadir=".Length).Replace("\"", "")).FirstOrDefault(); if (DataDir != null && ConfigurationFile != null) { var isRelativePath = Path.GetFullPath(ConfigurationFile).Length > ConfigurationFile.Length; if (isRelativePath) { ConfigurationFile = Path.Combine(DataDir, ConfigurationFile); } } Network = args.Contains("-testnet", StringComparer.OrdinalIgnoreCase) ? Network.TestNet : args.Contains("-regtest", StringComparer.OrdinalIgnoreCase) ? Network.RegTest : Network.Main; if (ConfigurationFile != null) { AssetConfigFileExists(); var configTemp = TextFileConfiguration.Parse(File.ReadAllText(ConfigurationFile)); Network = configTemp.GetOrDefault <bool>("testnet", false) ? Network.TestNet : configTemp.GetOrDefault <bool>("regtest", false) ? Network.RegTest : Network.Main; } if (DataDir == null) { DataDir = DefaultDataDirectory.GetDefaultDirectory("NTumbleBitServer", Network); } if (ConfigurationFile == null) { ConfigurationFile = GetDefaultConfigurationFile(Network); } Logs.Configuration.LogInformation("Network: " + Network); Logs.Configuration.LogInformation("Data directory set to " + DataDir); Logs.Configuration.LogInformation("Configuration file set to " + ConfigurationFile); if (!Directory.Exists(DataDir)) { throw new ConfigurationException("Data directory does not exists"); } var consoleConfig = new TextFileConfiguration(args); var config = TextFileConfiguration.Parse(File.ReadAllText(ConfigurationFile)); consoleConfig.MergeInto(config, true); if (config.Contains("help")) { Console.WriteLine("Details on the wiki page : https://github.com/NTumbleBit/NTumbleBit/wiki/Server-Config"); OpenBrowser("https://github.com/NTumbleBit/NTumbleBit/wiki/Server-Config"); Environment.Exit(0); } var standardCycles = new StandardCycles(Network); var cycleName = "kotori"; //config.GetOrDefault<string>("cycle", standardCycles.Debug ? "shorty2x" : "shorty2x"); Logs.Configuration.LogInformation($"Using cycle {cycleName}"); var standardCycle = standardCycles.GetStandardCycle(cycleName); if (standardCycle == null) { throw new ConfigException($"Invalid cycle name, choose among {String.Join(",", standardCycles.ToEnumerable().Select(c => c.FriendlyName).ToArray())}"); } ClassicTumblerParameters.CycleGenerator = standardCycle.Generator; ClassicTumblerParameters.Denomination = standardCycle.Denomination; var torEnabled = config.GetOrDefault <bool>("tor.enabled", true); if (torEnabled) { TorSettings = TorConnectionSettings.ParseConnectionSettings("tor", config); } Cooperative = config.GetOrDefault <bool>("cooperative", true); var defaultPort = config.GetOrDefault <int>("port", 37123); OnlyMonitor = config.GetOrDefault <bool>("onlymonitor", false); string listenAddress = config.GetOrDefault <string>("listen", Utils.GetInternetConnectedAddress().ToString()); Listen = new IPEndPoint(IPAddress.Parse(listenAddress), defaultPort); RPC = RPCArgs.Parse(config, Network); TorPath = config.GetOrDefault <string>("torpath", "tor"); DBreezeRepository = new DBreezeRepository(Path.Combine(DataDir, "db2")); Tracker = new Tracker(DBreezeRepository, Network); // The worst case scenario is tumbler posting Puzzle which than fails and the tumbler has to get a refund. // This it(`T[Puzzle]`) 447B + (`T[Refund]` for (`T[Puzzle]`)) 651B = 1098B // Assuming the average transaction fee @ 50 sat / B we get: 1098B * 50 sat / B = 0.00054900 BTC just the network fees // For the denomination 0.1 BTC the 1 % fee would be 0.001 BTC // Combining the network fees with 1 % fees for 0.1 BTC denomination gives us 0.00054900 BTC + 0.001 BTC = 0.00154900 BTC ≈ 0.00155 BTC // The overall tumbler fee will work out to be 1.55 % of the denomination var defaultFee = new Money(0.00155m, MoneyUnit.BTC); ClassicTumblerParameters.Fee = config.GetOrDefault <Money>("tumbler.fee", defaultFee); TumblerProtocol = config.GetOrDefault <TumblerProtocolType>("tumbler.protocol", TumblerProtocolType.Tcp); RPCClient rpc = null; try { rpc = RPC.ConfigureRPCClient(Network); } catch { throw new ConfigException("Please, fix rpc settings in " + ConfigurationFile); } Services = ExternalServices.CreateFromRPCClient(rpc, DBreezeRepository, Tracker, true); return(this); }
public TumblerConfiguration LoadArgs(String[] args) { ConfigurationFile = args.Where(a => a.StartsWith("-conf=", StringComparison.Ordinal)).Select(a => a.Substring("-conf=".Length).Replace("\"", "")).FirstOrDefault(); DataDir = args.Where(a => a.StartsWith("-datadir=", StringComparison.Ordinal)).Select(a => a.Substring("-datadir=".Length).Replace("\"", "")).FirstOrDefault(); if (DataDir != null && ConfigurationFile != null) { var isRelativePath = Path.GetFullPath(ConfigurationFile).Length > ConfigurationFile.Length; if (isRelativePath) { ConfigurationFile = Path.Combine(DataDir, ConfigurationFile); } } Network = args.Contains("-testnet", StringComparer.OrdinalIgnoreCase) ? Network.TestNet : args.Contains("-regtest", StringComparer.OrdinalIgnoreCase) ? Network.RegTest : Network.Main; if (ConfigurationFile != null) { AssetConfigFileExists(); var configTemp = TextFileConfiguration.Parse(File.ReadAllText(ConfigurationFile)); Network = configTemp.GetOrDefault <bool>("testnet", false) ? Network.TestNet : configTemp.GetOrDefault <bool>("regtest", false) ? Network.RegTest : Network.Main; } if (DataDir == null) { DataDir = DefaultDataDirectory.GetDefaultDirectory("NTumbleBitServer", Network); } if (ConfigurationFile == null) { ConfigurationFile = GetDefaultConfigurationFile(); } Logs.Configuration.LogInformation("Network: " + Network); Logs.Configuration.LogInformation("Data directory set to " + DataDir); Logs.Configuration.LogInformation("Configuration file set to " + ConfigurationFile); if (!Directory.Exists(DataDir)) { throw new ConfigurationException("Data directory does not exists"); } var consoleConfig = new TextFileConfiguration(args); var config = TextFileConfiguration.Parse(File.ReadAllText(ConfigurationFile)); consoleConfig.MergeInto(config, true); if (config.Contains("help")) { Console.WriteLine("Details on the wiki page : https://github.com/NTumbleBit/NTumbleBit/wiki/Server-Config"); OpenBrowser("https://github.com/NTumbleBit/NTumbleBit/wiki/Server-Config"); Environment.Exit(0); } var standardCycles = new StandardCycles(Network); var cycleName = config.GetOrDefault <string>("cycle", standardCycles.Debug ? "shorty" : "kotori"); Logs.Configuration.LogInformation($"Using cycle {cycleName}"); ClassicTumblerParameters.CycleGenerator = standardCycles.GetStandardCycle(cycleName)?.Generator; if (ClassicTumblerParameters.CycleGenerator == null) { throw new ConfigException($"Invalid cycle name, choose among {String.Join(",", standardCycles.ToEnumerable().Select(c => c.FriendlyName).ToArray())}"); } var torEnabled = config.GetOrDefault <bool>("tor.enabled", true); if (torEnabled) { TorSettings = TorConnectionSettings.ParseConnectionSettings("tor", config); } Cooperative = config.GetOrDefault <bool>("cooperative", true); var defaultPort = config.GetOrDefault <int>("port", 37123); OnlyMonitor = config.GetOrDefault <bool>("onlymonitor", false); Listen = new IPEndPoint(IPAddress.Parse("127.0.0.1"), defaultPort); RPC = RPCArgs.Parse(config, Network); TorPath = config.GetOrDefault <string>("torpath", "tor"); DBreezeRepository = new DBreezeRepository(Path.Combine(DataDir, "db2")); Tracker = new Tracker(DBreezeRepository, Network); RPCClient rpc = null; try { rpc = RPC.ConfigureRPCClient(Network); } catch { throw new ConfigException("Please, fix rpc settings in " + ConfigurationFile); } Services = ExternalServices.CreateFromRPCClient(rpc, DBreezeRepository, Tracker); return(this); }
public TumblerConfiguration LoadArgs(String[] args) { ConfigurationFile = args.Where(a => a.StartsWith("-conf=", StringComparison.Ordinal)).Select(a => a.Substring("-conf=".Length).Replace("\"", "")).FirstOrDefault(); DataDir = args.Where(a => a.StartsWith("-datadir=", StringComparison.Ordinal)).Select(a => a.Substring("-datadir=".Length).Replace("\"", "")).FirstOrDefault(); if (DataDir != null && ConfigurationFile != null) { var isRelativePath = Path.GetFullPath(ConfigurationFile).Length > ConfigurationFile.Length; if (isRelativePath) { ConfigurationFile = Path.Combine(DataDir, ConfigurationFile); } } Network = args.Contains("-testnet", StringComparer.OrdinalIgnoreCase) ? Network.TestNet : args.Contains("-regtest", StringComparer.OrdinalIgnoreCase) ? Network.RegTest : Network.Main; if (ConfigurationFile != null) { AssetConfigFileExists(); var configTemp = TextFileConfiguration.Parse(File.ReadAllText(ConfigurationFile)); Network = configTemp.GetOrDefault <bool>("testnet", false) ? Network.TestNet : configTemp.GetOrDefault <bool>("regtest", false) ? Network.RegTest : Network.Main; } if (DataDir == null) { DataDir = DefaultDataDirectory.GetDefaultDirectory("NTumbleBitServer", Network); } if (ConfigurationFile == null) { ConfigurationFile = GetDefaultConfigurationFile(); } Logs.Configuration.LogInformation("Network: " + Network); if (Network == Network.TestNet) { var cycle = ClassicTumblerParameters .CycleGenerator.FirstCycle; cycle.Start = 0; cycle.RegistrationDuration = 3; cycle.ClientChannelEstablishmentDuration = 3; cycle.TumblerChannelEstablishmentDuration = 3; cycle.SafetyPeriodDuration = 2; cycle.PaymentPhaseDuration = 3; cycle.TumblerCashoutDuration = 4; cycle.ClientCashoutDuration = 3; } Logs.Configuration.LogInformation("Data directory set to " + DataDir); Logs.Configuration.LogInformation("Configuration file set to " + ConfigurationFile); if (!Directory.Exists(DataDir)) { throw new ConfigurationException("Data directory does not exists"); } var consoleConfig = new TextFileConfiguration(args); var config = TextFileConfiguration.Parse(File.ReadAllText(ConfigurationFile)); consoleConfig.MergeInto(config, true); if (config.Contains("help")) { Console.WriteLine("Details on the wiki page : https://github.com/NTumbleBit/NTumbleBit/wiki/Server-Config"); OpenBrowser("https://github.com/NTumbleBit/NTumbleBit/wiki/Server-Config"); Environment.Exit(0); } var defaultPort = config.GetOrDefault <int>("port", 5000); OnlyMonitor = config.GetOrDefault <bool>("onlymonitor", false); Listen = config .GetAll("bind") .Select(p => ConvertToEndpoint(p, defaultPort)) .ToList(); if (Listen.Count == 0) { Listen.Add(new IPEndPoint(IPAddress.Any, defaultPort)); } RPC = RPCArgs.Parse(config, Network); return(this); }
public TumblerClientConfiguration LoadArgs(String[] args) { ConfigurationFile = args.Where(a => a.StartsWith("-conf=", StringComparison.Ordinal)).Select(a => a.Substring("-conf=".Length).Replace("\"", "")).FirstOrDefault(); DataDir = args.Where(a => a.StartsWith("-datadir=", StringComparison.Ordinal)).Select(a => a.Substring("-datadir=".Length).Replace("\"", "")).FirstOrDefault(); if (DataDir != null && ConfigurationFile != null) { var isRelativePath = Path.GetFullPath(ConfigurationFile).Length > ConfigurationFile.Length; if (isRelativePath) { ConfigurationFile = Path.Combine(DataDir, ConfigurationFile); } } Network = args.Contains("-testnet", StringComparer.OrdinalIgnoreCase) ? Network.TestNet : args.Contains("-regtest", StringComparer.OrdinalIgnoreCase) ? Network.RegTest : null; if (ConfigurationFile != null) { AssetConfigFileExists(); var configTemp = TextFileConfiguration.Parse(File.ReadAllText(ConfigurationFile)); Network = Network ?? (configTemp.GetOrDefault <bool>("testnet", false) ? Network.TestNet : configTemp.GetOrDefault <bool>("regtest", false) ? Network.RegTest : null); } Network = Network ?? Network.Main; if (DataDir == null) { DataDir = DefaultDataDirectory.GetDefaultDirectory("NTumbleBit", Network); } if (ConfigurationFile == null) { ConfigurationFile = GetDefaultConfigurationFile(DataDir, Network); } Logs.Configuration.LogInformation("Network: " + Network); Logs.Configuration.LogInformation("Data directory set to " + DataDir); Logs.Configuration.LogInformation("Configuration file set to " + ConfigurationFile); if (!Directory.Exists(DataDir)) { throw new ConfigurationException("Data directory does not exists"); } var consoleConfig = new TextFileConfiguration(args); var config = TextFileConfiguration.Parse(File.ReadAllText(ConfigurationFile)); consoleConfig.MergeInto(config, true); config.AddAlias("server", "tumbler.server"); OnlyMonitor = config.GetOrDefault <bool>("onlymonitor", false); Cooperative = config.GetOrDefault <bool>("cooperative", true); TumblerServer = config.GetOrDefault("tumbler.server", null as TumblerUrlBuilder); TorPath = config.GetOrDefault <string>("torpath", "tor"); RPCArgs = RPCArgs.Parse(config, Network); if (!OnlyMonitor && TumblerServer == null) { throw new ConfigException("tumbler.server not configured"); } try { var key = config.GetOrDefault("outputwallet.extpubkey", null as string); if (key != null) { OutputWallet.RootKey = new BitcoinExtPubKey(key, Network); } } catch { throw new ConfigException("outputwallet.extpubkey is not configured correctly"); } OutputWallet.KeyPath = new KeyPath("0"); string keyPathString = config.GetOrDefault("outputwallet.keypath", null as string); if (keyPathString != null) { try { OutputWallet.KeyPath = new KeyPath(keyPathString); } catch { throw new ConfigException("outputwallet.keypath is not configured correctly"); } } if (OutputWallet.KeyPath.ToString().Contains("'")) { throw new ConfigException("outputwallet.keypath should not contain any hardened derivation"); } if (OutputWallet.RootKey != null && OutputWallet.RootKey.Network != Network) { throw new ConfigException("outputwallet.extpubkey is pointing an incorrect network"); } OutputWallet.RPCArgs = RPCArgs.Parse(config, Network, "outputwallet"); AliceConnectionSettings = ConnectionSettingsBase.ParseConnectionSettings("alice", config); BobConnectionSettings = ConnectionSettingsBase.ParseConnectionSettings("bob", config); AllowInsecure = config.GetOrDefault <bool>("allowinsecure", IsTest(Network)); return(this); }
private static void StartTumbler(string[] args) { Logs.Configure(new FuncLoggerFactory(i => new ConsoleLogger(i, (a, b) => true, false))); CancellationTokenSource broadcasterCancel = new CancellationTokenSource(); DBreezeRepository dbreeze = null; try { var network = args.Contains("-testnet", StringComparer.OrdinalIgnoreCase) ? Network.TestNet : args.Contains("-regtest", StringComparer.OrdinalIgnoreCase) ? Network.RegTest : Network.Main; Logs.Configuration.LogInformation("Network: " + network); var dataDir = DefaultDataDirectory.GetDefaultDirectory("NTumbleBit", network); var consoleArgs = new TextFileConfiguration(args); var configFile = GetDefaultConfigurationFile(dataDir, network); var config = TextFileConfiguration.Parse(File.ReadAllText(configFile)); consoleArgs.MergeInto(config, true); config.AddAlias("server", "tumbler.server"); var onlymonitor = config.GetOrDefault <bool>("onlymonitor", false); RPCClient rpc = null; try { rpc = RPCArgs.ConfigureRPCClient(config, network); } catch { throw new ConfigException("Please, fix rpc settings in " + configFile); } dbreeze = new DBreezeRepository(Path.Combine(dataDir, "db")); var services = ExternalServices.CreateFromRPCClient(rpc, dbreeze); var broadcaster = new BroadcasterJob(services, Logs.Main); broadcaster.Start(broadcasterCancel.Token); Logs.Main.LogInformation("BroadcasterJob started"); if (!onlymonitor) { var server = config.GetOrDefault("tumbler.server", null as Uri); if (server == null) { Logs.Main.LogError("tumbler.server not configured"); throw new ConfigException(); } var client = new TumblerClient(network, server); Logs.Configuration.LogInformation("Downloading tumbler information of " + server.AbsoluteUri); var parameters = Retry(3, () => client.GetTumblerParameters()); Logs.Configuration.LogInformation("Tumbler Server Connection successfull"); var existingConfig = dbreeze.Get <ClassicTumbler.ClassicTumblerParameters>("Configuration", client.Address.AbsoluteUri); if (existingConfig != null) { if (Serializer.ToString(existingConfig) != Serializer.ToString(parameters)) { Logs.Configuration.LogError("The configuration file of the tumbler changed since last connection, it should never happen"); throw new ConfigException(); } } else { dbreeze.UpdateOrInsert("Configuration", client.Address.AbsoluteUri, parameters, (o, n) => n); } if (parameters.Network != rpc.Network) { throw new ConfigException("The tumbler server run on a different network than the local rpc server"); } IDestinationWallet destinationWallet = null; try { destinationWallet = GetDestinationWallet(config, rpc.Network, dbreeze); } catch (Exception ex) { Logs.Main.LogInformation("outputwallet.extpubkey is not configured, trying to use outputwallet.rpc settings."); try { destinationWallet = GetRPCDestinationWallet(config, rpc.Network); } catch { throw ex; } //Not a bug, want to throw the other exception } var stateMachine = new StateMachinesExecutor(parameters, client, destinationWallet, services, dbreeze, Logs.Main); stateMachine.Start(broadcasterCancel.Token); Logs.Main.LogInformation("State machines started"); } Logs.Main.LogInformation("Press enter to stop"); Console.ReadLine(); broadcasterCancel.Cancel(); } catch (ConfigException ex) { if (!string.IsNullOrEmpty(ex.Message)) { Logs.Configuration.LogError(ex.Message); } } catch (Exception ex) { Logs.Configuration.LogError(ex.Message); Logs.Configuration.LogDebug(ex.StackTrace); } finally { if (!broadcasterCancel.IsCancellationRequested) { broadcasterCancel.Cancel(); } dbreeze?.Dispose(); } }
public TumblerConfiguration LoadArgs(NetworksSelector networkSet, String[] args) { ConfigurationFile = args.Where(a => a.StartsWith("-conf=", StringComparison.Ordinal)).Select(a => a.Substring("-conf=".Length).Replace("\"", "")).FirstOrDefault(); DataDir = args.Where(a => a.StartsWith("-datadir=", StringComparison.Ordinal)).Select(a => a.Substring("-datadir=".Length).Replace("\"", "")).FirstOrDefault(); if (DataDir != null && ConfigurationFile != null) { var isRelativePath = Path.GetFullPath(ConfigurationFile).Length > ConfigurationFile.Length; if (isRelativePath) { ConfigurationFile = Path.Combine(DataDir, ConfigurationFile); } } Network = args.Contains("-testnet", StringComparer.OrdinalIgnoreCase) ? networkSet.Testnet() : args.Contains("-regtest", StringComparer.OrdinalIgnoreCase) ? networkSet.Regtest() : networkSet.Mainnet(); if (ConfigurationFile != null) { AssetConfigFileExists(); var configTemp = TextFileConfiguration.Parse(File.ReadAllText(ConfigurationFile)); Network = configTemp.GetOrDefault <bool>("testnet", false) ? networkSet.Testnet() : configTemp.GetOrDefault <bool>("regtest", false) ? networkSet.Regtest() : networkSet.Mainnet(); } if (DataDir == null) { DataDir = DefaultDataDirectory.GetDefaultDirectory("NTumbleBitServer", Network); } if (ConfigurationFile == null) { ConfigurationFile = GetDefaultConfigurationFile(Network); } Logs.Configuration.LogInformation("Network: " + Network); Logs.Configuration.LogInformation("Data directory set to " + DataDir); Logs.Configuration.LogInformation("Configuration file set to " + ConfigurationFile); if (!Directory.Exists(DataDir)) { throw new ConfigurationException("Data directory does not exists"); } var consoleConfig = new TextFileConfiguration(args); var config = TextFileConfiguration.Parse(File.ReadAllText(ConfigurationFile)); consoleConfig.MergeInto(config, true); if (config.Contains("help")) { Console.WriteLine("Details on the wiki page : https://github.com/NTumbleBit/NTumbleBit/wiki/Server-Config"); OpenBrowser("https://github.com/NTumbleBit/NTumbleBit/wiki/Server-Config"); Environment.Exit(0); } var standardCycles = new StandardCycles(Network); var cycleName = config.GetOrDefault <string>("cycle", standardCycles.Debug ? "shorty2x" : "kotori"); Logs.Configuration.LogInformation($"Using cycle {cycleName}"); var standardCycle = standardCycles.GetStandardCycle(cycleName); if (standardCycle == null) { throw new ConfigException($"Invalid cycle name, choose among {String.Join(",", standardCycles.ToEnumerable().Select(c => c.FriendlyName).ToArray())}"); } ClassicTumblerParameters.CycleGenerator = standardCycle.Generator; ClassicTumblerParameters.Denomination = standardCycle.Denomination; var torEnabled = config.GetOrDefault <bool>("tor.enabled", true); if (torEnabled) { TorSettings = TorConnectionSettings.ParseConnectionSettings("tor", config); } Cooperative = config.GetOrDefault <bool>("cooperative", true); var defaultPort = config.GetOrDefault <int>("port", 37123); OnlyMonitor = config.GetOrDefault <bool>("onlymonitor", false); Listen = new IPEndPoint(IPAddress.Parse("127.0.0.1"), defaultPort); RPC = RPCArgs.Parse(config, Network); //0.1% fee by default var defaultFee = Money.Satoshis((decimal)ClassicTumblerParameters.Denomination.Satoshi * 0.001m); ClassicTumblerParameters.Fee = config.GetOrDefault <Money>("tumbler.fee", defaultFee); TorPath = config.GetOrDefault <string>("torpath", "tor"); return(this); }