示例#1
0
        private async Task <IDnsQueryResponse> QueryAsync(DnsQuestion question, CancellationToken cancellationToken)
        {
            if (question == null)
            {
                throw new ArgumentNullException(nameof(question));
            }

            var head    = new DnsRequestHeader(GetNextUniqueId(), Recursion, DnsOpCode.Query);
            var request = new DnsRequestMessage(head, question);
            var handler = UseTcpOnly ? _tcpFallbackHandler : _messageHandler;

            if (_cache.Enabled)
            {
                var cacheKey = ResponseCache.GetCacheKey(question);
                var item     = _cache.Get(cacheKey);
                if (item == null)
                {
                    item = await ResolveQueryAsync(handler, request, cancellationToken).ConfigureAwait(false);

                    _cache.Add(cacheKey, item);
                }

                return(item);
            }
            else
            {
                return(await ResolveQueryAsync(handler, request, cancellationToken).ConfigureAwait(false));
            }
        }
示例#2
0
        private IDnsQueryResponse Query(DnsQuestion question)
        {
            if (question == null)
            {
                throw new ArgumentNullException(nameof(question));
            }

            var head    = new DnsRequestHeader(GetNextUniqueId(), Recursion, DnsOpCode.Query);
            var request = new DnsRequestMessage(head, question);
            var handler = UseTcpOnly ? _tcpFallbackHandler : _messageHandler;

            if (_cache.Enabled)
            {
                var cacheKey = ResponseCache.GetCacheKey(question);
                var item     = _cache.Get(cacheKey);
                if (item == null)
                {
                    item = ResolveQuery(handler, request);
                    _cache.Add(cacheKey, item);
                }

                return(item);
            }
            else
            {
                return(ResolveQuery(handler, request));
            }
        }
示例#3
0
        public DnsRequestMessage(DnsRequestHeader header, DnsQuestion question)
        {
            if (header == null)
            {
                throw new ArgumentNullException(nameof(header));
            }
            if (question == null)
            {
                throw new ArgumentNullException(nameof(question));
            }

            Header   = header;
            Question = question;
        }
示例#4
0
 public DnsRequestMessage(DnsRequestHeader header, DnsQuestion question, DnsQuerySettings dnsQuerySettings = null)
 {
     Header        = header ?? throw new ArgumentNullException(nameof(header));
     Question      = question ?? throw new ArgumentNullException(nameof(question));
     QuerySettings = dnsQuerySettings ?? new DnsQuerySettings(new DnsQueryOptions());
 }
 public DnsRequestMessage(DnsRequestHeader header, DnsQuestion question)
 {
     Header   = header ?? throw new ArgumentNullException(nameof(header));
     Question = question ?? throw new ArgumentNullException(nameof(question));
 }