Browse Source

[trac495] do store final answer in cache, but only if noerror

Jelte Jansen 14 years ago
parent
commit
6483bb374e
1 changed files with 8 additions and 5 deletions
  1. 8 5
      src/lib/resolve/recursive_query.cc

+ 8 - 5
src/lib/resolve/recursive_query.cc

@@ -184,6 +184,10 @@ private:
         if (cache_.lookup(question_.getName(), question_.getType(),
         if (cache_.lookup(question_.getName(), question_.getType(),
                           question_.getClass(), cached_message)) {
                           question_.getClass(), cached_message)) {
             dlog("Message found in cache, returning that");
             dlog("Message found in cache, returning that");
+            // Should these be set by the cache too?
+            cached_message.setOpcode(Opcode::QUERY());
+            cached_message.setRcode(Rcode::NOERROR());
+            cached_message.setHeaderFlag(Message::HEADERFLAG_QR);
             if (handleRecursiveAnswer(cached_message)) {
             if (handleRecursiveAnswer(cached_message)) {
                 callCallback(true);
                 callCallback(true);
                 stop();
                 stop();
@@ -261,11 +265,6 @@ private:
 
 
         bool found_ns_address = false;
         bool found_ns_address = false;
             
             
-        // If the packet is OK, store it in the cache
-        //if (!isc::resolve::ResponseClassifier::error(category)) {
-        //    cache_.update(incoming);
-        //}
-
         switch (category) {
         switch (category) {
         case isc::resolve::ResponseClassifier::ANSWER:
         case isc::resolve::ResponseClassifier::ANSWER:
         case isc::resolve::ResponseClassifier::ANSWERCNAME:
         case isc::resolve::ResponseClassifier::ANSWERCNAME:
@@ -358,6 +357,7 @@ private:
         case isc::resolve::ResponseClassifier::RCODE:
         case isc::resolve::ResponseClassifier::RCODE:
         case isc::resolve::ResponseClassifier::TRUNCATED:
         case isc::resolve::ResponseClassifier::TRUNCATED:
             dlog("Error in response, returning SERVFAIL");
             dlog("Error in response, returning SERVFAIL");
+            std::cout << "Error: " << category << std::endl;
             // Should we try a different server rather than SERVFAIL?
             // Should we try a different server rather than SERVFAIL?
             makeSERVFAIL();
             makeSERVFAIL();
             return true;
             return true;
@@ -467,6 +467,9 @@ public:
             // does mean that we overwrite the messages we stored in
             // does mean that we overwrite the messages we stored in
             // the previous iteration if we are following a delegation.
             // the previous iteration if we are following a delegation.
             if (success) {
             if (success) {
+                if (answer_message_->getRcode() == Rcode::NOERROR()) {
+                    cache_.update(*answer_message_);
+                }
                 resolvercallback_->success(answer_message_);
                 resolvercallback_->success(answer_message_);
             } else {
             } else {
                 resolvercallback_->failure();
                 resolvercallback_->failure();