public static async Task <TumblerClientRuntime> FromConfigurationAsync(TumblerClientConfigurationBase configuration, ClientInteraction interaction) { TumblerClientRuntime runtime = new TumblerClientRuntime(); try { await runtime.ConfigureAsync(configuration, interaction).ConfigureAwait(false); } catch { runtime.Dispose(); throw; } return(runtime); }
public static async Task <TumblerClientRuntime> FromConfigurationAsync(TumblerClientConfigurationBase configuration, ClientInteraction interaction = null, bool connectionTest = false) { TumblerClientRuntime runtime = new TumblerClientRuntime(); try { await runtime.ConfigureAsync(configuration, interaction, connectionTest).ConfigureAwait(false); } catch (Exception e) { Console.WriteLine("Exception during runtime configuration: " + e); runtime?.Dispose(); throw; } return(runtime); }
public async Task ConfigureAsync(TumblerClientConfigurationBase configuration, ClientInteraction interaction) { interaction = interaction ?? new AcceptAllClientInteraction(); Network = configuration.Network; TumblerServer = configuration.TumblerServer; BobSettings = configuration.BobConnectionSettings; AliceSettings = configuration.AliceConnectionSettings; AllowInsecure = configuration.AllowInsecure; if (this.TumblerServer.IsOnion) { await SetupTorAsync(interaction, configuration.TorPath).ConfigureAwait(false); } else if (configuration.TorMandatory) { throw new ConfigException("The tumbler server should use TOR"); } Cooperative = configuration.Cooperative; Repository = configuration.DBreezeRepository; _Disposables.Add(Repository); Tracker = configuration.Tracker; Services = configuration.Services; DestinationWallet = configuration.DestinationWallet; TumblerParameters = Repository.Get <ClassicTumbler.ClassicTumblerParameters>("Configuration", TumblerServer.ToString()); if (TumblerParameters != null && TumblerParameters.GetHash() != configuration.TumblerServer.ConfigurationHash) { TumblerParameters = null; } if (!configuration.OnlyMonitor) { var client = CreateTumblerClient(0); if (TumblerParameters == null) { Logs.Configuration.LogInformation("Downloading tumbler information of " + configuration.TumblerServer.ToString()); var parameters = Retry(3, () => client.GetTumblerParameters()); if (parameters == null) { throw new ConfigException("Unable to download tumbler's parameters"); } if (parameters.GetHash() != configuration.TumblerServer.ConfigurationHash) { throw new ConfigException("The tumbler returned an invalid configuration"); } var standardCycles = new StandardCycles(configuration.Network); var standardCycle = standardCycles.GetStandardCycle(parameters); if (parameters.ExpectedAddress != TumblerServer.GetRoutableUri(false).AbsoluteUri) { throw new ConfigException("This tumbler has parameters used for an unexpected uri"); } Logs.Configuration.LogInformation("Checking RSA key proof and standardness of the settings..."); if (standardCycle == null || !parameters.IsStandard()) { Logs.Configuration.LogWarning("This tumbler has non standard parameters"); if (!AllowInsecure) { throw new ConfigException("This tumbler has non standard parameters"); } standardCycle = null; } await interaction.ConfirmParametersAsync(parameters, standardCycle).ConfigureAwait(false); Repository.UpdateOrInsert("Configuration", TumblerServer.ToString(), parameters, (o, n) => n); TumblerParameters = parameters; Logs.Configuration.LogInformation("Tumbler parameters saved"); } Logs.Configuration.LogInformation($"Using tumbler {TumblerServer.ToString()}"); } }
public static TumblerClientRuntime FromConfiguration(TumblerClientConfigurationBase configuration, ClientInteraction interaction) { return(FromConfigurationAsync(configuration, interaction).GetAwaiter().GetResult()); }
public static TumblerClientRuntime FromConfiguration(TumblerClientConfigurationBase configuration, ClientInteraction interaction = null, bool connectionTest = false) { return(FromConfigurationAsync(configuration, interaction, connectionTest).GetAwaiter().GetResult()); }
public async Task ConfigureAsync(TumblerClientConfigurationBase configuration, ClientInteraction interaction = null, bool connectionTest = false) { interaction = interaction ?? new AcceptAllClientInteraction(); Network = configuration.Network;
public async Task ConfigureAsync(TumblerClientConfigurationBase configuration, TumblerProtocolType tumblerProtocol, ClientInteraction interaction = null, bool connectionTest = false) { interaction = interaction ?? new AcceptAllClientInteraction(); Network = configuration.Network; // if connectiontest then just test the connection, don't care about anything else // todo: refactor it in NTumbleBit for proper connectionTest, it's hacking if (connectionTest) { TumblerServer = configuration.TumblerServer; BobSettings = configuration.BobConnectionSettings; AliceSettings = configuration.AliceConnectionSettings; AllowInsecure = configuration.AllowInsecure; if (this.TumblerServer.IsOnion) { await SetupTorAsync(interaction, configuration.TorPath).ConfigureAwait(false); } else if (configuration.TorMandatory) { throw new ConfigException("The tumbler server should use TOR"); } var client = CreateTumblerClient(0, tumblerProtocol, connectTimeout: TimeSpan.FromSeconds(15)); TumblerParameters = Retry(1, () => client.GetTumblerParameters()); if (TumblerParameters == null) { throw new ConfigException("Unable to download tumbler's parameters"); } return; } Repository = configuration.DBreezeRepository; _Disposables.Add(Repository); Tracker = configuration.Tracker; Services = configuration.Services; if (!configuration.OnlyMonitor) { DataDir = configuration.DataDir; TumblerServer = configuration.TumblerServer; BobSettings = configuration.BobConnectionSettings; AliceSettings = configuration.AliceConnectionSettings; AllowInsecure = configuration.AllowInsecure; if (this.TumblerServer.IsOnion) { await SetupTorAsync(interaction, configuration.TorPath).ConfigureAwait(false); } else if (configuration.TorMandatory) { throw new ConfigException("The tumbler server should use TOR"); } Cooperative = configuration.Cooperative; DestinationWallet = configuration.DestinationWallet; try { TumblerParameters = Repository.Get <ClassicTumblerParameters>("Configuration", configuration.TumblerServer.ToString()); } catch { TumblerParameters = null; } if (TumblerParameters != null && TumblerParameters.GetHash() != configuration.TumblerServer.ConfigurationHash) { TumblerParameters = null; } var client = CreateTumblerClient(0, tumblerProtocol); Logs.Configuration.LogInformation("Downloading tumbler information of " + configuration.TumblerServer.ToString()); var parameters = Retry(3, () => client.GetTumblerParameters()); if (parameters == null) { throw new ConfigException("Unable to download tumbler's parameters"); } if (parameters.GetHash() != configuration.TumblerServer.ConfigurationHash) { throw new ConfigException("The tumbler returned an invalid configuration"); } var standardCycles = new StandardCycles(configuration.Network); var standardCycle = standardCycles.GetStandardCycle(parameters); if (parameters.ExpectedAddress != TumblerServer.GetRoutableUri(false).AbsoluteUri) { throw new ConfigException("This tumbler has parameters used for an unexpected uri"); } Logs.Configuration.LogInformation("Checking RSA key proof and standardness of the settings..."); try { if (standardCycle == null || !parameters.IsStandard()) { Logs.Configuration.LogWarning("This tumbler has non standard parameters"); if (!AllowInsecure) { throw new ConfigException("This tumbler has non standard parameters"); } standardCycle = null; } } catch (Exception e) { Console.WriteLine("Exception checking tumbler parameters: " + e); } await interaction.ConfirmParametersAsync(parameters, standardCycle).ConfigureAwait(false); if (TumblerParameters == null) { Repository.UpdateOrInsert("Configuration", TumblerServer.ToString(), parameters, (o, n) => n); TumblerParameters = parameters; Logs.Configuration.LogInformation("Tumbler parameters saved"); } Logs.Configuration.LogInformation($"Using tumbler {TumblerServer.ToString()}"); } }