/// <summary> /// Refresh the resolver list from the newest csv file. /// </summary> /// <exception cref="UnauthorizedAccessException"></exception> /// <exception cref="NotSupportedException"></exception> /// <exception cref="ArgumentOutOfRangeException"></exception> /// <exception cref="ArgumentException"></exception> /// <exception cref="ArgumentNullException"></exception> public async void RefreshResolverListAsync() { IsRefreshingResolverList = true; var state = await DnsCryptProxyListManager.UpdateResolverListAsync().ConfigureAwait(false); await Task.Run(() => { // we do this, to prevent excessive usage Thread.Sleep(2000); }).ConfigureAwait(false); if (state) { var proxyList = Path.Combine(Directory.GetCurrentDirectory(), Global.DnsCryptProxyFolder, Global.DnsCryptProxyResolverListName); var proxyListSignature = Path.Combine(Directory.GetCurrentDirectory(), Global.DnsCryptProxyFolder, Global.DnsCryptProxySignatureFileName); var dnsProxyList = DnsCryptProxyListManager.ReadProxyList(proxyList, proxyListSignature, _userData.UseIpv6); if (dnsProxyList != null && dnsProxyList.Any()) { Resolvers.Clear(); foreach (var dnsProxy in dnsProxyList) { if ( dnsProxy.ProviderPublicKey.Equals( PrimaryDnsCryptProxyManager.DnsCryptProxy.Parameter.ProviderKey)) { _primaryResolver = dnsProxy; // restore the local port _primaryResolver.LocalPort = PrimaryDnsCryptProxyManager.DnsCryptProxy.Parameter.LocalPort; } if ( dnsProxy.ProviderPublicKey.Equals( SecondaryDnsCryptProxyManager.DnsCryptProxy.Parameter.ProviderKey)) { _secondaryResolver = dnsProxy; } Resolvers.Add(dnsProxy); } } } else { _windowManager.ShowMetroMessageBox( LocalizationEx.GetUiString("dialog_message_refresh_failed", Thread.CurrentThread.CurrentCulture), LocalizationEx.GetUiString("dialog_warning_title", Thread.CurrentThread.CurrentCulture), MessageBoxButton.OK, BoxType.Warning); } IsRefreshingResolverList = false; }
public async Task DownloadResolverListTest() { var updated = await DnsCryptProxyListManager.UpdateResolverListAsync().ConfigureAwait(false); Assert.AreEqual(updated, true); Console.WriteLine(@"updated: " + updated); var dnsCryptProxyResolverListFile = Path.Combine(TestContext.CurrentContext.TestDirectory, Global.DnsCryptProxyFolder, Global.DnsCryptProxyResolverListName); var dnsCryptProxySignatureFile = Path.Combine(TestContext.CurrentContext.TestDirectory, Global.DnsCryptProxyFolder, Global.DnsCryptProxySignatureFileName); Assert.AreEqual(File.Exists(dnsCryptProxyResolverListFile), true); Assert.AreEqual(File.Exists(dnsCryptProxySignatureFile), true); Console.WriteLine(@"dnsCryptProxyResolverListFile: " + dnsCryptProxyResolverListFile); Console.WriteLine(@"dnsCryptProxySignatureFile: " + dnsCryptProxySignatureFile); var resolverList = DnsCryptProxyListManager.ReadProxyList(dnsCryptProxyResolverListFile, dnsCryptProxySignatureFile, true, true, true, false); Assert.Greater(resolverList.Count, 0); Console.WriteLine(@"resolverList.Count: " + resolverList.Count); }