BIND 10 trac598, updated. 0194cb0aaf6c8137e0699b8166c746a0c8a6302c [trac598] Implement the simplest forwarder by refactoring the code.

BIND 10 source code commits bind10-changes at lists.isc.org
Fri Apr 8 09:11:49 UTC 2011


The branch, trac598 has been updated
       via  0194cb0aaf6c8137e0699b8166c746a0c8a6302c (commit)
      from  5e2c9a0bce13ee28a63bc1843494e88ddd02d36e (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 0194cb0aaf6c8137e0699b8166c746a0c8a6302c
Author: zhanglikun <zhanglikun at cnnic.cn>
Date:   Fri Apr 8 17:07:10 2011 +0800

    [trac598] Implement the simplest forwarder by refactoring the code.

-----------------------------------------------------------------------

Summary of changes:
 src/lib/asiolink/recursive_query.cc |   94 +++++++----------------------------
 1 files changed, 18 insertions(+), 76 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/asiolink/recursive_query.cc b/src/lib/asiolink/recursive_query.cc
index 55aec7a..8de3dc0 100644
--- a/src/lib/asiolink/recursive_query.cc
+++ b/src/lib/asiolink/recursive_query.cc
@@ -454,7 +454,7 @@ public:
     }
 };
 
-class ForwardQuery : public IOFetch::Callback {
+class UpstreamQuery : public IOFetch::Callback {
 private:
     // The io service to handle async calls
     IOService& io_;
@@ -480,28 +480,17 @@ private:
      */
     // Timeout information
     int query_timeout_;
-    unsigned retries_;
-
-    // normal query state
 
     // TODO: replace by our wrapper
     asio::deadline_timer client_timer;
     asio::deadline_timer lookup_timer;
 
-    size_t queries_out_;
-    
-    // If we timed out ourselves (lookup timeout), stop issuing queries
-    bool done_;
-
     // If we have a client timeout, we send back an answer, but don't
     // stop. We use this variable to make sure we don't send another
     // answer if we do find one later (or if we have a lookup_timeout)
     bool answer_sent_;
 
-    // Reference to our cache
-    isc::cache::ResolverCache& cache_;
-
-    // (re)send the query to the server.
+    // send the query to the server.
     void send() {
         const int uc = upstream_->size();
         buffer_->clear();
@@ -517,20 +506,17 @@ private:
             upstream_->at(serverIndex).second,
             buffer_, this, query_timeout_);
 
-        ++queries_out_;
         io_.get_io_service().post(query);
     }
 
 public:
-    ForwardQuery(IOService& io,
+    UpstreamQuery(IOService& io,
         ConstMessagePtr query_message,
         MessagePtr answer_message,
         boost::shared_ptr<AddressVector> upstream,
         OutputBufferPtr buffer,
         isc::resolve::ResolverInterface::CallbackPtr cb,
-        int query_timeout, int client_timeout, int lookup_timeout,
-        unsigned retries,
-        isc::cache::ResolverCache& cache) :
+        int query_timeout, int client_timeout, int lookup_timeout) :
         io_(io),
         query_message_(query_message),
         answer_message_(answer_message),
@@ -538,26 +524,22 @@ public:
         buffer_(buffer),
         resolvercallback_(cb),
         query_timeout_(query_timeout),
-        retries_(retries),
         client_timer(io.get_io_service()),
         lookup_timer(io.get_io_service()),
-        queries_out_(0),
-        done_(false),
-        answer_sent_(false),
-        cache_(cache)
+        answer_sent_(false)
     {
         // Setup the timer to stop trying (lookup_timeout)
         if (lookup_timeout >= 0) {
             lookup_timer.expires_from_now(
                 boost::posix_time::milliseconds(lookup_timeout));
-            lookup_timer.async_wait(boost::bind(&ForwardQuery::stop, this, false));
+            lookup_timer.async_wait(boost::bind(&UpstreamQuery::stop, this, false));
         }
 
         // Setup the timer to send an answer (client_timeout)
         if (client_timeout >= 0) {
             client_timer.expires_from_now(
                 boost::posix_time::milliseconds(client_timeout));
-            client_timer.async_wait(boost::bind(&ForwardQuery::clientTimeout, this));
+            client_timer.async_wait(boost::bind(&UpstreamQuery::clientTimeout, this));
         }
 
         send();
@@ -582,29 +564,8 @@ public:
         // here again.
         // same goes if we have an outstanding query (can't delete
         // until that one comes back to us)
-        done_ = true;
         if (resume && !answer_sent_) {
             answer_sent_ = true;
-
-            // There are two types of messages we could store in the
-            // cache;
-            // 1. answers to our fetches from authoritative servers,
-            //    exactly as we receive them, and
-            // 2. answers to queries we received from clients, which
-            //    have received additional processing (following CNAME
-            //    chains, for instance)
-            //
-            // Doing only the first would mean we would have to re-do
-            // processing when we get data from our cache, and doing
-            // only the second would miss out on the side-effect of
-            // having nameserver data in our cache.
-            //
-            // So right now we do both. Since the cache (currently)
-            // stores Messages on their question section only, this
-            // does mean that we overwrite the messages we stored in
-            // the previous iteration if we are following a delegation.
-            cache_.update(*answer_message_);
-
             resolvercallback_->success(answer_message_);
         } else {
             resolvercallback_->failure();
@@ -615,30 +576,22 @@ public:
         if (client_timer.cancel() != 0) {
             return;
         }
-        if (queries_out_ > 0) {
-            return;
-        }
+
         delete this;
     }
 
     // This function is used as callback from DNSQuery.
     virtual void operator()(IOFetch::Result result) {
         // XXX is this the place for TCP retry?
-        --queries_out_;
-        if (!done_ && result != IOFetch::TIME_OUT) {
+        if (result != IOFetch::TIME_OUT) {
             // we got an answer
             Message incoming(Message::PARSE);
             InputBuffer ibuf(buffer_->getData(), buffer_->getLength());
             incoming.fromWire(ibuf);
             isc::resolve::copyResponseMessage(incoming, answer_message_);
-            done_ = true;
             stop(true);
-        } else if (!done_ && retries_--) {
-            // We timed out, but we have some retries, so send again
-            dlog("Timeout, resending query");
-            send();
         } else {
-            // out of retries, give up for now
+            // timeout, give up for now
             stop(false);
         }
     }
@@ -732,25 +685,14 @@ RecursiveQuery::forward(ConstMessagePtr query_message,
     answer_message->setOpcode(isc::dns::Opcode::QUERY());
     ConstQuestionPtr question = *query_message->beginQuestion();
     answer_message->addQuestion(*question);
-    
-    // First try to see if we have something cached in the messagecache
-    dlog("Try out cache first (started by incoming event)");
-    if (cache_.lookup(question->getName(), question->getType(),
-                      question->getClass(), *answer_message)) {
-        dlog("Message found in cache, returning that");
-        // TODO: err, should cache set rcode as well?
-        answer_message->setRcode(Rcode::NOERROR());
-        crs->success(answer_message);
-    } else {
-        dlog("Message not found in cache, starting forward query");
-        // It will delete itself when it is done
-        new ForwardQuery(io, query_message, answer_message,
-                         upstream_, buffer, crs, query_timeout_,
-                         client_timeout_, lookup_timeout_,
-                         retries_, cache_);
-    }
-}
-
 
+    // implement the simplest forwarder, which will pass
+    // everything throught without interpretation, except
+    // QID, port number. The response will not be cached.
+    // It will delete itself when it is done
+    new UpstreamQuery(io, query_message, answer_message,
+                      upstream_, buffer, crs, query_timeout_,
+                      client_timeout_, lookup_timeout_);
+}
 
 } // namespace asiolink




More information about the bind10-changes mailing list