BIND 10 trac491, updated. 949f642c90ab8ad7f0f02c35e383b9eb9e65792a [trac491] added isc::resolve::initResponseMessage() functions
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Feb 17 09:33:02 UTC 2011
The branch, trac491 has been updated
via 949f642c90ab8ad7f0f02c35e383b9eb9e65792a (commit)
via f59af8201a12342a2779440a4c7afed1b51fef7f (commit)
from 4864018bdb5a6f3f9ea9d7a9cc608521655233dd (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 949f642c90ab8ad7f0f02c35e383b9eb9e65792a
Author: Jelte Jansen <jelte at isc.org>
Date: Thu Feb 17 10:31:09 2011 +0100
[trac491] added isc::resolve::initResponseMessage() functions
commit f59af8201a12342a2779440a4c7afed1b51fef7f
Author: Jelte Jansen <jelte at isc.org>
Date: Thu Feb 17 10:05:11 2011 +0100
[trac491] Also cache intermediate results
Added some extensive dlog() calls for testing while we are building this
-----------------------------------------------------------------------
Summary of changes:
src/bin/resolver/resolver.cc | 2 +
src/lib/asiolink/recursive_query.cc | 38 +++++++++++++++++++++++++---------
src/lib/cache/message_cache.cc | 4 ++-
src/lib/resolve/resolve.cc | 19 +++++++++++++++++
src/lib/resolve/resolve.h | 30 +++++++++++++++++++++++++++
5 files changed, 82 insertions(+), 11 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/bin/resolver/resolver.cc b/src/bin/resolver/resolver.cc
index c635fc9..74eddfd 100644
--- a/src/bin/resolver/resolver.cc
+++ b/src/bin/resolver/resolver.cc
@@ -182,6 +182,8 @@ public:
MessagePtr message_;
};
+
+// TODO: REMOVE, USE isc::resolve::MakeErrorMessage?
void
makeErrorMessage(MessagePtr message, OutputBufferPtr buffer,
const Rcode& rcode)
diff --git a/src/lib/asiolink/recursive_query.cc b/src/lib/asiolink/recursive_query.cc
index a5e3d79..72f8a67 100644
--- a/src/lib/asiolink/recursive_query.cc
+++ b/src/lib/asiolink/recursive_query.cc
@@ -138,6 +138,23 @@ private:
// Reference to our cache
isc::cache::ResolverCache& cache_;
+ // perform a single lookup; first we check the cache to see
+ // if we have a response for our query stored already. if
+ // so, call handlerecursiveresponse(), if not, we call send()
+ void doLookup() {
+ dlog("doLookup: try cache");
+ Message cached_message(Message::RENDER);
+ isc::resolve::initResponseMessage(question_, cached_message);
+ if (cache_.lookup(question_.getName(), question_.getType(),
+ question_.getClass(), cached_message)) {
+ dlog("Message found in cache, returning that");
+ handleRecursiveAnswer(cached_message);
+ } else {
+ send();
+ }
+
+ }
+
// (re)send the query to the server.
void send() {
const int uc = upstream_->size();
@@ -219,7 +236,7 @@ private:
question_.getType());
dlog("Following CNAME chain to " + question_.toText());
- send();
+ doLookup();
return false;
break;
case isc::resolve::ResponseClassifier::NXDOMAIN:
@@ -256,6 +273,10 @@ private:
}
if (found_ns_address) {
// next resolver round
+ // we do NOT use doLookup() here, but send() (i.e. we
+ // skip the cache), since if we had the final answer
+ // instead of a delegation cached, we would have been
+ // there by now.
send();
return false;
} else {
@@ -336,7 +357,7 @@ public:
setZoneServersToRoot();
}
- send();
+ doLookup();
}
void setZoneServersToRoot() {
@@ -374,11 +395,6 @@ public:
// until that one comes back to us)
done_ = true;
if (resume && !answer_sent_) {
- // Store the answer we found in our cache
- std::cout << "[XX] caching our answer:" << std::endl;
- std::cout << answer_message_->toText();
- cache_.update(*answer_message_);
- std::cout << "[XX] done caching our answer" << std::endl;
resolvercallback_->success(answer_message_);
} else {
resolvercallback_->failure();
@@ -405,6 +421,9 @@ public:
InputBuffer ibuf(buffer_->getData(), buffer_->getLength());
incoming.fromWire(ibuf);
+ // let's first dunk it into our cache
+ cache_.update(incoming);
+
if (upstream_->size() == 0 &&
incoming.getRcode() == Rcode::NOERROR()) {
done_ = handleRecursiveAnswer(incoming);
@@ -436,11 +455,10 @@ RecursiveQuery::resolve(const QuestionPtr& question,
asio::io_service& io = dns_service_.get_io_service();
MessagePtr answer_message(new Message(Message::RENDER));
+ isc::resolve::initResponseMessage(*question, *answer_message);
+
OutputBufferPtr buffer(new OutputBuffer(0));
- // TODO: general 'prepareinitialanswer'
- answer_message->setOpcode(isc::dns::Opcode::QUERY());
- answer_message->addQuestion(question);
dlog("Try out cache first (direct call to resolve)");
// First try to see if we have something cached in the messagecache
if (cache_.lookup(question->getName(), question->getType(),
diff --git a/src/lib/cache/message_cache.cc b/src/lib/cache/message_cache.cc
index 5edf81c..3e447a9 100644
--- a/src/lib/cache/message_cache.cc
+++ b/src/lib/cache/message_cache.cc
@@ -60,7 +60,9 @@ bool
MessageCache::update(const Message& msg) {
QuestionIterator iter = msg.beginQuestion();
std::string entry_name = genCacheEntryName((*iter)->getName(), (*iter)->getType());
- std::cout << "[XX] MESSAGECACHE UDPATE: " << entry_name << std::endl;
+ std::cout << "[XX] MESSAGECACHE UPDATE: " << entry_name << std::endl;
+ std::cout << "[XX] FOR MESSAGE:" << std::endl;
+ std::cout << msg.toText();
HashKey entry_key = HashKey(entry_name, RRClass(message_class_));
// The simplest way to update is removing the old message entry directly.
diff --git a/src/lib/resolve/resolve.cc b/src/lib/resolve/resolve.cc
index 312c89d..c2bbe5c 100644
--- a/src/lib/resolve/resolve.cc
+++ b/src/lib/resolve/resolve.cc
@@ -14,6 +14,9 @@
#include <resolve/resolve.h>
+#include <dns/message.h>
+#include <dns/opcode.h>
+
using namespace isc::dns;
namespace {
@@ -44,6 +47,22 @@ makeErrorMessage(MessagePtr answer_message,
answer_message->setRcode(error_code);
}
+void initResponseMessage(const isc::dns::Message& query_message,
+ isc::dns::Message& response_message)
+{
+ response_message.setOpcode(query_message.getOpcode());
+ response_message.setQid(query_message.getQid());
+ response_message.appendSection(Message::SECTION_QUESTION,
+ query_message);
+}
+
+void initResponseMessage(const isc::dns::Question& question,
+ isc::dns::Message& response_message)
+{
+ response_message.setOpcode(isc::dns::Opcode::QUERY());
+ response_message.addQuestion(question);
+}
+
void copyResponseMessage(const Message& source, MessagePtr target) {
target->setRcode(source.getRcode());
diff --git a/src/lib/resolve/resolve.h b/src/lib/resolve/resolve.h
index b08c30c..944691d 100644
--- a/src/lib/resolve/resolve.h
+++ b/src/lib/resolve/resolve.h
@@ -42,6 +42,36 @@ namespace resolve {
void makeErrorMessage(isc::dns::MessagePtr answer_message,
const isc::dns::Rcode& error_code);
+
+/// \brief Initialize a response message
+///
+/// Based on the given query message, this fills in the very
+/// first details of the response (i.e. the Question section and
+/// the Opcode). This allows for direct usage of makeErrorMessage(),
+/// as well as ResolveCache.lookup().
+///
+/// \param query_message The query message to take the Question, Qid,
+/// and Opcode from.
+/// \param response_message The fresh response message to initialize
+/// (must be type Message::RENDER)
+void initResponseMessage(const isc::dns::Message& query_message,
+ isc::dns::Message& response_message);
+
+
+/// \brief Initialize a response message
+///
+/// Based on the given question, this fills in the very
+/// first details of the response (i.e. the Question section and the
+/// Opcode Query). This allows for direct usage of makeErrorMessage(),
+/// as well as ResolveCache.lookup().
+///
+/// \param question The question to place in the Question section
+/// \param response_message The fresh response message to initialize
+/// (must be type Message::RENDER)
+void initResponseMessage(const isc::dns::Question& question,
+ isc::dns::Message& response_message);
+
+
/// \brief Copies the parts relevant for a DNS response to the
/// target message
///
More information about the bind10-changes
mailing list