public void SetConfig(CustomConnectionConfig config) { lock (_lockObject) { _config = config; } _watchTimer.Run(); }
public void SetOptions() { ConnectionConfig connectionConfig; { TcpConnectionConfig tcpConnectionConfig; { var info = this.ConnectionOptions.Tcp; var type = TcpConnectionType.None; if (info.Ipv4IsEnabled) { type |= TcpConnectionType.Ipv4; } if (info.Ipv6IsEnabled) { type |= TcpConnectionType.Ipv6; } tcpConnectionConfig = new TcpConnectionConfig(type, info.Ipv4Port, info.Ipv6Port, info.ProxyUri); } I2pConnectionConfig i2PConnectionConfig; { var info = this.ConnectionOptions.I2p; i2PConnectionConfig = new I2pConnectionConfig(info.IsEnabled, info.SamBridgeUri); } CustomConnectionConfig customConnectionConfig; { var info = this.ConnectionOptions.Custom; customConnectionConfig = new CustomConnectionConfig(info.LocationUris, info.ConnectionFilters, info.ListenUris); } CatharsisConfig catharsisConfig; { var catharsisIpv4Config = new CatharsisIpv4Config(null, null); catharsisConfig = new CatharsisConfig(catharsisIpv4Config); } connectionConfig = new ConnectionConfig(tcpConnectionConfig, i2PConnectionConfig, customConnectionConfig, catharsisConfig); } NetworkConfig networkConfig; { var info = this.ConnectionOptions.Bandwidth; networkConfig = new NetworkConfig(info.ConnectionCountLimit, info.BandwidthLimit); } lock (_serviceManager.LockObject) { var oldConfig = _serviceManager.Config; _serviceManager.SetConfig(new ServiceConfig(new CoreConfig(networkConfig, oldConfig.Core.Download), connectionConfig, oldConfig.Message)); } }
public void Load() { lock (_lockObject) { int version = _settings.Load("Version", () => 0); _config = _settings.Load <CustomConnectionConfig>("Config", () => { var connectionFilters = new List <ConnectionFilter>(); connectionFilters.Add(new ConnectionFilter("tcp", ConnectionType.None, "tcp:127.0.0.1:19050")); connectionFilters.Add(new ConnectionFilter("tor", ConnectionType.Socks5Proxy, "tcp:127.0.0.1:19050")); var listenUris = new List <string>(); listenUris.Add($"tcp:{IPAddress.Loopback}:4050"); listenUris.Add($"tcp:[{IPAddress.IPv6Loopback}]:4050"); return(new CustomConnectionConfig(Array.Empty <string>(), connectionFilters, listenUris)); }); } }
public static void SetOptions(OptionsInfo options, AmoebaInterfaceManager serviceManager, DialogService dialogService) { try { bool uploadFlag = false; App.Current.Dispatcher.Invoke(new Action(() => { // AccountInfo { var info = SettingsManager.Instance.AccountSetting; if (info.Agreement == null || info.DigitalSignature != options.Account.DigitalSignature) { info.Agreement = new Agreement(AgreementAlgorithm.EcDhP521_Sha256); uploadFlag = true; } else if (info.Comment != options.Account.Comment || !CollectionUtils.Equals(info.TrustSignatures, options.Account.TrustSignatures) || !CollectionUtils.Equals(info.UntrustSignatures, options.Account.UntrustSignatures) || !CollectionUtils.Equals(info.Tags, options.Account.Tags)) { uploadFlag = true; } info.DigitalSignature = options.Account.DigitalSignature; info.Comment = options.Account.Comment; info.TrustSignatures.Clear(); info.TrustSignatures.AddRange(options.Account.TrustSignatures); info.UntrustSignatures.Clear(); info.UntrustSignatures.AddRange(options.Account.UntrustSignatures); info.Tags.Clear(); info.Tags.AddRange(options.Account.Tags); } // UpdateInfo { var info = SettingsManager.Instance.UpdateSetting; info.IsEnabled = options.Update.IsEnabled; info.Signature = options.Update.Signature; } // SubscribeSignatures { SettingsManager.Instance.SubscribeSignatures.Clear(); SettingsManager.Instance.SubscribeSignatures.UnionWith(options.View.SubscribeSignatures); } })); if (uploadFlag) { var info = SettingsManager.Instance.AccountSetting; ProgressCircleService.Instance.Increment(); var task = serviceManager.SetProfile( new ProfileContent(info.Comment, null, info.TrustSignatures, info.UntrustSignatures, info.Tags, info.Agreement.GetAgreementPublicKey()), info.DigitalSignature, CancellationToken.None); task.ContinueWith((_) => { ProgressCircleService.Instance.Decrement(); }); } // AmoebaInterfaceManager { ServiceConfig serviceConfig; { ConnectionConfig connectionConfig; { TcpConnectionConfig tcpConnectionConfig; { var type = TcpConnectionType.None; if (options.Connection.Tcp.Ipv4IsEnabled) { type |= TcpConnectionType.Ipv4; } if (options.Connection.Tcp.Ipv6IsEnabled) { type |= TcpConnectionType.Ipv6; } tcpConnectionConfig = new TcpConnectionConfig( type, options.Connection.Tcp.Ipv4Port, options.Connection.Tcp.Ipv6Port, options.Connection.Tcp.ProxyUri); } I2pConnectionConfig i2PConnectionConfig; { i2PConnectionConfig = new I2pConnectionConfig( options.Connection.I2p.IsEnabled, options.Connection.I2p.SamBridgeUri); } CustomConnectionConfig customConnectionConfig; { customConnectionConfig = new CustomConnectionConfig( options.Connection.Custom.LocationUris, options.Connection.Custom.ConnectionFilters, options.Connection.Custom.ListenUris); } CatharsisConfig catharsisConfig; { var catharsisIpv4Config = new CatharsisIpv4Config(Array.Empty <string>(), Array.Empty <string>()); catharsisConfig = new CatharsisConfig(catharsisIpv4Config); } connectionConfig = new ConnectionConfig( tcpConnectionConfig, i2PConnectionConfig, customConnectionConfig, catharsisConfig); } CoreConfig coreConfig; { NetworkConfig networkConfig; { networkConfig = new NetworkConfig( options.Connection.Bandwidth.ConnectionCountLimit, options.Connection.Bandwidth.BandwidthLimit); } DownloadConfig downloadConfig; { downloadConfig = new DownloadConfig( options.Data.Download.DirectoryPath, options.Data.Download.ProtectedPercentage); } coreConfig = new CoreConfig(networkConfig, downloadConfig); } MessageConfig messageConfig; { messageConfig = new MessageConfig(options.View.SubscribeSignatures); } serviceConfig = new ServiceConfig(coreConfig, connectionConfig, messageConfig); } serviceManager.SetConfig(serviceConfig); } // AmoebaInterfaceManager (Resize) { long orginalCacheSize = serviceManager.Size; if (options.Data.Cache.Size < orginalCacheSize) { App.Current.Dispatcher.Invoke(new Action(() => { if (dialogService.ShowDialog(LanguagesManager.Instance.DataOptionsControl_CacheResize_Message, MessageBoxButton.OKCancel, MessageBoxImage.Question, MessageBoxResult.Cancel) == MessageBoxResult.OK) { Task.Run(() => { ProgressCircleService.Instance.Increment(); serviceManager.Resize(options.Data.Cache.Size); ProgressCircleService.Instance.Decrement(); }); } })); } else if (options.Data.Cache.Size > orginalCacheSize) { ProgressCircleService.Instance.Increment(); serviceManager.Resize(options.Data.Cache.Size); ProgressCircleService.Instance.Decrement(); } } } catch (Exception e) { Log.Error(e); } }