コード例 #1
0
        /// <summary>
        /// Sends the specified <see cref="AK.Net.Dns.DnsQuery"/> to the specified
        /// end point and return the <see cref="AK.Net.Dns.DnsReply"/>.
        /// </summary>
        /// <param name="query">The query to send.</param>
        /// <param name="endpoint">The transport end point.</param>
        /// <returns>
        /// The <see cref="AK.Net.Dns.DnsReply"/> to the <see cref="AK.Net.Dns.DnsQuery"/>.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when <paramref name="endpoint"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="AK.Net.Dns.DnsTransportException">
        /// Thrown when a transport error occurs.
        /// </exception>
        public override DnsReply Send(DnsQuery query, IPEndPoint endpoint)
        {
            Guard.NotNull(endpoint, "endpoint");

            DnsReply      reply     = null;
            IDnsTransport transport = SelectTransport(query);

            try {
                reply = transport.Send(query, endpoint);
            } catch (DnsTransportException exc) {
                // If the selected transport was TCP, we cannot fail over.
                // NOTE this comparison is not thread safe, but at worst it would mean
                // the query being sent again.
                if (transport == this.TcpTransport)
                {
                    throw;
                }
                this.Log.Warn("UDP transport failure, failing over to TCP:", exc);
            }

            if (reply != null)
            {
                if (!reply.Header.IsTruncated)
                {
                    return(reply);
                }
                this.Log.InfoFormat("message truncated, failing over to TCP, question={0}", query.Question);
            }

            return(this.TcpTransport.Send(query, endpoint));
        }
コード例 #2
0
ファイル: Resolver.cs プロジェクト: shekky/ManagedDnsQuery
 public Resolver(IDnsTransport transport, IQueryCache cache = null, IWhoisTransport wtransport = null, ITLDHandler tldHandler = null, ISpfChecker checker = null, int retrys = 3, int timeout = 60)
 {
     Transport      = transport;
     SpfChecker     = (checker ?? new SpfChecker());
     Retries        = retrys;
     TimeOut        = timeout;
     UseRecursion   = useRecursion;
     Cache          = (cache ?? new QueryCache());
     WhoisTransport = (wtransport ?? new WhoisTcpTransport());
     TldHandler     = (tldHandler ?? new TldHandler());
 }
コード例 #3
0
        /// <summary>
        /// Selects the best transport for the specified <paramref name="query"/>.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <returns>The best <see cref="AK.Net.Dns.IDnsTransport"/> for the specified
        /// <paramref name="query"/>.</returns>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when <paramref name="query"/> is <see langword="null"/>.
        /// </exception>
        protected virtual IDnsTransport SelectTransport(DnsQuery query)
        {
            Guard.NotNull(query, "query");

            IDnsTransport transport = this.UdpTransport;

            if (query.Questions.Count > 0)
            {
                // TODO does this code belong here?
                switch (query.Questions[0].Type)
                {
                case DnsQueryType.Axfr:
                    transport = this.TcpTransport;
                    break;

                default:
                    break;
                }
            }

            return(transport);
        }