/// <summary>
		///   Forces to update all hints using the given resolver
		/// </summary>
		/// <param name="resolver">The resolver to use for resolving the new hints</param>
		public void Update(IDnsResolver resolver)
		{
			Zone zone = new Zone(DomainName.Root);

			var nameServer = resolver.Resolve<NsRecord>(DomainName.Root, RecordType.Ns);
			zone.AddRange(nameServer);

			foreach (var nsRecord in nameServer)
			{
				zone.AddRange(resolver.Resolve<ARecord>(nsRecord.NameServer, RecordType.A));
				zone.AddRange(resolver.Resolve<AaaaRecord>(nsRecord.NameServer, RecordType.Aaaa));
			}

			zone.AddRange(resolver.Resolve<DnsKeyRecord>(DomainName.Root, RecordType.DnsKey).Where(x => x.IsSecureEntryPoint));

			LoadZoneInternal(zone);

			Save(zone);
		}
		/// <summary>
		///   Forces to update all hints using the given resolver
		/// </summary>
		/// <param name="resolver">The resolver to use for resolving the new hints</param>
		public void Update(IDnsResolver resolver)
		{
			Zone zone = new Zone(DomainName.Root);

			var nameServer = resolver.Resolve<NsRecord>(DomainName.Root, RecordType.Ns);
			zone.AddRange(nameServer);

			foreach (var nsRecord in nameServer)
			{
				zone.AddRange(resolver.Resolve<ARecord>(nsRecord.NameServer, RecordType.A));
				zone.AddRange(resolver.Resolve<AaaaRecord>(nsRecord.NameServer, RecordType.Aaaa));
			}

			zone.AddRange(resolver.Resolve<DnsKeyRecord>(DomainName.Root, RecordType.DnsKey).Where(x => x.IsSecureEntryPoint));

			LoadZoneInternal(zone);

			Save(zone);
		}
예제 #3
0
        /// <summary>
        ///   Queries a dns resolver for IP addresses of a host.
        /// </summary>
        /// <param name="resolver"> The resolver instance, that should be used for queries </param>
        /// <param name="name"> Host name, that should be queried </param>
        /// <returns> A list of matching host addresses </returns>
        public static List <IPAddress> ResolveHost(this IDnsResolver resolver, DomainName name)
        {
            List <IPAddress> result = new List <IPAddress>();

            List <AaaaRecord> aaaaRecords = resolver.Resolve <AaaaRecord>(name, RecordType.Aaaa);

            if (aaaaRecords != null)
            {
                result.AddRange(aaaaRecords.Select(x => x.Address));
            }

            List <ARecord> aRecords = resolver.Resolve <ARecord>(name);

            if (aRecords != null)
            {
                result.AddRange(aRecords.Select(x => x.Address));
            }

            return(result);
        }
예제 #4
0
        private async Task <List <ResolvedEndPoint> > ResolveAtLeastOneAndShuffle(IEnumerable <HostAndPort> unresolvedEndPoints, int spinDelay)
        {
            var unresolvedForLog = unresolvedEndPoints.ToCommaDelimited();

            if (FirstDnsTry)
            {
                FirstDnsTry = false;
            }
            else
            {
                m_Log.debug("Since we couldn't resolve any IPs yet, we sleep for a second before retying");
                await TaskEx.Delay(spinDelay).ConfigureAwait(false);
            }
            m_Log.debug($"Trying to resolve at least one IP from hosts:{{{unresolvedForLog}}}");
            var resolved = await m_DnsResolver.Resolve(unresolvedEndPoints).ConfigureAwait(false);

            if (!resolved.Any())
            {
                m_Log.debug($"Failed to resolve any IP from hosts:{{{unresolvedForLog}}}");
                throw new SocketException((int)SocketError.HostUnreachable);
            }
            return(Shuffle(resolved).ToList());
        }
예제 #5
0
 /// <summary>
 ///   Queries a dns resolver for specified records.
 /// </summary>
 /// <typeparam name="T"> Type of records, that should be returned </typeparam>
 /// <param name="resolver"> The resolver instance, that should be used for queries </param>
 /// <param name="name"> Domain, that should be queried </param>
 /// <param name="recordType"> Type the should be queried </param>
 /// <param name="recordClass"> Class the should be queried </param>
 /// <returns> A list of matching <see cref="DnsRecordBase">records</see> </returns>
 public static List <T> Resolve <T>(this IDnsResolver resolver, string name, RecordType recordType = RecordType.A, RecordClass recordClass = RecordClass.INet)
     where T : DnsRecordBase
 {
     return(resolver.Resolve <T>(DomainName.Parse(name), recordType, recordClass));
 }
예제 #6
0
        /// <summary>
        ///   Queries a dns resolver for reverse name of an IP address.
        /// </summary>
        /// <param name="resolver"> The resolver instance, that should be used for queries </param>
        /// <param name="address"> The address, that should be queried </param>
        /// <returns> The reverse name of the IP address </returns>
        public static DomainName ResolvePtr(this IDnsResolver resolver, IPAddress address)
        {
            List <PtrRecord> ptrRecords = resolver.Resolve <PtrRecord>(address.GetReverseLookupDomain(), RecordType.Ptr);

            return(ptrRecords.Select(x => x.PointerDomainName).FirstOrDefault());
        }
예제 #7
0
        private async Task <List <ResolvedEndPoint> > ResolveAndShuffle(IEnumerable <HostAndPort> unresolvedEndPoints)
        {
            var resolvedEndPoints = await m_DnsResolver.Resolve(unresolvedEndPoints).ConfigureAwait(false);

            return(resolvedEndPoints.OrderBy(i => Guid.NewGuid()).ToList());
        }