Beispiel #1
0
        private Response SearchInCache(Question question)
        {
            if (!m_UseCache)
                return null;

            string strKey = question.QClass + "-" + question.QType + "-" + question.QName;

            Response response = null;

            if (!m_ResponseCache.TryGetValue(strKey, out response))
                return null;

            int TimeLived = (int)((DateTime.Now.Ticks - response.TimeStamp.Ticks) / TimeSpan.TicksPerSecond);
            foreach (RR rr in response.RecordsRR)
            {
                rr.TimeLived = TimeLived;
                // The TTL property calculates its actual time to live
                if (rr.TTL == 0)
                    return null; // out of date
            }
            return response;
        }
Beispiel #2
0
 public void AddQuestion(Question question)
 {
     questions.Add(question);
 }
Beispiel #3
0
        /// <summary>
        /// Do an QClass=IN Query on specified DNS servers
        /// </summary>
        /// <param name="name">Name to query</param>
        /// <param name="qtype">Question type</param>
        /// <returns>Response of the query</returns>
        public Response Query(string name, QType qtype)
        {
            Question question = new Question(name, qtype, QClass.IN);
            Response response = SearchInCache(question);
            if (response != null)
                return response;

            Request request = new Request();
            request.AddQuestion(question);
            return GetResponse(request);
        }