Browse Source

More convenient resolver interface

It does not return the whole message, just the RRset. This way we can
extract the data easier and it can be provided directly from cache.

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac408@3673 e5f2f494-b856-4b98-b285-d166d9295462
Michal Vaner 14 years ago
parent
commit
71e2459403
3 changed files with 22 additions and 38 deletions
  1. 18 33
      src/lib/nsas/nameserver_entry.cc
  2. 3 1
      src/lib/nsas/resolver_interface.h
  3. 1 4
      src/lib/nsas/tests/nsas_test.h

+ 18 - 33
src/lib/nsas/nameserver_entry.cc

@@ -297,45 +297,30 @@ class NameserverEntry::ResolverCallback : public ResolverInterface::Callback {
             family_(family),
             type_(type)
         { }
-        virtual void success(const Message& response) {
+        virtual void success(shared_ptr<AbstractRRset> response) {
             Lock lock(entry_->mutex_);
 
             vector<AddressEntry> entries;
 
-            bool found(false);
-            for (RRsetIterator set(
-                // TODO Trunk does Section::ANSWER() by constant
-                response.beginSection(Section::ANSWER()));
-                set != response.endSection(Section::ANSWER()); ++ set)
+            if (response->getType() != type_ ||
+                response->getClass() != RRClass(entry_->getClass()))
             {
-                if (found) {
-                    // TODO Log this
-                    // There are more than one RRset in the answer,
-                    // this shouldn't happen
-                    failureInternal(lock);
-                    return;
-                }
-
-                if ((*set)->getType() != type_ ||
-                    (*set)->getClass() != RRClass(entry_->getClass()))
-                {
-                    // TODO Log we got answer of different type
-                    failureInternal(lock);
-                    return;
-                }
+                // TODO Log we got answer of different type
+                failureInternal(lock);
+                return;
+            }
 
-                /**
-                 * TODO Move to common function, this is similar to
-                 * what is in constructor.
-                 */
-                RdataIteratorPtr i((*set)->getRdataIterator());
-                // TODO Remove at merge with trunk
-                i->first();
-                while (! i->isLast()) {
-                    entries.push_back(AddressEntry(IOAddress(
-                        i->getCurrent().toText()), ++ rtt_));
-                    i->next();
-                }
+            /**
+             * TODO Move to common function, this is similar to
+             * what is in constructor.
+             */
+            RdataIteratorPtr i(response->getRdataIterator());
+            // TODO Remove at merge with trunk
+            i->first();
+            while (! i->isLast()) {
+                entries.push_back(AddressEntry(IOAddress(
+                    i->getCurrent().toText()), ++ rtt_));
+                i->next();
             }
 
             if (entries.empty()) {

+ 3 - 1
src/lib/nsas/resolver_interface.h

@@ -18,6 +18,7 @@
 #define __RESOLVER_INTERFACE_H
 
 #include <dns/message.h>
+#include <dns/rrset.h>
 
 /**
  * \file resolver_interface.h
@@ -45,7 +46,8 @@ class ResolverInterface {
         class Callback {
             public:
                 /// \short Some data arrived.
-                virtual void success(const isc::dns::Message& response) = 0;
+                virtual void success(boost::shared_ptr<isc::dns::AbstractRRset>
+                    response) = 0;
                 /**
                  * \short No data available.
                  *

+ 1 - 4
src/lib/nsas/tests/nsas_test.h

@@ -274,10 +274,7 @@ class TestResolver : public isc::nsas::ResolverInterface {
             RRsetPtr set(new RRset(name, RRClass::IN(),
                 type, RRTTL(TTL)));
             set->addRdata(rdata);
-            Message address(Message::RENDER); // Not able to create different one
-            address.addRRset(Section::ANSWER(), set);
-            address.addQuestion(requests[index].first);
-            requests[index].second->success(address);
+            requests[index].second->success(set);
         }
 };