Exemple #1
0
        void HandleRequest(IAsyncResult result)
        {
            try
            {
                using (Socket socket = m_listener.EndAcceptSocket(result))
                {
                    TestTCPClient client   = new TestTCPClient(socket); // Chunk sends
                    DnsRequest    request  = client.ReceiveRequest();
                    DnsResponse   response = null;
                    try
                    {
                        response = m_store.Get(request);
                        if (response == null)
                        {
                            response = new DnsResponse(request);
                            response.Header.ResponseCode = DnsStandard.ResponseCode.NameError;
                        }
                    }
                    catch
                    {
                        response = new DnsResponse(request);
                        response.Header.ResponseCode = DnsStandard.ResponseCode.NameError;
                    }

                    if (response != null)
                    {
                        client.Send(response);
                    }
                }
            }
            catch
            {
            }
        }
Exemple #2
0
        public DnsResponse Get(DnsRequest request)
        {
            long requestNumber = System.Threading.Interlocked.Increment(ref m_requestCount);

            if (this.SuccessInterval <= 0 || (requestNumber % this.SuccessInterval) != 0)
            {
                if (this.ThrowDnsException)
                {
                    throw new DnsServerException(ErrorCode);
                }

                throw new InvalidOperationException();
            }

            return(m_innerStore.Get(request));
        }
Exemple #3
0
        public DnsResponse ProcessRequest(DnsRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException();
            }

            this.Received.SafeInvoke(request);

            DnsResponse response = null;

            try
            {
                this.Validate(request);

                response = m_store.Get(request);
                if (response == null || !response.IsSuccess)
                {
                    throw new DnsServerException(DnsStandard.ResponseCode.NameError);
                }

                this.FixupTTL(response);
            }
            catch (DnsProtocolException)
            {
                response = this.ProcessError(request, DnsStandard.ResponseCode.FormatError);
            }
            catch (DnsServerException serverEx)
            {
                response = this.ProcessError(request, serverEx.ResponseCode);
            }
            catch (Exception ex)
            {
                this.HandleException(ex);
                response = this.ProcessError(request, DnsStandard.ResponseCode.ServerFailure);
            }

            this.Responding.SafeInvoke(response);

            return(response);
        }