/// <summary> /// Validates the instance. /// </summary> /// <param name="context">The validation context.</param> public void Validate(TrafficValidationContext context) { Timeouts = Timeouts ?? new TrafficTimeouts(); Resolvers = Resolvers ?? new List <TrafficResolver>(); BridgeTargetAddresses = BridgeTargetAddresses ?? new List <IPAddress>(); if (!Resolvers.Exists(r => r.Name == "docker")) { Resolvers.Add( new TrafficResolver() { Name = "docker", NameServers = new List <TrafficNameserver>() { new TrafficNameserver() { Name = "docker0", Endpoint = HiveConst.DockerDnsEndpoint } } }); } if (!NetHelper.IsValidPort(ProxyPorts.PortRange.FirstPort) || !NetHelper.IsValidPort(ProxyPorts.PortRange.LastPort) || ProxyPorts.PortRange.LastPort <= ProxyPorts.PortRange.FirstPort + 1) { context.Error($"Load balancer port block [{ProxyPorts.PortRange.FirstPort}-{ProxyPorts.PortRange.LastPort}] range is not valid."); } if (MaxConnections <= 0) { context.Error($"Load balancer settings [{nameof(MaxConnections)}={MaxConnections}] is not positive."); } Timeouts.Validate(context); if (!Resolvers.Exists(r => r.Name == "docker")) { context.Error($"Load balancer settings [{nameof(Resolvers)}] must include a [docker] definition."); } foreach (var resolver in Resolvers) { resolver.Validate(context); } if (BridgeTargetCount < 0) { context.Error($"Load balancer settings [{nameof(BridgeTargetCount)}={BridgeTargetCount}] cannot be negative."); } if (BridgeTargetCount == 0 && BridgeTargetAddresses.Count == 0) { context.Error($"Load balancer settings no bridge targets are specified."); } }
/// <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 void AddResolver(IResourceResolver resolver) { Resolvers.Add(resolver); }
/// <summary> /// Adds the resolver. /// </summary> /// <param name="type">Type.</param> /// <param name="resolver">Resolver.</param> internal void AddResolver(Type type, ContentResolver resolver) { resolver.Content = this; Resolvers.Add(type, resolver); }
public static void RegisterResolver(AN_APIResolver resolver) { Resolvers.Add(resolver); }