Browse Source

[trac495] Add NSAS to resolver (unused as of yet)

Also moved initialization of the cache to Resolver
Jelte Jansen 14 years ago
parent
commit
19603be4d3

+ 11 - 4
src/bin/resolver/main.cc

@@ -45,6 +45,9 @@
 #include <resolver/spec_config.h>
 #include <resolver/resolver.h>
 
+#include <cache/resolver_cache.h>
+#include <nsas/nameserver_address_store.h>
+
 #include <log/dummylog.h>
 
 using namespace std;
@@ -60,7 +63,7 @@ namespace {
 static const string PROGRAM = "Resolver";
 
 IOService io_service;
-static Resolver *resolver;
+static boost::shared_ptr<Resolver> resolver;
 
 ConstElementPtr
 my_config_handler(ConstElementPtr new_config) {
@@ -136,15 +139,20 @@ main(int argc, char* argv[]) {
             specfile = string(RESOLVER_SPECFILE_LOCATION);
         }
 
-        resolver = new Resolver();
+        resolver = boost::shared_ptr<Resolver>(new Resolver());
         dlog("Server created.");
 
         SimpleCallback* checkin = resolver->getCheckinProvider();
         DNSLookup* lookup = resolver->getDNSLookupProvider();
         DNSAnswer* answer = resolver->getDNSAnswerProvider();
 
-        DNSService dns_service(io_service, checkin, lookup, answer);
+        isc::nsas::NameserverAddressStore nsas(resolver);
+        resolver->setNameserverAddressStore(nsas);
 
+        isc::cache::ResolverCache cache;
+        resolver->setCache(cache);
+
+        DNSService dns_service(io_service, checkin, lookup, answer);
         resolver->setDNSService(dns_service);
         dlog("IOService created.");
 
@@ -173,7 +181,6 @@ main(int argc, char* argv[]) {
 
     delete config_session;
     delete cc_session;
-    delete resolver;
 
     return (ret);
 }

+ 22 - 4
src/bin/resolver/resolver.cc

@@ -74,10 +74,15 @@ public:
         queryShutdown();
     }
 
-    void querySetup(DNSService& dnss) {
+    void querySetup(DNSService& dnss,
+                    isc::nsas::NameserverAddressStore& nsas,
+                    isc::cache::ResolverCache& cache)
+    {
         assert(!rec_query_); // queryShutdown must be called first
         dlog("Query setup");
-        rec_query_ = new RecursiveQuery(dnss, upstream_,
+        rec_query_ = new RecursiveQuery(dnss, 
+                                        nsas, cache,
+                                        upstream_,
                                         upstream_root_,
                                         query_timeout_,
                                         client_timeout_,
@@ -129,7 +134,7 @@ public:
             }
         }
     }
-
+    
     void resolve(const isc::dns::QuestionPtr& question,
         const isc::resolve::ResolverInterface::CallbackPtr& callback);
 
@@ -336,6 +341,19 @@ Resolver::setDNSService(asiolink::DNSService& dnss) {
 }
 
 void
+Resolver::setNameserverAddressStore(isc::nsas::NameserverAddressStore& nsas)
+{
+    nsas_ = &nsas;
+}
+
+void
+Resolver::setCache(isc::cache::ResolverCache& cache)
+{
+    cache_ = &cache;
+}
+
+
+void
 Resolver::setConfigSession(ModuleCCSession* config_session) {
     impl_->config_session_ = config_session;
 }
@@ -567,7 +585,7 @@ Resolver::updateConfig(ConstElementPtr config) {
 
         if (need_query_restart) {
             impl_->queryShutdown();
-            impl_->querySetup(*dnss_);
+            impl_->querySetup(*dnss_, *nsas_, *cache_);
         }
         return (isc::config::createAnswer());
     } catch (const isc::Exception& error) {

+ 21 - 0
src/bin/resolver/resolver.h

@@ -24,6 +24,9 @@
 
 #include <asiolink/asiolink.h>
 
+#include <nsas/nameserver_address_store.h>
+#include <cache/resolver_cache.h>
+
 #include <resolve/resolver_interface.h>
 
 class ResolverImpl;
@@ -86,10 +89,26 @@ public:
 
     /// \brief Assign an ASIO IO Service queue to this Resolver object
     void setDNSService(asiolink::DNSService& dnss);
+    
+    /// \brief Assign a NameserverAddressStore to this Resolver object
+    void setNameserverAddressStore(isc::nsas::NameserverAddressStore &nsas);
+    
+    /// \brief Assign a cache to this Resolver object
+    void setCache(isc::cache::ResolverCache& cache);
 
     /// \brief Return this object's ASIO IO Service queue
     asiolink::DNSService& getDNSService() const { return (*dnss_); }
 
+    /// \brief Returns this object's NSAS
+    isc::nsas::NameserverAddressStore& getNameserverAddressStore() const {
+        return *nsas_;
+    };
+
+    /// \brief Returns this object's ResolverCache
+    isc::cache::ResolverCache& getResolverCache() const {
+        return *cache_;
+    };
+    
     /// \brief Return pointer to the DNS Lookup callback function
     asiolink::DNSLookup* getDNSLookupProvider() { return (dns_lookup_); }
 
@@ -208,6 +227,8 @@ private:
     asiolink::SimpleCallback* checkin_;
     asiolink::DNSLookup* dns_lookup_;
     asiolink::DNSAnswer* dns_answer_;
+    isc::nsas::NameserverAddressStore* nsas_;
+    isc::cache::ResolverCache* cache_;
 };
 
 #endif // __RESOLVER_H

+ 14 - 6
src/lib/asiolink/recursive_query.cc

@@ -49,15 +49,20 @@ typedef std::vector<std::pair<std::string, uint16_t> > AddressVector;
 // We can probably use a typedef, but need to move it to a central
 // location and use it consistently.
 RecursiveQuery::RecursiveQuery(DNSService& dns_service,
+    isc::nsas::NameserverAddressStore& nsas,
+    isc::cache::ResolverCache& cache,
     const std::vector<std::pair<std::string, uint16_t> >& upstream,
     const std::vector<std::pair<std::string, uint16_t> >& upstream_root,
     int query_timeout, int client_timeout, int lookup_timeout,
     unsigned retries) :
-    dns_service_(dns_service), upstream_(new AddressVector(upstream)),
+    dns_service_(dns_service),
+    nsas_(nsas), cache_(cache),
+    upstream_(new AddressVector(upstream)),
     upstream_root_(new AddressVector(upstream_root)),
     query_timeout_(query_timeout), client_timeout_(client_timeout),
     lookup_timeout_(lookup_timeout), retries_(retries)
-{}
+{
+}
 
 namespace {
 
@@ -134,6 +139,9 @@ private:
     // answer if we do find one later (or if we have a lookup_timeout)
     bool answer_sent_;
 
+    // Reference to our NSAS
+    isc::nsas::NameserverAddressStore& nsas_;
+
     // Reference to our cache
     isc::cache::ResolverCache& cache_;
 
@@ -263,7 +271,6 @@ private:
                     // just use the first for now
                     if (!rdi->isLast()) {
                         std::string addr_str = rdi->getCurrent().toText();
-                        dlog("[XX] first address found: " + addr_str);
                         // now we have one address, simply
                         // resend that exact same query
                         // to that address and yield, when it
@@ -285,7 +292,6 @@ private:
                 send();
                 return false;
             } else {
-                dlog("[XX] no ready-made addresses in additional. need nsas.");
                 // TODO this will result in answering with the delegation. oh well
                 isc::resolve::copyResponseMessage(incoming, answer_message_);
                 return true;
@@ -324,6 +330,7 @@ public:
         isc::resolve::ResolverInterface::CallbackPtr cb,
         int query_timeout, int client_timeout, int lookup_timeout,
         unsigned retries,
+        isc::nsas::NameserverAddressStore& nsas,
         isc::cache::ResolverCache& cache) :
         io_(io),
         question_(question),
@@ -340,6 +347,7 @@ public:
         queries_out_(0),
         done_(false),
         answer_sent_(false),
+        nsas_(nsas),
         cache_(cache)
     {
         // Setup the timer to stop trying (lookup_timeout)
@@ -498,7 +506,7 @@ RecursiveQuery::resolve(const QuestionPtr& question,
         new RunningQuery(io, *question, answer_message, upstream_,
                          upstream_root_, buffer, callback, query_timeout_,
                          client_timeout_, lookup_timeout_, retries_,
-                         cache_);
+                         nsas_, cache_);
     }
 }
 
@@ -534,7 +542,7 @@ RecursiveQuery::resolve(const Question& question,
         // It will delete itself when it is done
         new RunningQuery(io, question, answer_message, upstream_, upstream_root_,
                              buffer, crs, query_timeout_, client_timeout_,
-                             lookup_timeout_, retries_, cache_);
+                             lookup_timeout_, retries_, nsas_, cache_);
     }
 }
 

+ 5 - 3
src/lib/asiolink/recursive_query.h

@@ -18,6 +18,7 @@
 #include <asiolink/dns_service.h>
 #include <asiolink/dns_server.h>
 #include <dns/buffer.h>
+#include <nsas/nameserver_address_store.h>
 #include <cache/resolver_cache.h>
 
 namespace asiolink {
@@ -52,6 +53,8 @@ public:
     /// \param retries how many times we try again (0 means just send and
     ///     and return if it returs).
     RecursiveQuery(DNSService& dns_service,
+                   isc::nsas::NameserverAddressStore& nsas,
+                   isc::cache::ResolverCache& cache,
                    const std::vector<std::pair<std::string, uint16_t> >&
                    upstream, 
                    const std::vector<std::pair<std::string, uint16_t> >&
@@ -100,6 +103,8 @@ public:
                  DNSServer* server);
 private:
     DNSService& dns_service_;
+    isc::nsas::NameserverAddressStore& nsas_;
+    isc::cache::ResolverCache& cache_;
     boost::shared_ptr<std::vector<std::pair<std::string, uint16_t> > >
         upstream_;
     boost::shared_ptr<std::vector<std::pair<std::string, uint16_t> > >
@@ -108,9 +113,6 @@ private:
     int client_timeout_;
     int lookup_timeout_;
     unsigned retries_;
-    // Cache. TODO: I think we want this initialized in Resolver class,
-    // not here
-    isc::cache::ResolverCache cache_;
 };
 
 }      // namespace asiolink

+ 23 - 2
src/lib/asiolink/tests/recursive_query_unittest.cc

@@ -33,6 +33,9 @@
 #include <dns/buffer.h>
 #include <dns/message.h>
 
+#include <nsas/nameserver_address_store.h>
+#include <cache/resolver_cache.h>
+
 // IMPORTANT: We shouldn't directly use ASIO definitions in this test.
 // In particular, we must not include asio.hpp in this file.
 // The asiolink module is primarily intended to be a wrapper that hide the
@@ -342,6 +345,12 @@ protected:
         private:
             bool* done_;
     };
+    
+    class MockResolver : public isc::resolve::ResolverInterface {
+        void resolve(const QuestionPtr& question,
+                     const ResolverInterface::CallbackPtr& callback) {
+        }
+    };
 
     // This version of mock server just stops the io_service when it is resumed
     // the second time. (Used in the clientTimeout test, where resume
@@ -402,6 +411,8 @@ protected:
     // need to recreate a new one within one onstance of this class
     IOService* io_service_;
     DNSService* dns_service_;
+    isc::nsas::NameserverAddressStore* nsas_;
+    isc::cache::ResolverCache cache_;
     ASIOCallBack* callback_;
     int callback_protocol_;
     int callback_native_;
@@ -416,6 +427,8 @@ RecursiveQueryTest::RecursiveQueryTest() :
 {
     io_service_ = new IOService();
     setDNSService(true, true);
+    boost::shared_ptr<MockResolver>mock_resolver(new MockResolver());
+    nsas_ = new isc::nsas::NameserverAddressStore(mock_resolver);
 }
 
 TEST_F(RecursiveQueryTest, v6UDPSend) {
@@ -517,6 +530,7 @@ TEST_F(RecursiveQueryTest, recursiveSetupV4) {
     setDNSService(true, false);
     uint16_t port = boost::lexical_cast<uint16_t>(TEST_CLIENT_PORT);
     EXPECT_NO_THROW(RecursiveQuery(*dns_service_,
+                                   *nsas_, cache_,
                                    singleAddress(TEST_IPV4_ADDR, port),
                                    singleAddress(TEST_IPV4_ADDR, port)));
 }
@@ -525,6 +539,7 @@ TEST_F(RecursiveQueryTest, recursiveSetupV6) {
     setDNSService(false, true);
     uint16_t port = boost::lexical_cast<uint16_t>(TEST_CLIENT_PORT);
     EXPECT_NO_THROW(RecursiveQuery(*dns_service_,
+                                   *nsas_, cache_,
                                    singleAddress(TEST_IPV6_ADDR, port),
                                    singleAddress(TEST_IPV6_ADDR,port)));
 }
@@ -543,6 +558,7 @@ TEST_F(RecursiveQueryTest, forwarderSend) {
 
     MockServer server(*io_service_);
     RecursiveQuery rq(*dns_service_,
+                      *nsas_, cache_,
                       singleAddress(TEST_IPV4_ADDR, port),
                       singleAddress(TEST_IPV4_ADDR, port));
 
@@ -630,6 +646,7 @@ TEST_F(RecursiveQueryTest, forwardQueryTimeout) {
     // Do the answer
     const uint16_t port = boost::lexical_cast<uint16_t>(TEST_CLIENT_PORT);
     RecursiveQuery query(*dns_service_,
+                         *nsas_, cache_,
                          singleAddress(TEST_IPV4_ADDR, port),
                          singleAddress(TEST_IPV4_ADDR, port),
                          10, 4000, 3000, 2);
@@ -675,6 +692,7 @@ TEST_F(RecursiveQueryTest, forwardClientTimeout) {
     // Since the lookup timer has not fired, it should retry
     // four times
     RecursiveQuery query(*dns_service_,
+                         *nsas_, cache_,
                          singleAddress(TEST_IPV4_ADDR, port),
                          singleAddress(TEST_IPV4_ADDR, port),
                          200, 480, 4000, 4);
@@ -719,6 +737,7 @@ TEST_F(RecursiveQueryTest, forwardLookupTimeout) {
     // Set up the test so that it will retry 5 times, but the lookup
     // timeout will fire after only 3 normal timeouts
     RecursiveQuery query(*dns_service_,
+                         *nsas_, cache_,
                          singleAddress(TEST_IPV4_ADDR, port),
                          singleAddress(TEST_IPV4_ADDR, port),
                          200, 4000, 480, 5);
@@ -753,7 +772,8 @@ TEST_F(RecursiveQueryTest, DISABLED_recursiveSendOk) {
     
     MockServerStop server(*io_service_, &done);
     vector<pair<string, uint16_t> > empty_vector;
-    RecursiveQuery rq(*dns_service_, empty_vector, empty_vector, 10000, 0);
+    RecursiveQuery rq(*dns_service_, *nsas_, cache_, empty_vector,
+                      empty_vector, 10000, 0);
 
     Question q(Name("www.isc.org"), RRClass::IN(), RRType::A());
     OutputBufferPtr buffer(new OutputBuffer(0));
@@ -778,7 +798,8 @@ TEST_F(RecursiveQueryTest, DISABLED_recursiveSendNXDOMAIN) {
     
     MockServerStop server(*io_service_, &done);
     vector<pair<string, uint16_t> > empty_vector;
-    RecursiveQuery rq(*dns_service_, empty_vector, empty_vector, 10000, 0);
+    RecursiveQuery rq(*dns_service_, *nsas_, cache_, empty_vector,
+                      empty_vector, 10000, 0);
 
     Question q(Name("wwwdoesnotexist.isc.org"), RRClass::IN(), RRType::A());
     OutputBufferPtr buffer(new OutputBuffer(0));