示例#1
0
 /// <summary>
 /// Initialises a new instance of the <see cref="DnsCache2"/> class.
 /// </summary>
 public DnsCache2()
 {
     _createdOn       = DnsClock.Now();
     _nodes           = new Dictionary <DnsName, CacheNode>();
     _statisticsTimer = new Timer((o) => LogStatistics(), null,
                                  STAT_LOG_INTERVAL, STAT_LOG_INTERVAL);
 }
示例#2
0
        public void now_returns_system_time()
        {
            DateTime dnsNow = DnsClock.Now();
            DateTime sysNow = DateTime.UtcNow;

            Assert.AreApproximatelyEqual <DateTime, TimeSpan>(sysNow, dnsNow, TimeSpan.FromMilliseconds(1D));
        }
示例#3
0
 private void WriteStats(IPEndPoint responder, TimeSpan elapsed)
 {
     WriteLine("QUERY STATS:");
     WriteLine();
     WriteLine("Elapsed: {0:0.00}ms", elapsed.TotalMilliseconds);
     WriteLine("Server:  {0} ({1})", responder, ReverseIfEnabled(responder.Address));
     WriteLine("When:    {0:r}", DnsClock.Now());
     WriteLine();
 }
示例#4
0
        protected virtual Node GetNode(DnsName owner, Type type)
        {
            Node     head;
            Node     match = null;
            DateTime now   = DnsClock.Now();

            IncrementQuestions();
            lock (this.Nodes) {
                if (this.Nodes.TryGetValue(owner, out head))
                {
                    Node next;
                    Node cur = head;
                    // Descend the list and look for a node of the correct type.
                    do
                    {
                        next = cur.Next;
                        if (cur.IsAlive(now))
                        {
                            if (cur.Type == type)
                            {
                                Debug.Assert(match == null, "DnsCache::GetNode - duplicate node");
                                match = cur;
                                if (match != head)
                                {
                                    // Move to the head of the list.
                                    match.Remove();
                                    head.Previous     = match;
                                    match.Next        = head;
                                    this.Nodes[owner] = match;
                                }
                                // Even though we have found a match we still descend the list
                                // looking for dead nodes.
                            }
                        }
                        else
                        {
                            cur.Remove();
                        }
                    } while((cur = next) != null);
                }
            }
            if (match != null)
            {
                IncrementHits();
                return(match);
            }
            else
            {
                IncrementMisses();
                return(null);
            }
        }
示例#5
0
        public void now_returns_utc()
        {
            DateTime now = DnsClock.Now();

            Assert.AreEqual(DateTimeKind.Utc, now.Kind);
        }
示例#6
0
 /// <summary>
 /// Initialises a new instance of the DnsCache class.
 /// </summary>
 public DnsCache()
 {
     _createdOn = DnsClock.Now();
     _nodes     = new Dictionary <DnsName, Node>();
 }