Example #1
0
        public virtual void start()
        {
            // According to draft-cheshire-dnsext-multicastdns.txt
            // chapter "8 Responding":
            // We respond immediately if we know for sure, that we are
            // the only one who can respond to the query.
            // In all other cases, we respond within 20-120 ms.
            //
            // According to draft-cheshire-dnsext-multicastdns.txt
            // chapter "7.2 Multi-Packet Known Answer Suppression":
            // We respond after 20-120 ms if the query is truncated.

            bool iAmTheOnlyOne = true;

            foreach (DNSEntry entry in in_Renamed.questions)
            {
                if (entry is DNSQuestion)
                {
                    DNSQuestion q = (DNSQuestion)entry;
                    logger.Debug("start() question=" + q);
                    iAmTheOnlyOne &= (q.type == DNSConstants.TYPE_SRV || q.type == DNSConstants.TYPE_TXT || q.type == DNSConstants.TYPE_A || q.type == DNSConstants.TYPE_AAAA || Enclosing_Instance.localHost.Name.ToUpper().Equals(q.name.ToUpper()) || Enclosing_Instance.services.Contains(q.name.ToLower()));
                    if (!iAmTheOnlyOne)
                    {
                        break;
                    }
                }
            }
            int delay = (iAmTheOnlyOne && !in_Renamed.Truncated)?0:DNSConstants.RESPONSE_MIN_WAIT_INTERVAL + random.Next(DNSConstants.RESPONSE_MAX_WAIT_INTERVAL - DNSConstants.RESPONSE_MIN_WAIT_INTERVAL + 1) - in_Renamed.ElapsedSinceArrival();

            if (delay < 0)
            {
                delay = 0;
            }
            logger.Debug("start() Responder chosen delay=" + delay);
            // TODO: check this
            Enclosing_Instance.Timer = new Timer(new TimerCallback(this.Run), null, delay, 0);
        }