Parcourir la source

Interface of resolver

Well, temporary one, for now

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac408@3475 e5f2f494-b856-4b98-b285-d166d9295462
Michal Vaner il y a 14 ans
Parent
commit
a27af596bb

+ 4 - 3
src/lib/nsas/nameserver_address_store.cc

@@ -36,13 +36,14 @@ namespace nsas {
 // The LRU lists are set equal to three times the size of the respective
 // hash table, on the assumption that three elements is the longest linear
 // search we want to do when looking up names in the hash table.
-NameserverAddressStore::NameserverAddressStore(uint32_t zonehashsize,
-    uint32_t nshashsize) :
+NameserverAddressStore::NameserverAddressStore(ResolverInterface& resolver,
+    uint32_t zonehashsize, uint32_t nshashsize) :
     zone_hash_(new NsasEntryCompare<ZoneEntry>, zonehashsize),
     nameserver_hash_(new NsasEntryCompare<NameserverEntry>, nshashsize),
     zone_lru_((3 * zonehashsize), new HashDeleter<ZoneEntry>(zone_hash_)),
     nameserver_lru_((3 * nshashsize), new HashDeleter<NameserverEntry>(
-        nameserver_hash_))
+        nameserver_hash_)),
+    resolver_(resolver)
 {
 }
 

+ 8 - 3
src/lib/nsas/nameserver_address_store.h

@@ -27,6 +27,7 @@
 #include "nameserver_entry.h"
 #include "lru_list.h"
 #include "zone_entry.h"
+#include "resolver_interface.h"
 
 namespace isc {
 namespace nsas {
@@ -46,15 +47,17 @@ public:
     /// The constructor sizes all the tables.  As there are various
     /// relationships between the table sizes, and as some values are best as
     /// prime numbers, the table sizes are determined by compile-time values.
-    /// 
+    ///
+    /// \param resolver Which resolver object (or resolver-like, in case of
+    /// tests) should it use to ask questions.
     /// \param zonehashsize Size of the zone hash table.  The default value of
     /// 1009 is the first prime number above 1000.
     /// \param nshash size Size of the nameserver hash table.  The default
     /// value of 2003 is the first prime number over 2000, and by implication,
     /// there is an assumption that there will be more nameservers than zones
     /// in the store.
-    NameserverAddressStore(uint32_t zonehashsize = 1009,
-        uint32_t nshashsize = 3001);
+    NameserverAddressStore(ResolverInterface& resolver,
+        uint32_t zonehashsize = 1009, uint32_t nshashsize = 3001);
 
     /// \brief Destructor
     ///
@@ -99,6 +102,8 @@ protected:
     LruList<ZoneEntry>          zone_lru_;
     LruList<NameserverEntry>    nameserver_lru_;
     //}@
+private:
+    ResolverInterface& resolver_;
 };
 
 } // namespace nsas

+ 73 - 0
src/lib/nsas/resolver_interface.h

@@ -0,0 +1,73 @@
+// Copyright (C) 2010  CZ NIC
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+// $id$
+
+#ifndef __RESOLVER_INTERFACE_H
+#define __RESOLVER_INTERFACE_H
+
+#include <dns/message.h>
+
+/**
+ * \file resolver_interface.h
+ * \short Temporary interface to resolver.
+ *
+ * This file contains a dummy interface for the resolver, which does not yet
+ * exist. When the resolver appears, this file should either wrap its
+ * interface or, better, be removed completely.
+ */
+
+namespace isc {
+namespace nsas {
+
+/**
+ * \short Abstract interface to the resolver.
+ *
+ * Abstract interface to the resolver. The NameserverAddressStore uses this
+ * to ask for addresses. It is here because resolver does not yet exist.
+ *
+ * It is abstract to allow tests pass dummy resolvers.
+ */
+class ResolverInterface {
+    public:
+        /// \short An abstract callback when data from resolver are ready.
+        class Callback {
+            public:
+                /// \short Some data arrived.
+                virtual void success(const isc::dns::Message& response) = 0;
+                /**
+                 * \short No data available.
+                 *
+                 * \todo Pass some reason.
+                 */
+                virtual void failure() = 0;
+        };
+        typedef boost::shared_ptr<Callback> CallbackPtr;
+        /**
+         * \short Ask a question.
+         *
+         * Asks the resolver a question. Once the answer is ready
+         * the callback is called.
+         *
+         * \param question What to ask. The resolver will decide who.
+         * \param callback What should happen when the answer is ready.
+         */
+        virtual void resolve(isc::dns::QuestionPtr question,
+            CallbackPtr callback) = 0;
+};
+
+} // namespace nsas
+} // namespace isc
+
+#endif //__RESOLVER_INTERFACE_H

+ 15 - 4
src/lib/nsas/tests/nameserver_address_store_unittest.cc

@@ -26,6 +26,7 @@
 
 #include <string.h>
 #include <vector>
+#include <cassert>
 
 #include "nameserver_address_store.h"
 #include "nsas_entry_compare.h"
@@ -33,6 +34,8 @@
 #include "zone_entry.h"
 #include "nsas_test.h"
 
+using namespace isc::dns;
+
 namespace isc {
 namespace nsas {
 
@@ -47,8 +50,9 @@ public:
     ///
     /// \param hashsize Size of the zone hash table
     /// \param lrusize Size of the zone hash table
-    DerivedNsas(uint32_t hashsize, uint32_t lrusize) :
-        NameserverAddressStore(hashsize, lrusize)
+    DerivedNsas(ResolverInterface& resolver, uint32_t hashsize,
+        uint32_t lrusize) :
+        NameserverAddressStore(resolver, hashsize, lrusize)
     {}
 
     /// \brief Virtual Destructor
@@ -94,6 +98,13 @@ protected:
     // Vector of pointers to nameserver and zone entries.
     std::vector<boost::shared_ptr<NameserverEntry> > nameservers_;
     std::vector<boost::shared_ptr<ZoneEntry> >       zones_;
+
+    class TestResolver : public ResolverInterface {
+        public:
+            virtual void resolve(QuestionPtr, CallbackPtr) {
+                assert(0); // TODO Implement
+            }
+    } defaultTestResolver;
 };
 
 
@@ -105,7 +116,7 @@ TEST_F(NameserverAddressStoreTest, ZoneDeletionCheck) {
 
     // Create a NSAS with a hash size of three and a LRU size of 9 (both zone and
     // nameserver tables).
-    DerivedNsas nsas(2, 2);
+    DerivedNsas nsas(defaultTestResolver, 2, 2);
 
     // Add six entries to the tables.  After addition the reference count of each element
     // should be 3 - one for the entry in the zones_ vector, and one each for the entries
@@ -135,7 +146,7 @@ TEST_F(NameserverAddressStoreTest, NameserverDeletionCheck) {
 
     // Create a NSAS with a hash size of three and a LRU size of 9 (both zone and
     // nameserver tables).
-    DerivedNsas nsas(2, 2);
+    DerivedNsas nsas(defaultTestResolver, 2, 2);
 
     // Add six entries to the tables.  After addition the reference count of each element
     // should be 3 - one for the entry in the nameservers_ vector, and one each for the entries